]>
Commit | Line | Data |
---|---|---|
507f26f6 | 1 | /* |
aed33805 | 2 | * Copyright (C) 2008-2012 Tobias Brunner |
507f26f6 TB |
3 | * Copyright (C) 2007 Martin Willi |
4 | * Hochschule fuer Technik Rapperswil | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the | |
8 | * Free Software Foundation; either version 2 of the License, or (at your | |
9 | * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 | * for more details. | |
507f26f6 TB |
15 | */ |
16 | ||
17 | /** | |
18 | * @defgroup kernel_net kernel_net | |
8394ea2a | 19 | * @{ @ingroup kernel |
507f26f6 TB |
20 | */ |
21 | ||
22 | #ifndef KERNEL_NET_H_ | |
23 | #define KERNEL_NET_H_ | |
24 | ||
25 | typedef struct kernel_net_t kernel_net_t; | |
4106aea8 | 26 | typedef enum kernel_address_type_t kernel_address_type_t; |
507f26f6 | 27 | |
12642a68 | 28 | #include <collections/enumerator.h> |
2e7cc07e | 29 | #include <networking/host.h> |
29d30991 | 30 | #include <plugins/plugin.h> |
76f7d80e | 31 | #include <kernel/kernel_interface.h> |
507f26f6 | 32 | |
4106aea8 TB |
33 | /** |
34 | * Type of addresses (e.g. when enumerating them) | |
35 | */ | |
36 | enum kernel_address_type_t { | |
37 | /** normal addresses (on regular, up, non-ignored) interfaces */ | |
1a2a8bff | 38 | ADDR_TYPE_REGULAR = (1 << 0), |
4106aea8 | 39 | /** addresses on down interfaces */ |
1a2a8bff | 40 | ADDR_TYPE_DOWN = (1 << 1), |
4106aea8 | 41 | /** addresses on ignored interfaces */ |
1a2a8bff | 42 | ADDR_TYPE_IGNORED = (1 << 2), |
4106aea8 | 43 | /** addresses on loopback interfaces */ |
1a2a8bff | 44 | ADDR_TYPE_LOOPBACK = (1 << 3), |
4106aea8 | 45 | /** virtual IP addresses */ |
1a2a8bff | 46 | ADDR_TYPE_VIRTUAL = (1 << 4), |
4106aea8 | 47 | /** to enumerate all available addresses */ |
1a2a8bff | 48 | ADDR_TYPE_ALL = (1 << 5) - 1, |
4106aea8 TB |
49 | }; |
50 | ||
507f26f6 TB |
51 | /** |
52 | * Interface to the network subsystem of the kernel. | |
7daf5226 | 53 | * |
507f26f6 TB |
54 | * The kernel network interface handles the communication with the kernel |
55 | * for interface and IP address management. | |
56 | */ | |
57 | struct kernel_net_t { | |
58 | ||
76f7d80e MW |
59 | /** |
60 | * Get the feature set supported by this kernel backend. | |
61 | * | |
62 | * @return ORed feature-set of backend | |
63 | */ | |
64 | kernel_feature_t (*get_features)(kernel_net_t *this); | |
65 | ||
507f26f6 TB |
66 | /** |
67 | * Get our outgoing source address for a destination. | |
68 | * | |
69 | * Does a route lookup to get the source address used to reach dest. | |
70 | * The returned host is allocated and must be destroyed. | |
ce5b1708 | 71 | * An optional src address can be used to check if a route is available |
dad6d904 | 72 | * for the given source to dest. |
507f26f6 TB |
73 | * |
74 | * @param dest target destination address | |
ce5b1708 | 75 | * @param src source address to check, or NULL |
507f26f6 TB |
76 | * @return outgoing source address, NULL if unreachable |
77 | */ | |
ce5b1708 | 78 | host_t* (*get_source_addr)(kernel_net_t *this, host_t *dest, host_t *src); |
7daf5226 | 79 | |
507f26f6 TB |
80 | /** |
81 | * Get the next hop for a destination. | |
82 | * | |
83 | * Does a route lookup to get the next hop used to reach dest. | |
84 | * The returned host is allocated and must be destroyed. | |
dad6d904 TB |
85 | * An optional src address can be used to check if a route is available |
86 | * for the given source to dest. | |
507f26f6 TB |
87 | * |
88 | * @param dest target destination address | |
c005073d | 89 | * @param prefix prefix length if dest is a subnet, -1 for auto |
dad6d904 | 90 | * @param src source address to check, or NULL |
507f26f6 TB |
91 | * @return next hop address, NULL if unreachable |
92 | */ | |
c005073d TB |
93 | host_t* (*get_nexthop)(kernel_net_t *this, host_t *dest, int prefix, |
94 | host_t *src); | |
7daf5226 | 95 | |
507f26f6 | 96 | /** |
940e1b0f TB |
97 | * Get the interface name of a local address. Interfaces that are down or |
98 | * ignored by config are not considered. | |
507f26f6 TB |
99 | * |
100 | * @param host address to get interface name from | |
9ba36c0f TB |
101 | * @param name allocated interface name (optional) |
102 | * @return TRUE if interface found and usable | |
507f26f6 | 103 | */ |
9ba36c0f | 104 | bool (*get_interface) (kernel_net_t *this, host_t *host, char **name); |
7daf5226 | 105 | |
507f26f6 TB |
106 | /** |
107 | * Creates an enumerator over all local addresses. | |
7daf5226 | 108 | * |
507f26f6 TB |
109 | * This function blocks an internal cached address list until the |
110 | * enumerator gets destroyed. | |
111 | * The hosts are read-only, do not modify of free. | |
7daf5226 | 112 | * |
4106aea8 TB |
113 | * @param which a combination of address types to enumerate |
114 | * @return enumerator over host_t's | |
507f26f6 TB |
115 | */ |
116 | enumerator_t *(*create_address_enumerator) (kernel_net_t *this, | |
4106aea8 | 117 | kernel_address_type_t which); |
7daf5226 | 118 | |
507f26f6 TB |
119 | /** |
120 | * Add a virtual IP to an interface. | |
121 | * | |
122 | * Virtual IPs are attached to an interface. If an IP is added multiple | |
123 | * times, the IP is refcounted and not removed until del_ip() was called | |
124 | * as many times as add_ip(). | |
507f26f6 TB |
125 | * |
126 | * @param virtual_ip virtual ip address to assign | |
50bd7558 | 127 | * @param prefix prefix length to install with IP address, -1 for auto |
b185cdd1 | 128 | * @param iface interface to install virtual IP on |
507f26f6 TB |
129 | * @return SUCCESS if operation completed |
130 | */ | |
50bd7558 | 131 | status_t (*add_ip) (kernel_net_t *this, host_t *virtual_ip, int prefix, |
b185cdd1 | 132 | char *iface); |
7daf5226 | 133 | |
507f26f6 TB |
134 | /** |
135 | * Remove a virtual IP from an interface. | |
136 | * | |
137 | * The kernel interface uses refcounting, see add_ip(). | |
138 | * | |
0ceb2888 | 139 | * @param virtual_ip virtual ip address to remove |
50bd7558 | 140 | * @param prefix prefix length of the IP to uninstall, -1 for auto |
d88597f0 | 141 | * @param wait TRUE to wait until IP is gone |
507f26f6 TB |
142 | * @return SUCCESS if operation completed |
143 | */ | |
d88597f0 MW |
144 | status_t (*del_ip) (kernel_net_t *this, host_t *virtual_ip, int prefix, |
145 | bool wait); | |
7daf5226 | 146 | |
507f26f6 TB |
147 | /** |
148 | * Add a route. | |
7daf5226 | 149 | * |
507f26f6 TB |
150 | * @param dst_net destination net |
151 | * @param prefixlen destination net prefix length | |
152 | * @param gateway gateway for this route | |
0ceb2888 | 153 | * @param src_ip source ip of the route |
507f26f6 TB |
154 | * @param if_name name of the interface the route is bound to |
155 | * @return SUCCESS if operation completed | |
211943be | 156 | * ALREADY_DONE if the route already exists |
507f26f6 | 157 | */ |
211943be TB |
158 | status_t (*add_route) (kernel_net_t *this, chunk_t dst_net, |
159 | u_int8_t prefixlen, host_t *gateway, host_t *src_ip, | |
160 | char *if_name); | |
7daf5226 | 161 | |
507f26f6 TB |
162 | /** |
163 | * Delete a route. | |
7daf5226 | 164 | * |
507f26f6 TB |
165 | * @param dst_net destination net |
166 | * @param prefixlen destination net prefix length | |
167 | * @param gateway gateway for this route | |
0ceb2888 | 168 | * @param src_ip source ip of the route |
507f26f6 TB |
169 | * @param if_name name of the interface the route is bound to |
170 | * @return SUCCESS if operation completed | |
171 | */ | |
211943be TB |
172 | status_t (*del_route) (kernel_net_t *this, chunk_t dst_net, |
173 | u_int8_t prefixlen, host_t *gateway, host_t *src_ip, | |
174 | char *if_name); | |
7daf5226 | 175 | |
507f26f6 TB |
176 | /** |
177 | * Destroy the implementation. | |
178 | */ | |
179 | void (*destroy) (kernel_net_t *this); | |
180 | }; | |
181 | ||
29d30991 MW |
182 | /** |
183 | * Helper function to (un-)register net kernel interfaces from plugin features. | |
184 | * | |
185 | * This function is a plugin_feature_callback_t and can be used with the | |
186 | * PLUGIN_CALLBACK macro to register an net kernel interface constructor. | |
187 | * | |
188 | * @param plugin plugin registering the kernel interface | |
189 | * @param feature associated plugin feature | |
190 | * @param reg TRUE to register, FALSE to unregister | |
191 | * @param data data passed to callback, an kernel_net_constructor_t | |
192 | */ | |
193 | bool kernel_net_register(plugin_t *plugin, plugin_feature_t *feature, | |
194 | bool reg, void *data); | |
195 | ||
1490ff4d | 196 | #endif /** KERNEL_NET_H_ @}*/ |