diff mbox series

[iproute2-next,3/6] bridge: mdb: Add filter mode support

Message ID 20221215175230.1907938-4-idosch@nvidia.com (mailing list archive)
State Accepted
Commit 7fe47f5160d334c6827f891aee4b9fd9ad7482c3
Delegated to: David Ahern
Headers show
Series bridge: mdb: Add support for new attributes | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Ido Schimmel Dec. 15, 2022, 5:52 p.m. UTC
Allow user space to specify the filter mode of (*, G) entries by adding
the 'MDBE_ATTR_GROUP_MODE' attribute to the 'MDBA_SET_ENTRY_ATTRS' nest.

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
 bridge/mdb.c      | 27 ++++++++++++++++++++++++++-
 man/man8/bridge.8 |  8 +++++++-
 2 files changed, 33 insertions(+), 2 deletions(-)

Comments

Nikolay Aleksandrov Dec. 16, 2022, noon UTC | #1
On 15/12/2022 19:52, Ido Schimmel wrote:
> Allow user space to specify the filter mode of (*, G) entries by adding
> the 'MDBE_ATTR_GROUP_MODE' attribute to the 'MDBA_SET_ENTRY_ATTRS' nest.
> 
> Signed-off-by: Ido Schimmel <idosch@nvidia.com>
> ---
>  bridge/mdb.c      | 27 ++++++++++++++++++++++++++-
>  man/man8/bridge.8 |  8 +++++++-
>  2 files changed, 33 insertions(+), 2 deletions(-)
> 

Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
diff mbox series

Patch

diff --git a/bridge/mdb.c b/bridge/mdb.c
index 64db2ee03c42..ceb8b25b37a5 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -32,6 +32,7 @@  static void usage(void)
 {
 	fprintf(stderr,
 		"Usage: bridge mdb { add | del } dev DEV port PORT grp GROUP [src SOURCE] [permanent | temp] [vid VID]\n"
+		"              [ filter_mode { include | exclude } ]\n"
 		"       bridge mdb {show} [ dev DEV ] [ vid VID ]\n");
 	exit(-1);
 }
@@ -493,6 +494,21 @@  static int mdb_parse_src(struct nlmsghdr *n, int maxlen, const char *src)
 	return -1;
 }
 
+static int mdb_parse_mode(struct nlmsghdr *n, int maxlen, const char *mode)
+{
+	if (strcmp(mode, "include") == 0) {
+		addattr8(n, maxlen, MDBE_ATTR_GROUP_MODE, MCAST_INCLUDE);
+		return 0;
+	}
+
+	if (strcmp(mode, "exclude") == 0) {
+		addattr8(n, maxlen, MDBE_ATTR_GROUP_MODE, MCAST_EXCLUDE);
+		return 0;
+	}
+
+	return -1;
+}
+
 static int mdb_modify(int cmd, int flags, int argc, char **argv)
 {
 	struct {
@@ -505,7 +521,7 @@  static int mdb_modify(int cmd, int flags, int argc, char **argv)
 		.n.nlmsg_type = cmd,
 		.bpm.family = PF_BRIDGE,
 	};
-	char *d = NULL, *p = NULL, *grp = NULL, *src = NULL;
+	char *d = NULL, *p = NULL, *grp = NULL, *src = NULL, *mode = NULL;
 	struct br_mdb_entry entry = {};
 	bool set_attrs = false;
 	short vid = 0;
@@ -532,6 +548,10 @@  static int mdb_modify(int cmd, int flags, int argc, char **argv)
 			NEXT_ARG();
 			src = *argv;
 			set_attrs = true;
+		} else if (strcmp(*argv, "filter_mode") == 0) {
+			NEXT_ARG();
+			mode = *argv;
+			set_attrs = true;
 		} else {
 			if (matches(*argv, "help") == 0)
 				usage();
@@ -570,6 +590,11 @@  static int mdb_modify(int cmd, int flags, int argc, char **argv)
 			return -1;
 		}
 
+		if (mode && mdb_parse_mode(&req.n, sizeof(req), mode)) {
+			fprintf(stderr, "Invalid filter mode \"%s\"\n", mode);
+			return -1;
+		}
+
 		addattr_nest_end(&req.n, nest);
 	}
 
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index e72826d750ca..e829b9cb592a 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -138,7 +138,8 @@  bridge \- show / manipulate bridge addresses and devices
 .IR SOURCE " ] [ "
 .BR permanent " | " temp " ] [ "
 .B vid
-.IR VID " ] "
+.IR VID " ] [ "
+.BR filter_mode " { " include " | " exclude " } ] "
 
 .ti -8
 .BR "bridge mdb show" " [ "
@@ -931,6 +932,11 @@  forwarding multicast traffic.
 .BI vid " VID"
 the VLAN ID which is known to have members of this multicast group.
 
+.TP
+.BR "filter_mode include " or " filter_mode exclude "
+controls whether the sources in the entry's source list are in INCLUDE or
+EXCLUDE mode. Can only be set for (*, G) entries.
+
 .in -8
 .SS bridge mdb delete - delete a multicast group database entry
 This command removes an existing mdb entry.