2 * Copyright (C) 2011 Martin Willi
3 * Copyright (C) 2011 revosec AG
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>.
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
16 #include "informational.h"
19 #include <sa/ikev1/tasks/isakmp_delete.h>
20 #include <sa/ikev1/tasks/quick_delete.h>
21 #include <encoding/payloads/delete_payload.h>
23 typedef struct private_informational_t private_informational_t
;
26 * Private members of a informational_t task.
28 struct private_informational_t
{
31 * Public methods and task_t interface.
33 informational_t
public;
41 * Notify payload to send
43 notify_payload_t
*notify
;
51 METHOD(task_t
, build_i
, status_t
,
52 private_informational_t
*this, message_t
*message
)
54 message
->add_payload(message
, &this->notify
->payload_interface
);
59 METHOD(task_t
, process_r
, status_t
,
60 private_informational_t
*this, message_t
*message
)
62 enumerator_t
*enumerator
;
63 delete_payload_t
*delete;
64 notify_payload_t
*notify
;
67 status_t status
= SUCCESS
;
69 enumerator
= message
->create_payload_enumerator(message
);
70 while (enumerator
->enumerate(enumerator
, &payload
))
72 switch (payload
->get_type(payload
))
75 notify
= (notify_payload_t
*)payload
;
76 type
= notify
->get_notify_type(notify
);
78 if (type
== INITIAL_CONTACT_IKEV1
)
80 this->ike_sa
->set_condition(this->ike_sa
,
81 COND_INIT_CONTACT_SEEN
, TRUE
);
83 else if (type
< 16384)
85 DBG1(DBG_IKE
, "received %N error notify",
86 notify_type_names
, notify
->get_notify_type(notify
));
87 if (this->ike_sa
->get_state(this->ike_sa
) == IKE_CONNECTING
)
88 { /* only critical during main mode */
95 DBG1(DBG_IKE
, "received %N notify",
96 notify_type_names
, notify
->get_notify_type(notify
));
102 delete = (delete_payload_t
*)payload
;
103 if (delete->get_protocol_id(delete) == PROTO_IKE
)
105 this->del
= (task_t
*)isakmp_delete_create(this->ike_sa
,
110 this->del
= (task_t
*)quick_delete_create(this->ike_sa
,
111 PROTO_NONE
, 0, FALSE
);
120 enumerator
->destroy(enumerator
);
122 if (this->del
&& status
== SUCCESS
)
124 return this->del
->process(this->del
, message
);
129 METHOD(task_t
, build_r
, status_t
,
130 private_informational_t
*this, message_t
*message
)
134 return this->del
->build(this->del
, message
);
139 METHOD(task_t
, process_i
, status_t
,
140 private_informational_t
*this, message_t
*message
)
145 METHOD(task_t
, get_type
, task_type_t
,
146 private_informational_t
*this)
148 return TASK_INFORMATIONAL
;
151 METHOD(task_t
, migrate
, void,
152 private_informational_t
*this, ike_sa_t
*ike_sa
)
154 this->ike_sa
= ike_sa
;
157 METHOD(task_t
, destroy
, void,
158 private_informational_t
*this)
160 DESTROY_IF(this->notify
);
161 DESTROY_IF(this->del
);
166 * Described in header.
168 informational_t
*informational_create(ike_sa_t
*ike_sa
, notify_payload_t
*notify
)
170 private_informational_t
*this;
175 .get_type
= _get_type
,
186 this->public.task
.build
= _build_i
;
187 this->public.task
.process
= _process_i
;
191 this->public.task
.build
= _build_r
;
192 this->public.task
.process
= _process_r
;
195 return &this->public;