2 * Copyright (C) 2015 Tobias Brunner
3 * HSR Hochschule fuer Technik Rapperswil
5 * Copyright (C) 2011 Martin Willi
6 * Copyright (C) 2011 revosec AG
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 #include "isakmp_delete.h"
22 #include <encoding/payloads/delete_payload.h>
24 typedef struct private_isakmp_delete_t private_isakmp_delete_t
;
27 * Private members of a isakmp_delete_t task.
29 struct private_isakmp_delete_t
{
32 * Public methods and task_t interface.
34 isakmp_delete_t
public;
42 METHOD(task_t
, build_i
, status_t
,
43 private_isakmp_delete_t
*this, message_t
*message
)
45 delete_payload_t
*delete_payload
;
48 DBG0(DBG_IKE
, "deleting IKE_SA %s[%d] between %H[%Y]...%H[%Y]",
49 this->ike_sa
->get_name(this->ike_sa
),
50 this->ike_sa
->get_unique_id(this->ike_sa
),
51 this->ike_sa
->get_my_host(this->ike_sa
),
52 this->ike_sa
->get_my_id(this->ike_sa
),
53 this->ike_sa
->get_other_host(this->ike_sa
),
54 this->ike_sa
->get_other_id(this->ike_sa
));
56 delete_payload
= delete_payload_create(PLV1_DELETE
, PROTO_IKE
);
57 id
= this->ike_sa
->get_id(this->ike_sa
);
58 delete_payload
->set_ike_spi(delete_payload
, id
->get_initiator_spi(id
),
59 id
->get_responder_spi(id
));
60 message
->add_payload(message
, (payload_t
*)delete_payload
);
62 DBG1(DBG_IKE
, "sending DELETE for IKE_SA %s[%d]",
63 this->ike_sa
->get_name(this->ike_sa
),
64 this->ike_sa
->get_unique_id(this->ike_sa
));
66 this->ike_sa
->set_state(this->ike_sa
, IKE_DELETING
);
67 charon
->bus
->ike_updown(charon
->bus
, this->ike_sa
, FALSE
);
71 METHOD(task_t
, process_i
, status_t
,
72 private_isakmp_delete_t
*this, message_t
*message
)
77 METHOD(task_t
, process_r
, status_t
,
78 private_isakmp_delete_t
*this, message_t
*message
)
80 enumerator_t
*payloads
;
82 delete_payload_t
*delete_payload
;
84 uint64_t spi_i
, spi_r
;
87 /* some peers send DELETE payloads for other IKE_SAs, e.g. those for expired
88 * ones after a rekeying, make sure the SPIs match */
89 id
= this->ike_sa
->get_id(this->ike_sa
);
90 payloads
= message
->create_payload_enumerator(message
);
91 while (payloads
->enumerate(payloads
, &payload
))
93 if (payload
->get_type(payload
) == PLV1_DELETE
)
95 delete_payload
= (delete_payload_t
*)payload
;
96 if (!delete_payload
->get_ike_spi(delete_payload
, &spi_i
, &spi_r
))
100 if (id
->get_initiator_spi(id
) == spi_i
&&
101 id
->get_responder_spi(id
) == spi_r
)
108 payloads
->destroy(payloads
);
112 DBG1(DBG_IKE
, "received DELETE for different IKE_SA, ignored");
116 DBG1(DBG_IKE
, "received DELETE for IKE_SA %s[%d]",
117 this->ike_sa
->get_name(this->ike_sa
),
118 this->ike_sa
->get_unique_id(this->ike_sa
));
119 DBG0(DBG_IKE
, "deleting IKE_SA %s[%d] between %H[%Y]...%H[%Y]",
120 this->ike_sa
->get_name(this->ike_sa
),
121 this->ike_sa
->get_unique_id(this->ike_sa
),
122 this->ike_sa
->get_my_host(this->ike_sa
),
123 this->ike_sa
->get_my_id(this->ike_sa
),
124 this->ike_sa
->get_other_host(this->ike_sa
),
125 this->ike_sa
->get_other_id(this->ike_sa
));
127 if (this->ike_sa
->get_state(this->ike_sa
) == IKE_ESTABLISHED
)
129 this->ike_sa
->set_state(this->ike_sa
, IKE_DELETING
);
130 this->ike_sa
->reestablish(this->ike_sa
);
132 this->ike_sa
->set_state(this->ike_sa
, IKE_DELETING
);
133 charon
->bus
->ike_updown(charon
->bus
, this->ike_sa
, FALSE
);
137 METHOD(task_t
, build_r
, status_t
,
138 private_isakmp_delete_t
*this, message_t
*message
)
143 METHOD(task_t
, get_type
, task_type_t
,
144 private_isakmp_delete_t
*this)
146 return TASK_ISAKMP_DELETE
;
149 METHOD(task_t
, migrate
, void,
150 private_isakmp_delete_t
*this, ike_sa_t
*ike_sa
)
152 this->ike_sa
= ike_sa
;
155 METHOD(task_t
, destroy
, void,
156 private_isakmp_delete_t
*this)
162 * Described in header.
164 isakmp_delete_t
*isakmp_delete_create(ike_sa_t
*ike_sa
, bool initiator
)
166 private_isakmp_delete_t
*this;
171 .get_type
= _get_type
,
181 this->public.task
.build
= _build_i
;
182 this->public.task
.process
= _process_i
;
186 this->public.task
.build
= _build_r
;
187 this->public.task
.process
= _process_r
;
190 return &this->public;