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