diff mbox series

[iproute2-next,2/7] bridge: mdb: Add underlay destination IP support

Message ID 20230321130127.264822-3-idosch@nvidia.com (mailing list archive)
State Accepted
Commit d36899c2244ccf61cf74180fc644d50f9230e773
Delegated to: David Ahern
Headers show
Series bridge: mdb: Add VXLAN attributes support | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Ido Schimmel March 21, 2023, 1:01 p.m. UTC
Allow user space to program and view VXLAN MDB entries. Specifically,
add support for the 'MDBE_ATTR_DST' and 'MDBA_MDB_EATTR_DST' attributes
in request and response messages, respectively.

The attributes encode the IP address of the destination VXLAN tunnel
endpoint where multicast receivers for the specified multicast flow
reside.

Multiple destinations can be added for each flow.

Example:

 # bridge mdb add dev vxlan0 port vxlan0 grp 239.1.1.1 permanent dst 198.51.100.1
 # bridge mdb add dev vxlan0 port vxlan0 grp 239.1.1.1 permanent dst 192.0.2.1

 $ bridge -d -s mdb show
 dev vxlan0 port vxlan0 grp 239.1.1.1 permanent filter_mode exclude proto static dst 192.0.2.1    0.00
 dev vxlan0 port vxlan0 grp 239.1.1.1 permanent filter_mode exclude proto static dst 198.51.100.1    0.00

 $ bridge -d -s -j -p mdb show
 [ {
         "mdb": [ {
                 "index": 15,
                 "dev": "vxlan0",
                 "port": "vxlan0",
                 "grp": "239.1.1.1",
                 "state": "permanent",
                 "filter_mode": "exclude",
                 "protocol": "static",
                 "flags": [ ],
                 "dst": "192.0.2.1",
                 "timer": "   0.00"
             },{
                 "index": 15,
                 "dev": "vxlan0",
                 "port": "vxlan0",
                 "grp": "239.1.1.1",
                 "state": "permanent",
                 "filter_mode": "exclude",
                 "protocol": "static",
                 "flags": [ ],
                 "dst": "198.51.100.1",
                 "timer": "   0.00"
             } ],
         "router": {}
     } ]

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

Comments

Nikolay Aleksandrov March 23, 2023, 3:17 p.m. UTC | #1
On 21/03/2023 15:01, Ido Schimmel wrote:
> Allow user space to program and view VXLAN MDB entries. Specifically,
> add support for the 'MDBE_ATTR_DST' and 'MDBA_MDB_EATTR_DST' attributes
> in request and response messages, respectively.
> 
> The attributes encode the IP address of the destination VXLAN tunnel
> endpoint where multicast receivers for the specified multicast flow
> reside.
> 
> Multiple destinations can be added for each flow.
> 
> Example:
> 
>  # bridge mdb add dev vxlan0 port vxlan0 grp 239.1.1.1 permanent dst 198.51.100.1
>  # bridge mdb add dev vxlan0 port vxlan0 grp 239.1.1.1 permanent dst 192.0.2.1
> 
>  $ bridge -d -s mdb show
>  dev vxlan0 port vxlan0 grp 239.1.1.1 permanent filter_mode exclude proto static dst 192.0.2.1    0.00
>  dev vxlan0 port vxlan0 grp 239.1.1.1 permanent filter_mode exclude proto static dst 198.51.100.1    0.00
> 
>  $ bridge -d -s -j -p mdb show
>  [ {
>          "mdb": [ {
>                  "index": 15,
>                  "dev": "vxlan0",
>                  "port": "vxlan0",
>                  "grp": "239.1.1.1",
>                  "state": "permanent",
>                  "filter_mode": "exclude",
>                  "protocol": "static",
>                  "flags": [ ],
>                  "dst": "192.0.2.1",
>                  "timer": "   0.00"
>              },{
>                  "index": 15,
>                  "dev": "vxlan0",
>                  "port": "vxlan0",
>                  "grp": "239.1.1.1",
>                  "state": "permanent",
>                  "filter_mode": "exclude",
>                  "protocol": "static",
>                  "flags": [ ],
>                  "dst": "198.51.100.1",
>                  "timer": "   0.00"
>              } ],
>          "router": {}
>      } ]
> 
> Signed-off-by: Ido Schimmel <idosch@nvidia.com>
> ---
>  bridge/mdb.c      | 51 +++++++++++++++++++++++++++++++++++++++++++++--
>  man/man8/bridge.8 | 15 +++++++++++++-
>  2 files changed, 63 insertions(+), 3 deletions(-)
> 

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

Patch

