Split link_socket_init_phase2 into smaller more managable/readable functions. No functional changes
PATCH v2 1/9 Split link_socket_init_phase2 into smaller more managable/readable functions. No functional changes
--- src/openvpn/socket.c | 468 ++++++++++++++++++++++++++++----------------------- 1 file changed, 261 insertions(+), 207 deletions(-)
src/openvpn/socket.c +261 -207
@@ -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,
@@ -1472,27 +1489,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); + } +} + +static +void phase2_inetd (struct link_socket * sock,const struct frame *frame, +const char *remote_dynamic,volatile int *signal_received) +{ +bool remote_changed = false; + +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 buffers based on --sndbuf and --rcvbuf options */ -socket_set_buffers (sock->sd, &sock->socket_buffer_sizes); +/* 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 socket to --mark packets with given value */ -socket_set_mark (sock->sd, mark); +/* set Path MTU discovery options on the socket */ +set_mtu_discover_type (sock->sd, sock->mtu_discover_type); -if (sock->bind_local) -resolve_bind_local (sock); -resolve_remote (sock,1 ,NULL ,NULL ); +#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 ;
@@ -1519,41 +1761,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 {
@@ -1562,139 +1773,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;
@@ -1705,49 +1801,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)
@@ -1755,7 +1810,6 @@ link_socket_init_phase2 (struct link_socket *sock,if (!*signal_received) *signal_received = sig_save; } -gc_free (&gc); }void
Signature · 1 line
1.8.3.4 (Apple Git-47)
PATCH v2 2/9 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)
[Openvpn-devel] [PATCH applied] Re: Change remote the proto_remote function to return a constant string
ACK. Code and feature.
Patch has been applied to the master branch, with some textual cleanup applied to the commit message.
commit 34136dd8533510f68a012ba9e6bcd8cf5d1ce80e (master)
Author: Arne Schwabe Date: Mon Nov 25 13:31:13 2013 +0100
Change remote the proto_remote function to return a constant string
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8055
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v2 3/9 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.8.3.4 (Apple Git-47)
[Openvpn-devel] [PATCH applied] Re: Remove the ip-remote-hint option.
ACK.
Feature-ACK agreed in Munich, on the assumption that it will eventually come back as an alias of "--resolve-remotes-at-startup <ip>". Right now, the feature just gets in the way of the dual-stack changes.
Code-ACK. Looks simple enough, and passes my t_client tests :-)
Patch has been applied to the master branch.
commit bb9026a60a8ebdf20fdf9a99e16c0d8afc658747 (master)
Author: Arne Schwabe Date: Mon Nov 25 13:31:14 2013 +0100
Remove the ip-remote-hint option.
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/8057
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v2 4/9 change the type of remote to addrinfo.
In reply to Arne Schwabe--- src/openvpn/init.c | 5 ++-- src/openvpn/socket.c | 51 ++++++++++++++++--------------- src/openvpn/socket.h | 85 ++++++++++++++++++++++++++++++++++++++++++++-------- src/openvpn/tun.c | 16 ++++++---- src/openvpn/tun.h | 2 +- 5 files changed, 114 insertions(+), 45 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 +27 -24
111 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.8.3.4 (Apple Git-47)
[Openvpn-devel] [PATCH applied] Re: change the type of remote to addrinfo.
ACK. Code reviewed, understood, makes sense (and some of the ASSERT(0) in there are to-be-cleanedup markers being fixed in the next hunks).
I have taken the liberty of carefully massaging some of the whitespace, pull up one fix to init.c from 6/9, and change one mishap in socket.h - a diff between "previous master + 4/9" and "6c5db192c30ff" is attached.
Word of warning: with this patch in place, connecting via "udp" or "tcp-client" to a host that has IPv4+IPv6 in place, on an OS that will prefer IPv6 to IPv4, will always fail. The remote_list will have IPv6 in it's first entry, while the socket will try to do AF_INET, and that will not work. This will be fixed when merging 6/9.
Patch has been applied to the master branch.
commit 6c5db192c30ff0c6b89e2e0aefec00329de39302
Author: Arne Schwabe Date: Mon Nov 25 13:31:15 2013 +0100
change the type of remote to addrinfo.
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8053
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH applied] Re: change the type of remote to addrinfo.
Hi,
Quoted 3 lines · Gert Doering
I have taken the liberty of carefully massaging some of the whitespace, pull up one fix to
init.cfrom 6/9, and change one mishap insocket.h- a diff between "previous master + 4/9" and "6c5db192c30ff" is attached.
Well. If people claim "... is attched", in the first mail, it never is...
Here it is now.
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...src/openvpn/init.c +1 -1
@@ -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_list), + c->c1.link_socket_addr.remote_list, !c->options.ifconfig_nowarn, c->c2.es);
src/openvpn/socket.h +10 -7
@@ -624,9 +624,10 @@ static inline bool addrlist_match (const struct openvpn_sockaddr *a1, const struct addrinfo *addrlist) { const struct addrinfo *curele; -for (curele = addrlist; curele; curele=curele->ai_next) { - -switch (a1->addr.sa.sa_family) { +for (curele = addrlist; curele; curele=curele->ai_next) + { +switch (a1->addr.sa.sa_family) + {case AF_INET :if (a1->addr.in4.sin_addr.s_addr == ((struct sockaddr_in *)curele->ai_addr)->sin_addr.s_addr)return true;
@@ -660,8 +661,10 @@ static inline bool addrlist_port_match (const struct openvpn_sockaddr *a1, const struct addrinfo *a2) { const struct addrinfo *curele; -for (curele=a2;curele;curele = curele->ai_next) { -switch (a1->addr.sa.sa_family) { +for (curele=a2;curele;curele = curele->ai_next) + { +switch (a1->addr.sa.sa_family) + {case AF_INET :if (curele->ai_family ==AF_INET && a1->addr.in4.sin_addr.s_addr == ((struct sockaddr_in*)curele->ai_addr)->sin_addr.s_addr
@@ -879,8 +882,8 @@ link_socket_set_outgoing_addr (const struct buffer *buf, || !addr_match_proto (&act->dest, &lsa->actual.dest, info->proto)) /* address undef or address == remote or --float */ && (info->remote_float - || !lsa->remote_list) - || addrlist_match_proto (&act->dest, lsa->remote_list, info->proto) + || !lsa->remote_list + || addrlist_match_proto (&act->dest, lsa->remote_list, info->proto)) ) {link_socket_connection_initiated (buf, info, act, common_name, es);
PATCH v2 5/9 When resolving fails print the error message from socket layer
In reply to Arne Schwabe--- src/openvpn/socket.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
src/openvpn/socket.c +7 -5
@@ -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; }
@@ -1718,8 +1718,10 @@ phase2_socks_client (struct link_socket *sock, bool *remote_changed, sock->did_resolve_remote = false;addr_zero_host (&sock->info.lsa->actual.dest); -if (sock->info.lsa->remote_list) +if (sock->info.lsa->remote_list) {freeaddrinfo (sock->info.lsa->remote_list); + sock->info.lsa->remote_list=NULL ; + }resolve_remote (sock,1 ,NULL , signal_received); }
Signature · 1 line
1.8.3.4 (Apple Git-47)
[Openvpn-devel] [PATCH applied] Re: When resolving fails print the error message from socket layer
ACK.
Patch has been applied to master branch. It looks useful for 2.3 as well, but the code is different enough already that it wouldn't apply as is, so it would be a separate patch.
commit aa162d44edae8530391775b55e7b4f149548537e (master)
Author: Arne Schwabe Date: Mon Nov 25 13:31:16 2013 +0100
When resolving fails print the error message from socket layer
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8059
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v2 6/9 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 | 759 +++++++++++++++++++++++++------------------------- src/openvpn/socket.h | 80 +++--- src/openvpn/tun.c | 11 +- src/openvpn/tun.h | 2 +- 16 files changed, 1037 insertions(+), 657 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 +372 -387
1,181 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.8.3.4 (Apple Git-47)
Re: [Openvpn-devel] [Patch v2 6/9] Implement dual stack client support for OpenVPN
Hi,
Quoted 1 line · Arne Schwabe
This patch contains a number of changes. I did not further spit this since some changes make only sense being changed together.
ACK, but...
- some parts of the patch did not apply cleanly due to whitespace issues (most likely I caused them in the previous merges, meh, but some of them were not my doing...), so I had to apply a few things manually - I *think* I got it all right, but hey...
- while at it, I've cleaned up more whitespace (trailing blanks)
- as discussed on IRC, I've adapted the complex if() condition in socket.h (link_socket_set_outgoing_addr()
- I've included the fix to make "openvpn --test-crypto" work again
- I've changed the patch to tun.c to use "local_public" (I assume this was intended and just a copy-paste overlook)
- I've changed the protocol list to add "tcp4-server", "tcp4-client", and also changed "tcp-server" and "tcp-client" from AF_INET to AF_UNSPEC - and I'm not 100% sure if that is "right" for tcp-server.
So - amended patch below. Arne, could you please verify that these changes are all good and formally ACK again? Transparency, and such :-)
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...From 91cecc4166eb65703441997822b4582292fa84bb Mon Sep 17 00:00:00 2001
From: Arne Schwabe <[email protected]...>
Date: Mon, 25 Nov 2013 13:31:17 +0100
Subject: [PATCH] Implement dual stack client support for OpenVPN
This patch contains a number of changes. I did not further spit this since some changes make only sense being changed together.
Always use connection_list, simplifies the reconnection logic.
Change meaning of --connect-retry-max and --connect-retry to be used all connections. This now allows OpenVPN to quit after n unsuccessful udp connection attempts
Remove the tcp reconnection logic. Failing a TCP connection will now cause a USR1 like a UDP connection. Also extend sig->source from bool to int to specify signal source. This allows a finer grained reconnection logic if necessary in the future.
Dual-Stack support: if an address resolves to multiple records each address is tried in sequential order. Then proceed to next connection entry. Introduce the field current_remote to represent the current connecting remote. Also change some fields to struct addrinfo* form openvn_addr to store multiple addresses needed for the dual stack support.
Change meaning from udp and tcp to allow both IPv4 and IPv6. Introducue new udp4 and tcp4 to force IPv4.
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8058
--- doc/openvpn.8 | 24 +- src/openvpn/error.c | 2 +- src/openvpn/init.c | 234 +++++++++------- src/openvpn/manage.c | 25 +- src/openvpn/manage.h | 2 +- src/openvpn/options.c | 133 ++++----- src/openvpn/options.h | 26 +- src/openvpn/ps.c | 8 +- src/openvpn/push.c | 3 +- src/openvpn/sig.c | 22 +- src/openvpn/sig.h | 11 +- src/openvpn/socket.c | 745 +++++++++++++++++++++++++------------------------- src/openvpn/socket.h | 81 +++--- src/openvpn/tun.c | 9 +- src/openvpn/tun.h | 2 +- 15 files changed, 684 insertions(+), 643 deletions(-)
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 +140 -94
368 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 +59 -74
229 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 +2 -1
@@ -49,7 +49,8 @@ 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 +368 -377
1,166 lines not on this page · raw message
src/openvpn/socket.h +42 -39
204 lines not on this page · raw message
src/openvpn/tun.c +6 -3
@@ -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)
@@ -474,11 +474,14 @@ init_tun (const char *dev, /* --dev option */* make sure they do not clash with our virtual subnet. */ -check_addr_clash ("local" , +for (curele=local_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.8.1.5
Re: [Openvpn-devel] [Patch v2 6/9] Implement dual stack client support for OpenVPN
Am 29.11.13 20:42, schrieb Gert Doering:
Quoted 21 lines
Hi,
Quoted 1 line · Arne Schwabe
This patch contains a number of changes. I did not further spit this since some changes make only sense being changed together.
ACK, but...
- some parts of the patch did not apply cleanly due to whitespace issues (most likely I caused them in the previous merges, meh, but some of them were not my doing...), so I had to apply a few things manually - I *think* I got it all right, but hey...
- while at it, I've cleaned up more whitespace (trailing blanks)
- as discussed on IRC, I've adapted the complex
if()condition insocket.h(link_socket_set_outgoing_addr()- I've included the fix to make "openvpn --test-crypto" work again
- I've changed the patch to
tun.cto use "local_public" (I assume this was intended and just a copy-paste overlook)
Quoted 8 lines
- I've changed the protocol list to add "tcp4-server", "tcp4-client", and also changed "tcp-server" and "tcp-client" from
AF_INETtoAF_UNSPEC- and I'm not 100% sure if that is "right" for tcp-server.So - amended patch below. Arne, could you please verify that these changes are all good and formally ACK again? Transparency, and such :-)
ACK and thanks for doing my work :)
Re: [Openvpn-devel] [Patch v2 6/9] Implement dual stack client support for OpenVPN
Hi,
Quoted 4 lines · Arne Schwabe
Quoted 2 lines
So - amended patch below. Arne, could you please verify that these changes are all good and formally ACK again? Transparency, and such :-)
ACK and thanks for doing my work :)
Well, without your previous work, we've never reached this point - the changes are quite big (but necessary). So thank you!
Anyway. It is official now, dual-stack client support pushed out...
commit 23d61c56b9fd218c39ad151b01b7e2d6690e6093
Author: Arne Schwabe <[email protected]...> Date: Mon Nov 25 13:31:17 2013 +0100
Implement dual stack client support for OpenVPN
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/8058
Signed-off-by: Gert Doering <[email protected]...>
Message-ID: <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8071
Signed-off-by: Gert Doering <[email protected]...>gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...PATCH v2 7/9 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 | 34 ++++++++++++++++++++++++---------- src/openvpn/socket.h | 5 ++++- 7 files changed, 42 insertions(+), 13 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 +24 -10
@@ -662,10 +662,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 ) {
@@ -880,7 +879,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 ();
@@ -891,8 +891,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)
@@ -903,7 +906,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 ();
@@ -1153,11 +1163,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); } }
@@ -1294,11 +1305,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);
@@ -1309,7 +1321,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,6 +1340,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
@@ -1388,6 +1401,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.8.3.4 (Apple Git-47)
[Openvpn-devel] [PATCH applied] Re: Implement listing on IPv4/IPv6 dual socket on all platform
ACK.
Some minor changes (v6only moved into the if() clause where the setsockopt() is called, option.bind_ipv6_only initialization fixed, --ipv6only fixed in manpage), but no actual functional changes.
Patch has been applied to the master branch and pushed.
commit a2c2faaeae66867055ee411aff924ef75bf28cce (master)
Author: Arne Schwabe Date: Mon Nov 25 13:31:18 2013 +0100
Implement listing on IPv4/IPv6 dual socket on all platform
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8052
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH 1/1 Fix IPv6_V6ONLY logic.
In reply to Arne SchwabeThe "ipv6only" setsockopt logic introduced by 8832c6c4cf was inverted, fix. Also add a msg() to show what value is set, as that makes strange v4/v6 connectivity problems much easier to spot.
--- src/openvpn/socket.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
src/openvpn/socket.c +2 -1
@@ -908,8 +908,9 @@ socket_bind (socket_descriptor_t sd,if (ai_family ==AF_INET6 ) { -int v6only = ipv6only ?0 :1 ;/* setsockopt must have an "int" */ +int v6only = ipv6only ?1 :0 ;/* setsockopt must have an "int" */ +msg (M_INFO ,"setsockopt(IPV6_V6ONLY=%d)" , v6only);if (setsockopt (sd,IPPROTO_IPV6 ,IPV6_V6ONLY , &v6only,sizeof (v6only))) {msg (M_NONFATAL |M_ERRNO ,"Setting IPV6_V6ONLY=%d failed" , v6only);
Signature · 1 line
1.8.1.5
Re: [Openvpn-devel] [PATCH] Fix IPv6_V6ONLY logic.
Am 30.11.13 22:38, schrieb Gert Doering:
Quoted 6 lines
The "ipv6only" setsockopt logic introduced by
8832c6c4cfwas inverted, fix. Also add amsg()to show what value is set, as that makes strange v4/v6 connectivity problems much easier to spot.Signed-off-by Gert Doering <[email protected]...>
ACK.
Arne
P.S.: I don't like the ? operator
[Openvpn-devel] [PATCH applied] Re: Fix IPv6_V6ONLY logic.
In reply to Gert DoeringYour patch has been applied to the master branch.
commit 451de0a8d61a8a2c4a049837374a728090b4e4d6
Author: Gert Doering Date: Sat Nov 30 22:38:28 2013 +0100
Fix IPv6_V6ONLY logic.
Signed-off-by: Gert Doering <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8079--
kind regards,
Gert Doering
PATCH v2 8/9 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
@@ -690,16 +690,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.
@@ -933,6 +941,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));
@@ -1790,6 +1802,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.8.3.4 (Apple Git-47)
PATCH v2 9/9 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.8.3.4 (Apple Git-47)
ACK. This really is just moving code bits around without any actual change I could spot. And it passes my test rig :-)
Patch has been applied to the master branch, with some whitespace fixes.
commit 48f1d41a80b1f2aa9e47b38f645dc880bd7090a4
Author: Arne Schwabe Date: Mon Nov 25 13:31:12 2013 +0100
Split link_socket_init_phase2 into smaller more managable/readable functions. No functional changes
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering