]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
bridge: mdb: add support to filter by vlan id
authorNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Mon, 11 Apr 2016 15:45:15 +0000 (17:45 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 11 Apr 2016 21:52:47 +0000 (21:52 +0000)
Add the optional keyword "vid" to bridge mdb show so the user can
request filtering by a specific vlan id. Currently the filtering is
implemented only in user-space. The argument name has been chosen to match
the add/del one - "vid".

Example:
$ bridge mdb show vid 200
dev br0 port eth2 grp 239.0.0.1 permanent vid 200

Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
bridge/mdb.c

index 842536ec003cde95a621adcd16f06740a4d55d45..6c904f8e6ae84e99dd47d1dadd0e581a642eda53 100644 (file)
        ((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct br_port_msg))))
 #endif
 
-static unsigned int filter_index;
+static unsigned int filter_index, filter_vlan;
 
 static void usage(void)
 {
        fprintf(stderr, "Usage: bridge mdb { add | del } dev DEV port PORT grp GROUP [permanent | temp] [vid VID]\n");
-       fprintf(stderr, "       bridge mdb {show} [ dev DEV ]\n");
+       fprintf(stderr, "       bridge mdb {show} [ dev DEV ] [ vid VID ]\n");
        exit(-1);
 }
 
@@ -92,6 +92,8 @@ static void print_mdb_entry(FILE *f, int ifindex, struct br_mdb_entry *e,
        const void *src;
        int af;
 
+       if (filter_vlan && e->vid != filter_vlan)
+               return;
        af = e->addr.proto == htons(ETH_P_IP) ? AF_INET : AF_INET6;
        src = af == AF_INET ? (const void *)&e->addr.u.ip4 :
                              (const void *)&e->addr.u.ip6;
@@ -195,6 +197,11 @@ static int mdb_show(int argc, char **argv)
                        if (filter_dev)
                                duparg("dev", *argv);
                        filter_dev = *argv;
+               } else if (strcmp(*argv, "vid") == 0) {
+                       NEXT_ARG();
+                       if (filter_vlan)
+                               duparg("vid", *argv);
+                       filter_vlan = atoi(*argv);
                }
                argc--; argv++;
        }