netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH 2/2] nvme-rdma: Add handling for connecting to IPv6 targets
       [not found]   ` <1469950060-18098-2-git-send-email-roland-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
@ 2016-08-01 11:09     ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2016-08-01 11:09 UTC (permalink / raw)
  To: Roland Dreier
  Cc: Jens Axboe, Christoph Hellwig,
	linux-nvme-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA, netdev-u79uwXL29TY76Z2rM5mHXA

Hi Roland,

On Sun, Jul 31, 2016 at 12:27:40AM -0700, Roland Dreier wrote:
> From: Roland Dreier <roland-BHEL68pLQRGGvPXPguhicg@public.gmane.org>
> 
> If a target address does not parse as IPv4, try parsing it as IPv6
> (including handling '%<scope-id>' suffixes for link-local addresses).

The code below looks fine to me, but is there any chance to add it to
net/ as a generic helper?  It's a little sad this sort of code would
have to live in each driver trying to parse IP addresses.

> Signed-off-by: Roland Dreier <roland-BHEL68pLQRGGvPXPguhicg@public.gmane.org>
> ---
>  drivers/nvme/host/rdma.c | 55 ++++++++++++++++++++++++++++++++++++++----------
>  1 file changed, 44 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
> index b96b88369871..dd4aa54cd709 100644
> --- a/drivers/nvme/host/rdma.c
> +++ b/drivers/nvme/host/rdma.c
> @@ -138,6 +138,7 @@ struct nvme_rdma_ctrl {
>  	union {
>  		struct sockaddr addr;
>  		struct sockaddr_in addr_in;
> +		struct sockaddr_in6 addr_in6;
>  	};
>  
>  	struct nvme_ctrl	ctrl;
> @@ -1847,19 +1848,51 @@ out_free_io_queues:
>  	return ret;
>  }
>  
> -static int nvme_rdma_parse_ipaddr(struct sockaddr_in *in_addr, char *p)
> +static int nvme_rdma_parse_ipaddr(struct sockaddr *addr, char *p)
>  {
> -	u8 *addr = (u8 *)&in_addr->sin_addr.s_addr;
>  	size_t buflen = strlen(p);
>  
> -	/* XXX: handle IPv6 addresses */
> +	if (buflen <= INET_ADDRSTRLEN) {
> +		struct sockaddr_in *addr4 = (struct sockaddr_in *) addr;
> +		if (in4_pton(p, buflen, (u8 *) &addr4->sin_addr.s_addr,
> +			     '\0', NULL) > 0) {
> +			addr4->sin_family = AF_INET;
> +			return 0;
> +		}
> +	}
>  
> -	if (buflen > INET_ADDRSTRLEN)
> -		return -EINVAL;
> -	if (in4_pton(p, buflen, addr, '\0', NULL) == 0)
> -		return -EINVAL;
> -	in_addr->sin_family = AF_INET;
> -	return 0;
> +	if (buflen <= INET6_ADDRSTRLEN) {
> +		struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) addr;
> +		const char *scope_delim;
> +
> +		if (in6_pton(p, buflen, (u8 *) &addr6->sin6_addr.s6_addr,
> +			     '%', &scope_delim) == 0)
> +			return -EINVAL;
> +		addr6->sin6_family = AF_INET6;
> +
> +		if (ipv6_addr_type(&addr6->sin6_addr) & IPV6_ADDR_LINKLOCAL &&
> +		    p + buflen != scope_delim && *scope_delim == '%') {
> +			char scope_id[16];
> +			size_t scope_len = min_t(size_t, sizeof scope_id,
> +						 p + buflen - scope_delim - 1);
> +			struct net_device *dev;
> +
> +			memcpy(scope_id, scope_delim + 1, scope_len);
> +			scope_id[scope_len] = '\0';
> +
> +			/* XXX: what network namespace should we use? */
> +			dev = dev_get_by_name(&init_net, scope_id);
> +			if (dev) {
> +				addr6->sin6_scope_id = dev->ifindex;
> +				dev_put(dev);
> +			} else if (kstrtouint(scope_id, 0, &addr6->sin6_scope_id))
> +				return -EINVAL;
> +		}
> +
> +		return 0;
> +	}
> +
> +	return -EINVAL;
>  }
>  
>  static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev,
> @@ -1875,7 +1908,7 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev,
>  	ctrl->ctrl.opts = opts;
>  	INIT_LIST_HEAD(&ctrl->list);
>  
> -	ret = nvme_rdma_parse_ipaddr(&ctrl->addr_in, opts->traddr);
> +	ret = nvme_rdma_parse_ipaddr(&ctrl->addr, opts->traddr);
>  	if (ret) {
>  		pr_err("malformed IP address passed: %s\n", opts->traddr);
>  		goto out_free_ctrl;
> @@ -1949,7 +1982,7 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev,
>  	changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE);
>  	WARN_ON_ONCE(!changed);
>  
> -	dev_info(ctrl->ctrl.device, "new ctrl: NQN \"%s\", addr %pISp\n",
> +	dev_info(ctrl->ctrl.device, "new ctrl: NQN \"%s\", addr %pISpcs\n",
>  		ctrl->ctrl.opts->subsysnqn, &ctrl->addr);
>  
>  	kref_get(&ctrl->ctrl.kref);
> -- 
> 2.7.4
---end quoted text---
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 2/2] nvme-rdma: Add handling for connecting to IPv6 targets
       [not found]             ` <CAG4TOxPNnUKWeh7FUY8YB127sx8yMu41FuP4hxUMCan_HWQmVQ@mail.gmail.com>
