ip_ipsp.h revision 1.160
1/*	$OpenBSD: ip_ipsp.h,v 1.160 2015/01/19 18:36:51 deraadt 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
43struct m_tag;
44
45/* IPSP global definitions. */
46
47#include <sys/types.h>
48#ifdef _KERNEL
49#include <sys/timeout.h>
50#endif
51#include <sys/queue.h>
52#include <netinet/in.h>
53
54union sockaddr_union {
55	struct sockaddr		sa;
56	struct sockaddr_in	sin;
57	struct sockaddr_in6	sin6;
58};
59
60/* HMAC key sizes */
61#define	MD5HMAC96_KEYSIZE	16
62#define	SHA1HMAC96_KEYSIZE	20
63#define	RIPEMD160HMAC96_KEYSIZE	20
64#define	SHA2_256HMAC96_KEYSIZE	32
65#define	SHA2_384HMAC96_KEYSIZE	48
66#define	SHA2_512HMAC96_KEYSIZE	64
67
68#define	AH_HMAC_MAX_HASHLEN	32	/* 256 bits of authenticator for SHA512 */
69#define	AH_HMAC_RPLENGTH	4	/* 32 bits of replay counter */
70#define	AH_HMAC_INITIAL_RPL	1	/* Replay counter initial value */
71
72/* Authenticator lengths */
73#define	AH_MD5_ALEN		16
74#define	AH_SHA1_ALEN		20
75#define	AH_RMD160_ALEN		20
76#define	AH_SHA2_256_ALEN	32
77#define	AH_SHA2_384_ALEN	48
78#define	AH_SHA2_512_ALEN	64
79#define	AH_ALEN_MAX		64 	/* Keep updated */
80
81/* Reserved SPI numbers */
82#define	SPI_LOCAL_USE		0
83#define	SPI_RESERVED_MIN	1
84#define	SPI_RESERVED_MAX	255
85
86/* Reserved CPI numbers */
87#define CPI_RESERVED_MIN	1
88#define CPI_RESERVED_MAX	255
89#define CPI_PRIVATE_MIN		61440
90#define CPI_PRIVATE_MAX		65535
91
92/* sysctl default values */
93#define	IPSEC_DEFAULT_EMBRYONIC_SA_TIMEOUT	60	/* 1 minute */
94#define	IPSEC_DEFAULT_PFS			1
95#define	IPSEC_DEFAULT_SOFT_ALLOCATIONS		0
96#define	IPSEC_DEFAULT_EXP_ALLOCATIONS		0
97#define	IPSEC_DEFAULT_SOFT_BYTES		0
98#define	IPSEC_DEFAULT_EXP_BYTES			0
99#define	IPSEC_DEFAULT_SOFT_TIMEOUT		80000
100#define	IPSEC_DEFAULT_EXP_TIMEOUT		86400
101#define	IPSEC_DEFAULT_SOFT_FIRST_USE		3600
102#define	IPSEC_DEFAULT_EXP_FIRST_USE		7200
103#define	IPSEC_DEFAULT_DEF_ENC			"aes"
104#define	IPSEC_DEFAULT_DEF_AUTH			"hmac-sha1"
105#define	IPSEC_DEFAULT_EXPIRE_ACQUIRE		30
106#define	IPSEC_DEFAULT_DEF_COMP			"deflate"
107
108struct sockaddr_encap {
109	u_int8_t	sen_len;		/* length */
110	u_int8_t	sen_family;		/* PF_KEY */
111	u_int16_t	sen_type;		/* see SENT_* */
112	union {
113		struct {				/* SENT_IP4 */
114			u_int8_t	Direction;
115			struct in_addr	Src;
116			struct in_addr	Dst;
117			u_int8_t	Proto;
118			u_int16_t	Sport;
119			u_int16_t	Dport;
120		} Sip4;
121
122		struct {				/* SENT_IP6 */
123			u_int8_t	Direction;
124			struct in6_addr	Src;
125			struct in6_addr	Dst;
126			u_int8_t	Proto;
127			u_int16_t	Sport;
128			u_int16_t	Dport;
129		} Sip6;
130
131		struct ipsec_policy	*PolicyHead;	/* SENT_IPSP */
132	} Sen;
133};
134
135#define	IPSP_DIRECTION_IN	0x1
136#define	IPSP_DIRECTION_OUT	0x2
137
138#ifdef _KERNEL
139
140#define	sen_data		Sen.Data
141#define	sen_ip_src		Sen.Sip4.Src
142#define	sen_ip_dst		Sen.Sip4.Dst
143#define	sen_proto		Sen.Sip4.Proto
144#define	sen_sport		Sen.Sip4.Sport
145#define	sen_dport		Sen.Sip4.Dport
146#define	sen_direction		Sen.Sip4.Direction
147#define	sen_ip6_src		Sen.Sip6.Src
148#define	sen_ip6_dst		Sen.Sip6.Dst
149#define	sen_ip6_proto		Sen.Sip6.Proto
150#define	sen_ip6_sport		Sen.Sip6.Sport
151#define	sen_ip6_dport		Sen.Sip6.Dport
152#define	sen_ip6_direction	Sen.Sip6.Direction
153#define	sen_ipsp		Sen.PolicyHead
154
155/*
156 * The "type" is really part of the address as far as the routing
157 * system is concerned. By using only one bit in the type field
158 * for each type, we sort-of make sure that different types of
159 * encapsulation addresses won't be matched against the wrong type.
160 *
161 */
162
163#define	SENT_IP4	0x0001		/* data is two struct in_addr */
164#define	SENT_IPSP	0x0002		/* data as in IP4/6 plus SPI */
165#define	SENT_IP6	0x0004
166
167#define	SENT_LEN	sizeof(struct sockaddr_encap)
168
169struct ipsec_ref {
170	u_int16_t	ref_type;	/* Subtype of data */
171	int16_t		ref_len;	/* Length of data following */
172	int		ref_count;	/* Reference count */
173	int		ref_malloctype;	/* malloc(9) type, for freeing */
174};
175
176struct ipsec_acquire {
177	union sockaddr_union		ipa_addr;
178	u_int32_t			ipa_seq;
179	struct sockaddr_encap		ipa_info;
180	struct sockaddr_encap		ipa_mask;
181	struct timeout			ipa_timeout;
182	struct ipsec_policy		*ipa_policy;
183	struct inpcb                    *ipa_pcb;
184	TAILQ_ENTRY(ipsec_acquire)	ipa_ipo_next;
185	TAILQ_ENTRY(ipsec_acquire)	ipa_next;
186	TAILQ_ENTRY(ipsec_acquire)      ipa_inp_next;
187};
188
189struct ipsec_policy {
190	struct sockaddr_encap	ipo_addr;
191	struct sockaddr_encap	ipo_mask;
192
193	union sockaddr_union	ipo_src;	/* Local address to use */
194	union sockaddr_union	ipo_dst;	/* Remote gateway -- if it's zeroed:
195						 * - on output, we try to
196						 * contact the remote host
197						 * directly (if needed).
198						 * - on input, we accept on if
199						 * the inner source is the
200						 * same as the outer source
201						 * address, or if transport
202						 * mode was used.
203						 */
204
205	u_int64_t		ipo_last_searched;	/* Timestamp of last lookup */
206
207	u_int8_t		ipo_flags;	/* See IPSP_POLICY_* definitions */
208	u_int8_t		ipo_type;	/* USE/ACQUIRE/... */
209	u_int8_t		ipo_sproto;	/* ESP/AH; if zero, use system dflts */
210	u_int			ipo_rdomain;
211
212	int                     ipo_ref_count;
213
214	struct tdb		*ipo_tdb;		/* Cached entry */
215
216	struct ipsec_ref	*ipo_srcid;
217	struct ipsec_ref	*ipo_dstid;
218	struct ipsec_ref	*ipo_local_cred;
219	struct ipsec_ref	*ipo_local_auth;
220
221	TAILQ_HEAD(ipo_acquires_head, ipsec_acquire) ipo_acquires; /* List of acquires */
222	TAILQ_ENTRY(ipsec_policy)	ipo_tdb_next;	/* List TDB policies */
223	TAILQ_ENTRY(ipsec_policy)	ipo_list;	/* List of all policies */
224};
225
226#define	IPSP_POLICY_NONE	0x0000	/* No flags set */
227#define	IPSP_POLICY_SOCKET	0x0001	/* Socket-attached policy */
228#define	IPSP_POLICY_STATIC	0x0002	/* Static policy */
229
230#define	IPSP_IPSEC_USE		0	/* Use if existing, don't acquire */
231#define	IPSP_IPSEC_ACQUIRE	1	/* Try acquire, let packet through */
232#define	IPSP_IPSEC_REQUIRE	2	/* Require SA */
233#define	IPSP_PERMIT		3	/* Permit traffic through */
234#define	IPSP_DENY		4	/* Deny traffic */
235#define	IPSP_IPSEC_DONTACQ	5	/* Require, but don't acquire */
236
237/* Notification types */
238#define	NOTIFY_SOFT_EXPIRE	0	/* Soft expiration of SA */
239#define	NOTIFY_HARD_EXPIRE	1	/* Hard expiration of SA */
240#define	NOTIFY_REQUEST_SA	2	/* Establish an SA */
241
242#define	NOTIFY_SATYPE_CONF	1	/* SA should do encryption */
243#define	NOTIFY_SATYPE_AUTH	2	/* SA should do authentication */
244#define	NOTIFY_SATYPE_TUNNEL	4	/* SA should use tunneling */
245#define NOTIFY_SATYPE_COMP	5       /* SA (IPCA) should use compression */
246
247/* Authentication types */
248#define	IPSP_AUTH_NONE		0
249#define	IPSP_AUTH_PASSPHRASE	1
250#define	IPSP_AUTH_RSA		2
251
252/* Credential types */
253#define	IPSP_CRED_NONE		0
254#define	IPSP_CRED_KEYNOTE	1
255#define	IPSP_CRED_X509		2
256
257/* Identity types */
258#define	IPSP_IDENTITY_NONE		0
259#define	IPSP_IDENTITY_PREFIX		1
260#define	IPSP_IDENTITY_FQDN		2
261#define	IPSP_IDENTITY_USERFQDN		3
262#define	IPSP_IDENTITY_CONNECTION	4
263
264struct tdb {				/* tunnel descriptor block */
265	/*
266	 * Each TDB is on three hash tables: one keyed on dst/spi/sproto,
267	 * one keyed on dst/sproto, and one keyed on src/sproto. The first
268	 * is used for finding a specific TDB, the second for finding TDBs
269	 * for outgoing policy matching, and the third for incoming
270	 * policy matching. The following three fields maintain the hash
271	 * queues in those three tables.
272	 */
273	struct tdb	*tdb_hnext;	/* dst/spi/sproto table */
274	struct tdb	*tdb_anext;	/* dst/sproto table */
275	struct tdb	*tdb_snext;	/* src/sproto table */
276	struct tdb	*tdb_inext;
277	struct tdb	*tdb_onext;
278
279	struct xformsw		*tdb_xform;		/* Transform to use */
280	struct enc_xform	*tdb_encalgxform;	/* Enc algorithm */
281	struct auth_hash	*tdb_authalgxform;	/* Auth algorithm */
282	struct comp_algo	*tdb_compalgxform;	/* Compression algo */
283
284#define	TDBF_UNIQUE		0x00001	/* This should not be used by others */
285#define	TDBF_TIMER		0x00002	/* Absolute expiration timer in use */
286#define	TDBF_BYTES		0x00004	/* Check the byte counters */
287#define	TDBF_ALLOCATIONS	0x00008	/* Check the flows counters */
288#define	TDBF_INVALID		0x00010	/* This SPI is not valid yet/anymore */
289#define	TDBF_FIRSTUSE		0x00020	/* Expire after first use */
290#define	TDBF_SOFT_TIMER		0x00080	/* Soft expiration */
291#define	TDBF_SOFT_BYTES		0x00100	/* Soft expiration */
292#define	TDBF_SOFT_ALLOCATIONS	0x00200	/* Soft expiration */
293#define	TDBF_SOFT_FIRSTUSE	0x00400	/* Soft expiration */
294#define	TDBF_PFS		0x00800	/* Ask for PFS from Key Mgmt. */
295#define	TDBF_TUNNELING		0x01000	/* Force IP-IP encapsulation */
296#define	TDBF_SKIPCRYPTO		0x08000	/* Skip actual crypto processing */
297#define	TDBF_USEDTUNNEL		0x10000	/* Appended a tunnel header in past */
298#define	TDBF_UDPENCAP		0x20000	/* UDP encapsulation */
299#define	TDBF_PFSYNC		0x40000	/* TDB will be synced */
300#define	TDBF_PFSYNC_RPL		0x80000	/* Replay counter should be bumped */
301#define	TDBF_ESN		0x100000 /* 64-bit sequence numbers (ESN) */
302
303	u_int32_t	tdb_flags;	/* Flags related to this TDB */
304
305	struct timeout	tdb_timer_tmo;
306	struct timeout	tdb_first_tmo;
307	struct timeout	tdb_stimer_tmo;
308	struct timeout	tdb_sfirst_tmo;
309
310	u_int32_t	tdb_seq;		/* Tracking number for PFKEY */
311	u_int32_t	tdb_exp_allocations;	/* Expire after so many flows */
312	u_int32_t	tdb_soft_allocations;	/* Expiration warning */
313	u_int32_t	tdb_cur_allocations;	/* Total number of allocs */
314
315	u_int64_t	tdb_exp_bytes;	/* Expire after so many bytes passed */
316	u_int64_t	tdb_soft_bytes;	/* Expiration warning */
317	u_int64_t	tdb_cur_bytes;	/* Current count of bytes */
318
319	u_int64_t	tdb_exp_timeout;	/* When does the SPI expire */
320	u_int64_t	tdb_soft_timeout;	/* Send soft-expire warning */
321	u_int64_t	tdb_established;	/* When was SPI established */
322
323	u_int64_t	tdb_first_use;		/* When was it first used */
324	u_int64_t	tdb_soft_first_use;	/* Soft warning */
325	u_int64_t	tdb_exp_first_use;	/* Expire if tdb_first_use +
326						 * tdb_exp_first_use <= curtime
327						 */
328
329	u_int64_t	tdb_last_used;	/* When was this SA last used */
330	u_int64_t	tdb_last_marked;/* Last SKIPCRYPTO status change */
331
332	u_int64_t	tdb_cryptoid;	/* Crypto session ID */
333
334	u_int32_t	tdb_spi;	/* SPI */
335	u_int16_t	tdb_amxkeylen;	/* Raw authentication key length */
336	u_int16_t	tdb_emxkeylen;	/* Raw encryption key length */
337	u_int16_t	tdb_ivlen;	/* IV length */
338	u_int8_t	tdb_sproto;	/* IPsec protocol */
339	u_int8_t	tdb_wnd;	/* Replay window */
340	u_int8_t	tdb_satype;	/* SA type (RFC2367, PF_KEY) */
341	u_int8_t	tdb_updates;	/* pfsync update counter */
342
343	union sockaddr_union	tdb_dst;	/* Destination address */
344	union sockaddr_union	tdb_src;	/* Source address */
345	union sockaddr_union	tdb_proxy;
346
347	u_int8_t	*tdb_amxkey;	/* Raw authentication key */
348	u_int8_t	*tdb_emxkey;	/* Raw encryption key */
349
350#define TDB_REPLAYWASTE	32
351#define TDB_REPLAYMAX	(2100+TDB_REPLAYWASTE)
352
353	u_int64_t	tdb_rpl;	/* Replay counter */
354	u_int32_t	tdb_seen[howmany(TDB_REPLAYMAX, 32)]; /* Anti-replay window */
355
356	u_int8_t	tdb_iv[4];	/* Used for HALF-IV ESP */
357
358	struct ipsec_ref	*tdb_local_cred;
359	struct ipsec_ref	*tdb_remote_cred;
360	struct ipsec_ref	*tdb_srcid;	/* Source ID for this SA */
361	struct ipsec_ref	*tdb_dstid;	/* Destination ID for this SA */
362	struct ipsec_ref	*tdb_local_auth;/* Local authentication material */
363	struct ipsec_ref	*tdb_remote_auth;/* Remote authentication material */
364
365	u_int32_t	tdb_mtu;	/* MTU at this point in the chain */
366	u_int64_t	tdb_mtutimeout;	/* When to ignore this entry */
367
368	u_int16_t	tdb_udpencap_port;	/* Peer UDP port */
369
370	u_int16_t	tdb_tag;		/* Packet filter tag */
371	u_int32_t	tdb_tap;		/* Alternate enc(4) interface */
372
373	u_int		tdb_rdomain;		/* Routing domain */
374
375	struct sockaddr_encap   tdb_filter; /* What traffic is acceptable */
376	struct sockaddr_encap   tdb_filtermask; /* And the mask */
377
378	TAILQ_HEAD(tdb_inp_head_in, inpcb)	tdb_inp_in;
379	TAILQ_HEAD(tdb_inp_head_out, inpcb)	tdb_inp_out;
380	TAILQ_HEAD(tdb_policy_head, ipsec_policy)	tdb_policy_head;
381	TAILQ_ENTRY(tdb)	tdb_sync_entry;
382};
383
384#endif /* _KERNEL */
385
386struct tdb_ident {
387	u_int32_t spi;
388	union sockaddr_union dst;
389	u_int8_t proto;
390	u_int rdomain;
391};
392
393struct tdb_crypto {
394	u_int32_t		tc_spi;
395	union sockaddr_union	tc_dst;
396	u_int8_t		tc_proto;
397	int			tc_protoff;
398	int			tc_skip;
399	caddr_t			tc_ptr;
400	u_int			tc_rdomain;
401};
402
403struct ipsecinit {
404	u_int8_t	*ii_enckey;
405	u_int8_t	*ii_authkey;
406	u_int16_t	ii_enckeylen;
407	u_int16_t	ii_authkeylen;
408	u_int8_t	ii_encalg;
409	u_int8_t	ii_authalg;
410	u_int8_t	ii_compalg;
411};
412
413/* xform IDs */
414#define	XF_IP4		1	/* IP inside IP */
415#define	XF_AH		2	/* AH */
416#define	XF_ESP		3	/* ESP */
417#define	XF_TCPSIGNATURE	5	/* TCP MD5 Signature option, RFC 2358 */
418#define	XF_IPCOMP	6	/* IPCOMP */
419
420/* xform attributes */
421#define	XFT_AUTH	0x0001
422#define	XFT_CONF	0x0100
423#define	XFT_COMP	0x1000
424
425#define	IPSEC_ZEROES_SIZE	256	/* Larger than an IP6 extension hdr. */
426
427#ifdef _KERNEL
428
429struct xformsw {
430	u_short	xf_type;		/* Unique ID of xform */
431	u_short	xf_flags;		/* flags (see below) */
432	char	*xf_name;		/* human-readable name */
433	int	(*xf_attach)(void);	/* called at config time */
434	int	(*xf_init)(struct tdb *, struct xformsw *, struct ipsecinit *);
435	int	(*xf_zeroize)(struct tdb *); /* termination */
436	int	(*xf_input)(struct mbuf *, struct tdb *, int, int); /* input */
437	int	(*xf_output)(struct mbuf *, struct tdb *, struct mbuf **,
438	    int, int);        /* output */
439};
440
441extern int ipsec_in_use;
442extern u_int64_t ipsec_last_added;
443extern int ipsec_policy_pool_initialized;
444
445extern int ipsec_keep_invalid;		/* lifetime of embryonic SAs (in sec) */
446extern int ipsec_require_pfs;		/* use Perfect Forward Secrecy */
447extern int ipsec_expire_acquire;	/* wait for security assoc. (in sec) */
448extern int ipsec_soft_allocations;	/* flows/SA before renegotiation */
449extern int ipsec_exp_allocations;	/* num. of flows/SA before it expires */
450extern int ipsec_soft_bytes;		/* bytes/SA before renegotiation */
451extern int ipsec_exp_bytes;		/* num of bytes/SA before it expires */
452extern int ipsec_soft_timeout;		/* seconds/SA before renegotiation */
453extern int ipsec_exp_timeout;		/* seconds/SA before it expires */
454extern int ipsec_soft_first_use;	/* seconds between 1st asso & renego */
455extern int ipsec_exp_first_use;		/* seconds between 1st asso & expire */
456
457extern char ipsec_def_enc[];
458extern char ipsec_def_auth[];
459extern char ipsec_def_comp[];
460
461extern struct enc_xform enc_xform_des;
462extern struct enc_xform enc_xform_3des;
463extern struct enc_xform enc_xform_blf;
464extern struct enc_xform enc_xform_cast5;
465
466extern struct auth_hash auth_hash_hmac_md5_96;
467extern struct auth_hash auth_hash_hmac_sha1_96;
468extern struct auth_hash auth_hash_hmac_ripemd_160_96;
469
470extern struct comp_algo comp_algo_deflate;
471
472extern TAILQ_HEAD(ipsec_policy_head, ipsec_policy) ipsec_policy_head;
473extern TAILQ_HEAD(ipsec_acquire_head, ipsec_acquire) ipsec_acquire_head;
474
475/* Check if a given tdb has encryption, authentication and/or tunneling */
476#define	TDB_ATTRIB(x) (((x)->tdb_encalgxform ? NOTIFY_SATYPE_CONF : 0) | \
477		       ((x)->tdb_authalgxform ? NOTIFY_SATYPE_AUTH : 0) | \
478		       ((x)->tdb_compalgxform ? NOTIFY_SATYPE_COMP : 0))
479
480/* Traverse spi chain and get attributes */
481
482#define	SPI_CHAIN_ATTRIB(have, TDB_DIR, TDBP)				\
483do {									\
484	int s = splsoftnet();						\
485	struct tdb *tmptdb = (TDBP);					\
486									\
487	(have) = 0;							\
488	while (tmptdb && tmptdb->tdb_xform) {				\
489	        if (tmptdb == NULL || tmptdb->tdb_flags & TDBF_INVALID)	\
490			break;						\
491		(have) |= TDB_ATTRIB(tmptdb);				\
492		tmptdb = tmptdb->TDB_DIR;				\
493	}								\
494	splx(s);							\
495} while (/* CONSTCOND */ 0)
496
497/* Misc. */
498uint8_t	get_sa_require(struct inpcb *);
499#ifdef ENCDEBUG
500const char *ipsp_address(union sockaddr_union);
501#endif /* ENCDEBUG */
502
503/* TDB management routines */
504void	tdb_add_inp(struct tdb *, struct inpcb *, int);
505uint32_t reserve_spi(u_int, u_int32_t, u_int32_t, union sockaddr_union *,
506		union sockaddr_union *, u_int8_t, int *);
507struct	tdb *gettdb(u_int, u_int32_t, union sockaddr_union *, u_int8_t);
508struct	tdb *gettdbbyaddr(u_int, union sockaddr_union *, u_int8_t,
509		struct ipsec_ref *, struct ipsec_ref *, struct ipsec_ref *,
510		struct mbuf *, int, struct sockaddr_encap *,
511		struct sockaddr_encap *);
512struct	tdb *gettdbbysrc(u_int, union sockaddr_union *, u_int8_t,
513		struct ipsec_ref *, struct ipsec_ref *, struct mbuf *, int,
514		struct sockaddr_encap *, struct sockaddr_encap *);
515struct	tdb *gettdbbysrcdst(u_int, u_int32_t, union sockaddr_union *,
516		union sockaddr_union *, u_int8_t);
517void	puttdb(struct tdb *);
518void	tdb_delete(struct tdb *);
519struct	tdb *tdb_alloc(u_int);
520void	tdb_free(struct tdb *);
521int	tdb_init(struct tdb *, u_int16_t, struct ipsecinit *);
522int	tdb_walk(u_int, int (*)(struct tdb *, void *, int), void *);
523
524/* XF_IP4 */
525int	ipe4_attach(void);
526int	ipe4_init(struct tdb *, struct xformsw *, struct ipsecinit *);
527int	ipe4_zeroize(struct tdb *);
528void	ipe4_input(struct mbuf *, ...);
529void	ipip_input(struct mbuf *, int, struct ifnet *, int);
530int	ipip_output(struct mbuf *, struct tdb *, struct mbuf **, int, int);
531
532void	ip4_input(struct mbuf *, ...);
533
534#ifdef INET6
535int	ip4_input6(struct mbuf **, int *, int);
536#endif /* INET */
537
538/* XF_AH */
539int 	ah_attach(void);
540int 	ah_init(struct tdb *, struct xformsw *, struct ipsecinit *);
541int 	ah_zeroize(struct tdb *);
542int	ah_input(struct mbuf *, struct tdb *, int, int);
543int	ah_output(struct mbuf *, struct tdb *, struct mbuf **, int, int);
544int	ah_sysctl(int *, u_int, void *, size_t *, void *, size_t);
545
546void	ah4_input(struct mbuf *, ...);
547void	*ah4_ctlinput(int, struct sockaddr *, u_int, void *);
548void	*udpencap_ctlinput(int, struct sockaddr *, u_int, void *);
549
550#ifdef INET6
551int	ah6_input(struct mbuf **, int *, int);
552#endif /* INET6 */
553
554/* XF_ESP */
555int	esp_attach(void);
556int	esp_init(struct tdb *, struct xformsw *, struct ipsecinit *);
557int	esp_zeroize(struct tdb *);
558int	esp_input(struct mbuf *, struct tdb *, int, int);
559int	esp_output(struct mbuf *, struct tdb *, struct mbuf **, int, int);
560int	esp_sysctl(int *, u_int, void *, size_t *, void *, size_t);
561
562void	esp4_input(struct mbuf *, ...);
563void	*esp4_ctlinput(int, struct sockaddr *, u_int, void *);
564
565#ifdef INET6
566int 	esp6_input(struct mbuf **, int *, int);
567#endif /* INET6 */
568
569/* XF_IPCOMP */
570int	ipcomp_attach(void);
571int	ipcomp_init(struct tdb *, struct xformsw *, struct ipsecinit *);
572int	ipcomp_zeroize(struct tdb *);
573int	ipcomp_input(struct mbuf *, struct tdb *, int, int);
574int	ipcomp_output(struct mbuf *, struct tdb *, struct mbuf **, int, int);
575int	ipcomp_sysctl(int *, u_int, void *, size_t *, void *, size_t);
576
577void	ipcomp4_input(struct mbuf *, ...);
578
579#ifdef INET6
580int	ipcomp6_input(struct mbuf **, int *, int);
581#endif /* INET6 */
582
583/* XF_TCPSIGNATURE */
584int	tcp_signature_tdb_attach(void);
585int	tcp_signature_tdb_init(struct tdb *, struct xformsw *,
586	    struct ipsecinit *);
587int	tcp_signature_tdb_zeroize(struct tdb *);
588int	tcp_signature_tdb_input(struct mbuf *, struct tdb *, int, int);
589int	tcp_signature_tdb_output(struct mbuf *, struct tdb *, struct mbuf **,
590	  int, int);
591
592/* Replay window */
593int	checkreplaywindow(struct tdb *, u_int32_t, u_int32_t *, int);
594
595/* Packet processing */
596int	ipsp_process_packet(struct mbuf *, struct tdb *, int, int);
597int	ipsp_process_done(struct mbuf *, struct tdb *);
598struct	tdb *ipsp_spd_lookup(struct mbuf *, int, int, int *, int,
599	    struct tdb *, struct inpcb *, u_int32_t);
600struct	tdb *ipsp_spd_inp(struct mbuf *, int, int, int *, int,
601	    struct tdb *, struct inpcb *, struct ipsec_policy *);
602int	ipsp_is_unspecified(union sockaddr_union);
603int	ipsp_ref_match(struct ipsec_ref *, struct ipsec_ref *);
604void	ipsp_reffree(struct ipsec_ref *);
605void	ipsp_skipcrypto_mark(struct tdb_ident *);
606void	ipsp_skipcrypto_unmark(struct tdb_ident *);
607int	ipsp_aux_match(struct tdb *, struct ipsec_ref *, struct ipsec_ref *,
608	    struct ipsec_ref *, struct ipsec_ref *, struct sockaddr_encap *,
609	    struct sockaddr_encap *);
610
611int	ipsec_common_input(struct mbuf *, int, int, int, int, int);
612int	ipsec_common_input_cb(struct mbuf *, struct tdb *, int, int,
613	    struct m_tag *);
614int	ipsec_delete_policy(struct ipsec_policy *);
615ssize_t	ipsec_hdrsz(struct tdb *);
616void	ipsec_adjust_mtu(struct mbuf *, u_int32_t);
617struct	ipsec_policy *ipsec_add_policy(struct inpcb *, int, int);
618struct	ipsec_acquire *ipsec_get_acquire(u_int32_t);
619
620#endif /* _KERNEL */
621#endif /* _NETINET_IPSP_H_ */
622