]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
bridge: fdb: add new flush command
authorNikolay Aleksandrov <razor@blackwall.org>
Wed, 8 Jun 2022 12:29:12 +0000 (15:29 +0300)
committerDavid Ahern <dsahern@kernel.org>
Fri, 10 Jun 2022 15:00:31 +0000 (09:00 -0600)
Add support for fdb bulk delete (aka flush) command. Currently it only
supports the self and master flags with the same semantics as fdb
add/del. The device is a mandatory argument.

Example:
$ bridge fdb flush dev br0
This will delete *all* fdb entries in br0's fdb table.

$ bridge fdb flush dev swp1 master
This will delete all fdb entries pointing to swp1.

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

index 8912f092ca15183e547c5c599498c49aaaf8ae9e..ac9f7af643361ae66041aa3485b7adb4f92f408c 100644 (file)
@@ -44,7 +44,8 @@ static void usage(void)
                "       bridge fdb [ show [ br BRDEV ] [ brport DEV ] [ vlan VID ]\n"
                "              [ state STATE ] [ dynamic ] ]\n"
                "       bridge fdb get [ to ] LLADDR [ br BRDEV ] { brport | dev } DEV\n"
-               "              [ vlan VID ] [ vni VNI ] [ self ] [ master ] [ dynamic ]\n");
+               "              [ vlan VID ] [ vni VNI ] [ self ] [ master ] [ dynamic ]\n"
+               "       bridge fdb flush dev DEV [ self ] [ master ]\n");
        exit(-1);
 }
 
@@ -666,6 +667,59 @@ static int fdb_get(int argc, char **argv)
        return 0;
 }
 
+static int fdb_flush(int argc, char **argv)
+{
+       struct {
+               struct nlmsghdr n;
+               struct ndmsg            ndm;
+               char                    buf[256];
+       } req = {
+               .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)),
+               .n.nlmsg_flags = NLM_F_REQUEST | NLM_F_BULK,
+               .n.nlmsg_type = RTM_DELNEIGH,
+               .ndm.ndm_family = PF_BRIDGE,
+       };
+       unsigned short ndm_flags = 0;
+       char *d = NULL;
+
+       while (argc > 0) {
+               if (strcmp(*argv, "dev") == 0) {
+                       NEXT_ARG();
+                       d = *argv;
+               } else if (strcmp(*argv, "master") == 0) {
+                       ndm_flags |= NTF_MASTER;
+               } else if (strcmp(*argv, "self") == 0) {
+                       ndm_flags |= NTF_SELF;
+               } else {
+                       if (strcmp(*argv, "help") == 0)
+                               NEXT_ARG();
+               }
+               argc--; argv++;
+       }
+
+       if (d == NULL) {
+               fprintf(stderr, "Device is a required argument.\n");
+               return -1;
+       }
+
+       req.ndm.ndm_ifindex = ll_name_to_index(d);
+       if (req.ndm.ndm_ifindex == 0) {
+               fprintf(stderr, "Cannot find bridge device \"%s\"\n", d);
+               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 (rtnl_talk(&rth, &req.n, NULL) < 0)
+               return -1;
+
+       return 0;
+}
+
 int do_fdb(int argc, char **argv)
 {
        ll_init_map(&rth);
@@ -685,6 +739,8 @@ int do_fdb(int argc, char **argv)
                    matches(*argv, "lst") == 0 ||
                    matches(*argv, "list") == 0)
                        return fdb_show(argc-1, argv+1);
+               if (strcmp(*argv, "flush") == 0)
+                       return fdb_flush(argc-1, argv+1);
                if (matches(*argv, "help") == 0)
                        usage();
        } else
index d8923d2eb07625c31f41daf250b068ee17166a00..bfda9f7ecd7b16f54843885e556b604623e9ee6f 100644 (file)
@@ -112,6 +112,12 @@ bridge \- show / manipulate bridge addresses and devices
 .IR VNI " ] ["
 .BR self " ] [ " master " ] [ " dynamic " ]"
 
+.ti -8
+.BR "bridge fdb flush"
+.B dev
+.IR DEV " [ "
+.BR self " ] [ " master " ]"
+
 .ti -8
 .BR "bridge mdb" " { " add " | " del " } "
 .B dev
@@ -782,6 +788,29 @@ the bridge to which this address is associated.
 .TP
 .B master
 - the address is associated with master devices fdb. Usually software (default).
+
+.SS bridge fdb flush - flush bridge forwarding table entries.
+
+flush the matching bridge forwarding table entries.
+
+.TP
+.BI dev " DEV"
+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
+.B self
+the operation is fulfilled directly by the driver for the specified network
+device. If the network device belongs to a master like a bridge, then the
+bridge is bypassed and not notified of this operation. The "bridge fdb flush"
+command can also be used on the bridge device itself. The flag is set by default if
+"master" is not specified.
+
+.TP
+.B master
+if the specified network device is a port that belongs to a master device
+such as a bridge, the operation is fulfilled by the master device's driver.
 .sp
 
 .SH bridge mdb - multicast group database management