2 * Copyright (C) 2006-2008 Tobias Brunner
3 * Copyright (C) 2006-2008 Martin Willi
4 * Copyright (C) 2006 Daniel Roethlisberger
5 * Hochschule fuer Technik Rapperswil
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>.
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
19 * @defgroup child_sa child_sa
26 typedef enum child_sa_state_t child_sa_state_t
;
27 typedef struct child_sa_t child_sa_t
;
30 #include <crypto/prf_plus.h>
31 #include <encoding/payloads/proposal_substructure.h>
32 #include <config/proposal.h>
33 #include <config/child_cfg.h>
36 * States of a CHILD_SA
38 enum child_sa_state_t
{
41 * Just created, uninstalled CHILD_SA
46 * Installed SPD, but no SAD entries
51 * Installing an in-use CHILD_SA
56 * Installed an in-use CHILD_SA
61 * While updating hosts, in update_hosts()
66 * CHILD_SA which is rekeying
71 * CHILD_SA in progress of delete
76 * CHILD_SA object gets destroyed
82 * enum strings for child_sa_state_t.
84 extern enum_name_t
*child_sa_state_names
;
87 * Represents an IPsec SAs between two hosts.
89 * A child_sa_t contains two SAs. SAs for both
90 * directions are managed in one child_sa_t object. Both
91 * SAs and the policies have the same reqid.
93 * The procedure for child sa setup is as follows:
94 * - A gets SPIs for a all protocols in its proposals via child_sa_t.alloc
95 * - A send the proposals with the allocated SPIs to B
96 * - B selects a suitable proposal
97 * - B allocates an SPI for the selected protocol
98 * - B calls child_sa_t.install for both, the allocated and received SPI
99 * - B sends the proposal with the allocated SPI to A
100 * - A calls child_sa_t.install for both, the allocated and recevied SPI
102 * Once SAs are set up, policies can be added using add_policies.
107 * Get the name of the config this CHILD_SA uses.
111 char* (*get_name
) (child_sa_t
*this);
114 * Get the reqid of the CHILD SA.
116 * Every CHILD_SA has a reqid. The kernel uses this ID to
119 * @return reqid of the CHILD SA
121 u_int32_t (*get_reqid
)(child_sa_t
*this);
124 * Get the config used to set up this child sa.
128 child_cfg_t
* (*get_config
) (child_sa_t
*this);
131 * Get the state of the CHILD_SA.
133 * @return CHILD_SA state
135 child_sa_state_t (*get_state
) (child_sa_t
*this);
138 * Set the state of the CHILD_SA.
140 * @param state state to set on CHILD_SA
142 void (*set_state
) (child_sa_t
*this, child_sa_state_t state
);
145 * Get the SPI of this CHILD_SA.
147 * Set the boolean parameter inbound to TRUE to
148 * get the SPI for which we receive packets, use
149 * FALSE to get those we use for sending packets.
151 * @param inbound TRUE to get inbound SPI, FALSE for outbound.
152 * @return SPI of the CHILD SA
154 u_int32_t (*get_spi
) (child_sa_t
*this, bool inbound
);
157 * Get the CPI of this CHILD_SA.
159 * Set the boolean parameter inbound to TRUE to
160 * get the CPI for which we receive packets, use
161 * FALSE to get those we use for sending packets.
163 * @param inbound TRUE to get inbound CPI, FALSE for outbound.
164 * @return CPI of the CHILD SA
166 u_int16_t (*get_cpi
) (child_sa_t
*this, bool inbound
);
169 * Get the protocol which this CHILD_SA uses to protect traffic.
173 protocol_id_t (*get_protocol
) (child_sa_t
*this);
176 * Set the negotiated protocol to use for this CHILD_SA.
178 * @param protocol AH | ESP
180 void (*set_protocol
)(child_sa_t
*this, protocol_id_t protocol
);
183 * Get the IPsec mode of this CHILD_SA.
185 * @return TUNNEL | TRANSPORT | BEET
187 ipsec_mode_t (*get_mode
)(child_sa_t
*this);
190 * Set the negotiated IPsec mode to use.
192 * @param mode TUNNEL | TRANPORT | BEET
194 void (*set_mode
)(child_sa_t
*this, ipsec_mode_t mode
);
197 * Get the used IPComp algorithm.
199 * @return IPComp compression algorithm.
201 ipcomp_transform_t (*get_ipcomp
)(child_sa_t
*this);
204 * Set the IPComp algorithm to use.
206 * @param ipcomp the IPComp transform to use
208 void (*set_ipcomp
)(child_sa_t
*this, ipcomp_transform_t ipcomp
);
211 * Get the selected proposal.
213 * @return selected proposal
215 proposal_t
* (*get_proposal
)(child_sa_t
*this);
218 * Set the negotiated proposal.
220 * @param proposal selected proposal
222 void (*set_proposal
)(child_sa_t
*this, proposal_t
*proposal
);
225 * Check if this CHILD_SA uses UDP encapsulation.
227 * @return TRUE if SA encapsulates ESP packets
229 bool (*has_encap
)(child_sa_t
*this);
232 * Get the lifetime of the CHILD_SA.
234 * @param hard TRUE for hard lifetime, FALSE for soft (rekey) lifetime
235 * @return lifetime in seconds
237 u_int32_t (*get_lifetime
)(child_sa_t
*this, bool hard
);
240 * Get last use time of the CHILD_SA.
242 * @param inbound TRUE for inbound traffic, FALSE for outbound
243 * @return time of last use in seconds
245 u_int32_t (*get_usetime
)(child_sa_t
*this, bool inbound
);
248 * Get the traffic selectors list added for one side.
250 * @param local TRUE for own traffic selectors, FALSE for remote
251 * @return list of traffic selectors
253 linked_list_t
* (*get_traffic_selectors
) (child_sa_t
*this, bool local
);
256 * Create an enumerator over installed policies.
258 * @return enumerator over pairs of traffic selectors.
260 enumerator_t
* (*create_policy_enumerator
)(child_sa_t
*this);
263 * Allocate an SPI to include in a proposal.
265 * @param protocol protocol to allocate SPI for (ESP|AH)
266 * @param spi SPI output pointer
267 * @return SPI, 0 on failure
269 u_int32_t (*alloc_spi
)(child_sa_t
*this, protocol_id_t protocol
);
272 * Allocate a CPI to use for IPComp.
274 * @return CPI, 0 on failure
276 u_int16_t (*alloc_cpi
)(child_sa_t
*this);
279 * Install an IPsec SA for one direction.
281 * @param encr encryption key, if any
282 * @param integ integrity key
283 * @param spi SPI to use, allocated for inbound
284 * @param cpi CPI to use, allocated for outbound
285 * @param inbound TRUE to install an inbound SA, FALSE for outbound
286 * @return SUCCESS or FAILED
288 status_t (*install
)(child_sa_t
*this, chunk_t encr
, chunk_t integ
,
289 u_int32_t spi
, u_int16_t cpi
, bool inbound
);
291 * Install the policies using some traffic selectors.
293 * Supplied lists of traffic_selector_t's specify the policies
294 * to use for this child sa.
296 * @param my_ts traffic selectors for local site
297 * @param other_ts traffic selectors for remote site
298 * @return SUCCESS or FAILED
300 status_t (*add_policies
)(child_sa_t
*this, linked_list_t
*my_ts_list
,
301 linked_list_t
*other_ts_list
);
303 * Update hosts and ecapulation mode in the kernel SAs and policies.
305 * @param me the new local host
306 * @param other the new remote host
307 * @param vip virtual IP, if any
308 * @param TRUE to use UDP encapsulation for NAT traversal
309 * @return SUCCESS or FAILED
311 status_t (*update
)(child_sa_t
*this, host_t
*me
, host_t
*other
,
312 host_t
*vip
, bool encap
);
314 * Destroys a child_sa.
316 void (*destroy
) (child_sa_t
*this);
320 * Constructor to create a new child_sa_t.
322 * @param me own address
323 * @param other remote address
324 * @param config config to use for this CHILD_SA
325 * @param reqid reqid of old CHILD_SA when rekeying, 0 otherwise
326 * @param encap TRUE to enable UDP encapsulation (NAT traversal)
327 * @return child_sa_t object
329 child_sa_t
* child_sa_create(host_t
*me
, host_t
*other
, child_cfg_t
*config
,
330 u_int32_t reqid
, bool encap
);
332 #endif /** CHILD_SA_H_ @}*/