207 |
mateuszvis |
1 |
/*!\file netinet6/ipsec.h
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
|
|
|
5 |
/* $FreeBSD: src/sys/netinet6/ipsec.h,v 1.9 2002/04/19 04:46:23 suz Exp $ */
|
|
|
6 |
/* $KAME: ipsec.h,v 1.53 2001/11/20 08:32:38 itojun Exp $ */
|
|
|
7 |
|
|
|
8 |
/*
|
|
|
9 |
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
|
|
10 |
* All rights reserved.
|
|
|
11 |
*
|
|
|
12 |
* Redistribution and use in source and binary forms, with or without
|
|
|
13 |
* modification, are permitted provided that the following conditions
|
|
|
14 |
* are met:
|
|
|
15 |
* 1. Redistributions of source code must retain the above copyright
|
|
|
16 |
* notice, this list of conditions and the following disclaimer.
|
|
|
17 |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
18 |
* notice, this list of conditions and the following disclaimer in the
|
|
|
19 |
* documentation and/or other materials provided with the distribution.
|
|
|
20 |
* 3. Neither the name of the project nor the names of its contributors
|
|
|
21 |
* may be used to endorse or promote products derived from this software
|
|
|
22 |
* without specific prior written permission.
|
|
|
23 |
*
|
|
|
24 |
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
|
|
25 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
26 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
27 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
|
|
28 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
29 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
30 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
31 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
32 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
33 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
34 |
* SUCH DAMAGE.
|
|
|
35 |
*/
|
|
|
36 |
|
|
|
37 |
/*
|
|
|
38 |
* IPsec controller part.
|
|
|
39 |
*/
|
|
|
40 |
|
|
|
41 |
#ifndef _NETINET6_IPSEC_H_
|
|
|
42 |
#define _NETINET6_IPSEC_H_
|
|
|
43 |
|
|
|
44 |
#if defined(_KERNEL) && !defined(_LKM) && !defined(KLD_MODULE)
|
|
|
45 |
#include "opt_inet.h"
|
|
|
46 |
#include "opt_ipsec.h"
|
|
|
47 |
#endif
|
|
|
48 |
|
|
|
49 |
#include <net/pfkeyv2.h>
|
|
|
50 |
#include <netkey/keydb.h>
|
|
|
51 |
|
|
|
52 |
#ifdef _KERNEL
|
|
|
53 |
|
|
|
54 |
/*
|
|
|
55 |
* Security Policy Index
|
|
|
56 |
* Ensure that both address families in the "src" and "dst" are same.
|
|
|
57 |
* When the value of the ul_proto is ICMPv6, the port field in "src"
|
|
|
58 |
* specifies ICMPv6 type, and the port field in "dst" specifies ICMPv6 code.
|
|
|
59 |
*/
|
|
|
60 |
struct secpolicyindex {
|
|
|
61 |
u_int8_t dir; /* direction of packet flow, see blow */
|
|
|
62 |
struct sockaddr_storage src; /* IP src address for SP */
|
|
|
63 |
struct sockaddr_storage dst; /* IP dst address for SP */
|
|
|
64 |
u_int8_t prefs; /* prefix length in bits for src */
|
|
|
65 |
u_int8_t prefd; /* prefix length in bits for dst */
|
|
|
66 |
u_int16_t ul_proto; /* upper layer Protocol */
|
|
|
67 |
#ifdef notyet
|
|
|
68 |
uid_t uids;
|
|
|
69 |
uid_t uidd;
|
|
|
70 |
gid_t gids;
|
|
|
71 |
gid_t gidd;
|
|
|
72 |
#endif
|
|
|
73 |
};
|
|
|
74 |
|
|
|
75 |
/* Security Policy Data Base */
|
|
|
76 |
struct secpolicy {
|
|
|
77 |
LIST_ENTRY(secpolicy) chain;
|
|
|
78 |
|
|
|
79 |
int refcnt; /* reference count */
|
|
|
80 |
struct secpolicyindex spidx; /* selector */
|
|
|
81 |
u_int32_t id; /* It's unique number on the system. */
|
|
|
82 |
u_int state; /* 0: dead, others: alive */
|
|
|
83 |
#define IPSEC_SPSTATE_DEAD 0
|
|
|
84 |
#define IPSEC_SPSTATE_ALIVE 1
|
|
|
85 |
|
|
|
86 |
u_int policy; /* DISCARD, NONE or IPSEC, see keyv2.h */
|
|
|
87 |
struct ipsecrequest *req;
|
|
|
88 |
/* pointer to the ipsec request tree, */
|
|
|
89 |
/* if policy == IPSEC else this value == NULL.*/
|
|
|
90 |
|
|
|
91 |
/*
|
|
|
92 |
* lifetime handler.
|
|
|
93 |
* the policy can be used without limitiation if both lifetime and
|
|
|
94 |
* validtime are zero.
|
|
|
95 |
* "lifetime" is passed by sadb_lifetime.sadb_lifetime_addtime.
|
|
|
96 |
* "validtime" is passed by sadb_lifetime.sadb_lifetime_usetime.
|
|
|
97 |
*/
|
|
|
98 |
long created; /* time created the policy */
|
|
|
99 |
long lastused; /* updated every when kernel sends a packet */
|
|
|
100 |
long lifetime; /* duration of the lifetime of this policy */
|
|
|
101 |
long validtime; /* duration this policy is valid without use */
|
|
|
102 |
};
|
|
|
103 |
|
|
|
104 |
/* Request for IPsec */
|
|
|
105 |
struct ipsecrequest {
|
|
|
106 |
struct ipsecrequest *next;
|
|
|
107 |
/* pointer to next structure */
|
|
|
108 |
/* If NULL, it means the end of chain. */
|
|
|
109 |
struct secasindex saidx;/* hint for search proper SA */
|
|
|
110 |
/* if __ss_len == 0 then no address specified.*/
|
|
|
111 |
u_int level; /* IPsec level defined below. */
|
|
|
112 |
|
|
|
113 |
struct secasvar *sav; /* place holder of SA for use */
|
|
|
114 |
struct secpolicy *sp; /* back pointer to SP */
|
|
|
115 |
};
|
|
|
116 |
|
|
|
117 |
/* security policy in PCB */
|
|
|
118 |
struct inpcbpolicy {
|
|
|
119 |
struct secpolicy *sp_in;
|
|
|
120 |
struct secpolicy *sp_out;
|
|
|
121 |
int priv; /* privileged socket ? */
|
|
|
122 |
};
|
|
|
123 |
|
|
|
124 |
/* SP acquiring list table. */
|
|
|
125 |
struct secspacq {
|
|
|
126 |
LIST_ENTRY(secspacq) chain;
|
|
|
127 |
|
|
|
128 |
struct secpolicyindex spidx;
|
|
|
129 |
|
|
|
130 |
long created; /* for lifetime */
|
|
|
131 |
int count; /* for lifetime */
|
|
|
132 |
/* XXX: here is mbuf place holder to be sent ? */
|
|
|
133 |
};
|
|
|
134 |
#endif /* _KERNEL */
|
|
|
135 |
|
|
|
136 |
/* according to IANA assignment, port 0x0000 and proto 0xff are reserved. */
|
|
|
137 |
#define IPSEC_PORT_ANY 0
|
|
|
138 |
#define IPSEC_ULPROTO_ANY 255
|
|
|
139 |
#define IPSEC_PROTO_ANY 255
|
|
|
140 |
|
|
|
141 |
/* mode of security protocol */
|
|
|
142 |
/* NOTE: DON'T use IPSEC_MODE_ANY at SPD. It's only use in SAD */
|
|
|
143 |
#define IPSEC_MODE_ANY 0 /* i.e. wildcard. */
|
|
|
144 |
#define IPSEC_MODE_TRANSPORT 1
|
|
|
145 |
#define IPSEC_MODE_TUNNEL 2
|
|
|
146 |
|
|
|
147 |
/*
|
|
|
148 |
* Direction of security policy.
|
|
|
149 |
* NOTE: Since INVALID is used just as flag.
|
|
|
150 |
* The other are used for loop counter too.
|
|
|
151 |
*/
|
|
|
152 |
#define IPSEC_DIR_ANY 0
|
|
|
153 |
#define IPSEC_DIR_INBOUND 1
|
|
|
154 |
#define IPSEC_DIR_OUTBOUND 2
|
|
|
155 |
#define IPSEC_DIR_MAX 3
|
|
|
156 |
#define IPSEC_DIR_INVALID 4
|
|
|
157 |
|
|
|
158 |
/* Policy level */
|
|
|
159 |
/*
|
|
|
160 |
* IPSEC, ENTRUST and BYPASS are allowed for setsockopt() in PCB,
|
|
|
161 |
* DISCARD, IPSEC and NONE are allowed for setkey() in SPD.
|
|
|
162 |
* DISCARD and NONE are allowed for system default.
|
|
|
163 |
*/
|
|
|
164 |
#define IPSEC_POLICY_DISCARD 0 /* discarding packet */
|
|
|
165 |
#define IPSEC_POLICY_NONE 1 /* through IPsec engine */
|
|
|
166 |
#define IPSEC_POLICY_IPSEC 2 /* do IPsec */
|
|
|
167 |
#define IPSEC_POLICY_ENTRUST 3 /* consulting SPD if present. */
|
|
|
168 |
#define IPSEC_POLICY_BYPASS 4 /* only for privileged socket. */
|
|
|
169 |
|
|
|
170 |
/* Security protocol level */
|
|
|
171 |
#define IPSEC_LEVEL_DEFAULT 0 /* reference to system default */
|
|
|
172 |
#define IPSEC_LEVEL_USE 1 /* use SA if present. */
|
|
|
173 |
#define IPSEC_LEVEL_REQUIRE 2 /* require SA. */
|
|
|
174 |
#define IPSEC_LEVEL_UNIQUE 3 /* unique SA. */
|
|
|
175 |
|
|
|
176 |
#define IPSEC_MANUAL_REQID_MAX 0x3fff
|
|
|
177 |
/*
|
|
|
178 |
* if security policy level == unique, this id
|
|
|
179 |
* indicate to a relative SA for use, else is
|
|
|
180 |
* zero.
|
|
|
181 |
* 1 - 0x3fff are reserved for manual keying.
|
|
|
182 |
* 0 are reserved for above reason. Others is
|
|
|
183 |
* for kernel use.
|
|
|
184 |
* Note that this id doesn't identify SA
|
|
|
185 |
* by only itself.
|
|
|
186 |
*/
|
|
|
187 |
#define IPSEC_REPLAYWSIZE 32
|
|
|
188 |
|
|
|
189 |
/* statistics for ipsec processing */
|
|
|
190 |
struct ipsecstat {
|
|
|
191 |
u_quad_t in_success; /* succeeded inbound process */
|
|
|
192 |
u_quad_t in_polvio;
|
|
|
193 |
/* security policy violation for inbound process */
|
|
|
194 |
u_quad_t in_nosa; /* inbound SA is unavailable */
|
|
|
195 |
u_quad_t in_inval; /* inbound processing failed due to EINVAL */
|
|
|
196 |
u_quad_t in_nomem; /* inbound processing failed due to ENOBUFS */
|
|
|
197 |
u_quad_t in_badspi; /* failed getting a SPI */
|
|
|
198 |
u_quad_t in_ahreplay; /* AH replay check failed */
|
|
|
199 |
u_quad_t in_espreplay; /* ESP replay check failed */
|
|
|
200 |
u_quad_t in_ahauthsucc; /* AH authentication success */
|
|
|
201 |
u_quad_t in_ahauthfail; /* AH authentication failure */
|
|
|
202 |
u_quad_t in_espauthsucc; /* ESP authentication success */
|
|
|
203 |
u_quad_t in_espauthfail; /* ESP authentication failure */
|
|
|
204 |
u_quad_t in_esphist[256];
|
|
|
205 |
u_quad_t in_ahhist[256];
|
|
|
206 |
u_quad_t in_comphist[256];
|
|
|
207 |
u_quad_t out_success; /* succeeded outbound process */
|
|
|
208 |
u_quad_t out_polvio;
|
|
|
209 |
/* security policy violation for outbound process */
|
|
|
210 |
u_quad_t out_nosa; /* outbound SA is unavailable */
|
|
|
211 |
u_quad_t out_inval; /* outbound process failed due to EINVAL */
|
|
|
212 |
u_quad_t out_nomem; /* inbound processing failed due to ENOBUFS */
|
|
|
213 |
u_quad_t out_noroute; /* there is no route */
|
|
|
214 |
u_quad_t out_esphist[256];
|
|
|
215 |
u_quad_t out_ahhist[256];
|
|
|
216 |
u_quad_t out_comphist[256];
|
|
|
217 |
};
|
|
|
218 |
|
|
|
219 |
/*
|
|
|
220 |
* Definitions for IPsec & Key sysctl operations.
|
|
|
221 |
*/
|
|
|
222 |
/*
|
|
|
223 |
* Names for IPsec & Key sysctl objects
|
|
|
224 |
*/
|
|
|
225 |
#define IPSECCTL_STATS 1 /* stats */
|
|
|
226 |
#define IPSECCTL_DEF_POLICY 2
|
|
|
227 |
#define IPSECCTL_DEF_ESP_TRANSLEV 3 /* int; ESP transport mode */
|
|
|
228 |
#define IPSECCTL_DEF_ESP_NETLEV 4 /* int; ESP tunnel mode */
|
|
|
229 |
#define IPSECCTL_DEF_AH_TRANSLEV 5 /* int; AH transport mode */
|
|
|
230 |
#define IPSECCTL_DEF_AH_NETLEV 6 /* int; AH tunnel mode */
|
|
|
231 |
#if 0 /* obsolete, do not reuse */
|
|
|
232 |
#define IPSECCTL_INBOUND_CALL_IKE 7
|
|
|
233 |
#endif
|
|
|
234 |
#define IPSECCTL_AH_CLEARTOS 8
|
|
|
235 |
#define IPSECCTL_AH_OFFSETMASK 9
|
|
|
236 |
#define IPSECCTL_DFBIT 10
|
|
|
237 |
#define IPSECCTL_ECN 11
|
|
|
238 |
#define IPSECCTL_DEBUG 12
|
|
|
239 |
#define IPSECCTL_ESP_RANDPAD 13
|
|
|
240 |
#define IPSECCTL_MAXID 14
|
|
|
241 |
|
|
|
242 |
#define IPSECCTL_NAMES { \
|
|
|
243 |
{ 0, 0 }, \
|
|
|
244 |
{ 0, 0 }, \
|
|
|
245 |
{ "def_policy", CTLTYPE_INT }, \
|
|
|
246 |
{ "esp_trans_deflev", CTLTYPE_INT }, \
|
|
|
247 |
{ "esp_net_deflev", CTLTYPE_INT }, \
|
|
|
248 |
{ "ah_trans_deflev", CTLTYPE_INT }, \
|
|
|
249 |
{ "ah_net_deflev", CTLTYPE_INT }, \
|
|
|
250 |
{ 0, 0 }, \
|
|
|
251 |
{ "ah_cleartos", CTLTYPE_INT }, \
|
|
|
252 |
{ "ah_offsetmask", CTLTYPE_INT }, \
|
|
|
253 |
{ "dfbit", CTLTYPE_INT }, \
|
|
|
254 |
{ "ecn", CTLTYPE_INT }, \
|
|
|
255 |
{ "debug", CTLTYPE_INT }, \
|
|
|
256 |
{ "esp_randpad", CTLTYPE_INT }, \
|
|
|
257 |
}
|
|
|
258 |
|
|
|
259 |
#define IPSEC6CTL_NAMES { \
|
|
|
260 |
{ 0, 0 }, \
|
|
|
261 |
{ 0, 0 }, \
|
|
|
262 |
{ "def_policy", CTLTYPE_INT }, \
|
|
|
263 |
{ "esp_trans_deflev", CTLTYPE_INT }, \
|
|
|
264 |
{ "esp_net_deflev", CTLTYPE_INT }, \
|
|
|
265 |
{ "ah_trans_deflev", CTLTYPE_INT }, \
|
|
|
266 |
{ "ah_net_deflev", CTLTYPE_INT }, \
|
|
|
267 |
{ 0, 0 }, \
|
|
|
268 |
{ 0, 0 }, \
|
|
|
269 |
{ 0, 0 }, \
|
|
|
270 |
{ 0, 0 }, \
|
|
|
271 |
{ "ecn", CTLTYPE_INT }, \
|
|
|
272 |
{ "debug", CTLTYPE_INT }, \
|
|
|
273 |
{ "esp_randpad", CTLTYPE_INT }, \
|
|
|
274 |
}
|
|
|
275 |
|
|
|
276 |
#ifdef _KERNEL
|
|
|
277 |
struct ipsec_output_state {
|
|
|
278 |
struct mbuf *m;
|
|
|
279 |
struct route *ro;
|
|
|
280 |
struct sockaddr *dst;
|
|
|
281 |
};
|
|
|
282 |
|
|
|
283 |
struct ipsec_history {
|
|
|
284 |
int ih_proto;
|
|
|
285 |
u_int32_t ih_spi;
|
|
|
286 |
};
|
|
|
287 |
|
|
|
288 |
extern int ipsec_debug;
|
|
|
289 |
|
|
|
290 |
extern struct ipsecstat ipsecstat;
|
|
|
291 |
extern struct secpolicy ip4_def_policy;
|
|
|
292 |
extern int ip4_esp_trans_deflev;
|
|
|
293 |
extern int ip4_esp_net_deflev;
|
|
|
294 |
extern int ip4_ah_trans_deflev;
|
|
|
295 |
extern int ip4_ah_net_deflev;
|
|
|
296 |
extern int ip4_ah_cleartos;
|
|
|
297 |
extern int ip4_ah_offsetmask;
|
|
|
298 |
extern int ip4_ipsec_dfbit;
|
|
|
299 |
extern int ip4_ipsec_ecn;
|
|
|
300 |
extern int ip4_esp_randpad;
|
|
|
301 |
|
|
|
302 |
#define ipseclog(x) do { if (ipsec_debug) log x; } while (0)
|
|
|
303 |
|
|
|
304 |
extern struct secpolicy *ipsec4_getpolicybysock
|
|
|
305 |
__P((struct mbuf *, u_int, struct socket *, int *));
|
|
|
306 |
extern struct secpolicy *ipsec4_getpolicybyaddr
|
|
|
307 |
__P((struct mbuf *, u_int, int, int *));
|
|
|
308 |
|
|
|
309 |
struct inpcb;
|
|
|
310 |
extern int ipsec_init_policy __P((struct socket *so, struct inpcbpolicy **));
|
|
|
311 |
extern int ipsec_copy_policy
|
|
|
312 |
__P((struct inpcbpolicy *, struct inpcbpolicy *));
|
|
|
313 |
extern u_int ipsec_get_reqlevel __P((struct ipsecrequest *));
|
|
|
314 |
|
|
|
315 |
extern int ipsec4_set_policy __P((struct inpcb *inp, int optname,
|
|
|
316 |
caddr_t request, size_t len, int priv));
|
|
|
317 |
extern int ipsec4_get_policy __P((struct inpcb *inpcb, caddr_t request,
|
|
|
318 |
size_t len, struct mbuf **mp));
|
|
|
319 |
extern int ipsec4_delete_pcbpolicy __P((struct inpcb *));
|
|
|
320 |
extern int ipsec4_in_reject_so __P((struct mbuf *, struct socket *));
|
|
|
321 |
extern int ipsec4_in_reject __P((struct mbuf *, struct inpcb *));
|
|
|
322 |
|
|
|
323 |
struct secas;
|
|
|
324 |
struct tcpcb;
|
|
|
325 |
extern int ipsec_chkreplay __P((u_int32_t, struct secasvar *));
|
|
|
326 |
extern int ipsec_updatereplay __P((u_int32_t, struct secasvar *));
|
|
|
327 |
|
|
|
328 |
extern size_t ipsec4_hdrsiz __P((struct mbuf *, u_int, struct inpcb *));
|
|
|
329 |
extern size_t ipsec_hdrsiz_tcp __P((struct tcpcb *));
|
|
|
330 |
|
|
|
331 |
struct ip;
|
|
|
332 |
extern const char *ipsec4_logpacketstr __P((struct ip *, u_int32_t));
|
|
|
333 |
extern const char *ipsec_logsastr __P((struct secasvar *));
|
|
|
334 |
|
|
|
335 |
extern void ipsec_dumpmbuf __P((struct mbuf *));
|
|
|
336 |
|
|
|
337 |
extern int ipsec4_output __P((struct ipsec_output_state *, struct secpolicy *,
|
|
|
338 |
int));
|
|
|
339 |
extern int ipsec4_tunnel_validate __P((struct mbuf *, int, u_int,
|
|
|
340 |
struct secasvar *));
|
|
|
341 |
extern struct mbuf *ipsec_copypkt __P((struct mbuf *));
|
|
|
342 |
extern void ipsec_delaux __P((struct mbuf *));
|
|
|
343 |
extern int ipsec_setsocket __P((struct mbuf *, struct socket *));
|
|
|
344 |
extern struct socket *ipsec_getsocket __P((struct mbuf *));
|
|
|
345 |
extern int ipsec_addhist __P((struct mbuf *, int, u_int32_t));
|
|
|
346 |
extern struct ipsec_history *ipsec_gethist __P((struct mbuf *, int *));
|
|
|
347 |
extern void ipsec_clearhist __P((struct mbuf *));
|
|
|
348 |
#endif /* _KERNEL */
|
|
|
349 |
|
|
|
350 |
#ifndef _KERNEL
|
|
|
351 |
extern caddr_t ipsec_set_policy __P((char *, int));
|
|
|
352 |
extern int ipsec_get_policylen __P((caddr_t));
|
|
|
353 |
extern char *ipsec_dump_policy __P((caddr_t, char *));
|
|
|
354 |
|
|
|
355 |
extern const char *ipsec_strerror __P((void));
|
|
|
356 |
#endif /* !_KERNEL */
|
|
|
357 |
|
|
|
358 |
#endif /* _NETINET6_IPSEC_H_ */
|