support for bridge fdb and neigh get
Subsystems (2)
v3 cover support for bridge fdb and neigh get
From: Roopa Prabhu <[email protected]>
This series adds iproute2 support to lookup a bridge fdb and neigh entry.
example:
$bridge fdb get 02:02:00:00:00:03 dev test-dummy0 vlan 1002 02:02:00:00:00:03 dev test-dummy0 vlan 1002 master bridge
$ip neigh get 10.0.2.4 dev test-dummy0
10.0.2.4 dev test-dummy0 lladdr de:ad:be:ef:13:37 PERMANENT
v2 - remove cast around stdout in print_fdb as pointed out by stephen
v3 - add Tested by Ivan. and address feedback from david ahern
Roopa Prabhu (2):
bridge: fdb get support
ipneigh: neigh get support
bridge/fdb.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++- ip/ipneigh.c | 72 ++++++++++++++++++++++++++++-- man/man8/bridge.8 | 35 +++++++++++++++ man/man8/ip-neighbour.8 | 25 +++++++++++ 4 files changed, 240 insertions(+), 5 deletions(-)
Signature · 1 line
2.1.4
PATCH v3 1/2 bridge: fdb get support
From: Roopa Prabhu <[email protected]>
This patch adds support to lookup a bridge fdb entry using recently added support in the kernel using RTM_GETNEIGH (and AF_BRIDGE family).
example:
$bridge fdb get 02:02:00:00:00:03 dev test-dummy0 vlan 1002 02:02:00:00:00:03 dev test-dummy0 vlan 1002 master bridge
--- bridge/fdb.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++- man/man8/bridge.8 | 40 +++++++++++++++++++ 2 files changed, 152 insertions(+), 1 deletion(-)
bridge/fdb.c +112 -1
@@ -40,7 +40,9 @@ static void usage(void)" [ sticky ] [ local | static | dynamic ] [ dst IPADDR ]\n" " [ vlan VID ] [ port PORT] [ vni VNI ] [ via DEV ]\n" " [ src_vni VNI ]\n" - " bridge fdb [ show [ br BRDEV ] [ brport DEV ] [ vlan VID ] [ state STATE ] ]\n"); +" bridge fdb [ show [ br BRDEV ] [ brport DEV ] [ vlan VID ] [ state STATE ] ]\n" +" bridge fdb get ADDR [ br BRDEV ] { brport |dev } DEV [ vlan VID ]\n" + " [ vni VNI ]\n");exit (-1 ); }
@@ -518,6 +520,113 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv)return 0 ; } +static int fdb_get (int argc,char **argv) +{ +struct { +struct nlmsghdr n; +struct ndmsg ndm; +char buf[1024 ]; + } req = { + .n.nlmsg_len =NLMSG_LENGTH (sizeof (struct ndmsg )), + .n.nlmsg_flags =NLM_F_REQUEST , + .n.nlmsg_type =RTM_GETNEIGH , + .ndm.ndm_family =AF_BRIDGE , + }; +char *d =NULL , *br =NULL ; +struct nlmsghdr *answer; +unsigned long vni = ~0 ; +char abuf[ETH_ALEN ]; +int br_ifindex =0 ; +char *addr =NULL ; +short vlan =-1 ; +char *endptr; + +while (argc >0 ) { +if ((strcmp (*argv,"brport" ) ==0 ) ||strcmp (*argv,"dev" ) ==0 ) { +NEXT_ARG (); + d = *argv; + }else if (strcmp (*argv,"br" ) ==0 ) { +NEXT_ARG (); + br = *argv; + }else if (strcmp (*argv,"dev" ) ==0 ) { +NEXT_ARG (); + d = *argv; + }else if (strcmp (*argv,"vni" ) ==0 ) { +NEXT_ARG (); + vni =strtoul (*argv, &endptr,0 ); +if ((endptr && *endptr) || + (vni >>24 ) || vni ==ULONG_MAX ) +invarg ("invalid VNI\n" , *argv); + }else if (strcmp (*argv,"self" ) ==0 ) { + req.ndm.ndm_flags |=NTF_SELF ; + }else if (matches (*argv,"master" ) ==0 ) { + req.ndm.ndm_flags |=NTF_MASTER ; + }else if (matches (*argv,"vlan" ) ==0 ) { +if (vlan >=0 ) +duparg2 ("vlan" , *argv); +NEXT_ARG (); + vlan =atoi (*argv); + }else { +if (strcmp (*argv,"to" ) ==0 ) +NEXT_ARG (); + +if (matches (*argv,"help" ) ==0 ) +usage (); +if (addr) +duparg2 ("to" , *argv); + addr = *argv; + } + argc--; argv++; + } + +if ((d ==NULL && br ==NULL ) || addr ==NULL ) { +fprintf (stderr,"Device or master and address are required arguments.\n" ); +return -1 ; + } + +if (sscanf (addr,"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx" , + abuf, abuf+1 , abuf+2 , + abuf+3 , abuf+4 , abuf+5 ) !=6 ) { +fprintf (stderr,"Invalid mac address %s\n" , addr); +return -1 ; + } + +addattr_l (&req.n,sizeof (req),NDA_LLADDR , abuf,ETH_ALEN ); + +if (vlan >=0 ) +addattr16 (&req.n,sizeof (req),NDA_VLAN , vlan); + +if (vni != ~0 ) +addattr32 (&req.n,sizeof (req),NDA_VNI , vni); + +if (d) { + req.ndm.ndm_ifindex =ll_name_to_index (d); +if (!req.ndm.ndm_ifindex) { +fprintf (stderr,"Cannot find device \"%s\"\n" , d); +return -1 ; + } + } + +if (br) { + br_ifindex =ll_name_to_index (br); +if (!br_ifindex) { +fprintf (stderr,"Cannot find bridge device \"%s\"\n" , br); +return -1 ; + } +addattr32 (&req.n,sizeof (req),NDA_MASTER , br_ifindex); + } + +if (rtnl_talk (&rth, &req.n, &answer) <0 ) +return -2 ; + +if (print_fdb (answer, stdout) <0 ) { +fprintf (stderr,"An error :-)\n" ); +return -1 ; + } + +return 0 ; +} +int do_fdb (int argc,char **argv) {ll_init_map (&rth);
@@ -531,6 +640,8 @@ int do_fdb(int argc, char **argv)return fdb_modify (RTM_NEWNEIGH ,NLM_F_CREATE |NLM_F_REPLACE , argc-1 , argv+1 );if (matches (*argv,"delete" ) ==0 )return fdb_modify (RTM_DELNEIGH ,0 , argc-1 , argv+1 ); +if (matches (*argv,"get" ) ==0 ) +return fdb_get (argc-1 , argv+1 );if (matches (*argv,"show" ) ==0 ||matches (*argv,"lst" ) ==0 ||matches (*argv,"list" ) ==0 )
man/man8/bridge.8 +40 -0
@@ -93,6 +93,17 @@ bridge \- show / manipulate bridge addresses and devices .IR STATE " ]" .ti -8 +.B bridge fdb get +.I LLADDR " [ " +.B dev +.IR DEV " ] [ " +.B br +.IR BRDEV " ] [ " +.B vlan +.IR VID " ] [" +.BR self " ] [ " master " ]" + +.ti -8 .BR "bridge mdb" " { " add " | " del " } " .B dev .IR DEV
@@ -550,6 +561,35 @@ With the option, the command becomes verbose. It prints out the last updated and last used time for each entry. +.SS bridge fdb get - get bridge forwarding entry. + +lookup a bridge forwarding table entry. + +.TP +.BI "LLADDR" +the Ethernet MAC address. + +.TP +.BI dev " DEV" +the interface to which this address is associated. + +.TP +.BI brport " DEV" +the bridge port to which this address is associated. same as dev above. + +.TP +.BI br " DEV" +the bridge to which this address is associated. + +.TP +.B self +- the address is associated with the port drivers fdb. Usually hardware. + +.TP +.B master +- the address is associated with master devices fdb. Usually software (default). +.sp + .SH bridge mdb - multicast group database management .B mdb
Signature · 1 line
2.1.4
Re: [PATCH iproute2 net-next v3 1/2] bridge: fdb get support
bridge/fdb.c static int fdb_modify(int cmd, int flags, int argc, char **argv) · line 592
Quoted 7 lines · On Mon, 30 Sep 2019 21:52:22 -0700 Roopa Prabhu <[email protected]>…
bridge/fdb.c +7
-0+ +if (sscanf (addr,"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx" , + abuf, abuf+1 , abuf+2 , + abuf+3 , abuf+4 , abuf+5 ) !=6 ) { +fprintf (stderr,"Invalid mac address %s\n" , addr); +return -1 ; + }
You could use ether_aton here if that would help. Not required, but ether_ntoa already used in iplink_bridge.c
Re: [PATCH iproute2 net-next v3 1/2] bridge: fdb get support
Quoted 12 lines · Stephen Hemminger
bridge/fdb.c static int fdb_modify(int cmd, int flags, int argc, char **argv) · line 592
Quoted 7 lines · On Mon, 30 Sep 2019 21:52:22 -0700 Roopa Prabhu <[email protected]>…
bridge/fdb.c +7
-0+ +if (sscanf (addr,"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx" , + abuf, abuf+1 , abuf+2 , + abuf+3 , abuf+4 , abuf+5 ) !=6 ) { +fprintf (stderr,"Invalid mac address %s\n" , addr); +return -1 ; + }
Quoted 2 lines
You could use
ether_atonhere if that would help. Not required, butether_ntoaalready used iniplink_bridge.
ok ack, i will take a look. I think i picked this up from bridge/fdb.c:fdb_modify
PATCH v3 2/2 ipneigh: neigh get support
In reply to Roopa PrabhuFrom: Roopa Prabhu <[email protected]>
This patch adds support to lookup a neigh entry using recently added support in the kernel using RTM_GETNEIGH
example:
$ip neigh get 10.0.2.4 dev test-dummy0
10.0.2.4 dev test-dummy0 lladdr de:ad:be:ef:13:37 PERMANENT
--- ip/ipneigh.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++--- man/man8/ip-neighbour.8 | 29 +++++++++++++++++ 2 files changed, 108 insertions(+), 4 deletions(-)
ip/ipneigh.c +79 -4
@@ -55,6 +55,7 @@ static void usage(void)"\n" " ip neigh { show | flush } [ proxy ] [ to PREFIX ] [ dev DEV ] [ nud STATE ]\n" " [ vrf NAME ]\n" +" ip neigh get { ADDR | proxy ADDR } dev DEV\n" "\n" "STATE := { permanent | noarp | stale | reachable | none |\n" " incomplete | delay | probe | failed }\n");
@@ -599,6 +600,82 @@ static int do_show_or_flush(int argc, char **argv, int flush)return 0 ; } +static int ipneigh_get (int argc,char **argv) +{ +struct { +struct nlmsghdr n; +struct ndmsg ndm; +char buf[1024 ]; + } req = { + .n.nlmsg_len =NLMSG_LENGTH (sizeof (struct ndmsg )), + .n.nlmsg_flags =NLM_F_REQUEST , + .n.nlmsg_type =RTM_GETNEIGH , + .ndm.ndm_family = preferred_family, + }; +struct nlmsghdr *answer; +char *d =NULL ; +int dst_ok =0 ; +int dev_ok =0 ; +inet_prefix dst; + +while (argc >0 ) { +if (strcmp (*argv,"dev" ) ==0 ) { +NEXT_ARG (); + d = *argv; + dev_ok =1 ; + }else if (matches (*argv,"proxy" ) ==0 ) { +NEXT_ARG (); +if (matches (*argv,"help" ) ==0 ) +usage (); +if (dst_ok) +duparg ("address" , *argv); +get_addr (&dst, *argv, preferred_family); + dst_ok =1 ; + dev_ok =1 ; + req.ndm.ndm_flags |=NTF_PROXY ; + }else { +if (strcmp (*argv,"to" ) ==0 ) +NEXT_ARG (); + +if (matches (*argv,"help" ) ==0 ) +usage (); +if (dst_ok) +duparg2 ("to" , *argv); +get_addr (&dst, *argv, preferred_family); + dst_ok =1 ; + } + argc--; argv++; + } + +if (!dev_ok || !dst_ok || dst.family ==AF_UNSPEC ) { +fprintf (stderr,"Device and address are required arguments.\n" ); +return -1 ; + } + + req.ndm.ndm_family = dst.family; +if (addattr_l (&req.n,sizeof (req),NDA_DST , &dst.data, dst.bytelen) <0 ) +return -1 ; + +if (d) { + req.ndm.ndm_ifindex =ll_name_to_index (d); +if (!req.ndm.ndm_ifindex) { +fprintf (stderr,"Cannot find device \"%s\"\n" , d); +return -1 ; + } + } + +if (rtnl_talk (&rth, &req.n, &answer) <0 ) +return -2 ; + +ipneigh_reset_filter (0 ); +if (print_neigh (answer, stdout) <0 ) { +fprintf (stderr,"An error :-)\n" ); +return -1 ; + } + +return 0 ; +} +int do_ipneigh (int argc,char **argv) {if (argc >0 ) {
@@ -611,10 +688,8 @@ int do_ipneigh(int argc, char **argv)return ipneigh_modify (RTM_NEWNEIGH ,NLM_F_CREATE |NLM_F_REPLACE , argc-1 , argv+1 );if (matches (*argv,"delete" ) ==0 )return ipneigh_modify (RTM_DELNEIGH ,0 , argc-1 , argv+1 ); -if (matches (*argv,"get" ) ==0 ) { -fprintf (stderr,"Sorry, \"neigh get\" is not implemented :-(\n" ); -return -1 ; - } +if (matches (*argv,"get" ) ==0 ) +return ipneigh_get (argc-1 , argv+1 );if (matches (*argv,"show" ) ==0 ||matches (*argv,"lst" ) ==0 ||matches (*argv,"list" ) ==0 )
man/man8/ip-neighbour.8 +29 -0
@@ -38,6 +38,12 @@ ip-neighbour \- neighbour/arp tables management. .IR NAME " ] " .ti -8 +.B ip neigh get +.IR ADDR +.B dev +.IR DEV + +.ti -8 .IR STATE " := {" .BR permanent " | " noarp " | " stale " | " reachable " | " none " |" .BR incomplete " | " delay " | " probe " | " failed " }"
@@ -231,6 +237,23 @@ twice, also dumps all the deleted neighbours. .RE +.TP +ip neigh get +lookup a neighbour entry to a destination given a device +.RS + +.TP +.BI proxy +indicates whether we should lookup a proxy neigbour entry + +.TP +.BI to " ADDRESS " (default) +the prefix selecting the neighbour to query. + +.TP +.BI dev " NAME" +get neighbour entry attached to this device. + .SH EXAMPLES .PP ip neighbour
@@ -242,6 +265,12 @@ ip neigh flush dev eth0 .RS Removes entries in the neighbour table on device eth0. .RE +.PP +ip neigh get 10.0.1.10 dev eth0 +.RS +Performs a neighbour lookup in the kernel and returns +a neighbour entry. +.RE .SH SEE ALSO .br
Signature · 1 line
2.1.4
David Ahern
AppliedQuoted 21 lines · Roopa Prabhu
From: Roopa Prabhu <[email protected]>
This series adds iproute2 support to lookup a bridge fdb and neigh entry.
example:
$bridge fdb get 02:02:00:00:00:03 dev test-dummy0 vlan 1002 02:02:00:00:00:03 dev test-dummy0 vlan 1002 master bridge$ip neigh get 10.0.2.4 dev test-dummy0
10.0.2.4 dev test-dummy0 lladdr de:ad:be:ef:13:37 PERMANENTv2 - remove cast around stdout in
print_fdbas pointed out by stephenv3 - add Tested by Ivan. and address feedback from david ahern
Roopa Prabhu (2):
bridge: fdb get support
ipneigh: neigh get support
Quoted 6 lines
bridge/fdb.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++- ip/ipneigh.c | 72 ++++++++++++++++++++++++++++-- man/man8/bridge.8 | 35 +++++++++++++++ man/man8/ip-neighbour.8 | 25 +++++++++++ 4 files changed, 240 insertions(+), 5 deletions(-)
applied to iproute2-next. Thanks