⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ldp_global.c

📁 Linux平台下
💻 C
📖 第 1 页 / 共 3 页
字号:
  MPLS_ASSERT(g && a);  ap = MPLS_LIST_HEAD(&g->attr);  while (ap != NULL) {    if (ap->index > a->index) {      MPLS_LIST_INSERT_BEFORE(&g->attr, ap, a, _global);      return;    }    ap = MPLS_LIST_NEXT(&g->attr, ap, _global);  }  MPLS_LIST_ADD_TAIL(&g->attr, a, _global, ldp_attr);}void _ldp_global_del_attr(ldp_global * g, ldp_attr * a){  MPLS_ASSERT(g && a);  MPLS_LIST_REMOVE(&g->attr, a, _global);}void _ldp_global_add_peer(ldp_global * g, ldp_peer * p){  ldp_peer *pp = NULL;  MPLS_ASSERT(g && p);  MPLS_REFCNT_HOLD(p);  pp = MPLS_LIST_HEAD(&g->peer);  while (pp != NULL) {    if (pp->index > p->index) {      MPLS_LIST_INSERT_BEFORE(&g->peer, pp, p, _global);      return;    }    pp = MPLS_LIST_NEXT(&g->peer, pp, _global);  }  MPLS_LIST_ADD_TAIL(&g->peer, p, _global, ldp_peer);}void _ldp_global_del_peer(ldp_global * g, ldp_peer * p){  MPLS_ASSERT(g && p);  MPLS_LIST_REMOVE(&g->peer, p, _global);  MPLS_REFCNT_RELEASE(p, ldp_peer_delete);}/* * _ldp_global_add_if/del_if and _ldp_global_add_addr/del_addr are * not the same as the rest of the global_add/del functions.  They * do not hold refcnts, they are used as part of the create and delete * process of these structures */void _ldp_global_add_if(ldp_global * g, ldp_if * i){  ldp_if *ip = NULL;  MPLS_ASSERT(g && i);  ip = MPLS_LIST_HEAD(&g->iff);  while (ip != NULL) {    if (ip->index > i->index) {      MPLS_LIST_INSERT_BEFORE(&g->iff, ip, i, _global);      return;    }    ip = MPLS_LIST_NEXT(&g->iff, ip, _global);  }  MPLS_LIST_ADD_TAIL(&g->iff, i, _global, ldp_if);}void _ldp_global_del_if(ldp_global * g, ldp_if * i){  MPLS_ASSERT(g && i);  MPLS_LIST_REMOVE(&g->iff, i, _global);}void _ldp_global_add_addr(ldp_global * g, ldp_addr * a){  ldp_addr *ap = NULL;  MPLS_ASSERT(g && a);  ap = MPLS_LIST_HEAD(&g->addr);  while (ap != NULL) {    if (ap->index > a->index) {      MPLS_LIST_INSERT_BEFORE(&g->addr, ap, a, _global);      return;    }    ap = MPLS_LIST_NEXT(&g->addr, ap, _global);  }  MPLS_LIST_ADD_TAIL(&g->addr, a, _global, ldp_addr);}void _ldp_global_del_addr(ldp_global * g, ldp_addr * a){  MPLS_ASSERT(g && a);  MPLS_LIST_REMOVE(&g->addr, a, _global);}void _ldp_global_add_adj(ldp_global * g, ldp_adj * a){  ldp_adj *ap = NULL;  MPLS_ASSERT(g && a);  MPLS_REFCNT_HOLD(a);  ap = MPLS_LIST_HEAD(&g->adj);  while (ap != NULL) {    if (ap->index > a->index) {      MPLS_LIST_INSERT_BEFORE(&g->adj, ap, a, _global);      return;    }    ap = MPLS_LIST_NEXT(&g->adj, ap, _global);  }  MPLS_LIST_ADD_TAIL(&g->adj, a, _global, ldp_adj);}void _ldp_global_del_adj(ldp_global * g, ldp_adj * a){  MPLS_ASSERT(g && a);  MPLS_LIST_REMOVE(&g->adj, a, _global);  MPLS_REFCNT_RELEASE(a, ldp_adj_delete);}void _ldp_global_add_entity(ldp_global * g, ldp_entity * e){  ldp_entity *ep = NULL;  MPLS_ASSERT(g && e);  MPLS_REFCNT_HOLD(e);  ep = MPLS_LIST_HEAD(&g->entity);  while (ep != NULL) {    if (ep->index > e->index) {      MPLS_LIST_INSERT_BEFORE(&g->entity, ep, e, _global);      return;    }    ep = MPLS_LIST_NEXT(&g->entity, ep, _global);  }  MPLS_LIST_ADD_TAIL(&g->entity, e, _global, ldp_entity);}void _ldp_global_del_entity(ldp_global * g, ldp_entity * e){  MPLS_ASSERT(g && e);  MPLS_LIST_REMOVE(&g->entity, e, _global);  MPLS_REFCNT_RELEASE(e, ldp_entity_delete);}void _ldp_global_add_session(ldp_global * g, ldp_session * s){  ldp_session *sp = NULL;  MPLS_ASSERT(g && s);  MPLS_REFCNT_HOLD(s);  s->on_global = MPLS_BOOL_TRUE;  sp = MPLS_LIST_HEAD(&g->session);  while (sp != NULL) {    if (sp->index > s->index) {      MPLS_LIST_INSERT_BEFORE(&g->session, sp, s, _global);      return;    }    sp = MPLS_LIST_NEXT(&g->session, sp, _global);  }  MPLS_LIST_ADD_TAIL(&g->session, s, _global, ldp_session);}void _ldp_global_del_session(ldp_global * g, ldp_session * s){  MPLS_ASSERT(g && s);  MPLS_ASSERT(s->on_global == MPLS_BOOL_TRUE);  MPLS_LIST_REMOVE(&g->session, s, _global);  s->on_global = MPLS_BOOL_FALSE;  MPLS_REFCNT_RELEASE(s, ldp_session_delete);}mpls_return_enum _ldp_global_add_inlabel(ldp_global * g, ldp_inlabel * i){  ldp_inlabel *ip = NULL;  mpls_return_enum result;  MPLS_ASSERT(g && i);#if MPLS_USE_LSR  {    lsr_insegment iseg;    memcpy(&iseg.info,&i->info,sizeof(mpls_insegment));    result = lsr_cfg_insegment_set(g->lsr_handle, &iseg, LSR_CFG_ADD|      LSR_INSEGMENT_CFG_NPOP|LSR_INSEGMENT_CFG_FAMILY|      LSR_INSEGMENT_CFG_LABELSPACE|LSR_INSEGMENT_CFG_LABEL|      LSR_INSEGMENT_CFG_OWNER);    memcpy(&i->info, &iseg.info, sizeof(mpls_insegment));    i->info.handle = iseg.index;  }#else  result = mpls_mpls_insegment_add(g->mpls_handle, &i->info);#endif  if (result != MPLS_SUCCESS) {    return result;  }  ip = MPLS_LIST_HEAD(&g->inlabel);  while (ip != NULL) {    if (ip->index > i->index) {      MPLS_LIST_INSERT_BEFORE(&g->inlabel, ip, i, _global);      return MPLS_SUCCESS;    }    ip = MPLS_LIST_NEXT(&g->inlabel, ip, _global);  }  MPLS_LIST_ADD_TAIL(&g->inlabel, i, _global, ldp_inlabel);  return MPLS_SUCCESS;}mpls_return_enum _ldp_global_del_inlabel(ldp_global * g, ldp_inlabel * i){  MPLS_ASSERT(g && i);  MPLS_ASSERT(i->reuse_count == 0);#if MPLS_USE_LSR  {    lsr_insegment iseg;    iseg.index = i->info.handle;    lsr_cfg_insegment_set(g->lsr_handle, &iseg, LSR_CFG_DEL);  }#else  mpls_mpls_insegment_del(g->mpls_handle, &i->info);#endif  MPLS_LIST_REMOVE(&g->inlabel, i, _global);  return MPLS_SUCCESS;}mpls_return_enum _ldp_global_add_outlabel(ldp_global * g, ldp_outlabel * o){  ldp_outlabel *op = NULL;  mpls_return_enum result;  MPLS_ASSERT(g && o);#if MPLS_USE_LSR  {    lsr_outsegment oseg;    memcpy(&oseg.info, &o->info, sizeof(mpls_outsegment));    result = lsr_cfg_outsegment_set(g->lsr_handle, &oseg, LSR_CFG_ADD|      LSR_OUTSEGMENT_CFG_PUSH_LABEL|LSR_OUTSEGMENT_CFG_OWNER|      LSR_OUTSEGMENT_CFG_INTERFACE|LSR_OUTSEGMENT_CFG_LABEL|      LSR_OUTSEGMENT_CFG_NEXTHOP);    o->info.handle = oseg.index;  }#else  result = mpls_mpls_outsegment_add(g->mpls_handle, &o->info);#endif  if (result != MPLS_SUCCESS) {    return result;  }  o->switching = MPLS_BOOL_TRUE;  op = MPLS_LIST_HEAD(&g->outlabel);  while (op != NULL) {    if (op->index > o->index) {      MPLS_LIST_INSERT_BEFORE(&g->outlabel, op, o, _global);      return MPLS_SUCCESS;    }    op = MPLS_LIST_NEXT(&g->outlabel, op, _global);  }  MPLS_LIST_ADD_TAIL(&g->outlabel, o, _global, ldp_outlabel);  return MPLS_SUCCESS;}mpls_return_enum _ldp_global_del_outlabel(ldp_global * g, ldp_outlabel * o){  MPLS_ASSERT(g && o);#if MPLS_USE_LSR  {    lsr_outsegment oseg;    oseg.index = o->info.handle;    lsr_cfg_outsegment_set(g->lsr_handle, &oseg, LSR_CFG_DEL);  }#else  mpls_mpls_outsegment_del(g->mpls_handle, &o->info);#endif  o->switching = MPLS_BOOL_FALSE;  MPLS_ASSERT(o->merge_count == 0);  MPLS_LIST_REMOVE(&g->outlabel, o, _global);  return MPLS_SUCCESS;}mpls_return_enum ldp_global_find_attr_index(ldp_global * g, uint32_t index,  ldp_attr ** attr){  ldp_attr *a = NULL;  if (g && index > 0) {    /* because we sort our inserts by index, this lets us know       if we've "walked" past the end of the list */    a = MPLS_LIST_TAIL(&g->attr);    if (a == NULL || a->index < index) {      return MPLS_END_OF_LIST;      *attr = NULL;    }    a = MPLS_LIST_HEAD(&g->attr);    while (a != NULL) {      if (a->index == index) {        *attr = a;        return MPLS_SUCCESS;      }      a = MPLS_LIST_NEXT(&g->attr, a, _global);    }  }  *attr = NULL;  return MPLS_FAILURE;}mpls_return_enum ldp_global_find_session_index(ldp_global * g, uint32_t index,  ldp_session ** session){  ldp_session *s = NULL;  if (g && index > 0) {    /* because we sort our inserts by index, this lets us know       if we've "walked" past the end of the list */    s = MPLS_LIST_TAIL(&g->session);    if (s == NULL || s->index < index) {      *session = NULL;      return MPLS_END_OF_LIST;    }    s = MPLS_LIST_HEAD(&g->session);    while (s != NULL) {      if (s->index == index) {        *session = s;        return MPLS_SUCCESS;      }      s = MPLS_LIST_NEXT(&g->session, s, _global);    }  }  *session = NULL;  return MPLS_FAILURE;}mpls_return_enum ldp_global_find_inlabel_index(ldp_global * g, uint32_t index,  ldp_inlabel ** inlabel){  ldp_inlabel *i = NULL;  if (g && index > 0) {    /* because we sort our inserts by index, this lets us know       if we've "walked" past the end of the list */    i = MPLS_LIST_TAIL(&g->inlabel);    if (i == NULL || i->index < index) {      *inlabel = NULL;      return MPLS_END_OF_LIST;    }    i = MPLS_LIST_HEAD(&g->inlabel);    while (i != NULL) {      if (i->index == index) {        *inlabel = i;        return MPLS_SUCCESS;      }      i = MPLS_LIST_NEXT(&g->inlabel, i, _global);    }  }  *inlabel = NULL;  return MPLS_FAILURE;}mpls_return_enum ldp_global_find_outlabel_index(ldp_global * g, uint32_t index,  ldp_outlabel ** outlabel){  ldp_outlabel *o = NULL;  if (g && index > 0) {    /* because we sort our inserts by index, this lets us know       if we've "walked" past the end of the list */    o = MPLS_LIST_TAIL(&g->outlabel);    if (o == NULL || o->index < index) {      *outlabel = NULL;      return MPLS_END_OF_LIST;    }    o = MPLS_LIST_HEAD(&g->outlabel);    while (o != NULL) {      if (o->index == index) {        *outlabel = o;        return MPLS_SUCCESS;      }      o = MPLS_LIST_NEXT(&g->outlabel, o, _global);    }  }  *outlabel = NULL;  return MPLS_FAILURE;}ldp_outlabel *ldp_global_find_outlabel_handle(ldp_global * g,  mpls_outsegment_handle handle){  ldp_outlabel *o = MPLS_LIST_HEAD(&g->outlabel);  if (g) {    while (o != NULL) {      if (!mpls_outsegment_handle_compare(o->info.handle, handle))        return o;      o = MPLS_LIST_NEXT(&g->outlabel, o, _global);    }  }  return NULL;}mpls_return_enum ldp_global_find_entity_index(ldp_global * g, uint32_t index,  ldp_entity ** entity){  ldp_entity *e = NULL;  if (g && index > 0) {    /* because we sort our inserts by index, this lets us know       if we've "walked" past the end of the list */    e = MPLS_LIST_TAIL(&g->entity);    if (e == NULL || e->index < index) {      *entity = NULL;      return MPLS_END_OF_LIST;    }    e = MPLS_LIST_HEAD(&g->entity);    while (e != NULL) {      if (e->index == index) {        *entity = e;        return MPLS_SUCCESS;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -