]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/charon/sa/tasks/ike_delete.c
restructured file layout
[thirdparty/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 DBG1(DBG_IKE, "initiated rekeying, but received delete for IKE_SA");
98 break;
99 default:
100 break;
101 }
102 this->ike_sa->set_state(this->ike_sa, IKE_DELETING);
103 return NEED_MORE;
104 }
105
106 /**
107 * Implementation of task_t.build for responder
108 */
109 static status_t build_r(private_ike_delete_t *this, message_t *message)
110 {
111 if (this->simultaneous)
112 {
113 /* wait for peers response for our delete request, but set a timeout */
114 return SUCCESS;
115 }
116 /* completed, delete IKE_SA by returning FAILED */
117 return FAILED;
118 }
119
120 /**
121 * Implementation of task_t.get_type
122 */
123 static task_type_t get_type(private_ike_delete_t *this)
124 {
125 return IKE_DELETE;
126 }
127
128 /**
129 * Implementation of task_t.migrate
130 */
131 static void migrate(private_ike_delete_t *this, ike_sa_t *ike_sa)
132 {
133 this->ike_sa = ike_sa;
134 this->simultaneous = FALSE;
135 }
136
137 /**
138 * Implementation of task_t.destroy
139 */
140 static void destroy(private_ike_delete_t *this)
141 {
142 free(this);
143 }
144
145 /*
146 * Described in header.
147 */
148 ike_delete_t *ike_delete_create(ike_sa_t *ike_sa, bool initiator)
149 {
150 private_ike_delete_t *this = malloc_thing(private_ike_delete_t);
151
152 this->public.task.get_type = (task_type_t(*)(task_t*))get_type;
153 this->public.task.migrate = (void(*)(task_t*,ike_sa_t*))migrate;
154 this->public.task.destroy = (void(*)(task_t*))destroy;
155
156 if (initiator)
157 {
158 this->public.task.build = (status_t(*)(task_t*,message_t*))build_i;
159 this->public.task.process = (status_t(*)(task_t*,message_t*))process_i;
160 }
161 else
162 {
163 this->public.task.build = (status_t(*)(task_t*,message_t*))build_r;
164 this->public.task.process = (status_t(*)(task_t*,message_t*))process_r;
165 }
166
167 this->ike_sa = ike_sa;
168 this->initiator = initiator;
169 this->simultaneous = FALSE;
170
171 return &this->public;
172 }