From: Ben Gamsa Date: Thu, 8 May 2008 15:42:09 +0000 (-0400) Subject: Added two new functions to facilitate processing the nexthop entries for routes. X-Git-Tag: libnl2_0~105 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cc9c6d63848400b77906a4a9df0be826dfc21b72;p=libnl Added two new functions to facilitate processing the nexthop entries for routes. Added rtnl_route_foreach_nexthop() to walk the list of nexthops invoking a caller-provided callback for each nexthop entry, and added rtnl_route_nexthop_n() to retrieve the Nth nexthop entry in the list. --- diff --git a/include/netlink/route/route.h b/include/netlink/route/route.h index b7bf155..071f2c5 100644 --- a/include/netlink/route/route.h +++ b/include/netlink/route/route.h @@ -102,6 +102,12 @@ extern void rtnl_route_remove_nexthop(struct rtnl_route *, extern struct nl_list_head * rtnl_route_get_nexthops(struct rtnl_route *); extern int rtnl_route_get_nnexthops(struct rtnl_route *); +extern void rtnl_route_foreach_nexthop(struct rtnl_route *r, + void (*cb)(struct rtnl_nexthop *, void *), + void *arg); + +extern struct rtnl_nexthop * rtnl_route_nexthop_n(struct rtnl_route *r, int n); + extern int rtnl_route_guess_scope(struct rtnl_route *); extern char * rtnl_route_table2str(int, char *, size_t); diff --git a/lib/route/route_obj.c b/lib/route/route_obj.c index 9b92214..200f561 100644 --- a/lib/route/route_obj.c +++ b/lib/route/route_obj.c @@ -763,6 +763,34 @@ int rtnl_route_get_nnexthops(struct rtnl_route *route) return route->rt_nr_nh; } +void rtnl_route_foreach_nexthop(struct rtnl_route *r, + void (*cb)(struct rtnl_nexthop *, void *), + void *arg) +{ + struct rtnl_nexthop *nh; + + if (r->ce_mask & ROUTE_ATTR_MULTIPATH) { + nl_list_for_each_entry(nh, &r->rt_nexthops, rtnh_list) { + cb(nh, arg); + } + } +} + +struct rtnl_nexthop *rtnl_route_nexthop_n(struct rtnl_route *r, int n) +{ + struct rtnl_nexthop *nh; + int i; + + if (r->ce_mask & ROUTE_ATTR_MULTIPATH && r->rt_nr_nh > n) { + i = 0; + nl_list_for_each_entry(nh, &r->rt_nexthops, rtnh_list) { + if (i == n) return nh; + i++; + } + } + return NULL; +} + /** @} */ /**