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