]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
bridge: fdb: add flush vlan matching
authorNikolay Aleksandrov <razor@blackwall.org>
Wed, 8 Jun 2022 12:29:13 +0000 (15:29 +0300)
committerDavid Ahern <dsahern@kernel.org>
Fri, 10 Jun 2022 15:00:41 +0000 (09:00 -0600)
Add flush support to match fdb entries in a specific vlan.
Example:
$ bridge fdb flush dev swp1 vlan 10 master
This will flush all fdb entries with port swp1 and vlan 10.

Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org>
Signed-off-by: David Ahern <dsahern@kernel.org>
bridge/fdb.c
man/man8/bridge.8

index ac9f7af643361ae66041aa3485b7adb4f92f408c..c2a1fb957f7e6cc8d9c8519297d09484bdeabe0d 100644 (file)
@@ -45,7 +45,7 @@ static void usage(void)
                "              [ state STATE ] [ dynamic ] ]\n"
                "       bridge fdb get [ to ] LLADDR [ br BRDEV ] { brport | dev } DEV\n"
                "              [ vlan VID ] [ vni VNI ] [ self ] [ master ] [ dynamic ]\n"
-               "       bridge fdb flush dev DEV [ self ] [ master ]\n");
+               "       bridge fdb flush dev DEV [ vlan VID ] [ self ] [ master ]\n");
        exit(-1);
 }
 
@@ -681,6 +681,7 @@ static int fdb_flush(int argc, char **argv)
        };
        unsigned short ndm_flags = 0;
        char *d = NULL;
+       short vid = -1;
 
        while (argc > 0) {
                if (strcmp(*argv, "dev") == 0) {
@@ -690,6 +691,11 @@ static int fdb_flush(int argc, char **argv)
                        ndm_flags |= NTF_MASTER;
                } else if (strcmp(*argv, "self") == 0) {
                        ndm_flags |= NTF_SELF;
+               } else if (strcmp(*argv, "vlan") == 0) {
+                       if (vid >= 0)
+                               duparg2("vlan", *argv);
+                       NEXT_ARG();
+                       vid = atoi(*argv);
                } else {
                        if (strcmp(*argv, "help") == 0)
                                NEXT_ARG();
@@ -708,11 +714,18 @@ static int fdb_flush(int argc, char **argv)
                return -1;
        }
 
+       if (vid >= 4096) {
+               fprintf(stderr, "Invalid VLAN ID \"%hu\"\n", vid);
+               return -1;
+       }
+
        /* if self and master were not specified assume self */
        if (!(ndm_flags & (NTF_SELF | NTF_MASTER)))
                ndm_flags |= NTF_SELF;
 
        req.ndm.ndm_flags = ndm_flags;
+       if (vid > -1)
+               addattr16(&req.n, sizeof(req), NDA_VLAN, vid);
 
        if (rtnl_talk(&rth, &req.n, NULL) < 0)
                return -1;
index bfda9f7ecd7b16f54843885e556b604623e9ee6f..d5db85b943bdf77e46e9a14b1c7384f8e8018611 100644 (file)
@@ -116,6 +116,8 @@ bridge \- show / manipulate bridge addresses and devices
 .BR "bridge fdb flush"
 .B dev
 .IR DEV " [ "
+.B vlan
+.IR VID " ] [ "
 .BR self " ] [ " master " ]"
 
 .ti -8
@@ -799,6 +801,11 @@ the target device for the operation. If the device is a bridge port and "master"
 is set then the operation will be fulfilled by its master device's driver and
 all entries pointing to that port will be deleted.
 
+.TP
+.BI vlan " VID"
+the target VLAN ID for the operation. Match forwarding table entries only with the
+specified VLAN ID.
+
 .TP
 .B self
 the operation is fulfilled directly by the driver for the specified network