ip_ipsp.h revision 1.118
1/*	$OpenBSD: ip_ipsp.h,v 1.118 2001/08/19 06:31:56 angelos Exp $	*/
2/*
3 * The authors of this code are John Ioannidis (ji@tla.org),
4 * Angelos D. Keromytis (kermit@csd.uch.gr),
5 * Niels Provos (provos@physnet.uni-hamburg.de) and
6 * Niklas Hallqvist (niklas@appli.se).
7 *
8 * The original version of this code was written by John Ioannidis
9 * for BSD/OS in Athens, Greece, in November 1995.
10 *
11 * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,
12 * by Angelos D. Keromytis.
13 *
14 * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis
15 * and Niels Provos.
16 *
17 * Additional features in 1999 by Angelos D. Keromytis and Niklas Hallqvist.
18 *
19 * Copyright (c) 1995, 1996, 1997, 1998, 1999 by John Ioannidis,
20 * Angelos D. Keromytis and Niels Provos.
21 * Copyright (c) 1999 Niklas Hallqvist.
22 * Copyright (c) 2001, Angelos D. Keromytis.
23 *
24 * Permission to use, copy, and modify this software with or without fee
25 * is hereby granted, provided that this entire notice is included in
26 * all copies of any software which is or includes a copy or
27 * modification of this software.
28 * You may use this code under the GNU public license if you so wish. Please
29 * contribute changes back to the authors under this freer than GPL license
30 * so that we may further the use of strong encryption without limitations to
31 * all.
32 *
33 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
34 * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
35 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
36 * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
37 * PURPOSE.
38 */
39
40#ifndef _NETINET_IPSP_H_
41#define _NETINET_IPSP_H_
42
43/* IPSP global definitions. */
44
45#include <sys/types.h>
46#include <sys/queue.h>
47#include <sys/timeout.h>
48#include <netinet/in.h>
49
50union sockaddr_union {
51	struct sockaddr		sa;
52	struct sockaddr_in	sin;
53	struct sockaddr_in6	sin6;
54};
55
56/* HMAC key sizes */
57#define	MD5HMAC96_KEYSIZE	16
58#define	SHA1HMAC96_KEYSIZE	20
59#define	RIPEMD160HMAC96_KEYSIZE	20
60
61#define	AH_HMAC_HASHLEN		12	/* 96 bits of authenticator */
62#define	AH_HMAC_RPLENGTH	4	/* 32 bits of replay counter */
63#define	AH_HMAC_INITIAL_RPL	1	/* Replay counter initial value */
64
65/* Authenticator lengths */
66#define	AH_MD5_ALEN		16
67#define	AH_SHA1_ALEN		20
68#define	AH_RMD160_ALEN		20
69#define	AH_ALEN_MAX		20 	/* Keep updated */
70
71/* Reserved SPI numbers */
72#define	SPI_LOCAL_USE		0
73#define	SPI_RESERVED_MIN	1
74#define	SPI_RESERVED_MAX	255
75
76/* Reserved CPI numbers */
77#define CPI_RESERVED_MIN	1
78#define CPI_RESERVED_MAX	255
79#define CPI_PRIVATE_MIN		61440
80#define CPI_PRIVATE_MAX		65535
81
82/* sysctl default values */
83#define	IPSEC_DEFAULT_EMBRYONIC_SA_TIMEOUT	60	/* 1 minute */
84#define	IPSEC_DEFAULT_PFS			1
85#define	IPSEC_DEFAULT_SOFT_ALLOCATIONS		0
86#define	IPSEC_DEFAULT_EXP_ALLOCATIONS		0
87#define	IPSEC_DEFAULT_SOFT_BYTES		0
88#define	IPSEC_DEFAULT_EXP_BYTES			0
89#define	IPSEC_DEFAULT_SOFT_TIMEOUT		80000
90#define	IPSEC_DEFAULT_EXP_TIMEOUT		86400
91#define	IPSEC_DEFAULT_SOFT_FIRST_USE		3600
92#define	IPSEC_DEFAULT_EXP_FIRST_USE		7200
93#define	IPSEC_DEFAULT_DEF_ENC			"aes"
94#define	IPSEC_DEFAULT_DEF_AUTH			"hmac-sha1"
95#define	IPSEC_DEFAULT_EXPIRE_ACQUIRE		30
96#define	IPSEC_DEFAULT_DEF_COMP			"deflate"
97
98struct sockaddr_encap {
99	u_int8_t	sen_len;		/* length */
100	u_int8_t	sen_family;		/* PF_KEY */
101	u_int16_t	sen_type;		/* see SENT_* */
102	union {
103		struct {				/* SENT_IP4 */
104			u_int8_t	Direction;
105			struct in_addr	Src;
106			struct in_addr	Dst;
107			u_int8_t	Proto;
108			u_int16_t	Sport;
109			u_int16_t	Dport;
110		} Sip4;
111
112		struct {				/* SENT_IP6 */
113			u_int8_t	Direction;
114			struct in6_addr	Src;
115			struct in6_addr	Dst;
116			u_int8_t	Proto;
117			u_int16_t	Sport;
118			u_int16_t	Dport;
119		} Sip6;
120
121		struct ipsec_policy	*PolicyHead;	/* SENT_IPSP */
122	} Sen;
123};
124
125#define	IPSP_DIRECTION_IN	0x1
126#define	IPSP_DIRECTION_OUT	0x2
127
128#define	sen_data		Sen.Data
129#define	sen_ip_src		Sen.Sip4.Src
130#define	sen_ip_dst		Sen.Sip4.Dst
131#define	sen_proto		Sen.Sip4.Proto
132#define	sen_sport		Sen.Sip4.Sport
133#define	sen_dport		Sen.Sip4.Dport
134#define	sen_direction		Sen.Sip4.Direction
135#define	sen_ip6_src		Sen.Sip6.Src
136#define	sen_ip6_dst		Sen.Sip6.Dst
137#define	sen_ip6_proto		Sen.Sip6.Proto
138#define	sen_ip6_sport		Sen.Sip6.Sport
139#define	sen_ip6_dport		Sen.Sip6.Dport
140#define	sen_ip6_direction	Sen.Sip6.Direction
141#define	sen_ipsp		Sen.PolicyHead
142
143/*
144 * The "type" is really part of the address as far as the routing
145 * system is concerned. By using only one bit in the type field
146 * for each type, we sort-of make sure that different types of
147 * encapsulation addresses won't be matched against the wrong type.
148 *
149 */
150
151#define	SENT_IP4	0x0001		/* data is two struct in_addr */
152#define	SENT_IPSP	0x0002		/* data as in IP4/6 plus SPI */
153#define	SENT_IP6	0x0004
154
155#define	SENT_LEN	sizeof(struct sockaddr_encap)
156
157struct ipsec_ref {
158	u_int16_t	ref_type;	/* Subtype of data */
159	int16_t		ref_len;	/* Length of data following */
160	int		ref_count;	/* Reference count */
161	int		ref_malloctype;	/* malloc(9) type, for freeing */
162};
163
164struct ipsec_acquire {
165	union sockaddr_union		ipa_addr;
166	u_int32_t			ipa_seq;
167	struct sockaddr_encap		ipa_info;
168	struct sockaddr_encap		ipa_mask;
169	struct timeout			ipa_timeout;
170	struct ipsec_policy		*ipa_policy;
171	TAILQ_ENTRY(ipsec_acquire)	ipa_ipo_next;
172	TAILQ_ENTRY(ipsec_acquire)	ipa_next;
173};
174
175struct ipsec_policy {
176	struct sockaddr_encap	ipo_addr;
177	struct sockaddr_encap	ipo_mask;
178
179	union sockaddr_union	ipo_src;	/* Local address to use */
180	union sockaddr_union	ipo_dst;	/* Remote gateway -- if it's zeroed:
181						 * - on output, we try to contact the
182						 * remote host directly (if needed).
183						 * - on input, we accept on if the
184						 * inner source is the same as the
185						 * outer source address, or if transport
186						 * mode was used.
187						 */
188
189	u_int64_t		ipo_last_searched;	/* Timestamp of last lookup */
190
191	u_int8_t		ipo_flags;	/* See IPSP_POLICY_* definitions */
192	u_int8_t		ipo_type;	/* USE/ACQUIRE/... */
193	u_int8_t		ipo_sproto;	/* ESP/AH; if zero, use system dflts */
194
195	struct tdb		*ipo_tdb;		/* Cached entry */
196
197	struct ipsec_ref	*ipo_srcid;
198	struct ipsec_ref	*ipo_dstid;
199	struct ipsec_ref	*ipo_local_cred;
200	struct ipsec_ref	*ipo_local_auth;
201
202	TAILQ_HEAD(ipo_acquires_head, ipsec_acquire) ipo_acquires; /* List of acquires */
203	TAILQ_ENTRY(ipsec_policy)	ipo_tdb_next;	/* List TDB policies */
204	TAILQ_ENTRY(ipsec_policy)	ipo_list;	/* List of all policies */
205};
206
207#define	IPSP_POLICY_NONE	0x0000	/* No flags set */
208#define	IPSP_POLICY_SOCKET	0x0001	/* Socket-attached policy */
209#define	IPSP_POLICY_STATIC	0x0002	/* Static policy */
210
211#define	IPSP_IPSEC_USE		0	/* Use if existing, don't acquire */
212#define	IPSP_IPSEC_ACQUIRE	1	/* Try acquire, let packet through */
213#define	IPSP_IPSEC_REQUIRE	2	/* Require SA */
214#define	IPSP_PERMIT		3	/* Permit traffic through */
215#define	IPSP_DENY		4	/* Deny traffic */
216#define	IPSP_IPSEC_DONTACQ	5	/* Require, but don't acquire */
217
218/* Notification types */
219#define	NOTIFY_SOFT_EXPIRE	0	/* Soft expiration of SA */
220#define	NOTIFY_HARD_EXPIRE	1	/* Hard expiration of SA */
221#define	NOTIFY_REQUEST_SA	2	/* Establish an SA */
222
223#define	NOTIFY_SATYPE_CONF	1	/* SA should do encryption */
224#define	NOTIFY_SATYPE_AUTH	2	/* SA should do authentication */
225#define	NOTIFY_SATYPE_TUNNEL	4	/* SA should use tunneling */
226#define NOTIFY_SATYPE_COMP	5       /* SA (IPCA) should use compression */
227
228/* Authentication types */
229#define	IPSP_AUTH_NONE		0
230#define	IPSP_AUTH_PASSPHRASE	1
231#define	IPSP_AUTH_RSA		2
232
233/* Credential types */
234#define	IPSP_CRED_NONE		0
235#define	IPSP_CRED_KEYNOTE	1
236#define	IPSP_CRED_X509		2
237
238/* Identity types */
239#define	IPSP_IDENTITY_NONE		0
240#define	IPSP_IDENTITY_PREFIX		1
241#define	IPSP_IDENTITY_FQDN		2
242#define	IPSP_IDENTITY_USERFQDN		3
243#define	IPSP_IDENTITY_CONNECTION	4
244
245/*
246 * For encapsulation routes are possible not only for the destination
247 * address but also for the protocol, source and destination ports
248 * if available
249 */
250
251struct route_enc {
252	struct rtentry		*re_rt;
253	struct sockaddr_encap	re_dst;
254};
255
256struct tdb {				/* tunnel descriptor block */
257	/*
258	 * Each TDB is on three hash tables: one keyed on dst/spi/sproto,
259	 * one keyed on dst/sproto, and one keyed on src/sproto. The first
260	 * is used for finding a specific TDB, the second for finding TDBs
261	 * TDBs for outgoing policy matching, and the third for incoming
262	 * policy matching. The following three fields maintain the hash
263	 * queues in those three tables.
264	 */
265	struct tdb	*tdb_hnext;	/* dst/spi/sproto table */
266	struct tdb	*tdb_anext;	/* dst/sproto table */
267	struct tdb	*tdb_snext;	/* src/sproto table */
268	struct tdb	*tdb_inext;
269	struct tdb	*tdb_onext;
270
271	struct xformsw		*tdb_xform;		/* Transform to use */
272	struct enc_xform	*tdb_encalgxform;	/* Enc algorithm */
273	struct auth_hash	*tdb_authalgxform;	/* Auth algorithm */
274	struct comp_algo	*tdb_compalgxform;	/* Compression algo */
275
276#define	TDBF_UNIQUE		0x00001	/* This should not be used by others */
277#define	TDBF_TIMER		0x00002	/* Absolute expiration timer in use */
278#define	TDBF_BYTES		0x00004	/* Check the byte counters */
279#define	TDBF_ALLOCATIONS	0x00008	/* Check the flows counters */
280#define	TDBF_INVALID		0x00010	/* This SPI is not valid yet/anymore */
281#define	TDBF_FIRSTUSE		0x00020	/* Expire after first use */
282#define	TDBF_HALFIV		0x00040	/* Use half-length IV (ESP old only) */
283#define	TDBF_SOFT_TIMER		0x00080	/* Soft expiration */
284#define	TDBF_SOFT_BYTES		0x00100	/* Soft expiration */
285#define	TDBF_SOFT_ALLOCATIONS	0x00200	/* Soft expiration */
286#define	TDBF_SOFT_FIRSTUSE	0x00400	/* Soft expiration */
287#define	TDBF_PFS		0x00800	/* Ask for PFS from Key Mgmt. */
288#define	TDBF_TUNNELING		0x01000	/* Force IP-IP encapsulation */
289#define	TDBF_NOREPLAY		0x02000	/* No replay counter present */
290#define	TDBF_RANDOMPADDING	0x04000	/* Random data in the ESP padding */
291#define	TDBF_SKIPCRYPTO		0x08000	/* Skip actual crypto processing */
292#define	TDBF_USEDTUNNEL		0x10000	/* Appended a tunnel header in past */
293
294	u_int32_t	tdb_flags;	/* Flags related to this TDB */
295
296	struct timeout	tdb_timer_tmo;
297	struct timeout	tdb_first_tmo;
298	struct timeout	tdb_stimer_tmo;
299	struct timeout	tdb_sfirst_tmo;
300
301	u_int32_t	tdb_seq;		/* Tracking number for PFKEY */
302	u_int32_t	tdb_exp_allocations;	/* Expire after so many flows */
303	u_int32_t	tdb_soft_allocations;	/* Expiration warning */
304	u_int32_t	tdb_cur_allocations;	/* Total number of allocs */
305
306	u_int64_t	tdb_exp_bytes;	/* Expire after so many bytes passed */
307	u_int64_t	tdb_soft_bytes;	/* Expiration warning */
308	u_int64_t	tdb_cur_bytes;	/* Current count of bytes */
309
310	u_int64_t	tdb_exp_timeout;	/* When does the SPI expire */
311	u_int64_t	tdb_soft_timeout;	/* Send soft-expire warning */
312	u_int64_t	tdb_established;	/* When was SPI established */
313
314	u_int64_t	tdb_first_use;		/* When was it first used */
315	u_int64_t	tdb_soft_first_use;	/* Soft warning */
316	u_int64_t	tdb_exp_first_use;	/* Expire if tdb_first_use +
317						 * tdb_exp_first_use <= curtime
318						 */
319
320	u_int64_t	tdb_last_used;	/* When was this SA last used */
321	u_int64_t	tdb_last_marked;/* Last SKIPCRYPTO status change */
322
323	u_int64_t	tdb_cryptoid;	/* Crypto session ID */
324
325	u_int32_t	tdb_spi;	/* SPI */
326	u_int16_t	tdb_amxkeylen;	/* Raw authentication key length */
327	u_int16_t	tdb_emxkeylen;	/* Raw encryption key length */
328	u_int16_t	tdb_ivlen;	/* IV length */
329	u_int8_t	tdb_sproto;	/* IPsec protocol */
330	u_int8_t	tdb_wnd;	/* Replay window */
331	u_int8_t	tdb_satype;	/* SA type (RFC2367, PF_KEY) */
332
333	union sockaddr_union	tdb_dst;	/* Destination address */
334	union sockaddr_union	tdb_src;	/* Source address */
335	union sockaddr_union	tdb_proxy;
336
337	u_int8_t	*tdb_amxkey;	/* Raw authentication key */
338	u_int8_t	*tdb_emxkey;	/* Raw encryption key */
339
340	u_int32_t	tdb_rpl;	/* Replay counter */
341	u_int32_t	tdb_bitmap;	/* Used for replay sliding window */
342	u_int32_t	tdb_initial;	/* Initial replay value */
343
344	u_int32_t	tdb_epoch;	/* Used by the kernfs interface */
345
346	u_int8_t	tdb_iv[4];	/* Used for HALF-IV ESP */
347
348	struct ipsec_ref	*tdb_local_cred;
349	struct ipsec_ref	*tdb_remote_cred;
350	struct ipsec_ref	*tdb_srcid;	/* Source ID for this SA */
351	struct ipsec_ref	*tdb_dstid;	/* Destination ID for this SA */
352	struct ipsec_ref	*tdb_local_auth;/* Local authentication material */
353	struct ipsec_ref	*tdb_remote_auth;/* Remote authentication material */
354
355	u_int32_t	tdb_mtu;	/* MTU at this point in the chain */
356	u_int64_t	tdb_mtutimeout;	/* When to ignore this entry */
357
358	TAILQ_HEAD(tdb_inp_head_in, inpcb)	tdb_inp_in;
359	TAILQ_HEAD(tdb_inp_head_out, inpcb)	tdb_inp_out;
360	TAILQ_HEAD(tdb_policy_head, ipsec_policy)	tdb_policy_head;
361};
362
363struct tdb_ident {
364	u_int32_t spi;
365	union sockaddr_union dst;
366	u_int8_t proto;
367};
368
369struct tdb_crypto {
370	u_int32_t		tc_spi;
371	union sockaddr_union	tc_dst;
372	u_int8_t		tc_proto;
373	int			tc_protoff;
374	int			tc_skip;
375	caddr_t			tc_ptr;
376};
377
378struct ipsecinit {
379	u_int8_t	*ii_enckey;
380	u_int8_t	*ii_authkey;
381	u_int16_t	ii_enckeylen;
382	u_int16_t	ii_authkeylen;
383	u_int8_t	ii_encalg;
384	u_int8_t	ii_authalg;
385	u_int8_t	ii_compalg;
386};
387
388struct xformsw {
389	u_short	xf_type;		/* Unique ID of xform */
390	u_short	xf_flags;		/* flags (see below) */
391	char	*xf_name;		/* human-readable name */
392	int	(*xf_attach)(void);	/* called at config time */
393	int	(*xf_init)(struct tdb *, struct xformsw *, struct ipsecinit *);
394	int	(*xf_zeroize)(struct tdb *); /* termination */
395	int	(*xf_input)(struct mbuf *, struct tdb *, int, int); /* input */
396	int	(*xf_output)(struct mbuf *, struct tdb *, struct mbuf **,
397	    int, int);        /* output */
398};
399
400/* xform IDs */
401#define	XF_IP4		1	/* IP inside IP */
402#define	XF_AH		2	/* AH */
403#define	XF_ESP		3	/* ESP */
404#define	XF_TCPSIGNATURE	5	/* TCP MD5 Signature option, RFC 2358 */
405#define	XF_IPCOMP	6	/* IPCOMP */
406
407/* xform attributes */
408#define	XFT_AUTH	0x0001
409#define	XFT_CONF	0x0100
410#define	XFT_COMP	0x1000
411
412#define	IPSEC_ZEROES_SIZE	256	/* Larger than an IP6 extension hdr. */
413#define	IPSEC_KERNFS_BUFSIZE	4096
414
415#if BYTE_ORDER == LITTLE_ENDIAN
416static __inline u_int64_t
417htonq(u_int64_t q)
418{
419	register u_int32_t u, l;
420	u = q >> 32;
421	l = (u_int32_t) q;
422
423	return htonl(u) | ((u_int64_t)htonl(l) << 32);
424}
425
426#define	ntohq(_x)	htonq(_x)
427
428#elif BYTE_ORDER == BIG_ENDIAN
429
430#define	htonq(_x)	(_x)
431#define	ntohq(_x)	htonq(_x)
432
433#else
434#error	"Please fix <machine/endian.h>"
435#endif
436
437#ifdef _KERNEL
438
439/*
440 * Protects all tdb lists.
441 * Must at least be splsoftnet (note: do not use splsoftclock as it is
442 * special on some architectures, assuming it is always an spl lowering
443 * operation).
444 */
445#define	spltdb	splsoftnet
446
447extern int encdebug;
448extern int ipsec_acl;
449extern int ipsec_keep_invalid;
450extern int ipsec_in_use;
451extern u_int64_t ipsec_last_added;
452extern int ipsec_require_pfs;
453extern int ipsec_expire_acquire;
454
455extern int ipsec_policy_pool_initialized;
456
457extern int ipsec_soft_allocations;
458extern int ipsec_exp_allocations;
459extern int ipsec_soft_bytes;
460extern int ipsec_exp_bytes;
461extern int ipsec_soft_timeout;
462extern int ipsec_exp_timeout;
463extern int ipsec_soft_first_use;
464extern int ipsec_exp_first_use;
465extern char ipsec_def_enc[];
466extern char ipsec_def_auth[];
467extern char ipsec_def_comp[];
468
469extern struct enc_xform enc_xform_des;
470extern struct enc_xform enc_xform_3des;
471extern struct enc_xform enc_xform_blf;
472extern struct enc_xform enc_xform_cast5;
473extern struct enc_xform enc_xform_skipjack;
474
475extern struct auth_hash auth_hash_hmac_md5_96;
476extern struct auth_hash auth_hash_hmac_sha1_96;
477extern struct auth_hash auth_hash_hmac_ripemd_160_96;
478
479extern struct comp_algo comp_algo_deflate;
480
481extern TAILQ_HEAD(ipsec_policy_head, ipsec_policy) ipsec_policy_head;
482extern TAILQ_HEAD(ipsec_acquire_head, ipsec_acquire) ipsec_acquire_head;
483
484extern struct xformsw xformsw[], *xformswNXFORMSW;
485
486/* Check if a given tdb has encryption, authentication and/or tunneling */
487#define	TDB_ATTRIB(x) (((x)->tdb_encalgxform ? NOTIFY_SATYPE_CONF : 0) | \
488		       ((x)->tdb_authalgxform ? NOTIFY_SATYPE_AUTH : 0) | \
489		       ((x)->tdb_compalgxform ? NOTIFY_SATYPE_COMP : 0))
490
491/* Traverse spi chain and get attributes */
492
493#define	SPI_CHAIN_ATTRIB(have, TDB_DIR, TDBP) do {\
494	int s = spltdb(); \
495	struct tdb *tmptdb = (TDBP); \
496	\
497	(have) = 0; \
498	while (tmptdb && tmptdb->tdb_xform) { \
499	        if (tmptdb == NULL || tmptdb->tdb_flags & TDBF_INVALID) \
500			break; \
501		(have) |= TDB_ATTRIB(tmptdb); \
502		tmptdb = tmptdb->TDB_DIR; \
503	} \
504	splx(s); \
505} while (0)
506
507/* Misc. */
508extern char *inet_ntoa4(struct in_addr);
509extern char *ipsp_address(union sockaddr_union);
510
511/* TDB management routines */
512extern void tdb_add_inp(struct tdb *, struct inpcb *, int);
513extern u_int32_t reserve_spi(u_int32_t, u_int32_t, union sockaddr_union *,
514    union sockaddr_union *, u_int8_t, int *);
515extern struct tdb *gettdb(u_int32_t, union sockaddr_union *, u_int8_t);
516extern struct tdb *gettdbbyaddr(union sockaddr_union *, struct ipsec_policy *,
517    struct mbuf *, int);
518extern struct tdb *gettdbbysrc(union sockaddr_union *, struct ipsec_policy *,
519    struct mbuf *, int);
520extern void puttdb(struct tdb *);
521extern void tdb_delete(struct tdb *);
522extern struct tdb *tdb_alloc(void);
523extern int tdb_init(struct tdb *, u_int16_t, struct ipsecinit *);
524extern int tdb_walk(int (*)(struct tdb *, void *, int), void *);
525
526/* XF_IP4 */
527extern int ipe4_attach(void);
528extern int ipe4_init(struct tdb *, struct xformsw *, struct ipsecinit *);
529extern int ipe4_zeroize(struct tdb *);
530extern int ipip_output(struct mbuf *, struct tdb *, struct mbuf **, int, int);
531extern void ipe4_input __P((struct mbuf *, ...));
532extern void ipip_input __P((struct mbuf *, int, struct ifnet *));
533
534#ifdef INET
535extern void ip4_input __P((struct mbuf *, ...));
536#endif /* INET */
537
538#ifdef INET6
539extern int ip4_input6 __P((struct mbuf **, int *, int));
540#endif /* INET */
541
542/* XF_ETHERIP */
543extern int etherip_output(struct mbuf *, struct tdb *, struct mbuf **,
544    int, int);
545extern void etherip_input __P((struct mbuf *, ...));
546
547/* XF_AH */
548extern int ah_attach(void);
549extern int ah_init(struct tdb *, struct xformsw *, struct ipsecinit *);
550extern int ah_zeroize(struct tdb *);
551extern int ah_output(struct mbuf *, struct tdb *, struct mbuf **, int, int);
552extern int ah_output_cb(void *);
553extern int ah_input(struct mbuf *, struct tdb *, int, int);
554extern int ah_input_cb(void *);
555extern int ah_sysctl(int *, u_int, void *, size_t *, void *, size_t);
556extern int ah_massage_headers(struct mbuf **, int, int, int, int);
557
558#ifdef INET
559extern void ah4_input __P((struct mbuf *, ...));
560extern int ah4_input_cb __P((struct mbuf *, ...));
561extern void *ah4_ctlinput __P((int, struct sockaddr *, void *));
562#endif /* INET */
563
564#ifdef INET6
565extern int ah6_input __P((struct mbuf **, int *, int));
566extern int ah6_input_cb __P((struct mbuf *, int, int));
567#endif /* INET6 */
568
569/* XF_ESP */
570extern int esp_attach(void);
571extern int esp_init(struct tdb *, struct xformsw *, struct ipsecinit *);
572extern int esp_zeroize(struct tdb *);
573extern int esp_output(struct mbuf *, struct tdb *, struct mbuf **, int, int);
574extern int esp_output_cb(void *);
575extern int esp_input(struct mbuf *, struct tdb *, int, int);
576extern int esp_input_cb(void *);
577extern int esp_sysctl(int *, u_int, void *, size_t *, void *, size_t);
578
579#ifdef INET
580extern void esp4_input __P((struct mbuf *, ...));
581extern int esp4_input_cb __P((struct mbuf *, ...));
582extern void *esp4_ctlinput __P((int, struct sockaddr *, void *));
583#endif /* INET */
584
585#ifdef INET6
586extern int esp6_input __P((struct mbuf **, int *, int));
587extern int esp6_input_cb __P((struct mbuf *, int, int));
588#endif /* INET6 */
589
590/* XF_IPCOMP */
591extern int ipcomp_attach(void);
592extern int ipcomp_init(struct tdb *, struct xformsw *, struct ipsecinit *);
593extern int ipcomp_zeroize(struct tdb *);
594extern int ipcomp_output(struct mbuf *, struct tdb *, struct mbuf **, int, int);
595extern int ipcomp_output_cb(void *);
596extern int ipcomp_input(struct mbuf *, struct tdb *, int, int);
597extern int ipcomp_input_cb(void *);
598extern int ipcomp_sysctl(int *, u_int, void *, size_t *, void *, size_t);
599
600#ifdef INET
601extern void ipcomp4_input __P((struct mbuf *, ...));
602extern int ipcomp4_input_cb __P((struct mbuf *, ...));
603#endif /* INET */
604
605#ifdef INET6
606extern int ipcomp6_input __P((struct mbuf **, int *, int));
607extern int ipcomp6_input_cb __P((struct mbuf *, int, int));
608#endif /* INET6 */
609
610/* XF_TCPSIGNATURE */
611extern int tcp_signature_tdb_attach __P((void));
612extern int tcp_signature_tdb_init __P((struct tdb *, struct xformsw *,
613    struct ipsecinit *));
614extern int tcp_signature_tdb_zeroize __P((struct tdb *));
615extern int tcp_signature_tdb_input __P((struct mbuf *, struct tdb *, int,
616    int));
617extern int tcp_signature_tdb_output __P((struct mbuf *, struct tdb *,
618    struct mbuf **, int, int));
619
620/* Padding */
621extern caddr_t m_pad(struct mbuf *, int);
622
623/* Replay window */
624extern int checkreplaywindow32(u_int32_t, u_int32_t, u_int32_t *, u_int32_t,
625    u_int32_t *);
626
627extern unsigned char ipseczeroes[];
628
629/* Packet processing */
630extern int ipsp_process_packet(struct mbuf *, struct tdb *, int, int);
631extern int ipsp_process_done(struct mbuf *, struct tdb *);
632extern struct tdb *ipsp_spd_lookup(struct mbuf *, int, int, int *, int,
633    struct tdb *, struct inpcb *);
634extern struct tdb *ipsp_spd_inp(struct mbuf *, int, int, int *, int,
635    struct tdb *, struct inpcb *, struct ipsec_policy *);
636extern int ipsec_common_input_cb(struct mbuf *, struct tdb *, int, int,
637    struct m_tag *);
638extern int ipsp_acquire_sa(struct ipsec_policy *, union sockaddr_union *,
639    union sockaddr_union *, struct sockaddr_encap *, struct mbuf *);
640extern struct ipsec_policy *ipsec_add_policy(struct sockaddr_encap *,
641    struct sockaddr_encap *, union sockaddr_union *, int, int);
642extern int ipsec_delete_policy(struct ipsec_policy *);
643extern struct ipsec_acquire *ipsp_pending_acquire(struct ipsec_policy *,
644    union sockaddr_union *);
645extern void ipsp_delete_acquire(void *);
646extern int ipsp_is_unspecified(union sockaddr_union);
647extern void ipsp_reffree(struct ipsec_ref *);
648extern void ipsp_skipcrypto_unmark(struct tdb_ident *);
649extern void ipsp_skipcrypto_mark(struct tdb_ident *);
650extern struct m_tag *ipsp_parse_headers(struct mbuf *, int, u_int8_t);
651extern int ipsp_ref_match(struct ipsec_ref *, struct ipsec_ref *);
652extern ssize_t ipsec_hdrsz(struct tdb *);
653extern void ipsec_adjust_mtu(struct mbuf *, u_int32_t);
654extern int ipsp_print_tdb(struct tdb *, char *);
655extern struct ipsec_acquire *ipsec_get_acquire(u_int32_t);
656#endif /* _KERNEL */
657#endif /* _NETINET_IPSP_H_ */
658