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