All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ido Schimmel <idosch@nvidia.com>
To: netdev@vger.kernel.org
Cc: dsahern@gmail.com, stephen@networkplumber.org,
	razor@blackwall.org, mlxsw@nvidia.com,
	Ido Schimmel <idosch@nvidia.com>
Subject: [PATCH iproute2-next 4/6] bridge: mdb: Add source list support
Date: Thu, 15 Dec 2022 19:52:28 +0200	[thread overview]
Message-ID: <20221215175230.1907938-5-idosch@nvidia.com> (raw)
In-Reply-To: <20221215175230.1907938-1-idosch@nvidia.com>

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": {}
     } ]

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

diff --git a/bridge/mdb.c b/bridge/mdb.c
index ceb8b25b37a5..58adf424bdcd 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -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);
 	}
 
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index e829b9cb592a..801bf70c0e43 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -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.
-- 
2.37.3


  parent reply	other threads:[~2022-12-15 17:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-15 17:52 [PATCH iproute2-next 0/6] bridge: mdb: Add support for new attributes Ido Schimmel
2022-12-15 17:52 ` [PATCH iproute2-next 1/6] bridge: mdb: Use a boolean to indicate nest is required Ido Schimmel
2022-12-16 11:59   ` Nikolay Aleksandrov
2022-12-15 17:52 ` [PATCH iproute2-next 2/6] bridge: mdb: Split source parsing to a separate function Ido Schimmel
2022-12-16 11:59   ` Nikolay Aleksandrov
2022-12-15 17:52 ` [PATCH iproute2-next 3/6] bridge: mdb: Add filter mode support Ido Schimmel
2022-12-16 12:00   ` Nikolay Aleksandrov
2022-12-15 17:52 ` Ido Schimmel [this message]
2022-12-16 12:05   ` [PATCH iproute2-next 4/6] bridge: mdb: Add source list support Nikolay Aleksandrov
2022-12-15 17:52 ` [PATCH iproute2-next 5/6] bridge: mdb: Add routing protocol support Ido Schimmel
2022-12-16 12:06   ` Nikolay Aleksandrov
2022-12-15 17:52 ` [PATCH iproute2-next 6/6] bridge: mdb: Add replace support Ido Schimmel
2022-12-16 12:06   ` Nikolay Aleksandrov
2022-12-19  1:50 ` [PATCH iproute2-next 0/6] bridge: mdb: Add support for new attributes patchwork-bot+netdevbpf

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=20221215175230.1907938-5-idosch@nvidia.com \
    --to=idosch@nvidia.com \
    --cc=dsahern@gmail.com \
    --cc=mlxsw@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=razor@blackwall.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.