@ 2016-08-02 12:51               ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2016-08-02 12:51 UTC (permalink / raw)
  To: Roland Dreier
  Cc: Christoph Hellwig, Sagi Grimberg, Jens Axboe, linux-nvme,
	linux-rdma@vger.kernel.org, netdev

On Mon, Aug 01, 2016 at 09:06:07AM -0700, Roland Dreier wrote:
> On Mon, Aug 1, 2016 at 8:50 AM, Christoph Hellwig <hch@lst.de> wrote:
> > It'd still need all the scope ID handling similar to what Roland did,
> > and that's a fair chunk of code.  We have a few options to handle the
> > different allowed addresses:
> >
> >  (1) v4/v6 only flags
> >  (2) having low-level v4/v6 handlers and one that tries these both
> >  (3) using the try both handler and rejecting the wrong one after
> >      parsing.
> >
> > (3) seems easiest, but (2) sounds fine to me.  But I'd really like to
> > hear from folks on the netdev list what they think of that idea first.
> 
> I think adding a new helper that parses both v4 and v6 addresses +
> scope ID seems like the best thing for now.  I did a grep for in6_pton
> and it looks like at least fs/cifs/netmisc.c and net/sunrpc/addr.c
> could use the helper.
> 
> What do you think of adding inet_pton_with_scope() to
> net/core/utils.c?  I'm open to better ideas on the name.  But I can
> code that up and use it in nvme, as well as convert over the two
> places I mentioned above.  The first parameter of the function can be
> an af, and the caller can pass in AF_UNSPEC, AF_INET, or AF_INET6 to
> restrict the parsing to one type of address (or not).

Sounds fine to me, and I hope the netdev folks (Cc'ed) are fine with
that as well.

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

end of thread, other threads:[~2016-08-02 12:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1469950060-18098-1-git-send-email-roland@kernel.org>
     [not found] ` <1469950060-18098-2-git-send-email-roland@kernel.org>
     [not found]   ` <1469950060-18098-2-git-send-email-roland-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2016-08-01 11:09     ` [PATCH 2/2] nvme-rdma: Add handling for connecting to IPv6 targets Christoph Hellwig
     [not found]   ` <4acdd466-b8f6-8208-7287-e97dfd45bbf1@grimberg.me>
     [not found]     ` <33dfc646-1804-363e-4d83-1ba618303dbb@grimberg.me>
     [not found]       ` <20160801110956.GI16141@lst.de>
     [not found]         ` <e6e54d3f-c6ee-2057-d4e5-13981cd95140@grimberg.me>
     [not found]           ` <20160801155036.GC22771@lst.de>
     [not found]             ` <CAG4TOxPNnUKWeh7FUY8YB127sx8yMu41FuP4hxUMCan_HWQmVQ@mail.gmail.com>
2016-08-02 12:51               ` Christoph Hellwig

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