isaacpittman-hitachi / rpms / openssl

Forked from rpms/openssl 2 years ago
Clone

Blame SOURCES/openssl-1.1.1-detected-addr-ipv6.patch

81356c
diff -up openssl-1.1.1k/apps/s_socket.c.addr-ipv6 openssl-1.1.1k/apps/s_socket.c
81356c
--- openssl-1.1.1k/apps/s_socket.c.addr-ipv6	2021-07-16 15:14:08.491986682 +0200
81356c
+++ openssl-1.1.1k/apps/s_socket.c	2021-07-16 15:23:21.271329197 +0200
81356c
@@ -214,6 +214,8 @@ int do_server(int *accept_sock, const ch
81356c
     const BIO_ADDRINFO *next;
81356c
     int sock_family, sock_type, sock_protocol, sock_port;
81356c
     const BIO_ADDR *sock_address;
81356c
+    int sock_family_fallback = AF_UNSPEC;
81356c
+    const BIO_ADDR *sock_address_fallback = NULL;
81356c
     int sock_options = BIO_SOCK_REUSEADDR;
81356c
     int ret = 0;
81356c
 
81356c
@@ -244,6 +246,10 @@ int do_server(int *accept_sock, const ch
81356c
             && BIO_ADDRINFO_protocol(next) == sock_protocol) {
81356c
         if (sock_family == AF_INET
81356c
                 && BIO_ADDRINFO_family(next) == AF_INET6) {
81356c
+            /* In case AF_INET6 is returned but not supported by the
81356c
+             * kernel, retry with the first detected address family */
81356c
+            sock_family_fallback = sock_family;
81356c
+            sock_address_fallback = sock_address;
81356c
             sock_family = AF_INET6;
81356c
             sock_address = BIO_ADDRINFO_address(next);
81356c
         } else if (sock_family == AF_INET6
81356c
@@ -253,6 +259,10 @@ int do_server(int *accept_sock, const ch
81356c
     }
81356c
 
81356c
     asock = BIO_socket(sock_family, sock_type, sock_protocol, 0);
81356c
+	if (asock == INVALID_SOCKET && sock_family_fallback != AF_UNSPEC) {
81356c
+       asock = BIO_socket(sock_family_fallback, sock_type, sock_protocol, 0);
81356c
+       sock_address = sock_address_fallback;
81356c
+	}
81356c
     if (asock == INVALID_SOCKET
81356c
         || !BIO_listen(asock, sock_address, sock_options)) {
81356c
         BIO_ADDRINFO_free(res);