ikev2: Add possibility to delay initiation of a queued task
[strongswan.git] / src / libcharon / sa / ike_sa.h
1 /*
2 * Copyright (C) 2006-2016 Tobias Brunner
3 * Copyright (C) 2006 Daniel Roethlisberger
4 * Copyright (C) 2005-2009 Martin Willi
5 * Copyright (C) 2005 Jan Hutter
6 * HSR 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 /**
20 * @defgroup ike_sa ike_sa
21 * @{ @ingroup sa
22 */
23
24 #ifndef IKE_SA_H_
25 #define IKE_SA_H_
26
27 typedef enum ike_extension_t ike_extension_t;
28 typedef enum ike_condition_t ike_condition_t;
29 typedef enum ike_sa_state_t ike_sa_state_t;
30 typedef enum statistic_t statistic_t;
31 typedef struct ike_sa_t ike_sa_t;
32
33 #include <library.h>
34 #include <attributes/attribute_handler.h>
35 #include <encoding/message.h>
36 #include <encoding/payloads/proposal_substructure.h>
37 #include <encoding/payloads/configuration_attribute.h>
38 #include <sa/ike_sa_id.h>
39 #include <sa/child_sa.h>
40 #include <sa/task.h>
41 #include <sa/task_manager.h>
42 #include <sa/keymat.h>
43 #include <config/peer_cfg.h>
44 #include <config/ike_cfg.h>
45 #include <credentials/auth_cfg.h>
46 #include <networking/packet.h>
47
48 /**
49 * Timeout in seconds after that a half open IKE_SA gets deleted.
50 */
51 #define HALF_OPEN_IKE_SA_TIMEOUT 30
52
53 /**
54 * Interval to send keepalives when NATed, in seconds.
55 */
56 #define KEEPALIVE_INTERVAL 20
57
58 /**
59 * After which time rekeying should be retried if it failed, in seconds.
60 */
61 #define RETRY_INTERVAL 15
62
63 /**
64 * Jitter to subtract from RETRY_INTERVAL to randomize rekey retry.
65 */
66 #define RETRY_JITTER 10
67
68 /**
69 * Number of redirects allowed within REDIRECT_LOOP_DETECT_PERIOD.
70 */
71 #define MAX_REDIRECTS 5
72
73 /**
74 * Time period in seconds in which at most MAX_REDIRECTS are allowed.
75 */
76 #define REDIRECT_LOOP_DETECT_PERIOD 300
77
78 /**
79 * Extensions (or optional features) the peer supports
80 */
81 enum ike_extension_t {
82
83 /**
84 * peer supports NAT traversal as specified in RFC4306 or RFC3947
85 * including some RFC3947 drafts
86 */
87 EXT_NATT = (1<<0),
88
89 /**
90 * peer supports MOBIKE (RFC4555)
91 */
92 EXT_MOBIKE = (1<<1),
93
94 /**
95 * peer supports HTTP cert lookups as specified in RFC4306
96 */
97 EXT_HASH_AND_URL = (1<<2),
98
99 /**
100 * peer supports multiple authentication exchanges, RFC4739
101 */
102 EXT_MULTIPLE_AUTH = (1<<3),
103
104 /**
105 * peer uses strongSwan, accept private use extensions
106 */
107 EXT_STRONGSWAN = (1<<4),
108
109 /**
110 * peer supports EAP-only authentication, draft-eronen-ipsec-ikev2-eap-auth
111 */
112 EXT_EAP_ONLY_AUTHENTICATION = (1<<5),
113
114 /**
115 * peer is probably a Windows RAS client
116 */
117 EXT_MS_WINDOWS = (1<<6),
118
119 /**
120 * peer supports XAuth authentication, draft-ietf-ipsec-isakmp-xauth-06
121 */
122 EXT_XAUTH = (1<<7),
123
124 /**
125 * peer supports DPD detection, RFC 3706 (or IKEv2)
126 */
127 EXT_DPD = (1<<8),
128
129 /**
130 * peer supports Cisco Unity configuration attributes
131 */
132 EXT_CISCO_UNITY = (1<<9),
133
134 /**
135 * peer supports NAT traversal as specified in
136 * draft-ietf-ipsec-nat-t-ike-02 .. -03
137 */
138 EXT_NATT_DRAFT_02_03 = (1<<10),
139
140 /**
141 * peer supports proprietary IKEv1 or standardized IKEv2 fragmentation
142 */
143 EXT_IKE_FRAGMENTATION = (1<<11),
144
145 /**
146 * Signature Authentication, RFC 7427
147 */
148 EXT_SIGNATURE_AUTH = (1<<12),
149
150 /**
151 * IKEv2 Redirect Mechanism, RFC 5685
152 */
153 EXT_IKE_REDIRECTION = (1<<13),
154 };
155
156 /**
157 * Conditions of an IKE_SA, change during its lifetime
158 */
159 enum ike_condition_t {
160
161 /**
162 * Connection is natted (or faked) somewhere
163 */
164 COND_NAT_ANY = (1<<0),
165
166 /**
167 * we are behind NAT
168 */
169 COND_NAT_HERE = (1<<1),
170
171 /**
172 * other is behind NAT
173 */
174 COND_NAT_THERE = (1<<2),
175
176 /**
177 * Faking NAT to enforce UDP encapsulation
178 */
179 COND_NAT_FAKE = (1<<3),
180
181 /**
182 * peer has been authenticated using EAP at least once
183 */
184 COND_EAP_AUTHENTICATED = (1<<4),
185
186 /**
187 * received a certificate request from the peer
188 */
189 COND_CERTREQ_SEEN = (1<<5),
190
191 /**
192 * Local peer is the "original" IKE initiator. Unaffected from rekeying.
193 */
194 COND_ORIGINAL_INITIATOR = (1<<6),
195
196 /**
197 * IKE_SA is stale, the peer is currently unreachable (MOBIKE)
198 */
199 COND_STALE = (1<<7),
200
201 /**
202 * Initial contact received
203 */
204 COND_INIT_CONTACT_SEEN = (1<<8),
205
206 /**
207 * Peer has been authenticated using XAuth
208 */
209 COND_XAUTH_AUTHENTICATED = (1<<9),
210
211 /**
212 * This IKE_SA is currently being reauthenticated
213 */
214 COND_REAUTHENTICATING = (1<<10),
215
216 /**
217 * This IKE_SA has been redirected
218 */
219 COND_REDIRECTED = (1<<11),
220
221 /**
222 * Online certificate revocation checking is suspended for this IKE_SA
223 */
224 COND_ONLINE_VALIDATION_SUSPENDED = (1<<12),
225 };
226
227 /**
228 * Timing information and statistics to query from an SA
229 */
230 enum statistic_t {
231 /** Timestamp of SA establishement */
232 STAT_ESTABLISHED = 0,
233 /** Timestamp of scheduled rekeying */
234 STAT_REKEY,
235 /** Timestamp of scheduled reauthentication */
236 STAT_REAUTH,
237 /** Timestamp of scheduled delete */
238 STAT_DELETE,
239 /** Timestamp of last inbound IKE packet */
240 STAT_INBOUND,
241 /** Timestamp of last outbound IKE packet */
242 STAT_OUTBOUND,
243
244 STAT_MAX
245 };
246
247 /**
248 * State of an IKE_SA.
249 *
250 * An IKE_SA passes various states in its lifetime. A newly created
251 * SA is in the state CREATED.
252 * @verbatim
253 +----------------+
254 ¦ SA_CREATED ¦
255 +----------------+
256 ¦
257 on initiate()---> ¦ <----- on IKE_SA_INIT received
258 V
259 +----------------+
260 ¦ SA_CONNECTING ¦
261 +----------------+
262 ¦
263 ¦ <----- on IKE_AUTH successfully completed
264 V
265 +----------------+
266 ¦ SA_ESTABLISHED ¦-------------------------+ <-- on rekeying
267 +----------------+ ¦
268 ¦ V
269 on delete()---> ¦ <----- on IKE_SA +-------------+
270 ¦ delete request ¦ SA_REKEYING ¦
271 ¦ received +-------------+
272 V ¦
273 +----------------+ ¦
274 ¦ SA_DELETING ¦<------------------------+ <-- after rekeying
275 +----------------+
276 ¦
277 ¦ <----- after delete() acknowledged
278 ¦
279 \V/
280 X
281 / \
282 @endverbatim
283 */
284 enum ike_sa_state_t {
285
286 /**
287 * IKE_SA just got created, but is not initiating nor responding yet.
288 */
289 IKE_CREATED,
290
291 /**
292 * IKE_SA gets initiated actively or passively
293 */
294 IKE_CONNECTING,
295
296 /**
297 * IKE_SA is fully established
298 */
299 IKE_ESTABLISHED,
300
301 /**
302 * IKE_SA is managed externally and does not process messages
303 */
304 IKE_PASSIVE,
305
306 /**
307 * IKE_SA rekeying in progress
308 */
309 IKE_REKEYING,
310
311 /**
312 * IKE_SA has been rekeyed (or is redundant)
313 */
314 IKE_REKEYED,
315
316 /**
317 * IKE_SA is in progress of deletion
318 */
319 IKE_DELETING,
320
321 /**
322 * IKE_SA object gets destroyed
323 */
324 IKE_DESTROYING,
325 };
326
327 /**
328 * enum names for ike_sa_state_t.
329 */
330 extern enum_name_t *ike_sa_state_names;
331
332 /**
333 * Class ike_sa_t representing an IKE_SA.
334 *
335 * An IKE_SA contains crypto information related to a connection
336 * with a peer. It contains multiple IPsec CHILD_SA, for which
337 * it is responsible. All traffic is handled by an IKE_SA, using
338 * the task manager and its tasks.
339 */
340 struct ike_sa_t {
341
342 /**
343 * Get the id of the SA.
344 *
345 * Returned ike_sa_id_t object is not getting cloned!
346 *
347 * @return ike_sa's ike_sa_id_t
348 */
349 ike_sa_id_t* (*get_id) (ike_sa_t *this);
350
351 /**
352 * Gets the IKE version of the SA
353 */
354 ike_version_t (*get_version)(ike_sa_t *this);
355
356 /**
357 * Get the numerical ID uniquely defining this IKE_SA.
358 *
359 * @return unique ID
360 */
361 uint32_t (*get_unique_id) (ike_sa_t *this);
362
363 /**
364 * Get the state of the IKE_SA.
365 *
366 * @return state of the IKE_SA
367 */
368 ike_sa_state_t (*get_state) (ike_sa_t *this);
369
370 /**
371 * Set the state of the IKE_SA.
372 *
373 * @param state state to set for the IKE_SA
374 */
375 void (*set_state) (ike_sa_t *this, ike_sa_state_t state);
376
377 /**
378 * Get the name of the connection this IKE_SA uses.
379 *
380 * @return name
381 */
382 char* (*get_name) (ike_sa_t *this);
383
384 /**
385 * Get statistic values from the IKE_SA.
386 *
387 * @param kind kind of requested value
388 * @return value as integer
389 */
390 uint32_t (*get_statistic)(ike_sa_t *this, statistic_t kind);
391
392 /**
393 * Set statistic value of the IKE_SA.
394 *
395 * @param kind kind of value to update
396 * @param value value as integer
397 */
398 void (*set_statistic)(ike_sa_t *this, statistic_t kind, uint32_t value);
399
400 /**
401 * Get the own host address.
402 *
403 * @return host address
404 */
405 host_t* (*get_my_host) (ike_sa_t *this);
406
407 /**
408 * Set the own host address.
409 *
410 * @param me host address
411 */
412 void (*set_my_host) (ike_sa_t *this, host_t *me);
413
414 /**
415 * Get the other peers host address.
416 *
417 * @return host address
418 */
419 host_t* (*get_other_host) (ike_sa_t *this);
420
421 /**
422 * Set the others host address.
423 *
424 * @param other host address
425 */
426 void (*set_other_host) (ike_sa_t *this, host_t *other);
427
428 /**
429 * Float to port 4500 (e.g. if a NAT is detected).
430 *
431 * The port of either endpoint is changed only if it is currently
432 * set to the default value of 500.
433 */
434 void (*float_ports)(ike_sa_t *this);
435
436 /**
437 * Update the IKE_SAs host.
438 *
439 * Hosts may be NULL to use current host.
440 *
441 * @param me new local host address, or NULL
442 * @param other new remote host address, or NULL
443 * @param force force update
444 */
445 void (*update_hosts)(ike_sa_t *this, host_t *me, host_t *other, bool force);
446
447 /**
448 * Get the own identification.
449 *
450 * @return identification
451 */
452 identification_t* (*get_my_id) (ike_sa_t *this);
453
454 /**
455 * Set the own identification.
456 *
457 * @param me identification
458 */
459 void (*set_my_id) (ike_sa_t *this, identification_t *me);
460
461 /**
462 * Get the other peer's identification.
463 *
464 * @return identification
465 */
466 identification_t* (*get_other_id) (ike_sa_t *this);
467
468 /**
469 * Get the others peer identity, but prefer an EAP-Identity.
470 *
471 * @return EAP or IKEv2 identity
472 */
473 identification_t* (*get_other_eap_id)(ike_sa_t *this);
474
475 /**
476 * Set the other peer's identification.
477 *
478 * @param other identification
479 */
480 void (*set_other_id) (ike_sa_t *this, identification_t *other);
481
482 /**
483 * Get the config used to setup this IKE_SA.
484 *
485 * @return ike_config
486 */
487 ike_cfg_t* (*get_ike_cfg) (ike_sa_t *this);
488
489 /**
490 * Set the config to setup this IKE_SA.
491 *
492 * @param config ike_config to use
493 */
494 void (*set_ike_cfg) (ike_sa_t *this, ike_cfg_t* config);
495
496 /**
497 * Get the peer config used by this IKE_SA.
498 *
499 * @return peer_config
500 */
501 peer_cfg_t* (*get_peer_cfg) (ike_sa_t *this);
502
503 /**
504 * Set the peer config to use with this IKE_SA.
505 *
506 * @param config peer_config to use
507 */
508 void (*set_peer_cfg) (ike_sa_t *this, peer_cfg_t *config);
509
510 /**
511 * Get the authentication config with rules of the current auth round.
512 *
513 * @param local TRUE for local rules, FALSE for remote constraints
514 * @return current cfg
515 */
516 auth_cfg_t* (*get_auth_cfg)(ike_sa_t *this, bool local);
517
518 /**
519 * Insert a completed authentication round.
520 *
521 * @param local TRUE for own rules, FALSE for others constraints
522 * @param cfg auth config to append
523 */
524 void (*add_auth_cfg)(ike_sa_t *this, bool local, auth_cfg_t *cfg);
525
526 /**
527 * Create an enumerator over added authentication rounds.
528 *
529 * @param local TRUE for own rules, FALSE for others constraints
530 * @return enumerator over auth_cfg_t
531 */
532 enumerator_t* (*create_auth_cfg_enumerator)(ike_sa_t *this, bool local);
533
534 /**
535 * Verify the trustchains (validity, revocation) in completed public key
536 * auth rounds.
537 *
538 * @return TRUE if certificates were valid, FALSE otherwise
539 */
540 bool (*verify_peer_certificate)(ike_sa_t *this);
541
542 /**
543 * Get the selected proposal of this IKE_SA.
544 *
545 * @return selected proposal
546 */
547 proposal_t* (*get_proposal)(ike_sa_t *this);
548
549 /**
550 * Set the proposal selected for this IKE_SA.
551 *
552 * @param selected proposal
553 */
554 void (*set_proposal)(ike_sa_t *this, proposal_t *proposal);
555
556 /**
557 * Set the message id of the IKE_SA.
558 *
559 * The IKE_SA stores two message IDs, one for initiating exchanges (send)
560 * and one to respond to exchanges (expect).
561 *
562 * @param initiate TRUE to set message ID for initiating
563 * @param mid message id to set
564 */
565 void (*set_message_id)(ike_sa_t *this, bool initiate, uint32_t mid);
566
567 /**
568 * Add an additional address for the peer.
569 *
570 * In MOBIKE, a peer may transmit additional addresses where it is
571 * reachable. These are stored in the IKE_SA.
572 * The own list of addresses is not stored, they are queried from
573 * the kernel when required.
574 *
575 * @param host host to add to list
576 */
577 void (*add_peer_address)(ike_sa_t *this, host_t *host);
578
579 /**
580 * Create an enumerator over all known addresses of the peer.
581 *
582 * @return enumerator over addresses
583 */
584 enumerator_t* (*create_peer_address_enumerator)(ike_sa_t *this);
585
586 /**
587 * Remove all known addresses of the peer.
588 */
589 void (*clear_peer_addresses)(ike_sa_t *this);
590
591 /**
592 * Check if mappings have changed on a NAT for our source address.
593 *
594 * @param hash received DESTINATION_IP hash
595 * @return TRUE if mappings have changed
596 */
597 bool (*has_mapping_changed)(ike_sa_t *this, chunk_t hash);
598
599 /**
600 * Enable an extension the peer supports.
601 *
602 * If support for an IKE extension is detected, this method is called
603 * to enable that extension and behave accordingly.
604 *
605 * @param extension extension to enable
606 */
607 void (*enable_extension)(ike_sa_t *this, ike_extension_t extension);
608
609 /**
610 * Check if the peer supports an extension.
611 *
612 * @param extension extension to check for support
613 * @return TRUE if peer supports it, FALSE otherwise
614 */
615 bool (*supports_extension)(ike_sa_t *this, ike_extension_t extension);
616
617 /**
618 * Enable/disable a condition flag for this IKE_SA.
619 *
620 * @param condition condition to enable/disable
621 * @param enable TRUE to enable condition, FALSE to disable
622 */
623 void (*set_condition) (ike_sa_t *this, ike_condition_t condition, bool enable);
624
625 /**
626 * Check if a condition flag is set.
627 *
628 * @param condition condition to check
629 * @return TRUE if condition flag set, FALSE otherwise
630 */
631 bool (*has_condition) (ike_sa_t *this, ike_condition_t condition);
632
633 /**
634 * Get the number of queued MOBIKE address updates.
635 *
636 * @return number of pending updates
637 */
638 uint32_t (*get_pending_updates)(ike_sa_t *this);
639
640 /**
641 * Set the number of queued MOBIKE address updates.
642 *
643 * @param updates number of pending updates
644 */
645 void (*set_pending_updates)(ike_sa_t *this, uint32_t updates);
646
647 #ifdef ME
648 /**
649 * Activate mediation server functionality for this IKE_SA.
650 */
651 void (*act_as_mediation_server) (ike_sa_t *this);
652
653 /**
654 * Get the server reflexive host.
655 *
656 * @return server reflexive host
657 */
658 host_t* (*get_server_reflexive_host) (ike_sa_t *this);
659
660 /**
661 * Set the server reflexive host.
662 *
663 * @param host server reflexive host
664 */
665 void (*set_server_reflexive_host) (ike_sa_t *this, host_t *host);
666
667 /**
668 * Get the connect ID.
669 *
670 * @return connect ID
671 */
672 chunk_t (*get_connect_id) (ike_sa_t *this);
673
674 /**
675 * Initiate the mediation of a mediated connection (i.e. initiate a
676 * ME_CONNECT exchange to a mediation server).
677 *
678 * @param mediated_cfg peer_cfg of the mediated connection
679 * @return
680 * - SUCCESS if initialization started
681 * - DESTROY_ME if initialization failed
682 */
683 status_t (*initiate_mediation) (ike_sa_t *this, peer_cfg_t *mediated_cfg);
684
685 /**
686 * Initiate the mediated connection
687 *
688 * @param me local endpoint (gets cloned)
689 * @param other remote endpoint (gets cloned)
690 * @param connect_id connect ID (gets cloned)
691 * @return
692 * - SUCCESS if initialization started
693 * - DESTROY_ME if initialization failed
694 */
695 status_t (*initiate_mediated) (ike_sa_t *this, host_t *me, host_t *other,
696 chunk_t connect_id);
697
698 /**
699 * Relay data from one peer to another (i.e. initiate a ME_CONNECT exchange
700 * to a peer).
701 *
702 * Data is cloned.
703 *
704 * @param requester ID of the requesting peer
705 * @param connect_id data of the ME_CONNECTID payload
706 * @param connect_key data of the ME_CONNECTKEY payload
707 * @param endpoints endpoints
708 * @param response TRUE if this is a response
709 * @return
710 * - SUCCESS if relay started
711 * - DESTROY_ME if relay failed
712 */
713 status_t (*relay) (ike_sa_t *this, identification_t *requester,
714 chunk_t connect_id, chunk_t connect_key,
715 linked_list_t *endpoints, bool response);
716
717 /**
718 * Send a callback to a peer.
719 *
720 * Data is cloned.
721 *
722 * @param peer_id ID of the other peer
723 * @return
724 * - SUCCESS if response started
725 * - DESTROY_ME if response failed
726 */
727 status_t (*callback) (ike_sa_t *this, identification_t *peer_id);
728
729 /**
730 * Respond to a ME_CONNECT request.
731 *
732 * Data is cloned.
733 *
734 * @param peer_id ID of the other peer
735 * @param connect_id the connect ID supplied by the initiator
736 * @return
737 * - SUCCESS if response started
738 * - DESTROY_ME if response failed
739 */
740 status_t (*respond) (ike_sa_t *this, identification_t *peer_id,
741 chunk_t connect_id);
742 #endif /* ME */
743
744 /**
745 * Initiate a new connection.
746 *
747 * The configs are owned by the IKE_SA after the call. If the initiate
748 * is triggered by a packet, traffic selectors of the packet can be added
749 * to the CHILD_SA.
750 *
751 * @param child_cfg child config to create CHILD from
752 * @param reqid reqid to use for CHILD_SA, 0 assigne uniquely
753 * @param tsi source of triggering packet
754 * @param tsr destination of triggering packet.
755 * @return
756 * - SUCCESS if initialization started
757 * - DESTROY_ME if initialization failed
758 */
759 status_t (*initiate) (ike_sa_t *this, child_cfg_t *child_cfg,
760 uint32_t reqid, traffic_selector_t *tsi,
761 traffic_selector_t *tsr);
762
763 /**
764 * Retry initiation of this IKE_SA after it got deferred previously.
765 *
766 * @return
767 * - SUCCESS if initiation deferred or started
768 * - DESTROY_ME if initiation failed
769 */
770 status_t (*retry_initiate) (ike_sa_t *this);
771
772 /**
773 * Initiates the deletion of an IKE_SA.
774 *
775 * Sends a delete message to the remote peer and waits for
776 * its response. If the response comes in, or a timeout occurs,
777 * the IKE SA gets deleted.
778 *
779 * @return
780 * - SUCCESS if deletion is initialized
781 * - DESTROY_ME, if the IKE_SA is not in
782 * an established state and can not be
783 * deleted (but destroyed).
784 */
785 status_t (*delete) (ike_sa_t *this);
786
787 /**
788 * Update IKE_SAs after network interfaces have changed.
789 *
790 * Whenever the network interface configuration changes, the kernel
791 * interface calls roam() on each IKE_SA. The IKE_SA then checks if
792 * the new network config requires changes, and handles appropriate.
793 * If MOBIKE is supported, addresses are updated; If not, the tunnel is
794 * restarted.
795 *
796 * @param address TRUE if address list changed, FALSE otherwise
797 * @return SUCCESS, FAILED, DESTROY_ME
798 */
799 status_t (*roam)(ike_sa_t *this, bool address);
800
801 /**
802 * Processes an incoming IKE message.
803 *
804 * Message processing may fail. If a critical failure occurs,
805 * process_message() return DESTROY_ME. Then the caller must
806 * destroy the IKE_SA immediately, as it is unusable.
807 *
808 * @param message message to process
809 * @return
810 * - SUCCESS
811 * - FAILED
812 * - DESTROY_ME if this IKE_SA MUST be deleted
813 */
814 status_t (*process_message)(ike_sa_t *this, message_t *message);
815
816 /**
817 * Generate an IKE message to send it to the peer.
818 *
819 * This method generates all payloads in the message and encrypts/signs
820 * the packet.
821 *
822 * @param message message to generate
823 * @param packet generated output packet
824 * @return
825 * - SUCCESS
826 * - FAILED
827 * - DESTROY_ME if this IKE_SA MUST be deleted
828 */
829 status_t (*generate_message)(ike_sa_t *this, message_t *message,
830 packet_t **packet);
831
832 /**
833 * Generate an IKE message to send it to the peer. If enabled and supported
834 * it will be fragmented.
835 *
836 * This method generates all payloads in the message and encrypts/signs
837 * the packet/fragments.
838 *
839 * @param message message to generate
840 * @param packets enumerator of generated packet_t* (are not destroyed
841 * with the enumerator)
842 * @return
843 * - SUCCESS
844 * - FAILED
845 * - DESTROY_ME if this IKE_SA MUST be deleted
846 */
847 status_t (*generate_message_fragmented)(ike_sa_t *this, message_t *message,
848 enumerator_t **packets);
849
850 /**
851 * Retransmits a request.
852 *
853 * @param message_id ID of the request to retransmit
854 * @return
855 * - SUCCESS
856 * - NOT_FOUND if request doesn't have to be retransmited
857 */
858 status_t (*retransmit) (ike_sa_t *this, uint32_t message_id);
859
860 /**
861 * Sends a DPD request to the peer.
862 *
863 * To check if a peer is still alive, periodic
864 * empty INFORMATIONAL messages are sent if no
865 * other traffic was received.
866 *
867 * @return
868 * - SUCCESS
869 * - DESTROY_ME, if peer did not respond
870 */
871 status_t (*send_dpd) (ike_sa_t *this);
872
873 /**
874 * Sends a keep alive packet.
875 *
876 * To refresh NAT tables in a NAT router between the peers, periodic empty
877 * UDP packets are sent if no other traffic was sent.
878 *
879 * @param scheduled if this is a scheduled keepalive
880 */
881 void (*send_keepalive) (ike_sa_t *this, bool scheduled);
882
883 /**
884 * Redirect an active IKE_SA.
885 *
886 * @param gateway gateway ID (IP or FQDN) of the target
887 * @return state, including DESTROY_ME, if this IKE_SA MUST be
888 * destroyed
889 */
890 status_t (*redirect)(ike_sa_t *this, identification_t *gateway);
891
892 /**
893 * Handle a redirect request.
894 *
895 * The behavior is different depending on the state of the IKE_SA.
896 *
897 * @param gateway gateway ID (IP or FQDN) of the target
898 * @return FALSE if redirect not possible, TRUE otherwise
899 */
900 bool (*handle_redirect)(ike_sa_t *this, identification_t *gateway);
901
902 /**
903 * Get the address of the gateway that redirected us.
904 *
905 * @return original gateway address
906 */
907 host_t *(*get_redirected_from)(ike_sa_t *this);
908
909 /**
910 * Get the keying material of this IKE_SA.
911 *
912 * @return per IKE_SA keymat instance
913 */
914 keymat_t* (*get_keymat)(ike_sa_t *this);
915
916 /**
917 * Associates a child SA to this IKE SA
918 *
919 * @param child_sa child_sa to add
920 */
921 void (*add_child_sa) (ike_sa_t *this, child_sa_t *child_sa);
922
923 /**
924 * Get a CHILD_SA identified by protocol and SPI.
925 *
926 * @param protocol protocol of the SA
927 * @param spi SPI of the CHILD_SA
928 * @param inbound TRUE if SPI is inbound, FALSE if outbound
929 * @return child_sa, or NULL if none found
930 */
931 child_sa_t* (*get_child_sa) (ike_sa_t *this, protocol_id_t protocol,
932 uint32_t spi, bool inbound);
933
934 /**
935 * Get the number of CHILD_SAs.
936 *
937 * @return number of CHILD_SAs
938 */
939 int (*get_child_count) (ike_sa_t *this);
940
941 /**
942 * Create an enumerator over all CHILD_SAs.
943 *
944 * @return enumerator
945 */
946 enumerator_t* (*create_child_sa_enumerator) (ike_sa_t *this);
947
948 /**
949 * Remove the CHILD_SA the given enumerator points to from this IKE_SA.
950 *
951 * @param enumerator enumerator pointing to CHILD_SA
952 */
953 void (*remove_child_sa) (ike_sa_t *this, enumerator_t *enumerator);
954
955 /**
956 * Rekey the CHILD SA with the specified reqid.
957 *
958 * Looks for a CHILD SA owned by this IKE_SA, and start the rekeing.
959 *
960 * @param protocol protocol of the SA
961 * @param spi inbound SPI of the CHILD_SA
962 * @return
963 * - NOT_FOUND, if IKE_SA has no such CHILD_SA
964 * - SUCCESS, if rekeying initiated
965 */
966 status_t (*rekey_child_sa) (ike_sa_t *this, protocol_id_t protocol, uint32_t spi);
967
968 /**
969 * Close the CHILD SA with the specified protocol/SPI.
970 *
971 * Looks for a CHILD SA owned by this IKE_SA, deletes it and
972 * notify's the remote peer about the delete. The associated
973 * states and policies in the kernel get deleted, if they exist.
974 *
975 * @param protocol protocol of the SA
976 * @param spi inbound SPI of the CHILD_SA
977 * @param expired TRUE if CHILD_SA is expired
978 * @return
979 * - NOT_FOUND, if IKE_SA has no such CHILD_SA
980 * - SUCCESS, if delete message sent
981 */
982 status_t (*delete_child_sa)(ike_sa_t *this, protocol_id_t protocol,
983 uint32_t spi, bool expired);
984
985 /**
986 * Destroy a CHILD SA with the specified protocol/SPI.
987 *
988 * Looks for a CHILD SA owned by this IKE_SA and destroys it.
989 *
990 * @param protocol protocol of the SA
991 * @param spi inbound SPI of the CHILD_SA
992 * @return
993 * - NOT_FOUND, if IKE_SA has no such CHILD_SA
994 * - SUCCESS
995 */
996 status_t (*destroy_child_sa) (ike_sa_t *this, protocol_id_t protocol, uint32_t spi);
997
998 /**
999 * Rekey the IKE_SA.
1000 *
1001 * Sets up a new IKE_SA, moves all CHILDs to it and deletes this IKE_SA.
1002 *
1003 * @return - SUCCESS, if IKE_SA rekeying initiated
1004 */
1005 status_t (*rekey) (ike_sa_t *this);
1006
1007 /**
1008 * Reauthenticate the IKE_SA.
1009 *
1010 * Triggers a new IKE_SA that replaces this one. IKEv1 implicitly inherits
1011 * all Quick Modes, while IKEv2 recreates all active and queued CHILD_SAs
1012 * in the new IKE_SA.
1013 *
1014 * @return DESTROY_ME to destroy the IKE_SA
1015 */
1016 status_t (*reauth) (ike_sa_t *this);
1017
1018 /**
1019 * Restablish the IKE_SA.
1020 *
1021 * Reestablish an IKE_SA after it has been closed.
1022 *
1023 * @return DESTROY_ME to destroy the IKE_SA
1024 */
1025 status_t (*reestablish) (ike_sa_t *this);
1026
1027 /**
1028 * Set the lifetime limit received/to send in a AUTH_LIFETIME notify.
1029 *
1030 * If the IKE_SA is already ESTABLISHED, an INFORMATIONAL is sent with
1031 * an AUTH_LIFETIME notify. The call never fails on unestablished SAs.
1032 *
1033 * @param lifetime lifetime in seconds
1034 * @return DESTROY_ME to destroy the IKE_SA
1035 */
1036 status_t (*set_auth_lifetime)(ike_sa_t *this, uint32_t lifetime);
1037
1038 /**
1039 * Add a virtual IP to use for this IKE_SA and its children.
1040 *
1041 * The virtual IP is assigned per IKE_SA, not per CHILD_SA. It has the same
1042 * lifetime as the IKE_SA.
1043 *
1044 * @param local TRUE to set local address, FALSE for remote
1045 * @param ip IP to set as virtual IP
1046 */
1047 void (*add_virtual_ip) (ike_sa_t *this, bool local, host_t *ip);
1048
1049 /**
1050 * Clear all virtual IPs stored on this IKE_SA.
1051 *
1052 * @param local TRUE to clear local addresses, FALSE for remote
1053 */
1054 void (*clear_virtual_ips) (ike_sa_t *this, bool local);
1055
1056 /**
1057 * Create an enumerator over virtual IPs.
1058 *
1059 * @param local TRUE to get local virtual IP, FALSE for remote
1060 * @return enumerator over host_t*
1061 */
1062 enumerator_t* (*create_virtual_ip_enumerator) (ike_sa_t *this, bool local);
1063
1064 /**
1065 * Register a configuration attribute to the IKE_SA.
1066 *
1067 * If an IRAS sends a configuration attribute it is installed and
1068 * registered at the IKE_SA. Attributes are inherit()ed and get released
1069 * when the IKE_SA is closed.
1070 *
1071 * Unhandled attributes are passed as well, but with a NULL handler. They
1072 * do not get released.
1073 *
1074 * @param handler handler installed the attribute, use for release()
1075 * @param type configuration attribute type
1076 * @param data associated attribute data
1077 */
1078 void (*add_configuration_attribute)(ike_sa_t *this,
1079 attribute_handler_t *handler,
1080 configuration_attribute_type_t type, chunk_t data);
1081
1082 /**
1083 * Create an enumerator over received configuration attributes.
1084 *
1085 * The resulting enumerator is over the configuration_attribute_type_t type,
1086 * a value chunk_t followed by a bool flag. The boolean flag indicates if
1087 * the attribute has been handled by an attribute handler.
1088 *
1089 * @return enumerator over type, value and the "handled" flag.
1090 */
1091 enumerator_t* (*create_attribute_enumerator)(ike_sa_t *this);
1092
1093 /**
1094 * Set local and remote host addresses to be used for IKE.
1095 *
1096 * These addresses are communicated via the KMADDRESS field of a MIGRATE
1097 * message sent via the NETLINK or PF _KEY kernel socket interface.
1098 *
1099 * @param local local kmaddress
1100 * @param remote remote kmaddress
1101 */
1102 void (*set_kmaddress) (ike_sa_t *this, host_t *local, host_t *remote);
1103
1104 /**
1105 * Create enumerator over a task queue of this IKE_SA.
1106 *
1107 * @param queue type to enumerate
1108 * @return enumerator over task_t
1109 */
1110 enumerator_t* (*create_task_enumerator)(ike_sa_t *this, task_queue_t queue);
1111
1112 /**
1113 * Flush a task queue, cancelling all tasks in it.
1114 *
1115 * @param queue queue type to flush
1116 */
1117 void (*flush_queue)(ike_sa_t *this, task_queue_t queue);
1118
1119 /**
1120 * Queue a task for initiaton to the task manager.
1121 *
1122 * @param task task to queue
1123 */
1124 void (*queue_task)(ike_sa_t *this, task_t *task);
1125
1126 /**
1127 * Queue a task in the manager, but delay its initiation for at least the
1128 * given number of seconds.
1129 *
1130 * @param task task to queue
1131 * @param delay minimum delay in s before initiating the task
1132 */
1133 void (*queue_task_delayed)(ike_sa_t *this, task_t *task, uint32_t delay);
1134
1135 /**
1136 * Inherit required attributes to new SA before rekeying.
1137 *
1138 * Some properties of the SA must be applied before starting IKE_SA
1139 * rekeying, such as the configuration or support extensions.
1140 *
1141 * @param other other IKE_SA to inherit from
1142 */
1143 void (*inherit_pre)(ike_sa_t *this, ike_sa_t *other);
1144
1145 /**
1146 * Inherit all attributes of other to this after rekeying.
1147 *
1148 * When rekeying is completed, all CHILD_SAs, the virtual IP and all
1149 * outstanding tasks are moved from other to this.
1150 *
1151 * @param other other IKE SA to inherit from
1152 */
1153 void (*inherit_post) (ike_sa_t *this, ike_sa_t *other);
1154
1155 /**
1156 * Reset the IKE_SA, useable when initiating fails
1157 */
1158 void (*reset) (ike_sa_t *this);
1159
1160 /**
1161 * Destroys a ike_sa_t object.
1162 */
1163 void (*destroy) (ike_sa_t *this);
1164 };
1165
1166 /**
1167 * Creates an ike_sa_t object with a specific ID and IKE version.
1168 *
1169 * @param ike_sa_id ike_sa_id_t to associate with new IKE_SA/ISAKMP_SA
1170 * @param initiator TRUE to create this IKE_SA as initiator
1171 * @param version IKE version of this SA
1172 * @return ike_sa_t object
1173 */
1174 ike_sa_t *ike_sa_create(ike_sa_id_t *ike_sa_id, bool initiator,
1175 ike_version_t version);
1176
1177 #endif /** IKE_SA_H_ @}*/