]> granicus.if.org Git - libnl/commitdiff
Added two new functions to facilitate processing the nexthop entries for routes.
authorBen Gamsa <ben@somanetworks.com>
Thu, 8 May 2008 15:42:09 +0000 (11:42 -0400)
committerThomas Graf <tgr@lsx.localdomain>
Thu, 8 May 2008 15:54:37 +0000 (17:54 +0200)
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.

include/netlink/route/route.h
lib/route/route_obj.c

index b7bf15528aded77eeb4ef6d2aa09a4e7ef16a44a..071f2c5c3e4473d6226577931473b650c7db050b 100644 (file)
@@ -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);
index 9b9221498136094e95784f26a0b1b4fd67036c5d..200f56159066665819fd5090006e1c2654ec2213 100644 (file)
@@ -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;
+}
+
 /** @} */
 
 /**