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