public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH rdma-core 3/3] ibacm: In acm_util.c:acm_if_iter_sys, try IPv4 if IPv6 doesn't find any appropriate interfaces
@ 2017-10-25 13:42 Hal Rosenstock
       [not found] ` <8d19d9a9-1f97-408e-ca60-d42e67fbf60c-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Hal Rosenstock @ 2017-10-25 13:42 UTC (permalink / raw)
  To: Hefty, Sean; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org


This can occur when IPv6 is disabled.

Signed-off-by: Hal Rosenstock <hal-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
 ibacm/src/acm_util.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/ibacm/src/acm_util.c b/ibacm/src/acm_util.c
index b50fd74..5b84be8 100644
--- a/ibacm/src/acm_util.c
+++ b/ibacm/src/acm_util.c
@@ -127,7 +127,8 @@ int acm_if_iter_sys(acm_if_iter_cb cb, void *ctx)
 	struct ifconf *ifc;
 	struct ifreq *ifr;
 	char ip_str[INET6_ADDRSTRLEN];
-	int s, ret, i, len;
+	int family = AF_INET6;
+	int s, ret, i, len, intfs = 0;
 	uint16_t pkey;
 	union ibv_gid sgid;
 	uint8_t addr_type;
@@ -135,9 +136,12 @@ 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;
+next_family:
+	s = socket(family, SOCK_DGRAM, 0);
+	if (!s) {
+		ret = -1;
+		goto out;
+	}
 
 	len = sizeof(*ifc) + sizeof(*ifr) * 64;
 	ifc = malloc(len);
@@ -152,7 +156,8 @@ int acm_if_iter_sys(acm_if_iter_cb cb, void *ctx)
 
 	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));
 		goto out2;
 	}
 
@@ -199,6 +204,7 @@ int acm_if_iter_sys(acm_if_iter_cb cb, void *ctx)
 			continue;
 
 		cb(ifr[i].ifr_name, &sgid, pkey, addr_type, addr, addr_len, ip_str, ctx);
+		intfs++;
 	}
 	ret = 0;
 
@@ -206,6 +212,10 @@ out2:
 	free(ifc);
 out1:
 	close(s);
+out:
+	if (family == AF_INET6 && intfs == 0) {
+		family = AF_INET;
+		goto next_family;
+	}
 	return ret;
-
 }
-- 
2.8.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-10-25 16:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-25 13:42 [PATCH rdma-core 3/3] ibacm: In acm_util.c:acm_if_iter_sys, try IPv4 if IPv6 doesn't find any appropriate interfaces Hal Rosenstock
     [not found] ` <8d19d9a9-1f97-408e-ca60-d42e67fbf60c-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2017-10-25 15:17   ` Hefty, Sean
     [not found]     ` <1828884A29C6694DAF28B7E6B8A82373AB1A24BB-P5GAC/sN6hkd3b2yrw5b5LfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2017-10-25 15:29       ` Hal Rosenstock
     [not found]         ` <cb3ecc66-d128-e735-4bc7-c35aca3fa915-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2017-10-25 15:35           ` Hefty, Sean
     [not found]             ` <1828884A29C6694DAF28B7E6B8A82373AB1A2521-P5GAC/sN6hkd3b2yrw5b5LfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2017-10-25 16:22               ` Jason Gunthorpe
     [not found]                 ` <20171025162235.GE15557-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2017-10-25 16:50                   ` Hal Rosenstock

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox