All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2-next 0/2] bridge: vlan: add support for mcast_router option
@ 2021-09-01 10:38 Nikolay Aleksandrov
  2021-09-01 10:38 ` [PATCH iproute2-next 1/2] bridge: vlan: set vlan option attributes while parsing Nikolay Aleksandrov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nikolay Aleksandrov @ 2021-09-01 10:38 UTC (permalink / raw)
  To: netdev; +Cc: roopa, dsahern, stephen, Nikolay Aleksandrov

From: Nikolay Aleksandrov <nikolay@nvidia.com>

Hi,
This set adds support for vlan port/bridge multicast router option. It is
similar to the already existing bridge-wide mcast_router control. Patch 01
moves attribute adding and parsing together for vlan option setting,
similar to global vlan option setting. It simplifies adding new options
because we can avoid reserved values and additional checks. Patch 02
adds the new mcast_router option and updates the related man page.

Example:
 # mark port ens16 as a permanent mcast router for vlan 100
 $ bridge vlan set dev ens16 vid 100 mcast_router 2
 # disable mcast router for port ens16 and vlan 200
 $ bridge vlan set dev ens16 vid 200 mcast_router 0
 $ bridge -d vlan show
 port              vlan-id
 ens16             1 PVID Egress Untagged
                     state forwarding mcast_router 1
                   100
                     state forwarding mcast_router 2
                   200
                     state forwarding mcast_router 0

Note that this set depends on the latest kernel uapi headers.

Thanks,
 Nik


Nikolay Aleksandrov (2):
  bridge: vlan: set vlan option attributes while parsing
  bridge: vlan: add support for mcast_router option

 bridge/vlan.c     | 70 +++++++++++++++++++++++++++++------------------
 man/man8/bridge.8 | 29 +++++++++++++++++++-
 2 files changed, 71 insertions(+), 28 deletions(-)

-- 
2.31.1


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

* [PATCH iproute2-next 1/2] bridge: vlan: set vlan option attributes while parsing
  2021-09-01 10:38 [PATCH iproute2-next 0/2] bridge: vlan: add support for mcast_router option Nikolay Aleksandrov
@ 2021-09-01 10:38 ` Nikolay Aleksandrov
  2021-09-01 10:38 ` [PATCH iproute2-next 2/2] bridge: vlan: add support for mcast_router option Nikolay Aleksandrov
  2021-09-06 23:04 ` [PATCH iproute2-next 0/2] " David Ahern
  2 siblings, 0 replies; 4+ messages in thread
From: Nikolay Aleksandrov @ 2021-09-01 10:38 UTC (permalink / raw)
  To: netdev; +Cc: roopa, dsahern, stephen, Nikolay Aleksandrov

From: Nikolay Aleksandrov <nikolay@nvidia.com>

Set vlan option attributes immediately while parsing to simplify the
checks, avoid having reserved values (e.g. -1 for unset var) and have
more limited scope for the variables. This is also similar to how global
vlan options are set. The attribute setting and checks are moved with
option parsing, no functional changes intended.

Signed-off-by: Nikolay Aleksandrov <nikolay@nvidia.com>
---
 bridge/vlan.c | 53 ++++++++++++++++++++++++++-------------------------
 1 file changed, 27 insertions(+), 26 deletions(-)

diff --git a/bridge/vlan.c b/bridge/vlan.c
index 4ead57b783a8..48365bca4c4a 100644
--- a/bridge/vlan.c
+++ b/bridge/vlan.c
@@ -272,16 +272,24 @@ static int vlan_option_set(int argc, char **argv)
 	};
 	struct bridge_vlan_info vinfo = {};
 	struct rtattr *afspec;
-	short vid_end = -1;
 	char *d = NULL;
 	short vid = -1;
-	int state = -1;
 
