]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
bridge: fdb: add flush [no]permanent entry matching
authorNikolay Aleksandrov <razor@blackwall.org>
Wed, 8 Jun 2022 12:29:15 +0000 (15:29 +0300)
committerDavid Ahern <dsahern@kernel.org>
Fri, 10 Jun 2022 15:01:33 +0000 (09:01 -0600)
Add flush support to match permanent or non-permanent entries if "no" is
prepended respectively.

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

$ bridge fdb flush dev br0 nopermanent
This will delete all entries except the permanent ones in br0's fdb
table.

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

index 4af13eb20dc54932d325fe4c3be3c855d700285a..b1c5161417501b4675fe6b4c9b3174aa9d4a2f45 100644 (file)
@@ -46,7 +46,7 @@ static void usage(void)
                "       bridge fdb get [ to ] LLADDR [ br BRDEV ] { brport | dev } DEV\n"
                "              [ vlan VID ] [ vni VNI ] [ self ] [ master ] [ dynamic ]\n"
                "       bridge fdb flush dev DEV [ brport DEV ] [ vlan VID ]\n"
-               "              [ self ] [ master ]\n");
+               "              [ self ] [ master ] [ [no]permanent ]\n");
        exit(-1);
 }
 
@@ -680,8 +680,10 @@ static int fdb_flush(int argc, char **argv)
                .n.nlmsg_type = RTM_DELNEIGH,
                .ndm.ndm_family = PF_BRIDGE,
        };
+       unsigned short ndm_state_mask = 0;
        short vid = -1, port_ifidx = -1;
        unsigned short ndm_flags = 0;
+       unsigned short ndm_state = 0;
        char *d = NULL, *port = NULL;
 
        while (argc > 0) {
@@ -692,6 +694,12 @@ 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, "permanent") == 0) {
+                       ndm_state |= NUD_PERMANENT;
+                       ndm_state_mask |= NUD_PERMANENT;
+               } else if (strcmp(*argv, "nopermanent") == 0) {
+                       ndm_state &= ~NUD_PERMANENT;
+                       ndm_state_mask |= NUD_PERMANENT;
                } else if (strcmp(*argv, "brport") == 0) {
                        if (port)
                                duparg2("brport", *argv);
@@ -739,10 +747,14 @@ static int fdb_flush(int argc, char **argv)
                ndm_flags |= NTF_SELF;
 
        req.ndm.ndm_flags = ndm_flags;
+       req.ndm.ndm_state = ndm_state;
        if (port_ifidx > -1)
                addattr32(&req.n, sizeof(req), NDA_IFINDEX, port_ifidx);
        if (vid > -1)
                addattr16(&req.n, sizeof(req), NDA_VLAN, vid);
+       if (ndm_state_mask)
+               addattr16(&req.n, sizeof(req), NDA_NDM_STATE_MASK,
+                         ndm_state_mask);
 
        if (rtnl_talk(&rth, &req.n, NULL) < 0)
                return -1;
index 32b81b4bd4fef60ab7e0c2d6026be126a8e03671..9dcd1f0a613f10c8fa1396cac43725cb3f7aa12e 100644 (file)
@@ -120,7 +120,8 @@ bridge \- show / manipulate bridge addresses and devices
 .IR DEV " ] [ "
 .B vlan
 .IR VID " ] [ "
-.BR self " ] [ " master " ]"
+.BR self " ] [ " master " ] [ "
+.BR [no]permanent " ]"
 
 .ti -8
 .BR "bridge mdb" " { " add " | " del " } "
@@ -795,7 +796,8 @@ the bridge to which this address is associated.
 
 .SS bridge fdb flush - flush bridge forwarding table entries.
 
-flush the matching bridge forwarding table entries.
+flush the matching bridge forwarding table entries. Some options below have a negated
+form when "no" is prepended to them (e.g. permanent and nopermanent).
 
 .TP
 .BI dev " DEV"
@@ -826,6 +828,11 @@ command can also be used on the bridge device itself. The flag is set by default
 .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.
+
+.TP
+.B [no]permanent
+if specified then only permanent entries will be deleted or respectively if "no"
+is prepended then only non-permanent entries will be deleted.
 .sp
 
 .SH bridge mdb - multicast group database management