summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Ahern <dsahern@kernel.org>2023-03-24 18:30:40 -0600
committerDavid Ahern <dsahern@kernel.org>2023-03-24 18:30:40 -0600
commit60acb023e6773924f3758c4733de233808187ee7 (patch)
tree3cab608afdcccfc6985085197d2fce6dbe4d9b43
parentd0d5eeff798c1ab84c7e13d5d75a3c336dfcdb49 (diff)
parentbe24eab05d664ff63d1216498e5f2e6986ccafc7 (diff)
downloadiproute2-60acb023e6773924f3758c4733de233808187ee7.tar.gz
Merge branch 'bridge-mdb-vxlan-attr' into next
Ido Schimmel says: ==================== Add support for new VXLAN MDB attributes. See kernel merge commit abf36703d704 ("Merge branch 'vxlan-MDB-support'") for background and motivation. ==================== Signed-off-by: David Ahern <dsahern@kernel.org>
-rw-r--r--bridge/mdb.c163
-rw-r--r--man/man8/bridge.852
2 files changed, 212 insertions, 3 deletions
diff --git a/bridge/mdb.c b/bridge/mdb.c
index 9b550365..dcc08235 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"
@@ -32,7 +33,8 @@ 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"
+ " [ dst_port DST_PORT ] [ vni VNI ] [ src_vni SRC_VNI ] [ via DEV ]\n"
" bridge mdb {show} [ dev DEV ] [ vid VID ]\n");
exit(-1);
}
@@ -146,6 +148,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 +257,29 @@ 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 (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 (tb[MDBA_MDB_EATTR_VNI])
+ print_uint(PRINT_ANY, "vni", " vni %u",
+ rta_getattr_u32(tb[MDBA_MDB_EATTR_VNI]));
+
+ if (tb[MDBA_MDB_EATTR_SRC_VNI])
+ print_uint(PRINT_ANY, "src_vni", " src_vni %u",
+ rta_getattr_u32(tb[MDBA_MDB_EATTR_SRC_VNI]));
+
+ if (tb[MDBA_MDB_EATTR_IFINDEX]) {
+ unsigned int ifindex;
+
+ ifindex = rta_getattr_u32(tb[MDBA_MDB_EATTR_IFINDEX]);
+ print_string(PRINT_ANY, "via", " via %s",
+ ll_index_to_name(ifindex));
+ }
+
if (show_stats && tb && tb[MDBA_MDB_EATTR_TIMER]) {
__u32 timer = rta_getattr_u32(tb[MDBA_MDB_EATTR_TIMER]);
@@ -570,6 +610,76 @@ 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_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_parse_vni(struct nlmsghdr *n, int maxlen, const char *vni,
+ int attr_type)
+{
+ unsigned long vni_num;
+ char *endptr;
+
+ vni_num = strtoul(vni, &endptr, 0);
+ if ((endptr && *endptr) || vni_num == ULONG_MAX)
+ return -1;
+
+ addattr32(n, maxlen, attr_type, vni_num);
+
+ return 0;
+}
+
+static int mdb_parse_dev(struct nlmsghdr *n, int maxlen, const char *dev)
+{
+ unsigned int ifindex;
+
+ ifindex = ll_name_to_index(dev);
+ if (!ifindex)
+ return -1;
+
+ addattr32(n, maxlen, MDBE_ATTR_IFINDEX, ifindex);
+
+ return 0;
+}
+
static int mdb_modify(int cmd, int flags, int argc, char **argv)
{
struct {
@@ -583,7 +693,8 @@ 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 *dst_port = NULL, *vni = NULL, *src_vni = NULL, *via = NULL;
+ char *src_list = NULL, *proto = NULL, *dst = NULL;
struct br_mdb_entry entry = {};
bool set_attrs = false;
short vid = 0;
@@ -622,6 +733,26 @@ 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 (strcmp(*argv, "dst_port") == 0) {
+ NEXT_ARG();
+ dst_port = *argv;
+ set_attrs = true;
+ } else if (strcmp(*argv, "vni") == 0) {
+ NEXT_ARG();
+ vni = *argv;
+ set_attrs = true;
+ } else if (strcmp(*argv, "src_vni") == 0) {
+ NEXT_ARG();
+ src_vni = *argv;
+ set_attrs = true;
+ } else if (strcmp(*argv, "via") == 0) {
+ NEXT_ARG();
+ via = *argv;
+ set_attrs = true;
} else {
if (matches(*argv, "help") == 0)
usage();
@@ -675,6 +806,34 @@ 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;
+ }
+
+ if (dst_port && mdb_parse_dst_port(&req.n, sizeof(req),
+ dst_port)) {
+ fprintf(stderr, "Invalid destination port \"%s\"\n", dst_port);
+ return -1;
+ }
+
+ if (vni && mdb_parse_vni(&req.n, sizeof(req), vni,
+ MDBE_ATTR_VNI)) {
+ fprintf(stderr, "Invalid destination VNI \"%s\"\n",
+ vni);
+ return -1;
+ }
+
+ if (src_vni && mdb_parse_vni(&req.n, sizeof(req), src_vni,
+ MDBE_ATTR_SRC_VNI)) {
+ fprintf(stderr, "Invalid source VNI \"%s\"\n", src_vni);
+ return -1;
+ }
+
+ if (via && mdb_parse_dev(&req.n, sizeof(req), via))
+ return nodev(via);
+
addattr_nest_end(&req.n, nest);
}
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index abc0417b..4006ad23 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -145,7 +145,17 @@ bridge \- show / manipulate bridge addresses and devices
.B source_list
.IR SOURCE_LIST " ] [ "
.B proto
-.IR PROTO " ]
+.IR PROTO " ] [ "
+.B dst
+.IR IPADDR " ] [ "
+.B dst_port
+.IR DST_PORT " ] [ "
+.B vni
+.IR VNI " ] [ "
+.B src_vni
+.IR SRC_VNI " ] [ "
+.B via
+.IR DEV " ]
.ti -8
.BR "bridge mdb show" " [ "
@@ -970,6 +980,46 @@ then
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.
+
+.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.
+
+.TP
+.BI vni " VNI"
+the VXLAN VNI Network Identifier to use to connect to the remote VXLAN tunnel
+endpoint. If omitted, the value specified at VXLAN device creation will be used
+or the source VNI when the VXLAN device is in external mode.
+
+.TP
+.BI src_vni " SRC_VNI"
+the source VNI Network Identifier this entry belongs to. Used only when the
+VXLAN device is in external mode. If omitted, the value specified at VXLAN
+device creation will be used.
+
+.TP
+.BI via " DEV"
+device name of the outgoing interface for the VXLAN device to reach the remote
+VXLAN tunnel endpoint.
+
+.in -8
+The 0.0.0.0 and :: MDB entries are special catchall entries used to flood IPv4
+and IPv6 unregistered multicast packets, respectively. Therefore, when these
+entries are programmed, the catchall 00:00:00:00:00:00 FDB entry will only
+flood broadcast, unknown unicast and link-local multicast.
+
+.in -8
.SS bridge mdb delete - delete a multicast group database entry
This command removes an existing mdb entry.