Skip to contentSkip to conversation

bridge: fdb: the 'dynamic' option in the show/get commands

PATCH In review Anton Danilov 3 participants 3 messages Jul 27, 2020 – Aug 9, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bridge: fdb: the 'dynamic' option in the show/get commands

In most of cases a user wants to see only the dynamic mac addresses in the fdb output. But currently the 'fdb show' displays tons of various self entries, those only waste the output without any useful goal.

New option 'dynamic' for 'show' and 'get' commands forces display only relevant records.

---
 bridge/fdb.c      | 17 +++++++++++++----
 man/man8/bridge.8 | 30 ++++++++++++++++++------------
 2 files changed, 31 insertions(+), 16 deletions(-)
bridge/fdb.c +13 -4
index 710dfc99..78aaaa5a 100644
@@ -30,7 +30,8 @@
 #include "rt_names.h"
 #include "utils.h"
 
-static unsigned int filter_index, filter_vlan, filter_state, filter_master;
+static unsigned int filter_index, filter_dynamic, filter_master,
+	filter_state, filter_vlan;
 
 static void usage(void)
 {
@@ -40,9 +41,10 @@ static void usage(void)
 		"              [ sticky ] [ local | static | dynamic ] [ dst IPADDR ]\n"
 		"              [ vlan VID ] [ port PORT] [ vni VNI ] [ via DEV ]\n"
 		"              [ src_vni VNI ]\n"
-		"       bridge fdb [ show [ br BRDEV ] [ brport DEV ] [ vlan VID ] [ state STATE ] ]\n"
-		"       bridge fdb get ADDR [ br BRDEV ] { brport |dev }  DEV [ vlan VID ]\n"
-		"              [ vni VNI ]\n");
+		"       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");
 	exit(-1);
 }
 
@@ -167,6 +169,9 @@ int print_fdb(struct nlmsghdr *n, void *arg)
 	if (filter_vlan && filter_vlan != vid)
 		return 0;
 
+	if (filter_dynamic && (r->ndm_state & NUD_PERMANENT))
+		return 0;
+
 	open_json_object(NULL);
 	if (n->nlmsg_type == RTM_DELNEIGH)
 		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
@@ -322,6 +327,8 @@ static int fdb_show(int argc, char **argv)
 			if (state_a2n(&state, *argv))
 				invarg("invalid state", *argv);
 			filter_state |= state;
+		} else if (strcmp(*argv, "dynamic") == 0) {
+			filter_dynamic = 1;
 		} else {
 			if (matches(*argv, "help") == 0)
 				usage();
@@ -566,6 +573,8 @@ static int fdb_get(int argc, char **argv)
 				duparg2("vlan", *argv);
 			NEXT_ARG();
 			vlan = atoi(*argv);
+		} else if (matches(*argv, "dynamic") == 0) {
+			filter_dynamic = 1;
 		} else {
 			if (strcmp(*argv, "to") == 0)
 				NEXT_ARG();
man/man8/bridge.8 +18 -12
index 71f2e890..5aa83e15 100644
@@ -77,12 +77,12 @@ bridge \- show / manipulate bridge addresses and devices
 .B port
 .IR PORT " ] ["
 .B via
-.IR DEVICE " ]"
+.IR DEVICE " ] ["
+.B src_vni
+.IR VNI " ]"
 
 .ti -8
-.BR "bridge fdb" " [ " show " ] [ "
-.B dev
-.IR DEV " ] [ "
+.BR "bridge fdb" " [ [ " show " ] [ "
 .B br
 .IR BRDEV " ] [ "
 .B brport
@@ -90,18 +90,24 @@ bridge \- show / manipulate bridge addresses and devices
 .B vlan
 .IR VID " ] [ "
 .B state
-.IR STATE " ]"
+.IR STATE " ] ["
+.B dynamic
+.IR "] ]"
 
 .ti -8
-.B bridge fdb get
-.I LLADDR " [ "
-.B dev
-.IR DEV " ] [ "
+.BR "bridge fdb get" " ["
+.B to
+.IR "]"
+.I LLADDR "[ "
 .B br
-.IR BRDEV " ] [ "
+.IR BRDEV " ]"
+.B { brport | dev }
+.IR DEV " [ "
 .B vlan
-.IR VID  " ] ["
-.BR self " ] [ " master " ]"
+.IR VID  " ] [ "
+.B vni
+.IR VNI " ] ["
+.BR self " ] [ " master " ] [ " dynamic " ]"
 
 .ti -8
 .BR "bridge mdb" " { " add " | " del " } "
Signature · 1 line
2.27.0
#1 lore raw
Quoted 9 lines · On Mon, 27 Jul 2020 16:26:07 +0300 Anton Danilov…

In most of cases a user wants to see only the dynamic mac addresses in the fdb output. But currently the 'fdb show' displays tons of various self entries, those only waste the output without any useful goal.

New option 'dynamic' for 'show' and 'get' commands forces display only relevant records.

Looks like a good solution.
Applied

#2 lore raw
In reply to Anton Danilov

Hello Anton,

Quoted 127 lines · Anton Danilov

In most of cases a user wants to see only the dynamic mac addresses in the fdb output. But currently the 'fdb show' displays tons of various self entries, those only waste the output without any useful goal.

New option 'dynamic' for 'show' and 'get' commands forces display only relevant records.

---
 bridge/fdb.c      | 17 +++++++++++++----
 man/man8/bridge.8 | 30 ++++++++++++++++++------------
 2 files changed, 31 insertions(+), 16 deletions(-)
bridge/fdb.c +13 -4
index 710dfc99..78aaaa5a 100644
@@ -30,7 +30,8 @@
 #include "rt_names.h"
 #include "utils.h"
 
-static unsigned int filter_index, filter_vlan, filter_state, filter_master;
+static unsigned int filter_index, filter_dynamic, filter_master,
+	filter_state, filter_vlan;
 
 static void usage(void)
 {
@@ -40,9 +41,10 @@ static void usage(void)
 		"              [ sticky ] [ local | static | dynamic ] [ dst IPADDR ]\n"
 		"              [ vlan VID ] [ port PORT] [ vni VNI ] [ via DEV ]\n"
 		"              [ src_vni VNI ]\n"
-		"       bridge fdb [ show [ br BRDEV ] [ brport DEV ] [ vlan VID ] [ state STATE ] ]\n"
-		"       bridge fdb get ADDR [ br BRDEV ] { brport |dev }  DEV [ vlan VID ]\n"
-		"              [ vni VNI ]\n");
+		"       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");
 	exit(-1);
 }
 
