Skip to contentSkip to conversation

bridge: mdb: Add support for new attributes

PATCH Applied Ido Schimmel 3 participants 14 messages Dec 15, 2022 – Dec 19, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover bridge: mdb: Add support for new attributes

Add support for new MDB attributes and replace command.

See kernel merge commit 8150f0cfb24f ("Merge branch 'bridge-mcast-extensions-for-evpn'") for background and motivation.

Patches #1-#2 are preparations.

Patches #3-#5 add support for new MDB attributes: Filter mode, source list and routing protocol.

Patch #6 adds replace support.

See individual commits for example output.

Ido Schimmel (6):
bridge: mdb: Use a boolean to indicate nest is required
bridge: mdb: Split source parsing to a separate function
bridge: mdb: Add filter mode support
bridge: mdb: Add source list support
bridge: mdb: Add routing protocol support
bridge: mdb: Add replace support

 bridge/mdb.c      | 149 ++++++++++++++++++++++++++++++++++++++++++----
 man/man8/bridge.8 |  40 +++++++++++--
 2 files changed, 172 insertions(+), 17 deletions(-)
Signature · 1 line
2.37.3
#1 lore raw

PATCH 1/6 bridge: mdb: Use a boolean to indicate nest is required

Currently, the only attribute inside the 'MDBA_SET_ENTRY_ATTRS' nest is 'MDBE_ATTR_SOURCE', but subsequent patches are going to add more attributes to the nest.

Prepare for the addition of these attributes by determining the necessity of the nest from a boolean variable that is set whenever one of these attributes is parsed. This avoids the need to have one long condition that checks for the presence of one of the individual attributes.

---
 bridge/mdb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
bridge/mdb.c +3 -1
index d3afc900e798..4ae91f15dac8 100644
@@ -488,6 +488,7 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
 	};
 	char *d = NULL, *p = NULL, *grp = NULL, *src = NULL;
 	struct br_mdb_entry entry = {};
