netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Ahern <dsahern@kernel.org>
To: netdev@vger.kernel.org
Cc: idosch@mellanox.com, stephen@networkplumber.org,
	David Ahern <dsahern@gmail.com>
Subject: [PATCH iproute2-next 1/5] libnetlink: Add filter function to rtnl_neighdump_req
Date: Wed,  2 Jan 2019 20:38:28 -0800	[thread overview]
Message-ID: <20190103043832.3748-2-dsahern@kernel.org> (raw)
In-Reply-To: <20190103043832.3748-1-dsahern@kernel.org>

From: David Ahern <dsahern@gmail.com>

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 |  3 ++-
 lib/libnetlink.c     | 12 +++++++++++-
 misc/arpd.c          |  2 +-
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/include/libnetlink.h b/include/libnetlink.h
index dc0c9c4eb3f5..148951510d1e 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 4d7d081054fd..19318b445266 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 ce7c09978c2b..504961cb5e3a 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);
 	}
-- 
2.11.0

  reply	other threads:[~2019-01-03  4:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-03  4:38 [PATCH iproute2-next 0/5] ip bridge: Updates to neigh and fdb dumps David Ahern
2019-01-03  4:38 ` David Ahern [this message]
2019-01-03  4:38 ` [PATCH iproute2-next 2/5] ip neigh: Convert do_show_or_flush to use rtnl_neighdump_req David Ahern
2019-01-03  4:38 ` [PATCH iproute2-next 3/5] bridge: Update fdb show " David Ahern
2019-01-03  4:38 ` [PATCH iproute2-next 4/5] libnetlink: Add RTNL_HANDLE_F_STRICT_CHK flag David Ahern
2019-01-03  4:38 ` [PATCH iproute2-next 5/5] bridge: fdb: Fix filtering with strict checking disabled David Ahern
2019-01-04 13:45   ` Ido Schimmel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190103043832.3748-2-dsahern@kernel.org \
    --to=dsahern@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=idosch@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).