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