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