xref: /freebsd/sys/netipsec/ipsec.h (revision b1c3a4d75f4ff74218434a11cdd4e56632e13711)
188768458SSam Leffler /*	$KAME: ipsec.h,v 1.53 2001/11/20 08:32:38 itojun Exp $	*/
288768458SSam Leffler 
3c398230bSWarner Losh /*-
451369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
551369649SPedro F. Giffuni  *
688768458SSam Leffler  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
788768458SSam Leffler  * All rights reserved.
888768458SSam Leffler  *
988768458SSam Leffler  * Redistribution and use in source and binary forms, with or without
1088768458SSam Leffler  * modification, are permitted provided that the following conditions
1188768458SSam Leffler  * are met:
1288768458SSam Leffler  * 1. Redistributions of source code must retain the above copyright
1388768458SSam Leffler  *    notice, this list of conditions and the following disclaimer.
1488768458SSam Leffler  * 2. Redistributions in binary form must reproduce the above copyright
1588768458SSam Leffler  *    notice, this list of conditions and the following disclaimer in the
1688768458SSam Leffler  *    documentation and/or other materials provided with the distribution.
1788768458SSam Leffler  * 3. Neither the name of the project nor the names of its contributors
1888768458SSam Leffler  *    may be used to endorse or promote products derived from this software
1988768458SSam Leffler  *    without specific prior written permission.
2088768458SSam Leffler  *
2188768458SSam Leffler  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
2288768458SSam Leffler  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2388768458SSam Leffler  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2488768458SSam Leffler  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2588768458SSam Leffler  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2688768458SSam Leffler  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2788768458SSam Leffler  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2888768458SSam Leffler  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2988768458SSam Leffler  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3088768458SSam Leffler  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3188768458SSam Leffler  * SUCH DAMAGE.
3288768458SSam Leffler  */
3388768458SSam Leffler 
3488768458SSam Leffler /*
3588768458SSam Leffler  * IPsec controller part.
3688768458SSam Leffler  */
3788768458SSam Leffler 
3888768458SSam Leffler #ifndef _NETIPSEC_IPSEC_H_
3988768458SSam Leffler #define _NETIPSEC_IPSEC_H_
4088768458SSam Leffler 
4188768458SSam Leffler #include <net/pfkeyv2.h>
4288768458SSam Leffler #include <netipsec/keydb.h>
4388768458SSam Leffler 
4488768458SSam Leffler #ifdef _KERNEL
4588768458SSam Leffler 
462d957916SAndrey V. Elsukov #include <sys/_lock.h>
472d957916SAndrey V. Elsukov #include <sys/_mutex.h>
482d957916SAndrey V. Elsukov #include <sys/_rwlock.h>
496023bd1dSKonstantin Belousov #include <sys/sysctl.h>
502d957916SAndrey V. Elsukov 
51*b1c3a4d7SKristof Provost #include <netinet/in_kdtrace.h>
52*b1c3a4d7SKristof Provost 
534b4b5fb6SGeorge V. Neville-Neil #define	IPSEC_ASSERT(_c,_m) KASSERT(_c, _m)
544b4b5fb6SGeorge V. Neville-Neil 
5588768458SSam Leffler /*
5688768458SSam Leffler  * Security Policy Index
5788768458SSam Leffler  * Ensure that both address families in the "src" and "dst" are same.
5888768458SSam Leffler  * When the value of the ul_proto is ICMPv6, the port field in "src"
5988768458SSam Leffler  * specifies ICMPv6 type, and the port field in "dst" specifies ICMPv6 code.
6088768458SSam Leffler  */
6188768458SSam Leffler struct secpolicyindex {
6288768458SSam Leffler 	union sockaddr_union src;	/* IP src address for SP */
6388768458SSam Leffler 	union sockaddr_union dst;	/* IP dst address for SP */
64fcf59617SAndrey V. Elsukov 	uint8_t ul_proto;		/* upper layer Protocol */
65fcf59617SAndrey V. Elsukov 	uint8_t dir;			/* direction of packet flow */
66fcf59617SAndrey V. Elsukov 	uint8_t prefs;			/* prefix length in bits for src */
67fcf59617SAndrey V. Elsukov 	uint8_t prefd;			/* prefix length in bits for dst */
68fcf59617SAndrey V. Elsukov };
69fcf59617SAndrey V. Elsukov 
70fcf59617SAndrey V. Elsukov /* Request for IPsec */
71fcf59617SAndrey V. Elsukov struct ipsecrequest {
72fcf59617SAndrey V. Elsukov 	struct secasindex saidx;/* hint for search proper SA */
73fcf59617SAndrey V. Elsukov 				/* if __ss_len == 0 then no address specified.*/
74fcf59617SAndrey V. Elsukov 	u_int level;		/* IPsec level defined below. */
7588768458SSam Leffler };
7688768458SSam Leffler 
77ef2a572bSKonstantin Belousov struct ipsec_accel_adddel_sp_tq {
78ef2a572bSKonstantin Belousov 	struct vnet *adddel_vnet;
79ef2a572bSKonstantin Belousov 	struct task adddel_task;
80ef2a572bSKonstantin Belousov 	int adddel_scheduled;
81ef2a572bSKonstantin Belousov };
82ef2a572bSKonstantin Belousov 
8388768458SSam Leffler /* Security Policy Data Base */
8488768458SSam Leffler struct secpolicy {
8593201211SAndrey V. Elsukov 	TAILQ_ENTRY(secpolicy) chain;
86fcf59617SAndrey V. Elsukov 	LIST_ENTRY(secpolicy) idhash;
87fcf59617SAndrey V. Elsukov 	LIST_ENTRY(secpolicy) drainq;
8888768458SSam Leffler 
8988768458SSam Leffler 	struct secpolicyindex spidx;	/* selector */
90fcf59617SAndrey V. Elsukov #define	IPSEC_MAXREQ		4
91fcf59617SAndrey V. Elsukov 	struct ipsecrequest *req[IPSEC_MAXREQ];
92fcf59617SAndrey V. Elsukov 	u_int tcount;			/* IPsec transforms count */
93fcf59617SAndrey V. Elsukov 	volatile u_int refcnt;		/* reference count */
9493201211SAndrey V. Elsukov 	u_int policy;			/* policy_type per pfkeyv2.h */
9547568136SAndrey V. Elsukov 	u_int state;
9647568136SAndrey V. Elsukov #define	IPSEC_SPSTATE_DEAD	0
97fcf59617SAndrey V. Elsukov #define	IPSEC_SPSTATE_LARVAL	1
98fcf59617SAndrey V. Elsukov #define	IPSEC_SPSTATE_ALIVE	2
99fcf59617SAndrey V. Elsukov #define	IPSEC_SPSTATE_PCB	3
100fcf59617SAndrey V. Elsukov #define	IPSEC_SPSTATE_IFNET	4
101fcf59617SAndrey V. Elsukov 	uint32_t priority;		/* priority of this policy */
102fcf59617SAndrey V. Elsukov 	uint32_t id;			/* It's unique number on the system. */
10388768458SSam Leffler 	/*
10488768458SSam Leffler 	 * lifetime handler.
10588768458SSam Leffler 	 * the policy can be used without limitiation if both lifetime and
10688768458SSam Leffler 	 * validtime are zero.
10788768458SSam Leffler 	 * "lifetime" is passed by sadb_lifetime.sadb_lifetime_addtime.
10888768458SSam Leffler 	 * "validtime" is passed by sadb_lifetime.sadb_lifetime_usetime.
10988768458SSam Leffler 	 */
1109ffa9677SSam Leffler 	time_t created;		/* time created the policy */
1119ffa9677SSam Leffler 	time_t lastused;	/* updated every when kernel sends a packet */
11288768458SSam Leffler 	long lifetime;		/* duration of the lifetime of this policy */
11388768458SSam Leffler 	long validtime;		/* duration this policy is valid without use */
114ef2a572bSKonstantin Belousov 	CK_LIST_HEAD(, ifp_handle_sp) accel_ifps;
115ef2a572bSKonstantin Belousov 	struct ipsec_accel_adddel_sp_tq accel_add_tq;
116ef2a572bSKonstantin Belousov 	struct ipsec_accel_adddel_sp_tq accel_del_tq;
117ef2a572bSKonstantin Belousov 	struct inpcb *ipsec_accel_add_sp_inp;
118ef2a572bSKonstantin Belousov 	const char *accel_ifname;
11988768458SSam Leffler };
12088768458SSam Leffler 
1219ffa9677SSam Leffler /*
122fcf59617SAndrey V. Elsukov  * PCB security policies.
123fcf59617SAndrey V. Elsukov  * Application can setup private security policies for socket.
124fcf59617SAndrey V. Elsukov  * Such policies can have IPSEC, BYPASS and ENTRUST type.
125fcf59617SAndrey V. Elsukov  * By default, policies are set to NULL. This means that they have ENTRUST type.
126fcf59617SAndrey V. Elsukov  * When application sets BYPASS or IPSEC type policy, the flags field
127fcf59617SAndrey V. Elsukov  * is also updated. When flags is not set, the system could store
128fcf59617SAndrey V. Elsukov  * used security policy into the sp_in/sp_out pointer to speed up further
129fcf59617SAndrey V. Elsukov  * lookups.
1309ffa9677SSam Leffler  */
13188768458SSam Leffler struct inpcbpolicy {
13288768458SSam Leffler 	struct secpolicy	*sp_in;
13388768458SSam Leffler 	struct secpolicy	*sp_out;
134fcf59617SAndrey V. Elsukov 
135fcf59617SAndrey V. Elsukov 	uint32_t		genid;
136fcf59617SAndrey V. Elsukov 	uint16_t		flags;
137fcf59617SAndrey V. Elsukov #define	INP_INBOUND_POLICY	0x0001
138fcf59617SAndrey V. Elsukov #define	INP_OUTBOUND_POLICY	0x0002
139fcf59617SAndrey V. Elsukov 	uint16_t		hdrsz;
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 
154fcf59617SAndrey V. Elsukov /* buffer size for formatted output of ipsec address */
155fcf59617SAndrey V. Elsukov #define	IPSEC_ADDRSTRLEN	(INET6_ADDRSTRLEN + 11)
156fcf59617SAndrey V. Elsukov 
15788768458SSam Leffler /* according to IANA assignment, port 0x0000 and proto 0xff are reserved. */
15888768458SSam Leffler #define IPSEC_PORT_ANY		0
15988768458SSam Leffler #define IPSEC_ULPROTO_ANY	255
16088768458SSam Leffler #define IPSEC_PROTO_ANY		255
16188768458SSam Leffler 
16288768458SSam Leffler /* mode of security protocol */
16388768458SSam Leffler /* NOTE: DON'T use IPSEC_MODE_ANY at SPD.  It's only use in SAD */
16488768458SSam Leffler #define	IPSEC_MODE_ANY		0	/* i.e. wildcard. */
16588768458SSam Leffler #define	IPSEC_MODE_TRANSPORT	1
16688768458SSam Leffler #define	IPSEC_MODE_TUNNEL	2
1671cfd4b53SBruce M Simpson #define	IPSEC_MODE_TCPMD5	3	/* TCP MD5 mode */
16888768458SSam Leffler 
16988768458SSam Leffler /*
17088768458SSam Leffler  * Direction of security policy.
17188768458SSam Leffler  * NOTE: Since INVALID is used just as flag.
17288768458SSam Leffler  * The other are used for loop counter too.
17388768458SSam Leffler  */
17488768458SSam Leffler #define IPSEC_DIR_ANY		0
17588768458SSam Leffler #define IPSEC_DIR_INBOUND	1
17688768458SSam Leffler #define IPSEC_DIR_OUTBOUND	2
17788768458SSam Leffler #define IPSEC_DIR_MAX		3
17888768458SSam Leffler #define IPSEC_DIR_INVALID	4
17988768458SSam Leffler 
18088768458SSam Leffler /* Policy level */
18188768458SSam Leffler /*
18288768458SSam Leffler  * IPSEC, ENTRUST and BYPASS are allowed for setsockopt() in PCB,
18388768458SSam Leffler  * DISCARD, IPSEC and NONE are allowed for setkey() in SPD.
18488768458SSam Leffler  * DISCARD and NONE are allowed for system default.
18588768458SSam Leffler  */
18688768458SSam Leffler #define IPSEC_POLICY_DISCARD	0	/* discarding packet */
18788768458SSam Leffler #define IPSEC_POLICY_NONE	1	/* through IPsec engine */
18888768458SSam Leffler #define IPSEC_POLICY_IPSEC	2	/* do IPsec */
18988768458SSam Leffler #define IPSEC_POLICY_ENTRUST	3	/* consulting SPD if present. */
19088768458SSam Leffler #define IPSEC_POLICY_BYPASS	4	/* only for privileged socket. */
19188768458SSam Leffler 
19222986c67SAndrey V. Elsukov /* Policy scope */
19322986c67SAndrey V. Elsukov #define	IPSEC_POLICYSCOPE_ANY		0x00	/* unspecified */
19422986c67SAndrey V. Elsukov #define	IPSEC_POLICYSCOPE_GLOBAL	0x01	/* global scope */
19522986c67SAndrey V. Elsukov #define	IPSEC_POLICYSCOPE_IFNET		0x02	/* if_ipsec(4) scope */
19622986c67SAndrey V. Elsukov #define	IPSEC_POLICYSCOPE_PCB		0x04	/* PCB scope */
19722986c67SAndrey V. Elsukov 
19888768458SSam Leffler /* Security protocol level */
19988768458SSam Leffler #define	IPSEC_LEVEL_DEFAULT	0	/* reference to system default */
20088768458SSam Leffler #define	IPSEC_LEVEL_USE		1	/* use SA if present. */
20188768458SSam Leffler #define	IPSEC_LEVEL_REQUIRE	2	/* require SA. */
20288768458SSam Leffler #define	IPSEC_LEVEL_UNIQUE	3	/* unique SA. */
20388768458SSam Leffler 
20488768458SSam Leffler #define IPSEC_MANUAL_REQID_MAX	0x3fff
20588768458SSam Leffler 				/*
20688768458SSam Leffler 				 * if security policy level == unique, this id
20788768458SSam Leffler 				 * indicate to a relative SA for use, else is
20888768458SSam Leffler 				 * zero.
20988768458SSam Leffler 				 * 1 - 0x3fff are reserved for manual keying.
21088768458SSam Leffler 				 * 0 are reserved for above reason.  Others is
21188768458SSam Leffler 				 * for kernel use.
21288768458SSam Leffler 				 * Note that this id doesn't identify SA
21388768458SSam Leffler 				 * by only itself.
21488768458SSam Leffler 				 */
21588768458SSam Leffler #define IPSEC_REPLAYWSIZE  32
21688768458SSam Leffler 
2172cb64cb2SGeorge V. Neville-Neil /* statistics for ipsec processing */
21888768458SSam Leffler struct ipsecstat {
219c80211e3SAndrey V. Elsukov 	uint64_t ips_in_polvio;		/* input: sec policy violation */
2206794f460SAndrey V. Elsukov 	uint64_t ips_in_nomem;		/* input: no memory available */
2216794f460SAndrey V. Elsukov 	uint64_t ips_in_inval;		/* input: generic error */
2226794f460SAndrey V. Elsukov 
223c80211e3SAndrey V. Elsukov 	uint64_t ips_out_polvio;	/* output: sec policy violation */
224c80211e3SAndrey V. Elsukov 	uint64_t ips_out_nosa;		/* output: SA unavailable  */
225c80211e3SAndrey V. Elsukov 	uint64_t ips_out_nomem;		/* output: no memory available */
226c80211e3SAndrey V. Elsukov 	uint64_t ips_out_noroute;	/* output: no route available */
227c80211e3SAndrey V. Elsukov 	uint64_t ips_out_inval;		/* output: generic error */
228c80211e3SAndrey V. Elsukov 	uint64_t ips_out_bundlesa;	/* output: bundled SA processed */
2296794f460SAndrey V. Elsukov 
230f8e73c47SFabien Thomas 	uint64_t ips_spdcache_hits;	/* SPD cache hits */
231f8e73c47SFabien Thomas 	uint64_t ips_spdcache_misses;	/* SPD cache misses */
232f8e73c47SFabien Thomas 
233c80211e3SAndrey V. Elsukov 	uint64_t ips_clcopied;		/* clusters copied during clone */
234c80211e3SAndrey V. Elsukov 	uint64_t ips_mbinserted;	/* mbufs inserted during makespace */
23588768458SSam Leffler 	/*
23688768458SSam Leffler 	 * Temporary statistics for performance analysis.
23788768458SSam Leffler 	 */
23888768458SSam Leffler 	/* See where ESP/AH/IPCOMP header land in mbuf on input */
239c80211e3SAndrey V. Elsukov 	uint64_t ips_input_front;
240c80211e3SAndrey V. Elsukov 	uint64_t ips_input_middle;
241c80211e3SAndrey V. Elsukov 	uint64_t ips_input_end;
24288768458SSam Leffler };
24388768458SSam Leffler 
24488768458SSam Leffler /*
24588768458SSam Leffler  * Definitions for IPsec & Key sysctl operations.
24688768458SSam Leffler  */
24788768458SSam Leffler #define IPSECCTL_STATS			1	/* stats */
24888768458SSam Leffler #define IPSECCTL_DEF_POLICY		2
24988768458SSam Leffler #define IPSECCTL_DEF_ESP_TRANSLEV	3	/* int; ESP transport mode */
25088768458SSam Leffler #define IPSECCTL_DEF_ESP_NETLEV		4	/* int; ESP tunnel mode */
25188768458SSam Leffler #define IPSECCTL_DEF_AH_TRANSLEV	5	/* int; AH transport mode */
25288768458SSam Leffler #define IPSECCTL_DEF_AH_NETLEV		6	/* int; AH tunnel mode */
25388768458SSam Leffler #if 0	/* obsolete, do not reuse */
25488768458SSam Leffler #define IPSECCTL_INBOUND_CALL_IKE	7
25588768458SSam Leffler #endif
25688768458SSam Leffler #define	IPSECCTL_AH_CLEARTOS		8
25788768458SSam Leffler #define	IPSECCTL_AH_OFFSETMASK		9
25888768458SSam Leffler #define	IPSECCTL_DFBIT			10
25988768458SSam Leffler #define	IPSECCTL_ECN			11
26088768458SSam Leffler #define	IPSECCTL_DEBUG			12
26188768458SSam Leffler #define	IPSECCTL_ESP_RANDPAD		13
262d9d59bb1SWojciech Macek #define	IPSECCTL_MIN_PMTU		14
26388768458SSam Leffler 
26488768458SSam Leffler #ifdef _KERNEL
265db8c0879SAndrey V. Elsukov #include <sys/counter.h>
266db8c0879SAndrey V. Elsukov 
267ef91a976SAndrey V. Elsukov struct ipsec_ctx_data;
2681a01e0e7SAndrey V. Elsukov #define	IPSEC_INIT_CTX(_ctx, _mp, _inp, _sav, _af, _enc) do {	\
269ef91a976SAndrey V. Elsukov 	(_ctx)->mp = (_mp);				\
2701a01e0e7SAndrey V. Elsukov 	(_ctx)->inp = (_inp);				\
271ef91a976SAndrey V. Elsukov 	(_ctx)->sav = (_sav);				\
272ef91a976SAndrey V. Elsukov 	(_ctx)->af = (_af);				\
273ef91a976SAndrey V. Elsukov 	(_ctx)->enc = (_enc);				\
274ef91a976SAndrey V. Elsukov } while(0)
275ef91a976SAndrey V. Elsukov int	ipsec_run_hhooks(struct ipsec_ctx_data *ctx, int direction);
276ef91a976SAndrey V. Elsukov 
277eddfbb76SRobert Watson VNET_DECLARE(int, ipsec_debug);
2781e77c105SRobert Watson #define	V_ipsec_debug		VNET(ipsec_debug)
279eddfbb76SRobert Watson 
280eddfbb76SRobert Watson #ifdef REGRESSION
281eddfbb76SRobert Watson VNET_DECLARE(int, ipsec_replay);
282eddfbb76SRobert Watson VNET_DECLARE(int, ipsec_integrity);
28382cea7e6SBjoern A. Zeeb 
28482cea7e6SBjoern A. Zeeb #define	V_ipsec_replay		VNET(ipsec_replay)
2851e77c105SRobert Watson #define	V_ipsec_integrity	VNET(ipsec_integrity)
286eddfbb76SRobert Watson #endif
28788768458SSam Leffler 
288db8c0879SAndrey V. Elsukov VNET_PCPUSTAT_DECLARE(struct ipsecstat, ipsec4stat);
28982cea7e6SBjoern A. Zeeb VNET_DECLARE(int, ip4_esp_trans_deflev);
29082cea7e6SBjoern A. Zeeb VNET_DECLARE(int, ip4_esp_net_deflev);
29182cea7e6SBjoern A. Zeeb VNET_DECLARE(int, ip4_ah_trans_deflev);
29282cea7e6SBjoern A. Zeeb VNET_DECLARE(int, ip4_ah_net_deflev);
29382cea7e6SBjoern A. Zeeb VNET_DECLARE(int, ip4_ipsec_dfbit);
294d9d59bb1SWojciech Macek VNET_DECLARE(int, ip4_ipsec_min_pmtu);
29582cea7e6SBjoern A. Zeeb VNET_DECLARE(int, ip4_ipsec_ecn);
29682cea7e6SBjoern A. Zeeb VNET_DECLARE(int, crypto_support);
29739bbca6fSFabien Thomas VNET_DECLARE(int, async_crypto);
298fcf59617SAndrey V. Elsukov VNET_DECLARE(int, natt_cksum_policy);
29982cea7e6SBjoern A. Zeeb 
300db8c0879SAndrey V. Elsukov #define IPSECSTAT_INC(name)                                               \
301*b1c3a4d7SKristof Provost 	do {                                                              \
302*b1c3a4d7SKristof Provost 		MIB_SDT_PROBE1(ipsec, count, name, 1);                    \
303*b1c3a4d7SKristof Provost 		VNET_PCPUSTAT_ADD(struct ipsecstat, ipsec4stat, name, 1); \
304*b1c3a4d7SKristof Provost 	} while (0)
305*b1c3a4d7SKristof Provost 
30682cea7e6SBjoern A. Zeeb #define	V_ip4_esp_trans_deflev	VNET(ip4_esp_trans_deflev)
30782cea7e6SBjoern A. Zeeb #define	V_ip4_esp_net_deflev	VNET(ip4_esp_net_deflev)
30882cea7e6SBjoern A. Zeeb #define	V_ip4_ah_trans_deflev	VNET(ip4_ah_trans_deflev)
30982cea7e6SBjoern A. Zeeb #define	V_ip4_ah_net_deflev	VNET(ip4_ah_net_deflev)
31082cea7e6SBjoern A. Zeeb #define	V_ip4_ipsec_dfbit	VNET(ip4_ipsec_dfbit)
311d9d59bb1SWojciech Macek #define	V_ip4_ipsec_min_pmtu	VNET(ip4_ipsec_min_pmtu)
31282cea7e6SBjoern A. Zeeb #define	V_ip4_ipsec_ecn		VNET(ip4_ipsec_ecn)
31382cea7e6SBjoern A. Zeeb #define	V_crypto_support	VNET(crypto_support)
31439bbca6fSFabien Thomas #define	V_async_crypto		VNET(async_crypto)
315fcf59617SAndrey V. Elsukov #define	V_natt_cksum_policy	VNET(natt_cksum_policy)
31682cea7e6SBjoern A. Zeeb 
317603724d3SBjoern A. Zeeb #define ipseclog(x)	do { if (V_ipsec_debug) log x; } while (0)
31888768458SSam Leffler /* for openbsd compatibility */
3197f1f6591SAndrey V. Elsukov #ifdef IPSEC_DEBUG
3207f1f6591SAndrey V. Elsukov #define	IPSEC_DEBUG_DECLARE(x)	x
321603724d3SBjoern A. Zeeb #define	DPRINTF(x)	do { if (V_ipsec_debug) printf x; } while (0)
3227f1f6591SAndrey V. Elsukov #else
3237f1f6591SAndrey V. Elsukov #define	IPSEC_DEBUG_DECLARE(x)
3247f1f6591SAndrey V. Elsukov #define	DPRINTF(x)
3257f1f6591SAndrey V. Elsukov #endif
32688768458SSam Leffler 
32788768458SSam Leffler struct inpcb;
328fcf59617SAndrey V. Elsukov struct m_tag;
329fcf59617SAndrey V. Elsukov struct secasvar;
330fcf59617SAndrey V. Elsukov struct sockopt;
331fcf59617SAndrey V. Elsukov struct tcphdr;
332fcf59617SAndrey V. Elsukov union sockaddr_union;
333fcf59617SAndrey V. Elsukov 
334fcf59617SAndrey V. Elsukov int ipsec_if_input(struct mbuf *, struct secasvar *, uint32_t);
335fcf59617SAndrey V. Elsukov 
336fcf59617SAndrey V. Elsukov struct ipsecrequest *ipsec_newisr(void);
337fcf59617SAndrey V. Elsukov void ipsec_delisr(struct ipsecrequest *);
338fcf59617SAndrey V. Elsukov struct secpolicy *ipsec4_checkpolicy(const struct mbuf *, struct inpcb *,
33922bbefb2SAndrey V. Elsukov     int *, int);
34088768458SSam Leffler 
341fcf59617SAndrey V. Elsukov u_int ipsec_get_reqlevel(struct secpolicy *, u_int);
34288768458SSam Leffler 
343fcf59617SAndrey V. Elsukov void udp_ipsec_adjust_cksum(struct mbuf *, struct secasvar *, int, int);
344fcf59617SAndrey V. Elsukov int udp_ipsec_output(struct mbuf *, struct secasvar *);
34588768458SSam Leffler 
3468b7f3994SMarcin Wojtas int ipsec_chkreplay(uint32_t, uint32_t *, struct secasvar *);
347fcf59617SAndrey V. Elsukov int ipsec_updatereplay(uint32_t, struct secasvar *);
3482e08e39fSConrad Meyer int ipsec_updateid(struct secasvar *, crypto_session_t *, crypto_session_t *);
349fcf59617SAndrey V. Elsukov int ipsec_initialized(void);
3506b66194bSKornel Duleba size_t ipsec_hdrsiz_internal(struct secpolicy *);
35188768458SSam Leffler 
352fcf59617SAndrey V. Elsukov void ipsec_setspidx_inpcb(struct inpcb *, struct secpolicyindex *, u_int);
35388768458SSam Leffler 
354fcf59617SAndrey V. Elsukov void ipsec4_setsockaddrs(const struct mbuf *, union sockaddr_union *,
355fcf59617SAndrey V. Elsukov     union sockaddr_union *);
356fcf59617SAndrey V. Elsukov int ipsec4_common_input_cb(struct mbuf *, struct secasvar *, int, int);
357de1da299SKonstantin Belousov int ipsec4_check_pmtu(struct ifnet *, struct mbuf *, struct secpolicy *, int);
358de1da299SKonstantin Belousov int ipsec4_process_packet(struct ifnet *, struct mbuf *, struct secpolicy *,
35900524fd4SKonstantin Belousov     struct inpcb *, u_long);
360fcf59617SAndrey V. Elsukov int ipsec_process_done(struct mbuf *, struct secpolicy *, struct secasvar *,
361fcf59617SAndrey V. Elsukov     u_int);
36288768458SSam Leffler 
363eb0fdc77SKonstantin Belousov void m_checkalignment(const char* where, struct mbuf *m0,
36488768458SSam Leffler     int off, int len);
365eb0fdc77SKonstantin Belousov struct mbuf *m_makespace(struct mbuf *m0, int skip, int hlen, int *off);
366eb0fdc77SKonstantin Belousov caddr_t m_pad(struct mbuf *m, int n);
367eb0fdc77SKonstantin Belousov int m_striphdr(struct mbuf *m, int skip, int hlen);
36819ad9831SBjoern A. Zeeb 
3696023bd1dSKonstantin Belousov SYSCTL_DECL(_net_inet_ipsec);
3706023bd1dSKonstantin Belousov SYSCTL_DECL(_net_inet6_ipsec6);
3716023bd1dSKonstantin Belousov 
37288768458SSam Leffler #endif /* _KERNEL */
37388768458SSam Leffler 
37488768458SSam Leffler #ifndef _KERNEL
375eb0fdc77SKonstantin Belousov caddr_t ipsec_set_policy(const char *, int);
376eb0fdc77SKonstantin Belousov int ipsec_get_policylen(c_caddr_t);
377eb0fdc77SKonstantin Belousov char *ipsec_dump_policy(c_caddr_t, const char *);
378eb0fdc77SKonstantin Belousov const char *ipsec_strerror(void);
3798b615593SMarko Zec 
3808b615593SMarko Zec #endif /* ! KERNEL */
38188768458SSam Leffler 
38288768458SSam Leffler #endif /* _NETIPSEC_IPSEC_H_ */
383