+	afspec = addattr_nest(&req.n, sizeof(req), BRIDGE_VLANDB_ENTRY);
+	afspec->rta_type |= NLA_F_NESTED;
 	while (argc > 0) {
 		if (strcmp(*argv, "dev") == 0) {
 			NEXT_ARG();
 			d = *argv;
+			req.bvm.ifindex = ll_name_to_index(d);
+			if (req.bvm.ifindex == 0) {
+				fprintf(stderr,
+					"Cannot find network device \"%s\"\n",
+					d);
+				return -1;
+			}
 		} else if (strcmp(*argv, "vid") == 0) {
+			short vid_end = -1;
 			char *p;
 
 			NEXT_ARG();
@@ -299,8 +307,22 @@ static int vlan_option_set(int argc, char **argv)
 			} else {
 				vid = atoi(*argv);
 			}
+			if (vid >= 4096) {
+				fprintf(stderr, "Invalid VLAN ID \"%hu\"\n",
+					vid);
+				return -1;
+			}
+
+			vinfo.flags = BRIDGE_VLAN_INFO_ONLY_OPTS;
+			vinfo.vid = vid;
+			addattr_l(&req.n, sizeof(req), BRIDGE_VLANDB_ENTRY_INFO,
+				  &vinfo, sizeof(vinfo));
+			if (vid_end != -1)
+				addattr16(&req.n, sizeof(req),
+					  BRIDGE_VLANDB_ENTRY_RANGE, vid_end);
 		} else if (strcmp(*argv, "state") == 0) {
 			char *endptr;
+			int state;
 
 			NEXT_ARG();
 			state = strtol(*argv, &endptr, 10);
@@ -310,42 +332,21 @@ static int vlan_option_set(int argc, char **argv)
 				fprintf(stderr, "Error: invalid STP state\n");
 				return -1;
 			}
+			addattr8(&req.n, sizeof(req), BRIDGE_VLANDB_ENTRY_STATE,
+				 state);
 		} else {
 			if (matches(*argv, "help") == 0)
 				NEXT_ARG();
 		}
 		argc--; argv++;
 	}
+	addattr_nest_end(&req.n, afspec);
 
 	if (d == NULL || vid == -1) {
 		fprintf(stderr, "Device and VLAN ID are required arguments.\n");
 		return -1;
 	}
 
-	req.bvm.ifindex = ll_name_to_index(d);
-	if (req.bvm.ifindex == 0) {
-		fprintf(stderr, "Cannot find network device \"%s\"\n", d);
-		return -1;
-	}
-
-	if (vid >= 4096) {
-		fprintf(stderr, "Invalid VLAN ID \"%hu\"\n", vid);
-		return -1;
-	}
-	afspec = addattr_nest(&req.n, sizeof(req), BRIDGE_VLANDB_ENTRY);
-	afspec->rta_type |= NLA_F_NESTED;
-
-	vinfo.flags = BRIDGE_VLAN_INFO_ONLY_OPTS;
-	vinfo.vid = vid;
-	addattr_l(&req.n, sizeof(req), BRIDGE_VLANDB_ENTRY_INFO, &vinfo,
-		  sizeof(vinfo));
-	if (vid_end != -1)
-		addattr16(&req.n, sizeof(req), BRIDGE_VLANDB_ENTRY_RANGE,
-			  vid_end);
-	if (state >= 0)
-		addattr8(&req.n, sizeof(req), BRIDGE_VLANDB_ENTRY_STATE, state);
-	addattr_nest_end(&req.n, afspec);
-
 	if (rtnl_talk(&rth, &req.n, NULL) < 0)
 		return -1;
 
-- 
2.31.1


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

