typo
[strongswan.git] / src / charon / kernel / kernel_interface.h
1 /*
2 * Copyright (C) 2006 Tobias Brunner, Daniel Roethlisberger
3 * Copyright (C) 2005-2006 Martin Willi
4 * Copyright (C) 2005 Jan Hutter
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 *
17 * $Id$
18 */
19
20 /**
21 * @defgroup kernel_interface kernel_interface
22 * @{ @ingroup kernel
23 */
24
25 #ifndef KERNEL_INTERFACE_H_
26 #define KERNEL_INTERFACE_H_
27
28 typedef enum policy_dir_t policy_dir_t;
29 typedef struct kernel_interface_t kernel_interface_t;
30
31 #include <utils/host.h>
32 #include <crypto/prf_plus.h>
33 #include <encoding/payloads/proposal_substructure.h>
34
35
36 /**
37 * Direction of a policy. These are equal to those
38 * defined in xfrm.h, but we want to stay implementation
39 * neutral here.
40 */
41 enum policy_dir_t {
42 /** Policy for inbound traffic */
43 POLICY_IN = 0,
44 /** Policy for outbound traffic */
45 POLICY_OUT = 1,
46 /** Policy for forwarded traffic */
47 POLICY_FWD = 2,
48 };
49
50 /**
51 * Interface to the kernel.
52 *
53 * The kernel interface handles the communication with the kernel
54 * for SA and policy management. It allows setup of these, and provides
55 * further the handling of kernel events.
56 * Policy information are cached in the interface. This is necessary to do
57 * reference counting. The Linux kernel does not allow the same policy
58 * installed twice, but we need this as CHILD_SA exist multiple times
59 * when rekeying. Thats why we do reference counting of policies.
60 */
61 struct kernel_interface_t {
62
63 /**
64 * Get a SPI from the kernel.
65 *
66 * @warning get_spi() implicitely creates an SA with
67 * the allocated SPI, therefore the replace flag
68 * in add_sa() must be set when installing this SA.
69 *
70 * @param src source address of SA
71 * @param dst destination address of SA
72 * @param protocol protocol for SA (ESP/AH)
73 * @param reqid unique ID for this SA
74 * @param spi allocated spi
75 * @return SUCCESS if operation completed
76 */
77 status_t (*get_spi)(kernel_interface_t *this, host_t *src, host_t *dst,
78 protocol_id_t protocol, u_int32_t reqid, u_int32_t *spi);
79
80 /**
81 * Add an SA to the SAD.
82 *
83 * add_sa() may update an already allocated
84 * SPI (via get_spi). In this case, the replace
85 * flag must be set.
86 * This function does install a single SA for a
87 * single protocol in one direction. The kernel-interface
88 * gets the keys itself from the PRF, as we don't know
89 * his algorithms and key sizes.
90 *
91 * @param src source address for this SA
92 * @param dst destination address for this SA
93 * @param spi SPI allocated by us or remote peer
94 * @param protocol protocol for this SA (ESP/AH)
95 * @param reqid unique ID for this SA
96 * @param expire_soft lifetime in seconds before rekeying
97 * @param expire_hard lieftime in seconds before delete
98 * @param enc_alg Algorithm to use for encryption (ESP only)
99 * @param enc_size key length of encryption algorithm, if dynamic
100 * @param int_alg Algorithm to use for integrity protection
101 * @param int_size key length of integrity algorithm, if dynamic
102 * @param prf_plus PRF to derive keys from
103 * @param mode mode of the SA (tunnel, transport)
104 * @param encap enable UDP encapsulation for NAT traversal
105 * @param replace Should an already installed SA be updated?
106 * @return SUCCESS if operation completed
107 */
108 status_t (*add_sa) (kernel_interface_t *this,
109 host_t *src, host_t *dst, u_int32_t spi,
110 protocol_id_t protocol, u_int32_t reqid,
111 u_int64_t expire_soft, u_int64_t expire_hard,
112 u_int16_t enc_alg, u_int16_t enc_size,
113 u_int16_t int_alg, u_int16_t int_size,
114 prf_plus_t *prf_plus, mode_t mode, bool encap,
115 bool update);
116
117 /**
118 * Update the hosts on an installed SA.
119 *
120 * We cannot directly update the destination address as the kernel
121 * requires the spi, the protocol AND the destination address (and family)
122 * to identify SAs. Therefore if the destination address changed we
123 * create a new SA and delete the old one.
124 *
125 * @param spi SPI of the SA
126 * @param protocol protocol for this SA (ESP/AH)
127 * @param src current source address
128 * @param dst current destination address
129 * @param new_src new source address
130 * @param new_dst new destination address
131 * @param encap use UDP encapsulation
132 * @return SUCCESS if operation completed
133 */
134 status_t (*update_sa)(kernel_interface_t *this,
135 u_int32_t spi, protocol_id_t protocol,
136 host_t *src, host_t *dst,
137 host_t *new_src, host_t *new_dst, bool encap);
138
139 /**
140 * Query the use time of an SA.
141 *
142 * The use time of an SA is not the time of the last usage, but
143 * the time of the first usage of the SA.
144 *
145 * @param dst destination address for this SA
146 * @param spi SPI allocated by us or remote peer
147 * @param protocol protocol for this SA (ESP/AH)
148 * @param use_time pointer receives the time of this SA's last use
149 * @return SUCCESS if operation completed
150 */
151 status_t (*query_sa) (kernel_interface_t *this, host_t *dst, u_int32_t spi,
152 protocol_id_t protocol, u_int32_t *use_time);
153
154 /**
155 * Delete a previusly installed SA from the SAD.
156 *
157 * @param dst destination address for this SA
158 * @param spi SPI allocated by us or remote peer
159 * @param protocol protocol for this SA (ESP/AH)
160 * @return SUCCESS if operation completed
161 */
162 status_t (*del_sa) (kernel_interface_t *this, host_t *dst, u_int32_t spi,
163 protocol_id_t protocol);
164
165 /**
166 * Add a policy to the SPD.
167 *
168 * A policy is always associated to an SA. Traffic which matches a
169 * policy is handled by the SA with the same reqid.
170 *
171 * @param src source address of SA
172 * @param dst dest address of SA
173 * @param src_ts traffic selector to match traffic source
174 * @param dst_ts traffic selector to match traffic dest
175 * @param direction direction of traffic, POLICY_IN, POLICY_OUT, POLICY_FWD
176 * @param protocol protocol to use to protect traffic (AH/ESP)
177 * @param reqid uniqe ID of an SA to use to enforce policy
178 * @param high_prio if TRUE, uses a higher priority than any with FALSE
179 * @param mode mode of SA (tunnel, transport)
180 * @return SUCCESS if operation completed
181 */
182 status_t (*add_policy) (kernel_interface_t *this,
183 host_t *src, host_t *dst,
184 traffic_selector_t *src_ts,
185 traffic_selector_t *dst_ts,
186 policy_dir_t direction, protocol_id_t protocol,
187 u_int32_t reqid, bool high_prio, mode_t mode);
188
189 /**
190 * Query the use time of a policy.
191 *
192 * The use time of a policy is the time the policy was used
193 * for the last time.
194 *
195 * @param src_ts traffic selector to match traffic source
196 * @param dst_ts traffic selector to match traffic dest
197 * @param direction direction of traffic, POLICY_IN, POLICY_OUT, POLICY_FWD
198 * @param[out] use_time the time of this SA's last use
199 * @return SUCCESS if operation completed
200 */
201 status_t (*query_policy) (kernel_interface_t *this,
202 traffic_selector_t *src_ts,
203 traffic_selector_t *dst_ts,
204 policy_dir_t direction, u_int32_t *use_time);
205
206 /**
207 * Remove a policy from the SPD.
208 *
209 * The kernel interface implements reference counting for policies.
210 * If the same policy is installed multiple times (in the case of rekeying),
211 * the reference counter is increased. del_policy() decreases the ref counter
212 * and removes the policy only when no more references are available.
213 *
214 * @param src_ts traffic selector to match traffic source
215 * @param dst_ts traffic selector to match traffic dest
216 * @param direction direction of traffic, POLICY_IN, POLICY_OUT, POLICY_FWD
217 * @return SUCCESS if operation completed
218 */
219 status_t (*del_policy) (kernel_interface_t *this,
220 traffic_selector_t *src_ts,
221 traffic_selector_t *dst_ts,
222 policy_dir_t direction);
223
224 /**
225 * Get our outgoing source address for a destination.
226 *
227 * Does a route lookup to get the source address used to reach dest.
228 * The returned host is allocated and must be destroyed.
229 *
230 * @param dest target destination address
231 * @return outgoing source address, NULL if unreachable
232 */
233 host_t* (*get_source_addr)(kernel_interface_t *this, host_t *dest);
234
235 /**
236 * Get the interface name of a local address.
237 *
238 * @param host address to get interface name from
239 * @return allocated interface name, or NULL if not found
240 */
241 char* (*get_interface) (kernel_interface_t *this, host_t *host);
242
243 /**
244 * Creates an iterator over all local addresses.
245 *
246 * This function blocks an internal cached address list until the
247 * iterator gets destroyed.
248 * These hosts are read-only, do not modify or free.
249 *
250 * @return iterator over host_t's
251 */
252 iterator_t *(*create_address_iterator) (kernel_interface_t *this);
253
254 /**
255 * Add a virtual IP to an interface.
256 *
257 * Virtual IPs are attached to an interface. If an IP is added multiple
258 * times, the IP is refcounted and not removed until del_ip() was called
259 * as many times as add_ip().
260 * The virtual IP is attached to the interface where the iface_ip is found.
261 *
262 * @param virtual_ip virtual ip address to assign
263 * @param iface_ip IP of an interface to attach virtual IP
264 * @return SUCCESS if operation completed
265 */
266 status_t (*add_ip) (kernel_interface_t *this, host_t *virtual_ip,
267 host_t *iface_ip);
268
269 /**
270 * Remove a virtual IP from an interface.
271 *
272 * The kernel interface uses refcounting, see add_ip().
273 *
274 * @param virtual_ip virtual ip address to assign
275 * @return SUCCESS if operation completed
276 */
277 status_t (*del_ip) (kernel_interface_t *this, host_t *virtual_ip);
278
279 /**
280 * Destroys a kernel_interface object.
281 */
282 void (*destroy) (kernel_interface_t *kernel_interface);
283 };
284
285 /**
286 * Creates an object of type kernel_interface_t.
287 */
288 kernel_interface_t *kernel_interface_create(void);
289
290 #endif /*KERNEL_INTERFACE_H_ @} */