From: David Ahern Date: Mon, 31 Dec 2018 17:54:47 +0000 (-0800) Subject: libnetlink: Add filter function to rtnl_neighdump_req X-Git-Tag: v5.0.0~36^2~2^2~4 X-Git-Url: https://git.proxmox.com/?p=mirror_iproute2.git;a=commitdiff_plain;h=f255ab122537992e522abd29333084ca434b0a61 libnetlink: Add filter function to rtnl_neighdump_req Add filter function to rtnl_neighdump_req and a buffer to the request for the filter functions to append attributes. Signed-off-by: David Ahern --- diff --git a/include/libnetlink.h b/include/libnetlink.h index dc0c9c4e..14895151 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -60,7 +60,8 @@ int rtnl_routedump_req(struct rtnl_handle *rth, int family, __attribute__((warn_unused_result)); int rtnl_ruledump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); -int rtnl_neighdump_req(struct rtnl_handle *rth, int family) +int rtnl_neighdump_req(struct rtnl_handle *rth, int family, + req_filter_fn_t filter_fn) __attribute__((warn_unused_result)); int rtnl_neightbldump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); diff --git a/lib/libnetlink.c b/lib/libnetlink.c index 4d7d0810..19318b44 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -327,11 +327,13 @@ int rtnl_ruledump_req(struct rtnl_handle *rth, int family) return send(rth->fd, &req, sizeof(req), 0); } -int rtnl_neighdump_req(struct rtnl_handle *rth, int family) +int rtnl_neighdump_req(struct rtnl_handle *rth, int family, + req_filter_fn_t filter_fn) { struct { struct nlmsghdr nlh; struct ndmsg ndm; + char buf[256]; } req = { .nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)), .nlh.nlmsg_type = RTM_GETNEIGH, @@ -340,6 +342,14 @@ int rtnl_neighdump_req(struct rtnl_handle *rth, int family) .ndm.ndm_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); } diff --git a/misc/arpd.c b/misc/arpd.c index ce7c0997..504961cb 100644 --- a/misc/arpd.c +++ b/misc/arpd.c @@ -424,7 +424,7 @@ static int do_one_request(struct nlmsghdr *n) static void load_initial_table(void) { - if (rtnl_neighdump_req(&rth, AF_INET) < 0) { + if (rtnl_neighdump_req(&rth, AF_INET, NULL) < 0) { perror("dump request failed"); exit(1); }