xref: /freebsd/sys/net/if_pfsync.h (revision e7809dceb520087d1a6fbeef93aa77f6b486e2ee)
1f6eef2c2SGleb Smirnoff /*-
2fe267a55SPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3fe267a55SPedro F. Giffuni  *
43b3a8eb9SGleb Smirnoff  * Copyright (c) 2001 Michael Shalayeff
53b3a8eb9SGleb Smirnoff  * All rights reserved.
63b3a8eb9SGleb Smirnoff  *
73b3a8eb9SGleb Smirnoff  * Redistribution and use in source and binary forms, with or without
83b3a8eb9SGleb Smirnoff  * modification, are permitted provided that the following conditions
93b3a8eb9SGleb Smirnoff  * are met:
103b3a8eb9SGleb Smirnoff  * 1. Redistributions of source code must retain the above copyright
113b3a8eb9SGleb Smirnoff  *    notice, this list of conditions and the following disclaimer.
123b3a8eb9SGleb Smirnoff  * 2. Redistributions in binary form must reproduce the above copyright
133b3a8eb9SGleb Smirnoff  *    notice, this list of conditions and the following disclaimer in the
143b3a8eb9SGleb Smirnoff  *    documentation and/or other materials provided with the distribution.
153b3a8eb9SGleb Smirnoff  *
163b3a8eb9SGleb Smirnoff  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
173b3a8eb9SGleb Smirnoff  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
183b3a8eb9SGleb Smirnoff  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
193b3a8eb9SGleb Smirnoff  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
203b3a8eb9SGleb Smirnoff  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
213b3a8eb9SGleb Smirnoff  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
223b3a8eb9SGleb Smirnoff  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
233b3a8eb9SGleb Smirnoff  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
243b3a8eb9SGleb Smirnoff  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
253b3a8eb9SGleb Smirnoff  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
263b3a8eb9SGleb Smirnoff  * THE POSSIBILITY OF SUCH DAMAGE.
273b3a8eb9SGleb Smirnoff  */
283b3a8eb9SGleb Smirnoff 
29f6eef2c2SGleb Smirnoff /*-
303b3a8eb9SGleb Smirnoff  * Copyright (c) 2008 David Gwynne <dlg@openbsd.org>
313b3a8eb9SGleb Smirnoff  *
323b3a8eb9SGleb Smirnoff  * Permission to use, copy, modify, and distribute this software for any
333b3a8eb9SGleb Smirnoff  * purpose with or without fee is hereby granted, provided that the above
343b3a8eb9SGleb Smirnoff  * copyright notice and this permission notice appear in all copies.
353b3a8eb9SGleb Smirnoff  *
363b3a8eb9SGleb Smirnoff  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
373b3a8eb9SGleb Smirnoff  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
383b3a8eb9SGleb Smirnoff  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
393b3a8eb9SGleb Smirnoff  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
403b3a8eb9SGleb Smirnoff  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
413b3a8eb9SGleb Smirnoff  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
423b3a8eb9SGleb Smirnoff  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
433b3a8eb9SGleb Smirnoff  */
443b3a8eb9SGleb Smirnoff 
45f6eef2c2SGleb Smirnoff /*
46f6eef2c2SGleb Smirnoff  *	$OpenBSD: if_pfsync.h,v 1.35 2008/06/29 08:42:15 mcbride Exp $
47f6eef2c2SGleb Smirnoff  *	$FreeBSD$
48f6eef2c2SGleb Smirnoff  */
49f6eef2c2SGleb Smirnoff 
503b3a8eb9SGleb Smirnoff #ifndef _NET_IF_PFSYNC_H_
513b3a8eb9SGleb Smirnoff #define	_NET_IF_PFSYNC_H_
523b3a8eb9SGleb Smirnoff 
53*e7809dceSKristof Provost #include <sys/types.h>
54*e7809dceSKristof Provost 
55*e7809dceSKristof Provost #include <net/if.h>
56*e7809dceSKristof Provost #include <net/pfvar.h>
57*e7809dceSKristof Provost #include <netpfil/pf/pf.h>
58*e7809dceSKristof Provost 
593b3a8eb9SGleb Smirnoff #define	PFSYNC_VERSION		5
603b3a8eb9SGleb Smirnoff #define	PFSYNC_DFLTTL		255
613b3a8eb9SGleb Smirnoff 
623b3a8eb9SGleb Smirnoff #define	PFSYNC_ACT_CLR		0	/* clear all states */
633b3a8eb9SGleb Smirnoff #define	PFSYNC_ACT_INS		1	/* insert state */
645666643aSGordon Bergling #define	PFSYNC_ACT_INS_ACK	2	/* ack of inserted state */
653b3a8eb9SGleb Smirnoff #define	PFSYNC_ACT_UPD		3	/* update state */
663b3a8eb9SGleb Smirnoff #define	PFSYNC_ACT_UPD_C	4	/* "compressed" update state */
673b3a8eb9SGleb Smirnoff #define	PFSYNC_ACT_UPD_REQ	5	/* request "uncompressed" state */
683b3a8eb9SGleb Smirnoff #define	PFSYNC_ACT_DEL		6	/* delete state */
693b3a8eb9SGleb Smirnoff #define	PFSYNC_ACT_DEL_C	7	/* "compressed" delete state */
703b3a8eb9SGleb Smirnoff #define	PFSYNC_ACT_INS_F	8	/* insert fragment */
713b3a8eb9SGleb Smirnoff #define	PFSYNC_ACT_DEL_F	9	/* delete fragments */
723b3a8eb9SGleb Smirnoff #define	PFSYNC_ACT_BUS		10	/* bulk update status */
733b3a8eb9SGleb Smirnoff #define	PFSYNC_ACT_TDB		11	/* TDB replay counter update */
743b3a8eb9SGleb Smirnoff #define	PFSYNC_ACT_EOF		12	/* end of frame */
753b3a8eb9SGleb Smirnoff #define	PFSYNC_ACT_MAX		13
763b3a8eb9SGleb Smirnoff 
773b3a8eb9SGleb Smirnoff /*
783b3a8eb9SGleb Smirnoff  * A pfsync frame is built from a header followed by several sections which
793b3a8eb9SGleb Smirnoff  * are all prefixed with their own subheaders. Frames must be terminated with
803b3a8eb9SGleb Smirnoff  * an EOF subheader.
813b3a8eb9SGleb Smirnoff  *
823b3a8eb9SGleb Smirnoff  * | ...			|
833b3a8eb9SGleb Smirnoff  * | IP header			|
843b3a8eb9SGleb Smirnoff  * +============================+
853b3a8eb9SGleb Smirnoff  * | pfsync_header		|
863b3a8eb9SGleb Smirnoff  * +----------------------------+
873b3a8eb9SGleb Smirnoff  * | pfsync_subheader		|
883b3a8eb9SGleb Smirnoff  * +----------------------------+
893b3a8eb9SGleb Smirnoff  * | first action fields	|
903b3a8eb9SGleb Smirnoff  * | ...			|
913b3a8eb9SGleb Smirnoff  * +----------------------------+
923b3a8eb9SGleb Smirnoff  * | pfsync_subheader		|
933b3a8eb9SGleb Smirnoff  * +----------------------------+
943b3a8eb9SGleb Smirnoff  * | second action fields	|
953b3a8eb9SGleb Smirnoff  * | ...			|
963b3a8eb9SGleb Smirnoff  * +----------------------------+
973b3a8eb9SGleb Smirnoff  * | EOF pfsync_subheader	|
983b3a8eb9SGleb Smirnoff  * +----------------------------+
993b3a8eb9SGleb Smirnoff  * | HMAC			|
1003b3a8eb9SGleb Smirnoff  * +============================+
1013b3a8eb9SGleb Smirnoff  */
1023b3a8eb9SGleb Smirnoff 
1033b3a8eb9SGleb Smirnoff /*
1043b3a8eb9SGleb Smirnoff  * Frame header
1053b3a8eb9SGleb Smirnoff  */
1063b3a8eb9SGleb Smirnoff 
1073b3a8eb9SGleb Smirnoff struct pfsync_header {
1083b3a8eb9SGleb Smirnoff 	u_int8_t			version;
1093b3a8eb9SGleb Smirnoff 	u_int8_t			_pad;
1103b3a8eb9SGleb Smirnoff 	u_int16_t			len;
1113b3a8eb9SGleb Smirnoff 	u_int8_t			pfcksum[PF_MD5_DIGEST_LENGTH];
1123b3a8eb9SGleb Smirnoff } __packed;
1133b3a8eb9SGleb Smirnoff 
1143b3a8eb9SGleb Smirnoff /*
1153b3a8eb9SGleb Smirnoff  * Frame region subheader
1163b3a8eb9SGleb Smirnoff  */
1173b3a8eb9SGleb Smirnoff 
1183b3a8eb9SGleb Smirnoff struct pfsync_subheader {
1193b3a8eb9SGleb Smirnoff 	u_int8_t			action;
1203b3a8eb9SGleb Smirnoff 	u_int8_t			_pad;
1213b3a8eb9SGleb Smirnoff 	u_int16_t			count;
1223b3a8eb9SGleb Smirnoff } __packed;
1233b3a8eb9SGleb Smirnoff 
1243b3a8eb9SGleb Smirnoff /*
1253b3a8eb9SGleb Smirnoff  * CLR
1263b3a8eb9SGleb Smirnoff  */
1273b3a8eb9SGleb Smirnoff 
1283b3a8eb9SGleb Smirnoff struct pfsync_clr {
1293b3a8eb9SGleb Smirnoff 	char				ifname[IFNAMSIZ];
1303b3a8eb9SGleb Smirnoff 	u_int32_t			creatorid;
1313b3a8eb9SGleb Smirnoff } __packed;
1323b3a8eb9SGleb Smirnoff 
1333b3a8eb9SGleb Smirnoff /*
1343b3a8eb9SGleb Smirnoff  * INS, UPD, DEL
1353b3a8eb9SGleb Smirnoff  */
1363b3a8eb9SGleb Smirnoff 
1373b3a8eb9SGleb Smirnoff /* these use struct pfsync_state in pfvar.h */
1383b3a8eb9SGleb Smirnoff 
1393b3a8eb9SGleb Smirnoff /*
1403b3a8eb9SGleb Smirnoff  * INS_ACK
1413b3a8eb9SGleb Smirnoff  */
1423b3a8eb9SGleb Smirnoff 
1433b3a8eb9SGleb Smirnoff struct pfsync_ins_ack {
1443b3a8eb9SGleb Smirnoff 	u_int64_t			id;
1453b3a8eb9SGleb Smirnoff 	u_int32_t			creatorid;
1463b3a8eb9SGleb Smirnoff } __packed;
1473b3a8eb9SGleb Smirnoff 
1483b3a8eb9SGleb Smirnoff /*
1493b3a8eb9SGleb Smirnoff  * UPD_C
1503b3a8eb9SGleb Smirnoff  */
1513b3a8eb9SGleb Smirnoff 
1523b3a8eb9SGleb Smirnoff struct pfsync_upd_c {
1533b3a8eb9SGleb Smirnoff 	u_int64_t			id;
1543b3a8eb9SGleb Smirnoff 	struct pfsync_state_peer	src;
1553b3a8eb9SGleb Smirnoff 	struct pfsync_state_peer	dst;
1563b3a8eb9SGleb Smirnoff 	u_int32_t			creatorid;
1573b3a8eb9SGleb Smirnoff 	u_int32_t			expire;
1583b3a8eb9SGleb Smirnoff 	u_int8_t			timeout;
1593b3a8eb9SGleb Smirnoff 	u_int8_t			_pad[3];
1603b3a8eb9SGleb Smirnoff } __packed;
1613b3a8eb9SGleb Smirnoff 
1623b3a8eb9SGleb Smirnoff /*
1633b3a8eb9SGleb Smirnoff  * UPD_REQ
1643b3a8eb9SGleb Smirnoff  */
1653b3a8eb9SGleb Smirnoff 
1663b3a8eb9SGleb Smirnoff struct pfsync_upd_req {
1673b3a8eb9SGleb Smirnoff 	u_int64_t			id;
1683b3a8eb9SGleb Smirnoff 	u_int32_t			creatorid;
1693b3a8eb9SGleb Smirnoff } __packed;
1703b3a8eb9SGleb Smirnoff 
1713b3a8eb9SGleb Smirnoff /*
1723b3a8eb9SGleb Smirnoff  * DEL_C
1733b3a8eb9SGleb Smirnoff  */
1743b3a8eb9SGleb Smirnoff 
1753b3a8eb9SGleb Smirnoff struct pfsync_del_c {
1763b3a8eb9SGleb Smirnoff 	u_int64_t			id;
1773b3a8eb9SGleb Smirnoff 	u_int32_t			creatorid;
1783b3a8eb9SGleb Smirnoff } __packed;
1793b3a8eb9SGleb Smirnoff 
1803b3a8eb9SGleb Smirnoff /*
1813b3a8eb9SGleb Smirnoff  * INS_F, DEL_F
1823b3a8eb9SGleb Smirnoff  */
1833b3a8eb9SGleb Smirnoff 
1843b3a8eb9SGleb Smirnoff /* not implemented (yet) */
1853b3a8eb9SGleb Smirnoff 
1863b3a8eb9SGleb Smirnoff /*
1873b3a8eb9SGleb Smirnoff  * BUS
1883b3a8eb9SGleb Smirnoff  */
1893b3a8eb9SGleb Smirnoff 
1903b3a8eb9SGleb Smirnoff struct pfsync_bus {
1913b3a8eb9SGleb Smirnoff 	u_int32_t			creatorid;
1923b3a8eb9SGleb Smirnoff 	u_int32_t			endtime;
1933b3a8eb9SGleb Smirnoff 	u_int8_t			status;
1943b3a8eb9SGleb Smirnoff #define	PFSYNC_BUS_START			1
1953b3a8eb9SGleb Smirnoff #define	PFSYNC_BUS_END				2
1963b3a8eb9SGleb Smirnoff 	u_int8_t			_pad[3];
1973b3a8eb9SGleb Smirnoff } __packed;
1983b3a8eb9SGleb Smirnoff 
1993b3a8eb9SGleb Smirnoff /*
2003b3a8eb9SGleb Smirnoff  * TDB
2013b3a8eb9SGleb Smirnoff  */
2023b3a8eb9SGleb Smirnoff 
2033b3a8eb9SGleb Smirnoff struct pfsync_tdb {
2043b3a8eb9SGleb Smirnoff 	u_int32_t			spi;
2053b3a8eb9SGleb Smirnoff 	union sockaddr_union		dst;
2063b3a8eb9SGleb Smirnoff 	u_int32_t			rpl;
2073b3a8eb9SGleb Smirnoff 	u_int64_t			cur_bytes;
2083b3a8eb9SGleb Smirnoff 	u_int8_t			sproto;
2093b3a8eb9SGleb Smirnoff 	u_int8_t			updates;
2103b3a8eb9SGleb Smirnoff 	u_int8_t			_pad[2];
2113b3a8eb9SGleb Smirnoff } __packed;
2123b3a8eb9SGleb Smirnoff 
2133b3a8eb9SGleb Smirnoff #define	PFSYNC_HDRLEN		sizeof(struct pfsync_header)
2143b3a8eb9SGleb Smirnoff 
2153b3a8eb9SGleb Smirnoff struct pfsyncstats {
2163b3a8eb9SGleb Smirnoff 	u_int64_t	pfsyncs_ipackets;	/* total input packets, IPv4 */
2173b3a8eb9SGleb Smirnoff 	u_int64_t	pfsyncs_ipackets6;	/* total input packets, IPv6 */
2183b3a8eb9SGleb Smirnoff 	u_int64_t	pfsyncs_badif;		/* not the right interface */
2193b3a8eb9SGleb Smirnoff 	u_int64_t	pfsyncs_badttl;		/* TTL is not PFSYNC_DFLTTL */
2203b3a8eb9SGleb Smirnoff 	u_int64_t	pfsyncs_hdrops;		/* packets shorter than hdr */
2213b3a8eb9SGleb Smirnoff 	u_int64_t	pfsyncs_badver;		/* bad (incl unsupp) version */
2223b3a8eb9SGleb Smirnoff 	u_int64_t	pfsyncs_badact;		/* bad action */
2233b3a8eb9SGleb Smirnoff 	u_int64_t	pfsyncs_badlen;		/* data length does not match */
2243b3a8eb9SGleb Smirnoff 	u_int64_t	pfsyncs_badauth;	/* bad authentication */
2253b3a8eb9SGleb Smirnoff 	u_int64_t	pfsyncs_stale;		/* stale state */
2263b3a8eb9SGleb Smirnoff 	u_int64_t	pfsyncs_badval;		/* bad values */
2273b3a8eb9SGleb Smirnoff 	u_int64_t	pfsyncs_badstate;	/* insert/lookup failed */
2283b3a8eb9SGleb Smirnoff 
2293b3a8eb9SGleb Smirnoff 	u_int64_t	pfsyncs_opackets;	/* total output packets, IPv4 */
2303b3a8eb9SGleb Smirnoff 	u_int64_t	pfsyncs_opackets6;	/* total output packets, IPv6 */
2313b3a8eb9SGleb Smirnoff 	u_int64_t	pfsyncs_onomem;		/* no memory for an mbuf */
2323b3a8eb9SGleb Smirnoff 	u_int64_t	pfsyncs_oerrors;	/* ip output error */
2333b3a8eb9SGleb Smirnoff 
2343b3a8eb9SGleb Smirnoff 	u_int64_t	pfsyncs_iacts[PFSYNC_ACT_MAX];
2353b3a8eb9SGleb Smirnoff 	u_int64_t	pfsyncs_oacts[PFSYNC_ACT_MAX];
2363b3a8eb9SGleb Smirnoff };
2373b3a8eb9SGleb Smirnoff 
2383b3a8eb9SGleb Smirnoff /*
2393b3a8eb9SGleb Smirnoff  * Configuration structure for SIOCSETPFSYNC SIOCGETPFSYNC
2403b3a8eb9SGleb Smirnoff  */
2413b3a8eb9SGleb Smirnoff struct pfsyncreq {
2423b3a8eb9SGleb Smirnoff 	char		 pfsyncr_syncdev[IFNAMSIZ];
2433b3a8eb9SGleb Smirnoff 	struct in_addr	 pfsyncr_syncpeer;
2443b3a8eb9SGleb Smirnoff 	int		 pfsyncr_maxupdates;
2455f5bf889SKristof Provost #define	PFSYNCF_OK		0x00000001
2465f5bf889SKristof Provost #define	PFSYNCF_DEFER		0x00000002
2473b3a8eb9SGleb Smirnoff 	int		 pfsyncr_defer;
2483b3a8eb9SGleb Smirnoff };
2493b3a8eb9SGleb Smirnoff 
2503b3a8eb9SGleb Smirnoff #define	SIOCSETPFSYNC   _IOW('i', 247, struct ifreq)
2513b3a8eb9SGleb Smirnoff #define	SIOCGETPFSYNC   _IOWR('i', 248, struct ifreq)
2523b3a8eb9SGleb Smirnoff 
2533b3a8eb9SGleb Smirnoff #ifdef _KERNEL
2543b3a8eb9SGleb Smirnoff 
2553b3a8eb9SGleb Smirnoff /*
2563b3a8eb9SGleb Smirnoff  * this shows where a pf state is with respect to the syncing.
2573b3a8eb9SGleb Smirnoff  */
2583b3a8eb9SGleb Smirnoff #define	PFSYNC_S_INS	0x00
2593b3a8eb9SGleb Smirnoff #define	PFSYNC_S_IACK	0x01
2603b3a8eb9SGleb Smirnoff #define	PFSYNC_S_UPD	0x02
2613b3a8eb9SGleb Smirnoff #define	PFSYNC_S_UPD_C	0x03
2623b3a8eb9SGleb Smirnoff #define	PFSYNC_S_DEL	0x04
2633b3a8eb9SGleb Smirnoff #define	PFSYNC_S_COUNT	0x05
2643b3a8eb9SGleb Smirnoff 
2653b3a8eb9SGleb Smirnoff #define	PFSYNC_S_DEFER	0xfe
2663b3a8eb9SGleb Smirnoff #define	PFSYNC_S_NONE	0xff
2673b3a8eb9SGleb Smirnoff 
2683b3a8eb9SGleb Smirnoff #define	PFSYNC_SI_IOCTL		0x01
2693b3a8eb9SGleb Smirnoff #define	PFSYNC_SI_CKSUM		0x02
2703b3a8eb9SGleb Smirnoff #define	PFSYNC_SI_ACK		0x04
2713b3a8eb9SGleb Smirnoff 
2723b3a8eb9SGleb Smirnoff #endif /* _KERNEL */
2733b3a8eb9SGleb Smirnoff 
2743b3a8eb9SGleb Smirnoff #endif /* _NET_IF_PFSYNC_H_ */
275