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