+	bool set_attrs = false;
 	short vid = 0;
 
 	while (argc > 0) {
@@ -511,6 +512,7 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
 		} else if (strcmp(*argv, "src") == 0) {
 			NEXT_ARG();
 			src = *argv;
+			set_attrs = true;
 		} else {
 			if (matches(*argv, "help") == 0)
 				usage();
@@ -538,7 +540,7 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
 
 	entry.vid = vid;
 	addattr_l(&req.n, sizeof(req), MDBA_SET_ENTRY, &entry, sizeof(entry));
-	if (src) {
+	if (set_attrs) {
 		struct rtattr *nest = addattr_nest(&req.n, sizeof(req),
 						   MDBA_SET_ENTRY_ATTRS);
 		struct in6_addr src_ip6;
Signature · 1 line
2.37.3
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH iproute2-next 1/6] bridge: mdb: Use a boolean to indicate nest is required

Quoted 36 lines · Ido Schimmel

Currently, the only attribute inside the 'MDBA_SET_ENTRY_ATTRS' nest is 'MDBE_ATTR_SOURCE', but subsequent patches are going to add more attributes to the nest.

Prepare for the addition of these attributes by determining the necessity of the nest from a boolean variable that is set whenever one of these attributes is parsed. This avoids the need to have one long condition that checks for the presence of one of the individual attributes.

---
 bridge/mdb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
bridge/mdb.c +2 -0
index d3afc900e798..4ae91f15dac8 100644
@@ -488,6 +488,7 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
 	};
 	char *d = NULL, *p = NULL, *grp = NULL, *src = NULL;
 	struct br_mdb_entry entry = {};
+	bool set_attrs = false;
 	short vid = 0;
 
 	while (argc > 0) {
@@ -511,6 +512,7 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
 		} else if (strcmp(*argv, "src") == 0) {
 			NEXT_ARG();
 			src = *argv;
+			set_attrs = true;
 		} else {
 			if (matches(*argv, "help") == 0)
 				usage();

bridge/mdb.c static int mdb_modify(int cmd, int flags, int argc, char **argv) · line 546

Quoted 8 lines
bridge/mdb.c +1 -1
@@ -538,7 +540,7 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
 
 	entry.vid = vid;
 	addattr_l(&req.n, sizeof(req), MDBA_SET_ENTRY, &entry, sizeof(entry));
-	if (src) {
+	if (set_attrs) {
 		struct rtattr *nest = addattr_nest(&req.n, sizeof(req),
 						   MDBA_SET_ENTRY_ATTRS);
 		struct in6_addr src_ip6;
#3 lore raw

PATCH 2/6 bridge: mdb: Split source parsing to a separate function

In reply to Ido Schimmel

Currently, the only attribute inside the 'MDBA_SET_ENTRY_ATTRS' nest is 'MDBE_ATTR_SOURCE', but subsequent patches are going to add more attributes to the nest.

Prepare for the addition of these attributes by splitting the parsing of individual attributes inside the nest to separate functions.

---
 bridge/mdb.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)
bridge/mdb.c +24 -10
index 4ae91f15dac8..64db2ee03c42 100644
@@ -474,6 +474,25 @@ static int mdb_parse_grp(const char *grp, struct br_mdb_entry *e)
 	return -1;
 }
 
+static int mdb_parse_src(struct nlmsghdr *n, int maxlen, const char *src)
+{
+	struct in6_addr src_ip6;
+	__be32 src_ip4;
+
+	if (inet_pton(AF_INET, src, &src_ip4)) {
+		addattr32(n, maxlen, MDBE_ATTR_SOURCE, src_ip4);
+		return 0;
+	}
+
+	if (inet_pton(AF_INET6, src, &src_ip6)) {
+		addattr_l(n, maxlen, MDBE_ATTR_SOURCE, &src_ip6,
+			  sizeof(src_ip6));
+		return 0;
+	}
+
+	return -1;
+}
+
 static int mdb_modify(int cmd, int flags, int argc, char **argv)
 {
 	struct {
@@ -543,19 +562,14 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
 	if (set_attrs) {
 		struct rtattr *nest = addattr_nest(&req.n, sizeof(req),
 						   MDBA_SET_ENTRY_ATTRS);
-		struct in6_addr src_ip6;
-		__be32 src_ip4;
 
 		nest->rta_type |= NLA_F_NESTED;
-		if (!inet_pton(AF_INET, src, &src_ip4)) {
-			if (!inet_pton(AF_INET6, src, &src_ip6)) {
-				fprintf(stderr, "Invalid source address \"%s\"\n", src);
-				return -1;
-			}
-			addattr_l(&req.n, sizeof(req), MDBE_ATTR_SOURCE, &src_ip6, sizeof(src_ip6));
-		} else {
-			addattr32(&req.n, sizeof(req), MDBE_ATTR_SOURCE, src_ip4);
+
+		if (src && mdb_parse_src(&req.n, sizeof(req), src)) {
+			fprintf(stderr, "Invalid source address \"%s\"\n", src);
+			return -1;
 		}
+
 		addattr_nest_end(&req.n, nest);
 	}
 
Signature · 1 line
2.37.3
Reviewed-by on v1 2/6
#4 lore raw

Re: [PATCH iproute2-next 2/6] bridge: mdb: Split source parsing to a separate function

Quoted 4 lines · Ido Schimmel

Currently, the only attribute inside the 'MDBA_SET_ENTRY_ATTRS' nest is 'MDBE_ATTR_SOURCE', but subsequent patches are going to add more attributes to the nest.

Quoted 8 lines

Prepare for the addition of these attributes by splitting the parsing of individual attributes inside the nest to separate functions.

---
 bridge/mdb.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)
#5 lore raw

PATCH 3/6 bridge: mdb: Add filter mode support

In reply to Ido Schimmel

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.

---
 bridge/mdb.c      | 27 ++++++++++++++++++++++++++-
 man/man8/bridge.8 |  8 +++++++-
 2 files changed, 33 insertions(+), 2 deletions(-)
bridge/mdb.c +26 -1
index 64db2ee03c42..ceb8b25b37a5 100644
@@ -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);
 	}
 
man/man8/bridge.8 +7 -1
index e72826d750ca..e829b9cb592a 100644
@@ -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.
Signature · 1 line
2.37.3
Reviewed-by on v1 3/6
#6 lore raw

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

Quoted 9 lines · Ido Schimmel

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.

---
 bridge/mdb.c      | 27 ++++++++++++++++++++++++++-
 man/man8/bridge.8 |  8 +++++++-
 2 files changed, 33 insertions(+), 2 deletions(-)
#7 lore raw

PATCH 4/6 bridge: mdb: Add source list support

In reply to Ido Schimmel

Allow user space to specify the source list of (*, G) entries by adding the 'MDBE_ATTR_SRC_LIST' attribute to the 'MDBA_SET_ENTRY_ATTRS' nest.

Example:

 # bridge mdb add dev br0 port dummy10 grp 239.1.1.1 temp source_list 198.51.100.1,198.51.100.2 filter_mode exclude
 # bridge -d -s mdb show
 dev br0 port dummy10 grp 239.1.1.1 src 198.51.100.2 temp filter_mode include proto static  blocked    0.00
 dev br0 port dummy10 grp 239.1.1.1 src 198.51.100.1 temp filter_mode include proto static  blocked    0.00
 dev br0 port dummy10 grp 239.1.1.1 temp filter_mode exclude source_list 198.51.100.2/0.00,198.51.100.1/0.00 proto static   256.42
 # bridge -j -p -d -s mdb show
 [ {
         "mdb": [ {
                 "index": 10,
                 "dev": "br0",
                 "port": "dummy10",
                 "grp": "239.1.1.1",
                 "src": "198.51.100.2",
                 "state": "temp",
                 "filter_mode": "include",
                 "protocol": "static",
                 "flags": [ "blocked" ],
                 "timer": "   0.00"
             },{
                 "index": 10,
                 "dev": "br0",
                 "port": "dummy10",
                 "grp": "239.1.1.1",
                 "src": "198.51.100.1",
                 "state": "temp",
                 "filter_mode": "include",
                 "protocol": "static",
                 "flags": [ "blocked" ],
                 "timer": "   0.00"
             },{
             },{
                 "index": 10,
                 "dev": "br0",
                 "port": "dummy10",
                 "grp": "239.1.1.1",
                 "state": "temp",
                 "filter_mode": "exclude",
                 "source_list": [ {
                         "address": "198.51.100.2",
                         "timer": "0.00"
                     },{
                         "address": "198.51.100.1",
                         "timer": "0.00"
                     } ],
                 "protocol": "static",
                 "flags": [ ],
                 "timer": " 251.19"
             } ],
         "router": {}
     } ]
---
 bridge/mdb.c      | 58 ++++++++++++++++++++++++++++++++++++++++++++++-
 man/man8/bridge.8 | 11 ++++++++-
 2 files changed, 67 insertions(+), 2 deletions(-)
bridge/mdb.c +57 -1
index ceb8b25b37a5..58adf424bdcd 100644
@@ -32,7 +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"
+		"              [ filter_mode { include | exclude } ] [ source_list SOURCE_LIST ]\n"
 		"       bridge mdb {show} [ dev DEV ] [ vid VID ]\n");
 	exit(-1);
 }
