From patchwork Wed Oct 25 16:13:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hal Rosenstock X-Patchwork-Id: 10026971 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 5C9DE60375 for ; Wed, 25 Oct 2017 16:13:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C5C928BC1 for ; Wed, 25 Oct 2017 16:13:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4002328BCE; Wed, 25 Oct 2017 16:13:50 +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 8271A28BC1 for ; Wed, 25 Oct 2017 16:13:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751723AbdJYQNr (ORCPT ); Wed, 25 Oct 2017 12:13:47 -0400 Received: from mail-qt0-f196.google.com ([209.85.216.196]:49589 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750974AbdJYQNq (ORCPT ); Wed, 25 Oct 2017 12:13:46 -0400 Received: by mail-qt0-f196.google.com with SMTP id k31so697928qta.6 for ; Wed, 25 Oct 2017 09:13:46 -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=GKlFWKMQcwPM2/406YBsi7rfX+A7mR0w1qoU8EAQguM=; b=D0OabR86xVRB/QoJi6ozJqCwp0TNfTS1m06TMCWf5x+RsdB/QnI/6jr4Vb1X2EneBq 4F+8ueS2kmAMLHeWfxKH2+B8QQgEf77wW9wz7xyLZr/ywPbpSxTJhvK7GGoXbcLPnhSf ANAE9eZJJlHqTcQksKG7+h3xKnpvp2u+xXsgeOKnNQFO6vvSO4XK2tiFQ/cUzuh2otIZ eEW0UycanpXbtzEB4zywgkM3sOQWjWQejtW57SZrxCap0jAUeMrquVPxUdtWlilNmiQ+ hILscjUXhIlsqi1dXSYL13BAsyX1dpKHu8t6mwI2wIWCkAZQuIdHXR+odHh7IumxVa55 YmmA== 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=GKlFWKMQcwPM2/406YBsi7rfX+A7mR0w1qoU8EAQguM=; b=PfTRQnPc7T4wdxF5gtgnHWdGm26pGEgkSRlZPP7rCSK8/6OAruczNA/Zp3vRIC8ngP FJxbVrEkriTmAew4NJVsQSBCxYccf99aGfsJNSAYEdfa/ThnLdCT4pHm9im3sxwTnnmg wjUUbd9CZfV0MQvB+CWrsZN3SbfdzJFKsSAKGl4b8yB43A/ZTwEGz0moHNuQMfHPooSS TozCwG3w4M2wT7zcKicOzZqTwm+mPOc6tuCDiaxPz+8yf6CRezcofROWMHEcc8Fb47jI 6/gx0JyiRro83k5M54mRxJkayR1lMcvsbn5SVNFlvqfPFlMPO5ViCF4GVpeWKuBE0BoZ ejEw== X-Gm-Message-State: AMCzsaX4iMtFSMv1RDk43ue2Vu1LvXPNgzGXkD1MRMeqCu5SNwGdA0oT IavOVCnEIE/mOzPx1XNZuetWs7cm X-Google-Smtp-Source: ABhQp+RNQRJWHjYUaLJ2KjLzYluRakhMyO3AevTSMBsS2Zxe2syJvKRQLON1g9Zj+UUtVTCVtnZQkA== X-Received: by 10.200.23.85 with SMTP id u21mr29002202qtk.200.1508948026226; Wed, 25 Oct 2017 09:13:46 -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 h4sm2238374qth.90.2017.10.25.09.13.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Oct 2017 09:13:45 -0700 (PDT) To: "Hefty, Sean" Cc: "linux-rdma@vger.kernel.org" From: Hal Rosenstock Subject: [PATCHv2 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: Date: Wed, 25 Oct 2017 12:13:45 -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. Signed-off-by: Hal Rosenstock --- 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; - }