git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@5010 e7ae566f-a301-0410-adde-c780ea21d3b5
| ... | ... |
@@ -119,6 +119,17 @@ check_inactivity_timeout (struct context *c) |
| 119 | 119 |
} |
| 120 | 120 |
|
| 121 | 121 |
#if P2MP |
| 122 |
+ |
|
| 123 |
+static inline void |
|
| 124 |
+check_server_poll_timeout (struct context *c) |
|
| 125 |
+{
|
|
| 126 |
+ void check_server_poll_timeout_dowork (struct context *c); |
|
| 127 |
+ |
|
| 128 |
+ if (c->options.server_poll_timeout |
|
| 129 |
+ && event_timeout_trigger (&c->c2.server_poll_interval, &c->c2.timeval, ETT_DEFAULT)) |
|
| 130 |
+ check_server_poll_timeout_dowork (c); |
|
| 131 |
+} |
|
| 132 |
+ |
|
| 122 | 133 |
/* |
| 123 | 134 |
* Scheduled exit? |
| 124 | 135 |
*/ |
| ... | ... |
@@ -314,6 +314,19 @@ check_inactivity_timeout_dowork (struct context *c) |
| 314 | 314 |
|
| 315 | 315 |
#if P2MP |
| 316 | 316 |
|
| 317 |
+void |
|
| 318 |
+check_server_poll_timeout_dowork (struct context *c) |
|
| 319 |
+{
|
|
| 320 |
+ event_timeout_reset (&c->c2.server_poll_interval); |
|
| 321 |
+ if (!tls_initial_packet_received (c->c2.tls_multi)) |
|
| 322 |
+ {
|
|
| 323 |
+ msg (M_INFO, "Server poll timeout, restarting"); |
|
| 324 |
+ c->sig->signal_received = SIGUSR1; |
|
| 325 |
+ c->sig->signal_text = "server_poll"; |
|
| 326 |
+ c->persist.restart_sleep_seconds = -1; |
|
| 327 |
+ } |
|
| 328 |
+} |
|
| 329 |
+ |
|
| 317 | 330 |
/* |
| 318 | 331 |
* Schedule a SIGTERM n_seconds from now. |
| 319 | 332 |
*/ |
| ... | ... |
@@ -516,6 +529,10 @@ process_coarse_timers (struct context *c) |
| 516 | 516 |
return; |
| 517 | 517 |
|
| 518 | 518 |
#if P2MP |
| 519 |
+ check_server_poll_timeout (c); |
|
| 520 |
+ if (c->sig->signal_received) |
|
| 521 |
+ return; |
|
| 522 |
+ |
|
| 519 | 523 |
check_scheduled_exit (c); |
| 520 | 524 |
if (c->sig->signal_received) |
| 521 | 525 |
return; |
| ... | ... |
@@ -792,6 +792,11 @@ do_init_timers (struct context *c, bool deferred) |
| 792 | 792 |
if (c->options.ping_rec_timeout) |
| 793 | 793 |
event_timeout_init (&c->c2.ping_rec_interval, c->options.ping_rec_timeout, now); |
| 794 | 794 |
|
| 795 |
+#if P2MP |
|
| 796 |
+ if (c->options.server_poll_timeout) |
|
| 797 |
+ event_timeout_init (&c->c2.server_poll_interval, c->options.server_poll_timeout, now); |
|
| 798 |
+#endif |
|
| 799 |
+ |
|
| 795 | 800 |
if (!deferred) |
| 796 | 801 |
{
|
| 797 | 802 |
/* initialize connection establishment timer */ |
| ... | ... |
@@ -1444,10 +1449,15 @@ socket_restart_pause (struct context *c) |
| 1444 | 1444 |
#if P2MP |
| 1445 | 1445 |
if (auth_retry_get () == AR_NOINTERACT) |
| 1446 | 1446 |
sec = 10; |
| 1447 |
+ |
|
| 1448 |
+ if (c->options.server_poll_timeout && sec > 1) |
|
| 1449 |
+ sec = 1; |
|
| 1447 | 1450 |
#endif |
| 1448 | 1451 |
|
| 1449 | 1452 |
if (c->persist.restart_sleep_seconds > 0 && c->persist.restart_sleep_seconds > sec) |
| 1450 | 1453 |
sec = c->persist.restart_sleep_seconds; |
| 1454 |
+ else if (c->persist.restart_sleep_seconds == -1) |
|
| 1455 |
+ sec = 0; |
|
| 1451 | 1456 |
c->persist.restart_sleep_seconds = 0; |
| 1452 | 1457 |
|
| 1453 | 1458 |
/* do managment hold on context restart, i.e. second, third, fourth, etc. initialization */ |
| ... | ... |
@@ -3279,6 +3279,13 @@ Note that while this option cannot be pushed, it can be controlled |
| 3279 | 3279 |
from the management interface. |
| 3280 | 3280 |
.\"********************************************************* |
| 3281 | 3281 |
.TP |
| 3282 |
+.B --server-poll-timeout n |
|
| 3283 |
+when polling possible remote servers to connect to |
|
| 3284 |
+in a round-robin fashion, spend no more than |
|
| 3285 |
+.B n |
|
| 3286 |
+seconds waiting for a response before trying the next server. |
|
| 3287 |
+.\"********************************************************* |
|
| 3288 |
+.TP |
|
| 3282 | 3289 |
.B --explicit-exit-notify [n] |
| 3283 | 3290 |
In UDP client mode or point-to-point mode, send server/peer an exit notification |
| 3284 | 3291 |
if tunnel is restarted or OpenVPN process is exited. In client mode, on |
| ... | ... |
@@ -432,6 +432,9 @@ static const char usage_message[] = |
| 432 | 432 |
" when connecting to a '--mode server' remote host.\n" |
| 433 | 433 |
"--auth-retry t : How to handle auth failures. Set t to\n" |
| 434 | 434 |
" none (default), interact, or nointeract.\n" |
| 435 |
+ "--server-poll-timeout n : when polling possible remote servers to connect to\n" |
|
| 436 |
+ " in a round-robin fashion, spend no more than n seconds\n" |
|
| 437 |
+ " waiting for a response before trying the next server.\n" |
|
| 435 | 438 |
#endif |
| 436 | 439 |
#ifdef ENABLE_OCC |
| 437 | 440 |
"--explicit-exit-notify [n] : On exit/restart, send exit signal to\n" |
| ... | ... |
@@ -726,6 +729,7 @@ init_options (struct options *o, const bool init_gc) |
| 726 | 726 |
#endif |
| 727 | 727 |
#if P2MP |
| 728 | 728 |
o->scheduled_exit_interval = 5; |
| 729 |
+ o->server_poll_timeout = 0; |
|
| 729 | 730 |
#endif |
| 730 | 731 |
#ifdef USE_CRYPTO |
| 731 | 732 |
o->ciphername = "BF-CBC"; |
| ... | ... |
@@ -4464,6 +4468,12 @@ add_option (struct options *options, |
| 4464 | 4464 |
{
|
| 4465 | 4465 |
options->sockflags |= SF_HOST_RANDOMIZE; |
| 4466 | 4466 |
} |
| 4467 |
+#if P2MP |
|
| 4468 |
+ else if (streq (p[1], "SERVER_POLL_TIMEOUT") && p[2]) |
|
| 4469 |
+ {
|
|
| 4470 |
+ options->server_poll_timeout = positive_atoi(p[2]); |
|
| 4471 |
+ } |
|
| 4472 |
+#endif |
|
| 4467 | 4473 |
else |
| 4468 | 4474 |
{
|
| 4469 | 4475 |
if (streq (p[1], "FORWARD_COMPATIBLE") && p[2] && streq (p[2], "1")) |
| ... | ... |
@@ -4887,6 +4897,11 @@ add_option (struct options *options, |
| 4887 | 4887 |
VERIFY_PERMISSION (OPT_P_PULL_MODE); |
| 4888 | 4888 |
options->push_continuation = atoi(p[1]); |
| 4889 | 4889 |
} |
| 4890 |
+ else if (streq (p[0], "server-poll-timeout") && p[1]) |
|
| 4891 |
+ {
|
|
| 4892 |
+ VERIFY_PERMISSION (OPT_P_GENERAL); |
|
| 4893 |
+ options->server_poll_timeout = positive_atoi(p[1]); |
|
| 4894 |
+ } |
|
| 4890 | 4895 |
else if (streq (p[0], "auth-user-pass")) |
| 4891 | 4896 |
{
|
| 4892 | 4897 |
VERIFY_PERMISSION (OPT_P_GENERAL); |
| ... | ... |
@@ -703,6 +703,12 @@ bool tls_authenticate_key (struct tls_multi *multi, const unsigned int mda_key_i |
| 703 | 703 |
*/ |
| 704 | 704 |
|
| 705 | 705 |
static inline bool |
| 706 |
+tls_initial_packet_received (const struct tls_multi *multi) |
|
| 707 |
+{
|
|
| 708 |
+ return multi->n_sessions > 0; |
|
| 709 |
+} |
|
| 710 |
+ |
|
| 711 |
+static inline bool |
|
| 706 | 712 |
tls_test_auth_deferred_interval (const struct tls_multi *multi) |
| 707 | 713 |
{
|
| 708 | 714 |
if (multi) |