xref: /freebsd/sys/net/pfvar.h (revision efc6c51f)
13b3a8eb9SGleb Smirnoff /*
23b3a8eb9SGleb Smirnoff  * Copyright (c) 2001 Daniel Hartmeier
33b3a8eb9SGleb Smirnoff  * All rights reserved.
43b3a8eb9SGleb Smirnoff  *
53b3a8eb9SGleb Smirnoff  * Redistribution and use in source and binary forms, with or without
63b3a8eb9SGleb Smirnoff  * modification, are permitted provided that the following conditions
73b3a8eb9SGleb Smirnoff  * are met:
83b3a8eb9SGleb Smirnoff  *
93b3a8eb9SGleb Smirnoff  *    - Redistributions of source code must retain the above copyright
103b3a8eb9SGleb Smirnoff  *      notice, this list of conditions and the following disclaimer.
113b3a8eb9SGleb Smirnoff  *    - Redistributions in binary form must reproduce the above
123b3a8eb9SGleb Smirnoff  *      copyright notice, this list of conditions and the following
133b3a8eb9SGleb Smirnoff  *      disclaimer in the documentation and/or other materials provided
143b3a8eb9SGleb Smirnoff  *      with the distribution.
153b3a8eb9SGleb Smirnoff  *
163b3a8eb9SGleb Smirnoff  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
173b3a8eb9SGleb Smirnoff  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
183b3a8eb9SGleb Smirnoff  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
193b3a8eb9SGleb Smirnoff  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
203b3a8eb9SGleb Smirnoff  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
213b3a8eb9SGleb Smirnoff  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
223b3a8eb9SGleb Smirnoff  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
233b3a8eb9SGleb Smirnoff  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
243b3a8eb9SGleb Smirnoff  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
253b3a8eb9SGleb Smirnoff  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
263b3a8eb9SGleb Smirnoff  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
273b3a8eb9SGleb Smirnoff  * POSSIBILITY OF SUCH DAMAGE.
283b3a8eb9SGleb Smirnoff  *
299ed8bbbdSGleb Smirnoff  *	$OpenBSD: pfvar.h,v 1.282 2009/01/29 15:12:28 pyr Exp $
309e8c4accSGleb Smirnoff  *	$FreeBSD$
313b3a8eb9SGleb Smirnoff  */
323b3a8eb9SGleb Smirnoff 
333b3a8eb9SGleb Smirnoff #ifndef _NET_PFVAR_H_
343b3a8eb9SGleb Smirnoff #define _NET_PFVAR_H_
353b3a8eb9SGleb Smirnoff 
363b3a8eb9SGleb Smirnoff #include <sys/param.h>
373b3a8eb9SGleb Smirnoff #include <sys/queue.h>
3848278b88SGleb Smirnoff #include <sys/counter.h>
393b3a8eb9SGleb Smirnoff #include <sys/refcount.h>
403b3a8eb9SGleb Smirnoff #include <sys/tree.h>
413b3a8eb9SGleb Smirnoff 
423b3a8eb9SGleb Smirnoff #include <net/radix.h>
433b3a8eb9SGleb Smirnoff #include <netinet/in.h>
443b3a8eb9SGleb Smirnoff 
4575bf2db3SGleb Smirnoff #include <netpfil/pf/pf.h>
4675bf2db3SGleb Smirnoff #include <netpfil/pf/pf_altq.h>
4775bf2db3SGleb Smirnoff #include <netpfil/pf/pf_mtag.h>
483b3a8eb9SGleb Smirnoff 
493b3a8eb9SGleb Smirnoff struct pf_addr {
503b3a8eb9SGleb Smirnoff 	union {
513b3a8eb9SGleb Smirnoff 		struct in_addr		v4;
523b3a8eb9SGleb Smirnoff 		struct in6_addr		v6;
533b3a8eb9SGleb Smirnoff 		u_int8_t		addr8[16];
543b3a8eb9SGleb Smirnoff 		u_int16_t		addr16[8];
553b3a8eb9SGleb Smirnoff 		u_int32_t		addr32[4];
563b3a8eb9SGleb Smirnoff 	} pfa;		    /* 128-bit address */
573b3a8eb9SGleb Smirnoff #define v4	pfa.v4
583b3a8eb9SGleb Smirnoff #define v6	pfa.v6
593b3a8eb9SGleb Smirnoff #define addr8	pfa.addr8
603b3a8eb9SGleb Smirnoff #define addr16	pfa.addr16
613b3a8eb9SGleb Smirnoff #define addr32	pfa.addr32
623b3a8eb9SGleb Smirnoff };
633b3a8eb9SGleb Smirnoff 
643b3a8eb9SGleb Smirnoff #define PFI_AFLAG_NETWORK	0x01
653b3a8eb9SGleb Smirnoff #define PFI_AFLAG_BROADCAST	0x02
663b3a8eb9SGleb Smirnoff #define PFI_AFLAG_PEER		0x04
673b3a8eb9SGleb Smirnoff #define PFI_AFLAG_MODEMASK	0x07
683b3a8eb9SGleb Smirnoff #define PFI_AFLAG_NOALIAS	0x08
693b3a8eb9SGleb Smirnoff 
703b3a8eb9SGleb Smirnoff struct pf_addr_wrap {
713b3a8eb9SGleb Smirnoff 	union {
723b3a8eb9SGleb Smirnoff 		struct {
733b3a8eb9SGleb Smirnoff 			struct pf_addr		 addr;
743b3a8eb9SGleb Smirnoff 			struct pf_addr		 mask;
753b3a8eb9SGleb Smirnoff 		}			 a;
763b3a8eb9SGleb Smirnoff 		char			 ifname[IFNAMSIZ];
773b3a8eb9SGleb Smirnoff 		char			 tblname[PF_TABLE_NAME_SIZE];
783b3a8eb9SGleb Smirnoff 	}			 v;
793b3a8eb9SGleb Smirnoff 	union {
803b3a8eb9SGleb Smirnoff 		struct pfi_dynaddr	*dyn;
813b3a8eb9SGleb Smirnoff 		struct pfr_ktable	*tbl;
823b3a8eb9SGleb Smirnoff 		int			 dyncnt;
833b3a8eb9SGleb Smirnoff 		int			 tblcnt;
843b3a8eb9SGleb Smirnoff 	}			 p;
853b3a8eb9SGleb Smirnoff 	u_int8_t		 type;		/* PF_ADDR_* */
863b3a8eb9SGleb Smirnoff 	u_int8_t		 iflags;	/* PFI_AFLAG_* */
873b3a8eb9SGleb Smirnoff };
883b3a8eb9SGleb Smirnoff 
893b3a8eb9SGleb Smirnoff #ifdef _KERNEL
903b3a8eb9SGleb Smirnoff 
913b3a8eb9SGleb Smirnoff struct pfi_dynaddr {
923b3a8eb9SGleb Smirnoff 	TAILQ_ENTRY(pfi_dynaddr)	 entry;
933b3a8eb9SGleb Smirnoff 	struct pf_addr			 pfid_addr4;
943b3a8eb9SGleb Smirnoff 	struct pf_addr			 pfid_mask4;
953b3a8eb9SGleb Smirnoff 	struct pf_addr			 pfid_addr6;
963b3a8eb9SGleb Smirnoff 	struct pf_addr			 pfid_mask6;
973b3a8eb9SGleb Smirnoff 	struct pfr_ktable		*pfid_kt;
983b3a8eb9SGleb Smirnoff 	struct pfi_kif			*pfid_kif;
993b3a8eb9SGleb Smirnoff 	int				 pfid_net;	/* mask or 128 */
1003b3a8eb9SGleb Smirnoff 	int				 pfid_acnt4;	/* address count IPv4 */
1013b3a8eb9SGleb Smirnoff 	int				 pfid_acnt6;	/* address count IPv6 */
1023b3a8eb9SGleb Smirnoff 	sa_family_t			 pfid_af;	/* rule af */
1033b3a8eb9SGleb Smirnoff 	u_int8_t			 pfid_iflags;	/* PFI_AFLAG_* */
1043b3a8eb9SGleb Smirnoff };
1053b3a8eb9SGleb Smirnoff 
1063b3a8eb9SGleb Smirnoff /*
1073b3a8eb9SGleb Smirnoff  * Address manipulation macros
1083b3a8eb9SGleb Smirnoff  */
1093b3a8eb9SGleb Smirnoff #define	HTONL(x)	(x) = htonl((__uint32_t)(x))
1103b3a8eb9SGleb Smirnoff #define	HTONS(x)	(x) = htons((__uint16_t)(x))
1113b3a8eb9SGleb Smirnoff #define	NTOHL(x)	(x) = ntohl((__uint32_t)(x))
1123b3a8eb9SGleb Smirnoff #define	NTOHS(x)	(x) = ntohs((__uint16_t)(x))
1133b3a8eb9SGleb Smirnoff 
1143b3a8eb9SGleb Smirnoff #define	PF_NAME		"pf"
1153b3a8eb9SGleb Smirnoff 
1163b3a8eb9SGleb Smirnoff #define	PF_HASHROW_ASSERT(h)	mtx_assert(&(h)->lock, MA_OWNED)
1173b3a8eb9SGleb Smirnoff #define	PF_HASHROW_LOCK(h)	mtx_lock(&(h)->lock)
1183b3a8eb9SGleb Smirnoff #define	PF_HASHROW_UNLOCK(h)	mtx_unlock(&(h)->lock)
1193b3a8eb9SGleb Smirnoff 
1203b3a8eb9SGleb Smirnoff #define	PF_STATE_LOCK(s)						\
1213b3a8eb9SGleb Smirnoff 	do {								\
1223b3a8eb9SGleb Smirnoff 		struct pf_idhash *_ih = &V_pf_idhash[PF_IDHASH(s)];	\
1233b3a8eb9SGleb Smirnoff 		PF_HASHROW_LOCK(_ih);					\
1243b3a8eb9SGleb Smirnoff 	} while (0)
1253b3a8eb9SGleb Smirnoff 
1263b3a8eb9SGleb Smirnoff #define	PF_STATE_UNLOCK(s)						\
1273b3a8eb9SGleb Smirnoff 	do {								\
1283b3a8eb9SGleb Smirnoff 		struct pf_idhash *_ih = &V_pf_idhash[PF_IDHASH((s))];	\
1293b3a8eb9SGleb Smirnoff 		PF_HASHROW_UNLOCK(_ih);					\
1303b3a8eb9SGleb Smirnoff 	} while (0)
1313b3a8eb9SGleb Smirnoff 
1323b3a8eb9SGleb Smirnoff #ifdef INVARIANTS
1333b3a8eb9SGleb Smirnoff #define	PF_STATE_LOCK_ASSERT(s)						\
1343b3a8eb9SGleb Smirnoff 	do {								\
1353b3a8eb9SGleb Smirnoff 		struct pf_idhash *_ih = &V_pf_idhash[PF_IDHASH(s)];	\
1363b3a8eb9SGleb Smirnoff 		PF_HASHROW_ASSERT(_ih);					\
1373b3a8eb9SGleb Smirnoff 	} while (0)
1383b3a8eb9SGleb Smirnoff #else /* !INVARIANTS */
1393b3a8eb9SGleb Smirnoff #define	PF_STATE_LOCK_ASSERT(s)		do {} while (0)
1403b3a8eb9SGleb Smirnoff #endif /* INVARIANTS */
1413b3a8eb9SGleb Smirnoff 
1423b3a8eb9SGleb Smirnoff extern struct mtx pf_unlnkdrules_mtx;
1433b3a8eb9SGleb Smirnoff #define	PF_UNLNKDRULES_LOCK()	mtx_lock(&pf_unlnkdrules_mtx)
1443b3a8eb9SGleb Smirnoff #define	PF_UNLNKDRULES_UNLOCK()	mtx_unlock(&pf_unlnkdrules_mtx)
1453b3a8eb9SGleb Smirnoff 
1463b3a8eb9SGleb Smirnoff extern struct rwlock pf_rules_lock;
1473b3a8eb9SGleb Smirnoff #define	PF_RULES_RLOCK()	rw_rlock(&pf_rules_lock)
1483b3a8eb9SGleb Smirnoff #define	PF_RULES_RUNLOCK()	rw_runlock(&pf_rules_lock)
1493b3a8eb9SGleb Smirnoff #define	PF_RULES_WLOCK()	rw_wlock(&pf_rules_lock)
1503b3a8eb9SGleb Smirnoff #define	PF_RULES_WUNLOCK()	rw_wunlock(&pf_rules_lock)
1513b3a8eb9SGleb Smirnoff #define	PF_RULES_ASSERT()	rw_assert(&pf_rules_lock, RA_LOCKED)
1523b3a8eb9SGleb Smirnoff #define	PF_RULES_RASSERT()	rw_assert(&pf_rules_lock, RA_RLOCKED)
1533b3a8eb9SGleb Smirnoff #define	PF_RULES_WASSERT()	rw_assert(&pf_rules_lock, RA_WLOCKED)
1543b3a8eb9SGleb Smirnoff 
1553b3a8eb9SGleb Smirnoff #define	PF_MODVER	1
1563b3a8eb9SGleb Smirnoff #define	PFLOG_MODVER	1
1573b3a8eb9SGleb Smirnoff #define	PFSYNC_MODVER	1
1583b3a8eb9SGleb Smirnoff 
1593b3a8eb9SGleb Smirnoff #define	PFLOG_MINVER	1
1603b3a8eb9SGleb Smirnoff #define	PFLOG_PREFVER	PFLOG_MODVER
1613b3a8eb9SGleb Smirnoff #define	PFLOG_MAXVER	1
1623b3a8eb9SGleb Smirnoff #define	PFSYNC_MINVER	1
1633b3a8eb9SGleb Smirnoff #define	PFSYNC_PREFVER	PFSYNC_MODVER
1643b3a8eb9SGleb Smirnoff #define	PFSYNC_MAXVER	1
1653b3a8eb9SGleb Smirnoff 
1663b3a8eb9SGleb Smirnoff #ifdef INET
1673b3a8eb9SGleb Smirnoff #ifndef INET6
1683b3a8eb9SGleb Smirnoff #define	PF_INET_ONLY
1693b3a8eb9SGleb Smirnoff #endif /* ! INET6 */
1703b3a8eb9SGleb Smirnoff #endif /* INET */
1713b3a8eb9SGleb Smirnoff 
1723b3a8eb9SGleb Smirnoff #ifdef INET6
1733b3a8eb9SGleb Smirnoff #ifndef INET
1743b3a8eb9SGleb Smirnoff #define	PF_INET6_ONLY
1753b3a8eb9SGleb Smirnoff #endif /* ! INET */
1763b3a8eb9SGleb Smirnoff #endif /* INET6 */
1773b3a8eb9SGleb Smirnoff 
1783b3a8eb9SGleb Smirnoff #ifdef INET
1793b3a8eb9SGleb Smirnoff #ifdef INET6
1803b3a8eb9SGleb Smirnoff #define	PF_INET_INET6
1813b3a8eb9SGleb Smirnoff #endif /* INET6 */
1823b3a8eb9SGleb Smirnoff #endif /* INET */
1833b3a8eb9SGleb Smirnoff 
1843b3a8eb9SGleb Smirnoff #else
1853b3a8eb9SGleb Smirnoff 
1863b3a8eb9SGleb Smirnoff #define	PF_INET_INET6
1873b3a8eb9SGleb Smirnoff 
1883b3a8eb9SGleb Smirnoff #endif /* _KERNEL */
1893b3a8eb9SGleb Smirnoff 
1903b3a8eb9SGleb Smirnoff /* Both IPv4 and IPv6 */
1913b3a8eb9SGleb Smirnoff #ifdef PF_INET_INET6
1923b3a8eb9SGleb Smirnoff 
1933b3a8eb9SGleb Smirnoff #define PF_AEQ(a, b, c) \
1943b3a8eb9SGleb Smirnoff 	((c == AF_INET && (a)->addr32[0] == (b)->addr32[0]) || \
1953b3a8eb9SGleb Smirnoff 	((a)->addr32[3] == (b)->addr32[3] && \
1963b3a8eb9SGleb Smirnoff 	(a)->addr32[2] == (b)->addr32[2] && \
1973b3a8eb9SGleb Smirnoff 	(a)->addr32[1] == (b)->addr32[1] && \
1983b3a8eb9SGleb Smirnoff 	(a)->addr32[0] == (b)->addr32[0])) \
1993b3a8eb9SGleb Smirnoff 
2003b3a8eb9SGleb Smirnoff #define PF_ANEQ(a, b, c) \
2013b3a8eb9SGleb Smirnoff 	((c == AF_INET && (a)->addr32[0] != (b)->addr32[0]) || \
2023b3a8eb9SGleb Smirnoff 	((a)->addr32[3] != (b)->addr32[3] || \
2033b3a8eb9SGleb Smirnoff 	(a)->addr32[2] != (b)->addr32[2] || \
2043b3a8eb9SGleb Smirnoff 	(a)->addr32[1] != (b)->addr32[1] || \
2053b3a8eb9SGleb Smirnoff 	(a)->addr32[0] != (b)->addr32[0])) \
2063b3a8eb9SGleb Smirnoff 
2073b3a8eb9SGleb Smirnoff #define PF_AZERO(a, c) \
2083b3a8eb9SGleb Smirnoff 	((c == AF_INET && !(a)->addr32[0]) || \
2093b3a8eb9SGleb Smirnoff 	(!(a)->addr32[0] && !(a)->addr32[1] && \
2103b3a8eb9SGleb Smirnoff 	!(a)->addr32[2] && !(a)->addr32[3] )) \
2113b3a8eb9SGleb Smirnoff 
2123b3a8eb9SGleb Smirnoff #define PF_MATCHA(n, a, m, b, f) \
2133b3a8eb9SGleb Smirnoff 	pf_match_addr(n, a, m, b, f)
2143b3a8eb9SGleb Smirnoff 
2153b3a8eb9SGleb Smirnoff #define PF_ACPY(a, b, f) \
2163b3a8eb9SGleb Smirnoff 	pf_addrcpy(a, b, f)
2173b3a8eb9SGleb Smirnoff 
2183b3a8eb9SGleb Smirnoff #define PF_AINC(a, f) \
2193b3a8eb9SGleb Smirnoff 	pf_addr_inc(a, f)
2203b3a8eb9SGleb Smirnoff 
2213b3a8eb9SGleb Smirnoff #define PF_POOLMASK(a, b, c, d, f) \
2223b3a8eb9SGleb Smirnoff 	pf_poolmask(a, b, c, d, f)
2233b3a8eb9SGleb Smirnoff 
2243b3a8eb9SGleb Smirnoff #else
2253b3a8eb9SGleb Smirnoff 
2263b3a8eb9SGleb Smirnoff /* Just IPv6 */
2273b3a8eb9SGleb Smirnoff 
2283b3a8eb9SGleb Smirnoff #ifdef PF_INET6_ONLY
2293b3a8eb9SGleb Smirnoff 
2303b3a8eb9SGleb Smirnoff #define PF_AEQ(a, b, c) \
2313b3a8eb9SGleb Smirnoff 	((a)->addr32[3] == (b)->addr32[3] && \
2323b3a8eb9SGleb Smirnoff 	(a)->addr32[2] == (b)->addr32[2] && \
2333b3a8eb9SGleb Smirnoff 	(a)->addr32[1] == (b)->addr32[1] && \
2343b3a8eb9SGleb Smirnoff 	(a)->addr32[0] == (b)->addr32[0]) \
2353b3a8eb9SGleb Smirnoff 
2363b3a8eb9SGleb Smirnoff #define PF_ANEQ(a, b, c) \
2373b3a8eb9SGleb Smirnoff 	((a)->addr32[3] != (b)->addr32[3] || \
2383b3a8eb9SGleb Smirnoff 	(a)->addr32[2] != (b)->addr32[2] || \
2393b3a8eb9SGleb Smirnoff 	(a)->addr32[1] != (b)->addr32[1] || \
2403b3a8eb9SGleb Smirnoff 	(a)->addr32[0] != (b)->addr32[0]) \
2413b3a8eb9SGleb Smirnoff 
2423b3a8eb9SGleb Smirnoff #define PF_AZERO(a, c) \
2433b3a8eb9SGleb Smirnoff 	(!(a)->addr32[0] && \
2443b3a8eb9SGleb Smirnoff 	!(a)->addr32[1] && \
2453b3a8eb9SGleb Smirnoff 	!(a)->addr32[2] && \
2463b3a8eb9SGleb Smirnoff 	!(a)->addr32[3] ) \
2473b3a8eb9SGleb Smirnoff 
2483b3a8eb9SGleb Smirnoff #define PF_MATCHA(n, a, m, b, f) \
2493b3a8eb9SGleb Smirnoff 	pf_match_addr(n, a, m, b, f)
2503b3a8eb9SGleb Smirnoff 
2513b3a8eb9SGleb Smirnoff #define PF_ACPY(a, b, f) \
2523b3a8eb9SGleb Smirnoff 	pf_addrcpy(a, b, f)
2533b3a8eb9SGleb Smirnoff 
2543b3a8eb9SGleb Smirnoff #define PF_AINC(a, f) \
2553b3a8eb9SGleb Smirnoff 	pf_addr_inc(a, f)
2563b3a8eb9SGleb Smirnoff 
2573b3a8eb9SGleb Smirnoff #define PF_POOLMASK(a, b, c, d, f) \
2583b3a8eb9SGleb Smirnoff 	pf_poolmask(a, b, c, d, f)
2593b3a8eb9SGleb Smirnoff 
2603b3a8eb9SGleb Smirnoff #else
2613b3a8eb9SGleb Smirnoff 
2623b3a8eb9SGleb Smirnoff /* Just IPv4 */
2633b3a8eb9SGleb Smirnoff #ifdef PF_INET_ONLY
2643b3a8eb9SGleb Smirnoff 
2653b3a8eb9SGleb Smirnoff #define PF_AEQ(a, b, c) \
2663b3a8eb9SGleb Smirnoff 	((a)->addr32[0] == (b)->addr32[0])
2673b3a8eb9SGleb Smirnoff 
2683b3a8eb9SGleb Smirnoff #define PF_ANEQ(a, b, c) \
2693b3a8eb9SGleb Smirnoff 	((a)->addr32[0] != (b)->addr32[0])
2703b3a8eb9SGleb Smirnoff 
2713b3a8eb9SGleb Smirnoff #define PF_AZERO(a, c) \
2723b3a8eb9SGleb Smirnoff 	(!(a)->addr32[0])
2733b3a8eb9SGleb Smirnoff 
2743b3a8eb9SGleb Smirnoff #define PF_MATCHA(n, a, m, b, f) \
2753b3a8eb9SGleb Smirnoff 	pf_match_addr(n, a, m, b, f)
2763b3a8eb9SGleb Smirnoff 
2773b3a8eb9SGleb Smirnoff #define PF_ACPY(a, b, f) \
2783b3a8eb9SGleb Smirnoff 	(a)->v4.s_addr = (b)->v4.s_addr
2793b3a8eb9SGleb Smirnoff 
2803b3a8eb9SGleb Smirnoff #define PF_AINC(a, f) \
2813b3a8eb9SGleb Smirnoff 	do { \
2823b3a8eb9SGleb Smirnoff 		(a)->addr32[0] = htonl(ntohl((a)->addr32[0]) + 1); \
2833b3a8eb9SGleb Smirnoff 	} while (0)
2843b3a8eb9SGleb Smirnoff 
2853b3a8eb9SGleb Smirnoff #define PF_POOLMASK(a, b, c, d, f) \
2863b3a8eb9SGleb Smirnoff 	do { \
2873b3a8eb9SGleb Smirnoff 		(a)->addr32[0] = ((b)->addr32[0] & (c)->addr32[0]) | \
2883b3a8eb9SGleb Smirnoff 		(((c)->addr32[0] ^ 0xffffffff ) & (d)->addr32[0]); \
2893b3a8eb9SGleb Smirnoff 	} while (0)
2903b3a8eb9SGleb Smirnoff 
2913b3a8eb9SGleb Smirnoff #endif /* PF_INET_ONLY */
2923b3a8eb9SGleb Smirnoff #endif /* PF_INET6_ONLY */
2933b3a8eb9SGleb Smirnoff #endif /* PF_INET_INET6 */
2943b3a8eb9SGleb Smirnoff 
2953b3a8eb9SGleb Smirnoff /*
2963b3a8eb9SGleb Smirnoff  * XXX callers not FIB-aware in our version of pf yet.
2973b3a8eb9SGleb Smirnoff  * OpenBSD fixed it later it seems, 2010/05/07 13:33:16 claudio.
2983b3a8eb9SGleb Smirnoff  */
2993b3a8eb9SGleb Smirnoff #define	PF_MISMATCHAW(aw, x, af, neg, ifp, rtid)			\
3003b3a8eb9SGleb Smirnoff 	(								\
3013b3a8eb9SGleb Smirnoff 		(((aw)->type == PF_ADDR_NOROUTE &&			\
3023b3a8eb9SGleb Smirnoff 		    pf_routable((x), (af), NULL, (rtid))) ||		\
3033b3a8eb9SGleb Smirnoff 		(((aw)->type == PF_ADDR_URPFFAILED && (ifp) != NULL &&	\
3043b3a8eb9SGleb Smirnoff 		    pf_routable((x), (af), (ifp), (rtid))) ||		\
3053b3a8eb9SGleb Smirnoff 		((aw)->type == PF_ADDR_TABLE &&				\
3063b3a8eb9SGleb Smirnoff 		    !pfr_match_addr((aw)->p.tbl, (x), (af))) ||		\
3073b3a8eb9SGleb Smirnoff 		((aw)->type == PF_ADDR_DYNIFTL &&			\
3083b3a8eb9SGleb Smirnoff 		    !pfi_match_addr((aw)->p.dyn, (x), (af))) ||		\
3093b3a8eb9SGleb Smirnoff 		((aw)->type == PF_ADDR_RANGE &&				\
3103b3a8eb9SGleb Smirnoff 		    !pf_match_addr_range(&(aw)->v.a.addr,		\
3113b3a8eb9SGleb Smirnoff 		    &(aw)->v.a.mask, (x), (af))) ||			\
3123b3a8eb9SGleb Smirnoff 		((aw)->type == PF_ADDR_ADDRMASK &&			\
3133b3a8eb9SGleb Smirnoff 		    !PF_AZERO(&(aw)->v.a.mask, (af)) &&			\
3143b3a8eb9SGleb Smirnoff 		    !PF_MATCHA(0, &(aw)->v.a.addr,			\
3153b3a8eb9SGleb Smirnoff 		    &(aw)->v.a.mask, (x), (af))))) !=			\
3163b3a8eb9SGleb Smirnoff 		(neg)							\
3173b3a8eb9SGleb Smirnoff 	)
3183b3a8eb9SGleb Smirnoff 
3193b3a8eb9SGleb Smirnoff 
3203b3a8eb9SGleb Smirnoff struct pf_rule_uid {
3213b3a8eb9SGleb Smirnoff 	uid_t		 uid[2];
3223b3a8eb9SGleb Smirnoff 	u_int8_t	 op;
3233b3a8eb9SGleb Smirnoff };
3243b3a8eb9SGleb Smirnoff 
3253b3a8eb9SGleb Smirnoff struct pf_rule_gid {
3263b3a8eb9SGleb Smirnoff 	uid_t		 gid[2];
3273b3a8eb9SGleb Smirnoff 	u_int8_t	 op;
3283b3a8eb9SGleb Smirnoff };
3293b3a8eb9SGleb Smirnoff 
3303b3a8eb9SGleb Smirnoff struct pf_rule_addr {
3313b3a8eb9SGleb Smirnoff 	struct pf_addr_wrap	 addr;
3323b3a8eb9SGleb Smirnoff 	u_int16_t		 port[2];
3333b3a8eb9SGleb Smirnoff 	u_int8_t		 neg;
3343b3a8eb9SGleb Smirnoff 	u_int8_t		 port_op;
3353b3a8eb9SGleb Smirnoff };
3363b3a8eb9SGleb Smirnoff 
3373b3a8eb9SGleb Smirnoff struct pf_pooladdr {
3383b3a8eb9SGleb Smirnoff 	struct pf_addr_wrap		 addr;
3393b3a8eb9SGleb Smirnoff 	TAILQ_ENTRY(pf_pooladdr)	 entries;
3403b3a8eb9SGleb Smirnoff 	char				 ifname[IFNAMSIZ];
3413b3a8eb9SGleb Smirnoff 	struct pfi_kif			*kif;
3423b3a8eb9SGleb Smirnoff };
3433b3a8eb9SGleb Smirnoff 
3443b3a8eb9SGleb Smirnoff TAILQ_HEAD(pf_palist, pf_pooladdr);
3453b3a8eb9SGleb Smirnoff 
3463b3a8eb9SGleb Smirnoff struct pf_poolhashkey {
3473b3a8eb9SGleb Smirnoff 	union {
3483b3a8eb9SGleb Smirnoff 		u_int8_t		key8[16];
3493b3a8eb9SGleb Smirnoff 		u_int16_t		key16[8];
3503b3a8eb9SGleb Smirnoff 		u_int32_t		key32[4];
3513b3a8eb9SGleb Smirnoff 	} pfk;		    /* 128-bit hash key */
3523b3a8eb9SGleb Smirnoff #define key8	pfk.key8
3533b3a8eb9SGleb Smirnoff #define key16	pfk.key16
3543b3a8eb9SGleb Smirnoff #define key32	pfk.key32
3553b3a8eb9SGleb Smirnoff };
3563b3a8eb9SGleb Smirnoff 
3573b3a8eb9SGleb Smirnoff struct pf_pool {
3583b3a8eb9SGleb Smirnoff 	struct pf_palist	 list;
3593b3a8eb9SGleb Smirnoff 	struct pf_pooladdr	*cur;
3603b3a8eb9SGleb Smirnoff 	struct pf_poolhashkey	 key;
3613b3a8eb9SGleb Smirnoff 	struct pf_addr		 counter;
3623b3a8eb9SGleb Smirnoff 	int			 tblidx;
3633b3a8eb9SGleb Smirnoff 	u_int16_t		 proxy_port[2];
3643b3a8eb9SGleb Smirnoff 	u_int8_t		 opts;
3653b3a8eb9SGleb Smirnoff };
3663b3a8eb9SGleb Smirnoff 
3673b3a8eb9SGleb Smirnoff 
3683b3a8eb9SGleb Smirnoff /* A packed Operating System description for fingerprinting */
3693b3a8eb9SGleb Smirnoff typedef u_int32_t pf_osfp_t;
3703b3a8eb9SGleb Smirnoff #define PF_OSFP_ANY	((pf_osfp_t)0)
3713b3a8eb9SGleb Smirnoff #define PF_OSFP_UNKNOWN	((pf_osfp_t)-1)
3723b3a8eb9SGleb Smirnoff #define PF_OSFP_NOMATCH	((pf_osfp_t)-2)
3733b3a8eb9SGleb Smirnoff 
3743b3a8eb9SGleb Smirnoff struct pf_osfp_entry {
3753b3a8eb9SGleb Smirnoff 	SLIST_ENTRY(pf_osfp_entry) fp_entry;
3763b3a8eb9SGleb Smirnoff 	pf_osfp_t		fp_os;
3773b3a8eb9SGleb Smirnoff 	int			fp_enflags;
3783b3a8eb9SGleb Smirnoff #define PF_OSFP_EXPANDED	0x001		/* expanded entry */
3793b3a8eb9SGleb Smirnoff #define PF_OSFP_GENERIC		0x002		/* generic signature */
3803b3a8eb9SGleb Smirnoff #define PF_OSFP_NODETAIL	0x004		/* no p0f details */
3813b3a8eb9SGleb Smirnoff #define PF_OSFP_LEN	32
3823b3a8eb9SGleb Smirnoff 	char			fp_class_nm[PF_OSFP_LEN];
3833b3a8eb9SGleb Smirnoff 	char			fp_version_nm[PF_OSFP_LEN];
3843b3a8eb9SGleb Smirnoff 	char			fp_subtype_nm[PF_OSFP_LEN];
3853b3a8eb9SGleb Smirnoff };
3863b3a8eb9SGleb Smirnoff #define PF_OSFP_ENTRY_EQ(a, b) \
3873b3a8eb9SGleb Smirnoff     ((a)->fp_os == (b)->fp_os && \
3883b3a8eb9SGleb Smirnoff     memcmp((a)->fp_class_nm, (b)->fp_class_nm, PF_OSFP_LEN) == 0 && \
3893b3a8eb9SGleb Smirnoff     memcmp((a)->fp_version_nm, (b)->fp_version_nm, PF_OSFP_LEN) == 0 && \
3903b3a8eb9SGleb Smirnoff     memcmp((a)->fp_subtype_nm, (b)->fp_subtype_nm, PF_OSFP_LEN) == 0)
3913b3a8eb9SGleb Smirnoff 
3923b3a8eb9SGleb Smirnoff /* handle pf_osfp_t packing */
3933b3a8eb9SGleb Smirnoff #define _FP_RESERVED_BIT	1  /* For the special negative #defines */
3943b3a8eb9SGleb Smirnoff #define _FP_UNUSED_BITS		1
3953b3a8eb9SGleb Smirnoff #define _FP_CLASS_BITS		10 /* OS Class (Windows, Linux) */
3963b3a8eb9SGleb Smirnoff #define _FP_VERSION_BITS	10 /* OS version (95, 98, NT, 2.4.54, 3.2) */
3973b3a8eb9SGleb Smirnoff #define _FP_SUBTYPE_BITS	10 /* patch level (NT SP4, SP3, ECN patch) */
3983b3a8eb9SGleb Smirnoff #define PF_OSFP_UNPACK(osfp, class, version, subtype) do { \
3993b3a8eb9SGleb Smirnoff 	(class) = ((osfp) >> (_FP_VERSION_BITS+_FP_SUBTYPE_BITS)) & \
4003b3a8eb9SGleb Smirnoff 	    ((1 << _FP_CLASS_BITS) - 1); \
4013b3a8eb9SGleb Smirnoff 	(version) = ((osfp) >> _FP_SUBTYPE_BITS) & \
4023b3a8eb9SGleb Smirnoff 	    ((1 << _FP_VERSION_BITS) - 1);\
4033b3a8eb9SGleb Smirnoff 	(subtype) = (osfp) & ((1 << _FP_SUBTYPE_BITS) - 1); \
4043b3a8eb9SGleb Smirnoff } while(0)
4053b3a8eb9SGleb Smirnoff #define PF_OSFP_PACK(osfp, class, version, subtype) do { \
4063b3a8eb9SGleb Smirnoff 	(osfp) = ((class) & ((1 << _FP_CLASS_BITS) - 1)) << (_FP_VERSION_BITS \
4073b3a8eb9SGleb Smirnoff 	    + _FP_SUBTYPE_BITS); \
4083b3a8eb9SGleb Smirnoff 	(osfp) |= ((version) & ((1 << _FP_VERSION_BITS) - 1)) << \
4093b3a8eb9SGleb Smirnoff 	    _FP_SUBTYPE_BITS; \
4103b3a8eb9SGleb Smirnoff 	(osfp) |= (subtype) & ((1 << _FP_SUBTYPE_BITS) - 1); \
4113b3a8eb9SGleb Smirnoff } while(0)
4123b3a8eb9SGleb Smirnoff 
4133b3a8eb9SGleb Smirnoff /* the fingerprint of an OSes TCP SYN packet */
4143b3a8eb9SGleb Smirnoff typedef u_int64_t	pf_tcpopts_t;
4153b3a8eb9SGleb Smirnoff struct pf_os_fingerprint {
4163b3a8eb9SGleb Smirnoff 	SLIST_HEAD(pf_osfp_enlist, pf_osfp_entry) fp_oses; /* list of matches */
4173b3a8eb9SGleb Smirnoff 	pf_tcpopts_t		fp_tcpopts;	/* packed TCP options */
4183b3a8eb9SGleb Smirnoff 	u_int16_t		fp_wsize;	/* TCP window size */
4193b3a8eb9SGleb Smirnoff 	u_int16_t		fp_psize;	/* ip->ip_len */
4203b3a8eb9SGleb Smirnoff 	u_int16_t		fp_mss;		/* TCP MSS */
4213b3a8eb9SGleb Smirnoff 	u_int16_t		fp_flags;
4223b3a8eb9SGleb Smirnoff #define PF_OSFP_WSIZE_MOD	0x0001		/* Window modulus */
4233b3a8eb9SGleb Smirnoff #define PF_OSFP_WSIZE_DC	0x0002		/* Window don't care */
4243b3a8eb9SGleb Smirnoff #define PF_OSFP_WSIZE_MSS	0x0004		/* Window multiple of MSS */
4253b3a8eb9SGleb Smirnoff #define PF_OSFP_WSIZE_MTU	0x0008		/* Window multiple of MTU */
4263b3a8eb9SGleb Smirnoff #define PF_OSFP_PSIZE_MOD	0x0010		/* packet size modulus */
4273b3a8eb9SGleb Smirnoff #define PF_OSFP_PSIZE_DC	0x0020		/* packet size don't care */
4283b3a8eb9SGleb Smirnoff #define PF_OSFP_WSCALE		0x0040		/* TCP window scaling */
4293b3a8eb9SGleb Smirnoff #define PF_OSFP_WSCALE_MOD	0x0080		/* TCP window scale modulus */
4303b3a8eb9SGleb Smirnoff #define PF_OSFP_WSCALE_DC	0x0100		/* TCP window scale dont-care */
4313b3a8eb9SGleb Smirnoff #define PF_OSFP_MSS		0x0200		/* TCP MSS */
4323b3a8eb9SGleb Smirnoff #define PF_OSFP_MSS_MOD		0x0400		/* TCP MSS modulus */
4333b3a8eb9SGleb Smirnoff #define PF_OSFP_MSS_DC		0x0800		/* TCP MSS dont-care */
4343b3a8eb9SGleb Smirnoff #define PF_OSFP_DF		0x1000		/* IPv4 don't fragment bit */
4353b3a8eb9SGleb Smirnoff #define PF_OSFP_TS0		0x2000		/* Zero timestamp */
4363b3a8eb9SGleb Smirnoff #define PF_OSFP_INET6		0x4000		/* IPv6 */
4373b3a8eb9SGleb Smirnoff 	u_int8_t		fp_optcnt;	/* TCP option count */
4383b3a8eb9SGleb Smirnoff 	u_int8_t		fp_wscale;	/* TCP window scaling */
4393b3a8eb9SGleb Smirnoff 	u_int8_t		fp_ttl;		/* IPv4 TTL */
4403b3a8eb9SGleb Smirnoff #define PF_OSFP_MAXTTL_OFFSET	40
4413b3a8eb9SGleb Smirnoff /* TCP options packing */
4423b3a8eb9SGleb Smirnoff #define PF_OSFP_TCPOPT_NOP	0x0		/* TCP NOP option */
4433b3a8eb9SGleb Smirnoff #define PF_OSFP_TCPOPT_WSCALE	0x1		/* TCP window scaling option */
4443b3a8eb9SGleb Smirnoff #define PF_OSFP_TCPOPT_MSS	0x2		/* TCP max segment size opt */
4453b3a8eb9SGleb Smirnoff #define PF_OSFP_TCPOPT_SACK	0x3		/* TCP SACK OK option */
4463b3a8eb9SGleb Smirnoff #define PF_OSFP_TCPOPT_TS	0x4		/* TCP timestamp option */
4473b3a8eb9SGleb Smirnoff #define PF_OSFP_TCPOPT_BITS	3		/* bits used by each option */
4483b3a8eb9SGleb Smirnoff #define PF_OSFP_MAX_OPTS \
4493b3a8eb9SGleb Smirnoff     (sizeof(((struct pf_os_fingerprint *)0)->fp_tcpopts) * 8) \
4503b3a8eb9SGleb Smirnoff     / PF_OSFP_TCPOPT_BITS
4513b3a8eb9SGleb Smirnoff 
4523b3a8eb9SGleb Smirnoff 	SLIST_ENTRY(pf_os_fingerprint)	fp_next;
4533b3a8eb9SGleb Smirnoff };
4543b3a8eb9SGleb Smirnoff 
4553b3a8eb9SGleb Smirnoff struct pf_osfp_ioctl {
4563b3a8eb9SGleb Smirnoff 	struct pf_osfp_entry	fp_os;
4573b3a8eb9SGleb Smirnoff 	pf_tcpopts_t		fp_tcpopts;	/* packed TCP options */
4583b3a8eb9SGleb Smirnoff 	u_int16_t		fp_wsize;	/* TCP window size */
4593b3a8eb9SGleb Smirnoff 	u_int16_t		fp_psize;	/* ip->ip_len */
4603b3a8eb9SGleb Smirnoff 	u_int16_t		fp_mss;		/* TCP MSS */
4613b3a8eb9SGleb Smirnoff 	u_int16_t		fp_flags;
4623b3a8eb9SGleb Smirnoff 	u_int8_t		fp_optcnt;	/* TCP option count */
4633b3a8eb9SGleb Smirnoff 	u_int8_t		fp_wscale;	/* TCP window scaling */
4643b3a8eb9SGleb Smirnoff 	u_int8_t		fp_ttl;		/* IPv4 TTL */
4653b3a8eb9SGleb Smirnoff 
4663b3a8eb9SGleb Smirnoff 	int			fp_getnum;	/* DIOCOSFPGET number */
4673b3a8eb9SGleb Smirnoff };
4683b3a8eb9SGleb Smirnoff 
4693b3a8eb9SGleb Smirnoff 
4703b3a8eb9SGleb Smirnoff union pf_rule_ptr {
4713b3a8eb9SGleb Smirnoff 	struct pf_rule		*ptr;
4723b3a8eb9SGleb Smirnoff 	u_int32_t		 nr;
4733b3a8eb9SGleb Smirnoff };
4743b3a8eb9SGleb Smirnoff 
4753b3a8eb9SGleb Smirnoff #define	PF_ANCHOR_NAME_SIZE	 64
4763b3a8eb9SGleb Smirnoff 
4773b3a8eb9SGleb Smirnoff struct pf_rule {
4783b3a8eb9SGleb Smirnoff 	struct pf_rule_addr	 src;
4793b3a8eb9SGleb Smirnoff 	struct pf_rule_addr	 dst;
4803b3a8eb9SGleb Smirnoff #define PF_SKIP_IFP		0
4813b3a8eb9SGleb Smirnoff #define PF_SKIP_DIR		1
4823b3a8eb9SGleb Smirnoff #define PF_SKIP_AF		2
4833b3a8eb9SGleb Smirnoff #define PF_SKIP_PROTO		3
4843b3a8eb9SGleb Smirnoff #define PF_SKIP_SRC_ADDR	4
4853b3a8eb9SGleb Smirnoff #define PF_SKIP_SRC_PORT	5
4863b3a8eb9SGleb Smirnoff #define PF_SKIP_DST_ADDR	6
4873b3a8eb9SGleb Smirnoff #define PF_SKIP_DST_PORT	7
4883b3a8eb9SGleb Smirnoff #define PF_SKIP_COUNT		8
4893b3a8eb9SGleb Smirnoff 	union pf_rule_ptr	 skip[PF_SKIP_COUNT];
4903b3a8eb9SGleb Smirnoff #define PF_RULE_LABEL_SIZE	 64
4913b3a8eb9SGleb Smirnoff 	char			 label[PF_RULE_LABEL_SIZE];
4923b3a8eb9SGleb Smirnoff 	char			 ifname[IFNAMSIZ];
4933b3a8eb9SGleb Smirnoff 	char			 qname[PF_QNAME_SIZE];
4943b3a8eb9SGleb Smirnoff 	char			 pqname[PF_QNAME_SIZE];
4953b3a8eb9SGleb Smirnoff #define	PF_TAG_NAME_SIZE	 64
4963b3a8eb9SGleb Smirnoff 	char			 tagname[PF_TAG_NAME_SIZE];
4973b3a8eb9SGleb Smirnoff 	char			 match_tagname[PF_TAG_NAME_SIZE];
4983b3a8eb9SGleb Smirnoff 
4993b3a8eb9SGleb Smirnoff 	char			 overload_tblname[PF_TABLE_NAME_SIZE];
5003b3a8eb9SGleb Smirnoff 
5013b3a8eb9SGleb Smirnoff 	TAILQ_ENTRY(pf_rule)	 entries;
5023b3a8eb9SGleb Smirnoff 	struct pf_pool		 rpool;
5033b3a8eb9SGleb Smirnoff 
5043b3a8eb9SGleb Smirnoff 	u_int64_t		 evaluations;
5053b3a8eb9SGleb Smirnoff 	u_int64_t		 packets[2];
5063b3a8eb9SGleb Smirnoff 	u_int64_t		 bytes[2];
5073b3a8eb9SGleb Smirnoff 
5083b3a8eb9SGleb Smirnoff 	struct pfi_kif		*kif;
5093b3a8eb9SGleb Smirnoff 	struct pf_anchor	*anchor;
5103b3a8eb9SGleb Smirnoff 	struct pfr_ktable	*overload_tbl;
5113b3a8eb9SGleb Smirnoff 
5123b3a8eb9SGleb Smirnoff 	pf_osfp_t		 os_fingerprint;
5133b3a8eb9SGleb Smirnoff 
5143b3a8eb9SGleb Smirnoff 	int			 rtableid;
5153b3a8eb9SGleb Smirnoff 	u_int32_t		 timeout[PFTM_MAX];
5163b3a8eb9SGleb Smirnoff 	u_int32_t		 max_states;
5173b3a8eb9SGleb Smirnoff 	u_int32_t		 max_src_nodes;
5183b3a8eb9SGleb Smirnoff 	u_int32_t		 max_src_states;
5193b3a8eb9SGleb Smirnoff 	u_int32_t		 max_src_conn;
5203b3a8eb9SGleb Smirnoff 	struct {
5213b3a8eb9SGleb Smirnoff 		u_int32_t		limit;
5223b3a8eb9SGleb Smirnoff 		u_int32_t		seconds;
5233b3a8eb9SGleb Smirnoff 	}			 max_src_conn_rate;
5243b3a8eb9SGleb Smirnoff 	u_int32_t		 qid;
5253b3a8eb9SGleb Smirnoff 	u_int32_t		 pqid;
5263b3a8eb9SGleb Smirnoff 	u_int32_t		 rt_listid;
5273b3a8eb9SGleb Smirnoff 	u_int32_t		 nr;
5283b3a8eb9SGleb Smirnoff 	u_int32_t		 prob;
5293b3a8eb9SGleb Smirnoff 	uid_t			 cuid;
5303b3a8eb9SGleb Smirnoff 	pid_t			 cpid;
5313b3a8eb9SGleb Smirnoff 
53248278b88SGleb Smirnoff 	counter_u64_t		 states_cur;
53348278b88SGleb Smirnoff 	counter_u64_t		 states_tot;
53448278b88SGleb Smirnoff 	counter_u64_t		 src_nodes;
53548278b88SGleb Smirnoff 
5363b3a8eb9SGleb Smirnoff 	u_int16_t		 return_icmp;
5373b3a8eb9SGleb Smirnoff 	u_int16_t		 return_icmp6;
5383b3a8eb9SGleb Smirnoff 	u_int16_t		 max_mss;
5393b3a8eb9SGleb Smirnoff 	u_int16_t		 tag;
5403b3a8eb9SGleb Smirnoff 	u_int16_t		 match_tag;
5413b3a8eb9SGleb Smirnoff 	u_int16_t		 spare2;			/* netgraph */
5423b3a8eb9SGleb Smirnoff 
5433b3a8eb9SGleb Smirnoff 	struct pf_rule_uid	 uid;
5443b3a8eb9SGleb Smirnoff 	struct pf_rule_gid	 gid;
5453b3a8eb9SGleb Smirnoff 
5463b3a8eb9SGleb Smirnoff 	u_int32_t		 rule_flag;
5473b3a8eb9SGleb Smirnoff 	u_int8_t		 action;
5483b3a8eb9SGleb Smirnoff 	u_int8_t		 direction;
5493b3a8eb9SGleb Smirnoff 	u_int8_t		 log;
5503b3a8eb9SGleb Smirnoff 	u_int8_t		 logif;
5513b3a8eb9SGleb Smirnoff 	u_int8_t		 quick;
5523b3a8eb9SGleb Smirnoff 	u_int8_t		 ifnot;
5533b3a8eb9SGleb Smirnoff 	u_int8_t		 match_tag_not;
5543b3a8eb9SGleb Smirnoff 	u_int8_t		 natpass;
5553b3a8eb9SGleb Smirnoff 
5563b3a8eb9SGleb Smirnoff #define PF_STATE_NORMAL		0x1
5573b3a8eb9SGleb Smirnoff #define PF_STATE_MODULATE	0x2
5583b3a8eb9SGleb Smirnoff #define PF_STATE_SYNPROXY	0x3
5593b3a8eb9SGleb Smirnoff 	u_int8_t		 keep_state;
5603b3a8eb9SGleb Smirnoff 	sa_family_t		 af;
5613b3a8eb9SGleb Smirnoff 	u_int8_t		 proto;
5623b3a8eb9SGleb Smirnoff 	u_int8_t		 type;
5633b3a8eb9SGleb Smirnoff 	u_int8_t		 code;
5643b3a8eb9SGleb Smirnoff 	u_int8_t		 flags;
5653b3a8eb9SGleb Smirnoff 	u_int8_t		 flagset;
5663b3a8eb9SGleb Smirnoff 	u_int8_t		 min_ttl;
5673b3a8eb9SGleb Smirnoff 	u_int8_t		 allow_opts;
5683b3a8eb9SGleb Smirnoff 	u_int8_t		 rt;
5693b3a8eb9SGleb Smirnoff 	u_int8_t		 return_ttl;
5703b3a8eb9SGleb Smirnoff 	u_int8_t		 tos;
5713b3a8eb9SGleb Smirnoff 	u_int8_t		 set_tos;
5723b3a8eb9SGleb Smirnoff 	u_int8_t		 anchor_relative;
5733b3a8eb9SGleb Smirnoff 	u_int8_t		 anchor_wildcard;
5743b3a8eb9SGleb Smirnoff 
5753b3a8eb9SGleb Smirnoff #define PF_FLUSH		0x01
5763b3a8eb9SGleb Smirnoff #define PF_FLUSH_GLOBAL		0x02
5773b3a8eb9SGleb Smirnoff 	u_int8_t		 flush;
5783b3a8eb9SGleb Smirnoff 
5793b3a8eb9SGleb Smirnoff 	struct {
5803b3a8eb9SGleb Smirnoff 		struct pf_addr		addr;
5813b3a8eb9SGleb Smirnoff 		u_int16_t		port;
5823b3a8eb9SGleb Smirnoff 	}			divert;
583fb3541adSGleb Smirnoff 
584fb3541adSGleb Smirnoff 	uint64_t		 u_states_cur;
585fb3541adSGleb Smirnoff 	uint64_t		 u_states_tot;
586fb3541adSGleb Smirnoff 	uint64_t		 u_src_nodes;
5873b3a8eb9SGleb Smirnoff };
5883b3a8eb9SGleb Smirnoff 
5893b3a8eb9SGleb Smirnoff /* rule flags */
5903b3a8eb9SGleb Smirnoff #define	PFRULE_DROP		0x0000
5913b3a8eb9SGleb Smirnoff #define	PFRULE_RETURNRST	0x0001
5923b3a8eb9SGleb Smirnoff #define	PFRULE_FRAGMENT		0x0002
5933b3a8eb9SGleb Smirnoff #define	PFRULE_RETURNICMP	0x0004
5943b3a8eb9SGleb Smirnoff #define	PFRULE_RETURN		0x0008
5953b3a8eb9SGleb Smirnoff #define	PFRULE_NOSYNC		0x0010
5963b3a8eb9SGleb Smirnoff #define PFRULE_SRCTRACK		0x0020  /* track source states */
5973b3a8eb9SGleb Smirnoff #define PFRULE_RULESRCTRACK	0x0040  /* per rule */
5983b3a8eb9SGleb Smirnoff #define	PFRULE_REFS		0x0080	/* rule has references */
5993b3a8eb9SGleb Smirnoff 
6003b3a8eb9SGleb Smirnoff /* scrub flags */
6013b3a8eb9SGleb Smirnoff #define	PFRULE_NODF		0x0100
6023b3a8eb9SGleb Smirnoff #define	PFRULE_FRAGCROP		0x0200	/* non-buffering frag cache */
6033b3a8eb9SGleb Smirnoff #define	PFRULE_FRAGDROP		0x0400	/* drop funny fragments */
6043b3a8eb9SGleb Smirnoff #define PFRULE_RANDOMID		0x0800
6053b3a8eb9SGleb Smirnoff #define PFRULE_REASSEMBLE_TCP	0x1000
6063b3a8eb9SGleb Smirnoff #define PFRULE_SET_TOS		0x2000
6073b3a8eb9SGleb Smirnoff 
6083b3a8eb9SGleb Smirnoff /* rule flags again */
6093b3a8eb9SGleb Smirnoff #define PFRULE_IFBOUND		0x00010000	/* if-bound */
6103b3a8eb9SGleb Smirnoff #define PFRULE_STATESLOPPY	0x00020000	/* sloppy state tracking */
6113b3a8eb9SGleb Smirnoff 
6123b3a8eb9SGleb Smirnoff #define PFSTATE_HIWAT		10000	/* default state table size */
6133b3a8eb9SGleb Smirnoff #define PFSTATE_ADAPT_START	6000	/* default adaptive timeout start */
6143b3a8eb9SGleb Smirnoff #define PFSTATE_ADAPT_END	12000	/* default adaptive timeout end */
6153b3a8eb9SGleb Smirnoff 
6163b3a8eb9SGleb Smirnoff 
6173b3a8eb9SGleb Smirnoff struct pf_threshold {
6183b3a8eb9SGleb Smirnoff 	u_int32_t	limit;
6193b3a8eb9SGleb Smirnoff #define	PF_THRESHOLD_MULT	1000
6203b3a8eb9SGleb Smirnoff #define PF_THRESHOLD_MAX	0xffffffff / PF_THRESHOLD_MULT
6213b3a8eb9SGleb Smirnoff 	u_int32_t	seconds;
6223b3a8eb9SGleb Smirnoff 	u_int32_t	count;
6233b3a8eb9SGleb Smirnoff 	u_int32_t	last;
6243b3a8eb9SGleb Smirnoff };
6253b3a8eb9SGleb Smirnoff 
6263b3a8eb9SGleb Smirnoff struct pf_src_node {
6273b3a8eb9SGleb Smirnoff 	LIST_ENTRY(pf_src_node) entry;
6283b3a8eb9SGleb Smirnoff 	struct pf_addr	 addr;
6293b3a8eb9SGleb Smirnoff 	struct pf_addr	 raddr;
6303b3a8eb9SGleb Smirnoff 	union pf_rule_ptr rule;
6313b3a8eb9SGleb Smirnoff 	struct pfi_kif	*kif;
6323b3a8eb9SGleb Smirnoff 	u_int64_t	 bytes[2];
6333b3a8eb9SGleb Smirnoff 	u_int64_t	 packets[2];
6343b3a8eb9SGleb Smirnoff 	u_int32_t	 states;
6353b3a8eb9SGleb Smirnoff 	u_int32_t	 conn;
6363b3a8eb9SGleb Smirnoff 	struct pf_threshold	conn_rate;
6373b3a8eb9SGleb Smirnoff 	u_int32_t	 creation;
6383b3a8eb9SGleb Smirnoff 	u_int32_t	 expire;
6393b3a8eb9SGleb Smirnoff 	sa_family_t	 af;
6403b3a8eb9SGleb Smirnoff 	u_int8_t	 ruletype;
6413b3a8eb9SGleb Smirnoff };
6423b3a8eb9SGleb Smirnoff 
6433b3a8eb9SGleb Smirnoff #define PFSNODE_HIWAT		10000	/* default source node table size */
6443b3a8eb9SGleb Smirnoff 
6453b3a8eb9SGleb Smirnoff struct pf_state_scrub {
6463b3a8eb9SGleb Smirnoff 	struct timeval	pfss_last;	/* time received last packet	*/
6473b3a8eb9SGleb Smirnoff 	u_int32_t	pfss_tsecr;	/* last echoed timestamp	*/
6483b3a8eb9SGleb Smirnoff 	u_int32_t	pfss_tsval;	/* largest timestamp		*/
6493b3a8eb9SGleb Smirnoff 	u_int32_t	pfss_tsval0;	/* original timestamp		*/
6503b3a8eb9SGleb Smirnoff 	u_int16_t	pfss_flags;
6513b3a8eb9SGleb Smirnoff #define PFSS_TIMESTAMP	0x0001		/* modulate timestamp		*/
6523b3a8eb9SGleb Smirnoff #define PFSS_PAWS	0x0010		/* stricter PAWS checks		*/
6533b3a8eb9SGleb Smirnoff #define PFSS_PAWS_IDLED	0x0020		/* was idle too long.  no PAWS	*/
6543b3a8eb9SGleb Smirnoff #define PFSS_DATA_TS	0x0040		/* timestamp on data packets	*/
6553b3a8eb9SGleb Smirnoff #define PFSS_DATA_NOTS	0x0080		/* no timestamp on data packets	*/
6563b3a8eb9SGleb Smirnoff 	u_int8_t	pfss_ttl;	/* stashed TTL			*/
6573b3a8eb9SGleb Smirnoff 	u_int8_t	pad;
6583b3a8eb9SGleb Smirnoff 	u_int32_t	pfss_ts_mod;	/* timestamp modulation		*/
6593b3a8eb9SGleb Smirnoff };
6603b3a8eb9SGleb Smirnoff 
6613b3a8eb9SGleb Smirnoff struct pf_state_host {
6623b3a8eb9SGleb Smirnoff 	struct pf_addr	addr;
6633b3a8eb9SGleb Smirnoff 	u_int16_t	port;
6643b3a8eb9SGleb Smirnoff 	u_int16_t	pad;
6653b3a8eb9SGleb Smirnoff };
6663b3a8eb9SGleb Smirnoff 
6673b3a8eb9SGleb Smirnoff struct pf_state_peer {
6683b3a8eb9SGleb Smirnoff 	struct pf_state_scrub	*scrub;	/* state is scrubbed		*/
6693b3a8eb9SGleb Smirnoff 	u_int32_t	seqlo;		/* Max sequence number sent	*/
6703b3a8eb9SGleb Smirnoff 	u_int32_t	seqhi;		/* Max the other end ACKd + win	*/
6713b3a8eb9SGleb Smirnoff 	u_int32_t	seqdiff;	/* Sequence number modulator	*/
6723b3a8eb9SGleb Smirnoff 	u_int16_t	max_win;	/* largest window (pre scaling)	*/
6733b3a8eb9SGleb Smirnoff 	u_int16_t	mss;		/* Maximum segment size option	*/
6743b3a8eb9SGleb Smirnoff 	u_int8_t	state;		/* active state level		*/
6753b3a8eb9SGleb Smirnoff 	u_int8_t	wscale;		/* window scaling factor	*/
6763b3a8eb9SGleb Smirnoff 	u_int8_t	tcp_est;	/* Did we reach TCPS_ESTABLISHED */
6773b3a8eb9SGleb Smirnoff 	u_int8_t	pad[1];
6783b3a8eb9SGleb Smirnoff };
6793b3a8eb9SGleb Smirnoff 
6803b3a8eb9SGleb Smirnoff /* Keep synced with struct pf_state_key. */
6813b3a8eb9SGleb Smirnoff struct pf_state_key_cmp {
6823b3a8eb9SGleb Smirnoff 	struct pf_addr	 addr[2];
6833b3a8eb9SGleb Smirnoff 	u_int16_t	 port[2];
6843b3a8eb9SGleb Smirnoff 	sa_family_t	 af;
6853b3a8eb9SGleb Smirnoff 	u_int8_t	 proto;
6863b3a8eb9SGleb Smirnoff 	u_int8_t	 pad[2];
6873b3a8eb9SGleb Smirnoff };
6883b3a8eb9SGleb Smirnoff 
6893b3a8eb9SGleb Smirnoff struct pf_state_key {
6903b3a8eb9SGleb Smirnoff 	struct pf_addr	 addr[2];
6913b3a8eb9SGleb Smirnoff 	u_int16_t	 port[2];
6923b3a8eb9SGleb Smirnoff 	sa_family_t	 af;
6933b3a8eb9SGleb Smirnoff 	u_int8_t	 proto;
6943b3a8eb9SGleb Smirnoff 	u_int8_t	 pad[2];
6953b3a8eb9SGleb Smirnoff 
6963b3a8eb9SGleb Smirnoff 	LIST_ENTRY(pf_state_key) entry;
6973b3a8eb9SGleb Smirnoff 	TAILQ_HEAD(, pf_state)	 states[2];
6983b3a8eb9SGleb Smirnoff };
6993b3a8eb9SGleb Smirnoff 
7003b3a8eb9SGleb Smirnoff /* Keep synced with struct pf_state. */
7013b3a8eb9SGleb Smirnoff struct pf_state_cmp {
7023b3a8eb9SGleb Smirnoff 	u_int64_t		 id;
7033b3a8eb9SGleb Smirnoff 	u_int32_t		 creatorid;
7043b3a8eb9SGleb Smirnoff 	u_int8_t		 direction;
7053b3a8eb9SGleb Smirnoff 	u_int8_t		 pad[3];
7063b3a8eb9SGleb Smirnoff };
7073b3a8eb9SGleb Smirnoff 
7083b3a8eb9SGleb Smirnoff struct pf_state {
7093b3a8eb9SGleb Smirnoff 	u_int64_t		 id;
7103b3a8eb9SGleb Smirnoff 	u_int32_t		 creatorid;
7113b3a8eb9SGleb Smirnoff 	u_int8_t		 direction;
7123b3a8eb9SGleb Smirnoff 	u_int8_t		 pad[3];
7133b3a8eb9SGleb Smirnoff 
7143b3a8eb9SGleb Smirnoff 	u_int			 refs;
7153b3a8eb9SGleb Smirnoff 	TAILQ_ENTRY(pf_state)	 sync_list;
7163b3a8eb9SGleb Smirnoff 	TAILQ_ENTRY(pf_state)	 key_list[2];
7173b3a8eb9SGleb Smirnoff 	LIST_ENTRY(pf_state)	 entry;
7183b3a8eb9SGleb Smirnoff 	struct pf_state_peer	 src;
7193b3a8eb9SGleb Smirnoff 	struct pf_state_peer	 dst;
7203b3a8eb9SGleb Smirnoff 	union pf_rule_ptr	 rule;
7213b3a8eb9SGleb Smirnoff 	union pf_rule_ptr	 anchor;
7223b3a8eb9SGleb Smirnoff 	union pf_rule_ptr	 nat_rule;
7233b3a8eb9SGleb Smirnoff 	struct pf_addr		 rt_addr;
7243b3a8eb9SGleb Smirnoff 	struct pf_state_key	*key[2];	/* addresses stack and wire  */
7253b3a8eb9SGleb Smirnoff 	struct pfi_kif		*kif;
7263b3a8eb9SGleb Smirnoff 	struct pfi_kif		*rt_kif;
7273b3a8eb9SGleb Smirnoff 	struct pf_src_node	*src_node;
7283b3a8eb9SGleb Smirnoff 	struct pf_src_node	*nat_src_node;
7293b3a8eb9SGleb Smirnoff 	u_int64_t		 packets[2];
7303b3a8eb9SGleb Smirnoff 	u_int64_t		 bytes[2];
7313b3a8eb9SGleb Smirnoff 	u_int32_t		 creation;
7323b3a8eb9SGleb Smirnoff 	u_int32_t	 	 expire;
7333b3a8eb9SGleb Smirnoff 	u_int32_t		 pfsync_time;
7343b3a8eb9SGleb Smirnoff 	u_int16_t		 tag;
7353b3a8eb9SGleb Smirnoff 	u_int8_t		 log;
7363b3a8eb9SGleb Smirnoff 	u_int8_t		 state_flags;
7373b3a8eb9SGleb Smirnoff #define	PFSTATE_ALLOWOPTS	0x01
7383b3a8eb9SGleb Smirnoff #define	PFSTATE_SLOPPY		0x02
7393b3a8eb9SGleb Smirnoff /*  was	PFSTATE_PFLOW		0x04 */
7403b3a8eb9SGleb Smirnoff #define	PFSTATE_NOSYNC		0x08
7413b3a8eb9SGleb Smirnoff #define	PFSTATE_ACK		0x10
7423b3a8eb9SGleb Smirnoff 	u_int8_t		 timeout;
7433b3a8eb9SGleb Smirnoff 	u_int8_t		 sync_state; /* PFSYNC_S_x */
7443b3a8eb9SGleb Smirnoff 
7453b3a8eb9SGleb Smirnoff 	/* XXX */
7463b3a8eb9SGleb Smirnoff 	u_int8_t		 sync_updates;
7473b3a8eb9SGleb Smirnoff 	u_int8_t		_tail[3];
7483b3a8eb9SGleb Smirnoff };
7493b3a8eb9SGleb Smirnoff 
7503b3a8eb9SGleb Smirnoff /*
7513b3a8eb9SGleb Smirnoff  * Unified state structures for pulling states out of the kernel
7523b3a8eb9SGleb Smirnoff  * used by pfsync(4) and the pf(4) ioctl.
7533b3a8eb9SGleb Smirnoff  */
7543b3a8eb9SGleb Smirnoff struct pfsync_state_scrub {
7553b3a8eb9SGleb Smirnoff 	u_int16_t	pfss_flags;
7563b3a8eb9SGleb Smirnoff 	u_int8_t	pfss_ttl;	/* stashed TTL		*/
7573b3a8eb9SGleb Smirnoff #define PFSYNC_SCRUB_FLAG_VALID		0x01
7583b3a8eb9SGleb Smirnoff 	u_int8_t	scrub_flag;
7593b3a8eb9SGleb Smirnoff 	u_int32_t	pfss_ts_mod;	/* timestamp modulation	*/
7603b3a8eb9SGleb Smirnoff } __packed;
7613b3a8eb9SGleb Smirnoff 
7623b3a8eb9SGleb Smirnoff struct pfsync_state_peer {
7633b3a8eb9SGleb Smirnoff 	struct pfsync_state_scrub scrub;	/* state is scrubbed	*/
7643b3a8eb9SGleb Smirnoff 	u_int32_t	seqlo;		/* Max sequence number sent	*/
7653b3a8eb9SGleb Smirnoff 	u_int32_t	seqhi;		/* Max the other end ACKd + win	*/
7663b3a8eb9SGleb Smirnoff 	u_int32_t	seqdiff;	/* Sequence number modulator	*/
7673b3a8eb9SGleb Smirnoff 	u_int16_t	max_win;	/* largest window (pre scaling)	*/
7683b3a8eb9SGleb Smirnoff 	u_int16_t	mss;		/* Maximum segment size option	*/
7693b3a8eb9SGleb Smirnoff 	u_int8_t	state;		/* active state level		*/
7703b3a8eb9SGleb Smirnoff 	u_int8_t	wscale;		/* window scaling factor	*/
7713b3a8eb9SGleb Smirnoff 	u_int8_t	pad[6];
7723b3a8eb9SGleb Smirnoff } __packed;
7733b3a8eb9SGleb Smirnoff 
7743b3a8eb9SGleb Smirnoff struct pfsync_state_key {
7753b3a8eb9SGleb Smirnoff 	struct pf_addr	 addr[2];
7763b3a8eb9SGleb Smirnoff 	u_int16_t	 port[2];
7773b3a8eb9SGleb Smirnoff };
7783b3a8eb9SGleb Smirnoff 
7793b3a8eb9SGleb Smirnoff struct pfsync_state {
7803b3a8eb9SGleb Smirnoff 	u_int64_t	 id;
7813b3a8eb9SGleb Smirnoff 	char		 ifname[IFNAMSIZ];
7823b3a8eb9SGleb Smirnoff 	struct pfsync_state_key	key[2];
7833b3a8eb9SGleb Smirnoff 	struct pfsync_state_peer src;
7843b3a8eb9SGleb Smirnoff 	struct pfsync_state_peer dst;
7853b3a8eb9SGleb Smirnoff 	struct pf_addr	 rt_addr;
7863b3a8eb9SGleb Smirnoff 	u_int32_t	 rule;
7873b3a8eb9SGleb Smirnoff 	u_int32_t	 anchor;
7883b3a8eb9SGleb Smirnoff 	u_int32_t	 nat_rule;
7893b3a8eb9SGleb Smirnoff 	u_int32_t	 creation;
7903b3a8eb9SGleb Smirnoff 	u_int32_t	 expire;
7913b3a8eb9SGleb Smirnoff 	u_int32_t	 packets[2][2];
7923b3a8eb9SGleb Smirnoff 	u_int32_t	 bytes[2][2];
7933b3a8eb9SGleb Smirnoff 	u_int32_t	 creatorid;
7943b3a8eb9SGleb Smirnoff 	sa_family_t	 af;
7953b3a8eb9SGleb Smirnoff 	u_int8_t	 proto;
7963b3a8eb9SGleb Smirnoff 	u_int8_t	 direction;
7973b3a8eb9SGleb Smirnoff 	u_int8_t	 __spare[2];
7983b3a8eb9SGleb Smirnoff 	u_int8_t	 log;
7993b3a8eb9SGleb Smirnoff 	u_int8_t	 state_flags;
8003b3a8eb9SGleb Smirnoff 	u_int8_t	 timeout;
8013b3a8eb9SGleb Smirnoff 	u_int8_t	 sync_flags;
8023b3a8eb9SGleb Smirnoff 	u_int8_t	 updates;
8033b3a8eb9SGleb Smirnoff } __packed;
8043b3a8eb9SGleb Smirnoff 
8053b3a8eb9SGleb Smirnoff #ifdef _KERNEL
8063b3a8eb9SGleb Smirnoff /* pfsync */
8073b3a8eb9SGleb Smirnoff typedef int		pfsync_state_import_t(struct pfsync_state *, u_int8_t);
8083b3a8eb9SGleb Smirnoff typedef	void		pfsync_insert_state_t(struct pf_state *);
8093b3a8eb9SGleb Smirnoff typedef	void		pfsync_update_state_t(struct pf_state *);
8103b3a8eb9SGleb Smirnoff typedef	void		pfsync_delete_state_t(struct pf_state *);
8113b3a8eb9SGleb Smirnoff typedef void		pfsync_clear_states_t(u_int32_t, const char *);
8123b3a8eb9SGleb Smirnoff typedef int		pfsync_defer_t(struct pf_state *, struct mbuf *);
8133b3a8eb9SGleb Smirnoff 
8143b3a8eb9SGleb Smirnoff extern pfsync_state_import_t	*pfsync_state_import_ptr;
8153b3a8eb9SGleb Smirnoff extern pfsync_insert_state_t	*pfsync_insert_state_ptr;
8163b3a8eb9SGleb Smirnoff extern pfsync_update_state_t	*pfsync_update_state_ptr;
8173b3a8eb9SGleb Smirnoff extern pfsync_delete_state_t	*pfsync_delete_state_ptr;
8183b3a8eb9SGleb Smirnoff extern pfsync_clear_states_t	*pfsync_clear_states_ptr;
8193b3a8eb9SGleb Smirnoff extern pfsync_defer_t		*pfsync_defer_ptr;
8203b3a8eb9SGleb Smirnoff 
8213b3a8eb9SGleb Smirnoff void			pfsync_state_export(struct pfsync_state *,
8223b3a8eb9SGleb Smirnoff 			    struct pf_state *);
8233b3a8eb9SGleb Smirnoff 
8243b3a8eb9SGleb Smirnoff /* pflog */
8253b3a8eb9SGleb Smirnoff struct pf_ruleset;
8263b3a8eb9SGleb Smirnoff struct pf_pdesc;
8273b3a8eb9SGleb Smirnoff typedef int pflog_packet_t(struct pfi_kif *, struct mbuf *, sa_family_t,
8283b3a8eb9SGleb Smirnoff     u_int8_t, u_int8_t, struct pf_rule *, struct pf_rule *,
8293b3a8eb9SGleb Smirnoff     struct pf_ruleset *, struct pf_pdesc *, int);
8303b3a8eb9SGleb Smirnoff extern pflog_packet_t		*pflog_packet_ptr;
8313b3a8eb9SGleb Smirnoff 
832*efc6c51fSGleb Smirnoff #define	V_pf_end_threads	VNET(pf_end_threads)
8333b3a8eb9SGleb Smirnoff #endif /* _KERNEL */
8343b3a8eb9SGleb Smirnoff 
8353b3a8eb9SGleb Smirnoff #define	PFSYNC_FLAG_SRCNODE	0x04
8363b3a8eb9SGleb Smirnoff #define	PFSYNC_FLAG_NATSRCNODE	0x08
8373b3a8eb9SGleb Smirnoff 
8383b3a8eb9SGleb Smirnoff /* for copies to/from network byte order */
8393b3a8eb9SGleb Smirnoff /* ioctl interface also uses network byte order */
8403b3a8eb9SGleb Smirnoff #define pf_state_peer_hton(s,d) do {		\
8413b3a8eb9SGleb Smirnoff 	(d)->seqlo = htonl((s)->seqlo);		\
8423b3a8eb9SGleb Smirnoff 	(d)->seqhi = htonl((s)->seqhi);		\
8433b3a8eb9SGleb Smirnoff 	(d)->seqdiff = htonl((s)->seqdiff);	\
8443b3a8eb9SGleb Smirnoff 	(d)->max_win = htons((s)->max_win);	\
8453b3a8eb9SGleb Smirnoff 	(d)->mss = htons((s)->mss);		\
8463b3a8eb9SGleb Smirnoff 	(d)->state = (s)->state;		\
8473b3a8eb9SGleb Smirnoff 	(d)->wscale = (s)->wscale;		\
8483b3a8eb9SGleb Smirnoff 	if ((s)->scrub) {						\
8493b3a8eb9SGleb Smirnoff 		(d)->scrub.pfss_flags = 				\
8503b3a8eb9SGleb Smirnoff 		    htons((s)->scrub->pfss_flags & PFSS_TIMESTAMP);	\
8513b3a8eb9SGleb Smirnoff 		(d)->scrub.pfss_ttl = (s)->scrub->pfss_ttl;		\
8523b3a8eb9SGleb Smirnoff 		(d)->scrub.pfss_ts_mod = htonl((s)->scrub->pfss_ts_mod);\
8533b3a8eb9SGleb Smirnoff 		(d)->scrub.scrub_flag = PFSYNC_SCRUB_FLAG_VALID;	\
8543b3a8eb9SGleb Smirnoff 	}								\
8553b3a8eb9SGleb Smirnoff } while (0)
8563b3a8eb9SGleb Smirnoff 
8573b3a8eb9SGleb Smirnoff #define pf_state_peer_ntoh(s,d) do {		\
8583b3a8eb9SGleb Smirnoff 	(d)->seqlo = ntohl((s)->seqlo);		\
8593b3a8eb9SGleb Smirnoff 	(d)->seqhi = ntohl((s)->seqhi);		\
8603b3a8eb9SGleb Smirnoff 	(d)->seqdiff = ntohl((s)->seqdiff);	\
8613b3a8eb9SGleb Smirnoff 	(d)->max_win = ntohs((s)->max_win);	\
8623b3a8eb9SGleb Smirnoff 	(d)->mss = ntohs((s)->mss);		\
8633b3a8eb9SGleb Smirnoff 	(d)->state = (s)->state;		\
8643b3a8eb9SGleb Smirnoff 	(d)->wscale = (s)->wscale;		\
8653b3a8eb9SGleb Smirnoff 	if ((s)->scrub.scrub_flag == PFSYNC_SCRUB_FLAG_VALID && 	\
8663b3a8eb9SGleb Smirnoff 	    (d)->scrub != NULL) {					\
8673b3a8eb9SGleb Smirnoff 		(d)->scrub->pfss_flags =				\
8683b3a8eb9SGleb Smirnoff 		    ntohs((s)->scrub.pfss_flags) & PFSS_TIMESTAMP;	\
8693b3a8eb9SGleb Smirnoff 		(d)->scrub->pfss_ttl = (s)->scrub.pfss_ttl;		\
8703b3a8eb9SGleb Smirnoff 		(d)->scrub->pfss_ts_mod = ntohl((s)->scrub.pfss_ts_mod);\
8713b3a8eb9SGleb Smirnoff 	}								\
8723b3a8eb9SGleb Smirnoff } while (0)
8733b3a8eb9SGleb Smirnoff 
8743b3a8eb9SGleb Smirnoff #define pf_state_counter_hton(s,d) do {				\
8753b3a8eb9SGleb Smirnoff 	d[0] = htonl((s>>32)&0xffffffff);			\
8763b3a8eb9SGleb Smirnoff 	d[1] = htonl(s&0xffffffff);				\
8773b3a8eb9SGleb Smirnoff } while (0)
8783b3a8eb9SGleb Smirnoff 
8793b3a8eb9SGleb Smirnoff #define pf_state_counter_from_pfsync(s)				\
8803b3a8eb9SGleb Smirnoff 	(((u_int64_t)(s[0])<<32) | (u_int64_t)(s[1]))
8813b3a8eb9SGleb Smirnoff 
8823b3a8eb9SGleb Smirnoff #define pf_state_counter_ntoh(s,d) do {				\
8833b3a8eb9SGleb Smirnoff 	d = ntohl(s[0]);					\
8843b3a8eb9SGleb Smirnoff 	d = d<<32;						\
8853b3a8eb9SGleb Smirnoff 	d += ntohl(s[1]);					\
8863b3a8eb9SGleb Smirnoff } while (0)
8873b3a8eb9SGleb Smirnoff 
8883b3a8eb9SGleb Smirnoff TAILQ_HEAD(pf_rulequeue, pf_rule);
8893b3a8eb9SGleb Smirnoff 
8903b3a8eb9SGleb Smirnoff struct pf_anchor;
8913b3a8eb9SGleb Smirnoff 
8923b3a8eb9SGleb Smirnoff struct pf_ruleset {
8933b3a8eb9SGleb Smirnoff 	struct {
8943b3a8eb9SGleb Smirnoff 		struct pf_rulequeue	 queues[2];
8953b3a8eb9SGleb Smirnoff 		struct {
8963b3a8eb9SGleb Smirnoff 			struct pf_rulequeue	*ptr;
8973b3a8eb9SGleb Smirnoff 			struct pf_rule		**ptr_array;
8983b3a8eb9SGleb Smirnoff 			u_int32_t		 rcount;
8993b3a8eb9SGleb Smirnoff 			u_int32_t		 ticket;
9003b3a8eb9SGleb Smirnoff 			int			 open;
9013b3a8eb9SGleb Smirnoff 		}			 active, inactive;
9023b3a8eb9SGleb Smirnoff 	}			 rules[PF_RULESET_MAX];
9033b3a8eb9SGleb Smirnoff 	struct pf_anchor	*anchor;
9043b3a8eb9SGleb Smirnoff 	u_int32_t		 tticket;
9053b3a8eb9SGleb Smirnoff 	int			 tables;
9063b3a8eb9SGleb Smirnoff 	int			 topen;
9073b3a8eb9SGleb Smirnoff };
9083b3a8eb9SGleb Smirnoff 
9093b3a8eb9SGleb Smirnoff RB_HEAD(pf_anchor_global, pf_anchor);
9103b3a8eb9SGleb Smirnoff RB_HEAD(pf_anchor_node, pf_anchor);
9113b3a8eb9SGleb Smirnoff struct pf_anchor {
9123b3a8eb9SGleb Smirnoff 	RB_ENTRY(pf_anchor)	 entry_global;
9133b3a8eb9SGleb Smirnoff 	RB_ENTRY(pf_anchor)	 entry_node;
9143b3a8eb9SGleb Smirnoff 	struct pf_anchor	*parent;
9153b3a8eb9SGleb Smirnoff 	struct pf_anchor_node	 children;
9163b3a8eb9SGleb Smirnoff 	char			 name[PF_ANCHOR_NAME_SIZE];
9173b3a8eb9SGleb Smirnoff 	char			 path[MAXPATHLEN];
9183b3a8eb9SGleb Smirnoff 	struct pf_ruleset	 ruleset;
9193b3a8eb9SGleb Smirnoff 	int			 refcnt;	/* anchor rules */
9201d6139c0SGleb Smirnoff 	int			 match;	/* XXX: used for pfctl black magic */
9213b3a8eb9SGleb Smirnoff };
9223b3a8eb9SGleb Smirnoff RB_PROTOTYPE(pf_anchor_global, pf_anchor, entry_global, pf_anchor_compare);
9233b3a8eb9SGleb Smirnoff RB_PROTOTYPE(pf_anchor_node, pf_anchor, entry_node, pf_anchor_compare);
9243b3a8eb9SGleb Smirnoff 
9253b3a8eb9SGleb Smirnoff #define PF_RESERVED_ANCHOR	"_pf"
9263b3a8eb9SGleb Smirnoff 
9273b3a8eb9SGleb Smirnoff #define PFR_TFLAG_PERSIST	0x00000001
9283b3a8eb9SGleb Smirnoff #define PFR_TFLAG_CONST		0x00000002
9293b3a8eb9SGleb Smirnoff #define PFR_TFLAG_ACTIVE	0x00000004
9303b3a8eb9SGleb Smirnoff #define PFR_TFLAG_INACTIVE	0x00000008
9313b3a8eb9SGleb Smirnoff #define PFR_TFLAG_REFERENCED	0x00000010
9323b3a8eb9SGleb Smirnoff #define PFR_TFLAG_REFDANCHOR	0x00000020
9333b3a8eb9SGleb Smirnoff #define PFR_TFLAG_COUNTERS	0x00000040
9343b3a8eb9SGleb Smirnoff /* Adjust masks below when adding flags. */
9353b3a8eb9SGleb Smirnoff #define PFR_TFLAG_USRMASK	(PFR_TFLAG_PERSIST	| \
9363b3a8eb9SGleb Smirnoff 				 PFR_TFLAG_CONST	| \
9373b3a8eb9SGleb Smirnoff 				 PFR_TFLAG_COUNTERS)
9383b3a8eb9SGleb Smirnoff #define PFR_TFLAG_SETMASK	(PFR_TFLAG_ACTIVE	| \
9393b3a8eb9SGleb Smirnoff 				 PFR_TFLAG_INACTIVE	| \
9403b3a8eb9SGleb Smirnoff 				 PFR_TFLAG_REFERENCED	| \
9413b3a8eb9SGleb Smirnoff 				 PFR_TFLAG_REFDANCHOR)
9423b3a8eb9SGleb Smirnoff #define PFR_TFLAG_ALLMASK	(PFR_TFLAG_PERSIST	| \
9433b3a8eb9SGleb Smirnoff 				 PFR_TFLAG_CONST	| \
9443b3a8eb9SGleb Smirnoff 				 PFR_TFLAG_ACTIVE	| \
9453b3a8eb9SGleb Smirnoff 				 PFR_TFLAG_INACTIVE	| \
9463b3a8eb9SGleb Smirnoff 				 PFR_TFLAG_REFERENCED	| \
9473b3a8eb9SGleb Smirnoff 				 PFR_TFLAG_REFDANCHOR	| \
9483b3a8eb9SGleb Smirnoff 				 PFR_TFLAG_COUNTERS)
9493b3a8eb9SGleb Smirnoff 
9501d6139c0SGleb Smirnoff struct pf_anchor_stackframe;
9511d6139c0SGleb Smirnoff 
9523b3a8eb9SGleb Smirnoff struct pfr_table {
9533b3a8eb9SGleb Smirnoff 	char			 pfrt_anchor[MAXPATHLEN];
9543b3a8eb9SGleb Smirnoff 	char			 pfrt_name[PF_TABLE_NAME_SIZE];
9553b3a8eb9SGleb Smirnoff 	u_int32_t		 pfrt_flags;
9563b3a8eb9SGleb Smirnoff 	u_int8_t		 pfrt_fback;
9573b3a8eb9SGleb Smirnoff };
9583b3a8eb9SGleb Smirnoff 
9593b3a8eb9SGleb Smirnoff enum { PFR_FB_NONE, PFR_FB_MATCH, PFR_FB_ADDED, PFR_FB_DELETED,
9603b3a8eb9SGleb Smirnoff 	PFR_FB_CHANGED, PFR_FB_CLEARED, PFR_FB_DUPLICATE,
9613b3a8eb9SGleb Smirnoff 	PFR_FB_NOTMATCH, PFR_FB_CONFLICT, PFR_FB_NOCOUNT, PFR_FB_MAX };
9623b3a8eb9SGleb Smirnoff 
9633b3a8eb9SGleb Smirnoff struct pfr_addr {
9643b3a8eb9SGleb Smirnoff 	union {
9653b3a8eb9SGleb Smirnoff 		struct in_addr	 _pfra_ip4addr;
9663b3a8eb9SGleb Smirnoff 		struct in6_addr	 _pfra_ip6addr;
9673b3a8eb9SGleb Smirnoff 	}		 pfra_u;
9683b3a8eb9SGleb Smirnoff 	u_int8_t	 pfra_af;
9693b3a8eb9SGleb Smirnoff 	u_int8_t	 pfra_net;
9703b3a8eb9SGleb Smirnoff 	u_int8_t	 pfra_not;
9713b3a8eb9SGleb Smirnoff 	u_int8_t	 pfra_fback;
9723b3a8eb9SGleb Smirnoff };
9733b3a8eb9SGleb Smirnoff #define	pfra_ip4addr	pfra_u._pfra_ip4addr
9743b3a8eb9SGleb Smirnoff #define	pfra_ip6addr	pfra_u._pfra_ip6addr
9753b3a8eb9SGleb Smirnoff 
9763b3a8eb9SGleb Smirnoff enum { PFR_DIR_IN, PFR_DIR_OUT, PFR_DIR_MAX };
9773b3a8eb9SGleb Smirnoff enum { PFR_OP_BLOCK, PFR_OP_PASS, PFR_OP_ADDR_MAX, PFR_OP_TABLE_MAX };
9783b3a8eb9SGleb Smirnoff #define PFR_OP_XPASS	PFR_OP_ADDR_MAX
9793b3a8eb9SGleb Smirnoff 
9803b3a8eb9SGleb Smirnoff struct pfr_astats {
9813b3a8eb9SGleb Smirnoff 	struct pfr_addr	 pfras_a;
9823b3a8eb9SGleb Smirnoff 	u_int64_t	 pfras_packets[PFR_DIR_MAX][PFR_OP_ADDR_MAX];
9833b3a8eb9SGleb Smirnoff 	u_int64_t	 pfras_bytes[PFR_DIR_MAX][PFR_OP_ADDR_MAX];
9843b3a8eb9SGleb Smirnoff 	long		 pfras_tzero;
9853b3a8eb9SGleb Smirnoff };
9863b3a8eb9SGleb Smirnoff 
9873b3a8eb9SGleb Smirnoff enum { PFR_REFCNT_RULE, PFR_REFCNT_ANCHOR, PFR_REFCNT_MAX };
9883b3a8eb9SGleb Smirnoff 
9893b3a8eb9SGleb Smirnoff struct pfr_tstats {
9903b3a8eb9SGleb Smirnoff 	struct pfr_table pfrts_t;
9913b3a8eb9SGleb Smirnoff 	u_int64_t	 pfrts_packets[PFR_DIR_MAX][PFR_OP_TABLE_MAX];
9923b3a8eb9SGleb Smirnoff 	u_int64_t	 pfrts_bytes[PFR_DIR_MAX][PFR_OP_TABLE_MAX];
9933b3a8eb9SGleb Smirnoff 	u_int64_t	 pfrts_match;
9943b3a8eb9SGleb Smirnoff 	u_int64_t	 pfrts_nomatch;
9953b3a8eb9SGleb Smirnoff 	long		 pfrts_tzero;
9963b3a8eb9SGleb Smirnoff 	int		 pfrts_cnt;
9973b3a8eb9SGleb Smirnoff 	int		 pfrts_refcnt[PFR_REFCNT_MAX];
9983b3a8eb9SGleb Smirnoff };
9993b3a8eb9SGleb Smirnoff #define	pfrts_name	pfrts_t.pfrt_name
10003b3a8eb9SGleb Smirnoff #define pfrts_flags	pfrts_t.pfrt_flags
10013b3a8eb9SGleb Smirnoff 
10023b3a8eb9SGleb Smirnoff #ifndef _SOCKADDR_UNION_DEFINED
10033b3a8eb9SGleb Smirnoff #define	_SOCKADDR_UNION_DEFINED
10043b3a8eb9SGleb Smirnoff union sockaddr_union {
10053b3a8eb9SGleb Smirnoff 	struct sockaddr		sa;
10063b3a8eb9SGleb Smirnoff 	struct sockaddr_in	sin;
10073b3a8eb9SGleb Smirnoff 	struct sockaddr_in6	sin6;
10083b3a8eb9SGleb Smirnoff };
10093b3a8eb9SGleb Smirnoff #endif /* _SOCKADDR_UNION_DEFINED */
10103b3a8eb9SGleb Smirnoff 
10113b3a8eb9SGleb Smirnoff struct pfr_kcounters {
10123b3a8eb9SGleb Smirnoff 	u_int64_t		 pfrkc_packets[PFR_DIR_MAX][PFR_OP_ADDR_MAX];
10133b3a8eb9SGleb Smirnoff 	u_int64_t		 pfrkc_bytes[PFR_DIR_MAX][PFR_OP_ADDR_MAX];
10143b3a8eb9SGleb Smirnoff };
10153b3a8eb9SGleb Smirnoff 
10163b3a8eb9SGleb Smirnoff SLIST_HEAD(pfr_kentryworkq, pfr_kentry);
10173b3a8eb9SGleb Smirnoff struct pfr_kentry {
10183b3a8eb9SGleb Smirnoff 	struct radix_node	 pfrke_node[2];
10193b3a8eb9SGleb Smirnoff 	union sockaddr_union	 pfrke_sa;
10203b3a8eb9SGleb Smirnoff 	SLIST_ENTRY(pfr_kentry)	 pfrke_workq;
10213b3a8eb9SGleb Smirnoff 	struct pfr_kcounters	*pfrke_counters;
10223b3a8eb9SGleb Smirnoff 	long			 pfrke_tzero;
10233b3a8eb9SGleb Smirnoff 	u_int8_t		 pfrke_af;
10243b3a8eb9SGleb Smirnoff 	u_int8_t		 pfrke_net;
10253b3a8eb9SGleb Smirnoff 	u_int8_t		 pfrke_not;
10263b3a8eb9SGleb Smirnoff 	u_int8_t		 pfrke_mark;
10273b3a8eb9SGleb Smirnoff };
10283b3a8eb9SGleb Smirnoff 
10293b3a8eb9SGleb Smirnoff SLIST_HEAD(pfr_ktableworkq, pfr_ktable);
10303b3a8eb9SGleb Smirnoff RB_HEAD(pfr_ktablehead, pfr_ktable);
10313b3a8eb9SGleb Smirnoff struct pfr_ktable {
10323b3a8eb9SGleb Smirnoff 	struct pfr_tstats	 pfrkt_ts;
10333b3a8eb9SGleb Smirnoff 	RB_ENTRY(pfr_ktable)	 pfrkt_tree;
10343b3a8eb9SGleb Smirnoff 	SLIST_ENTRY(pfr_ktable)	 pfrkt_workq;
10353b3a8eb9SGleb Smirnoff 	struct radix_node_head	*pfrkt_ip4;
10363b3a8eb9SGleb Smirnoff 	struct radix_node_head	*pfrkt_ip6;
10373b3a8eb9SGleb Smirnoff 	struct pfr_ktable	*pfrkt_shadow;
10383b3a8eb9SGleb Smirnoff 	struct pfr_ktable	*pfrkt_root;
10393b3a8eb9SGleb Smirnoff 	struct pf_ruleset	*pfrkt_rs;
10403b3a8eb9SGleb Smirnoff 	long			 pfrkt_larg;
10413b3a8eb9SGleb Smirnoff 	int			 pfrkt_nflags;
10423b3a8eb9SGleb Smirnoff };
10433b3a8eb9SGleb Smirnoff #define pfrkt_t		pfrkt_ts.pfrts_t
10443b3a8eb9SGleb Smirnoff #define pfrkt_name	pfrkt_t.pfrt_name
10453b3a8eb9SGleb Smirnoff #define pfrkt_anchor	pfrkt_t.pfrt_anchor
10463b3a8eb9SGleb Smirnoff #define pfrkt_ruleset	pfrkt_t.pfrt_ruleset
10473b3a8eb9SGleb Smirnoff #define pfrkt_flags	pfrkt_t.pfrt_flags
10483b3a8eb9SGleb Smirnoff #define pfrkt_cnt	pfrkt_ts.pfrts_cnt
10493b3a8eb9SGleb Smirnoff #define pfrkt_refcnt	pfrkt_ts.pfrts_refcnt
10503b3a8eb9SGleb Smirnoff #define pfrkt_packets	pfrkt_ts.pfrts_packets
10513b3a8eb9SGleb Smirnoff #define pfrkt_bytes	pfrkt_ts.pfrts_bytes
10523b3a8eb9SGleb Smirnoff #define pfrkt_match	pfrkt_ts.pfrts_match
10533b3a8eb9SGleb Smirnoff #define pfrkt_nomatch	pfrkt_ts.pfrts_nomatch
10543b3a8eb9SGleb Smirnoff #define pfrkt_tzero	pfrkt_ts.pfrts_tzero
10553b3a8eb9SGleb Smirnoff 
10563b3a8eb9SGleb Smirnoff /* keep synced with pfi_kif, used in RB_FIND */
10573b3a8eb9SGleb Smirnoff struct pfi_kif_cmp {
10583b3a8eb9SGleb Smirnoff 	char				 pfik_name[IFNAMSIZ];
10593b3a8eb9SGleb Smirnoff };
10603b3a8eb9SGleb Smirnoff 
10613b3a8eb9SGleb Smirnoff struct pfi_kif {
10623b3a8eb9SGleb Smirnoff 	char				 pfik_name[IFNAMSIZ];
10633b3a8eb9SGleb Smirnoff 	union {
10643b3a8eb9SGleb Smirnoff 		RB_ENTRY(pfi_kif)	 _pfik_tree;
10653b3a8eb9SGleb Smirnoff 		LIST_ENTRY(pfi_kif)	 _pfik_list;
10663b3a8eb9SGleb Smirnoff 	} _pfik_glue;
10673b3a8eb9SGleb Smirnoff #define	pfik_tree	_pfik_glue._pfik_tree
10683b3a8eb9SGleb Smirnoff #define	pfik_list	_pfik_glue._pfik_list
10693b3a8eb9SGleb Smirnoff 	u_int64_t			 pfik_packets[2][2][2];
10703b3a8eb9SGleb Smirnoff 	u_int64_t			 pfik_bytes[2][2][2];
10713b3a8eb9SGleb Smirnoff 	u_int32_t			 pfik_tzero;
10723b3a8eb9SGleb Smirnoff 	u_int				 pfik_flags;
10733b3a8eb9SGleb Smirnoff 	struct ifnet			*pfik_ifp;
10743b3a8eb9SGleb Smirnoff 	struct ifg_group		*pfik_group;
10753b3a8eb9SGleb Smirnoff 	u_int				 pfik_rulerefs;
10763b3a8eb9SGleb Smirnoff 	TAILQ_HEAD(, pfi_dynaddr)	 pfik_dynaddrs;
10773b3a8eb9SGleb Smirnoff };
10783b3a8eb9SGleb Smirnoff 
10793b3a8eb9SGleb Smirnoff #define	PFI_IFLAG_REFS		0x0001	/* has state references */
10803b3a8eb9SGleb Smirnoff #define PFI_IFLAG_SKIP		0x0100	/* skip filtering on interface */
10813b3a8eb9SGleb Smirnoff 
10823b3a8eb9SGleb Smirnoff struct pf_pdesc {
10833b3a8eb9SGleb Smirnoff 	struct {
10843b3a8eb9SGleb Smirnoff 		int	 done;
10853b3a8eb9SGleb Smirnoff 		uid_t	 uid;
10863b3a8eb9SGleb Smirnoff 		gid_t	 gid;
10873b3a8eb9SGleb Smirnoff 	}		 lookup;
10883b3a8eb9SGleb Smirnoff 	u_int64_t	 tot_len;	/* Make Mickey money */
10893b3a8eb9SGleb Smirnoff 	union {
10903b3a8eb9SGleb Smirnoff 		struct tcphdr		*tcp;
10913b3a8eb9SGleb Smirnoff 		struct udphdr		*udp;
10923b3a8eb9SGleb Smirnoff 		struct icmp		*icmp;
10933b3a8eb9SGleb Smirnoff #ifdef INET6
10943b3a8eb9SGleb Smirnoff 		struct icmp6_hdr	*icmp6;
10953b3a8eb9SGleb Smirnoff #endif /* INET6 */
10963b3a8eb9SGleb Smirnoff 		void			*any;
10973b3a8eb9SGleb Smirnoff 	} hdr;
10983b3a8eb9SGleb Smirnoff 
10993b3a8eb9SGleb Smirnoff 	struct pf_rule	*nat_rule;	/* nat/rdr rule applied to packet */
11003b3a8eb9SGleb Smirnoff 	struct pf_addr	*src;		/* src address */
11013b3a8eb9SGleb Smirnoff 	struct pf_addr	*dst;		/* dst address */
11023b3a8eb9SGleb Smirnoff 	u_int16_t *sport;
11033b3a8eb9SGleb Smirnoff 	u_int16_t *dport;
11043b3a8eb9SGleb Smirnoff 	struct pf_mtag	*pf_mtag;
11053b3a8eb9SGleb Smirnoff 
11063b3a8eb9SGleb Smirnoff 	u_int32_t	 p_len;		/* total length of payload */
11073b3a8eb9SGleb Smirnoff 
11083b3a8eb9SGleb Smirnoff 	u_int16_t	*ip_sum;
11093b3a8eb9SGleb Smirnoff 	u_int16_t	*proto_sum;
11103b3a8eb9SGleb Smirnoff 	u_int16_t	 flags;		/* Let SCRUB trigger behavior in
11113b3a8eb9SGleb Smirnoff 					 * state code. Easier than tags */
11123b3a8eb9SGleb Smirnoff #define PFDESC_TCP_NORM	0x0001		/* TCP shall be statefully scrubbed */
11133b3a8eb9SGleb Smirnoff #define PFDESC_IP_REAS	0x0002		/* IP frags would've been reassembled */
11143b3a8eb9SGleb Smirnoff 	sa_family_t	 af;
11153b3a8eb9SGleb Smirnoff 	u_int8_t	 proto;
11163b3a8eb9SGleb Smirnoff 	u_int8_t	 tos;
11173b3a8eb9SGleb Smirnoff 	u_int8_t	 dir;		/* direction */
11183b3a8eb9SGleb Smirnoff 	u_int8_t	 sidx;		/* key index for source */
11193b3a8eb9SGleb Smirnoff 	u_int8_t	 didx;		/* key index for destination */
11203b3a8eb9SGleb Smirnoff };
11213b3a8eb9SGleb Smirnoff 
11223b3a8eb9SGleb Smirnoff /* flags for RDR options */
11233b3a8eb9SGleb Smirnoff #define PF_DPORT_RANGE	0x01		/* Dest port uses range */
11243b3a8eb9SGleb Smirnoff #define PF_RPORT_RANGE	0x02		/* RDR'ed port uses range */
11253b3a8eb9SGleb Smirnoff 
11263b3a8eb9SGleb Smirnoff /* UDP state enumeration */
11273b3a8eb9SGleb Smirnoff #define PFUDPS_NO_TRAFFIC	0
11283b3a8eb9SGleb Smirnoff #define PFUDPS_SINGLE		1
11293b3a8eb9SGleb Smirnoff #define PFUDPS_MULTIPLE		2
11303b3a8eb9SGleb Smirnoff 
11313b3a8eb9SGleb Smirnoff #define PFUDPS_NSTATES		3	/* number of state levels */
11323b3a8eb9SGleb Smirnoff 
11333b3a8eb9SGleb Smirnoff #define PFUDPS_NAMES { \
11343b3a8eb9SGleb Smirnoff 	"NO_TRAFFIC", \
11353b3a8eb9SGleb Smirnoff 	"SINGLE", \
11363b3a8eb9SGleb Smirnoff 	"MULTIPLE", \
11373b3a8eb9SGleb Smirnoff 	NULL \
11383b3a8eb9SGleb Smirnoff }
11393b3a8eb9SGleb Smirnoff 
11403b3a8eb9SGleb Smirnoff /* Other protocol state enumeration */
11413b3a8eb9SGleb Smirnoff #define PFOTHERS_NO_TRAFFIC	0
11423b3a8eb9SGleb Smirnoff #define PFOTHERS_SINGLE		1
11433b3a8eb9SGleb Smirnoff #define PFOTHERS_MULTIPLE	2
11443b3a8eb9SGleb Smirnoff 
11453b3a8eb9SGleb Smirnoff #define PFOTHERS_NSTATES	3	/* number of state levels */
11463b3a8eb9SGleb Smirnoff 
11473b3a8eb9SGleb Smirnoff #define PFOTHERS_NAMES { \
11483b3a8eb9SGleb Smirnoff 	"NO_TRAFFIC", \
11493b3a8eb9SGleb Smirnoff 	"SINGLE", \
11503b3a8eb9SGleb Smirnoff 	"MULTIPLE", \
11513b3a8eb9SGleb Smirnoff 	NULL \
11523b3a8eb9SGleb Smirnoff }
11533b3a8eb9SGleb Smirnoff 
11543b3a8eb9SGleb Smirnoff #define ACTION_SET(a, x) \
11553b3a8eb9SGleb Smirnoff 	do { \
11563b3a8eb9SGleb Smirnoff 		if ((a) != NULL) \
11573b3a8eb9SGleb Smirnoff 			*(a) = (x); \
11583b3a8eb9SGleb Smirnoff 	} while (0)
11593b3a8eb9SGleb Smirnoff 
11603b3a8eb9SGleb Smirnoff #define REASON_SET(a, x) \
11613b3a8eb9SGleb Smirnoff 	do { \
11623b3a8eb9SGleb Smirnoff 		if ((a) != NULL) \
11633b3a8eb9SGleb Smirnoff 			*(a) = (x); \
11643b3a8eb9SGleb Smirnoff 		if (x < PFRES_MAX) \
1165a9572d8fSGleb Smirnoff 			counter_u64_add(V_pf_status.counters[x], 1); \
11663b3a8eb9SGleb Smirnoff 	} while (0)
11673b3a8eb9SGleb Smirnoff 
1168a9572d8fSGleb Smirnoff struct pf_kstatus {
1169a9572d8fSGleb Smirnoff 	counter_u64_t	counters[PFRES_MAX]; /* reason for passing/dropping */
1170a9572d8fSGleb Smirnoff 	counter_u64_t	lcounters[LCNT_MAX]; /* limit counters */
1171a9572d8fSGleb Smirnoff 	counter_u64_t	fcounters[FCNT_MAX]; /* state operation counters */
1172a9572d8fSGleb Smirnoff 	counter_u64_t	scounters[SCNT_MAX]; /* src_node operation counters */
1173a9572d8fSGleb Smirnoff 	uint32_t	states;
1174a9572d8fSGleb Smirnoff 	uint32_t	src_nodes;
1175a9572d8fSGleb Smirnoff 	uint32_t	running;
1176a9572d8fSGleb Smirnoff 	uint32_t	since;
1177a9572d8fSGleb Smirnoff 	uint32_t	debug;
1178a9572d8fSGleb Smirnoff 	uint32_t	hostid;
11793b3a8eb9SGleb Smirnoff 	char		ifname[IFNAMSIZ];
1180a9572d8fSGleb Smirnoff 	uint8_t		pf_chksum[PF_MD5_DIGEST_LENGTH];
11813b3a8eb9SGleb Smirnoff };
11823b3a8eb9SGleb Smirnoff 
11833b3a8eb9SGleb Smirnoff struct pf_divert {
11843b3a8eb9SGleb Smirnoff 	union {
11853b3a8eb9SGleb Smirnoff 		struct in_addr	ipv4;
11863b3a8eb9SGleb Smirnoff 		struct in6_addr	ipv6;
11873b3a8eb9SGleb Smirnoff 	}		addr;
11883b3a8eb9SGleb Smirnoff 	u_int16_t	port;
11893b3a8eb9SGleb Smirnoff };
11903b3a8eb9SGleb Smirnoff 
11913b3a8eb9SGleb Smirnoff #define PFFRAG_FRENT_HIWAT	5000	/* Number of fragment entries */
11923b3a8eb9SGleb Smirnoff #define PFR_KENTRY_HIWAT	200000	/* Number of table entries */
11933b3a8eb9SGleb Smirnoff 
11943b3a8eb9SGleb Smirnoff /*
11953b3a8eb9SGleb Smirnoff  * ioctl parameter structures
11963b3a8eb9SGleb Smirnoff  */
11973b3a8eb9SGleb Smirnoff 
11983b3a8eb9SGleb Smirnoff struct pfioc_pooladdr {
11993b3a8eb9SGleb Smirnoff 	u_int32_t		 action;
12003b3a8eb9SGleb Smirnoff 	u_int32_t		 ticket;
12013b3a8eb9SGleb Smirnoff 	u_int32_t		 nr;
12023b3a8eb9SGleb Smirnoff 	u_int32_t		 r_num;
12033b3a8eb9SGleb Smirnoff 	u_int8_t		 r_action;
12043b3a8eb9SGleb Smirnoff 	u_int8_t		 r_last;
12053b3a8eb9SGleb Smirnoff 	u_int8_t		 af;
12063b3a8eb9SGleb Smirnoff 	char			 anchor[MAXPATHLEN];
12073b3a8eb9SGleb Smirnoff 	struct pf_pooladdr	 addr;
12083b3a8eb9SGleb Smirnoff };
12093b3a8eb9SGleb Smirnoff 
12103b3a8eb9SGleb Smirnoff struct pfioc_rule {
12113b3a8eb9SGleb Smirnoff 	u_int32_t	 action;
12123b3a8eb9SGleb Smirnoff 	u_int32_t	 ticket;
12133b3a8eb9SGleb Smirnoff 	u_int32_t	 pool_ticket;
12143b3a8eb9SGleb Smirnoff 	u_int32_t	 nr;
12153b3a8eb9SGleb Smirnoff 	char		 anchor[MAXPATHLEN];
12163b3a8eb9SGleb Smirnoff 	char		 anchor_call[MAXPATHLEN];
12173b3a8eb9SGleb Smirnoff 	struct pf_rule	 rule;
12183b3a8eb9SGleb Smirnoff };
12193b3a8eb9SGleb Smirnoff 
12203b3a8eb9SGleb Smirnoff struct pfioc_natlook {
12213b3a8eb9SGleb Smirnoff 	struct pf_addr	 saddr;
12223b3a8eb9SGleb Smirnoff 	struct pf_addr	 daddr;
12233b3a8eb9SGleb Smirnoff 	struct pf_addr	 rsaddr;
12243b3a8eb9SGleb Smirnoff 	struct pf_addr	 rdaddr;
12253b3a8eb9SGleb Smirnoff 	u_int16_t	 sport;
12263b3a8eb9SGleb Smirnoff 	u_int16_t	 dport;
12273b3a8eb9SGleb Smirnoff 	u_int16_t	 rsport;
12283b3a8eb9SGleb Smirnoff 	u_int16_t	 rdport;
12293b3a8eb9SGleb Smirnoff 	sa_family_t	 af;
12303b3a8eb9SGleb Smirnoff 	u_int8_t	 proto;
12313b3a8eb9SGleb Smirnoff 	u_int8_t	 direction;
12323b3a8eb9SGleb Smirnoff };
12333b3a8eb9SGleb Smirnoff 
12343b3a8eb9SGleb Smirnoff struct pfioc_state {
12353b3a8eb9SGleb Smirnoff 	struct pfsync_state	state;
12363b3a8eb9SGleb Smirnoff };
12373b3a8eb9SGleb Smirnoff 
12383b3a8eb9SGleb Smirnoff struct pfioc_src_node_kill {
12393b3a8eb9SGleb Smirnoff 	sa_family_t psnk_af;
12403b3a8eb9SGleb Smirnoff 	struct pf_rule_addr psnk_src;
12413b3a8eb9SGleb Smirnoff 	struct pf_rule_addr psnk_dst;
12423b3a8eb9SGleb Smirnoff 	u_int		    psnk_killed;
12433b3a8eb9SGleb Smirnoff };
12443b3a8eb9SGleb Smirnoff 
12453b3a8eb9SGleb Smirnoff struct pfioc_state_kill {
12463b3a8eb9SGleb Smirnoff 	struct pf_state_cmp	psk_pfcmp;
12473b3a8eb9SGleb Smirnoff 	sa_family_t		psk_af;
12483b3a8eb9SGleb Smirnoff 	int			psk_proto;
12493b3a8eb9SGleb Smirnoff 	struct pf_rule_addr	psk_src;
12503b3a8eb9SGleb Smirnoff 	struct pf_rule_addr	psk_dst;
12513b3a8eb9SGleb Smirnoff 	char			psk_ifname[IFNAMSIZ];
12523b3a8eb9SGleb Smirnoff 	char			psk_label[PF_RULE_LABEL_SIZE];
12533b3a8eb9SGleb Smirnoff 	u_int			psk_killed;
12543b3a8eb9SGleb Smirnoff };
12553b3a8eb9SGleb Smirnoff 
12563b3a8eb9SGleb Smirnoff struct pfioc_states {
12573b3a8eb9SGleb Smirnoff 	int	ps_len;
12583b3a8eb9SGleb Smirnoff 	union {
12593b3a8eb9SGleb Smirnoff 		caddr_t			 psu_buf;
12603b3a8eb9SGleb Smirnoff 		struct pfsync_state	*psu_states;
12613b3a8eb9SGleb Smirnoff 	} ps_u;
12623b3a8eb9SGleb Smirnoff #define ps_buf		ps_u.psu_buf
12633b3a8eb9SGleb Smirnoff #define ps_states	ps_u.psu_states
12643b3a8eb9SGleb Smirnoff };
12653b3a8eb9SGleb Smirnoff 
12663b3a8eb9SGleb Smirnoff struct pfioc_src_nodes {
12673b3a8eb9SGleb Smirnoff 	int	psn_len;
12683b3a8eb9SGleb Smirnoff 	union {
12693b3a8eb9SGleb Smirnoff 		caddr_t		 psu_buf;
12703b3a8eb9SGleb Smirnoff 		struct pf_src_node	*psu_src_nodes;
12713b3a8eb9SGleb Smirnoff 	} psn_u;
12723b3a8eb9SGleb Smirnoff #define psn_buf		psn_u.psu_buf
12733b3a8eb9SGleb Smirnoff #define psn_src_nodes	psn_u.psu_src_nodes
12743b3a8eb9SGleb Smirnoff };
12753b3a8eb9SGleb Smirnoff 
12763b3a8eb9SGleb Smirnoff struct pfioc_if {
12773b3a8eb9SGleb Smirnoff 	char		 ifname[IFNAMSIZ];
12783b3a8eb9SGleb Smirnoff };
12793b3a8eb9SGleb Smirnoff 
12803b3a8eb9SGleb Smirnoff struct pfioc_tm {
12813b3a8eb9SGleb Smirnoff 	int		 timeout;
12823b3a8eb9SGleb Smirnoff 	int		 seconds;
12833b3a8eb9SGleb Smirnoff };
12843b3a8eb9SGleb Smirnoff 
12853b3a8eb9SGleb Smirnoff struct pfioc_limit {
12863b3a8eb9SGleb Smirnoff 	int		 index;
12873b3a8eb9SGleb Smirnoff 	unsigned	 limit;
12883b3a8eb9SGleb Smirnoff };
12893b3a8eb9SGleb Smirnoff 
12903b3a8eb9SGleb Smirnoff struct pfioc_altq {
12913b3a8eb9SGleb Smirnoff 	u_int32_t	 action;
12923b3a8eb9SGleb Smirnoff 	u_int32_t	 ticket;
12933b3a8eb9SGleb Smirnoff 	u_int32_t	 nr;
12943b3a8eb9SGleb Smirnoff 	struct pf_altq	 altq;
12953b3a8eb9SGleb Smirnoff };
12963b3a8eb9SGleb Smirnoff 
12973b3a8eb9SGleb Smirnoff struct pfioc_qstats {
12983b3a8eb9SGleb Smirnoff 	u_int32_t	 ticket;
12993b3a8eb9SGleb Smirnoff 	u_int32_t	 nr;
13003b3a8eb9SGleb Smirnoff 	void		*buf;
13013b3a8eb9SGleb Smirnoff 	int		 nbytes;
13023b3a8eb9SGleb Smirnoff 	u_int8_t	 scheduler;
13033b3a8eb9SGleb Smirnoff };
13043b3a8eb9SGleb Smirnoff 
13053b3a8eb9SGleb Smirnoff struct pfioc_ruleset {
13063b3a8eb9SGleb Smirnoff 	u_int32_t	 nr;
13073b3a8eb9SGleb Smirnoff 	char		 path[MAXPATHLEN];
13083b3a8eb9SGleb Smirnoff 	char		 name[PF_ANCHOR_NAME_SIZE];
13093b3a8eb9SGleb Smirnoff };
13103b3a8eb9SGleb Smirnoff 
13113b3a8eb9SGleb Smirnoff #define PF_RULESET_ALTQ		(PF_RULESET_MAX)
13123b3a8eb9SGleb Smirnoff #define PF_RULESET_TABLE	(PF_RULESET_MAX+1)
13133b3a8eb9SGleb Smirnoff struct pfioc_trans {
13143b3a8eb9SGleb Smirnoff 	int		 size;	/* number of elements */
13153b3a8eb9SGleb Smirnoff 	int		 esize; /* size of each element in bytes */
13163b3a8eb9SGleb Smirnoff 	struct pfioc_trans_e {
13173b3a8eb9SGleb Smirnoff 		int		rs_num;
13183b3a8eb9SGleb Smirnoff 		char		anchor[MAXPATHLEN];
13193b3a8eb9SGleb Smirnoff 		u_int32_t	ticket;
13203b3a8eb9SGleb Smirnoff 	}		*array;
13213b3a8eb9SGleb Smirnoff };
13223b3a8eb9SGleb Smirnoff 
13233b3a8eb9SGleb Smirnoff #define PFR_FLAG_ATOMIC		0x00000001	/* unused */
13243b3a8eb9SGleb Smirnoff #define PFR_FLAG_DUMMY		0x00000002
13253b3a8eb9SGleb Smirnoff #define PFR_FLAG_FEEDBACK	0x00000004
13263b3a8eb9SGleb Smirnoff #define PFR_FLAG_CLSTATS	0x00000008
13273b3a8eb9SGleb Smirnoff #define PFR_FLAG_ADDRSTOO	0x00000010
13283b3a8eb9SGleb Smirnoff #define PFR_FLAG_REPLACE	0x00000020
13293b3a8eb9SGleb Smirnoff #define PFR_FLAG_ALLRSETS	0x00000040
13303b3a8eb9SGleb Smirnoff #define PFR_FLAG_ALLMASK	0x0000007F
13313b3a8eb9SGleb Smirnoff #ifdef _KERNEL
13323b3a8eb9SGleb Smirnoff #define PFR_FLAG_USERIOCTL	0x10000000
13333b3a8eb9SGleb Smirnoff #endif
13343b3a8eb9SGleb Smirnoff 
13353b3a8eb9SGleb Smirnoff struct pfioc_table {
13363b3a8eb9SGleb Smirnoff 	struct pfr_table	 pfrio_table;
13373b3a8eb9SGleb Smirnoff 	void			*pfrio_buffer;
13383b3a8eb9SGleb Smirnoff 	int			 pfrio_esize;
13393b3a8eb9SGleb Smirnoff 	int			 pfrio_size;
13403b3a8eb9SGleb Smirnoff 	int			 pfrio_size2;
13413b3a8eb9SGleb Smirnoff 	int			 pfrio_nadd;
13423b3a8eb9SGleb Smirnoff 	int			 pfrio_ndel;
13433b3a8eb9SGleb Smirnoff 	int			 pfrio_nchange;
13443b3a8eb9SGleb Smirnoff 	int			 pfrio_flags;
13453b3a8eb9SGleb Smirnoff 	u_int32_t		 pfrio_ticket;
13463b3a8eb9SGleb Smirnoff };
13473b3a8eb9SGleb Smirnoff #define	pfrio_exists	pfrio_nadd
13483b3a8eb9SGleb Smirnoff #define	pfrio_nzero	pfrio_nadd
13493b3a8eb9SGleb Smirnoff #define	pfrio_nmatch	pfrio_nadd
13503b3a8eb9SGleb Smirnoff #define pfrio_naddr	pfrio_size2
13513b3a8eb9SGleb Smirnoff #define pfrio_setflag	pfrio_size2
13523b3a8eb9SGleb Smirnoff #define pfrio_clrflag	pfrio_nadd
13533b3a8eb9SGleb Smirnoff 
13543b3a8eb9SGleb Smirnoff struct pfioc_iface {
13553b3a8eb9SGleb Smirnoff 	char	 pfiio_name[IFNAMSIZ];
13563b3a8eb9SGleb Smirnoff 	void	*pfiio_buffer;
13573b3a8eb9SGleb Smirnoff 	int	 pfiio_esize;
13583b3a8eb9SGleb Smirnoff 	int	 pfiio_size;
13593b3a8eb9SGleb Smirnoff 	int	 pfiio_nzero;
13603b3a8eb9SGleb Smirnoff 	int	 pfiio_flags;
13613b3a8eb9SGleb Smirnoff };
13623b3a8eb9SGleb Smirnoff 
13633b3a8eb9SGleb Smirnoff 
13643b3a8eb9SGleb Smirnoff /*
13653b3a8eb9SGleb Smirnoff  * ioctl operations
13663b3a8eb9SGleb Smirnoff  */
13673b3a8eb9SGleb Smirnoff 
13683b3a8eb9SGleb Smirnoff #define DIOCSTART	_IO  ('D',  1)
13693b3a8eb9SGleb Smirnoff #define DIOCSTOP	_IO  ('D',  2)
13703b3a8eb9SGleb Smirnoff #define DIOCADDRULE	_IOWR('D',  4, struct pfioc_rule)
13713b3a8eb9SGleb Smirnoff #define DIOCGETRULES	_IOWR('D',  6, struct pfioc_rule)
13723b3a8eb9SGleb Smirnoff #define DIOCGETRULE	_IOWR('D',  7, struct pfioc_rule)
13733b3a8eb9SGleb Smirnoff /* XXX cut 8 - 17 */
13743b3a8eb9SGleb Smirnoff #define DIOCCLRSTATES	_IOWR('D', 18, struct pfioc_state_kill)
13753b3a8eb9SGleb Smirnoff #define DIOCGETSTATE	_IOWR('D', 19, struct pfioc_state)
13763b3a8eb9SGleb Smirnoff #define DIOCSETSTATUSIF _IOWR('D', 20, struct pfioc_if)
13773b3a8eb9SGleb Smirnoff #define DIOCGETSTATUS	_IOWR('D', 21, struct pf_status)
13783b3a8eb9SGleb Smirnoff #define DIOCCLRSTATUS	_IO  ('D', 22)
13793b3a8eb9SGleb Smirnoff #define DIOCNATLOOK	_IOWR('D', 23, struct pfioc_natlook)
13803b3a8eb9SGleb Smirnoff #define DIOCSETDEBUG	_IOWR('D', 24, u_int32_t)
13813b3a8eb9SGleb Smirnoff #define DIOCGETSTATES	_IOWR('D', 25, struct pfioc_states)
13823b3a8eb9SGleb Smirnoff #define DIOCCHANGERULE	_IOWR('D', 26, struct pfioc_rule)
13833b3a8eb9SGleb Smirnoff /* XXX cut 26 - 28 */
13843b3a8eb9SGleb Smirnoff #define DIOCSETTIMEOUT	_IOWR('D', 29, struct pfioc_tm)
13853b3a8eb9SGleb Smirnoff #define DIOCGETTIMEOUT	_IOWR('D', 30, struct pfioc_tm)
13863b3a8eb9SGleb Smirnoff #define DIOCADDSTATE	_IOWR('D', 37, struct pfioc_state)
13873b3a8eb9SGleb Smirnoff #define DIOCCLRRULECTRS	_IO  ('D', 38)
13883b3a8eb9SGleb Smirnoff #define DIOCGETLIMIT	_IOWR('D', 39, struct pfioc_limit)
13893b3a8eb9SGleb Smirnoff #define DIOCSETLIMIT	_IOWR('D', 40, struct pfioc_limit)
13903b3a8eb9SGleb Smirnoff #define DIOCKILLSTATES	_IOWR('D', 41, struct pfioc_state_kill)
13913b3a8eb9SGleb Smirnoff #define DIOCSTARTALTQ	_IO  ('D', 42)
13923b3a8eb9SGleb Smirnoff #define DIOCSTOPALTQ	_IO  ('D', 43)
13933b3a8eb9SGleb Smirnoff #define DIOCADDALTQ	_IOWR('D', 45, struct pfioc_altq)
13943b3a8eb9SGleb Smirnoff #define DIOCGETALTQS	_IOWR('D', 47, struct pfioc_altq)
13953b3a8eb9SGleb Smirnoff #define DIOCGETALTQ	_IOWR('D', 48, struct pfioc_altq)
13963b3a8eb9SGleb Smirnoff #define DIOCCHANGEALTQ	_IOWR('D', 49, struct pfioc_altq)
13973b3a8eb9SGleb Smirnoff #define DIOCGETQSTATS	_IOWR('D', 50, struct pfioc_qstats)
13983b3a8eb9SGleb Smirnoff #define DIOCBEGINADDRS	_IOWR('D', 51, struct pfioc_pooladdr)
13993b3a8eb9SGleb Smirnoff #define DIOCADDADDR	_IOWR('D', 52, struct pfioc_pooladdr)
14003b3a8eb9SGleb Smirnoff #define DIOCGETADDRS	_IOWR('D', 53, struct pfioc_pooladdr)
14013b3a8eb9SGleb Smirnoff #define DIOCGETADDR	_IOWR('D', 54, struct pfioc_pooladdr)
14023b3a8eb9SGleb Smirnoff #define DIOCCHANGEADDR	_IOWR('D', 55, struct pfioc_pooladdr)
14033b3a8eb9SGleb Smirnoff /* XXX cut 55 - 57 */
14043b3a8eb9SGleb Smirnoff #define	DIOCGETRULESETS	_IOWR('D', 58, struct pfioc_ruleset)
14053b3a8eb9SGleb Smirnoff #define	DIOCGETRULESET	_IOWR('D', 59, struct pfioc_ruleset)
14063b3a8eb9SGleb Smirnoff #define	DIOCRCLRTABLES	_IOWR('D', 60, struct pfioc_table)
14073b3a8eb9SGleb Smirnoff #define	DIOCRADDTABLES	_IOWR('D', 61, struct pfioc_table)
14083b3a8eb9SGleb Smirnoff #define	DIOCRDELTABLES	_IOWR('D', 62, struct pfioc_table)
14093b3a8eb9SGleb Smirnoff #define	DIOCRGETTABLES	_IOWR('D', 63, struct pfioc_table)
14103b3a8eb9SGleb Smirnoff #define	DIOCRGETTSTATS	_IOWR('D', 64, struct pfioc_table)
14113b3a8eb9SGleb Smirnoff #define DIOCRCLRTSTATS	_IOWR('D', 65, struct pfioc_table)
14123b3a8eb9SGleb Smirnoff #define	DIOCRCLRADDRS	_IOWR('D', 66, struct pfioc_table)
14133b3a8eb9SGleb Smirnoff #define	DIOCRADDADDRS	_IOWR('D', 67, struct pfioc_table)
14143b3a8eb9SGleb Smirnoff #define	DIOCRDELADDRS	_IOWR('D', 68, struct pfioc_table)
14153b3a8eb9SGleb Smirnoff #define	DIOCRSETADDRS	_IOWR('D', 69, struct pfioc_table)
14163b3a8eb9SGleb Smirnoff #define	DIOCRGETADDRS	_IOWR('D', 70, struct pfioc_table)
14173b3a8eb9SGleb Smirnoff #define	DIOCRGETASTATS	_IOWR('D', 71, struct pfioc_table)
14183b3a8eb9SGleb Smirnoff #define	DIOCRCLRASTATS	_IOWR('D', 72, struct pfioc_table)
14193b3a8eb9SGleb Smirnoff #define	DIOCRTSTADDRS	_IOWR('D', 73, struct pfioc_table)
14203b3a8eb9SGleb Smirnoff #define	DIOCRSETTFLAGS	_IOWR('D', 74, struct pfioc_table)
14213b3a8eb9SGleb Smirnoff #define	DIOCRINADEFINE	_IOWR('D', 77, struct pfioc_table)
14223b3a8eb9SGleb Smirnoff #define	DIOCOSFPFLUSH	_IO('D', 78)
14233b3a8eb9SGleb Smirnoff #define	DIOCOSFPADD	_IOWR('D', 79, struct pf_osfp_ioctl)
14243b3a8eb9SGleb Smirnoff #define	DIOCOSFPGET	_IOWR('D', 80, struct pf_osfp_ioctl)
14253b3a8eb9SGleb Smirnoff #define	DIOCXBEGIN	_IOWR('D', 81, struct pfioc_trans)
14263b3a8eb9SGleb Smirnoff #define	DIOCXCOMMIT	_IOWR('D', 82, struct pfioc_trans)
14273b3a8eb9SGleb Smirnoff #define	DIOCXROLLBACK	_IOWR('D', 83, struct pfioc_trans)
14283b3a8eb9SGleb Smirnoff #define	DIOCGETSRCNODES	_IOWR('D', 84, struct pfioc_src_nodes)
14293b3a8eb9SGleb Smirnoff #define	DIOCCLRSRCNODES	_IO('D', 85)
14303b3a8eb9SGleb Smirnoff #define	DIOCSETHOSTID	_IOWR('D', 86, u_int32_t)
14313b3a8eb9SGleb Smirnoff #define	DIOCIGETIFACES	_IOWR('D', 87, struct pfioc_iface)
14323b3a8eb9SGleb Smirnoff #define	DIOCSETIFFLAG	_IOWR('D', 89, struct pfioc_iface)
14333b3a8eb9SGleb Smirnoff #define	DIOCCLRIFFLAG	_IOWR('D', 90, struct pfioc_iface)
14343b3a8eb9SGleb Smirnoff #define	DIOCKILLSRCNODES	_IOWR('D', 91, struct pfioc_src_node_kill)
14353b3a8eb9SGleb Smirnoff struct pf_ifspeed {
14363b3a8eb9SGleb Smirnoff 	char			ifname[IFNAMSIZ];
14373b3a8eb9SGleb Smirnoff 	u_int32_t		baudrate;
14383b3a8eb9SGleb Smirnoff };
14393b3a8eb9SGleb Smirnoff #define	DIOCGIFSPEED	_IOWR('D', 92, struct pf_ifspeed)
14403b3a8eb9SGleb Smirnoff 
14413b3a8eb9SGleb Smirnoff #ifdef _KERNEL
1442d77c1b32SGleb Smirnoff LIST_HEAD(pf_src_node_list, pf_src_node);
14433b3a8eb9SGleb Smirnoff struct pf_srchash {
1444d77c1b32SGleb Smirnoff 	struct pf_src_node_list		nodes;
14453b3a8eb9SGleb Smirnoff 	struct mtx			lock;
14463b3a8eb9SGleb Smirnoff };
14473b3a8eb9SGleb Smirnoff 
14483b3a8eb9SGleb Smirnoff struct pf_keyhash {
14493b3a8eb9SGleb Smirnoff 	LIST_HEAD(, pf_state_key)	keys;
14503b3a8eb9SGleb Smirnoff 	struct mtx			lock;
14513b3a8eb9SGleb Smirnoff };
14523b3a8eb9SGleb Smirnoff 
14533b3a8eb9SGleb Smirnoff struct pf_idhash {
14543b3a8eb9SGleb Smirnoff 	LIST_HEAD(, pf_state)		states;
14553b3a8eb9SGleb Smirnoff 	struct mtx			lock;
14563b3a8eb9SGleb Smirnoff };
14573b3a8eb9SGleb Smirnoff 
14586828cc99SGleb Smirnoff extern u_long		pf_hashmask;
14596828cc99SGleb Smirnoff extern u_long		pf_srchashmask;
14603b3a8eb9SGleb Smirnoff #define	PF_HASHSIZ	(32768)
14613b3a8eb9SGleb Smirnoff VNET_DECLARE(struct pf_keyhash *, pf_keyhash);
14623b3a8eb9SGleb Smirnoff VNET_DECLARE(struct pf_idhash *, pf_idhash);
14633b3a8eb9SGleb Smirnoff #define V_pf_keyhash	VNET(pf_keyhash)
14643b3a8eb9SGleb Smirnoff #define	V_pf_idhash	VNET(pf_idhash)
14653b3a8eb9SGleb Smirnoff VNET_DECLARE(struct pf_srchash *, pf_srchash);
14663b3a8eb9SGleb Smirnoff #define	V_pf_srchash	VNET(pf_srchash)
14673b3a8eb9SGleb Smirnoff 
14686828cc99SGleb Smirnoff #define PF_IDHASH(s)	(be64toh((s)->id) % (pf_hashmask + 1))
14693b3a8eb9SGleb Smirnoff 
14703b3a8eb9SGleb Smirnoff VNET_DECLARE(void *, pf_swi_cookie);
14713b3a8eb9SGleb Smirnoff #define V_pf_swi_cookie	VNET(pf_swi_cookie)
14723b3a8eb9SGleb Smirnoff 
14733b3a8eb9SGleb Smirnoff VNET_DECLARE(uint64_t, pf_stateid[MAXCPU]);
14743b3a8eb9SGleb Smirnoff #define	V_pf_stateid	VNET(pf_stateid)
14753b3a8eb9SGleb Smirnoff 
14763b3a8eb9SGleb Smirnoff TAILQ_HEAD(pf_altqqueue, pf_altq);
14773b3a8eb9SGleb Smirnoff VNET_DECLARE(struct pf_altqqueue,	 pf_altqs[2]);
14783b3a8eb9SGleb Smirnoff #define	V_pf_altqs			 VNET(pf_altqs)
14793b3a8eb9SGleb Smirnoff VNET_DECLARE(struct pf_palist,		 pf_pabuf);
14803b3a8eb9SGleb Smirnoff #define	V_pf_pabuf			 VNET(pf_pabuf)
14813b3a8eb9SGleb Smirnoff 
14823b3a8eb9SGleb Smirnoff VNET_DECLARE(u_int32_t,			 ticket_altqs_active);
14833b3a8eb9SGleb Smirnoff #define	V_ticket_altqs_active		 VNET(ticket_altqs_active)
14843b3a8eb9SGleb Smirnoff VNET_DECLARE(u_int32_t,			 ticket_altqs_inactive);
14853b3a8eb9SGleb Smirnoff #define	V_ticket_altqs_inactive		 VNET(ticket_altqs_inactive)
14863b3a8eb9SGleb Smirnoff VNET_DECLARE(int,			 altqs_inactive_open);
14873b3a8eb9SGleb Smirnoff #define	V_altqs_inactive_open		 VNET(altqs_inactive_open)
14883b3a8eb9SGleb Smirnoff VNET_DECLARE(u_int32_t,			 ticket_pabuf);
14893b3a8eb9SGleb Smirnoff #define	V_ticket_pabuf			 VNET(ticket_pabuf)
14903b3a8eb9SGleb Smirnoff VNET_DECLARE(struct pf_altqqueue *,	 pf_altqs_active);
14913b3a8eb9SGleb Smirnoff #define	V_pf_altqs_active		 VNET(pf_altqs_active)
14923b3a8eb9SGleb Smirnoff VNET_DECLARE(struct pf_altqqueue *,	 pf_altqs_inactive);
14933b3a8eb9SGleb Smirnoff #define	V_pf_altqs_inactive		 VNET(pf_altqs_inactive)
14943b3a8eb9SGleb Smirnoff 
14953b3a8eb9SGleb Smirnoff VNET_DECLARE(struct pf_rulequeue, pf_unlinked_rules);
14963b3a8eb9SGleb Smirnoff #define	V_pf_unlinked_rules	VNET(pf_unlinked_rules)
14973b3a8eb9SGleb Smirnoff 
1498*efc6c51fSGleb Smirnoff void				 pf_initialize(void);
14997e92ce73SMartin Matuska void				 pf_mtag_initialize(void);
15007e92ce73SMartin Matuska void				 pf_mtag_cleanup(void);
15013b3a8eb9SGleb Smirnoff void				 pf_cleanup(void);
15023b3a8eb9SGleb Smirnoff 
15033b3a8eb9SGleb Smirnoff struct pf_mtag			*pf_get_mtag(struct mbuf *);
15043b3a8eb9SGleb Smirnoff 
15053b3a8eb9SGleb Smirnoff extern void			 pf_calc_skip_steps(struct pf_rulequeue *);
15063b3a8eb9SGleb Smirnoff #ifdef ALTQ
15073b3a8eb9SGleb Smirnoff extern	void			 pf_altq_ifnet_event(struct ifnet *, int);
15083b3a8eb9SGleb Smirnoff #endif
15093b3a8eb9SGleb Smirnoff VNET_DECLARE(uma_zone_t,	 pf_state_z);
15103b3a8eb9SGleb Smirnoff #define	V_pf_state_z		 VNET(pf_state_z)
15113b3a8eb9SGleb Smirnoff VNET_DECLARE(uma_zone_t,	 pf_state_key_z);
15123b3a8eb9SGleb Smirnoff #define	V_pf_state_key_z	 VNET(pf_state_key_z)
15133b3a8eb9SGleb Smirnoff VNET_DECLARE(uma_zone_t,	 pf_state_scrub_z);
15143b3a8eb9SGleb Smirnoff #define	V_pf_state_scrub_z	 VNET(pf_state_scrub_z)
15153b3a8eb9SGleb Smirnoff 
15163b3a8eb9SGleb Smirnoff extern void			 pf_purge_thread(void *);
15173b3a8eb9SGleb Smirnoff extern void			 pf_intr(void *);
15183b3a8eb9SGleb Smirnoff extern void			 pf_purge_expired_src_nodes(void);
15193b3a8eb9SGleb Smirnoff 
15203b3a8eb9SGleb Smirnoff extern int			 pf_unlink_state(struct pf_state *, u_int);
15213b3a8eb9SGleb Smirnoff #define	PF_ENTER_LOCKED		0x00000001
15223b3a8eb9SGleb Smirnoff #define	PF_RETURN_LOCKED	0x00000002
15233b3a8eb9SGleb Smirnoff extern int			 pf_state_insert(struct pfi_kif *,
15243b3a8eb9SGleb Smirnoff 				    struct pf_state_key *,
15253b3a8eb9SGleb Smirnoff 				    struct pf_state_key *,
15263b3a8eb9SGleb Smirnoff 				    struct pf_state *);
15273b3a8eb9SGleb Smirnoff extern void			 pf_free_state(struct pf_state *);
15283b3a8eb9SGleb Smirnoff 
15293b3a8eb9SGleb Smirnoff static __inline void
15303b3a8eb9SGleb Smirnoff pf_ref_state(struct pf_state *s)
15313b3a8eb9SGleb Smirnoff {
15323b3a8eb9SGleb Smirnoff 
15333b3a8eb9SGleb Smirnoff 	refcount_acquire(&s->refs);
15343b3a8eb9SGleb Smirnoff }
15353b3a8eb9SGleb Smirnoff 
15363b3a8eb9SGleb Smirnoff static __inline int
15373b3a8eb9SGleb Smirnoff pf_release_state(struct pf_state *s)
15383b3a8eb9SGleb Smirnoff {
15393b3a8eb9SGleb Smirnoff 
15403b3a8eb9SGleb Smirnoff 	if (refcount_release(&s->refs)) {
15413b3a8eb9SGleb Smirnoff 		pf_free_state(s);
15423b3a8eb9SGleb Smirnoff 		return (1);
15433b3a8eb9SGleb Smirnoff 	} else
15443b3a8eb9SGleb Smirnoff 		return (0);
15453b3a8eb9SGleb Smirnoff }
15463b3a8eb9SGleb Smirnoff 
15473b3a8eb9SGleb Smirnoff extern struct pf_state		*pf_find_state_byid(uint64_t, uint32_t);
15483b3a8eb9SGleb Smirnoff extern struct pf_state		*pf_find_state_all(struct pf_state_key_cmp *,
15493b3a8eb9SGleb Smirnoff 				    u_int, int *);
15503260ae00SGleb Smirnoff extern struct pf_src_node	*pf_find_src_node(struct pf_addr *,
15513260ae00SGleb Smirnoff 				    struct pf_rule *, sa_family_t, int);
1552d77c1b32SGleb Smirnoff extern void			 pf_unlink_src_node(struct pf_src_node *);
1553d77c1b32SGleb Smirnoff extern void			 pf_unlink_src_node_locked(struct pf_src_node *);
1554d77c1b32SGleb Smirnoff extern u_int			 pf_free_src_nodes(struct pf_src_node_list *);
155507d9bc07SGleb Smirnoff extern void			 pf_print_state(struct pf_state *);
155607d9bc07SGleb Smirnoff extern void			 pf_print_flags(u_int8_t);
15573b3a8eb9SGleb Smirnoff extern u_int16_t		 pf_cksum_fixup(u_int16_t, u_int16_t, u_int16_t,
15583b3a8eb9SGleb Smirnoff 				    u_int8_t);
15593b3a8eb9SGleb Smirnoff 
15603b3a8eb9SGleb Smirnoff VNET_DECLARE(struct ifnet *,		 sync_ifp);
15613b3a8eb9SGleb Smirnoff #define	V_sync_ifp		 	 VNET(sync_ifp);
15623b3a8eb9SGleb Smirnoff VNET_DECLARE(struct pf_rule,		 pf_default_rule);
15633b3a8eb9SGleb Smirnoff #define	V_pf_default_rule		  VNET(pf_default_rule)
15643b3a8eb9SGleb Smirnoff extern void			 pf_addrcpy(struct pf_addr *, struct pf_addr *,
15653b3a8eb9SGleb Smirnoff 				    u_int8_t);
15663b3a8eb9SGleb Smirnoff void				pf_free_rule(struct pf_rule *);
15673b3a8eb9SGleb Smirnoff 
15683b3a8eb9SGleb Smirnoff #ifdef INET
15693b3a8eb9SGleb Smirnoff int	pf_test(int, struct ifnet *, struct mbuf **, struct inpcb *);
15703b3a8eb9SGleb Smirnoff #endif /* INET */
15713b3a8eb9SGleb Smirnoff 
15723b3a8eb9SGleb Smirnoff #ifdef INET6
15733b3a8eb9SGleb Smirnoff int	pf_test6(int, struct ifnet *, struct mbuf **, struct inpcb *);
15743b3a8eb9SGleb Smirnoff void	pf_poolmask(struct pf_addr *, struct pf_addr*,
15753b3a8eb9SGleb Smirnoff 	    struct pf_addr *, struct pf_addr *, u_int8_t);
15763b3a8eb9SGleb Smirnoff void	pf_addr_inc(struct pf_addr *, sa_family_t);
15773b3a8eb9SGleb Smirnoff #endif /* INET6 */
15783b3a8eb9SGleb Smirnoff 
15793b3a8eb9SGleb Smirnoff u_int32_t	pf_new_isn(struct pf_state *);
15803b3a8eb9SGleb Smirnoff void   *pf_pull_hdr(struct mbuf *, int, void *, int, u_short *, u_short *,
15813b3a8eb9SGleb Smirnoff 	    sa_family_t);
15823b3a8eb9SGleb Smirnoff void	pf_change_a(void *, u_int16_t *, u_int32_t, u_int8_t);
15833b3a8eb9SGleb Smirnoff void	pf_send_deferred_syn(struct pf_state *);
15843b3a8eb9SGleb Smirnoff int	pf_match_addr(u_int8_t, struct pf_addr *, struct pf_addr *,
15853b3a8eb9SGleb Smirnoff 	    struct pf_addr *, sa_family_t);
15863b3a8eb9SGleb Smirnoff int	pf_match_addr_range(struct pf_addr *, struct pf_addr *,
15873b3a8eb9SGleb Smirnoff 	    struct pf_addr *, sa_family_t);
15883b3a8eb9SGleb Smirnoff int	pf_match_port(u_int8_t, u_int16_t, u_int16_t, u_int16_t);
15893b3a8eb9SGleb Smirnoff 
1590*efc6c51fSGleb Smirnoff void	pf_normalize_init(void);
15913b3a8eb9SGleb Smirnoff void	pf_normalize_cleanup(void);
15923b3a8eb9SGleb Smirnoff int	pf_normalize_ip(struct mbuf **, int, struct pfi_kif *, u_short *,
15933b3a8eb9SGleb Smirnoff 	    struct pf_pdesc *);
15943b3a8eb9SGleb Smirnoff int	pf_normalize_ip6(struct mbuf **, int, struct pfi_kif *, u_short *,
15953b3a8eb9SGleb Smirnoff 	    struct pf_pdesc *);
15963b3a8eb9SGleb Smirnoff int	pf_normalize_tcp(int, struct pfi_kif *, struct mbuf *, int, int, void *,
15973b3a8eb9SGleb Smirnoff 	    struct pf_pdesc *);
15983b3a8eb9SGleb Smirnoff void	pf_normalize_tcp_cleanup(struct pf_state *);
15993b3a8eb9SGleb Smirnoff int	pf_normalize_tcp_init(struct mbuf *, int, struct pf_pdesc *,
16003b3a8eb9SGleb Smirnoff 	    struct tcphdr *, struct pf_state_peer *, struct pf_state_peer *);
16013b3a8eb9SGleb Smirnoff int	pf_normalize_tcp_stateful(struct mbuf *, int, struct pf_pdesc *,
16023b3a8eb9SGleb Smirnoff 	    u_short *, struct tcphdr *, struct pf_state *,
16033b3a8eb9SGleb Smirnoff 	    struct pf_state_peer *, struct pf_state_peer *, int *);
16043b3a8eb9SGleb Smirnoff u_int32_t
16053b3a8eb9SGleb Smirnoff 	pf_state_expires(const struct pf_state *);
16063b3a8eb9SGleb Smirnoff void	pf_purge_expired_fragments(void);
16073b3a8eb9SGleb Smirnoff int	pf_routable(struct pf_addr *addr, sa_family_t af, struct pfi_kif *,
16083b3a8eb9SGleb Smirnoff 	    int);
16093b3a8eb9SGleb Smirnoff int	pf_socket_lookup(int, struct pf_pdesc *, struct mbuf *);
16103b3a8eb9SGleb Smirnoff struct pf_state_key *pf_alloc_state_key(int);
16113b3a8eb9SGleb Smirnoff void	pfr_initialize(void);
16123b3a8eb9SGleb Smirnoff void	pfr_cleanup(void);
16133b3a8eb9SGleb Smirnoff int	pfr_match_addr(struct pfr_ktable *, struct pf_addr *, sa_family_t);
16143b3a8eb9SGleb Smirnoff void	pfr_update_stats(struct pfr_ktable *, struct pf_addr *, sa_family_t,
16153b3a8eb9SGleb Smirnoff 	    u_int64_t, int, int, int);
16163b3a8eb9SGleb Smirnoff int	pfr_pool_get(struct pfr_ktable *, int *, struct pf_addr *, sa_family_t);
16173b3a8eb9SGleb Smirnoff void	pfr_dynaddr_update(struct pfr_ktable *, struct pfi_dynaddr *);
16183b3a8eb9SGleb Smirnoff struct pfr_ktable *
16193b3a8eb9SGleb Smirnoff 	pfr_attach_table(struct pf_ruleset *, char *);
16203b3a8eb9SGleb Smirnoff void	pfr_detach_table(struct pfr_ktable *);
16213b3a8eb9SGleb Smirnoff int	pfr_clr_tables(struct pfr_table *, int *, int);
16223b3a8eb9SGleb Smirnoff int	pfr_add_tables(struct pfr_table *, int, int *, int);
16233b3a8eb9SGleb Smirnoff int	pfr_del_tables(struct pfr_table *, int, int *, int);
16243b3a8eb9SGleb Smirnoff int	pfr_get_tables(struct pfr_table *, struct pfr_table *, int *, int);
16253b3a8eb9SGleb Smirnoff int	pfr_get_tstats(struct pfr_table *, struct pfr_tstats *, int *, int);
16263b3a8eb9SGleb Smirnoff int	pfr_clr_tstats(struct pfr_table *, int, int *, int);
16273b3a8eb9SGleb Smirnoff int	pfr_set_tflags(struct pfr_table *, int, int, int, int *, int *, int);
16283b3a8eb9SGleb Smirnoff int	pfr_clr_addrs(struct pfr_table *, int *, int);
16293b3a8eb9SGleb Smirnoff int	pfr_insert_kentry(struct pfr_ktable *, struct pfr_addr *, long);
16303b3a8eb9SGleb Smirnoff int	pfr_add_addrs(struct pfr_table *, struct pfr_addr *, int, int *,
16313b3a8eb9SGleb Smirnoff 	    int);
16323b3a8eb9SGleb Smirnoff int	pfr_del_addrs(struct pfr_table *, struct pfr_addr *, int, int *,
16333b3a8eb9SGleb Smirnoff 	    int);
16343b3a8eb9SGleb Smirnoff int	pfr_set_addrs(struct pfr_table *, struct pfr_addr *, int, int *,
16353b3a8eb9SGleb Smirnoff 	    int *, int *, int *, int, u_int32_t);
16363b3a8eb9SGleb Smirnoff int	pfr_get_addrs(struct pfr_table *, struct pfr_addr *, int *, int);
16373b3a8eb9SGleb Smirnoff int	pfr_get_astats(struct pfr_table *, struct pfr_astats *, int *, int);
16383b3a8eb9SGleb Smirnoff int	pfr_clr_astats(struct pfr_table *, struct pfr_addr *, int, int *,
16393b3a8eb9SGleb Smirnoff 	    int);
16403b3a8eb9SGleb Smirnoff int	pfr_tst_addrs(struct pfr_table *, struct pfr_addr *, int, int *,
16413b3a8eb9SGleb Smirnoff 	    int);
16423b3a8eb9SGleb Smirnoff int	pfr_ina_begin(struct pfr_table *, u_int32_t *, int *, int);
16433b3a8eb9SGleb Smirnoff int	pfr_ina_rollback(struct pfr_table *, u_int32_t, int *, int);
16443b3a8eb9SGleb Smirnoff int	pfr_ina_commit(struct pfr_table *, u_int32_t, int *, int *, int);
16453b3a8eb9SGleb Smirnoff int	pfr_ina_define(struct pfr_table *, struct pfr_addr *, int, int *,
16463b3a8eb9SGleb Smirnoff 	    int *, u_int32_t, int);
16473b3a8eb9SGleb Smirnoff 
16483b3a8eb9SGleb Smirnoff MALLOC_DECLARE(PFI_MTYPE);
16493b3a8eb9SGleb Smirnoff VNET_DECLARE(struct pfi_kif *,		 pfi_all);
16503b3a8eb9SGleb Smirnoff #define	V_pfi_all	 		 VNET(pfi_all)
16513b3a8eb9SGleb Smirnoff 
1652*efc6c51fSGleb Smirnoff void		 pfi_initialize(void);
16533b3a8eb9SGleb Smirnoff void		 pfi_cleanup(void);
16543b3a8eb9SGleb Smirnoff void		 pfi_kif_ref(struct pfi_kif *);
16553b3a8eb9SGleb Smirnoff void		 pfi_kif_unref(struct pfi_kif *);
16563b3a8eb9SGleb Smirnoff struct pfi_kif	*pfi_kif_find(const char *);
16573b3a8eb9SGleb Smirnoff struct pfi_kif	*pfi_kif_attach(struct pfi_kif *, const char *);
16583b3a8eb9SGleb Smirnoff int		 pfi_kif_match(struct pfi_kif *, struct pfi_kif *);
16593b3a8eb9SGleb Smirnoff void		 pfi_kif_purge(void);
16603b3a8eb9SGleb Smirnoff int		 pfi_match_addr(struct pfi_dynaddr *, struct pf_addr *,
16613b3a8eb9SGleb Smirnoff 		    sa_family_t);
16623b3a8eb9SGleb Smirnoff int		 pfi_dynaddr_setup(struct pf_addr_wrap *, sa_family_t);
16633b3a8eb9SGleb Smirnoff void		 pfi_dynaddr_remove(struct pfi_dynaddr *);
16643b3a8eb9SGleb Smirnoff void		 pfi_dynaddr_copyout(struct pf_addr_wrap *);
16653b3a8eb9SGleb Smirnoff void		 pfi_update_status(const char *, struct pf_status *);
16663b3a8eb9SGleb Smirnoff void		 pfi_get_ifaces(const char *, struct pfi_kif *, int *);
16673b3a8eb9SGleb Smirnoff int		 pfi_set_flags(const char *, int);
16683b3a8eb9SGleb Smirnoff int		 pfi_clear_flags(const char *, int);
16693b3a8eb9SGleb Smirnoff 
16703b3a8eb9SGleb Smirnoff int		 pf_match_tag(struct mbuf *, struct pf_rule *, int *, int);
16713b3a8eb9SGleb Smirnoff int		 pf_tag_packet(struct mbuf *, struct pf_pdesc *, int);
16723b3a8eb9SGleb Smirnoff void		 pf_qid2qname(u_int32_t, char *);
16733b3a8eb9SGleb Smirnoff 
1674a9572d8fSGleb Smirnoff VNET_DECLARE(struct pf_kstatus, pf_status);
16753b3a8eb9SGleb Smirnoff #define	V_pf_status	VNET(pf_status)
16763b3a8eb9SGleb Smirnoff 
16773b3a8eb9SGleb Smirnoff struct pf_limit {
16783b3a8eb9SGleb Smirnoff 	uma_zone_t	zone;
16793b3a8eb9SGleb Smirnoff 	u_int		limit;
16803b3a8eb9SGleb Smirnoff };
16813b3a8eb9SGleb Smirnoff VNET_DECLARE(struct pf_limit, pf_limits[PF_LIMIT_MAX]);
16823b3a8eb9SGleb Smirnoff #define	V_pf_limits VNET(pf_limits)
16833b3a8eb9SGleb Smirnoff 
16843b3a8eb9SGleb Smirnoff #endif /* _KERNEL */
16853b3a8eb9SGleb Smirnoff 
16863b3a8eb9SGleb Smirnoff #ifdef _KERNEL
16873b3a8eb9SGleb Smirnoff VNET_DECLARE(struct pf_anchor_global,		 pf_anchors);
16883b3a8eb9SGleb Smirnoff #define	V_pf_anchors				 VNET(pf_anchors)
16893b3a8eb9SGleb Smirnoff VNET_DECLARE(struct pf_anchor,			 pf_main_anchor);
16903b3a8eb9SGleb Smirnoff #define	V_pf_main_anchor			 VNET(pf_main_anchor)
16913b3a8eb9SGleb Smirnoff #define pf_main_ruleset	V_pf_main_anchor.ruleset
16923b3a8eb9SGleb Smirnoff #endif
16933b3a8eb9SGleb Smirnoff 
16943b3a8eb9SGleb Smirnoff /* these ruleset functions can be linked into userland programs (pfctl) */
16953b3a8eb9SGleb Smirnoff int			 pf_get_ruleset_number(u_int8_t);
16963b3a8eb9SGleb Smirnoff void			 pf_init_ruleset(struct pf_ruleset *);
16973b3a8eb9SGleb Smirnoff int			 pf_anchor_setup(struct pf_rule *,
16983b3a8eb9SGleb Smirnoff 			    const struct pf_ruleset *, const char *);
16993b3a8eb9SGleb Smirnoff int			 pf_anchor_copyout(const struct pf_ruleset *,
17003b3a8eb9SGleb Smirnoff 			    const struct pf_rule *, struct pfioc_rule *);
17013b3a8eb9SGleb Smirnoff void			 pf_anchor_remove(struct pf_rule *);
17023b3a8eb9SGleb Smirnoff void			 pf_remove_if_empty_ruleset(struct pf_ruleset *);
17033b3a8eb9SGleb Smirnoff struct pf_ruleset	*pf_find_ruleset(const char *);
17043b3a8eb9SGleb Smirnoff struct pf_ruleset	*pf_find_or_create_ruleset(const char *);
17053b3a8eb9SGleb Smirnoff void			 pf_rs_initialize(void);
17063b3a8eb9SGleb Smirnoff 
17073b3a8eb9SGleb Smirnoff /* The fingerprint functions can be linked into userland programs (tcpdump) */
17083b3a8eb9SGleb Smirnoff int	pf_osfp_add(struct pf_osfp_ioctl *);
17093b3a8eb9SGleb Smirnoff #ifdef _KERNEL
17103b3a8eb9SGleb Smirnoff struct pf_osfp_enlist *
17113b3a8eb9SGleb Smirnoff 	pf_osfp_fingerprint(struct pf_pdesc *, struct mbuf *, int,
17123b3a8eb9SGleb Smirnoff 	    const struct tcphdr *);
17133b3a8eb9SGleb Smirnoff #endif /* _KERNEL */
17143b3a8eb9SGleb Smirnoff void	pf_osfp_flush(void);
17153b3a8eb9SGleb Smirnoff int	pf_osfp_get(struct pf_osfp_ioctl *);
17163b3a8eb9SGleb Smirnoff int	pf_osfp_match(struct pf_osfp_enlist *, pf_osfp_t);
17173b3a8eb9SGleb Smirnoff 
17183b3a8eb9SGleb Smirnoff #ifdef _KERNEL
171907d9bc07SGleb Smirnoff void			 pf_print_host(struct pf_addr *, u_int16_t, u_int8_t);
172007d9bc07SGleb Smirnoff 
17211d6139c0SGleb Smirnoff void			 pf_step_into_anchor(struct pf_anchor_stackframe *, int *,
17221d6139c0SGleb Smirnoff 			    struct pf_ruleset **, int, struct pf_rule **,
17231d6139c0SGleb Smirnoff 			    struct pf_rule **, int *);
17241d6139c0SGleb Smirnoff int			 pf_step_out_of_anchor(struct pf_anchor_stackframe *, int *,
17251d6139c0SGleb Smirnoff 			    struct pf_ruleset **, int, struct pf_rule **,
17261d6139c0SGleb Smirnoff 			    struct pf_rule **, int *);
17273b3a8eb9SGleb Smirnoff 
17283b3a8eb9SGleb Smirnoff int			 pf_map_addr(u_int8_t, struct pf_rule *,
17293b3a8eb9SGleb Smirnoff 			    struct pf_addr *, struct pf_addr *,
17303b3a8eb9SGleb Smirnoff 			    struct pf_addr *, struct pf_src_node **);
17313b3a8eb9SGleb Smirnoff struct pf_rule		*pf_get_translation(struct pf_pdesc *, struct mbuf *,
17323b3a8eb9SGleb Smirnoff 			    int, int, struct pfi_kif *, struct pf_src_node **,
17333b3a8eb9SGleb Smirnoff 			    struct pf_state_key **, struct pf_state_key **,
17343b3a8eb9SGleb Smirnoff 			    struct pf_addr *, struct pf_addr *,
17351d6139c0SGleb Smirnoff 			    uint16_t, uint16_t, struct pf_anchor_stackframe *);
17363b3a8eb9SGleb Smirnoff 
17373b3a8eb9SGleb Smirnoff struct pf_state_key	*pf_state_key_setup(struct pf_pdesc *, struct pf_addr *,
17383b3a8eb9SGleb Smirnoff 			    struct pf_addr *, u_int16_t, u_int16_t);
17393b3a8eb9SGleb Smirnoff struct pf_state_key	*pf_state_key_clone(struct pf_state_key *);
17403b3a8eb9SGleb Smirnoff #endif /* _KERNEL */
17413b3a8eb9SGleb Smirnoff 
17423b3a8eb9SGleb Smirnoff #endif /* _NET_PFVAR_H_ */
1743