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