restructured file layout
[strongswan.git] / src / charon / config / child_cfg.h
1 /**
2 * @file child_cfg.h
3 *
4 * @brief Interface of child_cfg_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005-2007 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
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 #ifndef CHILD_CFG_H_
25 #define CHILD_CFG_H_
26
27 typedef enum mode_t mode_t;
28 typedef struct child_cfg_t child_cfg_t;
29
30 #include <library.h>
31 #include <config/proposal.h>
32 #include <config/traffic_selector.h>
33
34 /**
35 * @brief Mode of an CHILD_SA.
36 *
37 * These are equal to those defined in XFRM, so don't change.
38 *
39 * @ingroup child_cfg
40 */
41 enum mode_t {
42 /** transport mode, no inner address */
43 MODE_TRANSPORT = 0,
44 /** tunnel mode, inner and outer addresses */
45 MODE_TUNNEL = 1,
46 /** BEET mode, tunnel mode but fixed, bound inner addresses */
47 MODE_BEET = 4,
48 };
49
50 /**
51 * enum names for mode_t.
52 */
53 extern enum_name_t *mode_names;
54
55 /**
56 * @brief A child_cfg_t defines the config template for a CHILD_SA.
57 *
58 * After creation, proposals and traffic selectors may be added to the config.
59 * A child_cfg object is referenced multiple times, and is not thread save.
60 * Reading from the object is save, adding things is not allowed when other
61 * threads may access the object.
62 * A reference counter handles the number of references hold to this config.
63 *
64 * @b Constructors:
65 * - child_cfg_create()
66 *
67 * @ingroup child_cfg
68 */
69 struct child_cfg_t {
70
71 /**
72 * @brief Get the name of the child_cfg.
73 *
74 * @param this calling object
75 * @return child_cfg's name
76 */
77 char *(*get_name) (child_cfg_t *this);
78
79 /**
80 * @brief Add a proposal to the list.
81 *
82 * The proposals are stored by priority, first added
83 * is the most prefered.
84 * After add, proposal is owned by child_cfg.
85 *
86 * @param this calling object
87 * @param proposal proposal to add
88 */
89 void (*add_proposal) (child_cfg_t *this, proposal_t *proposal);
90
91 /**
92 * @brief Get the list of proposals for the CHILD_SA.
93 *
94 * Resulting list and all of its proposals must be freed after use.
95 *
96 * @param this calling object
97 * @return list of proposals
98 */
99 linked_list_t* (*get_proposals)(child_cfg_t *this);
100
101 /**
102 * @brief Select a proposal from a supplied list.
103 *
104 * Returned propsal is newly created and must be destroyed after usage.
105 *
106 * @param this calling object
107 * @param proposals list from from wich proposals are selected
108 * @return selected proposal, or NULL if nothing matches
109 */
110 proposal_t* (*select_proposal)(child_cfg_t*this, linked_list_t *proposals);
111
112 /**
113 * @brief Add a traffic selector to the config.
114 *
115 * Use the "local" parameter to add it for the local or the remote side.
116 * After add, traffic selector is owned by child_cfg.
117 *
118 * @param this calling object
119 * @param local TRUE for local side, FALSE for remote
120 * @param ts traffic_selector to add
121 */
122 void (*add_traffic_selector)(child_cfg_t *this, bool local,
123 traffic_selector_t *ts);
124
125 /**
126 * @brief Get a list of traffic selectors to use for the CHILD_SA.
127 *
128 * The config contains two set of traffic selectors, one for the local
129 * side, one for the remote side.
130 * If a list with traffic selectors is supplied, these are used to narrow
131 * down the traffic selector list to the greatest common divisor.
132 * Some traffic selector may be "dymamic", meaning they are narrowed down
133 * to a specific address (host-to-host or virtual-IP setups). Use
134 * the "host" parameter to narrow such traffic selectors to that address.
135 * Resulted list and its traffic selectors must be destroyed after use.
136 *
137 * @param this calling object
138 * @param local TRUE for TS on local side, FALSE for remote
139 * @param supplied list with TS to select from, or NULL
140 * @param host address to use for narrowing "dynamic" TS', or NULL
141 * @return list containing the traffic selectors
142 */
143 linked_list_t *(*get_traffic_selectors)(child_cfg_t *this, bool local,
144 linked_list_t *supplied,
145 host_t *host);
146
147 /**
148 * @brief Get the updown script to run for the CHILD_SA.
149 *
150 * @param this calling object
151 * @return path to updown script
152 */
153 char* (*get_updown)(child_cfg_t *this);
154
155 /**
156 * @brief Should we allow access to the local host (gateway)?
157 *
158 * @param this calling object
159 * @return value of hostaccess flag
160 */
161 bool (*get_hostaccess) (child_cfg_t *this);
162
163 /**
164 * @brief Get the lifetime of a CHILD_SA.
165 *
166 * If "rekey" is set to TRUE, a lifetime is returned before the first
167 * rekeying should be started. If it is FALSE, the actual lifetime is
168 * returned when the CHILD_SA must be deleted.
169 * The rekey time automatically contains a jitter to avoid simlutaneous
170 * rekeying.
171 *
172 * @param this child_cfg
173 * @param rekey TRUE to get rekey time
174 * @return lifetime in seconds
175 */
176 u_int32_t (*get_lifetime) (child_cfg_t *this, bool rekey);
177
178 /**
179 * @brief Get the mode to use for the CHILD_SA.
180 *
181 * The mode is either tunnel, transport or BEET. The peer must agree
182 * on the method, fallback is tunnel mode.
183 *
184 * @param this child_cfg
185 * @return lifetime in seconds
186 */
187 mode_t (*get_mode) (child_cfg_t *this);
188
189 /**
190 * @brief Get a new reference.
191 *
192 * Get a new reference to this child_cfg by increasing
193 * it's internal reference counter.
194 * Do not call get_ref or any other function until you
195 * already have a reference. Otherwise the object may get
196 * destroyed while calling get_ref(),
197 *
198 * @param this calling object
199 */
200 void (*get_ref) (child_cfg_t *this);
201
202 /**
203 * @brief Destroys the child_cfg object.
204 *
205 * Decrements the internal reference counter and
206 * destroys the child_cfg when it reaches zero.
207 *
208 * @param this calling object
209 */
210 void (*destroy) (child_cfg_t *this);
211 };
212
213 /**
214 * @brief Create a configuration template for CHILD_SA setup.
215 *
216 * The "name" string gets cloned.
217 * Lifetimes are in seconds. To prevent to peers to start rekeying at the
218 * same time, a jitter may be specified. Rekeying of an SA starts at
219 * (rekeytime - random(0, jitter)). You should specify
220 * lifetime > rekeytime > jitter.
221 * After a call to create, a reference is obtained (refcount = 1).
222 *
223 * @param name name of the child_cfg
224 * @param lifetime lifetime after CHILD_SA expires and gets deleted
225 * @param rekeytime time when rekeying should be initiated
226 * @param jitter range of randomization time to remove from rekeytime
227 * @param updown updown script to execute on up/down event
228 * @param hostaccess TRUE to allow access to the local host
229 * @param mode mode to propose for CHILD_SA, transport, tunnel or BEET
230 * @return child_cfg_t object
231 *
232 * @ingroup child_cfg
233 */
234 child_cfg_t *child_cfg_create(char *name, u_int32_t lifetime,
235 u_int32_t rekeytime, u_int32_t jitter,
236 char *updown, bool hostaccess,
237 mode_t mode);
238
239 #endif /* CHILD_CFG_H_ */