xref: /freebsd/sys/netipsec/ipsec.h (revision eb0fdc77533db88d309a73f67f19222843597267)
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>
492d957916SAndrey V. Elsukov 
504b4b5fb6SGeorge V. Neville-Neil #define	IPSEC_ASSERT(_c,_m) KASSERT(_c, _m)
514b4b5fb6SGeorge V. Neville-Neil 
5288768458SSam Leffler /*
5388768458SSam Leffler  * Security Policy Index
5488768458SSam Leffler  * Ensure that both address families in the "src" and "dst" are same.
5588768458SSam Leffler  * When the value of the ul_proto is ICMPv6, the port field in "src"
5688768458SSam Leffler  * specifies ICMPv6 type, and the port field in "dst" specifies ICMPv6 code.
5788768458SSam Leffler  */
5888768458SSam Leffler struct secpolicyindex {
5988768458SSam Leffler 	union sockaddr_union src;	/* IP src address for SP */
6088768458SSam Leffler 	union sockaddr_union dst;	/* IP dst address for SP */
61fcf59617SAndrey V. Elsukov 	uint8_t ul_proto;		/* upper layer Protocol */
62fcf59617SAndrey V. Elsukov 	uint8_t dir;			/* direction of packet flow */
63fcf59617SAndrey V. Elsukov 	uint8_t prefs;			/* prefix length in bits for src */
64fcf59617SAndrey V. Elsukov 	uint8_t prefd;			/* prefix length in bits for dst */
65fcf59617SAndrey V. Elsukov };
66fcf59617SAndrey V. Elsukov 
67fcf59617SAndrey V. Elsukov /* Request for IPsec */
68fcf59617SAndrey V. Elsukov struct ipsecrequest {
69fcf59617SAndrey V. Elsukov 	struct secasindex saidx;/* hint for search proper SA */
70fcf59617SAndrey V. Elsukov 				/* if __ss_len == 0 then no address specified.*/
71fcf59617SAndrey V. Elsukov 	u_int level;		/* IPsec level defined below. */
7288768458SSam Leffler };
7388768458SSam Leffler 
74ef2a572bSKonstantin Belousov struct ipsec_accel_adddel_sp_tq {
75ef2a572bSKonstantin Belousov 	struct vnet *adddel_vnet;
76ef2a572bSKonstantin Belousov 	struct task adddel_task;
77ef2a572bSKonstantin Belousov 	int adddel_scheduled;
78ef2a572bSKonstantin Belousov };
79ef2a572bSKonstantin Belousov 
8088768458SSam Leffler /* Security Policy Data Base */
8188768458SSam Leffler struct secpolicy {
8293201211SAndrey V. Elsukov 	TAILQ_ENTRY(secpolicy) chain;
83fcf59617SAndrey V. Elsukov 	LIST_ENTRY(secpolicy) idhash;
84fcf59617SAndrey V. Elsukov 	LIST_ENTRY(secpolicy) drainq;
8588768458SSam Leffler 
8688768458SSam Leffler 	struct secpolicyindex spidx;	/* selector */
87fcf59617SAndrey V. Elsukov #define	IPSEC_MAXREQ		4
88fcf59617SAndrey V. Elsukov 	struct ipsecrequest *req[IPSEC_MAXREQ];
89fcf59617SAndrey V. Elsukov 	u_int tcount;			/* IPsec transforms count */
90fcf59617SAndrey V. Elsukov 	volatile u_int refcnt;		/* reference count */
9193201211SAndrey V. Elsukov 	u_int policy;			/* policy_type per pfkeyv2.h */
9247568136SAndrey V. Elsukov 	u_int state;
9347568136SAndrey V. Elsukov #define	IPSEC_SPSTATE_DEAD	0
94fcf59617SAndrey V. Elsukov #define	IPSEC_SPSTATE_LARVAL	1
95fcf59617SAndrey V. Elsukov #define	IPSEC_SPSTATE_ALIVE	2
96fcf59617SAndrey V. Elsukov #define	IPSEC_SPSTATE_PCB	3
97fcf59617SAndrey V. Elsukov #define	IPSEC_SPSTATE_IFNET	4
98fcf59617SAndrey V. Elsukov 	uint32_t priority;		/* priority of this policy */
99fcf59617SAndrey V. Elsukov 	uint32_t id;			/* It's unique number on the system. */
10088768458SSam Leffler 	/*
10188768458SSam Leffler 	 * lifetime handler.
10288768458SSam Leffler 	 * the policy can be used without limitiation if both lifetime and
10388768458SSam Leffler 	 * validtime are zero.
10488768458SSam Leffler 	 * "lifetime" is passed by sadb_lifetime.sadb_lifetime_addtime.
10588768458SSam Leffler 	 * "validtime" is passed by sadb_lifetime.sadb_lifetime_usetime.
10688768458SSam Leffler 	 */
1079ffa9677SSam Leffler 	time_t created;		/* time created the policy */
1089ffa9677SSam Leffler 	time_t lastused;	/* updated every when kernel sends a packet */
10988768458SSam Leffler 	long lifetime;		/* duration of the lifetime of this policy */
11088768458SSam Leffler 	long validtime;		/* duration this policy is valid without use */
111ef2a572bSKonstantin Belousov 	CK_LIST_HEAD(, ifp_handle_sp) accel_ifps;
112ef2a572bSKonstantin Belousov 	struct ipsec_accel_adddel_sp_tq accel_add_tq;
113ef2a572bSKonstantin Belousov 	struct ipsec_accel_adddel_sp_tq accel_del_tq;
114ef2a572bSKonstantin Belousov 	struct inpcb *ipsec_accel_add_sp_inp;
115ef2a572bSKonstantin Belousov 	const char *accel_ifname;
11688768458SSam Leffler };
11788768458SSam Leffler 
1189ffa9677SSam Leffler /*
119fcf59617SAndrey V. Elsukov  * PCB security policies.
120fcf59617SAndrey V. Elsukov  * Application can setup private security policies for socket.
121fcf59617SAndrey V. Elsukov  * Such policies can have IPSEC, BYPASS and ENTRUST type.
122fcf59617SAndrey V. Elsukov  * By default, policies are set to NULL. This means that they have ENTRUST type.
123fcf59617SAndrey V. Elsukov  * When application sets BYPASS or IPSEC type policy, the flags field
124fcf59617SAndrey V. Elsukov  * is also updated. When flags is not set, the system could store
125fcf59617SAndrey V. Elsukov  * used security policy into the sp_in/sp_out pointer to speed up further
126fcf59617SAndrey V. Elsukov  * lookups.
1279ffa9677SSam Leffler  */
12888768458SSam Leffler struct inpcbpolicy {
12988768458SSam Leffler 	struct secpolicy	*sp_in;
13088768458SSam Leffler 	struct secpolicy	*sp_out;
131fcf59617SAndrey V. Elsukov 
132fcf59617SAndrey V. Elsukov 	uint32_t		genid;
133fcf59617SAndrey V. Elsukov 	uint16_t		flags;
134fcf59617SAndrey V. Elsukov #define	INP_INBOUND_POLICY	0x0001
135fcf59617SAndrey V. Elsukov #define	INP_OUTBOUND_POLICY	0x0002
136fcf59617SAndrey V. Elsukov 	uint16_t		hdrsz;
13788768458SSam Leffler };
13888768458SSam Leffler 
13988768458SSam Leffler /* SP acquiring list table. */
14088768458SSam Leffler struct secspacq {
14188768458SSam Leffler 	LIST_ENTRY(secspacq) chain;
14288768458SSam Leffler 
14388768458SSam Leffler 	struct secpolicyindex spidx;
14488768458SSam Leffler 
1459ffa9677SSam Leffler 	time_t created;		/* for lifetime */
14688768458SSam Leffler 	int count;		/* for lifetime */
14788768458SSam Leffler 	/* XXX: here is mbuf place holder to be sent ? */
14888768458SSam Leffler };
14988768458SSam Leffler #endif /* _KERNEL */
15088768458SSam Leffler 
151fcf59617SAndrey V. Elsukov /* buffer size for formatted output of ipsec address */
152fcf59617SAndrey V. Elsukov #define	IPSEC_ADDRSTRLEN	(INET6_ADDRSTRLEN + 11)
153fcf59617SAndrey V. Elsukov 
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
1641cfd4b53SBruce M Simpson #define	IPSEC_MODE_TCPMD5	3	/* TCP MD5 mode */
16588768458SSam Leffler 
16688768458SSam Leffler /*
16788768458SSam Leffler  * Direction of security policy.
16888768458SSam Leffler  * NOTE: Since INVALID is used just as flag.
16988768458SSam Leffler  * The other are used for loop counter too.
17088768458SSam Leffler  */
17188768458SSam Leffler #define IPSEC_DIR_ANY		0
17288768458SSam Leffler #define IPSEC_DIR_INBOUND	1
17388768458SSam Leffler #define IPSEC_DIR_OUTBOUND	2
17488768458SSam Leffler #define IPSEC_DIR_MAX		3
17588768458SSam Leffler #define IPSEC_DIR_INVALID	4
17688768458SSam Leffler 
17788768458SSam Leffler /* Policy level */
17888768458SSam Leffler /*
17988768458SSam Leffler  * IPSEC, ENTRUST and BYPASS are allowed for setsockopt() in PCB,
18088768458SSam Leffler  * DISCARD, IPSEC and NONE are allowed for setkey() in SPD.
18188768458SSam Leffler  * DISCARD and NONE are allowed for system default.
18288768458SSam Leffler  */
18388768458SSam Leffler #define IPSEC_POLICY_DISCARD	0	/* discarding packet */
18488768458SSam Leffler #define IPSEC_POLICY_NONE	1	/* through IPsec engine */
18588768458SSam Leffler #define IPSEC_POLICY_IPSEC	2	/* do IPsec */
18688768458SSam Leffler #define IPSEC_POLICY_ENTRUST	3	/* consulting SPD if present. */
18788768458SSam Leffler #define IPSEC_POLICY_BYPASS	4	/* only for privileged socket. */
18888768458SSam Leffler 
18922986c67SAndrey V. Elsukov /* Policy scope */
19022986c67SAndrey V. Elsukov #define	IPSEC_POLICYSCOPE_ANY		0x00	/* unspecified */
19122986c67SAndrey V. Elsukov #define	IPSEC_POLICYSCOPE_GLOBAL	0x01	/* global scope */
19222986c67SAndrey V. Elsukov #define	IPSEC_POLICYSCOPE_IFNET		0x02	/* if_ipsec(4) scope */
19322986c67SAndrey V. Elsukov #define	IPSEC_POLICYSCOPE_PCB		0x04	/* PCB scope */
19422986c67SAndrey V. Elsukov 
19588768458SSam Leffler /* Security protocol level */
19688768458SSam Leffler #define	IPSEC_LEVEL_DEFAULT	0	/* reference to system default */
19788768458SSam Leffler #define	IPSEC_LEVEL_USE		1	/* use SA if present. */
19888768458SSam Leffler #define	IPSEC_LEVEL_REQUIRE	2	/* require SA. */
19988768458SSam Leffler #define	IPSEC_LEVEL_UNIQUE	3	/* unique SA. */
20088768458SSam Leffler 
20188768458SSam Leffler #define IPSEC_MANUAL_REQID_MAX	0x3fff
20288768458SSam Leffler 				/*
20388768458SSam Leffler 				 * if security policy level == unique, this id
20488768458SSam Leffler 				 * indicate to a relative SA for use, else is
20588768458SSam Leffler 				 * zero.
20688768458SSam Leffler 				 * 1 - 0x3fff are reserved for manual keying.
20788768458SSam Leffler 				 * 0 are reserved for above reason.  Others is
20888768458SSam Leffler 				 * for kernel use.
20988768458SSam Leffler 				 * Note that this id doesn't identify SA
21088768458SSam Leffler 				 * by only itself.
21188768458SSam Leffler 				 */
21288768458SSam Leffler #define IPSEC_REPLAYWSIZE  32
21388768458SSam Leffler 
2142cb64cb2SGeorge V. Neville-Neil /* statistics for ipsec processing */
21588768458SSam Leffler struct ipsecstat {
216c80211e3SAndrey V. Elsukov 	uint64_t ips_in_polvio;		/* input: sec policy violation */
2176794f460SAndrey V. Elsukov 	uint64_t ips_in_nomem;		/* input: no memory available */
2186794f460SAndrey V. Elsukov 	uint64_t ips_in_inval;		/* input: generic error */
2196794f460SAndrey V. Elsukov 
220c80211e3SAndrey V. Elsukov 	uint64_t ips_out_polvio;	/* output: sec policy violation */
221c80211e3SAndrey V. Elsukov 	uint64_t ips_out_nosa;		/* output: SA unavailable  */
222c80211e3SAndrey V. Elsukov 	uint64_t ips_out_nomem;		/* output: no memory available */
223c80211e3SAndrey V. Elsukov 	uint64_t ips_out_noroute;	/* output: no route available */
224c80211e3SAndrey V. Elsukov 	uint64_t ips_out_inval;		/* output: generic error */
225c80211e3SAndrey V. Elsukov 	uint64_t ips_out_bundlesa;	/* output: bundled SA processed */
2266794f460SAndrey V. Elsukov 
227f8e73c47SFabien Thomas 	uint64_t ips_spdcache_hits;	/* SPD cache hits */
228f8e73c47SFabien Thomas 	uint64_t ips_spdcache_misses;	/* SPD cache misses */
229f8e73c47SFabien Thomas 
230c80211e3SAndrey V. Elsukov 	uint64_t ips_clcopied;		/* clusters copied during clone */
231c80211e3SAndrey V. Elsukov 	uint64_t ips_mbinserted;	/* mbufs inserted during makespace */
23288768458SSam Leffler 	/*
23388768458SSam Leffler 	 * Temporary statistics for performance analysis.
23488768458SSam Leffler 	 */
23588768458SSam Leffler 	/* See where ESP/AH/IPCOMP header land in mbuf on input */
236c80211e3SAndrey V. Elsukov 	uint64_t ips_input_front;
237c80211e3SAndrey V. Elsukov 	uint64_t ips_input_middle;
238c80211e3SAndrey V. Elsukov 	uint64_t ips_input_end;
23988768458SSam Leffler };
24088768458SSam Leffler 
24188768458SSam Leffler /*
24288768458SSam Leffler  * Definitions for IPsec & Key sysctl operations.
24388768458SSam Leffler  */
24488768458SSam Leffler #define IPSECCTL_STATS			1	/* stats */
24588768458SSam Leffler #define IPSECCTL_DEF_POLICY		2
24688768458SSam Leffler #define IPSECCTL_DEF_ESP_TRANSLEV	3	/* int; ESP transport mode */
24788768458SSam Leffler #define IPSECCTL_DEF_ESP_NETLEV		4	/* int; ESP tunnel mode */
24888768458SSam Leffler #define IPSECCTL_DEF_AH_TRANSLEV	5	/* int; AH transport mode */
24988768458SSam Leffler #define IPSECCTL_DEF_AH_NETLEV		6	/* int; AH tunnel mode */
25088768458SSam Leffler #if 0	/* obsolete, do not reuse */
25188768458SSam Leffler #define IPSECCTL_INBOUND_CALL_IKE	7
25288768458SSam Leffler #endif
25388768458SSam Leffler #define	IPSECCTL_AH_CLEARTOS		8
25488768458SSam Leffler #define	IPSECCTL_AH_OFFSETMASK		9
25588768458SSam Leffler #define	IPSECCTL_DFBIT			10
25688768458SSam Leffler #define	IPSECCTL_ECN			11
25788768458SSam Leffler #define	IPSECCTL_DEBUG			12
25888768458SSam Leffler #define	IPSECCTL_ESP_RANDPAD		13
259d9d59bb1SWojciech Macek #define	IPSECCTL_MIN_PMTU		14
26088768458SSam Leffler 
26188768458SSam Leffler #ifdef _KERNEL
262db8c0879SAndrey V. Elsukov #include <sys/counter.h>
263db8c0879SAndrey V. Elsukov 
264ef91a976SAndrey V. Elsukov struct ipsec_ctx_data;
2651a01e0e7SAndrey V. Elsukov #define	IPSEC_INIT_CTX(_ctx, _mp, _inp, _sav, _af, _enc) do {	\
266ef91a976SAndrey V. Elsukov 	(_ctx)->mp = (_mp);				\
2671a01e0e7SAndrey V. Elsukov 	(_ctx)->inp = (_inp);				\
268ef91a976SAndrey V. Elsukov 	(_ctx)->sav = (_sav);				\
269ef91a976SAndrey V. Elsukov 	(_ctx)->af = (_af);				\
270ef91a976SAndrey V. Elsukov 	(_ctx)->enc = (_enc);				\
271ef91a976SAndrey V. Elsukov } while(0)
272ef91a976SAndrey V. Elsukov int	ipsec_run_hhooks(struct ipsec_ctx_data *ctx, int direction);
273ef91a976SAndrey V. Elsukov 
274eddfbb76SRobert Watson VNET_DECLARE(int, ipsec_debug);
2751e77c105SRobert Watson #define	V_ipsec_debug		VNET(ipsec_debug)
276eddfbb76SRobert Watson 
277eddfbb76SRobert Watson #ifdef REGRESSION
278eddfbb76SRobert Watson VNET_DECLARE(int, ipsec_replay);
279eddfbb76SRobert Watson VNET_DECLARE(int, ipsec_integrity);
28082cea7e6SBjoern A. Zeeb 
28182cea7e6SBjoern A. Zeeb #define	V_ipsec_replay		VNET(ipsec_replay)
2821e77c105SRobert Watson #define	V_ipsec_integrity	VNET(ipsec_integrity)
283eddfbb76SRobert Watson #endif
28488768458SSam Leffler 
285db8c0879SAndrey V. Elsukov VNET_PCPUSTAT_DECLARE(struct ipsecstat, ipsec4stat);
28682cea7e6SBjoern A. Zeeb VNET_DECLARE(int, ip4_esp_trans_deflev);
28782cea7e6SBjoern A. Zeeb VNET_DECLARE(int, ip4_esp_net_deflev);
28882cea7e6SBjoern A. Zeeb VNET_DECLARE(int, ip4_ah_trans_deflev);
28982cea7e6SBjoern A. Zeeb VNET_DECLARE(int, ip4_ah_net_deflev);
29082cea7e6SBjoern A. Zeeb VNET_DECLARE(int, ip4_ipsec_dfbit);
291d9d59bb1SWojciech Macek VNET_DECLARE(int, ip4_ipsec_min_pmtu);
29282cea7e6SBjoern A. Zeeb VNET_DECLARE(int, ip4_ipsec_ecn);
29382cea7e6SBjoern A. Zeeb VNET_DECLARE(int, crypto_support);
29439bbca6fSFabien Thomas VNET_DECLARE(int, async_crypto);
295fcf59617SAndrey V. Elsukov VNET_DECLARE(int, natt_cksum_policy);
29682cea7e6SBjoern A. Zeeb 
297db8c0879SAndrey V. Elsukov #define	IPSECSTAT_INC(name)	\
298db8c0879SAndrey V. Elsukov     VNET_PCPUSTAT_ADD(struct ipsecstat, ipsec4stat, name, 1)
29982cea7e6SBjoern A. Zeeb #define	V_ip4_esp_trans_deflev	VNET(ip4_esp_trans_deflev)
30082cea7e6SBjoern A. Zeeb #define	V_ip4_esp_net_deflev	VNET(ip4_esp_net_deflev)
30182cea7e6SBjoern A. Zeeb #define	V_ip4_ah_trans_deflev	VNET(ip4_ah_trans_deflev)
30282cea7e6SBjoern A. Zeeb #define	V_ip4_ah_net_deflev	VNET(ip4_ah_net_deflev)
30382cea7e6SBjoern A. Zeeb #define	V_ip4_ipsec_dfbit	VNET(ip4_ipsec_dfbit)
304d9d59bb1SWojciech Macek #define	V_ip4_ipsec_min_pmtu	VNET(ip4_ipsec_min_pmtu)
30582cea7e6SBjoern A. Zeeb #define	V_ip4_ipsec_ecn		VNET(ip4_ipsec_ecn)
30682cea7e6SBjoern A. Zeeb #define	V_crypto_support	VNET(crypto_support)
30739bbca6fSFabien Thomas #define	V_async_crypto		VNET(async_crypto)
308fcf59617SAndrey V. Elsukov #define	V_natt_cksum_policy	VNET(natt_cksum_policy)
30982cea7e6SBjoern A. Zeeb 
310603724d3SBjoern A. Zeeb #define ipseclog(x)	do { if (V_ipsec_debug) log x; } while (0)
31188768458SSam Leffler /* for openbsd compatibility */
3127f1f6591SAndrey V. Elsukov #ifdef IPSEC_DEBUG
3137f1f6591SAndrey V. Elsukov #define	IPSEC_DEBUG_DECLARE(x)	x
314603724d3SBjoern A. Zeeb #define	DPRINTF(x)	do { if (V_ipsec_debug) printf x; } while (0)
3157f1f6591SAndrey V. Elsukov #else
3167f1f6591SAndrey V. Elsukov #define	IPSEC_DEBUG_DECLARE(x)
3177f1f6591SAndrey V. Elsukov #define	DPRINTF(x)
3187f1f6591SAndrey V. Elsukov #endif
31988768458SSam Leffler 
32088768458SSam Leffler struct inpcb;
321fcf59617SAndrey V. Elsukov struct m_tag;
322fcf59617SAndrey V. Elsukov struct secasvar;
323fcf59617SAndrey V. Elsukov struct sockopt;
324fcf59617SAndrey V. Elsukov struct tcphdr;
325fcf59617SAndrey V. Elsukov union sockaddr_union;
326fcf59617SAndrey V. Elsukov 
327fcf59617SAndrey V. Elsukov int ipsec_if_input(struct mbuf *, struct secasvar *, uint32_t);
328fcf59617SAndrey V. Elsukov 
329fcf59617SAndrey V. Elsukov struct ipsecrequest *ipsec_newisr(void);
330fcf59617SAndrey V. Elsukov void ipsec_delisr(struct ipsecrequest *);
331fcf59617SAndrey V. Elsukov struct secpolicy *ipsec4_checkpolicy(const struct mbuf *, struct inpcb *,
33222bbefb2SAndrey V. Elsukov     int *, int);
33388768458SSam Leffler 
334fcf59617SAndrey V. Elsukov u_int ipsec_get_reqlevel(struct secpolicy *, u_int);
33588768458SSam Leffler 
336fcf59617SAndrey V. Elsukov void udp_ipsec_adjust_cksum(struct mbuf *, struct secasvar *, int, int);
337fcf59617SAndrey V. Elsukov int udp_ipsec_output(struct mbuf *, struct secasvar *);
33888768458SSam Leffler 
3398b7f3994SMarcin Wojtas int ipsec_chkreplay(uint32_t, uint32_t *, struct secasvar *);
340fcf59617SAndrey V. Elsukov int ipsec_updatereplay(uint32_t, struct secasvar *);
3412e08e39fSConrad Meyer int ipsec_updateid(struct secasvar *, crypto_session_t *, crypto_session_t *);
342fcf59617SAndrey V. Elsukov int ipsec_initialized(void);
3436b66194bSKornel Duleba size_t ipsec_hdrsiz_internal(struct secpolicy *);
34488768458SSam Leffler 
345fcf59617SAndrey V. Elsukov void ipsec_setspidx_inpcb(struct inpcb *, struct secpolicyindex *, u_int);
34688768458SSam Leffler 
347fcf59617SAndrey V. Elsukov void ipsec4_setsockaddrs(const struct mbuf *, union sockaddr_union *,
348fcf59617SAndrey V. Elsukov     union sockaddr_union *);
349fcf59617SAndrey V. Elsukov int ipsec4_common_input_cb(struct mbuf *, struct secasvar *, int, int);
350de1da299SKonstantin Belousov int ipsec4_check_pmtu(struct ifnet *, struct mbuf *, struct secpolicy *, int);
351de1da299SKonstantin Belousov int ipsec4_process_packet(struct ifnet *, struct mbuf *, struct secpolicy *,
35200524fd4SKonstantin Belousov     struct inpcb *, u_long);
353fcf59617SAndrey V. Elsukov int ipsec_process_done(struct mbuf *, struct secpolicy *, struct secasvar *,
354fcf59617SAndrey V. Elsukov     u_int);
35588768458SSam Leffler 
356*eb0fdc77SKonstantin Belousov void m_checkalignment(const char* where, struct mbuf *m0,
35788768458SSam Leffler     int off, int len);
358*eb0fdc77SKonstantin Belousov struct mbuf *m_makespace(struct mbuf *m0, int skip, int hlen, int *off);
359*eb0fdc77SKonstantin Belousov caddr_t m_pad(struct mbuf *m, int n);
360*eb0fdc77SKonstantin Belousov int m_striphdr(struct mbuf *m, int skip, int hlen);
36119ad9831SBjoern A. Zeeb 
36288768458SSam Leffler #endif /* _KERNEL */
36388768458SSam Leffler 
36488768458SSam Leffler #ifndef _KERNEL
365*eb0fdc77SKonstantin Belousov caddr_t ipsec_set_policy(const char *, int);
366*eb0fdc77SKonstantin Belousov int ipsec_get_policylen(c_caddr_t);
367*eb0fdc77SKonstantin Belousov char *ipsec_dump_policy(c_caddr_t, const char *);
368*eb0fdc77SKonstantin Belousov const char *ipsec_strerror(void);
3698b615593SMarko Zec 
3708b615593SMarko Zec #endif /* ! KERNEL */
37188768458SSam Leffler 
37288768458SSam Leffler #endif /* _NETIPSEC_IPSEC_H_ */
373