]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Work around Solaris getaddrinfo() returing ai_protocol=0
authorArne Schwabe <arne@rfc2549.org>
Mon, 7 Apr 2014 20:12:05 +0000 (22:12 +0200)
committerGert Doering <gert@greenie.muc.de>
Thu, 10 Apr 2014 14:27:09 +0000 (16:27 +0200)
Create_socket() and sub-functions assume that the ai_protocol value
returned by getaddrinfo() is IPPROTO_UDP or IPPROTO_TCP.  On Solaris,
it is "0", because Solaris's socket() call will then "select the right
protocol" - but it breaks our code.  So remove ASSERT()s on ai_protocol,
and also accept properly set ai_socktype (SOCK_DGRAM/SOCK_STREAM) values
if ai_protocol is not set.

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20140407201711.GN16637@greenie.muc.de>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8428

src/openvpn/socket.c

index 7deef0ad5d3075907b5db28ff84dfcf87d611145..ed4bc6fd9801c9070addc8cb28ea8886e223872f 100644 (file)
@@ -775,7 +775,6 @@ create_socket_tcp (struct addrinfo* addrinfo)
 
   ASSERT (addrinfo);
   ASSERT (addrinfo->ai_socktype == SOCK_STREAM);
-  ASSERT (addrinfo->ai_protocol == IPPROTO_TCP);
 
   if ((sd = socket (addrinfo->ai_family, addrinfo->ai_socktype, addrinfo->ai_protocol)) < 0)
     msg (M_ERR, "Cannot create TCP socket");
@@ -800,7 +799,6 @@ create_socket_udp (struct addrinfo* addrinfo, const unsigned int flags)
 
   ASSERT (addrinfo);
   ASSERT (addrinfo->ai_socktype == SOCK_DGRAM);
-  ASSERT (addrinfo->ai_protocol == IPPROTO_UDP);
 
   if ((sd = socket (addrinfo->ai_family, addrinfo->ai_socktype, addrinfo->ai_protocol)) < 0)
     msg (M_ERR, "UDP: Cannot create UDP/UDP6 socket");
@@ -858,7 +856,7 @@ static void bind_local (struct link_socket *sock, const sa_family_t ai_family)
 static void
 create_socket (struct link_socket* sock, struct addrinfo* addr)
 {
-  if (addr->ai_protocol == IPPROTO_UDP)
+  if (addr->ai_protocol == IPPROTO_UDP || addr->ai_socktype == SOCK_DGRAM)
     {
       sock->sd = create_socket_udp (addr, sock->sockflags);
       sock->sockflags |= SF_GETADDRINFO_DGRAM;
@@ -878,7 +876,7 @@ create_socket (struct link_socket* sock, struct addrinfo* addr)
        }
 #endif
     }
-  else if (addr->ai_protocol == IPPROTO_TCP)
+  else if (addr->ai_protocol == IPPROTO_TCP || addr->ai_socktype == SOCK_STREAM)
     {
       sock->sd = create_socket_tcp (addr);
     }
@@ -1806,7 +1804,6 @@ phase2_tcp_client (struct link_socket *sock, struct signal_info *sig_info)
   const bool proxy_retry = false;
 #endif
   do {
-    ASSERT (sock->info.lsa->current_remote->ai_protocol == IPPROTO_TCP);
     socket_connect (&sock->sd,
                    sock->info.lsa->current_remote->ai_addr,
                    sock->connect_timeout,