naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone
Blob Blame History Raw
From 8dab50579927df9b7dacd82480bbefc1cc231547 Mon Sep 17 00:00:00 2001
From: Phil Sutter <psutter@redhat.com>
Date: Tue, 28 Feb 2017 16:11:51 +0100
Subject: [PATCH] bridge: mdb: add support for vlans

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1417289
Upstream Status: iproute2.git commit 6aac8617139a9

commit 6aac8617139a96a124d63aeae843b73c38f88fc5
Author: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Date:   Wed Jul 15 08:45:20 2015 -0700

    bridge: mdb: add support for vlans

    This patch allows the user to specify the vlan of the mdb group being
    added or deleted and adds support for displaying the vlan when
    dumping mdb information or monitoring it. It also updates the man page
    to reflect the new "vid" argument for mdb.

    Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
---
 bridge/mdb.c      | 31 +++++++++++++++++++------------
 man/man8/bridge.8 |  8 +++++++-
 2 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/bridge/mdb.c b/bridge/mdb.c
index 680ec30..1b34f69 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -28,7 +28,7 @@ static unsigned int filter_index;
 
 static void usage(void)
 {
-	fprintf(stderr, "Usage: bridge mdb { add | del } dev DEV port PORT grp GROUP [permanent | temp]\n");
+	fprintf(stderr, "Usage: bridge mdb { add | del } dev DEV port PORT grp GROUP [permanent | temp] [vid VID]\n");
 	fprintf(stderr, "       bridge mdb {show} [ dev DEV ]\n");
 	exit(-1);
 }
@@ -51,17 +51,19 @@ static void br_print_router_ports(FILE *f, struct rtattr *attr)
 static void print_mdb_entry(FILE *f, int ifindex, struct br_mdb_entry *e)
 {
 	SPRINT_BUF(abuf);
-
-	if (e->addr.proto == htons(ETH_P_IP))
-		fprintf(f, "dev %s port %s grp %s %s\n", ll_index_to_name(ifindex),
-			ll_index_to_name(e->ifindex),
-			inet_ntop(AF_INET, &e->addr.u.ip4, abuf, sizeof(abuf)),
-			(e->state & MDB_PERMANENT) ? "permanent" : "temp");
-	else
-		fprintf(f, "dev %s port %s grp %s %s\n", ll_index_to_name(ifindex),
-			ll_index_to_name(e->ifindex),
-			inet_ntop(AF_INET6, &e->addr.u.ip6, abuf, sizeof(abuf)),
-			(e->state & MDB_PERMANENT) ? "permanent" : "temp");
+	const void *src;
+	int af;
+
+	af = e->addr.proto == htons(ETH_P_IP) ? AF_INET : AF_INET6;
+	src = af == AF_INET ? (const void *)&e->addr.u.ip4 :
+			      (const void *)&e->addr.u.ip6;
+	fprintf(f, "dev %s port %s grp %s %s", ll_index_to_name(ifindex),
+		ll_index_to_name(e->ifindex),
+		inet_ntop(af, src, abuf, sizeof(abuf)),
+		(e->state & MDB_PERMANENT) ? "permanent" : "temp");
+	if (e->vid)
+		fprintf(f, " vid %hu", e->vid);
+	fprintf(f, "\n");
 }
 
 static void br_print_mdb_entry(FILE *f, int ifindex, struct rtattr *attr)
@@ -177,6 +179,7 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
 	} req;
 	struct br_mdb_entry entry;
 	char *d = NULL, *p = NULL, *grp = NULL;
+	short vid = 0;
 
 	memset(&req, 0, sizeof(req));
 	memset(&entry, 0, sizeof(entry));
@@ -201,6 +204,9 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
 				entry.state |= MDB_PERMANENT;
 		} else if (strcmp(*argv, "temp") == 0) {
 			;/* nothing */
+		} else if (strcmp(*argv, "vid") == 0) {
+			NEXT_ARG();
+			vid = atoi(*argv);
 		} else {
 			if (matches(*argv, "help") == 0)
 				usage();
@@ -234,6 +240,7 @@ static int mdb_modify(int cmd, int flags, int argc, char **argv)
 	} else
 		entry.addr.proto = htons(ETH_P_IP);
 
+	entry.vid = vid;
 	addattr_l(&req.n, sizeof(req), MDBA_SET_ENTRY, &entry, sizeof(entry));
 
 	if (rtnl_talk(&rth, &req.n, NULL, 0) < 0)
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index 8fae74b..210a3ee 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -77,7 +77,9 @@ bridge \- show / manipulate bridge addresses and devices
 .IR PORT
 .B grp
 .IR GROUP " [ "
-.BR permanent " | " temp " ]"
+.BR permanent " | " temp " ] [ "
+.B vid
+.IR VID " ] "
 
 .ti -8
 .BR "bridge mdb show " [ "
@@ -435,6 +437,10 @@ the port.
 - the mdb entry is temporary (default)
 .sp
 
+.TP
+.BI vid " VID"
+the VLAN ID which is known to have members of this multicast group.
+
 .in -8
 .SS bridge mdb delete - delete a multicast group database entry
 This command removes an existing mdb entry.
-- 
1.8.3.1