diff mbox series

[iproute2-next,04/10] bridge: fdb: add flush [no]permanent entry matching

Message ID 20220608122921.3962382-5-razor@blackwall.org (mailing list archive)
State Accepted
Commit 988c319807508ba6de79f22e859edc50aaaad171
Delegated to: David Ahern
Headers show
Series bridge: fdb: add extended flush support | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Nikolay Aleksandrov June 8, 2022, 12:29 p.m. UTC
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>
---
 bridge/fdb.c      | 14 +++++++++++++-
 man/man8/bridge.8 | 11 +++++++++--
 2 files changed, 22 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/bridge/fdb.c b/bridge/fdb.c
index 4af13eb20dc5..b1c516141750 100644
--- a/bridge/fdb.c
+++ b/bridge/fdb.c
@@ -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;
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index 32b81b4bd4fe..9dcd1f0a613f 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -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