]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
* correctly setup hints.ai_socktype for getaddrinfo(),
authorJuanJo Ciarlante <jjo@google.com>
Thu, 24 Sep 2009 18:09:55 +0000 (20:09 +0200)
committerJuanJo Ciarlante <juanjosec@gmail.com>
Fri, 25 Mar 2011 12:30:29 +0000 (13:30 +0100)
  althought sorta hacky, see TODO.ipv6.

README.ipv6.txt
TODO.ipv6 [new file with mode: 0644]
socket.c
socket.h

index 3a894f0269e82a180d262287c9be47f0afe58c59..f9b617139b73d6e516fab679db89cffc5527f1f2 100644 (file)
@@ -60,15 +60,7 @@ Available under GPLv2 from
     addr_copy(), addr_zero(), ...etc
     proto_is_udp(), proto_is_dgram(), proto_is_net()
 
-* TODO:
-  -  Should not use random for listening in IPv6 "by name", as eg
-     ip6-localhost could return any ifindex, or "randomly" behave as
-     if it were IPV6_V6ONLY (caught this in my unittesting)
-  -  win32: find out about mapped addresses, as I can't make it work
-            with bound at ::1 and connect to 127.0.0.1
-  -  Implement comparison for mapped addesses: server in dual stack
-     listening IPv6 must permit incoming streams from allowed IPv4 peer,
-     currently you need to pass eg:  --remote ffff::1.2.3.4
+* TODO: See TODO.ipv6
 
 --
 JuanJo Ciarlante   jjo () google () com
diff --git a/TODO.ipv6 b/TODO.ipv6
new file mode 100644 (file)
index 0000000..c19e42c
--- /dev/null
+++ b/TODO.ipv6
@@ -0,0 +1,11 @@
+* make possible to get AF from getaddrinfo() answer, ie allow openvpn to
+  use ipv4/6 if DNS returns A/AAAA without specifying protocol.
+  Hard: requires deep changes in initialization/calling logic
+* the getaddr()/getaddr6() interface is not prepared for handling socktype
+  "tagging", currently I abuse the sockflags bits for getting the ai_socktype
+  downstream.
+* win32: find out about mapped addresses, as I can't make it work
+  with bound at ::1 and connect to 127.0.0.1
+* implement comparison for mapped addesses: server in dual stack
+  listening IPv6 must permit incoming streams from allowed IPv4 peer,
+  currently you need to pass eg:  --remote ffff::1.2.3.4
index 3024ea4e96cc08cd5b86e6551d151bdb9b027260..96d26026eecae0b6dc73e5d3f1c734eade549144 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -52,13 +52,12 @@ const int proto_overhead[] = { /* indexed by PROTO_x */
  * Convert sockflags/getaddr_flags into getaddr_flags
  */
 static unsigned int
-sf2gaf(const unsigned int getaddr_flags,
+sf2gaf(unsigned int getaddr_flags,
        const unsigned int sockflags)
 {
-  if (sockflags & SF_HOST_RANDOMIZE)
-    return getaddr_flags | GETADDR_RANDOMIZE;
-  else
-    return getaddr_flags;
+  getaddr_flags |= (sockflags & SF_GETADDRINFO_DGRAM) ? GETADDR_DGRAM : 0;
+  getaddr_flags |= (sockflags & SF_HOST_RANDOMIZE) ? GETADDR_RANDOMIZE : 0;
+  return getaddr_flags;
 }
 
 /*
@@ -375,7 +374,11 @@ getaddr6 (unsigned int flags,
        {
          /* try hostname lookup */
           hints.ai_flags = 0;
+          hints.ai_socktype = dnsflags_to_socktype(flags);
+         dmsg (D_SOCKET_DEBUG, "GETADDR6 flags=0x%04x ai_family=%d ai_socktype=%d",
+               flags, hints.ai_family, hints.ai_socktype);
           err = getaddrinfo(hostname, NULL, &hints, &ai);
+
           if (gai_err)
             *gai_err = err;
 
@@ -891,6 +894,7 @@ create_socket (struct link_socket *sock)
   if (sock->info.proto == PROTO_UDPv4)
     {
       sock->sd = create_socket_udp (sock->sockflags);
+      sock->sockflags |= SF_GETADDRINFO_DGRAM;
 
 #ifdef ENABLE_SOCKS
       if (sock->socks_proxy)
@@ -911,6 +915,7 @@ create_socket (struct link_socket *sock)
   else if (sock->info.proto == PROTO_UDPv6)
     {
       sock->sd = create_socket_udp6 (sock->sockflags);
+      sock->sockflags |= SF_GETADDRINFO_DGRAM;
     }
 #endif
   else
@@ -1492,7 +1497,6 @@ resolve_remote (struct link_socket *sock,
                 }
 #endif
 
-             
              dmsg (D_SOCKET_DEBUG, "RESOLVE_REMOTE flags=0x%04x phase=%d rrs=%d sig=%d status=%d",
                   flags,
                   phase,
index 092d448fbd5dc0a4d4c02a0747c0b4998be2bd36..f864ab198477ee511e2421c44601dd60b4ec6142 100644 (file)
--- a/socket.h
+++ b/socket.h
@@ -210,6 +210,7 @@ struct link_socket
 # define SF_TCP_NODELAY (1<<1)
 # define SF_PORT_SHARE (1<<2)
 # define SF_HOST_RANDOMIZE (1<<3)
+# define SF_GETADDRINFO_DGRAM (1<<4)
   unsigned int sockflags;
 
   /* for stream sockets */
@@ -474,6 +475,11 @@ struct resolve_list {
 #define GETADDR_UPDATE_MANAGEMENT_STATE (1<<8)
 #define GETADDR_RANDOMIZE             (1<<9)
 
+/* [ab]use flags bits to get socktype info downstream */
+/* TODO(jjo): resolve tradeoff between hackiness|args-overhead */
+#define GETADDR_DGRAM                 (1<<10)
+#define dnsflags_to_socktype(flags) ((flags & GETADDR_DGRAM) ? SOCK_DGRAM : SOCK_STREAM)
+
 in_addr_t getaddr (unsigned int flags,
                   const char *hostname,
                   int resolve_retry_seconds,