2 * Copyright (C) 2006-2009 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
18 * @{ @ingroup libcharon
24 typedef enum alert_t alert_t
;
25 typedef enum narrow_hook_t narrow_hook_t
;
26 typedef struct bus_t bus_t
;
31 #include <sa/ike_sa.h>
32 #include <sa/child_sa.h>
33 #include <processing/jobs/job.h>
34 #include <bus/listeners/listener.h>
36 /* undefine the definitions from libstrongswan */
44 # define DEBUG_LEVEL 4
45 #endif /* DEBUG_LEVEL */
48 #define DBG0(group, format, ...) charon->bus->log(charon->bus, group, 0, format, ##__VA_ARGS__)
49 #endif /* DEBUG_LEVEL >= 0 */
51 #define DBG1(group, format, ...) charon->bus->log(charon->bus, group, 1, format, ##__VA_ARGS__)
52 #endif /* DEBUG_LEVEL >= 1 */
54 #define DBG2(group, format, ...) charon->bus->log(charon->bus, group, 2, format, ##__VA_ARGS__)
55 #endif /* DEBUG_LEVEL >= 2 */
57 #define DBG3(group, format, ...) charon->bus->log(charon->bus, group, 3, format, ##__VA_ARGS__)
58 #endif /* DEBUG_LEVEL >= 3 */
60 #define DBG4(group, format, ...) charon->bus->log(charon->bus, group, 4, format, ##__VA_ARGS__)
61 #endif /* DEBUG_LEVEL >= 4 */
80 * Kind of alerts to raise.
83 /** a RADIUS server did not respond, no additional arguments */
84 ALERT_RADIUS_NOT_RESPONDING
,
85 /** a shutdown signal has been received, argument is the signal (int) */
86 ALERT_SHUTDOWN_SIGNAL
,
87 /** peer authentication failed, no arguments */
88 ALERT_PEER_AUTH_FAILED
,
89 /** failed to resolve peer address, no arguments */
90 ALERT_PEER_ADDR_FAILED
,
94 * Kind of narrow hook.
96 * There is a non-authenticated (IKE_AUTH) and a authenticated
97 * (CREATE_CHILD_SA) narrowing hook for the initiator. Only one of these
98 * hooks is invoked before the exchange.
99 * To verify the traffic selectors negotiated, each PRE hook has a POST
100 * counterpart that follows. POST hooks are invoked with an authenticated peer.
101 * It is usually not a good idea to narrow in the POST hooks,
102 * as the resulting traffic selector is not negotiated and results
103 * in non-matching policies.
106 /** invoked as initiator before exchange, peer is not yet authenticated */
107 NARROW_INITIATOR_PRE_NOAUTH
,
108 /** invoked as initiator before exchange, peer is authenticated */
109 NARROW_INITIATOR_PRE_AUTH
,
110 /** invoked as responder during exchange, peer is authenticated */
112 /** invoked as initiator after exchange, follows a INITIATOR_PRE_NOAUTH */
113 NARROW_INITIATOR_POST_NOAUTH
,
114 /** invoked as initiator after exchange, follows a INITIATOR_PRE_AUTH */
115 NARROW_INITIATOR_POST_AUTH
,
119 * The bus receives events and sends them to all registered listeners.
121 * Calls to bus_t.log() are handled seperately from calls to other event
122 * functions. This means that listeners have to be aware that calls to
123 * listener_t.log() can happen concurrently with calls to one of the other
124 * callbacks. Due to this unregistering from the log() callback is not fully
125 * in sync with the other callbacks, thus, one of these might be called before
126 * the listener is finally unregistered.
131 * Register a listener to the bus.
133 * A registered listener receives all events which are sent to the bus.
134 * The listener is passive; the thread which emitted the event
135 * processes the listener routine.
137 * @param listener listener to register.
139 void (*add_listener
) (bus_t
*this, listener_t
*listener
);
142 * Unregister a listener from the bus.
144 * @param listener listener to unregister.
146 void (*remove_listener
) (bus_t
*this, listener_t
*listener
);
149 * Set the IKE_SA the calling thread is using.
151 * To associate a received log message with an IKE_SA without passing it as
152 * parameter each time, the thread registers the currently used IKE_SA
153 * during check-out. Before check-in, the thread unregisters the IKE_SA.
154 * This IKE_SA is stored per-thread, so each thread has its own IKE_SA
157 * @param ike_sa ike_sa to register, or NULL to unregister
159 void (*set_sa
) (bus_t
*this, ike_sa_t
*ike_sa
);
162 * Get the IKE_SA the calling thread is currently using.
164 * If a thread currently does not know what IKE_SA it is processing,
165 * it can call get_sa() to look up the SA set during checkout via set_sa().
167 * @return registered ike_sa, NULL if none registered
169 ike_sa_t
* (*get_sa
)(bus_t
*this);
172 * Send a log message to the bus.
174 * The format string specifies an additional informational or error
175 * message with a printf() like variable argument list.
176 * Use the DBG() macros.
178 * @param group debugging group
179 * @param level verbosity level of the signal
180 * @param format printf() style format string
181 * @param ... printf() style argument list
183 void (*log
)(bus_t
*this, debug_t group
, level_t level
, char* format
, ...);
186 * Send a log message to the bus using va_list arguments.
188 * Same as bus_t.log(), but uses va_list argument list.
190 * @param group kind of the signal (up, down, rekeyed, ...)
191 * @param level verbosity level of the signal
192 * @param format printf() style format string
193 * @param args va_list arguments
195 void (*vlog
)(bus_t
*this, debug_t group
, level_t level
,
196 char* format
, va_list args
);
199 * Raise an alert over the bus.
201 * @param alert kind of alert
202 * @param ... alert specific arguments
204 void (*alert
)(bus_t
*this, alert_t alert
, ...);
207 * Send a IKE_SA state change event to the bus.
209 * @param ike_sa IKE_SA which changes its state
210 * @param state new state IKE_SA changes to
212 void (*ike_state_change
)(bus_t
*this, ike_sa_t
*ike_sa
,
213 ike_sa_state_t state
);
215 * Send a CHILD_SA state change event to the bus.
217 * @param child_sa CHILD_SA which changes its state
218 * @param state new state CHILD_SA changes to
220 void (*child_state_change
)(bus_t
*this, child_sa_t
*child_sa
,
221 child_sa_state_t state
);
223 * Message send/receive hook.
225 * The hook is invoked twice for each message: Once with plain, parsed data
226 * and once encoded and encrypted.
228 * @param message message to send/receive
229 * @param incoming TRUE for incoming messages, FALSE for outgoing
230 * @param plain TRUE if message is parsed and decrypted, FALSE it not
233 void (*message
)(bus_t
*this, message_t
*message
, bool incoming
, bool plain
);
236 * IKE_SA authorization hook.
238 * @param final TRUE if this is the final invocation
239 * @return TRUE to establish IKE_SA, FALSE to send AUTH_FAILED
241 bool (*authorize
)(bus_t
*this, bool final
);
244 * CHILD_SA traffic selector narrowing hook.
246 * @param child_sa CHILD_SA set up with these traffic selectors
247 * @param type type of hook getting invoked
248 * @param local list of local traffic selectors to narrow
249 * @param remote list of remote traffic selectors to narrow
251 void (*narrow
)(bus_t
*this, child_sa_t
*child_sa
, narrow_hook_t type
,
252 linked_list_t
*local
, linked_list_t
*remote
);
255 * IKE_SA keymat hook.
257 * @param ike_sa IKE_SA this keymat belongs to
258 * @param dh diffie hellman shared secret
259 * @param dh_other others DH public value (IKEv1 only)
260 * @param nonce_i initiators nonce
261 * @param nonce_r responders nonce
262 * @param rekey IKE_SA we are rekeying, if any (IKEv2 only)
263 * @param shared shared key used for key derivation (IKEv1-PSK only)
265 void (*ike_keys
)(bus_t
*this, ike_sa_t
*ike_sa
, diffie_hellman_t
*dh
,
266 chunk_t dh_other
, chunk_t nonce_i
, chunk_t nonce_r
,
267 ike_sa_t
*rekey
, shared_key_t
*shared
);
270 * CHILD_SA keymat hook.
272 * @param child_sa CHILD_SA this keymat is used for
273 * @param initiator initiator of the CREATE_CHILD_SA exchange
274 * @param dh diffie hellman shared secret
275 * @param nonce_i initiators nonce
276 * @param nonce_r responders nonce
278 void (*child_keys
)(bus_t
*this, child_sa_t
*child_sa
, bool initiator
,
279 diffie_hellman_t
*dh
, chunk_t nonce_i
, chunk_t nonce_r
);
282 * IKE_SA up/down hook.
284 * @param ike_sa IKE_SA coming up/going down
285 * @param up TRUE for an up event, FALSE for a down event
287 void (*ike_updown
)(bus_t
*this, ike_sa_t
*ike_sa
, bool up
);
290 * IKE_SA rekeying hook.
292 * @param old rekeyed and obsolete IKE_SA
293 * @param new new IKE_SA replacing old
295 void (*ike_rekey
)(bus_t
*this, ike_sa_t
*old
, ike_sa_t
*new);
298 * CHILD_SA up/down hook.
300 * @param child_sa CHILD_SA coming up/going down
301 * @param up TRUE for an up event, FALSE for a down event
303 void (*child_updown
)(bus_t
*this, child_sa_t
*child_sa
, bool up
);
306 * CHILD_SA rekeying hook.
308 * @param old rekeyed and obsolete CHILD_SA
309 * @param new new CHILD_SA replacing old
311 void (*child_rekey
)(bus_t
*this, child_sa_t
*old
, child_sa_t
*new);
314 * Destroy the event bus.
316 void (*destroy
) (bus_t
*this);
320 * Create the event bus which forwards events to its listeners.
322 * @return event bus instance
326 #endif /** BUS_H_ @}*/