summaryrefslogtreecommitdiff
path: root/accel-pppd/session.c
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2015-02-21 14:31:34 +0300
committerDmitry Kozlov <xeb@mail.ru>2015-02-21 14:31:34 +0300
commit9280d2cf0d7d514cc2a3aaf76608d8e053d287bc (patch)
tree42f6683412868c9e48ed8dc1beab70809afbd0e3 /accel-pppd/session.c
parenta8cf09aafaf8bd4995cd205537ec8d8aa7fdb969 (diff)
downloadaccel-ppp-9280d2cf0d7d514cc2a3aaf76608d8e053d287bc.tar.gz
accel-ppp-9280d2cf0d7d514cc2a3aaf76608d8e053d287bc.zip
session: implemented idle and timeout timers
Diffstat (limited to 'accel-pppd/session.c')
-rw-r--r--accel-pppd/session.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/accel-pppd/session.c b/accel-pppd/session.c
index dd7ffd44..da18e434 100644
--- a/accel-pppd/session.c
+++ b/accel-pppd/session.c
@@ -118,6 +118,27 @@ int __export ap_session_starting(struct ap_session *ses)
return 0;
}
+static void ap_session_timer(struct triton_timer_t *t)
+{
+ struct timespec ts;
+ struct ap_session *ses = container_of(t, typeof(*ses), timer);
+
+ if (ap_session_read_stats(ses, NULL))
+ ap_session_terminate(ses, TERM_NAS_ERROR, 0);
+
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+
+ if (ses->idle_timeout && ts.tv_sec - ses->idle_time >= ses->idle_timeout) {
+ log_ppp_msg("idle timeout\n");
+ ap_session_terminate(ses, TERM_SESSION_TIMEOUT, 0);
+ } else if (ses->session_timeout) {
+ if (ts.tv_sec - ses->start_time >= ses->session_timeout) {
+ log_ppp_msg("session timeout\n");
+ ap_session_terminate(ses, TERM_SESSION_TIMEOUT, 0);
+ }
+ }
+}
+
void __export ap_session_activate(struct ap_session *ses)
{
if (ap_shutdown)
@@ -132,6 +153,16 @@ void __export ap_session_activate(struct ap_session *ses)
__sync_sub_and_fetch(&ap_session_stat.starting, 1);
__sync_add_and_fetch(&ap_session_stat.active, 1);
+ if (ses->idle_timeout) {
+ ses->timer.expire = ap_session_timer;
+ ses->timer.period = 60000;
+ triton_timer_add(ses->ctrl->ctx, &ses->timer, 0);
+ } else if (ses->session_timeout) {
+ ses->timer.expire = ap_session_timer;
+ ses->timer.expire_tv.tv_sec = ses->session_timeout;
+ triton_timer_add(ses->ctrl->ctx, &ses->timer, 0);
+ }
+
#ifdef USE_BACKUP
if (!ses->backup)
backup_save_session(ses);
@@ -197,6 +228,9 @@ void __export ap_session_finished(struct ap_session *ses)
ses->ifname_rename = NULL;
}
+ if (ses->timer.tpd)
+ triton_timer_del(&ses->timer);
+
#ifdef USE_BACKUP
if (ses->backup)
ses->backup->storage->free(ses->backup);
@@ -221,6 +255,9 @@ void __export ap_session_terminate(struct ap_session *ses, int cause, int hard)
if (!ses->terminate_cause)
ses->terminate_cause = cause;
+ if (ses->timer.tpd)
+ triton_timer_del(&ses->timer);
+
if (ses->terminating) {
if (hard)
ses->ctrl->terminate(ses, hard);