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