Skip to contentSkip to conversation

Remove dnsflags_to_socktype, it is not used anywhere

PATCH Applied Arne Schwabe 5 participants 23 messages Nov 30, 2012 – Jan 10, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/10 Remove dnsflags_to_socktype, it is not used anywhere

---
 src/openvpn/socket.c |    2 +-
 src/openvpn/socket.h |    5 -----
 2 files changed, 1 insertion(+), 6 deletions(-)
src/openvpn/socket.c +1 -1
index 505cf3b..21a4b2b 100644
@@ -158,7 +158,7 @@ openvpn_getaddrinfo (unsigned int flags,
   CLEAR(hints);
   hints.ai_family = ai_family;
   hints.ai_flags = AI_NUMERICHOST;
-  hints.ai_socktype = dnsflags_to_socktype(flags);
+  hints.ai_socktype = SOCK_STREAM;
 
   status = getaddrinfo(hostname, NULL, &hints, res);
 
src/openvpn/socket.h +0 -5
index 44f1098..9cb01fa 100644
@@ -478,11 +478,6 @@ bool unix_socket_get_peer_uid_gid (const socket_descriptor_t sd, int *uid, int *
 #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,
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 2/10 Change the type of all ports in openvpn to const char* and let getaddrinfo resolve the port together with the hostname.

This delays error reporting from config parsing to resolving of host addresses. But it allows statements like

remote openvpn.example.org openvpn
port https
management localhost ntp

---
 doc/openvpn.8         |    8 +--
 src/openvpn/init.c    |   20 +++-----
 src/openvpn/manage.c  |   21 ++++----
 src/openvpn/manage.h  |    2 +-
 src/openvpn/options.c |  128 +++++++++++------------------------------------
 src/openvpn/options.h |   14 +++---
 src/openvpn/proxy.c   |   10 ++--
 src/openvpn/proxy.h   |    6 +--
 src/openvpn/ps.c      |   29 ++++++-----
 src/openvpn/ps.h      |    2 +-
 src/openvpn/route.c   |    4 +-
 src/openvpn/socket.c  |  132 ++++++++++++++++++++++---------------------------
 src/openvpn/socket.h  |   20 +++-----
 src/openvpn/socks.c   |   30 +++++++++--
 src/openvpn/socks.h   |    6 +--
 15 files changed, 183 insertions(+), 249 deletions(-)
doc/openvpn.8 +4 -4
index 2ed5201..01257b6 100644
@@ -651,18 +651,18 @@ peer on its new IP address.
 .\"*********************************************************
 .TP
 .B \-\-port port
-TCP/UDP port number for both local and remote.  The current
+TCP/UDP port number or port name for both local and remote.  The current
 default of 1194 represents the official IANA port number
 assignment for OpenVPN and has been used since version 2.0-beta17.
 Previous versions used port 5000 as the default.
 .\"*********************************************************
 .TP
 .B \-\-lport port
-TCP/UDP port number for bind.
+TCP/UDP port number or name for bind.
 .\"*********************************************************
 .TP
 .B \-\-rport port
-TCP/UDP port number for remote.
+TCP/UDP port number or name for remote.
 .\"*********************************************************
 .TP
 .B \-\-bind
@@ -5696,7 +5696,7 @@ Set on program initiation and reset on SIGHUP.
 .\"*********************************************************
 .TP
 .B local_port
-The local port number, specified by
+The local port number or name, specified by
 .B \-\-port
 or
 .B \-\-lport.
src/openvpn/init.c +7 -13
index 25d8225..e21c304 100644
@@ -125,13 +125,6 @@ management_callback_proxy_cmd (void *arg, const char **p)
     ret = true;
   else if (p[2] && p[3])
     {
-      const int port = atoi(p[3]);
-      if (!legal_ipv4_port (port))
-        {
-          msg (M_WARN, "Bad proxy port number: %s", p[3]);
-          return false;
-        }
-
       if (streq (p[1], "HTTP"))
         {
 #ifndef ENABLE_HTTP_PROXY
@@ -146,7 +139,7 @@ management_callback_proxy_cmd (void *arg, const char **p)
             }
           ho = init_http_proxy_options_once (&ce->http_proxy_options, gc);
           ho->server = string_alloc (p[2], gc);
-          ho->port = port;
+          ho->port = p[3];
           ho->retry = true;
           ho->auth_retry = (p[4] && streq (p[4], "nct") ? PAR_NCT : PAR_ALL);
           ret = true;
@@ -158,7 +151,7 @@ management_callback_proxy_cmd (void *arg, const char **p)
           msg (M_WARN, "SOCKS proxy support is not available");
 #else
           ce->socks_proxy_server = string_alloc (p[2], gc);
-          ce->socks_proxy_port = port;
+          ce->socks_proxy_port = p[3];
           ret = true;
 #endif
         }
@@ -225,8 +218,7 @@ management_callback_remote_cmd (void *arg, const char **p)
 	}
       else if (!strcmp(p[1], "MOD") && p[2] && p[3])
 	{
-	  const int port = atoi(p[3]);
-	  if (strlen(p[2]) < RH_HOST_LEN && legal_ipv4_port(port))
+	  if (strlen(p[2]) < RH_HOST_LEN && strlen(p[3]) < RH_PORT_LEN)
 	    {
 	      struct remote_host_store *rhs = c->options.rh_store;
 	      if (!rhs)
@@ -235,8 +227,10 @@ management_callback_remote_cmd (void *arg, const char **p)
 		  c->options.rh_store = rhs;
 		}
 	      strncpynt(rhs->host, p[2], RH_HOST_LEN);
+              strncpynt(rhs->port, p[3], RH_PORT_LEN);
+
 	      ce->remote = rhs->host;
-	      ce->remote_port = port;
+	      ce->remote_port = rhs->port;
 	      flags = CE_MAN_QUERY_REMOTE_MOD;
 	      ret = true;
 	    }
@@ -260,7 +254,7 @@ ce_management_query_remote (struct context *c, const char *remote_ip_hint)
   if (management)
     {
       struct buffer out = alloc_buf_gc (256, &gc);
-      buf_printf (&out, ">REMOTE:%s,%d,%s", np(ce->remote), ce->remote_port, proto2ascii(ce->proto, false));
+      buf_printf (&out, ">REMOTE:%s,%s,%s", np(ce->remote), ce->remote_port, proto2ascii(ce->proto, false));
       management_notify_generic(management, BSTR (&out));
       ce->flags &= ~(CE_MAN_QUERY_REMOTE_MASK<<CE_MAN_QUERY_REMOTE_SHIFT);
       ce->flags |= (CE_MAN_QUERY_REMOTE_QUERY<<CE_MAN_QUERY_REMOTE_SHIFT);
src/openvpn/manage.c +10 -11
index 0a4542a..1ec9b74 100644
@@ -1957,7 +1957,7 @@ man_persist_close (struct man_persist *mp)
 static void
 man_settings_init (struct man_settings *ms,
 		   const char *addr,
-		   const int port,
+		   const char *port,
 		   const char *pass_file,
 		   const char *client_user,
 		   const char *client_group,
@@ -2004,18 +2004,12 @@ man_settings_init (struct man_settings *ms,
 
       ms->write_peer_info_file = string_alloc (write_peer_info_file, NULL);
 
-#if UNIX_SOCK_SUPPORT
+#if UNIX_SOCK_SUPg
       if (ms->flags & MF_UNIX_SOCK)
 	sockaddr_unix_init (&ms->local_unix, addr);
       else
 #endif
 	{
-	  /*
-	   * Initialize socket address
-	   */
-	  ms->local.addr.in4.sin_family = AF_INET;
-	  ms->local.addr.in4.sin_addr.s_addr = 0;
-	  ms->local.addr.in4.sin_port = htons (port);
 
 	  /*
 	   * Run management over tunnel, or
@@ -2027,8 +2021,13 @@ man_settings_init (struct man_settings *ms,
 	    }
 	  else
 	    {
-	      ms->local.addr.in4.sin_addr.s_addr = getaddr
-		(GETADDR_RESOLVE|GETADDR_WARN_ON_SIGNAL|GETADDR_FATAL, addr, 0, NULL, NULL);
+              struct addrinfo* ai;
+              int status = openvpn_getaddrinfo(GETADDR_RESOLVE|GETADDR_WARN_ON_SIGNAL|GETADDR_FATAL,
+                                               addr, port, 0, NULL, AF_INET, &ai);
+              ASSERT(status==0);
+              ms->local.addr.in4 = *((struct sockaddr_in*)ai->ai_addr);
+              freeaddrinfo(ai);
+
 	    }
 	}
       
@@ -2147,7 +2146,7 @@ management_init (void)
 bool
 management_open (struct management *man,
 		 const char *addr,
-		 const int port,
+		 const char *port,
 		 const char *pass_file,
 		 const char *client_user,
 		 const char *client_group,
src/openvpn/manage.h +1 -1
index 28da69f..1498163 100644
@@ -337,7 +337,7 @@ struct management *management_init (void);
 
 bool management_open (struct management *man,
 		      const char *addr,
-		      const int port,
+		      const char *port,
 		      const char *pass_file,
 		      const char *client_user,
 		      const char *client_group,
src/openvpn/options.c +28 -100

282 lines not on this page · raw message

src/openvpn/options.h +8 -6
index 306520b..e4f41cc 100644
@@ -87,9 +87,9 @@ struct options_pre_pull
 struct connection_entry
 {
   int proto;
-  int local_port;
+  const char* local_port;
   bool local_port_defined;
-  int remote_port;
+  const char* remote_port;
   const char *local;
   const char *remote;
   bool remote_float;
@@ -105,7 +105,7 @@ struct connection_entry
 #endif  
 #ifdef ENABLE_SOCKS
   const char *socks_proxy_server;
-  int socks_proxy_port;
+  const char *socks_proxy_port;
   const char *socks_proxy_authfile;
   bool socks_proxy_retry;
 #endif
@@ -143,7 +143,7 @@ struct connection_entry
 struct remote_entry
 {
   const char *remote;
-  int remote_port;
+  const char *remote_port;
   int proto;
 };
 
@@ -168,6 +168,8 @@ struct remote_host_store
 {
 # define RH_HOST_LEN 80
   char host[RH_HOST_LEN];
+#define RH_PORT_LEN 20
+  char port[RH_PORT_LEN];
 };
 
 /* Command line options */
@@ -354,7 +356,7 @@ struct options
 
 #ifdef ENABLE_MANAGEMENT
   const char *management_addr;
-  int management_port;
+  const char *management_port;
   const char *management_user_pass;
   int management_log_history_cache;
   int management_echo_buffer_size;
@@ -449,7 +451,7 @@ struct options
   bool auth_user_pass_verify_script_via_file;
 #if PORT_SHARE
   char *port_share_host;
-  int port_share_port;
+  char *port_share_port;
   const char *port_share_journal_dir;
 #endif
 #endif
src/openvpn/proxy.c +5 -5
index 363d8a7..1774850 100644
@@ -444,7 +444,7 @@ http_proxy_new (const struct http_proxy_options *o)
   if (!o || !o->server)
     msg (M_FATAL, "HTTP_PROXY: server not specified");
 
-  ASSERT (legal_ipv4_port (o->port));
+  ASSERT ( o->port);
 
   ALLOC_OBJ_CLEAR (p, struct http_proxy_info);
   p->options = *o;
@@ -493,7 +493,7 @@ bool
 establish_http_proxy_passthru (struct http_proxy_info *p,
 			       socket_descriptor_t sd, /* already open to proxy */
 			       const char *host,       /* openvpn server remote */
-			       const int port,         /* openvpn server port */
+			       const char *port,         /* openvpn server port */
 			       struct buffer *lookahead,
 			       volatile int *signal_received)
 {
@@ -521,7 +521,7 @@ establish_http_proxy_passthru (struct http_proxy_info *p,
   else
     {
       /* format HTTP CONNECT message */
-      openvpn_snprintf (buf, sizeof(buf), "CONNECT %s:%d HTTP/%s",
+      openvpn_snprintf (buf, sizeof(buf), "CONNECT %s:%s HTTP/%s",
 			host,
 			port,
 			p->options.http_version);
@@ -642,7 +642,7 @@ establish_http_proxy_passthru (struct http_proxy_info *p,
           /* now send the phase 3 reply */
 
           /* format HTTP CONNECT message */
-          openvpn_snprintf (buf, sizeof(buf), "CONNECT %s:%d HTTP/%s",
+          openvpn_snprintf (buf, sizeof(buf), "CONNECT %s:%s HTTP/%s",
 			    host,
 			    port,
 			    p->options.http_version);
@@ -730,7 +730,7 @@ establish_http_proxy_passthru (struct http_proxy_info *p,
 
 
 	      /* build the digest response */
-	      openvpn_snprintf (uri, sizeof(uri), "%s:%d",
+	      openvpn_snprintf (uri, sizeof(uri), "%s:%s",
 				host,
 				port);
 
src/openvpn/proxy.h +3 -3
index 5e476f1..9d75e06 100644
@@ -40,7 +40,7 @@
 
 struct http_proxy_options {
   const char *server;
-  int port;
+  const char *port;
   bool retry;
   int timeout;
 
@@ -57,7 +57,7 @@ struct http_proxy_options {
 
 struct http_proxy_options_simple {
   const char *server;
-  int port;
+  const char *port;
   int auth_retry;
 };
 
@@ -80,7 +80,7 @@ void http_proxy_close (struct http_proxy_info *hp);
 bool establish_http_proxy_passthru (struct http_proxy_info *p,
 				    socket_descriptor_t sd, /* already open to proxy */
 				    const char *host,       /* openvpn server remote */
-				    const int port,         /* openvpn server port */
+				    const char *port,         /* openvpn server port */
 				    struct buffer *lookahead,
 				    volatile int *signal_received);
 
src/openvpn/ps.c +16 -13
index 6495dc7..44eda89 100644
@@ -403,8 +403,7 @@ proxy_connection_io_requeue (struct proxy_connection *pc, const int rwflags_new,
 static bool
 proxy_entry_new (struct proxy_connection **list,
 		 struct event_set *es,
-		 const in_addr_t server_addr,
-		 const int server_port,
+		 const struct sockaddr_in server_addr,
 		 const socket_descriptor_t sd_client,
 		 struct buffer *initial_data,
 		 const char *journal_dir)
@@ -416,7 +415,7 @@ proxy_entry_new (struct proxy_connection **list,
   struct proxy_connection *cp;
 
   /* connect to port share server */
-  sock_addr_set (&osaddr, server_addr, server_port);
+  osaddr.addr.in4 = server_addr;
   if ((sd_server = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
     {
       msg (M_WARN|M_ERRNO, "PORT SHARE PROXY: cannot create socket");
@@ -482,8 +481,7 @@ static bool
 control_message_from_parent (const socket_descriptor_t sd_control,
 			     struct proxy_connection **list,
 			     struct event_set *es,
-			     const in_addr_t server_addr,
-			     const int server_port,
+			     const struct sockaddr_in server_addr,
 			     const int max_initial_buf,
 			     const char *journal_dir)
 {
@@ -539,7 +537,6 @@ control_message_from_parent (const socket_descriptor_t sd_control,
 	      if (proxy_entry_new (list,
 				   es,
 				   server_addr,
-				   server_port,
 				   received_fd,
 				   &buf,
 				   journal_dir))
@@ -716,8 +713,7 @@ proxy_connection_io_dispatch (struct proxy_connection *pc,
  * This is the main function for the port share proxy background process.
  */
 static void
-port_share_proxy (const in_addr_t hostaddr,
-		  const int port,
+port_share_proxy (const struct sockaddr_in hostaddr,
 		  const socket_descriptor_t sd_control,
 		  const int max_initial_buf,
 		  const char *journal_dir)
@@ -754,7 +750,7 @@ port_share_proxy (const in_addr_t hostaddr,
 		  const struct event_set_return *e = &esr[i];
 		  if (e->arg == sd_control_marker)
 		    {
-		      if (!control_message_from_parent (sd_control, &list, es, hostaddr, port, max_initial_buf, journal_dir))
+		      if (!control_message_from_parent (sd_control, &list, es, hostaddr, max_initial_buf, journal_dir))
 			goto done;
 		    }
 		  else
@@ -789,14 +785,16 @@ port_share_proxy (const in_addr_t hostaddr,
  */
 struct port_share *
 port_share_open (const char *host,
-		 const int port,
+		 const char *port,
 		 const int max_initial_buf,
 		 const char *journal_dir)
 {
   pid_t pid;
   socket_descriptor_t fd[2];
-  in_addr_t hostaddr;
+  struct sockaddr_in hostaddr;
   struct port_share *ps;
+  int status;
+  struct addrinfo* ai;
 
   ALLOC_OBJ_CLEAR (ps, struct port_share);
   ps->foreground_fd = -1;
@@ -805,7 +803,12 @@ port_share_open (const char *host,
   /*
    * Get host's IP address
    */
-  hostaddr = getaddr (GETADDR_RESOLVE|GETADDR_HOST_ORDER|GETADDR_FATAL, host, 0, NULL, NULL);
+  
+  status = openvpn_getaddrinfo (GETADDR_RESOLVE|GETADDR_HOST_ORDER|GETADDR_FATAL,
+                                 host, port,  0, NULL, AF_INET, &ai);
+  ASSERT (status==0);
+  hostaddr = *((struct sockaddr_in*) ai->ai_addr);
+  freeaddrinfo(ai);
 
   /*
    * Make a socket for foreground and background processes
@@ -881,7 +884,7 @@ port_share_open (const char *host,
       prng_init (NULL, 0);
 
       /* execute the event loop */
-      port_share_proxy (hostaddr, port, fd[1], max_initial_buf, journal_dir);
+      port_share_proxy (hostaddr, fd[1], max_initial_buf, journal_dir);
 
       openvpn_close_socket (fd[1]);
 
src/openvpn/ps.h +1 -1
index 4280635..e8919d4 100644
@@ -44,7 +44,7 @@ struct port_share {
 extern struct port_share *port_share;
 
 struct port_share *port_share_open (const char *host,
-				    const int port,
+				    const char *port,
 				    const int max_initial_buf,
 				    const char *journal_dir);
 
src/openvpn/route.c +2 -2
index dd69d8e..e7ccd17 100644
@@ -294,12 +294,12 @@ init_route (struct route *r,
   if(get_special_addr (rl, ro->network, &special.s_addr, &status))
     {
       special.s_addr = htonl(special.s_addr);
-      ret = openvpn_getaddrinfo(0, inet_ntoa(special), 0, NULL,
+      ret = openvpn_getaddrinfo(0, inet_ntoa(special), NULL, 0, NULL,
                                 AF_INET, network_list);
     }
   else
     ret = openvpn_getaddrinfo(GETADDR_RESOLVE | GETADDR_WARN_ON_SIGNAL,
-                              ro->network, 0, NULL, AF_INET, network_list);
+                              ro->network, NULL, 0, NULL, AF_INET, network_list);
 
   status = (ret == 0);
 
src/openvpn/socket.c +60 -72

228 lines not on this page · raw message

src/openvpn/socket.h +8 -12
index 9cb01fa..280e5ab 100644
@@ -39,7 +39,7 @@
 /*
  * OpenVPN's default port number as assigned by IANA.
  */
-#define OPENVPN_PORT 1194
+#define OPENVPN_PORT "1194"
 
 /*
  * Maximum size passed passed to setsockopt SNDBUF/RCVBUF
@@ -179,9 +179,9 @@ struct link_socket
   bool connection_profiles_defined;
 
   const char *remote_host;
-  int remote_port;
+  const char *remote_port;
   const char *local_host;
-  int local_port;
+  const char *local_port;
   bool bind_local;
 
 # define INETD_NONE   0
@@ -232,7 +232,7 @@ struct link_socket
 #if defined(ENABLE_HTTP_PROXY) || defined(ENABLE_SOCKS)
   /* The OpenVPN server we will use the proxy to connect to */
   const char *proxy_dest_host;
-  int proxy_dest_port;
+  const char *proxy_dest_port;
 #endif
 
 #if PASSTOS_CAPABILITY
@@ -295,9 +295,9 @@ void
 link_socket_init_phase1 (struct link_socket *sock,
 			 const bool connection_profiles_defined,
 			 const char *local_host,
-			 int local_port,
+			 const char *local_port,
 			 const char *remote_host,
-			 int remote_port,
+			 const char *remote_port,
 			 int proto,
 			 int mode,
 			 const struct link_socket *accept_from,
@@ -477,6 +477,7 @@ bool unix_socket_get_peer_uid_gid (const socket_descriptor_t sd, int *uid, int *
 #define GETADDR_TRY_ONCE              (1<<7)
 #define GETADDR_UPDATE_MANAGEMENT_STATE (1<<8)
 #define GETADDR_RANDOMIZE             (1<<9)
+#define GETADDR_PASSIVE               (1<<10)
 
 in_addr_t getaddr (unsigned int flags,
 		   const char *hostname,
@@ -486,6 +487,7 @@ in_addr_t getaddr (unsigned int flags,
 
 int openvpn_getaddrinfo (unsigned int flags,
                          const char *hostname,
+                         const char *servname,
                          int resolve_retry_seconds,
                          volatile int *signal_received,
                          int ai_family,
@@ -540,12 +542,6 @@ datagram_overhead (int proto)
  */
 
 static inline bool
-legal_ipv4_port (int port)
-{
-  return port > 0 && port < 65536;
-}
-
-static inline bool
 link_socket_proto_connection_oriented (int proto)
 {
   return !proto_is_dgram(proto);
src/openvpn/socks.c +27 -3
index 235982e..c2203c2 100644
@@ -61,7 +61,7 @@ socks_adjust_frame_parameters (struct frame *frame, int proto)
 
 struct socks_proxy_info *
 socks_proxy_new (const char *server,
-		 int port,
+		 const char *port,
 		 const char *authfile,
 		 bool retry)
 {
@@ -70,7 +70,7 @@ socks_proxy_new (const char *server,
   ALLOC_OBJ_CLEAR (p, struct socks_proxy_info);
 
   ASSERT (server);
-  ASSERT (legal_ipv4_port (port));
+  ASSERT (port);
 
   strncpynt (p->server, server, sizeof (p->server));
   p->port = port;
@@ -389,11 +389,27 @@ recv_socks_reply (socket_descriptor_t sd,
   return true;
 }
 
+static int
+port_from_servname(const char* servname)
+{
+    int port =0;
+    port = atoi(servname);
+    if(port >0 && port < 65536)
+        return port;
+    
+    struct  servent* service;
+    service = getservbyname(servname, NULL);
+    if(service)
+        return service->s_port;
+
+    return 0;
+}
+
 void
 establish_socks_proxy_passthru (struct socks_proxy_info *p,
 			        socket_descriptor_t sd, /* already open to proxy */
 			        const char *host,       /* openvpn server remote */
-			        const int port,         /* openvpn server port */
+			        const char *servname,   /* openvpn server port */
 			        volatile int *signal_received)
 {
   char buf[128];
@@ -414,6 +430,13 @@ establish_socks_proxy_passthru (struct socks_proxy_info *p,
   buf[4] = (char) len;
   memcpy(buf + 5, host, len);
 
+  int port = port_from_servname (servname);
+  if (port ==0)
+    {
+      msg (D_LINK_ERRORS, "establish_socks_proxy_passthrough: Cannot convert %s to port number", servname);
+      goto error;
+    }
+    
   buf[5 + len] = (char) (port >> 8);
   buf[5 + len + 1] = (char) (port & 0xff);
 
@@ -425,6 +448,7 @@ establish_socks_proxy_passthru (struct socks_proxy_info *p,
 	goto error;
       }
   }
+    
 
   /* receive reply from Socks proxy and discard */
   if (!recv_socks_reply (sd, NULL, signal_received))
src/openvpn/socks.h +3 -3
index b55ff6f..30b957d 100644
@@ -42,14 +42,14 @@ struct socks_proxy_info {
   bool retry;
 
   char server[128];
-  int port;
+  const char *port;
   char authfile[256];
 };
 
 void socks_adjust_frame_parameters (struct frame *frame, int proto);
 
 struct socks_proxy_info *socks_proxy_new (const char *server,
-					  int port,
+					  const char *port,
 					  const char *authfile,
 					  bool retry);
 
@@ -58,7 +58,7 @@ void socks_proxy_close (struct socks_proxy_info *sp);
 void establish_socks_proxy_passthru (struct socks_proxy_info *p,
 				     socket_descriptor_t sd, /* already open to proxy */
 				     const char *host,       /* openvpn server remote */
-				     const int port,         /* openvpn server port */
+				     const char *servname,         /* openvpn server port */
 				     volatile int *signal_received);
 
 void establish_socks_proxy_udpassoc (struct socks_proxy_info *p,
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 3/10 Simplify print_sockaddr_ex function, merge duplicate ipv4/ipv6 logic

In reply to Arne Schwabe
---
 src/openvpn/socket.c |   68 ++++++++++++++++++++++----------------------------
 1 file changed, 30 insertions(+), 38 deletions(-)
src/openvpn/socket.c +30 -38
index 5a99de5..8a3301f 100644
@@ -2152,60 +2152,52 @@ print_sockaddr (const struct openvpn_sockaddr *addr, struct gc_arena *gc)
 
 const char *
 print_sockaddr_ex (const struct openvpn_sockaddr *addr,
-		   const char* separator,
-		   const unsigned int flags,
-		   struct gc_arena *gc)
+				   const char* separator,
+				   const unsigned int flags,
+				   struct gc_arena *gc)
 {
   struct buffer out = alloc_buf_gc (128, gc);
   bool addr_is_defined;
+  char buf[NI_MAXHOST] = "";
+
   addr_is_defined = addr_defined (addr);
   if (!addr_is_defined) {
     return "[undef]";
   }
+
+  int port;
+  int salen;
   switch(addr->addr.sa.sa_family)
     {
     case AF_INET:
-	{
-	  const int port= ntohs (addr->addr.in4.sin_port);
-	  buf_puts (&out, "[AF_INET]");
-
-	  if (!(flags & PS_DONT_SHOW_ADDR))
-	    buf_printf (&out, "%s", (addr_defined (addr) ? inet_ntoa (addr->addr.in4.sin_addr) : "[undef]"));
-
-	  if (((flags & PS_SHOW_PORT) || (addr_defined (addr) && (flags & PS_SHOW_PORT_IF_DEFINED)))
-	      && port)
-	    {
-	      if (separator)
-		buf_printf (&out, "%s", separator);
-
-	      buf_printf (&out, "%d", port);
-	    }
-	}
+      port= ntohs (addr->addr.in4.sin_port);
+      buf_puts (&out, "[AF_INET]");
+      salen = sizeof (struct sockaddr_in);
       break;
     case AF_INET6:
-	{
-	  const int port= ntohs (addr->addr.in6.sin6_port);
-	  char buf[INET6_ADDRSTRLEN] = "";
-	  buf_puts (&out, "[AF_INET6]");
-	  if (addr_is_defined)
-	    {
-	      getnameinfo(&addr->addr.sa, sizeof (struct sockaddr_in6),
-			  buf, sizeof (buf), NULL, 0, NI_NUMERICHOST);
-	      buf_puts (&out, buf);
-	    }
-	  if (((flags & PS_SHOW_PORT) || (addr_is_defined && (flags & PS_SHOW_PORT_IF_DEFINED)))
-	      && port)
-	    {
-	      if (separator)
-		buf_puts (&out, separator);
-
-	      buf_printf (&out, "%d", port);
-	    }
-	}
+      port= ntohs (addr->addr.in6.sin6_port);
+      buf_puts (&out, "[AF_INET6]");
+      salen = sizeof (struct sockaddr_in6);
       break;
     default:
       ASSERT(0);
     }
+	
+  if (!(flags & PS_DONT_SHOW_ADDR))
+    {
+      getnameinfo(&addr->addr.sa, salen,
+                  buf, sizeof (buf), NULL, 0, NI_NUMERICHOST);
+      buf_puts (&out, buf);
+    }
+  if (((flags & PS_SHOW_PORT) || (addr_is_defined && (flags & PS_SHOW_PORT_IF_DEFINED)))
+      && port)
+    {
+      if (separator)
+        buf_puts (&out, separator);
+		
+      buf_printf (&out, "%d", port);
+    }
+	
   return BSTR (&out);
 }
 
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 4/10 Split the PROTO_UDP_xx options into AF_INET/AF_INET6 and PROTO_TCP/PROTO_UDP part.

In reply to Arne Schwabe

Splitting will make the code a little bit cleaner and prepares for dual stack

---
 src/openvpn/error.c   |    6 +-
 src/openvpn/forward.c |    8 +--
 src/openvpn/init.c    |   21 +++----
 src/openvpn/options.c |   69 ++++++++++-----------
 src/openvpn/options.h |    2 +
 src/openvpn/socket.c  |  160 ++++++++++++++++++++++++-------------------------
 src/openvpn/socket.h  |   21 ++++---
 src/openvpn/socks.c   |    2 +-
 8 files changed, 140 insertions(+), 149 deletions(-)
src/openvpn/error.c +3 -3
index 6848425..4a0418a 100644
@@ -602,7 +602,7 @@ x_check_status (int status,
   const char *extended_msg = NULL;
 
   msg (x_cs_verbose_level, "%s %s returned %d",
-       sock ? proto2ascii (sock->info.proto, true) : "",
+       sock ? proto2ascii (sock->info.proto, sock->info.af, true) : "",
        description,
        status);
 
@@ -630,14 +630,14 @@ x_check_status (int status,
 	  if (extended_msg)
 	    msg (x_cs_info_level, "%s %s [%s]: %s (code=%d)",
 		 description,
-		 sock ? proto2ascii (sock->info.proto, true) : "",
+		 sock ? proto2ascii (sock->info.proto, sock->info.af, true) : "",
 		 extended_msg,
 		 strerror_ts (my_errno, &gc),
 		 my_errno);
 	  else
 	    msg (x_cs_info_level, "%s %s: %s (code=%d)",
 		 description,
-		 sock ? proto2ascii (sock->info.proto, true) : "",
+		 sock ? proto2ascii (sock->info.proto, sock->info.af, true) : "",
 		 strerror_ts (my_errno, &gc),
 		 my_errno);
 
src/openvpn/forward.c +4 -4
index 57c7846..173d5a5 100644
@@ -620,7 +620,7 @@ check_timeout_random_component (struct context *c)
 static inline void
 socks_postprocess_incoming_link (struct context *c)
 {
-  if (c->c2.link_socket->socks_proxy && c->c2.link_socket->info.proto == PROTO_UDPv4)
+  if (c->c2.link_socket->socks_proxy && c->c2.link_socket->info.proto == PROTO_UDP)
     socks_process_incoming_udp (&c->c2.buf, &c->c2.from);
 }
 
@@ -629,7 +629,7 @@ socks_preprocess_outgoing_link (struct context *c,
 				struct link_socket_actual **to_addr,
 				int *size_delta)
 {
-  if (c->c2.link_socket->socks_proxy && c->c2.link_socket->info.proto == PROTO_UDPv4)
+  if (c->c2.link_socket->socks_proxy && c->c2.link_socket->info.proto == PROTO_UDP)
     {
       *size_delta += socks_process_outgoing_udp (&c->c2.to_link, c->c2.to_link_addr);
       *to_addr = &c->c2.link_socket->socks_relay;
@@ -778,7 +778,7 @@ process_incoming_link (struct context *c)
     fprintf (stderr, "R");
 #endif
   msg (D_LINK_RW, "%s READ [%d] from %s: %s",
-       proto2ascii (lsi->proto, true),
+       proto2ascii (lsi->proto, lsi->af, true),
        BLEN (&c->c2.buf),
        print_link_socket_actual (&c->c2.from, &gc),
        PROTO_DUMP (&c->c2.buf, &gc));
@@ -1116,7 +1116,7 @@ process_outgoing_link (struct context *c)
 	    fprintf (stderr, "W");
 #endif
 	  msg (D_LINK_RW, "%s WRITE [%d] to %s: %s",
-	       proto2ascii (c->c2.link_socket->info.proto, true),
+	       proto2ascii (c->c2.link_socket->info.proto, c->c2.link_socket->info.proto, true),
 	       BLEN (&c->c2.to_link),
 	       print_link_socket_actual (c->c2.to_link_addr, &gc),
 	       PROTO_DUMP (&c->c2.to_link, &gc));
src/openvpn/init.c +8 -13
index e21c304..9cfb618 100644
@@ -131,9 +131,7 @@ management_callback_proxy_cmd (void *arg, const char **p)
           msg (M_WARN, "HTTP proxy support is not available");
 #else
           struct http_proxy_options *ho;
-          if (ce->proto != PROTO_TCPv4 && ce->proto != PROTO_TCPv4_CLIENT &&
-              ce->proto != PROTO_TCPv6 && ce->proto != PROTO_TCPv6_CLIENT)
-            {
+          if (ce->proto != PROTO_TCP && ce->proto != PROTO_TCP_CLIENT )            {
               msg (M_WARN, "HTTP proxy support only works for TCP based connections");
               return false;
             }
@@ -254,7 +252,7 @@ ce_management_query_remote (struct context *c, const char *remote_ip_hint)
   if (management)
     {
       struct buffer out = alloc_buf_gc (256, &gc);
-      buf_printf (&out, ">REMOTE:%s,%s,%s", np(ce->remote), ce->remote_port, proto2ascii(ce->proto, false));
+      buf_printf (&out, ">REMOTE:%s,%s,%s", np(ce->remote), ce->remote_port, proto2ascii(ce->proto, ce->af, false));
       management_notify_generic(management, BSTR (&out));
       ce->flags &= ~(CE_MAN_QUERY_REMOTE_MASK<<CE_MAN_QUERY_REMOTE_SHIFT);
       ce->flags |= (CE_MAN_QUERY_REMOTE_QUERY<<CE_MAN_QUERY_REMOTE_SHIFT);
@@ -1824,17 +1822,14 @@ socket_restart_pause (struct context *c)
 
   switch (c->options.ce.proto)
     {
-    case PROTO_UDPv4:
-    case PROTO_UDPv6:
+    case PROTO_UDP:
       if (proxy)
 	sec = c->options.ce.connect_retry_seconds;
       break;
-    case PROTO_TCPv4_SERVER:
-    case PROTO_TCPv6_SERVER:
+    case PROTO_TCP_SERVER:
       sec = 1;
       break;
-    case PROTO_TCPv4_CLIENT:
-    case PROTO_TCPv6_CLIENT:
+    case PROTO_TCP_CLIENT:
       sec = c->options.ce.connect_retry_seconds;
       break;
     }
@@ -2190,7 +2185,7 @@ do_init_crypto_tls (struct context *c, const unsigned int flags)
 
   /* should we not xmit any packets until we get an initial
      response from client? */
-  if (to.server && options->ce.proto == PROTO_TCPv4_SERVER)
+  if (to.server && options->ce.proto == PROTO_TCP_SERVER)
     to.xmit_hold = true;
 
 #ifdef ENABLE_OCC
@@ -2609,6 +2604,7 @@ do_init_socket_1 (struct context *c, const int mode)
 			   c->options.ce.remote,
 			   c->options.ce.remote_port,
 			   c->options.ce.proto,
+         c->options.ce.af,
 			   mode,
 			   c->c2.accept_from,
 #ifdef ENABLE_HTTP_PROXY
@@ -3265,8 +3261,7 @@ init_instance (struct context *c, const struct env_set *env, const unsigned int
   /* link_socket_mode allows CM_CHILD_TCP
      instances to inherit acceptable fds
      from a top-level parent */
-  if (c->options.ce.proto == PROTO_TCPv4_SERVER
-      || c->options.ce.proto == PROTO_TCPv6_SERVER)
+  if (c->options.ce.proto == PROTO_TCP_SERVER)
     {
       if (c->mode == CM_TOP)
 	link_socket_mode = LS_MODE_TCP_LISTEN;
src/openvpn/options.c +35 -34

224 lines not on this page · raw message

src/openvpn/options.h +2 -0
index e4f41cc..c16d509 100644
@@ -87,6 +87,7 @@ struct options_pre_pull
 struct connection_entry
 {
   int proto;
+  sa_family_t af;
   const char* local_port;
   bool local_port_defined;
   const char* remote_port;
@@ -145,6 +146,7 @@ struct remote_entry
   const char *remote;
   const char *remote_port;
   int proto;
+  sa_family_t af;
 };
 
 #define CONNECTION_LIST_SIZE 64
src/openvpn/socket.c +77 -83

358 lines not on this page · raw message

src/openvpn/socket.h +10 -11
index 280e5ab..1eff572 100644
@@ -110,6 +110,7 @@ struct link_socket_info
   const struct plugin_list *plugins;
   bool remote_float;  
   int proto;                    /* Protocol (PROTO_x defined below) */
+  sa_family_t af;                       /* Address family like AF_INET, AF_INET6 or AF_UNSPEC*/
   int mtu_changed;              /* Set to true when mtu value is changed */
 };
 
@@ -299,6 +300,7 @@ link_socket_init_phase1 (struct link_socket *sock,
 			 const char *remote_host,
 			 const char *remote_port,
 			 int proto,
+       sa_family_t af,
 			 int mode,
 			 const struct link_socket *accept_from,
 #ifdef ENABLE_HTTP_PROXY
@@ -503,19 +505,16 @@ int openvpn_getaddrinfo (unsigned int flags,
  */
 enum proto_num {
 	PROTO_NONE, /* catch for uninitialized */
-	PROTO_UDPv4,
-	PROTO_TCPv4_SERVER,
-	PROTO_TCPv4_CLIENT,
-	PROTO_TCPv4,
-	PROTO_UDPv6,
-	PROTO_TCPv6_SERVER,
-	PROTO_TCPv6_CLIENT,
-	PROTO_TCPv6,
+	PROTO_UDP,
+	PROTO_TCP,
+	PROTO_TCP_SERVER,
+	PROTO_TCP_CLIENT,
 	PROTO_N
 };
 
 int ascii2proto (const char* proto_name);
-const char *proto2ascii (int proto, bool display_form);
+sa_family_t ascii2af (const char* proto_name);
+const char *proto2ascii (int proto, sa_family_t af, bool display_form);
 const char *proto2ascii_all (struct gc_arena *gc);
 int proto_remote (int proto, bool remote);
 const char *addr_family_name(int af);
@@ -681,9 +680,9 @@ addr_inet4or6(struct sockaddr *addr)
 	return addr->sa_family == AF_INET || addr->sa_family == AF_INET6;
 }
 
-int addr_guess_family(int proto, const char *name);
+int addr_guess_family(sa_family_t af,const char *name);
 static inline int
-af_addr_size(unsigned short af)
+af_addr_size(sa_family_t af)
 {
    switch(af) {
      case AF_INET: return sizeof (struct sockaddr_in);
src/openvpn/socks.c +1 -1
index c2203c2..804c983 100644
@@ -55,7 +55,7 @@
 void
 socks_adjust_frame_parameters (struct frame *frame, int proto)
 {
-  if (proto == PROTO_UDPv4)
+  if (proto == PROTO_UDP)
     frame_add_to_extra_link (frame, 10);
 }
 
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH 5/10 Split link_socket_init_phase2 into smaller more managable/readable functions. No functional changes

In reply to Arne Schwabe
---
 src/openvpn/socket.c |  509 ++++++++++++++++++++++++++++----------------------
 1 file changed, 282 insertions(+), 227 deletions(-)
src/openvpn/socket.c +282 -227
index 31d05eb..3a9af65 100644
@@ -1316,6 +1316,23 @@ link_socket_new (void)
   return sock;
 }
 
+void
+create_new_socket (struct link_socket* sock, int mark)
+{
+  create_socket (sock);
+    
+  /* set socket buffers based on --sndbuf and --rcvbuf options */
+  socket_set_buffers (sock->sd, &sock->socket_buffer_sizes);
+    
+  /* set socket to --mark packets with given value */
+  socket_set_mark (sock->sd, mark);
+    
+  if(sock->bind_local)
+      resolve_bind_local (sock);
+  resolve_remote (sock, 1, NULL, NULL);
+}
+
+
 /* bind socket if necessary */
 void
 link_socket_init_phase1 (struct link_socket *sock,
@@ -1461,27 +1478,253 @@ link_socket_init_phase1 (struct link_socket *sock,
     }
   else if (mode != LS_MODE_TCP_ACCEPT_FROM)
     {
-      create_socket (sock);
+      create_new_socket (sock, mark);
+    }
+}
+
+static
+void phase2_inetd (struct link_socket* sock, const struct frame *frame,
+                   const char *remote_dynamic, volatile int *signal_received)
+{
+  bool remote_changed = false;
 
-      /* set socket buffers based on --sndbuf and --rcvbuf options */
-      socket_set_buffers (sock->sd, &sock->socket_buffer_sizes);
+  if (sock->info.proto == PROTO_TCP_SERVER) {
+    /* AF_INET as default (and fallback) for inetd */
+    sock->info.lsa->actual.dest.addr.sa.sa_family = AF_INET;
+#ifdef HAVE_GETSOCKNAME
+    {
+      /* inetd: hint family type for dest = local's */
+      struct openvpn_sockaddr local_addr;
+      socklen_t addrlen = sizeof(local_addr);
+      if (getsockname (sock->sd, (struct sockaddr *)&local_addr, &addrlen) == 0) {
+        sock->info.lsa->actual.dest.addr.sa.sa_family = local_addr.addr.sa.sa_family;
+        dmsg (D_SOCKET_DEBUG, "inetd(%s): using sa_family=%d from getsockname(%d)",
+              proto2ascii(sock->info.proto, sock->info.af, false), local_addr.addr.sa.sa_family,
+              sock->sd);
+      } else
+        msg (M_WARN, "inetd(%s): getsockname(%d) failed, using AF_INET",
+             proto2ascii(sock->info.proto, sock->info.af, false), sock->sd);
+    }
+#else
+    msg (M_WARN, "inetd(%s): this OS does not provide the getsockname() "
+         "function, using AF_INET",
+         proto2ascii(sock->info.proto, false));
+#endif
+    sock->sd =
+      socket_listen_accept (sock->sd,
+                            &sock->info.lsa->actual,
+                            remote_dynamic,
+                            &remote_changed,
+                            &sock->info.lsa->local,
+                            false,
+                            sock->inetd == INETD_NOWAIT,
+                            signal_received);
+  }
+  ASSERT (!remote_changed);
+}
 
-      /* set socket to --mark packets with given value */
-      socket_set_mark (sock->sd, mark);
-      
-      if(sock->bind_local)
-          resolve_bind_local (sock);
-      resolve_remote (sock, 1, NULL, NULL);
+static void
+phase2_set_socket_flags (struct link_socket* sock)
+{
+  /* set misc socket parameters */
+  socket_set_flags (sock->sd, sock->sockflags);
+
+  /* set socket to non-blocking mode */
+  set_nonblock (sock->sd);
+
+  /* set socket file descriptor to not pass across execs, so that
+     scripts don't have access to it */
+  set_cloexec (sock->sd);
+
+#ifdef ENABLE_SOCKS
+  if (socket_defined (sock->ctrl_sd))
+    set_cloexec (sock->ctrl_sd);
+#endif
+
+  /* set Path MTU discovery options on the socket */
+  set_mtu_discover_type (sock->sd, sock->mtu_discover_type);
+
+#if EXTENDED_SOCKET_ERROR_CAPABILITY
+  /* if the OS supports it, enable extended error passing on the socket */
+  set_sock_extended_error_passing (sock->sd);
+#endif
+}
+
+
+static void
+linksock_print_addr (struct link_socket *sock)
+{
+  struct gc_arena gc = gc_new ();
+
+  /* print local address */
+  {
+    const int msglevel = (sock->mode == LS_MODE_TCP_ACCEPT_FROM) ? D_INIT_MEDIUM : M_INFO;
+    
+    if (sock->inetd)
+      msg (msglevel, "%s link local: [inetd]", proto2ascii (sock->info.proto, sock->info.af, true));
+    else
+      msg (msglevel, "%s link local%s: %s",
+           proto2ascii (sock->info.proto, sock->info.af, true),
+           (sock->bind_local ? " (bound)" : ""),
+           print_sockaddr_ex (&sock->info.lsa->local, ":", sock->bind_local ? PS_SHOW_PORT : 0, &gc));
+    
+    /* print active remote address */
+    msg (msglevel, "%s link remote: %s",
+         proto2ascii (sock->info.proto, sock->info.af, true),
+         print_link_socket_actual_ex (&sock->info.lsa->actual,
+                                      ":",
+                                      PS_SHOW_PORT_IF_DEFINED,
+                                      &gc));
+  }
+  gc_free(&gc);
+}
+
+static void
+phase2_tcp_server (struct link_socket *sock, bool *remote_changed,
+                   const char *remote_dynamic, volatile int *signal_received)
+{
+  switch (sock->mode)
+    {
+    case LS_MODE_DEFAULT:
+      sock->sd = socket_listen_accept (sock->sd,
+                                       &sock->info.lsa->actual,
+                                       remote_dynamic,
+                                       remote_changed,
+                                       &sock->info.lsa->local,
+                                       true,
+                                       false,
+                                       signal_received);
+      break;
+    case LS_MODE_TCP_LISTEN:
+      socket_do_listen (sock->sd,
+                        &sock->info.lsa->local,
+                        true,
+                        false);
+      break;
+    case LS_MODE_TCP_ACCEPT_FROM:
+      sock->sd = socket_do_accept (sock->sd,
+                                   &sock->info.lsa->actual,
+                                   false);
+      if (!socket_defined (sock->sd))
+        {
+          *signal_received = SIGTERM;
+          return;
+        }
+      tcp_connection_established (&sock->info.lsa->actual);
+      break;
+    default:
+      ASSERT (0);
     }
+
 }
 
+
+static void
+phase2_tcp_client (struct link_socket *sock, bool *remote_changed,
+                   const char *remote_dynamic, volatile int *signal_received)
+{
+#ifdef GENERAL_PROXY_SUPPORT
+    bool proxy_retry = false;
+#else
+    const bool proxy_retry = false;
+#endif
+    do {
+        socket_connect (&sock->sd,
+                        &sock->info.lsa->local,
+                        sock->bind_local,
+                        &sock->info.lsa->actual.dest,
+                        sock->connection_profiles_defined,
+                        remote_dynamic,
+                        remote_changed,
+                        sock->connect_retry_seconds,
+                        sock->connect_timeout,
+                        sock->connect_retry_max,
+                        sock->sockflags,
+                        signal_received);
+        
+        if (*signal_received)
+            return;
+        
+        if (false)
+            ;
+#ifdef ENABLE_HTTP_PROXY
+        else if (sock->http_proxy)
+            {
+                proxy_retry = establish_http_proxy_passthru (sock->http_proxy,
+                                                             sock->sd,
+                                                             sock->proxy_dest_host,
+                                                             sock->proxy_dest_port,
+                                                             &sock->stream_buf.residual,
+                                                             signal_received);
+            }
+#endif
+#ifdef ENABLE_SOCKS
+        else if (sock->socks_proxy)
+            {
+                establish_socks_proxy_passthru (sock->socks_proxy,
+                                                sock->sd,
+                                                sock->proxy_dest_host,
+                                                sock->proxy_dest_port,
+                                                signal_received);
+            }
+#endif
+        if (proxy_retry)
+            {
+                openvpn_close_socket (sock->sd);
+                sock->sd = create_socket_tcp (AF_INET);
+            }
+    } while (proxy_retry);
+
+}
+
+#ifdef ENABLE_SOCKS
+static void
+phase2_socks_client (struct link_socket *sock, bool *remote_changed,
+                      const char *remote_dynamic, volatile int *signal_received)
+{
+    socket_connect (&sock->ctrl_sd,
+                    &sock->info.lsa->local,
+                    sock->bind_local,
+                    &sock->info.lsa->actual.dest,
+                    sock->connection_profiles_defined,
+                    remote_dynamic,
+                    remote_changed,
+                    sock->connect_retry_seconds,
+                    sock->connect_timeout,
+                    sock->connect_retry_max,
+                    sock->sockflags,
+                    signal_received);
+    
+    if (*signal_received)
+        return;
+    
+    establish_socks_proxy_udpassoc (sock->socks_proxy,
+                                    sock->ctrl_sd,
+                                    sock->sd,
+                                    &sock->socks_relay.dest,
+                                    signal_received);
+    
+    if (*signal_received)
+        return;
+    
+    sock->remote_host = sock->proxy_dest_host;
+    sock->remote_port = sock->proxy_dest_port;
+    sock->did_resolve_remote = false;
+    
+    addr_zero_host(&sock->info.lsa->actual.dest);
+    addr_zero_host(&sock->info.lsa->remote);
+    
+    resolve_remote (sock, 1, NULL, signal_received);
+    
+}
+#endif
+
 /* finalize socket initialization */
 void
 link_socket_init_phase2 (struct link_socket *sock,
-			 const struct frame *frame,
-			 volatile int *signal_received)
+                         const struct frame *frame,
+                         volatile int *signal_received)
 {
-  struct gc_arena gc = gc_new ();
   const char *remote_dynamic = NULL;
   bool remote_changed = false;
   int sig_save = 0;
@@ -1508,243 +1751,55 @@ link_socket_init_phase2 (struct link_socket *sock,
   /* were we started by inetd or xinetd? */
   if (sock->inetd)
     {
-      if (sock->info.proto == PROTO_TCP_SERVER) {
-	/* AF_INET as default (and fallback) for inetd */
-	sock->info.lsa->actual.dest.addr.sa.sa_family = AF_INET;
-#ifdef HAVE_GETSOCKNAME
-	  {
-	    /* inetd: hint family type for dest = local's */
-	    struct openvpn_sockaddr local_addr;
-	    socklen_t addrlen = sizeof(local_addr);
-	    if (getsockname (sock->sd, (struct sockaddr *)&local_addr, &addrlen) == 0) {
-	      sock->info.lsa->actual.dest.addr.sa.sa_family = local_addr.addr.sa.sa_family;
-	      dmsg (D_SOCKET_DEBUG, "inetd(%s): using sa_family=%d from getsockname(%d)",
-		    proto2ascii(sock->info.proto, sock->info.af, false), local_addr.addr.sa.sa_family,
-		    sock->sd);
-	    } else
-	      msg (M_WARN, "inetd(%s): getsockname(%d) failed, using AF_INET",
-		   proto2ascii(sock->info.proto, sock->info.af, false), sock->sd);
-	  }
-#else
-	msg (M_WARN, "inetd(%s): this OS does not provide the getsockname() "
-	     "function, using AF_INET",
-	     proto2ascii(sock->info.proto, false));
-#endif
-	sock->sd =
-	  socket_listen_accept (sock->sd,
-				&sock->info.lsa->actual,
-				remote_dynamic,
-				&remote_changed,
-				&sock->info.lsa->local,
-				false,
-				sock->inetd == INETD_NOWAIT,
-				signal_received);
-      }
-      ASSERT (!remote_changed);
+      phase2_inetd (sock, frame, remote_dynamic, signal_received);
       if (*signal_received)
-	goto done;
+        goto done;
+
     }
   else
     {
       resolve_remote (sock, 2, &remote_dynamic, signal_received);
 
       if (*signal_received)
-	goto done;
+        goto done;
 
-      /* TCP client/server */
       if (sock->info.proto == PROTO_TCP_SERVER)
-	{
-	  switch (sock->mode)
-	    {
-	    case LS_MODE_DEFAULT:
-	      sock->sd = socket_listen_accept (sock->sd,
-					       &sock->info.lsa->actual,
-					       remote_dynamic,
-					       &remote_changed,
-					       &sock->info.lsa->local,
-					       true,
-					       false,
-					       signal_received);
-	      break;
-	    case LS_MODE_TCP_LISTEN:
-	      socket_do_listen (sock->sd,
-				&sock->info.lsa->local,
-				true,
-				false);
-	      break;
-	    case LS_MODE_TCP_ACCEPT_FROM:
-	      sock->sd = socket_do_accept (sock->sd,
-					   &sock->info.lsa->actual,
-					   false);
-	      if (!socket_defined (sock->sd))
-		{
-		  *signal_received = SIGTERM;
-		  goto done;
-		}
-	      tcp_connection_established (&sock->info.lsa->actual);
-	      break;
-	    default:
-	      ASSERT (0);
-	    }
-	}
+        {
+          phase2_tcp_server(sock, &remote_changed, remote_dynamic,
+                            signal_received);
+        }
       else if (sock->info.proto == PROTO_TCP_CLIENT)
-	{
-
-#ifdef GENERAL_PROXY_SUPPORT
-	  bool proxy_retry = false;
-#else
-	  const bool proxy_retry = false;
-#endif
-	  do {
-	    socket_connect (&sock->sd,
-			    &sock->info.lsa->local,
-			    sock->bind_local,
-			    &sock->info.lsa->actual.dest,
-			    sock->connection_profiles_defined,
-			    remote_dynamic,
-			    &remote_changed,
-			    sock->connect_retry_seconds,
-			    sock->connect_timeout,
-			    sock->connect_retry_max,
-			    sock->sockflags,
-			    signal_received);
-
-	    if (*signal_received)
-	      goto done;
-
-	    if (false)
-	      ;
-#ifdef ENABLE_HTTP_PROXY
-	    else if (sock->http_proxy)
-	      {
-		proxy_retry = establish_http_proxy_passthru (sock->http_proxy,
-							     sock->sd,
-							     sock->proxy_dest_host,
-							     sock->proxy_dest_port,
-							     &sock->stream_buf.residual,
-							     signal_received);
-	      }
-#endif
-#ifdef ENABLE_SOCKS
-	    else if (sock->socks_proxy)
-	      {
-		establish_socks_proxy_passthru (sock->socks_proxy,
-						sock->sd,
-						sock->proxy_dest_host,
-						sock->proxy_dest_port,
-						signal_received);
-	      }
-#endif
-	    if (proxy_retry)
-	      {
-		openvpn_close_socket (sock->sd);
-		sock->sd = create_socket_tcp (AF_INET);
-	      }
-	  } while (proxy_retry);
-	}
+        {
+          phase2_tcp_client(sock, &remote_changed, remote_dynamic,
+                            signal_received);
+    
+        }
 #ifdef ENABLE_SOCKS
       else if (sock->info.proto == PROTO_UDP && sock->socks_proxy && sock->info.af == AF_INET)
-	{
-	  socket_connect (&sock->ctrl_sd,
-                          &sock->info.lsa->local,
-                          sock->bind_local,
-			  &sock->info.lsa->actual.dest,
-			  sock->connection_profiles_defined,
-			  remote_dynamic,
-			  &remote_changed,
-			  sock->connect_retry_seconds,
-			  sock->connect_timeout,
-			  sock->connect_retry_max,
-			  sock->sockflags,
-			  signal_received);
-
-	  if (*signal_received)
-	    goto done;
-
-	  establish_socks_proxy_udpassoc (sock->socks_proxy,
-					  sock->ctrl_sd,
-					  sock->sd,
-					  &sock->socks_relay.dest,
-					  signal_received);
-
-	  if (*signal_received)
-	    goto done;
-
-	  sock->remote_host = sock->proxy_dest_host;
-	  sock->remote_port = sock->proxy_dest_port;
-	  sock->did_resolve_remote = false;
-
-	  addr_zero_host(&sock->info.lsa->actual.dest);
-	  addr_zero_host(&sock->info.lsa->remote);
-
-	  resolve_remote (sock, 1, NULL, signal_received);
-
-	  if (*signal_received)
-	    goto done;
-	}
+        {
+          phase2_socks_client(sock, &remote_changed, remote_dynamic,
+                              signal_received);
 #endif
-
+        }
       if (*signal_received)
-	goto done;
-
+        goto done;
+    
       if (remote_changed)
-	{
-	  msg (M_INFO, "TCP/UDP: Dynamic remote address changed during TCP connection establishment");
-	  addr_copy_host(&sock->info.lsa->remote, &sock->info.lsa->actual.dest);
-	}
+        {
+          msg (M_INFO, "TCP/UDP: Dynamic remote address changed during TCP connection establishment");
+          addr_copy_host(&sock->info.lsa->remote, &sock->info.lsa->actual.dest);
+        }
     }
 
-  /* set misc socket parameters */
-  socket_set_flags (sock->sd, sock->sockflags);
-
-  /* set socket to non-blocking mode */
-  set_nonblock (sock->sd);
-
-  /* set socket file descriptor to not pass across execs, so that
-     scripts don't have access to it */
-  set_cloexec (sock->sd);
-
-#ifdef ENABLE_SOCKS
-  if (socket_defined (sock->ctrl_sd))
-    set_cloexec (sock->ctrl_sd);
-#endif
-
-  /* set Path MTU discovery options on the socket */
-  set_mtu_discover_type (sock->sd, sock->mtu_discover_type);
-
-#if EXTENDED_SOCKET_ERROR_CAPABILITY
-  /* if the OS supports it, enable extended error passing on the socket */
-  set_sock_extended_error_passing (sock->sd);
-#endif
-
-  /* print local address */
-  {
-    const int msglevel = (sock->mode == LS_MODE_TCP_ACCEPT_FROM) ? D_INIT_MEDIUM : M_INFO;
-
-    if (sock->inetd)
-      msg (msglevel, "%s link local: [inetd]", proto2ascii (sock->info.proto, sock->info.af, true));
-    else
-      msg (msglevel, "%s link local%s: %s",
-	   proto2ascii (sock->info.proto, sock->info.af, true),
-	   (sock->bind_local ? " (bound)" : ""),
-	   print_sockaddr_ex (&sock->info.lsa->local, ":", sock->bind_local ? PS_SHOW_PORT : 0, &gc));
-
-    /* print active remote address */
-    msg (msglevel, "%s link remote: %s",
-	 proto2ascii (sock->info.proto, sock->info.af, true),
-	 print_link_socket_actual_ex (&sock->info.lsa->actual,
-				      ":",
-				      PS_SHOW_PORT_IF_DEFINED,
-				      &gc));
-  }
-
+  phase2_set_socket_flags(sock);
+  linksock_print_addr(sock);
+ 
  done:
   if (sig_save && signal_received)
     {
       if (!*signal_received)
-	*signal_received = sig_save;
+        *signal_received = sig_save;
     }
-  gc_free (&gc);
 }
 
 void
Signature · 1 line
1.7.9.5
#5 lore raw

PATCH 6/10 Remove the ip-remote-hint option.

In reply to Arne Schwabe

The ip-remote-hint option overrides the remote hostname of every remote/connection entry unless management-query-remote is also defined and the management interfaces overrides the option with remote MOD … The remote name is even overridden when when management interface issues remote ACCEPT after being presented with the non overridden remote.

Overriding all remote options can also be done by management-query-remote and issuing remote MOD or by changing alll remote statements in the configuration.

Also: remove unused variable newcycle

---
 src/openvpn/init.c    |   17 ++---------------
 src/openvpn/options.c |    5 -----
 src/openvpn/options.h |    1 -
 3 files changed, 2 insertions(+), 21 deletions(-)
src/openvpn/init.c +2 -15
index 9cfb618..864ff3b 100644
@@ -243,7 +243,7 @@ management_callback_remote_cmd (void *arg, const char **p)
 }
 
 static bool
-ce_management_query_remote (struct context *c, const char *remote_ip_hint)
+ce_management_query_remote (struct context *c)
 {
   struct gc_arena gc = gc_new ();
   volatile struct connection_entry *ce = &c->options.ce;
@@ -268,8 +268,6 @@ ce_management_query_remote (struct context *c, const char *remote_ip_hint)
     }
   {
     const int flags = ((ce->flags>>CE_MAN_QUERY_REMOTE_SHIFT) & CE_MAN_QUERY_REMOTE_MASK);
-    if (flags == CE_MAN_QUERY_REMOTE_ACCEPT && remote_ip_hint)
-      ce->remote = remote_ip_hint;
     ret = (flags != CE_MAN_QUERY_REMOTE_SKIP);
   }
   gc_free (&gc);
@@ -319,9 +317,6 @@ next_connection_entry (struct context *c)
       int n_cycles = 0;
 
       do {
-	const char *remote_ip_hint = NULL;
-	bool newcycle = false;
-
 	ce_defined = true;
 	if (l->no_advance && l->current >= 0)
 	  {
@@ -336,16 +331,10 @@ next_connection_entry (struct context *c)
 		if (++n_cycles >= 2)
 		  msg (M_FATAL, "No usable connection profiles are present");
 	      }
-
-	    if (l->current == 0)
-	      newcycle = true;
 	  }
 
 	ce = l->array[l->current];
 
-	if (c->options.remote_ip_hint && !l->n_cycles)
-	  remote_ip_hint = c->options.remote_ip_hint;
-
 	if (ce->flags & CE_DISABLED)
 	  ce_defined = false;
 
@@ -354,14 +343,12 @@ next_connection_entry (struct context *c)
 	if (ce_defined && management && management_query_remote_enabled(management))
 	  {
 	    /* allow management interface to override connection entry details */
-	    ce_defined = ce_management_query_remote(c, remote_ip_hint);
+	    ce_defined = ce_management_query_remote(c);
 	    if (IS_SIG (c))
 	      break;
 	  }
         else
 #endif
-	if (remote_ip_hint)
-	  c->options.ce.remote = remote_ip_hint;
 
 #ifdef ENABLE_MANAGEMENT
         if (ce_defined && management && management_query_proxy_enabled (management))
src/openvpn/options.c +0 -5
index 56fee68..2dd8c9d 100644
@@ -4354,11 +4354,6 @@ add_option (struct options *options,
 	  uninit_options (&sub);
 	}
     }
-  else if (streq (p[0], "remote-ip-hint") && p[1])
-    {
-      VERIFY_PERMISSION (OPT_P_GENERAL);
-      options->remote_ip_hint = p[1];
-    }
 #if HTTP_PROXY_OVERRIDE
   else if (streq (p[0], "http-proxy-override") && p[1] && p[2])
     {
src/openvpn/options.h +0 -1
index c16d509..fde6468 100644
@@ -208,7 +208,6 @@ struct options
 
   /* Networking parms */
   struct connection_entry ce;
-  char *remote_ip_hint;
   struct connection_list *connection_list;
   struct remote_list *remote_list;
   bool force_connection_list;
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH 7/10 change the type of remote to addrinfo.

In reply to Arne Schwabe
---
 src/openvpn/init.c   |    5 +--
 src/openvpn/route.c  |    1 +
 src/openvpn/socket.c |   52 ++++++++++++++++--------------
 src/openvpn/socket.h |   85 +++++++++++++++++++++++++++++++++++++++++++-------
 src/openvpn/tun.c    |   16 ++++++----
 src/openvpn/tun.h    |    2 +-
 6 files changed, 116 insertions(+), 45 deletions(-)
src/openvpn/init.c +3 -2
index 864ff3b..bf72303 100644
@@ -1354,7 +1354,7 @@ do_init_tun (struct context *c)
 			   c->options.ifconfig_ipv6_netbits,
 			   c->options.ifconfig_ipv6_remote,
 			   addr_host (&c->c1.link_socket_addr.local),
-			   addr_host (&c->c1.link_socket_addr.remote),
+			   addr_host (&c->c1.link_socket_addr.remote_list),
 			   !c->options.ifconfig_nowarn,
 			   c->c2.es);
 
@@ -2801,7 +2801,8 @@ do_close_link_socket (struct context *c)
 
   if (!(c->sig->signal_received == SIGUSR1 && c->options.persist_remote_ip))
     {
-      CLEAR (c->c1.link_socket_addr.remote);
+      if (c->c1.link_socket_addr.remote_list)
+        freeaddrinfo(c->c1.link_socket_addr.remote_list);
       CLEAR (c->c1.link_socket_addr.actual);
     }
 
src/openvpn/route.c +1 -0
index e7ccd17..b8704ff 100644
@@ -301,6 +301,7 @@ init_route (struct route *r,
     ret = openvpn_getaddrinfo(GETADDR_RESOLVE | GETADDR_WARN_ON_SIGNAL,
                               ro->network, NULL, 0, NULL, AF_INET, network_list);
 
+
   status = (ret == 0);
 
   if (!status)
src/openvpn/socket.c +28 -24

116 lines not on this page · raw message

src/openvpn/socket.h +73 -12

130 lines not on this page · raw message

src/openvpn/tun.c +10 -6
index 4b0365d..6c842d2 100644
@@ -413,7 +413,7 @@ init_tun (const char *dev,       /* --dev option */
 	  int         ifconfig_ipv6_netbits_parm,
 	  const char *ifconfig_ipv6_remote_parm,    /* --ifconfig parm 2 IPv6 */
 	  in_addr_t local_public,
-	  in_addr_t remote_public,
+	  struct addrinfo *remote_public,
 	  const bool strict_warn,
 	  struct env_set *es)
 {
@@ -467,6 +467,7 @@ init_tun (const char *dev,       /* --dev option */
        */
       if (strict_warn)
 	{
+          struct addrinfo *curele;
 	  ifconfig_sanity_check (tt->type == DEV_TYPE_TUN, tt->remote_netmask, tt->topology);
 
 	  /*
@@ -480,11 +481,14 @@ init_tun (const char *dev,       /* --dev option */
 			    tt->local,
 			    tt->remote_netmask);
 
-	  check_addr_clash ("remote",
-			    tt->type,
-			    remote_public,
-			    tt->local,
-			    tt->remote_netmask);
+          for(curele=remote_public;curele;curele=curele->ai_next) {
+            if(curele->ai_family == AF_INET)
+              check_addr_clash ("remote",
+                                tt->type,
+                                ((struct sockaddr_in*)curele->ai_addr)->sin_addr.s_addr,
+			        tt->local,
+			        tt->remote_netmask);
+          }
 
 	  if (tt->type == DEV_TYPE_TAP || (tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET))
 	    check_subnet_conflict (tt->local, tt->remote_netmask, "TUN/TAP adapter");
src/openvpn/tun.h +1 -1
index 8622bf8..ce23b0d 100644
@@ -232,7 +232,7 @@ struct tuntap *init_tun (const char *dev,       /* --dev option */
 			 int ifconfig_ipv6_netbits_parm,           /* --ifconfig parm 1 / bits */
 			 const char *ifconfig_ipv6_remote_parm,    /* --ifconfig parm 2 / IPv6 */
 			 in_addr_t local_public,
-			 in_addr_t remote_public,
+			 struct addrinfo *remote_public,
 			 const bool strict_warn,
 			 struct env_set *es);
 
Signature · 1 line
1.7.9.5
#7 lore raw

PATCH 8/10 Fix print_sockaddr part 2

In reply to Arne Schwabe
---
 src/openvpn/ps.c     |    4 +--
 src/openvpn/socket.c |   66 ++++++++++++++++++++++++--------------------------
 src/openvpn/socket.h |   16 ++++++++++--
 3 files changed, 47 insertions(+), 39 deletions(-)
src/openvpn/ps.c +2 -2
index 44eda89..98d6580 100644
@@ -330,8 +330,8 @@ journal_add (const char *journal_dir, struct proxy_connection *pc, struct proxy_
   if (!getpeername (pc->sd, (struct sockaddr *) &from.addr.sa, &slen)
       && !getsockname (cp->sd, (struct sockaddr *) &to.addr.sa, &dlen))
     {
-      const char *f = print_sockaddr_ex (&from, ":", PS_SHOW_PORT, &gc);
-      const char *t = print_sockaddr_ex (&to, ":", PS_SHOW_PORT, &gc);
+      const char *f = print_sockaddr (&from, &gc);
+      const char *t = print_sockaddr (&to, &gc);
       fnlen =  strlen(journal_dir) + strlen(t) + 2;
       jfn = (char *) malloc(fnlen);
       check_malloc_return (jfn);
src/openvpn/socket.c +31 -35

126 lines not on this page · raw message

src/openvpn/socket.h +14 -2
index 85307a7..d341c0a 100644
@@ -345,14 +345,26 @@ void sd_close (socket_descriptor_t *sd);
 #define PS_SHOW_PKTINFO         (1<<2)
 #define PS_DONT_SHOW_ADDR       (1<<3)
 
-const char *print_sockaddr_ex (const struct openvpn_sockaddr *addr,
+const char *print_sockaddr_ex (const struct sockaddr *addr,
 			       const char* separator,
 			       const unsigned int flags,
 			       struct gc_arena *gc);
 
+static inline
+const char *print_openvpn_sockaddr_ex (const struct openvpn_sockaddr *addr,
+			       const char* separator,
+			       const unsigned int flags,
+			       struct gc_arena *gc)
+{
+    return print_sockaddr_ex(&addr->addr.sa, separator, flags, gc);
+}
 
+static inline
 const char *print_sockaddr (const struct openvpn_sockaddr *addr,
-			    struct gc_arena *gc);
+			    struct gc_arena *gc)
+{
+    return print_sockaddr_ex (&addr->addr.sa, ":", PS_SHOW_PORT, gc);
+}
 
 const char *print_link_socket_actual_ex (const struct link_socket_actual *act,
 					 const char* separator,
Signature · 1 line
1.7.9.5
#8 lore raw

PATCH 9/10 When resolving fails print the error message from socket layer

In reply to Arne Schwabe
---
 src/openvpn/socket.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
src/openvpn/socket.c +4 -4
index b4d7ea7..7b4a4fb 100644
@@ -186,15 +186,15 @@ openvpn_getaddrinfo (unsigned int flags,
       const char *fmt;
       int level = 0;
       
-      fmt = "RESOLVE: Cannot resolve host address: %s: %s";
+      fmt = "RESOLVE: Cannot resolve host address: %s:%s (%s)";
       if ((flags & GETADDR_MENTION_RESOLVE_RETRY)
           && !resolve_retry_seconds)
-        fmt = "RESOLVE: Cannot resolve host address: %s: %s (I would have retried this name query if you had specified the --resolv-retry option.)";
+        fmt = "RESOLVE: Cannot resolve host address: %s:%s (%s) (I would have retried this name query if you had specified the --resolv-retry option.)";
 
       if (!(flags & GETADDR_RESOLVE) || status == EAI_FAIL)
         {
-          msg (msglevel, "RESOLVE: Cannot parse IP address: %s:%s",
-               print_hostname,print_servname);
+          msg (msglevel, "RESOLVE: Cannot parse IP address: %s:%s (%s)",
+               print_hostname,print_servname, gai_strerror(status));
           goto done;
         }
 
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH 10/10 Implement dual stack client support for OpenVPN

In reply to Arne Schwabe

This patch contains a number of changes. I did not further spit this since some changes make only sense being changed together.

Always use connection_list, simplifies the reconnection logic.

Change meaning of --connect-retry-max and --connect-retry to be used all connections. This now allows OpenVPN to quit after n unsuccessful udp connection attempts

Remove the tcp reconnection logic. Failing a TCP connection will now cause a USR1 like a UDP connection. Also extend sig->source from bool to int to specify signal source. This allows a finer grained reconnection logic if necessary in the future.

Dual-Stack support: if an address resolves to multiple records each address is tried in sequential order. Then proceed to next connection entry. Introduce the field current_remote to represent the current connecting remote. Also change some fields to struct addrinfo* form openvn_addr to store multiple addresses needed for the dual stack support.

Change meaning from udp and tcp to allow both IPv4 and IPv6. Introducue new udp4 and tcp4 to force IPv4.

---
 doc/openvpn.8                |   21 +-
 src/openvpn/error.c          |    2 +-
 src/openvpn/forward-inline.h |    1 +
 src/openvpn/init.c           |  229 +++++++++-------
 src/openvpn/manage.c         |   27 +-
 src/openvpn/manage.h         |    2 +-
 src/openvpn/options.c        |  117 ++++-----
 src/openvpn/options.h        |   24 +-
 src/openvpn/ps.c             |    4 +-
 src/openvpn/push.c           |    2 +-
 src/openvpn/route.c          |    1 -
 src/openvpn/sig.c            |   22 +-
 src/openvpn/sig.h            |   11 +-
 src/openvpn/socket.c         |  591 +++++++++++++++++++-----------------------
 src/openvpn/socket.h         |   62 ++---
 src/openvpn/tun.c            |   11 +-
 src/openvpn/tun.h            |    2 +-
 17 files changed, 554 insertions(+), 575 deletions(-)
doc/openvpn.8 +10 -11
index 01257b6..d66bd66 100644
@@ -456,13 +456,9 @@ possess a built-in reliability layer.
 .\"*********************************************************
 .TP
 .B \-\-connect-retry n
-For
-.B \-\-proto tcp-client,
-take
+Wait
 .B n
-as the
-number of seconds to wait
-between connection retries (default=5).
+seconds  between connection attempts (default=5).
 .\"*********************************************************
 .TP
 .B \-\-connect-timeout n
@@ -474,12 +470,15 @@ seconds (default=10).
 .\"*********************************************************
 .TP
 .B \-\-connect-retry-max n
-For
-.B \-\-proto tcp-client,
-take
 .B n
-as the
-number of retries of connection attempt (default=infinite).
+specifies the number of times all 
+.B \-\-remote 
+respectively 
+.B <connection>
+statements are tried. Specifiying 
+.B n
+as one would try each entry exactly once. A sucessful connection 
+resets the counter. (default=umlimited).
 .\"*********************************************************
 .TP
 .B \-\-show-proxy-settings
src/openvpn/error.c +1 -1
index 4a0418a..ebe9a52 100644
@@ -259,7 +259,7 @@ void x_msg_va (const unsigned int flags, const char *format, va_list arglist)
   if (flags & M_SSL)
     {
       int nerrs = 0;
-      int err;
+      size_t err;
       while ((err = ERR_get_error ()))
 	{
 	  openvpn_snprintf (m2, ERR_BUF_SIZE, "%s: %s",
src/openvpn/forward-inline.h +1 -0
index 5853ce2..7eb480d 100644
@@ -228,6 +228,7 @@ context_reschedule_sec (struct context *c, int sec)
 static inline struct link_socket_info *
 get_link_socket_info (struct context *c)
 {
+
   if (c->c2.link_socket_info)
     return c->c2.link_socket_info;
   else
src/openvpn/init.c +134 -95

350 lines not on this page · raw message

src/openvpn/manage.c +15 -12
index 1ec9b74..dcd303c 100644
@@ -1461,7 +1461,7 @@ man_new_connection_post (struct management *man, const char *description)
 #endif
     msg (D_MANAGEMENT, "MANAGEMENT: %s %s",
 	 description,
-	 print_sockaddr (&man->settings.local, &gc));
+	 print_sockaddr (man->settings.local->ai_addr, &gc));
 
   buffer_list_reset (man->connection.out);
 
@@ -1569,7 +1569,8 @@ man_listen (struct management *man)
 #endif
 	{
 	  man->connection.sd_top = create_socket_tcp (AF_INET);
-	  socket_bind (man->connection.sd_top, &man->settings.local, "MANAGEMENT");
+	  socket_bind (man->connection.sd_top, man->settings.local,
+                       AF_INET, "MANAGEMENT");
 	}
 
       /*
@@ -1593,7 +1594,7 @@ man_listen (struct management *man)
       else
 #endif
 	msg (D_MANAGEMENT, "MANAGEMENT: TCP Socket listening on %s",
-	     print_sockaddr (&man->settings.local, &gc));
+	     print_sockaddr (man->settings.local->ai_addr, &gc));
     }
 
 #ifdef WIN32
@@ -1636,7 +1637,7 @@ man_connect (struct management *man)
     {
       man->connection.sd_cli = create_socket_tcp (AF_INET);
       status = openvpn_connect (man->connection.sd_cli,
-				&man->settings.local,
+				man->settings.local->ai_addr,
 				5,
 				&signal_received);
     }
@@ -1661,7 +1662,7 @@ man_connect (struct management *man)
 #endif
       msg (D_LINK_ERRORS,
 	   "MANAGEMENT: connect to %s failed: %s",
-	   print_sockaddr (&man->settings.local, &gc),
+	   print_sockaddr (man->settings.local->ai_addr, &gc),
 	   strerror_ts (status, &gc));
       throw_signal_soft (SIGTERM, "management-connect-failed");
       goto done;
@@ -2004,7 +2005,7 @@ man_settings_init (struct man_settings *ms,
 
       ms->write_peer_info_file = string_alloc (write_peer_info_file, NULL);
 
-#if UNIX_SOCK_SUPg
+#if UNIX_SOCK_SUPPORT
       if (ms->flags & MF_UNIX_SOCK)
 	sockaddr_unix_init (&ms->local_unix, addr);
       else
@@ -2021,13 +2022,9 @@ man_settings_init (struct man_settings *ms,
 	    }
 	  else
 	    {
-              struct addrinfo* ai;
               int status = openvpn_getaddrinfo(GETADDR_RESOLVE|GETADDR_WARN_ON_SIGNAL|GETADDR_FATAL,
-                                               addr, port, 0, NULL, AF_INET, &ai);
+                                               addr, port, 0, NULL, AF_INET, &ms->local);
               ASSERT(status==0);
-              ms->local.addr.in4 = *((struct sockaddr_in*)ai->ai_addr);
-              freeaddrinfo(ai);
-
 	    }
 	}
       
@@ -2512,7 +2509,13 @@ management_post_tunnel_open (struct management *man, const in_addr_t tun_local_i
       && man->connection.state == MS_INITIAL)
     {
       /* listen on our local TUN/TAP IP address */
-      man->settings.local.addr.in4.sin_addr.s_addr = htonl (tun_local_ip);
+      struct in_addr ia;
+      int ret;
+      
+      ia.s_addr = htonl(tun_local_ip);
+      ret = openvpn_getaddrinfo(0, inet_ntoa(ia), NULL, 0, NULL,
+                                AF_INET, &man->settings.local);
+      ASSERT (ret==0);
       man_connection_init (man);
     }
 
src/openvpn/manage.h +1 -1
index 1498163..febeb01 100644
@@ -212,7 +212,7 @@ struct man_persist {
 struct man_settings {
   bool defined;
   unsigned int flags; /* MF_x flags */
-  struct openvpn_sockaddr local;
+  struct addrinfo* local;
 #if UNIX_SOCK_SUPPORT
   struct sockaddr_un local_unix;
 #endif
src/openvpn/options.c +49 -68

187 lines not on this page · raw message

src/openvpn/options.h +6 -18
index fde6468..62b1cbf 100644
@@ -98,7 +98,6 @@ struct connection_entry
   bool bind_local;
   int connect_retry_seconds;
   bool connect_retry_defined;
-  int connect_retry_max;
   int connect_timeout;
   bool connect_timeout_defined;
 #ifdef ENABLE_HTTP_PROXY
@@ -156,7 +155,6 @@ struct connection_list
   int len;
   int current;
   int n_cycles;
-  bool no_advance;
   struct connection_entry *array[CONNECTION_LIST_SIZE];
 };
 
@@ -207,10 +205,15 @@ struct options
 #endif
 
   /* Networking parms */
+  int connect_retry_max;
   struct connection_entry ce;
   struct connection_list *connection_list;
+
   struct remote_list *remote_list;
-  bool force_connection_list;
+  /* Do not advanced the connection or remote addr list*/
+  bool no_advance;
+  /* Counts the number of unsuccessful connection attempts */
+  unsigned int unsuccessful_attempts;
 
 #if HTTP_PROXY_OVERRIDE
   struct http_proxy_options *http_proxy_override;
@@ -772,20 +775,5 @@ bool get_ipv6_addr( const char * prefix_str, struct in6_addr *network,
 		    unsigned int * netbits, char ** printable_ipv6, 
 		    int msglevel );
 
-/*
- * inline functions
- */
-static inline bool
-connection_list_defined (const struct options *o)
-{
-  return o->connection_list != NULL;
-}
-
-static inline void
-connection_list_set_no_advance (struct options *o)
-{
-  if (o->connection_list)
-    o->connection_list->no_advance = true;
-}
 
 #endif
src/openvpn/ps.c +2 -2
index 98d6580..c186864 100644
@@ -330,8 +330,8 @@ journal_add (const char *journal_dir, struct proxy_connection *pc, struct proxy_
   if (!getpeername (pc->sd, (struct sockaddr *) &from.addr.sa, &slen)
       && !getsockname (cp->sd, (struct sockaddr *) &to.addr.sa, &dlen))
     {
-      const char *f = print_sockaddr (&from, &gc);
-      const char *t = print_sockaddr (&to, &gc);
+      const char *f = print_openvpn_sockaddr (&from, &gc);
+      const char *t = print_openvpn_sockaddr (&to, &gc);
       fnlen =  strlen(journal_dir) + strlen(t) + 2;
       jfn = (char *) malloc(fnlen);
       check_malloc_return (jfn);
src/openvpn/push.c +1 -1
index 05a38e0..929a2f2 100644
@@ -49,7 +49,7 @@ void
 receive_auth_failed (struct context *c, const struct buffer *buffer)
 {
   msg (M_VERB0, "AUTH: Received control message: %s", BSTR(buffer));
-  connection_list_set_no_advance(&c->options);
+    c->options.no_advance=true;
   if (c->options.pull)
     {
       switch (auth_retry_get ())
src/openvpn/route.c +0 -1
index b8704ff..e7ccd17 100644
@@ -301,7 +301,6 @@ init_route (struct route *r,
     ret = openvpn_getaddrinfo(GETADDR_RESOLVE | GETADDR_WARN_ON_SIGNAL,
                               ro->network, NULL, 0, NULL, AF_INET, network_list);
 
-
   status = (ret == 0);
 
   if (!status)
src/openvpn/sig.c +18 -4
index 0ebde24..7ddfd0e 100644
@@ -97,14 +97,14 @@ void
 throw_signal (const int signum)
 {
   siginfo_static.signal_received = signum;
-  siginfo_static.hard = true;
+  siginfo_static.source = SIG_SOURCE_HARD;
 }
 
 void
 throw_signal_soft (const int signum, const char *signal_text)
 {
   siginfo_static.signal_received = signum;
-  siginfo_static.hard = false;
+  siginfo_static.source = SIG_SOURCE_SOFT;
   siginfo_static.signal_text = signal_text;
 }
 
@@ -115,7 +115,7 @@ signal_reset (struct signal_info *si)
     {
       si->signal_received = 0;
       si->signal_text = NULL;
-      si->hard = false;
+      si->source = SIG_SOURCE_SOFT;
     }
 }
 
@@ -124,9 +124,23 @@ print_signal (const struct signal_info *si, const char *title, int msglevel)
 {
   if (si)
     {
-      const char *hs = (si->hard ? "hard" : "soft");
       const char *type = (si->signal_text ? si->signal_text : "");
       const char *t = (title ? title : "process");
+      const char *hs;
+      switch (si->source)
+        {
+        case SIG_SOURCE_SOFT:
+          hs= "soft";
+          break;
+        case SIG_SOURCE_HARD:
+          hs = "hard";
+          break;
+        case SIG_SOURCE_CONNECTION_FAILED:
+          hs = "connection failed(soft)";
+          break;
+        default:
+          ASSERT(0);
+        }
 
       switch (si->signal_received)
 	{
src/openvpn/sig.h +10 -1
index 987efef..c2c7b54 100644
@@ -28,6 +28,15 @@
 #include "status.h"
 #include "win32.h"
 
+
+
+#define SIG_SOURCE_SOFT 0
+#define SIG_SOURCE_HARD 1
+/* CONNECTION_FAILED is also a "soft" status,
+ * It is thrown if a connection attempt fails
+ */
+#define SIG_SOURCE_CONNECTION_FAILED 2
+
 /*
  * Signal information, including signal code
  * and descriptive text.
@@ -35,7 +44,7 @@
 struct signal_info
 {
   volatile int signal_received;
-  volatile bool hard;
+  volatile int source;
   const char *signal_text;
 };
 
src/openvpn/socket.c +267 -324

1,017 lines not on this page · raw message

src/openvpn/socket.h +31 -31

167 lines not on this page · raw message

src/openvpn/tun.c +7 -4
index 6c842d2..e889164 100644
@@ -412,7 +412,7 @@ init_tun (const char *dev,       /* --dev option */
 	  const char *ifconfig_ipv6_local_parm,     /* --ifconfig parm 1 IPv6 */
 	  int         ifconfig_ipv6_netbits_parm,
 	  const char *ifconfig_ipv6_remote_parm,    /* --ifconfig parm 2 IPv6 */
-	  in_addr_t local_public,
+	  struct addrinfo *local_public,
 	  struct addrinfo *remote_public,
 	  const bool strict_warn,
 	  struct env_set *es)
@@ -474,12 +474,15 @@ init_tun (const char *dev,       /* --dev option */
 	   * If local_public or remote_public addresses are defined,
 	   * make sure they do not clash with our virtual subnet.
 	   */
-
-	  check_addr_clash ("local",
+          
+          for(curele=remote_public;curele;curele=curele->ai_next) {
+            if(curele->ai_family == AF_INET)
+              check_addr_clash ("local",
 			    tt->type,
-			    local_public,
+                            ((struct sockaddr_in*)curele->ai_addr)->sin_addr.s_addr,
 			    tt->local,
 			    tt->remote_netmask);
+          }
 
           for(curele=remote_public;curele;curele=curele->ai_next) {
             if(curele->ai_family == AF_INET)
src/openvpn/tun.h +1 -1
index ce23b0d..6a0470e 100644
@@ -231,7 +231,7 @@ struct tuntap *init_tun (const char *dev,       /* --dev option */
 			 const char *ifconfig_ipv6_local_parm,     /* --ifconfig parm 1 / IPv6 */
 			 int ifconfig_ipv6_netbits_parm,           /* --ifconfig parm 1 / bits */
 			 const char *ifconfig_ipv6_remote_parm,    /* --ifconfig parm 2 / IPv6 */
-			 in_addr_t local_public,
+			 struct addrinfo *local_public,
 			 struct addrinfo *remote_public,
 			 const bool strict_warn,
 			 struct env_set *es);
Signature · 1 line
1.7.9.5
#10 lore raw

Re: [Openvpn-devel] [PATCH 10/10] Implement dual stack client support for OpenVPN

Quoted 1 line · Arne Schwabe

Change meaning from udp and tcp to allow both IPv4 and IPv6. Introducue new udp4 and tcp4 to force IPv4.

The tcp4 and tcp6 should only temporary. I will later follow up with a patch which cleans up the protocol names and options. But I did not want this patch to get even bigger.

Arne

#11 lore raw

Re: [Openvpn-devel] [PATCH 10/10] Implement dual stack client support for OpenVPN

In reply to Arne Schwabe

* Arne Schwabe

Quoted 21 lines

This patch contains a number of changes. I did not further spit this since some changes make only sense being changed together.

Always use connection_list, simplifies the reconnection logic.

Change meaning of --connect-retry-max and --connect-retry to be used all connections. This now allows OpenVPN to quit after n unsuccessful udp connection attempts

Remove the tcp reconnection logic. Failing a TCP connection will now cause a USR1 like a UDP connection. Also extend sig->source from bool to int to specify signal source. This allows a finer grained reconnection logic if necessary in the future.

Dual-Stack support: if an address resolves to multiple records each address is tried in sequential order. Then proceed to next connection entry. Introduce the field current_remote to represent the current connecting remote. Also change some fields to struct addrinfo* form openvn_addr to store multiple addresses needed for the dual stack support.

Quoted 2 lines

Change meaning from udp and tcp to allow both IPv4 and IPv6. Introducue new udp4 and tcp4 to force IPv4.

ACK, I tested several different fail-over scenarios and all worked fine. Also all my pre-existing VPNs (maintained by GNOME NetworkManager) worked just fine.

Signature · 1 line
Tore Anderson
#12 lore raw

Re: [Openvpn-devel] [PATCH 10/10] Implement dual stack client support for OpenVPN

Hi,

Quoted 4 lines · Tore Anderson

* Arne Schwabe

Quoted 2 lines

This patch contains a number of changes. I did not further spit this since some changes make only sense being changed together.

[..]

Quoted 4 lines

ACK, I tested several different fail-over scenarios and all worked fine. Also all my pre-existing VPNs (maintained by GNOME NetworkManager) worked just fine.

Thanks for testing.

Nevertheless, as this is a HUGE change (and needs patch 02/10...09/10 as prerequisites), I'd put this in 2.4 - so we can release 2.3 "real soon now", without an even longer test/beta/RC phase.

(And yes, this is important work!)

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#13 lore raw

Re: [Openvpn-devel] [PATCH 10/10] Implement dual stack client support for OpenVPN

Quoted 14 lines

Hi,

Quoted 4 lines · Tore Anderson

* Arne Schwabe

Quoted 2 lines

This patch contains a number of changes. I did not further spit this since some changes make only sense being changed together.

[..]

Quoted 3 lines

ACK, I tested several different fail-over scenarios and all worked fine. Also all my pre-existing VPNs (maintained by GNOME NetworkManager) worked just fine.

Thanks for testing.

Quoted 7 lines

Nevertheless, as this is a HUGE change (and needs patch 02/10...09/10 as prerequisites), I'd put this in 2.4 - so we can release 2.3 "real soon now", without an even longer test/beta/RC phase.

(And yes, this is important work!)

gert

ACK for "getting 2.3.0 out real soon". I'd also push 2.4-alpha1 out very soon after 2.3.0, so that we get this new features/cleanups into wider circulation.

Signature · 5 lines
Samuli Seppänen
Community Manager
OpenVPN Technologies, Inc

irc freenode net: mattock
#14 lore raw

Re: [Openvpn-devel] [PATCH 10/10] Implement dual stack client support for OpenVPN

* Samuli Seppänen

Quoted 15 lines
Quoted 15 lines · Tore Anderson
Quoted 4 lines

* Arne Schwabe

Quoted 2 lines

This patch contains a number of changes. I did not further spit this since some changes make only sense being changed together.

[..]

Quoted 3 lines

ACK, I tested several different fail-over scenarios and all worked fine. Also all my pre-existing VPNs (maintained by GNOME NetworkManager) worked just fine.

Thanks for testing.

Nevertheless, as this is a HUGE change (and needs patch 02/10...09/10 as prerequisites), I'd put this in 2.4 - so we can release 2.3 "real soon now", without an even longer test/beta/RC phase.

Quoted 6 lines
Quoted 3 lines

(And yes, this is important work!)

gert

ACK for "getting 2.3.0 out real soon". I'd also push 2.4-alpha1 out very soon after 2.3.0, so that we get this new features/cleanups into wider circulation.

Hi,

It's been half a year, so I was wondering if this patch has been forgotten about? I don't see it in either the master branch of either the openvpn or openvpn-testing git repo.

FWIW, I'd like to push the GNOME NetworkManager folks some more to implement IPv6 support in their OpenVPN plugin, which is currently IPv4 only. This patch breaks one of the assumptions made there, in particular that IPv4 transport will always be used when OpenVPN is started "--remote <dns-hostname> --proto [tcp|udp]". I'm hoping that when dealing with that, which they'll have to do anyway, they'll seize the opportunity to implement IPv6 payload support as well.

However in order to do so it would be very nice to have a 2.4-alpha1 or at least a git master commit that I could point to, that could be used for testing interoperability with the new behaviour.

Tore

#15 lore raw

Re: [Openvpn-devel] [PATCH 10/10] Implement dual stack client support for OpenVPN

Am 22.06.13 12:48, schrieb Tore Anderson:

Quoted 12 lines

It's been half a year, so I was wondering if this patch has been forgotten about? I don't see it in either the master branch of either the openvpn or openvpn-testing git repo.

FWIW, I'd like to push the GNOME NetworkManager folks some more to implement IPv6 support in their OpenVPN plugin, which is currently IPv4 only. This patch breaks one of the assumptions made there, in particular that IPv4 transport will always be used when OpenVPN is started "--remote <dns-hostname> --proto [tcp|udp]". I'm hoping that when dealing with that, which they'll have to do anyway, they'll seize the opportunity to implement IPv6 payload support as well.

Quoted 3 lines

However in order to do so it would be very nice to have a 2.4-alpha1 or at least a git master commit that I could point to, that could be used for testing interoperability with the new behaviour.

Not really forgotten about. The dual stack patches are rather large. There has been lack of time of the OpenVPN core team member to review the patches.

I still maintain the dualstack patches for my client: https://github.com/schwabe/openvpn/commits/ds10
The branch name sometimes changes when I rebase the patches.

If someone steps up and has time to review the patches I can send another patch set.

Arne

#16 lore raw

Re: [Openvpn-devel] [PATCH 10/10] Implement dual stack client support for OpenVPN

In reply to Tore Anderson

Hi Tore,

Quoted 5 lines · Tore Anderson
Quoted 5 lines
Quoted 5 lines · Tore Anderson

[..]

Quoted 3 lines

ACK, I tested several different fail-over scenarios and all worked fine. Also all my pre-existing VPNs (maintained by GNOME NetworkManager) worked just fine.

[..]

Quoted 4 lines

It's been half a year, so I was wondering if this patch has been forgotten about? I don't see it in either the master branch of either the openvpn or openvpn-testing git repo.

Thanks for your patience :-) - indeed, it has been way too long, but (insert long list of excuses)...

I have just pushed 23d61c56b9fd218c39ad151b01b7e2d6690e6093 to master, which has the "latest generation" of the dual-stack patches - the basic stuff is what you have reviewed and tested, but during the intermediate year of heavy Android user testing, some more fixes have been found and integrated, and when reviewing, I found a few warts of my own... so it should be even better.

Quoted 7 lines

FWIW, I'd like to push the GNOME NetworkManager folks some more to implement IPv6 support in their OpenVPN plugin, which is currently IPv4 only. This patch breaks one of the assumptions made there, in particular that IPv4 transport will always be used when OpenVPN is started "--remote <dns-hostname> --proto [tcp|udp]". I'm hoping that when dealing with that, which they'll have to do anyway, they'll seize the opportunity to implement IPv6 payload support as well.

There! I'll take you up on this now :-) (thanks!)

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#17 lore raw

Re: [Openvpn-devel] [PATCH 10/10] Implement dual stack client support for OpenVPN

* Gert Doering

Quoted 2 lines

Thanks for your patience :-) - indeed, it has been way too long, but (insert long list of excuses)...

Good things come to those who wait :-)

Quoted 9 lines
Quoted 7 lines

FWIW, I'd like to push the GNOME NetworkManager folks some more to implement IPv6 support in their OpenVPN plugin, which is currently IPv4 only. This patch breaks one of the assumptions made there, in particular that IPv4 transport will always be used when OpenVPN is started "--remote <dns-hostname> --proto [tcp|udp]". I'm hoping that when dealing with that, which they'll have to do anyway, they'll seize the opportunity to implement IPv6 payload support as well.

There! I'll take you up on this now :-) (thanks!)

On it!

BTW: Will this go into 2.3.3 or 2.4.0, and approx. when is the first alpha/beta/rc/whatever release containing it due?

Tore

#18 lore raw

Re: [Openvpn-devel] [PATCH 10/10] Implement dual stack client support for OpenVPN

Hi,

Quoted 10 lines · Tore Anderson

* Gert Doering

Quoted 8 lines
Quoted 7 lines

FWIW, I'd like to push the GNOME NetworkManager folks some more to implement IPv6 support in their OpenVPN plugin, which is currently IPv4 only. This patch breaks one of the assumptions made there, in particular that IPv4 transport will always be used when OpenVPN is started "--remote <dns-hostname> --proto [tcp|udp]". I'm hoping that when dealing with that, which they'll have to do anyway, they'll seize the opportunity to implement IPv6 payload support as well.

Quoted 6 lines
Quoted 1 line

There! I'll take you up on this now :-) (thanks!)

On it!

BTW: Will this go into 2.3.3 or 2.4.0, and approx. when is the first alpha/beta/rc/whatever release containing it due?

It will not go int 2.3.3 - these changes are way too intrusive, and 2.3.2 -> 2.3.3 is meant to only receive "bugfixes" and "new features that are needed for long-time client/server compatibility" (like the TLS negotiation part).

It will go into 2.4.0 - I'm not promising anything, but about half of the "really big things" are in the tree now, so it depends a bit on Heiko's windows privilege separation patches - but we *might* be able to do "February/March 2014" for a first 2.4_alpha.

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#19 lore raw

Re: [Openvpn-devel] [PATCH 10/10] Implement dual stack client support for OpenVPN

In reply to Tore Anderson

* Tore Anderson

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

FWIW, I'd like to push the GNOME NetworkManager folks some more to implement IPv6 support in their OpenVPN plugin, which is currently IPv4 only. This patch breaks one of the assumptions made there, in particular that IPv4 transport will always be used when OpenVPN is started "--remote <dns-hostname> --proto [tcp|udp]". I'm hoping that when dealing with that, which they'll have to do anyway, they'll seize the opportunity to implement IPv6 payload support as well.

Quoted 3 lines
Quoted 1 line

There! I'll take you up on this now :-) (thanks!)

On it!

https://git.gnome.org/browse/network-manager-openvpn/commit/?id=77115c5377e009220c3c98102450f92d3a7f6f9e

This will likely go into Fedora 20.

Tore

#20 lore raw

Re: [Openvpn-devel] [PATCH 10/10] Implement dual stack client support for OpenVPN

Hi,

Quoted 3 lines · Tore Anderson

https://git.gnome.org/browse/network-manager-openvpn/commit/?id=77115c5377e009220c3c98102450f92d3a7f6f9e

This will likely go into Fedora 20.

Woot! This is great news indeed :-)

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#21 lore raw
In reply to Arne Schwabe

Hi,

ACK, this can go into 2.3 - dead code removal.

gert

Quoted 47 lines · Arne Schwabe
---
 src/openvpn/socket.c |    2 +-
 src/openvpn/socket.h |    5 -----
 2 files changed, 1 insertion(+), 6 deletions(-)
src/openvpn/socket.c +1 -1
index 505cf3b..21a4b2b 100644
@@ -158,7 +158,7 @@ openvpn_getaddrinfo (unsigned int flags,
   CLEAR(hints);
   hints.ai_family = ai_family;
   hints.ai_flags = AI_NUMERICHOST;
-  hints.ai_socktype = dnsflags_to_socktype(flags);
+  hints.ai_socktype = SOCK_STREAM;
 
   status = getaddrinfo(hostname, NULL, &hints, res);
 
src/openvpn/socket.h +0 -5
index 44f1098..9cb01fa 100644
@@ -478,11 +478,6 @@ bool unix_socket_get_peer_uid_gid (const socket_descriptor_t sd, int *uid, int *
 #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,
Signature · 11 lines
1.7.9.5


------------------------------------------------------------------------------
Keep yourself connected to Go Parallel: 
TUNE You got it built. Now make it sing. Tune shows you how.
http://goparallel.sourceforge.net
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#22 lore raw
In reply to Arne Schwabe
Quoted 4 lines · Arne Schwabe
---
 src/openvpn/socket.c |    2 +-
 src/openvpn/socket.h |    5 -----
 2 files changed, 1 insertion(+), 6 deletions(-)

Applied to master and beta/2.3

commit 740137f6bb7b3565054c3a8e894ceca93f2ff0e4 (master) commit e99982218b5549894a94cc3c5f6209219d911ba1 (beta/2.3)

Author: Arne Schwabe <[email protected]...>
Date:   Fri Nov 30 20:17:47 2012 +0100
    Remove dnsflags_to_socktype, it is not used anywhere

    Signed-off-by: Arne Schwabe <[email protected]...>
    Acked-by: Gert Doering <[email protected]...>
    Message-Id: [email protected]...
    URL: http://article.gmane.org/gmane.network.openvpn.devel/7160
    Signed-off-by: David Sommerseth <[email protected]...>
Signature · 3 lines
kind regards,

David Sommerseth