Removed strayed code fragment
[strongswan.git] / src / charon / kernel / kernel_ipsec.h
1 /*
2 * Copyright (C) 2006-2009 Tobias Brunner
3 * Copyright (C) 2006 Daniel Roethlisberger
4 * Copyright (C) 2005-2006 Martin Willi
5 * Copyright (C) 2005 Jan Hutter
6 * Hochschule fuer Technik Rapperswil
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 */
18
19 /**
20 * @defgroup kernel_ipsec kernel_ipsec
21 * @{ @ingroup kernel
22 */
23
24 #ifndef KERNEL_IPSEC_H_
25 #define KERNEL_IPSEC_H_
26
27 typedef enum ipsec_mode_t ipsec_mode_t;
28 typedef enum policy_dir_t policy_dir_t;
29 typedef struct kernel_ipsec_t kernel_ipsec_t;
30
31 #include <utils/host.h>
32 #include <crypto/prf_plus.h>
33 #include <config/proposal.h>
34 #include <config/child_cfg.h>
35
36 /**
37 * Mode of a CHILD_SA.
38 */
39 enum ipsec_mode_t {
40 /** transport mode, no inner address */
41 MODE_TRANSPORT = 1,
42 /** tunnel mode, inner and outer addresses */
43 MODE_TUNNEL,
44 /** BEET mode, tunnel mode but fixed, bound inner addresses */
45 MODE_BEET,
46 };
47
48 /**
49 * enum names for ipsec_mode_t.
50 */
51 extern enum_name_t *ipsec_mode_names;
52
53 /**
54 * Direction of a policy. These are equal to those
55 * defined in xfrm.h, but we want to stay implementation
56 * neutral here.
57 */
58 enum policy_dir_t {
59 /** Policy for inbound traffic */
60 POLICY_IN = 0,
61 /** Policy for outbound traffic */
62 POLICY_OUT = 1,
63 /** Policy for forwarded traffic */
64 POLICY_FWD = 2,
65 };
66
67 /**
68 * enum names for policy_dir_t.
69 */
70 extern enum_name_t *policy_dir_names;
71
72 /**
73 * Interface to the ipsec subsystem of the kernel.
74 *
75 * The kernel ipsec interface handles the communication with the kernel
76 * for SA and policy management. It allows setup of these, and provides
77 * further the handling of kernel events.
78 * Policy information are cached in the interface. This is necessary to do
79 * reference counting. The Linux kernel does not allow the same policy
80 * installed twice, but we need this as CHILD_SA exist multiple times
81 * when rekeying. Thats why we do reference counting of policies.
82 */
83 struct kernel_ipsec_t {
84
85 /**
86 * Get a SPI from the kernel.
87 *
88 * @param src source address of SA
89 * @param dst destination address of SA
90 * @param protocol protocol for SA (ESP/AH)
91 * @param reqid unique ID for this SA
92 * @param spi allocated spi
93 * @return SUCCESS if operation completed
94 */
95 status_t (*get_spi)(kernel_ipsec_t *this, host_t *src, host_t *dst,
96 protocol_id_t protocol, u_int32_t reqid, u_int32_t *spi);
97
98 /**
99 * Get a Compression Parameter Index (CPI) from the kernel.
100 *
101 * @param src source address of SA
102 * @param dst destination address of SA
103 * @param reqid unique ID for the corresponding SA
104 * @param cpi allocated cpi
105 * @return SUCCESS if operation completed
106 */
107 status_t (*get_cpi)(kernel_ipsec_t *this, host_t *src, host_t *dst,
108 u_int32_t reqid, u_int16_t *cpi);
109
110 /**
111 * Add an SA to the SAD.
112 *
113 * add_sa() may update an already allocated
114 * SPI (via get_spi). In this case, the replace
115 * flag must be set.
116 * This function does install a single SA for a
117 * single protocol in one direction.
118 *
119 * @param src source address for this SA
120 * @param dst destination address for this SA
121 * @param spi SPI allocated by us or remote peer
122 * @param protocol protocol for this SA (ESP/AH)
123 * @param reqid unique ID for this SA
124 * @param lifetime lifetime_cfg_t for this SA
125 * @param enc_alg Algorithm to use for encryption (ESP only)
126 * @param enc_key key to use for encryption
127 * @param int_alg Algorithm to use for integrity protection
128 * @param int_key key to use for integrity protection
129 * @param mode mode of the SA (tunnel, transport)
130 * @param ipcomp IPComp transform to use
131 * @param cpi CPI for IPComp
132 * @param encap enable UDP encapsulation for NAT traversal
133 * @param inbound TRUE if this is an inbound SA
134 * @param src_ts traffic selector with BEET source address
135 * @param dst_ts traffic selector with BEET destination address
136 * @return SUCCESS if operation completed
137 */
138 status_t (*add_sa) (kernel_ipsec_t *this,
139 host_t *src, host_t *dst, u_int32_t spi,
140 protocol_id_t protocol, u_int32_t reqid,
141 lifetime_cfg_t *lifetime,
142 u_int16_t enc_alg, chunk_t enc_key,
143 u_int16_t int_alg, chunk_t int_key,
144 ipsec_mode_t mode, u_int16_t ipcomp, u_int16_t cpi,
145 bool encap, bool inbound,
146 traffic_selector_t *src_ts, traffic_selector_t *dst_ts);
147
148 /**
149 * Update the hosts on an installed SA.
150 *
151 * We cannot directly update the destination address as the kernel
152 * requires the spi, the protocol AND the destination address (and family)
153 * to identify SAs. Therefore if the destination address changed we
154 * create a new SA and delete the old one.
155 *
156 * @param spi SPI of the SA
157 * @param protocol protocol for this SA (ESP/AH)
158 * @param cpi CPI for IPComp, 0 if no IPComp is used
159 * @param src current source address
160 * @param dst current destination address
161 * @param new_src new source address
162 * @param new_dst new destination address
163 * @param encap current use of UDP encapsulation
164 * @param new_encap new use of UDP encapsulation
165 * @return SUCCESS if operation completed, NOT_SUPPORTED if
166 * the kernel interface can't update the SA
167 */
168 status_t (*update_sa)(kernel_ipsec_t *this,
169 u_int32_t spi, protocol_id_t protocol, u_int16_t cpi,
170 host_t *src, host_t *dst,
171 host_t *new_src, host_t *new_dst,
172 bool encap, bool new_encap);
173
174 /**
175 * Query the number of bytes processed by an SA from the SAD.
176 *
177 * @param src source address for this SA
178 * @param dst destination address for this SA
179 * @param spi SPI allocated by us or remote peer
180 * @param protocol protocol for this SA (ESP/AH)
181 * @param[out] bytes the number of bytes processed by SA
182 * @return SUCCESS if operation completed
183 */
184 status_t (*query_sa) (kernel_ipsec_t *this, host_t *src, host_t *dst,
185 u_int32_t spi, protocol_id_t protocol, u_int64_t *bytes);
186
187 /**
188 * Delete a previusly installed SA from the SAD.
189 *
190 * @param src source address for this SA
191 * @param dst destination address for this SA
192 * @param spi SPI allocated by us or remote peer
193 * @param protocol protocol for this SA (ESP/AH)
194 * @param cpi CPI for IPComp or 0
195 * @return SUCCESS if operation completed
196 */
197 status_t (*del_sa) (kernel_ipsec_t *this, host_t *src, host_t *dst,
198 u_int32_t spi, protocol_id_t protocol, u_int16_t cpi);
199
200 /**
201 * Add a policy to the SPD.
202 *
203 * A policy is always associated to an SA. Traffic which matches a
204 * policy is handled by the SA with the same reqid.
205 *
206 * @param src source address of SA
207 * @param dst dest address of SA
208 * @param src_ts traffic selector to match traffic source
209 * @param dst_ts traffic selector to match traffic dest
210 * @param direction direction of traffic, POLICY_IN, POLICY_OUT, POLICY_FWD
211 * @param spi SPI of SA
212 * @param protocol protocol to use to protect traffic (AH/ESP)
213 * @param reqid unique ID of an SA to use to enforce policy
214 * @param mode mode of SA (tunnel, transport)
215 * @param ipcomp the IPComp transform used
216 * @param cpi CPI for IPComp
217 * @param routed TRUE, if this policy is routed in the kernel
218 * @return SUCCESS if operation completed
219 */
220 status_t (*add_policy) (kernel_ipsec_t *this,
221 host_t *src, host_t *dst,
222 traffic_selector_t *src_ts,
223 traffic_selector_t *dst_ts,
224 policy_dir_t direction, u_int32_t spi,
225 protocol_id_t protocol, u_int32_t reqid,
226 ipsec_mode_t mode, u_int16_t ipcomp, u_int16_t cpi,
227 bool routed);
228
229 /**
230 * Query the use time of a policy.
231 *
232 * The use time of a policy is the time the policy was used for the last
233 * time. It is not the system time, but a monotonic timestamp as returned
234 * by time_monotonic.
235 *
236 * @param src_ts traffic selector to match traffic source
237 * @param dst_ts traffic selector to match traffic dest
238 * @param direction direction of traffic, POLICY_IN, POLICY_OUT, POLICY_FWD
239 * @param[out] use_time the monotonic timestamp of this SA's last use
240 * @return SUCCESS if operation completed
241 */
242 status_t (*query_policy) (kernel_ipsec_t *this,
243 traffic_selector_t *src_ts,
244 traffic_selector_t *dst_ts,
245 policy_dir_t direction, u_int32_t *use_time);
246
247 /**
248 * Remove a policy from the SPD.
249 *
250 * The kernel interface implements reference counting for policies.
251 * If the same policy is installed multiple times (in the case of rekeying),
252 * the reference counter is increased. del_policy() decreases the ref counter
253 * and removes the policy only when no more references are available.
254 *
255 * @param src_ts traffic selector to match traffic source
256 * @param dst_ts traffic selector to match traffic dest
257 * @param direction direction of traffic, POLICY_IN, POLICY_OUT, POLICY_FWD
258 * @param unrouted TRUE, if this policy is unrouted from the kernel
259 * @return SUCCESS if operation completed
260 */
261 status_t (*del_policy) (kernel_ipsec_t *this,
262 traffic_selector_t *src_ts,
263 traffic_selector_t *dst_ts,
264 policy_dir_t direction,
265 bool unrouted);
266
267 /**
268 * Install a bypass policy for the given socket.
269 *
270 * @param fd socket file descriptor to setup policy for
271 * @param family protocol family of the socket
272 * @return TRUE of policy set up successfully
273 */
274 bool (*bypass_socket)(kernel_ipsec_t *this, int fd, int family);
275
276 /**
277 * Destroy the implementation.
278 */
279 void (*destroy) (kernel_ipsec_t *this);
280 };
281
282 #endif /** KERNEL_IPSEC_H_ @}*/