@@ -509,6 +509,53 @@ static int mdb_parse_mode(struct nlmsghdr *n, int maxlen, const char *mode)
 	return -1;
 }
 
+static int mdb_parse_src_entry(struct nlmsghdr *n, int maxlen, char *src_entry)
+{
+	struct in6_addr src_ip6;
+	struct rtattr *nest;
+	__be32 src_ip4;
+
+	nest = addattr_nest(n, maxlen, MDBE_SRC_LIST_ENTRY | NLA_F_NESTED);
+
+	if (inet_pton(AF_INET, src_entry, &src_ip4))
+		addattr32(n, maxlen, MDBE_SRCATTR_ADDRESS, src_ip4);
+	else if (inet_pton(AF_INET6, src_entry, &src_ip6))
+		addattr_l(n, maxlen, MDBE_SRCATTR_ADDRESS, &src_ip6,
+			  sizeof(src_ip6));
+	else
+		return -1;
+
+	addattr_nest_end(n, nest);
+
+	return 0;
+}
+
+static int mdb_parse_src_list(struct nlmsghdr *n, int maxlen, char *src_list)
+{
+	struct rtattr *nest;
+	char *sep;
+
+	nest = addattr_nest(n, maxlen, MDBE_ATTR_SRC_LIST | NLA_F_NESTED);
+
+	do {
+		sep = strchr(src_list, ',');
+		if (sep)
+			*sep = '\0';
+
+		if (mdb_parse_src_entry(n, maxlen, src_list)) {
+			fprintf(stderr, "Invalid source entry \"%s\" in source list\n",
+				src_list);
+			return -1;
+		}
+
+		src_list = sep + 1;
+	} while (sep);
+
+	addattr_nest_end(n, nest);
+
+	return 0;
+}
+
 static int mdb_modify(int cmd, int flags, int argc, char **argv)
 {
 	struct {
@@ -524,6 +571,7 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
 	char *d = NULL, *p = NULL, *grp = NULL, *src = NULL, *mode = NULL;
 	struct br_mdb_entry entry = {};
 	bool set_attrs = false;
+	char *src_list = NULL;
 	short vid = 0;
 
 	while (argc > 0) {
@@ -552,6 +600,10 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
 			NEXT_ARG();
 			mode = *argv;
 			set_attrs = true;
+		} else if (strcmp(*argv, "source_list") == 0) {
+			NEXT_ARG();
+			src_list = *argv;
+			set_attrs = true;
 		} else {
 			if (matches(*argv, "help") == 0)
 				usage();
@@ -595,6 +647,10 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
 			return -1;
 		}
 
+		if (src_list && mdb_parse_src_list(&req.n, sizeof(req),
+						   src_list))
+			return -1;
+
 		addattr_nest_end(&req.n, nest);
 	}
 
man/man8/bridge.8 +10 -1
index e829b9cb592a..801bf70c0e43 100644
@@ -139,7 +139,9 @@ bridge \- show / manipulate bridge addresses and devices
 .BR permanent " | " temp " ] [ "
 .B vid
 .IR VID " ] [ "
-.BR filter_mode " { " include " | " exclude " } ] "
+.BR filter_mode " { " include " | " exclude " } ] [ "
+.B source_list
+.IR SOURCE_LIST " ]
 
 .ti -8
 .BR "bridge mdb show" " [ "
@@ -937,6 +939,13 @@ the VLAN ID which is known to have members of this multicast group.
 controls whether the sources in the entry's source list are in INCLUDE or
 EXCLUDE mode. Can only be set for (*, G) entries.
 
+.TP
+.BI source_list " SOURCE_LIST"
+optional list of source IP addresses of senders for this multicast group,
+separated by a ','.  Whether the entry forwards packets from these senders or
+not is determined by the entry's filter mode, which becomes a mandatory
+argument. 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.
Signature · 1 line
2.37.3
Reviewed-by on v1 4/6
#8 lore raw

Re: [PATCH iproute2-next 4/6] bridge: mdb: Add source list support

Quoted 58 lines · Ido Schimmel

Allow user space to specify the source list of (*, G) entries by adding the 'MDBE_ATTR_SRC_LIST' attribute to the 'MDBA_SET_ENTRY_ATTRS' nest.

Example:

 # bridge mdb add dev br0 port dummy10 grp 239.1.1.1 temp source_list 198.51.100.1,198.51.100.2 filter_mode exclude
 # bridge -d -s mdb show
 dev br0 port dummy10 grp 239.1.1.1 src 198.51.100.2 temp filter_mode include proto static  blocked    0.00
 dev br0 port dummy10 grp 239.1.1.1 src 198.51.100.1 temp filter_mode include proto static  blocked    0.00
 dev br0 port dummy10 grp 239.1.1.1 temp filter_mode exclude source_list 198.51.100.2/0.00,198.51.100.1/0.00 proto static   256.42
 # bridge -j -p -d -s mdb show
 [ {
         "mdb": [ {
                 "index": 10,
                 "dev": "br0",
                 "port": "dummy10",
                 "grp": "239.1.1.1",
                 "src": "198.51.100.2",
                 "state": "temp",
                 "filter_mode": "include",
                 "protocol": "static",
                 "flags": [ "blocked" ],
                 "timer": "   0.00"
             },{
                 "index": 10,
                 "dev": "br0",
                 "port": "dummy10",
                 "grp": "239.1.1.1",
                 "src": "198.51.100.1",
                 "state": "temp",
                 "filter_mode": "include",
                 "protocol": "static",
                 "flags": [ "blocked" ],
                 "timer": "   0.00"
             },{
             },{
                 "index": 10,
                 "dev": "br0",
                 "port": "dummy10",
                 "grp": "239.1.1.1",
                 "state": "temp",
                 "filter_mode": "exclude",
                 "source_list": [ {
                         "address": "198.51.100.2",
                         "timer": "0.00"
                     },{
                         "address": "198.51.100.1",
                         "timer": "0.00"
                     } ],
                 "protocol": "static",
                 "flags": [ ],
                 "timer": " 251.19"
             } ],
         "router": {}
     } ]
Quoted 6 lines
---
 bridge/mdb.c      | 58 ++++++++++++++++++++++++++++++++++++++++++++++-
 man/man8/bridge.8 | 11 ++++++++-
 2 files changed, 67 insertions(+), 2 deletions(-)
#9 lore raw

PATCH 5/6 bridge: mdb: Add routing protocol support

In reply to Ido Schimmel

Allow user space to specify the routing protocol of the MDB port group entry by adding the 'MDBE_ATTR_RTPROT' attribute to the 'MDBA_SET_ENTRY_ATTRS' nest.

Examples:

 # bridge mdb add dev br0 port dummy10 grp 239.1.1.1 permanent proto zebra
 # bridge mdb add dev br0 port dummy10 grp 239.1.1.2 permanent
 # bridge -d mdb show
 dev br0 port dummy10 grp 239.1.1.2 permanent filter_mode exclude proto static
 dev br0 port dummy10 grp 239.1.1.1 permanent filter_mode exclude proto zebra
---
 bridge/mdb.c      | 28 ++++++++++++++++++++++++++--
 man/man8/bridge.8 | 12 +++++++++++-
 2 files changed, 37 insertions(+), 3 deletions(-)
bridge/mdb.c +26 -2
index 58adf424bdcd..195a032c211b 100644
@@ -32,7 +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 } ] [ source_list SOURCE_LIST ]\n"
+		"              [ filter_mode { include | exclude } ] [ source_list SOURCE_LIST ] [ proto PROTO ]\n"
 		"       bridge mdb {show} [ dev DEV ] [ vid VID ]\n");
 	exit(-1);
 }
@@ -556,6 +556,20 @@ static int mdb_parse_src_list(struct nlmsghdr *n, int maxlen, char *src_list)
 	return 0;
 }
 
+static int mdb_parse_proto(struct nlmsghdr *n, int maxlen, const char *proto)
+{
+	__u32 proto_id;
+	int err;
+
+	err = rtnl_rtprot_a2n(&proto_id, proto);
+	if (err)
+		return err;
+
+	addattr8(n, maxlen, MDBE_ATTR_RTPROT, proto_id);
+
+	return 0;
+}
+
 static int mdb_modify(int cmd, int flags, int argc, char **argv)
 {
 	struct {
@@ -569,9 +583,9 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
 		.bpm.family = PF_BRIDGE,
 	};
 	char *d = NULL, *p = NULL, *grp = NULL, *src = NULL, *mode = NULL;
+	char *src_list = NULL, *proto = NULL;
 	struct br_mdb_entry entry = {};
 	bool set_attrs = false;
-	char *src_list = NULL;
 	short vid = 0;
 
 	while (argc > 0) {
@@ -604,6 +618,10 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
 			NEXT_ARG();
 			src_list = *argv;
 			set_attrs = true;
+		} else if (strcmp(*argv, "proto") == 0) {
+			NEXT_ARG();
+			proto = *argv;
+			set_attrs = true;
 		} else {
 			if (matches(*argv, "help") == 0)
 				usage();
@@ -651,6 +669,12 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
 						   src_list))
 			return -1;
 
+		if (proto && mdb_parse_proto(&req.n, sizeof(req), proto)) {
+			fprintf(stderr, "Invalid protocol value \"%s\"\n",
+				proto);
+			return -1;
+		}
+
 		addattr_nest_end(&req.n, nest);
 	}
 
man/man8/bridge.8 +11 -1
index 801bf70c0e43..3e6e928c895f 100644
@@ -141,7 +141,9 @@ bridge \- show / manipulate bridge addresses and devices
 .IR VID " ] [ "
 .BR filter_mode " { " include " | " exclude " } ] [ "
 .B source_list
-.IR SOURCE_LIST " ]
+.IR SOURCE_LIST " ] [ "
+.B proto
+.IR PROTO " ]
 
 .ti -8
 .BR "bridge mdb show" " [ "
@@ -946,6 +948,14 @@ separated by a ','.  Whether the entry forwards packets from these senders or
 not is determined by the entry's filter mode, which becomes a mandatory
 argument. Can only be set for (*, G) entries.
 
+.TP
+.BI proto " PROTO"
+the routing protocol identifier of this mdb entry. Can be a number or a string
+from the file /etc/iproute2/rt_protos. If the routing protocol is not given,
+then
+.B static
+is assumed.
+
 .in -8
 .SS bridge mdb delete - delete a multicast group database entry
 This command removes an existing mdb entry.
