added parsing level to x509_create_from_chunk()
[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 <threads/sender.h>
31 #include <threads/receiver.h>
32 #include <threads/scheduler.h>
33 #include <threads/kernel_interface.h>
34 #include <threads/thread_pool.h>
35 #include <threads/stroke_interface.h>
36 #include <network/socket.h>
37 #include <bus/bus.h>
38 #include <bus/listeners/file_logger.h>
39 #include <bus/listeners/sys_logger.h>
40 #include <sa/ike_sa_manager.h>
41 #include <queues/send_queue.h>
42 #include <queues/job_queue.h>
43 #include <queues/event_queue.h>
44 #include <config/configuration.h>
45 #include <config/connections/connection_store.h>
46 #include <config/policies/policy_store.h>
47 #include <config/credentials/credential_store.h>
48
49 /**
50 * @defgroup charon charon
51 *
52 * @brief IKEv2 keying daemon.
53 *
54 * @section Architecture
55 *
56 * All IKEv2 stuff is handled in charon. It uses a newer and more flexible
57 * architecture than pluto. Charon uses a thread-pool, which allows parallel
58 * execution SA-management. Beside the thread-pool, there are some special purpose
59 * threads which do their job for the common health of the daemon.
60 @verbatim
61 +------+
62 | E Q |
63 | v u |---+ +------+ +------+
64 | e e | | | | | IKE- |
65 | n u | +-----------+ | |--| SA |
66 | t e | | | | I M | +------+
67 +------------+ | - | | Scheduler | | K a |
68 | receiver | +------+ | | | E n | +------+
69 +----+-------+ +-----------+ | - a | | IKE- |
70 | | +------+ | | S g |--| SA |
71 +-------+--+ +-----| J Q |---+ +------------+ | A e | +------+
72 -| socket | | o u | | | | - r |
73 +-------+--+ | b e | | Thread- | | |
74 | | - u | | Pool | | |
75 +----+-------+ | e |------| |---| |
76 | sender | +------+ +------------+ +------+
77 +----+-------+
78 | +------+
79 | | S Q |
80 | | e u |
81 | | n e |
82 +------------| d u |
83 | - e |
84 +--+---+
85 @endverbatim
86 * The thread-pool is the heart of the architecture. It processes jobs from a
87 * (fully synchronized) job-queue. Mostly, a job is associated with a specific
88 * IKE SA. These IKE SAs are synchronized, only one thread can work one an IKE SA.
89 * This makes it unnecesary to use further synchronisation methods once a IKE SA
90 * is checked out. The (rather complex) synchronization of IKE SAs is completely
91 * done in the IKE SA manager.
92 * The sceduler is responsible for event firing. It waits until a event in the
93 * (fully synchronized) event-queue is ready for processing and pushes the event
94 * down to the job-queue. A thread form the pool will pick it up as quick as
95 * possible. Every thread can queue events or jobs. Furter, an event can place a
96 * packet in the send-queue. The sender thread waits for those packets and sends
97 * them over the wire, via the socket. The receiver does exactly the opposite of
98 * the sender. It waits on the socket, reads in packets an places them on the
99 * job-queue for further processing by a thread from the pool.
100 * There are even more threads, not drawn in the upper scheme. The stroke thread
101 * is responsible for reading and processessing commands from another process. The
102 * kernel interface thread handles communication from and to the kernel via a
103 * netlink socket. It waits for kernel events and processes them appropriately.
104 */
105
106 /**
107 * @defgroup config config
108 *
109 * Classes implementing configuration related things.
110 *
111 * @ingroup charon
112 */
113
114 /**
115 * @defgroup encoding encoding
116 *
117 * Classes used to encode and decode IKEv2 messages.
118 *
119 * @ingroup charon
120 */
121
122 /**
123 * @defgroup payloads payloads
124 *
125 * Classes representing specific IKEv2 payloads.
126 *
127 * @ingroup encoding
128 */
129
130 /**
131 * @defgroup network network
132 *
133 * Classes for network relevant stuff.
134 *
135 * @ingroup charon
136 */
137
138 /**
139 * @defgroup queues queues
140 *
141 * Different kind of queues
142 * (thread save lists).
143 *
144 * @ingroup charon
145 */
146
147 /**
148 * @defgroup jobs jobs
149 *
150 * Jobs used in job queue and event queue.
151 *
152 * @ingroup queues
153 */
154
155 /**
156 * @defgroup sa sa
157 *
158 * Security associations for IKE and IPSec,
159 * and some helper classes.
160 *
161 * @ingroup charon
162 */
163
164 /**
165 * @defgroup tasks tasks
166 *
167 * Tasks process and build message payloads. They are used to create
168 * and process multiple exchanges.
169 *
170 * @ingroup sa
171 */
172
173 /**
174 * @defgroup authenticators authenticators
175 *
176 * Authenticator classes to prove identity of peer.
177 *
178 * @ingroup sa
179 */
180
181 /**
182 * @defgroup eap eap
183 *
184 * EAP authentication module interface and it's implementations.
185 *
186 * @ingroup authenticators
187 */
188
189 /**
190 * @defgroup threads threads
191 *
192 * Threaded classes, which will do their job alone.
193 *
194 * @ingroup charon
195 */
196
197 /**
198 * @defgroup bus bus
199 *
200 * Signaling bus and its listeners.
201 *
202 * @ingroup charon
203 */
204
205 /**
206 * Name of the daemon.
207 *
208 * @ingroup charon
209 */
210 #define DAEMON_NAME "charon"
211
212 /**
213 * @brief Number of threads in the thread pool.
214 *
215 * There are several other threads, this defines
216 * only the number of threads in thread_pool_t.
217 *
218 * @ingroup charon
219 */
220 #define NUMBER_OF_WORKING_THREADS 4
221
222 /**
223 * UDP Port on which the daemon will listen for incoming traffic.
224 *
225 * @ingroup charon
226 */
227 #define IKEV2_UDP_PORT 500
228
229 /**
230 * UDP Port to which the daemon will float to if NAT is detected.
231 *
232 * @ingroup charon
233 */
234 #define IKEV2_NATT_PORT 4500
235
236 /**
237 * PID file, in which charon stores its process id
238 *
239 * @ingroup charon
240 */
241 #define PID_FILE IPSEC_PIDDIR "/charon.pid"
242
243 /**
244 * Configuration directory
245 *
246 * @ingroup charon
247 */
248 #define CONFIG_DIR IPSEC_CONFDIR
249
250 /**
251 * Directory of IPsec relevant files
252 *
253 * @ingroup charon
254 */
255 #define IPSEC_D_DIR CONFIG_DIR "/ipsec.d"
256
257 /**
258 * Default directory for private keys
259 *
260 * @ingroup charon
261 */
262 #define PRIVATE_KEY_DIR IPSEC_D_DIR "/private"
263
264 /**
265 * Default directory for end entity certificates
266 *
267 * @ingroup charon
268 */
269 #define CERTIFICATE_DIR IPSEC_D_DIR "/certs"
270
271 /**
272 * Default directory for trusted CA certificates
273 *
274 * @ingroup charon
275 */
276 #define CA_CERTIFICATE_DIR IPSEC_D_DIR "/cacerts"
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 send_queue_t instance.
305 */
306 send_queue_t *send_queue;
307
308 /**
309 * A job_queue_t instance.
310 */
311 job_queue_t *job_queue;
312
313 /**
314 * A event_queue_t instance.
315 */
316 event_queue_t *event_queue;
317
318 /**
319 * A ike_sa_manager_t instance.
320 */
321 ike_sa_manager_t *ike_sa_manager;
322
323 /**
324 * A configuration_t instance.
325 */
326 configuration_t *configuration;
327
328 /**
329 * A connection_store_t instance.
330 */
331 connection_store_t *connections;
332
333 /**
334 * A policy_store_t instance.
335 */
336 policy_store_t *policies;
337
338 /**
339 * A credential_store_t instance.
340 */
341 credential_store_t *credentials;
342
343 /**
344 * The Sender-Thread.
345 */
346 sender_t *sender;
347
348 /**
349 * The Receiver-Thread.
350 */
351 receiver_t *receiver;
352
353 /**
354 * The Scheduler-Thread.
355 */
356 scheduler_t *scheduler;
357
358 /**
359 * The Thread pool managing the worker threads.
360 */
361 thread_pool_t *thread_pool;
362
363 /**
364 * The signaling bus.
365 */
366 bus_t *bus;
367
368 /**
369 * A bus listener logging to stdout
370 */
371 file_logger_t *outlog;
372
373 /**
374 * A bus listener logging to syslog
375 */
376 sys_logger_t *syslog;
377
378 /**
379 * A bus listener logging most important events
380 */
381 sys_logger_t *authlog;
382
383 /**
384 * Kernel Interface to communicate with kernel
385 */
386 kernel_interface_t *kernel_interface;
387
388 /**
389 * IPC interface, as whack in pluto
390 */
391 stroke_t *stroke;
392
393 /**
394 * @brief Shut down the daemon.
395 *
396 * @param this the daemon to kill
397 * @param reason describtion why it will be killed
398 */
399 void (*kill) (daemon_t *this, char *reason);
400 };
401
402 /**
403 * The one and only instance of the daemon.
404 */
405 extern daemon_t *charon;
406
407 #endif /*DAEMON_H_*/