From patchwork Wed Oct 25 16:51:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hal Rosenstock X-Patchwork-Id: 10027019 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 531A160375 for ; Wed, 25 Oct 2017 16:51:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 406DF28BE3 for ; Wed, 25 Oct 2017 16:51:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3311D28BED; Wed, 25 Oct 2017 16:51:12 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 A206D28BE3 for ; Wed, 25 Oct 2017 16:51:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751793AbdJYQvK (ORCPT ); Wed, 25 Oct 2017 12:51:10 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:43407 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751513AbdJYQvK (ORCPT ); Wed, 25 Oct 2017 12:51:10 -0400 Received: by mail-qt0-f193.google.com with SMTP id j58so877705qtj.0 for ; Wed, 25 Oct 2017 09:51:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dev-mellanox-co-il.20150623.gappssmtp.com; s=20150623; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=CzFVja6NCkd73ZqAv1yjx4urGDg5NVGgJnsYLlPgl3A=; b=KoMJJn8IN6QmlIHxBdrRe3nFXlt/yRyMNd9XlmMo9htA153O81i4zBfF7A0e0JFgoK ciRoonvpdkEd1r5dFaMlW7WuzUmmXqRzU0hr1293qmBaeY+L+kpM9fQ+3RvQ3OI5ffTL yvESxeE8uyF+ELyd2jaSbiZYKdSEDGkHB7cpbsIwgL56ioRgVRHOQpTLoZQn4S9y+0FP ZA4smljkjk+QZOyC1zf8fvS54aB7GYNOBsX81xS8f+yy/rlenLxfndf3J4Cwng4Paapj JXOSaOG/wsgY3t5bXpmMiI7UHx39GxjCeo08igg3Lh8vC5XrrpKWhnjxXqLv+LQx2qY6 JWsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=CzFVja6NCkd73ZqAv1yjx4urGDg5NVGgJnsYLlPgl3A=; b=MHY9jRTUfUHcgQe9wsC1R/mH9NnQRCriJeZyi5h0qE6EUpzGDoSeHHrIoy3l/VfRCj 2BvYa4Ncs8zwpoN414H5d+OArq2uAn2y3YIcuFd9x6AAsm/8nBVRvyvdQnYhP975++QT ClOye+1jzCULwSG12GoAtSVA98hqf1mtFCZ0j68+95WhcC13wSdIRy/JvH76zVwd7HwI t3pZ3sDe2PkDgQFDPKwU7afOK8Lw7kIXaqZYkA5Fzn53AcHzERXvvpe5c99GGUoRaSd3 sOLoKASPWp5mcz3dLRe3Arn4r5KE0cMe6zu9kBxJno6nIN9ETuPEXEjEfDAqwGZ37d68 jiNw== X-Gm-Message-State: AMCzsaVySiWIs7UXHrHKLZdJ0ymxqFm+femjXzD99WbDkBVH9HZYzmJ6 uZT9G2cQsS3ZXHGWEXkgECz6tiQu X-Google-Smtp-Source: ABhQp+QUjc4Ka+h5/hyBU5pk8rzbvoMdrwF/BgQv+k+oypOXBkw++OthYtGROTmpCXdj1CnH2GnHvg== X-Received: by 10.200.38.122 with SMTP id v55mr30563973qtv.134.1508950269568; Wed, 25 Oct 2017 09:51:09 -0700 (PDT) Received: from [192.168.1.183] (c-73-182-207-166.hsd1.ma.comcast.net. [73.182.207.166]) by smtp.googlemail.com with ESMTPSA id h21sm2253318qte.72.2017.10.25.09.51.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Oct 2017 09:51:08 -0700 (PDT) To: "Hefty, Sean" Cc: "linux-rdma@vger.kernel.org" From: Hal Rosenstock Subject: [PATCHv3 rdma-core 3/3] ibacm: In acm_util.c:acm_if_iter_sys, try IPv4 if IPv6 doesn't find any appropriate interfaces Message-ID: <18b32f97-973a-1eb1-ac57-a5e06287d723@dev.mellanox.co.il> Date: Wed, 25 Oct 2017 12:51:08 -0400 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 Content-Language: en-US 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 This can occur when IPv6 is disabled. In the case where ipv6 is disabled in kernel, the socket is created but the ioctl fails. Signed-off-by: Hal Rosenstock --- Change since v2: Updated commit message to clarify that it's ioctl not socket call which fails when IPv6 is disabled Changes since v1: Handle AF_INET6 socket and ioctl errors more "locally" rather than looping around entire routine Also, remove loop on no interfaces found ibacm/src/acm_util.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/ibacm/src/acm_util.c b/ibacm/src/acm_util.c index b50fd74..ad454f2 100644 --- a/ibacm/src/acm_util.c +++ b/ibacm/src/acm_util.c @@ -127,6 +127,7 @@ int acm_if_iter_sys(acm_if_iter_cb cb, void *ctx) struct ifconf *ifc; struct ifreq *ifr; char ip_str[INET6_ADDRSTRLEN]; + int family = AF_INET6; int s, ret, i, len; uint16_t pkey; union ibv_gid sgid; @@ -135,9 +136,13 @@ int acm_if_iter_sys(acm_if_iter_cb cb, void *ctx) size_t addr_len; char *alias_sep; - s = socket(AF_INET6, SOCK_DGRAM, 0); - if (!s) - return -1; + s = socket(family, SOCK_DGRAM, 0); + if (!s) { + family = AF_INET; + s = socket(family, SOCK_DGRAM, 0); + if (!s) + return -1; + } len = sizeof(*ifc) + sizeof(*ifr) * 64; ifc = malloc(len); @@ -150,9 +155,21 @@ int acm_if_iter_sys(acm_if_iter_cb cb, void *ctx) ifc->ifc_len = len - sizeof(*ifc); ifc->ifc_req = (struct ifreq *) (ifc + 1); +retry_ioctl: ret = ioctl(s, SIOCGIFCONF, ifc); if (ret < 0) { - acm_log(0, "ioctl ifconf error: %s\n", strerror(errno)); + acm_log(0, "ioctl IPv%s ifconf error: %s\n", + (family == AF_INET6) ? "6" : "4", strerror(errno)); + if (family == AF_INET6) { + close(s); + family = AF_INET; + s = socket(family, SOCK_DGRAM, 0); + if (!s) { + free(ifc); + return ret; + } + goto retry_ioctl; + } goto out2; } @@ -207,5 +224,4 @@ out2: out1: close(s); return ret; - }