From patchwork Thu Oct 3 23:02:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arlin Davis X-Patchwork-Id: 2986521 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B6075BFF0B for ; Thu, 3 Oct 2013 23:02:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 382C4203A8 for ; Thu, 3 Oct 2013 23:02:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4B6D52035C for ; Thu, 3 Oct 2013 23:02:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753122Ab3JCXCn (ORCPT ); Thu, 3 Oct 2013 19:02:43 -0400 Received: from mga01.intel.com ([192.55.52.88]:63413 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751374Ab3JCXCm (ORCPT ); Thu, 3 Oct 2013 19:02:42 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 03 Oct 2013 16:02:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.90,1028,1371106800"; d="scan'208";a="405039578" Received: from orsmsx109.amr.corp.intel.com ([10.22.240.7]) by fmsmga001.fm.intel.com with ESMTP; 03 Oct 2013 16:02:29 -0700 Received: from orsmsx113.amr.corp.intel.com (10.22.240.9) by ORSMSX109.amr.corp.intel.com (10.22.240.7) with Microsoft SMTP Server (TLS) id 14.3.123.3; Thu, 3 Oct 2013 16:02:28 -0700 Received: from orsmsx101.amr.corp.intel.com ([169.254.8.125]) by ORSMSX113.amr.corp.intel.com ([169.254.7.187]) with mapi id 14.03.0123.003; Thu, 3 Oct 2013 16:02:28 -0700 From: "Davis, Arlin R" To: "linux-rdma@vger.kernel.org" , "ofw@lists.openfabrics.org" Subject: [PATCH] DAPL v2.0: SCM: getifaddrs modfications for better out of the box experience Thread-Topic: [PATCH] DAPL v2.0: SCM: getifaddrs modfications for better out of the box experience Thread-Index: Ac7AjCuzac7am0iTS6K9uvWtBK8bbg== Date: Thu, 3 Oct 2013 23:02:28 +0000 Message-ID: <54347E5A035A054EAE9D05927FB467F972DB44B4@ORSMSX101.amr.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.22.254.140] MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP socket cm will now walk list of interfaces and ignore loopback and ignore IB devices, unless the IB netdev is the only device. Works better in a heterogeneous environment with a mix of net device. Tested with br0, mic0, and mic0:ib netdev mixes. Overriding with DAPL_SCM_NETDEV still works as is. Signed-off-by: Patrick Mccormick Signed-off-by: Arlin Davis --- dapl/openib_common/util.c | 70 +++++++++++++++++++++++--------------------- 1 files changed, 37 insertions(+), 33 deletions(-) -- 1.7.3 diff --git a/dapl/openib_common/util.c b/dapl/openib_common/util.c index 8b97263..20fb8b2 100644 --- a/dapl/openib_common/util.c +++ b/dapl/openib_common/util.c @@ -28,6 +28,7 @@ #include "dapl_osd.h" #include +#include int g_dapl_loopback_connection = 0; @@ -148,7 +149,6 @@ int getipaddr_netdev(char *name, char *addr, int addr_len) /* Fill in the structure */ snprintf(ifr.ifr_name, IFNAMSIZ, "%s", name); - ifr.ifr_hwaddr.sa_family = ARPHRD_INFINIBAND; /* Create a socket fd */ skfd = socket(PF_INET, SOCK_STREAM, 0); @@ -178,51 +178,54 @@ int getipaddr_netdev(char *name, char *addr, int addr_len) return ret; } -DAT_RETURN getlocalipaddr(char *addr, int addr_len) +/* IPv4 only, use IB if netdev set or it's the only interface */ +DAT_RETURN getlocalipaddr (char *addr, int addr_len) { - struct sockaddr_in *sin; - int ret, skfd, i; + struct ifaddrs *ifap, *ifa; + int ret, found=0, ib_ok=0; char *netdev = getenv("DAPL_SCM_NETDEV"); - struct ifreq ifr[10]; - struct ifconf ifc; - /* use provided netdev instead of default hostname */ if (netdev != NULL) { ret = getipaddr_netdev(netdev, addr, addr_len); if (ret) { - dapl_log(DAPL_DBG_TYPE_ERR, - " getlocalipaddr: NETDEV = %s" - " but not configured on system? ERR = %s\n", - netdev, strerror(ret)); - return dapl_convert_errno(ret, "getlocalipaddr"); - } else + dapl_log(DAPL_DBG_TYPE_ERR, " ERR: NETDEV = %s" + " but not configured on system?\n", netdev); + return dapl_convert_errno(errno, "getlocalipaddr"); + } else { + dapl_log(DAPL_DBG_TYPE_UTIL," my_addr %s NETDEV = %s\n", + inet_ntoa(((struct sockaddr_in *)addr)->sin_addr), + netdev); return DAT_SUCCESS; + } } - if (addr_len < sizeof(*sin)) - return DAT_INTERNAL_ERROR; - - memset(&ifc,0,sizeof(ifc)); - ifc.ifc_buf = (char *)ifr; - ifc.ifc_len = sizeof(ifr); - - skfd = socket(PF_INET, SOCK_STREAM, 0); - ret = ioctl(skfd, SIOCGIFCONF, &ifc); - if (ret) - goto bail; + if ((ret = getifaddrs (&ifap))) + return dapl_convert_errno(errno, "getifaddrs"); - /* first non-loopback interface in list */ - for (i=0; i < ifc.ifc_len/sizeof(struct ifreq); i++) { - if (strcmp(ifr[i].ifr_name, "lo")) - break; +retry: + for (ifa = ifap; ifa; ifa = ifa->ifa_next) { + if (ifa->ifa_addr->sa_family == AF_INET) { + if (!found && !(ifa->ifa_flags & IFF_LOOPBACK) && + ((!ib_ok && dapl_os_pstrcmp("ib", ifa->ifa_name)) || + (ib_ok && !dapl_os_pstrcmp("ib", ifa->ifa_name)))) { + memcpy(addr, ifa->ifa_addr, sizeof(struct sockaddr_in)); + found++; + } + dapl_log(DAPL_DBG_TYPE_UTIL, + " getifaddrs: %s -> %s\n", ifa->ifa_name, + inet_ntoa(((struct sockaddr_in *)ifa->ifa_addr)->sin_addr)); + } + } + if (!found && !ib_ok) { + ib_ok = 1; + goto retry; } - memcpy(addr, &ifr[i].ifr_addr, sizeof(struct sockaddr_in)); + dapl_log(DAPL_DBG_TYPE_UTIL," my_addr %s\n", + inet_ntoa(((struct sockaddr_in *)addr)->sin_addr)); -bail: - close(skfd); - return dapl_convert_errno(ret, "getlocalipaddr"); + freeifaddrs(ifap); + return (found ? DAT_SUCCESS:DAT_INVALID_ADDRESS); } - #endif enum ibv_mtu dapl_ib_mtu(int mtu) @@ -811,3 +814,4 @@ ib_cm_events_t dapls_ib_get_cm_event(IN DAT_EVENT_NUMBER dat_event_num) } return ib_cm_event; } +