]>
Commit | Line | Data |
---|---|---|
3ebebc5e | 1 | /* |
02180ae2 | 2 | * Copyright (C) 2006-2023 Tobias Brunner |
d4aad554 | 3 | * Copyright (C) 2006 Daniel Roethlisberger |
c71d53ba MW |
4 | * Copyright (C) 2005-2006 Martin Willi |
5 | * Copyright (C) 2005 Jan Hutter | |
19ef2aec TB |
6 | * |
7 | * Copyright (C) secunet Security Networks AG | |
3ebebc5e MW |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify it | |
10 | * under the terms of the GNU General Public License as published by the | |
11 | * Free Software Foundation; either version 2 of the License, or (at your | |
12 | * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, but | |
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
16 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 | * for more details. | |
552cc11b MW |
18 | */ |
19 | ||
524fb37c TB |
20 | /* |
21 | * Copyright (c) 2012 Nanoteq Pty Ltd | |
22 | * | |
23 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
24 | * of this software and associated documentation files (the "Software"), to deal | |
25 | * in the Software without restriction, including without limitation the rights | |
26 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
27 | * copies of the Software, and to permit persons to whom the Software is | |
28 | * furnished to do so, subject to the following conditions: | |
29 | * | |
30 | * The above copyright notice and this permission notice shall be included in | |
31 | * all copies or substantial portions of the Software. | |
32 | * | |
33 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
34 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
35 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
36 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
37 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
38 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
39 | * THE SOFTWARE. | |
40 | */ | |
41 | ||
552cc11b MW |
42 | /** |
43 | * @defgroup kernel_interface kernel_interface | |
8394ea2a | 44 | * @{ @ingroup kernel |
3ebebc5e MW |
45 | */ |
46 | ||
47 | #ifndef KERNEL_INTERFACE_H_ | |
48 | #define KERNEL_INTERFACE_H_ | |
49 | ||
382b4817 | 50 | typedef struct kernel_interface_t kernel_interface_t; |
76f7d80e | 51 | typedef enum kernel_feature_t kernel_feature_t; |
382b4817 | 52 | |
2e7cc07e | 53 | #include <networking/host.h> |
3ebebc5e | 54 | |
c560ddeb | 55 | #include <kernel/kernel_listener.h> |
507f26f6 TB |
56 | #include <kernel/kernel_ipsec.h> |
57 | #include <kernel/kernel_net.h> | |
92ee45a0 | 58 | |
6d86d0f5 TB |
59 | /** |
60 | * Default range for SPIs requested from kernels | |
61 | */ | |
62 | #define KERNEL_SPI_MIN 0xc0000000 | |
63 | #define KERNEL_SPI_MAX 0xcfffffff | |
64 | ||
76f7d80e MW |
65 | /** |
66 | * Bitfield of optional features a kernel backend supports. | |
67 | * | |
68 | * This feature-set is for both, kernel_ipsec_t and kernel_net_t. Each | |
69 | * backend returns a subset of these features. | |
70 | */ | |
71 | enum kernel_feature_t { | |
72 | /** IPsec can process ESPv3 (RFC 4303) TFC padded packets */ | |
73 | KERNEL_ESP_V3_TFC = (1<<0), | |
580b768d MW |
74 | /** Networking requires an "exclude" route for IKE/ESP packets */ |
75 | KERNEL_REQUIRE_EXCLUDE_ROUTE = (1<<1), | |
35fe41f7 TB |
76 | /** IPsec implementation requires UDP encapsulation of ESP packets */ |
77 | KERNEL_REQUIRE_UDP_ENCAPSULATION = (1<<2), | |
7452adfa MW |
78 | /** IPsec backend does not require a policy reinstall on SA updates */ |
79 | KERNEL_NO_POLICY_UPDATES = (1<<3), | |
a46d233c TB |
80 | /** IPsec backend supports installing SPIs on policies */ |
81 | KERNEL_POLICY_SPI = (1<<4), | |
b9131c34 TB |
82 | /** IPsec backend reports use time per SA via query_sa() */ |
83 | KERNEL_SA_USE_TIME = (1<<5), | |
46c338a7 TB |
84 | /** IPsec backend associates acquires and SAs with a sequence number */ |
85 | KERNEL_ACQUIRE_SEQ = (1<<6), | |
76f7d80e MW |
86 | }; |
87 | ||
92ee45a0 | 88 | /** |
507f26f6 | 89 | * Constructor function for ipsec kernel interface |
92ee45a0 | 90 | */ |
507f26f6 TB |
91 | typedef kernel_ipsec_t* (*kernel_ipsec_constructor_t)(void); |
92 | ||
93 | /** | |
94 | * Constructor function for network kernel interface | |
95 | */ | |
96 | typedef kernel_net_t* (*kernel_net_constructor_t)(void); | |
1396815a | 97 | |
3ebebc5e | 98 | /** |
507f26f6 | 99 | * Manager and wrapper for different kernel interfaces. |
7daf5226 | 100 | * |
aa5a35a0 | 101 | * The kernel interface handles the communication with the kernel |
507f26f6 | 102 | * for SA and policy management and interface and IP address management. |
3ebebc5e MW |
103 | */ |
104 | struct kernel_interface_t { | |
105 | ||
76f7d80e MW |
106 | /** |
107 | * Get the feature set supported by the net and ipsec kernel backends. | |
108 | * | |
109 | * @return ORed feature-set of backends | |
110 | */ | |
111 | kernel_feature_t (*get_features)(kernel_interface_t *this); | |
112 | ||
3febcf15 | 113 | /** |
552cc11b | 114 | * Get a SPI from the kernel. |
1396815a | 115 | * |
aa5a35a0 MW |
116 | * @param src source address of SA |
117 | * @param dst destination address of SA | |
118 | * @param protocol protocol for SA (ESP/AH) | |
552cc11b | 119 | * @param spi allocated spi |
2a1c9e20 | 120 | * @return SUCCESS if operation completed |
3febcf15 | 121 | */ |
7daf5226 | 122 | status_t (*get_spi)(kernel_interface_t *this, host_t *src, host_t *dst, |
b12c53ce | 123 | uint8_t protocol, uint32_t *spi); |
7daf5226 | 124 | |
d4aad554 TB |
125 | /** |
126 | * Get a Compression Parameter Index (CPI) from the kernel. | |
7daf5226 | 127 | * |
d4aad554 TB |
128 | * @param src source address of SA |
129 | * @param dst destination address of SA | |
d4aad554 | 130 | * @param cpi allocated cpi |
2a1c9e20 | 131 | * @return SUCCESS if operation completed |
d4aad554 | 132 | */ |
7daf5226 | 133 | status_t (*get_cpi)(kernel_interface_t *this, host_t *src, host_t *dst, |
b12c53ce | 134 | uint16_t *cpi); |
7daf5226 | 135 | |
cc08ce83 MW |
136 | /** |
137 | * Allocate or confirm a reqid to use for a given SA pair. | |
138 | * | |
139 | * Each returned reqid by a successful call to alloc_reqid() must be | |
140 | * released using release_reqid(). | |
141 | * | |
142 | * The reqid parameter is an in/out parameter. If it points to non-zero, | |
143 | * the reqid is confirmed and registered for use. If it points to zero, | |
144 | * a reqid is allocated for the given selectors, and returned to reqid. | |
145 | * | |
cc08ce83 MW |
146 | * @param local_ts traffic selectors of local side for SA |
147 | * @param remote_ts traffic selectors of remote side for SA | |
148 | * @param mark_in inbound mark on SA | |
149 | * @param mark_out outbound mark on SA | |
f99bd2a5 TB |
150 | * @param if_id_in inbound interface ID on SA |
151 | * @param if_id_out outbound interface ID on SA | |
6cb83c30 | 152 | * @param label security label (usually the one on the policy, not SA) |
cc08ce83 | 153 | * @param reqid allocated reqid |
4ea61dcb TE |
154 | * @return SUCCESS if reqid allocated, OUT_OF_RES if no reqid is |
155 | * available due to an overflow | |
cc08ce83 MW |
156 | */ |
157 | status_t (*alloc_reqid)(kernel_interface_t *this, | |
158 | linked_list_t *local_ts, linked_list_t *remote_ts, | |
f99bd2a5 | 159 | mark_t mark_in, mark_t mark_out, uint32_t if_id_in, |
6cb83c30 TB |
160 | uint32_t if_id_out, sec_label_t *label, |
161 | uint32_t *reqid); | |
cc08ce83 | 162 | |
e623f579 TB |
163 | /** |
164 | * Increase the reference count for the given reqid that was previously | |
165 | * allocated by alloc_reqid(). | |
166 | * | |
167 | * The reference must be released with a call to release_reqid(). | |
168 | * | |
169 | * @param reqid previously allocated reqid | |
170 | * @return SUCCESS if refcount increased, NOT_FOUND if reqid is | |
171 | * unknown (shouldn't happen) | |
172 | */ | |
173 | status_t (*ref_reqid)(kernel_interface_t *this, uint32_t reqid); | |
174 | ||
cc08ce83 MW |
175 | /** |
176 | * Release a previously allocated reqid. | |
177 | * | |
178 | * @param reqid reqid to release | |
cc08ce83 MW |
179 | * @return SUCCESS if reqid released |
180 | */ | |
02180ae2 | 181 | status_t (*release_reqid)(kernel_interface_t *this, uint32_t reqid); |
cc08ce83 | 182 | |
3febcf15 | 183 | /** |
552cc11b | 184 | * Add an SA to the SAD. |
888af963 | 185 | * |
d05d85fe MW |
186 | * This function does install a single SA for a single protocol in one |
187 | * direction. | |
888af963 | 188 | * |
89da06ac TB |
189 | * @param id data identifying this SA |
190 | * @param data data for this SA | |
552cc11b | 191 | * @return SUCCESS if operation completed |
3febcf15 | 192 | */ |
89da06ac TB |
193 | status_t (*add_sa)(kernel_interface_t *this, kernel_ipsec_sa_id_t *id, |
194 | kernel_ipsec_add_sa_t *data); | |
7daf5226 | 195 | |
1396815a | 196 | /** |
552cc11b | 197 | * Update the hosts on an installed SA. |
1396815a | 198 | * |
92ee45a0 MW |
199 | * We cannot directly update the destination address as the kernel |
200 | * requires the spi, the protocol AND the destination address (and family) | |
201 | * to identify SAs. Therefore if the destination address changed we | |
202 | * create a new SA and delete the old one. | |
1396815a | 203 | * |
89da06ac TB |
204 | * @param id data identifying this SA |
205 | * @param data updated data for this SA | |
ea625fab | 206 | * @return SUCCESS if operation completed, NOT_SUPPORTED if |
89da06ac | 207 | * the kernel interface can't update the SA |
1396815a | 208 | */ |
89da06ac TB |
209 | status_t (*update_sa)(kernel_interface_t *this, kernel_ipsec_sa_id_t *id, |
210 | kernel_ipsec_update_sa_t *data); | |
7daf5226 | 211 | |
2ad51539 | 212 | /** |
b9131c34 TB |
213 | * Query the number of bytes and packets processed by an SA from the SAD. |
214 | * | |
215 | * Some implementations may also return the last use time (as indicated by | |
216 | * get_features()). This is a monotonic timestamp as returned by | |
217 | * time_monotonic(). | |
7daf5226 | 218 | * |
89da06ac TB |
219 | * @param id data identifying this SA |
220 | * @param data data to query the SA | |
2ad51539 | 221 | * @param[out] bytes the number of bytes processed by SA |
7eeeb1c7 | 222 | * @param[out] packets number of packets processed by SA |
c99458e9 | 223 | * @param[out] time last (monotonic) time of SA use |
2ad51539 AS |
224 | * @return SUCCESS if operation completed |
225 | */ | |
89da06ac TB |
226 | status_t (*query_sa)(kernel_interface_t *this, kernel_ipsec_sa_id_t *id, |
227 | kernel_ipsec_query_sa_t *data, uint64_t *bytes, | |
228 | uint64_t *packets, time_t *time); | |
7daf5226 | 229 | |
aa5a35a0 | 230 | /** |
507f26f6 | 231 | * Delete a previously installed SA from the SAD. |
7daf5226 | 232 | * |
89da06ac TB |
233 | * @param id data identifying this SA |
234 | * @param data data to delete the SA | |
552cc11b | 235 | * @return SUCCESS if operation completed |
aa5a35a0 | 236 | */ |
89da06ac TB |
237 | status_t (*del_sa)(kernel_interface_t *this, kernel_ipsec_sa_id_t *id, |
238 | kernel_ipsec_del_sa_t *data); | |
7daf5226 | 239 | |
0b0f466b TB |
240 | /** |
241 | * Flush all SAs from the SAD. | |
242 | * | |
243 | * @return SUCCESS if operation completed | |
244 | */ | |
89da06ac | 245 | status_t (*flush_sas)(kernel_interface_t *this); |
0b0f466b | 246 | |
aa5a35a0 | 247 | /** |
552cc11b | 248 | * Add a policy to the SPD. |
7daf5226 | 249 | * |
89da06ac TB |
250 | * @param id data identifying this policy |
251 | * @param data data for this policy | |
552cc11b | 252 | * @return SUCCESS if operation completed |
aa5a35a0 | 253 | */ |
89da06ac TB |
254 | status_t (*add_policy)(kernel_interface_t *this, |
255 | kernel_ipsec_policy_id_t *id, | |
256 | kernel_ipsec_manage_policy_t *data); | |
7daf5226 | 257 | |
92ee45a0 | 258 | /** |
552cc11b | 259 | * Query the use time of a policy. |
92ee45a0 MW |
260 | * |
261 | * The use time of a policy is the time the policy was used | |
b9131c34 TB |
262 | * for the last time. This is a monotonic timestamp as returned by |
263 | * time_monotonic(). | |
7daf5226 | 264 | * |
89da06ac TB |
265 | * @param id data identifying this policy |
266 | * @param data data to query the policy | |
b9131c34 | 267 | * @param[out] use_time the monotonic timestamp of this policy's last use |
552cc11b | 268 | * @return SUCCESS if operation completed |
92ee45a0 | 269 | */ |
89da06ac TB |
270 | status_t (*query_policy)(kernel_interface_t *this, |
271 | kernel_ipsec_policy_id_t *id, | |
272 | kernel_ipsec_query_policy_t *data, | |
273 | time_t *use_time); | |
7daf5226 | 274 | |
aa5a35a0 | 275 | /** |
552cc11b | 276 | * Remove a policy from the SPD. |
aeeb4f4f | 277 | * |
89da06ac TB |
278 | * @param id data identifying this policy |
279 | * @param data data for this policy | |
552cc11b | 280 | * @return SUCCESS if operation completed |
aa5a35a0 | 281 | */ |
89da06ac TB |
282 | status_t (*del_policy)(kernel_interface_t *this, |
283 | kernel_ipsec_policy_id_t *id, | |
284 | kernel_ipsec_manage_policy_t *data); | |
7daf5226 | 285 | |
0b0f466b TB |
286 | /** |
287 | * Flush all policies from the SPD. | |
288 | * | |
289 | * @return SUCCESS if operation completed | |
290 | */ | |
89da06ac | 291 | status_t (*flush_policies)(kernel_interface_t *this); |
0b0f466b | 292 | |
7068410b | 293 | /** |
552cc11b | 294 | * Get our outgoing source address for a destination. |
7068410b MW |
295 | * |
296 | * Does a route lookup to get the source address used to reach dest. | |
297 | * The returned host is allocated and must be destroyed. | |
ce5b1708 | 298 | * An optional src address can be used to check if a route is available |
dad6d904 | 299 | * for the given source to dest. |
7068410b | 300 | * |
7068410b | 301 | * @param dest target destination address |
ce5b1708 | 302 | * @param src source address to check, or NULL |
7068410b MW |
303 | * @return outgoing source address, NULL if unreachable |
304 | */ | |
ce5b1708 MW |
305 | host_t* (*get_source_addr)(kernel_interface_t *this, |
306 | host_t *dest, host_t *src); | |
7daf5226 | 307 | |
507f26f6 TB |
308 | /** |
309 | * Get the next hop for a destination. | |
310 | * | |
311 | * Does a route lookup to get the next hop used to reach dest. | |
312 | * The returned host is allocated and must be destroyed. | |
dad6d904 TB |
313 | * An optional src address can be used to check if a route is available |
314 | * for the given source to dest. | |
507f26f6 TB |
315 | * |
316 | * @param dest target destination address | |
c005073d TB |
317 | * @param prefix prefix length if dest is a subnet, -1 for auto |
318 | * @param src source address to check, or NULL | |
99a57aa5 TB |
319 | * @param[out] iface allocated name of the interface to reach dest, if |
320 | * available (optional) | |
507f26f6 TB |
321 | * @return next hop address, NULL if unreachable |
322 | */ | |
c005073d | 323 | host_t* (*get_nexthop)(kernel_interface_t *this, host_t *dest, |
99a57aa5 | 324 | int prefix, host_t *src, char **iface); |
7daf5226 | 325 | |
373b8a60 | 326 | /** |
940e1b0f TB |
327 | * Get the interface name of a local address. Interfaces that are down or |
328 | * ignored by config are not considered. | |
373b8a60 | 329 | * |
373b8a60 | 330 | * @param host address to get interface name from |
9ba36c0f TB |
331 | * @param name allocated interface name (optional) |
332 | * @return TRUE if interface found and usable | |
373b8a60 | 333 | */ |
2e2feffb | 334 | bool (*get_interface)(kernel_interface_t *this, host_t *host, char **name); |
7daf5226 | 335 | |
373b8a60 | 336 | /** |
507f26f6 | 337 | * Creates an enumerator over all local addresses. |
7daf5226 | 338 | * |
02b3ec0a | 339 | * This function blocks an internal cached address list until the |
507f26f6 TB |
340 | * enumerator gets destroyed. |
341 | * The hosts are read-only, do not modify of free. | |
7daf5226 | 342 | * |
4106aea8 TB |
343 | * @param which a combination of address types to enumerate |
344 | * @return enumerator over host_t's | |
373b8a60 | 345 | */ |
507f26f6 | 346 | enumerator_t *(*create_address_enumerator) (kernel_interface_t *this, |
4106aea8 | 347 | kernel_address_type_t which); |
7daf5226 | 348 | |
324fc2cb TB |
349 | /** |
350 | * Creates an enumerator over all local subnets. | |
351 | * | |
352 | * Local subnets are subnets the host is directly connected to. | |
353 | * | |
46c21e3c TB |
354 | * The enumerator returns the network, subnet mask and interface. |
355 | * | |
356 | * @return enumerator over host_t*, uint8_t, char* | |
324fc2cb TB |
357 | */ |
358 | enumerator_t *(*create_local_subnet_enumerator)(kernel_interface_t *this); | |
359 | ||
c60c7694 | 360 | /** |
552cc11b | 361 | * Add a virtual IP to an interface. |
c60c7694 MW |
362 | * |
363 | * Virtual IPs are attached to an interface. If an IP is added multiple | |
364 | * times, the IP is refcounted and not removed until del_ip() was called | |
365 | * as many times as add_ip(). | |
c60c7694 | 366 | * |
c60c7694 | 367 | * @param virtual_ip virtual ip address to assign |
50bd7558 | 368 | * @param prefix prefix length to install IP with, -1 for auto |
b185cdd1 | 369 | * @param iface interface to install virtual IP on |
552cc11b | 370 | * @return SUCCESS if operation completed |
c60c7694 | 371 | */ |
50bd7558 | 372 | status_t (*add_ip) (kernel_interface_t *this, host_t *virtual_ip, int prefix, |
b185cdd1 | 373 | char *iface); |
7daf5226 | 374 | |
c60c7694 | 375 | /** |
552cc11b | 376 | * Remove a virtual IP from an interface. |
c60c7694 MW |
377 | * |
378 | * The kernel interface uses refcounting, see add_ip(). | |
379 | * | |
0ceb2888 | 380 | * @param virtual_ip virtual ip address to remove |
50bd7558 | 381 | * @param prefix prefix length of the IP to uninstall, -1 for auto |
b3ab7a48 | 382 | * @param wait TRUE to wait until IP is gone |
552cc11b | 383 | * @return SUCCESS if operation completed |
c60c7694 | 384 | */ |
d88597f0 MW |
385 | status_t (*del_ip) (kernel_interface_t *this, host_t *virtual_ip, |
386 | int prefix, bool wait); | |
7daf5226 | 387 | |
3ebebc5e | 388 | /** |
507f26f6 | 389 | * Add a route. |
7daf5226 | 390 | * |
507f26f6 TB |
391 | * @param dst_net destination net |
392 | * @param prefixlen destination net prefix length | |
393 | * @param gateway gateway for this route | |
0ceb2888 | 394 | * @param src_ip source ip of the route |
507f26f6 | 395 | * @param if_name name of the interface the route is bound to |
09f4bccf | 396 | * @param pass TRUE if route is installed for passthrough policy |
507f26f6 | 397 | * @return SUCCESS if operation completed |
211943be | 398 | * ALREADY_DONE if the route already exists |
507f26f6 | 399 | */ |
211943be | 400 | status_t (*add_route) (kernel_interface_t *this, chunk_t dst_net, |
b12c53ce | 401 | uint8_t prefixlen, host_t *gateway, host_t *src_ip, |
09f4bccf | 402 | char *if_name, bool pass); |
7daf5226 | 403 | |
507f26f6 TB |
404 | /** |
405 | * Delete a route. | |
7daf5226 | 406 | * |
507f26f6 TB |
407 | * @param dst_net destination net |
408 | * @param prefixlen destination net prefix length | |
409 | * @param gateway gateway for this route | |
0ceb2888 | 410 | * @param src_ip source ip of the route |
507f26f6 | 411 | * @param if_name name of the interface the route is bound to |
09f4bccf | 412 | * @param pass TRUE if route was installed for passthrough policy |
507f26f6 TB |
413 | * @return SUCCESS if operation completed |
414 | */ | |
211943be | 415 | status_t (*del_route) (kernel_interface_t *this, chunk_t dst_net, |
b12c53ce | 416 | uint8_t prefixlen, host_t *gateway, host_t *src_ip, |
09f4bccf | 417 | char *if_name, bool pass); |
7daf5226 | 418 | |
54f81859 MW |
419 | /** |
420 | * Set up a bypass policy for a given socket. | |
421 | * | |
422 | * @param fd socket file descriptor to setup policy for | |
423 | * @param family protocol family of the socket | |
e49abced | 424 | * @return TRUE if policy set up successfully |
54f81859 MW |
425 | */ |
426 | bool (*bypass_socket)(kernel_interface_t *this, int fd, int family); | |
427 | ||
e49abced TB |
428 | /** |
429 | * Enable decapsulation of ESP-in-UDP packets for the given port/socket. | |
430 | * | |
431 | * @param fd socket file descriptor | |
432 | * @param family protocol family of the socket | |
433 | * @param port the UDP port | |
434 | * @return TRUE if UDP decapsulation was enabled successfully | |
435 | */ | |
436 | bool (*enable_udp_decap)(kernel_interface_t *this, int fd, int family, | |
b12c53ce | 437 | uint16_t port); |
e49abced TB |
438 | |
439 | ||
507f26f6 TB |
440 | /** |
441 | * manager methods | |
442 | */ | |
7daf5226 | 443 | |
1adaa02b | 444 | /** |
9513225e TB |
445 | * Verifies that the given interface is usable and not excluded by |
446 | * configuration. | |
447 | * | |
448 | * @param iface interface name | |
449 | * @return TRUE if usable | |
450 | */ | |
451 | bool (*is_interface_usable)(kernel_interface_t *this, const char *iface); | |
452 | ||
2e2feffb TB |
453 | /** |
454 | * Check if interfaces are excluded by config. | |
455 | * | |
b3ab7a48 | 456 | * @return TRUE if no interfaces are excluded by config |
2e2feffb TB |
457 | */ |
458 | bool (*all_interfaces_usable)(kernel_interface_t *this); | |
459 | ||
9513225e TB |
460 | /** |
461 | * Tries to find an IP address of a local interface that is included in the | |
1adaa02b | 462 | * supplied traffic selector. |
7daf5226 | 463 | * |
1adaa02b | 464 | * @param ts traffic selector |
9513225e | 465 | * @param ip returned IP address (has to be destroyed) |
f52cf075 | 466 | * @param vip set to TRUE if returned address is a virtual IP |
1adaa02b TB |
467 | * @return SUCCESS if address found |
468 | */ | |
211943be | 469 | status_t (*get_address_by_ts)(kernel_interface_t *this, |
f52cf075 | 470 | traffic_selector_t *ts, host_t **ip, bool *vip); |
7daf5226 | 471 | |
507f26f6 TB |
472 | /** |
473 | * Register an ipsec kernel interface constructor on the manager. | |
474 | * | |
db61c376 TE |
475 | * @param create constructor to register |
476 | * @return TRUE if the ipsec kernel interface was registered | |
477 | * successfully, FALSE if an interface was already | |
478 | * registered or the registration failed | |
507f26f6 | 479 | */ |
db61c376 | 480 | bool (*add_ipsec_interface)(kernel_interface_t *this, |
211943be | 481 | kernel_ipsec_constructor_t create); |
7daf5226 | 482 | |
507f26f6 TB |
483 | /** |
484 | * Unregister an ipsec kernel interface constructor. | |
485 | * | |
db61c376 TE |
486 | * @param create constructor to unregister |
487 | * @return TRUE if the ipsec kernel interface was unregistered | |
488 | * successfully, FALSE otherwise | |
507f26f6 | 489 | */ |
db61c376 | 490 | bool (*remove_ipsec_interface)(kernel_interface_t *this, |
211943be | 491 | kernel_ipsec_constructor_t create); |
7daf5226 | 492 | |
507f26f6 TB |
493 | /** |
494 | * Register a network kernel interface constructor on the manager. | |
495 | * | |
db61c376 TE |
496 | * @param create constructor to register |
497 | * @return TRUE if the kernel net interface was registered | |
498 | * successfully, FALSE if an interface was already | |
499 | * registered or the registration failed | |
507f26f6 | 500 | */ |
db61c376 | 501 | bool (*add_net_interface)(kernel_interface_t *this, |
211943be | 502 | kernel_net_constructor_t create); |
7daf5226 | 503 | |
507f26f6 TB |
504 | /** |
505 | * Unregister a network kernel interface constructor. | |
506 | * | |
db61c376 TE |
507 | * @param create constructor to unregister |
508 | * @return TRUE if the kernel net interface was unregistered | |
509 | * successfully, FALSE otherwise | |
507f26f6 | 510 | */ |
db61c376 | 511 | bool (*remove_net_interface)(kernel_interface_t *this, |
211943be | 512 | kernel_net_constructor_t create); |
7daf5226 | 513 | |
c560ddeb TB |
514 | /** |
515 | * Add a listener to the kernel interface. | |
516 | * | |
db61c376 | 517 | * @param listener listener to add |
c560ddeb TB |
518 | */ |
519 | void (*add_listener)(kernel_interface_t *this, | |
520 | kernel_listener_t *listener); | |
521 | ||
522 | /** | |
523 | * Remove a listener from the kernel interface. | |
524 | * | |
db61c376 | 525 | * @param listener listener to remove |
c560ddeb TB |
526 | */ |
527 | void (*remove_listener)(kernel_interface_t *this, | |
528 | kernel_listener_t *listener); | |
529 | ||
530 | /** | |
531 | * Raise an acquire event. | |
532 | * | |
533 | * @param reqid reqid of the policy to acquire | |
3b699c72 | 534 | * @param data data from the acquire |
c560ddeb | 535 | */ |
b12c53ce | 536 | void (*acquire)(kernel_interface_t *this, uint32_t reqid, |
3b699c72 | 537 | kernel_acquire_data_t *data); |
c560ddeb TB |
538 | |
539 | /** | |
540 | * Raise an expire event. | |
541 | * | |
c560ddeb TB |
542 | * @param protocol protocol of the expired SA |
543 | * @param spi spi of the expired SA | |
f81a9497 | 544 | * @param dst destination address of expired SA |
c560ddeb TB |
545 | * @param hard TRUE if it is a hard expire, FALSE otherwise |
546 | */ | |
b12c53ce | 547 | void (*expire)(kernel_interface_t *this, uint8_t protocol, uint32_t spi, |
f81a9497 | 548 | host_t *dst, bool hard); |
c560ddeb TB |
549 | |
550 | /** | |
551 | * Raise a mapping event. | |
552 | * | |
b125839a | 553 | * @param protocol protocol of affected SA |
c560ddeb | 554 | * @param spi spi of the SA |
b125839a | 555 | * @param dst original destination address of SA |
c560ddeb TB |
556 | * @param remote new remote host |
557 | */ | |
b12c53ce | 558 | void (*mapping)(kernel_interface_t *this, uint8_t protocol, uint32_t spi, |
b125839a | 559 | host_t *dst, host_t *remote); |
c560ddeb TB |
560 | |
561 | /** | |
562 | * Raise a migrate event. | |
563 | * | |
564 | * @param reqid reqid of the policy | |
565 | * @param src_ts source traffic selector | |
566 | * @param dst_ts destination traffic selector | |
567 | * @param direction direction of the policy (in|out) | |
568 | * @param local local host address to be used in the IKE_SA | |
569 | * @param remote remote host address to be used in the IKE_SA | |
570 | */ | |
b12c53ce | 571 | void (*migrate)(kernel_interface_t *this, uint32_t reqid, |
c560ddeb TB |
572 | traffic_selector_t *src_ts, traffic_selector_t *dst_ts, |
573 | policy_dir_t direction, host_t *local, host_t *remote); | |
574 | ||
575 | /** | |
576 | * Raise a roam event. | |
577 | * | |
578 | * @param address TRUE if address list, FALSE if routing changed | |
579 | */ | |
580 | void (*roam)(kernel_interface_t *this, bool address); | |
581 | ||
4868d1c3 TB |
582 | /** |
583 | * Raise a tun event. | |
584 | * | |
585 | * @param tun TUN device | |
586 | * @param created TRUE if created, FALSE if going to be destroyed | |
587 | */ | |
588 | void (*tun)(kernel_interface_t *this, tun_device_t *tun, bool created); | |
589 | ||
524fb37c TB |
590 | /** |
591 | * Register a new algorithm with the kernel interface. | |
592 | * | |
593 | * @param alg_id the IKE id of the algorithm | |
594 | * @param type the transform type of the algorithm | |
595 | * @param kernel_id the kernel id of the algorithm | |
596 | * @param kernel_name the kernel name of the algorithm | |
597 | */ | |
b12c53ce AS |
598 | void (*register_algorithm)(kernel_interface_t *this, uint16_t alg_id, |
599 | transform_type_t type, uint16_t kernel_id, | |
524fb37c TB |
600 | char *kernel_name); |
601 | ||
602 | /** | |
603 | * Return the kernel-specific id and/or name for an algorithms depending on | |
604 | * the arguments specified. | |
605 | * | |
606 | * @param alg_id the IKE id of the algorithm | |
607 | * @param type the transform type of the algorithm | |
608 | * @param kernel_id the kernel id of the algorithm (optional) | |
609 | * @param kernel_name the kernel name of the algorithm (optional) | |
610 | * @return TRUE if algorithm was found | |
611 | */ | |
b12c53ce AS |
612 | bool (*lookup_algorithm)(kernel_interface_t *this, uint16_t alg_id, |
613 | transform_type_t type, uint16_t *kernel_id, | |
524fb37c TB |
614 | char **kernel_name); |
615 | ||
507f26f6 | 616 | /** |
0ceb2888 | 617 | * Destroys a kernel_interface_t object. |
3ebebc5e | 618 | */ |
507f26f6 | 619 | void (*destroy) (kernel_interface_t *this); |
3ebebc5e MW |
620 | }; |
621 | ||
622 | /** | |
552cc11b | 623 | * Creates an object of type kernel_interface_t. |
3ebebc5e | 624 | */ |
f768bdc3 | 625 | kernel_interface_t *kernel_interface_create(void); |
3ebebc5e | 626 | |
1490ff4d | 627 | #endif /** KERNEL_INTERFACE_H_ @}*/ |