diff mbox series

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

Message ID 20220608122921.3962382-7-razor@blackwall.org (mailing list archive)
State Accepted
Commit 8198f75073ede4e486ed9496e195fc065f8af486
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 dynamic or non-dynamic (static or permanent)
entries if "no" is prepended respectively. Note that dynamic entries are
defined as fdbs without NUD_NOARP and NUD_PERMANENT set, and non-dynamic
entries are fdbs with NUD_NOARP set (that matches both static and
permanent entries).

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

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

Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org>
---
 bridge/fdb.c      | 8 +++++++-
 man/man8/bridge.8 | 7 ++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/bridge/fdb.c b/bridge/fdb.c
index 93806d7d35b5..9c1899c167be 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 ] [ [no]permanent | [no]static ]\n");
+		"              [ self ] [ master ] [ [no]permanent | [no]static | [no]dynamic ]\n");
 	exit(-1);
 }
 
@@ -706,6 +706,12 @@  static int fdb_flush(int argc, char **argv)
 		} else if (strcmp(*argv, "nostatic") == 0) {
 			ndm_state &= ~NUD_NOARP;
 			ndm_state_mask |= NUD_NOARP;
+		} else if (strcmp(*argv, "dynamic") == 0) {
+			ndm_state &= ~NUD_NOARP | NUD_PERMANENT;
+			ndm_state_mask |= NUD_NOARP | NUD_PERMANENT;
+		} else if (strcmp(*argv, "nodynamic") == 0) {
+			ndm_state |= NUD_NOARP;
+			ndm_state_mask |= NUD_NOARP;
 		} else if (strcmp(*argv, "brport") == 0) {
 			if (port)
 				duparg2("brport", *argv);
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index 9e2952b8c6d6..f4b3887a9144 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -121,7 +121,7 @@  bridge \- show / manipulate bridge addresses and devices
 .B vlan
 .IR VID " ] [ "
 .BR self " ] [ " master " ] [ "
-.BR [no]permanent " | " [no]static " ]"
+.BR [no]permanent " | " [no]static " | " [no]dynamic " ]"
 
 .ti -8
 .BR "bridge mdb" " { " add " | " del " } "
@@ -838,6 +838,11 @@  is prepended then only non-permanent entries will be deleted.
 .B [no]static
 if specified then only static entries will be deleted or respectively if "no"
 is prepended then only non-static entries will be deleted.
+
+.TP
+.B [no]dynamic
+if specified then only dynamic entries will be deleted or respectively if "no"
+is prepended then only non-dynamic (static or permanent) entries will be deleted.
 .sp
 
 .SH bridge mdb - multicast group database management