4 * @brief Interface of daemon_t.
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
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>.
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
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>
36 #include <bus/listeners/file_logger.h>
37 #include <bus/listeners/sys_logger.h>
38 #include <sa/ike_sa_manager.h>
39 #include <queues/send_queue.h>
40 #include <queues/job_queue.h>
41 #include <queues/event_queue.h>
42 #include <config/configuration.h>
43 #include <config/connections/connection_store.h>
44 #include <config/policies/policy_store.h>
45 #include <config/credentials/credential_store.h>
48 * @defgroup charon charon
50 * @brief IKEv2 keying daemon.
52 * @section Architecture
54 * All IKEv2 stuff is handled in charon. It uses a newer and more flexible
55 * architecture than pluto. Charon uses a thread-pool, which allows parallel
56 * execution SA-management. Beside the thread-pool, there are some special purpose
57 * threads which do their job for the common health of the daemon.
61 | v u |---+ +------+ +------+
62 | e e | | | | | IKE- |
63 | n u | +-----------+ | |--| SA |
64 | t e | | | | I M | +------+
65 +------------+ | - | | Scheduler | | K a |
66 | receiver | +------+ | | | E n | +------+
67 +----+-------+ +-----------+ | - a | | IKE- |
68 | | +------+ | | S g |--| SA |
69 +-------+--+ +-----| J Q |---+ +------------+ | A e | +------+
70 -| socket | | o u | | | | - r |
71 +-------+--+ | b e | | Thread- | | |
72 | | - u | | Pool | | |
73 +----+-------+ | e |------| |---| |
74 | sender | +------+ +------------+ +------+
84 * The thread-pool is the heart of the architecture. It processes jobs from a
85 * (fully synchronized) job-queue. Mostly, a job is associated with a specific
86 * IKE SA. These IKE SAs are synchronized, only one thread can work one an IKE SA.
87 * This makes it unnecesary to use further synchronisation methods once a IKE SA
88 * is checked out. The (rather complex) synchronization of IKE SAs is completely
89 * done in the IKE SA manager.
90 * The sceduler is responsible for event firing. It waits until a event in the
91 * (fully synchronized) event-queue is ready for processing and pushes the event
92 * down to the job-queue. A thread form the pool will pick it up as quick as
93 * possible. Every thread can queue events or jobs. Furter, an event can place a
94 * packet in the send-queue. The sender thread waits for those packets and sends
95 * them over the wire, via the socket. The receiver does exactly the opposite of
96 * the sender. It waits on the socket, reads in packets an places them on the
97 * job-queue for further processing by a thread from the pool.
98 * There are even more threads, not drawn in the upper scheme. The stroke thread
99 * is responsible for reading and processessing commands from another process. The
100 * kernel interface thread handles communication from and to the kernel via a
101 * netlink socket. It waits for kernel events and processes them appropriately.
105 * @defgroup config config
107 * Classes implementing configuration related things.
113 * @defgroup encoding encoding
115 * Classes used to encode and decode IKEv2 messages.
121 * @defgroup payloads payloads
123 * Classes representing specific IKEv2 payloads.
129 * @defgroup network network
131 * Classes for network relevant stuff.
137 * @defgroup queues queues
139 * Different kind of queues
140 * (thread save lists).
146 * @defgroup jobs jobs
148 * Jobs used in job queue and event queue.
156 * Security associations for IKE and IPSec,
157 * and some helper classes.
163 * @defgroup transactions transactions
165 * Transactions represent a request/response
166 * message exchange to implement the IKEv2
167 * protocol exchange scenarios.
173 * @defgroup threads threads
175 * Threaded classes, which will do their job alone.
183 * Signaling bus and its listeners.
189 * Name of the daemon.
193 #define DAEMON_NAME "charon"
196 * @brief Number of threads in the thread pool.
198 * There are several other threads, this defines
199 * only the number of threads in thread_pool_t.
203 #define NUMBER_OF_WORKING_THREADS 4
206 * UDP Port on which the daemon will listen for incoming traffic.
210 #define IKEV2_UDP_PORT 500
213 * UDP Port to which the daemon will float to if NAT is detected.
217 #define IKEV2_NATT_PORT 4500
220 * PID file, in which charon stores its process id
224 #define PID_FILE IPSEC_PIDDIR "/charon.pid"
227 * Configuration directory
231 #define CONFIG_DIR IPSEC_CONFDIR
234 * Directory of IPsec relevant files
238 #define IPSEC_D_DIR CONFIG_DIR "/ipsec.d"
241 * Default directory for private keys
245 #define PRIVATE_KEY_DIR IPSEC_D_DIR "/private"
248 * Default directory for end entity certificates
252 #define CERTIFICATE_DIR IPSEC_D_DIR "/certs"
255 * Default directory for trusted CA certificates
259 #define CA_CERTIFICATE_DIR IPSEC_D_DIR "/cacerts"
262 * Default directory for CRLs
266 #define CRL_DIR IPSEC_D_DIR "/crls"
273 #define SECRETS_FILE CONFIG_DIR "/ipsec.secrets"
276 typedef struct daemon_t daemon_t
;
279 * @brief Main class of daemon, contains some globals.
285 * A socket_t instance.
290 * A send_queue_t instance.
292 send_queue_t
*send_queue
;
295 * A job_queue_t instance.
297 job_queue_t
*job_queue
;
300 * A event_queue_t instance.
302 event_queue_t
*event_queue
;
305 * A ike_sa_manager_t instance.
307 ike_sa_manager_t
*ike_sa_manager
;
310 * A configuration_t instance.
312 configuration_t
*configuration
;
315 * A connection_store_t instance.
317 connection_store_t
*connections
;
320 * A policy_store_t instance.
322 policy_store_t
*policies
;
325 * A credential_store_t instance.
327 credential_store_t
*credentials
;
335 * The Receiver-Thread.
337 receiver_t
*receiver
;
340 * The Scheduler-Thread.
342 scheduler_t
*scheduler
;
345 * The Thread pool managing the worker threads.
347 thread_pool_t
*thread_pool
;
355 * A bus listener logging to stdout
357 file_logger_t
*outlog
;
360 * A bus listener logging to syslog
362 sys_logger_t
*syslog
;
365 * A bus listener logging most important events
367 sys_logger_t
*authlog
;
370 * Kernel Interface to communicate with kernel
372 kernel_interface_t
*kernel_interface
;
375 * IPC interface, as whack in pluto
380 * @brief Shut down the daemon.
382 * @param this the daemon to kill
383 * @param reason describtion why it will be killed
385 void (*kill
) (daemon_t
*this, char *reason
);
389 * The one and only instance of the daemon.
391 extern daemon_t
*charon
;