diff --git a/bridge/mdb.c b/bridge/mdb.c
index 9b5503657178..137d509ce764 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -32,7 +32,7 @@  static void usage(void)
 {
 	fprintf(stderr,
 		"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"
+		"              [ filter_mode { include | exclude } ] [ source_list SOURCE_LIST ] [ proto PROTO ] [ dst IPADDR ]\n"
 		"       bridge mdb {show} [ dev DEV ] [ vid VID ]\n");
 	exit(-1);
 }
@@ -146,6 +146,21 @@  static void print_src_entry(struct rtattr *src_attr, int af, const char *sep)
 	close_json_object();
 }
 
+static void print_dst(const struct rtattr *dst_attr)
+{
+	SPRINT_BUF(abuf);
+	int af = AF_INET;
+	const void *dst;
+
+	if (RTA_PAYLOAD(dst_attr) == sizeof(struct in6_addr))
+		af = AF_INET6;
+
+	dst = (const void *)RTA_DATA(dst_attr);
+	print_color_string(PRINT_ANY, ifa_family_color(af),
+			   "dst", " dst %s",
+			   inet_ntop(af, dst, abuf, sizeof(abuf)));
+}
+
 static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e,
 			    struct nlmsghdr *n, struct rtattr **tb)
 {
@@ -240,6 +255,9 @@  static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e,
 	if (e->vid)
 		print_uint(PRINT_ANY, "vid", " vid %u", e->vid);
 
+	if (tb[MDBA_MDB_EATTR_DST])
+		print_dst(tb[MDBA_MDB_EATTR_DST]);
+
 	if (show_stats && tb && tb[MDBA_MDB_EATTR_TIMER]) {
 		__u32 timer = rta_getattr_u32(tb[MDBA_MDB_EATTR_TIMER]);
 
@@ -570,6 +588,25 @@  static int mdb_parse_proto(struct nlmsghdr *n, int maxlen, const char *proto)
 	return 0;
 }
 
+static int mdb_parse_dst(struct nlmsghdr *n, int maxlen, const char *dst)
+{
+	struct in6_addr dst_ip6;
+	__be32 dst_ip4;
+
+	if (inet_pton(AF_INET, dst, &dst_ip4)) {
+		addattr32(n, maxlen, MDBE_ATTR_DST, dst_ip4);
+		return 0;
+	}
+
+	if (inet_pton(AF_INET6, dst, &dst_ip6)) {
+		addattr_l(n, maxlen, MDBE_ATTR_DST, &dst_ip6,
+			  sizeof(dst_ip6));
+		return 0;
+	}
+
+	return -1;
+}
+
 static int mdb_modify(int cmd, int flags, int argc, char **argv)
 {
 	struct {
@@ -583,7 +620,7 @@  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;
+	char *src_list = NULL, *proto = NULL, *dst = NULL;
 	struct br_mdb_entry entry = {};
 	bool set_attrs = false;
 	short vid = 0;
@@ -622,6 +659,10 @@  static int mdb_modify(int cmd, int flags, int argc, char **argv)
 			NEXT_ARG();
 			proto = *argv;
 			set_attrs = true;
+		} else if (strcmp(*argv, "dst") == 0) {
+			NEXT_ARG();
+			dst = *argv;
+			set_attrs = true;
 		} else {
 			if (matches(*argv, "help") == 0)
 				usage();
@@ -675,6 +716,12 @@  static int mdb_modify(int cmd, int flags, int argc, char **argv)
 			return -1;
 		}
 
+		if (dst && mdb_parse_dst(&req.n, sizeof(req), dst)) {
+			fprintf(stderr, "Invalid underlay destination address \"%s\"\n",
+				dst);
+			return -1;
+		}
+
 		addattr_nest_end(&req.n, nest);
 	}
 
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index abc0417b2057..2f8500af1f02 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -145,7 +145,9 @@  bridge \- show / manipulate bridge addresses and devices
 .B source_list
 .IR SOURCE_LIST " ] [ "
 .B proto
-.IR PROTO " ]
+.IR PROTO " ] [ "
+.B dst
+.IR IPADDR " ]
 
 .ti -8
 .BR "bridge mdb show" " [ "
@@ -969,6 +971,17 @@  then
 .B static
 is assumed.
 
+.in -8
+The next command line parameters apply only
+when the specified device
+.I DEV
+is of type VXLAN.
+
+.TP
+.BI dst " IPADDR"
+the IP address of the destination
+VXLAN tunnel endpoint where the multicast receivers reside.
+
 .in -8
 .SS bridge mdb delete - delete a multicast group database entry
 This command removes an existing mdb entry.