* [PATCH iproute2-next 2/2] bridge: vlan: add support for mcast_router option
  2021-09-01 10:38 [PATCH iproute2-next 0/2] bridge: vlan: add support for mcast_router option Nikolay Aleksandrov
  2021-09-01 10:38 ` [PATCH iproute2-next 1/2] bridge: vlan: set vlan option attributes while parsing Nikolay Aleksandrov
@ 2021-09-01 10:38 ` Nikolay Aleksandrov
  2021-09-06 23:04 ` [PATCH iproute2-next 0/2] " David Ahern
  2 siblings, 0 replies; 4+ messages in thread
From: Nikolay Aleksandrov @ 2021-09-01 10:38 UTC (permalink / raw)
  To: netdev; +Cc: roopa, dsahern, stephen, Nikolay Aleksandrov

From: Nikolay Aleksandrov <nikolay@nvidia.com>

Add support for setting and dumping per-vlan/interface mcast_router
option. It controls the mcast router mode of a vlan/interface pair.
For bridge devices only modes 0 - 2 are allowed. The possible modes
are:
 0 - disabled
 1 - automatic router presence detection (default)
 2 - permanent router
 3 - temporary router (available only for ports)

Example:
 # mark port ens16 as a permanent mcast router for vlan 100
 $ bridge vlan set dev ens16 vid 100 mcast_router 2
 # disable mcast router for port ens16 and vlan 200
 $ bridge vlan set dev ens16 vid 200 mcast_router 0
 $ bridge -d vlan show
 port              vlan-id
 ens16             1 PVID Egress Untagged
                     state forwarding mcast_router 1
                   100
                     state forwarding mcast_router 2
                   200
                     state forwarding mcast_router 0

Signed-off-by: Nikolay Aleksandrov <nikolay@nvidia.com>
---
 bridge/vlan.c     | 17 ++++++++++++++++-
 man/man8/bridge.8 | 29 ++++++++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/bridge/vlan.c b/bridge/vlan.c
index 48365bca4c4a..8300f353f1a7 100644
--- a/bridge/vlan.c
+++ b/bridge/vlan.c
@@ -36,6 +36,7 @@ static void usage(void)
 		"                                                     [ pvid ] [ untagged ]\n"
 		"                                                     [ self ] [ master ]\n"
 		"       bridge vlan { set } vid VLAN_ID dev DEV [ state STP_STATE ]\n"
+		"                                               [ mcast_router MULTICAST_ROUTER ]\n"
 		"       bridge vlan { show } [ dev DEV ] [ vid VLAN_ID ]\n"
 		"       bridge vlan { tunnelshow } [ dev DEV ] [ vid VLAN_ID ]\n"
 		"       bridge vlan global { set } vid VLAN_ID dev DEV\n"
@@ -334,6 +335,15 @@ static int vlan_option_set(int argc, char **argv)
 			}
 			addattr8(&req.n, sizeof(req), BRIDGE_VLANDB_ENTRY_STATE,
 				 state);
+		} else if (strcmp(*argv, "mcast_router") == 0) {
+			__u8 mcast_router;
+
+			NEXT_ARG();
+			if (get_u8(&mcast_router, *argv, 0))
+				invarg("invalid mcast_router", *argv);
+			addattr8(&req.n, sizeof(req),
+				 BRIDGE_VLANDB_ENTRY_MCAST_ROUTER,
+				 mcast_router);
 		} else {
 			if (matches(*argv, "help") == 0)
 				NEXT_ARG();
@@ -942,7 +952,7 @@ static void print_vlan_global_opts(struct rtattr *a, int ifindex)
 
 static void print_vlan_opts(struct rtattr *a, int ifindex)
 {
-	struct rtattr *vtb[BRIDGE_VLANDB_ENTRY_MAX + 1];
+	struct rtattr *vtb[BRIDGE_VLANDB_ENTRY_MAX + 1], *vattr;
 	struct bridge_vlan_xstats vstats;
 	struct bridge_vlan_info *vinfo;
 	__u16 vrange = 0;
@@ -1006,6 +1016,11 @@ static void print_vlan_opts(struct rtattr *a, int ifindex)
 	print_nl();
 	print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s    ", "");
 	print_stp_state(state);
+	if (vtb[BRIDGE_VLANDB_ENTRY_MCAST_ROUTER]) {
+		vattr = vtb[BRIDGE_VLANDB_ENTRY_MCAST_ROUTER];
+		print_uint(PRINT_ANY, "mcast_router", "mcast_router %u ",
+			   rta_getattr_u8(vattr));
+	}
 	print_nl();
 	if (show_stats)
 		__print_one_vlan_stats(&vstats);
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index 76d2fa09d5bc..c3c4ae48aaed 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -145,7 +145,9 @@ bridge \- show / manipulate bridge addresses and devices
 .B vid
 .IR VID " [ "
 .B state
-.IR STP_STATE " ] "
+.IR STP_STATE " ] [ "
+.B mcast_router
+.IR MULTICAST_ROUTER " ]"
 
 .ti -8
 .BR "bridge vlan" " [ " show " | " tunnelshow " ] [ "
@@ -915,6 +917,31 @@ is used during the STP election process. In this state, the vlan will only proce
 STP BPDUs.
 .sp
 
+.TP
+.BI mcast_router " MULTICAST_ROUTER "
+configure this vlan and interface's multicast router mode, note that only modes
+0 - 2 are available for bridge devices.
+A vlan and interface with a multicast router will receive all multicast traffic.
+.I MULTICAST_ROUTER
+may be either
+.sp
+.B 0
+- to disable multicast router.
+.sp
+
+.B 1
+- to let the system detect the presence of routers (default).
+.sp
+
+.B 2
+- to permanently enable multicast traffic forwarding on this vlan and interface.
+.sp
+
+.B 3
+- to temporarily mark this vlan and port as having a multicast router, i.e.
+enable multicast traffic forwarding. This mode is available only for ports.
+.sp
+
 .SS bridge vlan show - list vlan configuration.
 
 This command displays the current VLAN filter table.
-- 
2.31.1


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

* Re: [PATCH iproute2-next 0/2] bridge: vlan: add support for mcast_router option
  2021-09-01 10:38 [PATCH iproute2-next 0/2] bridge: vlan: add support for mcast_router option Nikolay Aleksandrov
  2021-09-01 10:38 ` [PATCH iproute2-next 1/2] bridge: vlan: set vlan option attributes while parsing Nikolay Aleksandrov
  2021-09-01 10:38 ` [PATCH iproute2-next 2/2] bridge: vlan: add support for mcast_router option Nikolay Aleksandrov
@ 2021-09-06 23:04 ` David Ahern
  2 siblings, 0 replies; 4+ messages in thread
