diff mbox series

[iproute2-next,3/7] bridge: mdb: Add UDP destination port support

Message ID 20230321130127.264822-4-idosch@nvidia.com (mailing list archive)
State Accepted
Commit 42a96e81c85fa150b9d6f21bc75e59b70fb1463b
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
In a similar fashion to VXLAN FDB entries, allow user space to program
and view the UDP destination port of VXLAN MDB entries. Specifically,
add support for the 'MDBE_ATTR_DST_PORT' and 'MDBA_MDB_EATTR_DST_PORT'
attributes in request and response messages, respectively.

Use the keyword "dst_port" instead of "port" as the latter is already
used to specify the net device associated with the MDB entry.

Example:

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

 $ bridge -d -s mdb show
 dev vxlan0 port vxlan0 grp 239.1.1.1 permanent filter_mode exclude proto static dst 198.51.100.1 dst_port 1234    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": "198.51.100.1",
                 "dst_port": 1234,
                 "timer": "   0.00"
             } ],
         "router": {}
     } ]

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
 bridge/mdb.c      | 40 ++++++++++++++++++++++++++++++++++++++++
 man/man8/bridge.8 | 10 +++++++++-
 2 files changed, 49 insertions(+), 1 deletion(-)

Comments

Nikolay Aleksandrov March 23, 2023, 3:18 p.m. UTC | #1
On 21/03/2023 15:01, Ido Schimmel wrote:
> In a similar fashion to VXLAN FDB entries, allow user space to program
> and view the UDP destination port of VXLAN MDB entries. Specifically,
> add support for the 'MDBE_ATTR_DST_PORT' and 'MDBA_MDB_EATTR_DST_PORT'
> attributes in request and response messages, respectively.
> 
> Use the keyword "dst_port" instead of "port" as the latter is already
> used to specify the net device associated with the MDB entry.
> 
> Example:
> 
>  # bridge mdb add dev vxlan0 port vxlan0 grp 239.1.1.1 permanent dst 198.51.100.1 dst_port 1234
> 
>  $ bridge -d -s mdb show
>  dev vxlan0 port vxlan0 grp 239.1.1.1 permanent filter_mode exclude proto static dst 198.51.100.1 dst_port 1234    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": "198.51.100.1",
>                  "dst_port": 1234,
>                  "timer": "   0.00"
>              } ],
>          "router": {}
>      } ]
> 
> Signed-off-by: Ido Schimmel <idosch@nvidia.com>
> ---
>  bridge/mdb.c      | 40 ++++++++++++++++++++++++++++++++++++++++
>  man/man8/bridge.8 | 10 +++++++++-
>  2 files changed, 49 insertions(+), 1 deletion(-)
> 

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

Patch

diff --git a/bridge/mdb.c b/bridge/mdb.c
index 137d509ce764..893488211911 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -14,6 +14,7 @@ 
 #include <linux/if_ether.h>
 #include <string.h>
 #include <arpa/inet.h>
+#include <netdb.h>
 
 #include "libnetlink.h"
 #include "utils.h"
@@ -33,6 +34,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 ] [ dst IPADDR ]\n"
+		"              [ dst_port DST_PORT ]\n"
 		"       bridge mdb {show} [ dev DEV ] [ vid VID ]\n");
 	exit(-1);
 }
@@ -258,6 +260,10 @@  static void print_mdb_entry(FILE *f, int ifindex, const struct br_mdb_entry *e,
 	if (tb[MDBA_MDB_EATTR_DST])
 		print_dst(tb[MDBA_MDB_EATTR_DST]);
 
+	if (tb[MDBA_MDB_EATTR_DST_PORT])
+		print_uint(PRINT_ANY, "dst_port", " dst_port %u",
+			   rta_getattr_u16(tb[MDBA_MDB_EATTR_DST_PORT]));
+
 	if (show_stats && tb && tb[MDBA_MDB_EATTR_TIMER]) {
 		__u32 timer = rta_getattr_u32(tb[MDBA_MDB_EATTR_TIMER]);
 
@@ -607,6 +613,29 @@  static int mdb_parse_dst(struct nlmsghdr *n, int maxlen, const char *dst)
 	return -1;
 }
 
+static int mdb_parse_dst_port(struct nlmsghdr *n, int maxlen,
+			      const char *dst_port)
+{
+	unsigned long port;
+	char *endptr;
+
+	port = strtoul(dst_port, &endptr, 0);
+	if (endptr && *endptr) {
+		struct servent *pse;
+
+		pse = getservbyname(dst_port, "udp");
+		if (!pse)
+			return -1;
+		port = ntohs(pse->s_port);
+	} else if (port > USHRT_MAX) {
+		return -1;
+	}
+
+	addattr16(n, maxlen, MDBE_ATTR_DST_PORT, port);
+
+	return 0;
+}
+
 static int mdb_modify(int cmd, int flags, int argc, char **argv)
 {
 	struct {
@@ -621,6 +650,7 @@  static int mdb_modify(int cmd, int flags, int argc, char **argv)
 	};
 	char *d = NULL, *p = NULL, *grp = NULL, *src = NULL, *mode = NULL;
 	char *src_list = NULL, *proto = NULL, *dst = NULL;
+	char *dst_port = NULL;
 	struct br_mdb_entry entry = {};
 	bool set_attrs = false;
 	short vid = 0;
@@ -663,6 +693,10 @@  static int mdb_modify(int cmd, int flags, int argc, char **argv)
 			NEXT_ARG();
 			dst = *argv;
 			set_attrs = true;
+		} else if (strcmp(*argv, "dst_port") == 0) {
+			NEXT_ARG();
+			dst_port = *argv;
+			set_attrs = true;
 		} else {
 			if (matches(*argv, "help") == 0)
 				usage();
@@ -722,6 +756,12 @@  static int mdb_modify(int cmd, int flags, int argc, char **argv)
 			return -1;
 		}
 
+		if (dst_port && mdb_parse_dst_port(&req.n, sizeof(req),
+						   dst_port)) {
+			fprintf(stderr, "Invalid destination port \"%s\"\n", dst_port);
+			return -1;
+		}
+
 		addattr_nest_end(&req.n, nest);
 	}
 
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index 2f8500af1f02..9385aba0ee68 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -147,7 +147,9 @@  bridge \- show / manipulate bridge addresses and devices
 .B proto
 .IR PROTO " ] [ "
 .B dst
-.IR IPADDR " ]
+.IR IPADDR " ] [ "
+.B dst_port
+.IR DST_PORT " ]
 
 .ti -8
 .BR "bridge mdb show" " [ "
@@ -982,6 +984,12 @@  is of type VXLAN.
 the IP address of the destination
 VXLAN tunnel endpoint where the multicast receivers reside.
 
+.TP
+.BI dst_port " DST_PORT"
+the UDP destination port number to use to connect to the remote VXLAN tunnel
+endpoint. If omitted, the value specified at VXLAN device creation will be
+used.
+
 .in -8
 .SS bridge mdb delete - delete a multicast group database entry
 This command removes an existing mdb entry.