added support for transport mode and (experimental!) BEET mode
[strongswan.git] / src / charon / sa / child_sa.h
1 /**
2 * @file child_sa.h
3 *
4 * @brief Interface of child_sa_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2006 Tobias Brunner, Daniel Roethlisberger
10 * Copyright (C) 2006 Martin Willi
11 * Hochschule fuer Technik Rapperswil
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24
25 #ifndef CHILD_SA_H_
26 #define CHILD_SA_H_
27
28 typedef enum child_sa_state_t child_sa_state_t;
29 typedef struct child_sa_t child_sa_t;
30
31 #include <library.h>
32 #include <crypto/prf_plus.h>
33 #include <encoding/payloads/proposal_substructure.h>
34 #include <config/proposal.h>
35 #include <sa/transactions/transaction.h>
36
37 /**
38 * Where we should start with reqid enumeration
39 */
40 #define REQID_START 2000000000
41
42 /**
43 * @brief States of a CHILD_SA
44 */
45 enum child_sa_state_t {
46
47 /**
48 * Just created, uninstalled CHILD_SA
49 */
50 CHILD_CREATED,
51
52 /**
53 * Installed SPD, but no SAD entries
54 */
55 CHILD_ROUTED,
56
57 /**
58 * Installed an in-use CHILD_SA
59 */
60 CHILD_INSTALLED,
61
62 /**
63 * CHILD_SA which is rekeying
64 */
65 CHILD_REKEYING,
66
67 /**
68 * CHILD_SA in progress of delete
69 */
70 CHILD_DELETING,
71 };
72
73 /**
74 * enum strings for child_sa_state_t.
75 */
76 extern enum_name_t *child_sa_state_names;
77
78 /**
79 * @brief Represents an IPsec SAs between two hosts.
80 *
81 * A child_sa_t contains two SAs. SAs for both
82 * directions are managed in one child_sa_t object. Both
83 * SAs and the policies have the same reqid.
84 *
85 * The procedure for child sa setup is as follows:
86 * - A gets SPIs for a proposal via child_sa_t.alloc
87 * - A send the updated proposal to B
88 * - B selects a suitable proposal
89 * - B calls child_sa_t.add to add and update the selected proposal
90 * - B sends the updated proposal to A
91 * - A calls child_sa_t.update to update the already allocated SPIs with the chosen proposal
92 *
93 * Once SAs are set up, policies can be added using add_policies.
94 *
95 *
96 * @b Constructors:
97 * - child_sa_create()
98 *
99 * @ingroup sa
100 */
101 struct child_sa_t {
102
103 /**
104 * @brief Get the name of the policy this CHILD_SA uses.
105 *
106 * @param this calling object
107 * @return name
108 */
109 char* (*get_name) (child_sa_t *this);
110
111 /**
112 * @brief Set the name of the policy this IKE_SA uses.
113 *
114 * @param this calling object
115 * @param name name, gets cloned
116 */
117 void (*set_name) (child_sa_t *this, char* name);
118
119 /**
120 * @brief Get the unique reqid of the CHILD SA.
121 *
122 * Every CHILD_SA has a unique reqid, which is also
123 * stored down in the kernel.
124 *
125 * @param this calling object
126 * @return reqid of the CHILD SA
127 */
128 u_int32_t (*get_reqid)(child_sa_t *this);
129
130 /**
131 * @brief Get the SPI of this CHILD_SA.
132 *
133 * Set the boolean parameter inbound to TRUE to
134 * get the SPI for which we receive packets, use
135 * FALSE to get those we use for sending packets.
136 *
137 * @param this calling object
138 * @param inbound TRUE to get inbound SPI, FALSE for outbound.
139 * @return spi of the CHILD SA
140 */
141 u_int32_t (*get_spi) (child_sa_t *this, bool inbound);
142
143 /**
144 * @brief Get the protocol which this CHILD_SA uses to protect traffic.
145 *
146 * @param this calling object
147 * @return AH | ESP
148 */
149 protocol_id_t (*get_protocol) (child_sa_t *this);
150
151 /**
152 * @brief Allocate SPIs for given proposals.
153 *
154 * Since the kernel manages SPIs for us, we need
155 * to allocate them. If a proposal contains more
156 * than one protocol, for each protocol an SPI is
157 * allocated. SPIs are stored internally and written
158 * back to the proposal.
159 *
160 * @param this calling object
161 * @param proposals list of proposals for which SPIs are allocated
162 */
163 status_t (*alloc)(child_sa_t *this, linked_list_t* proposals);
164
165 /**
166 * @brief Install the kernel SAs for a proposal, without previous SPI allocation.
167 *
168 * @param this calling object
169 * @param proposal proposal for which SPIs are allocated
170 * @param mode mode for the CHILD_SA
171 * @param prf_plus key material to use for key derivation
172 * @return SUCCESS or FAILED
173 */
174 status_t (*add)(child_sa_t *this, proposal_t *proposal, mode_t mode,
175 prf_plus_t *prf_plus);
176
177 /**
178 * @brief Install the kernel SAs for a proposal, after SPIs have been allocated.
179 *
180 * Updates an SA, for which SPIs are already allocated via alloc().
181 *
182 * @param this calling object
183 * @param proposal proposal for which SPIs are allocated
184 * @param mode mode for the CHILD_SA
185 * @param prf_plus key material to use for key derivation
186 * @return SUCCESS or FAILED
187 */
188 status_t (*update)(child_sa_t *this, proposal_t *proposal, mode_t mode,
189 prf_plus_t *prf_plus);
190
191 /**
192 * @brief Update the hosts in the kernel SAs and policies
193 *
194 * @warning only call this after update() has been called.
195 *
196 * @param this calling object
197 * @param new_me the new local host
198 * @param new_other the new remote host
199 * @param my_diff differences to apply for me
200 * @param other_diff differences to apply for other
201 * @return SUCCESS or FAILED
202 */
203 status_t (*update_hosts)(child_sa_t *this, host_t *new_me, host_t *new_other,
204 host_diff_t my_diff, host_diff_t other_diff);
205
206 /**
207 * @brief Install the policies using some traffic selectors.
208 *
209 * Supplied lists of traffic_selector_t's specify the policies
210 * to use for this child sa.
211 *
212 * @param this calling object
213 * @param my_ts traffic selectors for local site
214 * @param other_ts traffic selectors for remote site
215 * @param mode mode for the SA: tunnel/transport
216 * @return SUCCESS or FAILED
217 */
218 status_t (*add_policies)(child_sa_t *this, linked_list_t *my_ts_list,
219 linked_list_t *other_ts_list, mode_t mode);
220
221 /**
222 * @brief Get the traffic selectors of added policies of local host.
223 *
224 * @param this calling object
225 * @return list of traffic selectors
226 */
227 linked_list_t* (*get_my_traffic_selectors) (child_sa_t *this);
228
229 /**
230 * @brief Get the traffic selectors of added policies of remote host.
231 *
232 * @param this calling object
233 * @return list of traffic selectors
234 */
235 linked_list_t* (*get_other_traffic_selectors) (child_sa_t *this);
236
237 /**
238 * @brief Get the time of this child_sa_t's last use (i.e. last use of any of its policies)
239 *
240 * @param this calling object
241 * @param inbound query for in- or outbound usage
242 * @param use_time the time
243 * @return SUCCESS or FAILED
244 */
245 status_t (*get_use_time) (child_sa_t *this, bool inbound, time_t *use_time);
246
247 /**
248 * @brief Get the state of the CHILD_SA.
249 *
250 * @param this calling object
251 */
252 child_sa_state_t (*get_state) (child_sa_t *this);
253
254 /**
255 * @brief Set the state of the CHILD_SA.
256 *
257 * @param this calling object
258 */
259 void (*set_state) (child_sa_t *this, child_sa_state_t state);
260
261 /**
262 * @brief Set the transaction which rekeys this CHILD_SA.
263 *
264 * Since either end may initiate CHILD_SA rekeying, we must detect
265 * such situations to handle them cleanly. A rekeying transaction
266 * registers itself to the CHILD_SA, and checks later if another
267 * transaction is in progress of a rekey.
268 *
269 * @param this calling object
270 */
271 void (*set_rekeying_transaction) (child_sa_t *this, transaction_t *transaction);
272
273 /**
274 * @brief Get the transaction which rekeys this CHILD_SA.
275 *
276 * @param this calling object
277 */
278 transaction_t* (*get_rekeying_transaction) (child_sa_t *this);
279
280 /**
281 * @brief Destroys a child_sa.
282 *
283 * @param this calling object
284 */
285 void (*destroy) (child_sa_t *this);
286 };
287
288 /**
289 * @brief Constructor to create a new child_sa_t.
290 *
291 * @param rekey_reqid reqid of old CHILD_SA when rekeying, 0 otherwise
292 * @param me own address
293 * @param other remote address
294 * @param my_id id of own peer
295 * @param other_id id of remote peer
296 * @param soft_lifetime time before rekeying
297 * @param hard_lifteime time before delete
298 * @param script updown script to use when calling child_sa_t.script()
299 * @param hostaccess allow host access (needed by updown script)
300 * @param use_natt TRUE if NAT traversal is used
301 * @return child_sa_t object
302 *
303 * @ingroup sa
304 */
305 child_sa_t * child_sa_create(u_int32_t rekey_reqid, host_t *me, host_t *other,
306 identification_t *my_id, identification_t* other_id,
307 u_int32_t soft_lifetime, u_int32_t hard_lifetime,
308 char *script, bool hostaccess, bool use_natt);
309
310 #endif /*CHILD_SA_H_*/