diff mbox series

[04/29] lnet: handle possiblity of IPv6 being unavailable.

Message ID 1619381316-7719-5-git-send-email-jsimmons@infradead.org (mailing list archive)
State New, archived
Headers show
Series lustre: Update to OpenSFS tree as of April 25, 2020 | expand

Commit Message

James Simmons April 25, 2021, 8:08 p.m. UTC
From: Mr NeilBrown <neilb@suse.de>

If CONFIG_IPV6 is not enabled, the attempt to create an IPv6 socket
for accepting new incoming connections will fail.  In that case
we need to creae an IPv4 socket instead.

Also ipv6_dev_get_saddr will not be available, so we must not include
the code that tries to use it.

Fixes: 7314102c80ae ("lnet: allow creation of IPv6 socket")
WC-bug-id: https://jira.whamcloud.com/browse/LU-14477
Lustre-commit: 6376551ca266f839 ("LU-14477 lnet: handle possiblity of IPv6 being unavailable.")
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Reviewed-on: https://review.whamcloud.com/41791
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
---
 net/lnet/lnet/lib-socket.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/net/lnet/lnet/lib-socket.c b/net/lnet/lnet/lib-socket.c
index ee675ae..317d3cf 100644
--- a/net/lnet/lnet/lib-socket.c
+++ b/net/lnet/lnet/lib-socket.c
@@ -188,7 +188,13 @@  int choose_ipv4_src(u32 *ret, int interface, u32 dst_ipaddr, struct net *ns)
 	family = AF_INET6;
 	if (remaddr)
 		family = remaddr->sa_family;
+retry:
 	rc = sock_create_kern(ns, family, SOCK_STREAM, 0, &sock);
+	if (rc == -EAFNOSUPPORT && family == AF_INET6 && !remaddr) {
+		family = AF_INET;
+		goto retry;
+	}
+
 	if (rc) {
 		CERROR("Can't create socket: %d\n", rc);
 		return ERR_PTR(rc);
@@ -204,11 +210,11 @@  int choose_ipv4_src(u32 *ret, int interface, u32 dst_ipaddr, struct net *ns)
 
 	if (interface >= 0 || local_port) {
 		struct sockaddr_storage locaddr = {};
-		struct sockaddr_in *sin = (void *)&locaddr;
-		struct sockaddr_in6 *sin6 = (void *)&locaddr;
 
 		switch (family) {
-		case AF_INET:
+		case AF_INET: {
+			struct sockaddr_in *sin = (void *)&locaddr;
+
 			sin->sin_family = AF_INET;
 			sin->sin_addr.s_addr = INADDR_ANY;
 			if (interface >= 0 && remaddr) {
@@ -225,7 +231,11 @@  int choose_ipv4_src(u32 *ret, int interface, u32 dst_ipaddr, struct net *ns)
 			}
 			sin->sin_port = htons(local_port);
 			break;
-		case AF_INET6:
+		}
+#if IS_ENABLED(CONFIG_IPV6)
+		case AF_INET6: {
+			struct sockaddr_in6 *sin6 = (void *)&locaddr;
+
 			sin6->sin6_family = AF_INET6;
 			sin6->sin6_addr = in6addr_any;
 			if (interface >= 0 && remaddr) {
@@ -240,6 +250,8 @@  int choose_ipv4_src(u32 *ret, int interface, u32 dst_ipaddr, struct net *ns)
 			sin6->sin6_port = htons(local_port);
 			break;
 		}
+#endif /* IS_ENABLED(CONFIG_IPV6) */
+		}
 
 		rc = kernel_bind(sock, (struct sockaddr *)&locaddr,
 				 sizeof(locaddr));