diff options
author | Ido Schimmel <idosch@nvidia.com> | 2023-03-21 15:01:23 +0200 |
---|---|---|
committer | David Ahern <dsahern@kernel.org> | 2023-03-24 18:29:37 -0600 |
commit | 42a96e81c85fa150b9d6f21bc75e59b70fb1463b (patch) | |
tree | b238938d0208f05c2bf3c2623d25e28fd20c386a | |
parent | d36899c2244ccf61cf74180fc644d50f9230e773 (diff) | |
download | iproute2-42a96e81c85fa150b9d6f21bc75e59b70fb1463b.tar.gz |
bridge: mdb: Add UDP destination port support
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>
-rw-r--r-- | bridge/mdb.c | 40 | ||||
-rw-r--r-- | man/man8/bridge.8 | 10 |
2 files changed, 49 insertions, 1 deletions
diff --git a/bridge/mdb.c b/bridge/mdb.c index 137d509ce..893488211 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 2f8500af1..9385aba0e 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. |