Introduce priority classes for jobs
[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 METHOD(job_t, destroy, void,
43 private_rekey_ike_sa_job_t *this)
44 {
45 this->ike_sa_id->destroy(this->ike_sa_id);
46 free(this);
47 }
48
49 METHOD(job_t, execute, void,
50 private_rekey_ike_sa_job_t *this)
51 {
52 ike_sa_t *ike_sa;
53 status_t status = SUCCESS;
54
55 ike_sa = charon->ike_sa_manager->checkout(charon->ike_sa_manager,
56 this->ike_sa_id);
57 if (ike_sa == NULL)
58 {
59 DBG2(DBG_JOB, "IKE_SA to rekey not found");
60 }
61 else
62 {
63 if (this->reauth)
64 {
65 status = ike_sa->reauth(ike_sa);
66 }
67 else
68 {
69 status = ike_sa->rekey(ike_sa);
70 }
71
72 if (status == DESTROY_ME)
73 {
74 charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager, ike_sa);
75 }
76 else
77 {
78 charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
79 }
80 }
81 destroy(this);
82 }
83
84 METHOD(job_t, get_priority, job_priority_t,
85 private_rekey_ike_sa_job_t *this)
86 {
87 return JOB_PRIO_MEDIUM;
88 }
89
90 /*
91 * Described in header
92 */
93 rekey_ike_sa_job_t *rekey_ike_sa_job_create(ike_sa_id_t *ike_sa_id, bool reauth)
94 {
95 private_rekey_ike_sa_job_t *this;
96
97 INIT(this,
98 .public = {
99 .job_interface = {
100 .execute = _execute,
101 .get_priority = _get_priority,
102 .destroy = _destroy,
103 },
104 },
105 .ike_sa_id = ike_sa_id->clone(ike_sa_id),
106 .reauth = reauth,
107 );
108
109 return &(this->public);
110 }