Signature · 1 line
2.37.3
Reviewed-by on v1 5/6
#10 lore raw

Re: [PATCH iproute2-next 5/6] bridge: mdb: Add routing protocol support

Quoted 14 lines · Ido Schimmel

Allow user space to specify the routing protocol of the MDB port group entry by adding the 'MDBE_ATTR_RTPROT' attribute to the 'MDBA_SET_ENTRY_ATTRS' nest.

Examples:

 # bridge mdb add dev br0 port dummy10 grp 239.1.1.1 permanent proto zebra
 # bridge mdb add dev br0 port dummy10 grp 239.1.1.2 permanent
 # bridge -d mdb show
 dev br0 port dummy10 grp 239.1.1.2 permanent filter_mode exclude proto static
 dev br0 port dummy10 grp 239.1.1.1 permanent filter_mode exclude proto zebra
Quoted 6 lines
---
 bridge/mdb.c      | 28 ++++++++++++++++++++++++++--
 man/man8/bridge.8 | 12 +++++++++++-
 2 files changed, 37 insertions(+), 3 deletions(-)
#11 lore raw

PATCH 6/6 bridge: mdb: Add replace support

In reply to Ido Schimmel

Allow user space to replace MDB port group entries by specifying the 'NLM_F_REPLACE' flag in the netlink message header.

