]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
bridge: fdb: add state filter support
authorNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Thu, 12 Jan 2017 16:47:39 +0000 (17:47 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Fri, 13 Jan 2017 01:38:55 +0000 (17:38 -0800)
This patch adds a new argument to the bridge fdb show command that allows
to filter by entry state.
Also update the man page to include all available show arguments.

Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
bridge/fdb.c
man/man8/bridge.8

index a91521776e99043d32cb723986f298f702f1c6a4..a71a78f23b202e8e3fd8742345a6c8c3ecefca4e 100644 (file)
@@ -29,7 +29,7 @@
 #include "rt_names.h"
 #include "utils.h"
 
-static unsigned int filter_index, filter_vlan;
+static unsigned int filter_index, filter_vlan, filter_state;
 
 json_writer_t *jw_global;
 
@@ -39,7 +39,7 @@ static void usage(void)
                        "              [ self ] [ master ] [ use ] [ router ]\n"
                        "              [ local | static | dynamic ] [ dst IPADDR ] [ vlan VID ]\n"
                        "              [ port PORT] [ vni VNI ] [ via DEV ]\n");
-       fprintf(stderr, "       bridge fdb [ show [ br BRDEV ] [ brport DEV ] [ vlan VID ] ]\n");
+       fprintf(stderr, "       bridge fdb [ show [ br BRDEV ] [ brport DEV ] [ vlan VID ] [ state STATE ] ]\n");
        exit(-1);
 }
 
@@ -63,6 +63,24 @@ static const char *state_n2a(unsigned int s)
        return buf;
 }
 
+static int state_a2n(unsigned int *s, const char *arg)
+{
+       if (matches(arg, "permanent") == 0)
+               *s = NUD_PERMANENT;
+       else if (matches(arg, "static") == 0 || matches(arg, "temp") == 0)
+               *s = NUD_NOARP;
+       else if (matches(arg, "stale") == 0)
+               *s = NUD_STALE;
+       else if (matches(arg, "reachable") == 0 || matches(arg, "dynamic") == 0)
+               *s = NUD_REACHABLE;
+       else if (strcmp(arg, "all") == 0)
+               *s = ~0;
+       else if (get_unsigned(s, arg, 0))
+               return -1;
+
+       return 0;
+}
+
 static void start_json_fdb_flags_array(bool *fdb_flags)
 {
        if (*fdb_flags)
@@ -100,6 +118,9 @@ int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
        if (filter_index && filter_index != r->ndm_ifindex)
                return 0;
 
+       if (filter_state && !(r->ndm_state & filter_state))
+               return 0;
+
        parse_rtattr(tb, NDA_MAX, NDA_RTA(r),
                     n->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
 
@@ -310,6 +331,13 @@ static int fdb_show(int argc, char **argv)
                        if (filter_vlan)
                                duparg("vlan", *argv);
                        filter_vlan = atoi(*argv);
+               } else if (strcmp(*argv, "state") == 0) {
+                       unsigned int state;
+
+                       NEXT_ARG();
+                       if (state_a2n(&state, *argv))
+                               invarg("invalid state", *argv);
+                       filter_state |= state;
                } else {
                        if (matches(*argv, "help") == 0)
                                usage();
index 6617e188a384716b80a13eb4b0906bcbb0c0e846..9c5f855df72e1e86188a46cedf9f8b0d7de953f1 100644 (file)
@@ -70,7 +70,15 @@ bridge \- show / manipulate bridge addresses and devices
 .ti -8
 .BR "bridge fdb" " [ " show " ] [ "
 .B dev
-.IR DEV " ]"
+.IR DEV " ] [ "
+.B br
+.IR BRDEV " ] [ "
+.B brport
+.IR DEV " ] [ "
+.B vlan
+.IR VID " ] [ "
+.B state
+.IR STATE " ]"
 
 .ti -8
 .BR "bridge mdb" " { " add " | " del " } "