simple roaming of the client works (not MOBIKE conform yet!)
[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-2007 Martin Willi
10 * Copyright (C) 2006 Tobias Brunner, Daniel Roethlisberger
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 <config/child_cfg.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 config 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 Get the reqid of the CHILD SA.
113 *
114 * Every CHILD_SA has a reqid. The kernel uses this ID to
115 * identify it.
116 *
117 * @param this calling object
118 * @return reqid of the CHILD SA
119 */
120 u_int32_t (*get_reqid)(child_sa_t *this);
121
122 /**
123 * @brief Get the SPI of this CHILD_SA.
124 *
125 * Set the boolean parameter inbound to TRUE to
126 * get the SPI for which we receive packets, use
127 * FALSE to get those we use for sending packets.
128 *
129 * @param this calling object
130 * @param inbound TRUE to get inbound SPI, FALSE for outbound.
131 * @return spi of the CHILD SA
132 */
133 u_int32_t (*get_spi) (child_sa_t *this, bool inbound);
134
135 /**
136 * @brief Get the protocol which this CHILD_SA uses to protect traffic.
137 *
138 * @param this calling object
139 * @return AH | ESP
140 */
141 protocol_id_t (*get_protocol) (child_sa_t *this);
142
143 /**
144 * @brief Get info and statistics about this CHILD_SA.
145 *
146 * @param mode mode this IKE_SA uses
147 * @param encr_algo encryption algorithm used by this CHILD_SA.
148 * @param encr_len key length of the algorithm, if any
149 * @param int_algo integrity algorithm used by this CHILD_SA
150 * @param int_len key length of the algorithm, if any
151 * @param rekey time when rekeying is scheduled
152 * @param use_in time when last traffic was seen coming in
153 * @param use_out time when last traffic was seen going out
154 * @param use_fwd time when last traffic was getting forwarded
155 */
156 void (*get_stats)(child_sa_t *this, mode_t *mode,
157 encryption_algorithm_t *encr, size_t *encr_len,
158 integrity_algorithm_t *int_algo, size_t *int_len,
159 u_int32_t *rekey, u_int32_t *use_in, u_int32_t *use_out,
160 u_int32_t *use_fwd);
161
162 /**
163 * @brief Allocate SPIs for given proposals.
164 *
165 * Since the kernel manages SPIs for us, we need
166 * to allocate them. If a proposal contains more
167 * than one protocol, for each protocol an SPI is
168 * allocated. SPIs are stored internally and written
169 * back to the proposal.
170 *
171 * @param this calling object
172 * @param proposals list of proposals for which SPIs are allocated
173 */
174 status_t (*alloc)(child_sa_t *this, linked_list_t* proposals);
175
176 /**
177 * @brief Install the kernel SAs for a proposal, without previous SPI allocation.
178 *
179 * @param this calling object
180 * @param proposal proposal for which SPIs are allocated
181 * @param mode mode for the CHILD_SA
182 * @param prf_plus key material to use for key derivation
183 * @return SUCCESS or FAILED
184 */
185 status_t (*add)(child_sa_t *this, proposal_t *proposal, mode_t mode,
186 prf_plus_t *prf_plus);
187
188 /**
189 * @brief Install the kernel SAs for a proposal, after SPIs have been allocated.
190 *
191 * Updates an SA, for which SPIs are already allocated via alloc().
192 *
193 * @param this calling object
194 * @param proposal proposal for which SPIs are allocated
195 * @param mode mode for the CHILD_SA
196 * @param prf_plus key material to use for key derivation
197 * @return SUCCESS or FAILED
198 */
199 status_t (*update)(child_sa_t *this, proposal_t *proposal, mode_t mode,
200 prf_plus_t *prf_plus);
201
202 /**
203 * @brief Update the hosts in the kernel SAs and policies.
204 *
205 * The CHILD must be INSTALLED to do this update.
206 *
207 * @param this calling object
208 * @param me the new local host
209 * @param other the new remote host
210 * @return SUCCESS or FAILED
211 */
212 status_t (*update_hosts)(child_sa_t *this, host_t *me, host_t *other);
213
214 /**
215 * @brief Install the policies using some traffic selectors.
216 *
217 * Supplied lists of traffic_selector_t's specify the policies
218 * to use for this child sa.
219 *
220 * @param this calling object
221 * @param my_ts traffic selectors for local site
222 * @param other_ts traffic selectors for remote site
223 * @param mode mode for the SA: tunnel/transport
224 * @return SUCCESS or FAILED
225 */
226 status_t (*add_policies)(child_sa_t *this, linked_list_t *my_ts_list,
227 linked_list_t *other_ts_list, mode_t mode);
228
229 /**
230 * @brief Get the traffic selectors of added policies of local host.
231 *
232 * @param this calling object
233 * @param local TRUE for own traffic selectors, FALSE for remote
234 * @return list of traffic selectors
235 */
236 linked_list_t* (*get_traffic_selectors) (child_sa_t *this, bool local);
237
238 /**
239 * @brief Get the time of this child_sa_t's last use (i.e. last use of any of its policies)
240 *
241 * @param this calling object
242 * @param inbound query for in- or outbound usage
243 * @param use_time the time
244 * @return SUCCESS or FAILED
245 */
246 status_t (*get_use_time) (child_sa_t *this, bool inbound, time_t *use_time);
247
248 /**
249 * @brief Get the state of the CHILD_SA.
250 *
251 * @param this calling object
252 */
253 child_sa_state_t (*get_state) (child_sa_t *this);
254
255 /**
256 * @brief Set the state of the CHILD_SA.
257 *
258 * @param this calling object
259 */
260 void (*set_state) (child_sa_t *this, child_sa_state_t state);
261
262 /**
263 * @brief Get the config used to set up this child sa.
264 *
265 * @param this calling object
266 * @return child_cfg
267 */
268 child_cfg_t* (*get_config) (child_sa_t *this);
269
270 /**
271 * @brief Set the virtual IP used received from IRAS.
272 *
273 * To allow proper setup of firewall rules, the virtual IP is required
274 * for filtering.
275 *
276 * @param this calling object
277 * @param ip own virtual IP
278 */
279 void (*set_virtual_ip) (child_sa_t *this, host_t *ip);
280
281 /**
282 * @brief Destroys a child_sa.
283 *
284 * @param this calling object
285 */
286 void (*destroy) (child_sa_t *this);
287 };
288
289 /**
290 * @brief Constructor to create a new child_sa_t.
291 *
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 config config to use for this CHILD_SA
297 * @param reqid reqid of old CHILD_SA when rekeying, 0 otherwise
298 * @param use_natt TRUE if NAT traversal is used
299 * @return child_sa_t object
300 *
301 * @ingroup sa
302 */
303 child_sa_t * child_sa_create(host_t *me, host_t *other,
304 identification_t *my_id, identification_t* other_id,
305 child_cfg_t *config, u_int32_t reqid, bool use_natt);
306
307 #endif /*CHILD_SA_H_*/