]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
libnetlink: Add filter function to rtnl_neighdump_req
authorDavid Ahern <dsahern@gmail.com>
Mon, 31 Dec 2018 17:54:47 +0000 (09:54 -0800)
committerDavid Ahern <dsahern@gmail.com>
Fri, 4 Jan 2019 20:17:11 +0000 (12:17 -0800)
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 <dsahern@gmail.com>
include/libnetlink.h
lib/libnetlink.c
misc/arpd.c

index dc0c9c4eb3f5218c33263dbd1bb1962125c1b533..148951510d1e5cb1f9437b662e7e86ce5c4b8e44 100644 (file)
@@ -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));
index 4d7d081054fd324c8b92c8bf141b89ab8393db6c..19318b445266d8aa4060ad5b6ca8304932d531d2 100644 (file)
@@ -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);
 }
 
index ce7c09978c2b7b96aeec442f639cad153fb72a51..504961cb5e3a0e15f54132d881bd2829bac96912 100644 (file)
@@ -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);
        }