Message ID | 20190530031746.2040-6-dsahern@kernel.org |
---|---|
State | Changes Requested |
Delegated to: | David Ahern |
Headers | show |
Series | ip: Add support for nexthop objects | expand |
On Wed, May 29, 2019 at 9:04 PM David Ahern <dsahern@kernel.org> wrote: > > From: David Ahern <dsahern@gmail.com> > > Add rtnl_nexthopdump_req to initiate a dump request of nexthop objects. > > Signed-off-by: David Ahern <dsahern@gmail.com> > --- > include/libnetlink.h | 4 ++++ > lib/libnetlink.c | 27 +++++++++++++++++++++++++++ > 2 files changed, 31 insertions(+) > > diff --git a/include/libnetlink.h b/include/libnetlink.h > index 599b2c592f68..1ddba8dcd220 100644 > --- a/include/libnetlink.h > +++ b/include/libnetlink.h > @@ -93,6 +93,10 @@ int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, > int rtnl_dump_request_n(struct rtnl_handle *rth, struct nlmsghdr *n) > __attribute__((warn_unused_result)); > > +int rtnl_nexthopdump_req(struct rtnl_handle *rth, int family, > + req_filter_fn_t filter_fn) > + __attribute__((warn_unused_result)); > + > struct rtnl_ctrl_data { > int nsid; > }; > diff --git a/lib/libnetlink.c b/lib/libnetlink.c > index eb85bbdf01ee..c1cdda3b8d4e 100644 > --- a/lib/libnetlink.c > +++ b/lib/libnetlink.c > @@ -25,6 +25,7 @@ > #include <linux/fib_rules.h> > #include <linux/if_addrlabel.h> > #include <linux/if_bridge.h> > +#include <linux/nexthop.h> > > #include "libnetlink.h" > > @@ -252,6 +253,32 @@ int rtnl_open(struct rtnl_handle *rth, unsigned int subscriptions) > return rtnl_open_byproto(rth, subscriptions, NETLINK_ROUTE); > } > > +int rtnl_nexthopdump_req(struct rtnl_handle *rth, int family, > + req_filter_fn_t filter_fn) > +{ > + struct { > + struct nlmsghdr nlh; > + struct nhmsg nhm; > + char buf[128]; > + } req = { > + .nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)), sizeof(struct nhmsg) ? > + .nlh.nlmsg_type = RTM_GETNEXTHOP, > + .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, > + .nlh.nlmsg_seq = rth->dump = ++rth->seq, > + .nhm.nh_family = family, > + }; > + > + if (filter_fn) { > + int err; > + > + err = filter_fn(&req.nlh, sizeof(req)); > + if (err) > + return err; > + } > + > + return send(rth->fd, &req, sizeof(req), 0); > +} > + > int rtnl_addrdump_req(struct rtnl_handle *rth, int family, > req_filter_fn_t filter_fn) > { > -- > 2.11.0 >
On 5/30/19 1:56 PM, Roopa Prabhu wrote: >> diff --git a/lib/libnetlink.c b/lib/libnetlink.c >> index eb85bbdf01ee..c1cdda3b8d4e 100644 >> --- a/lib/libnetlink.c >> +++ b/lib/libnetlink.c >> @@ -25,6 +25,7 @@ >> #include <linux/fib_rules.h> >> #include <linux/if_addrlabel.h> >> #include <linux/if_bridge.h> >> +#include <linux/nexthop.h> >> >> #include "libnetlink.h" >> >> @@ -252,6 +253,32 @@ int rtnl_open(struct rtnl_handle *rth, unsigned int subscriptions) >> return rtnl_open_byproto(rth, subscriptions, NETLINK_ROUTE); >> } >> >> +int rtnl_nexthopdump_req(struct rtnl_handle *rth, int family, >> + req_filter_fn_t filter_fn) >> +{ >> + struct { >> + struct nlmsghdr nlh; >> + struct nhmsg nhm; >> + char buf[128]; >> + } req = { >> + .nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)), > > sizeof(struct nhmsg) ? > good catch. fixed.
diff --git a/include/libnetlink.h b/include/libnetlink.h index 599b2c592f68..1ddba8dcd220 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -93,6 +93,10 @@ int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int rtnl_dump_request_n(struct rtnl_handle *rth, struct nlmsghdr *n) __attribute__((warn_unused_result)); +int rtnl_nexthopdump_req(struct rtnl_handle *rth, int family, + req_filter_fn_t filter_fn) + __attribute__((warn_unused_result)); + struct rtnl_ctrl_data { int nsid; }; diff --git a/lib/libnetlink.c b/lib/libnetlink.c index eb85bbdf01ee..c1cdda3b8d4e 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -25,6 +25,7 @@ #include <linux/fib_rules.h> #include <linux/if_addrlabel.h> #include <linux/if_bridge.h> +#include <linux/nexthop.h> #include "libnetlink.h" @@ -252,6 +253,32 @@ int rtnl_open(struct rtnl_handle *rth, unsigned int subscriptions) return rtnl_open_byproto(rth, subscriptions, NETLINK_ROUTE); } +int rtnl_nexthopdump_req(struct rtnl_handle *rth, int family, + req_filter_fn_t filter_fn) +{ + struct { + struct nlmsghdr nlh; + struct nhmsg nhm; + char buf[128]; + } req = { + .nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)), + .nlh.nlmsg_type = RTM_GETNEXTHOP, + .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .nhm.nh_family = family, + }; + + if (filter_fn) { + int err; + + err = filter_fn(&req.nlh, sizeof(req)); + if (err) + return err; + } + + return send(rth->fd, &req, sizeof(req), 0); +} + int rtnl_addrdump_req(struct rtnl_handle *rth, int family, req_filter_fn_t filter_fn) {