netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2 net-next v3 0/2] support for bridge fdb and neigh get
@ 2019-10-01  4:52 Roopa Prabhu
  2019-10-01  4:52 ` [PATCH iproute2 net-next v3 1/2] bridge: fdb get support Roopa Prabhu
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Roopa Prabhu @ 2019-10-01  4:52 UTC (permalink / raw)
  To: dsahern; +Cc: netdev, ivecera, nikolay, stephen

From: Roopa Prabhu <roopa@cumulusnetworks.com>

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(-)

-- 
2.1.4


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH iproute2 net-next v3 1/2] bridge: fdb get support
  2019-10-01  4:52 [PATCH iproute2 net-next v3 0/2] support for bridge fdb and neigh get Roopa Prabhu
@ 2019-10-01  4:52 ` Roopa Prabhu
  2019-10-01 14:59   ` Stephen Hemminger
  2019-10-01  4:52 ` [PATCH iproute2 net-next v3 2/2] ipneigh: neigh " Roopa Prabhu
  2019-10-01 15:30 ` [PATCH iproute2 net-next v3 0/2] support for bridge fdb and neigh get David Ahern
  2 siblings, 1 reply; 6+ messages in thread
From: Roopa Prabhu @ 2019-10-01  4:52 UTC (permalink / raw)
  To: dsahern; +Cc: netdev, ivecera, nikolay, stephen

From: Roopa Prabhu <roopa@cumulusnetworks.com>

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

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Tested-by: Ivan Vecera <ivecera@redhat.com>
---
 bridge/fdb.c      | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 man/man8/bridge.8 |  40 +++++++++++++++++++
 2 files changed, 152 insertions(+), 1 deletion(-)

diff --git a/bridge/fdb.c b/bridge/fdb.c
index 941ce2d..710dfc9 100644
--- a/bridge/fdb.c
+++ b/bridge/fdb.c
@@ -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)
diff --git a/man/man8/bridge.8 b/man/man8/bridge.8
index bb4fb52..10f6cf0 100644
--- a/man/man8/bridge.8
+++ b/man/man8/bridge.8
@@ -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
-- 
2.1.4


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH iproute2 net-next v3 2/2] ipneigh: neigh get support
  2019-10-01  4:52 [PATCH iproute2 net-next v3 0/2] support for bridge fdb and neigh get Roopa Prabhu
  2019-10-01  4:52 ` [PATCH iproute2 net-next v3 1/2] bridge: fdb get support Roopa Prabhu
@ 2019-10-01  4:52 ` Roopa Prabhu
  2019-10-01 15:30 ` [PATCH iproute2 net-next v3 0/2] support for bridge fdb and neigh get David Ahern
  2 siblings, 0 replies; 6+ messages in thread
From: Roopa Prabhu @ 2019-10-01  4:52 UTC (permalink / raw)
  To: dsahern; +Cc: netdev, ivecera, nikolay, stephen

From: Roopa Prabhu <roopa@cumulusnetworks.com>

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

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Tested-by: Ivan Vecera <ivecera@redhat.com>
---
 ip/ipneigh.c            | 83 ++++++++++++++++++++++++++++++++++++++++++++++---
 man/man8/ip-neighbour.8 | 29 +++++++++++++++++
 2 files changed, 108 insertions(+), 4 deletions(-)

diff --git a/ip/ipneigh.c b/ip/ipneigh.c
index a3869c8..678b403 100644
--- a/ip/ipneigh.c
+++ b/ip/ipneigh.c
@@ -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)
diff --git a/man/man8/ip-neighbour.8 b/man/man8/ip-neighbour.8
index 4a672bb..bc77b43 100644
--- a/man/man8/ip-neighbour.8
+++ b/man/man8/ip-neighbour.8
@@ -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
-- 
2.1.4


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH iproute2 net-next v3 1/2] bridge: fdb get support
  2019-10-01  4:52 ` [PATCH iproute2 net-next v3 1/2] bridge: fdb get support Roopa Prabhu
@ 2019-10-01 14:59   ` Stephen Hemminger
  2019-10-02 16:07     ` Roopa Prabhu
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2019-10-01 14:59 UTC (permalink / raw)
  To: Roopa Prabhu; +Cc: dsahern, netdev, ivecera, nikolay

On Mon, 30 Sep 2019 21:52:22 -0700
Roopa Prabhu <roopa@cumulusnetworks.com> wrote:

> +
> +	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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH iproute2 net-next v3 0/2] support for bridge fdb and neigh get
  2019-10-01  4:52 [PATCH iproute2 net-next v3 0/2] support for bridge fdb and neigh get Roopa Prabhu
  2019-10-01  4:52 ` [PATCH iproute2 net-next v3 1/2] bridge: fdb get support Roopa Prabhu
  2019-10-01  4:52 ` [PATCH iproute2 net-next v3 2/2] ipneigh: neigh " Roopa Prabhu
@ 2019-10-01 15:30 ` David Ahern
  2 siblings, 0 replies; 6+ messages in thread
From: David Ahern @ 2019-10-01 15:30 UTC (permalink / raw)
  To: Roopa Prabhu; +Cc: netdev, ivecera, nikolay, stephen

On 9/30/19 10:52 PM, Roopa Prabhu wrote:
> From: Roopa Prabhu <roopa@cumulusnetworks.com>
> 
> 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(-)
> 

applied to iproute2-next. Thanks

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH iproute2 net-next v3 1/2] bridge: fdb get support
  2019-10-01 14:59   ` Stephen Hemminger
@ 2019-10-02 16:07     ` Roopa Prabhu
  0 siblings, 0 replies; 6+ messages in thread
From: Roopa Prabhu @ 2019-10-02 16:07 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: David Ahern, netdev, Ivan Vecera, Nikolay Aleksandrov

On Tue, Oct 1, 2019 at 7:59 AM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> On Mon, 30 Sep 2019 21:52:22 -0700
> Roopa Prabhu <roopa@cumulusnetworks.com> wrote:
>
> > +
> > +     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.

ok ack, i will take a look. I think i picked this up from
bridge/fdb.c:fdb_modify

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-10-02 16:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-01  4:52 [PATCH iproute2 net-next v3 0/2] support for bridge fdb and neigh get Roopa Prabhu
2019-10-01  4:52 ` [PATCH iproute2 net-next v3 1/2] bridge: fdb get support Roopa Prabhu
2019-10-01 14:59   ` Stephen Hemminger
2019-10-02 16:07     ` Roopa Prabhu
2019-10-01  4:52 ` [PATCH iproute2 net-next v3 2/2] ipneigh: neigh " Roopa Prabhu
2019-10-01 15:30 ` [PATCH iproute2 net-next v3 0/2] support for bridge fdb and neigh get David Ahern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).