1e6fe3fe919fd6c40c29afc193f0cae7ba880a3f
[strongswan.git] / src / libcharon / config / child_cfg.h
1 /*
2 * Copyright (C) 2008-2009 Tobias Brunner
3 * Copyright (C) 2005-2007 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 child_cfg child_cfg
20 * @{ @ingroup config
21 */
22
23 #ifndef CHILD_CFG_H_
24 #define CHILD_CFG_H_
25
26 typedef enum action_t action_t;
27 typedef struct child_cfg_t child_cfg_t;
28
29 #include <library.h>
30 #include <selectors/traffic_selector.h>
31 #include <config/proposal.h>
32 #include <kernel/kernel_ipsec.h>
33
34 /**
35 * Action to take when DPD detected/connection gets closed by peer.
36 */
37 enum action_t {
38 /** No action */
39 ACTION_NONE,
40 /** Route config to reestablish on demand */
41 ACTION_ROUTE,
42 /** Restart config immediately */
43 ACTION_RESTART,
44 };
45
46 /**
47 * enum names for action_t.
48 */
49 extern enum_name_t *action_names;
50
51 /**
52 * A child_cfg_t defines the config template for a CHILD_SA.
53 *
54 * After creation, proposals and traffic selectors may be added to the config.
55 * A child_cfg object is referenced multiple times, and is not thread save.
56 * Reading from the object is save, adding things is not allowed while other
57 * threads may access the object.
58 * A reference counter handles the number of references hold to this config.
59 *
60 * @see peer_cfg_t to get an overview over the configurations.
61 */
62 struct child_cfg_t {
63
64 /**
65 * Get the name of the child_cfg.
66 *
67 * @return child_cfg's name
68 */
69 char *(*get_name) (child_cfg_t *this);
70
71 /**
72 * Add a proposal to the list.
73 *
74 * The proposals are stored by priority, first added
75 * is the most prefered.
76 * After add, proposal is owned by child_cfg.
77 *
78 * @param proposal proposal to add
79 */
80 void (*add_proposal) (child_cfg_t *this, proposal_t *proposal);
81
82 /**
83 * Get the list of proposals for the CHILD_SA.
84 *
85 * Resulting list and all of its proposals must be freed after use.
86 *
87 * @param strip_dh TRUE strip out diffie hellman groups
88 * @return list of proposals
89 */
90 linked_list_t* (*get_proposals)(child_cfg_t *this, bool strip_dh);
91
92 /**
93 * Select a proposal from a supplied list.
94 *
95 * Returned propsal is newly created and must be destroyed after usage.
96 *
97 * @param proposals list from from wich proposals are selected
98 * @param strip_dh TRUE strip out diffie hellman groups
99 * @param private accept algorithms from a private range
100 * @return selected proposal, or NULL if nothing matches
101 */
102 proposal_t* (*select_proposal)(child_cfg_t*this, linked_list_t *proposals,
103 bool strip_dh, bool private);
104
105 /**
106 * Add a traffic selector to the config.
107 *
108 * Use the "local" parameter to add it for the local or the remote side.
109 * After add, traffic selector is owned by child_cfg.
110 *
111 * @param local TRUE for local side, FALSE for remote
112 * @param ts traffic_selector to add
113 */
114 void (*add_traffic_selector)(child_cfg_t *this, bool local,
115 traffic_selector_t *ts);
116
117 /**
118 * Get a list of traffic selectors to use for the CHILD_SA.
119 *
120 * The config contains two set of traffic selectors, one for the local
121 * side, one for the remote side.
122 * If a list with traffic selectors is supplied, these are used to narrow
123 * down the traffic selector list to the greatest common divisor.
124 * Some traffic selector may be "dymamic", meaning they are narrowed down
125 * to a specific address (host-to-host or virtual-IP setups). Use
126 * the "host" parameter to narrow such traffic selectors to that address.
127 * Resulted list and its traffic selectors must be destroyed after use.
128 *
129 * @param local TRUE for TS on local side, FALSE for remote
130 * @param supplied list with TS to select from, or NULL
131 * @param host address to use for narrowing "dynamic" TS', or NULL
132 * @return list containing the traffic selectors
133 */
134 linked_list_t *(*get_traffic_selectors)(child_cfg_t *this, bool local,
135 linked_list_t *supplied,
136 host_t *host);
137 /**
138 * Get the updown script to run for the CHILD_SA.
139 *
140 * @return path to updown script
141 */
142 char* (*get_updown)(child_cfg_t *this);
143
144 /**
145 * Should we allow access to the local host (gateway)?
146 *
147 * @return value of hostaccess flag
148 */
149 bool (*get_hostaccess) (child_cfg_t *this);
150
151 /**
152 * Get the lifetime configuration of a CHILD_SA.
153 *
154 * The rekey limits automatically contain a jitter to avoid simultaneous
155 * rekeying. These values will change with each call to this function.
156 *
157 * @return lifetime_cfg_t (has to be freed)
158 */
159 lifetime_cfg_t* (*get_lifetime) (child_cfg_t *this);
160
161 /**
162 * Get the mode to use for the CHILD_SA.
163 *
164 * The mode is either tunnel, transport or BEET. The peer must agree
165 * on the method, fallback is tunnel mode.
166 *
167 * @return ipsec mode
168 */
169 ipsec_mode_t (*get_mode) (child_cfg_t *this);
170
171 /**
172 * Action to take on DPD.
173 *
174 * @return DPD action
175 */
176 action_t (*get_dpd_action) (child_cfg_t *this);
177
178 /**
179 * Action to take if CHILD_SA gets closed.
180 *
181 * @return close action
182 */
183 action_t (*get_close_action) (child_cfg_t *this);
184
185 /**
186 * Get the DH group to use for CHILD_SA setup.
187 *
188 * @return dh group to use
189 */
190 diffie_hellman_group_t (*get_dh_group)(child_cfg_t *this);
191
192 /**
193 * Check whether IPComp should be used, if the other peer supports it.
194 *
195 * @return TRUE, if IPComp should be used
196 * FALSE, otherwise
197 */
198 bool (*use_ipcomp)(child_cfg_t *this);
199
200 /**
201 * Get the inactivity timeout value.
202 *
203 * @return inactivity timeout in s
204 */
205 u_int32_t (*get_inactivity)(child_cfg_t *this);
206
207 /**
208 * Specific reqid to use for CHILD_SA
209 *
210 * @return reqid
211 */
212 u_int32_t (*get_reqid)(child_cfg_t *this);
213
214 /**
215 * Optional mark for CHILD_SA
216 *
217 * @param inbound TRUE for inbound, FALSE for outbound
218 * @return mark
219 */
220 mark_t (*get_mark)(child_cfg_t *this, bool inbound);
221
222 /**
223 * Sets two options needed for Mobile IPv6 interoperability
224 *
225 * @param proxy_mode use IPsec transport proxy mode (default FALSE)
226 * @param install_policy install IPsec kernel policies (default TRUE)
227 */
228 void (*set_mipv6_options)(child_cfg_t *this, bool proxy_mode,
229 bool install_policy);
230
231 /**
232 * Check whether IPsec transport SA should be set up in proxy mode
233 *
234 * @return TRUE, if proxy mode should be used
235 * FALSE, otherwise
236 */
237 bool (*use_proxy_mode)(child_cfg_t *this);
238
239 /**
240 * Check whether IPsec policies should be installed in the kernel
241 *
242 * @return TRUE, if IPsec kernel policies should be installed
243 * FALSE, otherwise
244 */
245 bool (*install_policy)(child_cfg_t *this);
246
247 /**
248 * Increase the reference count.
249 *
250 * @return reference to this
251 */
252 child_cfg_t* (*get_ref) (child_cfg_t *this);
253
254 /**
255 * Destroys the child_cfg object.
256 *
257 * Decrements the internal reference counter and
258 * destroys the child_cfg when it reaches zero.
259 */
260 void (*destroy) (child_cfg_t *this);
261 };
262
263 /**
264 * Create a configuration template for CHILD_SA setup.
265 *
266 * The "name" string gets cloned.
267 *
268 * The lifetime_cfg_t object gets cloned.
269 * To prevent two peers to start rekeying at the same time, a jitter may be
270 * specified. Rekeying of an SA starts at (x.rekey - random(0, x.jitter)).
271 *
272 * After a call to create, a reference is obtained (refcount = 1).
273 *
274 * @param name name of the child_cfg
275 * @param lifetime lifetime_cfg_t for this child_cfg
276 * @param updown updown script to execute on up/down event
277 * @param hostaccess TRUE to allow access to the local host
278 * @param mode mode to propose for CHILD_SA, transport, tunnel or BEET
279 * @param dpd_action DPD action
280 * @param close_action close action
281 * @param ipcomp use IPComp, if peer supports it
282 * @param inactivity inactivity timeout in s before closing a CHILD_SA
283 * @param reqid specific reqid to use for CHILD_SA, 0 for auto assign
284 * @param mark_in optional inbound mark (can be NULL)
285 * @param mark_out optional outbound mark (can be NULL)
286 * @return child_cfg_t object
287 */
288 child_cfg_t *child_cfg_create(char *name, lifetime_cfg_t *lifetime,
289 char *updown, bool hostaccess,
290 ipsec_mode_t mode, action_t dpd_action,
291 action_t close_action, bool ipcomp,
292 u_int32_t inactivity, u_int32_t reqid,
293 mark_t *mark_in, mark_t *mark_out);
294
295 #endif /** CHILD_CFG_H_ @}*/