Examples:

 # bridge mdb replace dev br0 port dummy10 grp 239.1.1.1 permanent source_list 192.0.2.1,192.0.2.2 filter_mode include
 # bridge -d -s mdb show
 dev br0 port dummy10 grp 239.1.1.1 src 192.0.2.2 permanent filter_mode include proto static     0.00
 dev br0 port dummy10 grp 239.1.1.1 src 192.0.2.1 permanent filter_mode include proto static     0.00
 dev br0 port dummy10 grp 239.1.1.1 permanent filter_mode include source_list 192.0.2.2/0.00,192.0.2.1/0.00 proto static     0.00
 # bridge mdb replace dev br0 port dummy10 grp 239.1.1.1 permanent source_list 192.0.2.1,192.0.2.3 filter_mode exclude proto zebra
 # bridge -d -s mdb show
 dev br0 port dummy10 grp 239.1.1.1 src 192.0.2.3 permanent filter_mode include proto zebra  blocked    0.00
 dev br0 port dummy10 grp 239.1.1.1 src 192.0.2.1 permanent filter_mode include proto zebra  blocked    0.00
 dev br0 port dummy10 grp 239.1.1.1 permanent filter_mode exclude source_list 192.0.2.3/0.00,192.0.2.1/0.00 proto zebra     0.00
 # bridge mdb replace dev br0 port dummy10 grp 239.1.1.1 temp source_list 192.0.2.4,192.0.2.3 filter_mode include proto bgp
 # bridge -d -s mdb show
 dev br0 port dummy10 grp 239.1.1.1 src 192.0.2.4 temp filter_mode include proto bgp     0.00
 dev br0 port dummy10 grp 239.1.1.1 src 192.0.2.3 temp filter_mode include proto bgp     0.00
 dev br0 port dummy10 grp 239.1.1.1 temp filter_mode include source_list 192.0.2.4/259.44,192.0.2.3/259.44 proto bgp     0.00
---
 bridge/mdb.c      |  4 +++-
 man/man8/bridge.8 | 13 ++++++++++---
 2 files changed, 13 insertions(+), 4 deletions(-)
