2 * Copyright (c) 2008 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 /* $apfw: pfvar.h,v 1.12 2008/08/27 00:01:32 jhw Exp $ */
30 /* $OpenBSD: pfvar.h,v 1.259 2007/12/02 12:08:04 pascoe Exp $ */
33 * Copyright (c) 2001 Daniel Hartmeier
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
40 * - Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * - Redistributions in binary form must reproduce the above
43 * copyright notice, this list of conditions and the following
44 * disclaimer in the documentation and/or other materials provided
45 * with the distribution.
47 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
48 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
49 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
50 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
51 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
52 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
53 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
54 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
55 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
57 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
58 * POSSIBILITY OF SUCH DAMAGE.
66 #if PF || !defined(KERNEL)
72 #include <sys/param.h>
73 #include <sys/types.h>
74 #include <sys/queue.h>
77 #include <net/radix.h>
78 #include <netinet/in.h>
81 #include <kern/kern_types.h>
82 #include <kern/zalloc.h>
83 #include <kern/lock.h>
85 #include <machine/endian.h>
86 #include <sys/systm.h>
87 #include <net/pf_mtag.h>
89 #if BYTE_ORDER == BIG_ENDIAN
90 #define htobe64(x) (x)
91 #else /* LITTLE ENDIAN */
92 #define htobe64(x) __DARWIN_OSSwapInt64(x)
93 #endif /* LITTLE_ENDIAN */
95 #define be64toh(x) htobe64(x)
97 __private_extern__ lck_rw_t
*pf_perim_lock
;
98 __private_extern__ lck_mtx_t
*pf_lock
;
101 struct zone
*pool_zone
; /* pointer to backend zone */
102 const char *pool_name
; /* name of pool */
103 unsigned int pool_count
; /* # of outstanding elements */
104 unsigned int pool_hiwat
; /* high watermark */
105 unsigned int pool_limit
; /* hard limit */
106 unsigned int pool_fails
; /* # of failed allocs due to limit */
109 #define PR_NOWAIT FALSE
110 #define PR_WAITOK TRUE
112 __private_extern__
void pool_init(struct pool
*, size_t, unsigned int,
113 unsigned int, int, const char *, void *);
114 __private_extern__
void pool_destroy(struct pool
*);
115 __private_extern__
void pool_sethiwat(struct pool
*, int);
116 __private_extern__
void pool_sethardlimit(struct pool
*, int,
118 __private_extern__
void *pool_get(struct pool
*, int);
119 __private_extern__
void pool_put(struct pool
*, void *);
120 __private_extern__ u_int64_t
pf_time_second(void);
123 union sockaddr_union
{
125 struct sockaddr_in sin
;
126 struct sockaddr_in6 sin6
;
133 #define PF_TCPS_PROXY_SRC ((TCP_NSTATES)+0)
134 #define PF_TCPS_PROXY_DST ((TCP_NSTATES)+1)
136 #define PF_MD5_DIGEST_LENGTH 16
137 #ifdef MD5_DIGEST_LENGTH
138 #if PF_MD5_DIGEST_LENGTH != MD5_DIGEST_LENGTH
143 #ifndef NO_APPLE_EXTENSIONS
148 enum { PF_INOUT
, PF_IN
, PF_OUT
};
149 enum { PF_PASS
, PF_DROP
, PF_SCRUB
, PF_NOSCRUB
, PF_NAT
, PF_NONAT
,
150 PF_BINAT
, PF_NOBINAT
, PF_RDR
, PF_NORDR
, PF_SYNPROXY_DROP
};
151 enum { PF_RULESET_SCRUB
, PF_RULESET_FILTER
, PF_RULESET_NAT
,
152 PF_RULESET_BINAT
, PF_RULESET_RDR
, PF_RULESET_MAX
};
153 enum { PF_OP_NONE
, PF_OP_IRG
, PF_OP_EQ
, PF_OP_NE
, PF_OP_LT
,
154 PF_OP_LE
, PF_OP_GT
, PF_OP_GE
, PF_OP_XRG
, PF_OP_RRG
};
155 enum { PF_DEBUG_NONE
, PF_DEBUG_URGENT
, PF_DEBUG_MISC
, PF_DEBUG_NOISY
};
156 enum { PF_CHANGE_NONE
, PF_CHANGE_ADD_HEAD
, PF_CHANGE_ADD_TAIL
,
157 PF_CHANGE_ADD_BEFORE
, PF_CHANGE_ADD_AFTER
,
158 PF_CHANGE_REMOVE
, PF_CHANGE_GET_TICKET
};
159 enum { PF_GET_NONE
, PF_GET_CLR_CNTR
};
162 * Note about PFTM_*: real indices into pf_rule.timeout[] come before
163 * PFTM_MAX, special cases afterwards. See pf_state_expires().
165 enum { PFTM_TCP_FIRST_PACKET
, PFTM_TCP_OPENING
, PFTM_TCP_ESTABLISHED
,
166 PFTM_TCP_CLOSING
, PFTM_TCP_FIN_WAIT
, PFTM_TCP_CLOSED
,
167 PFTM_UDP_FIRST_PACKET
, PFTM_UDP_SINGLE
, PFTM_UDP_MULTIPLE
,
168 PFTM_ICMP_FIRST_PACKET
, PFTM_ICMP_ERROR_REPLY
,
169 #ifndef NO_APPLE_EXTENSIONS
170 PFTM_GREv1_FIRST_PACKET
, PFTM_GREv1_INITIATING
, PFTM_GREv1_ESTABLISHED
,
171 PFTM_ESP_FIRST_PACKET
, PFTM_ESP_INITIATING
, PFTM_ESP_ESTABLISHED
,
173 PFTM_OTHER_FIRST_PACKET
, PFTM_OTHER_SINGLE
,
174 PFTM_OTHER_MULTIPLE
, PFTM_FRAG
, PFTM_INTERVAL
,
175 PFTM_ADAPTIVE_START
, PFTM_ADAPTIVE_END
, PFTM_SRC_NODE
,
176 PFTM_TS_DIFF
, PFTM_MAX
, PFTM_PURGE
, PFTM_UNLINKED
,
179 /* PFTM default values */
180 #define PFTM_TCP_FIRST_PACKET_VAL 120 /* First TCP packet */
181 #define PFTM_TCP_OPENING_VAL 30 /* No response yet */
182 #define PFTM_TCP_ESTABLISHED_VAL (24 * 60 * 60) /* Established */
183 #define PFTM_TCP_CLOSING_VAL (15 * 60) /* Half closed */
184 #define PFTM_TCP_FIN_WAIT_VAL 45 /* Got both FINs */
185 #define PFTM_TCP_CLOSED_VAL 90 /* Got a RST */
186 #define PFTM_UDP_FIRST_PACKET_VAL 60 /* First UDP packet */
187 #define PFTM_UDP_SINGLE_VAL 30 /* Unidirectional */
188 #define PFTM_UDP_MULTIPLE_VAL 60 /* Bidirectional */
189 #define PFTM_ICMP_FIRST_PACKET_VAL 20 /* First ICMP packet */
190 #define PFTM_ICMP_ERROR_REPLY_VAL 10 /* Got error response */
191 #ifndef NO_APPLE_EXTENSIONS
192 #define PFTM_GREv1_FIRST_PACKET_VAL 120
193 #define PFTM_GREv1_INITIATING_VAL 30
194 #define PFTM_GREv1_ESTABLISHED_VAL 1800
195 #define PFTM_ESP_FIRST_PACKET_VAL 120
196 #define PFTM_ESP_INITIATING_VAL 30
197 #define PFTM_ESP_ESTABLISHED_VAL 900
199 #define PFTM_OTHER_FIRST_PACKET_VAL 60 /* First packet */
200 #define PFTM_OTHER_SINGLE_VAL 30 /* Unidirectional */
201 #define PFTM_OTHER_MULTIPLE_VAL 60 /* Bidirectional */
202 #define PFTM_FRAG_VAL 30 /* Fragment expire */
203 #define PFTM_INTERVAL_VAL 10 /* Expire interval */
204 #define PFTM_SRC_NODE_VAL 0 /* Source tracking */
205 #define PFTM_TS_DIFF_VAL 30 /* Allowed TS diff */
207 enum { PF_NOPFROUTE
, PF_FASTROUTE
, PF_ROUTETO
, PF_DUPTO
, PF_REPLYTO
};
208 enum { PF_LIMIT_STATES
,
209 #ifndef NO_APPLE_EXTENSIONS
212 PF_LIMIT_SRC_NODES
, PF_LIMIT_FRAGS
,
213 PF_LIMIT_TABLES
, PF_LIMIT_TABLE_ENTRIES
, PF_LIMIT_MAX
};
214 #define PF_POOL_IDMASK 0x0f
215 enum { PF_POOL_NONE
, PF_POOL_BITMASK
, PF_POOL_RANDOM
,
216 PF_POOL_SRCHASH
, PF_POOL_ROUNDROBIN
};
217 enum { PF_ADDR_ADDRMASK
, PF_ADDR_NOROUTE
, PF_ADDR_DYNIFTL
,
218 PF_ADDR_TABLE
, PF_ADDR_RTLABEL
, PF_ADDR_URPFFAILED
,
220 #define PF_POOL_TYPEMASK 0x0f
221 #define PF_POOL_STICKYADDR 0x20
222 #define PF_WSCALE_FLAG 0x80
223 #define PF_WSCALE_MASK 0x0f
226 #define PF_LOG_ALL 0x02
227 #define PF_LOG_SOCKET_LOOKUP 0x04
236 } pfa
; /* 128-bit address */
239 #define addr8 pfa.addr8
240 #define addr16 pfa.addr16
241 #define addr32 pfa.addr32
244 #define PF_TABLE_NAME_SIZE 32
246 #define PFI_AFLAG_NETWORK 0x01
247 #define PFI_AFLAG_BROADCAST 0x02
248 #define PFI_AFLAG_PEER 0x04
249 #define PFI_AFLAG_MODEMASK 0x07
250 #define PFI_AFLAG_NOALIAS 0x08
253 #define RTLABEL_LEN 32
256 struct pf_addr_wrap
{
262 char ifname
[IFNAMSIZ
];
263 char tblname
[PF_TABLE_NAME_SIZE
];
264 char rtlabelname
[RTLABEL_LEN
];
268 struct pfi_dynaddr
*dyn
__attribute__((aligned(8)));
269 struct pfr_ktable
*tbl
__attribute__((aligned(8)));
270 int dyncnt
__attribute__((aligned(8)));
271 int tblcnt
__attribute__((aligned(8)));
272 } p
__attribute__((aligned(8)));
273 u_int8_t type
; /* PF_ADDR_* */
274 u_int8_t iflags
; /* PFI_AFLAG_* */
277 #ifndef NO_APPLE_EXTENSIONS
278 struct pf_port_range
{
283 union pf_rule_xport
{
284 struct pf_port_range range
;
292 TAILQ_ENTRY(pfi_dynaddr
) entry
;
293 struct pf_addr pfid_addr4
;
294 struct pf_addr pfid_mask4
;
295 struct pf_addr pfid_addr6
;
296 struct pf_addr pfid_mask6
;
297 struct pfr_ktable
*pfid_kt
;
298 struct pfi_kif
*pfid_kif
;
299 void *pfid_hook_cookie
;
300 int pfid_net
; /* mask or 128 */
301 int pfid_acnt4
; /* address count IPv4 */
302 int pfid_acnt6
; /* address count IPv6 */
303 sa_family_t pfid_af
; /* rule af */
304 u_int8_t pfid_iflags
; /* PFI_AFLAG_* */
308 * Address manipulation macros
319 #define PF_INET6_ONLY
325 #define PF_INET_INET6
331 #define PF_INET_INET6
335 /* Both IPv4 and IPv6 */
338 #define PF_AEQ(a, b, c) \
339 ((c == AF_INET && (a)->addr32[0] == (b)->addr32[0]) || \
340 ((a)->addr32[3] == (b)->addr32[3] && \
341 (a)->addr32[2] == (b)->addr32[2] && \
342 (a)->addr32[1] == (b)->addr32[1] && \
343 (a)->addr32[0] == (b)->addr32[0])) \
345 #define PF_ANEQ(a, b, c) \
346 ((c == AF_INET && (a)->addr32[0] != (b)->addr32[0]) || \
347 ((a)->addr32[3] != (b)->addr32[3] || \
348 (a)->addr32[2] != (b)->addr32[2] || \
349 (a)->addr32[1] != (b)->addr32[1] || \
350 (a)->addr32[0] != (b)->addr32[0])) \
352 #define PF_AZERO(a, c) \
353 ((c == AF_INET && !(a)->addr32[0]) || \
354 (!(a)->addr32[0] && !(a)->addr32[1] && \
355 !(a)->addr32[2] && !(a)->addr32[3])) \
357 #define PF_MATCHA(n, a, m, b, f) \
358 pf_match_addr(n, a, m, b, f)
360 #define PF_ACPY(a, b, f) \
363 #define PF_AINC(a, f) \
366 #define PF_POOLMASK(a, b, c, d, f) \
367 pf_poolmask(a, b, c, d, f)
375 #define PF_AEQ(a, b, c) \
376 ((a)->addr32[3] == (b)->addr32[3] && \
377 (a)->addr32[2] == (b)->addr32[2] && \
378 (a)->addr32[1] == (b)->addr32[1] && \
379 (a)->addr32[0] == (b)->addr32[0]) \
381 #define PF_ANEQ(a, b, c) \
382 ((a)->addr32[3] != (b)->addr32[3] || \
383 (a)->addr32[2] != (b)->addr32[2] || \
384 (a)->addr32[1] != (b)->addr32[1] || \
385 (a)->addr32[0] != (b)->addr32[0]) \
387 #define PF_AZERO(a, c) \
388 (!(a)->addr32[0] && \
393 #define PF_MATCHA(n, a, m, b, f) \
394 pf_match_addr(n, a, m, b, f)
396 #define PF_ACPY(a, b, f) \
399 #define PF_AINC(a, f) \
402 #define PF_POOLMASK(a, b, c, d, f) \
403 pf_poolmask(a, b, c, d, f)
410 #define PF_AEQ(a, b, c) \
411 ((a)->addr32[0] == (b)->addr32[0])
413 #define PF_ANEQ(a, b, c) \
414 ((a)->addr32[0] != (b)->addr32[0])
416 #define PF_AZERO(a, c) \
419 #define PF_MATCHA(n, a, m, b, f) \
420 pf_match_addr(n, a, m, b, f)
422 #define PF_ACPY(a, b, f) \
423 (a)->v4.s_addr = (b)->v4.s_addr
425 #define PF_AINC(a, f) \
427 (a)->addr32[0] = htonl(ntohl((a)->addr32[0]) + 1); \
430 #define PF_POOLMASK(a, b, c, d, f) \
432 (a)->addr32[0] = ((b)->addr32[0] & (c)->addr32[0]) | \
433 (((c)->addr32[0] ^ 0xffffffff) & (d)->addr32[0]); \
436 #endif /* PF_INET_ONLY */
437 #endif /* PF_INET6_ONLY */
438 #endif /* PF_INET_INET6 */
440 #define PF_MISMATCHAW(aw, x, af, neg, ifp) \
442 (((aw)->type == PF_ADDR_NOROUTE && \
443 pf_routable((x), (af), NULL)) || \
444 (((aw)->type == PF_ADDR_URPFFAILED && (ifp) != NULL && \
445 pf_routable((x), (af), (ifp))) || \
446 ((aw)->type == PF_ADDR_RTLABEL && \
447 !pf_rtlabel_match((x), (af), (aw))) || \
448 ((aw)->type == PF_ADDR_TABLE && \
449 !pfr_match_addr((aw)->p.tbl, (x), (af))) || \
450 ((aw)->type == PF_ADDR_DYNIFTL && \
451 !pfi_match_addr((aw)->p.dyn, (x), (af))) || \
452 ((aw)->type == PF_ADDR_RANGE && \
453 !pf_match_addr_range(&(aw)->v.a.addr, \
454 &(aw)->v.a.mask, (x), (af))) || \
455 ((aw)->type == PF_ADDR_ADDRMASK && \
456 !PF_AZERO(&(aw)->v.a.mask, (af)) && \
457 !PF_MATCHA(0, &(aw)->v.a.addr, \
458 &(aw)->v.a.mask, (x), (af))))) != \
475 struct pf_rule_addr
{
476 struct pf_addr_wrap addr
;
477 #ifndef NO_APPLE_EXTENSIONS
478 union pf_rule_xport xport
;
488 struct pf_addr_wrap addr
;
489 TAILQ_ENTRY(pf_pooladdr
) entries
;
490 #if !defined(__LP64__)
492 #endif /* !__LP64__ */
493 char ifname
[IFNAMSIZ
];
494 struct pfi_kif
*kif
__attribute__((aligned(8)));
497 TAILQ_HEAD(pf_palist
, pf_pooladdr
);
499 struct pf_poolhashkey
{
504 } pfk
; /* 128-bit hash key */
505 #define key8 pfk.key8
506 #define key16 pfk.key16
507 #define key32 pfk.key32
511 struct pf_palist list
;
512 #if !defined(__LP64__)
514 #endif /* !__LP64__ */
515 struct pf_pooladdr
*cur
__attribute__((aligned(8)));
516 struct pf_poolhashkey key
__attribute__((aligned(8)));
517 struct pf_addr counter
;
519 u_int16_t proxy_port
[2];
525 /* A packed Operating System description for fingerprinting */
526 typedef u_int32_t pf_osfp_t
;
527 #define PF_OSFP_ANY ((pf_osfp_t)0)
528 #define PF_OSFP_UNKNOWN ((pf_osfp_t)-1)
529 #define PF_OSFP_NOMATCH ((pf_osfp_t)-2)
531 struct pf_osfp_entry
{
532 SLIST_ENTRY(pf_osfp_entry
) fp_entry
;
533 #if !defined(__LP64__)
535 #endif /* !__LP64__ */
538 #define PF_OSFP_EXPANDED 0x001 /* expanded entry */
539 #define PF_OSFP_GENERIC 0x002 /* generic signature */
540 #define PF_OSFP_NODETAIL 0x004 /* no p0f details */
541 #define PF_OSFP_LEN 32
542 char fp_class_nm
[PF_OSFP_LEN
];
543 char fp_version_nm
[PF_OSFP_LEN
];
544 char fp_subtype_nm
[PF_OSFP_LEN
];
546 #define PF_OSFP_ENTRY_EQ(a, b) \
547 ((a)->fp_os == (b)->fp_os && \
548 memcmp((a)->fp_class_nm, (b)->fp_class_nm, PF_OSFP_LEN) == 0 && \
549 memcmp((a)->fp_version_nm, (b)->fp_version_nm, PF_OSFP_LEN) == 0 && \
550 memcmp((a)->fp_subtype_nm, (b)->fp_subtype_nm, PF_OSFP_LEN) == 0)
552 /* handle pf_osfp_t packing */
553 #define _FP_RESERVED_BIT 1 /* For the special negative #defines */
554 #define _FP_UNUSED_BITS 1
555 #define _FP_CLASS_BITS 10 /* OS Class (Windows, Linux) */
556 #define _FP_VERSION_BITS 10 /* OS version (95, 98, NT, 2.4.54, 3.2) */
557 #define _FP_SUBTYPE_BITS 10 /* patch level (NT SP4, SP3, ECN patch) */
558 #define PF_OSFP_UNPACK(osfp, class, version, subtype) do { \
559 (class) = ((osfp) >> (_FP_VERSION_BITS+_FP_SUBTYPE_BITS)) & \
560 ((1 << _FP_CLASS_BITS) - 1); \
561 (version) = ((osfp) >> _FP_SUBTYPE_BITS) & \
562 ((1 << _FP_VERSION_BITS) - 1);\
563 (subtype) = (osfp) & ((1 << _FP_SUBTYPE_BITS) - 1); \
565 #define PF_OSFP_PACK(osfp, class, version, subtype) do { \
566 (osfp) = ((class) & ((1 << _FP_CLASS_BITS) - 1)) << (_FP_VERSION_BITS \
567 + _FP_SUBTYPE_BITS); \
568 (osfp) |= ((version) & ((1 << _FP_VERSION_BITS) - 1)) << \
570 (osfp) |= (subtype) & ((1 << _FP_SUBTYPE_BITS) - 1); \
573 /* the fingerprint of an OSes TCP SYN packet */
574 typedef u_int64_t pf_tcpopts_t
;
575 struct pf_os_fingerprint
{
576 SLIST_HEAD(pf_osfp_enlist
, pf_osfp_entry
) fp_oses
; /* list of matches */
577 pf_tcpopts_t fp_tcpopts
; /* packed TCP options */
578 u_int16_t fp_wsize
; /* TCP window size */
579 u_int16_t fp_psize
; /* ip->ip_len */
580 u_int16_t fp_mss
; /* TCP MSS */
582 #define PF_OSFP_WSIZE_MOD 0x0001 /* Window modulus */
583 #define PF_OSFP_WSIZE_DC 0x0002 /* Window don't care */
584 #define PF_OSFP_WSIZE_MSS 0x0004 /* Window multiple of MSS */
585 #define PF_OSFP_WSIZE_MTU 0x0008 /* Window multiple of MTU */
586 #define PF_OSFP_PSIZE_MOD 0x0010 /* packet size modulus */
587 #define PF_OSFP_PSIZE_DC 0x0020 /* packet size don't care */
588 #define PF_OSFP_WSCALE 0x0040 /* TCP window scaling */
589 #define PF_OSFP_WSCALE_MOD 0x0080 /* TCP window scale modulus */
590 #define PF_OSFP_WSCALE_DC 0x0100 /* TCP window scale dont-care */
591 #define PF_OSFP_MSS 0x0200 /* TCP MSS */
592 #define PF_OSFP_MSS_MOD 0x0400 /* TCP MSS modulus */
593 #define PF_OSFP_MSS_DC 0x0800 /* TCP MSS dont-care */
594 #define PF_OSFP_DF 0x1000 /* IPv4 don't fragment bit */
595 #define PF_OSFP_TS0 0x2000 /* Zero timestamp */
596 #define PF_OSFP_INET6 0x4000 /* IPv6 */
597 u_int8_t fp_optcnt
; /* TCP option count */
598 u_int8_t fp_wscale
; /* TCP window scaling */
599 u_int8_t fp_ttl
; /* IPv4 TTL */
600 #define PF_OSFP_MAXTTL_OFFSET 40
601 /* TCP options packing */
602 #define PF_OSFP_TCPOPT_NOP 0x0 /* TCP NOP option */
603 #define PF_OSFP_TCPOPT_WSCALE 0x1 /* TCP window scaling option */
604 #define PF_OSFP_TCPOPT_MSS 0x2 /* TCP max segment size opt */
605 #define PF_OSFP_TCPOPT_SACK 0x3 /* TCP SACK OK option */
606 #define PF_OSFP_TCPOPT_TS 0x4 /* TCP timestamp option */
607 #define PF_OSFP_TCPOPT_BITS 3 /* bits used by each option */
608 #define PF_OSFP_MAX_OPTS \
609 (sizeof(((struct pf_os_fingerprint *)0)->fp_tcpopts) * 8) \
610 / PF_OSFP_TCPOPT_BITS
612 SLIST_ENTRY(pf_os_fingerprint
) fp_next
;
615 struct pf_osfp_ioctl
{
616 struct pf_osfp_entry fp_os
;
617 pf_tcpopts_t fp_tcpopts
; /* packed TCP options */
618 u_int16_t fp_wsize
; /* TCP window size */
619 u_int16_t fp_psize
; /* ip->ip_len */
620 u_int16_t fp_mss
; /* TCP MSS */
622 u_int8_t fp_optcnt
; /* TCP option count */
623 u_int8_t fp_wscale
; /* TCP window scaling */
624 u_int8_t fp_ttl
; /* IPv4 TTL */
626 int fp_getnum
; /* DIOCOSFPGET number */
631 struct pf_rule
*ptr
__attribute__((aligned(8)));
632 u_int32_t nr
__attribute__((aligned(8)));
633 } __attribute__((aligned(8)));
635 #define PF_ANCHOR_NAME_SIZE 64
638 struct pf_rule_addr src
;
639 struct pf_rule_addr dst
;
640 #define PF_SKIP_IFP 0
641 #define PF_SKIP_DIR 1
643 #define PF_SKIP_PROTO 3
644 #define PF_SKIP_SRC_ADDR 4
645 #define PF_SKIP_SRC_PORT 5
646 #define PF_SKIP_DST_ADDR 6
647 #define PF_SKIP_DST_PORT 7
648 #define PF_SKIP_COUNT 8
649 union pf_rule_ptr skip
[PF_SKIP_COUNT
];
650 #define PF_RULE_LABEL_SIZE 64
651 char label
[PF_RULE_LABEL_SIZE
];
652 #define PF_QNAME_SIZE 64
653 char ifname
[IFNAMSIZ
];
654 char qname
[PF_QNAME_SIZE
];
655 char pqname
[PF_QNAME_SIZE
];
656 #define PF_TAG_NAME_SIZE 64
657 char tagname
[PF_TAG_NAME_SIZE
];
658 char match_tagname
[PF_TAG_NAME_SIZE
];
660 char overload_tblname
[PF_TABLE_NAME_SIZE
];
662 TAILQ_ENTRY(pf_rule
) entries
;
663 #if !defined(__LP64__)
665 #endif /* !__LP64__ */
666 struct pf_pool rpool
;
668 u_int64_t evaluations
;
669 u_int64_t packets
[2];
672 struct pfi_kif
*kif
__attribute__((aligned(8)));
673 struct pf_anchor
*anchor
__attribute__((aligned(8)));
674 struct pfr_ktable
*overload_tbl
__attribute__((aligned(8)));
676 pf_osfp_t os_fingerprint
__attribute__((aligned(8)));
678 unsigned int rtableid
;
679 u_int32_t timeout
[PFTM_MAX
];
681 u_int32_t max_states
;
683 u_int32_t max_src_nodes
;
684 u_int32_t max_src_states
;
685 u_int32_t max_src_conn
;
698 u_int16_t return_icmp
;
699 u_int16_t return_icmp6
;
704 struct pf_rule_uid uid
;
705 struct pf_rule_gid gid
;
714 u_int8_t match_tag_not
;
717 #define PF_STATE_NORMAL 0x1
718 #define PF_STATE_MODULATE 0x2
719 #define PF_STATE_SYNPROXY 0x3
732 u_int8_t anchor_relative
;
733 u_int8_t anchor_wildcard
;
735 #define PF_FLUSH 0x01
736 #define PF_FLUSH_GLOBAL 0x02
739 #ifndef NO_APPLE_EXTENSIONS
740 u_int8_t proto_variant
;
741 u_int8_t extfilter
; /* Filter mode [PF_EXTFILTER_xxx] */
742 u_int8_t extmap
; /* Mapping mode [PF_EXTMAP_xxx] */
747 #define PFRULE_DROP 0x0000
748 #define PFRULE_RETURNRST 0x0001
749 #define PFRULE_FRAGMENT 0x0002
750 #define PFRULE_RETURNICMP 0x0004
751 #define PFRULE_RETURN 0x0008
752 #define PFRULE_NOSYNC 0x0010
753 #define PFRULE_SRCTRACK 0x0020 /* track source states */
754 #define PFRULE_RULESRCTRACK 0x0040 /* per rule */
757 #define PFRULE_NODF 0x0100
758 #define PFRULE_FRAGCROP 0x0200 /* non-buffering frag cache */
759 #define PFRULE_FRAGDROP 0x0400 /* drop funny fragments */
760 #define PFRULE_RANDOMID 0x0800
761 #define PFRULE_REASSEMBLE_TCP 0x1000
763 /* rule flags again */
764 #define PFRULE_IFBOUND 0x00010000 /* if-bound */
766 #define PFSTATE_HIWAT 10000 /* default state table size */
767 #define PFSTATE_ADAPT_START 6000 /* default adaptive timeout start */
768 #define PFSTATE_ADAPT_END 12000 /* default adaptive timeout end */
770 #ifndef NO_APPLE_EXTENSIONS
771 #define PFAPPSTATE_HIWAT 10000 /* default same as state table */
774 PF_EXTMAP_APD
= 1, /* Address-port-dependent mapping */
775 PF_EXTMAP_AD
, /* Address-dependent mapping */
776 PF_EXTMAP_EI
/* Endpoint-independent mapping */
780 PF_EXTFILTER_APD
= 1, /* Address-port-dependent filtering */
781 PF_EXTFILTER_AD
, /* Address-dependent filtering */
782 PF_EXTFILTER_EI
/* Endpoint-independent filtering */
786 struct pf_threshold
{
788 #define PF_THRESHOLD_MULT 1000
789 #define PF_THRESHOLD_MAX 0xffffffff / PF_THRESHOLD_MULT
796 RB_ENTRY(pf_src_node
) entry
;
798 struct pf_addr raddr
;
799 union pf_rule_ptr rule
;
802 u_int64_t packets
[2];
805 struct pf_threshold conn_rate
;
812 #define PFSNODE_HIWAT 10000 /* default source node table size */
814 struct pf_state_scrub
{
815 struct timeval pfss_last
; /* time received last packet */
816 u_int32_t pfss_tsecr
; /* last echoed timestamp */
817 u_int32_t pfss_tsval
; /* largest timestamp */
818 u_int32_t pfss_tsval0
; /* original timestamp */
819 u_int16_t pfss_flags
;
820 #define PFSS_TIMESTAMP 0x0001 /* modulate timestamp */
821 #define PFSS_PAWS 0x0010 /* stricter PAWS checks */
822 #define PFSS_PAWS_IDLED 0x0020 /* was idle too long. no PAWS */
823 #define PFSS_DATA_TS 0x0040 /* timestamp on data packets */
824 #define PFSS_DATA_NOTS 0x0080 /* no timestamp on data packets */
825 u_int8_t pfss_ttl
; /* stashed TTL */
827 u_int32_t pfss_ts_mod
; /* timestamp modulation */
830 #ifndef NO_APPLE_EXTENSIONS
831 union pf_state_xport
{
837 struct pf_state_host
{
839 union pf_state_xport xport
;
842 struct pf_state_host
{
849 struct pf_state_peer
{
850 u_int32_t seqlo
; /* Max sequence number sent */
851 u_int32_t seqhi
; /* Max the other end ACKd + win */
852 u_int32_t seqdiff
; /* Sequence number modulator */
853 u_int16_t max_win
; /* largest window (pre scaling) */
854 u_int8_t state
; /* active state level */
855 u_int8_t wscale
; /* window scaling factor */
856 u_int16_t mss
; /* Maximum segment size option */
857 u_int8_t tcp_est
; /* Did we reach TCPS_ESTABLISHED */
858 struct pf_state_scrub
*scrub
; /* state is scrubbed */
862 TAILQ_HEAD(pf_state_queue
, pf_state
);
864 #ifndef NO_APPLE_EXTENSIONS
870 typedef void (*pf_app_handler
)(struct pf_state
*, int, int, struct pf_pdesc
*,
873 typedef int (*pf_app_compare
)(struct pf_app_state
*, struct pf_app_state
*);
875 struct pf_pptp_state
{
876 struct pf_state
*grev1_state
;
879 struct pf_ike_state
{
883 struct pf_app_state
{
884 pf_app_handler handler
;
885 pf_app_compare compare_lan_ext
;
886 pf_app_compare compare_ext_gwy
;
888 struct pf_pptp_state pptp
;
889 struct pf_ike_state ike
;
893 #define PF_GRE_PPTP_VARIANT 0x01
896 /* keep synced with struct pf_state, used in RB_FIND */
897 struct pf_state_key_cmp
{
898 struct pf_state_host lan
;
899 struct pf_state_host gwy
;
900 struct pf_state_host ext
;
904 #ifndef NO_APPLE_EXTENSIONS
905 u_int8_t proto_variant
;
906 struct pf_app_state
*app_state
;
912 TAILQ_HEAD(pf_statelist
, pf_state
);
914 struct pf_state_key
{
915 struct pf_state_host lan
;
916 struct pf_state_host gwy
;
917 struct pf_state_host ext
;
921 #ifndef NO_APPLE_EXTENSIONS
922 u_int8_t proto_variant
;
923 struct pf_app_state
*app_state
;
928 RB_ENTRY(pf_state_key
) entry_lan_ext
;
929 RB_ENTRY(pf_state_key
) entry_ext_gwy
;
930 struct pf_statelist states
;
931 u_short refcnt
; /* same size as if_index */
935 /* keep synced with struct pf_state, used in RB_FIND */
936 struct pf_state_cmp
{
943 TAILQ_HEAD(hook_desc_head
, hook_desc
);
950 TAILQ_ENTRY(pf_state
) entry_list
;
951 TAILQ_ENTRY(pf_state
) next
;
952 RB_ENTRY(pf_state
) entry_id
;
953 struct pf_state_peer src
;
954 struct pf_state_peer dst
;
955 union pf_rule_ptr rule
;
956 union pf_rule_ptr anchor
;
957 union pf_rule_ptr nat_rule
;
958 struct pf_addr rt_addr
;
959 #ifndef NO_APPLE_EXTENSIONS
960 struct hook_desc_head unlink_hooks
;
962 struct pf_state_key
*state_key
;
964 struct pfi_kif
*rt_kif
;
965 struct pf_src_node
*src_node
;
966 struct pf_src_node
*nat_src_node
;
967 u_int64_t packets
[2];
971 u_int64_t pfsync_time
;
977 #define PFSTATE_NOSYNC 0x01
978 #define PFSTATE_FROMSYNC 0x02
979 #define PFSTATE_STALE 0x04
982 #define __packed __attribute__((__packed__))
985 * Unified state structures for pulling states out of the kernel
986 * used by pfsync(4) and the pf(4) ioctl.
988 struct pfsync_state_scrub
{
989 u_int16_t pfss_flags
;
990 u_int8_t pfss_ttl
; /* stashed TTL */
991 #define PFSYNC_SCRUB_FLAG_VALID 0x01
993 u_int32_t pfss_ts_mod
; /* timestamp modulation */
996 struct pfsync_state_host
{
998 #ifndef NO_APPLE_EXTENSIONS
999 union pf_state_xport xport
;
1007 struct pfsync_state_peer
{
1008 struct pfsync_state_scrub scrub
; /* state is scrubbed */
1009 u_int32_t seqlo
; /* Max sequence number sent */
1010 u_int32_t seqhi
; /* Max the other end ACKd + win */
1011 u_int32_t seqdiff
; /* Sequence number modulator */
1012 u_int16_t max_win
; /* largest window (pre scaling) */
1013 u_int16_t mss
; /* Maximum segment size option */
1014 u_int8_t state
; /* active state level */
1015 u_int8_t wscale
; /* window scaling factor */
1019 struct pfsync_state
{
1021 char ifname
[IFNAMSIZ
];
1022 struct pfsync_state_host lan
;
1023 struct pfsync_state_host gwy
;
1024 struct pfsync_state_host ext
;
1025 struct pfsync_state_peer src
;
1026 struct pfsync_state_peer dst
;
1027 struct pf_addr rt_addr
;
1028 #ifndef NO_APPLE_EXTENSIONS
1029 struct hook_desc_head unlink_hooks
;
1030 #if !defined(__LP64__)
1032 #endif /* !__LP64__ */
1039 u_int32_t packets
[2][2];
1040 u_int32_t bytes
[2][2];
1041 u_int32_t creatorid
;
1042 #ifndef NO_APPLE_EXTENSIONS
1049 u_int8_t allow_opts
;
1051 u_int8_t sync_flags
;
1053 #ifndef NO_APPLE_EXTENSIONS
1054 u_int8_t proto_variant
;
1058 #define PFSYNC_FLAG_COMPRESS 0x01
1059 #define PFSYNC_FLAG_STALE 0x02
1060 #define PFSYNC_FLAG_SRCNODE 0x04
1061 #define PFSYNC_FLAG_NATSRCNODE 0x08
1063 /* for copies to/from userland via pf_ioctl() */
1064 #define pf_state_peer_to_pfsync(s, d) do { \
1065 (d)->seqlo = (s)->seqlo; \
1066 (d)->seqhi = (s)->seqhi; \
1067 (d)->seqdiff = (s)->seqdiff; \
1068 (d)->max_win = (s)->max_win; \
1069 (d)->mss = (s)->mss; \
1070 (d)->state = (s)->state; \
1071 (d)->wscale = (s)->wscale; \
1073 (d)->scrub.pfss_flags = \
1074 (s)->scrub->pfss_flags & PFSS_TIMESTAMP; \
1075 (d)->scrub.pfss_ttl = (s)->scrub->pfss_ttl; \
1076 (d)->scrub.pfss_ts_mod = (s)->scrub->pfss_ts_mod; \
1077 (d)->scrub.scrub_flag = PFSYNC_SCRUB_FLAG_VALID; \
1081 #define pf_state_peer_from_pfsync(s, d) do { \
1082 (d)->seqlo = (s)->seqlo; \
1083 (d)->seqhi = (s)->seqhi; \
1084 (d)->seqdiff = (s)->seqdiff; \
1085 (d)->max_win = (s)->max_win; \
1086 (d)->mss = ntohs((s)->mss); \
1087 (d)->state = (s)->state; \
1088 (d)->wscale = (s)->wscale; \
1089 if ((s)->scrub.scrub_flag == PFSYNC_SCRUB_FLAG_VALID && \
1090 (d)->scrub != NULL) { \
1091 (d)->scrub->pfss_flags = \
1092 ntohs((s)->scrub.pfss_flags) & PFSS_TIMESTAMP; \
1093 (d)->scrub->pfss_ttl = (s)->scrub.pfss_ttl; \
1094 (d)->scrub->pfss_ts_mod = (s)->scrub.pfss_ts_mod; \
1098 #define pf_state_counter_to_pfsync(s, d) do { \
1099 d[0] = (s>>32)&0xffffffff; \
1100 d[1] = s&0xffffffff; \
1103 #define pf_state_counter_from_pfsync(s) \
1104 (((u_int64_t)(s[0])<<32) | (u_int64_t)(s[1]))
1108 TAILQ_HEAD(pf_rulequeue
, pf_rule
);
1114 struct pf_rulequeue queues
[2];
1116 struct pf_rulequeue
*ptr
;
1117 struct pf_rule
**ptr_array
;
1122 } rules
[PF_RULESET_MAX
];
1123 struct pf_anchor
*anchor
;
1129 RB_HEAD(pf_anchor_global
, pf_anchor
);
1130 RB_HEAD(pf_anchor_node
, pf_anchor
);
1132 RB_ENTRY(pf_anchor
) entry_global
;
1133 RB_ENTRY(pf_anchor
) entry_node
;
1134 struct pf_anchor
*parent
;
1135 struct pf_anchor_node children
;
1136 char name
[PF_ANCHOR_NAME_SIZE
];
1137 char path
[MAXPATHLEN
];
1138 struct pf_ruleset ruleset
;
1139 int refcnt
; /* anchor rules */
1143 RB_PROTOTYPE_SC(__private_extern__
, pf_anchor_global
, pf_anchor
, entry_global
,
1145 RB_PROTOTYPE_SC(__private_extern__
, pf_anchor_node
, pf_anchor
, entry_node
,
1148 RB_PROTOTYPE(pf_anchor_global
, pf_anchor
, entry_global
, pf_anchor_compare
);
1149 RB_PROTOTYPE(pf_anchor_node
, pf_anchor
, entry_node
, pf_anchor_compare
);
1150 #endif /* !KERNEL */
1152 #define PF_RESERVED_ANCHOR "_pf"
1154 #define PFR_TFLAG_PERSIST 0x00000001
1155 #define PFR_TFLAG_CONST 0x00000002
1156 #define PFR_TFLAG_ACTIVE 0x00000004
1157 #define PFR_TFLAG_INACTIVE 0x00000008
1158 #define PFR_TFLAG_REFERENCED 0x00000010
1159 #define PFR_TFLAG_REFDANCHOR 0x00000020
1160 #define PFR_TFLAG_USRMASK 0x00000003
1161 #define PFR_TFLAG_SETMASK 0x0000003C
1162 #define PFR_TFLAG_ALLMASK 0x0000003F
1165 char pfrt_anchor
[MAXPATHLEN
];
1166 char pfrt_name
[PF_TABLE_NAME_SIZE
];
1167 u_int32_t pfrt_flags
;
1168 u_int8_t pfrt_fback
;
1171 enum { PFR_FB_NONE
, PFR_FB_MATCH
, PFR_FB_ADDED
, PFR_FB_DELETED
,
1172 PFR_FB_CHANGED
, PFR_FB_CLEARED
, PFR_FB_DUPLICATE
,
1173 PFR_FB_NOTMATCH
, PFR_FB_CONFLICT
, PFR_FB_MAX
};
1177 struct in_addr _pfra_ip4addr
;
1178 struct in6_addr _pfra_ip6addr
;
1183 u_int8_t pfra_fback
;
1185 #define pfra_ip4addr pfra_u._pfra_ip4addr
1186 #define pfra_ip6addr pfra_u._pfra_ip6addr
1188 enum { PFR_DIR_IN
, PFR_DIR_OUT
, PFR_DIR_MAX
};
1189 enum { PFR_OP_BLOCK
, PFR_OP_PASS
, PFR_OP_ADDR_MAX
, PFR_OP_TABLE_MAX
};
1190 #define PFR_OP_XPASS PFR_OP_ADDR_MAX
1193 struct pfr_addr pfras_a
;
1194 u_int64_t pfras_packets
[PFR_DIR_MAX
][PFR_OP_ADDR_MAX
];
1195 u_int64_t pfras_bytes
[PFR_DIR_MAX
][PFR_OP_ADDR_MAX
];
1196 u_int64_t pfras_tzero
;
1199 enum { PFR_REFCNT_RULE
, PFR_REFCNT_ANCHOR
, PFR_REFCNT_MAX
};
1202 struct pfr_table pfrts_t
;
1203 u_int64_t pfrts_packets
[PFR_DIR_MAX
][PFR_OP_TABLE_MAX
];
1204 u_int64_t pfrts_bytes
[PFR_DIR_MAX
][PFR_OP_TABLE_MAX
];
1205 u_int64_t pfrts_match
;
1206 u_int64_t pfrts_nomatch
;
1207 u_int64_t pfrts_tzero
;
1209 int pfrts_refcnt
[PFR_REFCNT_MAX
];
1211 #define pfrts_name pfrts_t.pfrt_name
1212 #define pfrts_flags pfrts_t.pfrt_flags
1214 SLIST_HEAD(pfr_kentryworkq
, pfr_kentry
);
1216 struct radix_node pfrke_node
[2];
1217 union sockaddr_union pfrke_sa
;
1218 u_int64_t pfrke_packets
[PFR_DIR_MAX
][PFR_OP_ADDR_MAX
];
1219 u_int64_t pfrke_bytes
[PFR_DIR_MAX
][PFR_OP_ADDR_MAX
];
1220 SLIST_ENTRY(pfr_kentry
) pfrke_workq
;
1221 u_int64_t pfrke_tzero
;
1225 u_int8_t pfrke_mark
;
1226 u_int8_t pfrke_intrpool
;
1229 SLIST_HEAD(pfr_ktableworkq
, pfr_ktable
);
1230 RB_HEAD(pfr_ktablehead
, pfr_ktable
);
1232 struct pfr_tstats pfrkt_ts
;
1233 RB_ENTRY(pfr_ktable
) pfrkt_tree
;
1234 SLIST_ENTRY(pfr_ktable
) pfrkt_workq
;
1235 struct radix_node_head
*pfrkt_ip4
;
1236 struct radix_node_head
*pfrkt_ip6
;
1237 struct pfr_ktable
*pfrkt_shadow
;
1238 struct pfr_ktable
*pfrkt_root
;
1239 struct pf_ruleset
*pfrkt_rs
;
1240 u_int64_t pfrkt_larg
;
1241 u_int32_t pfrkt_nflags
;
1243 #define pfrkt_t pfrkt_ts.pfrts_t
1244 #define pfrkt_name pfrkt_t.pfrt_name
1245 #define pfrkt_anchor pfrkt_t.pfrt_anchor
1246 #define pfrkt_ruleset pfrkt_t.pfrt_ruleset
1247 #define pfrkt_flags pfrkt_t.pfrt_flags
1248 #define pfrkt_cnt pfrkt_ts.pfrts_cnt
1249 #define pfrkt_refcnt pfrkt_ts.pfrts_refcnt
1250 #define pfrkt_packets pfrkt_ts.pfrts_packets
1251 #define pfrkt_bytes pfrkt_ts.pfrts_bytes
1252 #define pfrkt_match pfrkt_ts.pfrts_match
1253 #define pfrkt_nomatch pfrkt_ts.pfrts_nomatch
1254 #define pfrkt_tzero pfrkt_ts.pfrts_tzero
1256 RB_HEAD(pf_state_tree_lan_ext
, pf_state_key
);
1258 RB_PROTOTYPE_SC(__private_extern__
, pf_state_tree_lan_ext
, pf_state_key
,
1259 entry_lan_ext
, pf_state_compare_lan_ext
);
1261 RB_PROTOTYPE(pf_state_tree_lan_ext
, pf_state_key
, entry_lan_ext
,
1262 pf_state_compare_lan_ext
);
1263 #endif /* !KERNEL */
1265 RB_HEAD(pf_state_tree_ext_gwy
, pf_state_key
);
1267 RB_PROTOTYPE_SC(__private_extern__
, pf_state_tree_ext_gwy
, pf_state_key
,
1268 entry_ext_gwy
, pf_state_compare_ext_gwy
);
1270 RB_PROTOTYPE(pf_state_tree_ext_gwy
, pf_state_key
, entry_ext_gwy
,
1271 pf_state_compare_ext_gwy
);
1272 #endif /* !KERNEL */
1274 RB_HEAD(pfi_ifhead
, pfi_kif
);
1278 __private_extern__
struct pf_state_tree_lan_ext pf_statetbl_lan_ext
;
1279 __private_extern__
struct pf_state_tree_ext_gwy pf_statetbl_ext_gwy
;
1281 extern struct pf_state_tree_lan_ext pf_statetbl_lan_ext
;
1282 extern struct pf_state_tree_ext_gwy pf_statetbl_ext_gwy
;
1283 #endif /* !KERNEL */
1285 /* keep synced with pfi_kif, used in RB_FIND */
1286 struct pfi_kif_cmp
{
1287 char pfik_name
[IFNAMSIZ
];
1291 char pfik_name
[IFNAMSIZ
];
1292 RB_ENTRY(pfi_kif
) pfik_tree
;
1293 u_int64_t pfik_packets
[2][2][2];
1294 u_int64_t pfik_bytes
[2][2][2];
1295 u_int64_t pfik_tzero
;
1297 void *pfik_ah_cookie
;
1298 struct ifnet
*pfik_ifp
;
1301 TAILQ_HEAD(, pfi_dynaddr
) pfik_dynaddrs
;
1310 #define PFI_IFLAG_SKIP 0x0100 /* skip filtering on interface */
1320 u_int64_t tot_len
; /* Make Mickey money */
1326 struct icmp6_hdr
*icmp6
;
1328 #ifndef NO_APPLE_EXTENSIONS
1329 struct pf_grev1_hdr
*grev1
;
1330 struct pf_esp_hdr
*esp
;
1334 struct pf_addr baddr
; /* address before translation */
1335 struct pf_addr naddr
; /* address after translation */
1336 struct pf_rule
*nat_rule
; /* nat/rdr rule applied to packet */
1337 struct pf_addr
*src
;
1338 struct pf_addr
*dst
;
1341 #ifndef NO_APPLE_EXTENSIONS
1343 int lmw
; /* lazy writable offset */
1345 struct pf_mtag
*pf_mtag
;
1347 u_int32_t p_len
; /* total length of payload */
1348 u_int16_t flags
; /* Let SCRUB trigger behavior in */
1349 /* state code. Easier than tags */
1350 #define PFDESC_TCP_NORM 0x0001 /* TCP shall be statefully scrubbed */
1351 #define PFDESC_IP_REAS 0x0002 /* IP frags would've been reassembled */
1355 #ifndef NO_APPLE_EXTENSIONS
1356 u_int8_t proto_variant
;
1361 /* flags for RDR options */
1362 #define PF_DPORT_RANGE 0x01 /* Dest port uses range */
1363 #define PF_RPORT_RANGE 0x02 /* RDR'ed port uses range */
1365 /* Reasons code for passing/dropping a packet */
1366 #define PFRES_MATCH 0 /* Explicit match of a rule */
1367 #define PFRES_BADOFF 1 /* Bad offset for pull_hdr */
1368 #define PFRES_FRAG 2 /* Dropping following fragment */
1369 #define PFRES_SHORT 3 /* Dropping short packet */
1370 #define PFRES_NORM 4 /* Dropping by normalizer */
1371 #define PFRES_MEMORY 5 /* Dropped due to lacking mem */
1372 #define PFRES_TS 6 /* Bad TCP Timestamp (RFC1323) */
1373 #define PFRES_CONGEST 7 /* Congestion (of ipintrq) */
1374 #define PFRES_IPOPTIONS 8 /* IP option */
1375 #define PFRES_PROTCKSUM 9 /* Protocol checksum invalid */
1376 #define PFRES_BADSTATE 10 /* State mismatch */
1377 #define PFRES_STATEINS 11 /* State insertion failure */
1378 #define PFRES_MAXSTATES 12 /* State limit */
1379 #define PFRES_SRCLIMIT 13 /* Source node/conn limit */
1380 #define PFRES_SYNPROXY 14 /* SYN proxy */
1381 #define PFRES_MAX 15 /* total+1 */
1383 #define PFRES_NAMES { \
1402 /* Counters for other things we want to keep track of */
1403 #define LCNT_STATES 0 /* states */
1404 #define LCNT_SRCSTATES 1 /* max-src-states */
1405 #define LCNT_SRCNODES 2 /* max-src-nodes */
1406 #define LCNT_SRCCONN 3 /* max-src-conn */
1407 #define LCNT_SRCCONNRATE 4 /* max-src-conn-rate */
1408 #define LCNT_OVERLOAD_TABLE 5 /* entry added to overload table */
1409 #define LCNT_OVERLOAD_FLUSH 6 /* state entries flushed */
1410 #define LCNT_MAX 7 /* total+1 */
1412 #define LCNT_NAMES { \
1413 "max states per rule", \
1417 "max-src-conn-rate", \
1418 "overload table insertion", \
1419 "overload flush states", \
1423 /* UDP state enumeration */
1424 #define PFUDPS_NO_TRAFFIC 0
1425 #define PFUDPS_SINGLE 1
1426 #define PFUDPS_MULTIPLE 2
1428 #define PFUDPS_NSTATES 3 /* number of state levels */
1430 #define PFUDPS_NAMES { \
1437 #ifndef NO_APPLE_EXTENSIONS
1438 /* GREv1 protocol state enumeration */
1439 #define PFGRE1S_NO_TRAFFIC 0
1440 #define PFGRE1S_INITIATING 1
1441 #define PFGRE1S_ESTABLISHED 2
1443 #define PFGRE1S_NSTATES 3 /* number of state levels */
1445 #define PFGRE1S_NAMES { \
1452 #define PFESPS_NO_TRAFFIC 0
1453 #define PFESPS_INITIATING 1
1454 #define PFESPS_ESTABLISHED 2
1456 #define PFESPS_NSTATES 3 /* number of state levels */
1458 #define PFESPS_NAMES { "NO_TRAFFIC", "INITIATING", "ESTABLISHED", NULL }
1461 /* Other protocol state enumeration */
1462 #define PFOTHERS_NO_TRAFFIC 0
1463 #define PFOTHERS_SINGLE 1
1464 #define PFOTHERS_MULTIPLE 2
1466 #define PFOTHERS_NSTATES 3 /* number of state levels */
1468 #define PFOTHERS_NAMES { \
1475 #define FCNT_STATE_SEARCH 0
1476 #define FCNT_STATE_INSERT 1
1477 #define FCNT_STATE_REMOVALS 2
1480 #define SCNT_SRC_NODE_SEARCH 0
1481 #define SCNT_SRC_NODE_INSERT 1
1482 #define SCNT_SRC_NODE_REMOVALS 2
1485 #define ACTION_SET(a, x) \
1491 #define REASON_SET(a, x) \
1495 if (x < PFRES_MAX) \
1496 pf_status.counters[x]++; \
1500 u_int64_t counters
[PFRES_MAX
];
1501 u_int64_t lcounters
[LCNT_MAX
]; /* limit counters */
1502 u_int64_t fcounters
[FCNT_MAX
];
1503 u_int64_t scounters
[SCNT_MAX
];
1504 u_int64_t pcounters
[2][2][3];
1505 u_int64_t bcounters
[2][2];
1509 u_int32_t src_nodes
;
1510 u_int64_t since
__attribute__((aligned(8)));
1513 char ifname
[IFNAMSIZ
];
1514 u_int8_t pf_chksum
[PF_MD5_DIGEST_LENGTH
];
1534 /* real-time service curve */
1535 u_int rtsc_m1
; /* slope of the 1st segment in bps */
1536 u_int rtsc_d
; /* the x-projection of m1 in msec */
1537 u_int rtsc_m2
; /* slope of the 2nd segment in bps */
1538 /* link-sharing service curve */
1542 /* upper-limit service curve */
1550 char ifname
[IFNAMSIZ
];
1552 void *altq_disc
; /* discipline-specific state */
1553 #if !defined(__LP64__)
1555 #endif /* !__LP64__ */
1556 TAILQ_ENTRY(pf_altq
) entries
;
1557 #if !defined(__LP64__)
1559 #endif /* !__LP64__ */
1561 /* scheduler spec */
1562 u_int8_t scheduler
; /* scheduler type */
1563 u_int16_t tbrsize
; /* tokenbucket regulator size */
1564 u_int32_t ifbandwidth
; /* interface bandwidth */
1567 char qname
[PF_QNAME_SIZE
]; /* queue name */
1568 char parent
[PF_QNAME_SIZE
]; /* parent name */
1569 u_int32_t parent_qid
; /* parent queue id */
1570 u_int32_t bandwidth
; /* queue bandwidth */
1571 u_int8_t priority
; /* priority */
1572 u_int16_t qlimit
; /* queue size limit */
1573 u_int16_t flags
; /* misc flags */
1575 struct cbq_opts cbq_opts
;
1576 struct priq_opts priq_opts
;
1577 struct hfsc_opts hfsc_opts
;
1580 u_int32_t qid
; /* return value */
1584 TAILQ_ENTRY(pf_tagname
) entries
;
1585 char name
[PF_TAG_NAME_SIZE
];
1590 #define PFFRAG_FRENT_HIWAT 5000 /* Number of fragment entries */
1591 #define PFFRAG_FRAG_HIWAT 1000 /* Number of fragmented packets */
1592 #define PFFRAG_FRCENT_HIWAT 50000 /* Number of fragment cache entries */
1593 #define PFFRAG_FRCACHE_HIWAT 10000 /* Number of fragment descriptors */
1595 #define PFR_KTABLE_HIWAT 1000 /* Number of tables */
1596 #define PFR_KENTRY_HIWAT 200000 /* Number of table entries */
1597 #define PFR_KENTRY_HIWAT_SMALL 100000 /* Number of table entries (tiny hosts) */
1600 * ioctl parameter structures
1603 struct pfioc_pooladdr
{
1611 char anchor
[MAXPATHLEN
];
1612 struct pf_pooladdr addr
;
1618 u_int32_t pool_ticket
;
1620 char anchor
[MAXPATHLEN
];
1621 char anchor_call
[MAXPATHLEN
];
1622 struct pf_rule rule
;
1625 struct pfioc_natlook
{
1626 struct pf_addr saddr
;
1627 struct pf_addr daddr
;
1628 struct pf_addr rsaddr
;
1629 struct pf_addr rdaddr
;
1630 #ifndef NO_APPLE_EXTENSIONS
1631 union pf_state_xport sxport
;
1632 union pf_state_xport dxport
;
1633 union pf_state_xport rsxport
;
1634 union pf_state_xport rdxport
;
1637 u_int8_t proto_variant
;
1650 struct pfioc_state
{
1651 struct pfsync_state state
;
1654 struct pfioc_src_node_kill
{
1655 /* XXX returns the number of src nodes killed in psnk_af */
1656 sa_family_t psnk_af
;
1657 struct pf_rule_addr psnk_src
;
1658 struct pf_rule_addr psnk_dst
;
1661 #ifndef NO_APPLE_EXTENSIONS
1662 struct pfioc_state_addr_kill
{
1663 struct pf_addr_wrap addr
;
1664 u_int8_t reserved_
[3];
1666 union pf_rule_xport xport
;
1670 struct pfioc_state_kill
{
1671 /* XXX returns the number of states killed in psk_af */
1673 #ifndef NO_APPLE_EXTENSIONS
1675 u_int8_t psk_proto_variant
;
1677 struct pfioc_state_addr_kill psk_src
;
1678 struct pfioc_state_addr_kill psk_dst
;
1681 struct pf_rule_addr psk_src
;
1682 struct pf_rule_addr psk_dst
;
1684 char psk_ifname
[IFNAMSIZ
];
1687 struct pfioc_states
{
1691 struct pfsync_state
*psu_states
;
1692 } ps_u
__attribute__((aligned(8)));
1693 #define ps_buf ps_u.psu_buf
1694 #define ps_states ps_u.psu_states
1697 struct pfioc_src_nodes
{
1701 struct pf_src_node
*psu_src_nodes
;
1702 } psn_u
__attribute__((aligned(8)));
1703 #define psn_buf psn_u.psu_buf
1704 #define psn_src_nodes psn_u.psu_src_nodes
1708 char ifname
[IFNAMSIZ
];
1716 struct pfioc_limit
{
1725 struct pf_altq altq
__attribute__((aligned(8)));
1728 struct pfioc_qstats
{
1731 void *buf
__attribute__((aligned(8)));
1732 int nbytes
__attribute__((aligned(8)));
1736 struct pfioc_ruleset
{
1738 char path
[MAXPATHLEN
];
1739 char name
[PF_ANCHOR_NAME_SIZE
];
1742 #define PF_RULESET_ALTQ (PF_RULESET_MAX)
1743 #define PF_RULESET_TABLE (PF_RULESET_MAX+1)
1744 struct pfioc_trans
{
1745 int size
; /* number of elements */
1746 int esize
; /* size of each element in bytes */
1747 struct pfioc_trans_e
{
1749 char anchor
[MAXPATHLEN
];
1751 } *array
__attribute__((aligned(8)));
1754 #define PFR_FLAG_ATOMIC 0x00000001
1755 #define PFR_FLAG_DUMMY 0x00000002
1756 #define PFR_FLAG_FEEDBACK 0x00000004
1757 #define PFR_FLAG_CLSTATS 0x00000008
1758 #define PFR_FLAG_ADDRSTOO 0x00000010
1759 #define PFR_FLAG_REPLACE 0x00000020
1760 #define PFR_FLAG_ALLRSETS 0x00000040
1761 #define PFR_FLAG_ALLMASK 0x0000007F
1763 #define PFR_FLAG_USERIOCTL 0x10000000
1766 struct pfioc_table
{
1767 struct pfr_table pfrio_table
;
1768 void *pfrio_buffer
__attribute__((aligned(8)));
1769 int pfrio_esize
__attribute__((aligned(8)));
1776 u_int32_t pfrio_ticket
;
1778 #define pfrio_exists pfrio_nadd
1779 #define pfrio_nzero pfrio_nadd
1780 #define pfrio_nmatch pfrio_nadd
1781 #define pfrio_naddr pfrio_size2
1782 #define pfrio_setflag pfrio_size2
1783 #define pfrio_clrflag pfrio_nadd
1785 struct pfioc_iface
{
1786 char pfiio_name
[IFNAMSIZ
];
1787 void *pfiio_buffer
__attribute__((aligned(8)));
1788 int pfiio_esize
__attribute__((aligned(8)));
1799 #define DIOCSTART _IO ('D', 1)
1800 #define DIOCSTOP _IO ('D', 2)
1801 #define DIOCADDRULE _IOWR('D', 4, struct pfioc_rule)
1802 #define DIOCGETRULES _IOWR('D', 6, struct pfioc_rule)
1803 #define DIOCGETRULE _IOWR('D', 7, struct pfioc_rule)
1804 /* XXX cut 8 - 17 */
1805 #define DIOCCLRSTATES _IOWR('D', 18, struct pfioc_state_kill)
1806 #define DIOCGETSTATE _IOWR('D', 19, struct pfioc_state)
1807 #define DIOCSETSTATUSIF _IOWR('D', 20, struct pfioc_if)
1808 #define DIOCGETSTATUS _IOWR('D', 21, struct pf_status)
1809 #define DIOCCLRSTATUS _IO ('D', 22)
1810 #define DIOCNATLOOK _IOWR('D', 23, struct pfioc_natlook)
1811 #define DIOCSETDEBUG _IOWR('D', 24, u_int32_t)
1812 #define DIOCGETSTATES _IOWR('D', 25, struct pfioc_states)
1813 #define DIOCCHANGERULE _IOWR('D', 26, struct pfioc_rule)
1814 /* XXX cut 26 - 28 */
1815 #define DIOCSETTIMEOUT _IOWR('D', 29, struct pfioc_tm)
1816 #define DIOCGETTIMEOUT _IOWR('D', 30, struct pfioc_tm)
1817 #define DIOCADDSTATE _IOWR('D', 37, struct pfioc_state)
1818 #define DIOCCLRRULECTRS _IO ('D', 38)
1819 #define DIOCGETLIMIT _IOWR('D', 39, struct pfioc_limit)
1820 #define DIOCSETLIMIT _IOWR('D', 40, struct pfioc_limit)
1821 #define DIOCKILLSTATES _IOWR('D', 41, struct pfioc_state_kill)
1822 #define DIOCSTARTALTQ _IO ('D', 42)
1823 #define DIOCSTOPALTQ _IO ('D', 43)
1824 #define DIOCADDALTQ _IOWR('D', 45, struct pfioc_altq)
1825 #define DIOCGETALTQS _IOWR('D', 47, struct pfioc_altq)
1826 #define DIOCGETALTQ _IOWR('D', 48, struct pfioc_altq)
1827 #define DIOCCHANGEALTQ _IOWR('D', 49, struct pfioc_altq)
1828 #define DIOCGETQSTATS _IOWR('D', 50, struct pfioc_qstats)
1829 #define DIOCBEGINADDRS _IOWR('D', 51, struct pfioc_pooladdr)
1830 #define DIOCADDADDR _IOWR('D', 52, struct pfioc_pooladdr)
1831 #define DIOCGETADDRS _IOWR('D', 53, struct pfioc_pooladdr)
1832 #define DIOCGETADDR _IOWR('D', 54, struct pfioc_pooladdr)
1833 #define DIOCCHANGEADDR _IOWR('D', 55, struct pfioc_pooladdr)
1834 /* XXX cut 55 - 57 */
1835 #define DIOCGETRULESETS _IOWR('D', 58, struct pfioc_ruleset)
1836 #define DIOCGETRULESET _IOWR('D', 59, struct pfioc_ruleset)
1837 #define DIOCRCLRTABLES _IOWR('D', 60, struct pfioc_table)
1838 #define DIOCRADDTABLES _IOWR('D', 61, struct pfioc_table)
1839 #define DIOCRDELTABLES _IOWR('D', 62, struct pfioc_table)
1840 #define DIOCRGETTABLES _IOWR('D', 63, struct pfioc_table)
1841 #define DIOCRGETTSTATS _IOWR('D', 64, struct pfioc_table)
1842 #define DIOCRCLRTSTATS _IOWR('D', 65, struct pfioc_table)
1843 #define DIOCRCLRADDRS _IOWR('D', 66, struct pfioc_table)
1844 #define DIOCRADDADDRS _IOWR('D', 67, struct pfioc_table)
1845 #define DIOCRDELADDRS _IOWR('D', 68, struct pfioc_table)
1846 #define DIOCRSETADDRS _IOWR('D', 69, struct pfioc_table)
1847 #define DIOCRGETADDRS _IOWR('D', 70, struct pfioc_table)
1848 #define DIOCRGETASTATS _IOWR('D', 71, struct pfioc_table)
1849 #define DIOCRCLRASTATS _IOWR('D', 72, struct pfioc_table)
1850 #define DIOCRTSTADDRS _IOWR('D', 73, struct pfioc_table)
1851 #define DIOCRSETTFLAGS _IOWR('D', 74, struct pfioc_table)
1852 #define DIOCRINADEFINE _IOWR('D', 77, struct pfioc_table)
1853 #define DIOCOSFPFLUSH _IO('D', 78)
1854 #define DIOCOSFPADD _IOWR('D', 79, struct pf_osfp_ioctl)
1855 #define DIOCOSFPGET _IOWR('D', 80, struct pf_osfp_ioctl)
1856 #define DIOCXBEGIN _IOWR('D', 81, struct pfioc_trans)
1857 #define DIOCXCOMMIT _IOWR('D', 82, struct pfioc_trans)
1858 #define DIOCXROLLBACK _IOWR('D', 83, struct pfioc_trans)
1859 #define DIOCGETSRCNODES _IOWR('D', 84, struct pfioc_src_nodes)
1860 #define DIOCCLRSRCNODES _IO('D', 85)
1861 #define DIOCSETHOSTID _IOWR('D', 86, u_int32_t)
1862 #define DIOCIGETIFACES _IOWR('D', 87, struct pfioc_iface)
1863 #define DIOCSETIFFLAG _IOWR('D', 89, struct pfioc_iface)
1864 #define DIOCCLRIFFLAG _IOWR('D', 90, struct pfioc_iface)
1865 #define DIOCKILLSRCNODES _IOWR('D', 91, struct pfioc_src_node_kill)
1868 RB_HEAD(pf_src_tree
, pf_src_node
);
1869 RB_PROTOTYPE_SC(__private_extern__
, pf_src_tree
, pf_src_node
, entry
,
1871 __private_extern__
struct pf_src_tree tree_src_tracking
;
1873 RB_HEAD(pf_state_tree_id
, pf_state
);
1874 RB_PROTOTYPE_SC(__private_extern__
, pf_state_tree_id
, pf_state
,
1875 entry_id
, pf_state_compare_id
);
1876 __private_extern__
struct pf_state_tree_id tree_id
;
1877 __private_extern__
struct pf_state_queue state_list
;
1879 TAILQ_HEAD(pf_poolqueue
, pf_pool
);
1880 __private_extern__
struct pf_poolqueue pf_pools
[2];
1881 __private_extern__
struct pf_palist pf_pabuf
;
1882 __private_extern__ u_int32_t ticket_pabuf
;
1884 TAILQ_HEAD(pf_altqqueue
, pf_altq
);
1885 __private_extern__
struct pf_altqqueue pf_altqs
[2];
1886 __private_extern__ u_int32_t ticket_altqs_active
;
1887 __private_extern__ u_int32_t ticket_altqs_inactive
;
1888 __private_extern__
int altqs_inactive_open
;
1889 __private_extern__
struct pf_altqqueue
*pf_altqs_active
;
1890 __private_extern__
struct pf_altqqueue
*pf_altqs_inactive
;
1892 __private_extern__
struct pf_poolqueue
*pf_pools_active
;
1893 __private_extern__
struct pf_poolqueue
*pf_pools_inactive
;
1895 __private_extern__
int pf_tbladdr_setup(struct pf_ruleset
*,
1896 struct pf_addr_wrap
*);
1897 __private_extern__
void pf_tbladdr_remove(struct pf_addr_wrap
*);
1898 __private_extern__
void pf_tbladdr_copyout(struct pf_addr_wrap
*);
1899 __private_extern__
void pf_calc_skip_steps(struct pf_rulequeue
*);
1901 __private_extern__
struct pool pf_src_tree_pl
, pf_rule_pl
;
1902 __private_extern__
struct pool pf_state_pl
, pf_state_key_pl
, pf_pooladdr_pl
;
1903 __private_extern__
struct pool pf_state_scrub_pl
;
1905 __private_extern__
struct pool pf_altq_pl
;
1907 #ifndef NO_APPLE_EXTENSIONS
1908 __private_extern__
struct pool pf_app_state_pl
;
1911 __private_extern__
struct thread
*pf_purge_thread
;
1913 __private_extern__
void pfinit(void);
1914 __private_extern__
void pf_purge_thread_fn(void *, wait_result_t
);
1915 __private_extern__
void pf_purge_expired_src_nodes(void);
1916 __private_extern__
void pf_purge_expired_states(u_int32_t
);
1917 __private_extern__
void pf_unlink_state(struct pf_state
*);
1918 __private_extern__
void pf_free_state(struct pf_state
*);
1919 __private_extern__
int pf_insert_state(struct pfi_kif
*, struct pf_state
*);
1920 __private_extern__
int pf_insert_src_node(struct pf_src_node
**,
1921 struct pf_rule
*, struct pf_addr
*, sa_family_t
);
1922 __private_extern__
void pf_src_tree_remove_state(struct pf_state
*);
1923 __private_extern__
struct pf_state
*pf_find_state_byid(struct pf_state_cmp
*);
1924 __private_extern__
struct pf_state
*pf_find_state_all(struct pf_state_key_cmp
*,
1926 __private_extern__
void pf_print_state(struct pf_state
*);
1927 __private_extern__
void pf_print_flags(u_int8_t
);
1928 __private_extern__ u_int16_t
pf_cksum_fixup(u_int16_t
, u_int16_t
, u_int16_t
,
1931 __private_extern__
struct ifnet
*sync_ifp
;
1932 __private_extern__
struct pf_rule pf_default_rule
;
1933 __private_extern__
void pf_addrcpy(struct pf_addr
*, struct pf_addr
*,
1935 __private_extern__
void pf_rm_rule(struct pf_rulequeue
*, struct pf_rule
*);
1938 __private_extern__
int pf_test(int, struct ifnet
*, struct mbuf
**,
1939 struct ether_header
*);
1943 __private_extern__
int pf_test6(int, struct ifnet
*, struct mbuf
**,
1944 struct ether_header
*);
1945 __private_extern__
void pf_poolmask(struct pf_addr
*, struct pf_addr
*,
1946 struct pf_addr
*, struct pf_addr
*, u_int8_t
);
1947 __private_extern__
void pf_addr_inc(struct pf_addr
*, sa_family_t
);
1950 #ifndef NO_APPLE_EXTENSIONS
1951 __private_extern__
struct mbuf
*pf_lazy_makewritable(struct pf_pdesc
*,
1952 struct mbuf
*, int);
1954 __private_extern__
void *pf_pull_hdr(struct mbuf
*, int, void *, int,
1955 u_short
*, u_short
*, sa_family_t
);
1956 __private_extern__
void pf_change_a(void *, u_int16_t
*, u_int32_t
, u_int8_t
);
1957 __private_extern__
int pflog_packet(struct pfi_kif
*, struct mbuf
*,
1958 sa_family_t
, u_int8_t
, u_int8_t
, struct pf_rule
*, struct pf_rule
*,
1959 struct pf_ruleset
*, struct pf_pdesc
*);
1960 __private_extern__
int pf_match_addr(u_int8_t
, struct pf_addr
*,
1961 struct pf_addr
*, struct pf_addr
*, sa_family_t
);
1962 __private_extern__
int pf_match_addr_range(struct pf_addr
*, struct pf_addr
*,
1963 struct pf_addr
*, sa_family_t
);
1964 __private_extern__
int pf_match(u_int8_t
, u_int32_t
, u_int32_t
, u_int32_t
);
1965 __private_extern__
int pf_match_port(u_int8_t
, u_int16_t
, u_int16_t
, u_int16_t
);
1966 #ifndef NO_APPLE_EXTENSIONS
1967 __private_extern__
int pf_match_xport(u_int8_t
, u_int8_t
, union pf_rule_xport
*,
1968 union pf_state_xport
*);
1970 __private_extern__
int pf_match_uid(u_int8_t
, uid_t
, uid_t
, uid_t
);
1971 __private_extern__
int pf_match_gid(u_int8_t
, gid_t
, gid_t
, gid_t
);
1973 __private_extern__
void pf_normalize_init(void);
1974 __private_extern__
int pf_normalize_isempty(void);
1975 __private_extern__
int pf_normalize_ip(struct mbuf
**, int, struct pfi_kif
*,
1976 u_short
*, struct pf_pdesc
*);
1977 __private_extern__
int pf_normalize_ip6(struct mbuf
**, int, struct pfi_kif
*,
1978 u_short
*, struct pf_pdesc
*);
1979 __private_extern__
int pf_normalize_tcp(int, struct pfi_kif
*, struct mbuf
*,
1980 int, int, void *, struct pf_pdesc
*);
1981 __private_extern__
void pf_normalize_tcp_cleanup(struct pf_state
*);
1982 __private_extern__
int pf_normalize_tcp_init(struct mbuf
*, int,
1983 struct pf_pdesc
*, struct tcphdr
*, struct pf_state_peer
*,
1984 struct pf_state_peer
*);
1985 __private_extern__
int pf_normalize_tcp_stateful(struct mbuf
*, int,
1986 struct pf_pdesc
*, u_short
*, struct tcphdr
*, struct pf_state
*,
1987 struct pf_state_peer
*, struct pf_state_peer
*, int *);
1988 __private_extern__ u_int64_t
pf_state_expires(const struct pf_state
*);
1989 __private_extern__
void pf_purge_expired_fragments(void);
1990 __private_extern__
int pf_routable(struct pf_addr
*addr
, sa_family_t af
,
1992 __private_extern__
int pf_rtlabel_match(struct pf_addr
*, sa_family_t
,
1993 struct pf_addr_wrap
*);
1994 __private_extern__
int pf_socket_lookup(int, struct pf_pdesc
*);
1995 __private_extern__
struct pf_state_key
*pf_alloc_state_key(struct pf_state
*);
1996 __private_extern__
void pfr_initialize(void);
1997 __private_extern__
int pfr_match_addr(struct pfr_ktable
*, struct pf_addr
*,
1999 __private_extern__
void pfr_update_stats(struct pfr_ktable
*, struct pf_addr
*,
2000 sa_family_t
, u_int64_t
, int, int, int);
2001 __private_extern__
int pfr_pool_get(struct pfr_ktable
*, int *,
2002 struct pf_addr
*, struct pf_addr
**, struct pf_addr
**, sa_family_t
);
2003 __private_extern__
void pfr_dynaddr_update(struct pfr_ktable
*,
2004 struct pfi_dynaddr
*);
2005 __private_extern__
struct pfr_ktable
*pfr_attach_table(struct pf_ruleset
*,
2007 __private_extern__
void pfr_detach_table(struct pfr_ktable
*);
2008 __private_extern__
int pfr_clr_tables(struct pfr_table
*, int *, int);
2009 __private_extern__
int pfr_add_tables(struct pfr_table
*, int, int *, int);
2010 __private_extern__
int pfr_del_tables(struct pfr_table
*, int, int *, int);
2011 __private_extern__
int pfr_get_tables(struct pfr_table
*, struct pfr_table
*,
2013 __private_extern__
int pfr_get_tstats(struct pfr_table
*, struct pfr_tstats
*,
2015 __private_extern__
int pfr_clr_tstats(struct pfr_table
*, int, int *, int);
2016 __private_extern__
int pfr_set_tflags(struct pfr_table
*, int, int, int, int *,
2018 __private_extern__
int pfr_clr_addrs(struct pfr_table
*, int *, int);
2019 __private_extern__
int pfr_insert_kentry(struct pfr_ktable
*, struct pfr_addr
*,
2021 __private_extern__
int pfr_add_addrs(struct pfr_table
*, struct pfr_addr
*,
2023 __private_extern__
int pfr_del_addrs(struct pfr_table
*, struct pfr_addr
*,
2025 __private_extern__
int pfr_set_addrs(struct pfr_table
*, struct pfr_addr
*,
2026 int, int *, int *, int *, int *, int, u_int32_t
);
2027 __private_extern__
int pfr_get_addrs(struct pfr_table
*, struct pfr_addr
*,
2029 __private_extern__
int pfr_get_astats(struct pfr_table
*, struct pfr_astats
*,
2031 __private_extern__
int pfr_clr_astats(struct pfr_table
*, struct pfr_addr
*,
2033 __private_extern__
int pfr_tst_addrs(struct pfr_table
*, struct pfr_addr
*,
2035 __private_extern__
int pfr_ina_begin(struct pfr_table
*, u_int32_t
*, int *,
2037 __private_extern__
int pfr_ina_rollback(struct pfr_table
*, u_int32_t
, int *,
2039 __private_extern__
int pfr_ina_commit(struct pfr_table
*, u_int32_t
, int *,
2041 __private_extern__
int pfr_ina_define(struct pfr_table
*, struct pfr_addr
*,
2042 int, int *, int *, u_int32_t
, int);
2044 __private_extern__
struct pfi_kif
*pfi_all
;
2046 __private_extern__
void pfi_initialize(void);
2047 __private_extern__
struct pfi_kif
*pfi_kif_get(const char *);
2048 __private_extern__
void pfi_kif_ref(struct pfi_kif
*, enum pfi_kif_refs
);
2049 __private_extern__
void pfi_kif_unref(struct pfi_kif
*, enum pfi_kif_refs
);
2050 __private_extern__
int pfi_kif_match(struct pfi_kif
*, struct pfi_kif
*);
2051 __private_extern__
void pfi_attach_ifnet(struct ifnet
*);
2052 __private_extern__
void pfi_detach_ifnet(struct ifnet
*);
2053 __private_extern__
int pfi_match_addr(struct pfi_dynaddr
*, struct pf_addr
*,
2055 __private_extern__
int pfi_dynaddr_setup(struct pf_addr_wrap
*, sa_family_t
);
2056 __private_extern__
void pfi_dynaddr_remove(struct pf_addr_wrap
*);
2057 __private_extern__
void pfi_dynaddr_copyout(struct pf_addr_wrap
*);
2058 __private_extern__
void pfi_update_status(const char *, struct pf_status
*);
2059 __private_extern__
int pfi_get_ifaces(const char *, struct pfi_kif
*, int *);
2060 __private_extern__
int pfi_set_flags(const char *, int);
2061 __private_extern__
int pfi_clear_flags(const char *, int);
2063 __private_extern__ u_int16_t
pf_tagname2tag(char *);
2064 __private_extern__
void pf_tag2tagname(u_int16_t
, char *);
2065 __private_extern__
void pf_tag_ref(u_int16_t
);
2066 __private_extern__
void pf_tag_unref(u_int16_t
);
2067 __private_extern__
int pf_tag_packet(struct mbuf
*, struct pf_mtag
*,
2069 __private_extern__ u_int32_t
pf_qname2qid(char *);
2070 __private_extern__
void pf_qid2qname(u_int32_t
, char *);
2071 __private_extern__
void pf_qid_unref(u_int32_t
);
2073 __private_extern__
struct pf_status pf_status
;
2074 __private_extern__
struct pool pf_frent_pl
, pf_frag_pl
;
2076 struct pf_pool_limit
{
2080 __private_extern__
struct pf_pool_limit pf_pool_limits
[PF_LIMIT_MAX
];
2082 __private_extern__
int pf_af_hook(struct ifnet
*, struct mbuf
**,
2083 struct mbuf
**, unsigned int, int);
2084 __private_extern__
int pf_ifaddr_hook(struct ifnet
*, unsigned long);
2085 __private_extern__
void pf_ifnet_hook(struct ifnet
*, int);
2088 * The following are defined with "private extern" storage class for
2089 * kernel, and "extern" for user-space.
2091 __private_extern__
struct pf_anchor_global pf_anchors
;
2092 __private_extern__
struct pf_anchor pf_main_anchor
;
2093 #define pf_main_ruleset pf_main_anchor.ruleset
2095 /* these ruleset functions can be linked into userland programs (pfctl) */
2096 __private_extern__
int pf_get_ruleset_number(u_int8_t
);
2097 __private_extern__
void pf_init_ruleset(struct pf_ruleset
*);
2098 __private_extern__
int pf_anchor_setup(struct pf_rule
*,
2099 const struct pf_ruleset
*, const char *);
2100 __private_extern__
int pf_anchor_copyout(const struct pf_ruleset
*,
2101 const struct pf_rule
*, struct pfioc_rule
*);
2102 __private_extern__
void pf_anchor_remove(struct pf_rule
*);
2103 __private_extern__
void pf_remove_if_empty_ruleset(struct pf_ruleset
*);
2104 __private_extern__
struct pf_anchor
*pf_find_anchor(const char *);
2105 __private_extern__
struct pf_ruleset
*pf_find_ruleset(const char *);
2106 __private_extern__
struct pf_ruleset
*pf_find_or_create_ruleset(const char *);
2107 __private_extern__
void pf_rs_initialize(void);
2109 __private_extern__
int pf_osfp_add(struct pf_osfp_ioctl
*);
2110 __private_extern__
struct pf_osfp_enlist
*pf_osfp_fingerprint(struct pf_pdesc
*,
2111 struct mbuf
*, int, const struct tcphdr
*);
2112 __private_extern__
struct pf_osfp_enlist
*pf_osfp_fingerprint_hdr(
2113 const struct ip
*, const struct ip6_hdr
*, const struct tcphdr
*);
2114 __private_extern__
void pf_osfp_flush(void);
2115 __private_extern__
int pf_osfp_get(struct pf_osfp_ioctl
*);
2116 __private_extern__
void pf_osfp_initialize(void);
2117 __private_extern__
int pf_osfp_match(struct pf_osfp_enlist
*, pf_osfp_t
);
2118 __private_extern__
struct pf_os_fingerprint
*pf_osfp_validate(void);
2120 extern struct pf_anchor_global pf_anchors
;
2121 extern struct pf_anchor pf_main_anchor
;
2122 #define pf_main_ruleset pf_main_anchor.ruleset
2124 /* these ruleset functions can be linked into userland programs (pfctl) */
2125 extern int pf_get_ruleset_number(u_int8_t
);
2126 extern void pf_init_ruleset(struct pf_ruleset
*);
2127 extern int pf_anchor_setup(struct pf_rule
*, const struct pf_ruleset
*,
2129 extern int pf_anchor_copyout(const struct pf_ruleset
*, const struct pf_rule
*,
2130 struct pfioc_rule
*);
2131 extern void pf_anchor_remove(struct pf_rule
*);
2132 extern void pf_remove_if_empty_ruleset(struct pf_ruleset
*);
2133 extern struct pf_anchor
*pf_find_anchor(const char *);
2134 extern struct pf_ruleset
*pf_find_ruleset(const char *);
2135 extern struct pf_ruleset
*pf_find_or_create_ruleset(const char *);
2136 extern void pf_rs_initialize(void);
2137 #endif /* !KERNEL */
2142 #endif /* PF || !KERNEL */
2143 #endif /* PRIVATE */
2144 #endif /* _NET_PFVAR_H_ */