]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/pfkeyv2.h
cd966f618ec782f6bf53022f88df976b643c9c17
[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 /* $Id: pfkeyv2.h,v 1.3 2000/11/22 01:12:11 zarzycki Exp $ */
54
55 /*
56 * This file has been derived rfc 2367,
57 * And added some flags of SADB_KEY_FLAGS_ as SADB_X_EXT_.
58 * sakane@ydc.co.jp
59 */
60
61 #ifndef _NET_PFKEYV2_H_
62 #define _NET_PFKEYV2_H_
63
64 /*
65 This file defines structures and symbols for the PF_KEY Version 2
66 key management interface. It was written at the U.S. Naval Research
67 Laboratory. This file is in the public domain. The authors ask that
68 you leave this credit intact on any copies of this file.
69 */
70 #ifndef __PFKEY_V2_H
71 #define __PFKEY_V2_H 1
72
73 #define PF_KEY_V2 2
74 #define PFKEYV2_REVISION 199806L
75
76 #define SADB_RESERVED 0
77 #define SADB_GETSPI 1
78 #define SADB_UPDATE 2
79 #define SADB_ADD 3
80 #define SADB_DELETE 4
81 #define SADB_GET 5
82 #define SADB_ACQUIRE 6
83 #define SADB_REGISTER 7
84 #define SADB_EXPIRE 8
85 #define SADB_FLUSH 9
86 #define SADB_DUMP 10
87 #define SADB_X_PROMISC 11
88 #define SADB_X_PCHANGE 12
89
90 #define SADB_X_SPDUPDATE 13
91 #define SADB_X_SPDADD 14
92 #define SADB_X_SPDDELETE 15 /* by policy index */
93 #define SADB_X_SPDGET 16
94 #define SADB_X_SPDACQUIRE 17
95 #define SADB_X_SPDDUMP 18
96 #define SADB_X_SPDFLUSH 19
97 #define SADB_X_SPDSETIDX 20
98 #define SADB_X_SPDEXPIRE 21 /* not yet */
99 #define SADB_X_SPDDELETE2 22 /* by policy id */
100 #define SADB_MAX 22
101
102 struct sadb_msg {
103 u_int8_t sadb_msg_version;
104 u_int8_t sadb_msg_type;
105 u_int8_t sadb_msg_errno;
106 u_int8_t sadb_msg_satype;
107 u_int16_t sadb_msg_len;
108 u_int8_t sadb_msg_mode; /* XXX */
109 u_int8_t sadb_msg_reserved1;
110 u_int32_t sadb_msg_seq;
111 u_int32_t sadb_msg_pid;
112 u_int32_t sadb_msg_reqid; /* XXX */
113 /* when policy mng, value is zero. */
114 u_int32_t sadb_msg_reserved2;
115 };
116
117 struct sadb_ext {
118 u_int16_t sadb_ext_len;
119 u_int16_t sadb_ext_type;
120 };
121
122 struct sadb_sa {
123 u_int16_t sadb_sa_len;
124 u_int16_t sadb_sa_exttype;
125 u_int32_t sadb_sa_spi;
126 u_int8_t sadb_sa_replay;
127 u_int8_t sadb_sa_state;
128 u_int8_t sadb_sa_auth;
129 u_int8_t sadb_sa_encrypt;
130 u_int32_t sadb_sa_flags;
131 };
132
133 struct sadb_lifetime {
134 u_int16_t sadb_lifetime_len;
135 u_int16_t sadb_lifetime_exttype;
136 u_int32_t sadb_lifetime_allocations;
137 u_int64_t sadb_lifetime_bytes;
138 u_int64_t sadb_lifetime_addtime;
139 u_int64_t sadb_lifetime_usetime;
140 };
141
142 struct sadb_address {
143 u_int16_t sadb_address_len;
144 u_int16_t sadb_address_exttype;
145 u_int8_t sadb_address_proto;
146 u_int8_t sadb_address_prefixlen;
147 u_int16_t sadb_address_reserved;
148 };
149
150 struct sadb_key {
151 u_int16_t sadb_key_len;
152 u_int16_t sadb_key_exttype;
153 u_int16_t sadb_key_bits;
154 u_int16_t sadb_key_reserved;
155 };
156
157 struct sadb_ident {
158 u_int16_t sadb_ident_len;
159 u_int16_t sadb_ident_exttype;
160 u_int16_t sadb_ident_type;
161 u_int16_t sadb_ident_reserved;
162 u_int64_t sadb_ident_id;
163 };
164 /* in order to use to divide sadb_ident.sadb_ident_id */
165 union sadb_x_ident_id {
166 u_int64_t sadb_x_ident_id;
167 struct _sadb_x_ident_id_addr {
168 u_int16_t prefix;
169 u_int16_t ul_proto;
170 u_int32_t reserved;
171 } sadb_x_ident_id_addr;
172 };
173
174 struct sadb_sens {
175 u_int16_t sadb_sens_len;
176 u_int16_t sadb_sens_exttype;
177 u_int32_t sadb_sens_dpd;
178 u_int8_t sadb_sens_sens_level;
179 u_int8_t sadb_sens_sens_len;
180 u_int8_t sadb_sens_integ_level;
181 u_int8_t sadb_sens_integ_len;
182 u_int32_t sadb_sens_reserved;
183 };
184
185 struct sadb_prop {
186 u_int16_t sadb_prop_len;
187 u_int16_t sadb_prop_exttype;
188 u_int8_t sadb_prop_replay;
189 u_int8_t sadb_prop_reserved[3];
190 };
191
192 struct sadb_comb {
193 u_int8_t sadb_comb_auth;
194 u_int8_t sadb_comb_encrypt;
195 u_int16_t sadb_comb_flags;
196 u_int16_t sadb_comb_auth_minbits;
197 u_int16_t sadb_comb_auth_maxbits;
198 u_int16_t sadb_comb_encrypt_minbits;
199 u_int16_t sadb_comb_encrypt_maxbits;
200 u_int32_t sadb_comb_reserved;
201 u_int32_t sadb_comb_soft_allocations;
202 u_int32_t sadb_comb_hard_allocations;
203 u_int64_t sadb_comb_soft_bytes;
204 u_int64_t sadb_comb_hard_bytes;
205 u_int64_t sadb_comb_soft_addtime;
206 u_int64_t sadb_comb_hard_addtime;
207 u_int64_t sadb_comb_soft_usetime;
208 u_int64_t sadb_comb_hard_usetime;
209 };
210
211 struct sadb_supported {
212 u_int16_t sadb_supported_len;
213 u_int16_t sadb_supported_exttype;
214 u_int32_t sadb_supported_reserved;
215 };
216
217 struct sadb_alg {
218 u_int8_t sadb_alg_id;
219 u_int8_t sadb_alg_ivlen;
220 u_int16_t sadb_alg_minbits;
221 u_int16_t sadb_alg_maxbits;
222 u_int16_t sadb_alg_reserved;
223 };
224
225 struct sadb_spirange {
226 u_int16_t sadb_spirange_len;
227 u_int16_t sadb_spirange_exttype;
228 u_int32_t sadb_spirange_min;
229 u_int32_t sadb_spirange_max;
230 u_int32_t sadb_spirange_reserved;
231 };
232
233 struct sadb_x_kmprivate {
234 u_int16_t sadb_x_kmprivate_len;
235 u_int16_t sadb_x_kmprivate_exttype;
236 u_int32_t sadb_x_kmprivate_reserved;
237 };
238
239 /* XXX Policy Extension */
240 /* sizeof(struct sadb_x_policy) == 8 */
241 struct sadb_x_policy {
242 u_int16_t sadb_x_policy_len;
243 u_int16_t sadb_x_policy_exttype;
244 u_int16_t sadb_x_policy_type; /* See policy type of ipsec.h */
245 u_int8_t sadb_x_policy_dir; /* direction, see ipsec.h */
246 u_int8_t sadb_x_policy_reserved;
247 u_int32_t sadb_x_policy_id;
248 u_int32_t sadb_x_policy_reserved2;
249 };
250 /*
251 * When policy_type == IPSEC, it is followed by some of
252 * the ipsec policy request.
253 * [total length of ipsec policy requests]
254 * = (sadb_x_policy_len * sizeof(uint64_t) - sizeof(struct sadb_x_policy))
255 */
256
257 /* XXX IPsec Policy Request Extension */
258 /*
259 * This structure is aligned 8 bytes.
260 */
261 struct sadb_x_ipsecrequest {
262 u_int16_t sadb_x_ipsecrequest_len; /* structure length aligned to 8 bytes.
263 * This value is true length of bytes.
264 * Not in units of 64 bits. */
265 u_int16_t sadb_x_ipsecrequest_proto; /* See ipsec.h */
266 u_int8_t sadb_x_ipsecrequest_mode; /* See IPSEC_MODE_XX in ipsec.h. */
267 u_int8_t sadb_x_ipsecrequest_level; /* See IPSEC_LEVEL_XX in ipsec.h */
268 u_int16_t sadb_x_ipsecrequest_reqid; /* See ipsec.h */
269
270 /*
271 * followed by source IP address of SA, and immediately followed by
272 * destination IP address of SA. These encoded into two of sockaddr
273 * structure without any padding. Must set each sa_len exactly.
274 * Each of length of the sockaddr structure are not aligned to 64bits,
275 * but sum of x_request and addresses is aligned to 64bits.
276 */
277 };
278
279 #define SADB_EXT_RESERVED 0
280 #define SADB_EXT_SA 1
281 #define SADB_EXT_LIFETIME_CURRENT 2
282 #define SADB_EXT_LIFETIME_HARD 3
283 #define SADB_EXT_LIFETIME_SOFT 4
284 #define SADB_EXT_ADDRESS_SRC 5
285 #define SADB_EXT_ADDRESS_DST 6
286 #define SADB_EXT_ADDRESS_PROXY 7
287 #define SADB_EXT_KEY_AUTH 8
288 #define SADB_EXT_KEY_ENCRYPT 9
289 #define SADB_EXT_IDENTITY_SRC 10
290 #define SADB_EXT_IDENTITY_DST 11
291 #define SADB_EXT_SENSITIVITY 12
292 #define SADB_EXT_PROPOSAL 13
293 #define SADB_EXT_SUPPORTED_AUTH 14
294 #define SADB_EXT_SUPPORTED_ENCRYPT 15
295 #define SADB_EXT_SPIRANGE 16
296 #define SADB_X_EXT_KMPRIVATE 17
297 #define SADB_X_EXT_POLICY 18
298 #define SADB_EXT_MAX 18
299
300 #define SADB_SATYPE_UNSPEC 0
301 #define SADB_SATYPE_AH 2
302 #define SADB_SATYPE_ESP 3
303 #define SADB_SATYPE_RSVP 5
304 #define SADB_SATYPE_OSPFV2 6
305 #define SADB_SATYPE_RIPV2 7
306 #define SADB_SATYPE_MIP 8
307 #define SADB_X_SATYPE_IPCOMP 9
308 #define SADB_X_SATYPE_POLICY 10
309 #define SADB_SATYPE_MAX 11
310
311 #define SADB_SASTATE_LARVAL 0
312 #define SADB_SASTATE_MATURE 1
313 #define SADB_SASTATE_DYING 2
314 #define SADB_SASTATE_DEAD 3
315 #define SADB_SASTATE_MAX 3
316
317 #define SADB_SAFLAGS_PFS 1
318
319 #define SADB_AALG_NONE 0
320 #define SADB_AALG_MD5HMAC 1 /* 2 */
321 #define SADB_AALG_SHA1HMAC 2 /* 3 */
322 #define SADB_AALG_MD5 3 /* Keyed MD5 */
323 #define SADB_AALG_SHA 4 /* Keyed SHA */
324 #define SADB_AALG_NULL 5 /* null authentication */
325 #define SADB_AALG_MAX 6
326
327 #define SADB_EALG_NONE 0
328 #define SADB_EALG_DESCBC 1 /* 2 */
329 #define SADB_EALG_3DESCBC 2 /* 3 */
330 #define SADB_EALG_NULL 3 /* 11 */
331 #define SADB_EALG_BLOWFISHCBC 4
332 #define SADB_EALG_CAST128CBC 5
333 #define SADB_EALG_RC5CBC 6
334 #define SADB_EALG_MAX 7
335
336 #if 1 /*nonstandard */
337 #define SADB_X_CALG_NONE 0
338 #define SADB_X_CALG_OUI 1
339 #define SADB_X_CALG_DEFLATE 2
340 #define SADB_X_CALG_LZS 3
341 #define SADB_X_CALG_MAX 4
342 #endif
343
344 #define SADB_IDENTTYPE_RESERVED 0
345 #define SADB_IDENTTYPE_PREFIX 1
346 #define SADB_IDENTTYPE_FQDN 2
347 #define SADB_IDENTTYPE_USERFQDN 3
348 #define SADB_X_IDENTTYPE_ADDR 4
349 #define SADB_IDENTTYPE_MAX 4
350
351 /* `flags' in sadb_sa structure holds followings */
352 #define SADB_X_EXT_NONE 0x0000 /* i.e. new format. */
353 #define SADB_X_EXT_OLD 0x0001 /* old format. */
354
355 #define SADB_X_EXT_IV4B 0x0010 /* IV length of 4 bytes in use */
356 #define SADB_X_EXT_DERIV 0x0020 /* DES derived */
357 #define SADB_X_EXT_CYCSEQ 0x0040 /* allowing to cyclic sequence. */
358
359 /* three of followings are exclusive flags each them */
360 #define SADB_X_EXT_PSEQ 0x0000 /* sequencial padding for ESP */
361 #define SADB_X_EXT_PRAND 0x0100 /* random padding for ESP */
362 #define SADB_X_EXT_PZERO 0x0200 /* zero padding for ESP */
363 #define SADB_X_EXT_PMASK 0x0300 /* mask for padding flag */
364
365 #if 1
366 #define SADB_X_EXT_RAWCPI 0x0080 /* use well known CPI (IPComp) */
367 #endif
368
369 #define SADB_KEY_FLAGS_MAX 0x0fff
370
371 /* SPI size for PF_KEYv2 */
372 #define PFKEY_SPI_SIZE sizeof(u_int32_t)
373
374 /* Identifier for menber of lifetime structure */
375 #define SADB_X_LIFETIME_ALLOCATIONS 0
376 #define SADB_X_LIFETIME_BYTES 1
377 #define SADB_X_LIFETIME_ADDTIME 2
378 #define SADB_X_LIFETIME_USETIME 3
379
380 /* The rate for SOFT lifetime against HARD one. */
381 #define PFKEY_SOFT_LIFETIME_RATE 80
382
383 /* Utilities */
384 #define PFKEY_ALIGN8(a) (1 + (((a) - 1) | (8 - 1)))
385 #define PFKEY_EXTLEN(msg) \
386 PFKEY_UNUNIT64(((struct sadb_ext *)(msg))->sadb_ext_len)
387 #define PFKEY_ADDR_PREFIX(ext) \
388 (((struct sadb_address *)(ext))->sadb_address_prefixlen)
389 #define PFKEY_ADDR_PROTO(ext) \
390 (((struct sadb_address *)(ext))->sadb_address_proto)
391 #define PFKEY_ADDR_SADDR(ext) \
392 ((struct sockaddr *)((caddr_t)(ext) + sizeof(struct sadb_address)))
393
394 #if 1
395 /* in 64bits */
396 #define PFKEY_UNUNIT64(a) ((a) << 3)
397 #define PFKEY_UNIT64(a) ((a) >> 3)
398 #else
399 #define PFKEY_UNUNIT64(a) (a)
400 #define PFKEY_UNIT64(a) (a)
401 #endif
402
403 #ifndef KERNEL
404 extern void pfkey_sadump __P((struct sadb_msg *));
405 extern void pfkey_spdump __P((struct sadb_msg *));
406
407 struct sockaddr;
408 int ipsec_check_keylen __P((u_int, u_int, u_int));
409 u_int pfkey_set_softrate __P((u_int, u_int));
410 u_int pfkey_get_softrate __P((u_int));
411 int pfkey_send_getspi __P((int, u_int, u_int, struct sockaddr *,
412 struct sockaddr *, u_int32_t, u_int32_t, u_int32_t, u_int32_t));
413 int pfkey_send_update __P((int, u_int, u_int, struct sockaddr *,
414 struct sockaddr *, u_int32_t, u_int32_t, u_int,
415 caddr_t, u_int, u_int, u_int, u_int, u_int, u_int32_t, u_int64_t,
416 u_int64_t, u_int64_t, u_int32_t));
417 int pfkey_send_add __P((int, u_int, u_int, struct sockaddr *,
418 struct sockaddr *, u_int32_t, u_int32_t, u_int,
419 caddr_t, u_int, u_int, u_int, u_int, u_int, u_int32_t, u_int64_t,
420 u_int64_t, u_int64_t, u_int32_t));
421 int pfkey_send_delete __P((int, u_int, u_int,
422 struct sockaddr *, struct sockaddr *, u_int32_t));
423 int pfkey_send_get __P((int, u_int, u_int,
424 struct sockaddr *, struct sockaddr *, u_int32_t));
425 int pfkey_send_register __P((int, u_int));
426 int pfkey_recv_register __P((int));
427 int pfkey_send_flush __P((int, u_int));
428 int pfkey_send_dump __P((int, u_int));
429 int pfkey_send_promisc_toggle __P((int, int));
430 int pfkey_send_spdadd __P((int, struct sockaddr *, u_int,
431 struct sockaddr *, u_int, u_int, caddr_t, int, u_int32_t));
432 int pfkey_send_spdupdate __P((int, struct sockaddr *, u_int,
433 struct sockaddr *, u_int, u_int, caddr_t, int, u_int32_t));
434 int pfkey_send_spddelete __P((int, struct sockaddr *, u_int,
435 struct sockaddr *, u_int, u_int, caddr_t, int, u_int32_t));
436 int pfkey_send_spddelete2 __P((int, u_int32_t));
437 int pfkey_send_spdget __P((int, u_int32_t));
438 int pfkey_send_spdsetidx __P((int, struct sockaddr *, u_int,
439 struct sockaddr *, u_int, u_int, caddr_t, int, u_int32_t));
440 int pfkey_send_spdflush __P((int));
441 int pfkey_send_spddump __P((int));
442
443 int pfkey_open __P((void));
444 void pfkey_close __P((int));
445 struct sadb_msg *pfkey_recv __P((int));
446 int pfkey_send __P((int, struct sadb_msg *, int));
447 int pfkey_align __P((struct sadb_msg *, caddr_t *));
448 int pfkey_check __P((caddr_t *));
449
450 #endif /*!KERNEL*/
451
452 #endif /* __PFKEY_V2_H */
453
454 #endif /* _NET_PFKEYV2_H_ */