removed misleading warning when rekeying
[strongswan.git] / src / charon / sa / tasks / ike_delete.c
1 /**
2 * @file ike_delete.c
3 *
4 * @brief Implementation of the ike_delete task.
5 *
6 */
7
8 /*
9 * Copyright (C) 2006-2007 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 "ike_delete.h"
24
25 #include <daemon.h>
26 #include <encoding/payloads/delete_payload.h>
27
28
29 typedef struct private_ike_delete_t private_ike_delete_t;
30
31 /**file
32 * Private members of a ike_delete_t task.
33 */
34 struct private_ike_delete_t {
35
36 /**
37 * Public methods and task_t interface.
38 */
39 ike_delete_t public;
40
41 /**
42 * Assigned IKE_SA.
43 */
44 ike_sa_t *ike_sa;
45
46 /**
47 * Are we the initiator?
48 */
49 bool initiator;
50
51 /**
52 * are we responding to a delete, but have initated our own?
53 */
54 bool simultaneous;
55 };
56
57 /**
58 * Implementation of task_t.build for initiator
59 */
60 static status_t build_i(private_ike_delete_t *this, message_t *message)
61 {
62 delete_payload_t *delete_payload;
63
64 delete_payload = delete_payload_create(PROTO_IKE);
65 message->add_payload(message, (payload_t*)delete_payload);
66
67 this->ike_sa->set_state(this->ike_sa, IKE_DELETING);
68
69 return NEED_MORE;
70 }
71
72 /**
73 * Implementation of task_t.process for initiator
74 */
75 static status_t process_i(private_ike_delete_t *this, message_t *message)
76 {
77 /* completed, delete IKE_SA by returning FAILED */
78 return FAILED;
79 }
80
81 /**
82 * Implementation of task_t.process for initiator
83 */
84 static status_t process_r(private_ike_delete_t *this, message_t *message)
85 {
86 /* we don't even scan the payloads, as the message wouldn't have
87 * come so far without being correct */
88 switch (this->ike_sa->get_state(this->ike_sa))
89 {
90 case IKE_DELETING:
91 this->simultaneous = TRUE;
92 break;
93 case IKE_ESTABLISHED:
94 DBG1(DBG_IKE, "deleting IKE_SA on request");
95 break;
96 case IKE_REKEYING:
97 break;
98 default:
99 break;
100 }
101 this->ike_sa->set_state(this->ike_sa, IKE_DELETING);
102 return NEED_MORE;
103 }
104
105 /**
106 * Implementation of task_t.build for responder
107 */
108 static status_t build_r(private_ike_delete_t *this, message_t *message)
109 {
110 if (this->simultaneous)
111 {
112 /* wait for peers response for our delete request, but set a timeout */
113 return SUCCESS;
114 }
115 /* completed, delete IKE_SA by returning FAILED */
116 return FAILED;
117 }
118
119 /**
120 * Implementation of task_t.get_type
121 */
122 static task_type_t get_type(private_ike_delete_t *this)
123 {
124 return IKE_DELETE;
125 }
126
127 /**
128 * Implementation of task_t.migrate
129 */
130 static void migrate(private_ike_delete_t *this, ike_sa_t *ike_sa)
131 {
132 this->ike_sa = ike_sa;
133 this->simultaneous = FALSE;
134 }
135
136 /**
137 * Implementation of task_t.destroy
138 */
139 static void destroy(private_ike_delete_t *this)
140 {
141 free(this);
142 }
143
144 /*
145 * Described in header.
146 */
147 ike_delete_t *ike_delete_create(ike_sa_t *ike_sa, bool initiator)
148 {
149 private_ike_delete_t *this = malloc_thing(private_ike_delete_t);
150
151 this->public.task.get_type = (task_type_t(*)(task_t*))get_type;
152 this->public.task.migrate = (void(*)(task_t*,ike_sa_t*))migrate;
153 this->public.task.destroy = (void(*)(task_t*))destroy;
154
155 if (initiator)
156 {
157 this->public.task.build = (status_t(*)(task_t*,message_t*))build_i;
158 this->public.task.process = (status_t(*)(task_t*,message_t*))process_i;
159 }
160 else
161 {
162 this->public.task.build = (status_t(*)(task_t*,message_t*))build_r;
163 this->public.task.process = (status_t(*)(task_t*,message_t*))process_r;
164 }
165
166 this->ike_sa = ike_sa;
167 this->initiator = initiator;
168 this->simultaneous = FALSE;
169
170 return &this->public;
171 }