child-sa-manager: Add a global manager storing CHILD_SA relations
[strongswan.git] / src / libcharon / daemon.h
1 /*
2 * Copyright (C) 2006-2012 Tobias Brunner
3 * Copyright (C) 2005-2009 Martin Willi
4 * Copyright (C) 2006 Daniel Roethlisberger
5 * Copyright (C) 2005 Jan Hutter
6 * Hochschule fuer Technik Rapperswil
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 */
18
19 /**
20 * @defgroup libcharon libcharon
21 *
22 * @defgroup bus bus
23 * @ingroup libcharon
24 *
25 * @defgroup listeners listeners
26 * @ingroup bus
27 *
28 * @defgroup config config
29 * @ingroup libcharon
30 *
31 * @defgroup control control
32 * @ingroup libcharon
33 *
34 * @defgroup encoding encoding
35 * @ingroup libcharon
36 *
37 * @defgroup payloads payloads
38 * @ingroup encoding
39 *
40 * @defgroup ckernel kernel
41 * @ingroup libcharon
42 *
43 * @defgroup network network
44 * @ingroup libcharon
45 *
46 * @defgroup cplugins plugins
47 * @ingroup libcharon
48 *
49 * @defgroup cprocessing processing
50 * @ingroup libcharon
51 *
52 * @defgroup cjobs jobs
53 * @ingroup cprocessing
54 *
55 * @defgroup sa sa
56 * @ingroup libcharon
57 *
58 * @defgroup ikev1 ikev1
59 * @ingroup sa
60 *
61 * @defgroup ikev2 ikev2
62 * @ingroup sa
63 *
64 * @defgroup authenticators_v1 authenticators
65 * @ingroup ikev1
66 *
67 * @defgroup authenticators_v2 authenticators
68 * @ingroup ikev2
69 *
70 * @defgroup eap eap
71 * @ingroup sa
72 *
73 * @defgroup xauth xauth
74 * @ingroup sa
75 *
76 * @defgroup tasks_v1 tasks
77 * @ingroup ikev1
78 *
79 * @defgroup tasks_v2 tasks
80 * @ingroup ikev2
81 *
82 * @addtogroup libcharon
83 * @{
84 *
85 * IKEv2 keying daemon.
86 *
87 * All IKEv2 stuff is handled in charon. It uses a newer and more flexible
88 * architecture than pluto. Charon uses a thread-pool (called processor),
89 * which allows parallel execution SA-management. All threads originate
90 * from the processor. Work is delegated to the processor by queueing jobs
91 * to it.
92 @verbatim
93
94 +---------------------------------+ +----------------------------+
95 | controller | | config |
96 +---------------------------------+ +----------------------------+
97 | | | ^ ^ ^
98 V V V | | |
99
100 +----------+ +-----------+ +------+ +----------+ +----+
101 | receiver | | | | | +------+ | CHILD_SA | | K |
102 +---+------+ | Scheduler | | IKE- | | IKE- |--+----------+ | e |
103 | | | | SA |--| SA | | CHILD_SA | | r |
104 +------+---+ +-----------+ | | +------+ +----------+ | n |
105 <->| socket | | | Man- | | e |
106 +------+---+ +-----------+ | ager | +------+ +----------+ | l |
107 | | | | | | IKE- |--| CHILD_SA | | - |
108 +---+------+ | Processor |---| |--| SA | +----------+ | I |
109 | sender | | | | | +------+ | f |
110 +----------+ +-----------+ +------+ +----+
111
112 | | | | | |
113 V V V V V V
114 +---------------------------------+ +----------------------------+
115 | Bus | | credentials |
116 +---------------------------------+ +----------------------------+
117
118 @endverbatim
119 * The scheduler is responsible to execute timed events. Jobs may be queued to
120 * the scheduler to get executed at a defined time (e.g. rekeying). The
121 * scheduler does not execute the jobs itself, it queues them to the processor.
122 *
123 * The IKE_SA manager managers all IKE_SA. It further handles the
124 * synchronization:
125 * Each IKE_SA must be checked out strictly and checked in again after use. The
126 * manager guarantees that only one thread may check out a single IKE_SA. This
127 * allows us to write the (complex) IKE_SAs routines non-threadsave.
128 * The IKE_SA contain the state and the logic of each IKE_SA and handle the
129 * messages.
130 *
131 * The CHILD_SA contains state about a IPsec security association and manages
132 * them. An IKE_SA may have multiple CHILD_SAs. Communication to the kernel
133 * takes place here through the kernel interface.
134 *
135 * The kernel interface installs IPsec security associations, policies, routes
136 * and virtual addresses. It further provides methods to enumerate interfaces
137 * and may notify the daemon about state changes at lower layers.
138 *
139 * The bus receives signals from the different threads and relays them to
140 * interested listeners. Debugging signals, but also important state changes or
141 * error messages are sent over the bus.
142 * Its listeners are not only for logging, but also to track the state of an
143 * IKE_SA.
144 *
145 * The controller, credential_manager, bus and backend_manager (config) are
146 * places where a plugin ca register itself to privide information or observe
147 * and control the daemon.
148 */
149
150 #ifndef DAEMON_H_
151 #define DAEMON_H_
152
153 typedef struct daemon_t daemon_t;
154
155 #include <network/sender.h>
156 #include <network/receiver.h>
157 #include <network/socket_manager.h>
158 #include <control/controller.h>
159 #include <bus/bus.h>
160 #include <sa/ike_sa_manager.h>
161 #include <sa/child_sa_manager.h>
162 #include <sa/trap_manager.h>
163 #include <sa/shunt_manager.h>
164 #include <config/backend_manager.h>
165 #include <sa/eap/eap_manager.h>
166 #include <sa/xauth/xauth_manager.h>
167
168 #ifdef ME
169 #include <sa/ikev2/connect_manager.h>
170 #include <sa/ikev2/mediation_manager.h>
171 #endif /* ME */
172
173 /**
174 * Number of threads in the thread pool, if not specified in config.
175 */
176 #define DEFAULT_THREADS 16
177
178 /**
179 * Primary UDP port used by IKE.
180 */
181 #define IKEV2_UDP_PORT 500
182
183 /**
184 * UDP port defined for use in case a NAT is detected.
185 */
186 #define IKEV2_NATT_PORT 4500
187
188 /**
189 * UDP port on which the daemon will listen for incoming traffic (also used as
190 * source port for outgoing traffic).
191 */
192 #ifndef CHARON_UDP_PORT
193 #define CHARON_UDP_PORT IKEV2_UDP_PORT
194 #endif
195
196 /**
197 * UDP port used by the daemon in case a NAT is detected.
198 */
199 #ifndef CHARON_NATT_PORT
200 #define CHARON_NATT_PORT IKEV2_NATT_PORT
201 #endif
202
203 /**
204 * Main class of daemon, contains some globals.
205 */
206 struct daemon_t {
207
208 /**
209 * Socket manager instance
210 */
211 socket_manager_t *socket;
212
213 /**
214 * A ike_sa_manager_t instance.
215 */
216 ike_sa_manager_t *ike_sa_manager;
217
218 /**
219 * A child_sa_manager_t instance.
220 */
221 child_sa_manager_t *child_sa_manager;
222
223 /**
224 * Manager for triggering policies, called traps
225 */
226 trap_manager_t *traps;
227
228 /**
229 * Manager for shunt PASS|DROP policies
230 */
231 shunt_manager_t *shunts;
232
233 /**
234 * Manager for the different configuration backends.
235 */
236 backend_manager_t *backends;
237
238 /**
239 * The Sender-Thread.
240 */
241 sender_t *sender;
242
243 /**
244 * The Receiver-Thread.
245 */
246 receiver_t *receiver;
247
248 /**
249 * The signaling bus.
250 */
251 bus_t *bus;
252
253 /**
254 * Controller to control the daemon
255 */
256 controller_t *controller;
257
258 /**
259 * EAP manager to maintain registered EAP methods
260 */
261 eap_manager_t *eap;
262
263 /**
264 * XAuth manager to maintain registered XAuth methods
265 */
266 xauth_manager_t *xauth;
267
268 #ifdef ME
269 /**
270 * Connect manager
271 */
272 connect_manager_t *connect_manager;
273
274 /**
275 * Mediation manager
276 */
277 mediation_manager_t *mediation_manager;
278 #endif /* ME */
279
280 /**
281 * Initialize the daemon.
282 *
283 * @param plugins list of plugins to load
284 * @return TRUE, if successful
285 */
286 bool (*initialize)(daemon_t *this, char *plugins);
287
288 /**
289 * Starts the daemon, i.e. spawns the threads of the thread pool.
290 */
291 void (*start)(daemon_t *this);
292
293 /**
294 * Load/Reload loggers defined in strongswan.conf
295 *
296 * @param levels optional debug levels used to create default loggers
297 * if none are defined in strongswan.conf
298 * @param to_stderr TRUE to log to stderr/stdout if no loggers are defined
299 * in strongswan.conf
300 */
301 void (*load_loggers)(daemon_t *this, level_t levels[DBG_MAX],
302 bool to_stderr);
303
304 /**
305 * Set the log level for the given log group for all configured file- and
306 * syslog-loggers.
307 *
308 * @param group log group
309 * @param level log level
310 */
311 void (*set_level)(daemon_t *this, debug_t group, level_t level);
312 };
313
314 /**
315 * The one and only instance of the daemon.
316 *
317 * Set between libcharon_init() and libcharon_deinit() calls.
318 */
319 extern daemon_t *charon;
320
321 /**
322 * Initialize libcharon and create the "charon" instance of daemon_t.
323 *
324 * This function initializes the bus, listeners can be registered before
325 * calling initialize().
326 *
327 * libcharon_init() may be called multiple times in a single process, but each
328 * caller must call libcharon_deinit() for each call to libcharon_init().
329 *
330 * @return FALSE if integrity check failed
331 */
332 bool libcharon_init();
333
334 /**
335 * Deinitialize libcharon and destroy the "charon" instance of daemon_t.
336 */
337 void libcharon_deinit();
338
339 #endif /** DAEMON_H_ @}*/