From 30b0617f3999aaac1ce621bc13aa21d365b8c97f Mon Sep 17 00:00:00 2001 From: "James R. Leu" Date: Wed, 10 Jun 2009 23:04:42 -0500 Subject: [PATCH] From: Vasu Dasari Implement ldp_global_find_nexthop_index() --- ldp/ldp_global.c | 29 +++++++++++++++++++++++++++++ ldp/ldp_global.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/ldp/ldp_global.c b/ldp/ldp_global.c index ab6ec6d..7006965 100644 --- a/ldp/ldp_global.c +++ b/ldp/ldp_global.c @@ -1294,3 +1294,32 @@ void _ldp_global_del_nexthop(ldp_global * g, ldp_nexthop * nh) MPLS_ASSERT(g && nh); MPLS_LIST_REMOVE(&g->nexthop, nh, _global); } + +mpls_return_enum ldp_global_find_nexthop_index(ldp_global * g, uint32_t index, + ldp_nexthop ** nexthop) +{ + ldp_nexthop *n = 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 */ + + n = MPLS_LIST_TAIL(&g->nexthop); + if (n == NULL || n->index < index) { + *nexthop = NULL; + return MPLS_END_OF_LIST; + } + + n = MPLS_LIST_HEAD(&g->nexthop); + while (n != NULL) { + if (n->index == index) { + *nexthop = n; + return MPLS_SUCCESS; + } + n = MPLS_LIST_NEXT(&g->nexthop, n, _global); + } + } + *nexthop = NULL; + return MPLS_FAILURE; +} diff --git a/ldp/ldp_global.h b/ldp/ldp_global.h index af40d69..0e6aeb2 100644 --- a/ldp/ldp_global.h +++ b/ldp/ldp_global.h @@ -69,6 +69,8 @@ extern void _ldp_global_del_fec(ldp_global * g, ldp_fec * l); extern void _ldp_global_add_nexthop(ldp_global * g, ldp_nexthop * l); extern void _ldp_global_del_nexthop(ldp_global * g, ldp_nexthop * l); +extern mpls_return_enum ldp_global_find_nexthop_index(ldp_global * g, + uint32_t index, ldp_nexthop ** nexthop); extern void _ldp_global_add_attr(ldp_global * g, ldp_attr * a); extern void _ldp_global_del_attr(ldp_global * g, ldp_attr * a); -- 2.11.4.GIT