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