From: David Ahern @ 2021-09-06 23:04 UTC (permalink / raw)
  To: Nikolay Aleksandrov, netdev; +Cc: roopa, dsahern, stephen, Nikolay Aleksandrov

On 9/1/21 4:38 AM, Nikolay Aleksandrov wrote:
> From: Nikolay Aleksandrov <nikolay@nvidia.com>
> 
> Hi,
> This set adds support for vlan port/bridge multicast router option. It is
> similar to the already existing bridge-wide mcast_router control. Patch 01
> moves attribute adding and parsing together for vlan option setting,
> similar to global vlan option setting. It simplifies adding new options
> because we can avoid reserved values and additional checks. Patch 02
> adds the new mcast_router option and updates the related man page.
> 
> Example:
>  # mark port ens16 as a permanent mcast router for vlan 100
>  $ bridge vlan set dev ens16 vid 100 mcast_router 2
>  # disable mcast router for port ens16 and vlan 200
>  $ bridge vlan set dev ens16 vid 200 mcast_router 0
>  $ bridge -d vlan show
>  port              vlan-id
>  ens16             1 PVID Egress Untagged
>                      state forwarding mcast_router 1
>                    100
>                      state forwarding mcast_router 2
>                    200
>                      state forwarding mcast_router 0
> 
> Note that this set depends on the latest kernel uapi headers.
> 

applied to iproute2-next.


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

end of thread, other threads:[~2021-09-06 23:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-01 10:38 [PATCH iproute2-next 0/2] bridge: vlan: add support for mcast_router option Nikolay Aleksandrov
2021-09-01 10:38 ` [PATCH iproute2-next 1/2] bridge: vlan: set vlan option attributes while parsing Nikolay Aleksandrov
2021-09-01 10:38 ` [PATCH iproute2-next 2/2] bridge: vlan: add support for mcast_router option Nikolay Aleksandrov
2021-09-06 23:04 ` [PATCH iproute2-next 0/2] " David Ahern

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.