aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcharon/processing/jobs/dpd_timeout_job.c
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2012-05-15 14:44:30 +0200
committerMartin Willi <martin@revosec.ch>2012-05-15 14:46:02 +0200
commit4b38c22c00ea24a9b47c9f81da0e2ea8c1731e69 (patch)
tree8e013d7743fd1d6bb6118c3c67e622c68ddb5acc /src/libcharon/processing/jobs/dpd_timeout_job.c
parentebf829f2eb2484a0576824a53b34a98cd22017ef (diff)
downloadstrongswan-4b38c22c00ea24a9b47c9f81da0e2ea8c1731e69.tar.bz2
strongswan-4b38c22c00ea24a9b47c9f81da0e2ea8c1731e69.tar.xz
Schedule a DPD timeout job that enforces the IKE message timeout policy
Diffstat (limited to 'src/libcharon/processing/jobs/dpd_timeout_job.c')
-rw-r--r--src/libcharon/processing/jobs/dpd_timeout_job.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/src/libcharon/processing/jobs/dpd_timeout_job.c b/src/libcharon/processing/jobs/dpd_timeout_job.c
new file mode 100644
index 000000000..8dc458ff6
--- /dev/null
+++ b/src/libcharon/processing/jobs/dpd_timeout_job.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2012 Martin Willi
+ * Copyright (C) 2012 revosec AG
+ *
+ * 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 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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.
+ */
+
+#include <stdlib.h>
+
+#include "dpd_timeout_job.h"
+
+#include <sa/ike_sa.h>
+#include <daemon.h>
+
+
+typedef struct private_dpd_timeout_job_t private_dpd_timeout_job_t;
+
+/**
+ * Private data
+ */
+struct private_dpd_timeout_job_t {
+
+ /**
+ * public dpd_timeout_job_t interface
+ */
+ dpd_timeout_job_t public;
+
+ /**
+ * IKE_SA identifier
+ */
+ ike_sa_id_t *ike_sa_id;
+
+ /**
+ * Timestamp of first DPD check
+ */
+ u_int32_t check;
+};
+
+METHOD(job_t, destroy, void,
+ private_dpd_timeout_job_t *this)
+{
+ this->ike_sa_id->destroy(this->ike_sa_id);
+ free(this);
+}
+
+METHOD(job_t, execute, void,
+ private_dpd_timeout_job_t *this)
+{
+ ike_sa_t *ike_sa;
+
+ ike_sa = charon->ike_sa_manager->checkout(charon->ike_sa_manager,
+ this->ike_sa_id);
+ if (ike_sa)
+ {
+ /* check if no incoming packet during timeout, reestalish SA */
+ if (ike_sa->get_statistic(ike_sa, STAT_INBOUND) < this->check)
+ {
+ DBG1(DBG_JOB, "DPD check timed out, enforcing DPD action");
+ if (ike_sa->reestablish(ike_sa) == SUCCESS)
+ {
+ charon->ike_sa_manager->checkin_and_destroy(
+ charon->ike_sa_manager, ike_sa);
+ }
+ else
+ {
+ charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
+ }
+ }
+ else
+ {
+ charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
+ }
+ }
+ destroy(this);
+}
+
+METHOD(job_t, get_priority, job_priority_t,
+ private_dpd_timeout_job_t *this)
+{
+ return JOB_PRIO_HIGH;
+}
+
+/*
+ * Described in header
+ */
+dpd_timeout_job_t *dpd_timeout_job_create(ike_sa_id_t *ike_sa_id)
+{
+ private_dpd_timeout_job_t *this;
+
+ INIT(this,
+ .public = {
+ .job_interface = {
+ .execute = _execute,
+ .get_priority = _get_priority,
+ .destroy = _destroy,
+ },
+ },
+ .ike_sa_id = ike_sa_id->clone(ike_sa_id),
+ .check = time_monotonic(NULL),
+ );
+
+ return &this->public;
+}