2 * @file kernel_interface.h
4 * @brief Interface of kernel_interface_t.
9 * Copyright (C) 2006 Tobias Brunner, Daniel Roethlisberger
10 * Copyright (C) 2005-2006 Martin Willi
11 * Copyright (C) 2005 Jan Hutter
12 * Hochschule fuer Technik Rapperswil
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 #ifndef KERNEL_INTERFACE_H_
26 #define KERNEL_INTERFACE_H_
28 typedef struct natt_conf_t natt_conf_t
;
29 typedef enum policy_dir_t policy_dir_t
;
30 typedef struct kernel_interface_t kernel_interface_t
;
32 #include <utils/host.h>
33 #include <crypto/prf_plus.h>
34 #include <encoding/payloads/proposal_substructure.h>
37 * Configuration for NAT-T
40 /** source port to use for UDP-encapsulated packets */
42 /** dest port to use for UDP-encapsulated packets */
47 * Direction of a policy. These are equal to those
48 * defined in xfrm.h, but we want to stay implementation
52 /** Policy for inbound traffic */
54 /** Policy for outbound traffic */
56 /** Policy for forwarded traffic */
61 * @brief Interface to the kernel.
63 * The kernel interface handles the communication with the kernel
64 * for SA and policy management. It allows setup of these, and provides
65 * further the handling of kernel events.
66 * Policy information are cached in the interface. This is necessary to do
67 * reference counting. The Linux kernel does not allow the same policy
68 * installed twice, but we need this as CHILD_SA exist multiple times
69 * when rekeying. Thats why we do reference counting of policies.
72 * - kernel_interface_create()
76 struct kernel_interface_t
{
79 * @brief Get a SPI from the kernel.
81 * @warning get_spi() implicitely creates an SA with
82 * the allocated SPI, therefore the replace flag
83 * in add_sa() must be set when installing this SA.
85 * @param this calling object
86 * @param src source address of SA
87 * @param dst destination address of SA
88 * @param protocol protocol for SA (ESP/AH)
89 * @param reqid unique ID for this SA
90 * @param[out] spi allocated spi
93 * - FAILED if kernel comm failed
95 status_t (*get_spi
)(kernel_interface_t
*this, host_t
*src
, host_t
*dst
,
96 protocol_id_t protocol
, u_int32_t reqid
, u_int32_t
*spi
);
99 * @brief Add an SA to the SAD.
101 * add_sa() may update an already allocated
102 * SPI (via get_spi). In this case, the replace
104 * This function does install a single SA for a
105 * single protocol in one direction. The kernel-interface
106 * gets the keys itself from the PRF, as we don't know
107 * his algorithms and key sizes.
109 * @param this calling object
110 * @param src source address for this SA
111 * @param dst destination address for this SA
112 * @param spi SPI allocated by us or remote peer
113 * @param protocol protocol for this SA (ESP/AH)
114 * @param reqid unique ID for this SA
115 * @param expire_soft lifetime in seconds before rekeying
116 * @param expire_hard lieftime in seconds before delete
117 * @param enc_alg Algorithm to use for encryption (ESP only)
118 * @param int_alg Algorithm to use for integrity protection
119 * @param prf_plus PRF to derive keys from
120 * @param natt NAT-T Configuration, or NULL of no NAT-T used
121 * @param mode mode of the SA (tunnel, transport)
122 * @param replace Should an already installed SA be updated?
125 * - FAILED if kernel comm failed
127 status_t (*add_sa
) (kernel_interface_t
*this,
128 host_t
*src
, host_t
*dst
, u_int32_t spi
,
129 protocol_id_t protocol
, u_int32_t reqid
,
130 u_int64_t expire_soft
, u_int64_t expire_hard
,
131 algorithm_t
*enc_alg
, algorithm_t
*int_alg
,
132 prf_plus_t
*prf_plus
, natt_conf_t
*natt
,
133 mode_t mode
, bool update
);
136 * @brief Update the hosts on an installed SA.
138 * We cannot directly update the destination address as the kernel
139 * requires the spi, the protocol AND the destination address (and family)
140 * to identify SAs. Therefore if the destination address changed we
141 * create a new SA and delete the old one.
143 * @param this calling object
144 * @param dst destination address for this SA
145 * @param spi SPI of the SA
146 * @param protocol protocol for this SA (ESP/AH)
147 * @param new_src new source address for this SA
148 * @param new_dst new destination address for this SA
149 * @param src_changes changes in src
150 * @param dst_changes changes in dst
153 * - FAILED if kernel comm failed
155 status_t (*update_sa
)(kernel_interface_t
*this, host_t
*dst
, u_int32_t spi
,
156 protocol_id_t protocol
,
157 host_t
*new_src
, host_t
*new_dst
,
158 host_diff_t src_changes
, host_diff_t dst_changes
);
161 * @brief Query the use time of an SA.
163 * The use time of an SA is not the time of the last usage, but
164 * the time of the first usage of the SA.
166 * @param this calling object
167 * @param dst destination address for this SA
168 * @param spi SPI allocated by us or remote peer
169 * @param protocol protocol for this SA (ESP/AH)
170 * @param[out] use_time the time of this SA's last use
173 * - FAILED if kernel comm failed
175 status_t (*query_sa
) (kernel_interface_t
*this, host_t
*dst
, u_int32_t spi
,
176 protocol_id_t protocol
, u_int32_t
*use_time
);
179 * @brief Delete a previusly installed SA from the SAD.
181 * @param this calling object
182 * @param dst destination address for this SA
183 * @param spi SPI allocated by us or remote peer
184 * @param protocol protocol for this SA (ESP/AH)
187 * - FAILED if kernel comm failed
189 status_t (*del_sa
) (kernel_interface_t
*this, host_t
*dst
, u_int32_t spi
,
190 protocol_id_t protocol
);
193 * @brief Add a policy to the SPD.
195 * A policy is always associated to an SA. Traffic which matches a
196 * policy is handled by the SA with the same reqid.
197 * If the update flag is set, the policy is updated with the new
199 * If the update flag is not set, but a such policy is already in the
200 * kernel, the reference count to this policy is increased.
202 * @param this calling object
203 * @param src source address of SA
204 * @param dst dest address of SA
205 * @param src_ts traffic selector to match traffic source
206 * @param dst_ts traffic selector to match traffic dest
207 * @param direction direction of traffic, POLICY_IN, POLICY_OUT, POLICY_FWD
208 * @param protocol protocol to use to protect traffic (AH/ESP)
209 * @param reqid uniqe ID of an SA to use to enforce policy
210 * @param high_prio if TRUE, uses a higher priority than any with FALSE
211 * @param mode mode of SA (tunnel, transport)
212 * @param update update an existing policy, if TRUE
215 * - FAILED if kernel comm failed
217 status_t (*add_policy
) (kernel_interface_t
*this,
218 host_t
*src
, host_t
*dst
,
219 traffic_selector_t
*src_ts
,
220 traffic_selector_t
*dst_ts
,
221 policy_dir_t direction
, protocol_id_t protocol
,
222 u_int32_t reqid
, bool high_prio
,
223 mode_t mode
, bool update
);
226 * @brief Query the use time of a policy.
228 * The use time of a policy is the time the policy was used
231 * @param this calling object
232 * @param src_ts traffic selector to match traffic source
233 * @param dst_ts traffic selector to match traffic dest
234 * @param direction direction of traffic, POLICY_IN, POLICY_OUT, POLICY_FWD
235 * @param[out] use_time the time of this SA's last use
238 * - FAILED if kernel comm failed
240 status_t (*query_policy
) (kernel_interface_t
*this,
241 traffic_selector_t
*src_ts
,
242 traffic_selector_t
*dst_ts
,
243 policy_dir_t direction
, u_int32_t
*use_time
);
246 * @brief Remove a policy from the SPD.
248 * The kernel interface implements reference counting for policies.
249 * If the same policy is installed multiple times (in the case of rekeying),
250 * the reference counter is increased. del_policy() decreases the ref counter
251 * and removes the policy only when no more references are available.
253 * @param this calling object
254 * @param src_ts traffic selector to match traffic source
255 * @param dst_ts traffic selector to match traffic dest
256 * @param direction direction of traffic, POLICY_IN, POLICY_OUT, POLICY_FWD
259 * - FAILED if kernel comm failed
261 status_t (*del_policy
) (kernel_interface_t
*this,
262 traffic_selector_t
*src_ts
,
263 traffic_selector_t
*dst_ts
,
264 policy_dir_t direction
);
267 * @brief Get the interface name of a local address.
269 * @param this calling object
270 * @param host address to get interface name from
271 * @return allocated interface name, or NULL if not found
273 char* (*get_interface
) (kernel_interface_t
*this, host_t
*host
);
276 * @brief Creates a list of all local addresses.
278 * @param this calling object
279 * @return allocated list with host_t objects
281 linked_list_t
*(*create_address_list
) (kernel_interface_t
*this);
284 * @brief Add a virtual IP to an interface.
286 * Virtual IPs are attached to an interface. If an IP is added multiple
287 * times, the IP is refcounted and not removed until del_ip() was called
288 * as many times as add_ip().
289 * The virtual IP is attached to the interface where the iface_ip is found.
291 * @param this calling object
292 * @param virtual_ip virtual ip address to assign
293 * @param iface_ip IP of an interface to attach virtual IP
296 * - FAILED if kernel comm failed
298 status_t (*add_ip
) (kernel_interface_t
*this, host_t
*virtual_ip
,
302 * @brief Remove a virtual IP from an interface.
304 * The kernel interface uses refcounting, see add_ip().
306 * @param this calling object
307 * @param virtual_ip virtual ip address to assign
308 * @param iface_ip IP of an interface to remove virtual IP from
311 * - FAILED if kernel comm failed
313 status_t (*del_ip
) (kernel_interface_t
*this, host_t
*virtual_ip
,
317 * @brief Destroys a kernel_interface object.
319 * @param kernel_interface_t calling object
321 void (*destroy
) (kernel_interface_t
*kernel_interface
);
325 * @brief Creates an object of type kernel_interface_t.
329 kernel_interface_t
*kernel_interface_create(void);
331 #endif /*KERNEL_INTERFACE_H_*/