Moving charon to libcharon.
[strongswan.git] / src / libcharon / processing / jobs / rekey_ike_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_ike_sa_job.h"
17
18 #include <daemon.h>
19
20 typedef struct private_rekey_ike_sa_job_t private_rekey_ike_sa_job_t;
21
22 /**
23 * Private data of an rekey_ike_sa_job_t object.
24 */
25 struct private_rekey_ike_sa_job_t {
26 /**
27 * Public rekey_ike_sa_job_t interface.
28 */
29 rekey_ike_sa_job_t public;
30
31 /**
32 * ID of the IKE_SA to rekey
33 */
34 ike_sa_id_t *ike_sa_id;
35
36 /**
37 * force reauthentication of the peer (full IKE_SA setup)
38 */
39 bool reauth;
40 };
41
42 /**
43 * Implementation of job_t.destroy.
44 */
45 static void destroy(private_rekey_ike_sa_job_t *this)
46 {
47 this->ike_sa_id->destroy(this->ike_sa_id);
48 free(this);
49 }
50
51 /**
52 * Implementation of job_t.execute.
53 */
54 static void execute(private_rekey_ike_sa_job_t *this)
55 {
56 ike_sa_t *ike_sa;
57 status_t status = SUCCESS;
58
59 ike_sa = charon->ike_sa_manager->checkout(charon->ike_sa_manager,
60 this->ike_sa_id);
61 if (ike_sa == NULL)
62 {
63 DBG2(DBG_JOB, "IKE_SA to rekey not found");
64 }
65 else
66 {
67 if (this->reauth)
68 {
69 status = ike_sa->reauth(ike_sa);
70 }
71 else
72 {
73 status = ike_sa->rekey(ike_sa);
74 }
75
76 if (status == DESTROY_ME)
77 {
78 charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager, ike_sa);
79 }
80 else
81 {
82 charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
83 }
84 }
85 destroy(this);
86 }
87
88 /*
89 * Described in header
90 */
91 rekey_ike_sa_job_t *rekey_ike_sa_job_create(ike_sa_id_t *ike_sa_id, bool reauth)
92 {
93 private_rekey_ike_sa_job_t *this = malloc_thing(private_rekey_ike_sa_job_t);
94
95 /* interface functions */
96 this->public.job_interface.execute = (void (*) (job_t *)) execute;
97 this->public.job_interface.destroy = (void (*)(job_t*)) destroy;
98
99 /* private variables */
100 this->ike_sa_id = ike_sa_id->clone(ike_sa_id);
101 this->reauth = reauth;
102
103 return &(this->public);
104 }