Browse code

socket: don't transfer bind family to socket in case of ANY address

With the introduction of multisocket, we need to transfer the
AI family of the bound address to the socket, as it may differ
from what was set globally.

However, this operation makes sense only when getaddrinfo()
for bind is performed on a non-empty hostname.
An empty hostname (ANY) may return AF_INET which will break
following connection attempts to v6 only remotes.

Change-Id: I27f305d3ae9bf650bab409e99173688d9f88ab65
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
Acked-by: Arne Schwabe <arne-openvpn@rfc2549.org>
Message-Id: <20250325090121.28813-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg31235.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Antonio Quartulli authored on 2025/03/25 18:01:15
Showing 1 changed files
... ...
@@ -1741,9 +1741,19 @@ resolve_bind_local(struct link_socket *sock, const sa_family_t af)
1741 1741
                 gai_strerror(status));
1742 1742
         }
1743 1743
 
1744
-        /* the resolved 'local entry' might have a different family than what
1745
-         * was globally configured */
1746
-        sock->info.af = sock->info.lsa->bind_local->ai_family;
1744
+        /* the address family returned by openvpn_getaddrinfo() should be
1745
+         * taken into consideration only if we really passed an hostname
1746
+         * to resolve. Otherwise its value is not useful to us and may
1747
+         * actually break our socket, i.e. when it returns AF_INET
1748
+         * but our remote is v6 only.
1749
+         */
1750
+        if (sock->local_host)
1751
+        {
1752
+            /* the resolved 'local entry' might have a different family than
1753
+             * what was globally configured
1754
+             */
1755
+            sock->info.af = sock->info.lsa->bind_local->ai_family;
1756
+        }
1747 1757
     }
1748 1758
 
1749 1759
     gc_free(&gc);