All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v2] iproute2: bridge: support vlan range
@ 2015-01-23  6:25 roopa
  2015-01-23  6:51 ` Stephen Hemminger
  0 siblings, 1 reply; 3+ messages in thread
From: roopa @ 2015-01-23  6:25 UTC (permalink / raw)
  To: davem, stephen, netdev, vyasevic; +Cc: wkok, sfeldma

From: Roopa Prabhu <roopa@cumulusnetworks.com>

This patch adds vlan range support to bridge command
using the newly added vinfo flags BRIDGE_VLAN_INFO_RANGE_BEGIN and
BRIDGE_VLAN_INFO_RANGE_END.

$bridge vlan show
port    vlan ids
br0      1 PVID Egress Untagged

dummy0   1 PVID Egress Untagged

$bridge vlan add vid 10-15 dev dummy0
port    vlan ids
br0      1 PVID Egress Untagged

dummy0   1 PVID Egress Untagged
         10
         11
         12
         13
         14
         15

$bridge vlan del vid 14 dev dummy0

$bridge vlan show
port    vlan ids
br0      1 PVID Egress Untagged

dummy0   1 PVID Egress Untagged
         10
         11
         12
         13
         15

$bridge vlan del vid 10-15 dev dummy0

$bridge vlan show
port    vlan ids
br0      1 PVID Egress Untagged

dummy0   1 PVID Egress Untagged

v2: fix vid check

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Signed-off-by: Wilson Kok <wkok@cumulusnetworks.com>
---
 bridge/vlan.c             |   44 ++++++++++++++++++++++++++++++++++++++++----
 include/linux/if_bridge.h |    2 ++
 2 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/bridge/vlan.c b/bridge/vlan.c
index 3bd7b0d..88992e6 100644
--- a/bridge/vlan.c
+++ b/bridge/vlan.c
@@ -32,6 +32,7 @@ static int vlan_modify(int cmd, int argc, char **argv)
 	} req;
 	char *d = NULL;
 	short vid = -1;
+	short vid_end = -1;
 	struct rtattr *afspec;
 	struct bridge_vlan_info vinfo;
 	unsigned short flags = 0;
@@ -49,8 +50,18 @@ static int vlan_modify(int cmd, int argc, char **argv)
 			NEXT_ARG();
 			d = *argv;
 		} else if (strcmp(*argv, "vid") == 0) {
+			char *p;
 			NEXT_ARG();
-			vid = atoi(*argv);
+			p = strchr(*argv, '-');
+			if (p) {
+				*p = '\0';
+				p++;
+				vid = atoi(*argv);
+				vid_end = atoi(p);
+				vinfo.flags |= BRIDGE_VLAN_INFO_RANGE_BEGIN;
+			} else {
+				vid = atoi(*argv);
+			}
 		} else if (strcmp(*argv, "self") == 0) {
 			flags |= BRIDGE_FLAGS_SELF;
 		} else if (strcmp(*argv, "master") == 0) {
@@ -83,15 +94,40 @@ static int vlan_modify(int cmd, int argc, char **argv)
 		return -1;
 	}
 
-	vinfo.vid = vid;
+	if (vinfo.flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) {
+		if (vid_end == -1 || vid_end >= 4096 || vid >= vid_end) {
+			fprintf(stderr, "Invalid VLAN range \"%hu-%hu\"\n",
+				vid, vid_end);
+			return -1;
+		}
+		if (vinfo.flags & BRIDGE_VLAN_INFO_PVID) {
+			fprintf(stderr,
+				"pvid cannot be configured for a vlan range\n");
+			return -1;
+		}
+	}
 
 	afspec = addattr_nest(&req.n, sizeof(req), IFLA_AF_SPEC);
 
 	if (flags)
 		addattr16(&req.n, sizeof(req), IFLA_BRIDGE_FLAGS, flags);
 
-	addattr_l(&req.n, sizeof(req), IFLA_BRIDGE_VLAN_INFO, &vinfo,
-		  sizeof(vinfo));
+	vinfo.vid = vid;
+	if (vid_end != -1) {
+		/* send vlan range start */
+		addattr_l(&req.n, sizeof(req), IFLA_BRIDGE_VLAN_INFO, &vinfo,
+			  sizeof(vinfo));
+		vinfo.flags &= ~BRIDGE_VLAN_INFO_RANGE_BEGIN;
+
+		/* Now send the vlan range end */
+		vinfo.flags |= BRIDGE_VLAN_INFO_RANGE_END;
+		vinfo.vid = vid_end;
+		addattr_l(&req.n, sizeof(req), IFLA_BRIDGE_VLAN_INFO, &vinfo,
+			  sizeof(vinfo));
+	} else {
+		addattr_l(&req.n, sizeof(req), IFLA_BRIDGE_VLAN_INFO, &vinfo,
+			  sizeof(vinfo));
+	}
 
 	addattr_nest_end(&req.n, afspec);
 
diff --git a/include/linux/if_bridge.h b/include/linux/if_bridge.h
index 19ff22a..efa10b8 100644
--- a/include/linux/if_bridge.h
+++ b/include/linux/if_bridge.h
@@ -125,6 +125,8 @@ enum {
 #define BRIDGE_VLAN_INFO_MASTER	(1<<0)	/* Operate on Bridge device as well */
 #define BRIDGE_VLAN_INFO_PVID	(1<<1)	/* VLAN is PVID, ingress untagged */
 #define BRIDGE_VLAN_INFO_UNTAGGED	(1<<2)	/* VLAN egresses untagged */
+#define BRIDGE_VLAN_INFO_RANGE_BEGIN	(1<<3) /* VLAN is start of vlan range */
+#define BRIDGE_VLAN_INFO_RANGE_END	(1<<4)	/* VLAN is end of vlan range */
 
 struct bridge_vlan_info {
 	__u16 flags;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next v2] iproute2: bridge: support vlan range
  2015-01-23  6:25 [PATCH net-next v2] iproute2: bridge: support vlan range roopa
@ 2015-01-23  6:51 ` Stephen Hemminger
  2015-01-23 15:42   ` roopa
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2015-01-23  6:51 UTC (permalink / raw)
  To: roopa; +Cc: davem, netdev, vyasevic, wkok, sfeldma

On Thu, 22 Jan 2015 22:25:10 -0800
roopa@cumulusnetworks.com wrote:

> From: Roopa Prabhu <roopa@cumulusnetworks.com>
> 
> This patch adds vlan range support to bridge command
> using the newly added vinfo flags BRIDGE_VLAN_INFO_RANGE_BEGIN and
> BRIDGE_VLAN_INFO_RANGE_END.
> 
> $bridge vlan show
> port    vlan ids
> br0      1 PVID Egress Untagged
> 
> dummy0   1 PVID Egress Untagged
> 
> $bridge vlan add vid 10-15 dev dummy0
> port    vlan ids
> br0      1 PVID Egress Untagged
> 
> dummy0   1 PVID Egress Untagged
>          10
>          11
>          12
>          13
>          14
>          15

Doing on vlan id per line gets ridiculous with 1000 vlan's
how about something more compact?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next v2] iproute2: bridge: support vlan range
  2015-01-23  6:51 ` Stephen Hemminger
