xref: /freebsd/sys/netipsec/ipsec.h (revision 9ffa96777e7ffbd3565a956780e930023e71cadb)
188768458SSam Leffler /*	$FreeBSD$	*/
288768458SSam Leffler /*	$KAME: ipsec.h,v 1.53 2001/11/20 08:32:38 itojun Exp $	*/
388768458SSam Leffler 
488768458SSam Leffler /*
588768458SSam Leffler  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
688768458SSam Leffler  * All rights reserved.
788768458SSam Leffler  *
888768458SSam Leffler  * Redistribution and use in source and binary forms, with or without
988768458SSam Leffler  * modification, are permitted provided that the following conditions
1088768458SSam Leffler  * are met:
1188768458SSam Leffler  * 1. Redistributions of source code must retain the above copyright
1288768458SSam Leffler  *    notice, this list of conditions and the following disclaimer.
1388768458SSam Leffler  * 2. Redistributions in binary form must reproduce the above copyright
1488768458SSam Leffler  *    notice, this list of conditions and the following disclaimer in the
1588768458SSam Leffler  *    documentation and/or other materials provided with the distribution.
1688768458SSam Leffler  * 3. Neither the name of the project nor the names of its contributors
1788768458SSam Leffler  *    may be used to endorse or promote products derived from this software
1888768458SSam Leffler  *    without specific prior written permission.
1988768458SSam Leffler  *
2088768458SSam Leffler  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
2188768458SSam Leffler  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2288768458SSam Leffler  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2388768458SSam Leffler  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2488768458SSam Leffler  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2588768458SSam Leffler  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2688768458SSam Leffler  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2788768458SSam Leffler  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2888768458SSam Leffler  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2988768458SSam Leffler  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3088768458SSam Leffler  * SUCH DAMAGE.
3188768458SSam Leffler  */
3288768458SSam Leffler 
3388768458SSam Leffler /*
3488768458SSam Leffler  * IPsec controller part.
3588768458SSam Leffler  */
3688768458SSam Leffler 
3788768458SSam Leffler #ifndef _NETIPSEC_IPSEC_H_
3888768458SSam Leffler #define _NETIPSEC_IPSEC_H_
3988768458SSam Leffler 
4088768458SSam Leffler #if defined(_KERNEL) && !defined(_LKM) && !defined(KLD_MODULE)
4188768458SSam Leffler #include "opt_inet.h"
4288768458SSam Leffler #include "opt_ipsec.h"
4388768458SSam Leffler #endif
4488768458SSam Leffler 
4588768458SSam Leffler #include <net/pfkeyv2.h>
4688768458SSam Leffler #include <netipsec/keydb.h>
479ffa9677SSam Leffler #include <netipsec/ipsec_osdep.h>
4888768458SSam Leffler 
4988768458SSam Leffler #ifdef _KERNEL
5088768458SSam Leffler 
5188768458SSam Leffler /*
5288768458SSam Leffler  * Security Policy Index
5388768458SSam Leffler  * Ensure that both address families in the "src" and "dst" are same.
5488768458SSam Leffler  * When the value of the ul_proto is ICMPv6, the port field in "src"
5588768458SSam Leffler  * specifies ICMPv6 type, and the port field in "dst" specifies ICMPv6 code.
5688768458SSam Leffler  */
5788768458SSam Leffler struct secpolicyindex {
5888768458SSam Leffler 	u_int8_t dir;			/* direction of packet flow, see blow */
5988768458SSam Leffler 	union sockaddr_union src;	/* IP src address for SP */
6088768458SSam Leffler 	union sockaddr_union dst;	/* IP dst address for SP */
6188768458SSam Leffler 	u_int8_t prefs;			/* prefix length in bits for src */
6288768458SSam Leffler 	u_int8_t prefd;			/* prefix length in bits for dst */
6388768458SSam Leffler 	u_int16_t ul_proto;		/* upper layer Protocol */
6488768458SSam Leffler #ifdef notyet
6588768458SSam Leffler 	uid_t uids;
6688768458SSam Leffler 	uid_t uidd;
6788768458SSam Leffler 	gid_t gids;
6888768458SSam Leffler 	gid_t gidd;
6988768458SSam Leffler #endif
7088768458SSam Leffler };
7188768458SSam Leffler 
7288768458SSam Leffler /* Security Policy Data Base */
7388768458SSam Leffler struct secpolicy {
7488768458SSam Leffler 	LIST_ENTRY(secpolicy) chain;
756464079fSSam Leffler 	struct mtx lock;
7688768458SSam Leffler 
7788768458SSam Leffler 	u_int refcnt;			/* reference count */
7888768458SSam Leffler 	struct secpolicyindex spidx;	/* selector */
7988768458SSam Leffler 	u_int32_t id;			/* It's unique number on the system. */
8088768458SSam Leffler 	u_int state;			/* 0: dead, others: alive */
8188768458SSam Leffler #define IPSEC_SPSTATE_DEAD	0
8288768458SSam Leffler #define IPSEC_SPSTATE_ALIVE	1
839ffa9677SSam Leffler 	u_int16_t policy;		/* policy_type per pfkeyv2.h */
849ffa9677SSam Leffler 	u_int16_t scangen;		/* scan generation # */
8588768458SSam Leffler 	struct ipsecrequest *req;
8688768458SSam Leffler 				/* pointer to the ipsec request tree, */
8788768458SSam Leffler 				/* if policy == IPSEC else this value == NULL.*/
8888768458SSam Leffler 
8988768458SSam Leffler 	/*
9088768458SSam Leffler 	 * lifetime handler.
9188768458SSam Leffler 	 * the policy can be used without limitiation if both lifetime and
9288768458SSam Leffler 	 * validtime are zero.
9388768458SSam Leffler 	 * "lifetime" is passed by sadb_lifetime.sadb_lifetime_addtime.
9488768458SSam Leffler 	 * "validtime" is passed by sadb_lifetime.sadb_lifetime_usetime.
9588768458SSam Leffler 	 */
969ffa9677SSam Leffler 	time_t created;		/* time created the policy */
979ffa9677SSam Leffler 	time_t lastused;	/* updated every when kernel sends a packet */
9888768458SSam Leffler 	long lifetime;		/* duration of the lifetime of this policy */
9988768458SSam Leffler 	long validtime;		/* duration this policy is valid without use */
10088768458SSam Leffler };
10188768458SSam Leffler 
1029ffa9677SSam Leffler #define	SECPOLICY_LOCK_INIT(_sp) \
1039ffa9677SSam Leffler 	mtx_init(&(_sp)->lock, "ipsec policy", NULL, MTX_DEF)
1049ffa9677SSam Leffler #define	SECPOLICY_LOCK(_sp)		mtx_lock(&(_sp)->lock)
1059ffa9677SSam Leffler #define	SECPOLICY_UNLOCK(_sp)		mtx_unlock(&(_sp)->lock)
1069ffa9677SSam Leffler #define	SECPOLICY_LOCK_DESTROY(_sp)	mtx_destroy(&(_sp)->lock)
1079ffa9677SSam Leffler #define	SECPOLICY_LOCK_ASSERT(_sp)	mtx_assert(&(_sp)->lock, MA_OWNED)
1089ffa9677SSam Leffler 
10988768458SSam Leffler /* Request for IPsec */
11088768458SSam Leffler struct ipsecrequest {
11188768458SSam Leffler 	struct ipsecrequest *next;
11288768458SSam Leffler 				/* pointer to next structure */
11388768458SSam Leffler 				/* If NULL, it means the end of chain. */
11488768458SSam Leffler 	struct secasindex saidx;/* hint for search proper SA */
11588768458SSam Leffler 				/* if __ss_len == 0 then no address specified.*/
11688768458SSam Leffler 	u_int level;		/* IPsec level defined below. */
11788768458SSam Leffler 
11888768458SSam Leffler 	struct secasvar *sav;	/* place holder of SA for use */
11988768458SSam Leffler 	struct secpolicy *sp;	/* back pointer to SP */
1206464079fSSam Leffler 	struct mtx lock;	/* to interlock updates */
12188768458SSam Leffler };
12288768458SSam Leffler 
1239ffa9677SSam Leffler /*
1249ffa9677SSam Leffler  * Need recursion for when crypto callbacks happen directly,
1259ffa9677SSam Leffler  * as in the case of software crypto.  Need to look at how
1269ffa9677SSam Leffler  * hard it is to remove this...
1279ffa9677SSam Leffler  */
1289ffa9677SSam Leffler #define	IPSECREQUEST_LOCK_INIT(_isr) \
1299ffa9677SSam Leffler 	mtx_init(&(_isr)->lock, "ipsec request", NULL, MTX_DEF | MTX_RECURSE)
1309ffa9677SSam Leffler #define	IPSECREQUEST_LOCK(_isr)		mtx_lock(&(_isr)->lock)
1319ffa9677SSam Leffler #define	IPSECREQUEST_UNLOCK(_isr)	mtx_unlock(&(_isr)->lock)
1329ffa9677SSam Leffler #define	IPSECREQUEST_LOCK_DESTROY(_isr)	mtx_destroy(&(_isr)->lock)
1339ffa9677SSam Leffler #define	IPSECREQUEST_LOCK_ASSERT(_isr)	mtx_assert(&(_isr)->lock, MA_OWNED)
1349ffa9677SSam Leffler 
13588768458SSam Leffler /* security policy in PCB */
13688768458SSam Leffler struct inpcbpolicy {
13788768458SSam Leffler 	struct secpolicy *sp_in;
13888768458SSam Leffler 	struct secpolicy *sp_out;
13988768458SSam Leffler 	int priv;			/* privileged socket ? */
14088768458SSam Leffler };
14188768458SSam Leffler 
14288768458SSam Leffler /* SP acquiring list table. */
14388768458SSam Leffler struct secspacq {
14488768458SSam Leffler 	LIST_ENTRY(secspacq) chain;
14588768458SSam Leffler 
14688768458SSam Leffler 	struct secpolicyindex spidx;
14788768458SSam Leffler 
1489ffa9677SSam Leffler 	time_t created;		/* for lifetime */
14988768458SSam Leffler 	int count;		/* for lifetime */
15088768458SSam Leffler 	/* XXX: here is mbuf place holder to be sent ? */
15188768458SSam Leffler };
15288768458SSam Leffler #endif /* _KERNEL */
15388768458SSam Leffler 
15488768458SSam Leffler /* according to IANA assignment, port 0x0000 and proto 0xff are reserved. */
15588768458SSam Leffler #define IPSEC_PORT_ANY		0
15688768458SSam Leffler #define IPSEC_ULPROTO_ANY	255
15788768458SSam Leffler #define IPSEC_PROTO_ANY		255
15888768458SSam Leffler 
15988768458SSam Leffler /* mode of security protocol */
16088768458SSam Leffler /* NOTE: DON'T use IPSEC_MODE_ANY at SPD.  It's only use in SAD */
16188768458SSam Leffler #define	IPSEC_MODE_ANY		0	/* i.e. wildcard. */
16288768458SSam Leffler #define	IPSEC_MODE_TRANSPORT	1
16388768458SSam Leffler #define	IPSEC_MODE_TUNNEL	2
16488768458SSam Leffler 
16588768458SSam Leffler /*
16688768458SSam Leffler  * Direction of security policy.
16788768458SSam Leffler  * NOTE: Since INVALID is used just as flag.
16888768458SSam Leffler  * The other are used for loop counter too.
16988768458SSam Leffler  */
17088768458SSam Leffler #define IPSEC_DIR_ANY		0
17188768458SSam Leffler #define IPSEC_DIR_INBOUND	1
17288768458SSam Leffler #define IPSEC_DIR_OUTBOUND	2
17388768458SSam Leffler #define IPSEC_DIR_MAX		3
17488768458SSam Leffler #define IPSEC_DIR_INVALID	4
17588768458SSam Leffler 
17688768458SSam Leffler /* Policy level */
17788768458SSam Leffler /*
17888768458SSam Leffler  * IPSEC, ENTRUST and BYPASS are allowed for setsockopt() in PCB,
17988768458SSam Leffler  * DISCARD, IPSEC and NONE are allowed for setkey() in SPD.
18088768458SSam Leffler  * DISCARD and NONE are allowed for system default.
18188768458SSam Leffler  */
18288768458SSam Leffler #define IPSEC_POLICY_DISCARD	0	/* discarding packet */
18388768458SSam Leffler #define IPSEC_POLICY_NONE	1	/* through IPsec engine */
18488768458SSam Leffler #define IPSEC_POLICY_IPSEC	2	/* do IPsec */
18588768458SSam Leffler #define IPSEC_POLICY_ENTRUST	3	/* consulting SPD if present. */
18688768458SSam Leffler #define IPSEC_POLICY_BYPASS	4	/* only for privileged socket. */
18788768458SSam Leffler 
18888768458SSam Leffler /* Security protocol level */
18988768458SSam Leffler #define	IPSEC_LEVEL_DEFAULT	0	/* reference to system default */
19088768458SSam Leffler #define	IPSEC_LEVEL_USE		1	/* use SA if present. */
19188768458SSam Leffler #define	IPSEC_LEVEL_REQUIRE	2	/* require SA. */
19288768458SSam Leffler #define	IPSEC_LEVEL_UNIQUE	3	/* unique SA. */
19388768458SSam Leffler 
19488768458SSam Leffler #define IPSEC_MANUAL_REQID_MAX	0x3fff
19588768458SSam Leffler 				/*
19688768458SSam Leffler 				 * if security policy level == unique, this id
19788768458SSam Leffler 				 * indicate to a relative SA for use, else is
19888768458SSam Leffler 				 * zero.
19988768458SSam Leffler 				 * 1 - 0x3fff are reserved for manual keying.
20088768458SSam Leffler 				 * 0 are reserved for above reason.  Others is
20188768458SSam Leffler 				 * for kernel use.
20288768458SSam Leffler 				 * Note that this id doesn't identify SA
20388768458SSam Leffler 				 * by only itself.
20488768458SSam Leffler 				 */
20588768458SSam Leffler #define IPSEC_REPLAYWSIZE  32
20688768458SSam Leffler 
20788768458SSam Leffler /* old statistics for ipsec processing */
20888768458SSam Leffler struct ipsecstat {
20988768458SSam Leffler 	u_quad_t in_success;  /* succeeded inbound process */
21088768458SSam Leffler 	u_quad_t in_polvio;
21188768458SSam Leffler 			/* security policy violation for inbound process */
21288768458SSam Leffler 	u_quad_t in_nosa;     /* inbound SA is unavailable */
21388768458SSam Leffler 	u_quad_t in_inval;    /* inbound processing failed due to EINVAL */
21488768458SSam Leffler 	u_quad_t in_nomem;    /* inbound processing failed due to ENOBUFS */
21588768458SSam Leffler 	u_quad_t in_badspi;   /* failed getting a SPI */
21688768458SSam Leffler 	u_quad_t in_ahreplay; /* AH replay check failed */
21788768458SSam Leffler 	u_quad_t in_espreplay; /* ESP replay check failed */
21888768458SSam Leffler 	u_quad_t in_ahauthsucc; /* AH authentication success */
21988768458SSam Leffler 	u_quad_t in_ahauthfail; /* AH authentication failure */
22088768458SSam Leffler 	u_quad_t in_espauthsucc; /* ESP authentication success */
22188768458SSam Leffler 	u_quad_t in_espauthfail; /* ESP authentication failure */
22288768458SSam Leffler 	u_quad_t in_esphist[256];
22388768458SSam Leffler 	u_quad_t in_ahhist[256];
22488768458SSam Leffler 	u_quad_t in_comphist[256];
22588768458SSam Leffler 	u_quad_t out_success; /* succeeded outbound process */
22688768458SSam Leffler 	u_quad_t out_polvio;
22788768458SSam Leffler 			/* security policy violation for outbound process */
22888768458SSam Leffler 	u_quad_t out_nosa;    /* outbound SA is unavailable */
22988768458SSam Leffler 	u_quad_t out_inval;   /* outbound process failed due to EINVAL */
23088768458SSam Leffler 	u_quad_t out_nomem;    /* inbound processing failed due to ENOBUFS */
23188768458SSam Leffler 	u_quad_t out_noroute; /* there is no route */
23288768458SSam Leffler 	u_quad_t out_esphist[256];
23388768458SSam Leffler 	u_quad_t out_ahhist[256];
23488768458SSam Leffler 	u_quad_t out_comphist[256];
23588768458SSam Leffler };
23688768458SSam Leffler 
23788768458SSam Leffler /* statistics for ipsec processing */
23888768458SSam Leffler struct newipsecstat {
23988768458SSam Leffler 	u_int32_t ips_in_polvio;	/* input: sec policy violation */
24088768458SSam Leffler 	u_int32_t ips_out_polvio;	/* output: sec policy violation */
24188768458SSam Leffler 	u_int32_t ips_out_nosa;		/* output: SA unavailable  */
24288768458SSam Leffler 	u_int32_t ips_out_nomem;	/* output: no memory available */
24388768458SSam Leffler 	u_int32_t ips_out_noroute;	/* output: no route available */
24488768458SSam Leffler 	u_int32_t ips_out_inval;	/* output: generic error */
24588768458SSam Leffler 	u_int32_t ips_out_bundlesa;	/* output: bundled SA processed */
24688768458SSam Leffler 	u_int32_t ips_mbcoalesced;	/* mbufs coalesced during clone */
24788768458SSam Leffler 	u_int32_t ips_clcoalesced;	/* clusters coalesced during clone */
24888768458SSam Leffler 	u_int32_t ips_clcopied;		/* clusters copied during clone */
24988768458SSam Leffler 	u_int32_t ips_mbinserted;	/* mbufs inserted during makespace */
25088768458SSam Leffler 	/*
25188768458SSam Leffler 	 * Temporary statistics for performance analysis.
25288768458SSam Leffler 	 */
25388768458SSam Leffler 	/* See where ESP/AH/IPCOMP header land in mbuf on input */
25488768458SSam Leffler 	u_int32_t ips_input_front;
25588768458SSam Leffler 	u_int32_t ips_input_middle;
25688768458SSam Leffler 	u_int32_t ips_input_end;
25788768458SSam Leffler };
25888768458SSam Leffler 
25988768458SSam Leffler /*
26088768458SSam Leffler  * Definitions for IPsec & Key sysctl operations.
26188768458SSam Leffler  */
26288768458SSam Leffler /*
26388768458SSam Leffler  * Names for IPsec & Key sysctl objects
26488768458SSam Leffler  */
26588768458SSam Leffler #define IPSECCTL_STATS			1	/* stats */
26688768458SSam Leffler #define IPSECCTL_DEF_POLICY		2
26788768458SSam Leffler #define IPSECCTL_DEF_ESP_TRANSLEV	3	/* int; ESP transport mode */
26888768458SSam Leffler #define IPSECCTL_DEF_ESP_NETLEV		4	/* int; ESP tunnel mode */
26988768458SSam Leffler #define IPSECCTL_DEF_AH_TRANSLEV	5	/* int; AH transport mode */
27088768458SSam Leffler #define IPSECCTL_DEF_AH_NETLEV		6	/* int; AH tunnel mode */
27188768458SSam Leffler #if 0	/* obsolete, do not reuse */
27288768458SSam Leffler #define IPSECCTL_INBOUND_CALL_IKE	7
27388768458SSam Leffler #endif
27488768458SSam Leffler #define	IPSECCTL_AH_CLEARTOS		8
27588768458SSam Leffler #define	IPSECCTL_AH_OFFSETMASK		9
27688768458SSam Leffler #define	IPSECCTL_DFBIT			10
27788768458SSam Leffler #define	IPSECCTL_ECN			11
27888768458SSam Leffler #define	IPSECCTL_DEBUG			12
27988768458SSam Leffler #define	IPSECCTL_ESP_RANDPAD		13
28088768458SSam Leffler #define IPSECCTL_MAXID			14
28188768458SSam Leffler 
28288768458SSam Leffler #define IPSECCTL_NAMES { \
28388768458SSam Leffler 	{ 0, 0 }, \
28488768458SSam Leffler 	{ 0, 0 }, \
28588768458SSam Leffler 	{ "def_policy", CTLTYPE_INT }, \
28688768458SSam Leffler 	{ "esp_trans_deflev", CTLTYPE_INT }, \
28788768458SSam Leffler 	{ "esp_net_deflev", CTLTYPE_INT }, \
28888768458SSam Leffler 	{ "ah_trans_deflev", CTLTYPE_INT }, \
28988768458SSam Leffler 	{ "ah_net_deflev", CTLTYPE_INT }, \
29088768458SSam Leffler 	{ 0, 0 }, \
29188768458SSam Leffler 	{ "ah_cleartos", CTLTYPE_INT }, \
29288768458SSam Leffler 	{ "ah_offsetmask", CTLTYPE_INT }, \
29388768458SSam Leffler 	{ "dfbit", CTLTYPE_INT }, \
29488768458SSam Leffler 	{ "ecn", CTLTYPE_INT }, \
29588768458SSam Leffler 	{ "debug", CTLTYPE_INT }, \
29688768458SSam Leffler 	{ "esp_randpad", CTLTYPE_INT }, \
29788768458SSam Leffler }
29888768458SSam Leffler 
29988768458SSam Leffler #define IPSEC6CTL_NAMES { \
30088768458SSam Leffler 	{ 0, 0 }, \
30188768458SSam Leffler 	{ 0, 0 }, \
30288768458SSam Leffler 	{ "def_policy", CTLTYPE_INT }, \
30388768458SSam Leffler 	{ "esp_trans_deflev", CTLTYPE_INT }, \
30488768458SSam Leffler 	{ "esp_net_deflev", CTLTYPE_INT }, \
30588768458SSam Leffler 	{ "ah_trans_deflev", CTLTYPE_INT }, \
30688768458SSam Leffler 	{ "ah_net_deflev", CTLTYPE_INT }, \
30788768458SSam Leffler 	{ 0, 0 }, \
30888768458SSam Leffler 	{ 0, 0 }, \
30988768458SSam Leffler 	{ 0, 0 }, \
31088768458SSam Leffler 	{ 0, 0 }, \
31188768458SSam Leffler 	{ "ecn", CTLTYPE_INT }, \
31288768458SSam Leffler 	{ "debug", CTLTYPE_INT }, \
31388768458SSam Leffler 	{ "esp_randpad", CTLTYPE_INT }, \
31488768458SSam Leffler }
31588768458SSam Leffler 
31688768458SSam Leffler #ifdef _KERNEL
31788768458SSam Leffler struct ipsec_output_state {
31888768458SSam Leffler 	struct mbuf *m;
31988768458SSam Leffler 	struct route *ro;
32088768458SSam Leffler 	struct sockaddr *dst;
32188768458SSam Leffler };
32288768458SSam Leffler 
32388768458SSam Leffler struct ipsec_history {
32488768458SSam Leffler 	int ih_proto;
32588768458SSam Leffler 	u_int32_t ih_spi;
32688768458SSam Leffler };
32788768458SSam Leffler 
32888768458SSam Leffler extern int ipsec_debug;
32988768458SSam Leffler 
33088768458SSam Leffler extern struct newipsecstat newipsecstat;
33188768458SSam Leffler extern struct secpolicy ip4_def_policy;
33288768458SSam Leffler extern int ip4_esp_trans_deflev;
33388768458SSam Leffler extern int ip4_esp_net_deflev;
33488768458SSam Leffler extern int ip4_ah_trans_deflev;
33588768458SSam Leffler extern int ip4_ah_net_deflev;
33688768458SSam Leffler extern int ip4_ah_cleartos;
33788768458SSam Leffler extern int ip4_ah_offsetmask;
33888768458SSam Leffler extern int ip4_ipsec_dfbit;
33988768458SSam Leffler extern int ip4_ipsec_ecn;
34088768458SSam Leffler extern int ip4_esp_randpad;
34188768458SSam Leffler extern int crypto_support;
34288768458SSam Leffler 
34388768458SSam Leffler #define ipseclog(x)	do { if (ipsec_debug) log x; } while (0)
34488768458SSam Leffler /* for openbsd compatibility */
34588768458SSam Leffler #define	DPRINTF(x)	do { if (ipsec_debug) printf x; } while (0)
34688768458SSam Leffler 
3476464079fSSam Leffler extern	struct ipsecrequest *ipsec_newisr(void);
3486464079fSSam Leffler extern	void ipsec_delisr(struct ipsecrequest *);
3496464079fSSam Leffler 
35088768458SSam Leffler struct tdb_ident;
35188768458SSam Leffler extern struct secpolicy *ipsec_getpolicy __P((struct tdb_ident*, u_int));
35288768458SSam Leffler struct inpcb;
35388768458SSam Leffler extern struct secpolicy *ipsec4_checkpolicy __P((struct mbuf *, u_int, u_int,
35488768458SSam Leffler 	int *, struct inpcb *));
35588768458SSam Leffler extern struct secpolicy *ipsec_getpolicybysock(struct mbuf *, u_int,
35688768458SSam Leffler 	struct inpcb *, int *);
35788768458SSam Leffler extern struct secpolicy * ipsec_getpolicybyaddr(struct mbuf *, u_int,
35888768458SSam Leffler 	int, int *);
35988768458SSam Leffler 
36088768458SSam Leffler struct inpcb;
36188768458SSam Leffler extern int ipsec_init_policy __P((struct socket *so, struct inpcbpolicy **));
36288768458SSam Leffler extern int ipsec_copy_policy
36388768458SSam Leffler 	__P((struct inpcbpolicy *, struct inpcbpolicy *));
36488768458SSam Leffler extern u_int ipsec_get_reqlevel __P((struct ipsecrequest *));
36588768458SSam Leffler extern int ipsec_in_reject __P((struct secpolicy *, struct mbuf *));
36688768458SSam Leffler 
36788768458SSam Leffler extern int ipsec4_set_policy __P((struct inpcb *inp, int optname,
36888768458SSam Leffler 	caddr_t request, size_t len, int priv));
36988768458SSam Leffler extern int ipsec4_get_policy __P((struct inpcb *inpcb, caddr_t request,
37088768458SSam Leffler 	size_t len, struct mbuf **mp));
37188768458SSam Leffler extern int ipsec4_delete_pcbpolicy __P((struct inpcb *));
37288768458SSam Leffler extern int ipsec4_in_reject __P((struct mbuf *, struct inpcb *));
37388768458SSam Leffler 
37488768458SSam Leffler struct secas;
37588768458SSam Leffler struct tcpcb;
37688768458SSam Leffler extern int ipsec_chkreplay __P((u_int32_t, struct secasvar *));
37788768458SSam Leffler extern int ipsec_updatereplay __P((u_int32_t, struct secasvar *));
37888768458SSam Leffler 
37988768458SSam Leffler extern size_t ipsec4_hdrsiz __P((struct mbuf *, u_int, struct inpcb *));
38088768458SSam Leffler extern size_t ipsec_hdrsiz_tcp __P((struct tcpcb *));
38188768458SSam Leffler 
38288768458SSam Leffler union sockaddr_union;
38388768458SSam Leffler extern char * ipsec_address(union sockaddr_union* sa);
38488768458SSam Leffler extern const char *ipsec_logsastr __P((struct secasvar *));
38588768458SSam Leffler 
38688768458SSam Leffler extern void ipsec_dumpmbuf __P((struct mbuf *));
38788768458SSam Leffler 
38888768458SSam Leffler struct m_tag;
389e8539d32SSam Leffler extern void ah4_input(struct mbuf *m, int off);
3909ffa9677SSam Leffler extern void ah4_ctlinput(int cmd, struct sockaddr *sa, void *);
391e8539d32SSam Leffler extern void esp4_input(struct mbuf *m, int off);
3929ffa9677SSam Leffler extern void esp4_ctlinput(int cmd, struct sockaddr *sa, void *);
393e8539d32SSam Leffler extern void ipcomp4_input(struct mbuf *m, int off);
39488768458SSam Leffler extern int ipsec4_common_input(struct mbuf *m, ...);
39588768458SSam Leffler extern int ipsec4_common_input_cb(struct mbuf *m, struct secasvar *sav,
39688768458SSam Leffler 			int skip, int protoff, struct m_tag *mt);
39788768458SSam Leffler extern int ipsec4_process_packet __P((struct mbuf *, struct ipsecrequest *,
39888768458SSam Leffler 			int, int));
39988768458SSam Leffler extern int ipsec_process_done __P((struct mbuf *, struct ipsecrequest *));
40088768458SSam Leffler 
40188768458SSam Leffler extern struct mbuf *ipsec_copypkt __P((struct mbuf *));
40288768458SSam Leffler 
40388768458SSam Leffler extern	void m_checkalignment(const char* where, struct mbuf *m0,
40488768458SSam Leffler 		int off, int len);
40588768458SSam Leffler extern	struct mbuf *m_clone(struct mbuf *m0);
40688768458SSam Leffler extern	struct mbuf *m_makespace(struct mbuf *m0, int skip, int hlen, int *off);
40788768458SSam Leffler extern	caddr_t m_pad(struct mbuf *m, int n);
40888768458SSam Leffler extern	int m_striphdr(struct mbuf *m, int skip, int hlen);
40988768458SSam Leffler #endif /* _KERNEL */
41088768458SSam Leffler 
41188768458SSam Leffler #ifndef _KERNEL
41288768458SSam Leffler extern caddr_t ipsec_set_policy __P((char *, int));
41388768458SSam Leffler extern int ipsec_get_policylen __P((caddr_t));
41488768458SSam Leffler extern char *ipsec_dump_policy __P((caddr_t, char *));
41588768458SSam Leffler 
41688768458SSam Leffler extern const char *ipsec_strerror __P((void));
41788768458SSam Leffler #endif /* !_KERNEL */
41888768458SSam Leffler 
41988768458SSam Leffler #endif /* _NETIPSEC_IPSEC_H_ */
420