- fixed bad bugs in kernel interface
[strongswan.git] / Source / 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/connection_store.h>
40 #include <config/policy_store.h>
41 #include <config/credential_store.h>
42
43 /**
44 * @mainpage
45 *
46 * @section Threading Architecture
47 *
48 * All IKEv2 stuff is handled in charon. It uses a newer and more flexible
49 * architecture than pluto. Charon uses a thread-pool, which allows parallel
50 * execution SA-management. Beside the thread-pool, there are some special purpose
51 * threads which do their job for the common health of the daemon.
52 @verbatim
53 +------+
54 | E Q |
55 | v u |---+ +------+ +------+
56 | e e | | | | | IKE- |
57 | n u | +-----------+ | |--| SA |
58 | t e | | | | I M | +------+
59 +------------+ | - | | Scheduler | | K a |
60 | receiver | +------+ | | | E n | +------+
61 +----+-------+ +-----------+ | - a | | IKE- |
62 | | +------+ | | S g |--| SA |
63 +-------+--+ +-----| J Q |---+ +------------+ | A e | +------+
64 -| socket | | o u | | | | - r |
65 +-------+--+ | b e | | Thread- | | |
66 | | - u | | Pool | | |
67 +----+-------+ | e |------| |---| |
68 | sender | +------+ +------------+ +------+
69 +----+-------+
70 | +------+
71 | | S Q |
72 | | e u |
73 | | n e |
74 +------------| d u |
75 | - e |
76 +--+---+
77 @endverbatim
78 * The thread-pool is the heart of the architecture. It processes jobs from a
79 * (fully synchronized) job-queue. Mostly, a job is associated with a specific
80 * IKE SA. These IKE SAs are synchronized, only one thread can work one an IKE SA.
81 * This makes it unnecesary to use further synchronisation methods once a IKE SA
82 * is checked out. The (rather complex) synchronization of IKE SAs is completely
83 * done in the IKE SA manager.
84 * The sceduler is responsible for event firing. It waits until a event in the
85 * (fully synchronized) event-queue is ready for processing and pushes the event
86 * down to the job-queue. A thread form the pool will pick it up as quick as
87 * possible. Every thread can queue events or jobs. Furter, an event can place a
88 * packet in the send-queue. The sender thread waits for those packets and sends
89 * them over the wire, via the socket. The receiver does exactly the opposite of
90 * the sender. It waits on the socket, reads in packets an places them on the
91 * job-queue for further processing by a thread from the pool.
92 * There are even more threads, not drawn in the upper scheme. The stroke thread
93 * is responsible for reading and processessing commands from another process. The
94 * kernel interface thread handles communication from and to the kernel via a
95 * netlink socket. It waits for kernel events and processes them appropriately.
96 */
97
98 /**
99 * Name of the daemon.
100 */
101 #define DAEMON_NAME "charon"
102
103 /**
104 * @brief Number of threads in the thread pool.
105 *
106 * There are several other threads, this defines
107 * only the number of threads in thread_pool_t.
108 */
109 #define NUMBER_OF_WORKING_THREADS 4
110
111 /**
112 * UDP Port on which the daemon will listen for incoming traffic.
113 */
114 #define IKEV2_UDP_PORT 500
115
116 /**
117 * PID file, in which charon stores its process id
118 */
119 #define PID_FILE "/var/run/charon.pid"
120
121
122 typedef struct daemon_t daemon_t;
123
124 /**
125 * @brief Main class of daemon, contains some globals.
126 */
127 struct daemon_t {
128 /**
129 * A socket_t instance.
130 */
131 socket_t *socket;
132
133 /**
134 * A send_queue_t instance.
135 */
136 send_queue_t *send_queue;
137
138 /**
139 * A job_queue_t instance.
140 */
141 job_queue_t *job_queue;
142
143 /**
144 * A event_queue_t instance.
145 */
146 event_queue_t *event_queue;
147
148 /**
149 * A ike_sa_manager_t instance.
150 */
151 ike_sa_manager_t *ike_sa_manager;
152
153 /**
154 * A configuration_t instance.
155 */
156 configuration_t *configuration;
157
158 /**
159 * A connection_store_t instance.
160 */
161 connection_store_t *connections;
162
163 /**
164 * A policy_store_t instance.
165 */
166 policy_store_t *policies;
167
168 /**
169 * A credential_store_t instance.
170 */
171 credential_store_t *credentials;
172
173 /**
174 * The Sender-Thread.
175 */
176 sender_t *sender;
177
178 /**
179 * The Receiver-Thread.
180 */
181 receiver_t *receiver;
182
183 /**
184 * The Scheduler-Thread.
185 */
186 scheduler_t *scheduler;
187
188 /**
189 * The Thread pool managing the worker threads.
190 */
191 thread_pool_t *thread_pool;
192
193 /**
194 * Kernel Interface to communicate with kernel
195 */
196 kernel_interface_t *kernel_interface;
197
198 /**
199 * IPC interface, as whack in pluto
200 */
201 stroke_t *stroke;
202
203 /**
204 * @brief Shut down the daemon.
205 *
206 * @param this the daemon to kill
207 * @param reason describtion why it will be killed
208 */
209 void (*kill) (daemon_t *this, char *reason);
210 };
211
212 /**
213 * The one and only instance of the daemon.
214 */
215 extern daemon_t *charon;
216
217 #endif /*DAEMON_H_*/