]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/charon/processing/jobs/rekey_ike_sa_job.c
adapt evaltest to changed debug output
[thirdparty/strongswan.git] / src / charon / processing / jobs / rekey_ike_sa_job.c
1 /**
2 * @file rekey_ike_sa_job.c
3 *
4 * @brief Implementation of rekey_ike_sa_job_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2006 Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #include "rekey_ike_sa_job.h"
24
25 #include <daemon.h>
26
27
28 typedef struct private_rekey_ike_sa_job_t private_rekey_ike_sa_job_t;
29
30 /**
31 * Private data of an rekey_ike_sa_job_t object.
32 */
33 struct private_rekey_ike_sa_job_t {
34 /**
35 * Public rekey_ike_sa_job_t interface.
36 */
37 rekey_ike_sa_job_t public;
38
39 /**
40 * ID of the IKE_SA to rekey
41 */
42 ike_sa_id_t *ike_sa_id;
43
44 /**
45 * force reauthentication of the peer (full IKE_SA setup)
46 */
47 bool reauth;
48 };
49
50 /**
51 * Implementation of job_t.get_type.
52 */
53 static job_type_t get_type(private_rekey_ike_sa_job_t *this)
54 {
55 return REKEY_IKE_SA;
56 }
57
58 /**
59 * Implementation of job_t.execute.
60 */
61 static status_t execute(private_rekey_ike_sa_job_t *this)
62 {
63 ike_sa_t *ike_sa;
64 status_t status = SUCCESS;
65
66 ike_sa = charon->ike_sa_manager->checkout(charon->ike_sa_manager,
67 this->ike_sa_id);
68 if (ike_sa == NULL)
69 {
70 DBG2(DBG_JOB, "IKE_SA %J to rekey not found", this->ike_sa_id);
71 return DESTROY_ME;
72 }
73
74 if (this->reauth)
75 {
76 ike_sa->reestablish(ike_sa);
77 }
78 else
79 {
80 status = ike_sa->rekey(ike_sa);
81 }
82
83 if (status == DESTROY_ME)
84 {
85 charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager, ike_sa);
86 }
87 else
88 {
89 charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
90 }
91 return DESTROY_ME;
92 }
93
94 /**
95 * Implementation of job_t.destroy.
96 */
97 static void destroy(private_rekey_ike_sa_job_t *this)
98 {
99 this->ike_sa_id->destroy(this->ike_sa_id);
100 free(this);
101 }
102
103 /*
104 * Described in header
105 */
106 rekey_ike_sa_job_t *rekey_ike_sa_job_create(ike_sa_id_t *ike_sa_id, bool reauth)
107 {
108 private_rekey_ike_sa_job_t *this = malloc_thing(private_rekey_ike_sa_job_t);
109
110 /* interface functions */
111 this->public.job_interface.get_type = (job_type_t (*) (job_t *)) get_type;
112 this->public.job_interface.execute = (status_t (*) (job_t *)) execute;
113 this->public.job_interface.destroy = (void (*)(job_t*)) destroy;
114
115 /* private variables */
116 this->ike_sa_id = ike_sa_id->clone(ike_sa_id);
117 this->reauth = reauth;
118
119 return &(this->public);
120 }