From 739809454864ecec6098a849c009526fc59d44d3 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Tue, 28 Feb 2017 16:09:46 +0100 Subject: [PATCH] iproute2: bridge: support vlan range adds Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1417289 Upstream Status: iproute2.git commit 3ac0d36ddde97 commit 3ac0d36ddde9715a8d027a919eb564f7b42c6c40 Author: Roopa Prabhu Date: Sun Jan 25 18:26:24 2015 -0800 iproute2: bridge: support vlan range adds This patch adds vlan range support to bridge add 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 Signed-off-by: Roopa Prabhu Signed-off-by: Wilson Kok --- bridge/vlan.c | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index 2ceecc9..da53b4d 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); -- 1.8.3.1