Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Bart.VanAssche@wdc.com (Bart Van Assche)
Subject: [PATCH 1/3] net/utils: Introduce inet_addr_is_any
Date: Tue, 6 Feb 2018 15:27:39 +0000	[thread overview]
Message-ID: <1517930858.3934.15.camel@wdc.com> (raw)
In-Reply-To: <20180206094432.12761-2-sagi@grimberg.me>

On Tue, 2018-02-06@11:44 +0200, Sagi Grimberg wrote:
> +bool inet_addr_is_any(struct sockaddr *addr)
> +{
> +	bool ret = false;
> +
> +	if (addr->sa_family == AF_INET6) {
> +		struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)addr;
> +		const struct sockaddr_in6 in6_any =
> +			{ .sin6_addr = IN6ADDR_ANY_INIT };
> +
> +		if (!memcmp(in6->sin6_addr.s6_addr,
> +			in6_any.sin6_addr.s6_addr, 16))
> +			ret = true;
> +	} else if (addr->sa_family == AF_INET) {
> +		struct sockaddr_in *in = (struct sockaddr_in *)addr;
> +
> +		if (in->sin_addr.s_addr == htonl(INADDR_ANY))
> +			ret = true;
> +	}
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL(inet_addr_is_any);

Have you considered to eliminate the local variable 'ret' and to use multiple
return statements? Additionally, should this function trigger a warning if a
socket address is passed with an address family that is not supported by this
function? Should the in6_any local variable be declared static?

Thanks,

Bart.

  parent reply	other threads:[~2018-02-06 15:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-06  9:44 [PATCH 0/3] Commonise address any check Sagi Grimberg
2018-02-06  9:44 ` [PATCH 1/3] net/utils: Introduce inet_addr_is_any Sagi Grimberg
2018-02-06 14:42   ` David Miller
2018-02-06 15:27   ` Bart Van Assche [this message]
2018-02-06  9:44 ` [PATCH 2/3] nvmet: don't return "any" ip address in discovery log page Sagi Grimberg
2018-02-06 10:36   ` Johannes Thumshirn
2018-02-06  9:44 ` [PATCH 3/3] iscsi-target: use common inet_addr_is_any Sagi Grimberg

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=1517930858.3934.15.camel@wdc.com \
    --to=bart.vanassche@wdc.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