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