Blame SOURCES/0089-bridge-vlan-add-support-to-filter-by-vlan-id.patch

4aca6e
From e139f3f1d7f669edea662b9f847faee30f2c5f6c Mon Sep 17 00:00:00 2001
4aca6e
From: Phil Sutter <psutter@redhat.com>
4aca6e
Date: Tue, 28 Feb 2017 16:12:44 +0100
4aca6e
Subject: [PATCH] bridge: vlan: add support to filter by vlan id
4aca6e
4aca6e
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1417289
4aca6e
Upstream Status: iproute2.git commit 5a2d0201cce16
4aca6e
4aca6e
commit 5a2d0201cce161617b30102d10b709fa24c6e833
4aca6e
Author: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
4aca6e
Date:   Mon Apr 11 17:45:16 2016 +0200
4aca6e
4aca6e
    bridge: vlan: add support to filter by vlan id
4aca6e
4aca6e
    Add the optional keyword "vid" to bridge vlan show so the user can
4aca6e
    request filtering by a specific vlan id. Currently the filtering is
4aca6e
    implemented only in user-space. The argument name has been chosen to
4aca6e
    match the add/del one - "vid". This filtering can be used also with the
4aca6e
    "-compressvlans" option to see in which range is a vlan (if in any).
4aca6e
    Also this will be used to show only specific per-vlan statistics later
4aca6e
    when support is added to the kernel for it.
4aca6e
4aca6e
    Examples:
4aca6e
    $ bridge vlan show vid 450
4aca6e
    port    vlan ids
4aca6e
    eth2     450
4aca6e
4aca6e
    $ bridge -c vlan show vid 450
4aca6e
    port    vlan ids
4aca6e
    eth2     400-500
4aca6e
4aca6e
    $ bridge vlan show vid 1
4aca6e
    port    vlan ids
4aca6e
    eth1     1 PVID Egress Untagged
4aca6e
    eth2     1 PVID
4aca6e
    br0      1 PVID Egress Untagged
4aca6e
4aca6e
    Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
4aca6e
---
4aca6e
 bridge/vlan.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++----------
4aca6e
 1 file changed, 50 insertions(+), 10 deletions(-)
4aca6e
4aca6e
diff --git a/bridge/vlan.c b/bridge/vlan.c
4aca6e
index ae58832..717025a 100644
4aca6e
--- a/bridge/vlan.c
4aca6e
+++ b/bridge/vlan.c
4aca6e
@@ -13,13 +13,13 @@
4aca6e
 #include "br_common.h"
4aca6e
 #include "utils.h"
4aca6e
 
4aca6e
-static unsigned int filter_index;
4aca6e
+static unsigned int filter_index, filter_vlan;
4aca6e
 
4aca6e
 static void usage(void)
4aca6e
 {
4aca6e
 	fprintf(stderr, "Usage: bridge vlan { add | del } vid VLAN_ID dev DEV [ pvid] [ untagged ]\n");
4aca6e
 	fprintf(stderr, "                                                     [ self ] [ master ]\n");
4aca6e
-	fprintf(stderr, "       bridge vlan { show } [ dev DEV ]\n");
4aca6e
+	fprintf(stderr, "       bridge vlan { show } [ dev DEV ] [ vid VLAN_ID ]\n");
4aca6e
 	exit(-1);
4aca6e
 }
4aca6e
 
4aca6e
@@ -138,6 +138,26 @@ static int vlan_modify(int cmd, int argc, char **argv)
4aca6e
 	return 0;
4aca6e
 }
4aca6e
 
4aca6e
+/* In order to use this function for both filtering and non-filtering cases
4aca6e
+ * we need to make it a tristate:
4aca6e
+ * return -1 - if filtering we've gone over so don't continue
4aca6e
+ * return  0 - skip entry and continue (applies to range start or to entries
4aca6e
+ *             which are less than filter_vlan)
4aca6e
+ * return  1 - print the entry and continue
4aca6e
+ */
4aca6e
+static int filter_vlan_check(struct bridge_vlan_info *vinfo)
4aca6e
+{
4aca6e
+	/* if we're filtering we should stop on the first greater entry */
4aca6e
+	if (filter_vlan && vinfo->vid > filter_vlan &&
4aca6e
+	    !(vinfo->flags & BRIDGE_VLAN_INFO_RANGE_END))
4aca6e
+		return -1;
4aca6e
+	if ((vinfo->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) ||
4aca6e
+	    vinfo->vid < filter_vlan)
4aca6e
+		return 0;
4aca6e
+
4aca6e
+	return 1;
4aca6e
+}
4aca6e
+
4aca6e
 static int print_vlan(const struct sockaddr_nl *who,
4aca6e
 		      struct nlmsghdr *n,
4aca6e
 		      void *arg)
