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