ipsec.h revision 253081
1105197Ssam/*	$FreeBSD: head/sys/netipsec/ipsec.h 253081 2013-07-09 09:32:06Z ae $	*/
2105197Ssam/*	$KAME: ipsec.h,v 1.53 2001/11/20 08:32:38 itojun Exp $	*/
3105197Ssam
4139823Simp/*-
5105197Ssam * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6105197Ssam * All rights reserved.
7105197Ssam *
8105197Ssam * Redistribution and use in source and binary forms, with or without
9105197Ssam * modification, are permitted provided that the following conditions
10105197Ssam * are met:
11105197Ssam * 1. Redistributions of source code must retain the above copyright
12105197Ssam *    notice, this list of conditions and the following disclaimer.
13105197Ssam * 2. Redistributions in binary form must reproduce the above copyright
14105197Ssam *    notice, this list of conditions and the following disclaimer in the
15105197Ssam *    documentation and/or other materials provided with the distribution.
16105197Ssam * 3. Neither the name of the project nor the names of its contributors
17105197Ssam *    may be used to endorse or promote products derived from this software
18105197Ssam *    without specific prior written permission.
19105197Ssam *
20105197Ssam * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21105197Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22105197Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23105197Ssam * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24105197Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25105197Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26105197Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27105197Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28105197Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29105197Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30105197Ssam * SUCH DAMAGE.
31105197Ssam */
32105197Ssam
33105197Ssam/*
34105197Ssam * IPsec controller part.
35105197Ssam */
36105197Ssam
37105197Ssam#ifndef _NETIPSEC_IPSEC_H_
38105197Ssam#define _NETIPSEC_IPSEC_H_
39105197Ssam
40105197Ssam#if defined(_KERNEL) && !defined(_LKM) && !defined(KLD_MODULE)
41105197Ssam#include "opt_inet.h"
42105197Ssam#include "opt_ipsec.h"
43105197Ssam#endif
44105197Ssam
45105197Ssam#include <net/pfkeyv2.h>
46105197Ssam#include <netipsec/keydb.h>
47105197Ssam
48105197Ssam#ifdef _KERNEL
49105197Ssam
50179067Sgnn#define	IPSEC_ASSERT(_c,_m) KASSERT(_c, _m)
51179067Sgnn
52179067Sgnn#define	IPSEC_IS_PRIVILEGED_SO(_so) \
53179067Sgnn	((_so)->so_cred != NULL && \
54179067Sgnn	 priv_check_cred((_so)->so_cred, PRIV_NETINET_IPSEC, 0) \
55179067Sgnn	 == 0)
56179067Sgnn
57105197Ssam/*
58105197Ssam * Security Policy Index
59105197Ssam * Ensure that both address families in the "src" and "dst" are same.
60105197Ssam * When the value of the ul_proto is ICMPv6, the port field in "src"
61105197Ssam * specifies ICMPv6 type, and the port field in "dst" specifies ICMPv6 code.
62105197Ssam */
63105197Ssamstruct secpolicyindex {
64196882Spjd	u_int8_t dir;			/* direction of packet flow, see below */
65105197Ssam	union sockaddr_union src;	/* IP src address for SP */
66105197Ssam	union sockaddr_union dst;	/* IP dst address for SP */
67105197Ssam	u_int8_t prefs;			/* prefix length in bits for src */
68105197Ssam	u_int8_t prefd;			/* prefix length in bits for dst */
69105197Ssam	u_int16_t ul_proto;		/* upper layer Protocol */
70105197Ssam#ifdef notyet
71105197Ssam	uid_t uids;
72105197Ssam	uid_t uidd;
73105197Ssam	gid_t gids;
74105197Ssam	gid_t gidd;
75105197Ssam#endif
76105197Ssam};
77105197Ssam
78105197Ssam/* Security Policy Data Base */
79105197Ssamstruct secpolicy {
80105197Ssam	LIST_ENTRY(secpolicy) chain;
81119643Ssam	struct mtx lock;
82105197Ssam
83105197Ssam	u_int refcnt;			/* reference count */
84105197Ssam	struct secpolicyindex spidx;	/* selector */
85105197Ssam	u_int32_t id;			/* It's unique number on the system. */
86105197Ssam	u_int state;			/* 0: dead, others: alive */
87105197Ssam#define IPSEC_SPSTATE_DEAD	0
88105197Ssam#define IPSEC_SPSTATE_ALIVE	1
89120585Ssam	u_int16_t policy;		/* policy_type per pfkeyv2.h */
90120585Ssam	u_int16_t scangen;		/* scan generation # */
91105197Ssam	struct ipsecrequest *req;
92105197Ssam				/* pointer to the ipsec request tree, */
93105197Ssam				/* if policy == IPSEC else this value == NULL.*/
94105197Ssam
95105197Ssam	/*
96105197Ssam	 * lifetime handler.
97105197Ssam	 * the policy can be used without limitiation if both lifetime and
98105197Ssam	 * validtime are zero.
99105197Ssam	 * "lifetime" is passed by sadb_lifetime.sadb_lifetime_addtime.
100105197Ssam	 * "validtime" is passed by sadb_lifetime.sadb_lifetime_usetime.
101105197Ssam	 */
102120585Ssam	time_t created;		/* time created the policy */
103120585Ssam	time_t lastused;	/* updated every when kernel sends a packet */
104105197Ssam	long lifetime;		/* duration of the lifetime of this policy */
105105197Ssam	long validtime;		/* duration this policy is valid without use */
106105197Ssam};
107105197Ssam
108120585Ssam#define	SECPOLICY_LOCK_INIT(_sp) \
109120585Ssam	mtx_init(&(_sp)->lock, "ipsec policy", NULL, MTX_DEF)
110120585Ssam#define	SECPOLICY_LOCK(_sp)		mtx_lock(&(_sp)->lock)
111120585Ssam#define	SECPOLICY_UNLOCK(_sp)		mtx_unlock(&(_sp)->lock)
112120585Ssam#define	SECPOLICY_LOCK_DESTROY(_sp)	mtx_destroy(&(_sp)->lock)
113120585Ssam#define	SECPOLICY_LOCK_ASSERT(_sp)	mtx_assert(&(_sp)->lock, MA_OWNED)
114120585Ssam
115105197Ssam/* Request for IPsec */
116105197Ssamstruct ipsecrequest {
117105197Ssam	struct ipsecrequest *next;
118105197Ssam				/* pointer to next structure */
119105197Ssam				/* If NULL, it means the end of chain. */
120105197Ssam	struct secasindex saidx;/* hint for search proper SA */
121105197Ssam				/* if __ss_len == 0 then no address specified.*/
122105197Ssam	u_int level;		/* IPsec level defined below. */
123105197Ssam
124105197Ssam	struct secasvar *sav;	/* place holder of SA for use */
125105197Ssam	struct secpolicy *sp;	/* back pointer to SP */
126220206Sfabient	struct rwlock lock;	/* to interlock updates */
127105197Ssam};
128105197Ssam
129120585Ssam/*
130120585Ssam * Need recursion for when crypto callbacks happen directly,
131120585Ssam * as in the case of software crypto.  Need to look at how
132120585Ssam * hard it is to remove this...
133120585Ssam */
134120585Ssam#define	IPSECREQUEST_LOCK_INIT(_isr) \
135220206Sfabient	rw_init_flags(&(_isr)->lock, "ipsec request", RW_RECURSE)
136220206Sfabient#define	IPSECREQUEST_LOCK(_isr)		rw_rlock(&(_isr)->lock)
137220206Sfabient#define	IPSECREQUEST_UNLOCK(_isr)	rw_runlock(&(_isr)->lock)
138220206Sfabient#define	IPSECREQUEST_WLOCK(_isr)	rw_wlock(&(_isr)->lock)
139220206Sfabient#define	IPSECREQUEST_WUNLOCK(_isr)	rw_wunlock(&(_isr)->lock)
140220206Sfabient#define	IPSECREQUEST_UPGRADE(_isr)	rw_try_upgrade(&(_isr)->lock)
141220206Sfabient#define	IPSECREQUEST_DOWNGRADE(_isr)	rw_downgrade(&(_isr)->lock)
142220206Sfabient#define	IPSECREQUEST_LOCK_DESTROY(_isr)	rw_destroy(&(_isr)->lock)
143220206Sfabient#define	IPSECREQUEST_LOCK_ASSERT(_isr)	rw_assert(&(_isr)->lock, RA_LOCKED)
144120585Ssam
145105197Ssam/* security policy in PCB */
146105197Ssamstruct inpcbpolicy {
147105197Ssam	struct secpolicy *sp_in;
148105197Ssam	struct secpolicy *sp_out;
149105197Ssam	int priv;			/* privileged socket ? */
150105197Ssam};
151105197Ssam
152105197Ssam/* SP acquiring list table. */
153105197Ssamstruct secspacq {
154105197Ssam	LIST_ENTRY(secspacq) chain;
155105197Ssam
156105197Ssam	struct secpolicyindex spidx;
157105197Ssam
158120585Ssam	time_t created;		/* for lifetime */
159105197Ssam	int count;		/* for lifetime */
160105197Ssam	/* XXX: here is mbuf place holder to be sent ? */
161105197Ssam};
162105197Ssam#endif /* _KERNEL */
163105197Ssam
164105197Ssam/* according to IANA assignment, port 0x0000 and proto 0xff are reserved. */
165105197Ssam#define IPSEC_PORT_ANY		0
166105197Ssam#define IPSEC_ULPROTO_ANY	255
167105197Ssam#define IPSEC_PROTO_ANY		255
168105197Ssam
169105197Ssam/* mode of security protocol */
170105197Ssam/* NOTE: DON'T use IPSEC_MODE_ANY at SPD.  It's only use in SAD */
171105197Ssam#define	IPSEC_MODE_ANY		0	/* i.e. wildcard. */
172105197Ssam#define	IPSEC_MODE_TRANSPORT	1
173105197Ssam#define	IPSEC_MODE_TUNNEL	2
174125680Sbms#define	IPSEC_MODE_TCPMD5	3	/* TCP MD5 mode */
175105197Ssam
176105197Ssam/*
177105197Ssam * Direction of security policy.
178105197Ssam * NOTE: Since INVALID is used just as flag.
179105197Ssam * The other are used for loop counter too.
180105197Ssam */
181105197Ssam#define IPSEC_DIR_ANY		0
182105197Ssam#define IPSEC_DIR_INBOUND	1
183105197Ssam#define IPSEC_DIR_OUTBOUND	2
184105197Ssam#define IPSEC_DIR_MAX		3
185105197Ssam#define IPSEC_DIR_INVALID	4
186105197Ssam
187105197Ssam/* Policy level */
188105197Ssam/*
189105197Ssam * IPSEC, ENTRUST and BYPASS are allowed for setsockopt() in PCB,
190105197Ssam * DISCARD, IPSEC and NONE are allowed for setkey() in SPD.
191105197Ssam * DISCARD and NONE are allowed for system default.
192105197Ssam */
193105197Ssam#define IPSEC_POLICY_DISCARD	0	/* discarding packet */
194105197Ssam#define IPSEC_POLICY_NONE	1	/* through IPsec engine */
195105197Ssam#define IPSEC_POLICY_IPSEC	2	/* do IPsec */
196105197Ssam#define IPSEC_POLICY_ENTRUST	3	/* consulting SPD if present. */
197105197Ssam#define IPSEC_POLICY_BYPASS	4	/* only for privileged socket. */
198105197Ssam
199105197Ssam/* Security protocol level */
200105197Ssam#define	IPSEC_LEVEL_DEFAULT	0	/* reference to system default */
201105197Ssam#define	IPSEC_LEVEL_USE		1	/* use SA if present. */
202105197Ssam#define	IPSEC_LEVEL_REQUIRE	2	/* require SA. */
203105197Ssam#define	IPSEC_LEVEL_UNIQUE	3	/* unique SA. */
204105197Ssam
205105197Ssam#define IPSEC_MANUAL_REQID_MAX	0x3fff
206105197Ssam				/*
207105197Ssam				 * if security policy level == unique, this id
208105197Ssam				 * indicate to a relative SA for use, else is
209105197Ssam				 * zero.
210105197Ssam				 * 1 - 0x3fff are reserved for manual keying.
211105197Ssam				 * 0 are reserved for above reason.  Others is
212105197Ssam				 * for kernel use.
213105197Ssam				 * Note that this id doesn't identify SA
214105197Ssam				 * by only itself.
215105197Ssam				 */
216105197Ssam#define IPSEC_REPLAYWSIZE  32
217105197Ssam
218171133Sgnn/* statistics for ipsec processing */
219105197Ssamstruct ipsecstat {
220253081Sae	uint64_t in_success;  /* succeeded inbound process */
221253081Sae	uint64_t in_polvio;
222105197Ssam			/* security policy violation for inbound process */
223253081Sae	uint64_t in_nosa;     /* inbound SA is unavailable */
224253081Sae	uint64_t in_inval;    /* inbound processing failed due to EINVAL */
225253081Sae	uint64_t in_nomem;    /* inbound processing failed due to ENOBUFS */
226253081Sae	uint64_t in_badspi;   /* failed getting a SPI */
227253081Sae	uint64_t in_ahreplay; /* AH replay check failed */
228253081Sae	uint64_t in_espreplay; /* ESP replay check failed */
229253081Sae	uint64_t in_ahauthsucc; /* AH authentication success */
230253081Sae	uint64_t in_ahauthfail; /* AH authentication failure */
231253081Sae	uint64_t in_espauthsucc; /* ESP authentication success */
232253081Sae	uint64_t in_espauthfail; /* ESP authentication failure */
233253081Sae	uint64_t in_esphist[256];
234253081Sae	uint64_t in_ahhist[256];
235253081Sae	uint64_t in_comphist[256];
236253081Sae	uint64_t out_success; /* succeeded outbound process */
237253081Sae	uint64_t out_polvio;
238105197Ssam			/* security policy violation for outbound process */
239253081Sae	uint64_t out_nosa;    /* outbound SA is unavailable */
240253081Sae	uint64_t out_inval;   /* outbound process failed due to EINVAL */
241253081Sae	uint64_t out_nomem;    /* inbound processing failed due to ENOBUFS */
242253081Sae	uint64_t out_noroute; /* there is no route */
243253081Sae	uint64_t out_esphist[256];
244253081Sae	uint64_t out_ahhist[256];
245253081Sae	uint64_t out_comphist[256];
246125098Ssam
247253081Sae	uint64_t spdcachelookup;
248253081Sae	uint64_t spdcachemiss;
249105197Ssam
250253081Sae	uint64_t ips_in_polvio;		/* input: sec policy violation */
251253081Sae	uint64_t ips_out_polvio;	/* output: sec policy violation */
252253081Sae	uint64_t ips_out_nosa;		/* output: SA unavailable  */
253253081Sae	uint64_t ips_out_nomem;		/* output: no memory available */
254253081Sae	uint64_t ips_out_noroute;	/* output: no route available */
255253081Sae	uint64_t ips_out_inval;		/* output: generic error */
256253081Sae	uint64_t ips_out_bundlesa;	/* output: bundled SA processed */
257253081Sae	uint64_t ips_mbcoalesced;	/* mbufs coalesced during clone */
258253081Sae	uint64_t ips_clcoalesced;	/* clusters coalesced during clone */
259253081Sae	uint64_t ips_clcopied;		/* clusters copied during clone */
260253081Sae	uint64_t ips_mbinserted;	/* mbufs inserted during makespace */
261105197Ssam	/*
262105197Ssam	 * Temporary statistics for performance analysis.
263105197Ssam	 */
264105197Ssam	/* See where ESP/AH/IPCOMP header land in mbuf on input */
265253081Sae	uint64_t ips_input_front;
266253081Sae	uint64_t ips_input_middle;
267253081Sae	uint64_t ips_input_end;
268105197Ssam};
269105197Ssam
270105197Ssam/*
271105197Ssam * Definitions for IPsec & Key sysctl operations.
272105197Ssam */
273105197Ssam/*
274105197Ssam * Names for IPsec & Key sysctl objects
275105197Ssam */
276105197Ssam#define IPSECCTL_STATS			1	/* stats */
277105197Ssam#define IPSECCTL_DEF_POLICY		2
278105197Ssam#define IPSECCTL_DEF_ESP_TRANSLEV	3	/* int; ESP transport mode */
279105197Ssam#define IPSECCTL_DEF_ESP_NETLEV		4	/* int; ESP tunnel mode */
280105197Ssam#define IPSECCTL_DEF_AH_TRANSLEV	5	/* int; AH transport mode */
281105197Ssam#define IPSECCTL_DEF_AH_NETLEV		6	/* int; AH tunnel mode */
282105197Ssam#if 0	/* obsolete, do not reuse */
283105197Ssam#define IPSECCTL_INBOUND_CALL_IKE	7
284105197Ssam#endif
285105197Ssam#define	IPSECCTL_AH_CLEARTOS		8
286105197Ssam#define	IPSECCTL_AH_OFFSETMASK		9
287105197Ssam#define	IPSECCTL_DFBIT			10
288105197Ssam#define	IPSECCTL_ECN			11
289105197Ssam#define	IPSECCTL_DEBUG			12
290105197Ssam#define	IPSECCTL_ESP_RANDPAD		13
291105197Ssam#define IPSECCTL_MAXID			14
292105197Ssam
293105197Ssam#define IPSECCTL_NAMES { \
294105197Ssam	{ 0, 0 }, \
295105197Ssam	{ 0, 0 }, \
296105197Ssam	{ "def_policy", CTLTYPE_INT }, \
297105197Ssam	{ "esp_trans_deflev", CTLTYPE_INT }, \
298105197Ssam	{ "esp_net_deflev", CTLTYPE_INT }, \
299105197Ssam	{ "ah_trans_deflev", CTLTYPE_INT }, \
300105197Ssam	{ "ah_net_deflev", CTLTYPE_INT }, \
301105197Ssam	{ 0, 0 }, \
302105197Ssam	{ "ah_cleartos", CTLTYPE_INT }, \
303105197Ssam	{ "ah_offsetmask", CTLTYPE_INT }, \
304105197Ssam	{ "dfbit", CTLTYPE_INT }, \
305105197Ssam	{ "ecn", CTLTYPE_INT }, \
306105197Ssam	{ "debug", CTLTYPE_INT }, \
307105197Ssam	{ "esp_randpad", CTLTYPE_INT }, \
308105197Ssam}
309105197Ssam
310105197Ssam#define IPSEC6CTL_NAMES { \
311105197Ssam	{ 0, 0 }, \
312105197Ssam	{ 0, 0 }, \
313105197Ssam	{ "def_policy", CTLTYPE_INT }, \
314105197Ssam	{ "esp_trans_deflev", CTLTYPE_INT }, \
315105197Ssam	{ "esp_net_deflev", CTLTYPE_INT }, \
316105197Ssam	{ "ah_trans_deflev", CTLTYPE_INT }, \
317105197Ssam	{ "ah_net_deflev", CTLTYPE_INT }, \
318105197Ssam	{ 0, 0 }, \
319105197Ssam	{ 0, 0 }, \
320105197Ssam	{ 0, 0 }, \
321105197Ssam	{ 0, 0 }, \
322105197Ssam	{ "ecn", CTLTYPE_INT }, \
323105197Ssam	{ "debug", CTLTYPE_INT }, \
324105197Ssam	{ "esp_randpad", CTLTYPE_INT }, \
325105197Ssam}
326105197Ssam
327105197Ssam#ifdef _KERNEL
328105197Ssamstruct ipsec_output_state {
329105197Ssam	struct mbuf *m;
330105197Ssam	struct route *ro;
331105197Ssam	struct sockaddr *dst;
332105197Ssam};
333105197Ssam
334105197Ssamstruct ipsec_history {
335105197Ssam	int ih_proto;
336105197Ssam	u_int32_t ih_spi;
337105197Ssam};
338105197Ssam
339195699SrwatsonVNET_DECLARE(int, ipsec_debug);
340195727Srwatson#define	V_ipsec_debug		VNET(ipsec_debug)
341207369Sbz
342207369Sbz#ifdef REGRESSION
343207369SbzVNET_DECLARE(int, ipsec_replay);
344207369SbzVNET_DECLARE(int, ipsec_integrity);
345207369Sbz
346207369Sbz#define	V_ipsec_replay		VNET(ipsec_replay)
347207369Sbz#define	V_ipsec_integrity	VNET(ipsec_integrity)
348207369Sbz#endif
349207369Sbz
350195699SrwatsonVNET_DECLARE(struct ipsecstat, ipsec4stat);
351207369SbzVNET_DECLARE(struct secpolicy, ip4_def_policy);
352207369SbzVNET_DECLARE(int, ip4_esp_trans_deflev);
353207369SbzVNET_DECLARE(int, ip4_esp_net_deflev);
354207369SbzVNET_DECLARE(int, ip4_ah_trans_deflev);
355207369SbzVNET_DECLARE(int, ip4_ah_net_deflev);
356195699SrwatsonVNET_DECLARE(int, ip4_ah_offsetmask);
357195699SrwatsonVNET_DECLARE(int, ip4_ipsec_dfbit);
358207369SbzVNET_DECLARE(int, ip4_ipsec_ecn);
359207369SbzVNET_DECLARE(int, ip4_esp_randpad);
360207369SbzVNET_DECLARE(int, crypto_support);
361207369Sbz
362252026Sae#define	IPSECSTAT_INC(name)	V_ipsec4stat.name += 1
363207369Sbz#define	V_ipsec4stat		VNET(ipsec4stat)
364207369Sbz#define	V_ip4_def_policy	VNET(ip4_def_policy)
365195727Srwatson#define	V_ip4_esp_trans_deflev	VNET(ip4_esp_trans_deflev)
366195727Srwatson#define	V_ip4_esp_net_deflev	VNET(ip4_esp_net_deflev)
367195727Srwatson#define	V_ip4_ah_trans_deflev	VNET(ip4_ah_trans_deflev)
368195727Srwatson#define	V_ip4_ah_net_deflev	VNET(ip4_ah_net_deflev)
369207369Sbz#define	V_ip4_ah_offsetmask	VNET(ip4_ah_offsetmask)
370207369Sbz#define	V_ip4_ipsec_dfbit	VNET(ip4_ipsec_dfbit)
371195727Srwatson#define	V_ip4_ipsec_ecn		VNET(ip4_ipsec_ecn)
372195727Srwatson#define	V_ip4_esp_randpad	VNET(ip4_esp_randpad)
373195727Srwatson#define	V_crypto_support	VNET(crypto_support)
374195699Srwatson
375181803Sbz#define ipseclog(x)	do { if (V_ipsec_debug) log x; } while (0)
376105197Ssam/* for openbsd compatibility */
377181803Sbz#define	DPRINTF(x)	do { if (V_ipsec_debug) printf x; } while (0)
378105197Ssam
379119643Ssamextern	struct ipsecrequest *ipsec_newisr(void);
380119643Ssamextern	void ipsec_delisr(struct ipsecrequest *);
381119643Ssam
382105197Ssamstruct tdb_ident;
383105197Ssamextern struct secpolicy *ipsec_getpolicy __P((struct tdb_ident*, u_int));
384105197Ssamstruct inpcb;
385105197Ssamextern struct secpolicy *ipsec4_checkpolicy __P((struct mbuf *, u_int, u_int,
386105197Ssam	int *, struct inpcb *));
387105197Ssamextern struct secpolicy * ipsec_getpolicybyaddr(struct mbuf *, u_int,
388105197Ssam	int, int *);
389105197Ssam
390105197Ssamstruct inpcb;
391105197Ssamextern int ipsec_init_policy __P((struct socket *so, struct inpcbpolicy **));
392105197Ssamextern int ipsec_copy_policy
393105197Ssam	__P((struct inpcbpolicy *, struct inpcbpolicy *));
394105197Ssamextern u_int ipsec_get_reqlevel __P((struct ipsecrequest *));
395105197Ssamextern int ipsec_in_reject __P((struct secpolicy *, struct mbuf *));
396105197Ssam
397188306Sbzextern int ipsec_set_policy __P((struct inpcb *inp, int optname,
398175892Sbz	caddr_t request, size_t len, struct ucred *cred));
399188306Sbzextern int ipsec_get_policy __P((struct inpcb *inpcb, caddr_t request,
400105197Ssam	size_t len, struct mbuf **mp));
401185366Sbzextern int ipsec_delete_pcbpolicy __P((struct inpcb *));
402105197Ssamextern int ipsec4_in_reject __P((struct mbuf *, struct inpcb *));
403105197Ssam
404105197Ssamstruct secas;
405105197Ssamstruct tcpcb;
406105197Ssamextern int ipsec_chkreplay __P((u_int32_t, struct secasvar *));
407105197Ssamextern int ipsec_updatereplay __P((u_int32_t, struct secasvar *));
408105197Ssam
409188306Sbzextern size_t ipsec_hdrsiz __P((struct mbuf *, u_int, struct inpcb *));
410105197Ssamextern size_t ipsec_hdrsiz_tcp __P((struct tcpcb *));
411105197Ssam
412105197Ssamunion sockaddr_union;
413105197Ssamextern char * ipsec_address(union sockaddr_union* sa);
414105197Ssamextern const char *ipsec_logsastr __P((struct secasvar *));
415105197Ssam
416105197Ssamextern void ipsec_dumpmbuf __P((struct mbuf *));
417105197Ssam
418105197Ssamstruct m_tag;
419106680Ssamextern void ah4_input(struct mbuf *m, int off);
420120585Ssamextern void ah4_ctlinput(int cmd, struct sockaddr *sa, void *);
421106680Ssamextern void esp4_input(struct mbuf *m, int off);
422120585Ssamextern void esp4_ctlinput(int cmd, struct sockaddr *sa, void *);
423106680Ssamextern void ipcomp4_input(struct mbuf *m, int off);
424105197Ssamextern int ipsec4_common_input(struct mbuf *m, ...);
425105197Ssamextern int ipsec4_common_input_cb(struct mbuf *m, struct secasvar *sav,
426105197Ssam			int skip, int protoff, struct m_tag *mt);
427105197Ssamextern int ipsec4_process_packet __P((struct mbuf *, struct ipsecrequest *,
428105197Ssam			int, int));
429105197Ssamextern int ipsec_process_done __P((struct mbuf *, struct ipsecrequest *));
430105197Ssam
431105197Ssamextern struct mbuf *ipsec_copypkt __P((struct mbuf *));
432105197Ssam
433105197Ssamextern	void m_checkalignment(const char* where, struct mbuf *m0,
434105197Ssam		int off, int len);
435105197Ssamextern	struct mbuf *m_makespace(struct mbuf *m0, int skip, int hlen, int *off);
436105197Ssamextern	caddr_t m_pad(struct mbuf *m, int n);
437105197Ssamextern	int m_striphdr(struct mbuf *m, int skip, int hlen);
438174054Sbz
439174054Sbz#ifdef DEV_ENC
440174054Sbz#define	ENC_BEFORE	0x0001
441174054Sbz#define	ENC_AFTER	0x0002
442174054Sbz#define	ENC_IN		0x0100
443174054Sbz#define	ENC_OUT		0x0200
444174054Sbzextern	int ipsec_filter(struct mbuf **, int, int);
445174054Sbzextern	void ipsec_bpf(struct mbuf *, struct secasvar *, int, int);
446174054Sbz#endif
447105197Ssam#endif /* _KERNEL */
448105197Ssam
449105197Ssam#ifndef _KERNEL
450105197Ssamextern caddr_t ipsec_set_policy __P((char *, int));
451105197Ssamextern int ipsec_get_policylen __P((caddr_t));
452105197Ssamextern char *ipsec_dump_policy __P((caddr_t, char *));
453105197Ssam
454105197Ssamextern const char *ipsec_strerror __P((void));
455105197Ssam
456183550Szec#endif /* ! KERNEL */
457183550Szec
458105197Ssam#endif /* _NETIPSEC_IPSEC_H_ */
459