From patchwork Sun Jul 31 07:27:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland Dreier X-Patchwork-Id: 9253289 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C394B60865 for ; Sun, 31 Jul 2016 07:27:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B12C72845C for ; Sun, 31 Jul 2016 07:27:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5D5628482; Sun, 31 Jul 2016 07:27:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48D342845C for ; Sun, 31 Jul 2016 07:27:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751273AbcGaH1w (ORCPT ); Sun, 31 Jul 2016 03:27:52 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:35395 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751002AbcGaH1v (ORCPT ); Sun, 31 Jul 2016 03:27:51 -0400 Received: by mail-pa0-f49.google.com with SMTP id iw10so43086704pac.2 for ; Sun, 31 Jul 2016 00:27:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ahPl/fptbc3JOhTOU/NpU1d+IdR5w7cYoxcxfryEBcA=; b=SyCsZoJyShm9F711apZUzLhGHfhLQKjKc3ulaFIVvaEn+uOPHf8oGfq7rllPdVA85h HJMf2VC7oB3W+Dac6SrJP/V35+UoU2wAc9Tibs6hfumhkn2okhhq2rzI3ya8bkW920GX 5jug+2j7DeZvEAg6cy3V9HP6NnDYf8lsgGGgY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ahPl/fptbc3JOhTOU/NpU1d+IdR5w7cYoxcxfryEBcA=; b=cB6gvjHCYoKOpHIl1K7N4HE8EKDQ6T9B9PujjZFgiA5MYyL3ZY7hRZZ5gqM4SEdrch QRSqEs4zbd0DWXOETS3/STvw+qRZvmfK4c54JRj70fq37go9l4T3z3jq0i3y3mbAyFB+ UocUoz2lPv2qvChIhHesnuKRLFkb6ongr7+7AaOUonaIPyJ3Qn/+zIVmZrQusjAhqgoY 4MS9b/ijAve1AdyHbejgCFPyeOLx0YlFyWKTgIaVXVuQJfXm/dDaTo1FApV8/lO/je+a tR+7izItpRtwruCp90TW0F9DqgYcWDYiBHtJKb1AOfmoCyNsjn4pq0XltlTdRuoAxi11 5SpQ== X-Gm-Message-State: AEkoouv4vBlEx1WkQbtPOPsfb8yAMnCeAw5fVvSgy/zzT8y2jox6oQ4Q50/zbmnEG4vvUrzm X-Received: by 10.66.88.161 with SMTP id bh1mr28555192pab.133.1469950070783; Sun, 31 Jul 2016 00:27:50 -0700 (PDT) Received: from roland-t440p.purestorage.com ([2001:470:1f05:221:40bb:149:7900:7883]) by smtp.gmail.com with ESMTPSA id u72sm36480481pfa.31.2016.07.31.00.27.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 31 Jul 2016 00:27:50 -0700 (PDT) From: Roland Dreier To: Jens Axboe , Christoph Hellwig Cc: linux-nvme@lists.infradead.org, linux-rdma@vger.kernel.org Subject: [PATCH 2/2] nvme-rdma: Add handling for connecting to IPv6 targets Date: Sun, 31 Jul 2016 00:27:40 -0700 Message-Id: <1469950060-18098-2-git-send-email-roland@kernel.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1469950060-18098-1-git-send-email-roland@kernel.org> References: <1469950060-18098-1-git-send-email-roland@kernel.org> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Roland Dreier If a target address does not parse as IPv4, try parsing it as IPv6 (including handling '%' suffixes for link-local addresses). Signed-off-by: Roland Dreier --- 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);