All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nikolay Aleksandrov <razor@blackwall.org>
To: netdev@vger.kernel.org
Cc: roopa@nvidia.com, dsahern@gmail.com, stephen@networkplumber.org,
	Joachim Wiberg <troglobit@gmail.com>,
	Nikolay Aleksandrov <nikolay@nvidia.com>
Subject: [PATCH iproute2-next v2 06/19] bridge: vlan: add support to set global vlan options
Date: Sat, 28 Aug 2021 14:07:52 +0300	[thread overview]
Message-ID: <20210828110805.463429-7-razor@blackwall.org> (raw)
In-Reply-To: <20210828110805.463429-1-razor@blackwall.org>

From: Nikolay Aleksandrov <nikolay@nvidia.com>

Add support to change global vlan options via a new vlan global
set subcommand similar to the current vlan set subcommand. The man page
and help are updated accordingly. The command works only with bridge
devices. It doesn't support any options yet.

Syntax: $ bridge vlan global set vid VID dev DEV

Signed-off-by: Nikolay Aleksandrov <nikolay@nvidia.com>
---
v2: use strcmp instead of matches

 bridge/vlan.c     | 80 +++++++++++++++++++++++++++++++++++++++++++++++
 man/man8/bridge.8 | 20 ++++++++++++
 2 files changed, 100 insertions(+)

diff --git a/bridge/vlan.c b/bridge/vlan.c
index 77db90d8a617..c9b445bc65aa 100644
--- a/bridge/vlan.c
+++ b/bridge/vlan.c
@@ -37,6 +37,7 @@ static void usage(void)
 		"       bridge vlan { set } vid VLAN_ID dev DEV [ state STP_STATE ]\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"
 		"       bridge vlan global { show } [ dev DEV ] [ vid VLAN_ID ]\n");
 	exit(-1);
 }
@@ -338,6 +339,83 @@ static int vlan_option_set(int argc, char **argv)
 	return 0;
 }
 
