]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
bridge: mdb: Add UDP destination port support
authorIdo Schimmel <idosch@nvidia.com>
Tue, 21 Mar 2023 13:01:23 +0000 (15:01 +0200)
committerDavid Ahern <dsahern@kernel.org>
Sat, 25 Mar 2023 00:29:37 +0000 (18:29 -0600)
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>
Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
bridge/mdb.c
man/man8/bridge.8

index 137d509ce7644deb4a34a08d386f5b0e4685c850..893488211911563d76d7c9510f14c4161751089b 100644 (file)
@@ -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);
        }
 
index 2f8500af1f022e5013c28dac64b9471212ca0ad1..9385aba0ee685ac896645f8fec3973b2285318a8 100644 (file)
@@ -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.