Send EAP-Nak with supported types if requested type is unsupported
[strongswan.git] / src / libcharon / sa / ikev2 / task_manager_v2.c
1 /*
2 * Copyright (C) 2007-2011 Tobias Brunner
3 * Copyright (C) 2007-2010 Martin Willi
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #include "task_manager_v2.h"
18
19 #include <math.h>
20
21 #include <daemon.h>
22 #include <sa/ikev2/tasks/ike_init.h>
23 #include <sa/ikev2/tasks/ike_natd.h>
24 #include <sa/ikev2/tasks/ike_mobike.h>
25 #include <sa/ikev2/tasks/ike_auth.h>
26 #include <sa/ikev2/tasks/ike_auth_lifetime.h>
27 #include <sa/ikev2/tasks/ike_cert_pre.h>
28 #include <sa/ikev2/tasks/ike_cert_post.h>
29 #include <sa/ikev2/tasks/ike_rekey.h>
30 #include <sa/ikev2/tasks/ike_reauth.h>
31 #include <sa/ikev2/tasks/ike_delete.h>
32 #include <sa/ikev2/tasks/ike_config.h>
33 #include <sa/ikev2/tasks/ike_dpd.h>
34 #include <sa/ikev2/tasks/ike_vendor.h>
35 #include <sa/ikev2/tasks/child_create.h>
36 #include <sa/ikev2/tasks/child_rekey.h>
37 #include <sa/ikev2/tasks/child_delete.h>
38 #include <encoding/payloads/delete_payload.h>
39 #include <encoding/payloads/unknown_payload.h>
40 #include <processing/jobs/retransmit_job.h>
41 #include <processing/jobs/delete_ike_sa_job.h>
42
43 #ifdef ME
44 #include <sa/ikev2/tasks/ike_me.h>
45 #endif
46
47 typedef struct exchange_t exchange_t;
48
49 /**
50 * An exchange in the air, used do detect and handle retransmission
51 */
52 struct exchange_t {
53
54 /**
55 * Message ID used for this transaction
56 */
57 u_int32_t mid;
58
59 /**
60 * generated packet for retransmission
61 */
62 packet_t *packet;
63 };
64
65 typedef struct private_task_manager_t private_task_manager_t;
66
67 /**
68 * private data of the task manager
69 */
70 struct private_task_manager_t {
71
72 /**
73 * public functions
74 */
75 task_manager_v2_t public;
76
77 /**
78 * associated IKE_SA we are serving
79 */
80 ike_sa_t *ike_sa;
81
82 /**
83 * Exchange we are currently handling as responder
84 */
85 struct {
86 /**
87 * Message ID of the exchange
88 */
89 u_int32_t mid;
90
91 /**
92 * packet for retransmission
93 */
94 packet_t *packet;
95
96 } responding;
97
98 /**
99 * Exchange we are currently handling as initiator
100 */
101 struct {
102 /**
103 * Message ID of the exchange
104 */
105 u_int32_t mid;
106
107 /**
108 * how many times we have retransmitted so far
109 */
110 u_int retransmitted;
111
112 /**
113 * packet for retransmission
114 */
115 packet_t *packet;
116
117 /**
118 * type of the initated exchange
119 */
120 exchange_type_t type;
121
122 } initiating;
123
124 /**
125 * List of queued tasks not yet in action
126 */
127 linked_list_t *queued_tasks;
128
129 /**
130 * List of active tasks, initiated by ourselve
131 */
132 linked_list_t *active_tasks;
133
134 /**
135 * List of tasks initiated by peer
136 */
137 linked_list_t *passive_tasks;
138
139 /**
140 * the task manager has been reset
141 */
142 bool reset;
143
144 /**
145 * Number of times we retransmit messages before giving up
146 */
147 u_int retransmit_tries;
148
149 /**
150 * Retransmission timeout
151 */
152 double retransmit_timeout;
153
154 /**
155 * Base to calculate retransmission timeout
156 */
157 double retransmit_base;
158 };
159
160 METHOD(task_manager_t, flush_queue, void,
161 private_task_manager_t *this, task_queue_t queue)
162 {
163 linked_list_t *list;
164 task_t *task;
165
166 switch (queue)
167 {
168 case TASK_QUEUE_ACTIVE:
169 list = this->active_tasks;
170 break;
171 case TASK_QUEUE_PASSIVE:
172 list = this->passive_tasks;
173 break;
174 case TASK_QUEUE_QUEUED:
175 list = this->queued_tasks;
176 break;
177 default:
178 return;
179 }
180 while (list->remove_last(list, (void**)&task) == SUCCESS)
181 {
182 task->destroy(task);
183 }
184 }
185
186 /**
187 * flush all tasks in the task manager
188 */
189 static void flush(private_task_manager_t *this)
190 {
191 flush_queue(this, TASK_QUEUE_QUEUED);
192 flush_queue(this, TASK_QUEUE_PASSIVE);
193 flush_queue(this, TASK_QUEUE_ACTIVE);
194 }
195
196 /**
197 * move a task of a specific type from the queue to the active list
198 */
199 static bool activate_task(private_task_manager_t *this, task_type_t type)
200 {
201 enumerator_t *enumerator;
202 task_t *task;
203 bool found = FALSE;
204
205 enumerator = this->queued_tasks->create_enumerator(this->queued_tasks);
206 while (enumerator->enumerate(enumerator, (void**)&task))
207 {
208 if (task->get_type(task) == type)
209 {
210 DBG2(DBG_IKE, " activating %N task", task_type_names, type);
211 this->queued_tasks->remove_at(this->queued_tasks, enumerator);
212 this->active_tasks->insert_last(this->active_tasks, task);
213 found = TRUE;
214 break;
215 }
216 }
217 enumerator->destroy(enumerator);
218 return found;
219 }
220
221 METHOD(task_manager_t, retransmit, status_t,
222 private_task_manager_t *this, u_int32_t message_id)
223 {
224 if (this->initiating.packet && message_id == this->initiating.mid)
225 {
226 u_int32_t timeout;
227 job_t *job;
228 enumerator_t *enumerator;
229 packet_t *packet;
230 task_t *task;
231 ike_mobike_t *mobike = NULL;
232
233 /* check if we are retransmitting a MOBIKE routability check */
234 enumerator = this->active_tasks->create_enumerator(this->active_tasks);
235 while (enumerator->enumerate(enumerator, (void*)&task))
236 {
237 if (task->get_type(task) == TASK_IKE_MOBIKE)
238 {
239 mobike = (ike_mobike_t*)task;
240 if (!mobike->is_probing(mobike))
241 {
242 mobike = NULL;
243 }
244 break;
245 }
246 }
247 enumerator->destroy(enumerator);
248
249 if (mobike == NULL)
250 {
251 if (this->initiating.retransmitted <= this->retransmit_tries)
252 {
253 timeout = (u_int32_t)(this->retransmit_timeout * 1000.0 *
254 pow(this->retransmit_base, this->initiating.retransmitted));
255 }
256 else
257 {
258 DBG1(DBG_IKE, "giving up after %d retransmits",
259 this->initiating.retransmitted - 1);
260 if (this->ike_sa->get_state(this->ike_sa) != IKE_CONNECTING)
261 {
262 charon->bus->ike_updown(charon->bus, this->ike_sa, FALSE);
263 }
264 return DESTROY_ME;
265 }
266
267 if (this->initiating.retransmitted)
268 {
269 DBG1(DBG_IKE, "retransmit %d of request with message ID %d",
270 this->initiating.retransmitted, message_id);
271 }
272 packet = this->initiating.packet->clone(this->initiating.packet);
273 charon->sender->send(charon->sender, packet);
274 }
275 else
276 { /* for routeability checks, we use a more aggressive behavior */
277 if (this->initiating.retransmitted <= ROUTEABILITY_CHECK_TRIES)
278 {
279 timeout = ROUTEABILITY_CHECK_INTERVAL;
280 }
281 else
282 {
283 DBG1(DBG_IKE, "giving up after %d path probings",
284 this->initiating.retransmitted - 1);
285 charon->bus->ike_updown(charon->bus, this->ike_sa, FALSE);
286 return DESTROY_ME;
287 }
288
289 if (this->initiating.retransmitted)
290 {
291 DBG1(DBG_IKE, "path probing attempt %d",
292 this->initiating.retransmitted);
293 }
294 mobike->transmit(mobike, this->initiating.packet);
295 }
296
297 this->initiating.retransmitted++;
298 job = (job_t*)retransmit_job_create(this->initiating.mid,
299 this->ike_sa->get_id(this->ike_sa));
300 lib->scheduler->schedule_job_ms(lib->scheduler, job, timeout);
301 }
302 return SUCCESS;
303 }
304
305 METHOD(task_manager_t, initiate, status_t,
306 private_task_manager_t *this)
307 {
308 enumerator_t *enumerator;
309 task_t *task;
310 message_t *message;
311 host_t *me, *other;
312 status_t status;
313 exchange_type_t exchange = 0;
314
315 if (this->initiating.type != EXCHANGE_TYPE_UNDEFINED)
316 {
317 DBG2(DBG_IKE, "delaying task initiation, %N exchange in progress",
318 exchange_type_names, this->initiating.type);
319 /* do not initiate if we already have a message in the air */
320 return SUCCESS;
321 }
322
323 if (this->active_tasks->get_count(this->active_tasks) == 0)
324 {
325 DBG2(DBG_IKE, "activating new tasks");
326 switch (this->ike_sa->get_state(this->ike_sa))
327 {
328 case IKE_CREATED:
329 activate_task(this, TASK_IKE_VENDOR);
330 if (activate_task(this, TASK_IKE_INIT))
331 {
332 this->initiating.mid = 0;
333 exchange = IKE_SA_INIT;
334 activate_task(this, TASK_IKE_NATD);
335 activate_task(this, TASK_IKE_CERT_PRE);
336 #ifdef ME
337 /* this task has to be activated before the TASK_IKE_AUTH
338 * task, because that task pregenerates the packet after
339 * which no payloads can be added to the message anymore.
340 */
341 activate_task(this, TASK_IKE_ME);
342 #endif /* ME */
343 activate_task(this, TASK_IKE_AUTH);
344 activate_task(this, TASK_IKE_CERT_POST);
345 activate_task(this, TASK_IKE_CONFIG);
346 activate_task(this, TASK_CHILD_CREATE);
347 activate_task(this, TASK_IKE_AUTH_LIFETIME);
348 activate_task(this, TASK_IKE_MOBIKE);
349 }
350 break;
351 case IKE_ESTABLISHED:
352 if (activate_task(this, TASK_CHILD_CREATE))
353 {
354 exchange = CREATE_CHILD_SA;
355 break;
356 }
357 if (activate_task(this, TASK_CHILD_DELETE))
358 {
359 exchange = INFORMATIONAL;
360 break;
361 }
362 if (activate_task(this, TASK_CHILD_REKEY))
363 {
364 exchange = CREATE_CHILD_SA;
365 break;
366 }
367 if (activate_task(this, TASK_IKE_DELETE))
368 {
369 exchange = INFORMATIONAL;
370 break;
371 }
372 if (activate_task(this, TASK_IKE_REKEY))
373 {
374 exchange = CREATE_CHILD_SA;
375 break;
376 }
377 if (activate_task(this, TASK_IKE_REAUTH))
378 {
379 exchange = INFORMATIONAL;
380 break;
381 }
382 if (activate_task(this, TASK_IKE_MOBIKE))
383 {
384 exchange = INFORMATIONAL;
385 break;
386 }
387 if (activate_task(this, TASK_IKE_DPD))
388 {
389 exchange = INFORMATIONAL;
390 break;
391 }
392 if (activate_task(this, TASK_IKE_AUTH_LIFETIME))
393 {
394 exchange = INFORMATIONAL;
395 break;
396 }
397 #ifdef ME
398 if (activate_task(this, TASK_IKE_ME))
399 {
400 exchange = ME_CONNECT;
401 break;
402 }
403 #endif /* ME */
404 case IKE_REKEYING:
405 if (activate_task(this, TASK_IKE_DELETE))
406 {
407 exchange = INFORMATIONAL;
408 break;
409 }
410 case IKE_DELETING:
411 default:
412 break;
413 }
414 }
415 else
416 {
417 DBG2(DBG_IKE, "reinitiating already active tasks");
418 enumerator = this->active_tasks->create_enumerator(this->active_tasks);
419 while (enumerator->enumerate(enumerator, (void**)&task))
420 {
421 DBG2(DBG_IKE, " %N task", task_type_names, task->get_type(task));
422 switch (task->get_type(task))
423 {
424 case TASK_IKE_INIT:
425 exchange = IKE_SA_INIT;
426 break;
427 case TASK_IKE_AUTH:
428 exchange = IKE_AUTH;
429 break;
430 case TASK_CHILD_CREATE:
431 case TASK_CHILD_REKEY:
432 case TASK_IKE_REKEY:
433 exchange = CREATE_CHILD_SA;
434 break;
435 case TASK_IKE_MOBIKE:
436 exchange = INFORMATIONAL;
437 break;
438 default:
439 continue;
440 }
441 break;
442 }
443 enumerator->destroy(enumerator);
444 }
445
446 if (exchange == 0)
447 {
448 DBG2(DBG_IKE, "nothing to initiate");
449 /* nothing to do yet... */
450 return SUCCESS;
451 }
452
453 me = this->ike_sa->get_my_host(this->ike_sa);
454 other = this->ike_sa->get_other_host(this->ike_sa);
455
456 message = message_create(IKEV2_MAJOR_VERSION, IKEV2_MINOR_VERSION);
457 message->set_message_id(message, this->initiating.mid);
458 message->set_source(message, me->clone(me));
459 message->set_destination(message, other->clone(other));
460 message->set_exchange_type(message, exchange);
461 this->initiating.type = exchange;
462 this->initiating.retransmitted = 0;
463
464 enumerator = this->active_tasks->create_enumerator(this->active_tasks);
465 while (enumerator->enumerate(enumerator, (void*)&task))
466 {
467 switch (task->build(task, message))
468 {
469 case SUCCESS:
470 /* task completed, remove it */
471 this->active_tasks->remove_at(this->active_tasks, enumerator);
472 task->destroy(task);
473 break;
474 case NEED_MORE:
475 /* processed, but task needs another exchange */
476 break;
477 case FAILED:
478 default:
479 if (this->ike_sa->get_state(this->ike_sa) != IKE_CONNECTING)
480 {
481 charon->bus->ike_updown(charon->bus, this->ike_sa, FALSE);
482 }
483 /* FALL */
484 case DESTROY_ME:
485 /* critical failure, destroy IKE_SA */
486 enumerator->destroy(enumerator);
487 message->destroy(message);
488 flush(this);
489 return DESTROY_ME;
490 }
491 }
492 enumerator->destroy(enumerator);
493
494 /* update exchange type if a task changed it */
495 this->initiating.type = message->get_exchange_type(message);
496
497 status = this->ike_sa->generate_message(this->ike_sa, message,
498 &this->initiating.packet);
499 if (status != SUCCESS)
500 {
501 /* message generation failed. There is nothing more to do than to
502 * close the SA */
503 message->destroy(message);
504 flush(this);
505 charon->bus->ike_updown(charon->bus, this->ike_sa, FALSE);
506 return DESTROY_ME;
507 }
508 message->destroy(message);
509
510 return retransmit(this, this->initiating.mid);
511 }
512
513 /**
514 * handle an incoming response message
515 */
516 static status_t process_response(private_task_manager_t *this,
517 message_t *message)
518 {
519 enumerator_t *enumerator;
520 task_t *task;
521
522 if (message->get_exchange_type(message) != this->initiating.type)
523 {
524 DBG1(DBG_IKE, "received %N response, but expected %N",
525 exchange_type_names, message->get_exchange_type(message),
526 exchange_type_names, this->initiating.type);
527 charon->bus->ike_updown(charon->bus, this->ike_sa, FALSE);
528 return DESTROY_ME;
529 }
530
531 /* catch if we get resetted while processing */
532 this->reset = FALSE;
533 enumerator = this->active_tasks->create_enumerator(this->active_tasks);
534 while (enumerator->enumerate(enumerator, (void*)&task))
535 {
536 switch (task->process(task, message))
537 {
538 case SUCCESS:
539 /* task completed, remove it */
540 this->active_tasks->remove_at(this->active_tasks, enumerator);
541 task->destroy(task);
542 break;
543 case NEED_MORE:
544 /* processed, but task needs another exchange */
545 break;
546 case FAILED:
547 default:
548 charon->bus->ike_updown(charon->bus, this->ike_sa, FALSE);
549 /* FALL */
550 case DESTROY_ME:
551 /* critical failure, destroy IKE_SA */
552 this->active_tasks->remove_at(this->active_tasks, enumerator);
553 enumerator->destroy(enumerator);
554 task->destroy(task);
555 return DESTROY_ME;
556 }
557 if (this->reset)
558 { /* start all over again if we were reset */
559 this->reset = FALSE;
560 enumerator->destroy(enumerator);
561 return initiate(this);
562 }
563 }
564 enumerator->destroy(enumerator);
565
566 this->initiating.mid++;
567 this->initiating.type = EXCHANGE_TYPE_UNDEFINED;
568 this->initiating.packet->destroy(this->initiating.packet);
569 this->initiating.packet = NULL;
570
571 return initiate(this);
572 }
573
574 /**
575 * handle exchange collisions
576 */
577 static bool handle_collisions(private_task_manager_t *this, task_t *task)
578 {
579 enumerator_t *enumerator;
580 task_t *active;
581 task_type_t type;
582
583 type = task->get_type(task);
584
585 /* do we have to check */
586 if (type == TASK_IKE_REKEY || type == TASK_CHILD_REKEY ||
587 type == TASK_CHILD_DELETE || type == TASK_IKE_DELETE ||
588 type == TASK_IKE_REAUTH)
589 {
590 /* find an exchange collision, and notify these tasks */
591 enumerator = this->active_tasks->create_enumerator(this->active_tasks);
592 while (enumerator->enumerate(enumerator, (void**)&active))
593 {
594 switch (active->get_type(active))
595 {
596 case TASK_IKE_REKEY:
597 if (type == TASK_IKE_REKEY || type == TASK_IKE_DELETE ||
598 type == TASK_IKE_REAUTH)
599 {
600 ike_rekey_t *rekey = (ike_rekey_t*)active;
601 rekey->collide(rekey, task);
602 break;
603 }
604 continue;
605 case TASK_CHILD_REKEY:
606 if (type == TASK_CHILD_REKEY || type == TASK_CHILD_DELETE)
607 {
608 child_rekey_t *rekey = (child_rekey_t*)active;
609 rekey->collide(rekey, task);
610 break;
611 }
612 continue;
613 default:
614 continue;
615 }
616 enumerator->destroy(enumerator);
617 return TRUE;
618 }
619 enumerator->destroy(enumerator);
620 }
621 return FALSE;
622 }
623
624 /**
625 * build a response depending on the "passive" task list
626 */
627 static status_t build_response(private_task_manager_t *this, message_t *request)
628 {
629 enumerator_t *enumerator;
630 task_t *task;
631 message_t *message;
632 host_t *me, *other;
633 bool delete = FALSE, hook = FALSE;
634 status_t status;
635
636 me = request->get_destination(request);
637 other = request->get_source(request);
638
639 message = message_create(IKEV2_MAJOR_VERSION, IKEV2_MINOR_VERSION);
640 message->set_exchange_type(message, request->get_exchange_type(request));
641 /* send response along the path the request came in */
642 message->set_source(message, me->clone(me));
643 message->set_destination(message, other->clone(other));
644 message->set_message_id(message, this->responding.mid);
645 message->set_request(message, FALSE);
646
647 enumerator = this->passive_tasks->create_enumerator(this->passive_tasks);
648 while (enumerator->enumerate(enumerator, (void*)&task))
649 {
650 switch (task->build(task, message))
651 {
652 case SUCCESS:
653 /* task completed, remove it */
654 this->passive_tasks->remove_at(this->passive_tasks, enumerator);
655 if (!handle_collisions(this, task))
656 {
657 task->destroy(task);
658 }
659 break;
660 case NEED_MORE:
661 /* processed, but task needs another exchange */
662 if (handle_collisions(this, task))
663 {
664 this->passive_tasks->remove_at(this->passive_tasks,
665 enumerator);
666 }
667 break;
668 case FAILED:
669 default:
670 hook = TRUE;
671 /* FALL */
672 case DESTROY_ME:
673 /* destroy IKE_SA, but SEND response first */
674 delete = TRUE;
675 break;
676 }
677 if (delete)
678 {
679 break;
680 }
681 }
682 enumerator->destroy(enumerator);
683
684 /* remove resonder SPI if IKE_SA_INIT failed */
685 if (delete && request->get_exchange_type(request) == IKE_SA_INIT)
686 {
687 ike_sa_id_t *id = this->ike_sa->get_id(this->ike_sa);
688 id->set_responder_spi(id, 0);
689 }
690
691 /* message complete, send it */
692 DESTROY_IF(this->responding.packet);
693 this->responding.packet = NULL;
694 status = this->ike_sa->generate_message(this->ike_sa, message,
695 &this->responding.packet);
696 message->destroy(message);
697 if (status != SUCCESS)
698 {
699 charon->bus->ike_updown(charon->bus, this->ike_sa, FALSE);
700 return DESTROY_ME;
701 }
702
703 charon->sender->send(charon->sender,
704 this->responding.packet->clone(this->responding.packet));
705 if (delete)
706 {
707 if (hook)
708 {
709 charon->bus->ike_updown(charon->bus, this->ike_sa, FALSE);
710 }
711 return DESTROY_ME;
712 }
713 return SUCCESS;
714 }
715
716 /**
717 * handle an incoming request message
718 */
719 static status_t process_request(private_task_manager_t *this,
720 message_t *message)
721 {
722 enumerator_t *enumerator;
723 task_t *task = NULL;
724 payload_t *payload;
725 notify_payload_t *notify;
726 delete_payload_t *delete;
727
728 if (this->passive_tasks->get_count(this->passive_tasks) == 0)
729 { /* create tasks depending on request type, if not already some queued */
730 switch (message->get_exchange_type(message))
731 {
732 case IKE_SA_INIT:
733 {
734 task = (task_t*)ike_vendor_create(this->ike_sa, FALSE);
735 this->passive_tasks->insert_last(this->passive_tasks, task);
736 task = (task_t*)ike_init_create(this->ike_sa, FALSE, NULL);
737 this->passive_tasks->insert_last(this->passive_tasks, task);
738 task = (task_t*)ike_natd_create(this->ike_sa, FALSE);
739 this->passive_tasks->insert_last(this->passive_tasks, task);
740 task = (task_t*)ike_cert_pre_create(this->ike_sa, FALSE);
741 this->passive_tasks->insert_last(this->passive_tasks, task);
742 #ifdef ME
743 task = (task_t*)ike_me_create(this->ike_sa, FALSE);
744 this->passive_tasks->insert_last(this->passive_tasks, task);
745 #endif /* ME */
746 task = (task_t*)ike_auth_create(this->ike_sa, FALSE);
747 this->passive_tasks->insert_last(this->passive_tasks, task);
748 task = (task_t*)ike_cert_post_create(this->ike_sa, FALSE);
749 this->passive_tasks->insert_last(this->passive_tasks, task);
750 task = (task_t*)ike_config_create(this->ike_sa, FALSE);
751 this->passive_tasks->insert_last(this->passive_tasks, task);
752 task = (task_t*)child_create_create(this->ike_sa, NULL, FALSE,
753 NULL, NULL);
754 this->passive_tasks->insert_last(this->passive_tasks, task);
755 task = (task_t*)ike_auth_lifetime_create(this->ike_sa, FALSE);
756 this->passive_tasks->insert_last(this->passive_tasks, task);
757 task = (task_t*)ike_mobike_create(this->ike_sa, FALSE);
758 this->passive_tasks->insert_last(this->passive_tasks, task);
759 break;
760 }
761 case CREATE_CHILD_SA:
762 { /* FIXME: we should prevent this on mediation connections */
763 bool notify_found = FALSE, ts_found = FALSE;
764 enumerator = message->create_payload_enumerator(message);
765 while (enumerator->enumerate(enumerator, &payload))
766 {
767 switch (payload->get_type(payload))
768 {
769 case NOTIFY:
770 { /* if we find a rekey notify, its CHILD_SA rekeying */
771 notify = (notify_payload_t*)payload;
772 if (notify->get_notify_type(notify) == REKEY_SA &&
773 (notify->get_protocol_id(notify) == PROTO_AH ||
774 notify->get_protocol_id(notify) == PROTO_ESP))
775 {
776 notify_found = TRUE;
777 }
778 break;
779 }
780 case TRAFFIC_SELECTOR_INITIATOR:
781 case TRAFFIC_SELECTOR_RESPONDER:
782 { /* if we don't find a TS, its IKE rekeying */
783 ts_found = TRUE;
784 break;
785 }
786 default:
787 break;
788 }
789 }
790 enumerator->destroy(enumerator);
791
792 if (ts_found)
793 {
794 if (notify_found)
795 {
796 task = (task_t*)child_rekey_create(this->ike_sa,
797 PROTO_NONE, 0);
798 }
799 else
800 {
801 task = (task_t*)child_create_create(this->ike_sa, NULL,
802 FALSE, NULL, NULL);
803 }
804 }
805 else
806 {
807 task = (task_t*)ike_rekey_create(this->ike_sa, FALSE);
808 }
809 this->passive_tasks->insert_last(this->passive_tasks, task);
810 break;
811 }
812 case INFORMATIONAL:
813 {
814 enumerator = message->create_payload_enumerator(message);
815 while (enumerator->enumerate(enumerator, &payload))
816 {
817 switch (payload->get_type(payload))
818 {
819 case NOTIFY:
820 {
821 notify = (notify_payload_t*)payload;
822 switch (notify->get_notify_type(notify))
823 {
824 case ADDITIONAL_IP4_ADDRESS:
825 case ADDITIONAL_IP6_ADDRESS:
826 case NO_ADDITIONAL_ADDRESSES:
827 case UPDATE_SA_ADDRESSES:
828 case NO_NATS_ALLOWED:
829 case UNACCEPTABLE_ADDRESSES:
830 case UNEXPECTED_NAT_DETECTED:
831 case COOKIE2:
832 case NAT_DETECTION_SOURCE_IP:
833 case NAT_DETECTION_DESTINATION_IP:
834 task = (task_t*)ike_mobike_create(
835 this->ike_sa, FALSE);
836 break;
837 case AUTH_LIFETIME:
838 task = (task_t*)ike_auth_lifetime_create(
839 this->ike_sa, FALSE);
840 break;
841 default:
842 break;
843 }
844 break;
845 }
846 case DELETE:
847 {
848 delete = (delete_payload_t*)payload;
849 if (delete->get_protocol_id(delete) == PROTO_IKE)
850 {
851 task = (task_t*)ike_delete_create(this->ike_sa,
852 FALSE);
853 }
854 else
855 {
856 task = (task_t*)child_delete_create(this->ike_sa,
857 PROTO_NONE, 0, FALSE);
858 }
859 break;
860 }
861 default:
862 break;
863 }
864 if (task)
865 {
866 break;
867 }
868 }
869 enumerator->destroy(enumerator);
870
871 if (task == NULL)
872 {
873 task = (task_t*)ike_dpd_create(FALSE);
874 }
875 this->passive_tasks->insert_last(this->passive_tasks, task);
876 break;
877 }
878 #ifdef ME
879 case ME_CONNECT:
880 {
881 task = (task_t*)ike_me_create(this->ike_sa, FALSE);
882 this->passive_tasks->insert_last(this->passive_tasks, task);
883 }
884 #endif /* ME */
885 default:
886 break;
887 }
888 }
889
890 /* let the tasks process the message */
891 enumerator = this->passive_tasks->create_enumerator(this->passive_tasks);
892 while (enumerator->enumerate(enumerator, (void*)&task))
893 {
894 switch (task->process(task, message))
895 {
896 case SUCCESS:
897 /* task completed, remove it */
898 this->passive_tasks->remove_at(this->passive_tasks, enumerator);
899 task->destroy(task);
900 break;
901 case NEED_MORE:
902 /* processed, but task needs at least another call to build() */
903 break;
904 case FAILED:
905 default:
906 charon->bus->ike_updown(charon->bus, this->ike_sa, FALSE);
907 /* FALL */
908 case DESTROY_ME:
909 /* critical failure, destroy IKE_SA */
910 this->passive_tasks->remove_at(this->passive_tasks, enumerator);
911 enumerator->destroy(enumerator);
912 task->destroy(task);
913 return DESTROY_ME;
914 }
915 }
916 enumerator->destroy(enumerator);
917
918 return build_response(this, message);
919 }
920
921 METHOD(task_manager_t, incr_mid, void,
922 private_task_manager_t *this, bool initiate)
923 {
924 if (initiate)
925 {
926 this->initiating.mid++;
927 }
928 else
929 {
930 this->responding.mid++;
931 }
932 }
933
934 /**
935 * Send a notify back to the sender
936 */
937 static void send_notify_response(private_task_manager_t *this,
938 message_t *request, notify_type_t type,
939 chunk_t data)
940 {
941 message_t *response;
942 packet_t *packet;
943 host_t *me, *other;
944
945 response = message_create(IKEV2_MAJOR_VERSION, IKEV2_MINOR_VERSION);
946 response->set_exchange_type(response, request->get_exchange_type(request));
947 response->set_request(response, FALSE);
948 response->set_message_id(response, request->get_message_id(request));
949 response->add_notify(response, FALSE, type, data);
950 me = this->ike_sa->get_my_host(this->ike_sa);
951 if (me->is_anyaddr(me))
952 {
953 me = request->get_destination(request);
954 this->ike_sa->set_my_host(this->ike_sa, me->clone(me));
955 }
956 other = this->ike_sa->get_other_host(this->ike_sa);
957 if (other->is_anyaddr(other))
958 {
959 other = request->get_source(request);
960 this->ike_sa->set_other_host(this->ike_sa, other->clone(other));
961 }
962 response->set_source(response, me->clone(me));
963 response->set_destination(response, other->clone(other));
964 if (this->ike_sa->generate_message(this->ike_sa, response,
965 &packet) == SUCCESS)
966 {
967 charon->sender->send(charon->sender, packet);
968 }
969 response->destroy(response);
970 }
971
972 /**
973 * Parse the given message and verify that it is valid.
974 */
975 static status_t parse_message(private_task_manager_t *this, message_t *msg)
976 {
977 status_t status;
978 u_int8_t type = 0;
979
980 status = msg->parse_body(msg, this->ike_sa->get_keymat(this->ike_sa));
981
982 if (status == SUCCESS)
983 { /* check for unsupported critical payloads */
984 enumerator_t *enumerator;
985 unknown_payload_t *unknown;
986 payload_t *payload;
987
988 enumerator = msg->create_payload_enumerator(msg);
989 while (enumerator->enumerate(enumerator, &payload))
990 {
991 unknown = (unknown_payload_t*)payload;
992 type = payload->get_type(payload);
993 if (!payload_is_known(type) &&
994 unknown->is_critical(unknown))
995 {
996 DBG1(DBG_ENC, "payload type %N is not supported, "
997 "but its critical!", payload_type_names, type);
998 status = NOT_SUPPORTED;
999 }
1000 }
1001 enumerator->destroy(enumerator);
1002 }
1003
1004 if (status != SUCCESS)
1005 {
1006 bool is_request = msg->get_request(msg);
1007
1008 switch (status)
1009 {
1010 case NOT_SUPPORTED:
1011 DBG1(DBG_IKE, "critical unknown payloads found");
1012 if (is_request)
1013 {
1014 send_notify_response(this, msg,
1015 UNSUPPORTED_CRITICAL_PAYLOAD,
1016 chunk_from_thing(type));
1017 incr_mid(this, FALSE);
1018 }
1019 break;
1020 case PARSE_ERROR:
1021 DBG1(DBG_IKE, "message parsing failed");
1022 if (is_request)
1023 {
1024 send_notify_response(this, msg,
1025 INVALID_SYNTAX, chunk_empty);
1026 incr_mid(this, FALSE);
1027 }
1028 break;
1029 case VERIFY_ERROR:
1030 DBG1(DBG_IKE, "message verification failed");
1031 if (is_request)
1032 {
1033 send_notify_response(this, msg,
1034 INVALID_SYNTAX, chunk_empty);
1035 incr_mid(this, FALSE);
1036 }
1037 break;
1038 case FAILED:
1039 DBG1(DBG_IKE, "integrity check failed");
1040 /* ignored */
1041 break;
1042 case INVALID_STATE:
1043 DBG1(DBG_IKE, "found encrypted message, but no keys available");
1044 default:
1045 break;
1046 }
1047 DBG1(DBG_IKE, "%N %s with message ID %d processing failed",
1048 exchange_type_names, msg->get_exchange_type(msg),
1049 is_request ? "request" : "response",
1050 msg->get_message_id(msg));
1051
1052 if (this->ike_sa->get_state(this->ike_sa) == IKE_CREATED)
1053 { /* invalid initiation attempt, close SA */
1054 return DESTROY_ME;
1055 }
1056 }
1057 return status;
1058 }
1059
1060
1061 METHOD(task_manager_t, process_message, status_t,
1062 private_task_manager_t *this, message_t *msg)
1063 {
1064 host_t *me, *other;
1065 status_t status;
1066 u_int32_t mid;
1067
1068 charon->bus->message(charon->bus, msg, TRUE, FALSE);
1069 status = parse_message(this, msg);
1070 if (status != SUCCESS)
1071 {
1072 return status;
1073 }
1074
1075 me = msg->get_destination(msg);
1076 other = msg->get_source(msg);
1077
1078 /* if this IKE_SA is virgin, we check for a config */
1079 if (this->ike_sa->get_ike_cfg(this->ike_sa) == NULL)
1080 {
1081 ike_sa_id_t *ike_sa_id;
1082 ike_cfg_t *ike_cfg;
1083 job_t *job;
1084 ike_cfg = charon->backends->get_ike_cfg(charon->backends, me, other);
1085 if (ike_cfg == NULL)
1086 {
1087 /* no config found for these hosts, destroy */
1088 DBG1(DBG_IKE, "no IKE config found for %H...%H, sending %N",
1089 me, other, notify_type_names, NO_PROPOSAL_CHOSEN);
1090 send_notify_response(this, msg,
1091 NO_PROPOSAL_CHOSEN, chunk_empty);
1092 return DESTROY_ME;
1093 }
1094 this->ike_sa->set_ike_cfg(this->ike_sa, ike_cfg);
1095 ike_cfg->destroy(ike_cfg);
1096 /* add a timeout if peer does not establish it completely */
1097 ike_sa_id = this->ike_sa->get_id(this->ike_sa);
1098 job = (job_t*)delete_ike_sa_job_create(ike_sa_id, FALSE);
1099 lib->scheduler->schedule_job(lib->scheduler, job,
1100 lib->settings->get_int(lib->settings,
1101 "%s.half_open_timeout", HALF_OPEN_IKE_SA_TIMEOUT,
1102 charon->name));
1103 }
1104 this->ike_sa->set_statistic(this->ike_sa, STAT_INBOUND,
1105 time_monotonic(NULL));
1106
1107 mid = msg->get_message_id(msg);
1108 if (msg->get_request(msg))
1109 {
1110 if (mid == this->responding.mid)
1111 {
1112 if (this->ike_sa->get_state(this->ike_sa) == IKE_CREATED ||
1113 this->ike_sa->get_state(this->ike_sa) == IKE_CONNECTING ||
1114 msg->get_exchange_type(msg) != IKE_SA_INIT)
1115 { /* only do host updates based on verified messages */
1116 if (!this->ike_sa->supports_extension(this->ike_sa, EXT_MOBIKE))
1117 { /* with MOBIKE, we do no implicit updates */
1118 this->ike_sa->update_hosts(this->ike_sa, me, other, mid == 1);
1119 }
1120 }
1121 charon->bus->message(charon->bus, msg, TRUE, TRUE);
1122 if (msg->get_exchange_type(msg) == EXCHANGE_TYPE_UNDEFINED)
1123 { /* ignore messages altered to EXCHANGE_TYPE_UNDEFINED */
1124 return SUCCESS;
1125 }
1126 if (process_request(this, msg) != SUCCESS)
1127 {
1128 flush(this);
1129 return DESTROY_ME;
1130 }
1131 this->responding.mid++;
1132 }
1133 else if ((mid == this->responding.mid - 1) && this->responding.packet)
1134 {
1135 packet_t *clone;
1136 host_t *host;
1137
1138 DBG1(DBG_IKE, "received retransmit of request with ID %d, "
1139 "retransmitting response", mid);
1140 clone = this->responding.packet->clone(this->responding.packet);
1141 host = msg->get_destination(msg);
1142 clone->set_source(clone, host->clone(host));
1143 host = msg->get_source(msg);
1144 clone->set_destination(clone, host->clone(host));
1145 charon->sender->send(charon->sender, clone);
1146 }
1147 else
1148 {
1149 DBG1(DBG_IKE, "received message ID %d, expected %d. Ignored",
1150 mid, this->responding.mid);
1151 }
1152 }
1153 else
1154 {
1155 if (mid == this->initiating.mid)
1156 {
1157 if (this->ike_sa->get_state(this->ike_sa) == IKE_CREATED ||
1158 this->ike_sa->get_state(this->ike_sa) == IKE_CONNECTING ||
1159 msg->get_exchange_type(msg) != IKE_SA_INIT)
1160 { /* only do host updates based on verified messages */
1161 if (!this->ike_sa->supports_extension(this->ike_sa, EXT_MOBIKE))
1162 { /* with MOBIKE, we do no implicit updates */
1163 this->ike_sa->update_hosts(this->ike_sa, me, other, FALSE);
1164 }
1165 }
1166 charon->bus->message(charon->bus, msg, TRUE, TRUE);
1167 if (msg->get_exchange_type(msg) == EXCHANGE_TYPE_UNDEFINED)
1168 { /* ignore messages altered to EXCHANGE_TYPE_UNDEFINED */
1169 return SUCCESS;
1170 }
1171 if (process_response(this, msg) != SUCCESS)
1172 {
1173 flush(this);
1174 return DESTROY_ME;
1175 }
1176 }
1177 else
1178 {
1179 DBG1(DBG_IKE, "received message ID %d, expected %d. Ignored",
1180 mid, this->initiating.mid);
1181 return SUCCESS;
1182 }
1183 }
1184 return SUCCESS;
1185 }
1186
1187 METHOD(task_manager_t, queue_task, void,
1188 private_task_manager_t *this, task_t *task)
1189 {
1190 if (task->get_type(task) == TASK_IKE_MOBIKE)
1191 { /* there is no need to queue more than one mobike task */
1192 enumerator_t *enumerator;
1193 task_t *current;
1194
1195 enumerator = this->queued_tasks->create_enumerator(this->queued_tasks);
1196 while (enumerator->enumerate(enumerator, (void**)&current))
1197 {
1198 if (current->get_type(current) == TASK_IKE_MOBIKE)
1199 {
1200 enumerator->destroy(enumerator);
1201 task->destroy(task);
1202 return;
1203 }
1204 }
1205 enumerator->destroy(enumerator);
1206 }
1207 DBG2(DBG_IKE, "queueing %N task", task_type_names, task->get_type(task));
1208 this->queued_tasks->insert_last(this->queued_tasks, task);
1209 }
1210
1211 /**
1212 * Check if a given task has been queued already
1213 */
1214 static bool has_queued(private_task_manager_t *this, task_type_t type)
1215 {
1216 enumerator_t *enumerator;
1217 bool found = FALSE;
1218 task_t *task;
1219
1220 enumerator = this->queued_tasks->create_enumerator(this->queued_tasks);
1221 while (enumerator->enumerate(enumerator, &task))
1222 {
1223 if (task->get_type(task) == type)
1224 {
1225 found = TRUE;
1226 break;
1227 }
1228 }
1229 enumerator->destroy(enumerator);
1230 return found;
1231 }
1232
1233 METHOD(task_manager_t, queue_ike, void,
1234 private_task_manager_t *this)
1235 {
1236 if (!has_queued(this, TASK_IKE_VENDOR))
1237 {
1238 queue_task(this, (task_t*)ike_vendor_create(this->ike_sa, TRUE));
1239 }
1240 if (!has_queued(this, TASK_IKE_INIT))
1241 {
1242 queue_task(this, (task_t*)ike_init_create(this->ike_sa, TRUE, NULL));
1243 }
1244 if (!has_queued(this, TASK_IKE_NATD))
1245 {
1246 queue_task(this, (task_t*)ike_natd_create(this->ike_sa, TRUE));
1247 }
1248 if (!has_queued(this, TASK_IKE_CERT_PRE))
1249 {
1250 queue_task(this, (task_t*)ike_cert_pre_create(this->ike_sa, TRUE));
1251 }
1252 if (!has_queued(this, TASK_IKE_AUTH))
1253 {
1254 queue_task(this, (task_t*)ike_auth_create(this->ike_sa, TRUE));
1255 }
1256 if (!has_queued(this, TASK_IKE_CERT_POST))
1257 {
1258 queue_task(this, (task_t*)ike_cert_post_create(this->ike_sa, TRUE));
1259 }
1260 if (!has_queued(this, TASK_IKE_CONFIG))
1261 {
1262 queue_task(this, (task_t*)ike_config_create(this->ike_sa, TRUE));
1263 }
1264 if (!has_queued(this, TASK_IKE_AUTH_LIFETIME))
1265 {
1266 queue_task(this, (task_t*)ike_auth_lifetime_create(this->ike_sa, TRUE));
1267 }
1268 if (!has_queued(this, TASK_IKE_MOBIKE))
1269 {
1270 peer_cfg_t *peer_cfg;
1271
1272 peer_cfg = this->ike_sa->get_peer_cfg(this->ike_sa);
1273 if (peer_cfg->use_mobike(peer_cfg))
1274 {
1275 queue_task(this, (task_t*)ike_mobike_create(this->ike_sa, TRUE));
1276 }
1277 }
1278 #ifdef ME
1279 if (!has_queued(this, TASK_IKE_ME))
1280 {
1281 queue_task(this, (task_t*)ike_me_create(this->ike_sa, TRUE));
1282 }
1283 #endif /* ME */
1284 }
1285
1286 METHOD(task_manager_t, queue_ike_rekey, void,
1287 private_task_manager_t *this)
1288 {
1289 queue_task(this, (task_t*)ike_rekey_create(this->ike_sa, TRUE));
1290 }
1291
1292 METHOD(task_manager_t, queue_ike_reauth, void,
1293 private_task_manager_t *this)
1294 {
1295 queue_task(this, (task_t*)ike_reauth_create(this->ike_sa));
1296 }
1297
1298 METHOD(task_manager_t, queue_ike_delete, void,
1299 private_task_manager_t *this)
1300 {
1301 queue_task(this, (task_t*)ike_delete_create(this->ike_sa, TRUE));
1302 }
1303
1304 METHOD(task_manager_t, queue_mobike, void,
1305 private_task_manager_t *this, bool roam, bool address)
1306 {
1307 ike_mobike_t *mobike;
1308
1309 mobike = ike_mobike_create(this->ike_sa, TRUE);
1310 if (roam)
1311 {
1312 mobike->roam(mobike, address);
1313 }
1314 else
1315 {
1316 mobike->addresses(mobike);
1317 }
1318 queue_task(this, &mobike->task);
1319 }
1320
1321 METHOD(task_manager_t, queue_child, void,
1322 private_task_manager_t *this, child_cfg_t *cfg, u_int32_t reqid,
1323 traffic_selector_t *tsi, traffic_selector_t *tsr)
1324 {
1325 child_create_t *task;
1326
1327 task = child_create_create(this->ike_sa, cfg, FALSE, tsi, tsr);
1328 if (reqid)
1329 {
1330 task->use_reqid(task, reqid);
1331 }
1332 queue_task(this, &task->task);
1333 }
1334
1335 METHOD(task_manager_t, queue_child_rekey, void,
1336 private_task_manager_t *this, protocol_id_t protocol, u_int32_t spi)
1337 {
1338 queue_task(this, (task_t*)child_rekey_create(this->ike_sa, protocol, spi));
1339 }
1340
1341 METHOD(task_manager_t, queue_child_delete, void,
1342 private_task_manager_t *this, protocol_id_t protocol, u_int32_t spi,
1343 bool expired)
1344 {
1345 queue_task(this, (task_t*)child_delete_create(this->ike_sa,
1346 protocol, spi, expired));
1347 }
1348
1349 METHOD(task_manager_t, queue_dpd, void,
1350 private_task_manager_t *this)
1351 {
1352 ike_mobike_t *mobike;
1353
1354 if (this->ike_sa->supports_extension(this->ike_sa, EXT_MOBIKE) &&
1355 this->ike_sa->has_condition(this->ike_sa, COND_NAT_HERE))
1356 {
1357 /* use mobike enabled DPD to detect NAT mapping changes */
1358 mobike = ike_mobike_create(this->ike_sa, TRUE);
1359 mobike->dpd(mobike);
1360 queue_task(this, &mobike->task);
1361 }
1362 else
1363 {
1364 queue_task(this, (task_t*)ike_dpd_create(TRUE));
1365 }
1366 }
1367
1368 METHOD(task_manager_t, adopt_tasks, void,
1369 private_task_manager_t *this, task_manager_t *other_public)
1370 {
1371 private_task_manager_t *other = (private_task_manager_t*)other_public;
1372 task_t *task;
1373
1374 /* move queued tasks from other to this */
1375 while (other->queued_tasks->remove_last(other->queued_tasks,
1376 (void**)&task) == SUCCESS)
1377 {
1378 DBG2(DBG_IKE, "migrating %N task", task_type_names, task->get_type(task));
1379 task->migrate(task, this->ike_sa);
1380 this->queued_tasks->insert_first(this->queued_tasks, task);
1381 }
1382 }
1383
1384 METHOD(task_manager_t, busy, bool,
1385 private_task_manager_t *this)
1386 {
1387 return (this->active_tasks->get_count(this->active_tasks) > 0);
1388 }
1389
1390 METHOD(task_manager_t, reset, void,
1391 private_task_manager_t *this, u_int32_t initiate, u_int32_t respond)
1392 {
1393 enumerator_t *enumerator;
1394 task_t *task;
1395
1396 /* reset message counters and retransmit packets */
1397 DESTROY_IF(this->responding.packet);
1398 DESTROY_IF(this->initiating.packet);
1399 this->responding.packet = NULL;
1400 this->initiating.packet = NULL;
1401 if (initiate != UINT_MAX)
1402 {
1403 this->initiating.mid = initiate;
1404 }
1405 if (respond != UINT_MAX)
1406 {
1407 this->responding.mid = respond;
1408 }
1409 this->initiating.type = EXCHANGE_TYPE_UNDEFINED;
1410
1411 /* reset queued tasks */
1412 enumerator = this->queued_tasks->create_enumerator(this->queued_tasks);
1413 while (enumerator->enumerate(enumerator, &task))
1414 {
1415 task->migrate(task, this->ike_sa);
1416 }
1417 enumerator->destroy(enumerator);
1418
1419 /* reset active tasks */
1420 while (this->active_tasks->remove_last(this->active_tasks,
1421 (void**)&task) == SUCCESS)
1422 {
1423 task->migrate(task, this->ike_sa);
1424 this->queued_tasks->insert_first(this->queued_tasks, task);
1425 }
1426
1427 this->reset = TRUE;
1428 }
1429
1430 METHOD(task_manager_t, create_task_enumerator, enumerator_t*,
1431 private_task_manager_t *this, task_queue_t queue)
1432 {
1433 switch (queue)
1434 {
1435 case TASK_QUEUE_ACTIVE:
1436 return this->active_tasks->create_enumerator(this->active_tasks);
1437 case TASK_QUEUE_PASSIVE:
1438 return this->passive_tasks->create_enumerator(this->passive_tasks);
1439 case TASK_QUEUE_QUEUED:
1440 return this->queued_tasks->create_enumerator(this->queued_tasks);
1441 default:
1442 return enumerator_create_empty();
1443 }
1444 }
1445
1446 METHOD(task_manager_t, destroy, void,
1447 private_task_manager_t *this)
1448 {
1449 flush(this);
1450
1451 this->active_tasks->destroy(this->active_tasks);
1452 this->queued_tasks->destroy(this->queued_tasks);
1453 this->passive_tasks->destroy(this->passive_tasks);
1454
1455 DESTROY_IF(this->responding.packet);
1456 DESTROY_IF(this->initiating.packet);
1457 free(this);
1458 }
1459
1460 /*
1461 * see header file
1462 */
1463 task_manager_v2_t *task_manager_v2_create(ike_sa_t *ike_sa)
1464 {
1465 private_task_manager_t *this;
1466
1467 INIT(this,
1468 .public = {
1469 .task_manager = {
1470 .process_message = _process_message,
1471 .queue_task = _queue_task,
1472 .queue_ike = _queue_ike,
1473 .queue_ike_rekey = _queue_ike_rekey,
1474 .queue_ike_reauth = _queue_ike_reauth,
1475 .queue_ike_delete = _queue_ike_delete,
1476 .queue_mobike = _queue_mobike,
1477 .queue_child = _queue_child,
1478 .queue_child_rekey = _queue_child_rekey,
1479 .queue_child_delete = _queue_child_delete,
1480 .queue_dpd = _queue_dpd,
1481 .initiate = _initiate,
1482 .retransmit = _retransmit,
1483 .incr_mid = _incr_mid,
1484 .reset = _reset,
1485 .adopt_tasks = _adopt_tasks,
1486 .busy = _busy,
1487 .create_task_enumerator = _create_task_enumerator,
1488 .flush_queue = _flush_queue,
1489 .destroy = _destroy,
1490 },
1491 },
1492 .ike_sa = ike_sa,
1493 .initiating.type = EXCHANGE_TYPE_UNDEFINED,
1494 .queued_tasks = linked_list_create(),
1495 .active_tasks = linked_list_create(),
1496 .passive_tasks = linked_list_create(),
1497 .retransmit_tries = lib->settings->get_int(lib->settings,
1498 "%s.retransmit_tries", RETRANSMIT_TRIES, charon->name),
1499 .retransmit_timeout = lib->settings->get_double(lib->settings,
1500 "%s.retransmit_timeout", RETRANSMIT_TIMEOUT, charon->name),
1501 .retransmit_base = lib->settings->get_double(lib->settings,
1502 "%s.retransmit_base", RETRANSMIT_BASE, charon->name),
1503 );
1504
1505 return &this->public;
1506 }