diff --git a/bridge/fdb.c b/bridge/fdb.c index 9a07a327..a55fac1e 100644 --- a/bridge/fdb.c +++ b/bridge/fdb.c @@ -34,7 +34,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 ] [ brport DEV ]\n"); exit(-1); } @@ -161,18 +161,45 @@ int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) static int fdb_show(int argc, char **argv) { + struct { + struct nlmsghdr n; + struct ifinfomsg ifm; + char buf[256]; + } req; + char *filter_dev = NULL; + char *br = NULL; + int msg_size = sizeof(struct ifinfomsg); + + memset(&req, 0, sizeof(req)); + req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); + req.ifm.ifi_family = PF_BRIDGE; while (argc > 0) { - if (strcmp(*argv, "dev") == 0) { + if ((strcmp(*argv, "brport") == 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) { + int br_ifindex = ll_name_to_index(br); + if (br_ifindex == 0) { + fprintf(stderr, "Cannot find bridge device \"%s\"\n", br); + return -1; + } + addattr32(&req.n, sizeof(req), IFLA_MASTER, br_ifindex); + msg_size += RTA_LENGTH(4); + } + + /*we'll keep around filter_dev for older kernels */ if (filter_dev) { filter_index = if_nametoindex(filter_dev); if (filter_index == 0) { @@ -180,9 +207,10 @@ static int fdb_show(int argc, char **argv) filter_dev); return -1; } + req.ifm.ifi_index = filter_index; } - if (rtnl_wilddump_request(&rth, PF_BRIDGE, RTM_GETNEIGH) < 0) { + if (rtnl_dump_request(&rth, RTM_GETNEIGH, &req.ifm, msg_size) < 0) { perror("Cannot send dump request"); exit(1); }