Home | History | Annotate | Line # | Download | only in net
      1  1.23  riastrad /*	$NetBSD: pfvar.h,v 1.23 2020/03/05 07:46:36 riastradh Exp $	*/
      2  1.16      yamt /*	$OpenBSD: pfvar.h,v 1.254 2007/07/13 09:17:48 markus Exp $ */
      3   1.1    itojun 
      4   1.1    itojun /*
      5   1.1    itojun  * Copyright (c) 2001 Daniel Hartmeier
      6   1.1    itojun  * All rights reserved.
      7   1.1    itojun  *
      8   1.1    itojun  * Redistribution and use in source and binary forms, with or without
      9   1.1    itojun  * modification, are permitted provided that the following conditions
     10   1.1    itojun  * are met:
     11   1.1    itojun  *
     12   1.1    itojun  *    - Redistributions of source code must retain the above copyright
     13   1.1    itojun  *      notice, this list of conditions and the following disclaimer.
     14   1.1    itojun  *    - Redistributions in binary form must reproduce the above
     15   1.1    itojun  *      copyright notice, this list of conditions and the following
     16   1.1    itojun  *      disclaimer in the documentation and/or other materials provided
     17   1.1    itojun  *      with the distribution.
     18   1.1    itojun  *
     19   1.1    itojun  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     20   1.1    itojun  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     21   1.1    itojun  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     22   1.1    itojun  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     23   1.1    itojun  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     24   1.1    itojun  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     25   1.1    itojun  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     26   1.1    itojun  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     27   1.1    itojun  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28   1.1    itojun  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     29   1.1    itojun  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30   1.1    itojun  * POSSIBILITY OF SUCH DAMAGE.
     31   1.1    itojun  *
     32   1.1    itojun  */
     33   1.1    itojun 
     34   1.1    itojun #ifndef _NET_PFVAR_H_
     35   1.1    itojun #define _NET_PFVAR_H_
     36   1.1    itojun 
     37  1.23  riastrad #ifdef _KERNEL_OPT
     38  1.23  riastrad #include "opt_inet.h"
     39  1.23  riastrad #endif
     40  1.23  riastrad 
     41   1.6      yamt #include <sys/param.h>
     42   1.1    itojun #include <sys/types.h>
     43   1.1    itojun #include <sys/queue.h>
     44   1.1    itojun #include <sys/tree.h>
     45  1.16      yamt #include <sys/rwlock.h>
     46   1.1    itojun 
     47   1.1    itojun #include <net/radix.h>
     48  1.16      yamt #ifndef __NetBSD__
     49   1.9     peter #include <net/route.h>
     50   1.1    itojun #include <netinet/ip_ipsp.h>
     51  1.11     peter #else
     52  1.16      yamt /* files above include netinet/in.h so include it too for compatibility */
     53  1.11     peter #include <netinet/in.h>
     54  1.16      yamt #endif /* __NetBSD__ */
     55   1.1    itojun #include <netinet/tcp_fsm.h>
     56   1.1    itojun 
     57  1.16      yamt #if defined(__NetBSD__) && defined(_KERNEL)
     58  1.16      yamt #include <net/if_compat.h>
     59  1.16      yamt #include <net/pf_mtag.h>
     60  1.16      yamt #endif /* __NetBSD__ && _KERNEL */
     61  1.16      yamt 
     62   1.1    itojun struct ip;
     63  1.16      yamt struct ip6_hdr;
     64   1.1    itojun 
     65   1.1    itojun #define	PF_TCPS_PROXY_SRC	((TCP_NSTATES)+0)
     66   1.1    itojun #define	PF_TCPS_PROXY_DST	((TCP_NSTATES)+1)
     67   1.1    itojun 
     68  1.16      yamt #define	PF_MD5_DIGEST_LENGTH	16
     69  1.16      yamt #ifdef MD5_DIGEST_LENGTH
     70  1.16      yamt #if PF_MD5_DIGEST_LENGTH != MD5_DIGEST_LENGTH
     71  1.16      yamt #error
     72  1.16      yamt #endif
     73  1.16      yamt #endif
     74  1.16      yamt 
     75   1.1    itojun enum	{ PF_INOUT, PF_IN, PF_OUT };
     76   1.1    itojun enum	{ PF_LAN_EXT, PF_EXT_GWY, PF_ID };
     77   1.9     peter enum	{ PF_PASS, PF_DROP, PF_SCRUB, PF_NOSCRUB, PF_NAT, PF_NONAT,
     78   1.1    itojun 	  PF_BINAT, PF_NOBINAT, PF_RDR, PF_NORDR, PF_SYNPROXY_DROP };
     79   1.1    itojun enum	{ PF_RULESET_SCRUB, PF_RULESET_FILTER, PF_RULESET_NAT,
     80   1.1    itojun 	  PF_RULESET_BINAT, PF_RULESET_RDR, PF_RULESET_MAX };
     81   1.1    itojun enum	{ PF_OP_NONE, PF_OP_IRG, PF_OP_EQ, PF_OP_NE, PF_OP_LT,
     82   1.1    itojun 	  PF_OP_LE, PF_OP_GT, PF_OP_GE, PF_OP_XRG, PF_OP_RRG };
     83   1.1    itojun enum	{ PF_DEBUG_NONE, PF_DEBUG_URGENT, PF_DEBUG_MISC, PF_DEBUG_NOISY };
     84   1.1    itojun enum	{ PF_CHANGE_NONE, PF_CHANGE_ADD_HEAD, PF_CHANGE_ADD_TAIL,
     85   1.1    itojun 	  PF_CHANGE_ADD_BEFORE, PF_CHANGE_ADD_AFTER,
     86   1.1    itojun 	  PF_CHANGE_REMOVE, PF_CHANGE_GET_TICKET };
     87  1.16      yamt enum	{ PF_GET_NONE, PF_GET_CLR_CNTR };
     88  1.16      yamt 
     89   1.1    itojun /*
     90   1.1    itojun  * Note about PFTM_*: real indices into pf_rule.timeout[] come before
     91   1.1    itojun  * PFTM_MAX, special cases afterwards. See pf_state_expires().
     92   1.1    itojun  */
     93   1.1    itojun enum	{ PFTM_TCP_FIRST_PACKET, PFTM_TCP_OPENING, PFTM_TCP_ESTABLISHED,
     94   1.1    itojun 	  PFTM_TCP_CLOSING, PFTM_TCP_FIN_WAIT, PFTM_TCP_CLOSED,
     95   1.1    itojun 	  PFTM_UDP_FIRST_PACKET, PFTM_UDP_SINGLE, PFTM_UDP_MULTIPLE,
     96   1.1    itojun 	  PFTM_ICMP_FIRST_PACKET, PFTM_ICMP_ERROR_REPLY,
     97   1.1    itojun 	  PFTM_OTHER_FIRST_PACKET, PFTM_OTHER_SINGLE,
     98   1.1    itojun 	  PFTM_OTHER_MULTIPLE, PFTM_FRAG, PFTM_INTERVAL,
     99   1.1    itojun 	  PFTM_ADAPTIVE_START, PFTM_ADAPTIVE_END, PFTM_SRC_NODE,
    100  1.16      yamt 	  PFTM_TS_DIFF, PFTM_MAX, PFTM_PURGE, PFTM_UNLINKED,
    101  1.16      yamt 	  PFTM_UNTIL_PACKET };
    102   1.9     peter 
    103   1.9     peter /* PFTM default values */
    104   1.9     peter #define PFTM_TCP_FIRST_PACKET_VAL	120	/* First TCP packet */
    105   1.9     peter #define PFTM_TCP_OPENING_VAL		30	/* No response yet */
    106   1.9     peter #define PFTM_TCP_ESTABLISHED_VAL	24*60*60/* Established */
    107   1.9     peter #define PFTM_TCP_CLOSING_VAL		15 * 60	/* Half closed */
    108   1.9     peter #define PFTM_TCP_FIN_WAIT_VAL		45	/* Got both FINs */
    109   1.9     peter #define PFTM_TCP_CLOSED_VAL		90	/* Got a RST */
    110   1.9     peter #define PFTM_UDP_FIRST_PACKET_VAL	60	/* First UDP packet */
    111   1.9     peter #define PFTM_UDP_SINGLE_VAL		30	/* Unidirectional */
    112   1.9     peter #define PFTM_UDP_MULTIPLE_VAL		60	/* Bidirectional */
    113   1.9     peter #define PFTM_ICMP_FIRST_PACKET_VAL	20	/* First ICMP packet */
    114   1.9     peter #define PFTM_ICMP_ERROR_REPLY_VAL	10	/* Got error response */
    115   1.9     peter #define PFTM_OTHER_FIRST_PACKET_VAL	60	/* First packet */
    116   1.9     peter #define PFTM_OTHER_SINGLE_VAL		30	/* Unidirectional */
    117   1.9     peter #define PFTM_OTHER_MULTIPLE_VAL		60	/* Bidirectional */
    118   1.9     peter #define PFTM_FRAG_VAL			30	/* Fragment expire */
    119   1.9     peter #define PFTM_INTERVAL_VAL		10	/* Expire interval */
    120   1.9     peter #define PFTM_SRC_NODE_VAL		0	/* Source tracking */
    121   1.9     peter #define PFTM_TS_DIFF_VAL		30	/* Allowed TS diff */
    122   1.9     peter 
    123   1.1    itojun enum	{ PF_NOPFROUTE, PF_FASTROUTE, PF_ROUTETO, PF_DUPTO, PF_REPLYTO };
    124  1.16      yamt enum	{ PF_LIMIT_STATES, PF_LIMIT_SRC_NODES, PF_LIMIT_FRAGS,
    125  1.16      yamt 	  PF_LIMIT_TABLES, PF_LIMIT_TABLE_ENTRIES, PF_LIMIT_MAX };
    126   1.1    itojun #define PF_POOL_IDMASK		0x0f
    127   1.1    itojun enum	{ PF_POOL_NONE, PF_POOL_BITMASK, PF_POOL_RANDOM,
    128   1.1    itojun 	  PF_POOL_SRCHASH, PF_POOL_ROUNDROBIN };
    129   1.1    itojun enum	{ PF_ADDR_ADDRMASK, PF_ADDR_NOROUTE, PF_ADDR_DYNIFTL,
    130  1.16      yamt 	  PF_ADDR_TABLE, PF_ADDR_RTLABEL, PF_ADDR_URPFFAILED };
    131   1.1    itojun #define PF_POOL_TYPEMASK	0x0f
    132   1.1    itojun #define PF_POOL_STICKYADDR	0x20
    133   1.1    itojun #define	PF_WSCALE_FLAG		0x80
    134   1.1    itojun #define	PF_WSCALE_MASK		0x0f
    135   1.1    itojun 
    136  1.16      yamt #define	PF_LOG			0x01
    137  1.16      yamt #define	PF_LOG_ALL		0x02
    138  1.16      yamt #define	PF_LOG_SOCKET_LOOKUP	0x04
    139  1.16      yamt 
    140   1.1    itojun struct pf_addr {
    141   1.1    itojun 	union {
    142   1.1    itojun 		struct in_addr		v4;
    143   1.1    itojun 		struct in6_addr		v6;
    144   1.1    itojun 		u_int8_t		addr8[16];
    145   1.1    itojun 		u_int16_t		addr16[8];
    146   1.1    itojun 		u_int32_t		addr32[4];
    147   1.1    itojun 	} pfa;		    /* 128-bit address */
    148   1.1    itojun #define v4	pfa.v4
    149   1.1    itojun #define v6	pfa.v6
    150   1.1    itojun #define addr8	pfa.addr8
    151   1.1    itojun #define addr16	pfa.addr16
    152   1.1    itojun #define addr32	pfa.addr32
    153   1.1    itojun };
    154   1.1    itojun 
    155   1.1    itojun #define	PF_TABLE_NAME_SIZE	 32
    156   1.1    itojun 
    157   1.1    itojun #define PFI_AFLAG_NETWORK	0x01
    158   1.1    itojun #define PFI_AFLAG_BROADCAST	0x02
    159   1.1    itojun #define PFI_AFLAG_PEER		0x04
    160   1.1    itojun #define PFI_AFLAG_MODEMASK	0x07
    161   1.1    itojun #define PFI_AFLAG_NOALIAS	0x08
    162   1.1    itojun 
    163   1.9     peter #ifndef RTLABEL_LEN
    164   1.9     peter #define RTLABEL_LEN	32
    165   1.9     peter #endif
    166   1.9     peter 
    167   1.1    itojun struct pf_addr_wrap {
    168   1.1    itojun 	union {
    169   1.1    itojun 		struct {
    170   1.1    itojun 			struct pf_addr		 addr;
    171   1.1    itojun 			struct pf_addr		 mask;
    172   1.1    itojun 		}			 a;
    173   1.1    itojun 		char			 ifname[IFNAMSIZ];
    174   1.1    itojun 		char			 tblname[PF_TABLE_NAME_SIZE];
    175   1.9     peter 		char			 rtlabelname[RTLABEL_LEN];
    176   1.9     peter 		u_int32_t		 rtlabel;
    177   1.1    itojun 	}			 v;
    178   1.1    itojun 	union {
    179   1.1    itojun 		struct pfi_dynaddr	*dyn;
    180   1.1    itojun 		struct pfr_ktable	*tbl;
    181   1.1    itojun 		int			 dyncnt;
    182   1.1    itojun 		int			 tblcnt;
    183   1.1    itojun 	}			 p;
    184   1.1    itojun 	u_int8_t		 type;		/* PF_ADDR_* */
    185   1.1    itojun 	u_int8_t		 iflags;	/* PFI_AFLAG_* */
    186   1.1    itojun };
    187   1.1    itojun 
    188   1.8     peter #ifdef _KERNEL
    189   1.8     peter 
    190   1.1    itojun struct pfi_dynaddr {
    191  1.16      yamt 	TAILQ_ENTRY(pfi_dynaddr)	 entry;
    192  1.16      yamt 	struct pf_addr			 pfid_addr4;
    193  1.16      yamt 	struct pf_addr			 pfid_mask4;
    194  1.16      yamt 	struct pf_addr			 pfid_addr6;
    195  1.16      yamt 	struct pf_addr			 pfid_mask6;
    196  1.16      yamt 	struct pfr_ktable		*pfid_kt;
    197  1.16      yamt 	struct pfi_kif			*pfid_kif;
    198  1.16      yamt 	void				*pfid_hook_cookie;
    199  1.16      yamt 	int				 pfid_net;	/* mask or 128 */
    200  1.16      yamt 	int				 pfid_acnt4;	/* address count IPv4 */
    201  1.16      yamt 	int				 pfid_acnt6;	/* address count IPv6 */
    202  1.16      yamt 	sa_family_t			 pfid_af;	/* rule af */
    203  1.16      yamt 	u_int8_t			 pfid_iflags;	/* PFI_AFLAG_* */
    204   1.1    itojun };
    205   1.1    itojun 
    206   1.1    itojun /*
    207   1.1    itojun  * Address manipulation macros
    208   1.1    itojun  */
    209   1.1    itojun 
    210   1.1    itojun #ifdef INET
    211   1.1    itojun #ifndef INET6
    212   1.1    itojun #define PF_INET_ONLY
    213   1.1    itojun #endif /* ! INET6 */
    214   1.1    itojun #endif /* INET */
    215   1.1    itojun 
    216   1.1    itojun #ifdef INET6
    217   1.1    itojun #ifndef INET
    218   1.1    itojun #define PF_INET6_ONLY
    219   1.1    itojun #endif /* ! INET */
    220   1.1    itojun #endif /* INET6 */
    221   1.1    itojun 
    222   1.1    itojun #ifdef INET
    223   1.1    itojun #ifdef INET6
    224   1.1    itojun #define PF_INET_INET6
    225   1.1    itojun #endif /* INET6 */
    226   1.1    itojun #endif /* INET */
    227   1.1    itojun 
    228   1.1    itojun #else
    229   1.1    itojun 
    230   1.1    itojun #define PF_INET_INET6
    231   1.1    itojun 
    232   1.1    itojun #endif /* _KERNEL */
    233   1.1    itojun 
    234   1.1    itojun /* Both IPv4 and IPv6 */
    235   1.1    itojun #ifdef PF_INET_INET6
    236   1.1    itojun 
    237   1.1    itojun #define PF_AEQ(a, b, c) \
    238   1.1    itojun 	((c == AF_INET && (a)->addr32[0] == (b)->addr32[0]) || \
    239   1.1    itojun 	((a)->addr32[3] == (b)->addr32[3] && \
    240   1.1    itojun 	(a)->addr32[2] == (b)->addr32[2] && \
    241   1.1    itojun 	(a)->addr32[1] == (b)->addr32[1] && \
    242   1.1    itojun 	(a)->addr32[0] == (b)->addr32[0])) \
    243   1.1    itojun 
    244   1.1    itojun #define PF_ANEQ(a, b, c) \
    245   1.1    itojun 	((c == AF_INET && (a)->addr32[0] != (b)->addr32[0]) || \
    246   1.1    itojun 	((a)->addr32[3] != (b)->addr32[3] || \
    247   1.1    itojun 	(a)->addr32[2] != (b)->addr32[2] || \
    248   1.1    itojun 	(a)->addr32[1] != (b)->addr32[1] || \
    249   1.1    itojun 	(a)->addr32[0] != (b)->addr32[0])) \
    250   1.1    itojun 
    251   1.1    itojun #define PF_AZERO(a, c) \
    252   1.1    itojun 	((c == AF_INET && !(a)->addr32[0]) || \
    253   1.1    itojun 	(!(a)->addr32[0] && !(a)->addr32[1] && \
    254   1.1    itojun 	!(a)->addr32[2] && !(a)->addr32[3] )) \
    255   1.1    itojun 
    256   1.1    itojun #define PF_MATCHA(n, a, m, b, f) \
    257   1.1    itojun 	pf_match_addr(n, a, m, b, f)
    258   1.1    itojun 
    259   1.1    itojun #define PF_ACPY(a, b, f) \
    260   1.1    itojun 	pf_addrcpy(a, b, f)
    261   1.1    itojun 
    262   1.1    itojun #define PF_AINC(a, f) \
    263   1.1    itojun 	pf_addr_inc(a, f)
    264   1.1    itojun 
    265   1.1    itojun #define PF_POOLMASK(a, b, c, d, f) \
    266   1.1    itojun 	pf_poolmask(a, b, c, d, f)
    267   1.1    itojun 
    268   1.1    itojun #else
    269   1.1    itojun 
    270   1.1    itojun /* Just IPv6 */
    271   1.1    itojun 
    272   1.1    itojun #ifdef PF_INET6_ONLY
    273   1.1    itojun 
    274   1.1    itojun #define PF_AEQ(a, b, c) \
    275   1.1    itojun 	((a)->addr32[3] == (b)->addr32[3] && \
    276   1.1    itojun 	(a)->addr32[2] == (b)->addr32[2] && \
    277   1.1    itojun 	(a)->addr32[1] == (b)->addr32[1] && \
    278   1.1    itojun 	(a)->addr32[0] == (b)->addr32[0]) \
    279   1.1    itojun 
    280   1.1    itojun #define PF_ANEQ(a, b, c) \
    281   1.1    itojun 	((a)->addr32[3] != (b)->addr32[3] || \
    282   1.1    itojun 	(a)->addr32[2] != (b)->addr32[2] || \
    283   1.1    itojun 	(a)->addr32[1] != (b)->addr32[1] || \
    284   1.1    itojun 	(a)->addr32[0] != (b)->addr32[0]) \
    285   1.1    itojun 
    286   1.1    itojun #define PF_AZERO(a, c) \
    287   1.1    itojun 	(!(a)->addr32[0] && \
    288   1.1    itojun 	!(a)->addr32[1] && \
    289   1.1    itojun 	!(a)->addr32[2] && \
    290   1.1    itojun 	!(a)->addr32[3] ) \
    291   1.1    itojun 
    292   1.1    itojun #define PF_MATCHA(n, a, m, b, f) \
    293   1.1    itojun 	pf_match_addr(n, a, m, b, f)
    294   1.1    itojun 
    295   1.1    itojun #define PF_ACPY(a, b, f) \
    296   1.1    itojun 	pf_addrcpy(a, b, f)
    297   1.1    itojun 
    298   1.1    itojun #define PF_AINC(a, f) \
    299   1.1    itojun 	pf_addr_inc(a, f)
    300   1.1    itojun 
    301   1.1    itojun #define PF_POOLMASK(a, b, c, d, f) \
    302   1.1    itojun 	pf_poolmask(a, b, c, d, f)
    303   1.1    itojun 
    304   1.1    itojun #else
    305   1.1    itojun 
    306   1.1    itojun /* Just IPv4 */
    307   1.1    itojun #ifdef PF_INET_ONLY
    308   1.1    itojun 
    309   1.1    itojun #define PF_AEQ(a, b, c) \
    310   1.1    itojun 	((a)->addr32[0] == (b)->addr32[0])
    311   1.1    itojun 
    312   1.1    itojun #define PF_ANEQ(a, b, c) \
    313   1.1    itojun 	((a)->addr32[0] != (b)->addr32[0])
    314   1.1    itojun 
    315   1.1    itojun #define PF_AZERO(a, c) \
    316   1.1    itojun 	(!(a)->addr32[0])
    317   1.1    itojun 
    318   1.1    itojun #define PF_MATCHA(n, a, m, b, f) \
    319   1.1    itojun 	pf_match_addr(n, a, m, b, f)
    320   1.1    itojun 
    321   1.1    itojun #define PF_ACPY(a, b, f) \
    322   1.1    itojun 	(a)->v4.s_addr = (b)->v4.s_addr
    323   1.1    itojun 
    324   1.1    itojun #define PF_AINC(a, f) \
    325   1.1    itojun 	do { \
    326   1.1    itojun 		(a)->addr32[0] = htonl(ntohl((a)->addr32[0]) + 1); \
    327   1.1    itojun 	} while (0)
    328   1.1    itojun 
    329   1.1    itojun #define PF_POOLMASK(a, b, c, d, f) \
    330   1.1    itojun 	do { \
    331   1.1    itojun 		(a)->addr32[0] = ((b)->addr32[0] & (c)->addr32[0]) | \
    332   1.1    itojun 		(((c)->addr32[0] ^ 0xffffffff ) & (d)->addr32[0]); \
    333   1.1    itojun 	} while (0)
    334   1.1    itojun 
    335   1.1    itojun #endif /* PF_INET_ONLY */
    336   1.1    itojun #endif /* PF_INET6_ONLY */
    337   1.1    itojun #endif /* PF_INET_INET6 */
    338   1.1    itojun 
    339  1.16      yamt #define	PF_MISMATCHAW(aw, x, af, neg, ifp)				\
    340  1.16      yamt 	(								\
    341  1.16      yamt 		(((aw)->type == PF_ADDR_NOROUTE &&			\
    342  1.16      yamt 		    pf_routable((x), (af), NULL)) ||			\
    343  1.16      yamt 		(((aw)->type == PF_ADDR_URPFFAILED && (ifp) != NULL &&	\
    344  1.16      yamt 		    pf_routable((x), (af), (ifp))) ||			\
    345  1.16      yamt 		((aw)->type == PF_ADDR_RTLABEL &&			\
    346  1.16      yamt 		    !pf_rtlabel_match((x), (af), (aw))) ||		\
    347  1.16      yamt 		((aw)->type == PF_ADDR_TABLE &&				\
    348  1.16      yamt 		    !pfr_match_addr((aw)->p.tbl, (x), (af))) ||		\
    349  1.16      yamt 		((aw)->type == PF_ADDR_DYNIFTL &&			\
    350  1.16      yamt 		    !pfi_match_addr((aw)->p.dyn, (x), (af))) || 	\
    351  1.16      yamt 		((aw)->type == PF_ADDR_ADDRMASK &&			\
    352  1.16      yamt 		    !PF_AZERO(&(aw)->v.a.mask, (af)) &&			\
    353  1.16      yamt 		    !PF_MATCHA(0, &(aw)->v.a.addr,			\
    354  1.16      yamt 		    &(aw)->v.a.mask, (x), (af))))) !=			\
    355  1.16      yamt 		(neg)							\
    356   1.1    itojun 	)
    357   1.1    itojun 
    358  1.16      yamt 
    359   1.1    itojun struct pf_rule_uid {
    360   1.1    itojun 	uid_t		 uid[2];
    361   1.1    itojun 	u_int8_t	 op;
    362   1.1    itojun };
    363   1.1    itojun 
    364   1.1    itojun struct pf_rule_gid {
    365   1.1    itojun 	uid_t		 gid[2];
    366   1.1    itojun 	u_int8_t	 op;
    367   1.1    itojun };
    368   1.1    itojun 
    369   1.1    itojun struct pf_rule_addr {
    370   1.1    itojun 	struct pf_addr_wrap	 addr;
    371   1.1    itojun 	u_int16_t		 port[2];
    372   1.6      yamt 	u_int8_t		 neg;
    373   1.1    itojun 	u_int8_t		 port_op;
    374   1.1    itojun };
    375   1.1    itojun 
    376   1.1    itojun struct pf_pooladdr {
    377   1.1    itojun 	struct pf_addr_wrap		 addr;
    378   1.1    itojun 	TAILQ_ENTRY(pf_pooladdr)	 entries;
    379   1.1    itojun 	char				 ifname[IFNAMSIZ];
    380   1.1    itojun 	struct pfi_kif			*kif;
    381   1.1    itojun };
    382   1.1    itojun 
    383   1.1    itojun TAILQ_HEAD(pf_palist, pf_pooladdr);
    384   1.1    itojun 
    385   1.1    itojun struct pf_poolhashkey {
    386   1.1    itojun 	union {
    387   1.1    itojun 		u_int8_t		key8[16];
    388   1.1    itojun 		u_int16_t		key16[8];
    389   1.1    itojun 		u_int32_t		key32[4];
    390   1.1    itojun 	} pfk;		    /* 128-bit hash key */
    391   1.1    itojun #define key8	pfk.key8
    392   1.1    itojun #define key16	pfk.key16
    393   1.1    itojun #define key32	pfk.key32
    394   1.1    itojun };
    395   1.1    itojun 
    396   1.1    itojun struct pf_pool {
    397   1.1    itojun 	struct pf_palist	 list;
    398   1.1    itojun 	struct pf_pooladdr	*cur;
    399   1.1    itojun 	struct pf_poolhashkey	 key;
    400   1.1    itojun 	struct pf_addr		 counter;
    401   1.1    itojun 	int			 tblidx;
    402   1.1    itojun 	u_int16_t		 proxy_port[2];
    403   1.1    itojun 	u_int8_t		 port_op;
    404   1.1    itojun 	u_int8_t		 opts;
    405   1.1    itojun };
    406   1.1    itojun 
    407   1.1    itojun 
    408   1.1    itojun /* A packed Operating System description for fingerprinting */
    409   1.1    itojun typedef u_int32_t pf_osfp_t;
    410   1.1    itojun #define PF_OSFP_ANY	((pf_osfp_t)0)
    411   1.1    itojun #define PF_OSFP_UNKNOWN	((pf_osfp_t)-1)
    412   1.1    itojun #define PF_OSFP_NOMATCH	((pf_osfp_t)-2)
    413   1.1    itojun 
    414   1.1    itojun struct pf_osfp_entry {
    415   1.1    itojun 	SLIST_ENTRY(pf_osfp_entry) fp_entry;
    416   1.1    itojun 	pf_osfp_t		fp_os;
    417   1.1    itojun 	int			fp_enflags;
    418   1.1    itojun #define PF_OSFP_EXPANDED	0x001		/* expanded entry */
    419   1.1    itojun #define PF_OSFP_GENERIC		0x002		/* generic signature */
    420   1.1    itojun #define PF_OSFP_NODETAIL	0x004		/* no p0f details */
    421   1.1    itojun #define PF_OSFP_LEN	32
    422   1.1    itojun 	char			fp_class_nm[PF_OSFP_LEN];
    423   1.1    itojun 	char			fp_version_nm[PF_OSFP_LEN];
    424   1.1    itojun 	char			fp_subtype_nm[PF_OSFP_LEN];
    425   1.1    itojun };
    426   1.1    itojun #define PF_OSFP_ENTRY_EQ(a, b) \
    427   1.1    itojun     ((a)->fp_os == (b)->fp_os && \
    428   1.1    itojun     memcmp((a)->fp_class_nm, (b)->fp_class_nm, PF_OSFP_LEN) == 0 && \
    429   1.1    itojun     memcmp((a)->fp_version_nm, (b)->fp_version_nm, PF_OSFP_LEN) == 0 && \
    430   1.1    itojun     memcmp((a)->fp_subtype_nm, (b)->fp_subtype_nm, PF_OSFP_LEN) == 0)
    431   1.1    itojun 
    432   1.1    itojun /* handle pf_osfp_t packing */
    433   1.1    itojun #define _FP_RESERVED_BIT	1  /* For the special negative #defines */
    434   1.1    itojun #define _FP_UNUSED_BITS		1
    435   1.1    itojun #define _FP_CLASS_BITS		10 /* OS Class (Windows, Linux) */
    436   1.1    itojun #define _FP_VERSION_BITS	10 /* OS version (95, 98, NT, 2.4.54, 3.2) */
    437   1.1    itojun #define _FP_SUBTYPE_BITS	10 /* patch level (NT SP4, SP3, ECN patch) */
    438   1.1    itojun #define PF_OSFP_UNPACK(osfp, class, version, subtype) do { \
    439   1.1    itojun 	(class) = ((osfp) >> (_FP_VERSION_BITS+_FP_SUBTYPE_BITS)) & \
    440   1.1    itojun 	    ((1 << _FP_CLASS_BITS) - 1); \
    441   1.1    itojun 	(version) = ((osfp) >> _FP_SUBTYPE_BITS) & \
    442   1.1    itojun 	    ((1 << _FP_VERSION_BITS) - 1);\
    443   1.1    itojun 	(subtype) = (osfp) & ((1 << _FP_SUBTYPE_BITS) - 1); \
    444   1.1    itojun } while(0)
    445   1.1    itojun #define PF_OSFP_PACK(osfp, class, version, subtype) do { \
    446   1.1    itojun 	(osfp) = ((class) & ((1 << _FP_CLASS_BITS) - 1)) << (_FP_VERSION_BITS \
    447   1.1    itojun 	    + _FP_SUBTYPE_BITS); \
    448   1.1    itojun 	(osfp) |= ((version) & ((1 << _FP_VERSION_BITS) - 1)) << \
    449   1.1    itojun 	    _FP_SUBTYPE_BITS; \
    450   1.1    itojun 	(osfp) |= (subtype) & ((1 << _FP_SUBTYPE_BITS) - 1); \
    451   1.1    itojun } while(0)
    452   1.1    itojun 
    453   1.1    itojun /* the fingerprint of an OSes TCP SYN packet */
    454   1.1    itojun typedef u_int64_t	pf_tcpopts_t;
    455   1.1    itojun struct pf_os_fingerprint {
    456   1.1    itojun 	SLIST_HEAD(pf_osfp_enlist, pf_osfp_entry) fp_oses; /* list of matches */
    457   1.1    itojun 	pf_tcpopts_t		fp_tcpopts;	/* packed TCP options */
    458   1.1    itojun 	u_int16_t		fp_wsize;	/* TCP window size */
    459   1.1    itojun 	u_int16_t		fp_psize;	/* ip->ip_len */
    460   1.1    itojun 	u_int16_t		fp_mss;		/* TCP MSS */
    461   1.1    itojun 	u_int16_t		fp_flags;
    462   1.1    itojun #define PF_OSFP_WSIZE_MOD	0x0001		/* Window modulus */
    463   1.1    itojun #define PF_OSFP_WSIZE_DC	0x0002		/* Window don't care */
    464   1.1    itojun #define PF_OSFP_WSIZE_MSS	0x0004		/* Window multiple of MSS */
    465   1.1    itojun #define PF_OSFP_WSIZE_MTU	0x0008		/* Window multiple of MTU */
    466   1.1    itojun #define PF_OSFP_PSIZE_MOD	0x0010		/* packet size modulus */
    467   1.1    itojun #define PF_OSFP_PSIZE_DC	0x0020		/* packet size don't care */
    468   1.1    itojun #define PF_OSFP_WSCALE		0x0040		/* TCP window scaling */
    469   1.1    itojun #define PF_OSFP_WSCALE_MOD	0x0080		/* TCP window scale modulus */
    470   1.1    itojun #define PF_OSFP_WSCALE_DC	0x0100		/* TCP window scale dont-care */
    471   1.1    itojun #define PF_OSFP_MSS		0x0200		/* TCP MSS */
    472   1.1    itojun #define PF_OSFP_MSS_MOD		0x0400		/* TCP MSS modulus */
    473   1.1    itojun #define PF_OSFP_MSS_DC		0x0800		/* TCP MSS dont-care */
    474   1.1    itojun #define PF_OSFP_DF		0x1000		/* IPv4 don't fragment bit */
    475   1.1    itojun #define PF_OSFP_TS0		0x2000		/* Zero timestamp */
    476  1.16      yamt #define PF_OSFP_INET6		0x4000		/* IPv6 */
    477   1.1    itojun 	u_int8_t		fp_optcnt;	/* TCP option count */
    478   1.1    itojun 	u_int8_t		fp_wscale;	/* TCP window scaling */
    479   1.1    itojun 	u_int8_t		fp_ttl;		/* IPv4 TTL */
    480   1.1    itojun #define PF_OSFP_MAXTTL_OFFSET	40
    481   1.1    itojun /* TCP options packing */
    482   1.1    itojun #define PF_OSFP_TCPOPT_NOP	0x0		/* TCP NOP option */
    483   1.1    itojun #define PF_OSFP_TCPOPT_WSCALE	0x1		/* TCP window scaling option */
    484   1.1    itojun #define PF_OSFP_TCPOPT_MSS	0x2		/* TCP max segment size opt */
    485   1.1    itojun #define PF_OSFP_TCPOPT_SACK	0x3		/* TCP SACK OK option */
    486   1.1    itojun #define PF_OSFP_TCPOPT_TS	0x4		/* TCP timestamp option */
    487   1.1    itojun #define PF_OSFP_TCPOPT_BITS	3		/* bits used by each option */
    488   1.1    itojun #define PF_OSFP_MAX_OPTS \
    489   1.1    itojun     (sizeof(((struct pf_os_fingerprint *)0)->fp_tcpopts) * 8) \
    490   1.1    itojun     / PF_OSFP_TCPOPT_BITS
    491   1.1    itojun 
    492   1.1    itojun 	SLIST_ENTRY(pf_os_fingerprint)	fp_next;
    493   1.1    itojun };
    494   1.1    itojun 
    495   1.1    itojun struct pf_osfp_ioctl {
    496   1.1    itojun 	struct pf_osfp_entry	fp_os;
    497   1.1    itojun 	pf_tcpopts_t		fp_tcpopts;	/* packed TCP options */
    498   1.1    itojun 	u_int16_t		fp_wsize;	/* TCP window size */
    499   1.1    itojun 	u_int16_t		fp_psize;	/* ip->ip_len */
    500   1.1    itojun 	u_int16_t		fp_mss;		/* TCP MSS */
    501   1.1    itojun 	u_int16_t		fp_flags;
    502   1.1    itojun 	u_int8_t		fp_optcnt;	/* TCP option count */
    503   1.1    itojun 	u_int8_t		fp_wscale;	/* TCP window scaling */
    504   1.1    itojun 	u_int8_t		fp_ttl;		/* IPv4 TTL */
    505   1.1    itojun 
    506   1.1    itojun 	int			fp_getnum;	/* DIOCOSFPGET number */
    507   1.1    itojun };
    508   1.1    itojun 
    509   1.1    itojun 
    510   1.1    itojun union pf_rule_ptr {
    511   1.1    itojun 	struct pf_rule		*ptr;
    512   1.1    itojun 	u_int32_t		 nr;
    513   1.1    itojun };
    514   1.1    itojun 
    515   1.6      yamt #define	PF_ANCHOR_NAME_SIZE	 64
    516   1.6      yamt 
    517   1.1    itojun struct pf_rule {
    518   1.1    itojun 	struct pf_rule_addr	 src;
    519   1.1    itojun 	struct pf_rule_addr	 dst;
    520   1.1    itojun #define PF_SKIP_IFP		0
    521   1.1    itojun #define PF_SKIP_DIR		1
    522   1.1    itojun #define PF_SKIP_AF		2
    523   1.1    itojun #define PF_SKIP_PROTO		3
    524   1.1    itojun #define PF_SKIP_SRC_ADDR	4
    525   1.1    itojun #define PF_SKIP_SRC_PORT	5
    526   1.1    itojun #define PF_SKIP_DST_ADDR	6
    527   1.1    itojun #define PF_SKIP_DST_PORT	7
    528   1.1    itojun #define PF_SKIP_COUNT		8
    529   1.1    itojun 	union pf_rule_ptr	 skip[PF_SKIP_COUNT];
    530   1.1    itojun #define PF_RULE_LABEL_SIZE	 64
    531   1.1    itojun 	char			 label[PF_RULE_LABEL_SIZE];
    532  1.16      yamt #define PF_QNAME_SIZE		 64
    533   1.1    itojun 	char			 ifname[IFNAMSIZ];
    534   1.1    itojun 	char			 qname[PF_QNAME_SIZE];
    535   1.1    itojun 	char			 pqname[PF_QNAME_SIZE];
    536  1.16      yamt #define	PF_TAG_NAME_SIZE	 64
    537   1.1    itojun 	char			 tagname[PF_TAG_NAME_SIZE];
    538   1.1    itojun 	char			 match_tagname[PF_TAG_NAME_SIZE];
    539   1.1    itojun 
    540   1.9     peter 	char			 overload_tblname[PF_TABLE_NAME_SIZE];
    541   1.9     peter 
    542   1.1    itojun 	TAILQ_ENTRY(pf_rule)	 entries;
    543   1.1    itojun 	struct pf_pool		 rpool;
    544   1.1    itojun 
    545   1.1    itojun 	u_int64_t		 evaluations;
    546  1.16      yamt 	u_int64_t		 packets[2];
    547  1.16      yamt 	u_int64_t		 bytes[2];
    548   1.1    itojun 
    549   1.1    itojun 	struct pfi_kif		*kif;
    550   1.1    itojun 	struct pf_anchor	*anchor;
    551   1.9     peter 	struct pfr_ktable	*overload_tbl;
    552   1.1    itojun 
    553   1.1    itojun 	pf_osfp_t		 os_fingerprint;
    554   1.1    itojun 
    555  1.16      yamt 	int			 rtableid;
    556   1.1    itojun 	u_int32_t		 timeout[PFTM_MAX];
    557   1.1    itojun 	u_int32_t		 states;
    558   1.1    itojun 	u_int32_t		 max_states;
    559   1.1    itojun 	u_int32_t		 src_nodes;
    560   1.1    itojun 	u_int32_t		 max_src_nodes;
    561   1.1    itojun 	u_int32_t		 max_src_states;
    562   1.9     peter 	u_int32_t		 max_src_conn;
    563   1.9     peter 	struct {
    564   1.9     peter 		u_int32_t		limit;
    565   1.9     peter 		u_int32_t		seconds;
    566   1.9     peter 	}			 max_src_conn_rate;
    567   1.1    itojun 	u_int32_t		 qid;
    568   1.1    itojun 	u_int32_t		 pqid;
    569   1.1    itojun 	u_int32_t		 rt_listid;
    570   1.1    itojun 	u_int32_t		 nr;
    571   1.6      yamt 	u_int32_t		 prob;
    572  1.16      yamt 	uid_t			 cuid;
    573  1.16      yamt 	pid_t			 cpid;
    574   1.1    itojun 
    575   1.1    itojun 	u_int16_t		 return_icmp;
    576   1.1    itojun 	u_int16_t		 return_icmp6;
    577   1.1    itojun 	u_int16_t		 max_mss;
    578   1.1    itojun 	u_int16_t		 tag;
    579   1.1    itojun 	u_int16_t		 match_tag;
    580   1.1    itojun 
    581   1.1    itojun 	struct pf_rule_uid	 uid;
    582   1.1    itojun 	struct pf_rule_gid	 gid;
    583   1.1    itojun 
    584   1.1    itojun 	u_int32_t		 rule_flag;
    585   1.1    itojun 	u_int8_t		 action;
    586   1.1    itojun 	u_int8_t		 direction;
    587   1.1    itojun 	u_int8_t		 log;
    588  1.16      yamt 	u_int8_t		 logif;
    589   1.1    itojun 	u_int8_t		 quick;
    590   1.1    itojun 	u_int8_t		 ifnot;
    591   1.1    itojun 	u_int8_t		 match_tag_not;
    592   1.1    itojun 	u_int8_t		 natpass;
    593   1.1    itojun 
    594   1.1    itojun #define PF_STATE_NORMAL		0x1
    595   1.1    itojun #define PF_STATE_MODULATE	0x2
    596   1.1    itojun #define PF_STATE_SYNPROXY	0x3
    597   1.1    itojun 	u_int8_t		 keep_state;
    598   1.1    itojun 	sa_family_t		 af;
    599   1.1    itojun 	u_int8_t		 proto;
    600   1.1    itojun 	u_int8_t		 type;
    601   1.1    itojun 	u_int8_t		 code;
    602   1.1    itojun 	u_int8_t		 flags;
    603   1.1    itojun 	u_int8_t		 flagset;
    604   1.1    itojun 	u_int8_t		 min_ttl;
    605   1.1    itojun 	u_int8_t		 allow_opts;
    606   1.1    itojun 	u_int8_t		 rt;
    607   1.1    itojun 	u_int8_t		 return_ttl;
    608   1.1    itojun 	u_int8_t		 tos;
    609   1.6      yamt 	u_int8_t		 anchor_relative;
    610   1.6      yamt 	u_int8_t		 anchor_wildcard;
    611   1.9     peter 
    612   1.9     peter #define PF_FLUSH		0x01
    613   1.9     peter #define PF_FLUSH_GLOBAL		0x02
    614   1.9     peter 	u_int8_t		 flush;
    615   1.1    itojun };
    616   1.1    itojun 
    617   1.1    itojun /* rule flags */
    618   1.1    itojun #define	PFRULE_DROP		0x0000
    619   1.1    itojun #define	PFRULE_RETURNRST	0x0001
    620   1.1    itojun #define	PFRULE_FRAGMENT		0x0002
    621   1.1    itojun #define	PFRULE_RETURNICMP	0x0004
    622   1.1    itojun #define	PFRULE_RETURN		0x0008
    623   1.1    itojun #define	PFRULE_NOSYNC		0x0010
    624   1.1    itojun #define PFRULE_SRCTRACK		0x0020  /* track source states */
    625   1.1    itojun #define PFRULE_RULESRCTRACK	0x0040  /* per rule */
    626   1.1    itojun 
    627   1.1    itojun /* scrub flags */
    628   1.1    itojun #define	PFRULE_NODF		0x0100
    629   1.1    itojun #define	PFRULE_FRAGCROP		0x0200	/* non-buffering frag cache */
    630   1.1    itojun #define	PFRULE_FRAGDROP		0x0400	/* drop funny fragments */
    631   1.1    itojun #define PFRULE_RANDOMID		0x0800
    632   1.1    itojun #define PFRULE_REASSEMBLE_TCP	0x1000
    633   1.1    itojun 
    634   1.1    itojun /* rule flags again */
    635   1.1    itojun #define PFRULE_IFBOUND		0x00010000	/* if-bound */
    636   1.1    itojun 
    637   1.1    itojun #define PFSTATE_HIWAT		10000	/* default state table size */
    638  1.16      yamt #define PFSTATE_ADAPT_START	6000	/* default adaptive timeout start */
    639  1.16      yamt #define PFSTATE_ADAPT_END	12000	/* default adaptive timeout end */
    640   1.1    itojun 
    641   1.9     peter 
    642   1.9     peter struct pf_threshold {
    643   1.9     peter 	u_int32_t	limit;
    644   1.9     peter #define	PF_THRESHOLD_MULT	1000
    645   1.9     peter #define PF_THRESHOLD_MAX	0xffffffff / PF_THRESHOLD_MULT
    646   1.9     peter 	u_int32_t	seconds;
    647   1.9     peter 	u_int32_t	count;
    648   1.9     peter 	u_int32_t	last;
    649   1.9     peter };
    650   1.9     peter 
    651   1.1    itojun struct pf_src_node {
    652   1.1    itojun 	RB_ENTRY(pf_src_node) entry;
    653   1.1    itojun 	struct pf_addr	 addr;
    654   1.1    itojun 	struct pf_addr	 raddr;
    655   1.1    itojun 	union pf_rule_ptr rule;
    656   1.1    itojun 	struct pfi_kif	*kif;
    657  1.16      yamt 	u_int64_t	 bytes[2];
    658  1.16      yamt 	u_int64_t	 packets[2];
    659   1.1    itojun 	u_int32_t	 states;
    660   1.9     peter 	u_int32_t	 conn;
    661   1.9     peter 	struct pf_threshold	conn_rate;
    662   1.1    itojun 	u_int32_t	 creation;
    663   1.1    itojun 	u_int32_t	 expire;
    664   1.1    itojun 	sa_family_t	 af;
    665   1.1    itojun 	u_int8_t	 ruletype;
    666   1.1    itojun };
    667   1.1    itojun 
    668   1.1    itojun #define PFSNODE_HIWAT		10000	/* default source node table size */
    669   1.1    itojun 
    670   1.1    itojun struct pf_state_scrub {
    671   1.6      yamt 	struct timeval	pfss_last;	/* time received last packet	*/
    672   1.6      yamt 	u_int32_t	pfss_tsecr;	/* last echoed timestamp	*/
    673   1.6      yamt 	u_int32_t	pfss_tsval;	/* largest timestamp		*/
    674   1.6      yamt 	u_int32_t	pfss_tsval0;	/* original timestamp		*/
    675   1.1    itojun 	u_int16_t	pfss_flags;
    676   1.6      yamt #define PFSS_TIMESTAMP	0x0001		/* modulate timestamp		*/
    677   1.6      yamt #define PFSS_PAWS	0x0010		/* stricter PAWS checks		*/
    678   1.6      yamt #define PFSS_PAWS_IDLED	0x0020		/* was idle too long.  no PAWS	*/
    679   1.6      yamt #define PFSS_DATA_TS	0x0040		/* timestamp on data packets	*/
    680   1.6      yamt #define PFSS_DATA_NOTS	0x0080		/* no timestamp on data packets	*/
    681   1.6      yamt 	u_int8_t	pfss_ttl;	/* stashed TTL			*/
    682   1.1    itojun 	u_int8_t	pad;
    683   1.6      yamt 	u_int32_t	pfss_ts_mod;	/* timestamp modulation		*/
    684   1.1    itojun };
    685   1.1    itojun 
    686   1.1    itojun struct pf_state_host {
    687   1.1    itojun 	struct pf_addr	addr;
    688   1.1    itojun 	u_int16_t	port;
    689   1.1    itojun 	u_int16_t	pad;
    690   1.1    itojun };
    691   1.1    itojun 
    692   1.1    itojun struct pf_state_peer {
    693   1.1    itojun 	u_int32_t	seqlo;		/* Max sequence number sent	*/
    694   1.1    itojun 	u_int32_t	seqhi;		/* Max the other end ACKd + win	*/
    695   1.1    itojun 	u_int32_t	seqdiff;	/* Sequence number modulator	*/
    696   1.1    itojun 	u_int16_t	max_win;	/* largest window (pre scaling)	*/
    697   1.1    itojun 	u_int8_t	state;		/* active state level		*/
    698   1.1    itojun 	u_int8_t	wscale;		/* window scaling factor	*/
    699   1.1    itojun 	u_int16_t	mss;		/* Maximum segment size option	*/
    700  1.16      yamt 	u_int8_t	tcp_est;	/* Did we reach TCPS_ESTABLISHED */
    701   1.1    itojun 	struct pf_state_scrub	*scrub;	/* state is scrubbed		*/
    702  1.16      yamt 	u_int8_t	pad[3];
    703   1.1    itojun };
    704   1.1    itojun 
    705   1.1    itojun TAILQ_HEAD(pf_state_queue, pf_state);
    706   1.1    itojun 
    707  1.16      yamt /* keep synced with struct pf_state_key, used in RB_FIND */
    708  1.16      yamt struct pf_state_key_cmp {
    709  1.16      yamt 	struct pf_state_host lan;
    710  1.16      yamt 	struct pf_state_host gwy;
    711  1.16      yamt 	struct pf_state_host ext;
    712  1.16      yamt 	sa_family_t	 af;
    713  1.16      yamt 	u_int8_t	 proto;
    714  1.16      yamt 	u_int8_t	 direction;
    715  1.16      yamt 	u_int8_t	 pad;
    716  1.16      yamt };
    717  1.16      yamt 
    718  1.16      yamt TAILQ_HEAD(pf_statelist, pf_state);
    719  1.16      yamt 
    720  1.16      yamt struct pf_state_key {
    721   1.1    itojun 	struct pf_state_host lan;
    722   1.1    itojun 	struct pf_state_host gwy;
    723   1.1    itojun 	struct pf_state_host ext;
    724  1.16      yamt 	sa_family_t	 af;
    725  1.16      yamt 	u_int8_t	 proto;
    726  1.16      yamt 	u_int8_t	 direction;
    727  1.16      yamt 	u_int8_t	 pad;
    728  1.16      yamt 
    729  1.16      yamt 	RB_ENTRY(pf_state_key)	 entry_lan_ext;
    730  1.16      yamt 	RB_ENTRY(pf_state_key)	 entry_ext_gwy;
    731  1.16      yamt 	struct pf_statelist	 states;
    732  1.16      yamt 	u_short		 refcnt;	/* same size as if_index */
    733  1.16      yamt };
    734  1.16      yamt 
    735  1.16      yamt 
    736  1.16      yamt /* keep synced with struct pf_state, used in RB_FIND */
    737  1.16      yamt struct pf_state_cmp {
    738  1.16      yamt 	u_int64_t	 id;
    739  1.16      yamt 	u_int32_t	 creatorid;
    740  1.16      yamt 	u_int32_t	 pad;
    741  1.16      yamt };
    742  1.16      yamt 
    743  1.16      yamt struct pf_state {
    744  1.16      yamt 	u_int64_t		 id;
    745  1.16      yamt 	u_int32_t		 creatorid;
    746  1.16      yamt 	u_int32_t		 pad;
    747  1.16      yamt 
    748  1.16      yamt 	TAILQ_ENTRY(pf_state)	 entry_list;
    749  1.16      yamt 	TAILQ_ENTRY(pf_state)	 next;
    750  1.16      yamt 	RB_ENTRY(pf_state)	 entry_id;
    751  1.16      yamt 	struct pf_state_peer	 src;
    752  1.16      yamt 	struct pf_state_peer	 dst;
    753  1.16      yamt 	union pf_rule_ptr	 rule;
    754  1.16      yamt 	union pf_rule_ptr	 anchor;
    755  1.16      yamt 	union pf_rule_ptr	 nat_rule;
    756  1.16      yamt 	struct pf_addr		 rt_addr;
    757  1.16      yamt 	struct pf_state_key	*state_key;
    758  1.16      yamt 	struct pfi_kif		*kif;
    759  1.16      yamt 	struct pfi_kif		*rt_kif;
    760   1.1    itojun 	struct pf_src_node	*src_node;
    761   1.1    itojun 	struct pf_src_node	*nat_src_node;
    762  1.16      yamt 	u_int64_t		 packets[2];
    763  1.16      yamt 	u_int64_t		 bytes[2];
    764  1.16      yamt 	u_int32_t		 creation;
    765  1.16      yamt 	u_int32_t		 expire;
    766  1.16      yamt 	u_int32_t		 pfsync_time;
    767  1.16      yamt 	u_int16_t		 tag;
    768  1.16      yamt 	u_int8_t		 log;
    769  1.16      yamt 	u_int8_t		 allow_opts;
    770  1.16      yamt 	u_int8_t		 timeout;
    771  1.16      yamt 	u_int8_t		 sync_flags;
    772  1.16      yamt #define	PFSTATE_NOSYNC	 0x01
    773  1.16      yamt #define	PFSTATE_FROMSYNC 0x02
    774  1.16      yamt #define	PFSTATE_STALE	 0x04
    775  1.16      yamt };
    776  1.16      yamt 
    777  1.16      yamt /*
    778  1.16      yamt  * Unified state structures for pulling states out of the kernel
    779  1.16      yamt  * used by pfsync(4) and the pf(4) ioctl.
    780  1.16      yamt  */
    781  1.16      yamt struct pfsync_state_scrub {
    782  1.16      yamt 	u_int16_t	pfss_flags;
    783  1.16      yamt 	u_int8_t	pfss_ttl;	/* stashed TTL		*/
    784  1.16      yamt #define PFSYNC_SCRUB_FLAG_VALID 	0x01
    785  1.16      yamt 	u_int8_t	scrub_flag;
    786  1.16      yamt 	u_int32_t	pfss_ts_mod;	/* timestamp modulation	*/
    787  1.16      yamt } __packed;
    788  1.16      yamt 
    789  1.16      yamt struct pfsync_state_host {
    790  1.16      yamt 	struct pf_addr	addr;
    791  1.16      yamt 	u_int16_t	port;
    792  1.16      yamt 	u_int16_t	pad[3];
    793  1.16      yamt } __packed;
    794  1.16      yamt 
    795  1.16      yamt struct pfsync_state_peer {
    796  1.16      yamt 	struct pfsync_state_scrub scrub;	/* state is scrubbed	*/
    797  1.16      yamt 	u_int32_t	seqlo;		/* Max sequence number sent	*/
    798  1.16      yamt 	u_int32_t	seqhi;		/* Max the other end ACKd + win	*/
    799  1.16      yamt 	u_int32_t	seqdiff;	/* Sequence number modulator	*/
    800  1.16      yamt 	u_int16_t	max_win;	/* largest window (pre scaling)	*/
    801  1.16      yamt 	u_int16_t	mss;		/* Maximum segment size option	*/
    802  1.16      yamt 	u_int8_t	state;		/* active state level		*/
    803  1.16      yamt 	u_int8_t	wscale;		/* window scaling factor	*/
    804  1.16      yamt 	u_int8_t	pad[6];
    805  1.16      yamt } __packed;
    806  1.16      yamt 
    807  1.16      yamt struct pfsync_state {
    808  1.16      yamt 	u_int32_t	 id[2];
    809  1.16      yamt 	char		 ifname[IFNAMSIZ];
    810  1.16      yamt 	struct pfsync_state_host lan;
    811  1.16      yamt 	struct pfsync_state_host gwy;
    812  1.16      yamt 	struct pfsync_state_host ext;
    813  1.16      yamt 	struct pfsync_state_peer src;
    814  1.16      yamt 	struct pfsync_state_peer dst;
    815  1.16      yamt 	struct pf_addr	 rt_addr;
    816  1.16      yamt 	u_int32_t	 rule;
    817  1.16      yamt 	u_int32_t	 anchor;
    818  1.16      yamt 	u_int32_t	 nat_rule;
    819   1.1    itojun 	u_int32_t	 creation;
    820   1.1    itojun 	u_int32_t	 expire;
    821  1.16      yamt 	u_int32_t	 packets[2][2];
    822  1.16      yamt 	u_int32_t	 bytes[2][2];
    823   1.1    itojun 	u_int32_t	 creatorid;
    824   1.1    itojun 	sa_family_t	 af;
    825   1.1    itojun 	u_int8_t	 proto;
    826   1.1    itojun 	u_int8_t	 direction;
    827   1.1    itojun 	u_int8_t	 log;
    828   1.1    itojun 	u_int8_t	 allow_opts;
    829   1.1    itojun 	u_int8_t	 timeout;
    830   1.1    itojun 	u_int8_t	 sync_flags;
    831  1.16      yamt 	u_int8_t	 updates;
    832  1.16      yamt } __packed;
    833  1.16      yamt 
    834  1.16      yamt #define PFSYNC_FLAG_COMPRESS 	0x01
    835  1.16      yamt #define PFSYNC_FLAG_STALE	0x02
    836  1.16      yamt #define PFSYNC_FLAG_SRCNODE	0x04
    837  1.16      yamt #define PFSYNC_FLAG_NATSRCNODE	0x08
    838  1.16      yamt 
    839  1.16      yamt /* for copies to/from userland via pf_ioctl() */
    840  1.16      yamt #define pf_state_peer_to_pfsync(s,d) do {	\
    841  1.16      yamt 	(d)->seqlo = (s)->seqlo;		\
    842  1.16      yamt 	(d)->seqhi = (s)->seqhi;		\
    843  1.16      yamt 	(d)->seqdiff = (s)->seqdiff;		\
    844  1.16      yamt 	(d)->max_win = (s)->max_win;		\
    845  1.16      yamt 	(d)->mss = (s)->mss;			\
    846  1.16      yamt 	(d)->state = (s)->state;		\
    847  1.16      yamt 	(d)->wscale = (s)->wscale;		\
    848  1.16      yamt 	if ((s)->scrub) {						\
    849  1.16      yamt 		(d)->scrub.pfss_flags = 				\
    850  1.16      yamt 		    (s)->scrub->pfss_flags & PFSS_TIMESTAMP;		\
    851  1.16      yamt 		(d)->scrub.pfss_ttl = (s)->scrub->pfss_ttl;		\
    852  1.16      yamt 		(d)->scrub.pfss_ts_mod = (s)->scrub->pfss_ts_mod;	\
    853  1.16      yamt 		(d)->scrub.scrub_flag = PFSYNC_SCRUB_FLAG_VALID;	\
    854  1.16      yamt 	}								\
    855  1.16      yamt } while (0)
    856  1.16      yamt 
    857  1.16      yamt #define pf_state_peer_from_pfsync(s,d) do {	\
    858  1.16      yamt 	(d)->seqlo = (s)->seqlo;		\
    859  1.16      yamt 	(d)->seqhi = (s)->seqhi;		\
    860  1.16      yamt 	(d)->seqdiff = (s)->seqdiff;		\
    861  1.16      yamt 	(d)->max_win = (s)->max_win;		\
    862  1.16      yamt 	(d)->mss = ntohs((s)->mss);		\
    863  1.16      yamt 	(d)->state = (s)->state;		\
    864  1.16      yamt 	(d)->wscale = (s)->wscale;		\
    865  1.16      yamt 	if ((s)->scrub.scrub_flag == PFSYNC_SCRUB_FLAG_VALID && 	\
    866  1.16      yamt 	    (d)->scrub != NULL) {					\
    867  1.16      yamt 		(d)->scrub->pfss_flags =				\
    868  1.16      yamt 		    ntohs((s)->scrub.pfss_flags) & PFSS_TIMESTAMP;	\
    869  1.16      yamt 		(d)->scrub->pfss_ttl = (s)->scrub.pfss_ttl;		\
    870  1.16      yamt 		(d)->scrub->pfss_ts_mod = (s)->scrub.pfss_ts_mod;	\
    871  1.16      yamt 	}								\
    872  1.16      yamt } while (0)
    873  1.16      yamt 
    874  1.16      yamt #define pf_state_counter_to_pfsync(s,d) do {			\
    875  1.16      yamt 	d[0] = (s>>32)&0xffffffff;				\
    876  1.16      yamt 	d[1] = s&0xffffffff;					\
    877  1.16      yamt } while (0)
    878  1.16      yamt 
    879  1.16      yamt #define pf_state_counter_from_pfsync(s)		\
    880  1.16      yamt 	(((u_int64_t)(s[0])<<32) | (u_int64_t)(s[1]))
    881  1.16      yamt 
    882  1.16      yamt 
    883   1.1    itojun 
    884   1.1    itojun TAILQ_HEAD(pf_rulequeue, pf_rule);
    885   1.1    itojun 
    886   1.1    itojun struct pf_anchor;
    887   1.1    itojun 
    888   1.1    itojun struct pf_ruleset {
    889   1.1    itojun 	struct {
    890   1.1    itojun 		struct pf_rulequeue	 queues[2];
    891   1.1    itojun 		struct {
    892   1.1    itojun 			struct pf_rulequeue	*ptr;
    893  1.16      yamt 			struct pf_rule		**ptr_array;
    894  1.16      yamt 			u_int32_t		 rcount;
    895   1.1    itojun 			u_int32_t		 ticket;
    896   1.1    itojun 			int			 open;
    897   1.1    itojun 		}			 active, inactive;
    898   1.1    itojun 	}			 rules[PF_RULESET_MAX];
    899   1.1    itojun 	struct pf_anchor	*anchor;
    900   1.1    itojun 	u_int32_t		 tticket;
    901   1.1    itojun 	int			 tables;
    902   1.1    itojun 	int			 topen;
    903   1.1    itojun };
    904   1.1    itojun 
    905   1.6      yamt RB_HEAD(pf_anchor_global, pf_anchor);
    906   1.6      yamt RB_HEAD(pf_anchor_node, pf_anchor);
    907   1.1    itojun struct pf_anchor {
    908   1.6      yamt 	RB_ENTRY(pf_anchor)	 entry_global;
    909   1.6      yamt 	RB_ENTRY(pf_anchor)	 entry_node;
    910   1.6      yamt 	struct pf_anchor	*parent;
    911   1.6      yamt 	struct pf_anchor_node	 children;
    912   1.1    itojun 	char			 name[PF_ANCHOR_NAME_SIZE];
    913   1.6      yamt 	char			 path[MAXPATHLEN];
    914   1.6      yamt 	struct pf_ruleset	 ruleset;
    915   1.6      yamt 	int			 refcnt;	/* anchor rules */
    916  1.16      yamt 	int			 match;
    917   1.1    itojun };
    918   1.6      yamt RB_PROTOTYPE(pf_anchor_global, pf_anchor, entry_global, pf_anchor_compare);
    919   1.6      yamt RB_PROTOTYPE(pf_anchor_node, pf_anchor, entry_node, pf_anchor_compare);
    920   1.1    itojun 
    921   1.1    itojun #define PF_RESERVED_ANCHOR	"_pf"
    922   1.1    itojun 
    923   1.1    itojun #define PFR_TFLAG_PERSIST	0x00000001
    924   1.1    itojun #define PFR_TFLAG_CONST		0x00000002
    925   1.1    itojun #define PFR_TFLAG_ACTIVE	0x00000004
    926   1.1    itojun #define PFR_TFLAG_INACTIVE	0x00000008
    927   1.1    itojun #define PFR_TFLAG_REFERENCED	0x00000010
    928   1.1    itojun #define PFR_TFLAG_REFDANCHOR	0x00000020
    929   1.1    itojun #define PFR_TFLAG_USRMASK	0x00000003
    930   1.1    itojun #define PFR_TFLAG_SETMASK	0x0000003C
    931   1.1    itojun #define PFR_TFLAG_ALLMASK	0x0000003F
    932   1.1    itojun 
    933   1.1    itojun struct pfr_table {
    934   1.6      yamt 	char			 pfrt_anchor[MAXPATHLEN];
    935   1.1    itojun 	char			 pfrt_name[PF_TABLE_NAME_SIZE];
    936   1.1    itojun 	u_int32_t		 pfrt_flags;
    937   1.1    itojun 	u_int8_t		 pfrt_fback;
    938   1.1    itojun };
    939   1.1    itojun 
    940   1.1    itojun enum { PFR_FB_NONE, PFR_FB_MATCH, PFR_FB_ADDED, PFR_FB_DELETED,
    941   1.1    itojun 	PFR_FB_CHANGED, PFR_FB_CLEARED, PFR_FB_DUPLICATE,
    942   1.1    itojun 	PFR_FB_NOTMATCH, PFR_FB_CONFLICT, PFR_FB_MAX };
    943   1.1    itojun 
    944   1.1    itojun struct pfr_addr {
    945   1.1    itojun 	union {
    946   1.1    itojun 		struct in_addr	 _pfra_ip4addr;
    947   1.1    itojun 		struct in6_addr	 _pfra_ip6addr;
    948   1.1    itojun 	}		 pfra_u;
    949   1.1    itojun 	u_int8_t	 pfra_af;
    950   1.1    itojun 	u_int8_t	 pfra_net;
    951   1.1    itojun 	u_int8_t	 pfra_not;
    952   1.1    itojun 	u_int8_t	 pfra_fback;
    953   1.1    itojun };
    954   1.1    itojun #define	pfra_ip4addr	pfra_u._pfra_ip4addr
    955   1.1    itojun #define	pfra_ip6addr	pfra_u._pfra_ip6addr
    956   1.1    itojun 
    957   1.1    itojun enum { PFR_DIR_IN, PFR_DIR_OUT, PFR_DIR_MAX };
    958   1.1    itojun enum { PFR_OP_BLOCK, PFR_OP_PASS, PFR_OP_ADDR_MAX, PFR_OP_TABLE_MAX };
    959   1.1    itojun #define PFR_OP_XPASS	PFR_OP_ADDR_MAX
    960   1.1    itojun 
    961   1.1    itojun struct pfr_astats {
    962   1.1    itojun 	struct pfr_addr	 pfras_a;
    963   1.1    itojun 	u_int64_t	 pfras_packets[PFR_DIR_MAX][PFR_OP_ADDR_MAX];
    964   1.1    itojun 	u_int64_t	 pfras_bytes[PFR_DIR_MAX][PFR_OP_ADDR_MAX];
    965   1.1    itojun 	long		 pfras_tzero;
    966   1.1    itojun };
    967   1.1    itojun 
    968   1.1    itojun enum { PFR_REFCNT_RULE, PFR_REFCNT_ANCHOR, PFR_REFCNT_MAX };
    969   1.1    itojun 
    970   1.1    itojun struct pfr_tstats {
    971   1.1    itojun 	struct pfr_table pfrts_t;
    972   1.1    itojun 	u_int64_t	 pfrts_packets[PFR_DIR_MAX][PFR_OP_TABLE_MAX];
    973   1.1    itojun 	u_int64_t	 pfrts_bytes[PFR_DIR_MAX][PFR_OP_TABLE_MAX];
    974   1.1    itojun 	u_int64_t	 pfrts_match;
    975   1.1    itojun 	u_int64_t	 pfrts_nomatch;
    976   1.1    itojun 	long		 pfrts_tzero;
    977   1.1    itojun 	int		 pfrts_cnt;
    978   1.1    itojun 	int		 pfrts_refcnt[PFR_REFCNT_MAX];
    979   1.1    itojun };
    980   1.1    itojun #define	pfrts_name	pfrts_t.pfrt_name
    981   1.1    itojun #define pfrts_flags	pfrts_t.pfrt_flags
    982   1.1    itojun 
    983  1.20  drochner #ifndef _SOCKADDR_UNION_DEFINED
    984  1.20  drochner #define _SOCKADDR_UNION_DEFINED
    985  1.20  drochner union sockaddr_union {
    986  1.20  drochner 	struct sockaddr		sa;
    987  1.20  drochner 	struct sockaddr_in	sin;
    988  1.20  drochner 	struct sockaddr_in6	sin6;
    989  1.20  drochner };
    990  1.20  drochner #endif /* _SOCKADDR_UNION_DEFINED */
    991  1.20  drochner 
    992   1.1    itojun SLIST_HEAD(pfr_kentryworkq, pfr_kentry);
    993   1.1    itojun struct pfr_kentry {
    994   1.1    itojun 	struct radix_node	 pfrke_node[2];
    995   1.1    itojun 	union sockaddr_union	 pfrke_sa;
    996   1.1    itojun 	u_int64_t		 pfrke_packets[PFR_DIR_MAX][PFR_OP_ADDR_MAX];
    997   1.1    itojun 	u_int64_t		 pfrke_bytes[PFR_DIR_MAX][PFR_OP_ADDR_MAX];
    998   1.1    itojun 	SLIST_ENTRY(pfr_kentry)	 pfrke_workq;
    999   1.1    itojun 	long			 pfrke_tzero;
   1000   1.1    itojun 	u_int8_t		 pfrke_af;
   1001   1.1    itojun 	u_int8_t		 pfrke_net;
   1002   1.1    itojun 	u_int8_t		 pfrke_not;
   1003   1.1    itojun 	u_int8_t		 pfrke_mark;
   1004   1.9     peter 	u_int8_t		 pfrke_intrpool;
   1005   1.1    itojun };
   1006   1.1    itojun 
   1007   1.1    itojun SLIST_HEAD(pfr_ktableworkq, pfr_ktable);
   1008   1.1    itojun RB_HEAD(pfr_ktablehead, pfr_ktable);
   1009   1.1    itojun struct pfr_ktable {
   1010   1.1    itojun 	struct pfr_tstats	 pfrkt_ts;
   1011   1.1    itojun 	RB_ENTRY(pfr_ktable)	 pfrkt_tree;
   1012   1.1    itojun 	SLIST_ENTRY(pfr_ktable)	 pfrkt_workq;
   1013   1.1    itojun 	struct radix_node_head	*pfrkt_ip4;
   1014   1.1    itojun 	struct radix_node_head	*pfrkt_ip6;
   1015   1.1    itojun 	struct pfr_ktable	*pfrkt_shadow;
   1016   1.1    itojun 	struct pfr_ktable	*pfrkt_root;
   1017   1.1    itojun 	struct pf_ruleset	*pfrkt_rs;
   1018   1.1    itojun 	long			 pfrkt_larg;
   1019   1.1    itojun 	int			 pfrkt_nflags;
   1020   1.1    itojun };
   1021   1.1    itojun #define pfrkt_t		pfrkt_ts.pfrts_t
   1022   1.1    itojun #define pfrkt_name	pfrkt_t.pfrt_name
   1023   1.1    itojun #define pfrkt_anchor	pfrkt_t.pfrt_anchor
   1024   1.1    itojun #define pfrkt_ruleset	pfrkt_t.pfrt_ruleset
   1025   1.1    itojun #define pfrkt_flags	pfrkt_t.pfrt_flags
   1026   1.1    itojun #define pfrkt_cnt	pfrkt_ts.pfrts_cnt
   1027   1.1    itojun #define pfrkt_refcnt	pfrkt_ts.pfrts_refcnt
   1028   1.1    itojun #define pfrkt_packets	pfrkt_ts.pfrts_packets
   1029   1.1    itojun #define pfrkt_bytes	pfrkt_ts.pfrts_bytes
   1030   1.1    itojun #define pfrkt_match	pfrkt_ts.pfrts_match
   1031   1.1    itojun #define pfrkt_nomatch	pfrkt_ts.pfrts_nomatch
   1032   1.1    itojun #define pfrkt_tzero	pfrkt_ts.pfrts_tzero
   1033   1.1    itojun 
   1034  1.16      yamt RB_HEAD(pf_state_tree_lan_ext, pf_state_key);
   1035  1.16      yamt RB_PROTOTYPE(pf_state_tree_lan_ext, pf_state_key,
   1036  1.16      yamt     entry_lan_ext, pf_state_compare_lan_ext);
   1037  1.16      yamt 
   1038  1.16      yamt RB_HEAD(pf_state_tree_ext_gwy, pf_state_key);
   1039  1.16      yamt RB_PROTOTYPE(pf_state_tree_ext_gwy, pf_state_key,
   1040  1.16      yamt     entry_ext_gwy, pf_state_compare_ext_gwy);
   1041  1.16      yamt 
   1042  1.16      yamt RB_HEAD(pfi_ifhead, pfi_kif);
   1043  1.16      yamt 
   1044  1.16      yamt /* state tables */
   1045  1.16      yamt extern struct pf_state_tree_lan_ext	 pf_statetbl_lan_ext;
   1046  1.16      yamt extern struct pf_state_tree_ext_gwy	 pf_statetbl_ext_gwy;
   1047  1.16      yamt 
   1048  1.16      yamt /* keep synced with pfi_kif, used in RB_FIND */
   1049  1.16      yamt struct pfi_kif_cmp {
   1050  1.16      yamt 	char				 pfik_name[IFNAMSIZ];
   1051   1.1    itojun };
   1052   1.1    itojun 
   1053   1.1    itojun struct pfi_kif {
   1054  1.16      yamt 	char				 pfik_name[IFNAMSIZ];
   1055   1.1    itojun 	RB_ENTRY(pfi_kif)		 pfik_tree;
   1056  1.16      yamt 	u_int64_t			 pfik_packets[2][2][2];
   1057  1.16      yamt 	u_int64_t			 pfik_bytes[2][2][2];
   1058  1.16      yamt 	u_int32_t			 pfik_tzero;
   1059  1.16      yamt 	int				 pfik_flags;
   1060   1.1    itojun 	void				*pfik_ah_cookie;
   1061   1.1    itojun 	struct ifnet			*pfik_ifp;
   1062  1.16      yamt 	struct ifg_group		*pfik_group;
   1063   1.1    itojun 	int				 pfik_states;
   1064   1.1    itojun 	int				 pfik_rules;
   1065  1.16      yamt 	TAILQ_HEAD(, pfi_dynaddr)	 pfik_dynaddrs;
   1066  1.16      yamt };
   1067  1.16      yamt 
   1068  1.16      yamt enum pfi_kif_refs {
   1069  1.16      yamt 	PFI_KIF_REF_NONE,
   1070  1.16      yamt 	PFI_KIF_REF_STATE,
   1071  1.16      yamt 	PFI_KIF_REF_RULE
   1072   1.1    itojun };
   1073  1.16      yamt 
   1074   1.9     peter #define PFI_IFLAG_SKIP		0x0100	/* skip filtering on interface */
   1075   1.1    itojun 
   1076   1.1    itojun struct pf_pdesc {
   1077  1.16      yamt 	struct {
   1078  1.16      yamt 		int	 done;
   1079  1.16      yamt 		uid_t	 uid;
   1080  1.16      yamt 		gid_t	 gid;
   1081  1.16      yamt 		pid_t	 pid;
   1082  1.16      yamt 	}		 lookup;
   1083   1.1    itojun 	u_int64_t	 tot_len;	/* Make Mickey money */
   1084   1.1    itojun 	union {
   1085   1.1    itojun 		struct tcphdr		*tcp;
   1086   1.1    itojun 		struct udphdr		*udp;
   1087   1.1    itojun 		struct icmp		*icmp;
   1088   1.1    itojun #ifdef INET6
   1089   1.1    itojun 		struct icmp6_hdr	*icmp6;
   1090   1.1    itojun #endif /* INET6 */
   1091   1.1    itojun 		void			*any;
   1092   1.1    itojun 	} hdr;
   1093   1.1    itojun 	struct pf_addr	 baddr;		/* address before translation */
   1094   1.1    itojun 	struct pf_addr	 naddr;		/* address after translation */
   1095   1.1    itojun 	struct pf_rule	*nat_rule;	/* nat/rdr rule applied to packet */
   1096   1.1    itojun 	struct pf_addr	*src;
   1097   1.1    itojun 	struct pf_addr	*dst;
   1098   1.6      yamt 	struct ether_header
   1099   1.6      yamt 			*eh;
   1100   1.1    itojun 	u_int16_t	*ip_sum;
   1101   1.1    itojun 	u_int32_t	 p_len;		/* total length of payload */
   1102   1.1    itojun 	u_int16_t	 flags;		/* Let SCRUB trigger behavior in
   1103   1.1    itojun 					 * state code. Easier than tags */
   1104   1.1    itojun #define PFDESC_TCP_NORM	0x0001		/* TCP shall be statefully scrubbed */
   1105   1.6      yamt #define PFDESC_IP_REAS	0x0002		/* IP frags would've been reassembled */
   1106   1.1    itojun 	sa_family_t	 af;
   1107   1.1    itojun 	u_int8_t	 proto;
   1108   1.1    itojun 	u_int8_t	 tos;
   1109   1.1    itojun };
   1110   1.1    itojun 
   1111   1.1    itojun /* flags for RDR options */
   1112   1.1    itojun #define PF_DPORT_RANGE	0x01		/* Dest port uses range */
   1113   1.1    itojun #define PF_RPORT_RANGE	0x02		/* RDR'ed port uses range */
   1114   1.1    itojun 
   1115   1.1    itojun /* Reasons code for passing/dropping a packet */
   1116   1.1    itojun #define PFRES_MATCH	0		/* Explicit match of a rule */
   1117   1.1    itojun #define PFRES_BADOFF	1		/* Bad offset for pull_hdr */
   1118   1.1    itojun #define PFRES_FRAG	2		/* Dropping following fragment */
   1119   1.1    itojun #define PFRES_SHORT	3		/* Dropping short packet */
   1120   1.1    itojun #define PFRES_NORM	4		/* Dropping by normalizer */
   1121   1.1    itojun #define PFRES_MEMORY	5		/* Dropped due to lacking mem */
   1122   1.6      yamt #define PFRES_TS	6		/* Bad TCP Timestamp (RFC1323) */
   1123  1.22     rmind #define PFRES_CONGEST	7		/* Congestion (of IP queue) */
   1124   1.9     peter #define PFRES_IPOPTIONS 8		/* IP option */
   1125   1.9     peter #define PFRES_PROTCKSUM 9		/* Protocol checksum invalid */
   1126   1.9     peter #define PFRES_BADSTATE	10		/* State mismatch */
   1127   1.9     peter #define PFRES_STATEINS	11		/* State insertion failure */
   1128   1.9     peter #define PFRES_MAXSTATES	12		/* State limit */
   1129   1.9     peter #define PFRES_SRCLIMIT	13		/* Source node/conn limit */
   1130   1.9     peter #define PFRES_SYNPROXY	14		/* SYN proxy */
   1131  1.19  degroote #define PFRES_STATELOCKED 15    /* state table locked */
   1132  1.19  degroote #define PFRES_MAX	16		/* total+1 */
   1133   1.1    itojun 
   1134   1.1    itojun #define PFRES_NAMES { \
   1135   1.1    itojun 	"match", \
   1136   1.1    itojun 	"bad-offset", \
   1137   1.1    itojun 	"fragment", \
   1138   1.1    itojun 	"short", \
   1139   1.1    itojun 	"normalize", \
   1140   1.1    itojun 	"memory", \
   1141   1.6      yamt 	"bad-timestamp", \
   1142   1.9     peter 	"congestion", \
   1143   1.9     peter 	"ip-option", \
   1144   1.9     peter 	"proto-cksum", \
   1145   1.9     peter 	"state-mismatch", \
   1146   1.9     peter 	"state-insert", \
   1147   1.9     peter 	"state-limit", \
   1148   1.9     peter 	"src-limit", \
   1149   1.9     peter 	"synproxy", \
   1150  1.19  degroote 	"state-locked", \
   1151   1.9     peter 	NULL \
   1152   1.9     peter }
   1153   1.9     peter 
   1154   1.9     peter /* Counters for other things we want to keep track of */
   1155   1.9     peter #define LCNT_STATES		0	/* states */
   1156   1.9     peter #define LCNT_SRCSTATES		1	/* max-src-states */
   1157   1.9     peter #define LCNT_SRCNODES		2	/* max-src-nodes */
   1158   1.9     peter #define LCNT_SRCCONN		3	/* max-src-conn */
   1159   1.9     peter #define LCNT_SRCCONNRATE	4	/* max-src-conn-rate */
   1160   1.9     peter #define LCNT_OVERLOAD_TABLE	5	/* entry added to overload table */
   1161   1.9     peter #define LCNT_OVERLOAD_FLUSH	6	/* state entries flushed */
   1162   1.9     peter #define LCNT_MAX		7	/* total+1 */
   1163   1.9     peter 
   1164   1.9     peter #define LCNT_NAMES { \
   1165   1.9     peter 	"max states per rule", \
   1166   1.9     peter 	"max-src-states", \
   1167   1.9     peter 	"max-src-nodes", \
   1168   1.9     peter 	"max-src-conn", \
   1169   1.9     peter 	"max-src-conn-rate", \
   1170   1.9     peter 	"overload table insertion", \
   1171   1.9     peter 	"overload flush states", \
   1172   1.1    itojun 	NULL \
   1173   1.1    itojun }
   1174   1.1    itojun 
   1175   1.1    itojun /* UDP state enumeration */
   1176   1.1    itojun #define PFUDPS_NO_TRAFFIC	0
   1177   1.1    itojun #define PFUDPS_SINGLE		1
   1178   1.1    itojun #define PFUDPS_MULTIPLE		2
   1179   1.1    itojun 
   1180   1.1    itojun #define PFUDPS_NSTATES		3	/* number of state levels */
   1181   1.1    itojun 
   1182   1.1    itojun #define PFUDPS_NAMES { \
   1183   1.1    itojun 	"NO_TRAFFIC", \
   1184   1.1    itojun 	"SINGLE", \
   1185   1.1    itojun 	"MULTIPLE", \
   1186   1.1    itojun 	NULL \
   1187   1.1    itojun }
   1188   1.1    itojun 
   1189   1.1    itojun /* Other protocol state enumeration */
   1190   1.1    itojun #define PFOTHERS_NO_TRAFFIC	0
   1191   1.1    itojun #define PFOTHERS_SINGLE		1
   1192   1.1    itojun #define PFOTHERS_MULTIPLE	2
   1193   1.1    itojun 
   1194   1.1    itojun #define PFOTHERS_NSTATES	3	/* number of state levels */
   1195   1.1    itojun 
   1196   1.1    itojun #define PFOTHERS_NAMES { \
   1197   1.1    itojun 	"NO_TRAFFIC", \
   1198   1.1    itojun 	"SINGLE", \
   1199   1.1    itojun 	"MULTIPLE", \
   1200   1.1    itojun 	NULL \
   1201   1.1    itojun }
   1202   1.1    itojun 
   1203   1.1    itojun #define FCNT_STATE_SEARCH	0
   1204   1.1    itojun #define FCNT_STATE_INSERT	1
   1205   1.1    itojun #define FCNT_STATE_REMOVALS	2
   1206   1.1    itojun #define FCNT_MAX		3
   1207   1.1    itojun 
   1208   1.1    itojun #define SCNT_SRC_NODE_SEARCH	0
   1209   1.1    itojun #define SCNT_SRC_NODE_INSERT	1
   1210   1.1    itojun #define SCNT_SRC_NODE_REMOVALS	2
   1211   1.1    itojun #define SCNT_MAX		3
   1212   1.1    itojun 
   1213   1.1    itojun #define ACTION_SET(a, x) \
   1214   1.1    itojun 	do { \
   1215   1.1    itojun 		if ((a) != NULL) \
   1216   1.1    itojun 			*(a) = (x); \
   1217   1.1    itojun 	} while (0)
   1218   1.1    itojun 
   1219   1.1    itojun #define REASON_SET(a, x) \
   1220   1.1    itojun 	do { \
   1221   1.1    itojun 		if ((a) != NULL) \
   1222   1.1    itojun 			*(a) = (x); \
   1223   1.1    itojun 		if (x < PFRES_MAX) \
   1224   1.1    itojun 			pf_status.counters[x]++; \
   1225   1.1    itojun 	} while (0)
   1226  1.21  christos #define REASON_SET_NOPTR(a, x) \
   1227  1.21  christos 	do { \
   1228  1.21  christos 		*(a) = (x); \
   1229  1.21  christos 		if (x < PFRES_MAX) \
   1230  1.21  christos 			pf_status.counters[x]++; \
   1231  1.21  christos 	} while (0)
   1232   1.1    itojun 
   1233   1.1    itojun struct pf_status {
   1234   1.1    itojun 	u_int64_t	counters[PFRES_MAX];
   1235   1.9     peter 	u_int64_t	lcounters[LCNT_MAX];	/* limit counters */
   1236   1.1    itojun 	u_int64_t	fcounters[FCNT_MAX];
   1237   1.1    itojun 	u_int64_t	scounters[SCNT_MAX];
   1238   1.1    itojun 	u_int64_t	pcounters[2][2][3];
   1239   1.1    itojun 	u_int64_t	bcounters[2][2];
   1240   1.1    itojun 	u_int64_t	stateid;
   1241   1.1    itojun 	u_int32_t	running;
   1242   1.1    itojun 	u_int32_t	states;
   1243   1.1    itojun 	u_int32_t	src_nodes;
   1244   1.1    itojun 	u_int32_t	since;
   1245   1.1    itojun 	u_int32_t	debug;
   1246   1.1    itojun 	u_int32_t	hostid;
   1247   1.1    itojun 	char		ifname[IFNAMSIZ];
   1248  1.16      yamt 	u_int8_t	pf_chksum[PF_MD5_DIGEST_LENGTH];
   1249   1.1    itojun };
   1250   1.1    itojun 
   1251   1.1    itojun struct cbq_opts {
   1252   1.1    itojun 	u_int		minburst;
   1253   1.1    itojun 	u_int		maxburst;
   1254   1.1    itojun 	u_int		pktsize;
   1255   1.1    itojun 	u_int		maxpktsize;
   1256   1.1    itojun 	u_int		ns_per_byte;
   1257   1.1    itojun 	u_int		maxidle;
   1258   1.1    itojun 	int		minidle;
   1259   1.1    itojun 	u_int		offtime;
   1260   1.1    itojun 	int		flags;
   1261   1.1    itojun };
   1262   1.1    itojun 
   1263   1.1    itojun struct priq_opts {
   1264   1.1    itojun 	int		flags;
   1265   1.1    itojun };
   1266   1.1    itojun 
   1267   1.1    itojun struct hfsc_opts {
   1268   1.1    itojun 	/* real-time service curve */
   1269   1.1    itojun 	u_int		rtsc_m1;	/* slope of the 1st segment in bps */
   1270   1.1    itojun 	u_int		rtsc_d;		/* the x-projection of m1 in msec */
   1271   1.1    itojun 	u_int		rtsc_m2;	/* slope of the 2nd segment in bps */
   1272   1.1    itojun 	/* link-sharing service curve */
   1273   1.1    itojun 	u_int		lssc_m1;
   1274   1.1    itojun 	u_int		lssc_d;
   1275   1.1    itojun 	u_int		lssc_m2;
   1276   1.1    itojun 	/* upper-limit service curve */
   1277   1.1    itojun 	u_int		ulsc_m1;
   1278   1.1    itojun 	u_int		ulsc_d;
   1279   1.1    itojun 	u_int		ulsc_m2;
   1280   1.1    itojun 	int		flags;
   1281   1.1    itojun };
   1282   1.1    itojun 
   1283   1.1    itojun struct pf_altq {
   1284   1.1    itojun 	char			 ifname[IFNAMSIZ];
   1285   1.1    itojun 
   1286   1.1    itojun 	void			*altq_disc;	/* discipline-specific state */
   1287   1.1    itojun 	TAILQ_ENTRY(pf_altq)	 entries;
   1288   1.1    itojun 
   1289   1.1    itojun 	/* scheduler spec */
   1290   1.1    itojun 	u_int8_t		 scheduler;	/* scheduler type */
   1291   1.1    itojun 	u_int16_t		 tbrsize;	/* tokenbucket regulator size */
   1292   1.1    itojun 	u_int32_t		 ifbandwidth;	/* interface bandwidth */
   1293   1.1    itojun 
   1294   1.1    itojun 	/* queue spec */
   1295   1.1    itojun 	char			 qname[PF_QNAME_SIZE];	/* queue name */
   1296   1.1    itojun 	char			 parent[PF_QNAME_SIZE];	/* parent name */
   1297   1.1    itojun 	u_int32_t		 parent_qid;	/* parent queue id */
   1298   1.1    itojun 	u_int32_t		 bandwidth;	/* queue bandwidth */
   1299   1.1    itojun 	u_int8_t		 priority;	/* priority */
   1300   1.1    itojun 	u_int16_t		 qlimit;	/* queue size limit */
   1301   1.1    itojun 	u_int16_t		 flags;		/* misc flags */
   1302   1.1    itojun 	union {
   1303   1.1    itojun 		struct cbq_opts		 cbq_opts;
   1304   1.1    itojun 		struct priq_opts	 priq_opts;
   1305   1.1    itojun 		struct hfsc_opts	 hfsc_opts;
   1306   1.1    itojun 	} pq_u;
   1307   1.1    itojun 
   1308   1.1    itojun 	u_int32_t		 qid;		/* return value */
   1309   1.1    itojun };
   1310   1.1    itojun 
   1311   1.1    itojun struct pf_tag {
   1312   1.1    itojun 	u_int16_t	tag;		/* tag id */
   1313   1.1    itojun };
   1314   1.1    itojun 
   1315   1.1    itojun struct pf_tagname {
   1316   1.1    itojun 	TAILQ_ENTRY(pf_tagname)	entries;
   1317   1.1    itojun 	char			name[PF_TAG_NAME_SIZE];
   1318   1.1    itojun 	u_int16_t		tag;
   1319   1.1    itojun 	int			ref;
   1320   1.1    itojun };
   1321   1.1    itojun 
   1322   1.1    itojun #define PFFRAG_FRENT_HIWAT	5000	/* Number of fragment entries */
   1323   1.1    itojun #define PFFRAG_FRAG_HIWAT	1000	/* Number of fragmented packets */
   1324   1.1    itojun #define PFFRAG_FRCENT_HIWAT	50000	/* Number of fragment cache entries */
   1325   1.1    itojun #define PFFRAG_FRCACHE_HIWAT	10000	/* Number of fragment descriptors */
   1326   1.1    itojun 
   1327  1.16      yamt #define PFR_KTABLE_HIWAT	1000	/* Number of tables */
   1328  1.16      yamt #define PFR_KENTRY_HIWAT	200000	/* Number of table entries */
   1329  1.16      yamt #define PFR_KENTRY_HIWAT_SMALL	100000	/* Number of table entries (tiny hosts) */
   1330  1.16      yamt 
   1331   1.1    itojun /*
   1332   1.1    itojun  * ioctl parameter structures
   1333   1.1    itojun  */
   1334   1.1    itojun 
   1335   1.1    itojun struct pfioc_pooladdr {
   1336   1.1    itojun 	u_int32_t		 action;
   1337   1.1    itojun 	u_int32_t		 ticket;
   1338   1.1    itojun 	u_int32_t		 nr;
   1339   1.1    itojun 	u_int32_t		 r_num;
   1340   1.1    itojun 	u_int8_t		 r_action;
   1341   1.1    itojun 	u_int8_t		 r_last;
   1342   1.1    itojun 	u_int8_t		 af;
   1343   1.6      yamt 	char			 anchor[MAXPATHLEN];
   1344   1.1    itojun 	struct pf_pooladdr	 addr;
   1345   1.1    itojun };
   1346   1.1    itojun 
   1347   1.1    itojun struct pfioc_rule {
   1348   1.1    itojun 	u_int32_t	 action;
   1349   1.1    itojun 	u_int32_t	 ticket;
   1350   1.1    itojun 	u_int32_t	 pool_ticket;
   1351   1.1    itojun 	u_int32_t	 nr;
   1352   1.6      yamt 	char		 anchor[MAXPATHLEN];
   1353   1.6      yamt 	char		 anchor_call[MAXPATHLEN];
   1354   1.1    itojun 	struct pf_rule	 rule;
   1355   1.1    itojun };
   1356   1.1    itojun 
   1357   1.1    itojun struct pfioc_natlook {
   1358   1.1    itojun 	struct pf_addr	 saddr;
   1359   1.1    itojun 	struct pf_addr	 daddr;
   1360   1.1    itojun 	struct pf_addr	 rsaddr;
   1361   1.1    itojun 	struct pf_addr	 rdaddr;
   1362   1.1    itojun 	u_int16_t	 sport;
   1363   1.1    itojun 	u_int16_t	 dport;
   1364   1.1    itojun 	u_int16_t	 rsport;
   1365   1.1    itojun 	u_int16_t	 rdport;
   1366   1.1    itojun 	sa_family_t	 af;
   1367   1.1    itojun 	u_int8_t	 proto;
   1368   1.1    itojun 	u_int8_t	 direction;
   1369   1.1    itojun };
   1370   1.1    itojun 
   1371   1.1    itojun struct pfioc_state {
   1372  1.16      yamt 	u_int32_t 	 nr;
   1373  1.16      yamt 	void		*state;
   1374  1.16      yamt };
   1375  1.16      yamt 
   1376  1.16      yamt struct pfioc_src_node_kill {
   1377  1.16      yamt 	/* XXX returns the number of src nodes killed in psnk_af */
   1378  1.16      yamt 	sa_family_t psnk_af;
   1379  1.16      yamt 	struct pf_rule_addr psnk_src;
   1380  1.16      yamt 	struct pf_rule_addr psnk_dst;
   1381   1.1    itojun };
   1382   1.1    itojun 
   1383   1.1    itojun struct pfioc_state_kill {
   1384   1.1    itojun 	/* XXX returns the number of states killed in psk_af */
   1385   1.1    itojun 	sa_family_t		psk_af;
   1386   1.1    itojun 	int			psk_proto;
   1387   1.1    itojun 	struct pf_rule_addr	psk_src;
   1388   1.1    itojun 	struct pf_rule_addr	psk_dst;
   1389   1.1    itojun 	char			psk_ifname[IFNAMSIZ];
   1390   1.1    itojun };
   1391   1.1    itojun 
   1392   1.1    itojun struct pfioc_states {
   1393   1.1    itojun 	int	ps_len;
   1394   1.1    itojun 	union {
   1395  1.16      yamt 		void			*psu_buf;
   1396  1.16      yamt 		struct pfsync_state	*psu_states;
   1397   1.1    itojun 	} ps_u;
   1398   1.1    itojun #define ps_buf		ps_u.psu_buf
   1399   1.1    itojun #define ps_states	ps_u.psu_states
   1400   1.1    itojun };
   1401   1.1    itojun 
   1402   1.1    itojun struct pfioc_src_nodes {
   1403   1.1    itojun 	int	psn_len;
   1404   1.1    itojun 	union {
   1405  1.16      yamt 		void			*psu_buf;
   1406   1.1    itojun 		struct pf_src_node	*psu_src_nodes;
   1407   1.1    itojun 	} psn_u;
   1408   1.1    itojun #define psn_buf		psn_u.psu_buf
   1409   1.1    itojun #define psn_src_nodes	psn_u.psu_src_nodes
   1410   1.1    itojun };
   1411   1.1    itojun 
   1412   1.1    itojun struct pfioc_if {
   1413   1.1    itojun 	char		 ifname[IFNAMSIZ];
   1414   1.1    itojun };
   1415   1.1    itojun 
   1416   1.1    itojun struct pfioc_tm {
   1417   1.1    itojun 	int		 timeout;
   1418   1.1    itojun 	int		 seconds;
   1419   1.1    itojun };
   1420   1.1    itojun 
   1421   1.1    itojun struct pfioc_limit {
   1422   1.1    itojun 	int		 index;
   1423   1.1    itojun 	unsigned	 limit;
   1424   1.1    itojun };
   1425   1.1    itojun 
   1426   1.1    itojun struct pfioc_altq {
   1427   1.1    itojun 	u_int32_t	 action;
   1428   1.1    itojun 	u_int32_t	 ticket;
   1429   1.1    itojun 	u_int32_t	 nr;
   1430   1.1    itojun 	struct pf_altq	 altq;
   1431   1.1    itojun };
   1432   1.1    itojun 
   1433   1.1    itojun struct pfioc_qstats {
   1434   1.1    itojun 	u_int32_t	 ticket;
   1435   1.1    itojun 	u_int32_t	 nr;
   1436   1.1    itojun 	void		*buf;
   1437   1.1    itojun 	int		 nbytes;
   1438   1.1    itojun 	u_int8_t	 scheduler;
   1439   1.1    itojun };
   1440   1.1    itojun 
   1441   1.6      yamt struct pfioc_ruleset {
   1442   1.1    itojun 	u_int32_t	 nr;
   1443   1.6      yamt 	char		 path[MAXPATHLEN];
   1444   1.1    itojun 	char		 name[PF_ANCHOR_NAME_SIZE];
   1445   1.1    itojun };
   1446   1.1    itojun 
   1447   1.1    itojun #define PF_RULESET_ALTQ		(PF_RULESET_MAX)
   1448   1.1    itojun #define PF_RULESET_TABLE	(PF_RULESET_MAX+1)
   1449   1.1    itojun struct pfioc_trans {
   1450   1.1    itojun 	int		 size;	/* number of elements */
   1451   1.1    itojun 	int		 esize; /* size of each element in bytes */
   1452   1.1    itojun 	struct pfioc_trans_e {
   1453   1.1    itojun 		int		rs_num;
   1454   1.6      yamt 		char		anchor[MAXPATHLEN];
   1455   1.1    itojun 		u_int32_t	ticket;
   1456   1.1    itojun 	}		*array;
   1457   1.1    itojun };
   1458   1.1    itojun 
   1459   1.1    itojun #define PFR_FLAG_ATOMIC		0x00000001
   1460   1.1    itojun #define PFR_FLAG_DUMMY		0x00000002
   1461   1.1    itojun #define PFR_FLAG_FEEDBACK	0x00000004
   1462   1.1    itojun #define PFR_FLAG_CLSTATS	0x00000008
   1463   1.1    itojun #define PFR_FLAG_ADDRSTOO	0x00000010
   1464   1.1    itojun #define PFR_FLAG_REPLACE	0x00000020
   1465   1.1    itojun #define PFR_FLAG_ALLRSETS	0x00000040
   1466   1.1    itojun #define PFR_FLAG_ALLMASK	0x0000007F
   1467   1.1    itojun #ifdef _KERNEL
   1468   1.1    itojun #define PFR_FLAG_USERIOCTL	0x10000000
   1469   1.1    itojun #endif
   1470   1.1    itojun 
   1471   1.1    itojun struct pfioc_table {
   1472   1.1    itojun 	struct pfr_table	 pfrio_table;
   1473   1.1    itojun 	void			*pfrio_buffer;
   1474   1.1    itojun 	int			 pfrio_esize;
   1475   1.1    itojun 	int			 pfrio_size;
   1476   1.1    itojun 	int			 pfrio_size2;
   1477   1.1    itojun 	int			 pfrio_nadd;
   1478   1.1    itojun 	int			 pfrio_ndel;
   1479   1.1    itojun 	int			 pfrio_nchange;
   1480   1.1    itojun 	int			 pfrio_flags;
   1481   1.1    itojun 	u_int32_t		 pfrio_ticket;
   1482   1.1    itojun };
   1483   1.1    itojun #define	pfrio_exists	pfrio_nadd
   1484   1.1    itojun #define	pfrio_nzero	pfrio_nadd
   1485   1.1    itojun #define	pfrio_nmatch	pfrio_nadd
   1486   1.1    itojun #define pfrio_naddr	pfrio_size2
   1487   1.1    itojun #define pfrio_setflag	pfrio_size2
   1488   1.1    itojun #define pfrio_clrflag	pfrio_nadd
   1489   1.1    itojun 
   1490   1.1    itojun struct pfioc_iface {
   1491   1.1    itojun 	char	 pfiio_name[IFNAMSIZ];
   1492   1.1    itojun 	void	*pfiio_buffer;
   1493   1.1    itojun 	int	 pfiio_esize;
   1494   1.1    itojun 	int	 pfiio_size;
   1495   1.1    itojun 	int	 pfiio_nzero;
   1496   1.1    itojun 	int	 pfiio_flags;
   1497   1.1    itojun };
   1498   1.1    itojun 
   1499   1.1    itojun 
   1500   1.1    itojun /*
   1501   1.1    itojun  * ioctl operations
   1502   1.1    itojun  */
   1503   1.1    itojun 
   1504   1.1    itojun #define DIOCSTART	_IO  ('D',  1)
   1505   1.1    itojun #define DIOCSTOP	_IO  ('D',  2)
   1506   1.1    itojun #define DIOCADDRULE	_IOWR('D',  4, struct pfioc_rule)
   1507   1.1    itojun #define DIOCGETRULES	_IOWR('D',  6, struct pfioc_rule)
   1508   1.1    itojun #define DIOCGETRULE	_IOWR('D',  7, struct pfioc_rule)
   1509  1.19  degroote #define DIOCSETLCK  _IOWR('D', 8, uint32_t)
   1510  1.19  degroote /* XXX cut 9 - 17 */
   1511   1.1    itojun #define DIOCCLRSTATES	_IOWR('D', 18, struct pfioc_state_kill)
   1512   1.1    itojun #define DIOCGETSTATE	_IOWR('D', 19, struct pfioc_state)
   1513   1.1    itojun #define DIOCSETSTATUSIF _IOWR('D', 20, struct pfioc_if)
   1514   1.1    itojun #define DIOCGETSTATUS	_IOWR('D', 21, struct pf_status)
   1515   1.1    itojun #define DIOCCLRSTATUS	_IO  ('D', 22)
   1516   1.1    itojun #define DIOCNATLOOK	_IOWR('D', 23, struct pfioc_natlook)
   1517   1.1    itojun #define DIOCSETDEBUG	_IOWR('D', 24, u_int32_t)
   1518   1.1    itojun #define DIOCGETSTATES	_IOWR('D', 25, struct pfioc_states)
   1519   1.1    itojun #define DIOCCHANGERULE	_IOWR('D', 26, struct pfioc_rule)
   1520   1.1    itojun /* XXX cut 26 - 28 */
   1521   1.1    itojun #define DIOCSETTIMEOUT	_IOWR('D', 29, struct pfioc_tm)
   1522   1.1    itojun #define DIOCGETTIMEOUT	_IOWR('D', 30, struct pfioc_tm)
   1523   1.1    itojun #define DIOCADDSTATE	_IOWR('D', 37, struct pfioc_state)
   1524   1.1    itojun #define DIOCCLRRULECTRS	_IO  ('D', 38)
   1525   1.1    itojun #define DIOCGETLIMIT	_IOWR('D', 39, struct pfioc_limit)
   1526   1.1    itojun #define DIOCSETLIMIT	_IOWR('D', 40, struct pfioc_limit)
   1527   1.1    itojun #define DIOCKILLSTATES	_IOWR('D', 41, struct pfioc_state_kill)
   1528   1.1    itojun #define DIOCSTARTALTQ	_IO  ('D', 42)
   1529   1.1    itojun #define DIOCSTOPALTQ	_IO  ('D', 43)
   1530   1.1    itojun #define DIOCADDALTQ	_IOWR('D', 45, struct pfioc_altq)
   1531   1.1    itojun #define DIOCGETALTQS	_IOWR('D', 47, struct pfioc_altq)
   1532   1.1    itojun #define DIOCGETALTQ	_IOWR('D', 48, struct pfioc_altq)
   1533   1.1    itojun #define DIOCCHANGEALTQ	_IOWR('D', 49, struct pfioc_altq)
   1534   1.1    itojun #define DIOCGETQSTATS	_IOWR('D', 50, struct pfioc_qstats)
   1535   1.1    itojun #define DIOCBEGINADDRS	_IOWR('D', 51, struct pfioc_pooladdr)
   1536   1.1    itojun #define DIOCADDADDR	_IOWR('D', 52, struct pfioc_pooladdr)
   1537   1.1    itojun #define DIOCGETADDRS	_IOWR('D', 53, struct pfioc_pooladdr)
   1538   1.1    itojun #define DIOCGETADDR	_IOWR('D', 54, struct pfioc_pooladdr)
   1539   1.1    itojun #define DIOCCHANGEADDR	_IOWR('D', 55, struct pfioc_pooladdr)
   1540  1.19  degroote #define DIOCADDSTATES   _IOWR('D', 56, struct pfioc_states)
   1541  1.19  degroote /* XXX cut 57 - 57 */
   1542   1.1    itojun #define	DIOCGETRULESETS	_IOWR('D', 58, struct pfioc_ruleset)
   1543   1.1    itojun #define	DIOCGETRULESET	_IOWR('D', 59, struct pfioc_ruleset)
   1544   1.1    itojun #define	DIOCRCLRTABLES	_IOWR('D', 60, struct pfioc_table)
   1545   1.1    itojun #define	DIOCRADDTABLES	_IOWR('D', 61, struct pfioc_table)
   1546   1.1    itojun #define	DIOCRDELTABLES	_IOWR('D', 62, struct pfioc_table)
   1547   1.1    itojun #define	DIOCRGETTABLES	_IOWR('D', 63, struct pfioc_table)
   1548   1.1    itojun #define	DIOCRGETTSTATS	_IOWR('D', 64, struct pfioc_table)
   1549   1.1    itojun #define DIOCRCLRTSTATS  _IOWR('D', 65, struct pfioc_table)
   1550   1.1    itojun #define	DIOCRCLRADDRS	_IOWR('D', 66, struct pfioc_table)
   1551   1.1    itojun #define	DIOCRADDADDRS	_IOWR('D', 67, struct pfioc_table)
   1552   1.1    itojun #define	DIOCRDELADDRS	_IOWR('D', 68, struct pfioc_table)
   1553   1.1    itojun #define	DIOCRSETADDRS	_IOWR('D', 69, struct pfioc_table)
   1554   1.1    itojun #define	DIOCRGETADDRS	_IOWR('D', 70, struct pfioc_table)
   1555   1.1    itojun #define	DIOCRGETASTATS	_IOWR('D', 71, struct pfioc_table)
   1556   1.1    itojun #define DIOCRCLRASTATS  _IOWR('D', 72, struct pfioc_table)
   1557   1.1    itojun #define	DIOCRTSTADDRS	_IOWR('D', 73, struct pfioc_table)
   1558   1.1    itojun #define	DIOCRSETTFLAGS	_IOWR('D', 74, struct pfioc_table)
   1559   1.1    itojun #define DIOCRINADEFINE	_IOWR('D', 77, struct pfioc_table)
   1560   1.1    itojun #define DIOCOSFPFLUSH	_IO('D', 78)
   1561   1.1    itojun #define DIOCOSFPADD	_IOWR('D', 79, struct pf_osfp_ioctl)
   1562   1.1    itojun #define DIOCOSFPGET	_IOWR('D', 80, struct pf_osfp_ioctl)
   1563   1.1    itojun #define DIOCXBEGIN      _IOWR('D', 81, struct pfioc_trans)
   1564   1.1    itojun #define DIOCXCOMMIT     _IOWR('D', 82, struct pfioc_trans)
   1565   1.1    itojun #define DIOCXROLLBACK   _IOWR('D', 83, struct pfioc_trans)
   1566   1.1    itojun #define DIOCGETSRCNODES	_IOWR('D', 84, struct pfioc_src_nodes)
   1567   1.1    itojun #define DIOCCLRSRCNODES	_IO('D', 85)
   1568   1.1    itojun #define DIOCSETHOSTID	_IOWR('D', 86, u_int32_t)
   1569   1.1    itojun #define DIOCIGETIFACES	_IOWR('D', 87, struct pfioc_iface)
   1570   1.9     peter #define DIOCSETIFFLAG	_IOWR('D', 89, struct pfioc_iface)
   1571   1.9     peter #define DIOCCLRIFFLAG	_IOWR('D', 90, struct pfioc_iface)
   1572  1.16      yamt #define DIOCKILLSRCNODES	_IOWR('D', 91, struct pfioc_src_node_kill)
   1573   1.1    itojun 
   1574   1.1    itojun #ifdef _KERNEL
   1575   1.1    itojun RB_HEAD(pf_src_tree, pf_src_node);
   1576   1.1    itojun RB_PROTOTYPE(pf_src_tree, pf_src_node, entry, pf_src_compare);
   1577   1.1    itojun extern struct pf_src_tree tree_src_tracking;
   1578   1.1    itojun 
   1579   1.1    itojun RB_HEAD(pf_state_tree_id, pf_state);
   1580   1.1    itojun RB_PROTOTYPE(pf_state_tree_id, pf_state,
   1581   1.1    itojun     entry_id, pf_state_compare_id);
   1582   1.1    itojun extern struct pf_state_tree_id tree_id;
   1583  1.16      yamt extern struct pf_state_queue state_list;
   1584   1.1    itojun 
   1585   1.1    itojun TAILQ_HEAD(pf_poolqueue, pf_pool);
   1586   1.1    itojun extern struct pf_poolqueue		  pf_pools[2];
   1587   1.1    itojun TAILQ_HEAD(pf_altqqueue, pf_altq);
   1588   1.1    itojun extern struct pf_altqqueue		  pf_altqs[2];
   1589   1.1    itojun extern struct pf_palist			  pf_pabuf;
   1590   1.1    itojun 
   1591   1.1    itojun extern u_int32_t		 ticket_altqs_active;
   1592   1.1    itojun extern u_int32_t		 ticket_altqs_inactive;
   1593   1.1    itojun extern int			 altqs_inactive_open;
   1594   1.1    itojun extern u_int32_t		 ticket_pabuf;
   1595   1.1    itojun extern struct pf_altqqueue	*pf_altqs_active;
   1596   1.1    itojun extern struct pf_altqqueue	*pf_altqs_inactive;
   1597   1.1    itojun extern struct pf_poolqueue	*pf_pools_active;
   1598   1.1    itojun extern struct pf_poolqueue	*pf_pools_inactive;
   1599   1.1    itojun extern int			 pf_tbladdr_setup(struct pf_ruleset *,
   1600   1.1    itojun 				    struct pf_addr_wrap *);
   1601   1.1    itojun extern void			 pf_tbladdr_remove(struct pf_addr_wrap *);
   1602   1.1    itojun extern void			 pf_tbladdr_copyout(struct pf_addr_wrap *);
   1603   1.1    itojun extern void			 pf_calc_skip_steps(struct pf_rulequeue *);
   1604   1.1    itojun extern struct pool		 pf_src_tree_pl, pf_rule_pl;
   1605  1.16      yamt extern struct pool		 pf_state_pl, pf_state_key_pl, pf_altq_pl,
   1606  1.16      yamt 				    pf_pooladdr_pl;
   1607   1.1    itojun extern struct pool		 pf_state_scrub_pl;
   1608  1.16      yamt extern void			 pf_purge_thread(void *);
   1609  1.16      yamt extern void			 pf_purge_expired_src_nodes(int);
   1610  1.16      yamt extern void			 pf_purge_expired_states(u_int32_t);
   1611  1.16      yamt extern void			 pf_unlink_state(struct pf_state *);
   1612  1.16      yamt extern void			 pf_free_state(struct pf_state *);
   1613   1.1    itojun extern int			 pf_insert_state(struct pfi_kif *,
   1614   1.1    itojun 				    struct pf_state *);
   1615   1.1    itojun extern int			 pf_insert_src_node(struct pf_src_node **,
   1616   1.1    itojun 				    struct pf_rule *, struct pf_addr *,
   1617   1.1    itojun 				    sa_family_t);
   1618   1.1    itojun void				 pf_src_tree_remove_state(struct pf_state *);
   1619  1.16      yamt extern struct pf_state		*pf_find_state_byid(struct pf_state_cmp *);
   1620  1.16      yamt extern struct pf_state		*pf_find_state_all(struct pf_state_key_cmp *,
   1621  1.16      yamt 				    u_int8_t, int *);
   1622   1.6      yamt extern void			 pf_print_state(struct pf_state *);
   1623   1.6      yamt extern void			 pf_print_flags(u_int8_t);
   1624   1.6      yamt extern u_int16_t		 pf_cksum_fixup(u_int16_t, u_int16_t, u_int16_t,
   1625   1.6      yamt 				    u_int8_t);
   1626   1.1    itojun 
   1627   1.1    itojun extern struct ifnet		*sync_ifp;
   1628   1.1    itojun extern struct pf_rule		 pf_default_rule;
   1629  1.13    dyoung extern void			 pf_addrcpy(struct pf_addr *,
   1630  1.13    dyoung 				    const struct pf_addr *, u_int8_t);
   1631   1.1    itojun void				 pf_rm_rule(struct pf_rulequeue *,
   1632   1.1    itojun 				    struct pf_rule *);
   1633   1.1    itojun 
   1634   1.1    itojun #ifdef INET
   1635   1.6      yamt int	pf_test(int, struct ifnet *, struct mbuf **, struct ether_header *);
   1636   1.1    itojun #endif /* INET */
   1637   1.1    itojun 
   1638   1.1    itojun #ifdef INET6
   1639   1.6      yamt int	pf_test6(int, struct ifnet *, struct mbuf **, struct ether_header *);
   1640   1.1    itojun void	pf_poolmask(struct pf_addr *, struct pf_addr*,
   1641  1.13    dyoung 	    struct pf_addr *, const struct pf_addr *, u_int8_t);
   1642   1.1    itojun void	pf_addr_inc(struct pf_addr *, sa_family_t);
   1643   1.1    itojun #endif /* INET6 */
   1644   1.1    itojun 
   1645   1.1    itojun void   *pf_pull_hdr(struct mbuf *, int, void *, int, u_short *, u_short *,
   1646   1.1    itojun 	    sa_family_t);
   1647   1.1    itojun void	pf_change_a(void *, u_int16_t *, u_int32_t, u_int8_t);
   1648   1.1    itojun int	pflog_packet(struct pfi_kif *, struct mbuf *, sa_family_t, u_int8_t,
   1649  1.16      yamt 	    u_int8_t, struct pf_rule *, struct pf_rule *, struct pf_ruleset *,
   1650  1.16      yamt 	    struct pf_pdesc *);
   1651   1.1    itojun int	pf_match_addr(u_int8_t, struct pf_addr *, struct pf_addr *,
   1652   1.1    itojun 	    struct pf_addr *, sa_family_t);
   1653   1.1    itojun int	pf_match(u_int8_t, u_int32_t, u_int32_t, u_int32_t);
   1654   1.1    itojun int	pf_match_port(u_int8_t, u_int16_t, u_int16_t, u_int16_t);
   1655   1.1    itojun int	pf_match_uid(u_int8_t, uid_t, uid_t, uid_t);
   1656   1.1    itojun int	pf_match_gid(u_int8_t, gid_t, gid_t, gid_t);
   1657   1.1    itojun 
   1658   1.1    itojun void	pf_normalize_init(void);
   1659  1.18     ahoka #ifdef _MODULE
   1660  1.18     ahoka void	pf_normalize_destroy(void);
   1661  1.18     ahoka #endif /* _MODULE */
   1662   1.6      yamt int	pf_normalize_ip(struct mbuf **, int, struct pfi_kif *, u_short *,
   1663   1.6      yamt 	    struct pf_pdesc *);
   1664   1.6      yamt int	pf_normalize_ip6(struct mbuf **, int, struct pfi_kif *, u_short *,
   1665   1.6      yamt 	    struct pf_pdesc *);
   1666   1.1    itojun int	pf_normalize_tcp(int, struct pfi_kif *, struct mbuf *, int, int, void *,
   1667   1.1    itojun 	    struct pf_pdesc *);
   1668   1.1    itojun void	pf_normalize_tcp_cleanup(struct pf_state *);
   1669   1.1    itojun int	pf_normalize_tcp_init(struct mbuf *, int, struct pf_pdesc *,
   1670   1.1    itojun 	    struct tcphdr *, struct pf_state_peer *, struct pf_state_peer *);
   1671   1.1    itojun int	pf_normalize_tcp_stateful(struct mbuf *, int, struct pf_pdesc *,
   1672   1.6      yamt 	    u_short *, struct tcphdr *, struct pf_state *,
   1673   1.6      yamt 	    struct pf_state_peer *, struct pf_state_peer *, int *);
   1674   1.1    itojun u_int32_t
   1675   1.1    itojun 	pf_state_expires(const struct pf_state *);
   1676   1.1    itojun void	pf_purge_expired_fragments(void);
   1677  1.16      yamt int	pf_routable(struct pf_addr *addr, sa_family_t af, struct pfi_kif *);
   1678   1.9     peter int	pf_rtlabel_match(struct pf_addr *, sa_family_t, struct pf_addr_wrap *);
   1679  1.16      yamt int	pf_socket_lookup(int, struct pf_pdesc *);
   1680  1.16      yamt struct pf_state_key *
   1681  1.16      yamt 	pf_alloc_state_key(struct pf_state *);
   1682   1.1    itojun void	pfr_initialize(void);
   1683  1.18     ahoka #ifdef _MODULE
   1684  1.18     ahoka void	pfr_destroy(void);
   1685  1.18     ahoka #endif /* _MODULE */
   1686   1.1    itojun int	pfr_match_addr(struct pfr_ktable *, struct pf_addr *, sa_family_t);
   1687   1.1    itojun void	pfr_update_stats(struct pfr_ktable *, struct pf_addr *, sa_family_t,
   1688   1.1    itojun 	    u_int64_t, int, int, int);
   1689   1.1    itojun int	pfr_pool_get(struct pfr_ktable *, int *, struct pf_addr *,
   1690   1.1    itojun 	    struct pf_addr **, struct pf_addr **, sa_family_t);
   1691   1.1    itojun void	pfr_dynaddr_update(struct pfr_ktable *, struct pfi_dynaddr *);
   1692   1.1    itojun struct pfr_ktable *
   1693   1.1    itojun 	pfr_attach_table(struct pf_ruleset *, char *);
   1694   1.1    itojun void	pfr_detach_table(struct pfr_ktable *);
   1695   1.1    itojun int	pfr_clr_tables(struct pfr_table *, int *, int);
   1696   1.1    itojun int	pfr_add_tables(struct pfr_table *, int, int *, int);
   1697   1.1    itojun int	pfr_del_tables(struct pfr_table *, int, int *, int);
   1698   1.1    itojun int	pfr_get_tables(struct pfr_table *, struct pfr_table *, int *, int);
   1699   1.1    itojun int	pfr_get_tstats(struct pfr_table *, struct pfr_tstats *, int *, int);
   1700   1.1    itojun int	pfr_clr_tstats(struct pfr_table *, int, int *, int);
   1701   1.1    itojun int	pfr_set_tflags(struct pfr_table *, int, int, int, int *, int *, int);
   1702   1.1    itojun int	pfr_clr_addrs(struct pfr_table *, int *, int);
   1703   1.9     peter int	pfr_insert_kentry(struct pfr_ktable *, struct pfr_addr *, long);
   1704   1.1    itojun int	pfr_add_addrs(struct pfr_table *, struct pfr_addr *, int, int *,
   1705   1.1    itojun 	    int);
   1706   1.1    itojun int	pfr_del_addrs(struct pfr_table *, struct pfr_addr *, int, int *,
   1707   1.1    itojun 	    int);
   1708   1.1    itojun int	pfr_set_addrs(struct pfr_table *, struct pfr_addr *, int, int *,
   1709  1.16      yamt 	    int *, int *, int *, int, u_int32_t);
   1710   1.1    itojun int	pfr_get_addrs(struct pfr_table *, struct pfr_addr *, int *, int);
   1711   1.1    itojun int	pfr_get_astats(struct pfr_table *, struct pfr_astats *, int *, int);
   1712   1.1    itojun int	pfr_clr_astats(struct pfr_table *, struct pfr_addr *, int, int *,
   1713   1.1    itojun 	    int);
   1714   1.1    itojun int	pfr_tst_addrs(struct pfr_table *, struct pfr_addr *, int, int *,
   1715   1.1    itojun 	    int);
   1716   1.1    itojun int	pfr_ina_begin(struct pfr_table *, u_int32_t *, int *, int);
   1717   1.1    itojun int	pfr_ina_rollback(struct pfr_table *, u_int32_t, int *, int);
   1718   1.1    itojun int	pfr_ina_commit(struct pfr_table *, u_int32_t, int *, int *, int);
   1719   1.1    itojun int	pfr_ina_define(struct pfr_table *, struct pfr_addr *, int, int *,
   1720   1.1    itojun 	    int *, u_int32_t, int);
   1721   1.1    itojun 
   1722  1.16      yamt extern struct pfi_kif		*pfi_all;
   1723  1.16      yamt 
   1724   1.1    itojun void		 pfi_initialize(void);
   1725  1.18     ahoka #ifdef _MODULE
   1726  1.18     ahoka void		 pfi_destroy(void);
   1727  1.18     ahoka #endif /* _MODULE */
   1728  1.16      yamt struct pfi_kif	*pfi_kif_get(const char *);
   1729  1.16      yamt void		 pfi_kif_ref(struct pfi_kif *, enum pfi_kif_refs);
   1730  1.16      yamt void		 pfi_kif_unref(struct pfi_kif *, enum pfi_kif_refs);
   1731  1.16      yamt int		 pfi_kif_match(struct pfi_kif *, struct pfi_kif *);
   1732   1.1    itojun void		 pfi_attach_ifnet(struct ifnet *);
   1733   1.1    itojun void		 pfi_detach_ifnet(struct ifnet *);
   1734  1.16      yamt void		 pfi_attach_ifgroup(struct ifg_group *);
   1735  1.16      yamt void		 pfi_detach_ifgroup(struct ifg_group *);
   1736  1.16      yamt void		 pfi_group_change(const char *);
   1737  1.16      yamt int		 pfi_match_addr(struct pfi_dynaddr *, struct pf_addr *,
   1738  1.16      yamt 		    sa_family_t);
   1739   1.1    itojun int		 pfi_dynaddr_setup(struct pf_addr_wrap *, sa_family_t);
   1740  1.16      yamt void		 pfi_dynaddr_remove(struct pf_addr_wrap *);
   1741   1.1    itojun void		 pfi_dynaddr_copyout(struct pf_addr_wrap *);
   1742   1.1    itojun void		 pfi_fill_oldstatus(struct pf_status *);
   1743  1.16      yamt int		 pfi_clr_istats(const char *);
   1744  1.16      yamt int		 pfi_get_ifaces(const char *, struct pfi_kif *, int *);
   1745   1.9     peter int		 pfi_set_flags(const char *, int);
   1746   1.9     peter int		 pfi_clear_flags(const char *, int);
   1747   1.1    itojun 
   1748  1.16      yamt u_int16_t	 pf_tagname2tag(char *);
   1749  1.16      yamt void		 pf_tag2tagname(u_int16_t, char *);
   1750  1.16      yamt void		 pf_tag_ref(u_int16_t);
   1751  1.16      yamt void		 pf_tag_unref(u_int16_t);
   1752  1.16      yamt int		 pf_tag_packet(struct mbuf *, int, int);
   1753  1.16      yamt u_int32_t	 pf_qname2qid(char *);
   1754  1.16      yamt void		 pf_qid2qname(u_int32_t, char *);
   1755  1.16      yamt void		 pf_qid_unref(u_int32_t);
   1756   1.1    itojun 
   1757   1.1    itojun extern struct pf_status	pf_status;
   1758   1.1    itojun extern struct pool	pf_frent_pl, pf_frag_pl;
   1759  1.16      yamt #ifdef __NetBSD__
   1760  1.16      yamt extern krwlock_t	pf_consistency_lock;
   1761  1.16      yamt #else
   1762  1.16      yamt extern struct rwlock	pf_consistency_lock;
   1763  1.16      yamt #endif /* !__NetBSD__ */
   1764   1.1    itojun 
   1765   1.1    itojun struct pf_pool_limit {
   1766   1.1    itojun 	void		*pp;
   1767   1.1    itojun 	unsigned	 limit;
   1768   1.1    itojun };
   1769   1.1    itojun extern struct pf_pool_limit	pf_pool_limits[PF_LIMIT_MAX];
   1770   1.1    itojun 
   1771   1.6      yamt /*
   1772  1.16      yamt  * misc compatibility definitions
   1773   1.6      yamt  */
   1774   1.6      yamt #if !defined(PRIu32)
   1775   1.6      yamt #define	PRIu32	"u"	/* XXX */
   1776   1.6      yamt #endif
   1777  1.16      yamt 
   1778  1.16      yamt #if !defined(NO_PID)
   1779  1.16      yamt #define NO_PID		(PID_MAX + 1)
   1780  1.16      yamt #endif
   1781  1.16      yamt 
   1782  1.16      yamt #if defined(__NetBSD__)
   1783  1.16      yamt /* rwlock compatibility definitions */
   1784  1.16      yamt #define rw_enter_write(a)	rw_enter((a), (RW_WRITER))
   1785  1.16      yamt #define rw_exit_write(a)	rw_exit((a))
   1786  1.16      yamt #define rw_enter_read(a)	rw_enter((a), (RW_READER))
   1787  1.16      yamt #define rw_exit_read(a)		rw_exit((a))
   1788  1.16      yamt #endif /* __NetBSD__ */
   1789  1.16      yamt 
   1790  1.16      yamt #endif /* _KERNEL */
   1791  1.16      yamt 
   1792  1.16      yamt extern struct pf_anchor_global  pf_anchors;
   1793  1.16      yamt extern struct pf_anchor        pf_main_anchor;
   1794  1.16      yamt #define pf_main_ruleset	pf_main_anchor.ruleset
   1795  1.16      yamt 
   1796  1.16      yamt /* these ruleset functions can be linked into userland programs (pfctl) */
   1797  1.16      yamt int			 pf_get_ruleset_number(u_int8_t);
   1798  1.16      yamt void			 pf_init_ruleset(struct pf_ruleset *);
   1799  1.16      yamt int			 pf_anchor_setup(struct pf_rule *,
   1800  1.16      yamt 			    const struct pf_ruleset *, const char *);
   1801  1.16      yamt int			 pf_anchor_copyout(const struct pf_ruleset *,
   1802  1.16      yamt 			    const struct pf_rule *, struct pfioc_rule *);
   1803  1.16      yamt void			 pf_anchor_remove(struct pf_rule *);
   1804  1.16      yamt void			 pf_remove_if_empty_ruleset(struct pf_ruleset *);
   1805  1.16      yamt struct pf_anchor	*pf_find_anchor(const char *);
   1806  1.16      yamt struct pf_ruleset	*pf_find_ruleset(const char *);
   1807  1.16      yamt struct pf_ruleset	*pf_find_or_create_ruleset(const char *);
   1808  1.16      yamt void			 pf_rs_initialize(void);
   1809  1.16      yamt 
   1810  1.16      yamt #ifdef _KERNEL
   1811  1.16      yamt int			 pf_anchor_copyout(const struct pf_ruleset *,
   1812  1.16      yamt 			    const struct pf_rule *, struct pfioc_rule *);
   1813  1.16      yamt void			 pf_anchor_remove(struct pf_rule *);
   1814  1.16      yamt 
   1815   1.1    itojun #endif /* _KERNEL */
   1816   1.1    itojun 
   1817   1.1    itojun /* The fingerprint functions can be linked into userland programs (tcpdump) */
   1818   1.1    itojun int	pf_osfp_add(struct pf_osfp_ioctl *);
   1819   1.1    itojun #ifdef _KERNEL
   1820   1.1    itojun struct pf_osfp_enlist *
   1821   1.1    itojun 	pf_osfp_fingerprint(struct pf_pdesc *, struct mbuf *, int,
   1822   1.1    itojun 	    const struct tcphdr *);
   1823   1.1    itojun #endif /* _KERNEL */
   1824   1.1    itojun struct pf_osfp_enlist *
   1825  1.16      yamt 	pf_osfp_fingerprint_hdr(const struct ip *, const struct ip6_hdr *,
   1826  1.16      yamt 	    const struct tcphdr *);
   1827   1.1    itojun void	pf_osfp_flush(void);
   1828   1.1    itojun int	pf_osfp_get(struct pf_osfp_ioctl *);
   1829   1.1    itojun void	pf_osfp_initialize(void);
   1830  1.18     ahoka #ifdef _MODULE
   1831  1.18     ahoka void	pf_osfp_destroy(void);
   1832  1.18     ahoka #endif /* _MODULE */
   1833   1.1    itojun int	pf_osfp_match(struct pf_osfp_enlist *, pf_osfp_t);
   1834   1.1    itojun struct pf_os_fingerprint *
   1835   1.1    itojun 	pf_osfp_validate(void);
   1836   1.1    itojun 
   1837   1.1    itojun 
   1838   1.1    itojun #endif /* _NET_PFVAR_H_ */
   1839