[Openvpn-devel,S] Change in openvpn[master]: override ai_family if 'local' numeric address was specified

Message ID e421e135fdda0f54c3af1637635955c5d1ec3407-HTML@gerrit.openvpn.net
State Not Applicable
Headers show
Series [Openvpn-devel,S] Change in openvpn[master]: override ai_family if 'local' numeric address was specified | expand

Commit Message

flichtenheld (Code Review) Nov. 15, 2023, 1:45 p.m. UTC
Attention is currently required from: flichtenheld, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/437?usp=email

to review the following change.


Change subject: override ai_family if 'local' numeric address was specified
......................................................................

override ai_family if 'local' numeric address was specified

This change ensures that when a numeric IP address is specified
as argument to a 'local' directive, its ai_family overrides
the one extracted from the 'proto' config option.

Change-Id: I8c9ec61af9e786ec284e756ec3a77a959c79f49b
Signed-off-by: Antonio Quartulli <a@unstable.cc>
---
M src/openvpn/socket.c
1 file changed, 11 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/37/437/1

Patch

diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c
index 5d9e111..ffd8daf 100644
--- a/src/openvpn/socket.c
+++ b/src/openvpn/socket.c
@@ -489,9 +489,8 @@ 
         sig_info = &sigrec;
     }
 
-    /* try numeric ipv6 addr first */
+    /* try numeric ip addr first */
     CLEAR(hints);
-    hints.ai_family = ai_family;
     hints.ai_flags = AI_NUMERICHOST;
 
     if (flags & GETADDR_PASSIVE)
@@ -519,6 +518,10 @@ 
         const char *fmt;
         int level = 0;
 
+        /* this is not a numeric IP, therefore force resolution using the
+         * provided ai_family */
+        hints.ai_family = ai_family;
+
         if (hostname && (flags & GETADDR_RANDOMIZE))
         {
             hostname = hostname_randomize(hostname, &gc);
@@ -1120,7 +1123,9 @@ 
             /* force binding IPv6-only if an address was specified
              * an it is a IPv6 */
             if (sock->local_host && ai_family == AF_INET6)
+            {
                 v6only = true;
+            }
 
             socket_bind(sock->sd, sock->info.lsa->bind_local,
                         ai_family, "TCP/UDP", v6only);
@@ -1712,6 +1717,10 @@ 
                 sock->local_host, sock->local_port,
                 gai_strerror(status));
         }
+
+        /* the resolved 'local entry' might have a different family than what
+         * was globally configured */
+        sock->info.af = sock->info.lsa->bind_local->ai_family;
     }
 
     gc_free(&gc);