From patchwork Thu Mar 21 20:34:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10864333 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 81A121575 for ; Thu, 21 Mar 2019 20:34:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 660C72A34A for ; Thu, 21 Mar 2019 20:34:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59FF02A3A6; Thu, 21 Mar 2019 20:34:39 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 D02D12A369 for ; Thu, 21 Mar 2019 20:34:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728738AbfCUUei (ORCPT ); Thu, 21 Mar 2019 16:34:38 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:41731 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728659AbfCUUei (ORCPT ); Thu, 21 Mar 2019 16:34:38 -0400 Received: by mail-pf1-f193.google.com with SMTP id d25so5035088pfn.8; Thu, 21 Mar 2019 13:34:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=i3Uc98oNeE+tJ9CCoBHnLOW+yCjxRIYLtM7Dyaej8Yk=; b=ug0BZkIzhMcDgdkVomaN52OWORLFu6u3u5CkIkDXXj/Rwf0acs6kARJL7hfptVqL2T qe+leAR2wKBAoYUXgR33KGEtsDPXzckWta9GWN+NJzeTgKDV9fOEQLinKHYuM7G3C0Ol kheF92m7irQJ7eMc29qayJ6WllTSLHXCqn/CDFgWpZ8xGyZw4xd+yqHvP9hAChsp98pe sQjSwUtUy0MX8+0XwjtJd4D+K1cuiUatJVq/32Q+ODC8ydxKnlgWK6GAp+aZamfb0ppa JU34WoJO737Xx7qrSCu/fZy1hdZG4D9gmfI7EDUoKI9j7P+o3qxuocfXUxhX7OlXOyDN ZUHQ== X-Gm-Message-State: APjAAAUQ0a4XEFx/qnwLDtvB44+Ei3za1msyfYj99lWh7G8xYCOatB71 h5AWmZ3CVu/J+quHrfan8GM= X-Google-Smtp-Source: APXvYqwVjVDRRd6Fcf438CWQKOHFxfSAu8PveeY7qlZpBVzj+TEE+QxvexJbqWmCzbAefkIvp6WtAw== X-Received: by 2002:aa7:8249:: with SMTP id e9mr5233216pfn.6.1553200475821; Thu, 21 Mar 2019 13:34:35 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:203:5cdc:422c:7b28:ebb5]) by smtp.gmail.com with ESMTPSA id s5sm708506pgv.8.2019.03.21.13.34.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Mar 2019 13:34:35 -0700 (PDT) From: Bart Van Assche To: Jason Gunthorpe Cc: Leon Romanovsky , Doug Ledford , linux-rdma@vger.kernel.org, Bart Van Assche , Laurence Oberman , stable@vger.kernel.org Subject: [PATCH] RDMA/srp: Accept again source addresses that do not have a port number Date: Thu, 21 Mar 2019 13:34:28 -0700 Message-Id: <20190321203428.128471-1-bvanassche@acm.org> X-Mailer: git-send-email 2.20.GIT MIME-Version: 1.0 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 The function srp_parse_in() is used both for parsing source address specifications and for target address specifications. Target addresses must have a port number. Having to specify a port number for source addresses is inconvenient. Make sure that srp_parse_in() supports again parsing addresses with no port number. Cc: Laurence Oberman Cc: Fixes: c62adb7def71 ("IB/srp: Fix IPv6 address parsing") # v4.17. Signed-off-by: Bart Van Assche --- drivers/infiniband/ulp/srp/ib_srp.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c index a669c10f7adf..0c46f0d7cb7f 100644 --- a/drivers/infiniband/ulp/srp/ib_srp.c +++ b/drivers/infiniband/ulp/srp/ib_srp.c @@ -3487,13 +3487,14 @@ static const match_table_t srp_opt_tokens = { * @net: [in] Network namespace. * @sa: [out] Address family, IP address and port number. * @addr_port_str: [in] IP address and port number. + * @has_port: [out] Whether or not @addr_port_str includes a port number. * * Parse the following address formats: * - IPv4: :, e.g. 1.2.3.4:5. * - IPv6: \[\]:, e.g. [1::2:3%4]:5. */ static int srp_parse_in(struct net *net, struct sockaddr_storage *sa, - const char *addr_port_str) + const char *addr_port_str, bool *has_port) { char *addr_end, *addr = kstrdup(addr_port_str, GFP_KERNEL); char *port_str; @@ -3502,9 +3503,12 @@ static int srp_parse_in(struct net *net, struct sockaddr_storage *sa, if (!addr) return -ENOMEM; port_str = strrchr(addr, ':'); - if (!port_str) - return -EINVAL; - *port_str++ = '\0'; + if (port_str && strchr(port_str, ']')) + port_str = NULL; + if (port_str) + *port_str++ = '\0'; + if (has_port) + *has_port = port_str != NULL; ret = inet_pton_with_scope(net, AF_INET, addr, port_str, sa); if (ret && addr[0]) { addr_end = addr + strlen(addr) - 1; @@ -3526,6 +3530,7 @@ static int srp_parse_options(struct net *net, const char *buf, char *p; substring_t args[MAX_OPT_ARGS]; unsigned long long ull; + bool has_port; int opt_mask = 0; int token; int ret = -EINVAL; @@ -3624,7 +3629,8 @@ static int srp_parse_options(struct net *net, const char *buf, ret = -ENOMEM; goto out; } - ret = srp_parse_in(net, &target->rdma_cm.src.ss, p); + ret = srp_parse_in(net, &target->rdma_cm.src.ss, p, + NULL); if (ret < 0) { pr_warn("bad source parameter '%s'\n", p); kfree(p); @@ -3640,7 +3646,10 @@ static int srp_parse_options(struct net *net, const char *buf, ret = -ENOMEM; goto out; } - ret = srp_parse_in(net, &target->rdma_cm.dst.ss, p); + ret = srp_parse_in(net, &target->rdma_cm.dst.ss, p, + &has_port); + if (!has_port) + ret = -EINVAL; if (ret < 0) { pr_warn("bad dest parameter '%s'\n", p); kfree(p);