Added uninit_management_callback call to
init_instance_handle_signals so that
signals thrown during initialization can
bring us back to a management hold.
git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@786 e7ae566f-a301-0410-adde-c780ea21d3b5
... | ... |
@@ -1811,6 +1811,7 @@ do_init_socket_1 (struct context *c, int mode) |
1811 | 1811 |
c->plugins, |
1812 | 1812 |
c->options.resolve_retry_seconds, |
1813 | 1813 |
c->options.connect_retry_seconds, |
1814 |
+ c->options.connect_retry_max, |
|
1814 | 1815 |
c->options.mtu_discover_type, |
1815 | 1816 |
c->options.rcvbuf, |
1816 | 1817 |
c->options.sndbuf, |
... | ... |
@@ -2371,6 +2372,14 @@ init_instance_handle_signals (struct context *c, const struct env_set *env, cons |
2371 | 2371 |
pre_init_signal_catch (); |
2372 | 2372 |
init_instance (c, env, flags); |
2373 | 2373 |
post_init_signal_catch (); |
2374 |
+ |
|
2375 |
+ /* |
|
2376 |
+ * This is done so that signals thrown during |
|
2377 |
+ * initialization can bring us back to |
|
2378 |
+ * a management hold. |
|
2379 |
+ */ |
|
2380 |
+ if (IS_SIG (c)) |
|
2381 |
+ uninit_management_callback (); |
|
2374 | 2382 |
} |
2375 | 2383 |
|
2376 | 2384 |
/* |
... | ... |
@@ -119,6 +119,7 @@ openvpn \- secure IP tunnel daemon. |
119 | 119 |
[\ \fB\-\-config\fR\ \fIfile\fR\ ] |
120 | 120 |
[\ \fB\-\-connect\-freq\fR\ \fIn\ sec\fR\ ] |
121 | 121 |
[\ \fB\-\-connect\-retry\fR\ \fIn\fR\ ] |
122 |
+[\ \fB\-\-connect\-retry\-max\fR\ \fIn\fR\ ] |
|
122 | 123 |
[\ \fB\-\-crl\-verify\fR\ \fIcrl\fR\ ] |
123 | 124 |
[\ \fB\-\-cryptoapicert\fR\ \fIselect\-string\fR\ ] |
124 | 125 |
[\ \fB\-\-daemon\fR\ \fI[progname]\fR\ ] |
... | ... |
@@ -553,7 +554,9 @@ started with |
553 | 553 |
will attempt to connect, and if that fails, will sleep for 5 |
554 | 554 |
seconds (adjustable via the |
555 | 555 |
.B --connect-retry |
556 |
-option) and try again. Both TCP client and server will simulate |
|
556 |
+option) and try again infinite or up to N retries (adjustable via the |
|
557 |
+.B --connect-retry-max |
|
558 |
+option). Both TCP client and server will simulate |
|
557 | 559 |
a SIGUSR1 restart signal if either side resets the connection. |
558 | 560 |
|
559 | 561 |
OpenVPN is designed to operate optimally over UDP, but TCP capability is provided |
... | ... |
@@ -582,6 +585,15 @@ number of seconds to wait |
582 | 582 |
between connection retries (default=5). |
583 | 583 |
.\"********************************************************* |
584 | 584 |
.TP |
585 |
+.B --connect-retry-max n |
|
586 |
+For |
|
587 |
+.B --proto tcp-client, |
|
588 |
+take |
|
589 |
+.B n |
|
590 |
+as the |
|
591 |
+number of retries of connection attempt (default=infinite). |
|
592 |
+.\"********************************************************* |
|
593 |
+.TP |
|
585 | 594 |
.B --http-proxy server port [authfile] [auth-method] |
586 | 595 |
Connect to remote host through an HTTP proxy at address |
587 | 596 |
.B server |
... | ... |
@@ -95,6 +95,7 @@ static const char usage_message[] = |
95 | 95 |
" p = udp (default), tcp-server, or tcp-client\n" |
96 | 96 |
"--connect-retry n : For --proto tcp-client, number of seconds to wait\n" |
97 | 97 |
" between connection retries (default=%d).\n" |
98 |
+ "--connect-retry-max n : Maximum connection attempt retries, default infinite.\n" |
|
98 | 99 |
#ifdef ENABLE_HTTP_PROXY |
99 | 100 |
"--http-proxy s p [up] [auth] : Connect to remote host through an HTTP proxy at\n" |
100 | 101 |
" address s and port p. If proxy authentication is required,\n" |
... | ... |
@@ -586,6 +587,7 @@ init_options (struct options *o) |
586 | 586 |
o->topology = TOP_NET30; |
587 | 587 |
o->proto = PROTO_UDPv4; |
588 | 588 |
o->connect_retry_seconds = 5; |
589 |
+ o->connect_retry_max = 0; |
|
589 | 590 |
o->local_port = o->remote_port = OPENVPN_PORT; |
590 | 591 |
o->verbosity = 1; |
591 | 592 |
o->status_file_update_freq = 60; |
... | ... |
@@ -1086,6 +1088,7 @@ show_settings (const struct options *o) |
1086 | 1086 |
|
1087 | 1087 |
SHOW_INT (resolve_retry_seconds); |
1088 | 1088 |
SHOW_INT (connect_retry_seconds); |
1089 |
+ SHOW_INT (connect_retry_max); |
|
1089 | 1090 |
|
1090 | 1091 |
SHOW_STR (username); |
1091 | 1092 |
SHOW_STR (groupname); |
... | ... |
@@ -3218,6 +3221,11 @@ add_option (struct options *options, |
3218 | 3218 |
options->connect_retry_seconds = positive_atoi (p[1]); |
3219 | 3219 |
options->connect_retry_defined = true; |
3220 | 3220 |
} |
3221 |
+ else if (streq (p[0], "connect-retry-max") && p[1]) |
|
3222 |
+ { |
|
3223 |
+ VERIFY_PERMISSION (OPT_P_GENERAL); |
|
3224 |
+ options->connect_retry_max = positive_atoi (p[1]); |
|
3225 |
+ } |
|
3221 | 3226 |
else if (streq (p[0], "ipchange") && p[1]) |
3222 | 3227 |
{ |
3223 | 3228 |
VERIFY_PERMISSION (OPT_P_SCRIPT); |
... | ... |
@@ -721,9 +721,11 @@ socket_connect (socket_descriptor_t *sd, |
721 | 721 |
const char *remote_dynamic, |
722 | 722 |
bool *remote_changed, |
723 | 723 |
const int connect_retry_seconds, |
724 |
+ const int connect_retry_max, |
|
724 | 725 |
volatile int *signal_received) |
725 | 726 |
{ |
726 | 727 |
struct gc_arena gc = gc_new (); |
728 |
+ int retry = 0; |
|
727 | 729 |
|
728 | 730 |
msg (M_INFO, "Attempting to establish TCP connection with %s", |
729 | 731 |
print_sockaddr (remote, &gc)); |
... | ... |
@@ -732,6 +734,9 @@ socket_connect (socket_descriptor_t *sd, |
732 | 732 |
const int status = connect (*sd, (struct sockaddr *) &remote->sa, |
733 | 733 |
sizeof (remote->sa)); |
734 | 734 |
|
735 |
+ if (connect_retry_max != 0 && retry++ >= connect_retry_max) |
|
736 |
+ *signal_received = SIGUSR1; |
|
737 |
+ |
|
735 | 738 |
get_signal (signal_received); |
736 | 739 |
if (*signal_received) |
737 | 740 |
goto done; |
... | ... |
@@ -987,6 +992,7 @@ link_socket_init_phase1 (struct link_socket *sock, |
987 | 987 |
const struct plugin_list *plugins, |
988 | 988 |
int resolve_retry_seconds, |
989 | 989 |
int connect_retry_seconds, |
990 |
+ int connect_retry_max, |
|
990 | 991 |
int mtu_discover_type, |
991 | 992 |
int rcvbuf, |
992 | 993 |
int sndbuf, |
... | ... |
@@ -1017,6 +1023,7 @@ link_socket_init_phase1 (struct link_socket *sock, |
1017 | 1017 |
sock->inetd = inetd; |
1018 | 1018 |
sock->resolve_retry_seconds = resolve_retry_seconds; |
1019 | 1019 |
sock->connect_retry_seconds = connect_retry_seconds; |
1020 |
+ sock->connect_retry_max = connect_retry_max; |
|
1020 | 1021 |
sock->mtu_discover_type = mtu_discover_type; |
1021 | 1022 |
|
1022 | 1023 |
#ifdef ENABLE_DEBUG |
... | ... |
@@ -1215,6 +1222,7 @@ link_socket_init_phase2 (struct link_socket *sock, |
1215 | 1215 |
remote_dynamic, |
1216 | 1216 |
&remote_changed, |
1217 | 1217 |
sock->connect_retry_seconds, |
1218 |
+ sock->connect_retry_max, |
|
1218 | 1219 |
signal_received); |
1219 | 1220 |
|
1220 | 1221 |
if (*signal_received) |
... | ... |
@@ -1255,6 +1263,7 @@ link_socket_init_phase2 (struct link_socket *sock, |
1255 | 1255 |
remote_dynamic, |
1256 | 1256 |
&remote_changed, |
1257 | 1257 |
sock->connect_retry_seconds, |
1258 |
+ sock->connect_retry_max, |
|
1258 | 1259 |
signal_received); |
1259 | 1260 |
|
1260 | 1261 |
if (*signal_received) |
... | ... |
@@ -189,6 +189,7 @@ struct link_socket |
189 | 189 |
|
190 | 190 |
int resolve_retry_seconds; |
191 | 191 |
int connect_retry_seconds; |
192 |
+ int connect_retry_max; |
|
192 | 193 |
int mtu_discover_type; |
193 | 194 |
|
194 | 195 |
struct socket_buffer_size socket_buffer_sizes; |
... | ... |
@@ -299,6 +300,7 @@ link_socket_init_phase1 (struct link_socket *sock, |
299 | 299 |
const struct plugin_list *plugins, |
300 | 300 |
int resolve_retry_seconds, |
301 | 301 |
int connect_retry_seconds, |
302 |
+ int connect_retry_max, |
|
302 | 303 |
int mtu_discover_type, |
303 | 304 |
int rcvbuf, |
304 | 305 |
int sndbuf, |