4 * @brief Interface of bus_t.
9 * Copyright (C) 2006 Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
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>
38 * @brief signals emitted by the daemon.
40 * Signaling is for different purporses. First, it allows debugging via
41 * "debugging signal messages", sencondly, it allows to follow certain
42 * mechanisms currently going on in the daemon. As we are multithreaded,
43 * and of multiple transactions are involved, it's not possible to follow
44 * one connection setup without further infrastructure. These infrastructure
45 * is provided by the bus and the signals the daemon emits to the bus.
47 * There are different scenarios to follow these signals, but all have
48 * the same scheme. First, a START signal is emitted to indicate the daemon
54 /** pseudo signal, representing any other signal */
57 /** debugging message from daemon main loop */
59 /** debugging message from IKE_SA_MANAGER */
61 /** debugging message from an IKE_SA */
63 /** debugging message from a CHILD_SA */
65 /** debugging message from job processing */
67 /** debugging message from configuration backends */
69 /** debugging message from kernel interface */
71 /** debugging message from networking */
73 /** debugging message from message encoding/decoding */
75 /** debugging message from libstrongswan via logging hook */
78 /** number of debug signals */
81 /** signals for IKE_SA establishment */
86 /** signals for IKE_SA delete */
91 /** signals for IKE_SA rekeying */
96 /** signals for CHILD_SA establishment */
101 /** signals for CHILD_SA delete */
106 /** signals for CHILD_SA rekeying */
111 /** signals for CHILD_SA routing */
116 /** signals for CHILD_SA routing */
118 CHILD_UNROUTE_SUCCESS
,
119 CHILD_UNROUTE_FAILED
,
125 * short names of signals using 3 chars
127 extern enum_name_t
*signal_names
;
130 * Signal levels used to control output verbosity.
133 /** numerical levels from 0 to 4 */
139 /** absolutely silent, no signal is emitted with this level */
141 /** alias for numberical levels */
142 LEVEL_AUDIT
= LEVEL_0
,
143 LEVEL_CTRL
= LEVEL_1
,
144 LEVEL_CTRLMORE
= LEVEL_2
,
146 LEVEL_PRIVATE
= LEVEL_4
,
150 # define DEBUG_LEVEL 4
151 #endif /* DEBUG_LEVEL */
155 * @brief Log a debug message via the signal bus.
157 * @param signal signal_t signal description
158 * @param format printf() style format string
159 * @param ... printf() style agument list
161 # define DBG1(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_1, format, ##__VA_ARGS__)
162 #endif /* DEBUG_LEVEL */
164 #define DBG2(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_2, format, ##__VA_ARGS__)
165 #endif /* DEBUG_LEVEL */
167 #define DBG3(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_3, format, ##__VA_ARGS__)
168 #endif /* DEBUG_LEVEL */
170 #define DBG4(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_4, format, ##__VA_ARGS__)
171 #endif /* DEBUG_LEVEL */
174 # define DBG1(...) {}
177 # define DBG2(...) {}
180 # define DBG3(...) {}
183 # define DBG4(...) {}
187 * @brief Raise a signal for an occured event.
189 * @param sig signal_t signal description
190 * @param format printf() style format string
191 * @param ... printf() style agument list
193 #define SIG(sig, format, ...) charon->bus->signal(charon->bus, sig, LEVEL_0, format, ##__VA_ARGS__)
196 * @brief Get the type of a signal.
198 * A signal may be a debugging signal with a specific context. They have
199 * a level specific for their context > 0. All audit signals use the
200 * type 0. This allows filtering of singals by their type.
202 * @param signal signal to get the type from
203 * @return type of the signal, between 0..(DBG_MAX-1)
205 #define SIG_TYPE(sig) (sig > DBG_MAX ? SIG_ANY : sig)
209 * @brief Interface for registering at the signal bus.
211 * To receive signals from the bus, the client implementing the
212 * bus_listener_t interface registers itself at the signal bus.
216 struct bus_listener_t
{
219 * @brief Send a signal to a bus listener.
221 * A numerical identification for the thread is included, as the
222 * associated IKE_SA, if any. Signal specifies the type of
223 * the event occured. The format string specifies
224 * an additional informational or error message with a printf() like
225 * variable argument list. This is in the va_list form, as forwarding
226 * a "..." parameters to functions is not (cleanly) possible.
227 * The implementing signal function returns TRUE to stay registered
228 * to the bus, or FALSE to unregister itself.
230 * @param this listener
231 * @param singal kind of the signal (up, down, rekeyed, ...)
232 * @param level verbosity level of the signal
233 * @param thread ID of the thread raised this signal
234 * @param ike_sa IKE_SA associated to the event
235 * @param format printf() style format string
236 * @param args vprintf() style va_list argument list
237 " @return TRUE to stay registered, FALSE to unregister
239 bool (*signal
) (bus_listener_t
*this, signal_t signal
, level_t level
,
240 int thread
, ike_sa_t
*ike_sa
, char* format
, va_list args
);
244 * @brief Signal bus which sends signals to registered listeners.
246 * The signal bus is not much more than a multiplexer. A listener interested
247 * in receiving event signals registers at the bus. Any signals sent to
248 * are delivered to all registered listeners.
249 * To deliver signals to threads, the blocking listen() call may be used
250 * to wait for a signal.
257 * @brief Register a listener to the bus.
259 * A registered listener receives all signals which are sent to the bus.
260 * The listener is passive; the thread which emitted the signal
261 * processes the listener routine.
264 * @param listener listener to register.
266 void (*add_listener
) (bus_t
*this, bus_listener_t
*listener
);
269 * @brief Listen actively on the bus.
271 * As we are fully multithreaded, we must provide a mechanism
272 * for active threads to listen to the bus. With the listen() method,
273 * a thread waits until a signal occurs, and then processes it.
274 * To prevent the listen() calling thread to miss signals emitted while
275 * it processes a signal, registration is required. This is done through
276 * the set_listen_state() method, see below.
279 * @param level verbosity level of the signal
280 * @param thread receives thread number emitted the signal
281 * @param ike_sa receives the IKE_SA involved in the signal, or NULL
282 * @param format receives the format string supplied with the signal
283 * @param va_list receives the variable argument list for format
284 * @return the emitted signal type
286 signal_t (*listen
) (bus_t
*this, level_t
* level
, int *thread
,
287 ike_sa_t
**ike_sa
, char** format
, va_list* args
);
290 * @brief Set the listening state of the calling thread.
292 * To prevent message loss for active listeners using listen(), threads
293 * must register themself to the bus before starting to listen(). When
294 * a signal occurs, the emitter waits until all threads with listen_state
295 * TRUE are waiting in the listen() method to process the signal.
296 * It is important that a thread with liste_state TRUE calls listen()
297 * periodically, or sets it's listening state to FALSE; otherwise
298 * all signal emitting threads get blocked on the bus.
301 * @param active TRUE to set to listening
303 void (*set_listen_state
) (bus_t
*this, bool active
);
306 * @brief Set the IKE_SA the calling thread is using.
308 * To associate an received signal to an IKE_SA without passing it as
309 * parameter each time, the thread registers it's used IKE_SA each
310 * time it checked it out. Before checking it in, the thread unregisters
311 * the IKE_SA (by passing NULL). This IKE_SA is stored per-thread, so each
312 * thread has one IKE_SA registered (or not).
315 * @param ike_sa ike_sa to register, or NULL to unregister
317 void (*set_sa
) (bus_t
*this, ike_sa_t
*ike_sa
);
320 * @brief Send a signal to the bus.
322 * The signal specifies the type of the event occured. The format string
323 * specifies an additional informational or error message with a
324 * printf() like variable argument list.
325 * Some useful macros are available to shorten this call.
329 * @param singal kind of the signal (up, down, rekeyed, ...)
330 * @param level verbosity level of the signal
331 * @param format printf() style format string
332 * @param ... printf() style argument list
334 void (*signal
) (bus_t
*this, signal_t signal
, level_t level
, char* format
, ...);
337 * @brief Send a signal to the bus using va_list arguments.
339 * Same as bus_t.signal(), but uses va_list argument list.
342 * @param singal kind of the signal (up, down, rekeyed, ...)
343 * @param level verbosity level of the signal
344 * @param format printf() style format string
345 * @param args va_list arguments
347 void (*vsignal
) (bus_t
*this, signal_t signal
, level_t level
, char* format
, va_list args
);
350 * @brief Destroy the signal bus.
352 * @param this bus to destroy
354 void (*destroy
) (bus_t
*this);
358 * @brief Create the signal bus which multiplexes signals to its listeners.
360 * @return signal bus instance