+static int vlan_global_option_set(int argc, char **argv)
+{
+	struct {
+		struct nlmsghdr	n;
+		struct br_vlan_msg	bvm;
+		char			buf[1024];
+	} req = {
+		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct br_vlan_msg)),
+		.n.nlmsg_flags = NLM_F_REQUEST,
+		.n.nlmsg_type = RTM_NEWVLAN,
+		.bvm.family = PF_BRIDGE,
+	};
+	struct rtattr *afspec;
+	short vid_end = -1;
+	char *d = NULL;
+	short vid = -1;
+
+	afspec = addattr_nest(&req.n, sizeof(req),
+			      BRIDGE_VLANDB_GLOBAL_OPTIONS);
+	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) {
+			char *p;
+
+			NEXT_ARG();
+			p = strchr(*argv, '-');
+			if (p) {
+				*p = '\0';
+				p++;
+				vid = atoi(*argv);
+				vid_end = atoi(p);
+				if (vid >= vid_end || vid_end >= 4096) {
+					fprintf(stderr, "Invalid VLAN range \"%hu-%hu\"\n",
+						vid, vid_end);
+					return -1;
+				}
+			} else {
+				vid = atoi(*argv);
+			}
+			if (vid >= 4096) {
+				fprintf(stderr, "Invalid VLAN ID \"%hu\"\n",
+					vid);
+				return -1;
+			}
+			addattr16(&req.n, sizeof(req), BRIDGE_VLANDB_GOPTS_ID,
+				  vid);
+			if (vid_end != -1)
+				addattr16(&req.n, sizeof(req),
+					  BRIDGE_VLANDB_GOPTS_RANGE, vid_end);
+		} else {
+			if (strcmp(*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;
+	}
+
+	if (rtnl_talk(&rth, &req.n, NULL) < 0)
+		return -1;
+
+	return 0;
+}
+
 /* In order to use this function for both filtering and non-filtering cases
  * we need to make it a tristate:
  * return -1 - if filtering we've gone over so don't continue
@@ -1016,6 +1094,8 @@ static int vlan_global(int argc, char **argv)
 		    strcmp(*argv, "lst") == 0 ||
 		    strcmp(*argv, "list") == 0)
 			return vlan_global_show(argc-1, argv+1);
+		else if (strcmp(*argv, "set") == 0)
+			return vlan_global_option_set(argc-1, argv+1);
 		else
 			usage();
 	} else {
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index 9ec4cb1dec67..796d20b662ab 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -152,6 +152,13 @@ bridge \- show / manipulate bridge addresses and devices
 .B dev
 .IR DEV " ]"
 
+.ti -8
+.BR "bridge vlan global set"
+.B dev
+.I DEV
+.B vid
+.IR VID " [ ]"
+
 .ti -8
 .BR "bridge vlan global" " [ " show " ] [ "
 .B dev
@@ -902,6 +909,19 @@ option, the command displays per-vlan traffic statistics.
 
 This command displays the current vlan tunnel info mapping.
 
+.SS bridge vlan global set - change vlan filter entry's global options
+
+This command changes vlan filter entry's global options.
+
+.TP
+.BI dev " NAME"
+the interface with which this vlan is associated. Only bridge devices are
+supported for global options.
+
+.TP
+.BI vid " VID"
+the VLAN ID that identifies the vlan.
+
 .SS bridge vlan global show - list global vlan options.
 
 This command displays the global VLAN options for each VLAN entry.
-- 
2.31.1


  parent reply	other threads:[~2021-08-28 11:08 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-28 11:07 [PATCH iproute2-next v2 00/19] bridge: vlan: add global multicast options Nikolay Aleksandrov
2021-08-28 11:07 ` [PATCH iproute2-next v2 01/19] ip: bridge: add support for mcast_vlan_snooping Nikolay Aleksandrov
2021-08-28 11:07 ` [PATCH iproute2-next v2 02/19] bridge: vlan: factor out vlan option printing Nikolay Aleksandrov
2021-08-28 11:07 ` [PATCH iproute2-next v2 03/19] bridge: vlan: skip unknown attributes when printing options Nikolay Aleksandrov
2021-08-28 11:07 ` [PATCH iproute2-next v2 04/19] bridge: vlan: add support to show global vlan options Nikolay Aleksandrov
2021-08-28 11:07 ` [PATCH iproute2-next v2 05/19] bridge: vlan: add support for vlan filtering when dumping options Nikolay Aleksandrov
2021-08-28 11:07 ` Nikolay Aleksandrov [this message]
2021-08-28 11:07 ` [PATCH iproute2-next v2 07/19] bridge: vlan: add global mcast_snooping option Nikolay Aleksandrov
2021-09-01  3:36   ` David Ahern
2021-09-01  8:07     ` Nikolay Aleksandrov
2021-08-28 11:07 ` [PATCH iproute2-next v2 08/19] bridge: vlan: add global mcast_igmp_version option Nikolay Aleksandrov
2021-08-28 11:07 ` [PATCH iproute2-next v2 09/19] bridge: vlan: add global mcast_mld_version option Nikolay Aleksandrov
2021-08-28 11:07 ` [PATCH iproute2-next v2 10/19] bridge: vlan: add global mcast_last_member_count option Nikolay Aleksandrov
2021-08-28 11:07 ` [PATCH iproute2-next v2 11/19] bridge: vlan: add global mcast_startup_query_count option Nikolay Aleksandrov
2021-08-28 11:07 ` [PATCH iproute2-next v2 12/19] bridge: vlan: add global mcast_last_member_interval option Nikolay Aleksandrov
2021-08-28 11:07 ` [PATCH iproute2-next v2 13/19] bridge: vlan: add global mcast_membership_interval option Nikolay Aleksandrov
2021-08-28 11:08 ` [PATCH iproute2-next v2 14/19] bridge: vlan: add global mcast_querier_interval option Nikolay Aleksandrov
2021-08-28 11:08 ` [PATCH iproute2-next v2 15/19] bridge: vlan: add global mcast_query_interval option Nikolay Aleksandrov
2021-08-28 11:08 ` [PATCH iproute2-next v2 16/19] bridge: vlan: add global mcast_query_response_interval option Nikolay Aleksandrov
2021-08-28 11:08 ` [PATCH iproute2-next v2 17/19] bridge: vlan: add global mcast_startup_query_interval option Nikolay Aleksandrov
2021-08-28 11:08 ` [PATCH iproute2-next v2 18/19] bridge: vlan: add global mcast_querier option Nikolay Aleksandrov
2021-08-28 11:08 ` [PATCH iproute2-next v2 19/19] bridge: vlan: add support for dumping router ports Nikolay Aleksandrov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210828110805.463429-7-razor@blackwall.org \
    --to=razor@blackwall.org \
    --cc=dsahern@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=nikolay@nvidia.com \
    --cc=roopa@nvidia.com \
    --cc=stephen@networkplumber.org \
    --cc=troglobit@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.