Moved liveness checking task creation to protocol specific task manager
[strongswan.git] / src / libcharon / sa / ike_sa.c
1 /*
2 * Copyright (C) 2006-2011 Tobias Brunner
3 * Copyright (C) 2006 Daniel Roethlisberger
4 * Copyright (C) 2005-2009 Martin Willi
5 * Copyright (C) 2005 Jan Hutter
6 * Hochschule fuer Technik Rapperswil
7 *
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>.
12 *
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
16 * for more details.
17 */
18
19 #include <string.h>
20 #include <sys/stat.h>
21 #include <errno.h>
22 #include <time.h>
23
24 #include "ike_sa.h"
25
26 #include <library.h>
27 #include <hydra.h>
28 #include <daemon.h>
29 #include <utils/linked_list.h>
30 #include <utils/lexparser.h>
31 #include <sa/ikev2/tasks/ike_init.h>
32 #include <sa/ikev2/tasks/ike_natd.h>
33 #include <sa/ikev2/tasks/ike_mobike.h>
34 #include <sa/ikev2/tasks/ike_auth.h>
35 #include <sa/ikev2/tasks/ike_auth_lifetime.h>
36 #include <sa/ikev2/tasks/ike_config.h>
37 #include <sa/ikev2/tasks/ike_cert_pre.h>
38 #include <sa/ikev2/tasks/ike_cert_post.h>
39 #include <sa/ikev2/tasks/ike_rekey.h>
40 #include <sa/ikev2/tasks/ike_reauth.h>
41 #include <sa/ikev2/tasks/ike_delete.h>
42 #include <sa/ikev2/tasks/ike_dpd.h>
43 #include <sa/ikev2/tasks/ike_vendor.h>
44 #include <sa/ikev2/tasks/child_create.h>
45 #include <sa/ikev2/tasks/child_delete.h>
46 #include <sa/ikev2/tasks/child_rekey.h>
47 #include <sa/ikev1/tasks/main_mode.h>
48 #include <sa/ikev1/tasks/isakmp_cert_pre.h>
49 #include <sa/ikev1/tasks/isakmp_cert_post.h>
50 #include <sa/ikev1/tasks/isakmp_natd.h>
51 #include <sa/ikev1/tasks/quick_mode.h>
52 #include <sa/ikev1/tasks/quick_delete.h>
53 #include <sa/ikev1/tasks/isakmp_vendor.h>
54 #include <sa/ikev1/tasks/isakmp_delete.h>
55 #include <processing/jobs/retransmit_job.h>
56 #include <processing/jobs/delete_ike_sa_job.h>
57 #include <processing/jobs/send_dpd_job.h>
58 #include <processing/jobs/send_keepalive_job.h>
59 #include <processing/jobs/rekey_ike_sa_job.h>
60
61 #ifdef ME
62 #include <sa/ikev2/tasks/ike_me.h>
63 #include <processing/jobs/initiate_mediation_job.h>
64 #endif
65
66 ENUM(ike_sa_state_names, IKE_CREATED, IKE_DESTROYING,
67 "CREATED",
68 "CONNECTING",
69 "ESTABLISHED",
70 "PASSIVE",
71 "REKEYING",
72 "DELETING",
73 "DESTROYING",
74 );
75
76 typedef struct private_ike_sa_t private_ike_sa_t;
77 typedef struct attribute_entry_t attribute_entry_t;
78
79 /**
80 * Private data of an ike_sa_t object.
81 */
82 struct private_ike_sa_t {
83
84 /**
85 * Public members
86 */
87 ike_sa_t public;
88
89 /**
90 * Identifier for the current IKE_SA.
91 */
92 ike_sa_id_t *ike_sa_id;
93
94 /**
95 * IKE version of this SA.
96 */
97 ike_version_t version;
98
99 /**
100 * unique numerical ID for this IKE_SA.
101 */
102 u_int32_t unique_id;
103
104 /**
105 * Current state of the IKE_SA
106 */
107 ike_sa_state_t state;
108
109 /**
110 * IKE configuration used to set up this IKE_SA
111 */
112 ike_cfg_t *ike_cfg;
113
114 /**
115 * Peer and authentication information to establish IKE_SA.
116 */
117 peer_cfg_t *peer_cfg;
118
119 /**
120 * currently used authentication ruleset, local (as auth_cfg_t)
121 */
122 auth_cfg_t *my_auth;
123
124 /**
125 * list of completed local authentication rounds
126 */
127 linked_list_t *my_auths;
128
129 /**
130 * list of completed remote authentication rounds
131 */
132 linked_list_t *other_auths;
133
134 /**
135 * currently used authentication constraints, remote (as auth_cfg_t)
136 */
137 auth_cfg_t *other_auth;
138
139 /**
140 * Selected IKE proposal
141 */
142 proposal_t *proposal;
143
144 /**
145 * Juggles tasks to process messages
146 */
147 task_manager_t *task_manager;
148
149 /**
150 * Address of local host
151 */
152 host_t *my_host;
153
154 /**
155 * Address of remote host
156 */
157 host_t *other_host;
158
159 #ifdef ME
160 /**
161 * Are we mediation server
162 */
163 bool is_mediation_server;
164
165 /**
166 * Server reflexive host
167 */
168 host_t *server_reflexive_host;
169
170 /**
171 * Connect ID
172 */
173 chunk_t connect_id;
174 #endif /* ME */
175
176 /**
177 * Identification used for us
178 */
179 identification_t *my_id;
180
181 /**
182 * Identification used for other
183 */
184 identification_t *other_id;
185
186 /**
187 * set of extensions the peer supports
188 */
189 ike_extension_t extensions;
190
191 /**
192 * set of condition flags currently enabled for this IKE_SA
193 */
194 ike_condition_t conditions;
195
196 /**
197 * Linked List containing the child sa's of the current IKE_SA.
198 */
199 linked_list_t *child_sas;
200
201 /**
202 * keymat of this IKE_SA
203 */
204 keymat_t *keymat;
205
206 /**
207 * Virtual IP on local host, if any
208 */
209 host_t *my_virtual_ip;
210
211 /**
212 * Virtual IP on remote host, if any
213 */
214 host_t *other_virtual_ip;
215
216 /**
217 * List of configuration attributes (attribute_entry_t)
218 */
219 linked_list_t *attributes;
220
221 /**
222 * list of peers additional addresses, transmitted via MOBIKE
223 */
224 linked_list_t *additional_addresses;
225
226 /**
227 * previously value of received DESTINATION_IP hash
228 */
229 chunk_t nat_detection_dest;
230
231 /**
232 * number pending UPDATE_SA_ADDRESS (MOBIKE)
233 */
234 u_int32_t pending_updates;
235
236 /**
237 * NAT keep alive interval
238 */
239 u_int32_t keepalive_interval;
240
241 /**
242 * Timestamps for this IKE_SA
243 */
244 u_int32_t stats[STAT_MAX];
245
246 /**
247 * how many times we have retried so far (keyingtries)
248 */
249 u_int32_t keyingtry;
250
251 /**
252 * local host address to be used for IKE, set via MIGRATE kernel message
253 */
254 host_t *local_host;
255
256 /**
257 * remote host address to be used for IKE, set via MIGRATE kernel message
258 */
259 host_t *remote_host;
260
261 /**
262 * Flush auth configs once established?
263 */
264 bool flush_auth_cfg;
265 };
266
267 /**
268 * Entry to maintain install configuration attributes during IKE_SA lifetime
269 */
270 struct attribute_entry_t {
271 /** handler used to install this attribute */
272 attribute_handler_t *handler;
273 /** attribute type */
274 configuration_attribute_type_t type;
275 /** attribute data */
276 chunk_t data;
277 };
278
279 /**
280 * get the time of the latest traffic processed by the kernel
281 */
282 static time_t get_use_time(private_ike_sa_t* this, bool inbound)
283 {
284 enumerator_t *enumerator;
285 child_sa_t *child_sa;
286 time_t use_time, current;
287
288 if (inbound)
289 {
290 use_time = this->stats[STAT_INBOUND];
291 }
292 else
293 {
294 use_time = this->stats[STAT_OUTBOUND];
295 }
296 enumerator = this->child_sas->create_enumerator(this->child_sas);
297 while (enumerator->enumerate(enumerator, &child_sa))
298 {
299 child_sa->get_usestats(child_sa, inbound, &current, NULL);
300 use_time = max(use_time, current);
301 }
302 enumerator->destroy(enumerator);
303
304 return use_time;
305 }
306
307 METHOD(ike_sa_t, get_unique_id, u_int32_t,
308 private_ike_sa_t *this)
309 {
310 return this->unique_id;
311 }
312
313 METHOD(ike_sa_t, get_name, char*,
314 private_ike_sa_t *this)
315 {
316 if (this->peer_cfg)
317 {
318 return this->peer_cfg->get_name(this->peer_cfg);
319 }
320 return "(unnamed)";
321 }
322
323 METHOD(ike_sa_t, get_statistic, u_int32_t,
324 private_ike_sa_t *this, statistic_t kind)
325 {
326 if (kind < STAT_MAX)
327 {
328 return this->stats[kind];
329 }
330 return 0;
331 }
332
333 METHOD(ike_sa_t, set_statistic, void,
334 private_ike_sa_t *this, statistic_t kind, u_int32_t value)
335 {
336 if (kind < STAT_MAX)
337 {
338 this->stats[kind] = value;
339 }
340 }
341
342 METHOD(ike_sa_t, get_my_host, host_t*,
343 private_ike_sa_t *this)
344 {
345 return this->my_host;
346 }
347
348 METHOD(ike_sa_t, set_my_host, void,
349 private_ike_sa_t *this, host_t *me)
350 {
351 DESTROY_IF(this->my_host);
352 this->my_host = me;
353 }
354
355 METHOD(ike_sa_t, get_other_host, host_t*,
356 private_ike_sa_t *this)
357 {
358 return this->other_host;
359 }
360
361 METHOD(ike_sa_t, set_other_host, void,
362 private_ike_sa_t *this, host_t *other)
363 {
364 DESTROY_IF(this->other_host);
365 this->other_host = other;
366 }
367
368 METHOD(ike_sa_t, get_peer_cfg, peer_cfg_t*,
369 private_ike_sa_t *this)
370 {
371 return this->peer_cfg;
372 }
373
374 METHOD(ike_sa_t, set_peer_cfg, void,
375 private_ike_sa_t *this, peer_cfg_t *peer_cfg)
376 {
377 peer_cfg->get_ref(peer_cfg);
378 DESTROY_IF(this->peer_cfg);
379 this->peer_cfg = peer_cfg;
380
381 if (this->ike_cfg == NULL)
382 {
383 this->ike_cfg = peer_cfg->get_ike_cfg(peer_cfg);
384 this->ike_cfg->get_ref(this->ike_cfg);
385 }
386 }
387
388 METHOD(ike_sa_t, get_auth_cfg, auth_cfg_t*,
389 private_ike_sa_t *this, bool local)
390 {
391 if (local)
392 {
393 return this->my_auth;
394 }
395 return this->other_auth;
396 }
397
398 METHOD(ike_sa_t, add_auth_cfg, void,
399 private_ike_sa_t *this, bool local, auth_cfg_t *cfg)
400 {
401 if (local)
402 {
403 this->my_auths->insert_last(this->my_auths, cfg);
404 }
405 else
406 {
407 this->other_auths->insert_last(this->other_auths, cfg);
408 }
409 }
410
411 METHOD(ike_sa_t, create_auth_cfg_enumerator, enumerator_t*,
412 private_ike_sa_t *this, bool local)
413 {
414 if (local)
415 {
416 return this->my_auths->create_enumerator(this->my_auths);
417 }
418 return this->other_auths->create_enumerator(this->other_auths);
419 }
420
421 /**
422 * Flush the stored authentication round information
423 */
424 static void flush_auth_cfgs(private_ike_sa_t *this)
425 {
426 auth_cfg_t *cfg;
427
428 this->my_auth->purge(this->my_auth, FALSE);
429 this->other_auth->purge(this->other_auth, FALSE);
430
431 while (this->my_auths->remove_last(this->my_auths,
432 (void**)&cfg) == SUCCESS)
433 {
434 cfg->destroy(cfg);
435 }
436 while (this->other_auths->remove_last(this->other_auths,
437 (void**)&cfg) == SUCCESS)
438 {
439 cfg->destroy(cfg);
440 }
441 }
442
443 METHOD(ike_sa_t, get_proposal, proposal_t*,
444 private_ike_sa_t *this)
445 {
446 return this->proposal;
447 }
448
449 METHOD(ike_sa_t, set_proposal, void,
450 private_ike_sa_t *this, proposal_t *proposal)
451 {
452 DESTROY_IF(this->proposal);
453 this->proposal = proposal->clone(proposal);
454 }
455
456 METHOD(ike_sa_t, set_message_id, void,
457 private_ike_sa_t *this, bool initiate, u_int32_t mid)
458 {
459 if (initiate)
460 {
461 this->task_manager->reset(this->task_manager, mid, UINT_MAX);
462 }
463 else
464 {
465 this->task_manager->reset(this->task_manager, UINT_MAX, mid);
466 }
467 }
468
469 METHOD(ike_sa_t, send_keepalive, void,
470 private_ike_sa_t *this)
471 {
472 send_keepalive_job_t *job;
473 time_t last_out, now, diff;
474
475 if (!(this->conditions & COND_NAT_HERE) || this->keepalive_interval == 0)
476 { /* disable keep alives if we are not NATed anymore */
477 return;
478 }
479
480 last_out = get_use_time(this, FALSE);
481 now = time_monotonic(NULL);
482
483 diff = now - last_out;
484
485 if (diff >= this->keepalive_interval)
486 {
487 packet_t *packet;
488 chunk_t data;
489
490 packet = packet_create();
491 packet->set_source(packet, this->my_host->clone(this->my_host));
492 packet->set_destination(packet, this->other_host->clone(this->other_host));
493 data.ptr = malloc(1);
494 data.ptr[0] = 0xFF;
495 data.len = 1;
496 packet->set_data(packet, data);
497 DBG1(DBG_IKE, "sending keep alive");
498 charon->sender->send(charon->sender, packet);
499 diff = 0;
500 }
501 job = send_keepalive_job_create(this->ike_sa_id);
502 lib->scheduler->schedule_job(lib->scheduler, (job_t*)job,
503 this->keepalive_interval - diff);
504 }
505
506 METHOD(ike_sa_t, get_ike_cfg, ike_cfg_t*,
507 private_ike_sa_t *this)
508 {
509 return this->ike_cfg;
510 }
511
512 METHOD(ike_sa_t, set_ike_cfg, void,
513 private_ike_sa_t *this, ike_cfg_t *ike_cfg)
514 {
515 ike_cfg->get_ref(ike_cfg);
516 this->ike_cfg = ike_cfg;
517 }
518
519 METHOD(ike_sa_t, enable_extension, void,
520 private_ike_sa_t *this, ike_extension_t extension)
521 {
522 this->extensions |= extension;
523 }
524
525 METHOD(ike_sa_t, supports_extension, bool,
526 private_ike_sa_t *this, ike_extension_t extension)
527 {
528 return (this->extensions & extension) != FALSE;
529 }
530
531 METHOD(ike_sa_t, has_condition, bool,
532 private_ike_sa_t *this, ike_condition_t condition)
533 {
534 return (this->conditions & condition) != FALSE;
535 }
536
537 METHOD(ike_sa_t, set_condition, void,
538 private_ike_sa_t *this, ike_condition_t condition, bool enable)
539 {
540 if (has_condition(this, condition) != enable)
541 {
542 if (enable)
543 {
544 this->conditions |= condition;
545 switch (condition)
546 {
547 case COND_NAT_HERE:
548 DBG1(DBG_IKE, "local host is behind NAT, sending keep alives");
549 this->conditions |= COND_NAT_ANY;
550 send_keepalive(this);
551 break;
552 case COND_NAT_THERE:
553 DBG1(DBG_IKE, "remote host is behind NAT");
554 this->conditions |= COND_NAT_ANY;
555 break;
556 case COND_NAT_FAKE:
557 DBG1(DBG_IKE, "faking NAT situation to enforce UDP encapsulation");
558 this->conditions |= COND_NAT_ANY;
559 break;
560 default:
561 break;
562 }
563 }
564 else
565 {
566 this->conditions &= ~condition;
567 switch (condition)
568 {
569 case COND_NAT_HERE:
570 case COND_NAT_FAKE:
571 case COND_NAT_THERE:
572 set_condition(this, COND_NAT_ANY,
573 has_condition(this, COND_NAT_HERE) ||
574 has_condition(this, COND_NAT_THERE) ||
575 has_condition(this, COND_NAT_FAKE));
576 break;
577 default:
578 break;
579 }
580 }
581 }
582 }
583
584 METHOD(ike_sa_t, send_dpd, status_t,
585 private_ike_sa_t *this)
586 {
587 job_t *job;
588 time_t diff, delay;
589
590 delay = this->peer_cfg->get_dpd(this->peer_cfg);
591 if (this->task_manager->busy(this->task_manager))
592 {
593 /* an exchange is in the air, no need to start a DPD check */
594 diff = 0;
595 }
596 else
597 {
598 /* check if there was any inbound traffic */
599 time_t last_in, now;
600 last_in = get_use_time(this, TRUE);
601 now = time_monotonic(NULL);
602 diff = now - last_in;
603 if (!delay || diff >= delay)
604 {
605 /* to long ago, initiate dead peer detection */
606 DBG1(DBG_IKE, "sending DPD request");
607 this->task_manager->queue_dpd(this->task_manager);
608 diff = 0;
609 }
610 }
611 /* recheck in "interval" seconds */
612 if (delay)
613 {
614 job = (job_t*)send_dpd_job_create(this->ike_sa_id);
615 lib->scheduler->schedule_job(lib->scheduler, job, delay - diff);
616 }
617 return this->task_manager->initiate(this->task_manager);
618 }
619
620 METHOD(ike_sa_t, get_state, ike_sa_state_t,
621 private_ike_sa_t *this)
622 {
623 return this->state;
624 }
625
626 METHOD(ike_sa_t, set_state, void,
627 private_ike_sa_t *this, ike_sa_state_t state)
628 {
629 DBG2(DBG_IKE, "IKE_SA %s[%d] state change: %N => %N",
630 get_name(this), this->unique_id,
631 ike_sa_state_names, this->state,
632 ike_sa_state_names, state);
633
634 switch (state)
635 {
636 case IKE_ESTABLISHED:
637 {
638 if (this->state == IKE_CONNECTING ||
639 this->state == IKE_PASSIVE)
640 {
641 job_t *job;
642 u_int32_t t;
643
644 /* calculate rekey, reauth and lifetime */
645 this->stats[STAT_ESTABLISHED] = time_monotonic(NULL);
646
647 /* schedule rekeying if we have a time which is smaller than
648 * an already scheduled rekeying */
649 t = this->peer_cfg->get_rekey_time(this->peer_cfg, TRUE);
650 if (t && (this->stats[STAT_REKEY] == 0 ||
651 (this->stats[STAT_REKEY] > t + this->stats[STAT_ESTABLISHED])))
652 {
653 this->stats[STAT_REKEY] = t + this->stats[STAT_ESTABLISHED];
654 job = (job_t*)rekey_ike_sa_job_create(this->ike_sa_id, FALSE);
655 lib->scheduler->schedule_job(lib->scheduler, job, t);
656 DBG1(DBG_IKE, "scheduling rekeying in %ds", t);
657 }
658 t = this->peer_cfg->get_reauth_time(this->peer_cfg, TRUE);
659 if (t && (this->stats[STAT_REAUTH] == 0 ||
660 (this->stats[STAT_REAUTH] > t + this->stats[STAT_ESTABLISHED])))
661 {
662 this->stats[STAT_REAUTH] = t + this->stats[STAT_ESTABLISHED];
663 job = (job_t*)rekey_ike_sa_job_create(this->ike_sa_id, TRUE);
664 lib->scheduler->schedule_job(lib->scheduler, job, t);
665 DBG1(DBG_IKE, "scheduling reauthentication in %ds", t);
666 }
667 t = this->peer_cfg->get_over_time(this->peer_cfg);
668 if (this->stats[STAT_REKEY] || this->stats[STAT_REAUTH])
669 {
670 if (this->stats[STAT_REAUTH] == 0)
671 {
672 this->stats[STAT_DELETE] = this->stats[STAT_REKEY];
673 }
674 else if (this->stats[STAT_REKEY] == 0)
675 {
676 this->stats[STAT_DELETE] = this->stats[STAT_REAUTH];
677 }
678 else
679 {
680 this->stats[STAT_DELETE] = min(this->stats[STAT_REKEY],
681 this->stats[STAT_REAUTH]);
682 }
683 this->stats[STAT_DELETE] += t;
684 t = this->stats[STAT_DELETE] - this->stats[STAT_ESTABLISHED];
685 job = (job_t*)delete_ike_sa_job_create(this->ike_sa_id, TRUE);
686 lib->scheduler->schedule_job(lib->scheduler, job, t);
687 DBG1(DBG_IKE, "maximum IKE_SA lifetime %ds", t);
688 }
689
690 /* start DPD checks */
691 if (this->peer_cfg->get_dpd(this->peer_cfg))
692 {
693 send_dpd(this);
694 }
695 }
696 break;
697 }
698 case IKE_DELETING:
699 {
700 /* delete may fail if a packet gets lost, so set a timeout */
701 job_t *job = (job_t*)delete_ike_sa_job_create(this->ike_sa_id, TRUE);
702 lib->scheduler->schedule_job(lib->scheduler, job,
703 HALF_OPEN_IKE_SA_TIMEOUT);
704 break;
705 }
706 default:
707 break;
708 }
709 charon->bus->ike_state_change(charon->bus, &this->public, state);
710 this->state = state;
711 }
712
713 METHOD(ike_sa_t, reset, void,
714 private_ike_sa_t *this)
715 {
716 /* the responder ID is reset, as peer may choose another one */
717 if (this->ike_sa_id->is_initiator(this->ike_sa_id))
718 {
719 this->ike_sa_id->set_responder_spi(this->ike_sa_id, 0);
720 }
721
722 set_state(this, IKE_CREATED);
723
724 flush_auth_cfgs(this);
725
726 this->keymat->destroy(this->keymat);
727 this->keymat = keymat_create(this->version,
728 this->ike_sa_id->is_initiator(this->ike_sa_id));
729
730 this->task_manager->reset(this->task_manager, 0, 0);
731 }
732
733 METHOD(ike_sa_t, get_keymat, keymat_t*,
734 private_ike_sa_t *this)
735 {
736 return this->keymat;
737 }
738
739 METHOD(ike_sa_t, set_virtual_ip, void,
740 private_ike_sa_t *this, bool local, host_t *ip)
741 {
742 if (local)
743 {
744 DBG1(DBG_IKE, "installing new virtual IP %H", ip);
745 if (hydra->kernel_interface->add_ip(hydra->kernel_interface, ip,
746 this->my_host) == SUCCESS)
747 {
748 if (this->my_virtual_ip)
749 {
750 DBG1(DBG_IKE, "removing old virtual IP %H", this->my_virtual_ip);
751 hydra->kernel_interface->del_ip(hydra->kernel_interface,
752 this->my_virtual_ip);
753 }
754 DESTROY_IF(this->my_virtual_ip);
755 this->my_virtual_ip = ip->clone(ip);
756 }
757 else
758 {
759 DBG1(DBG_IKE, "installing virtual IP %H failed", ip);
760 this->my_virtual_ip = NULL;
761 }
762 }
763 else
764 {
765 DESTROY_IF(this->other_virtual_ip);
766 this->other_virtual_ip = ip->clone(ip);
767 }
768 }
769
770 METHOD(ike_sa_t, get_virtual_ip, host_t*,
771 private_ike_sa_t *this, bool local)
772 {
773 if (local)
774 {
775 return this->my_virtual_ip;
776 }
777 else
778 {
779 return this->other_virtual_ip;
780 }
781 }
782
783 METHOD(ike_sa_t, add_additional_address, void,
784 private_ike_sa_t *this, host_t *host)
785 {
786 this->additional_addresses->insert_last(this->additional_addresses, host);
787 }
788
789 METHOD(ike_sa_t, create_additional_address_enumerator, enumerator_t*,
790 private_ike_sa_t *this)
791 {
792 return this->additional_addresses->create_enumerator(
793 this->additional_addresses);
794 }
795
796 METHOD(ike_sa_t, remove_additional_addresses, void,
797 private_ike_sa_t *this)
798 {
799 enumerator_t *enumerator = create_additional_address_enumerator(this);
800 host_t *host;
801 while (enumerator->enumerate(enumerator, (void**)&host))
802 {
803 this->additional_addresses->remove_at(this->additional_addresses,
804 enumerator);
805 host->destroy(host);
806 }
807 enumerator->destroy(enumerator);
808 }
809
810 METHOD(ike_sa_t, has_mapping_changed, bool,
811 private_ike_sa_t *this, chunk_t hash)
812 {
813 if (this->nat_detection_dest.ptr == NULL)
814 {
815 this->nat_detection_dest = chunk_clone(hash);
816 return FALSE;
817 }
818 if (chunk_equals(hash, this->nat_detection_dest))
819 {
820 return FALSE;
821 }
822 free(this->nat_detection_dest.ptr);
823 this->nat_detection_dest = chunk_clone(hash);
824 return TRUE;
825 }
826
827 METHOD(ike_sa_t, set_pending_updates, void,
828 private_ike_sa_t *this, u_int32_t updates)
829 {
830 this->pending_updates = updates;
831 }
832
833 METHOD(ike_sa_t, get_pending_updates, u_int32_t,
834 private_ike_sa_t *this)
835 {
836 return this->pending_updates;
837 }
838
839 METHOD(ike_sa_t, float_ports, void,
840 private_ike_sa_t *this)
841 {
842 /* do not switch if we have a custom port from MOBIKE/NAT */
843 if (this->my_host->get_port(this->my_host) == IKEV2_UDP_PORT)
844 {
845 this->my_host->set_port(this->my_host, IKEV2_NATT_PORT);
846 }
847 if (this->other_host->get_port(this->other_host) == IKEV2_UDP_PORT)
848 {
849 this->other_host->set_port(this->other_host, IKEV2_NATT_PORT);
850 }
851 }
852
853 METHOD(ike_sa_t, update_hosts, void,
854 private_ike_sa_t *this, host_t *me, host_t *other, bool force)
855 {
856 bool update = FALSE;
857
858 if (me == NULL)
859 {
860 me = this->my_host;
861 }
862 if (other == NULL)
863 {
864 other = this->other_host;
865 }
866
867 /* apply hosts on first received message */
868 if (this->my_host->is_anyaddr(this->my_host) ||
869 this->other_host->is_anyaddr(this->other_host))
870 {
871 set_my_host(this, me->clone(me));
872 set_other_host(this, other->clone(other));
873 update = TRUE;
874 }
875 else
876 {
877 /* update our address in any case */
878 if (!me->equals(me, this->my_host))
879 {
880 set_my_host(this, me->clone(me));
881 update = TRUE;
882 }
883
884 if (!other->equals(other, this->other_host))
885 {
886 /* update others address if we are NOT NATed */
887 if (force || !has_condition(this, COND_NAT_HERE))
888 {
889 set_other_host(this, other->clone(other));
890 update = TRUE;
891 }
892 }
893 }
894
895 /* update all associated CHILD_SAs, if required */
896 if (update)
897 {
898 enumerator_t *enumerator;
899 child_sa_t *child_sa;
900
901 enumerator = this->child_sas->create_enumerator(this->child_sas);
902 while (enumerator->enumerate(enumerator, (void**)&child_sa))
903 {
904 if (child_sa->update(child_sa, this->my_host,
905 this->other_host, this->my_virtual_ip,
906 has_condition(this, COND_NAT_ANY)) == NOT_SUPPORTED)
907 {
908 this->public.rekey_child_sa(&this->public,
909 child_sa->get_protocol(child_sa),
910 child_sa->get_spi(child_sa, TRUE));
911 }
912 }
913 enumerator->destroy(enumerator);
914 }
915 }
916
917 METHOD(ike_sa_t, generate_message, status_t,
918 private_ike_sa_t *this, message_t *message, packet_t **packet)
919 {
920 if (message->is_encoded(message))
921 { /* already done */
922 *packet = message->get_packet(message);
923 return SUCCESS;
924 }
925 this->stats[STAT_OUTBOUND] = time_monotonic(NULL);
926 message->set_ike_sa_id(message, this->ike_sa_id);
927 charon->bus->message(charon->bus, message, FALSE);
928 return message->generate(message, this->keymat, packet);
929 }
930
931 METHOD(ike_sa_t, set_kmaddress, void,
932 private_ike_sa_t *this, host_t *local, host_t *remote)
933 {
934 DESTROY_IF(this->local_host);
935 DESTROY_IF(this->remote_host);
936 this->local_host = local->clone(local);
937 this->remote_host = remote->clone(remote);
938 }
939
940 #ifdef ME
941 METHOD(ike_sa_t, act_as_mediation_server, void,
942 private_ike_sa_t *this)
943 {
944 charon->mediation_manager->update_sa_id(charon->mediation_manager,
945 this->other_id, this->ike_sa_id);
946 this->is_mediation_server = TRUE;
947 }
948
949 METHOD(ike_sa_t, get_server_reflexive_host, host_t*,
950 private_ike_sa_t *this)
951 {
952 return this->server_reflexive_host;
953 }
954
955 METHOD(ike_sa_t, set_server_reflexive_host, void,
956 private_ike_sa_t *this, host_t *host)
957 {
958 DESTROY_IF(this->server_reflexive_host);
959 this->server_reflexive_host = host;
960 }
961
962 METHOD(ike_sa_t, get_connect_id, chunk_t,
963 private_ike_sa_t *this)
964 {
965 return this->connect_id;
966 }
967
968 METHOD(ike_sa_t, respond, status_t,
969 private_ike_sa_t *this, identification_t *peer_id, chunk_t connect_id)
970 {
971 ike_me_t *task = ike_me_create(&this->public, TRUE);
972 task->respond(task, peer_id, connect_id);
973 this->task_manager->queue_task(this->task_manager, (task_t*)task);
974 return this->task_manager->initiate(this->task_manager);
975 }
976
977 METHOD(ike_sa_t, callback, status_t,
978 private_ike_sa_t *this, identification_t *peer_id)
979 {
980 ike_me_t *task = ike_me_create(&this->public, TRUE);
981 task->callback(task, peer_id);
982 this->task_manager->queue_task(this->task_manager, (task_t*)task);
983 return this->task_manager->initiate(this->task_manager);
984 }
985
986 METHOD(ike_sa_t, relay, status_t,
987 private_ike_sa_t *this, identification_t *requester, chunk_t connect_id,
988 chunk_t connect_key, linked_list_t *endpoints, bool response)
989 {
990 ike_me_t *task = ike_me_create(&this->public, TRUE);
991 task->relay(task, requester, connect_id, connect_key, endpoints, response);
992 this->task_manager->queue_task(this->task_manager, (task_t*)task);
993 return this->task_manager->initiate(this->task_manager);
994 }
995
996 METHOD(ike_sa_t, initiate_mediation, status_t,
997 private_ike_sa_t *this, peer_cfg_t *mediated_cfg)
998 {
999 ike_me_t *task = ike_me_create(&this->public, TRUE);
1000 task->connect(task, mediated_cfg->get_peer_id(mediated_cfg));
1001 this->task_manager->queue_task(this->task_manager, (task_t*)task);
1002 return this->task_manager->initiate(this->task_manager);
1003 }
1004
1005 METHOD(ike_sa_t, initiate_mediated, status_t,
1006 private_ike_sa_t *this, host_t *me, host_t *other, chunk_t connect_id)
1007 {
1008 set_my_host(this, me->clone(me));
1009 set_other_host(this, other->clone(other));
1010 chunk_free(&this->connect_id);
1011 this->connect_id = chunk_clone(connect_id);
1012 return this->task_manager->initiate(this->task_manager);
1013 }
1014 #endif /* ME */
1015
1016 /**
1017 * Resolve DNS host in configuration
1018 */
1019 static void resolve_hosts(private_ike_sa_t *this)
1020 {
1021 host_t *host;
1022
1023 if (this->remote_host)
1024 {
1025 host = this->remote_host->clone(this->remote_host);
1026 host->set_port(host, IKEV2_UDP_PORT);
1027 }
1028 else
1029 {
1030 host = host_create_from_dns(this->ike_cfg->get_other_addr(this->ike_cfg),
1031 0, this->ike_cfg->get_other_port(this->ike_cfg));
1032 }
1033 if (host)
1034 {
1035 set_other_host(this, host);
1036 }
1037
1038 if (this->local_host)
1039 {
1040 host = this->local_host->clone(this->local_host);
1041 host->set_port(host, IKEV2_UDP_PORT);
1042 }
1043 else
1044 {
1045 int family = 0;
1046
1047 /* use same address family as for other */
1048 if (!this->other_host->is_anyaddr(this->other_host))
1049 {
1050 family = this->other_host->get_family(this->other_host);
1051 }
1052 host = host_create_from_dns(this->ike_cfg->get_my_addr(this->ike_cfg),
1053 family, this->ike_cfg->get_my_port(this->ike_cfg));
1054
1055 if (host && host->is_anyaddr(host) &&
1056 !this->other_host->is_anyaddr(this->other_host))
1057 {
1058 host->destroy(host);
1059 host = hydra->kernel_interface->get_source_addr(
1060 hydra->kernel_interface, this->other_host, NULL);
1061 if (host)
1062 {
1063 host->set_port(host, this->ike_cfg->get_my_port(this->ike_cfg));
1064 }
1065 else
1066 { /* fallback to address family specific %any(6), if configured */
1067 host = host_create_from_dns(
1068 this->ike_cfg->get_my_addr(this->ike_cfg),
1069 0, this->ike_cfg->get_my_port(this->ike_cfg));
1070 }
1071 }
1072 }
1073 if (host)
1074 {
1075 set_my_host(this, host);
1076 }
1077 }
1078
1079 METHOD(ike_sa_t, initiate, status_t,
1080 private_ike_sa_t *this, child_cfg_t *child_cfg, u_int32_t reqid,
1081 traffic_selector_t *tsi, traffic_selector_t *tsr)
1082 {
1083 task_t *task;
1084
1085 if (this->state == IKE_CREATED)
1086 {
1087 resolve_hosts(this);
1088
1089 if (this->other_host->is_anyaddr(this->other_host)
1090 #ifdef ME
1091 && !this->peer_cfg->get_mediated_by(this->peer_cfg)
1092 #endif /* ME */
1093 )
1094 {
1095 child_cfg->destroy(child_cfg);
1096 DBG1(DBG_IKE, "unable to initiate to %%any");
1097 charon->bus->alert(charon->bus, ALERT_PEER_ADDR_FAILED);
1098 return DESTROY_ME;
1099 }
1100
1101 set_condition(this, COND_ORIGINAL_INITIATOR, TRUE);
1102
1103 if (this->version == IKEV1)
1104 {
1105 task = (task_t*)isakmp_vendor_create(&this->public, TRUE);
1106 this->task_manager->queue_task(this->task_manager, task);
1107 task = (task_t*)isakmp_cert_pre_create(&this->public, TRUE);
1108 this->task_manager->queue_task(this->task_manager, task);
1109 task = (task_t*)main_mode_create(&this->public, TRUE);
1110 this->task_manager->queue_task(this->task_manager, task);
1111 task = (task_t*)isakmp_cert_post_create(&this->public, TRUE);
1112 this->task_manager->queue_task(this->task_manager, task);
1113 task = (task_t*)isakmp_natd_create(&this->public, TRUE);
1114 this->task_manager->queue_task(this->task_manager, task);
1115 }
1116 else
1117 {
1118 task = (task_t*)ike_vendor_create(&this->public, TRUE);
1119 this->task_manager->queue_task(this->task_manager, task);
1120 task = (task_t*)ike_init_create(&this->public, TRUE, NULL);
1121 this->task_manager->queue_task(this->task_manager, task);
1122 task = (task_t*)ike_natd_create(&this->public, TRUE);
1123 this->task_manager->queue_task(this->task_manager, task);
1124 task = (task_t*)ike_cert_pre_create(&this->public, TRUE);
1125 this->task_manager->queue_task(this->task_manager, task);
1126 task = (task_t*)ike_auth_create(&this->public, TRUE);
1127 this->task_manager->queue_task(this->task_manager, task);
1128 task = (task_t*)ike_cert_post_create(&this->public, TRUE);
1129 this->task_manager->queue_task(this->task_manager, task);
1130 task = (task_t*)ike_config_create(&this->public, TRUE);
1131 this->task_manager->queue_task(this->task_manager, task);
1132 task = (task_t*)ike_auth_lifetime_create(&this->public, TRUE);
1133 this->task_manager->queue_task(this->task_manager, task);
1134 if (this->peer_cfg->use_mobike(this->peer_cfg))
1135 {
1136 task = (task_t*)ike_mobike_create(&this->public, TRUE);
1137 this->task_manager->queue_task(this->task_manager, task);
1138 }
1139 #ifdef ME
1140 task = (task_t*)ike_me_create(&this->public, TRUE);
1141 this->task_manager->queue_task(this->task_manager, task);
1142 #endif /* ME */
1143 }
1144 }
1145
1146 #ifdef ME
1147 if (this->peer_cfg->is_mediation(this->peer_cfg))
1148 {
1149 if (this->state == IKE_ESTABLISHED)
1150 {
1151 /* mediation connection is already established, retrigger state
1152 * change to notify bus listeners */
1153 DBG1(DBG_IKE, "mediation connection is already up");
1154 set_state(this, IKE_ESTABLISHED);
1155 }
1156 DESTROY_IF(child_cfg);
1157 }
1158 else
1159 #endif /* ME */
1160 {
1161 /* normal IKE_SA with CHILD_SA */
1162 if (this->version == IKEV2)
1163 {
1164 task = (task_t*)child_create_create(&this->public, child_cfg, FALSE,
1165 tsi, tsr);
1166 if (reqid)
1167 {
1168 child_create_t *child_create = (child_create_t*)task;
1169 child_create->use_reqid(child_create, reqid);
1170 }
1171 }
1172 else
1173 {
1174 task = (task_t*)quick_mode_create(&this->public, child_cfg,
1175 tsi, tsr);
1176 }
1177 this->task_manager->queue_task(this->task_manager, task);
1178
1179 #ifdef ME
1180 if (this->peer_cfg->get_mediated_by(this->peer_cfg))
1181 {
1182 /* mediated connection, initiate mediation process */
1183 job_t *job = (job_t*)initiate_mediation_job_create(this->ike_sa_id);
1184 lib->processor->queue_job(lib->processor, job);
1185 return SUCCESS;
1186 }
1187 #endif /* ME */
1188 }
1189
1190 return this->task_manager->initiate(this->task_manager);
1191 }
1192
1193 METHOD(ike_sa_t, process_message, status_t,
1194 private_ike_sa_t *this, message_t *message)
1195 {
1196 status_t status;
1197
1198 if (this->state == IKE_PASSIVE)
1199 { /* do not handle messages in passive state */
1200 return FAILED;
1201 }
1202 status = this->task_manager->process_message(this->task_manager, message);
1203 if (this->flush_auth_cfg && this->state == IKE_ESTABLISHED)
1204 {
1205 /* authentication completed */
1206 this->flush_auth_cfg = FALSE;
1207 flush_auth_cfgs(this);
1208 }
1209 return status;
1210 }
1211
1212 METHOD(ike_sa_t, get_id, ike_sa_id_t*,
1213 private_ike_sa_t *this)
1214 {
1215 return this->ike_sa_id;
1216 }
1217
1218 METHOD(ike_sa_t, get_version, ike_version_t,
1219 private_ike_sa_t *this)
1220 {
1221 return this->version;
1222 }
1223
1224 METHOD(ike_sa_t, get_my_id, identification_t*,
1225 private_ike_sa_t *this)
1226 {
1227 return this->my_id;
1228 }
1229
1230 METHOD(ike_sa_t, set_my_id, void,
1231 private_ike_sa_t *this, identification_t *me)
1232 {
1233 DESTROY_IF(this->my_id);
1234 this->my_id = me;
1235 }
1236
1237 METHOD(ike_sa_t, get_other_id, identification_t*,
1238 private_ike_sa_t *this)
1239 {
1240 return this->other_id;
1241 }
1242
1243 METHOD(ike_sa_t, get_other_eap_id, identification_t*,
1244 private_ike_sa_t *this)
1245 {
1246 identification_t *id = NULL, *current;
1247 enumerator_t *enumerator;
1248 auth_cfg_t *cfg;
1249
1250 enumerator = this->other_auths->create_enumerator(this->other_auths);
1251 while (enumerator->enumerate(enumerator, &cfg))
1252 {
1253 /* prefer EAP-Identity of last round */
1254 current = cfg->get(cfg, AUTH_RULE_EAP_IDENTITY);
1255 if (!current || current->get_type(current) == ID_ANY)
1256 {
1257 current = cfg->get(cfg, AUTH_RULE_IDENTITY);
1258 }
1259 if (current && current->get_type(current) != ID_ANY)
1260 {
1261 id = current;
1262 continue;
1263 }
1264 }
1265 enumerator->destroy(enumerator);
1266 if (id)
1267 {
1268 return id;
1269 }
1270 return this->other_id;
1271 }
1272
1273 METHOD(ike_sa_t, set_other_id, void,
1274 private_ike_sa_t *this, identification_t *other)
1275 {
1276 DESTROY_IF(this->other_id);
1277 this->other_id = other;
1278 }
1279
1280 METHOD(ike_sa_t, add_child_sa, void,
1281 private_ike_sa_t *this, child_sa_t *child_sa)
1282 {
1283 this->child_sas->insert_last(this->child_sas, child_sa);
1284 }
1285
1286 METHOD(ike_sa_t, get_child_sa, child_sa_t*,
1287 private_ike_sa_t *this, protocol_id_t protocol, u_int32_t spi, bool inbound)
1288 {
1289 enumerator_t *enumerator;
1290 child_sa_t *current, *found = NULL;
1291
1292 enumerator = this->child_sas->create_enumerator(this->child_sas);
1293 while (enumerator->enumerate(enumerator, (void**)&current))
1294 {
1295 if (current->get_spi(current, inbound) == spi &&
1296 current->get_protocol(current) == protocol)
1297 {
1298 found = current;
1299 }
1300 }
1301 enumerator->destroy(enumerator);
1302 return found;
1303 }
1304
1305 METHOD(ike_sa_t, get_child_count, int,
1306 private_ike_sa_t *this)
1307 {
1308 return this->child_sas->get_count(this->child_sas);
1309 }
1310
1311 METHOD(ike_sa_t, create_child_sa_enumerator, enumerator_t*,
1312 private_ike_sa_t *this)
1313 {
1314 return this->child_sas->create_enumerator(this->child_sas);
1315 }
1316
1317 METHOD(ike_sa_t, remove_child_sa, void,
1318 private_ike_sa_t *this, enumerator_t *enumerator)
1319 {
1320 this->child_sas->remove_at(this->child_sas, enumerator);
1321 }
1322
1323 METHOD(ike_sa_t, rekey_child_sa, status_t,
1324 private_ike_sa_t *this, protocol_id_t protocol, u_int32_t spi)
1325 {
1326 child_rekey_t *child_rekey;
1327
1328 child_rekey = child_rekey_create(&this->public, protocol, spi);
1329 this->task_manager->queue_task(this->task_manager, &child_rekey->task);
1330 return this->task_manager->initiate(this->task_manager);
1331 }
1332
1333 METHOD(ike_sa_t, delete_child_sa, status_t,
1334 private_ike_sa_t *this, protocol_id_t protocol, u_int32_t spi)
1335 {
1336 task_t *task;
1337
1338 if (this->version == IKEV1)
1339 {
1340 task = (task_t*)quick_delete_create(&this->public, protocol, spi, FALSE);
1341 }
1342 else
1343 {
1344 task = (task_t*)child_delete_create(&this->public, protocol, spi);
1345 }
1346 this->task_manager->queue_task(this->task_manager, task);
1347 return this->task_manager->initiate(this->task_manager);
1348 }
1349
1350 METHOD(ike_sa_t, destroy_child_sa, status_t,
1351 private_ike_sa_t *this, protocol_id_t protocol, u_int32_t spi)
1352 {
1353 enumerator_t *enumerator;
1354 child_sa_t *child_sa;
1355 status_t status = NOT_FOUND;
1356
1357 enumerator = this->child_sas->create_enumerator(this->child_sas);
1358 while (enumerator->enumerate(enumerator, (void**)&child_sa))
1359 {
1360 if (child_sa->get_protocol(child_sa) == protocol &&
1361 child_sa->get_spi(child_sa, TRUE) == spi)
1362 {
1363 this->child_sas->remove_at(this->child_sas, enumerator);
1364 child_sa->destroy(child_sa);
1365 status = SUCCESS;
1366 break;
1367 }
1368 }
1369 enumerator->destroy(enumerator);
1370 return status;
1371 }
1372
1373 METHOD(ike_sa_t, delete_, status_t,
1374 private_ike_sa_t *this)
1375 {
1376 task_t *task;
1377
1378 switch (this->state)
1379 {
1380 case IKE_ESTABLISHED:
1381 case IKE_REKEYING:
1382 if (this->version == IKEV1)
1383 {
1384 task = (task_t*)isakmp_delete_create(&this->public, TRUE);
1385 }
1386 else
1387 {
1388 task = (task_t*)ike_delete_create(&this->public, TRUE);
1389 }
1390 this->task_manager->queue_task(this->task_manager, task);
1391 return this->task_manager->initiate(this->task_manager);
1392 case IKE_CREATED:
1393 DBG1(DBG_IKE, "deleting unestablished IKE_SA");
1394 break;
1395 case IKE_PASSIVE:
1396 break;
1397 default:
1398 DBG1(DBG_IKE, "destroying IKE_SA in state %N "
1399 "without notification", ike_sa_state_names, this->state);
1400 charon->bus->ike_updown(charon->bus, &this->public, FALSE);
1401 break;
1402 }
1403 return DESTROY_ME;
1404 }
1405
1406 METHOD(ike_sa_t, rekey, status_t,
1407 private_ike_sa_t *this)
1408 {
1409 ike_rekey_t *ike_rekey;
1410
1411 ike_rekey = ike_rekey_create(&this->public, TRUE);
1412
1413 this->task_manager->queue_task(this->task_manager, &ike_rekey->task);
1414 return this->task_manager->initiate(this->task_manager);
1415 }
1416
1417 METHOD(ike_sa_t, reauth, status_t,
1418 private_ike_sa_t *this)
1419 {
1420 task_t *task;
1421
1422 /* we can't reauthenticate as responder when we use EAP or virtual IPs.
1423 * If the peer does not support RFC4478, there is no way to keep the
1424 * IKE_SA up. */
1425 if (!has_condition(this, COND_ORIGINAL_INITIATOR))
1426 {
1427 DBG1(DBG_IKE, "initiator did not reauthenticate as requested");
1428 if (this->other_virtual_ip != NULL ||
1429 has_condition(this, COND_EAP_AUTHENTICATED)
1430 #ifdef ME
1431 /* as mediation server we too cannot reauth the IKE_SA */
1432 || this->is_mediation_server
1433 #endif /* ME */
1434 )
1435 {
1436 time_t now = time_monotonic(NULL);
1437
1438 DBG1(DBG_IKE, "IKE_SA will timeout in %V",
1439 &now, &this->stats[STAT_DELETE]);
1440 return FAILED;
1441 }
1442 else
1443 {
1444 DBG1(DBG_IKE, "reauthenticating actively");
1445 }
1446 }
1447 task = (task_t*)ike_reauth_create(&this->public);
1448 this->task_manager->queue_task(this->task_manager, task);
1449
1450 return this->task_manager->initiate(this->task_manager);
1451 }
1452
1453 METHOD(ike_sa_t, reestablish, status_t,
1454 private_ike_sa_t *this)
1455 {
1456 ike_sa_t *new;
1457 host_t *host;
1458 action_t action;
1459 enumerator_t *enumerator;
1460 child_sa_t *child_sa;
1461 child_cfg_t *child_cfg;
1462 bool restart = FALSE;
1463 status_t status = FAILED;
1464
1465 /* check if we have children to keep up at all */
1466 enumerator = this->child_sas->create_enumerator(this->child_sas);
1467 while (enumerator->enumerate(enumerator, (void**)&child_sa))
1468 {
1469 if (this->state == IKE_DELETING)
1470 {
1471 action = child_sa->get_close_action(child_sa);
1472 }
1473 else
1474 {
1475 action = child_sa->get_dpd_action(child_sa);
1476 }
1477 switch (action)
1478 {
1479 case ACTION_RESTART:
1480 restart = TRUE;
1481 break;
1482 case ACTION_ROUTE:
1483 charon->traps->install(charon->traps, this->peer_cfg,
1484 child_sa->get_config(child_sa));
1485 break;
1486 default:
1487 break;
1488 }
1489 }
1490 enumerator->destroy(enumerator);
1491 #ifdef ME
1492 /* mediation connections have no children, keep them up anyway */
1493 if (this->peer_cfg->is_mediation(this->peer_cfg))
1494 {
1495 restart = TRUE;
1496 }
1497 #endif /* ME */
1498 if (!restart)
1499 {
1500 return FAILED;
1501 }
1502
1503 /* check if we are able to reestablish this IKE_SA */
1504 if (!has_condition(this, COND_ORIGINAL_INITIATOR) &&
1505 (this->other_virtual_ip != NULL ||
1506 has_condition(this, COND_EAP_AUTHENTICATED)
1507 #ifdef ME
1508 || this->is_mediation_server
1509 #endif /* ME */
1510 ))
1511 {
1512 DBG1(DBG_IKE, "unable to reestablish IKE_SA due to asymmetric setup");
1513 return FAILED;
1514 }
1515
1516 new = charon->ike_sa_manager->checkout_new(charon->ike_sa_manager,
1517 this->version, TRUE);
1518 new->set_peer_cfg(new, this->peer_cfg);
1519 host = this->other_host;
1520 new->set_other_host(new, host->clone(host));
1521 host = this->my_host;
1522 new->set_my_host(new, host->clone(host));
1523 /* if we already have a virtual IP, we reuse it */
1524 host = this->my_virtual_ip;
1525 if (host)
1526 {
1527 new->set_virtual_ip(new, TRUE, host);
1528 }
1529
1530 #ifdef ME
1531 if (this->peer_cfg->is_mediation(this->peer_cfg))
1532 {
1533 status = new->initiate(new, NULL, 0, NULL, NULL);
1534 }
1535 else
1536 #endif /* ME */
1537 {
1538 enumerator = this->child_sas->create_enumerator(this->child_sas);
1539 while (enumerator->enumerate(enumerator, (void**)&child_sa))
1540 {
1541 if (this->state == IKE_DELETING)
1542 {
1543 action = child_sa->get_close_action(child_sa);
1544 }
1545 else
1546 {
1547 action = child_sa->get_dpd_action(child_sa);
1548 }
1549 switch (action)
1550 {
1551 case ACTION_RESTART:
1552 child_cfg = child_sa->get_config(child_sa);
1553 DBG1(DBG_IKE, "restarting CHILD_SA %s",
1554 child_cfg->get_name(child_cfg));
1555 child_cfg->get_ref(child_cfg);
1556 status = new->initiate(new, child_cfg, 0, NULL, NULL);
1557 break;
1558 default:
1559 continue;
1560 }
1561 if (status == DESTROY_ME)
1562 {
1563 break;
1564 }
1565 }
1566 enumerator->destroy(enumerator);
1567 }
1568
1569 if (status == DESTROY_ME)
1570 {
1571 charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager, new);
1572 status = FAILED;
1573 }
1574 else
1575 {
1576 charon->ike_sa_manager->checkin(charon->ike_sa_manager, new);
1577 status = SUCCESS;
1578 }
1579 charon->bus->set_sa(charon->bus, &this->public);
1580 return status;
1581 }
1582
1583 /**
1584 * Requeue the IKE_SA_INIT tasks for initiation, if required
1585 */
1586 static void requeue_init_tasks(private_ike_sa_t *this)
1587 {
1588 enumerator_t *enumerator;
1589 bool has_init = FALSE;
1590 task_t *task;
1591
1592 /* if we have advanced to IKE_AUTH, the IKE_INIT and related tasks
1593 * have already completed. Recreate them if necessary. */
1594 enumerator = this->task_manager->create_task_enumerator(
1595 this->task_manager, TASK_QUEUE_QUEUED);
1596 while (enumerator->enumerate(enumerator, &task))
1597 {
1598 if (task->get_type(task) == TASK_IKE_INIT)
1599 {
1600 has_init = TRUE;
1601 break;
1602 }
1603 }
1604 enumerator->destroy(enumerator);
1605
1606 if (!has_init)
1607 {
1608 task = (task_t*)ike_vendor_create(&this->public, TRUE);
1609 this->task_manager->queue_task(this->task_manager, task);
1610 task = (task_t*)ike_natd_create(&this->public, TRUE);
1611 this->task_manager->queue_task(this->task_manager, task);
1612 task = (task_t*)ike_init_create(&this->public, TRUE, NULL);
1613 this->task_manager->queue_task(this->task_manager, task);
1614 }
1615 }
1616
1617 METHOD(ike_sa_t, retransmit, status_t,
1618 private_ike_sa_t *this, u_int32_t message_id)
1619 {
1620 this->stats[STAT_OUTBOUND] = time_monotonic(NULL);
1621 if (this->task_manager->retransmit(this->task_manager, message_id) != SUCCESS)
1622 {
1623 /* send a proper signal to brief interested bus listeners */
1624 switch (this->state)
1625 {
1626 case IKE_CONNECTING:
1627 {
1628 /* retry IKE_SA_INIT if we have multiple keyingtries */
1629 u_int32_t tries = this->peer_cfg->get_keyingtries(this->peer_cfg);
1630 this->keyingtry++;
1631 if (tries == 0 || tries > this->keyingtry)
1632 {
1633 DBG1(DBG_IKE, "peer not responding, trying again (%d/%d)",
1634 this->keyingtry + 1, tries);
1635 reset(this);
1636 requeue_init_tasks(this);
1637 return this->task_manager->initiate(this->task_manager);
1638 }
1639 DBG1(DBG_IKE, "establishing IKE_SA failed, peer not responding");
1640 break;
1641 }
1642 case IKE_DELETING:
1643 DBG1(DBG_IKE, "proper IKE_SA delete failed, peer not responding");
1644 break;
1645 case IKE_REKEYING:
1646 DBG1(DBG_IKE, "rekeying IKE_SA failed, peer not responding");
1647 /* FALL */
1648 default:
1649 reestablish(this);
1650 break;
1651 }
1652 return DESTROY_ME;
1653 }
1654 return SUCCESS;
1655 }
1656
1657 METHOD(ike_sa_t, set_auth_lifetime, void,
1658 private_ike_sa_t *this, u_int32_t lifetime)
1659 {
1660 u_int32_t reduction = this->peer_cfg->get_over_time(this->peer_cfg);
1661 u_int32_t reauth_time = time_monotonic(NULL) + lifetime - reduction;
1662
1663 if (lifetime < reduction)
1664 {
1665 DBG1(DBG_IKE, "received AUTH_LIFETIME of %ds, starting reauthentication",
1666 lifetime);
1667 lib->processor->queue_job(lib->processor,
1668 (job_t*)rekey_ike_sa_job_create(this->ike_sa_id, TRUE));
1669 }
1670 else if (this->stats[STAT_REAUTH] == 0 ||
1671 this->stats[STAT_REAUTH] > reauth_time)
1672 {
1673 this->stats[STAT_REAUTH] = reauth_time;
1674 DBG1(DBG_IKE, "received AUTH_LIFETIME of %ds, scheduling reauthentication"
1675 " in %ds", lifetime, lifetime - reduction);
1676 lib->scheduler->schedule_job(lib->scheduler,
1677 (job_t*)rekey_ike_sa_job_create(this->ike_sa_id, TRUE),
1678 lifetime - reduction);
1679 }
1680 else
1681 {
1682 DBG1(DBG_IKE, "received AUTH_LIFETIME of %ds, "
1683 "reauthentication already scheduled in %ds", lifetime,
1684 this->stats[STAT_REAUTH] - time_monotonic(NULL));
1685 }
1686 }
1687
1688 /**
1689 * Check if the current combination of source and destination address is still
1690 * valid.
1691 */
1692 static bool is_current_path_valid(private_ike_sa_t *this)
1693 {
1694 bool valid = FALSE;
1695 host_t *src;
1696 src = hydra->kernel_interface->get_source_addr(hydra->kernel_interface,
1697 this->other_host, this->my_host);
1698 if (src)
1699 {
1700 if (src->ip_equals(src, this->my_host))
1701 {
1702 valid = TRUE;
1703 }
1704 src->destroy(src);
1705 }
1706 return valid;
1707 }
1708
1709 /**
1710 * Check if we have any path avialable for this IKE SA.
1711 */
1712 static bool is_any_path_valid(private_ike_sa_t *this)
1713 {
1714 bool valid = FALSE;
1715 enumerator_t *enumerator;
1716 host_t *src, *addr;
1717 DBG1(DBG_IKE, "old path is not available anymore, try to find another");
1718 src = hydra->kernel_interface->get_source_addr(hydra->kernel_interface,
1719 this->other_host, NULL);
1720 if (!src)
1721 {
1722 enumerator = this->additional_addresses->create_enumerator(
1723 this->additional_addresses);
1724 while (enumerator->enumerate(enumerator, &addr))
1725 {
1726 DBG1(DBG_IKE, "looking for a route to %H ...", addr);
1727 src = hydra->kernel_interface->get_source_addr(
1728 hydra->kernel_interface, addr, NULL);
1729 if (src)
1730 {
1731 break;
1732 }
1733 }
1734 enumerator->destroy(enumerator);
1735 }
1736 if (src)
1737 {
1738 valid = TRUE;
1739 src->destroy(src);
1740 }
1741 return valid;
1742 }
1743
1744 METHOD(ike_sa_t, roam, status_t,
1745 private_ike_sa_t *this, bool address)
1746 {
1747 ike_mobike_t *mobike;
1748
1749 switch (this->state)
1750 {
1751 case IKE_CREATED:
1752 case IKE_DELETING:
1753 case IKE_DESTROYING:
1754 case IKE_PASSIVE:
1755 return SUCCESS;
1756 default:
1757 break;
1758 }
1759
1760 /* keep existing path if possible */
1761 if (is_current_path_valid(this))
1762 {
1763 DBG2(DBG_IKE, "keeping connection path %H - %H",
1764 this->my_host, this->other_host);
1765 set_condition(this, COND_STALE, FALSE);
1766
1767 if (supports_extension(this, EXT_MOBIKE) && address)
1768 { /* if any addresses changed, send an updated list */
1769 DBG1(DBG_IKE, "sending address list update using MOBIKE");
1770 mobike = ike_mobike_create(&this->public, TRUE);
1771 mobike->addresses(mobike);
1772 this->task_manager->queue_task(this->task_manager,
1773 (task_t*)mobike);
1774 return this->task_manager->initiate(this->task_manager);
1775 }
1776 return SUCCESS;
1777 }
1778
1779 if (!is_any_path_valid(this))
1780 {
1781 DBG1(DBG_IKE, "no route found to reach %H, MOBIKE update deferred",
1782 this->other_host);
1783 set_condition(this, COND_STALE, TRUE);
1784 return SUCCESS;
1785 }
1786 set_condition(this, COND_STALE, FALSE);
1787
1788 /* update addresses with mobike, if supported ... */
1789 if (supports_extension(this, EXT_MOBIKE))
1790 {
1791 if (!has_condition(this, COND_ORIGINAL_INITIATOR))
1792 { /* responder updates the peer about changed address config */
1793 DBG1(DBG_IKE, "sending address list update using MOBIKE, "
1794 "implicitly requesting an address change");
1795 address = TRUE;
1796 }
1797 else
1798 {
1799 DBG1(DBG_IKE, "requesting address change using MOBIKE");
1800 }
1801 mobike = ike_mobike_create(&this->public, TRUE);
1802 mobike->roam(mobike, address);
1803 this->task_manager->queue_task(this->task_manager, (task_t*)mobike);
1804 return this->task_manager->initiate(this->task_manager);
1805 }
1806
1807 /* ... reauth if not */
1808 if (!has_condition(this, COND_ORIGINAL_INITIATOR))
1809 { /* responder does not reauthenticate */
1810 set_condition(this, COND_STALE, TRUE);
1811 return SUCCESS;
1812 }
1813 DBG1(DBG_IKE, "reauthenticating IKE_SA due to address change");
1814 return reauth(this);
1815 }
1816
1817 METHOD(ike_sa_t, add_configuration_attribute, void,
1818 private_ike_sa_t *this, attribute_handler_t *handler,
1819 configuration_attribute_type_t type, chunk_t data)
1820 {
1821 attribute_entry_t *entry = malloc_thing(attribute_entry_t);
1822
1823 entry->handler = handler;
1824 entry->type = type;
1825 entry->data = chunk_clone(data);
1826
1827 this->attributes->insert_last(this->attributes, entry);
1828 }
1829
1830 METHOD(ike_sa_t, create_task_enumerator, enumerator_t*,
1831 private_ike_sa_t *this, task_queue_t queue)
1832 {
1833 return this->task_manager->create_task_enumerator(this->task_manager, queue);
1834 }
1835
1836 METHOD(ike_sa_t, queue_task, void,
1837 private_ike_sa_t *this, task_t *task)
1838 {
1839 this->task_manager->queue_task(this->task_manager, task);
1840 }
1841
1842 METHOD(ike_sa_t, inherit, void,
1843 private_ike_sa_t *this, ike_sa_t *other_public)
1844 {
1845 private_ike_sa_t *other = (private_ike_sa_t*)other_public;
1846 child_sa_t *child_sa;
1847 attribute_entry_t *entry;
1848 enumerator_t *enumerator;
1849 auth_cfg_t *cfg;
1850
1851 /* apply hosts and ids */
1852 this->my_host->destroy(this->my_host);
1853 this->other_host->destroy(this->other_host);
1854 this->my_id->destroy(this->my_id);
1855 this->other_id->destroy(this->other_id);
1856 this->my_host = other->my_host->clone(other->my_host);
1857 this->other_host = other->other_host->clone(other->other_host);
1858 this->my_id = other->my_id->clone(other->my_id);
1859 this->other_id = other->other_id->clone(other->other_id);
1860
1861 /* apply virtual assigned IPs... */
1862 if (other->my_virtual_ip)
1863 {
1864 this->my_virtual_ip = other->my_virtual_ip;
1865 other->my_virtual_ip = NULL;
1866 }
1867 if (other->other_virtual_ip)
1868 {
1869 this->other_virtual_ip = other->other_virtual_ip;
1870 other->other_virtual_ip = NULL;
1871 }
1872
1873 /* authentication information */
1874 enumerator = other->my_auths->create_enumerator(other->my_auths);
1875 while (enumerator->enumerate(enumerator, &cfg))
1876 {
1877 this->my_auths->insert_last(this->my_auths, cfg->clone(cfg));
1878 }
1879 enumerator->destroy(enumerator);
1880 enumerator = other->other_auths->create_enumerator(other->other_auths);
1881 while (enumerator->enumerate(enumerator, &cfg))
1882 {
1883 this->other_auths->insert_last(this->other_auths, cfg->clone(cfg));
1884 }
1885 enumerator->destroy(enumerator);
1886
1887 /* ... and configuration attributes */
1888 while (other->attributes->remove_last(other->attributes,
1889 (void**)&entry) == SUCCESS)
1890 {
1891 this->attributes->insert_first(this->attributes, entry);
1892 }
1893
1894 /* inherit all conditions */
1895 this->conditions = other->conditions;
1896 if (this->conditions & COND_NAT_HERE)
1897 {
1898 send_keepalive(this);
1899 }
1900
1901 #ifdef ME
1902 if (other->is_mediation_server)
1903 {
1904 act_as_mediation_server(this);
1905 }
1906 else if (other->server_reflexive_host)
1907 {
1908 this->server_reflexive_host = other->server_reflexive_host->clone(
1909 other->server_reflexive_host);
1910 }
1911 #endif /* ME */
1912
1913 /* adopt all children */
1914 while (other->child_sas->remove_last(other->child_sas,
1915 (void**)&child_sa) == SUCCESS)
1916 {
1917 this->child_sas->insert_first(this->child_sas, (void*)child_sa);
1918 }
1919
1920 /* move pending tasks to the new IKE_SA */
1921 this->task_manager->adopt_tasks(this->task_manager, other->task_manager);
1922
1923 /* reauthentication timeout survives a rekeying */
1924 if (other->stats[STAT_REAUTH])
1925 {
1926 time_t reauth, delete, now = time_monotonic(NULL);
1927
1928 this->stats[STAT_REAUTH] = other->stats[STAT_REAUTH];
1929 reauth = this->stats[STAT_REAUTH] - now;
1930 delete = reauth + this->peer_cfg->get_over_time(this->peer_cfg);
1931 this->stats[STAT_DELETE] = this->stats[STAT_REAUTH] + delete;
1932 DBG1(DBG_IKE, "rescheduling reauthentication in %ds after rekeying, "
1933 "lifetime reduced to %ds", reauth, delete);
1934 lib->scheduler->schedule_job(lib->scheduler,
1935 (job_t*)rekey_ike_sa_job_create(this->ike_sa_id, TRUE), reauth);
1936 lib->scheduler->schedule_job(lib->scheduler,
1937 (job_t*)delete_ike_sa_job_create(this->ike_sa_id, TRUE), delete);
1938 }
1939 }
1940
1941 METHOD(ike_sa_t, destroy, void,
1942 private_ike_sa_t *this)
1943 {
1944 attribute_entry_t *entry;
1945
1946 charon->bus->set_sa(charon->bus, &this->public);
1947
1948 set_state(this, IKE_DESTROYING);
1949 this->task_manager->destroy(this->task_manager);
1950
1951 /* remove attributes first, as we pass the IKE_SA to the handler */
1952 while (this->attributes->remove_last(this->attributes,
1953 (void**)&entry) == SUCCESS)
1954 {
1955 hydra->attributes->release(hydra->attributes, entry->handler,
1956 this->other_id, entry->type, entry->data);
1957 free(entry->data.ptr);
1958 free(entry);
1959 }
1960 this->attributes->destroy(this->attributes);
1961
1962 this->child_sas->destroy_offset(this->child_sas, offsetof(child_sa_t, destroy));
1963
1964 /* unset SA after here to avoid usage by the listeners */
1965 charon->bus->set_sa(charon->bus, NULL);
1966
1967 this->keymat->destroy(this->keymat);
1968
1969 if (this->my_virtual_ip)
1970 {
1971 hydra->kernel_interface->del_ip(hydra->kernel_interface,
1972 this->my_virtual_ip);
1973 this->my_virtual_ip->destroy(this->my_virtual_ip);
1974 }
1975 if (this->other_virtual_ip)
1976 {
1977 if (this->peer_cfg && this->peer_cfg->get_pool(this->peer_cfg))
1978 {
1979 hydra->attributes->release_address(hydra->attributes,
1980 this->peer_cfg->get_pool(this->peer_cfg),
1981 this->other_virtual_ip, get_other_eap_id(this));
1982 }
1983 this->other_virtual_ip->destroy(this->other_virtual_ip);
1984 }
1985 this->additional_addresses->destroy_offset(this->additional_addresses,
1986 offsetof(host_t, destroy));
1987 #ifdef ME
1988 if (this->is_mediation_server)
1989 {
1990 charon->mediation_manager->remove(charon->mediation_manager,
1991 this->ike_sa_id);
1992 }
1993 DESTROY_IF(this->server_reflexive_host);
1994 chunk_free(&this->connect_id);
1995 #endif /* ME */
1996 free(this->nat_detection_dest.ptr);
1997
1998 DESTROY_IF(this->my_host);
1999 DESTROY_IF(this->other_host);
2000 DESTROY_IF(this->my_id);
2001 DESTROY_IF(this->other_id);
2002 DESTROY_IF(this->local_host);
2003 DESTROY_IF(this->remote_host);
2004
2005 DESTROY_IF(this->ike_cfg);
2006 DESTROY_IF(this->peer_cfg);
2007 DESTROY_IF(this->proposal);
2008 this->my_auth->destroy(this->my_auth);
2009 this->other_auth->destroy(this->other_auth);
2010 this->my_auths->destroy_offset(this->my_auths,
2011 offsetof(auth_cfg_t, destroy));
2012 this->other_auths->destroy_offset(this->other_auths,
2013 offsetof(auth_cfg_t, destroy));
2014
2015 this->ike_sa_id->destroy(this->ike_sa_id);
2016 free(this);
2017 }
2018
2019 /*
2020 * Described in header.
2021 */
2022 ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id, bool initiator,
2023 ike_version_t version)
2024 {
2025 private_ike_sa_t *this;
2026 static u_int32_t unique_id = 0;
2027
2028 if (version != IKEV1)
2029 {
2030 version = IKEV2;
2031 }
2032
2033 INIT(this,
2034 .public = {
2035 .get_version = _get_version,
2036 .get_state = _get_state,
2037 .set_state = _set_state,
2038 .get_name = _get_name,
2039 .get_statistic = _get_statistic,
2040 .set_statistic = _set_statistic,
2041 .process_message = _process_message,
2042 .initiate = _initiate,
2043 .get_ike_cfg = _get_ike_cfg,
2044 .set_ike_cfg = _set_ike_cfg,
2045 .get_peer_cfg = _get_peer_cfg,
2046 .set_peer_cfg = _set_peer_cfg,
2047 .get_auth_cfg = _get_auth_cfg,
2048 .create_auth_cfg_enumerator = _create_auth_cfg_enumerator,
2049 .add_auth_cfg = _add_auth_cfg,
2050 .get_proposal = _get_proposal,
2051 .set_proposal = _set_proposal,
2052 .get_id = _get_id,
2053 .get_my_host = _get_my_host,
2054 .set_my_host = _set_my_host,
2055 .get_other_host = _get_other_host,
2056 .set_other_host = _set_other_host,
2057 .set_message_id = _set_message_id,
2058 .float_ports = _float_ports,
2059 .update_hosts = _update_hosts,
2060 .get_my_id = _get_my_id,
2061 .set_my_id = _set_my_id,
2062 .get_other_id = _get_other_id,
2063 .set_other_id = _set_other_id,
2064 .get_other_eap_id = _get_other_eap_id,
2065 .enable_extension = _enable_extension,
2066 .supports_extension = _supports_extension,
2067 .set_condition = _set_condition,
2068 .has_condition = _has_condition,
2069 .set_pending_updates = _set_pending_updates,
2070 .get_pending_updates = _get_pending_updates,
2071 .create_additional_address_enumerator = _create_additional_address_enumerator,
2072 .add_additional_address = _add_additional_address,
2073 .remove_additional_addresses = _remove_additional_addresses,
2074 .has_mapping_changed = _has_mapping_changed,
2075 .retransmit = _retransmit,
2076 .delete = _delete_,
2077 .destroy = _destroy,
2078 .send_dpd = _send_dpd,
2079 .send_keepalive = _send_keepalive,
2080 .get_keymat = _get_keymat,
2081 .add_child_sa = _add_child_sa,
2082 .get_child_sa = _get_child_sa,
2083 .get_child_count = _get_child_count,
2084 .create_child_sa_enumerator = _create_child_sa_enumerator,
2085 .remove_child_sa = _remove_child_sa,
2086 .rekey_child_sa = _rekey_child_sa,
2087 .delete_child_sa = _delete_child_sa,
2088 .destroy_child_sa = _destroy_child_sa,
2089 .rekey = _rekey,
2090 .reauth = _reauth,
2091 .reestablish = _reestablish,
2092 .set_auth_lifetime = _set_auth_lifetime,
2093 .roam = _roam,
2094 .inherit = _inherit,
2095 .generate_message = _generate_message,
2096 .reset = _reset,
2097 .get_unique_id = _get_unique_id,
2098 .set_virtual_ip = _set_virtual_ip,
2099 .get_virtual_ip = _get_virtual_ip,
2100 .add_configuration_attribute = _add_configuration_attribute,
2101 .set_kmaddress = _set_kmaddress,
2102 .create_task_enumerator = _create_task_enumerator,
2103 .queue_task = _queue_task,
2104 #ifdef ME
2105 .act_as_mediation_server = _act_as_mediation_server,
2106 .get_server_reflexive_host = _get_server_reflexive_host,
2107 .set_server_reflexive_host = _set_server_reflexive_host,
2108 .get_connect_id = _get_connect_id,
2109 .initiate_mediation = _initiate_mediation,
2110 .initiate_mediated = _initiate_mediated,
2111 .relay = _relay,
2112 .callback = _callback,
2113 .respond = _respond,
2114 #endif /* ME */
2115 },
2116 .ike_sa_id = ike_sa_id->clone(ike_sa_id),
2117 .version = version,
2118 .child_sas = linked_list_create(),
2119 .my_host = host_create_any(AF_INET),
2120 .other_host = host_create_any(AF_INET),
2121 .my_id = identification_create_from_encoding(ID_ANY, chunk_empty),
2122 .other_id = identification_create_from_encoding(ID_ANY, chunk_empty),
2123 .keymat = keymat_create(version, initiator),
2124 .state = IKE_CREATED,
2125 .stats[STAT_INBOUND] = time_monotonic(NULL),
2126 .stats[STAT_OUTBOUND] = time_monotonic(NULL),
2127 .my_auth = auth_cfg_create(),
2128 .other_auth = auth_cfg_create(),
2129 .my_auths = linked_list_create(),
2130 .other_auths = linked_list_create(),
2131 .unique_id = ++unique_id,
2132 .additional_addresses = linked_list_create(),
2133 .attributes = linked_list_create(),
2134 .keepalive_interval = lib->settings->get_time(lib->settings,
2135 "charon.keep_alive", KEEPALIVE_INTERVAL),
2136 .flush_auth_cfg = lib->settings->get_bool(lib->settings,
2137 "charon.flush_auth_cfg", FALSE),
2138 );
2139
2140 this->task_manager = task_manager_create(&this->public);
2141 this->my_host->set_port(this->my_host, IKEV2_UDP_PORT);
2142
2143 return &this->public;
2144 }