2 * Copyright (C) 2010 Martin Willi
3 * Hochschule fuer Technik Rapperswil
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
16 #include "inactivity_job.h"
20 typedef struct private_inactivity_job_t private_inactivity_job_t
;
23 * Private data of an inactivity_job_t object.
25 struct private_inactivity_job_t
{
28 * Public inactivity_job_t interface.
30 inactivity_job_t
public;
33 * Reqid of CHILD_SA to check
43 * Close IKE_SA if last remaining CHILD inactive?
48 METHOD(job_t
, destroy
, void,
49 private_inactivity_job_t
*this)
54 METHOD(job_t
, execute
, void,
55 private_inactivity_job_t
*this)
58 bool rescheduled
= FALSE
;
60 ike_sa
= charon
->ike_sa_manager
->checkout_by_id(charon
->ike_sa_manager
,
67 protocol_id_t proto
= 0;
69 status_t status
= SUCCESS
;
71 iterator
= ike_sa
->create_child_sa_iterator(ike_sa
);
72 while (iterator
->iterate(iterator
, (void**)&child_sa
))
74 if (child_sa
->get_reqid(child_sa
) == this->reqid
)
78 child_sa
->get_usestats(child_sa
, TRUE
, &in
, NULL
);
79 child_sa
->get_usestats(child_sa
, FALSE
, &out
, NULL
);
81 diff
= time_monotonic(NULL
) - max(in
, out
);
83 if (diff
>= this->timeout
)
85 delete = child_sa
->get_spi(child_sa
, TRUE
);
86 proto
= child_sa
->get_protocol(child_sa
);
90 lib
->scheduler
->schedule_job(lib
->scheduler
,
91 &this->public.job_interface
, this->timeout
- diff
);
97 iterator
->destroy(iterator
);
101 if (children
== 1 && this->close_ike
)
103 DBG1(DBG_JOB
, "deleting IKE_SA after %d seconds "
104 "of CHILD_SA inactivity", this->timeout
);
105 status
= ike_sa
->delete(ike_sa
);
109 DBG1(DBG_JOB
, "deleting CHILD_SA after %d seconds "
110 "of inactivity", this->timeout
);
111 status
= ike_sa
->delete_child_sa(ike_sa
, proto
, delete);
114 if (status
== DESTROY_ME
)
116 charon
->ike_sa_manager
->checkin_and_destroy(charon
->ike_sa_manager
,
121 charon
->ike_sa_manager
->checkin(charon
->ike_sa_manager
, ike_sa
);
133 inactivity_job_t
*inactivity_job_create(u_int32_t reqid
, u_int32_t timeout
,
136 private_inactivity_job_t
*this;
147 .close_ike
= close_ike
,
150 return &this->public;