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