]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
bridge: vlan: add support to set global vlan options
authorNikolay Aleksandrov <nikolay@nvidia.com>
Sat, 28 Aug 2021 11:07:52 +0000 (14:07 +0300)
committerDavid Ahern <dsahern@kernel.org>
Wed, 1 Sep 2021 03:21:13 +0000 (21:21 -0600)
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>
Signed-off-by: David Ahern <dsahern@kernel.org>
bridge/vlan.c
man/man8/bridge.8

index 77db90d8a6174c33735155b0d37650a48fea23ef..c9b445bc65aaaf962f20bc911e0998974063a434 100644 (file)
@@ -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 {
index 9ec4cb1dec674af3254a72159a0d72d4dbcf3736..796d20b662abd526f82cf521ab6b953ea97abba8 100644 (file)
@@ -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.