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.

Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
Anton Danilov 2020-07-27 16:26:07 +03:00 committed by Stephen Hemminger
parent 3a53ff7e58
commit 65c0c4d21b
2 changed files with 31 additions and 16 deletions

View File

@ -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();

View File

@ -76,12 +76,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
@ -89,18 +89,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 " } "