@@ -167,6 +169,9 @@ int print_fdb(struct nlmsghdr *n, void *arg)
 	if (filter_vlan && filter_vlan != vid)
 		return 0;
 
+	if (filter_dynamic && (r->ndm_state & NUD_PERMANENT))
+		return 0;
+
 	open_json_object(NULL);
 	if (n->nlmsg_type == RTM_DELNEIGH)
 		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
@@ -322,6 +327,8 @@ static int fdb_show(int argc, char **argv)
 			if (state_a2n(&state, *argv))
 				invarg("invalid state", *argv);
 			filter_state |= state;
+		} else if (strcmp(*argv, "dynamic") == 0) {
+			filter_dynamic = 1;
 		} else {
 			if (matches(*argv, "help") == 0)
 				usage();
@@ -566,6 +573,8 @@ static int fdb_get(int argc, char **argv)
 				duparg2("vlan", *argv);
 			NEXT_ARG();
 			vlan = atoi(*argv);
+		} else if (matches(*argv, "dynamic") == 0) {
+			filter_dynamic = 1;
 		} else {
 			if (strcmp(*argv, "to") == 0)
 				NEXT_ARG();
man/man8/bridge.8 +18 -12
index 71f2e890..5aa83e15 100644
@@ -77,12 +77,12 @@ bridge \- show / manipulate bridge addresses and devices
 .B port
 .IR PORT " ] ["
 .B via
-.IR DEVICE " ]"
+.IR DEVICE " ] ["
+.B src_vni
+.IR VNI " ]"
 
 .ti -8
-.BR "bridge fdb" " [ " show " ] [ "
-.B dev
-.IR DEV " ] [ "
+.BR "bridge fdb" " [ [ " show " ] [ "
 .B br
 .IR BRDEV " ] [ "
 .B brport
@@ -90,18 +90,24 @@ bridge \- show / manipulate bridge addresses and devices
 .B vlan
 .IR VID " ] [ "
 .B state
-.IR STATE " ]"
+.IR STATE " ] ["
+.B dynamic
+.IR "] ]"
 
 .ti -8
-.B bridge fdb get
-.I LLADDR " [ "
-.B dev
-.IR DEV " ] [ "
+.BR "bridge fdb get" " ["
+.B to
+.IR "]"
+.I LLADDR "[ "
 .B br
-.IR BRDEV " ] [ "
+.IR BRDEV " ]"
+.B { brport | dev }
+.IR DEV " [ "
 .B vlan
-.IR VID  " ] ["
-.BR self " ] [ " master " ]"
+.IR VID  " ] [ "
+.B vni
+.IR VNI " ] ["
+.BR self " ] [ " master " ] [ " dynamic " ]"
 
 .ti -8
 .BR "bridge mdb" " { " add " | " del " } "
Signature · 1 line
2.27.0

Are the 'static' entries 'dynamic'?

bridge fdb add dev sw0p2 00:01:02:03:04:05 master static bridge fdb show dev sw0p2 dynamic | grep 00:01:02:03:04:05 00:01:02:03:04:05 vlan 1 offload master br0 static 00:01:02:03:04:05 offload master br0 static