@ 2015-01-23 15:42   ` roopa
  0 siblings, 0 replies; 3+ messages in thread
From: roopa @ 2015-01-23 15:42 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: davem, netdev, vyasevic, wkok, sfeldma

On 1/22/15, 10:51 PM, Stephen Hemminger wrote:
> On Thu, 22 Jan 2015 22:25:10 -0800
> roopa@cumulusnetworks.com wrote:
>
>> From: Roopa Prabhu <roopa@cumulusnetworks.com>
>>
>> This patch adds vlan range support to bridge command
>> using the newly added vinfo flags BRIDGE_VLAN_INFO_RANGE_BEGIN and
>> BRIDGE_VLAN_INFO_RANGE_END.
>>
>> $bridge vlan show
>> port    vlan ids
>> br0      1 PVID Egress Untagged
>>
>> dummy0   1 PVID Egress Untagged
>>
>> $bridge vlan add vid 10-15 dev dummy0
>> port    vlan ids
>> br0      1 PVID Egress Untagged
>>
>> dummy0   1 PVID Egress Untagged
>>           10
>>           11
>>           12
>>           13
>>           14
>>           15
> Doing on vlan id per line gets ridiculous with 1000 vlan's
> how about something more compact?
yes, I was going to do that in a separate patch ...the kernel can dump 
in ranges with the new flag.
I did not want to change default (current) show to print ranges.
Was planning on submitting a new patch with a new option. If you think 
there are not many users out there today..
..and no fear of breaking users, i will include it in the current patch 
in v3.

thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-01-23 15:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-23  6:25 [PATCH net-next v2] iproute2: bridge: support vlan range roopa
2015-01-23  6:51 ` Stephen Hemminger
2015-01-23 15:42   ` roopa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.