[Openvpn-devel,RFC,6/8] if a local IPv6 address is provided, socket must be v6-only

Message ID 20180425195722.20744-7-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
Signed-off-by: Antonio Quartulli <a@unstable.cc>
---
 src/openvpn/socket.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Patch

diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c
index 84d828e6..79fbc6a8 100644
--- a/src/openvpn/socket.c
+++ b/src/openvpn/socket.c
@@ -988,9 +988,15 @@  bind_local(struct link_socket *sock, const sa_family_t ai_family)
         }
         else
         {
+            bool v6only = sock->info.bind_ipv6_only;
+
+            /* 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", sock->info.bind_ipv6_only);
+                        ai_family, "TCP/UDP", v6only);
         }
     }
 }