4 * @brief Implementation of the ike_delete task.
9 * Copyright (C) 2006-2007 Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
23 #include "ike_delete.h"
26 #include <encoding/payloads/delete_payload.h>
29 typedef struct private_ike_delete_t private_ike_delete_t
;
32 * Private members of a ike_delete_t task.
34 struct private_ike_delete_t
{
37 * Public methods and task_t interface.
47 * Are we the initiator?
52 * are we responding to a delete, but have initated our own?
58 * Implementation of task_t.build for initiator
60 static status_t
build_i(private_ike_delete_t
*this, message_t
*message
)
62 delete_payload_t
*delete_payload
;
64 delete_payload
= delete_payload_create(PROTO_IKE
);
65 message
->add_payload(message
, (payload_t
*)delete_payload
);
67 this->ike_sa
->set_state(this->ike_sa
, IKE_DELETING
);
73 * Implementation of task_t.process for initiator
75 static status_t
process_i(private_ike_delete_t
*this, message_t
*message
)
77 /* completed, delete IKE_SA by returning FAILED */
82 * Implementation of task_t.process for initiator
84 static status_t
process_r(private_ike_delete_t
*this, message_t
*message
)
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
))
91 this->simultaneous
= TRUE
;
94 DBG1(DBG_IKE
, "deleting IKE_SA on request");
97 DBG1(DBG_IKE
, "initiated rekeying, but received delete for IKE_SA");
102 this->ike_sa
->set_state(this->ike_sa
, IKE_DELETING
);
107 * Implementation of task_t.build for responder
109 static status_t
build_r(private_ike_delete_t
*this, message_t
*message
)
111 if (this->simultaneous
)
113 /* wait for peers response for our delete request, but set a timeout */
116 /* completed, delete IKE_SA by returning FAILED */
121 * Implementation of task_t.get_type
123 static task_type_t
get_type(private_ike_delete_t
*this)
129 * Implementation of task_t.migrate
131 static void migrate(private_ike_delete_t
*this, ike_sa_t
*ike_sa
)
133 this->ike_sa
= ike_sa
;
134 this->simultaneous
= FALSE
;
138 * Implementation of task_t.destroy
140 static void destroy(private_ike_delete_t
*this)
146 * Described in header.
148 ike_delete_t
*ike_delete_create(ike_sa_t
*ike_sa
, bool initiator
)
150 private_ike_delete_t
*this = malloc_thing(private_ike_delete_t
);
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
;
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
;
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
;
167 this->ike_sa
= ike_sa
;
168 this->initiator
= initiator
;
169 this->simultaneous
= FALSE
;
171 return &this->public;