netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2] ip: Properly display AF_BRIDGE address information for neighbor events
@ 2018-02-22  2:26 Donald Sharp
  2018-02-23 16:28 ` Stephen Hemminger
  2018-02-23 19:10 ` [PATCH iproute2 v2] " Donald Sharp
  0 siblings, 2 replies; 4+ messages in thread
From: Donald Sharp @ 2018-02-22  2:26 UTC (permalink / raw)
  To: netdev, stephen

The vxlan driver when a neighbor add/delete event occurs sends
NDA_DST filled with a union:

union vxlan_addr {
	struct sockaddr_in sin;
	struct sockaddr_in6 sin6;
	struct sockaddr sa;
};

This eventually calls rt_addr_n2a_r which had no handler for the
AF_BRIDGE family and "???" was being printed.

Add code to properly display this data when requested.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
---
 lib/utils.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/lib/utils.c b/lib/utils.c
index 24aeddd8..e01e18a7 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -1004,6 +1004,24 @@ const char *rt_addr_n2a_r(int af, int len,
 	}
 	case AF_PACKET:
 		return ll_addr_n2a(addr, len, ARPHRD_VOID, buf, buflen);
+	case AF_BRIDGE:
+	{
+		unsigned short family = ((struct sockaddr *)addr)->sa_family;
+		struct sockaddr_in6 *sin6;
+		struct sockaddr_in *sin;
+
+		switch(family) {
+		case AF_INET:
+			sin = (struct sockaddr_in *)addr;
+			return inet_ntop(AF_INET, &sin->sin_addr, buf, buflen);
+		case AF_INET6:
+			sin6 = (struct sockaddr_in6 *)addr;
+			return inet_ntop(AF_INET6, &sin6->sin6_addr,
+					 buf, buflen);
+		}
+
+		/* fallthrough */
+	}
 	default:
 		return "???";
 	}
-- 
2.14.3

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

* Re: [PATCH iproute2] ip: Properly display AF_BRIDGE address information for neighbor events
  2018-02-22  2:26 [PATCH iproute2] ip: Properly display AF_BRIDGE address information for neighbor events Donald Sharp
@ 2018-02-23 16:28 ` Stephen Hemminger
  2018-02-23 19:10 ` [PATCH iproute2 v2] " Donald Sharp
  1 sibling, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2018-02-23 16:28 UTC (permalink / raw)
  To: Donald Sharp; +Cc: netdev

On Wed, 21 Feb 2018 21:26:50 -0500
Donald Sharp <sharpd@cumulusnetworks.com> wrote:

> The vxlan driver when a neighbor add/delete event occurs sends
> NDA_DST filled with a union:
> 
> union vxlan_addr {
> 	struct sockaddr_in sin;
> 	struct sockaddr_in6 sin6;
> 	struct sockaddr sa;
> };
> 
> This eventually calls rt_addr_n2a_r which had no handler for the
> AF_BRIDGE family and "???" was being printed.
> 
> Add code to properly display this data when requested.
> 
> Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>

Minor style comment.

> ---
>  lib/utils.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/lib/utils.c b/lib/utils.c
> index 24aeddd8..e01e18a7 100644
> --- a/lib/utils.c
> +++ b/lib/utils.c
> @@ -1004,6 +1004,24 @@ const char *rt_addr_n2a_r(int af, int len,
>  	}
>  	case AF_PACKET:
>  		return ll_addr_n2a(addr, len, ARPHRD_VOID, buf, buflen);
> +	case AF_BRIDGE:
> +	{
> +		unsigned short family = ((struct sockaddr *)addr)->sa_family;
> +		struct sockaddr_in6 *sin6;
> +		struct sockaddr_in *sin;
> +

Since you are doing aliasing, would it be clearer to do?
		union {
			struct sockaddr sa;
			struct sockaddr_in6 sin6;
			struct sockaddr_in sin;
		} *sa = addr;

> +		switch(family) {
> +		case AF_INET:
> +			sin = (struct sockaddr_in *)addr;
Casting a void pointer is unnecessary

> +			return inet_ntop(AF_INET, &sin->sin_addr, buf, buflen);
> +		case AF_INET6:
> +			sin6 = (struct sockaddr_in6 *)addr;
> +			return inet_ntop(AF_INET6, &sin6->sin6_addr,
> +					 buf, buflen);
> +		}
> +
> +		/* fallthrough */
> +	}
>  	default:
>  		return "???";
>  	}

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

