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