diff options
author | Ben Gamsa <ben@somanetworks.com> | 2008-05-08 15:42:09 (GMT) |
---|---|---|
committer | Thomas Graf <tgr@lsx.localdomain> | 2008-05-08 15:54:37 (GMT) |
commit | cc9c6d63848400b77906a4a9df0be826dfc21b72 (patch) | |
tree | 203c2ed72d8bd0c8fbd5bd9e748c7ee4714d72a0 /lib/route | |
parent | 48e1e5c4720094f60494ee55c2a22230ac986ad3 (diff) | |
download | libnl-cc9c6d63848400b77906a4a9df0be826dfc21b72.zip libnl-cc9c6d63848400b77906a4a9df0be826dfc21b72.tar.gz libnl-cc9c6d63848400b77906a4a9df0be826dfc21b72.tar.bz2 |
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.
Diffstat (limited to 'lib/route')
-rw-r--r-- | lib/route/route_obj.c | 28 |
1 files changed, 28 insertions, 0 deletions
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; +} + /** @} */ /** |