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