* [PATCH iproute2 v2] ip: Properly display AF_BRIDGE address information for neighbor events
  2018-02-22  2:26 [PATCH iproute2] ip: Properly display AF_BRIDGE address information for neighbor events Donald Sharp
  2018-02-23 16:28 ` Stephen Hemminger
@ 2018-02-23 19:10 ` Donald Sharp
  2018-02-23 19:28   ` Stephen Hemminger
  1 sibling, 1 reply; 4+ messages in thread
From: Donald Sharp @ 2018-02-23 19:10 UTC (permalink / raw)
  To: netdev, stephen

The vxlan driver when a neighbor add/delete event occurs sends
NDA_DST filled with a union:

union vxlan_addr {
	struct sockaddr_in sin;
	struct sockaddr_in6 sin6;
	struct sockaddr sa;
};

This eventually calls rt_addr_n2a_r which had no handler for the
AF_BRIDGE family and "???" was being printed.

Add code to properly display this data when requested.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
---
 lib/utils.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/lib/utils.c b/lib/utils.c
index 24aeddd8..fe5841f6 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -1004,6 +1004,25 @@ const char *rt_addr_n2a_r(int af, int len,
 	}
 	case AF_PACKET:
 		return ll_addr_n2a(addr, len, ARPHRD_VOID, buf, buflen);
+	case AF_BRIDGE:
+	{
+		const union {
+			struct sockaddr sa;
+			struct sockaddr_in sin;
+			struct sockaddr_in6 sin6;
+		} *sa = addr;
+		unsigned short family = sa->sa.sa_family;
+
+		switch(family) {
+		case AF_INET:
+			return inet_ntop(AF_INET, &sa->sin.sin_addr, buf, buflen);
+		case AF_INET6:
+			return inet_ntop(AF_INET6, &sa->sin6.sin6_addr,
+					 buf, buflen);
+		}
+
+		/* fallthrough */
+	}
 	default:
 		return "???";
 	}
-- 
2.14.3

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

* Re: [PATCH iproute2 v2] ip: Properly display AF_BRIDGE address information for neighbor events
  2018-02-23 19:10 ` [PATCH iproute2 v2] " Donald Sharp
@ 2018-02-23 19:28   ` Stephen Hemminger
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2018-02-23 19:28 UTC (permalink / raw)
  To: Donald Sharp; +Cc: netdev

On Fri, 23 Feb 2018 14:10:09 -0500
Donald Sharp <sharpd@cumulusnetworks.com> wrote:

> The vxlan driver when a neighbor add/delete event occurs sends
> NDA_DST filled with a union:
> 
> union vxlan_addr {
> 	struct sockaddr_in sin;
> 	struct sockaddr_in6 sin6;
> 	struct sockaddr sa;
> };
> 
> This eventually calls rt_addr_n2a_r which had no handler for the
> AF_BRIDGE family and "???" was being printed.
> 
> Add code to properly display this data when requested.
> 
> Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>

I did some minor changes to the patch and applied it.
(need space after switch, and can don't need local variable family).
Thanks.

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

end of thread, other threads:[~2018-02-23 19:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-22  2:26 [PATCH iproute2] ip: Properly display AF_BRIDGE address information for neighbor events Donald Sharp
2018-02-23 16:28 ` Stephen Hemminger
2018-02-23 19:10 ` [PATCH iproute2 v2] " Donald Sharp
2018-02-23 19:28   ` Stephen Hemminger

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