2 * Copyright (C) 2012 Martin Willi
3 * Copyright (C) 2012 revosec AG
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 #include "dpd_timeout_job.h"
20 #include <sa/ike_sa.h>
24 typedef struct private_dpd_timeout_job_t private_dpd_timeout_job_t
;
29 struct private_dpd_timeout_job_t
{
32 * public dpd_timeout_job_t interface
34 dpd_timeout_job_t
public;
39 ike_sa_id_t
*ike_sa_id
;
42 * Timestamp of first DPD check
47 METHOD(job_t
, destroy
, void,
48 private_dpd_timeout_job_t
*this)
50 this->ike_sa_id
->destroy(this->ike_sa_id
);
54 METHOD(job_t
, execute
, job_requeue_t
,
55 private_dpd_timeout_job_t
*this)
57 time_t use_time
, current
;
58 enumerator_t
*enumerator
;
62 ike_sa
= charon
->ike_sa_manager
->checkout(charon
->ike_sa_manager
,
66 if (ike_sa
->get_state(ike_sa
) == IKE_PASSIVE
)
68 charon
->ike_sa_manager
->checkin(charon
->ike_sa_manager
, ike_sa
);
69 return JOB_REQUEUE_NONE
;
72 use_time
= ike_sa
->get_statistic(ike_sa
, STAT_INBOUND
);
74 enumerator
= ike_sa
->create_child_sa_enumerator(ike_sa
);
75 while (enumerator
->enumerate(enumerator
, &child_sa
))
77 child_sa
->get_usestats(child_sa
, TRUE
, ¤t
, NULL
, NULL
);
78 use_time
= max(use_time
, current
);
80 enumerator
->destroy(enumerator
);
82 /* check if no incoming packet during timeout, reestablish SA */
83 if (use_time
< this->check
)
85 DBG1(DBG_JOB
, "DPD check timed out, enforcing DPD action");
86 charon
->bus
->alert(charon
->bus
, ALERT_RETRANSMIT_SEND_TIMEOUT
, NULL
);
87 charon
->bus
->ike_updown(charon
->bus
, ike_sa
, FALSE
);
88 ike_sa
->reestablish(ike_sa
);
89 charon
->ike_sa_manager
->checkin_and_destroy(charon
->ike_sa_manager
,
94 charon
->ike_sa_manager
->checkin(charon
->ike_sa_manager
, ike_sa
);
97 return JOB_REQUEUE_NONE
;
100 METHOD(job_t
, get_priority
, job_priority_t
,
101 private_dpd_timeout_job_t
*this)
103 return JOB_PRIO_HIGH
;
107 * Described in header
109 dpd_timeout_job_t
*dpd_timeout_job_create(ike_sa_id_t
*ike_sa_id
)
111 private_dpd_timeout_job_t
*this;
117 .get_priority
= _get_priority
,
121 .ike_sa_id
= ike_sa_id
->clone(ike_sa_id
),
122 .check
= time_monotonic(NULL
),
125 return &this->public;