]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/pfkeyv2.h
xnu-517.7.7.tar.gz
[apple/xnu.git] / bsd / net / pfkeyv2.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /* $KAME: pfkeyv2.h,v 1.10 2000/03/22 07:04:20 sakane Exp $ */
23
24 /*
25 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
26 * All rights reserved.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
30 * are met:
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. Neither the name of the project nor the names of its contributors
37 * may be used to endorse or promote products derived from this software
38 * without specific prior written permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 * SUCH DAMAGE.
51 */
52
53 /*
54 * This file has been derived rfc 2367,
55 * And added some flags of SADB_KEY_FLAGS_ as SADB_X_EXT_.
56 * sakane@ydc.co.jp
57 */
58
59 #ifndef _NET_PFKEYV2_H_
60 #define _NET_PFKEYV2_H_
61 #include <sys/appleapiopts.h>
62
63 /*
64 This file defines structures and symbols for the PF_KEY Version 2
65 key management interface. It was written at the U.S. Naval Research
66 Laboratory. This file is in the public domain. The authors ask that
67 you leave this credit intact on any copies of this file.
68 */
69 #ifndef __PFKEY_V2_H
70 #define __PFKEY_V2_H 1
71
72 #define PF_KEY_V2 2
73 #define PFKEYV2_REVISION 199806L
74
75 #define SADB_RESERVED 0
76 #define SADB_GETSPI 1
77 #define SADB_UPDATE 2
78 #define SADB_ADD 3
79 #define SADB_DELETE 4
80 #define SADB_GET 5
81 #define SADB_ACQUIRE 6
82 #define SADB_REGISTER 7
83 #define SADB_EXPIRE 8
84 #define SADB_FLUSH 9
85 #define SADB_DUMP 10
86 #define SADB_X_PROMISC 11
87 #define SADB_X_PCHANGE 12
88
89 #define SADB_X_SPDUPDATE 13
90 #define SADB_X_SPDADD 14
91 #define SADB_X_SPDDELETE 15 /* by policy index */
92 #define SADB_X_SPDGET 16
93 #define SADB_X_SPDACQUIRE 17
94 #define SADB_X_SPDDUMP 18
95 #define SADB_X_SPDFLUSH 19
96 #define SADB_X_SPDSETIDX 20
97 #define SADB_X_SPDEXPIRE 21
98 #define SADB_X_SPDDELETE2 22 /* by policy id */
99 #define SADB_MAX 22
100
101 struct sadb_msg {
102 u_int8_t sadb_msg_version;
103 u_int8_t sadb_msg_type;
104 u_int8_t sadb_msg_errno;
105 u_int8_t sadb_msg_satype;
106 u_int16_t sadb_msg_len;
107 u_int16_t sadb_msg_reserved;
108 u_int32_t sadb_msg_seq;
109 u_int32_t sadb_msg_pid;
110 };
111
112 struct sadb_ext {
113 u_int16_t sadb_ext_len;
114 u_int16_t sadb_ext_type;
115 };
116
117 struct sadb_sa {
118 u_int16_t sadb_sa_len;
119 u_int16_t sadb_sa_exttype;
120 u_int32_t sadb_sa_spi;
121 u_int8_t sadb_sa_replay;
122 u_int8_t sadb_sa_state;
123 u_int8_t sadb_sa_auth;
124 u_int8_t sadb_sa_encrypt;
125 u_int32_t sadb_sa_flags;
126 };
127
128 #ifdef __APPLE_API_PRIVATE
129 struct sadb_sa_2 {
130 struct sadb_sa sa;
131 u_int16_t sadb_sa_natt_port;
132 u_int16_t sadb_reserved0;
133 u_int32_t sadb_reserved1;
134 };
135 #endif
136
137 struct sadb_lifetime {
138 u_int16_t sadb_lifetime_len;
139 u_int16_t sadb_lifetime_exttype;
140 u_int32_t sadb_lifetime_allocations;
141 u_int64_t sadb_lifetime_bytes;
142 u_int64_t sadb_lifetime_addtime;
143 u_int64_t sadb_lifetime_usetime;
144 };
145
146 struct sadb_address {
147 u_int16_t sadb_address_len;
148 u_int16_t sadb_address_exttype;
149 u_int8_t sadb_address_proto;
150 u_int8_t sadb_address_prefixlen;
151 u_int16_t sadb_address_reserved;
152 };
153
154 struct sadb_key {
155 u_int16_t sadb_key_len;
156 u_int16_t sadb_key_exttype;
157 u_int16_t sadb_key_bits;
158 u_int16_t sadb_key_reserved;
159 };
160
161 struct sadb_ident {
162 u_int16_t sadb_ident_len;
163 u_int16_t sadb_ident_exttype;
164 u_int16_t sadb_ident_type;
165 u_int16_t sadb_ident_reserved;
166 u_int64_t sadb_ident_id;
167 };
168
169 struct sadb_sens {
170 u_int16_t sadb_sens_len;
171 u_int16_t sadb_sens_exttype;
172 u_int32_t sadb_sens_dpd;
173 u_int8_t sadb_sens_sens_level;
174 u_int8_t sadb_sens_sens_len;
175 u_int8_t sadb_sens_integ_level;
176 u_int8_t sadb_sens_integ_len;
177 u_int32_t sadb_sens_reserved;
178 };
179
180 struct sadb_prop {
181 u_int16_t sadb_prop_len;
182 u_int16_t sadb_prop_exttype;
183 u_int8_t sadb_prop_replay;
184 u_int8_t sadb_prop_reserved[3];
185 };
186
187 struct sadb_comb {
188 u_int8_t sadb_comb_auth;
189 u_int8_t sadb_comb_encrypt;
190 u_int16_t sadb_comb_flags;
191 u_int16_t sadb_comb_auth_minbits;
192 u_int16_t sadb_comb_auth_maxbits;
193 u_int16_t sadb_comb_encrypt_minbits;
194 u_int16_t sadb_comb_encrypt_maxbits;
195 u_int32_t sadb_comb_reserved;
196 u_int32_t sadb_comb_soft_allocations;
197 u_int32_t sadb_comb_hard_allocations;
198 u_int64_t sadb_comb_soft_bytes;
199 u_int64_t sadb_comb_hard_bytes;
200 u_int64_t sadb_comb_soft_addtime;
201 u_int64_t sadb_comb_hard_addtime;
202 u_int64_t sadb_comb_soft_usetime;
203 u_int64_t sadb_comb_hard_usetime;
204 };
205
206 struct sadb_supported {
207 u_int16_t sadb_supported_len;
208 u_int16_t sadb_supported_exttype;
209 u_int32_t sadb_supported_reserved;
210 };
211
212 struct sadb_alg {
213 u_int8_t sadb_alg_id;
214 u_int8_t sadb_alg_ivlen;
215 u_int16_t sadb_alg_minbits;
216 u_int16_t sadb_alg_maxbits;
217 u_int16_t sadb_alg_reserved;
218 };
219
220 struct sadb_spirange {
221 u_int16_t sadb_spirange_len;
222 u_int16_t sadb_spirange_exttype;
223 u_int32_t sadb_spirange_min;
224 u_int32_t sadb_spirange_max;
225 u_int32_t sadb_spirange_reserved;
226 };
227
228 struct sadb_x_kmprivate {
229 u_int16_t sadb_x_kmprivate_len;
230 u_int16_t sadb_x_kmprivate_exttype;
231 u_int32_t sadb_x_kmprivate_reserved;
232 };
233
234 /*
235 * XXX Additional SA Extension.
236 * mode: tunnel or transport
237 * reqid: to make SA unique nevertheless the address pair of SA are same.
238 * Mainly it's for VPN.
239 */
240 struct sadb_x_sa2 {
241 u_int16_t sadb_x_sa2_len;
242 u_int16_t sadb_x_sa2_exttype;
243 u_int8_t sadb_x_sa2_mode;
244 u_int8_t sadb_x_sa2_reserved1;
245 u_int16_t sadb_x_sa2_reserved2;
246 u_int32_t sadb_x_sa2_sequence;
247 u_int32_t sadb_x_sa2_reqid;
248 };
249
250 /* XXX Policy Extension */
251 /* sizeof(struct sadb_x_policy) == 16 */
252 struct sadb_x_policy {
253 u_int16_t sadb_x_policy_len;
254 u_int16_t sadb_x_policy_exttype;
255 u_int16_t sadb_x_policy_type; /* See policy type of ipsec.h */
256 u_int8_t sadb_x_policy_dir; /* direction, see ipsec.h */
257 u_int8_t sadb_x_policy_reserved;
258 u_int32_t sadb_x_policy_id;
259 u_int32_t sadb_x_policy_reserved2;
260 };
261 /*
262 * When policy_type == IPSEC, it is followed by some of
263 * the ipsec policy request.
264 * [total length of ipsec policy requests]
265 * = (sadb_x_policy_len * sizeof(uint64_t) - sizeof(struct sadb_x_policy))
266 */
267
268 /* XXX IPsec Policy Request Extension */
269 /*
270 * This structure is aligned 8 bytes.
271 */
272 struct sadb_x_ipsecrequest {
273 u_int16_t sadb_x_ipsecrequest_len; /* structure length aligned to 8 bytes.
274 * This value is true length of bytes.
275 * Not in units of 64 bits. */
276 u_int16_t sadb_x_ipsecrequest_proto; /* See ipsec.h */
277 u_int8_t sadb_x_ipsecrequest_mode; /* See IPSEC_MODE_XX in ipsec.h. */
278 u_int8_t sadb_x_ipsecrequest_level; /* See IPSEC_LEVEL_XX in ipsec.h */
279 u_int16_t sadb_x_ipsecrequest_reqid; /* See ipsec.h */
280
281 /*
282 * followed by source IP address of SA, and immediately followed by
283 * destination IP address of SA. These encoded into two of sockaddr
284 * structure without any padding. Must set each sa_len exactly.
285 * Each of length of the sockaddr structure are not aligned to 64bits,
286 * but sum of x_request and addresses is aligned to 64bits.
287 */
288 };
289
290 #define SADB_EXT_RESERVED 0
291 #define SADB_EXT_SA 1
292 #define SADB_EXT_LIFETIME_CURRENT 2
293 #define SADB_EXT_LIFETIME_HARD 3
294 #define SADB_EXT_LIFETIME_SOFT 4
295 #define SADB_EXT_ADDRESS_SRC 5
296 #define SADB_EXT_ADDRESS_DST 6
297 #define SADB_EXT_ADDRESS_PROXY 7
298 #define SADB_EXT_KEY_AUTH 8
299 #define SADB_EXT_KEY_ENCRYPT 9
300 #define SADB_EXT_IDENTITY_SRC 10
301 #define SADB_EXT_IDENTITY_DST 11
302 #define SADB_EXT_SENSITIVITY 12
303 #define SADB_EXT_PROPOSAL 13
304 #define SADB_EXT_SUPPORTED_AUTH 14
305 #define SADB_EXT_SUPPORTED_ENCRYPT 15
306 #define SADB_EXT_SPIRANGE 16
307 #define SADB_X_EXT_KMPRIVATE 17
308 #define SADB_X_EXT_POLICY 18
309 #define SADB_X_EXT_SA2 19
310 #define SADB_EXT_MAX 19
311
312 #define SADB_SATYPE_UNSPEC 0
313 #define SADB_SATYPE_AH 2
314 #define SADB_SATYPE_ESP 3
315 #define SADB_SATYPE_RSVP 5
316 #define SADB_SATYPE_OSPFV2 6
317 #define SADB_SATYPE_RIPV2 7
318 #define SADB_SATYPE_MIP 8
319 #define SADB_X_SATYPE_IPCOMP 9
320 #define SADB_X_SATYPE_POLICY 10
321 #define SADB_SATYPE_MAX 11
322
323 #define SADB_SASTATE_LARVAL 0
324 #define SADB_SASTATE_MATURE 1
325 #define SADB_SASTATE_DYING 2
326 #define SADB_SASTATE_DEAD 3
327 #define SADB_SASTATE_MAX 3
328
329 #define SADB_SAFLAGS_PFS 1
330
331 /* RFC2367 numbers - meets RFC2407 */
332 #define SADB_AALG_NONE 0
333 #define SADB_AALG_MD5HMAC 1 /*2*/
334 #define SADB_AALG_SHA1HMAC 2 /*3*/
335 #define SADB_AALG_MAX 8
336 /* private allocations - based on RFC2407/IANA assignment */
337 #define SADB_X_AALG_SHA2_256 6 /*5*/
338 #define SADB_X_AALG_SHA2_384 7 /*6*/
339 #define SADB_X_AALG_SHA2_512 8 /*7*/
340 /* private allocations should use 249-255 (RFC2407) */
341 #define SADB_X_AALG_MD5 3 /*249*/ /* Keyed MD5 */
342 #define SADB_X_AALG_SHA 4 /*250*/ /* Keyed SHA */
343 #define SADB_X_AALG_NULL 5 /*251*/ /* null authentication */
344
345 /* RFC2367 numbers - meets RFC2407 */
346 #define SADB_EALG_NONE 0
347 #define SADB_EALG_DESCBC 1 /*2*/
348 #define SADB_EALG_3DESCBC 2 /*3*/
349 #define SADB_EALG_NULL 3 /*11*/
350 #define SADB_EALG_MAX 12
351 /* private allocations - based on RFC2407/IANA assignment */
352 #define SADB_X_EALG_CAST128CBC 5 /*6*/
353 #define SADB_X_EALG_BLOWFISHCBC 4 /*7*/
354 #define SADB_X_EALG_RIJNDAELCBC 12
355 #define SADB_X_EALG_AES 12
356 /* private allocations should use 249-255 (RFC2407) */
357
358 #if 1 /*nonstandard */
359 #define SADB_X_CALG_NONE 0
360 #define SADB_X_CALG_OUI 1
361 #define SADB_X_CALG_DEFLATE 2
362 #define SADB_X_CALG_LZS 3
363 #define SADB_X_CALG_MAX 4
364 #endif
365
366 #define SADB_IDENTTYPE_RESERVED 0
367 #define SADB_IDENTTYPE_PREFIX 1
368 #define SADB_IDENTTYPE_FQDN 2
369 #define SADB_IDENTTYPE_USERFQDN 3
370 #define SADB_X_IDENTTYPE_ADDR 4
371 #define SADB_IDENTTYPE_MAX 4
372
373 /* `flags' in sadb_sa structure holds followings */
374 #define SADB_X_EXT_NONE 0x0000 /* i.e. new format. */
375 #define SADB_X_EXT_OLD 0x0001 /* old format. */
376 #ifdef __APPLE_API_PRIVATE
377 #define SADB_X_EXT_NATT 0x0002 /* Use UDP encapsulation to traverse NAT */
378 #define SADB_X_EXT_NATT_KEEPALIVE 0x0004 /* Local node is behind NAT, send keepalives */
379 /* Should only be set for outbound SAs */
380 #endif
381
382 #define SADB_X_EXT_IV4B 0x0010 /* IV length of 4 bytes in use */
383 #define SADB_X_EXT_DERIV 0x0020 /* DES derived */
384 #define SADB_X_EXT_CYCSEQ 0x0040 /* allowing to cyclic sequence. */
385
386 /* three of followings are exclusive flags each them */
387 #define SADB_X_EXT_PSEQ 0x0000 /* sequencial padding for ESP */
388 #define SADB_X_EXT_PRAND 0x0100 /* random padding for ESP */
389 #define SADB_X_EXT_PZERO 0x0200 /* zero padding for ESP */
390 #define SADB_X_EXT_PMASK 0x0300 /* mask for padding flag */
391
392 #if 1
393 #define SADB_X_EXT_RAWCPI 0x0080 /* use well known CPI (IPComp) */
394 #endif
395
396 #define SADB_KEY_FLAGS_MAX 0x0fff
397
398 /* SPI size for PF_KEYv2 */
399 #define PFKEY_SPI_SIZE sizeof(u_int32_t)
400
401 /* Identifier for menber of lifetime structure */
402 #define SADB_X_LIFETIME_ALLOCATIONS 0
403 #define SADB_X_LIFETIME_BYTES 1
404 #define SADB_X_LIFETIME_ADDTIME 2
405 #define SADB_X_LIFETIME_USETIME 3
406
407 /* The rate for SOFT lifetime against HARD one. */
408 #define PFKEY_SOFT_LIFETIME_RATE 80
409
410 /* Utilities */
411 #define PFKEY_ALIGN8(a) (1 + (((a) - 1) | (8 - 1)))
412 #define PFKEY_EXTLEN(msg) \
413 PFKEY_UNUNIT64(((struct sadb_ext *)(msg))->sadb_ext_len)
414 #define PFKEY_ADDR_PREFIX(ext) \
415 (((struct sadb_address *)(ext))->sadb_address_prefixlen)
416 #define PFKEY_ADDR_PROTO(ext) \
417 (((struct sadb_address *)(ext))->sadb_address_proto)
418 #define PFKEY_ADDR_SADDR(ext) \
419 ((struct sockaddr *)((caddr_t)(ext) + sizeof(struct sadb_address)))
420
421 /* in 64bits */
422 #define PFKEY_UNUNIT64(a) ((a) << 3)
423 #define PFKEY_UNIT64(a) ((a) >> 3)
424
425 #endif /* __PFKEY_V2_H */
426
427 #endif /* _NET_PFKEYV2_H_ */