Merge branch 'ikev1-clean' into ikev1-master
[strongswan.git] / src / libcharon / sa / ike_sa_id.h
1 /*
2 * Copyright (C) 2012 Tobias Brunner
3 * Copyright (C) 2005-2006 Martin Willi
4 * Copyright (C) 2005 Jan Hutter
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 /**
19 * @defgroup ike_sa_id ike_sa_id
20 * @{ @ingroup sa
21 */
22
23 #ifndef IKE_SA_ID_H_
24 #define IKE_SA_ID_H_
25
26 typedef struct ike_sa_id_t ike_sa_id_t;
27
28 #include <library.h>
29
30 /**
31 * An object of type ike_sa_id_t is used to identify an IKE_SA.
32 *
33 * An IKE_SA is identified by its initiator and responder SPIs.
34 * Additionally, it contains the major IKE version of the IKE_SA and, for IKEv2,
35 * the role of the daemon (original initiator or responder).
36 */
37 struct ike_sa_id_t {
38
39 /**
40 * Get the major IKE version of this IKE_SA.
41 *
42 * @return IKE version
43 */
44 u_int8_t (*get_ike_version) (ike_sa_id_t *this);
45
46 /**
47 * Set the SPI of the responder.
48 *
49 * This function is called when a request or reply of a IKE_SA_INIT is received.
50 *
51 * @param responder_spi SPI of responder to set
52 */
53 void (*set_responder_spi) (ike_sa_id_t *this, u_int64_t responder_spi);
54
55 /**
56 * Set the SPI of the initiator.
57 *
58 * @param initiator_spi SPI to set
59 */
60 void (*set_initiator_spi) (ike_sa_id_t *this, u_int64_t initiator_spi);
61
62 /**
63 * Get the initiator SPI.
64 *
65 * @return SPI of the initiator
66 */
67 u_int64_t (*get_initiator_spi) (ike_sa_id_t *this);
68
69 /**
70 * Get the responder SPI.
71 *
72 * @return SPI of the responder
73 */
74 u_int64_t (*get_responder_spi) (ike_sa_id_t *this);
75
76 /**
77 * Check if two ike_sa_id_t objects are equal.
78 *
79 * Two ike_sa_id_t objects are equal if version and both SPI values match.
80 * The role is not compared.
81 *
82 * @param other ike_sa_id_t object to check if equal
83 * @return TRUE if given ike_sa_id_t are equal,
84 * FALSE otherwise
85 */
86 bool (*equals) (ike_sa_id_t *this, ike_sa_id_t *other);
87
88 /**
89 * Replace all values of a given ike_sa_id_t object with values.
90 * from another ike_sa_id_t object.
91 *
92 * After calling this function, both objects are equal.
93 *
94 * @param other ike_sa_id_t object from which values will be taken
95 */
96 void (*replace_values) (ike_sa_id_t *this, ike_sa_id_t *other);
97
98 /**
99 * Get the initiator flag.
100 *
101 * @return TRUE if we are the original initiator
102 */
103 bool (*is_initiator) (ike_sa_id_t *this);
104
105 /**
106 * Switch the original initiator flag.
107 *
108 * @return new value if initiator flag.
109 */
110 bool (*switch_initiator) (ike_sa_id_t *this);
111
112 /**
113 * Clones a given ike_sa_id_t object.
114 *
115 * @return cloned ike_sa_id_t object
116 */
117 ike_sa_id_t *(*clone) (ike_sa_id_t *this);
118
119 /**
120 * Destroys an ike_sa_id_t object.
121 */
122 void (*destroy) (ike_sa_id_t *this);
123 };
124
125 /**
126 * Creates an ike_sa_id_t object.
127 *
128 * @param ike_version major IKE version
129 * @param initiator_spi initiators SPI
130 * @param responder_spi responders SPI
131 * @param is_initiaor TRUE if we are the original initiator
132 * @return ike_sa_id_t object
133 */
134 ike_sa_id_t * ike_sa_id_create(u_int8_t ike_version, u_int64_t initiator_spi,
135 u_int64_t responder_spi, bool is_initiaor);
136
137 #endif /** IKE_SA_ID_H_ @}*/