Use a separate list and mutex for loggers.
[strongswan.git] / src / libcharon / bus / listeners / listener.h
1 /*
2 * Copyright (C) 2009 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
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>.
9 *
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
13 * for more details.
14 */
15
16 /**
17 * @defgroup listener listener
18 * @{ @ingroup listeners
19 */
20
21 #ifndef LISTENER_H_
22 #define LISTENER_H_
23
24 typedef struct listener_t listener_t;
25
26 #include <bus/bus.h>
27
28 /**
29 * Listener interface, listens to events if registered to the bus.
30 */
31 struct listener_t {
32
33 /**
34 * Log a debugging message.
35 *
36 * The implementing signal function returns TRUE to stay registered
37 * to the bus, or FALSE to unregister itself.
38 *
39 * Calling bus_t.log() inside of a registered listener is possible
40 * from all listener_t callbacks, but recursive calls from log() itself
41 * are ignored.
42 *
43 * Note that calls to bus_t.log() are handled seperately from calls to
44 * other functions, thus this callback may be called concurrently with
45 * some of the others. Because of this unregistering from this callback
46 * does not happen in sync with the other callbacks, thus, one of the other
47 * callbacks might be called before the listener is finally unregistered.
48 *
49 * @param group kind of the signal (up, down, rekeyed, ...)
50 * @param level verbosity level of the signal
51 * @param thread ID of the thread raised this signal
52 * @param ike_sa IKE_SA associated to the event
53 * @param format printf() style format string
54 * @param args vprintf() style va_list argument list
55 * @return TRUE to stay registered, FALSE to unregister
56 */
57 bool (*log)(listener_t *this, debug_t group, level_t level, int thread,
58 ike_sa_t *ike_sa, char* format, va_list args);
59
60 /**
61 * Hook called if a critical alert is risen.
62 *
63 * @param ike_sa IKE_SA associated to the alert, if any
64 * @param alert kind of alert
65 * @param ... alert specific argument list
66 * @return TRUE to stay registered, FALSE to unregister
67 */
68 bool (*alert)(listener_t *this, ike_sa_t *ike_sa,
69 alert_t alert, va_list args);
70
71 /**
72 * Handle state changes in an IKE_SA.
73 *
74 * @param ike_sa IKE_SA which changes its state
75 * @param state new IKE_SA state this IKE_SA changes to
76 * @return TRUE to stay registered, FALSE to unregister
77 */
78 bool (*ike_state_change)(listener_t *this, ike_sa_t *ike_sa,
79 ike_sa_state_t state);
80
81 /**
82 * Handle state changes in a CHILD_SA.
83 *
84 * @param ike_sa IKE_SA containing the affected CHILD_SA
85 * @param child_sa CHILD_SA which changes its state
86 * @param state new CHILD_SA state this CHILD_SA changes to
87 * @return TRUE to stay registered, FALSE to unregister
88 */
89 bool (*child_state_change)(listener_t *this, ike_sa_t *ike_sa,
90 child_sa_t *child_sa, child_sa_state_t state);
91
92 /**
93 * Hook called for received/sent messages of an IKE_SA.
94 *
95 * The hook is invoked twice for each message: Once with plain, parsed data
96 * and once encoded and encrypted.
97 *
98 * @param ike_sa IKE_SA sending/receiving a message
99 * @param message message object
100 * @param incoming TRUE for incoming messages, FALSE for outgoing
101 * @param plain TRUE if message is parsed and decrypted, FALSE it not
102 * @return TRUE to stay registered, FALSE to unregister
103 */
104 bool (*message)(listener_t *this, ike_sa_t *ike_sa, message_t *message,
105 bool incoming, bool plain);
106
107 /**
108 * Hook called with IKE_SA key material.
109 *
110 * @param ike_sa IKE_SA this keymat belongs to
111 * @param dh diffie hellman shared secret
112 * @param dh_other others DH public value (IKEv1 only)
113 * @param nonce_i initiators nonce
114 * @param nonce_r responders nonce
115 * @param rekey IKE_SA we are rekeying, if any (IKEv2 only)
116 * @param shared shared key used for key derivation (IKEv1-PSK only)
117 * @return TRUE to stay registered, FALSE to unregister
118 */
119 bool (*ike_keys)(listener_t *this, ike_sa_t *ike_sa, diffie_hellman_t *dh,
120 chunk_t dh_other, chunk_t nonce_i, chunk_t nonce_r,
121 ike_sa_t *rekey, shared_key_t *shared);
122
123 /**
124 * Hook called with CHILD_SA key material.
125 *
126 * @param ike_sa IKE_SA the child sa belongs to
127 * @param child_sa CHILD_SA this keymat is used for
128 * @param initiator initiator of the CREATE_CHILD_SA exchange
129 * @param dh diffie hellman shared secret
130 * @param nonce_i initiators nonce
131 * @param nonce_r responders nonce
132 * @return TRUE to stay registered, FALSE to unregister
133 */
134 bool (*child_keys)(listener_t *this, ike_sa_t *ike_sa, child_sa_t *child_sa,
135 bool initiator, diffie_hellman_t *dh,
136 chunk_t nonce_i, chunk_t nonce_r);
137
138 /**
139 * Hook called if an IKE_SA gets up or down.
140 *
141 * @param ike_sa IKE_SA coming up/going down
142 * @param up TRUE for an up event, FALSE for a down event
143 * @return TRUE to stay registered, FALSE to unregister
144 */
145 bool (*ike_updown)(listener_t *this, ike_sa_t *ike_sa, bool up);
146
147 /**
148 * Hook called when an IKE_SA gets rekeyed.
149 *
150 * @param old rekeyed IKE_SA getting obsolete
151 * @param new new IKE_SA replacing old
152 * @return TRUE to stay registered, FALSE to unregister
153 */
154 bool (*ike_rekey)(listener_t *this, ike_sa_t *old, ike_sa_t *new);
155
156 /**
157 * Hook called when a CHILD_SA gets up or down.
158 *
159 * @param ike_sa IKE_SA containing the handled CHILD_SA
160 * @param child_sa CHILD_SA coming up/going down
161 * @param up TRUE for an up event, FALSE for a down event
162 * @return TRUE to stay registered, FALSE to unregister
163 */
164 bool (*child_updown)(listener_t *this, ike_sa_t *ike_sa,
165 child_sa_t *child_sa, bool up);
166
167 /**
168 * Hook called when an CHILD_SA gets rekeyed.
169 *
170 * @param ike_sa IKE_SA containing the rekeyed CHILD_SA
171 * @param old rekeyed CHILD_SA getting obsolete
172 * @param new new CHILD_SA replacing old
173 * @return TRUE to stay registered, FALSE to unregister
174 */
175 bool (*child_rekey)(listener_t *this, ike_sa_t *ike_sa,
176 child_sa_t *old, child_sa_t *new);
177
178 /**
179 * Hook called to invoke additional authorization rules.
180 *
181 * An authorization hook gets invoked several times: After each
182 * authentication round, the hook gets invoked with with final = FALSE.
183 * After authentication is complete and the peer configuration is selected,
184 * it is invoked again, but with final = TRUE.
185 *
186 * @param ike_sa IKE_SA to authorize
187 * @param final TRUE if this is the final hook invocation
188 * @param success set to TRUE to complete IKE_SA, FALSE abort
189 * @return TRUE to stay registered, FALSE to unregister
190 */
191 bool (*authorize)(listener_t *this, ike_sa_t *ike_sa,
192 bool final, bool *success);
193
194 /**
195 * CHILD_SA traffic selector narrowing hook.
196 *
197 * This hook is invoked for each CHILD_SA and allows plugins to modify
198 * the traffic selector list negotiated for this CHILD_SA.
199 *
200 * @param ike_sa IKE_SA the created CHILD_SA is created in
201 * @param child_sa CHILD_SA set up with these traffic selectors
202 * @param type type of hook getting invoked
203 * @param local list of local traffic selectors to narrow
204 * @param remote list of remote traffic selectors to narrow
205 */
206 bool (*narrow)(listener_t *this, ike_sa_t *ike_sa, child_sa_t *child_sa,
207 narrow_hook_t type, linked_list_t *local, linked_list_t *remote);
208 };
209
210 #endif /** LISTENER_H_ @}*/