ike: Maintain per-IKE_SA CHILD_SAs in the global CHILD_SA manager
[strongswan.git] / src / libcharon / processing / jobs / rekey_child_sa_job.c
1 /*
2 * Copyright (C) 2006 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
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>.
9 *
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
13 * for more details.
14 */
15
16 #include "rekey_child_sa_job.h"
17
18 #include <daemon.h>
19
20
21 typedef struct private_rekey_child_sa_job_t private_rekey_child_sa_job_t;
22
23 /**
24 * Private data of an rekey_child_sa_job_t object.
25 */
26 struct private_rekey_child_sa_job_t {
27 /**
28 * Public rekey_child_sa_job_t interface.
29 */
30 rekey_child_sa_job_t public;
31
32 /**
33 * reqid of the child to rekey
34 */
35 u_int32_t reqid;
36
37 /**
38 * protocol of the CHILD_SA (ESP/AH)
39 */
40 protocol_id_t protocol;
41
42 /**
43 * inbound SPI of the CHILD_SA
44 */
45 u_int32_t spi;
46 };
47
48 METHOD(job_t, destroy, void,
49 private_rekey_child_sa_job_t *this)
50 {
51 free(this);
52 }
53
54 METHOD(job_t, execute, job_requeue_t,
55 private_rekey_child_sa_job_t *this)
56 {
57 ike_sa_t *ike_sa;
58
59 ike_sa = charon->ike_sa_manager->checkout_by_id(charon->ike_sa_manager,
60 this->reqid, TRUE);
61 if (ike_sa == NULL)
62 {
63 DBG2(DBG_JOB, "CHILD_SA with reqid %d not found for rekeying",
64 this->reqid);
65 }
66 else
67 {
68 ike_sa->rekey_child_sa(ike_sa, this->protocol, this->spi);
69 charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
70 }
71 return JOB_REQUEUE_NONE;
72 }
73
74 METHOD(job_t, get_priority, job_priority_t,
75 private_rekey_child_sa_job_t *this)
76 {
77 return JOB_PRIO_MEDIUM;
78 }
79
80 /*
81 * Described in header
82 */
83 rekey_child_sa_job_t *rekey_child_sa_job_create(u_int32_t reqid,
84 protocol_id_t protocol,
85 u_int32_t spi)
86 {
87 private_rekey_child_sa_job_t *this;
88
89 INIT(this,
90 .public = {
91 .job_interface = {
92 .execute = _execute,
93 .get_priority = _get_priority,
94 .destroy = _destroy,
95 },
96 },
97 .reqid = reqid,
98 .protocol = protocol,
99 .spi = spi,
100 );
101
102 return &this->public;
103 }