restructured file layout
[strongswan.git] / src / charon / daemon.h
1 /**
2 * @file daemon.h
3 *
4 * @brief Interface of daemon_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2006 Tobias Brunner, Daniel Roethlisberger
10 * Copyright (C) 2005-2006 Martin Willi
11 * Copyright (C) 2005 Jan Hutter
12 * Hochschule fuer Technik Rapperswil
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
23 */
24
25 #ifndef DAEMON_H_
26 #define DAEMON_H_
27
28 typedef struct daemon_t daemon_t;
29
30 #include <credential_store.h>
31
32 #include <network/sender.h>
33 #include <network/receiver.h>
34 #include <network/socket.h>
35 #include <processing/scheduler.h>
36 #include <processing/thread_pool.h>
37 #include <processing/job_queue.h>
38 #include <processing/event_queue.h>
39 #include <kernel/kernel_interface.h>
40 #include <control/stroke_interface.h>
41 #include <bus/bus.h>
42 #include <bus/listeners/file_logger.h>
43 #include <bus/listeners/sys_logger.h>
44 #include <sa/ike_sa_manager.h>
45 #include <config/cfg_store.h>
46 #include <config/backends/local_backend.h>
47
48 /**
49 * @defgroup charon charon
50 *
51 * @brief IKEv2 keying daemon.
52 *
53 * @section Architecture
54 *
55 * All IKEv2 stuff is handled in charon. It uses a newer and more flexible
56 * architecture than pluto. Charon uses a thread-pool, which allows parallel
57 * execution SA-management. Beside the thread-pool, there are some special purpose
58 * threads which do their job for the common health of the daemon.
59 @verbatim
60 +------+
61 | E Q |
62 | v u |---+ +------+ +------+
63 | e e | | | | | IKE- |
64 | n u | +-----------+ | |--| SA |
65 | t e | | | | I M | +------+
66 +------------+ | - | | Scheduler | | K a |
67 | receiver | +------+ | | | E n | +------+
68 +----+-------+ +-----------+ | - a | | IKE- |
69 | | +------+ | | S g |--| SA |
70 +-------+--+ +-----| J Q |---+ +------------+ | A e | +------+
71 -| socket | | o u | | | | - r |
72 +-------+--+ | b e | | Thread- | | |
73 | | - u | | Pool | | |
74 +----+-------+ | e |------| |---| |
75 | sender | +------+ +------------+ +------+
76 +------------+
77
78 @endverbatim
79 * The thread-pool is the heart of the architecture. It processes jobs from a
80 * (fully synchronized) job-queue. Mostly, a job is associated with a specific
81 * IKE SA. These IKE SAs are synchronized, only one thread can work one an IKE SA.
82 * This makes it unnecesary to use further synchronisation methods once a IKE SA
83 * is checked out. The (rather complex) synchronization of IKE SAs is completely
84 * done in the IKE SA manager.
85 * The sceduler is responsible for event firing. It waits until a event in the
86 * (fully synchronized) event-queue is ready for processing and pushes the event
87 * down to the job-queue. A thread form the pool will pick it up as quick as
88 * possible. Every thread can queue events or jobs. Furter, an event can place a
89 * packet in the sender. The sender thread waits for those packets and sends
90 * them over the wire, via the socket. The receiver does exactly the opposite of
91 * the sender. It waits on the socket, reads in packets an places them on the
92 * job-queue for further processing by a thread from the pool.
93 * There are even more threads, not drawn in the upper scheme. The stroke thread
94 * is responsible for reading and processessing commands from another process. The
95 * kernel interface thread handles communication from and to the kernel via a
96 * netlink socket. It waits for kernel events and processes them appropriately.
97 */
98
99 /**
100 * @defgroup config config
101 *
102 * Classes implementing configuration related things.
103 *
104 * @ingroup charon
105 */
106
107 /**
108 * @defgroup encoding encoding
109 *
110 * Classes used to encode and decode IKEv2 messages.
111 *
112 * @ingroup charon
113 */
114
115 /**
116 * @defgroup payloads payloads
117 *
118 * Classes representing specific IKEv2 payloads.
119 *
120 * @ingroup encoding
121 */
122
123 /**
124 * @defgroup network network
125 *
126 * Classes for network relevant stuff.
127 *
128 * @ingroup charon
129 */
130
131 /**
132 * @defgroup queues queues
133 *
134 * Different kind of queues
135 * (thread save lists).
136 *
137 * @ingroup charon
138 */
139
140 /**
141 * @defgroup jobs jobs
142 *
143 * Jobs used in job queue and event queue.
144 *
145 * @ingroup queues
146 */
147
148 /**
149 * @defgroup sa sa
150 *
151 * Security associations for IKE and IPSec,
152 * and some helper classes.
153 *
154 * @ingroup charon
155 */
156
157 /**
158 * @defgroup tasks tasks
159 *
160 * Tasks process and build message payloads. They are used to create
161 * and process multiple exchanges.
162 *
163 * @ingroup sa
164 */
165
166 /**
167 * @defgroup authenticators authenticators
168 *
169 * Authenticator classes to prove identity of peer.
170 *
171 * @ingroup sa
172 */
173
174 /**
175 * @defgroup eap eap
176 *
177 * EAP authentication module interface and it's implementations.
178 *
179 * @ingroup authenticators
180 */
181
182 /**
183 * @defgroup threads threads
184 *
185 * Threaded classes, which will do their job alone.
186 *
187 * @ingroup charon
188 */
189
190 /**
191 * @defgroup bus bus
192 *
193 * Signaling bus and its listeners.
194 *
195 * @ingroup charon
196 */
197
198 /**
199 * Name of the daemon.
200 *
201 * @ingroup charon
202 */
203 #define DAEMON_NAME "charon"
204
205 /**
206 * @brief Number of threads in the thread pool.
207 *
208 * There are several other threads, this defines
209 * only the number of threads in thread_pool_t.
210 *
211 * @ingroup charon
212 */
213 #define NUMBER_OF_WORKING_THREADS 4
214
215 /**
216 * UDP Port on which the daemon will listen for incoming traffic.
217 *
218 * @ingroup charon
219 */
220 #define IKEV2_UDP_PORT 500
221
222 /**
223 * UDP Port to which the daemon will float to if NAT is detected.
224 *
225 * @ingroup charon
226 */
227 #define IKEV2_NATT_PORT 4500
228
229 /**
230 * PID file, in which charon stores its process id
231 *
232 * @ingroup charon
233 */
234 #define PID_FILE IPSEC_PIDDIR "/charon.pid"
235
236 /**
237 * Configuration directory
238 *
239 * @ingroup charon
240 */
241 #define CONFIG_DIR IPSEC_CONFDIR
242
243 /**
244 * Directory of IPsec relevant files
245 *
246 * @ingroup charon
247 */
248 #define IPSEC_D_DIR CONFIG_DIR "/ipsec.d"
249
250 /**
251 * Default directory for private keys
252 *
253 * @ingroup charon
254 */
255 #define PRIVATE_KEY_DIR IPSEC_D_DIR "/private"
256
257 /**
258 * Default directory for end entity certificates
259 *
260 * @ingroup charon
261 */
262 #define CERTIFICATE_DIR IPSEC_D_DIR "/certs"
263
264 /**
265 * Default directory for trusted CA certificates
266 *
267 * @ingroup charon
268 */
269 #define CA_CERTIFICATE_DIR IPSEC_D_DIR "/cacerts"
270
271 /**
272 * Default directory for OCSP signing certificates
273 *
274 * @ingroup charon
275 */
276 #define OCSP_CERTIFICATE_DIR IPSEC_D_DIR "/ocspcerts"
277
278 /**
279 * Default directory for CRLs
280 *
281 * @ingroup charon
282 */
283 #define CRL_DIR IPSEC_D_DIR "/crls"
284
285 /**
286 * Secrets files
287 *
288 * @ingroup charon
289 */
290 #define SECRETS_FILE CONFIG_DIR "/ipsec.secrets"
291
292 /**
293 * @brief Main class of daemon, contains some globals.
294 *
295 * @ingroup charon
296 */
297 struct daemon_t {
298 /**
299 * A socket_t instance.
300 */
301 socket_t *socket;
302
303 /**
304 * A job_queue_t instance.
305 */
306 job_queue_t *job_queue;
307
308 /**
309 * A event_queue_t instance.
310 */
311 event_queue_t *event_queue;
312
313 /**
314 * A ike_sa_manager_t instance.
315 */
316 ike_sa_manager_t *ike_sa_manager;
317
318 /**
319 * A configuration_t instance.
320 */
321 configuration_t *configuration;
322
323 /**
324 * A connection_store_t instance.
325 */
326 cfg_store_t *cfg_store;
327
328 /**
329 * A backend for cfg_store using in-memory lists
330 */
331 local_backend_t *local_backend;
332
333 /**
334 * A credential_store_t instance.
335 */
336 credential_store_t *credentials;
337
338 /**
339 * The Sender-Thread.
340 */
341 sender_t *sender;
342
343 /**
344 * The Receiver-Thread.
345 */
346 receiver_t *receiver;
347
348 /**
349 * The Scheduler-Thread.
350 */
351 scheduler_t *scheduler;
352
353 /**
354 * The Thread pool managing the worker threads.
355 */
356 thread_pool_t *thread_pool;
357
358 /**
359 * The signaling bus.
360 */
361 bus_t *bus;
362
363 /**
364 * A bus listener logging to stdout
365 */
366 file_logger_t *outlog;
367
368 /**
369 * A bus listener logging to syslog
370 */
371 sys_logger_t *syslog;
372
373 /**
374 * A bus listener logging most important events
375 */
376 sys_logger_t *authlog;
377
378 /**
379 * Kernel Interface to communicate with kernel
380 */
381 kernel_interface_t *kernel_interface;
382
383 /**
384 * IPC interface, as whack in pluto
385 */
386 stroke_t *stroke;
387
388 /**
389 * @brief Shut down the daemon.
390 *
391 * @param this the daemon to kill
392 * @param reason describtion why it will be killed
393 */
394 void (*kill) (daemon_t *this, char *reason);
395 };
396
397 /**
398 * The one and only instance of the daemon.
399 */
400 extern daemon_t *charon;
401
402 #endif /*DAEMON_H_*/