xref: /titanic_51/usr/src/uts/common/net/pfkeyv2.h (revision 7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fe)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_NET_PFKEYV2_H
28 #define	_NET_PFKEYV2_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * Definitions and structures for PF_KEY version 2.  See RFC 2367 for
34  * more details.  SA == Security Association, which is what PF_KEY provides
35  * an API for managing.
36  */
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 #define	PF_KEY_V2		2
43 #define	PFKEYV2_REVISION	200109L
44 
45 /*
46  * Base PF_KEY message.
47  */
48 
49 typedef struct sadb_msg {
50 	uint8_t sadb_msg_version;	/* Version, currently PF_KEY_V2 */
51 	uint8_t sadb_msg_type;		/* ADD, UPDATE, etc. */
52 	uint8_t sadb_msg_errno;		/* Error number from UNIX errno space */
53 	uint8_t sadb_msg_satype;	/* ESP, AH, etc. */
54 	uint16_t sadb_msg_len;		/* Length in 64-bit words. */
55 	uint16_t sadb_msg_reserved;	/* must be zero */
56 /*
57  * Use the reserved field for extended diagnostic information on errno
58  * responses.
59  */
60 #define	sadb_x_msg_diagnostic sadb_msg_reserved
61 	/* Union is for guaranteeing 64-bit alignment. */
62 	union {
63 		struct {
64 			uint32_t sadb_x_msg_useq;	/* Set by originator */
65 			uint32_t sadb_x_msg_upid;	/* Set by originator */
66 		} sadb_x_msg_actual;
67 		uint64_t sadb_x_msg_alignment;
68 	} sadb_x_msg_u;
69 #define	sadb_msg_seq sadb_x_msg_u.sadb_x_msg_actual.sadb_x_msg_useq
70 #define	sadb_msg_pid sadb_x_msg_u.sadb_x_msg_actual.sadb_x_msg_upid
71 } sadb_msg_t;
72 
73 /*
74  * Generic extension header.
75  */
76 
77 typedef struct sadb_ext {
78 	union {
79 		/* Union is for guaranteeing 64-bit alignment. */
80 		struct {
81 			uint16_t sadb_x_ext_ulen;	/* In 64s, inclusive */
82 			uint16_t sadb_x_ext_utype;	/* 0 is reserved */
83 		} sadb_x_ext_actual;
84 		uint64_t sadb_x_ext_alignment;
85 	} sadb_x_ext_u;
86 #define	sadb_ext_len sadb_x_ext_u.sadb_x_ext_actual.sadb_x_ext_ulen
87 #define	sadb_ext_type sadb_x_ext_u.sadb_x_ext_actual.sadb_x_ext_utype
88 } sadb_ext_t;
89 
90 /*
91  * Security Association information extension.
92  */
93 
94 typedef struct sadb_sa {
95 	/* Union is for guaranteeing 64-bit alignment. */
96 	union {
97 		struct {
98 			uint16_t sadb_x_sa_ulen;
99 			uint16_t sadb_x_sa_uexttype;	/* ASSOCIATION */
100 			uint32_t sadb_x_sa_uspi;	/* Sec. Param. Index */
101 		} sadb_x_sa_uactual;
102 		uint64_t sadb_x_sa_alignment;
103 	} sadb_x_sa_u;
104 #define	sadb_sa_len sadb_x_sa_u.sadb_x_sa_uactual.sadb_x_sa_ulen
105 #define	sadb_sa_exttype sadb_x_sa_u.sadb_x_sa_uactual.sadb_x_sa_uexttype
106 #define	sadb_sa_spi sadb_x_sa_u.sadb_x_sa_uactual.sadb_x_sa_uspi
107 	uint8_t sadb_sa_replay;		/* Replay counter */
108 	uint8_t sadb_sa_state;		/* MATURE, DEAD, DYING, LARVAL */
109 	uint8_t sadb_sa_auth;		/* Authentication algorithm */
110 	uint8_t sadb_sa_encrypt;	/* Encryption algorithm */
111 	uint32_t sadb_sa_flags;		/* SA flags. */
112 } sadb_sa_t;
113 
114 /*
115  * SA Lifetime extension.  Already 64-bit aligned thanks to uint64_t fields.
116  */
117 
118 typedef struct sadb_lifetime {
119 	uint16_t sadb_lifetime_len;
120 	uint16_t sadb_lifetime_exttype;		/* SOFT, HARD, CURRENT */
121 	uint32_t sadb_lifetime_allocations;
122 	uint64_t sadb_lifetime_bytes;
123 	uint64_t sadb_lifetime_addtime;	/* These fields are assumed to hold */
124 	uint64_t sadb_lifetime_usetime;	/* >= sizeof (time_t). */
125 } sadb_lifetime_t;
126 
127 /*
128  * SA address information.
129  */
130 
131 typedef struct sadb_address {
132 	/* Union is for guaranteeing 64-bit alignment. */
133 	union {
134 		struct {
135 			uint16_t sadb_x_address_ulen;
136 			uint16_t sadb_x_address_uexttype; /* SRC, DST, PROXY */
137 			uint8_t sadb_x_address_uproto; /* Proto for ports... */
138 			uint8_t sadb_x_address_uprefixlen; /* Prefix length. */
139 			uint16_t sadb_x_address_ureserved; /* Padding */
140 		} sadb_x_address_actual;
141 		uint64_t sadb_x_address_alignment;
142 	} sadb_x_address_u;
143 #define	sadb_address_len \
144 	sadb_x_address_u.sadb_x_address_actual.sadb_x_address_ulen
145 #define	sadb_address_exttype \
146 	sadb_x_address_u.sadb_x_address_actual.sadb_x_address_uexttype
147 #define	sadb_address_proto \
148 	sadb_x_address_u.sadb_x_address_actual.sadb_x_address_uproto
149 #define	sadb_address_prefixlen \
150 	sadb_x_address_u.sadb_x_address_actual.sadb_x_address_uprefixlen
151 #define	sadb_address_reserved \
152 	sadb_x_address_u.sadb_x_address_actual.sadb_x_address_ureserved
153 	/* Followed by a sockaddr structure which may contain ports. */
154 } sadb_address_t;
155 
156 /*
157  * SA key information.
158  */
159 
160 typedef struct sadb_key {
161 	/* Union is for guaranteeing 64-bit alignment. */
162 	union {
163 		struct {
164 			uint16_t sadb_x_key_ulen;
165 			uint16_t sadb_x_key_uexttype;	/* AUTH, ENCRYPT */
166 			uint16_t sadb_x_key_ubits;	/* Actual len (bits) */
167 			uint16_t sadb_x_key_ureserved;
168 		} sadb_x_key_actual;
169 		uint64_t sadb_x_key_alignment;
170 	} sadb_x_key_u;
171 #define	sadb_key_len sadb_x_key_u.sadb_x_key_actual.sadb_x_key_ulen
172 #define	sadb_key_exttype sadb_x_key_u.sadb_x_key_actual.sadb_x_key_uexttype
173 #define	sadb_key_bits sadb_x_key_u.sadb_x_key_actual.sadb_x_key_ubits
174 #define	sadb_key_reserved sadb_x_key_u.sadb_x_key_actual.sadb_x_key_ureserved
175 	/* Followed by actual key(s) in canonical (outbound proc.) order. */
176 } sadb_key_t;
177 
178 /*
179  * SA Identity information.  Already 64-bit aligned thanks to uint64_t fields.
180  */
181 
182 typedef struct sadb_ident {
183 	uint16_t sadb_ident_len;
184 	uint16_t sadb_ident_exttype;	/* SRC, DST, PROXY */
185 	uint16_t sadb_ident_type;	/* FQDN, USER_FQDN, etc. */
186 	uint16_t sadb_ident_reserved;	/* Padding */
187 	uint64_t sadb_ident_id;		/* For userid, etc. */
188 	/* Followed by an identity null-terminate C string if present. */
189 } sadb_ident_t;
190 
191 /*
192  * SA sensitivity information.  This is mostly useful on MLS systems.
193  */
194 
195 typedef struct sadb_sens {
196 	/* Union is for guaranteeing 64-bit alignment. */
197 	union {
198 		struct {
199 			uint16_t sadb_x_sens_ulen;
200 			uint16_t sadb_x_sens_uexttype;	/* SENSITIVITY */
201 			uint32_t sadb_x_sens_udpd;	/* Protection domain */
202 		} sadb_x_sens_actual;
203 		uint64_t sadb_x_sens_alignment;
204 	} sadb_x_sens_u;
205 #define	sadb_sens_len sadb_x_sens_u.sadb_x_sens_actual.sadb_x_sens_ulen
206 #define	sadb_sens_exttype sadb_x_sens_u.sadb_x_sens_actual.sadb_x_sens_uexttype
207 #define	sadb_sens_dpd sadb_x_sens_u.sadb_x_sens_actual.sadb_x_sens_udpd
208 	uint8_t sadb_sens_sens_level;
209 	uint8_t sadb_sens_sens_len;		/* 64-bit words */
210 	uint8_t sadb_sens_integ_level;
211 	uint8_t sadb_sens_integ_len;		/* 64-bit words */
212 	uint32_t sadb_sens_reserved;
213 	/*
214 	 * followed by two uint64_t arrays
215 	 * uint64_t sadb_sens_bitmap[sens_bitmap_len];
216 	 * uint64_t sadb_integ_bitmap[integ_bitmap_len];
217 	 */
218 } sadb_sens_t;
219 
220 /*
221  * A proposal extension.  This is found in an ACQUIRE message, and it
222  * proposes what sort of SA the kernel would like to ACQUIRE.
223  */
224 
225 /* First, a base structure... */
226 
227 typedef struct sadb_x_propbase {
228 	uint16_t sadb_x_propb_len;
229 	uint16_t sadb_x_propb_exttype;	/* PROPOSAL, X_EPROP */
230 	union {
231 		struct {
232 			uint8_t sadb_x_propb_lenres_replay;
233 			uint8_t sadb_x_propb_lenres_eres;
234 			uint16_t sadb_x_propb_lenres_numecombs;
235 		} sadb_x_propb_lenres;
236 		struct {
237 			uint8_t sadb_x_propb_oldres_replay;
238 			uint8_t sadb_x_propb_oldres_reserved[3];
239 		} sadb_x_propb_oldres;
240 	} sadb_x_propb_u;
241 #define	sadb_x_propb_replay \
242 	sadb_x_propb_u.sadb_x_propb_lenres.sadb_x_propb_lenres_replay
243 #define	sadb_x_propb_reserved \
244 	sadb_x_propb_u.sadb_x_propb_oldres.sadb_x_propb_oldres_reserved
245 #define	sadb_x_propb_ereserved \
246 	sadb_x_propb_u.sadb_x_propb_lenres.sadb_x_propb_lenres_eres
247 #define	sadb_x_propb_numecombs \
248 	sadb_x_propb_u.sadb_x_propb_lenres.sadb_x_propb_lenres_numecombs
249 	/* Followed by sadb_comb[] array or sadb_ecomb[] array. */
250 } sadb_x_propbase_t;
251 
252 /* Now, the actual sadb_prop structure, which will have alignment in it! */
253 
254 typedef struct sadb_prop {
255 	/* Union is for guaranteeing 64-bit alignment. */
256 	union {
257 		sadb_x_propbase_t sadb_x_prop_actual;
258 		uint64_t sadb_x_prop_alignment;
259 	} sadb_x_prop_u;
260 #define	sadb_prop_len sadb_x_prop_u.sadb_x_prop_actual.sadb_x_propb_len
261 #define	sadb_prop_exttype sadb_x_prop_u.sadb_x_prop_actual.sadb_x_propb_exttype
262 #define	sadb_prop_replay sadb_x_prop_u.sadb_x_prop_actual.sadb_x_propb_replay
263 #define	sadb_prop_reserved \
264 	sadb_x_prop_u.sadb_x_prop_actual.sadb_x_propb_reserved
265 #define	sadb_x_prop_ereserved \
266 	sadb_x_prop_u.sadb_x_prop_actual.sadb_x_propb_ereserved
267 #define	sadb_x_prop_numecombs \
268 	sadb_x_prop_u.sadb_x_prop_actual.sadb_x_propb_numecombs
269 } sadb_prop_t;
270 
271 /*
272  * This is a proposed combination.  Many of these can follow a proposal
273  * extension.  Already 64-bit aligned thanks to uint64_t fields.
274  */
275 
276 typedef struct sadb_comb {
277 	uint8_t sadb_comb_auth;			/* Authentication algorithm */
278 	uint8_t sadb_comb_encrypt;		/* Encryption algorithm */
279 	uint16_t sadb_comb_flags;		/* Comb. flags (e.g. PFS) */
280 	uint16_t sadb_comb_auth_minbits;	/* Bit strengths for auth */
281 	uint16_t sadb_comb_auth_maxbits;
282 	uint16_t sadb_comb_encrypt_minbits;	/* Bit strengths for encrypt */
283 	uint16_t sadb_comb_encrypt_maxbits;
284 	uint32_t sadb_comb_reserved;
285 	uint32_t sadb_comb_soft_allocations;	/* Lifetime proposals for */
286 	uint32_t sadb_comb_hard_allocations;	/* this combination. */
287 	uint64_t sadb_comb_soft_bytes;
288 	uint64_t sadb_comb_hard_bytes;
289 	uint64_t sadb_comb_soft_addtime;
290 	uint64_t sadb_comb_hard_addtime;
291 	uint64_t sadb_comb_soft_usetime;
292 	uint64_t sadb_comb_hard_usetime;
293 } sadb_comb_t;
294 
295 /*
296  * An extended combination that can comprise of many SA types.
297  * A single combination has algorithms and SA types locked.
298  * These are represented by algorithm descriptors, the second structure
299  * in the list.  For example, if the EACQUIRE requests AH(MD5) + ESP(DES/null)
300  * _or_ ESP(DES/MD5), it would have two combinations:
301  *
302  * COMB: algdes(AH, AUTH, MD5), algdes(ESP, CRYPT, DES)
303  * COMB: algdes(ESP, AUTH, MD5), algdes(ESP, CRYPT, DES)
304  *
305  * If an SA type supports an algorithm type, and there's no descriptor,
306  * assume it requires NONE, just like it were explicitly stated.
307  * (This includes ESP NULL encryption, BTW.)
308  *
309  * Already 64-bit aligned thanks to uint64_t fields.
310  */
311 
312 typedef struct sadb_x_ecomb {
313 	uint8_t sadb_x_ecomb_numalgs;
314 	uint8_t sadb_x_ecomb_reserved;
315 	uint16_t sadb_x_ecomb_flags;	/* E.g. PFS? */
316 	uint32_t sadb_x_ecomb_reserved2;
317 	uint32_t sadb_x_ecomb_soft_allocations;
318 	uint32_t sadb_x_ecomb_hard_allocations;
319 	uint64_t sadb_x_ecomb_soft_bytes;
320 	uint64_t sadb_x_ecomb_hard_bytes;
321 	uint64_t sadb_x_ecomb_soft_addtime;
322 	uint64_t sadb_x_ecomb_hard_addtime;
323 	uint64_t sadb_x_ecomb_soft_usetime;
324 	uint64_t sadb_x_ecomb_hard_usetime;
325 } sadb_x_ecomb_t;
326 
327 typedef struct sadb_x_algdesc {
328 	/* Union is for guaranteeing 64-bit alignment. */
329 	union {
330 		struct {
331 			uint8_t sadb_x_algdesc_usatype;	/* ESP, AH, etc. */
332 			uint8_t sadb_x_algdesc_ualgtype; /* AUTH, CRYPT, COMP */
333 			uint8_t sadb_x_algdesc_ualg;	/* 3DES, MD5, etc. */
334 			uint8_t sadb_x_algdesc_ureserved;
335 			uint16_t sadb_x_algdesc_uminbits; /* Bit strengths. */
336 			uint16_t sadb_x_algdesc_umaxbits;
337 		} sadb_x_algdesc_actual;
338 		uint64_t sadb_x_algdesc_alignment;
339 	} sadb_x_algdesc_u;
340 #define	sadb_x_algdesc_satype \
341 	sadb_x_algdesc_u.sadb_x_algdesc_actual.sadb_x_algdesc_usatype
342 #define	sadb_x_algdesc_algtype \
343 	sadb_x_algdesc_u.sadb_x_algdesc_actual.sadb_x_algdesc_ualgtype
344 #define	sadb_x_algdesc_alg \
345 	sadb_x_algdesc_u.sadb_x_algdesc_actual.sadb_x_algdesc_ualg
346 #define	sadb_x_algdesc_reserved \
347 	sadb_x_algdesc_u.sadb_x_algdesc_actual.sadb_x_algdesc_ureserved
348 #define	sadb_x_algdesc_minbits \
349 	sadb_x_algdesc_u.sadb_x_algdesc_actual.sadb_x_algdesc_uminbits
350 #define	sadb_x_algdesc_maxbits \
351 	sadb_x_algdesc_u.sadb_x_algdesc_actual.sadb_x_algdesc_umaxbits
352 } sadb_x_algdesc_t;
353 
354 /*
355  * When key mgmt. registers with the kernel, the kernel will tell key mgmt.
356  * its supported algorithms.
357  */
358 
359 typedef struct sadb_supported {
360 	/* Union is for guaranteeing 64-bit alignment. */
361 	union {
362 		struct {
363 			uint16_t sadb_x_supported_ulen;
364 			uint16_t sadb_x_supported_uexttype;
365 			uint32_t sadb_x_supported_ureserved;
366 		} sadb_x_supported_actual;
367 		uint64_t sadb_x_supported_alignment;
368 	} sadb_x_supported_u;
369 #define	sadb_supported_len \
370 	sadb_x_supported_u.sadb_x_supported_actual.sadb_x_supported_ulen
371 #define	sadb_supported_exttype \
372 	sadb_x_supported_u.sadb_x_supported_actual.sadb_x_supported_uexttype
373 #define	sadb_supported_reserved \
374 	sadb_x_supported_u.sadb_x_supported_actual.sadb_x_supported_ureserved
375 } sadb_supported_t;
376 
377 /* First, a base structure... */
378 typedef struct sadb_x_algb {
379 	uint8_t sadb_x_algb_id;		/* Algorithm type. */
380 	uint8_t sadb_x_algb_ivlen;		/* IV len, in bits */
381 	uint16_t sadb_x_algb_minbits;	/* Min. key len (in bits) */
382 	uint16_t sadb_x_algb_maxbits;	/* Max. key length */
383 	union {
384 		uint16_t sadb_x_algb_ureserved;
385 		uint8_t sadb_x_algb_udefaults[2];
386 	} sadb_x_algb_union;
387 
388 #define	sadb_x_algb_reserved sadb_x_algb_union.sadb_x_algb_ureserved
389 #define	sadb_x_algb_increment sadb_x_algb_union.sadb_x_algb_udefaults[0]
390 #define	sadb_x_algb_defincr sadb_x_algb_union.sadb_x_algb_udefaults[1]
391 /*
392  * alg_increment: the number of bits from a key length to the next
393  * alg_defincr: the number of increments from the smallest possible
394  * key to the default key length
395  */
396 } sadb_x_algb_t;
397 /* useful macros for dealing with defincr */
398 #define	SADB_ALG_DEFAULT_LEN(min, incr, defincr) ((min) + ((defincr) * (incr)))
399 #define	SADB_ALG_DEFAULT_INCR(min, incr, default) (((default) - (min)) / (incr))
400 
401 /* Now, the actual sadb_alg structure, which will have alignment in it. */
402 typedef struct sadb_alg {
403 	/* Union is for guaranteeing 64-bit alignment. */
404 	union {
405 		sadb_x_algb_t sadb_x_alg_actual;
406 		uint64_t sadb_x_alg_alignment;
407 	} sadb_x_alg_u;
408 #define	sadb_alg_id sadb_x_alg_u.sadb_x_alg_actual.sadb_x_algb_id
409 #define	sadb_alg_ivlen sadb_x_alg_u.sadb_x_alg_actual.sadb_x_algb_ivlen
410 #define	sadb_alg_minbits sadb_x_alg_u.sadb_x_alg_actual.sadb_x_algb_minbits
411 #define	sadb_alg_maxbits sadb_x_alg_u.sadb_x_alg_actual.sadb_x_algb_maxbits
412 #define	sadb_alg_reserved sadb_x_alg_u.sadb_x_alg_actual.sadb_x_algb_reserved
413 #define	sadb_x_alg_increment \
414 	sadb_x_alg_u.sadb_x_alg_actual.sadb_x_algb_increment
415 #define	sadb_x_alg_defincr sadb_x_alg_u.sadb_x_alg_actual.sadb_x_algb_defincr
416 } sadb_alg_t;
417 
418 /*
419  * If key mgmt. needs an SPI in a range (including 0 to 0xFFFFFFFF), it
420  * asks the kernel with this extension in the SADB_GETSPI message.
421  */
422 
423 typedef struct sadb_spirange {
424 	uint16_t sadb_spirange_len;
425 	uint16_t sadb_spirange_exttype;	/* SPI_RANGE */
426 	uint32_t sadb_spirange_min;
427 	/* Union is for guaranteeing 64-bit alignment. */
428 	union {
429 		struct {
430 			uint32_t sadb_x_spirange_umax;
431 			uint32_t sadb_x_spirange_ureserved;
432 		} sadb_x_spirange_actual;
433 		uint64_t sadb_x_spirange_alignment;
434 	} sadb_x_spirange_u;
435 #define	sadb_spirange_max \
436 	sadb_x_spirange_u.sadb_x_spirange_actual.sadb_x_spirange_umax
437 #define	sadb_spirange_reserved \
438 	sadb_x_spirange_u.sadb_x_spirange_actual.sadb_x_spirange_ureserved
439 } sadb_spirange_t;
440 
441 /*
442  * For the "extended REGISTER" which'll tell the kernel to send me
443  * "extended ACQUIREs".
444  */
445 
446 typedef struct sadb_x_ereg {
447 	/* Union is for guaranteeing 64-bit alignment. */
448 	union {
449 		struct {
450 			uint16_t sadb_x_ereg_ulen;
451 			uint16_t sadb_x_ereg_uexttype;	/* X_EREG */
452 			/* Array of SA types, 0-terminated. */
453 			uint8_t sadb_x_ereg_usatypes[4];
454 		} sadb_x_ereg_actual;
455 		uint64_t sadb_x_ereg_alignment;
456 	} sadb_x_ereg_u;
457 #define	sadb_x_ereg_len \
458 	sadb_x_ereg_u.sadb_x_ereg_actual.sadb_x_ereg_ulen
459 #define	sadb_x_ereg_exttype \
460 	sadb_x_ereg_u.sadb_x_ereg_actual.sadb_x_ereg_uexttype
461 #define	sadb_x_ereg_satypes \
462 	sadb_x_ereg_u.sadb_x_ereg_actual.sadb_x_ereg_usatypes
463 } sadb_x_ereg_t;
464 
465 /*
466  * For conveying a Key Management Cookie with SADB_GETSPI, SADB_ADD,
467  * SADB_ACQUIRE, or SADB_X_INVERSE_ACQUIRE.
468  */
469 
470 typedef struct sadb_x_kmc {
471 	uint16_t sadb_x_kmc_len;
472 	uint16_t sadb_x_kmc_exttype;	/* X_KM_COOKIE */
473 	uint32_t sadb_x_kmc_proto;	/* KM protocol */
474 	union {
475 		struct {
476 			uint32_t sadb_x_kmc_ucookie;	/* KMP-specific */
477 			uint32_t sadb_x_kmc_ureserved;	/* Must be zero */
478 		} sadb_x_kmc_actual;
479 		uint64_t sadb_x_kmc_alignment;
480 	} sadb_x_kmc_u;
481 #define	sadb_x_kmc_cookie sadb_x_kmc_u.sadb_x_kmc_actual.sadb_x_kmc_ucookie
482 #define	sadb_x_kmc_reserved sadb_x_kmc_u.sadb_x_kmc_actual.sadb_x_kmc_ureserved
483 } sadb_x_kmc_t;
484 
485 
486 
487 /*
488  * Base message types.
489  */
490 
491 #define	SADB_RESERVED	0
492 #define	SADB_GETSPI	1
493 #define	SADB_UPDATE	2
494 #define	SADB_ADD	3
495 #define	SADB_DELETE	4
496 #define	SADB_GET	5
497 #define	SADB_ACQUIRE	6
498 #define	SADB_REGISTER	7
499 #define	SADB_EXPIRE	8
500 #define	SADB_FLUSH	9
501 #define	SADB_DUMP	10   /* not used normally */
502 #define	SADB_X_PROMISC	11
503 #define	SADB_X_INVERSE_ACQUIRE	12
504 #define	SADB_MAX		12
505 
506 /*
507  * SA flags
508  */
509 
510 #define	SADB_SAFLAGS_PFS	0x1	/* Perfect forward secrecy? */
511 #define	SADB_SAFLAGS_NOREPLAY	0x2	/* Replay field NOT PRESENT. */
512 
513 /* Below flags are used by this implementation.  Grow from left-to-right. */
514 #define	SADB_X_SAFLAGS_USED	0x80000000	/* SA used/not used */
515 #define	SADB_X_SAFLAGS_UNIQUE	0x40000000	/* SA unique/reusable */
516 #define	SADB_X_SAFLAGS_AALG1	0x20000000	/* Auth-alg specific flag 1 */
517 #define	SADB_X_SAFLAGS_AALG2	0x10000000	/* Auth-alg specific flag 2 */
518 #define	SADB_X_SAFLAGS_EALG1	 0x8000000	/* Encr-alg specific flag 1 */
519 #define	SADB_X_SAFLAGS_EALG2	 0x4000000	/* Encr-alg specific flag 2 */
520 #define	SADB_X_SAFLAGS_KM1	 0x2000000	/* Key mgmt. specific flag 1 */
521 #define	SADB_X_SAFLAGS_KM2	 0x1000000	/* Key mgmt. specific flag 2 */
522 #define	SADB_X_SAFLAGS_KM3	  0x800000	/* Key mgmt. specific flag 3 */
523 #define	SADB_X_SAFLAGS_KM4	  0x400000	/* Key mgmt. specific flag 4 */
524 	/* skip x200000 because it's used in the kernel */
525 #define	SADB_X_SAFLAGS_NATT_LOC	  0x100000	/* this has a natted src SA */
526 #define	SADB_X_SAFLAGS_NATT_REM	   0x80000	/* this has a natted dst SA */
527 /*
528  * SA state.
529  */
530 
531 #define	SADB_SASTATE_LARVAL	  0
532 #define	SADB_SASTATE_MATURE	  1
533 #define	SADB_SASTATE_DYING	  2
534 #define	SADB_SASTATE_DEAD	  3
535 
536 #define	SADB_SASTATE_MAX	  3
537 
538 /*
539  * SA type.  Gaps are present in the number space because (for the time being)
540  * these types correspond to the SA types in the IPsec DOI document.
541  */
542 
543 #define	SADB_SATYPE_UNSPEC	0
544 #define	SADB_SATYPE_AH		2  /* RFC-1826 */
545 #define	SADB_SATYPE_ESP		3  /* RFC-1827 */
546 #define	SADB_SATYPE_RSVP	5  /* RSVP Authentication */
547 #define	SADB_SATYPE_OSPFV2	6  /* OSPFv2 Authentication */
548 #define	SADB_SATYPE_RIPV2	7  /* RIPv2 Authentication */
549 #define	SADB_SATYPE_MIP		8  /* Mobile IPv4 Authentication */
550 
551 #define	SADB_SATYPE_MAX		8
552 
553 /*
554  * Algorithm types.  Gaps are present because (for the time being) these types
555  * correspond to the SA types in the IPsec DOI document.
556  *
557  * NOTE:  These are numbered to play nice with the IPsec DOI.  That's why
558  *	  there are gaps.
559  */
560 
561 /* Authentication algorithms */
562 #define	SADB_AALG_NONE		0
563 #define	SADB_AALG_MD5HMAC	2
564 #define	SADB_AALG_SHA1HMAC	3
565 
566 #define	SADB_AALG_MAX		3
567 
568 /* Encryption algorithms */
569 #define	SADB_EALG_NONE		0
570 #define	SADB_EALG_DESCBC	2
571 #define	SADB_EALG_3DESCBC	3
572 #define	SADB_EALG_BLOWFISH	7
573 #define	SADB_EALG_NULL		11
574 #define	SADB_EALG_AES		12
575 #define	SADB_EALG_MAX		12
576 
577 /*
578  * Extension header values.
579  */
580 
581 #define	SADB_EXT_RESERVED		0
582 
583 #define	SADB_EXT_SA			1
584 #define	SADB_EXT_LIFETIME_CURRENT	2
585 #define	SADB_EXT_LIFETIME_HARD		3
586 #define	SADB_EXT_LIFETIME_SOFT		4
587 #define	SADB_EXT_ADDRESS_SRC		5
588 #define	SADB_EXT_ADDRESS_DST		6
589 #define	SADB_EXT_ADDRESS_PROXY		7
590 #define	SADB_EXT_KEY_AUTH		8
591 #define	SADB_EXT_KEY_ENCRYPT		9
592 #define	SADB_EXT_IDENTITY_SRC		10
593 #define	SADB_EXT_IDENTITY_DST		11
594 #define	SADB_EXT_SENSITIVITY		12
595 #define	SADB_EXT_PROPOSAL		13
596 #define	SADB_EXT_SUPPORTED_AUTH		14
597 #define	SADB_EXT_SUPPORTED_ENCRYPT	15
598 #define	SADB_EXT_SPIRANGE		16
599 #define	SADB_X_EXT_EREG			17
600 #define	SADB_X_EXT_EPROP		18
601 #define	SADB_X_EXT_KM_COOKIE		19
602 #define	SADB_X_EXT_ADDRESS_NATT_LOC	20
603 #define	SADB_X_EXT_ADDRESS_NATT_REM	21
604 
605 #define	SADB_EXT_MAX			21
606 
607 /*
608  * Identity types.
609  */
610 
611 #define	SADB_IDENTTYPE_RESERVED 0
612 
613 /*
614  * For PREFIX and ADDR_RANGE, use the AF of the PROXY if present, or the SRC
615  * if not present.
616  */
617 #define	SADB_IDENTTYPE_PREFIX		1
618 #define	SADB_IDENTTYPE_FQDN		2  /* Fully qualified domain name. */
619 #define	SADB_IDENTTYPE_USER_FQDN	3  /* e.g. root@domain.com */
620 #define	SADB_X_IDENTTYPE_DN		4  /* ASN.1 DER Distinguished Name. */
621 #define	SADB_X_IDENTTYPE_GN		5  /* ASN.1 DER Generic Name. */
622 #define	SADB_X_IDENTTYPE_KEY_ID		6  /* Generic KEY ID. */
623 #define	SADB_X_IDENTTYPE_ADDR_RANGE	7
624 
625 #define	SADB_IDENTTYPE_MAX 	7
626 
627 /*
628  * Protection DOI values for the SENSITIVITY extension.  There are no values
629  * currently, so the MAX is the only non-zero value available.
630  */
631 
632 #define	SADB_DPD_NONE	0
633 
634 #define	SADB_DPD_MAX	1
635 
636 /*
637  * Diagnostic codes.  These supplement error messages.  Be sure to
638  * update libipsecutil's keysock_diag() if you change any of these.
639  */
640 
641 #define	SADB_X_DIAGNOSTIC_PRESET		-1	/* Internal value. */
642 
643 #define	SADB_X_DIAGNOSTIC_NONE			0
644 
645 #define	SADB_X_DIAGNOSTIC_UNKNOWN_MSG		1
646 #define	SADB_X_DIAGNOSTIC_UNKNOWN_EXT		2
647 #define	SADB_X_DIAGNOSTIC_BAD_EXTLEN		3
648 #define	SADB_X_DIAGNOSTIC_UNKNOWN_SATYPE	4
649 #define	SADB_X_DIAGNOSTIC_SATYPE_NEEDED		5
650 #define	SADB_X_DIAGNOSTIC_NO_SADBS		6
651 #define	SADB_X_DIAGNOSTIC_NO_EXT		7
652 /* Bad address family value */
653 #define	SADB_X_DIAGNOSTIC_BAD_SRC_AF		8
654 /* in sockaddr->sa_family. */
655 #define	SADB_X_DIAGNOSTIC_BAD_DST_AF		9
656 #define	SADB_X_DIAGNOSTIC_BAD_PROXY_AF		10
657 #define	SADB_X_DIAGNOSTIC_AF_MISMATCH		11
658 
659 #define	SADB_X_DIAGNOSTIC_BAD_SRC		12
660 #define	SADB_X_DIAGNOSTIC_BAD_DST		13
661 
662 #define	SADB_X_DIAGNOSTIC_ALLOC_HSERR		14
663 #define	SADB_X_DIAGNOSTIC_BYTES_HSERR		15
664 #define	SADB_X_DIAGNOSTIC_ADDTIME_HSERR		16
665 #define	SADB_X_DIAGNOSTIC_USETIME_HSERR		17
666 
667 #define	SADB_X_DIAGNOSTIC_MISSING_SRC		18
668 #define	SADB_X_DIAGNOSTIC_MISSING_DST		19
669 #define	SADB_X_DIAGNOSTIC_MISSING_SA		20
670 #define	SADB_X_DIAGNOSTIC_MISSING_EKEY		21
671 #define	SADB_X_DIAGNOSTIC_MISSING_AKEY		22
672 #define	SADB_X_DIAGNOSTIC_MISSING_RANGE		23
673 
674 #define	SADB_X_DIAGNOSTIC_DUPLICATE_SRC		24
675 #define	SADB_X_DIAGNOSTIC_DUPLICATE_DST		25
676 #define	SADB_X_DIAGNOSTIC_DUPLICATE_SA		26
677 #define	SADB_X_DIAGNOSTIC_DUPLICATE_EKEY	27
678 #define	SADB_X_DIAGNOSTIC_DUPLICATE_AKEY	28
679 #define	SADB_X_DIAGNOSTIC_DUPLICATE_RANGE	29
680 
681 #define	SADB_X_DIAGNOSTIC_MALFORMED_SRC		30
682 #define	SADB_X_DIAGNOSTIC_MALFORMED_DST		31
683 #define	SADB_X_DIAGNOSTIC_MALFORMED_SA		32
684 #define	SADB_X_DIAGNOSTIC_MALFORMED_EKEY	33
685 #define	SADB_X_DIAGNOSTIC_MALFORMED_AKEY	34
686 #define	SADB_X_DIAGNOSTIC_MALFORMED_RANGE	35
687 
688 #define	SADB_X_DIAGNOSTIC_AKEY_PRESENT		36
689 #define	SADB_X_DIAGNOSTIC_EKEY_PRESENT		37
690 #define	SADB_X_DIAGNOSTIC_PROP_PRESENT		38
691 #define	SADB_X_DIAGNOSTIC_SUPP_PRESENT		39
692 
693 #define	SADB_X_DIAGNOSTIC_BAD_AALG		40
694 #define	SADB_X_DIAGNOSTIC_BAD_EALG		41
695 #define	SADB_X_DIAGNOSTIC_BAD_SAFLAGS		42
696 #define	SADB_X_DIAGNOSTIC_BAD_SASTATE		43
697 
698 #define	SADB_X_DIAGNOSTIC_BAD_AKEYBITS		44
699 #define	SADB_X_DIAGNOSTIC_BAD_EKEYBITS		45
700 
701 #define	SADB_X_DIAGNOSTIC_ENCR_NOTSUPP		46
702 
703 #define	SADB_X_DIAGNOSTIC_WEAK_EKEY		47
704 #define	SADB_X_DIAGNOSTIC_WEAK_AKEY		48
705 
706 #define	SADB_X_DIAGNOSTIC_DUPLICATE_KMP		49
707 #define	SADB_X_DIAGNOSTIC_DUPLICATE_KMC		50
708 
709 #define	SADB_X_DIAGNOSTIC_MISSING_NATT_LOC	51
710 #define	SADB_X_DIAGNOSTIC_MISSING_NATT_REM	52
711 #define	SADB_X_DIAGNOSTIC_DUPLICATE_NATT_LOC	53
712 #define	SADB_X_DIAGNOSTIC_DUPLICATE_NATT_REM	54
713 #define	SADB_X_DIAGNOSTIC_MALFORMED_NATT_LOC	55
714 #define	SADB_X_DIAGNOSTIC_MALFORMED_NATT_REM	56
715 #define	SADB_X_DIAGNOSTIC_DUPLICATE_NATT_PORTS	57
716 #define	SADB_X_DIAGNOSTIC_MAX			57
717 
718 /* Algorithm type for sadb_x_algdesc above... */
719 
720 #define	SADB_X_ALGTYPE_NONE		0
721 #define	SADB_X_ALGTYPE_AUTH		1
722 #define	SADB_X_ALGTYPE_CRYPT		2
723 #define	SADB_X_ALGTYPE_COMPRESS		3
724 
725 #define	SADB_X_ALGTYPE_MAX		3
726 
727 /* Key management protocol for sadb_x_kmc above... */
728 
729 #define	SADB_X_KMP_MANUAL	0
730 #define	SADB_X_KMP_IKE		1
731 #define	SADB_X_KMP_KINK		2
732 
733 #define	SADB_X_KMP_MAX		2
734 
735 /*
736  * Handy conversion macros.  Not part of the PF_KEY spec...
737  */
738 
739 #define	SADB_64TO8(x)	((x) << 3)
740 #define	SADB_8TO64(x)	((x) >> 3)
741 #define	SADB_8TO1(x)	((x) << 3)
742 #define	SADB_1TO8(x)	((x) >> 3)
743 
744 #ifdef	__cplusplus
745 }
746 #endif
747 
748 #endif	/* _NET_PFKEYV2_H */
749