diff mbox series

[iproute2-next,5/5] bridge: fdb: Fix filtering with strict checking disabled

Message ID 20190103043832.3748-6-dsahern@kernel.org
State Accepted
Delegated to: David Ahern
Headers show
Series ip bridge: Updates to neigh and fdb dumps | expand

Commit Message

David Ahern Jan. 3, 2019, 4:38 a.m. UTC
From: David Ahern <dsahern@gmail.com>

Older kernels expect an ifinfomsg struct as the ancillary header, and
after kernel commit bd961c9bc664 ("rtnetlink: fix rtnl_fdb_dump() for ndmsg
header") can handle either ifinfomsg or ndmsg. Strict data checking only
allows ndmsg.

Use the new RTNL_HANDLE_F_STRICT_CHK flag to know which header to send.

Signed-off-by: David Ahern <dsahern@gmail.com>
---
 bridge/fdb.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

Comments

Ido Schimmel Jan. 4, 2019, 1:45 p.m. UTC | #1
On Wed, Jan 02, 2019 at 08:38:32PM -0800, David Ahern wrote:
> From: David Ahern <dsahern@gmail.com>
> 
> Older kernels expect an ifinfomsg struct as the ancillary header, and
> after kernel commit bd961c9bc664 ("rtnetlink: fix rtnl_fdb_dump() for ndmsg
> header") can handle either ifinfomsg or ndmsg. Strict data checking only
> allows ndmsg.
> 
> Use the new RTNL_HANDLE_F_STRICT_CHK flag to know which header to send.
> 
> Signed-off-by: David Ahern <dsahern@gmail.com>

Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Tested-by: Ido Schimmel <idosch@mellanox.com>

Thanks!
diff mbox series

Patch

diff --git a/bridge/fdb.c b/bridge/fdb.c
index 676267e15ddc..a0fdac00e094 100644
--- a/bridge/fdb.c
+++ b/bridge/fdb.c
@@ -256,6 +256,25 @@  int print_fdb(struct nlmsghdr *n, void *arg)
 	return 0;
 }
 
+static int fdb_linkdump_filter(struct nlmsghdr *nlh, int reqlen)
+{
+	int err;
+
+	if (filter_index) {
+		struct ifinfomsg *ifm = NLMSG_DATA(nlh);
+
+		ifm->ifi_index = filter_index;
+	}
+
+	if (filter_master) {
+		err = addattr32(nlh, reqlen, IFLA_MASTER, filter_master);
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
 static int fdb_dump_filter(struct nlmsghdr *nlh, int reqlen)
 {
 	int err;
@@ -279,6 +298,7 @@  static int fdb_show(int argc, char **argv)
 {
 	char *filter_dev = NULL;
 	char *br = NULL;
+	int rc;
 
 	while (argc > 0) {
 		if ((strcmp(*argv, "brport") == 0) || strcmp(*argv, "dev") == 0) {
@@ -323,7 +343,12 @@  static int fdb_show(int argc, char **argv)
 			return nodev(filter_dev);
 	}
 
-	if (rtnl_neighdump_req(&rth, PF_BRIDGE, fdb_dump_filter) < 0) {
+	if (rth.flags & RTNL_HANDLE_F_STRICT_CHK)
+		rc = rtnl_neighdump_req(&rth, PF_BRIDGE, fdb_dump_filter);
+	else
+		rc = rtnl_linkdump_req_filter_fn(&rth, PF_BRIDGE,
+						 fdb_linkdump_filter);
+	if (rc < 0) {
 		perror("Cannot send dump request");
 		exit(1);
 	}