2 * Copyright (C) 2006 Martin Willi
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 typedef enum signal_t signal_t
;
27 typedef enum level_t level_t
;
28 typedef struct bus_listener_t bus_listener_t
;
29 typedef struct bus_t bus_t
;
33 #include <sa/ike_sa.h>
34 #include <sa/child_sa.h>
35 #include <processing/jobs/job.h>
39 * signals emitted by the daemon.
41 * Signaling is for different purporses. First, it allows debugging via
42 * "debugging signal messages", sencondly, it allows to follow certain
43 * mechanisms currently going on in the daemon. As we are multithreaded,
44 * and multiple transactions are involved, it's not possible to follow
45 * one connection setup without further infrastructure. These infrastructure
46 * is provided by the bus and the signals the daemon emits to the bus.
48 * There are different scenarios to follow these signals, but all have
49 * the same scheme. First, a START signal is emitted to indicate the daemon
50 * has started to do something. After a start signal, a SUCCESS or a FAILED
51 * signal of the same type follows. This allows to track the operation. Any
52 * Debug signal betwee a START and a SUCCESS/FAILED belongs to that operation
53 * if the IKE_SA is the same. The thread may change, as multiple threads
54 * may be involved in a complex scenario.
57 /** pseudo signal, representing any other signal */
60 /** debugging message from daemon main loop */
62 /** debugging message from IKE_SA_MANAGER */
64 /** debugging message from an IKE_SA */
66 /** debugging message from a CHILD_SA */
68 /** debugging message from job processing */
70 /** debugging message from configuration backends */
72 /** debugging message from kernel interface */
74 /** debugging message from networking */
76 /** debugging message from message encoding/decoding */
78 /** debugging message from libstrongswan via logging hook */
81 /** number of debug signals */
84 /** signals for IKE_SA establishment */
89 /** signals for IKE_SA delete */
94 /** signals for IKE_SA rekeying */
99 /** signals for CHILD_SA establishment */
104 /** signals for CHILD_SA delete */
109 /** signals for CHILD_SA rekeying */
114 /** signals for CHILD_SA routing */
119 /** signals for CHILD_SA routing */
121 CHILD_UNROUTE_SUCCESS
,
122 CHILD_UNROUTE_FAILED
,
128 * short names of signals using 3 chars
130 extern enum_name_t
*signal_names
;
133 * Signal levels used to control output verbosity.
136 /** numerical levels from 0 to 4 */
142 /** absolutely silent, no signal is emitted with this level */
144 /** alias for numberical levels */
145 LEVEL_AUDIT
= LEVEL_0
,
146 LEVEL_CTRL
= LEVEL_1
,
147 LEVEL_CTRLMORE
= LEVEL_2
,
149 LEVEL_PRIVATE
= LEVEL_4
,
153 # define DEBUG_LEVEL 4
154 #endif /* DEBUG_LEVEL */
158 * Log a debug message via the signal bus.
160 * @param signal signal_t signal description
161 * @param format printf() style format string
162 * @param ... printf() style agument list
164 # define DBG1(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_1, format, ##__VA_ARGS__)
165 #endif /* DEBUG_LEVEL */
167 #define DBG2(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_2, format, ##__VA_ARGS__)
168 #endif /* DEBUG_LEVEL */
170 #define DBG3(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_3, format, ##__VA_ARGS__)
171 #endif /* DEBUG_LEVEL */
173 #define DBG4(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_4, format, ##__VA_ARGS__)
174 #endif /* DEBUG_LEVEL */
177 # define DBG1(...) {}
180 # define DBG2(...) {}
183 # define DBG3(...) {}
186 # define DBG4(...) {}
190 * Raise a signal for an occured event.
192 * @param sig signal_t signal description
193 * @param format printf() style format string
194 * @param ... printf() style agument list
196 #define SIG(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_0, format, ##__VA_ARGS__)
199 * Get the type of a signal.
201 * A signal may be a debugging signal with a specific context. They have
202 * a level specific for their context > 0. All audit signals use the
203 * type 0. This allows filtering of singals by their type.
205 * @param signal signal to get the type from
206 * @return type of the signal, between 0..(DBG_MAX-1)
208 #define SIG_TYPE(sig) (sig > DBG_MAX ? SIG_ANY : sig)
212 * Interface for registering at the signal bus.
214 * To receive signals from the bus, the client implementing the
215 * bus_listener_t interface registers itself at the signal bus.
217 struct bus_listener_t
{
220 * Send a signal to a bus listener.
222 * A numerical identification for the thread is included, as the
223 * associated IKE_SA, if any. Signal specifies the type of
224 * the event occured. The format string specifies
225 * an additional informational or error message with a printf() like
226 * variable argument list. This is in the va_list form, as forwarding
227 * a "..." parameters to functions is not (cleanly) possible.
228 * The implementing signal function returns TRUE to stay registered
229 * to the bus, or FALSE to unregister itself.
230 * You should not call bus_t.signal() inside of a registered listener,
231 * as it WILL call itself recursively. If you do so, make shure to
232 * avoid infinite recursion. Watch your stack!
234 * @param singal kind of the signal (up, down, rekeyed, ...)
235 * @param level verbosity level of the signal
236 * @param thread ID of the thread raised this signal
237 * @param ike_sa IKE_SA associated to the event
238 * @param format printf() style format string
239 * @param args vprintf() style va_list argument list
240 " @return TRUE to stay registered, FALSE to unregister
242 bool (*signal
) (bus_listener_t
*this, signal_t signal
, level_t level
,
243 int thread
, ike_sa_t
*ike_sa
, char* format
, va_list args
);
247 * Signal bus which sends signals to registered listeners.
249 * The signal bus is not much more than a multiplexer. A listener interested
250 * in receiving event signals registers at the bus. Any signals sent to
251 * are delivered to all registered listeners.
252 * To deliver signals to threads, the blocking listen() call may be used
253 * to wait for a signal.
258 * Register a listener to the bus.
260 * A registered listener receives all signals which are sent to the bus.
261 * The listener is passive; the thread which emitted the signal
262 * processes the listener routine.
264 * @param listener listener to register.
266 void (*add_listener
) (bus_t
*this, bus_listener_t
*listener
);
269 * Unregister a listener from the bus.
271 * @param listener listener to unregister.
273 void (*remove_listener
) (bus_t
*this, bus_listener_t
*listener
);
276 * Register a listener and block the calling thread.
278 * This call registers a listener and blocks the calling thread until
279 * its listeners function returns FALSE. This allows to wait for certain
280 * events. The associated job is executed after the listener has been
281 * registered, this allows to listen on events we initiate with the job
282 * without missing any signals.
284 * @param listener listener to register
285 * @param job job to execute asynchronously when registered, or NULL
287 void (*listen
)(bus_t
*this, bus_listener_t
*listener
, job_t
*job
);
290 * Set the IKE_SA the calling thread is using.
292 * To associate an received signal to an IKE_SA without passing it as
293 * parameter each time, the thread registers it's used IKE_SA each
294 * time it checked it out. Before checking it in, the thread unregisters
295 * the IKE_SA (by passing NULL). This IKE_SA is stored per-thread, so each
296 * thread has one IKE_SA registered (or not).
298 * @param ike_sa ike_sa to register, or NULL to unregister
300 void (*set_sa
) (bus_t
*this, ike_sa_t
*ike_sa
);
303 * Send a signal to the bus.
305 * The signal specifies the type of the event occured. The format string
306 * specifies an additional informational or error message with a
307 * printf() like variable argument list.
308 * Some useful macros are available to shorten this call.
311 * @param singal kind of the signal (up, down, rekeyed, ...)
312 * @param level verbosity level of the signal
313 * @param format printf() style format string
314 * @param ... printf() style argument list
316 void (*signal
) (bus_t
*this, signal_t signal
, level_t level
, char* format
, ...);
319 * Send a signal to the bus using va_list arguments.
321 * Same as bus_t.signal(), but uses va_list argument list.
323 * @todo Improve performace of vsignal implementation. This method is
324 * called extensively and therefore shouldn't allocate heap memory or
325 * do other expensive tasks!
327 * @param singal kind of the signal (up, down, rekeyed, ...)
328 * @param level verbosity level of the signal
329 * @param format printf() style format string
330 * @param args va_list arguments
332 void (*vsignal
) (bus_t
*this, signal_t signal
, level_t level
, char* format
, va_list args
);
335 * Destroy the signal bus.
337 void (*destroy
) (bus_t
*this);
341 * Create the signal bus which multiplexes signals to its listeners.
343 * @return signal bus instance
347 #endif /* BUS_H_ @} */