Home | History | Annotate | Line # | Download | only in net
pfvar.h revision 1.1
      1  1.1  itojun /*	$OpenBSD: pfvar.h,v 1.187 2004/03/22 04:54:18 mcbride Exp $ */
      2  1.1  itojun 
      3  1.1  itojun /*
      4  1.1  itojun  * Copyright (c) 2001 Daniel Hartmeier
      5  1.1  itojun  * All rights reserved.
      6  1.1  itojun  *
      7  1.1  itojun  * Redistribution and use in source and binary forms, with or without
      8  1.1  itojun  * modification, are permitted provided that the following conditions
      9  1.1  itojun  * are met:
     10  1.1  itojun  *
     11  1.1  itojun  *    - Redistributions of source code must retain the above copyright
     12  1.1  itojun  *      notice, this list of conditions and the following disclaimer.
     13  1.1  itojun  *    - Redistributions in binary form must reproduce the above
     14  1.1  itojun  *      copyright notice, this list of conditions and the following
     15  1.1  itojun  *      disclaimer in the documentation and/or other materials provided
     16  1.1  itojun  *      with the distribution.
     17  1.1  itojun  *
     18  1.1  itojun  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  1.1  itojun  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  1.1  itojun  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     21  1.1  itojun  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     22  1.1  itojun  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     23  1.1  itojun  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     24  1.1  itojun  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     25  1.1  itojun  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     26  1.1  itojun  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  1.1  itojun  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     28  1.1  itojun  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  itojun  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  itojun  *
     31  1.1  itojun  */
     32  1.1  itojun 
     33  1.1  itojun #ifndef _NET_PFVAR_H_
     34  1.1  itojun #define _NET_PFVAR_H_
     35  1.1  itojun 
     36  1.1  itojun #include <sys/types.h>
     37  1.1  itojun #include <sys/queue.h>
     38  1.1  itojun #include <sys/tree.h>
     39  1.1  itojun 
     40  1.1  itojun #include <net/radix.h>
     41  1.1  itojun #include <netinet/ip_ipsp.h>
     42  1.1  itojun #include <netinet/tcp_fsm.h>
     43  1.1  itojun 
     44  1.1  itojun struct ip;
     45  1.1  itojun 
     46  1.1  itojun #define	PF_TCPS_PROXY_SRC	((TCP_NSTATES)+0)
     47  1.1  itojun #define	PF_TCPS_PROXY_DST	((TCP_NSTATES)+1)
     48  1.1  itojun 
     49  1.1  itojun enum	{ PF_INOUT, PF_IN, PF_OUT };
     50  1.1  itojun enum	{ PF_LAN_EXT, PF_EXT_GWY, PF_ID };
     51  1.1  itojun enum	{ PF_PASS, PF_DROP, PF_SCRUB, PF_NAT, PF_NONAT,
     52  1.1  itojun 	  PF_BINAT, PF_NOBINAT, PF_RDR, PF_NORDR, PF_SYNPROXY_DROP };
     53  1.1  itojun enum	{ PF_RULESET_SCRUB, PF_RULESET_FILTER, PF_RULESET_NAT,
     54  1.1  itojun 	  PF_RULESET_BINAT, PF_RULESET_RDR, PF_RULESET_MAX };
     55  1.1  itojun enum	{ PF_OP_NONE, PF_OP_IRG, PF_OP_EQ, PF_OP_NE, PF_OP_LT,
     56  1.1  itojun 	  PF_OP_LE, PF_OP_GT, PF_OP_GE, PF_OP_XRG, PF_OP_RRG };
     57  1.1  itojun enum	{ PF_DEBUG_NONE, PF_DEBUG_URGENT, PF_DEBUG_MISC, PF_DEBUG_NOISY };
     58  1.1  itojun enum	{ PF_CHANGE_NONE, PF_CHANGE_ADD_HEAD, PF_CHANGE_ADD_TAIL,
     59  1.1  itojun 	  PF_CHANGE_ADD_BEFORE, PF_CHANGE_ADD_AFTER,
     60  1.1  itojun 	  PF_CHANGE_REMOVE, PF_CHANGE_GET_TICKET };
     61  1.1  itojun /*
     62  1.1  itojun  * Note about PFTM_*: real indices into pf_rule.timeout[] come before
     63  1.1  itojun  * PFTM_MAX, special cases afterwards. See pf_state_expires().
     64  1.1  itojun  */
     65  1.1  itojun enum	{ PFTM_TCP_FIRST_PACKET, PFTM_TCP_OPENING, PFTM_TCP_ESTABLISHED,
     66  1.1  itojun 	  PFTM_TCP_CLOSING, PFTM_TCP_FIN_WAIT, PFTM_TCP_CLOSED,
     67  1.1  itojun 	  PFTM_UDP_FIRST_PACKET, PFTM_UDP_SINGLE, PFTM_UDP_MULTIPLE,
     68  1.1  itojun 	  PFTM_ICMP_FIRST_PACKET, PFTM_ICMP_ERROR_REPLY,
     69  1.1  itojun 	  PFTM_OTHER_FIRST_PACKET, PFTM_OTHER_SINGLE,
     70  1.1  itojun 	  PFTM_OTHER_MULTIPLE, PFTM_FRAG, PFTM_INTERVAL,
     71  1.1  itojun 	  PFTM_ADAPTIVE_START, PFTM_ADAPTIVE_END, PFTM_SRC_NODE,
     72  1.1  itojun 	  PFTM_MAX, PFTM_PURGE, PFTM_UNTIL_PACKET };
     73  1.1  itojun enum	{ PF_NOPFROUTE, PF_FASTROUTE, PF_ROUTETO, PF_DUPTO, PF_REPLYTO };
     74  1.1  itojun enum	{ PF_LIMIT_STATES, PF_LIMIT_SRC_NODES, PF_LIMIT_FRAGS, PF_LIMIT_MAX };
     75  1.1  itojun #define PF_POOL_IDMASK		0x0f
     76  1.1  itojun enum	{ PF_POOL_NONE, PF_POOL_BITMASK, PF_POOL_RANDOM,
     77  1.1  itojun 	  PF_POOL_SRCHASH, PF_POOL_ROUNDROBIN };
     78  1.1  itojun enum	{ PF_ADDR_ADDRMASK, PF_ADDR_NOROUTE, PF_ADDR_DYNIFTL,
     79  1.1  itojun 	  PF_ADDR_TABLE };
     80  1.1  itojun #define PF_POOL_TYPEMASK	0x0f
     81  1.1  itojun #define PF_POOL_STICKYADDR	0x20
     82  1.1  itojun #define	PF_WSCALE_FLAG		0x80
     83  1.1  itojun #define	PF_WSCALE_MASK		0x0f
     84  1.1  itojun 
     85  1.1  itojun struct pf_addr {
     86  1.1  itojun 	union {
     87  1.1  itojun 		struct in_addr		v4;
     88  1.1  itojun 		struct in6_addr		v6;
     89  1.1  itojun 		u_int8_t		addr8[16];
     90  1.1  itojun 		u_int16_t		addr16[8];
     91  1.1  itojun 		u_int32_t		addr32[4];
     92  1.1  itojun 	} pfa;		    /* 128-bit address */
     93  1.1  itojun #define v4	pfa.v4
     94  1.1  itojun #define v6	pfa.v6
     95  1.1  itojun #define addr8	pfa.addr8
     96  1.1  itojun #define addr16	pfa.addr16
     97  1.1  itojun #define addr32	pfa.addr32
     98  1.1  itojun };
     99  1.1  itojun 
    100  1.1  itojun #define	PF_TABLE_NAME_SIZE	 32
    101  1.1  itojun 
    102  1.1  itojun #define PFI_AFLAG_NETWORK	0x01
    103  1.1  itojun #define PFI_AFLAG_BROADCAST	0x02
    104  1.1  itojun #define PFI_AFLAG_PEER		0x04
    105  1.1  itojun #define PFI_AFLAG_MODEMASK	0x07
    106  1.1  itojun #define PFI_AFLAG_NOALIAS	0x08
    107  1.1  itojun 
    108  1.1  itojun struct pf_addr_wrap {
    109  1.1  itojun 	union {
    110  1.1  itojun 		struct {
    111  1.1  itojun 			struct pf_addr		 addr;
    112  1.1  itojun 			struct pf_addr		 mask;
    113  1.1  itojun 		}			 a;
    114  1.1  itojun 		char			 ifname[IFNAMSIZ];
    115  1.1  itojun 		char			 tblname[PF_TABLE_NAME_SIZE];
    116  1.1  itojun 	}			 v;
    117  1.1  itojun 	union {
    118  1.1  itojun 		struct pfi_dynaddr	*dyn;
    119  1.1  itojun 		struct pfr_ktable	*tbl;
    120  1.1  itojun 		int			 dyncnt;
    121  1.1  itojun 		int			 tblcnt;
    122  1.1  itojun 	}			 p;
    123  1.1  itojun 	u_int8_t		 type;		/* PF_ADDR_* */
    124  1.1  itojun 	u_int8_t		 iflags;	/* PFI_AFLAG_* */
    125  1.1  itojun };
    126  1.1  itojun 
    127  1.1  itojun #ifdef _KERNEL
    128  1.1  itojun 
    129  1.1  itojun struct pfi_dynaddr {
    130  1.1  itojun 	struct pf_addr		 pfid_addr4;
    131  1.1  itojun 	struct pf_addr		 pfid_mask4;
    132  1.1  itojun 	struct pf_addr		 pfid_addr6;
    133  1.1  itojun 	struct pf_addr		 pfid_mask6;
    134  1.1  itojun 	struct pfr_ktable	*pfid_kt;
    135  1.1  itojun 	struct pfi_kif		*pfid_kif;
    136  1.1  itojun 	void			*pfid_hook_cookie;
    137  1.1  itojun 	int			 pfid_net;	/* optional mask, or 128 */
    138  1.1  itojun 	int			 pfid_acnt4;	/* address count, IPv4 */
    139  1.1  itojun 	int			 pfid_acnt6;	/* address count, IPv6 */
    140  1.1  itojun 	sa_family_t		 pfid_af;	/* rule address family */
    141  1.1  itojun 	u_int8_t		 pfid_iflags;	/* PFI_AFLAG_* */
    142  1.1  itojun };
    143  1.1  itojun 
    144  1.1  itojun /*
    145  1.1  itojun  * Address manipulation macros
    146  1.1  itojun  */
    147  1.1  itojun 
    148  1.1  itojun #ifdef INET
    149  1.1  itojun #ifndef INET6
    150  1.1  itojun #define PF_INET_ONLY
    151  1.1  itojun #endif /* ! INET6 */
    152  1.1  itojun #endif /* INET */
    153  1.1  itojun 
    154  1.1  itojun #ifdef INET6
    155  1.1  itojun #ifndef INET
    156  1.1  itojun #define PF_INET6_ONLY
    157  1.1  itojun #endif /* ! INET */
    158  1.1  itojun #endif /* INET6 */
    159  1.1  itojun 
    160  1.1  itojun #ifdef INET
    161  1.1  itojun #ifdef INET6
    162  1.1  itojun #define PF_INET_INET6
    163  1.1  itojun #endif /* INET6 */
    164  1.1  itojun #endif /* INET */
    165  1.1  itojun 
    166  1.1  itojun #else
    167  1.1  itojun 
    168  1.1  itojun #define PF_INET_INET6
    169  1.1  itojun 
    170  1.1  itojun #endif /* _KERNEL */
    171  1.1  itojun 
    172  1.1  itojun /* Both IPv4 and IPv6 */
    173  1.1  itojun #ifdef PF_INET_INET6
    174  1.1  itojun 
    175  1.1  itojun #define PF_AEQ(a, b, c) \
    176  1.1  itojun 	((c == AF_INET && (a)->addr32[0] == (b)->addr32[0]) || \
    177  1.1  itojun 	((a)->addr32[3] == (b)->addr32[3] && \
    178  1.1  itojun 	(a)->addr32[2] == (b)->addr32[2] && \
    179  1.1  itojun 	(a)->addr32[1] == (b)->addr32[1] && \
    180  1.1  itojun 	(a)->addr32[0] == (b)->addr32[0])) \
    181  1.1  itojun 
    182  1.1  itojun #define PF_ANEQ(a, b, c) \
    183  1.1  itojun 	((c == AF_INET && (a)->addr32[0] != (b)->addr32[0]) || \
    184  1.1  itojun 	((a)->addr32[3] != (b)->addr32[3] || \
    185  1.1  itojun 	(a)->addr32[2] != (b)->addr32[2] || \
    186  1.1  itojun 	(a)->addr32[1] != (b)->addr32[1] || \
    187  1.1  itojun 	(a)->addr32[0] != (b)->addr32[0])) \
    188  1.1  itojun 
    189  1.1  itojun #define PF_AZERO(a, c) \
    190  1.1  itojun 	((c == AF_INET && !(a)->addr32[0]) || \
    191  1.1  itojun 	(!(a)->addr32[0] && !(a)->addr32[1] && \
    192  1.1  itojun 	!(a)->addr32[2] && !(a)->addr32[3] )) \
    193  1.1  itojun 
    194  1.1  itojun #define PF_MATCHA(n, a, m, b, f) \
    195  1.1  itojun 	pf_match_addr(n, a, m, b, f)
    196  1.1  itojun 
    197  1.1  itojun #define PF_ACPY(a, b, f) \
    198  1.1  itojun 	pf_addrcpy(a, b, f)
    199  1.1  itojun 
    200  1.1  itojun #define PF_AINC(a, f) \
    201  1.1  itojun 	pf_addr_inc(a, f)
    202  1.1  itojun 
    203  1.1  itojun #define PF_POOLMASK(a, b, c, d, f) \
    204  1.1  itojun 	pf_poolmask(a, b, c, d, f)
    205  1.1  itojun 
    206  1.1  itojun #else
    207  1.1  itojun 
    208  1.1  itojun /* Just IPv6 */
    209  1.1  itojun 
    210  1.1  itojun #ifdef PF_INET6_ONLY
    211  1.1  itojun 
    212  1.1  itojun #define PF_AEQ(a, b, c) \
    213  1.1  itojun 	((a)->addr32[3] == (b)->addr32[3] && \
    214  1.1  itojun 	(a)->addr32[2] == (b)->addr32[2] && \
    215  1.1  itojun 	(a)->addr32[1] == (b)->addr32[1] && \
    216  1.1  itojun 	(a)->addr32[0] == (b)->addr32[0]) \
    217  1.1  itojun 
    218  1.1  itojun #define PF_ANEQ(a, b, c) \
    219  1.1  itojun 	((a)->addr32[3] != (b)->addr32[3] || \
    220  1.1  itojun 	(a)->addr32[2] != (b)->addr32[2] || \
    221  1.1  itojun 	(a)->addr32[1] != (b)->addr32[1] || \
    222  1.1  itojun 	(a)->addr32[0] != (b)->addr32[0]) \
    223  1.1  itojun 
    224  1.1  itojun #define PF_AZERO(a, c) \
    225  1.1  itojun 	(!(a)->addr32[0] && \
    226  1.1  itojun 	!(a)->addr32[1] && \
    227  1.1  itojun 	!(a)->addr32[2] && \
    228  1.1  itojun 	!(a)->addr32[3] ) \
    229  1.1  itojun 
    230  1.1  itojun #define PF_MATCHA(n, a, m, b, f) \
    231  1.1  itojun 	pf_match_addr(n, a, m, b, f)
    232  1.1  itojun 
    233  1.1  itojun #define PF_ACPY(a, b, f) \
    234  1.1  itojun 	pf_addrcpy(a, b, f)
    235  1.1  itojun 
    236  1.1  itojun #define PF_AINC(a, f) \
    237  1.1  itojun 	pf_addr_inc(a, f)
    238  1.1  itojun 
    239  1.1  itojun #define PF_POOLMASK(a, b, c, d, f) \
    240  1.1  itojun 	pf_poolmask(a, b, c, d, f)
    241  1.1  itojun 
    242  1.1  itojun #else
    243  1.1  itojun 
    244  1.1  itojun /* Just IPv4 */
    245  1.1  itojun #ifdef PF_INET_ONLY
    246  1.1  itojun 
    247  1.1  itojun #define PF_AEQ(a, b, c) \
    248  1.1  itojun 	((a)->addr32[0] == (b)->addr32[0])
    249  1.1  itojun 
    250  1.1  itojun #define PF_ANEQ(a, b, c) \
    251  1.1  itojun 	((a)->addr32[0] != (b)->addr32[0])
    252  1.1  itojun 
    253  1.1  itojun #define PF_AZERO(a, c) \
    254  1.1  itojun 	(!(a)->addr32[0])
    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 	(a)->v4.s_addr = (b)->v4.s_addr
    261  1.1  itojun 
    262  1.1  itojun #define PF_AINC(a, f) \
    263  1.1  itojun 	do { \
    264  1.1  itojun 		(a)->addr32[0] = htonl(ntohl((a)->addr32[0]) + 1); \
    265  1.1  itojun 	} while (0)
    266  1.1  itojun 
    267  1.1  itojun #define PF_POOLMASK(a, b, c, d, f) \
    268  1.1  itojun 	do { \
    269  1.1  itojun 		(a)->addr32[0] = ((b)->addr32[0] & (c)->addr32[0]) | \
    270  1.1  itojun 		(((c)->addr32[0] ^ 0xffffffff ) & (d)->addr32[0]); \
    271  1.1  itojun 	} while (0)
    272  1.1  itojun 
    273  1.1  itojun #endif /* PF_INET_ONLY */
    274  1.1  itojun #endif /* PF_INET6_ONLY */
    275  1.1  itojun #endif /* PF_INET_INET6 */
    276  1.1  itojun 
    277  1.1  itojun #define	PF_MISMATCHAW(aw, x, af, not)				\
    278  1.1  itojun 	(							\
    279  1.1  itojun 		(((aw)->type == PF_ADDR_NOROUTE &&		\
    280  1.1  itojun 		    pf_routable((x), (af))) ||			\
    281  1.1  itojun 		((aw)->type == PF_ADDR_TABLE &&			\
    282  1.1  itojun 		    !pfr_match_addr((aw)->p.tbl, (x), (af))) ||	\
    283  1.1  itojun 		((aw)->type == PF_ADDR_DYNIFTL &&		\
    284  1.1  itojun 		    !pfi_match_addr((aw)->p.dyn, (x), (af))) || \
    285  1.1  itojun 		((aw)->type == PF_ADDR_ADDRMASK &&		\
    286  1.1  itojun 		    !PF_AZERO(&(aw)->v.a.mask, (af)) &&		\
    287  1.1  itojun 		    !PF_MATCHA(0, &(aw)->v.a.addr,		\
    288  1.1  itojun 		    &(aw)->v.a.mask, (x), (af)))) !=		\
    289  1.1  itojun 		(not)						\
    290  1.1  itojun 	)
    291  1.1  itojun 
    292  1.1  itojun struct pf_rule_uid {
    293  1.1  itojun 	uid_t		 uid[2];
    294  1.1  itojun 	u_int8_t	 op;
    295  1.1  itojun };
    296  1.1  itojun 
    297  1.1  itojun struct pf_rule_gid {
    298  1.1  itojun 	uid_t		 gid[2];
    299  1.1  itojun 	u_int8_t	 op;
    300  1.1  itojun };
    301  1.1  itojun 
    302  1.1  itojun struct pf_rule_addr {
    303  1.1  itojun 	struct pf_addr_wrap	 addr;
    304  1.1  itojun 	u_int16_t		 port[2];
    305  1.1  itojun 	u_int8_t		 not;
    306  1.1  itojun 	u_int8_t		 port_op;
    307  1.1  itojun };
    308  1.1  itojun 
    309  1.1  itojun struct pf_pooladdr {
    310  1.1  itojun 	struct pf_addr_wrap		 addr;
    311  1.1  itojun 	TAILQ_ENTRY(pf_pooladdr)	 entries;
    312  1.1  itojun 	char				 ifname[IFNAMSIZ];
    313  1.1  itojun 	struct pfi_kif			*kif;
    314  1.1  itojun };
    315  1.1  itojun 
    316  1.1  itojun TAILQ_HEAD(pf_palist, pf_pooladdr);
    317  1.1  itojun 
    318  1.1  itojun struct pf_poolhashkey {
    319  1.1  itojun 	union {
    320  1.1  itojun 		u_int8_t		key8[16];
    321  1.1  itojun 		u_int16_t		key16[8];
    322  1.1  itojun 		u_int32_t		key32[4];
    323  1.1  itojun 	} pfk;		    /* 128-bit hash key */
    324  1.1  itojun #define key8	pfk.key8
    325  1.1  itojun #define key16	pfk.key16
    326  1.1  itojun #define key32	pfk.key32
    327  1.1  itojun };
    328  1.1  itojun 
    329  1.1  itojun struct pf_pool {
    330  1.1  itojun 	struct pf_palist	 list;
    331  1.1  itojun 	struct pf_pooladdr	*cur;
    332  1.1  itojun 	struct pf_poolhashkey	 key;
    333  1.1  itojun 	struct pf_addr		 counter;
    334  1.1  itojun 	int			 tblidx;
    335  1.1  itojun 	u_int16_t		 proxy_port[2];
    336  1.1  itojun 	u_int8_t		 port_op;
    337  1.1  itojun 	u_int8_t		 opts;
    338  1.1  itojun };
    339  1.1  itojun 
    340  1.1  itojun 
    341  1.1  itojun /* A packed Operating System description for fingerprinting */
    342  1.1  itojun typedef u_int32_t pf_osfp_t;
    343  1.1  itojun #define PF_OSFP_ANY	((pf_osfp_t)0)
    344  1.1  itojun #define PF_OSFP_UNKNOWN	((pf_osfp_t)-1)
    345  1.1  itojun #define PF_OSFP_NOMATCH	((pf_osfp_t)-2)
    346  1.1  itojun 
    347  1.1  itojun struct pf_osfp_entry {
    348  1.1  itojun 	SLIST_ENTRY(pf_osfp_entry) fp_entry;
    349  1.1  itojun 	pf_osfp_t		fp_os;
    350  1.1  itojun 	int			fp_enflags;
    351  1.1  itojun #define PF_OSFP_EXPANDED	0x001		/* expanded entry */
    352  1.1  itojun #define PF_OSFP_GENERIC		0x002		/* generic signature */
    353  1.1  itojun #define PF_OSFP_NODETAIL	0x004		/* no p0f details */
    354  1.1  itojun #define PF_OSFP_LEN	32
    355  1.1  itojun 	char			fp_class_nm[PF_OSFP_LEN];
    356  1.1  itojun 	char			fp_version_nm[PF_OSFP_LEN];
    357  1.1  itojun 	char			fp_subtype_nm[PF_OSFP_LEN];
    358  1.1  itojun };
    359  1.1  itojun #define PF_OSFP_ENTRY_EQ(a, b) \
    360  1.1  itojun     ((a)->fp_os == (b)->fp_os && \
    361  1.1  itojun     memcmp((a)->fp_class_nm, (b)->fp_class_nm, PF_OSFP_LEN) == 0 && \
    362  1.1  itojun     memcmp((a)->fp_version_nm, (b)->fp_version_nm, PF_OSFP_LEN) == 0 && \
    363  1.1  itojun     memcmp((a)->fp_subtype_nm, (b)->fp_subtype_nm, PF_OSFP_LEN) == 0)
    364  1.1  itojun 
    365  1.1  itojun /* handle pf_osfp_t packing */
    366  1.1  itojun #define _FP_RESERVED_BIT	1  /* For the special negative #defines */
    367  1.1  itojun #define _FP_UNUSED_BITS		1
    368  1.1  itojun #define _FP_CLASS_BITS		10 /* OS Class (Windows, Linux) */
    369  1.1  itojun #define _FP_VERSION_BITS	10 /* OS version (95, 98, NT, 2.4.54, 3.2) */
    370  1.1  itojun #define _FP_SUBTYPE_BITS	10 /* patch level (NT SP4, SP3, ECN patch) */
    371  1.1  itojun #define PF_OSFP_UNPACK(osfp, class, version, subtype) do { \
    372  1.1  itojun 	(class) = ((osfp) >> (_FP_VERSION_BITS+_FP_SUBTYPE_BITS)) & \
    373  1.1  itojun 	    ((1 << _FP_CLASS_BITS) - 1); \
    374  1.1  itojun 	(version) = ((osfp) >> _FP_SUBTYPE_BITS) & \
    375  1.1  itojun 	    ((1 << _FP_VERSION_BITS) - 1);\
    376  1.1  itojun 	(subtype) = (osfp) & ((1 << _FP_SUBTYPE_BITS) - 1); \
    377  1.1  itojun } while(0)
    378  1.1  itojun #define PF_OSFP_PACK(osfp, class, version, subtype) do { \
    379  1.1  itojun 	(osfp) = ((class) & ((1 << _FP_CLASS_BITS) - 1)) << (_FP_VERSION_BITS \
    380  1.1  itojun 	    + _FP_SUBTYPE_BITS); \
    381  1.1  itojun 	(osfp) |= ((version) & ((1 << _FP_VERSION_BITS) - 1)) << \
    382  1.1  itojun 	    _FP_SUBTYPE_BITS; \
    383  1.1  itojun 	(osfp) |= (subtype) & ((1 << _FP_SUBTYPE_BITS) - 1); \
    384  1.1  itojun } while(0)
    385  1.1  itojun 
    386  1.1  itojun /* the fingerprint of an OSes TCP SYN packet */
    387  1.1  itojun typedef u_int64_t	pf_tcpopts_t;
    388  1.1  itojun struct pf_os_fingerprint {
    389  1.1  itojun 	SLIST_HEAD(pf_osfp_enlist, pf_osfp_entry) fp_oses; /* list of matches */
    390  1.1  itojun 	pf_tcpopts_t		fp_tcpopts;	/* packed TCP options */
    391  1.1  itojun 	u_int16_t		fp_wsize;	/* TCP window size */
    392  1.1  itojun 	u_int16_t		fp_psize;	/* ip->ip_len */
    393  1.1  itojun 	u_int16_t		fp_mss;		/* TCP MSS */
    394  1.1  itojun 	u_int16_t		fp_flags;
    395  1.1  itojun #define PF_OSFP_WSIZE_MOD	0x0001		/* Window modulus */
    396  1.1  itojun #define PF_OSFP_WSIZE_DC	0x0002		/* Window don't care */
    397  1.1  itojun #define PF_OSFP_WSIZE_MSS	0x0004		/* Window multiple of MSS */
    398  1.1  itojun #define PF_OSFP_WSIZE_MTU	0x0008		/* Window multiple of MTU */
    399  1.1  itojun #define PF_OSFP_PSIZE_MOD	0x0010		/* packet size modulus */
    400  1.1  itojun #define PF_OSFP_PSIZE_DC	0x0020		/* packet size don't care */
    401  1.1  itojun #define PF_OSFP_WSCALE		0x0040		/* TCP window scaling */
    402  1.1  itojun #define PF_OSFP_WSCALE_MOD	0x0080		/* TCP window scale modulus */
    403  1.1  itojun #define PF_OSFP_WSCALE_DC	0x0100		/* TCP window scale dont-care */
    404  1.1  itojun #define PF_OSFP_MSS		0x0200		/* TCP MSS */
    405  1.1  itojun #define PF_OSFP_MSS_MOD		0x0400		/* TCP MSS modulus */
    406  1.1  itojun #define PF_OSFP_MSS_DC		0x0800		/* TCP MSS dont-care */
    407  1.1  itojun #define PF_OSFP_DF		0x1000		/* IPv4 don't fragment bit */
    408  1.1  itojun #define PF_OSFP_TS0		0x2000		/* Zero timestamp */
    409  1.1  itojun 	u_int8_t		fp_optcnt;	/* TCP option count */
    410  1.1  itojun 	u_int8_t		fp_wscale;	/* TCP window scaling */
    411  1.1  itojun 	u_int8_t		fp_ttl;		/* IPv4 TTL */
    412  1.1  itojun #define PF_OSFP_MAXTTL_OFFSET	40
    413  1.1  itojun /* TCP options packing */
    414  1.1  itojun #define PF_OSFP_TCPOPT_NOP	0x0		/* TCP NOP option */
    415  1.1  itojun #define PF_OSFP_TCPOPT_WSCALE	0x1		/* TCP window scaling option */
    416  1.1  itojun #define PF_OSFP_TCPOPT_MSS	0x2		/* TCP max segment size opt */
    417  1.1  itojun #define PF_OSFP_TCPOPT_SACK	0x3		/* TCP SACK OK option */
    418  1.1  itojun #define PF_OSFP_TCPOPT_TS	0x4		/* TCP timestamp option */
    419  1.1  itojun #define PF_OSFP_TCPOPT_BITS	3		/* bits used by each option */
    420  1.1  itojun #define PF_OSFP_MAX_OPTS \
    421  1.1  itojun     (sizeof(((struct pf_os_fingerprint *)0)->fp_tcpopts) * 8) \
    422  1.1  itojun     / PF_OSFP_TCPOPT_BITS
    423  1.1  itojun 
    424  1.1  itojun 	SLIST_ENTRY(pf_os_fingerprint)	fp_next;
    425  1.1  itojun };
    426  1.1  itojun 
    427  1.1  itojun struct pf_osfp_ioctl {
    428  1.1  itojun 	struct pf_osfp_entry	fp_os;
    429  1.1  itojun 	pf_tcpopts_t		fp_tcpopts;	/* packed TCP options */
    430  1.1  itojun 	u_int16_t		fp_wsize;	/* TCP window size */
    431  1.1  itojun 	u_int16_t		fp_psize;	/* ip->ip_len */
    432  1.1  itojun 	u_int16_t		fp_mss;		/* TCP MSS */
    433  1.1  itojun 	u_int16_t		fp_flags;
    434  1.1  itojun 	u_int8_t		fp_optcnt;	/* TCP option count */
    435  1.1  itojun 	u_int8_t		fp_wscale;	/* TCP window scaling */
    436  1.1  itojun 	u_int8_t		fp_ttl;		/* IPv4 TTL */
    437  1.1  itojun 
    438  1.1  itojun 	int			fp_getnum;	/* DIOCOSFPGET number */
    439  1.1  itojun };
    440  1.1  itojun 
    441  1.1  itojun 
    442  1.1  itojun union pf_rule_ptr {
    443  1.1  itojun 	struct pf_rule		*ptr;
    444  1.1  itojun 	u_int32_t		 nr;
    445  1.1  itojun };
    446  1.1  itojun 
    447  1.1  itojun struct pf_rule {
    448  1.1  itojun 	struct pf_rule_addr	 src;
    449  1.1  itojun 	struct pf_rule_addr	 dst;
    450  1.1  itojun #define PF_SKIP_IFP		0
    451  1.1  itojun #define PF_SKIP_DIR		1
    452  1.1  itojun #define PF_SKIP_AF		2
    453  1.1  itojun #define PF_SKIP_PROTO		3
    454  1.1  itojun #define PF_SKIP_SRC_ADDR	4
    455  1.1  itojun #define PF_SKIP_SRC_PORT	5
    456  1.1  itojun #define PF_SKIP_DST_ADDR	6
    457  1.1  itojun #define PF_SKIP_DST_PORT	7
    458  1.1  itojun #define PF_SKIP_COUNT		8
    459  1.1  itojun 	union pf_rule_ptr	 skip[PF_SKIP_COUNT];
    460  1.1  itojun #define PF_RULE_LABEL_SIZE	 64
    461  1.1  itojun 	char			 label[PF_RULE_LABEL_SIZE];
    462  1.1  itojun #define PF_QNAME_SIZE		 16
    463  1.1  itojun 	char			 ifname[IFNAMSIZ];
    464  1.1  itojun 	char			 qname[PF_QNAME_SIZE];
    465  1.1  itojun 	char			 pqname[PF_QNAME_SIZE];
    466  1.1  itojun #define	PF_ANCHOR_NAME_SIZE	 16
    467  1.1  itojun 	char			 anchorname[PF_ANCHOR_NAME_SIZE];
    468  1.1  itojun #define	PF_TAG_NAME_SIZE	 16
    469  1.1  itojun 	char			 tagname[PF_TAG_NAME_SIZE];
    470  1.1  itojun 	char			 match_tagname[PF_TAG_NAME_SIZE];
    471  1.1  itojun 
    472  1.1  itojun 	TAILQ_ENTRY(pf_rule)	 entries;
    473  1.1  itojun 	struct pf_pool		 rpool;
    474  1.1  itojun 
    475  1.1  itojun 	u_int64_t		 evaluations;
    476  1.1  itojun 	u_int64_t		 packets;
    477  1.1  itojun 	u_int64_t		 bytes;
    478  1.1  itojun 
    479  1.1  itojun 	struct pfi_kif		*kif;
    480  1.1  itojun 	struct pf_anchor	*anchor;
    481  1.1  itojun 
    482  1.1  itojun 	pf_osfp_t		 os_fingerprint;
    483  1.1  itojun 
    484  1.1  itojun 	u_int32_t		 timeout[PFTM_MAX];
    485  1.1  itojun 	u_int32_t		 states;
    486  1.1  itojun 	u_int32_t		 max_states;
    487  1.1  itojun 	u_int32_t		 src_nodes;
    488  1.1  itojun 	u_int32_t		 max_src_nodes;
    489  1.1  itojun 	u_int32_t		 max_src_states;
    490  1.1  itojun 	u_int32_t		 qid;
    491  1.1  itojun 	u_int32_t		 pqid;
    492  1.1  itojun 	u_int32_t		 rt_listid;
    493  1.1  itojun 	u_int32_t		 nr;
    494  1.1  itojun 
    495  1.1  itojun 	u_int16_t		 return_icmp;
    496  1.1  itojun 	u_int16_t		 return_icmp6;
    497  1.1  itojun 	u_int16_t		 max_mss;
    498  1.1  itojun 	u_int16_t		 tag;
    499  1.1  itojun 	u_int16_t		 match_tag;
    500  1.1  itojun 
    501  1.1  itojun 	struct pf_rule_uid	 uid;
    502  1.1  itojun 	struct pf_rule_gid	 gid;
    503  1.1  itojun 
    504  1.1  itojun 	u_int32_t		 rule_flag;
    505  1.1  itojun 	u_int8_t		 action;
    506  1.1  itojun 	u_int8_t		 direction;
    507  1.1  itojun 	u_int8_t		 log;
    508  1.1  itojun 	u_int8_t		 quick;
    509  1.1  itojun 	u_int8_t		 ifnot;
    510  1.1  itojun 	u_int8_t		 match_tag_not;
    511  1.1  itojun 	u_int8_t		 natpass;
    512  1.1  itojun 
    513  1.1  itojun #define PF_STATE_NORMAL		0x1
    514  1.1  itojun #define PF_STATE_MODULATE	0x2
    515  1.1  itojun #define PF_STATE_SYNPROXY	0x3
    516  1.1  itojun 	u_int8_t		 keep_state;
    517  1.1  itojun 	sa_family_t		 af;
    518  1.1  itojun 	u_int8_t		 proto;
    519  1.1  itojun 	u_int8_t		 type;
    520  1.1  itojun 	u_int8_t		 code;
    521  1.1  itojun 	u_int8_t		 flags;
    522  1.1  itojun 	u_int8_t		 flagset;
    523  1.1  itojun 	u_int8_t		 min_ttl;
    524  1.1  itojun 	u_int8_t		 allow_opts;
    525  1.1  itojun 	u_int8_t		 rt;
    526  1.1  itojun 	u_int8_t		 return_ttl;
    527  1.1  itojun 	u_int8_t		 tos;
    528  1.1  itojun };
    529  1.1  itojun 
    530  1.1  itojun /* rule flags */
    531  1.1  itojun #define	PFRULE_DROP		0x0000
    532  1.1  itojun #define	PFRULE_RETURNRST	0x0001
    533  1.1  itojun #define	PFRULE_FRAGMENT		0x0002
    534  1.1  itojun #define	PFRULE_RETURNICMP	0x0004
    535  1.1  itojun #define	PFRULE_RETURN		0x0008
    536  1.1  itojun #define	PFRULE_NOSYNC		0x0010
    537  1.1  itojun #define PFRULE_SRCTRACK		0x0020  /* track source states */
    538  1.1  itojun #define PFRULE_RULESRCTRACK	0x0040  /* per rule */
    539  1.1  itojun 
    540  1.1  itojun /* scrub flags */
    541  1.1  itojun #define	PFRULE_NODF		0x0100
    542  1.1  itojun #define	PFRULE_FRAGCROP		0x0200	/* non-buffering frag cache */
    543  1.1  itojun #define	PFRULE_FRAGDROP		0x0400	/* drop funny fragments */
    544  1.1  itojun #define PFRULE_RANDOMID		0x0800
    545  1.1  itojun #define PFRULE_REASSEMBLE_TCP	0x1000
    546  1.1  itojun 
    547  1.1  itojun /* rule flags again */
    548  1.1  itojun #define PFRULE_IFBOUND		0x00010000	/* if-bound */
    549  1.1  itojun #define PFRULE_GRBOUND		0x00020000	/* group-bound */
    550  1.1  itojun 
    551  1.1  itojun #define PFSTATE_HIWAT		10000	/* default state table size */
    552  1.1  itojun 
    553  1.1  itojun struct pf_src_node {
    554  1.1  itojun 	RB_ENTRY(pf_src_node) entry;
    555  1.1  itojun 	struct pf_addr	 addr;
    556  1.1  itojun 	struct pf_addr	 raddr;
    557  1.1  itojun 	union pf_rule_ptr rule;
    558  1.1  itojun 	struct pfi_kif	*kif;
    559  1.1  itojun 	u_int32_t	 bytes;
    560  1.1  itojun 	u_int32_t	 packets;
    561  1.1  itojun 	u_int32_t	 states;
    562  1.1  itojun 	u_int32_t	 creation;
    563  1.1  itojun 	u_int32_t	 expire;
    564  1.1  itojun 	sa_family_t	 af;
    565  1.1  itojun 	u_int8_t	 ruletype;
    566  1.1  itojun };
    567  1.1  itojun 
    568  1.1  itojun #define PFSNODE_HIWAT		10000	/* default source node table size */
    569  1.1  itojun 
    570  1.1  itojun struct pf_state_scrub {
    571  1.1  itojun 	u_int16_t	pfss_flags;
    572  1.1  itojun #define PFSS_TIMESTAMP	0x0001		/* modulate timestamp	*/
    573  1.1  itojun 	u_int8_t	pfss_ttl;	/* stashed TTL		*/
    574  1.1  itojun 	u_int8_t	pad;
    575  1.1  itojun 	u_int32_t	pfss_ts_mod;	/* timestamp modulation	*/
    576  1.1  itojun };
    577  1.1  itojun 
    578  1.1  itojun struct pf_state_host {
    579  1.1  itojun 	struct pf_addr	addr;
    580  1.1  itojun 	u_int16_t	port;
    581  1.1  itojun 	u_int16_t	pad;
    582  1.1  itojun };
    583  1.1  itojun 
    584  1.1  itojun struct pf_state_peer {
    585  1.1  itojun 	u_int32_t	seqlo;		/* Max sequence number sent	*/
    586  1.1  itojun 	u_int32_t	seqhi;		/* Max the other end ACKd + win	*/
    587  1.1  itojun 	u_int32_t	seqdiff;	/* Sequence number modulator	*/
    588  1.1  itojun 	u_int16_t	max_win;	/* largest window (pre scaling)	*/
    589  1.1  itojun 	u_int8_t	state;		/* active state level		*/
    590  1.1  itojun 	u_int8_t	wscale;		/* window scaling factor	*/
    591  1.1  itojun 	u_int16_t	mss;		/* Maximum segment size option	*/
    592  1.1  itojun 	struct pf_state_scrub	*scrub;	/* state is scrubbed		*/
    593  1.1  itojun };
    594  1.1  itojun 
    595  1.1  itojun TAILQ_HEAD(pf_state_queue, pf_state);
    596  1.1  itojun 
    597  1.1  itojun struct pf_state {
    598  1.1  itojun 	u_int64_t	 id;
    599  1.1  itojun 	union {
    600  1.1  itojun 		struct {
    601  1.1  itojun 			RB_ENTRY(pf_state)	 entry_lan_ext;
    602  1.1  itojun 			RB_ENTRY(pf_state)	 entry_ext_gwy;
    603  1.1  itojun 			RB_ENTRY(pf_state)	 entry_id;
    604  1.1  itojun 			TAILQ_ENTRY(pf_state)	 entry_updates;
    605  1.1  itojun 			struct pfi_kif		*kif;
    606  1.1  itojun 		} s;
    607  1.1  itojun 		char	 ifname[IFNAMSIZ];
    608  1.1  itojun 	} u;
    609  1.1  itojun 	struct pf_state_host lan;
    610  1.1  itojun 	struct pf_state_host gwy;
    611  1.1  itojun 	struct pf_state_host ext;
    612  1.1  itojun 	struct pf_state_peer src;
    613  1.1  itojun 	struct pf_state_peer dst;
    614  1.1  itojun 	union pf_rule_ptr rule;
    615  1.1  itojun 	union pf_rule_ptr anchor;
    616  1.1  itojun 	union pf_rule_ptr nat_rule;
    617  1.1  itojun 	struct pf_addr	 rt_addr;
    618  1.1  itojun 	struct pfi_kif	*rt_kif;
    619  1.1  itojun 	struct pf_src_node	*src_node;
    620  1.1  itojun 	struct pf_src_node	*nat_src_node;
    621  1.1  itojun 	u_int32_t	 creation;
    622  1.1  itojun 	u_int32_t	 expire;
    623  1.1  itojun 	u_int32_t	 pfsync_time;
    624  1.1  itojun 	u_int32_t	 packets[2];
    625  1.1  itojun 	u_int32_t	 bytes[2];
    626  1.1  itojun 	u_int32_t	 creatorid;
    627  1.1  itojun 	sa_family_t	 af;
    628  1.1  itojun 	u_int8_t	 proto;
    629  1.1  itojun 	u_int8_t	 direction;
    630  1.1  itojun 	u_int8_t	 log;
    631  1.1  itojun 	u_int8_t	 allow_opts;
    632  1.1  itojun 	u_int8_t	 timeout;
    633  1.1  itojun 	u_int8_t	 sync_flags;
    634  1.1  itojun #define	PFSTATE_NOSYNC	 0x01
    635  1.1  itojun #define	PFSTATE_FROMSYNC 0x02
    636  1.1  itojun 	u_int8_t	 pad;
    637  1.1  itojun };
    638  1.1  itojun 
    639  1.1  itojun TAILQ_HEAD(pf_rulequeue, pf_rule);
    640  1.1  itojun 
    641  1.1  itojun struct pf_anchor;
    642  1.1  itojun 
    643  1.1  itojun struct pf_ruleset {
    644  1.1  itojun 	TAILQ_ENTRY(pf_ruleset)	 entries;
    645  1.1  itojun #define PF_RULESET_NAME_SIZE	 16
    646  1.1  itojun 	char			 name[PF_RULESET_NAME_SIZE];
    647  1.1  itojun 	struct {
    648  1.1  itojun 		struct pf_rulequeue	 queues[2];
    649  1.1  itojun 		struct {
    650  1.1  itojun 			struct pf_rulequeue	*ptr;
    651  1.1  itojun 			u_int32_t		 ticket;
    652  1.1  itojun 			int			 open;
    653  1.1  itojun 		}			 active, inactive;
    654  1.1  itojun 	}			 rules[PF_RULESET_MAX];
    655  1.1  itojun 	struct pf_anchor	*anchor;
    656  1.1  itojun 	u_int32_t		 tticket;
    657  1.1  itojun 	int			 tables;
    658  1.1  itojun 	int			 topen;
    659  1.1  itojun };
    660  1.1  itojun 
    661  1.1  itojun TAILQ_HEAD(pf_rulesetqueue, pf_ruleset);
    662  1.1  itojun 
    663  1.1  itojun struct pf_anchor {
    664  1.1  itojun 	TAILQ_ENTRY(pf_anchor)	 entries;
    665  1.1  itojun 	char			 name[PF_ANCHOR_NAME_SIZE];
    666  1.1  itojun 	struct pf_rulesetqueue	 rulesets;
    667  1.1  itojun 	int			 tables;
    668  1.1  itojun };
    669  1.1  itojun 
    670  1.1  itojun TAILQ_HEAD(pf_anchorqueue, pf_anchor);
    671  1.1  itojun 
    672  1.1  itojun #define PF_RESERVED_ANCHOR	"_pf"
    673  1.1  itojun #define PF_INTERFACE_RULESET	"_if"
    674  1.1  itojun 
    675  1.1  itojun #define PFR_TFLAG_PERSIST	0x00000001
    676  1.1  itojun #define PFR_TFLAG_CONST		0x00000002
    677  1.1  itojun #define PFR_TFLAG_ACTIVE	0x00000004
    678  1.1  itojun #define PFR_TFLAG_INACTIVE	0x00000008
    679  1.1  itojun #define PFR_TFLAG_REFERENCED	0x00000010
    680  1.1  itojun #define PFR_TFLAG_REFDANCHOR	0x00000020
    681  1.1  itojun #define PFR_TFLAG_USRMASK	0x00000003
    682  1.1  itojun #define PFR_TFLAG_SETMASK	0x0000003C
    683  1.1  itojun #define PFR_TFLAG_ALLMASK	0x0000003F
    684  1.1  itojun 
    685  1.1  itojun struct pfr_table {
    686  1.1  itojun 	char			 pfrt_anchor[PF_ANCHOR_NAME_SIZE];
    687  1.1  itojun 	char			 pfrt_ruleset[PF_RULESET_NAME_SIZE];
    688  1.1  itojun 	char			 pfrt_name[PF_TABLE_NAME_SIZE];
    689  1.1  itojun 	u_int32_t		 pfrt_flags;
    690  1.1  itojun 	u_int8_t		 pfrt_fback;
    691  1.1  itojun };
    692  1.1  itojun 
    693  1.1  itojun enum { PFR_FB_NONE, PFR_FB_MATCH, PFR_FB_ADDED, PFR_FB_DELETED,
    694  1.1  itojun 	PFR_FB_CHANGED, PFR_FB_CLEARED, PFR_FB_DUPLICATE,
    695  1.1  itojun 	PFR_FB_NOTMATCH, PFR_FB_CONFLICT, PFR_FB_MAX };
    696  1.1  itojun 
    697  1.1  itojun struct pfr_addr {
    698  1.1  itojun 	union {
    699  1.1  itojun 		struct in_addr	 _pfra_ip4addr;
    700  1.1  itojun 		struct in6_addr	 _pfra_ip6addr;
    701  1.1  itojun 	}		 pfra_u;
    702  1.1  itojun 	u_int8_t	 pfra_af;
    703  1.1  itojun 	u_int8_t	 pfra_net;
    704  1.1  itojun 	u_int8_t	 pfra_not;
    705  1.1  itojun 	u_int8_t	 pfra_fback;
    706  1.1  itojun };
    707  1.1  itojun #define	pfra_ip4addr	pfra_u._pfra_ip4addr
    708  1.1  itojun #define	pfra_ip6addr	pfra_u._pfra_ip6addr
    709  1.1  itojun 
    710  1.1  itojun enum { PFR_DIR_IN, PFR_DIR_OUT, PFR_DIR_MAX };
    711  1.1  itojun enum { PFR_OP_BLOCK, PFR_OP_PASS, PFR_OP_ADDR_MAX, PFR_OP_TABLE_MAX };
    712  1.1  itojun #define PFR_OP_XPASS	PFR_OP_ADDR_MAX
    713  1.1  itojun 
    714  1.1  itojun struct pfr_astats {
    715  1.1  itojun 	struct pfr_addr	 pfras_a;
    716  1.1  itojun 	u_int64_t	 pfras_packets[PFR_DIR_MAX][PFR_OP_ADDR_MAX];
    717  1.1  itojun 	u_int64_t	 pfras_bytes[PFR_DIR_MAX][PFR_OP_ADDR_MAX];
    718  1.1  itojun 	long		 pfras_tzero;
    719  1.1  itojun };
    720  1.1  itojun 
    721  1.1  itojun enum { PFR_REFCNT_RULE, PFR_REFCNT_ANCHOR, PFR_REFCNT_MAX };
    722  1.1  itojun 
    723  1.1  itojun struct pfr_tstats {
    724  1.1  itojun 	struct pfr_table pfrts_t;
    725  1.1  itojun 	u_int64_t	 pfrts_packets[PFR_DIR_MAX][PFR_OP_TABLE_MAX];
    726  1.1  itojun 	u_int64_t	 pfrts_bytes[PFR_DIR_MAX][PFR_OP_TABLE_MAX];
    727  1.1  itojun 	u_int64_t	 pfrts_match;
    728  1.1  itojun 	u_int64_t	 pfrts_nomatch;
    729  1.1  itojun 	long		 pfrts_tzero;
    730  1.1  itojun 	int		 pfrts_cnt;
    731  1.1  itojun 	int		 pfrts_refcnt[PFR_REFCNT_MAX];
    732  1.1  itojun };
    733  1.1  itojun #define	pfrts_name	pfrts_t.pfrt_name
    734  1.1  itojun #define pfrts_flags	pfrts_t.pfrt_flags
    735  1.1  itojun 
    736  1.1  itojun SLIST_HEAD(pfr_kentryworkq, pfr_kentry);
    737  1.1  itojun struct pfr_kentry {
    738  1.1  itojun 	struct radix_node	 pfrke_node[2];
    739  1.1  itojun 	union sockaddr_union	 pfrke_sa;
    740  1.1  itojun 	u_int64_t		 pfrke_packets[PFR_DIR_MAX][PFR_OP_ADDR_MAX];
    741  1.1  itojun 	u_int64_t		 pfrke_bytes[PFR_DIR_MAX][PFR_OP_ADDR_MAX];
    742  1.1  itojun 	SLIST_ENTRY(pfr_kentry)	 pfrke_workq;
    743  1.1  itojun 	long			 pfrke_tzero;
    744  1.1  itojun 	u_int8_t		 pfrke_af;
    745  1.1  itojun 	u_int8_t		 pfrke_net;
    746  1.1  itojun 	u_int8_t		 pfrke_not;
    747  1.1  itojun 	u_int8_t		 pfrke_mark;
    748  1.1  itojun };
    749  1.1  itojun 
    750  1.1  itojun SLIST_HEAD(pfr_ktableworkq, pfr_ktable);
    751  1.1  itojun RB_HEAD(pfr_ktablehead, pfr_ktable);
    752  1.1  itojun struct pfr_ktable {
    753  1.1  itojun 	struct pfr_tstats	 pfrkt_ts;
    754  1.1  itojun 	RB_ENTRY(pfr_ktable)	 pfrkt_tree;
    755  1.1  itojun 	SLIST_ENTRY(pfr_ktable)	 pfrkt_workq;
    756  1.1  itojun 	struct radix_node_head	*pfrkt_ip4;
    757  1.1  itojun 	struct radix_node_head	*pfrkt_ip6;
    758  1.1  itojun 	struct pfr_ktable	*pfrkt_shadow;
    759  1.1  itojun 	struct pfr_ktable	*pfrkt_root;
    760  1.1  itojun 	struct pf_ruleset	*pfrkt_rs;
    761  1.1  itojun 	long			 pfrkt_larg;
    762  1.1  itojun 	int			 pfrkt_nflags;
    763  1.1  itojun };
    764  1.1  itojun #define pfrkt_t		pfrkt_ts.pfrts_t
    765  1.1  itojun #define pfrkt_name	pfrkt_t.pfrt_name
    766  1.1  itojun #define pfrkt_anchor	pfrkt_t.pfrt_anchor
    767  1.1  itojun #define pfrkt_ruleset	pfrkt_t.pfrt_ruleset
    768  1.1  itojun #define pfrkt_flags	pfrkt_t.pfrt_flags
    769  1.1  itojun #define pfrkt_cnt	pfrkt_ts.pfrts_cnt
    770  1.1  itojun #define pfrkt_refcnt	pfrkt_ts.pfrts_refcnt
    771  1.1  itojun #define pfrkt_packets	pfrkt_ts.pfrts_packets
    772  1.1  itojun #define pfrkt_bytes	pfrkt_ts.pfrts_bytes
    773  1.1  itojun #define pfrkt_match	pfrkt_ts.pfrts_match
    774  1.1  itojun #define pfrkt_nomatch	pfrkt_ts.pfrts_nomatch
    775  1.1  itojun #define pfrkt_tzero	pfrkt_ts.pfrts_tzero
    776  1.1  itojun 
    777  1.1  itojun RB_HEAD(pf_state_tree_lan_ext, pf_state);
    778  1.1  itojun RB_PROTOTYPE(pf_state_tree_lan_ext, pf_state,
    779  1.1  itojun     u.s.entry_lan_ext, pf_state_compare_lan_ext);
    780  1.1  itojun 
    781  1.1  itojun RB_HEAD(pf_state_tree_ext_gwy, pf_state);
    782  1.1  itojun RB_PROTOTYPE(pf_state_tree_ext_gwy, pf_state,
    783  1.1  itojun     u.s.entry_ext_gwy, pf_state_compare_ext_gwy);
    784  1.1  itojun 
    785  1.1  itojun struct pfi_if {
    786  1.1  itojun 	char				 pfif_name[IFNAMSIZ];
    787  1.1  itojun 	u_int64_t			 pfif_packets[2][2][2];
    788  1.1  itojun 	u_int64_t			 pfif_bytes[2][2][2];
    789  1.1  itojun 	u_int64_t			 pfif_addcnt;
    790  1.1  itojun 	u_int64_t			 pfif_delcnt;
    791  1.1  itojun 	long				 pfif_tzero;
    792  1.1  itojun 	int				 pfif_states;
    793  1.1  itojun 	int				 pfif_rules;
    794  1.1  itojun 	int				 pfif_flags;
    795  1.1  itojun };
    796  1.1  itojun 
    797  1.1  itojun TAILQ_HEAD(pfi_grouphead, pfi_kif);
    798  1.1  itojun TAILQ_HEAD(pfi_statehead, pfi_kif);
    799  1.1  itojun RB_HEAD(pfi_ifhead, pfi_kif);
    800  1.1  itojun struct pfi_kif {
    801  1.1  itojun 	struct pfi_if			 pfik_if;
    802  1.1  itojun 	RB_ENTRY(pfi_kif)		 pfik_tree;
    803  1.1  itojun 	struct pf_state_tree_lan_ext	 pfik_lan_ext;
    804  1.1  itojun 	struct pf_state_tree_ext_gwy	 pfik_ext_gwy;
    805  1.1  itojun 	struct pfi_grouphead		 pfik_grouphead;
    806  1.1  itojun 	TAILQ_ENTRY(pfi_kif)		 pfik_instances;
    807  1.1  itojun 	TAILQ_ENTRY(pfi_kif)		 pfik_w_states;
    808  1.1  itojun 	struct hook_desc_head		*pfik_ah_head;
    809  1.1  itojun 	void				*pfik_ah_cookie;
    810  1.1  itojun 	struct pfi_kif			*pfik_parent;
    811  1.1  itojun 	struct ifnet			*pfik_ifp;
    812  1.1  itojun 	int				 pfik_states;
    813  1.1  itojun 	int				 pfik_rules;
    814  1.1  itojun };
    815  1.1  itojun #define pfik_name	pfik_if.pfif_name
    816  1.1  itojun #define pfik_packets	pfik_if.pfif_packets
    817  1.1  itojun #define pfik_bytes	pfik_if.pfif_bytes
    818  1.1  itojun #define pfik_tzero	pfik_if.pfif_tzero
    819  1.1  itojun #define pfik_flags	pfik_if.pfif_flags
    820  1.1  itojun #define pfik_addcnt	pfik_if.pfif_addcnt
    821  1.1  itojun #define pfik_delcnt	pfik_if.pfif_delcnt
    822  1.1  itojun #define pfik_states	pfik_if.pfif_states
    823  1.1  itojun #define pfik_rules	pfik_if.pfif_rules
    824  1.1  itojun 
    825  1.1  itojun #define PFI_IFLAG_GROUP		0x0001	/* group of interfaces */
    826  1.1  itojun #define PFI_IFLAG_INSTANCE	0x0002	/* single instance */
    827  1.1  itojun #define PFI_IFLAG_CLONABLE	0x0010	/* clonable group */
    828  1.1  itojun #define PFI_IFLAG_DYNAMIC	0x0020	/* dynamic group */
    829  1.1  itojun #define PFI_IFLAG_ATTACHED	0x0040	/* interface attached */
    830  1.1  itojun 
    831  1.1  itojun struct pf_pdesc {
    832  1.1  itojun 	u_int64_t	 tot_len;	/* Make Mickey money */
    833  1.1  itojun 	union {
    834  1.1  itojun 		struct tcphdr		*tcp;
    835  1.1  itojun 		struct udphdr		*udp;
    836  1.1  itojun 		struct icmp		*icmp;
    837  1.1  itojun #ifdef INET6
    838  1.1  itojun 		struct icmp6_hdr	*icmp6;
    839  1.1  itojun #endif /* INET6 */
    840  1.1  itojun 		void			*any;
    841  1.1  itojun 	} hdr;
    842  1.1  itojun 	struct pf_addr	 baddr;		/* address before translation */
    843  1.1  itojun 	struct pf_addr	 naddr;		/* address after translation */
    844  1.1  itojun 	struct pf_rule	*nat_rule;	/* nat/rdr rule applied to packet */
    845  1.1  itojun 	struct pf_addr	*src;
    846  1.1  itojun 	struct pf_addr	*dst;
    847  1.1  itojun 	u_int16_t	*ip_sum;
    848  1.1  itojun 	u_int32_t	 p_len;		/* total length of payload */
    849  1.1  itojun 	u_int16_t	 flags;		/* Let SCRUB trigger behavior in
    850  1.1  itojun 					 * state code. Easier than tags */
    851  1.1  itojun #define PFDESC_TCP_NORM	0x0001		/* TCP shall be statefully scrubbed */
    852  1.1  itojun 	sa_family_t	 af;
    853  1.1  itojun 	u_int8_t	 proto;
    854  1.1  itojun 	u_int8_t	 tos;
    855  1.1  itojun };
    856  1.1  itojun 
    857  1.1  itojun /* flags for RDR options */
    858  1.1  itojun #define PF_DPORT_RANGE	0x01		/* Dest port uses range */
    859  1.1  itojun #define PF_RPORT_RANGE	0x02		/* RDR'ed port uses range */
    860  1.1  itojun 
    861  1.1  itojun /* Reasons code for passing/dropping a packet */
    862  1.1  itojun #define PFRES_MATCH	0		/* Explicit match of a rule */
    863  1.1  itojun #define PFRES_BADOFF	1		/* Bad offset for pull_hdr */
    864  1.1  itojun #define PFRES_FRAG	2		/* Dropping following fragment */
    865  1.1  itojun #define PFRES_SHORT	3		/* Dropping short packet */
    866  1.1  itojun #define PFRES_NORM	4		/* Dropping by normalizer */
    867  1.1  itojun #define PFRES_MEMORY	5		/* Dropped due to lacking mem */
    868  1.1  itojun #define PFRES_MAX	6		/* total+1 */
    869  1.1  itojun 
    870  1.1  itojun #define PFRES_NAMES { \
    871  1.1  itojun 	"match", \
    872  1.1  itojun 	"bad-offset", \
    873  1.1  itojun 	"fragment", \
    874  1.1  itojun 	"short", \
    875  1.1  itojun 	"normalize", \
    876  1.1  itojun 	"memory", \
    877  1.1  itojun 	NULL \
    878  1.1  itojun }
    879  1.1  itojun 
    880  1.1  itojun /* UDP state enumeration */
    881  1.1  itojun #define PFUDPS_NO_TRAFFIC	0
    882  1.1  itojun #define PFUDPS_SINGLE		1
    883  1.1  itojun #define PFUDPS_MULTIPLE		2
    884  1.1  itojun 
    885  1.1  itojun #define PFUDPS_NSTATES		3	/* number of state levels */
    886  1.1  itojun 
    887  1.1  itojun #define PFUDPS_NAMES { \
    888  1.1  itojun 	"NO_TRAFFIC", \
    889  1.1  itojun 	"SINGLE", \
    890  1.1  itojun 	"MULTIPLE", \
    891  1.1  itojun 	NULL \
    892  1.1  itojun }
    893  1.1  itojun 
    894  1.1  itojun /* Other protocol state enumeration */
    895  1.1  itojun #define PFOTHERS_NO_TRAFFIC	0
    896  1.1  itojun #define PFOTHERS_SINGLE		1
    897  1.1  itojun #define PFOTHERS_MULTIPLE	2
    898  1.1  itojun 
    899  1.1  itojun #define PFOTHERS_NSTATES	3	/* number of state levels */
    900  1.1  itojun 
    901  1.1  itojun #define PFOTHERS_NAMES { \
    902  1.1  itojun 	"NO_TRAFFIC", \
    903  1.1  itojun 	"SINGLE", \
    904  1.1  itojun 	"MULTIPLE", \
    905  1.1  itojun 	NULL \
    906  1.1  itojun }
    907  1.1  itojun 
    908  1.1  itojun #define FCNT_STATE_SEARCH	0
    909  1.1  itojun #define FCNT_STATE_INSERT	1
    910  1.1  itojun #define FCNT_STATE_REMOVALS	2
    911  1.1  itojun #define FCNT_MAX		3
    912  1.1  itojun 
    913  1.1  itojun #define SCNT_SRC_NODE_SEARCH	0
    914  1.1  itojun #define SCNT_SRC_NODE_INSERT	1
    915  1.1  itojun #define SCNT_SRC_NODE_REMOVALS	2
    916  1.1  itojun #define SCNT_MAX		3
    917  1.1  itojun 
    918  1.1  itojun #define ACTION_SET(a, x) \
    919  1.1  itojun 	do { \
    920  1.1  itojun 		if ((a) != NULL) \
    921  1.1  itojun 			*(a) = (x); \
    922  1.1  itojun 	} while (0)
    923  1.1  itojun 
    924  1.1  itojun #define REASON_SET(a, x) \
    925  1.1  itojun 	do { \
    926  1.1  itojun 		if ((a) != NULL) \
    927  1.1  itojun 			*(a) = (x); \
    928  1.1  itojun 		if (x < PFRES_MAX) \
    929  1.1  itojun 			pf_status.counters[x]++; \
    930  1.1  itojun 	} while (0)
    931  1.1  itojun 
    932  1.1  itojun struct pf_status {
    933  1.1  itojun 	u_int64_t	counters[PFRES_MAX];
    934  1.1  itojun 	u_int64_t	fcounters[FCNT_MAX];
    935  1.1  itojun 	u_int64_t	scounters[SCNT_MAX];
    936  1.1  itojun 	u_int64_t	pcounters[2][2][3];
    937  1.1  itojun 	u_int64_t	bcounters[2][2];
    938  1.1  itojun 	u_int64_t	stateid;
    939  1.1  itojun 	u_int32_t	running;
    940  1.1  itojun 	u_int32_t	states;
    941  1.1  itojun 	u_int32_t	src_nodes;
    942  1.1  itojun 	u_int32_t	since;
    943  1.1  itojun 	u_int32_t	debug;
    944  1.1  itojun 	u_int32_t	hostid;
    945  1.1  itojun 	char		ifname[IFNAMSIZ];
    946  1.1  itojun };
    947  1.1  itojun 
    948  1.1  itojun struct cbq_opts {
    949  1.1  itojun 	u_int		minburst;
    950  1.1  itojun 	u_int		maxburst;
    951  1.1  itojun 	u_int		pktsize;
    952  1.1  itojun 	u_int		maxpktsize;
    953  1.1  itojun 	u_int		ns_per_byte;
    954  1.1  itojun 	u_int		maxidle;
    955  1.1  itojun 	int		minidle;
    956  1.1  itojun 	u_int		offtime;
    957  1.1  itojun 	int		flags;
    958  1.1  itojun };
    959  1.1  itojun 
    960  1.1  itojun struct priq_opts {
    961  1.1  itojun 	int		flags;
    962  1.1  itojun };
    963  1.1  itojun 
    964  1.1  itojun struct hfsc_opts {
    965  1.1  itojun 	/* real-time service curve */
    966  1.1  itojun 	u_int		rtsc_m1;	/* slope of the 1st segment in bps */
    967  1.1  itojun 	u_int		rtsc_d;		/* the x-projection of m1 in msec */
    968  1.1  itojun 	u_int		rtsc_m2;	/* slope of the 2nd segment in bps */
    969  1.1  itojun 	/* link-sharing service curve */
    970  1.1  itojun 	u_int		lssc_m1;
    971  1.1  itojun 	u_int		lssc_d;
    972  1.1  itojun 	u_int		lssc_m2;
    973  1.1  itojun 	/* upper-limit service curve */
    974  1.1  itojun 	u_int		ulsc_m1;
    975  1.1  itojun 	u_int		ulsc_d;
    976  1.1  itojun 	u_int		ulsc_m2;
    977  1.1  itojun 	int		flags;
    978  1.1  itojun };
    979  1.1  itojun 
    980  1.1  itojun struct pf_altq {
    981  1.1  itojun 	char			 ifname[IFNAMSIZ];
    982  1.1  itojun 
    983  1.1  itojun 	void			*altq_disc;	/* discipline-specific state */
    984  1.1  itojun 	TAILQ_ENTRY(pf_altq)	 entries;
    985  1.1  itojun 
    986  1.1  itojun 	/* scheduler spec */
    987  1.1  itojun 	u_int8_t		 scheduler;	/* scheduler type */
    988  1.1  itojun 	u_int16_t		 tbrsize;	/* tokenbucket regulator size */
    989  1.1  itojun 	u_int32_t		 ifbandwidth;	/* interface bandwidth */
    990  1.1  itojun 
    991  1.1  itojun 	/* queue spec */
    992  1.1  itojun 	char			 qname[PF_QNAME_SIZE];	/* queue name */
    993  1.1  itojun 	char			 parent[PF_QNAME_SIZE];	/* parent name */
    994  1.1  itojun 	u_int32_t		 parent_qid;	/* parent queue id */
    995  1.1  itojun 	u_int32_t		 bandwidth;	/* queue bandwidth */
    996  1.1  itojun 	u_int8_t		 priority;	/* priority */
    997  1.1  itojun 	u_int16_t		 qlimit;	/* queue size limit */
    998  1.1  itojun 	u_int16_t		 flags;		/* misc flags */
    999  1.1  itojun 	union {
   1000  1.1  itojun 		struct cbq_opts		 cbq_opts;
   1001  1.1  itojun 		struct priq_opts	 priq_opts;
   1002  1.1  itojun 		struct hfsc_opts	 hfsc_opts;
   1003  1.1  itojun 	} pq_u;
   1004  1.1  itojun 
   1005  1.1  itojun 	u_int32_t		 qid;		/* return value */
   1006  1.1  itojun };
   1007  1.1  itojun 
   1008  1.1  itojun struct pf_tag {
   1009  1.1  itojun 	u_int16_t	tag;		/* tag id */
   1010  1.1  itojun };
   1011  1.1  itojun 
   1012  1.1  itojun struct pf_tagname {
   1013  1.1  itojun 	TAILQ_ENTRY(pf_tagname)	entries;
   1014  1.1  itojun 	char			name[PF_TAG_NAME_SIZE];
   1015  1.1  itojun 	u_int16_t		tag;
   1016  1.1  itojun 	int			ref;
   1017  1.1  itojun };
   1018  1.1  itojun 
   1019  1.1  itojun #define PFFRAG_FRENT_HIWAT	5000	/* Number of fragment entries */
   1020  1.1  itojun #define PFFRAG_FRAG_HIWAT	1000	/* Number of fragmented packets */
   1021  1.1  itojun #define PFFRAG_FRCENT_HIWAT	50000	/* Number of fragment cache entries */
   1022  1.1  itojun #define PFFRAG_FRCACHE_HIWAT	10000	/* Number of fragment descriptors */
   1023  1.1  itojun 
   1024  1.1  itojun /*
   1025  1.1  itojun  * ioctl parameter structures
   1026  1.1  itojun  */
   1027  1.1  itojun 
   1028  1.1  itojun struct pfioc_pooladdr {
   1029  1.1  itojun 	u_int32_t		 action;
   1030  1.1  itojun 	u_int32_t		 ticket;
   1031  1.1  itojun 	u_int32_t		 nr;
   1032  1.1  itojun 	u_int32_t		 r_num;
   1033  1.1  itojun 	u_int8_t		 r_action;
   1034  1.1  itojun 	u_int8_t		 r_last;
   1035  1.1  itojun 	u_int8_t		 af;
   1036  1.1  itojun 	char			 anchor[PF_ANCHOR_NAME_SIZE];
   1037  1.1  itojun 	char			 ruleset[PF_RULESET_NAME_SIZE];
   1038  1.1  itojun 	struct pf_pooladdr	 addr;
   1039  1.1  itojun };
   1040  1.1  itojun 
   1041  1.1  itojun struct pfioc_rule {
   1042  1.1  itojun 	u_int32_t	 action;
   1043  1.1  itojun 	u_int32_t	 ticket;
   1044  1.1  itojun 	u_int32_t	 pool_ticket;
   1045  1.1  itojun 	u_int32_t	 nr;
   1046  1.1  itojun 	char		 anchor[PF_ANCHOR_NAME_SIZE];
   1047  1.1  itojun 	char		 ruleset[PF_RULESET_NAME_SIZE];
   1048  1.1  itojun 	struct pf_rule	 rule;
   1049  1.1  itojun };
   1050  1.1  itojun 
   1051  1.1  itojun struct pfioc_natlook {
   1052  1.1  itojun 	struct pf_addr	 saddr;
   1053  1.1  itojun 	struct pf_addr	 daddr;
   1054  1.1  itojun 	struct pf_addr	 rsaddr;
   1055  1.1  itojun 	struct pf_addr	 rdaddr;
   1056  1.1  itojun 	u_int16_t	 sport;
   1057  1.1  itojun 	u_int16_t	 dport;
   1058  1.1  itojun 	u_int16_t	 rsport;
   1059  1.1  itojun 	u_int16_t	 rdport;
   1060  1.1  itojun 	sa_family_t	 af;
   1061  1.1  itojun 	u_int8_t	 proto;
   1062  1.1  itojun 	u_int8_t	 direction;
   1063  1.1  itojun };
   1064  1.1  itojun 
   1065  1.1  itojun struct pfioc_state {
   1066  1.1  itojun 	u_int32_t	 nr;
   1067  1.1  itojun 	struct pf_state	 state;
   1068  1.1  itojun };
   1069  1.1  itojun 
   1070  1.1  itojun struct pfioc_state_kill {
   1071  1.1  itojun 	/* XXX returns the number of states killed in psk_af */
   1072  1.1  itojun 	sa_family_t		psk_af;
   1073  1.1  itojun 	int			psk_proto;
   1074  1.1  itojun 	struct pf_rule_addr	psk_src;
   1075  1.1  itojun 	struct pf_rule_addr	psk_dst;
   1076  1.1  itojun 	char			psk_ifname[IFNAMSIZ];
   1077  1.1  itojun };
   1078  1.1  itojun 
   1079  1.1  itojun struct pfioc_states {
   1080  1.1  itojun 	int	ps_len;
   1081  1.1  itojun 	union {
   1082  1.1  itojun 		caddr_t		 psu_buf;
   1083  1.1  itojun 		struct pf_state	*psu_states;
   1084  1.1  itojun 	} ps_u;
   1085  1.1  itojun #define ps_buf		ps_u.psu_buf
   1086  1.1  itojun #define ps_states	ps_u.psu_states
   1087  1.1  itojun };
   1088  1.1  itojun 
   1089  1.1  itojun struct pfioc_src_nodes {
   1090  1.1  itojun 	int	psn_len;
   1091  1.1  itojun 	union {
   1092  1.1  itojun 		caddr_t		 psu_buf;
   1093  1.1  itojun 		struct pf_src_node	*psu_src_nodes;
   1094  1.1  itojun 	} psn_u;
   1095  1.1  itojun #define psn_buf		psn_u.psu_buf
   1096  1.1  itojun #define psn_src_nodes	psn_u.psu_src_nodes
   1097  1.1  itojun };
   1098  1.1  itojun 
   1099  1.1  itojun struct pfioc_if {
   1100  1.1  itojun 	char		 ifname[IFNAMSIZ];
   1101  1.1  itojun };
   1102  1.1  itojun 
   1103  1.1  itojun struct pfioc_tm {
   1104  1.1  itojun 	int		 timeout;
   1105  1.1  itojun 	int		 seconds;
   1106  1.1  itojun };
   1107  1.1  itojun 
   1108  1.1  itojun struct pfioc_limit {
   1109  1.1  itojun 	int		 index;
   1110  1.1  itojun 	unsigned	 limit;
   1111  1.1  itojun };
   1112  1.1  itojun 
   1113  1.1  itojun struct pfioc_altq {
   1114  1.1  itojun 	u_int32_t	 action;
   1115  1.1  itojun 	u_int32_t	 ticket;
   1116  1.1  itojun 	u_int32_t	 nr;
   1117  1.1  itojun 	struct pf_altq	 altq;
   1118  1.1  itojun };
   1119  1.1  itojun 
   1120  1.1  itojun struct pfioc_qstats {
   1121  1.1  itojun 	u_int32_t	 ticket;
   1122  1.1  itojun 	u_int32_t	 nr;
   1123  1.1  itojun 	void		*buf;
   1124  1.1  itojun 	int		 nbytes;
   1125  1.1  itojun 	u_int8_t	 scheduler;
   1126  1.1  itojun };
   1127  1.1  itojun 
   1128  1.1  itojun struct pfioc_anchor {
   1129  1.1  itojun 	u_int32_t	 nr;
   1130  1.1  itojun 	char		 name[PF_ANCHOR_NAME_SIZE];
   1131  1.1  itojun };
   1132  1.1  itojun 
   1133  1.1  itojun struct pfioc_ruleset {
   1134  1.1  itojun 	u_int32_t	 nr;
   1135  1.1  itojun 	char		 anchor[PF_ANCHOR_NAME_SIZE];
   1136  1.1  itojun 	char		 name[PF_RULESET_NAME_SIZE];
   1137  1.1  itojun };
   1138  1.1  itojun 
   1139  1.1  itojun #define PF_RULESET_ALTQ		(PF_RULESET_MAX)
   1140  1.1  itojun #define PF_RULESET_TABLE	(PF_RULESET_MAX+1)
   1141  1.1  itojun struct pfioc_trans {
   1142  1.1  itojun 	int		 size;	/* number of elements */
   1143  1.1  itojun 	int		 esize; /* size of each element in bytes */
   1144  1.1  itojun 	struct pfioc_trans_e {
   1145  1.1  itojun 		int		rs_num;
   1146  1.1  itojun 		char		anchor[PF_ANCHOR_NAME_SIZE];
   1147  1.1  itojun 		char		ruleset[PF_RULESET_NAME_SIZE];
   1148  1.1  itojun 		u_int32_t	ticket;
   1149  1.1  itojun 	}		*array;
   1150  1.1  itojun };
   1151  1.1  itojun 
   1152  1.1  itojun #define PFR_FLAG_ATOMIC		0x00000001
   1153  1.1  itojun #define PFR_FLAG_DUMMY		0x00000002
   1154  1.1  itojun #define PFR_FLAG_FEEDBACK	0x00000004
   1155  1.1  itojun #define PFR_FLAG_CLSTATS	0x00000008
   1156  1.1  itojun #define PFR_FLAG_ADDRSTOO	0x00000010
   1157  1.1  itojun #define PFR_FLAG_REPLACE	0x00000020
   1158  1.1  itojun #define PFR_FLAG_ALLRSETS	0x00000040
   1159  1.1  itojun #define PFR_FLAG_ALLMASK	0x0000007F
   1160  1.1  itojun #ifdef _KERNEL
   1161  1.1  itojun #define PFR_FLAG_USERIOCTL	0x10000000
   1162  1.1  itojun #endif
   1163  1.1  itojun 
   1164  1.1  itojun struct pfioc_table {
   1165  1.1  itojun 	struct pfr_table	 pfrio_table;
   1166  1.1  itojun 	void			*pfrio_buffer;
   1167  1.1  itojun 	int			 pfrio_esize;
   1168  1.1  itojun 	int			 pfrio_size;
   1169  1.1  itojun 	int			 pfrio_size2;
   1170  1.1  itojun 	int			 pfrio_nadd;
   1171  1.1  itojun 	int			 pfrio_ndel;
   1172  1.1  itojun 	int			 pfrio_nchange;
   1173  1.1  itojun 	int			 pfrio_flags;
   1174  1.1  itojun 	u_int32_t		 pfrio_ticket;
   1175  1.1  itojun };
   1176  1.1  itojun #define	pfrio_exists	pfrio_nadd
   1177  1.1  itojun #define	pfrio_nzero	pfrio_nadd
   1178  1.1  itojun #define	pfrio_nmatch	pfrio_nadd
   1179  1.1  itojun #define pfrio_naddr	pfrio_size2
   1180  1.1  itojun #define pfrio_setflag	pfrio_size2
   1181  1.1  itojun #define pfrio_clrflag	pfrio_nadd
   1182  1.1  itojun 
   1183  1.1  itojun 
   1184  1.1  itojun #define PFI_FLAG_GROUP		0x0001	/* gets groups of interfaces */
   1185  1.1  itojun #define PFI_FLAG_INSTANCE	0x0002	/* gets single interfaces */
   1186  1.1  itojun #define PFI_FLAG_ALLMASK	0x0003
   1187  1.1  itojun 
   1188  1.1  itojun struct pfioc_iface {
   1189  1.1  itojun 	char	 pfiio_name[IFNAMSIZ];
   1190  1.1  itojun 	void	*pfiio_buffer;
   1191  1.1  itojun 	int	 pfiio_esize;
   1192  1.1  itojun 	int	 pfiio_size;
   1193  1.1  itojun 	int	 pfiio_nzero;
   1194  1.1  itojun 	int	 pfiio_flags;
   1195  1.1  itojun };
   1196  1.1  itojun 
   1197  1.1  itojun 
   1198  1.1  itojun /*
   1199  1.1  itojun  * ioctl operations
   1200  1.1  itojun  */
   1201  1.1  itojun 
   1202  1.1  itojun #define DIOCSTART	_IO  ('D',  1)
   1203  1.1  itojun #define DIOCSTOP	_IO  ('D',  2)
   1204  1.1  itojun #define DIOCBEGINRULES	_IOWR('D',  3, struct pfioc_rule)
   1205  1.1  itojun #define DIOCADDRULE	_IOWR('D',  4, struct pfioc_rule)
   1206  1.1  itojun #define DIOCCOMMITRULES	_IOWR('D',  5, struct pfioc_rule)
   1207  1.1  itojun #define DIOCGETRULES	_IOWR('D',  6, struct pfioc_rule)
   1208  1.1  itojun #define DIOCGETRULE	_IOWR('D',  7, struct pfioc_rule)
   1209  1.1  itojun /* XXX cut 8 - 17 */
   1210  1.1  itojun #define DIOCCLRSTATES	_IOWR('D', 18, struct pfioc_state_kill)
   1211  1.1  itojun #define DIOCGETSTATE	_IOWR('D', 19, struct pfioc_state)
   1212  1.1  itojun #define DIOCSETSTATUSIF _IOWR('D', 20, struct pfioc_if)
   1213  1.1  itojun #define DIOCGETSTATUS	_IOWR('D', 21, struct pf_status)
   1214  1.1  itojun #define DIOCCLRSTATUS	_IO  ('D', 22)
   1215  1.1  itojun #define DIOCNATLOOK	_IOWR('D', 23, struct pfioc_natlook)
   1216  1.1  itojun #define DIOCSETDEBUG	_IOWR('D', 24, u_int32_t)
   1217  1.1  itojun #define DIOCGETSTATES	_IOWR('D', 25, struct pfioc_states)
   1218  1.1  itojun #define DIOCCHANGERULE	_IOWR('D', 26, struct pfioc_rule)
   1219  1.1  itojun /* XXX cut 26 - 28 */
   1220  1.1  itojun #define DIOCSETTIMEOUT	_IOWR('D', 29, struct pfioc_tm)
   1221  1.1  itojun #define DIOCGETTIMEOUT	_IOWR('D', 30, struct pfioc_tm)
   1222  1.1  itojun #define DIOCADDSTATE	_IOWR('D', 37, struct pfioc_state)
   1223  1.1  itojun #define DIOCCLRRULECTRS	_IO  ('D', 38)
   1224  1.1  itojun #define DIOCGETLIMIT	_IOWR('D', 39, struct pfioc_limit)
   1225  1.1  itojun #define DIOCSETLIMIT	_IOWR('D', 40, struct pfioc_limit)
   1226  1.1  itojun #define DIOCKILLSTATES	_IOWR('D', 41, struct pfioc_state_kill)
   1227  1.1  itojun #define DIOCSTARTALTQ	_IO  ('D', 42)
   1228  1.1  itojun #define DIOCSTOPALTQ	_IO  ('D', 43)
   1229  1.1  itojun #define DIOCBEGINALTQS	_IOWR('D', 44, u_int32_t)
   1230  1.1  itojun #define DIOCADDALTQ	_IOWR('D', 45, struct pfioc_altq)
   1231  1.1  itojun #define DIOCCOMMITALTQS	_IOWR('D', 46, u_int32_t)
   1232  1.1  itojun #define DIOCGETALTQS	_IOWR('D', 47, struct pfioc_altq)
   1233  1.1  itojun #define DIOCGETALTQ	_IOWR('D', 48, struct pfioc_altq)
   1234  1.1  itojun #define DIOCCHANGEALTQ	_IOWR('D', 49, struct pfioc_altq)
   1235  1.1  itojun #define DIOCGETQSTATS	_IOWR('D', 50, struct pfioc_qstats)
   1236  1.1  itojun #define DIOCBEGINADDRS	_IOWR('D', 51, struct pfioc_pooladdr)
   1237  1.1  itojun #define DIOCADDADDR	_IOWR('D', 52, struct pfioc_pooladdr)
   1238  1.1  itojun #define DIOCGETADDRS	_IOWR('D', 53, struct pfioc_pooladdr)
   1239  1.1  itojun #define DIOCGETADDR	_IOWR('D', 54, struct pfioc_pooladdr)
   1240  1.1  itojun #define DIOCCHANGEADDR	_IOWR('D', 55, struct pfioc_pooladdr)
   1241  1.1  itojun #define	DIOCGETANCHORS	_IOWR('D', 56, struct pfioc_anchor)
   1242  1.1  itojun #define	DIOCGETANCHOR	_IOWR('D', 57, struct pfioc_anchor)
   1243  1.1  itojun #define	DIOCGETRULESETS	_IOWR('D', 58, struct pfioc_ruleset)
   1244  1.1  itojun #define	DIOCGETRULESET	_IOWR('D', 59, struct pfioc_ruleset)
   1245  1.1  itojun #define	DIOCRCLRTABLES	_IOWR('D', 60, struct pfioc_table)
   1246  1.1  itojun #define	DIOCRADDTABLES	_IOWR('D', 61, struct pfioc_table)
   1247  1.1  itojun #define	DIOCRDELTABLES	_IOWR('D', 62, struct pfioc_table)
   1248  1.1  itojun #define	DIOCRGETTABLES	_IOWR('D', 63, struct pfioc_table)
   1249  1.1  itojun #define	DIOCRGETTSTATS	_IOWR('D', 64, struct pfioc_table)
   1250  1.1  itojun #define DIOCRCLRTSTATS  _IOWR('D', 65, struct pfioc_table)
   1251  1.1  itojun #define	DIOCRCLRADDRS	_IOWR('D', 66, struct pfioc_table)
   1252  1.1  itojun #define	DIOCRADDADDRS	_IOWR('D', 67, struct pfioc_table)
   1253  1.1  itojun #define	DIOCRDELADDRS	_IOWR('D', 68, struct pfioc_table)
   1254  1.1  itojun #define	DIOCRSETADDRS	_IOWR('D', 69, struct pfioc_table)
   1255  1.1  itojun #define	DIOCRGETADDRS	_IOWR('D', 70, struct pfioc_table)
   1256  1.1  itojun #define	DIOCRGETASTATS	_IOWR('D', 71, struct pfioc_table)
   1257  1.1  itojun #define DIOCRCLRASTATS  _IOWR('D', 72, struct pfioc_table)
   1258  1.1  itojun #define	DIOCRTSTADDRS	_IOWR('D', 73, struct pfioc_table)
   1259  1.1  itojun #define	DIOCRSETTFLAGS	_IOWR('D', 74, struct pfioc_table)
   1260  1.1  itojun #define DIOCRINABEGIN	_IOWR('D', 75, struct pfioc_table)
   1261  1.1  itojun #define DIOCRINACOMMIT	_IOWR('D', 76, struct pfioc_table)
   1262  1.1  itojun #define DIOCRINADEFINE	_IOWR('D', 77, struct pfioc_table)
   1263  1.1  itojun #define DIOCOSFPFLUSH	_IO('D', 78)
   1264  1.1  itojun #define DIOCOSFPADD	_IOWR('D', 79, struct pf_osfp_ioctl)
   1265  1.1  itojun #define DIOCOSFPGET	_IOWR('D', 80, struct pf_osfp_ioctl)
   1266  1.1  itojun #define DIOCXBEGIN      _IOWR('D', 81, struct pfioc_trans)
   1267  1.1  itojun #define DIOCXCOMMIT     _IOWR('D', 82, struct pfioc_trans)
   1268  1.1  itojun #define DIOCXROLLBACK   _IOWR('D', 83, struct pfioc_trans)
   1269  1.1  itojun #define DIOCGETSRCNODES	_IOWR('D', 84, struct pfioc_src_nodes)
   1270  1.1  itojun #define DIOCCLRSRCNODES	_IO('D', 85)
   1271  1.1  itojun #define DIOCSETHOSTID	_IOWR('D', 86, u_int32_t)
   1272  1.1  itojun #define DIOCIGETIFACES	_IOWR('D', 87, struct pfioc_iface)
   1273  1.1  itojun #define DIOCICLRISTATS  _IOWR('D', 88, struct pfioc_iface)
   1274  1.1  itojun 
   1275  1.1  itojun #ifdef _KERNEL
   1276  1.1  itojun RB_HEAD(pf_src_tree, pf_src_node);
   1277  1.1  itojun RB_PROTOTYPE(pf_src_tree, pf_src_node, entry, pf_src_compare);
   1278  1.1  itojun extern struct pf_src_tree tree_src_tracking;
   1279  1.1  itojun 
   1280  1.1  itojun RB_HEAD(pf_state_tree_id, pf_state);
   1281  1.1  itojun RB_PROTOTYPE(pf_state_tree_id, pf_state,
   1282  1.1  itojun     entry_id, pf_state_compare_id);
   1283  1.1  itojun extern struct pf_state_tree_id tree_id;
   1284  1.1  itojun extern struct pf_state_queue state_updates;
   1285  1.1  itojun 
   1286  1.1  itojun extern struct pf_anchorqueue		  pf_anchors;
   1287  1.1  itojun extern struct pf_ruleset		  pf_main_ruleset;
   1288  1.1  itojun TAILQ_HEAD(pf_poolqueue, pf_pool);
   1289  1.1  itojun extern struct pf_poolqueue		  pf_pools[2];
   1290  1.1  itojun TAILQ_HEAD(pf_altqqueue, pf_altq);
   1291  1.1  itojun extern struct pf_altqqueue		  pf_altqs[2];
   1292  1.1  itojun extern struct pf_palist			  pf_pabuf;
   1293  1.1  itojun extern struct pfi_kif			**pfi_index2kif;
   1294  1.1  itojun 
   1295  1.1  itojun extern u_int32_t		 ticket_altqs_active;
   1296  1.1  itojun extern u_int32_t		 ticket_altqs_inactive;
   1297  1.1  itojun extern int			 altqs_inactive_open;
   1298  1.1  itojun extern u_int32_t		 ticket_pabuf;
   1299  1.1  itojun extern struct pf_altqqueue	*pf_altqs_active;
   1300  1.1  itojun extern struct pf_altqqueue	*pf_altqs_inactive;
   1301  1.1  itojun extern struct pf_poolqueue	*pf_pools_active;
   1302  1.1  itojun extern struct pf_poolqueue	*pf_pools_inactive;
   1303  1.1  itojun extern int			 pf_tbladdr_setup(struct pf_ruleset *,
   1304  1.1  itojun 				    struct pf_addr_wrap *);
   1305  1.1  itojun extern void			 pf_tbladdr_remove(struct pf_addr_wrap *);
   1306  1.1  itojun extern void			 pf_tbladdr_copyout(struct pf_addr_wrap *);
   1307  1.1  itojun extern void			 pf_calc_skip_steps(struct pf_rulequeue *);
   1308  1.1  itojun extern void			 pf_update_anchor_rules(void);
   1309  1.1  itojun extern struct pool		 pf_src_tree_pl, pf_rule_pl;
   1310  1.1  itojun extern struct pool		 pf_state_pl, pf_altq_pl, pf_pooladdr_pl;
   1311  1.1  itojun extern struct pool		 pf_state_scrub_pl;
   1312  1.1  itojun extern void			 pf_purge_timeout(void *);
   1313  1.1  itojun extern void			 pf_purge_expired_src_nodes(void);
   1314  1.1  itojun extern void			 pf_purge_expired_states(void);
   1315  1.1  itojun extern int			 pf_insert_state(struct pfi_kif *,
   1316  1.1  itojun 				    struct pf_state *);
   1317  1.1  itojun extern int			 pf_insert_src_node(struct pf_src_node **,
   1318  1.1  itojun 				    struct pf_rule *, struct pf_addr *,
   1319  1.1  itojun 				    sa_family_t);
   1320  1.1  itojun void				 pf_src_tree_remove_state(struct pf_state *);
   1321  1.1  itojun extern struct pf_state		*pf_find_state_byid(struct pf_state *);
   1322  1.1  itojun extern struct pf_state		*pf_find_state_all(struct pf_state *key,
   1323  1.1  itojun 				    u_int8_t tree, int *more);
   1324  1.1  itojun extern struct pf_anchor		*pf_find_anchor(const char *);
   1325  1.1  itojun extern struct pf_ruleset	*pf_find_ruleset(char *, char *);
   1326  1.1  itojun extern struct pf_ruleset	*pf_find_or_create_ruleset(
   1327  1.1  itojun 				    char[PF_ANCHOR_NAME_SIZE],
   1328  1.1  itojun 				    char[PF_RULESET_NAME_SIZE]);
   1329  1.1  itojun extern void			 pf_remove_if_empty_ruleset(
   1330  1.1  itojun 				    struct pf_ruleset *);
   1331  1.1  itojun 
   1332  1.1  itojun extern struct ifnet		*sync_ifp;
   1333  1.1  itojun extern struct pf_rule		 pf_default_rule;
   1334  1.1  itojun extern void			 pf_addrcpy(struct pf_addr *, struct pf_addr *,
   1335  1.1  itojun 				    u_int8_t);
   1336  1.1  itojun void				 pf_rm_rule(struct pf_rulequeue *,
   1337  1.1  itojun 				    struct pf_rule *);
   1338  1.1  itojun 
   1339  1.1  itojun #ifdef INET
   1340  1.1  itojun int	pf_test(int, struct ifnet *, struct mbuf **);
   1341  1.1  itojun #endif /* INET */
   1342  1.1  itojun 
   1343  1.1  itojun #ifdef INET6
   1344  1.1  itojun int	pf_test6(int, struct ifnet *, struct mbuf **);
   1345  1.1  itojun void	pf_poolmask(struct pf_addr *, struct pf_addr*,
   1346  1.1  itojun 	    struct pf_addr *, struct pf_addr *, u_int8_t);
   1347  1.1  itojun void	pf_addr_inc(struct pf_addr *, sa_family_t);
   1348  1.1  itojun #endif /* INET6 */
   1349  1.1  itojun 
   1350  1.1  itojun void   *pf_pull_hdr(struct mbuf *, int, void *, int, u_short *, u_short *,
   1351  1.1  itojun 	    sa_family_t);
   1352  1.1  itojun void	pf_change_a(void *, u_int16_t *, u_int32_t, u_int8_t);
   1353  1.1  itojun int	pflog_packet(struct pfi_kif *, struct mbuf *, sa_family_t, u_int8_t,
   1354  1.1  itojun 	    u_int8_t, struct pf_rule *, struct pf_rule *, struct pf_ruleset *);
   1355  1.1  itojun int	pf_match_addr(u_int8_t, struct pf_addr *, struct pf_addr *,
   1356  1.1  itojun 	    struct pf_addr *, sa_family_t);
   1357  1.1  itojun int	pf_match(u_int8_t, u_int32_t, u_int32_t, u_int32_t);
   1358  1.1  itojun int	pf_match_port(u_int8_t, u_int16_t, u_int16_t, u_int16_t);
   1359  1.1  itojun int	pf_match_uid(u_int8_t, uid_t, uid_t, uid_t);
   1360  1.1  itojun int	pf_match_gid(u_int8_t, gid_t, gid_t, gid_t);
   1361  1.1  itojun 
   1362  1.1  itojun void	pf_normalize_init(void);
   1363  1.1  itojun int	pf_normalize_ip(struct mbuf **, int, struct pfi_kif *, u_short *);
   1364  1.1  itojun int	pf_normalize_ip6(struct mbuf **, int, struct pfi_kif *, u_short *);
   1365  1.1  itojun int	pf_normalize_tcp(int, struct pfi_kif *, struct mbuf *, int, int, void *,
   1366  1.1  itojun 	    struct pf_pdesc *);
   1367  1.1  itojun void	pf_normalize_tcp_cleanup(struct pf_state *);
   1368  1.1  itojun int	pf_normalize_tcp_init(struct mbuf *, int, struct pf_pdesc *,
   1369  1.1  itojun 	    struct tcphdr *, struct pf_state_peer *, struct pf_state_peer *);
   1370  1.1  itojun int	pf_normalize_tcp_stateful(struct mbuf *, int, struct pf_pdesc *,
   1371  1.1  itojun 	    u_short *, struct tcphdr *, struct pf_state_peer *,
   1372  1.1  itojun 	    struct pf_state_peer *, int *);
   1373  1.1  itojun u_int32_t
   1374  1.1  itojun 	pf_state_expires(const struct pf_state *);
   1375  1.1  itojun void	pf_purge_expired_fragments(void);
   1376  1.1  itojun int	pf_routable(struct pf_addr *addr, sa_family_t af);
   1377  1.1  itojun void	pfr_initialize(void);
   1378  1.1  itojun int	pfr_match_addr(struct pfr_ktable *, struct pf_addr *, sa_family_t);
   1379  1.1  itojun void	pfr_update_stats(struct pfr_ktable *, struct pf_addr *, sa_family_t,
   1380  1.1  itojun 	    u_int64_t, int, int, int);
   1381  1.1  itojun int	pfr_pool_get(struct pfr_ktable *, int *, struct pf_addr *,
   1382  1.1  itojun 	    struct pf_addr **, struct pf_addr **, sa_family_t);
   1383  1.1  itojun void	pfr_dynaddr_update(struct pfr_ktable *, struct pfi_dynaddr *);
   1384  1.1  itojun struct pfr_ktable *
   1385  1.1  itojun 	pfr_attach_table(struct pf_ruleset *, char *);
   1386  1.1  itojun void	pfr_detach_table(struct pfr_ktable *);
   1387  1.1  itojun int	pfr_clr_tables(struct pfr_table *, int *, int);
   1388  1.1  itojun int	pfr_add_tables(struct pfr_table *, int, int *, int);
   1389  1.1  itojun int	pfr_del_tables(struct pfr_table *, int, int *, int);
   1390  1.1  itojun int	pfr_get_tables(struct pfr_table *, struct pfr_table *, int *, int);
   1391  1.1  itojun int	pfr_get_tstats(struct pfr_table *, struct pfr_tstats *, int *, int);
   1392  1.1  itojun int	pfr_clr_tstats(struct pfr_table *, int, int *, int);
   1393  1.1  itojun int	pfr_set_tflags(struct pfr_table *, int, int, int, int *, int *, int);
   1394  1.1  itojun int	pfr_clr_addrs(struct pfr_table *, int *, int);
   1395  1.1  itojun int	pfr_add_addrs(struct pfr_table *, struct pfr_addr *, int, int *,
   1396  1.1  itojun 	    int);
   1397  1.1  itojun int	pfr_del_addrs(struct pfr_table *, struct pfr_addr *, int, int *,
   1398  1.1  itojun 	    int);
   1399  1.1  itojun int	pfr_set_addrs(struct pfr_table *, struct pfr_addr *, int, int *,
   1400  1.1  itojun 	    int *, int *, int *, int);
   1401  1.1  itojun int	pfr_get_addrs(struct pfr_table *, struct pfr_addr *, int *, int);
   1402  1.1  itojun int	pfr_get_astats(struct pfr_table *, struct pfr_astats *, int *, int);
   1403  1.1  itojun int	pfr_clr_astats(struct pfr_table *, struct pfr_addr *, int, int *,
   1404  1.1  itojun 	    int);
   1405  1.1  itojun int	pfr_tst_addrs(struct pfr_table *, struct pfr_addr *, int, int *,
   1406  1.1  itojun 	    int);
   1407  1.1  itojun int	pfr_ina_begin(struct pfr_table *, u_int32_t *, int *, int);
   1408  1.1  itojun int	pfr_ina_rollback(struct pfr_table *, u_int32_t, int *, int);
   1409  1.1  itojun int	pfr_ina_commit(struct pfr_table *, u_int32_t, int *, int *, int);
   1410  1.1  itojun int	pfr_ina_define(struct pfr_table *, struct pfr_addr *, int, int *,
   1411  1.1  itojun 	    int *, u_int32_t, int);
   1412  1.1  itojun 
   1413  1.1  itojun void		 pfi_initialize(void);
   1414  1.1  itojun void		 pfi_attach_clone(struct if_clone *);
   1415  1.1  itojun void		 pfi_attach_ifnet(struct ifnet *);
   1416  1.1  itojun void		 pfi_detach_ifnet(struct ifnet *);
   1417  1.1  itojun struct pfi_kif	*pfi_lookup_create(const char *);
   1418  1.1  itojun struct pfi_kif	*pfi_lookup_if(const char *);
   1419  1.1  itojun int		 pfi_maybe_destroy(struct pfi_kif *);
   1420  1.1  itojun struct pfi_kif	*pfi_attach_rule(const char *);
   1421  1.1  itojun void		 pfi_detach_rule(struct pfi_kif *);
   1422  1.1  itojun void		 pfi_attach_state(struct pfi_kif *);
   1423  1.1  itojun void		 pfi_detach_state(struct pfi_kif *);
   1424  1.1  itojun int		 pfi_dynaddr_setup(struct pf_addr_wrap *, sa_family_t);
   1425  1.1  itojun void		 pfi_dynaddr_copyout(struct pf_addr_wrap *);
   1426  1.1  itojun void		 pfi_dynaddr_remove(struct pf_addr_wrap *);
   1427  1.1  itojun void		 pfi_fill_oldstatus(struct pf_status *);
   1428  1.1  itojun int		 pfi_clr_istats(const char *, int *, int);
   1429  1.1  itojun int		 pfi_get_ifaces(const char *, struct pfi_if *, int *, int);
   1430  1.1  itojun int		 pfi_match_addr(struct pfi_dynaddr *, struct pf_addr *,
   1431  1.1  itojun 		    sa_family_t);
   1432  1.1  itojun 
   1433  1.1  itojun extern struct pfi_statehead	pfi_statehead;
   1434  1.1  itojun 
   1435  1.1  itojun u_int16_t	pf_tagname2tag(char *);
   1436  1.1  itojun void		pf_tag2tagname(u_int16_t, char *);
   1437  1.1  itojun void		pf_tag_unref(u_int16_t);
   1438  1.1  itojun int		pf_tag_packet(struct mbuf *, struct pf_tag *, int);
   1439  1.1  itojun u_int32_t	pf_qname2qid(char *);
   1440  1.1  itojun void		pf_qid2qname(u_int32_t, char *);
   1441  1.1  itojun void		pf_qid_unref(u_int32_t);
   1442  1.1  itojun 
   1443  1.1  itojun extern struct pf_status	pf_status;
   1444  1.1  itojun extern struct pool	pf_frent_pl, pf_frag_pl;
   1445  1.1  itojun 
   1446  1.1  itojun struct pf_pool_limit {
   1447  1.1  itojun 	void		*pp;
   1448  1.1  itojun 	unsigned	 limit;
   1449  1.1  itojun };
   1450  1.1  itojun extern struct pf_pool_limit	pf_pool_limits[PF_LIMIT_MAX];
   1451  1.1  itojun 
   1452  1.1  itojun #endif /* _KERNEL */
   1453  1.1  itojun 
   1454  1.1  itojun /* The fingerprint functions can be linked into userland programs (tcpdump) */
   1455  1.1  itojun int	pf_osfp_add(struct pf_osfp_ioctl *);
   1456  1.1  itojun #ifdef _KERNEL
   1457  1.1  itojun struct pf_osfp_enlist *
   1458  1.1  itojun 	pf_osfp_fingerprint(struct pf_pdesc *, struct mbuf *, int,
   1459  1.1  itojun 	    const struct tcphdr *);
   1460  1.1  itojun #endif /* _KERNEL */
   1461  1.1  itojun struct pf_osfp_enlist *
   1462  1.1  itojun 	pf_osfp_fingerprint_hdr(const struct ip *, const struct tcphdr *);
   1463  1.1  itojun void	pf_osfp_flush(void);
   1464  1.1  itojun int	pf_osfp_get(struct pf_osfp_ioctl *);
   1465  1.1  itojun void	pf_osfp_initialize(void);
   1466  1.1  itojun int	pf_osfp_match(struct pf_osfp_enlist *, pf_osfp_t);
   1467  1.1  itojun struct pf_os_fingerprint *
   1468  1.1  itojun 	pf_osfp_validate(void);
   1469  1.1  itojun 
   1470  1.1  itojun 
   1471  1.1  itojun #endif /* _NET_PFVAR_H_ */
   1472