4aca6e
@@ -169,26 +189,40 @@ static int print_vlan(const struct sockaddr_nl *who,
4aca6e
 
4aca6e
 	/* if AF_SPEC isn't there, vlan table is not preset for this port */
4aca6e
 	if (!tb[IFLA_AF_SPEC]) {
4aca6e
-		fprintf(fp, "%s\tNone\n", ll_index_to_name(ifm->ifi_index));
4aca6e
+		if (!filter_vlan)
4aca6e
+			fprintf(fp, "%s\tNone\n",
4aca6e
+				ll_index_to_name(ifm->ifi_index));
4aca6e
 		return 0;
4aca6e
 	} else {
4aca6e
 		struct rtattr *i, *list = tb[IFLA_AF_SPEC];
4aca6e
 		int rem = RTA_PAYLOAD(list);
4aca6e
+		__u16 last_vid_start = 0;
4aca6e
 
4aca6e
-		fprintf(fp, "%s", ll_index_to_name(ifm->ifi_index));
4aca6e
+		if (!filter_vlan)
4aca6e
+			fprintf(fp, "%s", ll_index_to_name(ifm->ifi_index));
4aca6e
 		for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
4aca6e
 			struct bridge_vlan_info *vinfo;
4aca6e
+			int vcheck_ret;
4aca6e
 
4aca6e
 			if (i->rta_type != IFLA_BRIDGE_VLAN_INFO)
4aca6e
 				continue;
4aca6e
 
4aca6e
 			vinfo = RTA_DATA(i);
4aca6e
-			if (vinfo->flags & BRIDGE_VLAN_INFO_RANGE_END)
4aca6e
-				fprintf(fp, "-%hu", vinfo->vid);
4aca6e
-			else
4aca6e
-				fprintf(fp, "\t %hu", vinfo->vid);
4aca6e
-			if (vinfo->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN)
4aca6e
+
4aca6e
+			if (!(vinfo->flags & BRIDGE_VLAN_INFO_RANGE_END))
4aca6e
+				last_vid_start = vinfo->vid;
4aca6e
+			vcheck_ret = filter_vlan_check(vinfo);
4aca6e
+			if (vcheck_ret == -1)
4aca6e
+				break;
4aca6e
+			else if (vcheck_ret == 0)
4aca6e
 				continue;
4aca6e
+
4aca6e
+			if (filter_vlan)
4aca6e
+				fprintf(fp, "%s",
4aca6e
+					ll_index_to_name(ifm->ifi_index));
4aca6e
+			fprintf(fp, "\t %hu", last_vid_start);
4aca6e
+			if (last_vid_start != vinfo->vid)
4aca6e
+				fprintf(fp, "-%hu", vinfo->vid);
4aca6e
 			if (vinfo->flags & BRIDGE_VLAN_INFO_PVID)
4aca6e
 				fprintf(fp, " PVID");
4aca6e
 			if (vinfo->flags & BRIDGE_VLAN_INFO_UNTAGGED)
4aca6e
@@ -196,7 +230,8 @@ static int print_vlan(const struct sockaddr_nl *who,
4aca6e
 			fprintf(fp, "\n");
4aca6e
 		}
4aca6e
 	}
4aca6e
-	fprintf(fp, "\n");
4aca6e
+	if (!filter_vlan)
4aca6e
+		fprintf(fp, "\n");
4aca6e
 	fflush(fp);
4aca6e
 	return 0;
4aca6e
 }
4aca6e
@@ -211,6 +246,11 @@ static int vlan_show(int argc, char **argv)
4aca6e
 			if (filter_dev)
4aca6e
 				duparg("dev", *argv);
4aca6e
 			filter_dev = *argv;
4aca6e
+		} else if (strcmp(*argv, "vid") == 0) {
4aca6e
+			NEXT_ARG();
4aca6e
+			if (filter_vlan)
4aca6e
+				duparg("vid", *argv);
4aca6e
+			filter_vlan = atoi(*argv);
4aca6e
 		}
4aca6e
 		argc--; argv++;
4aca6e
 	}
4aca6e
-- 
4aca6e
1.8.3.1
4aca6e