bridge/mdb.c +3 -1
index 195a032c211b..f323cd091fcc 100644
@@ -31,7 +31,7 @@ static unsigned int filter_index, filter_vlan;
 static void usage(void)
 {
 	fprintf(stderr,
-		"Usage: bridge mdb { add | del } dev DEV port PORT grp GROUP [src SOURCE] [permanent | temp] [vid VID]\n"
+		"Usage: bridge mdb { add | del | replace } dev DEV port PORT grp GROUP [src SOURCE] [permanent | temp] [vid VID]\n"
 		"              [ filter_mode { include | exclude } ] [ source_list SOURCE_LIST ] [ proto PROTO ]\n"
 		"       bridge mdb {show} [ dev DEV ] [ vid VID ]\n");
 	exit(-1);
@@ -692,6 +692,8 @@ int do_mdb(int argc, char **argv)
 	if (argc > 0) {
 		if (matches(*argv, "add") == 0)
 			return mdb_modify(RTM_NEWMDB, NLM_F_CREATE|NLM_F_EXCL, argc-1, argv+1);
+		if (strcmp(*argv, "replace") == 0)
+			return mdb_modify(RTM_NEWMDB, NLM_F_CREATE|NLM_F_REPLACE, argc-1, argv+1);
 		if (matches(*argv, "delete") == 0)
 			return mdb_modify(RTM_DELMDB, 0, argc-1, argv+1);
 
man/man8/bridge.8 +10 -3
index 3e6e928c895f..f73e538a3536 100644
@@ -127,7 +127,7 @@ bridge \- show / manipulate bridge addresses and devices
 .BR [no]sticky " ] [ " [no]offloaded " ]"
 
 .ti -8
-.BR "bridge mdb" " { " add " | " del " } "
+.BR "bridge mdb" " { " add " | " del " | " replace " } "
 .B dev
 .I DEV
 .B port
@@ -898,8 +898,8 @@ if "no" is prepended then only entries without offloaded flag will be deleted.
 objects contain known IP or L2 multicast group addresses on a link.
 
 .P
-The corresponding commands display mdb entries, add new entries,
-and delete old ones.
+The corresponding commands display mdb entries, add new entries, replace
+entries and delete old ones.
 
 .SS bridge mdb add - add a new multicast group database entry
 
@@ -964,6 +964,13 @@ This command removes an existing mdb entry.
 The arguments are the same as with
 .BR "bridge mdb add" .
 
+.SS bridge mdb replace - replace a multicast group database entry
+If no matching entry is found, a new one will be created instead.
+
+.PP
+The arguments are the same as with
+.BR "bridge mdb add" .
+
 .SS bridge mdb show - list multicast group database entries
 
 This command displays the current multicast group membership table. The table
Signature · 1 line
2.37.3
Reviewed-by on v1 6/6
#12 lore raw

Re: [PATCH iproute2-next 6/6] bridge: mdb: Add replace support

Quoted 23 lines · Ido Schimmel

Allow user space to replace MDB port group entries by specifying the 'NLM_F_REPLACE' flag in the netlink message header.

Examples:

 # bridge mdb replace dev br0 port dummy10 grp 239.1.1.1 permanent source_list 192.0.2.1,192.0.2.2 filter_mode include
 # bridge -d -s mdb show
 dev br0 port dummy10 grp 239.1.1.1 src 192.0.2.2 permanent filter_mode include proto static     0.00
 dev br0 port dummy10 grp 239.1.1.1 src 192.0.2.1 permanent filter_mode include proto static     0.00
 dev br0 port dummy10 grp 239.1.1.1 permanent filter_mode include source_list 192.0.2.2/0.00,192.0.2.1/0.00 proto static     0.00
 # bridge mdb replace dev br0 port dummy10 grp 239.1.1.1 permanent source_list 192.0.2.1,192.0.2.3 filter_mode exclude proto zebra
 # bridge -d -s mdb show
 dev br0 port dummy10 grp 239.1.1.1 src 192.0.2.3 permanent filter_mode include proto zebra  blocked    0.00
 dev br0 port dummy10 grp 239.1.1.1 src 192.0.2.1 permanent filter_mode include proto zebra  blocked    0.00
 dev br0 port dummy10 grp 239.1.1.1 permanent filter_mode exclude source_list 192.0.2.3/0.00,192.0.2.1/0.00 proto zebra     0.00
 # bridge mdb replace dev br0 port dummy10 grp 239.1.1.1 temp source_list 192.0.2.4,192.0.2.3 filter_mode include proto bgp
 # bridge -d -s mdb show
 dev br0 port dummy10 grp 239.1.1.1 src 192.0.2.4 temp filter_mode include proto bgp     0.00
 dev br0 port dummy10 grp 239.1.1.1 src 192.0.2.3 temp filter_mode include proto bgp     0.00
 dev br0 port dummy10 grp 239.1.1.1 temp filter_mode include source_list 192.0.2.4/259.44,192.0.2.3/259.44 proto bgp     0.00
Quoted 6 lines
---
 bridge/mdb.c      |  4 +++-
 man/man8/bridge.8 | 13 ++++++++++---
 2 files changed, 13 insertions(+), 4 deletions(-)
#13 lore raw
In reply to Ido Schimmel
This series was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:

Hello:

This series was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:

Quoted 8 lines · On Thu, 15 Dec 2022 19:52:24 +0200 you wrote:

Add support for new MDB attributes and replace command.

See kernel merge commit 8150f0cfb24f ("Merge branch 'bridge-mcast-extensions-for-evpn'") for background and motivation.

Patches #1-#2 are preparations.

[...]

Here is the summary with links:
- [iproute2-next,1/6] bridge: mdb: Use a boolean to indicate nest is required

    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=935d942e6939
  - [iproute2-next,2/6] bridge: mdb: Split source parsing to a separate function
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=c305c76a01e1
  - [iproute2-next,3/6] bridge: mdb: Add filter mode support
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=7fe47f5160d3
  - [iproute2-next,4/6] bridge: mdb: Add source list support
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=aa9a0b0fa9c2
  - [iproute2-next,5/6] bridge: mdb: Add routing protocol support
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=7921c336dba4

- [iproute2-next,6/6] bridge: mdb: Add replace support
https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=9edecafda31e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html