netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Donald Sharp <sharpd@cumulusnetworks.com>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH iproute2] ip: Properly display AF_BRIDGE address information for neighbor events
Date: Fri, 23 Feb 2018 08:28:42 -0800	[thread overview]
Message-ID: <20180223082842.780c9f2d@xeon-e3> (raw)
In-Reply-To: <20180222022650.14316-1-sharpd@cumulusnetworks.com>

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 "???";
>  	}

  reply	other threads:[~2018-02-23 16:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2018-02-23 19:10 ` [PATCH iproute2 v2] " Donald Sharp
2018-02-23 19:28   ` Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180223082842.780c9f2d@xeon-e3 \
    --to=stephen@networkplumber.org \
    --cc=netdev@vger.kernel.org \
    --cc=sharpd@cumulusnetworks.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).