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 3/5] bridge: Update fdb show to use rtnl_neighdump_req
Date: Wed,  2 Jan 2019 20:38:30 -0800	[thread overview]
Message-ID: <20190103043832.3748-4-dsahern@kernel.org> (raw)
In-Reply-To: <20190103043832.3748-1-dsahern@kernel.org>

From: David Ahern <dsahern@gmail.com>

Add fdb_dump_filter to set filter attributes in dump request
and convert fdb_show to use rtnl_neighdump_req.

Signed-off-by: David Ahern <dsahern@gmail.com>
---
 bridge/fdb.c | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/bridge/fdb.c b/bridge/fdb.c
index a7a0d8052307..676267e15ddc 100644
--- a/bridge/fdb.c
+++ b/bridge/fdb.c
@@ -30,7 +30,7 @@
 #include "rt_names.h"
 #include "utils.h"
 
-static unsigned int filter_index, filter_vlan, filter_state;
+static unsigned int filter_index, filter_vlan, filter_state, filter_master;
 
 static void usage(void)
 {
@@ -256,20 +256,29 @@ int print_fdb(struct nlmsghdr *n, void *arg)
 	return 0;
 }
 
-static int fdb_show(int argc, char **argv)
+static int fdb_dump_filter(struct nlmsghdr *nlh, int reqlen)
 {
-	struct {
-		struct nlmsghdr	n;
-		struct ndmsg		ndm;
-		char			buf[256];
-	} req = {
-		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)),
-		.ndm.ndm_family = PF_BRIDGE,
-	};
+	int err;
+
+	if (filter_index) {
+		struct ndmsg *ndm = NLMSG_DATA(nlh);
 
+		ndm->ndm_ifindex = filter_index;
+	}
+
+	if (filter_master) {
+		err = addattr32(nlh, reqlen, NDA_MASTER, filter_master);
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
+static int fdb_show(int argc, char **argv)
+{
 	char *filter_dev = NULL;
 	char *br = NULL;
-	int msg_size = sizeof(struct ndmsg);
 
 	while (argc > 0) {
 		if ((strcmp(*argv, "brport") == 0) || strcmp(*argv, "dev") == 0) {
@@ -304,8 +313,7 @@ static int fdb_show(int argc, char **argv)
 			fprintf(stderr, "Cannot find bridge device \"%s\"\n", br);
 			return -1;
 		}
-		addattr32(&req.n, sizeof(req), IFLA_MASTER, br_ifindex);
-		msg_size += RTA_LENGTH(4);
+		filter_master = br_ifindex;
 	}
 
 	/*we'll keep around filter_dev for older kernels */
@@ -313,10 +321,9 @@ static int fdb_show(int argc, char **argv)
 		filter_index = ll_name_to_index(filter_dev);
 		if (!filter_index)
 			return nodev(filter_dev);
-		req.ndm.ndm_ifindex = filter_index;
 	}
 
-	if (rtnl_dump_request(&rth, RTM_GETNEIGH, &req.ndm, msg_size) < 0) {
+	if (rtnl_neighdump_req(&rth, PF_BRIDGE, fdb_dump_filter) < 0) {
 		perror("Cannot send dump request");
 		exit(1);
 	}
-- 
2.11.0

  parent 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 ` [PATCH iproute2-next 1/5] libnetlink: Add filter function to rtnl_neighdump_req David Ahern
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 ` David Ahern [this message]
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-4-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).