fixed bad cast which resulted in a crash on "ipsec update"
[strongswan.git] / src / charon / control / interface_manager.h
1 /**
2 * @file interface_manager.h
3 *
4 * @brief Interface of interface_manager_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2007 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 INTERFACE_MANAGER_H_
24 #define INTERFACE_MANAGER_H_
25
26 #include <bus/bus.h>
27
28 /**
29 * callback to log things triggered by interface_manager.
30 *
31 * @param param echoed parameter supplied when function invoked
32 * @param signal type of signal
33 * @param level verbosity level if log
34 * @param ike_sa associated IKE_SA, if any
35 * @param format printf like format string
36 * @param args list of arguments to use for format
37 * @return FALSE to return from invoked function
38 * @ingroup control
39 */
40 typedef bool(*interface_manager_cb_t)(void* param, signal_t signal, level_t level,
41 ike_sa_t* ike_sa, char* format, va_list args);
42
43 /**
44 * @brief Empty callback function for interface_manager_t functions.
45 *
46 * If you wan't to do a syncrhonous call, but don't need a callback, pass
47 * this function to the interface_managers methods.
48 */
49 bool interface_manager_cb_empty(void *param, signal_t signal, level_t level,
50 ike_sa_t *ike_sa, char *format, va_list args);
51
52 typedef struct interface_manager_t interface_manager_t;
53
54 /**
55 * @brief The interface_manager loads control interfaces and has helper methods.
56 *
57 * One job of the interface manager is to load pluggable control interface
58 * modules, implemented as interface_t.
59 * @verbatim
60
61 +---------+ +------------+ +--------------+ |
62 | | | |<----- +--------------+ | |
63 | daemon |<-----| interface- | +--------------+ |-+ <==|==> IPC
64 | core | | manager |<----| interfaces |-+ |
65 | |<-----| | +--------------+ |
66 | | | | |
67 +---------+ +------------+ |
68
69 @endverbatim
70 * The manager does not really use the interfaces, instead, the interface
71 * use the manager to fullfill their tasks (initiating, terminating, ...).
72 * The interface_manager starts actions by creating jobs. It then tries to
73 * evaluate the result of the operation by listening on the bus.
74 *
75 * Passing NULL as callback to the managers function calls them asynchronously.
76 * If a callback is specified, they are called synchronoulsy. There is a default
77 * callback "interface_manager_cb_empty" if you wan't to call a function
78 * synchronously, but don't need a callback.
79 *
80 * @b Constructors:
81 * - interface_manager_create()
82 *
83 * @ingroup control
84 */
85 struct interface_manager_t {
86
87 /**
88 * @brief Create an iterator for all IKE_SAs.
89 *
90 * The iterator blocks the IKE_SA manager until it gets destroyed. Do
91 * not call another interface/manager method while the iterator is alive.
92 *
93 * @param this calling object
94 * @return iterator, locks IKE_SA manager until destroyed
95 */
96 iterator_t* (*create_ike_sa_iterator)(interface_manager_t *this);
97
98 /**
99 * @brief Initiate a CHILD_SA, and if required, an IKE_SA.
100 *
101 * The inititate() function is synchronous and thus blocks until the
102 * IKE_SA is established or failed. Because of this, the initiate() function
103 * contains a thread cancellation point.
104 *
105 * @param this calling object
106 * @param peer_cfg peer_cfg to use for IKE_SA setup
107 * @param child_cfg child_cfg to set up CHILD_SA from
108 * @param cb logging callback
109 * @param param parameter to include in each call of cb
110 * @return
111 * - SUCCESS, if CHILD_SA established
112 * - FAILED, if setup failed
113 * - NEED_MORE, if callback returned FALSE
114 */
115 status_t (*initiate)(interface_manager_t *this,
116 peer_cfg_t *peer_cfg, child_cfg_t *child_cfg,
117 interface_manager_cb_t callback, void *param);
118
119 /**
120 * @brief Terminate an IKE_SA and all of its CHILD_SAs.
121 *
122 * The terminate() function is synchronous and thus blocks until the
123 * IKE_SA is properly deleted, or the delete timed out.
124 * The terminate() function contains a thread cancellation point.
125 *
126 * @param this calling object
127 * @param unique_id unique id of the IKE_SA to terminate.
128 * @param cb logging callback
129 * @param param parameter to include in each call of cb
130 * @return
131 * - SUCCESS, if CHILD_SA terminated
132 * - NOT_FOUND, if no such CHILD_SA found
133 * - NEED_MORE, if callback returned FALSE
134 */
135 status_t (*terminate_ike)(interface_manager_t *this, u_int32_t unique_id,
136 interface_manager_cb_t callback, void *param);
137
138 /**
139 * @brief Terminate a CHILD_SA.
140 *
141 * @param this calling object
142 * @param reqid reqid of the CHILD_SA to terminate
143 * @param cb logging callback
144 * @param param parameter to include in each call of cb
145 * @return
146 * - SUCCESS, if CHILD_SA terminated
147 * - NOT_FOUND, if no such CHILD_SA found
148 * - NEED_MORE, if callback returned FALSE
149 */
150 status_t (*terminate_child)(interface_manager_t *this, u_int32_t reqid,
151 interface_manager_cb_t callback, void *param);
152
153 /**
154 * @brief Route a CHILD_SA (install triggering policies).
155 *
156 * @param this calling object
157 * @param peer_cfg peer_cfg to use for IKE_SA setup, if triggered
158 * @param child_cfg child_cfg to route
159 * @param cb logging callback
160 * @param param parameter to include in each call of cb
161 * @return
162 * - SUCCESS, if CHILD_SA routed
163 * - FAILED, if routing failed
164 * - NEED_MORE, if callback returned FALSE
165 */
166 status_t (*route)(interface_manager_t *this,
167 peer_cfg_t *peer_cfg, child_cfg_t *child_cfg,
168 interface_manager_cb_t callback, void *param);
169
170 /**
171 * @brief Unroute a routed CHILD_SA (uninstall triggering policies).
172 *
173 * Only the route is removed, not the CHILD_SAs the route triggered.
174 *
175 * @param this calling object
176 * @param reqid reqid of the CHILD_SA to unroute
177 * @param cb logging callback
178 * @param param parameter to include in each call of cb
179 * @return
180 * - SUCCESS, if CHILD_SA terminated
181 * - NOT_FOUND, if no such CHILD_SA routed
182 * - NEED_MORE, if callback returned FALSE
183 */
184 status_t (*unroute)(interface_manager_t *this, u_int32_t reqid,
185 interface_manager_cb_t callback, void *param);
186
187 /**
188 * @brief Destroy a interface_manager_t instance.
189 *
190 * @param this interface_manager_t objec to destroy
191 */
192 void (*destroy) (interface_manager_t *this);
193 };
194
195
196 /**
197 * @brief Creates a interface_manager instance and loads all interface modules.
198 *
199 * @return interface_manager_t object
200 *
201 * @ingroup control
202 */
203 interface_manager_t *interface_manager_create(void);
204
205 #endif /* INTERFACE_MANAGER_H_ */
206