diff --git a/bridge/fdb.c b/bridge/fdb.c index e2e53f1..f3073d6 100644 --- a/bridge/fdb.c +++ b/bridge/fdb.c @@ -33,7 +33,7 @@ static void usage(void) fprintf(stderr, "Usage: bridge fdb { add | append | del | replace } ADDR dev DEV {self|master} [ temp ]\n" " [router] [ dst IPADDR] [ vlan VID ]\n" " [ port PORT] [ vni VNI ] [via DEV]\n"); - fprintf(stderr, " bridge fdb {show} [ dev DEV ]\n"); + fprintf(stderr, " bridge fdb {show} [ br BRDEV ] [ dev DEV ]\n"); exit(-1); } @@ -152,18 +152,35 @@ int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) static int fdb_show(int argc, char **argv) { + struct ndmsg ndm = { }; char *filter_dev = NULL; + char *br = NULL; + + ndm.ndm_family = PF_BRIDGE; + ndm.ndm_state = NUD_NOARP; while (argc > 0) { - if (strcmp(*argv, "dev") == 0) { + if ((strcmp(*argv, "port") == 0) || strcmp(*argv, "dev") == 0) { NEXT_ARG(); - if (filter_dev) - duparg("dev", *argv); filter_dev = *argv; + } else if (strcmp(*argv, "br") == 0) { + NEXT_ARG(); + br = *argv; + } else { + if (matches(*argv, "help") == 0) + usage(); } argc--; argv++; } + if (br) { + ndm.ndm_ifindex = ll_name_to_index(br); + if (ndm.ndm_ifindex == 0) { + fprintf(stderr, "Cannot find bridge device \"%s\"\n", br); + return -1; + } + } + if (filter_dev) { filter_index = if_nametoindex(filter_dev); if (filter_index == 0) { @@ -171,13 +188,15 @@ static int fdb_show(int argc, char **argv) filter_dev); return -1; } + } - if (rtnl_wilddump_request(&rth, PF_BRIDGE, RTM_GETNEIGH) < 0) { + if (rtnl_dump_request(&rth, RTM_GETNEIGH, &ndm, sizeof(struct ndmsg)) < 0) { perror("Cannot send dump request"); exit(1); } + if (rtnl_dump_filter(&rth, print_fdb, stdout) < 0) { fprintf(stderr, "Dump terminated\n"); exit(1);