|
|
4aca6e |
From 93a55d061ebebecdbb4af950771ebc371675b6cf Mon Sep 17 00:00:00 2001
|
|
|
4aca6e |
From: Phil Sutter <psutter@redhat.com>
|
|
|
4aca6e |
Date: Tue, 28 Feb 2017 16:09:45 +0100
|
|
|
4aca6e |
Subject: [PATCH] iproute2 bridge: bring to above par with brctl show macs
|
|
|
4aca6e |
|
|
|
4aca6e |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1417289
|
|
|
4aca6e |
Upstream Status: iproute2.git commit aeb14eb0b2649
|
|
|
4aca6e |
|
|
|
4aca6e |
commit aeb14eb0b2649ae6048b9cc0a10152079035ee92
|
|
|
4aca6e |
Author: Jamal Hadi Salim <jhs@mojatatu.com>
|
|
|
4aca6e |
Date: Fri Jul 4 08:37:10 2014 -0400
|
|
|
4aca6e |
|
|
|
4aca6e |
iproute2 bridge: bring to above par with brctl show macs
|
|
|
4aca6e |
|
|
|
4aca6e |
root@moja-mojo:bridge# ./bridge fdb help
|
|
|
4aca6e |
Usage: bridge fdb { add | append | del | replace } ADDR dev DEV {self|master} [ temp ]
|
|
|
4aca6e |
[router] [ dst IPADDR] [ vlan VID ]
|
|
|
4aca6e |
[ port PORT] [ vni VNI ] [via DEV]
|
|
|
4aca6e |
bridge fdb {show} [ br BRDEV ] [ brport DEV ]
|
|
|
4aca6e |
|
|
|
4aca6e |
Lets start with two bridges each with a port...
|
|
|
4aca6e |
|
|
|
4aca6e |
root@moja-mojo:bridge# ./bridge link
|
|
|
4aca6e |
10: sw1-p1 state DOWN : <BROADCAST,NOARP> mtu 1500 master sw1 state disabled priority 32 cost 100
|
|
|
4aca6e |
11: eth1 state DOWN : <BROADCAST,NOARP> mtu 1500 master br0 state disabled priority 32 cost 100
|
|
|
4aca6e |
|
|
|
4aca6e |
show all...
|
|
|
4aca6e |
root@moja-mojo:bridge# ./bridge fdb show
|
|
|
4aca6e |
33:33:00:00:00:01 dev ifb0 self permanent
|
|
|
4aca6e |
33:33:00:00:00:01 dev ifb1 self permanent
|
|
|
4aca6e |
33:33:00:00:00:01 dev eth0 self permanent
|
|
|
4aca6e |
01:00:5e:00:00:01 dev eth0 self permanent
|
|
|
4aca6e |
33:33:ff:92:c0:60 dev eth0 self permanent
|
|
|
4aca6e |
33:33:00:00:00:fb dev eth0 self permanent
|
|
|
4aca6e |
01:00:5e:00:00:fb dev eth0 self permanent
|
|
|
4aca6e |
01:00:5e:7f:ff:fd dev eth0 self permanent
|
|
|
4aca6e |
01:00:5e:00:00:01 dev wlan0 self permanent
|
|
|
4aca6e |
33:33:00:00:00:01 dev wlan0 self permanent
|
|
|
4aca6e |
33:33:ff:c2:84:3b dev wlan0 self permanent
|
|
|
4aca6e |
33:33:00:00:00:fb dev wlan0 self permanent
|
|
|
4aca6e |
01:00:5e:00:00:01 dev virbr0 self permanent
|
|
|
4aca6e |
01:00:5e:00:00:fb dev virbr0 self permanent
|
|
|
4aca6e |
33:33:00:00:00:01 dev br0 self permanent
|
|
|
4aca6e |
33:33:00:00:00:01 dev sw1 self permanent
|
|
|
4aca6e |
33:33:00:00:00:01 dev dummy0 self permanent
|
|
|
4aca6e |
5e:f4:03:44:da:9a dev sw1-p1 vlan 0 master sw1 permanent
|
|
|
4aca6e |
33:33:00:00:00:01 dev sw1-p1 self permanent
|
|
|
4aca6e |
b6:5e:dd:ce:d7:5e dev eth1 vlan 0 master br0 permanent
|
|
|
4aca6e |
33:33:00:00:00:01 dev eth1 self permanent
|
|
|
4aca6e |
|
|
|
4aca6e |
Lets see a netdev that is *not* attached to a bridge
|
|
|
4aca6e |
|
|
|
4aca6e |
root@moja-mojo:bridge# ./bridge fdb show brport eth0
|
|
|
4aca6e |
33:33:00:00:00:01 self permanent
|
|
|
4aca6e |
01:00:5e:00:00:01 self permanent
|
|
|
4aca6e |
33:33:ff:92:c0:60 self permanent
|
|
|
4aca6e |
33:33:00:00:00:fb self permanent
|
|
|
4aca6e |
01:00:5e:00:00:fb self permanent
|
|
|
4aca6e |
01:00:5e:7f:ff:fd self permanent
|
|
|
4aca6e |
|
|
|
4aca6e |
Lets see a netdev that is bridge port
|
|
|
4aca6e |
root@moja-mojo:bridge# ./bridge fdb show brport eth1
|
|
|
4aca6e |
hadi@jhs-1:/media/MT1/other-gits/iproute-jul04/bridge$ ./bridge fdb show brport eth1
|
|
|
4aca6e |
b6:5e:dd:ce:d7:5e vlan 0 master br0 permanent
|
|
|
4aca6e |
33:33:00:00:00:01 self permanent
|
|
|
4aca6e |
|
|
|
4aca6e |
Specify the correct bridge and you get good stuff
|
|
|
4aca6e |
root@moja-mojo:bridge# ./bridge fdb show brport eth1 br br0
|
|
|
4aca6e |
6:5e:dd:ce:d7:5e vlan 0 master br0 permanent
|
|
|
4aca6e |
33:33:00:00:00:01 self permanent
|
|
|
4aca6e |
|
|
|
4aca6e |
Specify the wrong bridge and you get good nada
|
|
|
4aca6e |
root@moja-mojo:bridge# ./bridge fdb show brport eth1 br sw1
|
|
|
4aca6e |
|
|
|
4aca6e |
dump br0
|
|
|
4aca6e |
root@moja-mojo:bridge# ./bridge fdb show br br0
|
|
|
4aca6e |
33:33:00:00:00:01 dev br0 self permanent
|
|
|
4aca6e |
b6:5e:dd:ce:d7:5e dev eth1 vlan 0 master br0 permanent
|
|
|
4aca6e |
33:33:00:00:00:01 dev eth1 self permanent
|
|
|
4aca6e |
|
|
|
4aca6e |
dump sw1
|
|
|
4aca6e |
root@moja-mojo:bridge# ./bridge fdb show br sw1
|
|
|
4aca6e |
33:33:00:00:00:01 dev sw1 self permanent
|
|
|
4aca6e |
5e:f4:03:44:da:9a dev sw1-p1 vlan 0 master sw1 permanent
|
|
|
4aca6e |
33:33:00:00:00:01 dev sw1-p1 self permanent
|
|
|
4aca6e |
|
|
|
4aca6e |
Lets move a port from one bridge to another for shits-and-giggles
|
|
|
4aca6e |
(as the New Brunswickians like to say)
|
|
|
4aca6e |
root@moja-mojo:bridge# ip link set sw1-p1 master br0
|
|
|
4aca6e |
|
|
|
4aca6e |
Now dump again br0
|
|
|
4aca6e |
root@moja-mojo:bridge# ./bridge fdb show br br0
|
|
|
4aca6e |
33:33:00:00:00:01 dev br0 self permanent
|
|
|
4aca6e |
5e:f4:03:44:da:9a dev sw1-p1 vlan 0 master br0 permanent
|
|
|
4aca6e |
33:33:00:00:00:01 dev sw1-p1 self permanent
|
|
|
4aca6e |
b6:5e:dd:ce:d7:5e dev eth1 vlan 0 master br0 permanent
|
|
|
4aca6e |
33:33:00:00:00:01 dev eth1 self permanent
|
|
|
4aca6e |
|
|
|
4aca6e |
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
|
|
|
4aca6e |
---
|
|
|
4aca6e |
bridge/fdb.c | 38 +++++++++++++++++++++++++++++++++-----
|
|
|
4aca6e |
1 file changed, 33 insertions(+), 5 deletions(-)
|
|
|
4aca6e |
|
|
|
4aca6e |
diff --git a/bridge/fdb.c b/bridge/fdb.c
|
|
|
4aca6e |
index b29c776..97385d0 100644
|
|
|
4aca6e |
--- a/bridge/fdb.c
|
|
|
4aca6e |
+++ b/bridge/fdb.c
|
|
|
4aca6e |
@@ -34,7 +34,7 @@ static void usage(void)
|
|
|
4aca6e |
" [ self ] [ master ] [ use ] [ router ]\n"
|
|
|
4aca6e |
" [ local | temp ] [ dst IPADDR ] [ vlan VID ]\n"
|
|
|
4aca6e |
" [ port PORT] [ vni VNI ] [via DEV]\n");
|
|
|
4aca6e |
- fprintf(stderr, " bridge fdb {show} [ dev DEV ]\n");
|
|
|
4aca6e |
+ fprintf(stderr, " bridge fdb {show} [ br BRDEV ] [ brport DEV ]\n");
|
|
|
4aca6e |
exit(-1);
|
|
|
4aca6e |
}
|
|
|
4aca6e |
|
|
|
4aca6e |
@@ -165,18 +165,45 @@ int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|
|
4aca6e |
|
|
|
4aca6e |
static int fdb_show(int argc, char **argv)
|
|
|
4aca6e |
{
|
|
|
4aca6e |
+ struct {
|
|
|
4aca6e |
+ struct nlmsghdr n;
|
|
|
4aca6e |
+ struct ifinfomsg ifm;
|
|
|
4aca6e |
+ char buf[256];
|
|
|
4aca6e |
+ } req;
|
|
|
4aca6e |
+
|
|
|
4aca6e |
char *filter_dev = NULL;
|
|
|
4aca6e |
+ char *br = NULL;
|
|
|
4aca6e |
+ int msg_size = sizeof(struct ifinfomsg);
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+ memset(&req, 0, sizeof(req));
|
|
|
4aca6e |
+ req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
|
|
|
4aca6e |
+ req.ifm.ifi_family = PF_BRIDGE;
|
|
|
4aca6e |
|
|
|
4aca6e |
while (argc > 0) {
|
|
|
4aca6e |
- if (strcmp(*argv, "dev") == 0) {
|
|
|
4aca6e |
+ if ((strcmp(*argv, "brport") == 0) || strcmp(*argv, "dev") == 0) {
|
|
|
4aca6e |
NEXT_ARG();
|
|
|
4aca6e |
- if (filter_dev)
|
|
|
4aca6e |
- duparg("dev", *argv);
|
|
|
4aca6e |
filter_dev = *argv;
|
|
|
4aca6e |
+ } else if (strcmp(*argv, "br") == 0) {
|
|
|
4aca6e |
+ NEXT_ARG();
|
|
|
4aca6e |
+ br = *argv;
|
|
|
4aca6e |
+ } else {
|
|
|
4aca6e |
+ if (matches(*argv, "help") == 0)
|
|
|
4aca6e |
+ usage();
|
|
|
4aca6e |
}
|
|
|
4aca6e |
argc--; argv++;
|
|
|
4aca6e |
}
|
|
|
4aca6e |
|
|
|
4aca6e |
+ if (br) {
|
|
|
4aca6e |
+ int br_ifindex = ll_name_to_index(br);
|
|
|
4aca6e |
+ if (br_ifindex == 0) {
|
|
|
4aca6e |
+ fprintf(stderr, "Cannot find bridge device \"%s\"\n", br);
|
|
|
4aca6e |
+ return -1;
|
|
|
4aca6e |
+ }
|
|
|
4aca6e |
+ addattr32(&req.n, sizeof(req), IFLA_MASTER, br_ifindex);
|
|
|
4aca6e |
+ msg_size += RTA_LENGTH(4);
|
|
|
4aca6e |
+ }
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+ /*we'll keep around filter_dev for older kernels */
|
|
|
4aca6e |
if (filter_dev) {
|
|
|
4aca6e |
filter_index = if_nametoindex(filter_dev);
|
|
|
4aca6e |
if (filter_index == 0) {
|
|
|
4aca6e |
@@ -184,9 +211,10 @@ static int fdb_show(int argc, char **argv)
|
|
|
4aca6e |
filter_dev);
|
|
|
4aca6e |
return -1;
|
|
|
4aca6e |
}
|
|
|
4aca6e |
+ req.ifm.ifi_index = filter_index;
|
|
|
4aca6e |
}
|
|
|
4aca6e |
|
|
|
4aca6e |
- if (rtnl_wilddump_request(&rth, PF_BRIDGE, RTM_GETNEIGH) < 0) {
|
|
|
4aca6e |
+ if (rtnl_dump_request(&rth, RTM_GETNEIGH, &req.ifm, msg_size) < 0) {
|
|
|
4aca6e |
perror("Cannot send dump request");
|
|
|
4aca6e |
exit(1);
|
|
|
4aca6e |
}
|
|
|
4aca6e |
--
|
|
|
4aca6e |
1.8.3.1
|
|
|
4aca6e |
|