[Openvpn-devel,RFC,8/8] override ai_family if 'local' numeric address was specified

Message ID 20180425195722.20744-9-a@unstable.cc
State RFC
Headers show
Series server: support listening on multiple ports/IPs | expand

Commit Message

Antonio Quartulli April 25, 2018, 9:57 a.m. UTC
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.

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

Patch

diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c
index 9d961347..3dd44b83 100644
--- a/src/openvpn/socket.c
+++ b/src/openvpn/socket.c
@@ -378,9 +378,8 @@  openvpn_getaddrinfo(unsigned int flags,
         signal_received = &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)
@@ -408,6 +407,10 @@  openvpn_getaddrinfo(unsigned int flags,
         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);
@@ -1599,6 +1602,10 @@  resolve_bind_local(struct link_socket *sock, const sa_family_t af)
                 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);