Change the type of all ports in openvpn to const char* and let getaddrinfo resolve the port together with the hostname.
PATCH 1/14 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 | 19 ++++--- src/openvpn/manage.h | 2 +- src/openvpn/options.c | 128 +++++++++++------------------------------------ src/openvpn/options.h | 14 +++--- src/openvpn/proxy.c | 12 ++--- src/openvpn/proxy.h | 6 +-- src/openvpn/ps.c | 29 ++++++----- src/openvpn/ps.h | 2 +- src/openvpn/route.c | 4 +- src/openvpn/socket.c | 131 ++++++++++++++++++++++--------------------------- src/openvpn/socket.h | 20 +++----- src/openvpn/socks.c | 30 +++++++++-- src/openvpn/socks.h | 6 +-- 15 files changed, 183 insertions(+), 248 deletions(-)
doc/openvpn.8 +4 -4
@@ -668,18 +668,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
@@ -5859,7 +5859,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
@@ -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 =string_alloc (p[3 ], gc); 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 }
@@ -227,8 +220,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)
@@ -237,8 +229,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; }
@@ -262,7 +256,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 +9 -10
@@ -2058,7 +2058,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,
@@ -2111,12 +2111,6 @@ man_settings_init (struct man_settings *ms, 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
@@ -2128,8 +2122,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); + } }
@@ -2248,7 +2247,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
@@ -341,7 +341,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
@@ -87,9 +87,9 @@ struct options_pre_pullstruct 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_entrystruct 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 80char host[RH_HOST_LEN ]; +#define RH_PORT_LEN 20 +char port[RH_PORT_LEN ]; };/* Command line options */
@@ -356,7 +358,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;
@@ -451,7 +453,7 @@ struct optionsbool 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 +6 -6
@@ -443,7 +443,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;
@@ -492,7 +492,7 @@ bool add_proxy_headers (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 */ ) { char buf[512];
@@ -553,7 +553,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) {
@@ -581,7 +581,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);
@@ -692,7 +692,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);
@@ -777,7 +777,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
@@ -46,7 +46,7 @@ struct http_custom_header {#define MAX_CUSTOM_HTTP_HEADER 10struct http_proxy_options {const char *server; -int port; +const char *port;bool retry;int timeout;
@@ -64,7 +64,7 @@ struct http_proxy_options {struct http_proxy_options_simple {const char *server; -int port; +const char *port;int auth_retry; };
@@ -87,7 +87,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
@@ -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
@@ -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
@@ -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 -71
227 lines not on this page · raw message
src/openvpn/socket.h +8 -12
@@ -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_socketbool 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
@@ -299,9 +299,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,
@@ -481,6 +481,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,
@@ -490,6 +491,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,
@@ -544,12 +546,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
@@ -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
@@ -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
PATCH 2/14 Simplify print_sockaddr_ex function, merge duplicate ipv4/ipv6 logic.
--- src/openvpn/ps.c | 4 +- src/openvpn/socket.c | 110 ++++++++++++++++++++++---------------------------- src/openvpn/socket.h | 16 +++++++- 3 files changed, 65 insertions(+), 65 deletions(-)
src/openvpn/ps.c +2 -2
@@ -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 +49 -61
154 lines not on this page · raw message
src/openvpn/socket.h +14 -2
@@ -347,14 +347,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
[Openvpn-devel] [PATCH applied] Re: Simplify print_sockaddr_ex function, merge duplicate ipv4/ipv6 logic.
ACK, with two fixes taken from patch 11/14 in that series, namely this hunk for socket.c:
@@ -2235,12 +2209,14 @@ print_sockaddr_ex (const struct sockaddr *sa,
case AF_INET6:
buf_puts (&out, "[AF_INET6]");
salen = sizeof (struct sockaddr_in6);
- addr_is_defined = IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6*) sa)->sin6_addr);
+ addr_is_defined = !IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6*) sa)->sin6_addr);
break;
+ case AF_UNSPEC:
+ return "[AF_UNSPEC]";
default:
ASSERT(0);
}Without these fixes, master + 02/14 will build but crash upon startup trying to print it's local socket address, which will (if not bound) be "AF_UNSPEC". If possible, I want each of the individual steps in the patch set to lead to a working openvpn binary, so we can bisect more easily should it become necessary later on.
Patch has been applied to the master branch.
commit d3310d2ea46a71c35313a653c9454fc468cb9c55
Author: Arne Schwabe Date: Thu Nov 21 21:08:03 2013 +0100
Simplify print_sockaddr_ex function, merge duplicate ipv4/ipv6 logic.
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8023
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH 3/14 Split the PROTO_UDP_xx options into AF_INET/AF_INET6 and PROTO_TCP/PROTO_UDP part.
In reply to Arne SchwabeSplitting 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 | 73 ++++++++++---------- src/openvpn/options.h | 2 + src/openvpn/socket.c | 176 ++++++++++++++++++++++--------------------------- src/openvpn/socket.h | 21 +++--- src/openvpn/socks.c | 2 +- 8 files changed, 143 insertions(+), 166 deletions(-)
src/openvpn/error.c +3 -3
@@ -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
@@ -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));
@@ -1122,7 +1122,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
@@ -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; }
@@ -256,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,%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 );
@@ -1847,17 +1845,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 ; }
@@ -2218,7 +2213,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
@@ -2675,6 +2670,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
@@ -3331,8 +3327,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 -38
229 lines not on this page · raw message
src/openvpn/options.h +2 -0
@@ -87,6 +87,7 @@ struct options_pre_pullstruct 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_entryconst char *remote;const char *remote_port;int proto; +sa_family_t af; };#define CONNECTION_LIST_SIZE 64
src/openvpn/socket.c +80 -96
390 lines not on this page · raw message
src/openvpn/socket.h +10 -11
@@ -110,6 +110,7 @@ struct link_socket_infoconst 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 */ };
@@ -303,6 +304,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
@@ -519,19 +521,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);
@@ -697,9 +696,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
@@ -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
PATCH 1/1 Split the PROTO_UDP_xx options into AF_INET/AF_INET6 and PROTO_TCP/PROTO_UDP part.
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 | 73 ++++++++++---------- src/openvpn/options.h | 2 + src/openvpn/socket.c | 180 +++++++++++++++++++++++--------------------------- src/openvpn/socket.h | 21 +++--- src/openvpn/socks.c | 2 +- 8 files changed, 145 insertions(+), 168 deletions(-)
src/openvpn/error.c +3 -3
@@ -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
@@ -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));
@@ -1122,7 +1122,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
@@ -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; }
@@ -256,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,%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 );
@@ -1847,17 +1845,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 ; }
@@ -2218,7 +2213,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
@@ -2675,6 +2670,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
@@ -3331,8 +3327,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 -38
229 lines not on this page · raw message
src/openvpn/options.h +2 -0
@@ -87,6 +87,7 @@ struct options_pre_pullstruct 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_entryconst char *remote;const char *remote_port;int proto; +sa_family_t af; };#define CONNECTION_LIST_SIZE 64
src/openvpn/socket.c +82 -98
395 lines not on this page · raw message
src/openvpn/socket.h +10 -11
@@ -110,6 +110,7 @@ struct link_socket_infoconst 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 */ };
@@ -303,6 +304,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
@@ -519,19 +521,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);
@@ -697,9 +696,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
@@ -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.8.3.4 (Apple Git-47)
[Openvpn-devel] [PATCH applied] Re: Split the PROTO_UDP_xx options into AF_INET/AF_INET6 and PROTO_TCP/PROTO_UDP part.
ACK.
I have fixed a few bits of whitespace, and one occurrence of proto2ascii() where the second parameter wasn't "proto.af".
Patch with those changes has been applied to the master branch.
commit 30077d1f415b8dc9bd7c8a1ac6a7585136ac6261 (master)
Author: Arne Schwabe Date: Sat Nov 23 20:57:04 2013 +0100
Split the PROTO_UDP_xx options into AF_INET/AF_INET6 and PROTO_TCP/PROTO_UDP part.
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/8043
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH 4/14 Fix assertion when SIGUSR1 is received while getaddrinfo is successful
In reply to Arne Schwabe--- src/openvpn/socket.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
src/openvpn/socket.c +8 -6
@@ -227,18 +227,20 @@ openvpn_getaddrinfo (unsigned int flags,get_signal (signal_received);if (*signal_received)/* were we interrupted by a signal? */ { -if (0 == status) { -ASSERT (res); -freeaddrinfo (*res); - res =NULL ; - }if (*signal_received ==SIGUSR1 )/* ignore SIGUSR1 */ {msg (level,"RESOLVE: Ignored SIGUSR1 signal received during DNS resolution attempt" ); *signal_received =0 ; }else - goto done; + { +if (0 == status) { +ASSERT (res); +freeaddrinfo (*res); + res =NULL ; + } + goto done; + } } }
Signature · 1 line
1.7.9.5
[Openvpn-devel] [PATCH applied] Re: Fix assertion when SIGUSR1 is received while getaddrinfo is successful
ACK.
I can't easily reproduce this issue here (it's timing critical and you need a slow resolver to be able to "hit" that window), but I think the bug is clear enough - without the patch, the code will destroy "res", then decide to ignore the signal (= not go to "done") and then fall over ASSERT(res)... so with the new code, it won't destry "res" for SIGUSR1.
Patch has been applied to the master and release/2.3 branch, as this is just a bug, not really related to dual-stack support.
commit 282788a835f6c9dfb85e8f9a3bd45f5841271b06 (master) commit 47a963681a6ed18d32405ec26b74d56925425093 (release/2.3)
Author: Arne Schwabe Date: Thu Nov 21 21:08:05 2013 +0100
Fix assertion when SIGUSR1 is received while getaddrinfo is successful
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8019
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH 5/14 Split link_socket_init_phase2 into smaller more managable/readable functions. No functional changes
In reply to Arne Schwabe--- src/openvpn/socket.c | 470 ++++++++++++++++++++++++++++---------------------- 1 file changed, 262 insertions(+), 208 deletions(-)
src/openvpn/socket.c +262 -208
@@ -1328,6 +1328,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,
@@ -1473,27 +1490,252 @@ link_socket_init_phase1 (struct link_socket *sock, }else if (mode !=LS_MODE_TCP_ACCEPT_FROM ) { -create_socket (sock); +create_new_socket (sock, mark); + } +} -/* set socket buffers based on --sndbuf and --rcvbuf options */ -socket_set_buffers (sock->sd, &sock->socket_buffer_sizes); +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 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 ); +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); +} + +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_openvpn_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) { -struct gc_arena gc =gc_new ();const char *remote_dynamic =NULL ;bool remote_changed = false;int sig_save =0 ;
@@ -1520,41 +1762,10 @@ 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; + }else {
@@ -1563,139 +1774,24 @@ link_socket_init_phase2 (struct link_socket *sock,if (*signal_received) 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, +phase2_tcp_client (sock, &remote_changed, remote_dynamic, 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); }#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;
@@ -1706,49 +1802,8 @@ link_socket_init_phase2 (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 - -/* 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_openvpn_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)
@@ -1756,7 +1811,6 @@ link_socket_init_phase2 (struct link_socket *sock,if (!*signal_received) *signal_received = sig_save; } -gc_free (&gc); }void
Signature · 1 line
1.7.9.5
PATCH 6/14 Fix two instances of asserting AF_INET
In reply to Arne SchwabeThe http-proxy and socks-proxy work fine with IPv6 but assert having IPv4
--- src/openvpn/socket.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
src/openvpn/socket.c +2 -3
@@ -1438,7 +1438,7 @@ link_socket_init_phase1 (struct link_socket *sock,/* are we running in HTTP proxy mode? */ else if (sock->http_proxy) { -ASSERT (sock->info.proto ==PROTO_TCP_CLIENT && sock->info.af ==AF_INET ); +ASSERT (sock->info.proto ==PROTO_TCP_CLIENT );ASSERT (!sock->inetd);/* the proxy server */
@@ -1454,7 +1454,6 @@ link_socket_init_phase1 (struct link_socket *sock,/* or in Socks proxy mode? */ else if (sock->socks_proxy) { -ASSERT (sock->info.af ==AF_INET );ASSERT (!sock->inetd);/* the proxy server */
@@ -1473,7 +1472,7 @@ link_socket_init_phase1 (struct link_socket *sock, }/* bind behavior for TCP server vs. client */ -if (sock->info.proto ==PROTO_TCP_SERVER && sock->info.af==AF_INET ) +if (sock->info.proto ==PROTO_TCP_SERVER ) {if (sock->mode ==LS_MODE_TCP_ACCEPT_FROM ) sock->bind_local = false;
Signature · 1 line
1.7.9.5
[Openvpn-devel] [PATCH applied] Re: Fix two instances of asserting AF_INET
ACK.
I have applied this patch slightly out of sequence, as it makes --http-proxy and --socks-proxy work using IPv6 to connect to the proxy (ASSERT(af==AF_INET) failure otherwise), and does not rely on changes introduced by 04/14 and 05/14.
Patch has been applied to the master branch.
commit 500c16f319e21ae9590a2207d0b518f8e57abdde
Author: Arne Schwabe Date: Thu Nov 21 21:08:07 2013 +0100
Fix two instances of asserting AF_INET
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8010
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH 7/14 Change remote the proto_remote function to return a constant string
In reply to Arne SchwabeInstead of using the implicit protocol string that is returned by the proto/af to names function return a constant string. The strings have become part of the wire protocl and we do not want them to change we the printing of proto/af changes.
--- src/openvpn/options.c | 2 +- src/openvpn/socket.c | 20 ++++++++++---------- src/openvpn/socket.h | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-)
src/openvpn/options.c +1 -1
@@ -2905,7 +2905,7 @@ options_string (const struct options *o,buf_printf (&out,",dev-type %s" ,dev_type_string (o->dev, o->dev_type));buf_printf (&out,",link-mtu %d" ,EXPANDED_SIZE (frame));buf_printf (&out,",tun-mtu %d" ,PAYLOAD_SIZE (frame)); -buf_printf (&out,",proto %s" ,proto2ascii (proto_remote (o->ce.proto, remote),o->ce.af, true)); +buf_printf (&out,",proto %s" ,proto_remote (o->ce.proto, remote));/* send tun_ipv6 only in peer2peer mode - in client/server mode, it * is usually pushed by the server, triggering a non-helpful warning
src/openvpn/socket.c +10 -10
@@ -2602,19 +2602,19 @@ addr_family_name (int af)* has always sent UDPv4, TCPv4 over the wire. Keep these * strings for backward compatbility */ -int +const char *proto_remote (int proto,bool remote) {ASSERT (proto >=0 && proto <PROTO_N ); -if (remote) - { -switch (proto) - { -case PROTO_TCP_SERVER :return PROTO_TCP_CLIENT ; -case PROTO_TCP_CLIENT :return PROTO_TCP_SERVER ; - } - } -return proto; +if (proto ==PROTO_UDP ) +return "UDPv4" ; + +if ( (remote && proto ==PROTO_TCP_CLIENT ) || proto ==PROTO_TCP_SERVER ) +return "TCPv4_SERVER" ; +if ( (remote && proto ==PROTO_TCP_SERVER ) || proto ==PROTO_TCP_CLIENT ) +return "TCPv4_CLIENT" ; + +ASSERT (0 ); }/*
src/openvpn/socket.h +1 -1
@@ -532,7 +532,7 @@ int ascii2proto (const char* proto_name);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 *proto_remote (int proto,bool remote);const char *addr_family_name (int af);/*
Signature · 1 line
1.7.9.5
PATCH 1/1 Change remote the proto_remote function to return a constant string
Instead of using the implicit protocol string that is returned by the proto/af to names function return a constant string. The strings have become part of the wire protocl and we do not want them to change we the printing of proto/af changes.
--- src/openvpn/options.c | 2 +- src/openvpn/socket.c | 22 ++++++++++++---------- src/openvpn/socket.h | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-)
src/openvpn/options.c +1 -1
@@ -2905,7 +2905,7 @@ options_string (const struct options *o,buf_printf (&out,",dev-type %s" ,dev_type_string (o->dev, o->dev_type));buf_printf (&out,",link-mtu %d" ,EXPANDED_SIZE (frame));buf_printf (&out,",tun-mtu %d" ,PAYLOAD_SIZE (frame)); -buf_printf (&out,",proto %s" ,proto2ascii (proto_remote (o->ce.proto, remote),o->ce.af, true)); +buf_printf (&out,",proto %s" ,proto_remote (o->ce.proto, remote));/* send tun_ipv6 only in peer2peer mode - in client/server mode, it * is usually pushed by the server, triggering a non-helpful warning
src/openvpn/socket.c +12 -10
@@ -2604,19 +2604,21 @@ addr_family_name (int af)* has always sent UDPv4, TCPv4 over the wire. Keep these * strings for backward compatbility */ -int +const char *proto_remote (int proto,bool remote) {ASSERT (proto >=0 && proto <PROTO_N ); -if (remote) - { -switch (proto) - { -case PROTO_TCP_SERVER :return PROTO_TCP_CLIENT ; -case PROTO_TCP_CLIENT :return PROTO_TCP_SERVER ; - } - } -return proto; +if (proto ==PROTO_UDP ) +return "UDPv4" ; + +if ( (remote && proto ==PROTO_TCP_CLIENT ) || + (!remote && proto ==PROTO_TCP_SERVER )) +return "TCPv4_SERVER" ; +if ( (remote && proto ==PROTO_TCP_SERVER ) || + (!remote && proto ==PROTO_TCP_CLIENT )) +return "TCPv4_CLIENT" ; + +ASSERT (0 ); }/*
src/openvpn/socket.h +1 -1
@@ -532,7 +532,7 @@ int ascii2proto (const char* proto_name);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 *proto_remote (int proto,bool remote);const char *addr_family_name (int af);/*
Signature · 1 line
1.8.3.4 (Apple Git-47)
PATCH 8/14 Remove the ip-remote-hint option.
In reply to Arne SchwabeThe 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
@@ -245,7 +245,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;
@@ -270,8 +270,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);
@@ -321,9 +319,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) {
@@ -338,16 +333,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;
@@ -356,14 +345,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
@@ -4435,11 +4435,6 @@ add_option (struct options *options, options->ignore_unknown_option[i] =NULL ; } -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
@@ -210,7 +210,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
PATCH 9/14 change the type of remote to addrinfo.
In reply to Arne Schwabe--- src/openvpn/init.c | 5 +-- src/openvpn/socket.c | 59 ++++++++++++++++++++++------------- src/openvpn/socket.h | 85 +++++++++++++++++++++++++++++++++++++++++++------- src/openvpn/tun.c | 16 ++++++---- src/openvpn/tun.h | 2 +- 5 files changed, 124 insertions(+), 43 deletions(-)
src/openvpn/init.c +3 -2
@@ -1356,7 +1356,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);
@@ -2867,7 +2867,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/socket.c +37 -22
125 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
@@ -412,7 +412,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) {
@@ -466,6 +466,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);/*
@@ -479,11 +480,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
@@ -233,7 +233,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
PATCH 10/14 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
@@ -187,15 +187,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
PATCH 11/14 Implement dual stack client support for OpenVPN
In reply to Arne SchwabeThis 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.
--- compile | 347 ++++++++++++++++++++++ doc/openvpn.8 | 24 +- src/openvpn/error.c | 2 +- src/openvpn/init.c | 237 +++++++++------ src/openvpn/manage.c | 25 +- src/openvpn/manage.h | 2 +- src/openvpn/options.c | 136 ++++----- src/openvpn/options.h | 26 +- src/openvpn/ps.c | 8 +- src/openvpn/push.c | 2 +- src/openvpn/sig.c | 22 +- src/openvpn/sig.h | 11 +- src/openvpn/socket.c | 776 ++++++++++++++++++++++++------------------------- src/openvpn/socket.h | 80 ++--- src/openvpn/tun.c | 11 +- src/openvpn/tun.h | 2 +- 16 files changed, 1042 insertions(+), 669 deletions(-) create mode 100755 compile
compile new file +347 -0
@@ -0,0 +1,347 @@ +#! /bin/sh +# Wrapper for compilers which do not understand '-c -o'. + +scriptversion=2012-10-14.11; # UTC + +# Copyright (C) 1999-2013 Free Software Foundation, Inc. +# Written by Tom Tromey <[email protected]...>. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# This file is maintained in Automake, please report +# bugs to <[email protected]...> or send patches to +# <[email protected]...>. + +nl=' +' + +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent tools from complaining about whitespace usage. +IFS=" "" $nl" + +file_conv= + +# func_file_conv build_file lazy +# Convert a $build file to $host form and store it in $file +# Currently only supports Windows hosts. If the determined conversion +# type is listed in (the comma separated) LAZY, no conversion will +# take place. +func_file_conv () +{ + file=$1 + case $file in + / | /[!/]*) # absolute file, and not a UNC file + if test -z "$file_conv"; then + # lazily determine how to convert abs files + case `uname -s` in + MINGW*) + file_conv=mingw + ;; + CYGWIN*) + file_conv=cygwin + ;; + *) + file_conv=wine + ;; + esac + fi + case $file_conv/,$2, in + *,$file_conv,*) + ;; + mingw/*) + file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` + ;; + cygwin/*) + file=`cygpath -m "$file" || echo "$file"` + ;; + wine/*) + file=`winepath -w "$file" || echo "$file"` + ;; + esac + ;; + esac +} + +# func_cl_dashL linkdir +# Make cl look for libraries in LINKDIR +func_cl_dashL () +{ + func_file_conv "$1" + if test -z "$lib_path"; then + lib_path=$file + else + lib_path="$lib_path;$file" + fi + linker_opts="$linker_opts -LIBPATH:$file" +} + +# func_cl_dashl library +# Do a library search-path lookup for cl +func_cl_dashl () +{ + lib=$1 + found=no + save_IFS=$IFS + IFS=';' + for dir in $lib_path $LIB + do + IFS=$save_IFS + if $shared && test -f "$dir/$lib.dll.lib"; then + found=yes + lib=$dir/$lib.dll.lib + break + fi + if test -f "$dir/$lib.lib"; then + found=yes + lib=$dir/$lib.lib + break + fi + if test -f "$dir/lib$lib.a"; then + found=yes + lib=$dir/lib$lib.a + break + fi + done + IFS=$save_IFS + + if test "$found" != yes; then + lib=$lib.lib + fi +} + +# func_cl_wrapper cl arg... +# Adjust compile command to suit cl +func_cl_wrapper () +{ + # Assume a capable shell + lib_path= + shared=: + linker_opts= + for arg + do + if test -n "$eat"; then + eat= + else + case $1 in + -o) + # configure might choose to run compile as 'compile cc -o foo foo.c'. + eat=1 + case $2 in + *.o | *.[oO][bB][jJ]) + func_file_conv "$2" + set x "$@" -Fo"$file" + shift + ;; + *) + func_file_conv "$2" + set x "$@" -Fe"$file" + shift + ;; + esac + ;; + -I) + eat=1 + func_file_conv "$2" mingw + set x "$@" -I"$file" + shift + ;; + -I*) + func_file_conv "${1#-I}" mingw + set x "$@" -I"$file" + shift + ;; + -l) + eat=1 + func_cl_dashl "$2" + set x "$@" "$lib" + shift + ;; + -l*) + func_cl_dashl "${1#-l}" + set x "$@" "$lib" + shift + ;; + -L) + eat=1 + func_cl_dashL "$2" + ;; + -L*) + func_cl_dashL "${1#-L}" + ;; + -static) + shared=false + ;; + -Wl,*) + arg=${1#-Wl,} + save_ifs="$IFS"; IFS=',' + for flag in $arg; do + IFS="$save_ifs" + linker_opts="$linker_opts $flag" + done + IFS="$save_ifs" + ;; + -Xlinker) + eat=1 + linker_opts="$linker_opts $2" + ;; + -*) + set x "$@" "$1" + shift + ;; + *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) + func_file_conv "$1" + set x "$@" -Tp"$file" + shift + ;; + *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) + func_file_conv "$1" mingw + set x "$@" "$file" + shift + ;; + *) + set x "$@" "$1" + shift + ;; + esac + fi + shift + done + if test -n "$linker_opts"; then + linker_opts="-link$linker_opts" + fi + exec "$@" $linker_opts + exit 1 +} + +eat= + +case $1 in + '') + echo "$0: No command. Try '$0 --help' for more information." 1>&2 + exit 1; + ;; + -h | --h*) + cat <<\EOF +Usage: compile [--help] [--version] PROGRAM [ARGS] + +Wrapper for compilers which do not understand '-c -o'. +Remove '-o dest.o' from ARGS, run PROGRAM with the remaining +arguments, and rename the output as expected. + +If you are trying to build a whole package this is not the +right script to run: please start by reading the file 'INSTALL'. + +Report bugs to <[email protected]...>. +EOF + exit $? + ;; + -v | --v*) + echo "compile $scriptversion" + exit $? + ;; + cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) + func_cl_wrapper "$@" # Doesn't return... + ;; +esac + +ofile= +cfile= + +for arg +do + if test -n "$eat"; then + eat= + else + case $1 in + -o) + # configure might choose to run compile as 'compile cc -o foo foo.c'. + # So we strip '-o arg' only if arg is an object. + eat=1 + case $2 in + *.o | *.obj) + ofile=$2 + ;; + *) + set x "$@" -o "$2" + shift + ;; + esac + ;; + *.c) + cfile=$1 + set x "$@" "$1" + shift + ;; + *) + set x "$@" "$1" + shift + ;; + esac + fi + shift +done + +if test -z "$ofile" || test -z "$cfile"; then + # If no '-o' option was seen then we might have been invoked from a + # pattern rule where we don't need one. That is ok -- this is a + # normal compilation that the losing compiler can handle. If no + # '.c' file was seen then we are probably linking. That is also + # ok. + exec "$@" +fi + +# Name of file we expect compiler to create. +cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` + +# Create the lock directory. +# Note: use '[/\\:.-]' here to ensure that we don't use the same name +# that we are using for the .o file. Also, base the name on the expected +# object file name, since that is what matters with a parallel build. +lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d +while true; do + if mkdir "$lockdir" >/dev/null 2>&1; then + break + fi + sleep 1 +done +# FIXME: race condition here if user kills between mkdir and trap. +trap "rmdir '$lockdir'; exit 1" 1 2 15 + +# Run the compile. +"$@" +ret=$? + +if test -f "$cofile"; then + test "$cofile" = "$ofile" || mv "$cofile" "$ofile" +elif test -f "${cofile}bj"; then + test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" +fi + +rmdir "$lockdir" +exit $ret + +# Local Variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC" +# time-stamp-end: "; # UTC" +# End:
doc/openvpn.8 +13 -11
@@ -221,6 +221,9 @@ options. indicates the protocol to use when connecting with the remote, and may be "tcp" or "udp". +For forcing IPv4 or IPv6 connection suffix tcp or udp +with 4/6 like udp4/udp6/tcp4/tcp6. + The client will move on to the next host in the list, in the event of connection failure. Note that at any given time, the OpenVPN client
@@ -463,13 +466,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
@@ -481,12 +480,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
@@ -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/init.c +141 -96
361 lines not on this page · raw message
src/openvpn/manage.c +14 -11
@@ -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;
@@ -2122,13 +2123,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); - } }
@@ -2587,7 +2584,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
@@ -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 +61 -75
225 lines not on this page · raw message
src/openvpn/options.h +6 -20
@@ -97,8 +97,6 @@ struct connection_entrybool bind_defined;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
@@ -155,8 +153,6 @@ struct connection_list {int len;int current; -int n_cycles; -bool no_advance;struct connection_entry *array[CONNECTION_LIST_SIZE ]; };
@@ -209,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;
@@ -775,20 +776,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 +3 -5
@@ -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);
@@ -408,20 +408,18 @@ proxy_entry_new (struct proxy_connection **list,struct buffer *initial_data, const char *journal_dir) { - struct openvpn_sockaddr osaddr; socket_descriptor_t sd_server;int status;struct proxy_connection *pc;struct proxy_connection *cp;/* connect to port share server */ - 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" );return false; } - status =openvpn_connect (sd_server, &osaddr,5 ,NULL ); + status =openvpn_connect (sd_server,(const struct sockaddr *) &server_addr,5 ,NULL );if (status) {msg (M_WARN ,"PORT SHARE PROXY: connect to port-share server failed" );
src/openvpn/push.c +1 -1
@@ -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/sig.c +18 -4
@@ -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
@@ -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 +377 -399
1,208 lines not on this page · raw message
src/openvpn/socket.h +41 -39
203 lines not on this page · raw message
src/openvpn/tun.c +7 -4
@@ -411,7 +411,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)
@@ -473,12 +473,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
@@ -232,7 +232,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
PATCH 12/14 Implement listing on IPv4/IPv6 dual socket on all platform
In reply to Arne SchwabeWith this patch OpenVPN will listen on Ipv4 as well as IPv6 when an IPv6 socket is used. Using bind ipv6only will disable this behavior
--- doc/openvpn.8 | 8 +++++++- src/openvpn/init.c | 1 + src/openvpn/manage.c | 2 +- src/openvpn/options.c | 4 ++++ src/openvpn/options.h | 1 + src/openvpn/socket.c | 36 +++++++++++++++++++++++++----------- src/openvpn/socket.h | 5 ++++- 7 files changed, 43 insertions(+), 14 deletions(-)
doc/openvpn.8 +7 -1
@@ -684,7 +684,7 @@ TCP/UDP port number or name for bind. TCP/UDP port number or name for remote. .\"********************************************************* .TP -.B \-\-bind +.B \-\-bind [ipv6only] Bind to local address and port. This is the default unless any of .B \-\-proto tcp-client ,
@@ -692,6 +692,12 @@ Bind to local address and port. This is the default unless any of or .B \-\-socks-proxy are used. + +If the +.B \-\-ipv6only +keyword is present OpenVPN will bind only to IPv6 (as oposed +to IPv6 and IPv4) when a IPv6 socket is opened. + .\"********************************************************* .TP .B \-\-nobind
src/openvpn/init.c +1 -0
@@ -2690,6 +2690,7 @@ do_init_socket_1 (struct context *c, const int mode) c->options.ce.remote_port, c->options.ce.proto, c->options.ce.af, + c->options.ce.bind_ipv6_only, mode, c->c2.accept_from, #ifdef ENABLE_HTTP_PROXY
src/openvpn/manage.c +1 -1
@@ -1570,7 +1570,7 @@ man_listen (struct management *man) { man->connection.sd_top =create_socket_tcp (AF_INET );socket_bind (man->connection.sd_top, man->settings.local, -AF_INET ,"MANAGEMENT" ); +AF_INET ,"MANAGEMENT" , true); }/*
src/openvpn/options.c +4 -0
@@ -779,6 +779,7 @@ init_options (struct options *o, const bool init_gc) o->topology =TOP_NET30 ; o->ce.proto =PROTO_UDP ; o->ce.af =AF_UNSPEC ; + o->ce.bind_local=false; o->ce.connect_retry_seconds =5 ; o->ce.connect_timeout =10 ; o->connect_retry_max =0 ;
@@ -4871,6 +4872,9 @@ add_option (struct options *options, {VERIFY_PERMISSION (OPT_P_GENERAL |OPT_P_CONNECTION ); options->ce.bind_defined = true; +if (p[1 ] &&streq (p[1 ],"ipv6only" )) + options->ce.bind_ipv6_only=true; + } else if (streq (p[0], "nobind")) {
src/openvpn/options.h +1 -0
@@ -95,6 +95,7 @@ struct connection_entryconst char *remote;bool remote_float;bool bind_defined; +bool bind_ipv6_only;bool bind_local;int connect_retry_seconds;int connect_timeout;
src/openvpn/socket.c +25 -11
@@ -663,10 +663,9 @@ create_socket (struct link_socket *sock) {/* create socket, use information carried over from getaddrinfo */ const int ai_proto = sock->info.lsa->actual.ai_protocol; -const int ai_family = sock->info.lsa->actual.ai_family; - -ASSERT (sock->info.af ==AF_UNSPEC || sock->info.af == ai_family); +int ai_family = sock->info.lsa->actual.ai_family; +ASSERT (sock->info.af ==AF_UNSPEC || sock->info.af == ai_family);if (ai_proto ==IPPROTO_UDP ) {
@@ -881,7 +880,8 @@ void socket_bind (socket_descriptor_t sd, struct addrinfo *local, int ai_family, - const char *prefix) + const char *prefix, + bool ipv6only) { struct gc_arena gc = gc_new ();
@@ -892,8 +892,11 @@ socket_bind (socket_descriptor_t sd,* What is the correct way to deal with it? */ -ASSERT (local);struct addrinfo * cur; +int v6only= ipv6only ?0 :1 ; + +ASSERT (local); +/* find the first addrinfo with correct ai_family */ for (cur = local; cur; cur=cur->ai_next)
@@ -904,7 +907,14 @@ socket_bind (socket_descriptor_t sd,if (!cur)msg (M_FATAL ,"%s: Socket bind failed: Addr to bind has no %s record" , prefix,addr_family_name (ai_family)); - + +if (ai_family ==AF_INET6 ) + { +if (setsockopt (sd,IPPROTO_IPV6 ,IPV6_V6ONLY , &v6only,sizeof (v6only))) + { +msg (M_NONFATAL |M_ERRNO ,"Setting IPV6_V6ONLY failed" ); + } + }if (bind (sd, cur->ai_addr, cur->ai_addrlen)) {const int errnum =openvpn_errno ();
@@ -1154,11 +1164,12 @@ static void bind_local (struct link_socket *sock)#ifdef ENABLE_SOCKS if (sock->socks_proxy && sock->info.proto ==PROTO_UDP )socket_bind (sock->ctrl_sd, sock->info.lsa->bind_local, - sock->info.lsa->actual.ai_family,"SOCKS" ); + sock->info.lsa->actual.ai_family,"SOCKS" , false); else#endif socket_bind (sock->sd, sock->info.lsa->bind_local, - sock->info.lsa->actual.ai_family,"TCP/UDP" ); + sock->info.lsa->actual.ai_family, +"TCP/UDP" , sock->info.bind_ipv6_only); } }
@@ -1295,11 +1306,12 @@ create_new_socket (struct link_socket* sock)resolve_bind_local (sock, sock->info.af); }resolve_remote (sock,1 ,NULL ,NULL ); +/* * In P2P or server mode we must create the socket even when resolving * the remote site fails/is not specified. */ -if (sock->info.af && sock->info.lsa->actual.ai_family==0 && sock->bind_local) +if (sock->info.lsa->actual.ai_family==0 && sock->bind_local) {/* Copy sock parameters from bind addr */ set_actual_address (&sock->info.lsa->actual, sock->info.lsa->bind_local);
@@ -1310,7 +1322,7 @@ create_new_socket (struct link_socket* sock)/* * Create the socket early if socket should be bound */ -if (sock->bind_local && sock->info.lsa->actual.ai_family) +if (sock->bind_local) {create_socket (sock);
@@ -1328,7 +1340,8 @@ link_socket_init_phase1 (struct link_socket *sock,const char *remote_host, const char *remote_port, int proto, - sa_family_t af, + sa_family_t af, + bool bind_ipv6_only, int mode, const struct link_socket *accept_from, #ifdef ENABLE_HTTP_PROXY
@@ -1389,6 +1402,7 @@ link_socket_init_phase1 (struct link_socket *sock, sock->info.af = af; sock->info.remote_float = remote_float; sock->info.lsa = lsa; + sock->info.bind_ipv6_only = bind_ipv6_only; sock->info.ipchange_command = ipchange_command; sock->info.plugins = plugins;
src/openvpn/socket.h +4 -1
@@ -118,6 +118,7 @@ struct link_socket_infobool remote_float;int proto;/* Protocol (PROTO_x defined below) */ sa_family_t af;/* Address family like AF_INET, AF_INET6 or AF_UNSPEC*/ +bool bind_ipv6_only;int mtu_changed;/* Set to true when mtu value is changed */ };
@@ -289,7 +290,8 @@ struct link_socket *link_socket_new (void);void socket_bind (socket_descriptor_t sd,struct addrinfo *local,int af_family, -const char *prefix); +const char *prefix, +bool ipv6only); int openvpn_connect (socket_descriptor_t sd, const struct sockaddr *remote,
@@ -308,6 +310,7 @@ link_socket_init_phase1 (struct link_socket *sock,const char *remote_port, int proto, sa_family_t af, + bool bind_ipv6_only, int mode, const struct link_socket *accept_from, #ifdef ENABLE_HTTP_PROXY
Signature · 1 line
1.7.9.5
PATCH 13/14 Fix connecting to localhost on Android
In reply to Arne SchwabeDo not protect the link socket when connecting to localhost
--- src/openvpn/socket.c | 21 ++++++++++++++++++--- src/openvpn/socket.h | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-)
src/openvpn/socket.c +18 -3
@@ -691,16 +691,24 @@ create_socket (struct link_socket *sock)/* set socket to --mark packets with given value */ socket_set_mark (sock->sd, sock->mark); +} +#ifdef TARGET_ANDROID +static void protect_fd_nonlocal (int fd,const struct sockaddr * addr) +{/* pass socket FD to management interface to pass on to VPNService API * as "protected socket" (exempt from being routed into tunnel) */ +if (addr_local (addr)) { +msg (M_DEBUG ,"Address is local, not protecting socket fd %d" , fd); +return ; + } - management->connection.fdtosend = sock->sd; +msg (M_DEBUG ,"Protecting socket fd %d" , fd); + management->connection.fdtosend = fd;management_android_control (management,"PROTECTFD" , __func__); -#endif - } +#endif /* * Functions used for establishing a TCP stream connection.
@@ -934,6 +942,10 @@ openvpn_connect (socket_descriptor_t sd, {int status =0 ; +#ifdef TARGET_ANDROID +protect_fd_nonlocal (sd, remote); +#endif +#ifdef CONNECT_NONBLOCK set_nonblock (sd); status =connect (sd, remote,af_addr_size (remote->sa_family));
@@ -1791,6 +1803,9 @@ link_socket_init_phase2 (struct link_socket *sock,phase2_socks_client (sock, sig_info);#endif } +#ifdef TARGET_ANDROID +protect_fd_nonlocal (sock->sd, &sock->info.lsa->actual.dest.addr.sa); +#endif if (sig_info && sig_info->signal_received) goto done; }
src/openvpn/socket.h +17 -0
@@ -598,6 +598,23 @@ addr_defined (const struct openvpn_sockaddr *addr)default :return 0 ; } } + +static inline bool +addr_local (const struct sockaddr *addr) +{ +if (!addr) +return false; +switch (addr->sa_family) { +case AF_INET : +return ((const struct sockaddr_in *)addr)->sin_addr.s_addr ==htonl (INADDR_LOOPBACK ); +case AF_INET6 : +return IN6_IS_ADDR_LOOPBACK (&((const struct sockaddr_in6 *)addr)->sin6_addr); +default : +return false; + } +} + +static inline bool addr_defined_ipi (const struct link_socket_actual *lsa) {
Signature · 1 line
1.7.9.5
PATCH 14/14 Move the initialization of the environment to the top so c2.es is initialized
In reply to Arne Schwabe--- src/openvpn/init.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
src/openvpn/init.c +4 -4
@@ -3339,6 +3339,10 @@ init_instance (struct context *c, const struct env_set *env, const unsigned int/* init garbage collection level */ gc_init (&c->c2.gc); +/* inherit environmental variables */ +if (env) +do_inherit_env (c, env); +/* signals caught here will abort */ c->sig->signal_received =0 ; c->sig->signal_text =NULL ;
@@ -3390,10 +3394,6 @@ init_instance (struct context *c, const struct env_set *env, const unsigned intif (c->mode ==CM_P2P || c->mode ==CM_TOP )do_option_warnings (c); -/* inherit environmental variables */ -if (env) -do_inherit_env (c, env); -#ifdef ENABLE_PLUGIN /* initialize plugins */ if (c->mode ==CM_P2P || c->mode ==CM_TOP )
Signature · 1 line
1.7.9.5
Feature-ACK from "the group" in Munich.
Code review ACK and (lightly) tested for a few cases by me.
Patch has been applied to the master branch.
commit 076fd3e46bbbe6261317d58cc2442f8eccc927ce (master)
Author: Arne Schwabe Date: Thu Nov 21 21:08:02 2013 +0100
Change the type of all ports in openvpn to const char* and let getaddrinfo resolve the port together with the hostname.
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/8018
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering