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

📄 ldp_global.c.new

📁 Linux平台下
💻 NEW
📖 第 1 页 / 共 2 页
字号:
  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;      }      e = MPLS_LIST_NEXT(&g->entity, e, _global);    }  }  *entity = NULL;  return MPLS_FAILURE;}ldp_peer *ldp_global_find_peer_addr(ldp_global * g, mpls_inet_addr * addr){  ldp_peer *p;  MPLS_ASSERT(g && addr);  /* JLEU: we will need to add a tree to optimize this search,     known peers will be in tree, unknown will take a "slow path" to     verify them, then be added to tree */  p = MPLS_LIST_HEAD(&g->peer);  while (p) {    LDP_PRINT(g->user_data,      "ldp_global_find_peer_lsrid: peer: %08x lsrid: %08x\n",      p->dest.addr.u.ipv4, addr->u.ipv4);    if (!mpls_inet_addr_compare(&p->dest.addr, addr)) {      return p;    }    p = MPLS_LIST_NEXT(&g->peer, p, _global);  }  return NULL;}mpls_return_enum ldp_global_find_adj_index(ldp_global * g, uint32_t index,  ldp_adj ** adj){  ldp_adj *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->adj);    if (a == NULL || a->index < index) {      return MPLS_END_OF_LIST;      *adj = NULL;    }    a = MPLS_LIST_HEAD(&g->adj);    while (a != NULL) {      if (a->index == index) {        *adj = a;        return MPLS_SUCCESS;      }      a = MPLS_LIST_NEXT(&g->adj, a, _global);    }  }  *adj = NULL;  return MPLS_FAILURE;}mpls_return_enum ldp_global_find_peer_index(ldp_global * g, uint32_t index,  ldp_peer ** peer){  ldp_peer *p = 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 */    p = MPLS_LIST_TAIL(&g->peer);    if (p == NULL || p->index < index) {      *peer = NULL;      return MPLS_END_OF_LIST;    }    p = MPLS_LIST_HEAD(&g->peer);    while (p != NULL) {      if (p->index == index) {        *peer = p;        return MPLS_SUCCESS;      }      p = MPLS_LIST_NEXT(&g->peer, p, _global);    }  }  *peer = NULL;  return MPLS_FAILURE;}mpls_return_enum ldp_global_find_fec_index(ldp_global * g, uint32_t index,  ldp_fec ** fec){  ldp_fec *f = 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 */    f = MPLS_LIST_TAIL(&g->fec);    if (f == NULL || f->index < index) {      *fec = NULL;      return MPLS_END_OF_LIST;    }    f = MPLS_LIST_HEAD(&g->fec);    while (f != NULL) {      if (f->index == index) {        *fec = f;        return MPLS_SUCCESS;      }      f = MPLS_LIST_NEXT(&g->fec, f, _global);    }  }  *fec = NULL;  return MPLS_FAILURE;}mpls_return_enum ldp_global_find_fec(ldp_global * g, mpls_fec * m,  ldp_fec ** fec){  ldp_fec *f = NULL;  MPLS_ASSERT(g && m);  f = MPLS_LIST_HEAD(&g->fec);  do {    if (!mpls_fec_compare(m, &f->info)) {      *fec = f;      return MPLS_SUCCESS;    }  } while((f = MPLS_LIST_NEXT(&g->fec, f, _global)));  *fec = NULL;  return MPLS_FAILURE;}mpls_return_enum ldp_global_find_addr_index(ldp_global * g, uint32_t index,  ldp_addr ** addr){  ldp_addr *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->addr);    if (a == NULL || a->index < index) {      *addr = NULL;      return MPLS_END_OF_LIST;    }    a = MPLS_LIST_HEAD(&g->addr);    while (a != NULL) {      if (a->index == index) {        *addr = a;        return MPLS_SUCCESS;      }      a = MPLS_LIST_NEXT(&g->addr, a, _global);    }  }  *addr = NULL;  return MPLS_FAILURE;}mpls_return_enum ldp_global_find_if_index(ldp_global * g, uint32_t index,  ldp_if ** iff){  ldp_if *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->iff);    if (i == NULL || i->index < index) {      *iff = NULL;      return MPLS_END_OF_LIST;    }    i = MPLS_LIST_HEAD(&g->iff);    while (i != NULL) {      if (i->index == index) {        *iff = i;        return MPLS_SUCCESS;      }      i = MPLS_LIST_NEXT(&g->iff, i, _global);    }  }  *iff = NULL;  return MPLS_FAILURE;}ldp_if *ldp_global_find_if_handle(ldp_global * g, mpls_if_handle handle){  ldp_if *i = MPLS_LIST_HEAD(&g->iff);  if (g) {    while (i != NULL) {      if (!mpls_if_handle_compare(i->handle, handle))        return i;      i = MPLS_LIST_NEXT(&g->iff, i, _global);    }  }  return NULL;}ldp_adj *ldp_global_find_adj_ldpid(ldp_global * g, mpls_inet_addr * lsraddr,  int labelspace){  ldp_adj *a = MPLS_LIST_HEAD(&g->adj);  while (a != NULL) {    if ((!mpls_inet_addr_compare(lsraddr, &a->remote_lsr_address)) &&      labelspace == a->remote_label_space)      return a;    a = MPLS_LIST_NEXT(&g->adj, a, _global);  }  return NULL;}mpls_return_enum ldp_global_find_tunnel_index(ldp_global * g, uint32_t index,  ldp_tunnel ** tunnel){  ldp_tunnel *t = 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 */    t = MPLS_LIST_TAIL(&g->tunnel);    if (t == NULL || t->index < index) {      *tunnel = NULL;      return MPLS_END_OF_LIST;    }    t = MPLS_LIST_HEAD(&g->tunnel);    while (t != NULL) {      if (t->index == index) {        *tunnel = t;        return MPLS_SUCCESS;      }      t = MPLS_LIST_NEXT(&g->tunnel, t, _global);    }  }  *tunnel = NULL;  return MPLS_FAILURE;}mpls_return_enum ldp_global_find_resource_index(ldp_global * g, uint32_t index,  ldp_resource ** resource){  ldp_resource *r = 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 */    r = MPLS_LIST_TAIL(&g->resource);    if (r == NULL || r->index < index) {      *resource = NULL;      return MPLS_END_OF_LIST;    }    r = MPLS_LIST_HEAD(&g->resource);    while (r != NULL) {      if (r->index == index) {        *resource = r;        return MPLS_SUCCESS;      }      r = MPLS_LIST_NEXT(&g->resource, r, _global);    }  }  *resource = NULL;  return MPLS_FAILURE;}mpls_return_enum ldp_global_find_hop_list_index(ldp_global * g, uint32_t index,  ldp_hop_list ** hop_list){  ldp_hop_list *h = 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 */    h = MPLS_LIST_TAIL(&g->hop_list);    if (h == NULL || h->index < index) {      *hop_list = NULL;      return MPLS_END_OF_LIST;    }    h = MPLS_LIST_HEAD(&g->hop_list);    while (h != NULL) {      if (h->index == index) {        *hop_list = h;        return MPLS_SUCCESS;      }      h = MPLS_LIST_NEXT(&g->hop_list, h, _global);    }  }  *hop_list = NULL;  return MPLS_FAILURE;}void _ldp_global_add_tunnel(ldp_global * g, ldp_tunnel * t){  ldp_tunnel *tp = NULL;  MPLS_ASSERT(g && t);  MPLS_REFCNT_HOLD(t);  tp = MPLS_LIST_HEAD(&g->tunnel);  while (tp != NULL) {    if (tp->index > t->index) {      MPLS_LIST_INSERT_BEFORE(&g->tunnel, tp, t, _global);      return;    }    tp = MPLS_LIST_NEXT(&g->tunnel, tp, _global);  }  MPLS_LIST_ADD_TAIL(&g->tunnel, t, _global, ldp_tunnel);}void _ldp_global_del_tunnel(ldp_global * g, ldp_tunnel * t){  MPLS_ASSERT(g && t);  MPLS_LIST_REMOVE(&g->tunnel, t, _global);  MPLS_REFCNT_RELEASE(t, ldp_tunnel_delete);}void _ldp_global_add_resource(ldp_global * g, ldp_resource * r){  ldp_resource *rp = NULL;  MPLS_ASSERT(g && r);  MPLS_REFCNT_HOLD(r);  rp = MPLS_LIST_HEAD(&g->resource);  while (rp != NULL) {    if (rp->index > r->index) {      MPLS_LIST_INSERT_BEFORE(&g->resource, rp, r, _global);      return;    }    rp = MPLS_LIST_NEXT(&g->resource, rp, _global);  }  MPLS_LIST_ADD_TAIL(&g->resource, r, _global, ldp_resource);}void _ldp_global_del_resource(ldp_global * g, ldp_resource * r){  MPLS_ASSERT(g && r);  MPLS_LIST_REMOVE(&g->resource, r, _global);  MPLS_REFCNT_RELEASE(r, ldp_resource_delete);}void _ldp_global_add_hop_list(ldp_global * g, ldp_hop_list * h){  ldp_hop_list *hp = NULL;  MPLS_ASSERT(g && h);  MPLS_REFCNT_HOLD(h);  hp = MPLS_LIST_HEAD(&g->hop_list);  while (hp != NULL) {    if (hp->index > h->index) {      MPLS_LIST_INSERT_BEFORE(&g->hop_list, hp, h, _global);      return;    }    hp = MPLS_LIST_NEXT(&g->hop_list, hp, _global);  }  MPLS_LIST_ADD_TAIL(&g->hop_list, h, _global, ldp_hop_list);}void _ldp_global_del_hop_list(ldp_global * g, ldp_hop_list * h){  MPLS_ASSERT(g && h);  MPLS_LIST_REMOVE(&g->hop_list, h, _global);  MPLS_REFCNT_RELEASE(h, ldp_hop_list_delete);}void _ldp_global_add_fec(ldp_global * g, ldp_fec * f){  ldp_fec *fp = NULL;  MPLS_ASSERT(g && f);  /*   * TESTING: jleu 6/7/2004, since I want the FEC to be cleaned up   * when it no longer has a nexthop, addr, or label, the only things that   * should increment the ref are those (nh, addr, label etc), not global   * nor inserting into the tree.  I also added this comment in   * ldp_fec_create()  MPLS_REFCNT_HOLD(f);   */  fp = MPLS_LIST_HEAD(&g->fec);  while (fp != NULL) {    if (fp->index > f->index) {      MPLS_LIST_INSERT_BEFORE(&g->fec, fp, f, _global);      return;    }    fp = MPLS_LIST_NEXT(&g->fec, fp, _global);  }  MPLS_LIST_ADD_TAIL(&g->fec, f, _global, ldp_fec);}void _ldp_global_del_fec(ldp_global * g, ldp_fec * f){  MPLS_ASSERT(g && f);  MPLS_LIST_REMOVE(&g->fec, f, _global);}void _ldp_global_add_nexthop(ldp_global * g, ldp_nexthop * nh){  ldp_nexthop *nhp = NULL;  MPLS_ASSERT(g && nh);  nhp = MPLS_LIST_HEAD(&g->nexthop);  while (nhp != NULL) {    if (nhp->index > nh->index) {      MPLS_LIST_INSERT_BEFORE(&g->nexthop, nhp, nh, _global);      return;    }    nhp = MPLS_LIST_NEXT(&g->nexthop, nhp, _global);  }  MPLS_LIST_ADD_TAIL(&g->nexthop, nh, _global, ldp_nexthop);}void _ldp_global_del_nexthop(ldp_global * g, ldp_nexthop * nh){  MPLS_ASSERT(g && nh);  MPLS_LIST_REMOVE(&g->nexthop, nh, _global);}

⌨️ 快捷键说明

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