From 6ee0899e22498698bd66230e822d783c540da45a Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Tue, 18 Feb 2014 18:54:50 +0100 Subject: [PATCH] Added the mobile-idle-timeout config option. --- src/config.c | 2 ++ src/ocserv-args.def | 4 ++++ src/vpn.h | 1 + src/worker-vpn.c | 21 ++++++++++----------- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/config.c b/src/config.c index 31503777..ac55d76d 100644 --- a/src/config.c +++ b/src/config.c @@ -92,6 +92,7 @@ static struct cfg_options available_options[] = { { .name = "rekey-time", .type = OPTION_NUMERIC, .mandatory = 0 }, { .name = "auth-timeout", .type = OPTION_NUMERIC, .mandatory = 0 }, { .name = "idle-timeout", .type = OPTION_NUMERIC, .mandatory = 0 }, + { .name = "mobile-idle-timeout", .type = OPTION_NUMERIC, .mandatory = 0 }, { .name = "max-clients", .type = OPTION_NUMERIC, .mandatory = 0 }, { .name = "min-reauth-time", .type = OPTION_NUMERIC, .mandatory = 0 }, { .name = "max-same-clients", .type = OPTION_NUMERIC, .mandatory = 0 }, @@ -394,6 +395,7 @@ unsigned force_cert_auth; READ_NUMERIC("auth-timeout", config->auth_timeout); READ_NUMERIC("idle-timeout", config->idle_timeout); + READ_NUMERIC("mobile-idle-timeout", config->mobile_idle_timeout); READ_NUMERIC("max-clients", config->max_clients); READ_NUMERIC("min-reauth-time", config->min_reauth_time); READ_NUMERIC("max-same-clients", config->max_same_clients); diff --git a/src/ocserv-args.def b/src/ocserv-args.def index 0b8bdfda..5bf2b079 100644 --- a/src/ocserv-args.def +++ b/src/ocserv-args.def @@ -187,6 +187,10 @@ auth-timeout = 40 # before being disconnected. Unset to disable. #idle-timeout = 1200 +# The time (in seconds) that a mobile client is allowed to stay idle (no +# traffic) before being disconnected. Unset to disable. +#mobile-idle-timeout = 2400 + # The time (in seconds) that a client is not allowed to reconnect after # a failed authentication attempt. #min-reauth-time = 2 diff --git a/src/vpn.h b/src/vpn.h index 26441523..c20dd19e 100644 --- a/src/vpn.h +++ b/src/vpn.h @@ -204,6 +204,7 @@ struct cfg_st { time_t min_reauth_time; /* after a failed auth, how soon one can reauthenticate -> in seconds */ unsigned auth_timeout; /* timeout of HTTP auth */ unsigned idle_timeout; /* timeout when idle */ + unsigned mobile_idle_timeout; /* timeout when a mobile is idle */ unsigned keepalive; unsigned dpd; unsigned mobile_dpd; diff --git a/src/worker-vpn.c b/src/worker-vpn.c index f0b5a705..8ef31713 100644 --- a/src/worker-vpn.c +++ b/src/worker-vpn.c @@ -1030,7 +1030,6 @@ static int connect_handler(worker_st * ws) struct http_req_st *req = &ws->req; fd_set rfds; int l, e, max, ret, overhead, t; - int dpd; unsigned tls_retry, dtls_mtu, cstp_mtu; char *p; #ifdef HAVE_PSELECT @@ -1121,14 +1120,14 @@ static int connect_handler(worker_st * ws) ret = tls_puts(ws->session, "X-CSTP-Version: 1\r\n"); SEND_ERR(ret); - if (req->is_mobile) - dpd = ws->config->mobile_dpd; - else - dpd = ws->config->dpd; + if (req->is_mobile) { + ws->config->dpd = ws->config->mobile_dpd; + ws->config->idle_timeout = ws->config->mobile_idle_timeout; + } - oclog(ws, LOG_DEBUG, "suggesting DPD of %d secs", dpd); - if (dpd > 0) { - ret = tls_printf(ws->session, "X-CSTP-DPD: %u\r\n", dpd); + oclog(ws, LOG_DEBUG, "suggesting DPD of %d secs", ws->config->dpd); + if (ws->config->dpd > 0) { + ret = tls_printf(ws->session, "X-CSTP-DPD: %u\r\n", ws->config->dpd); SEND_ERR(ret); } @@ -1363,8 +1362,8 @@ static int connect_handler(worker_st * ws) ws->buffer); SEND_ERR(ret); - if (dpd > 0) { - ret = tls_printf(ws->session, "X-DTLS-DPD: %u\r\n", dpd); + if (ws->config->dpd > 0) { + ret = tls_printf(ws->session, "X-DTLS-DPD: %u\r\n", ws->config->dpd); SEND_ERR(ret); } @@ -1545,7 +1544,7 @@ static int connect_handler(worker_st * ws) gettime(&tnow); now = tnow.tv_sec; - if (periodic_check(ws, mtu_overhead, now, dpd) < 0) + if (periodic_check(ws, mtu_overhead, now, ws->config->dpd) < 0) goto exit; if (FD_ISSET(ws->tun_fd, &rfds)) {