1 /* $NetBSD: pfvar.h,v 1.16 2008/06/18 09:06:27 yamt Exp $ */
2 /* $OpenBSD: pfvar.h,v 1.254 2007/07/13 09:17:48 markus Exp $ */
5 * Copyright (c) 2001 Daniel Hartmeier
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
37 #include <sys/param.h>
38 #include <sys/types.h>
39 #include <sys/queue.h>
41 #include <sys/rwlock.h>
43 #include <net/radix.h>
45 #include <net/route.h>
46 #include <netinet/ip_ipsp.h>
48 /* files above include netinet/in.h so include it too for compatibility */
49 #include <netinet/in.h>
50 #endif /* __NetBSD__ */
51 #include <netinet/tcp_fsm.h>
53 #if defined(__NetBSD__) && defined(_KERNEL)
54 #include <net/if_compat.h>
55 #include <net/pf_mtag.h>
56 #endif /* __NetBSD__ && _KERNEL */
59 union sockaddr_union
{
61 struct sockaddr_in sin
;
62 struct sockaddr_in6 sin6
;
64 #endif /* __NetBSD__ */
69 #define PF_TCPS_PROXY_SRC ((TCP_NSTATES)+0)
70 #define PF_TCPS_PROXY_DST ((TCP_NSTATES)+1)
72 #define PF_MD5_DIGEST_LENGTH 16
73 #ifdef MD5_DIGEST_LENGTH
74 #if PF_MD5_DIGEST_LENGTH != MD5_DIGEST_LENGTH
79 enum { PF_INOUT
, PF_IN
, PF_OUT
};
80 enum { PF_LAN_EXT
, PF_EXT_GWY
, PF_ID
};
81 enum { PF_PASS
, PF_DROP
, PF_SCRUB
, PF_NOSCRUB
, PF_NAT
, PF_NONAT
,
82 PF_BINAT
, PF_NOBINAT
, PF_RDR
, PF_NORDR
, PF_SYNPROXY_DROP
};
83 enum { PF_RULESET_SCRUB
, PF_RULESET_FILTER
, PF_RULESET_NAT
,
84 PF_RULESET_BINAT
, PF_RULESET_RDR
, PF_RULESET_MAX
};
85 enum { PF_OP_NONE
, PF_OP_IRG
, PF_OP_EQ
, PF_OP_NE
, PF_OP_LT
,
86 PF_OP_LE
, PF_OP_GT
, PF_OP_GE
, PF_OP_XRG
, PF_OP_RRG
};
87 enum { PF_DEBUG_NONE
, PF_DEBUG_URGENT
, PF_DEBUG_MISC
, PF_DEBUG_NOISY
};
88 enum { PF_CHANGE_NONE
, PF_CHANGE_ADD_HEAD
, PF_CHANGE_ADD_TAIL
,
89 PF_CHANGE_ADD_BEFORE
, PF_CHANGE_ADD_AFTER
,
90 PF_CHANGE_REMOVE
, PF_CHANGE_GET_TICKET
};
91 enum { PF_GET_NONE
, PF_GET_CLR_CNTR
};
94 * Note about PFTM_*: real indices into pf_rule.timeout[] come before
95 * PFTM_MAX, special cases afterwards. See pf_state_expires().
97 enum { PFTM_TCP_FIRST_PACKET
, PFTM_TCP_OPENING
, PFTM_TCP_ESTABLISHED
,
98 PFTM_TCP_CLOSING
, PFTM_TCP_FIN_WAIT
, PFTM_TCP_CLOSED
,
99 PFTM_UDP_FIRST_PACKET
, PFTM_UDP_SINGLE
, PFTM_UDP_MULTIPLE
,
100 PFTM_ICMP_FIRST_PACKET
, PFTM_ICMP_ERROR_REPLY
,
101 PFTM_OTHER_FIRST_PACKET
, PFTM_OTHER_SINGLE
,
102 PFTM_OTHER_MULTIPLE
, PFTM_FRAG
, PFTM_INTERVAL
,
103 PFTM_ADAPTIVE_START
, PFTM_ADAPTIVE_END
, PFTM_SRC_NODE
,
104 PFTM_TS_DIFF
, PFTM_MAX
, PFTM_PURGE
, PFTM_UNLINKED
,
107 /* PFTM default values */
108 #define PFTM_TCP_FIRST_PACKET_VAL 120 /* First TCP packet */
109 #define PFTM_TCP_OPENING_VAL 30 /* No response yet */
110 #define PFTM_TCP_ESTABLISHED_VAL 24*60*60/* Established */
111 #define PFTM_TCP_CLOSING_VAL 15 * 60 /* Half closed */
112 #define PFTM_TCP_FIN_WAIT_VAL 45 /* Got both FINs */
113 #define PFTM_TCP_CLOSED_VAL 90 /* Got a RST */
114 #define PFTM_UDP_FIRST_PACKET_VAL 60 /* First UDP packet */
115 #define PFTM_UDP_SINGLE_VAL 30 /* Unidirectional */
116 #define PFTM_UDP_MULTIPLE_VAL 60 /* Bidirectional */
117 #define PFTM_ICMP_FIRST_PACKET_VAL 20 /* First ICMP packet */
118 #define PFTM_ICMP_ERROR_REPLY_VAL 10 /* Got error response */
119 #define PFTM_OTHER_FIRST_PACKET_VAL 60 /* First packet */
120 #define PFTM_OTHER_SINGLE_VAL 30 /* Unidirectional */
121 #define PFTM_OTHER_MULTIPLE_VAL 60 /* Bidirectional */
122 #define PFTM_FRAG_VAL 30 /* Fragment expire */
123 #define PFTM_INTERVAL_VAL 10 /* Expire interval */
124 #define PFTM_SRC_NODE_VAL 0 /* Source tracking */
125 #define PFTM_TS_DIFF_VAL 30 /* Allowed TS diff */
127 enum { PF_NOPFROUTE
, PF_FASTROUTE
, PF_ROUTETO
, PF_DUPTO
, PF_REPLYTO
};
128 enum { PF_LIMIT_STATES
, PF_LIMIT_SRC_NODES
, PF_LIMIT_FRAGS
,
129 PF_LIMIT_TABLES
, PF_LIMIT_TABLE_ENTRIES
, PF_LIMIT_MAX
};
130 #define PF_POOL_IDMASK 0x0f
131 enum { PF_POOL_NONE
, PF_POOL_BITMASK
, PF_POOL_RANDOM
,
132 PF_POOL_SRCHASH
, PF_POOL_ROUNDROBIN
};
133 enum { PF_ADDR_ADDRMASK
, PF_ADDR_NOROUTE
, PF_ADDR_DYNIFTL
,
134 PF_ADDR_TABLE
, PF_ADDR_RTLABEL
, PF_ADDR_URPFFAILED
};
135 #define PF_POOL_TYPEMASK 0x0f
136 #define PF_POOL_STICKYADDR 0x20
137 #define PF_WSCALE_FLAG 0x80
138 #define PF_WSCALE_MASK 0x0f
141 #define PF_LOG_ALL 0x02
142 #define PF_LOG_SOCKET_LOOKUP 0x04
151 } pfa
; /* 128-bit address */
154 #define addr8 pfa.addr8
155 #define addr16 pfa.addr16
156 #define addr32 pfa.addr32
159 #define PF_TABLE_NAME_SIZE 32
161 #define PFI_AFLAG_NETWORK 0x01
162 #define PFI_AFLAG_BROADCAST 0x02
163 #define PFI_AFLAG_PEER 0x04
164 #define PFI_AFLAG_MODEMASK 0x07
165 #define PFI_AFLAG_NOALIAS 0x08
168 #define RTLABEL_LEN 32
171 struct pf_addr_wrap
{
177 char ifname
[IFNAMSIZ
];
178 char tblname
[PF_TABLE_NAME_SIZE
];
179 char rtlabelname
[RTLABEL_LEN
];
183 struct pfi_dynaddr
*dyn
;
184 struct pfr_ktable
*tbl
;
188 u_int8_t type
; /* PF_ADDR_* */
189 u_int8_t iflags
; /* PFI_AFLAG_* */
195 TAILQ_ENTRY(pfi_dynaddr
) entry
;
196 struct pf_addr pfid_addr4
;
197 struct pf_addr pfid_mask4
;
198 struct pf_addr pfid_addr6
;
199 struct pf_addr pfid_mask6
;
200 struct pfr_ktable
*pfid_kt
;
201 struct pfi_kif
*pfid_kif
;
202 void *pfid_hook_cookie
;
203 int pfid_net
; /* mask or 128 */
204 int pfid_acnt4
; /* address count IPv4 */
205 int pfid_acnt6
; /* address count IPv6 */
206 sa_family_t pfid_af
; /* rule af */
207 u_int8_t pfid_iflags
; /* PFI_AFLAG_* */
211 * Address manipulation macros
222 #define PF_INET6_ONLY
228 #define PF_INET_INET6
234 #define PF_INET_INET6
238 /* Both IPv4 and IPv6 */
241 #define PF_AEQ(a, b, c) \
242 ((c == AF_INET && (a)->addr32[0] == (b)->addr32[0]) || \
243 ((a)->addr32[3] == (b)->addr32[3] && \
244 (a)->addr32[2] == (b)->addr32[2] && \
245 (a)->addr32[1] == (b)->addr32[1] && \
246 (a)->addr32[0] == (b)->addr32[0])) \
248 #define PF_ANEQ(a, b, c) \
249 ((c == AF_INET && (a)->addr32[0] != (b)->addr32[0]) || \
250 ((a)->addr32[3] != (b)->addr32[3] || \
251 (a)->addr32[2] != (b)->addr32[2] || \
252 (a)->addr32[1] != (b)->addr32[1] || \
253 (a)->addr32[0] != (b)->addr32[0])) \
255 #define PF_AZERO(a, c) \
256 ((c == AF_INET && !(a)->addr32[0]) || \
257 (!(a)->addr32[0] && !(a)->addr32[1] && \
258 !(a)->addr32[2] && !(a)->addr32[3] )) \
260 #define PF_MATCHA(n, a, m, b, f) \
261 pf_match_addr(n, a, m, b, f)
263 #define PF_ACPY(a, b, f) \
266 #define PF_AINC(a, f) \
269 #define PF_POOLMASK(a, b, c, d, f) \
270 pf_poolmask(a, b, c, d, f)
278 #define PF_AEQ(a, b, c) \
279 ((a)->addr32[3] == (b)->addr32[3] && \
280 (a)->addr32[2] == (b)->addr32[2] && \
281 (a)->addr32[1] == (b)->addr32[1] && \
282 (a)->addr32[0] == (b)->addr32[0]) \
284 #define PF_ANEQ(a, b, c) \
285 ((a)->addr32[3] != (b)->addr32[3] || \
286 (a)->addr32[2] != (b)->addr32[2] || \
287 (a)->addr32[1] != (b)->addr32[1] || \
288 (a)->addr32[0] != (b)->addr32[0]) \
290 #define PF_AZERO(a, c) \
291 (!(a)->addr32[0] && \
296 #define PF_MATCHA(n, a, m, b, f) \
297 pf_match_addr(n, a, m, b, f)
299 #define PF_ACPY(a, b, f) \
302 #define PF_AINC(a, f) \
305 #define PF_POOLMASK(a, b, c, d, f) \
306 pf_poolmask(a, b, c, d, f)
313 #define PF_AEQ(a, b, c) \
314 ((a)->addr32[0] == (b)->addr32[0])
316 #define PF_ANEQ(a, b, c) \
317 ((a)->addr32[0] != (b)->addr32[0])
319 #define PF_AZERO(a, c) \
322 #define PF_MATCHA(n, a, m, b, f) \
323 pf_match_addr(n, a, m, b, f)
325 #define PF_ACPY(a, b, f) \
326 (a)->v4.s_addr = (b)->v4.s_addr
328 #define PF_AINC(a, f) \
330 (a)->addr32[0] = htonl(ntohl((a)->addr32[0]) + 1); \
333 #define PF_POOLMASK(a, b, c, d, f) \
335 (a)->addr32[0] = ((b)->addr32[0] & (c)->addr32[0]) | \
336 (((c)->addr32[0] ^ 0xffffffff ) & (d)->addr32[0]); \
339 #endif /* PF_INET_ONLY */
340 #endif /* PF_INET6_ONLY */
341 #endif /* PF_INET_INET6 */
343 #define PF_MISMATCHAW(aw, x, af, neg, ifp) \
345 (((aw)->type == PF_ADDR_NOROUTE && \
346 pf_routable((x), (af), NULL)) || \
347 (((aw)->type == PF_ADDR_URPFFAILED && (ifp) != NULL && \
348 pf_routable((x), (af), (ifp))) || \
349 ((aw)->type == PF_ADDR_RTLABEL && \
350 !pf_rtlabel_match((x), (af), (aw))) || \
351 ((aw)->type == PF_ADDR_TABLE && \
352 !pfr_match_addr((aw)->p.tbl, (x), (af))) || \
353 ((aw)->type == PF_ADDR_DYNIFTL && \
354 !pfi_match_addr((aw)->p.dyn, (x), (af))) || \
355 ((aw)->type == PF_ADDR_ADDRMASK && \
356 !PF_AZERO(&(aw)->v.a.mask, (af)) && \
357 !PF_MATCHA(0, &(aw)->v.a.addr, \
358 &(aw)->v.a.mask, (x), (af))))) != \
373 struct pf_rule_addr
{
374 struct pf_addr_wrap addr
;
381 struct pf_addr_wrap addr
;
382 TAILQ_ENTRY(pf_pooladdr
) entries
;
383 char ifname
[IFNAMSIZ
];
387 TAILQ_HEAD(pf_palist
, pf_pooladdr
);
389 struct pf_poolhashkey
{
394 } pfk
; /* 128-bit hash key */
395 #define key8 pfk.key8
396 #define key16 pfk.key16
397 #define key32 pfk.key32
401 struct pf_palist list
;
402 struct pf_pooladdr
*cur
;
403 struct pf_poolhashkey key
;
404 struct pf_addr counter
;
406 u_int16_t proxy_port
[2];
412 /* A packed Operating System description for fingerprinting */
413 typedef u_int32_t pf_osfp_t
;
414 #define PF_OSFP_ANY ((pf_osfp_t)0)
415 #define PF_OSFP_UNKNOWN ((pf_osfp_t)-1)
416 #define PF_OSFP_NOMATCH ((pf_osfp_t)-2)
418 struct pf_osfp_entry
{
419 SLIST_ENTRY(pf_osfp_entry
) fp_entry
;
422 #define PF_OSFP_EXPANDED 0x001 /* expanded entry */
423 #define PF_OSFP_GENERIC 0x002 /* generic signature */
424 #define PF_OSFP_NODETAIL 0x004 /* no p0f details */
425 #define PF_OSFP_LEN 32
426 char fp_class_nm
[PF_OSFP_LEN
];
427 char fp_version_nm
[PF_OSFP_LEN
];
428 char fp_subtype_nm
[PF_OSFP_LEN
];
430 #define PF_OSFP_ENTRY_EQ(a, b) \
431 ((a)->fp_os == (b)->fp_os && \
432 memcmp((a)->fp_class_nm, (b)->fp_class_nm, PF_OSFP_LEN) == 0 && \
433 memcmp((a)->fp_version_nm, (b)->fp_version_nm, PF_OSFP_LEN) == 0 && \
434 memcmp((a)->fp_subtype_nm, (b)->fp_subtype_nm, PF_OSFP_LEN) == 0)
436 /* handle pf_osfp_t packing */
437 #define _FP_RESERVED_BIT 1 /* For the special negative #defines */
438 #define _FP_UNUSED_BITS 1
439 #define _FP_CLASS_BITS 10 /* OS Class (Windows, Linux) */
440 #define _FP_VERSION_BITS 10 /* OS version (95, 98, NT, 2.4.54, 3.2) */
441 #define _FP_SUBTYPE_BITS 10 /* patch level (NT SP4, SP3, ECN patch) */
442 #define PF_OSFP_UNPACK(osfp, class, version, subtype) do { \
443 (class) = ((osfp) >> (_FP_VERSION_BITS+_FP_SUBTYPE_BITS)) & \
444 ((1 << _FP_CLASS_BITS) - 1); \
445 (version) = ((osfp) >> _FP_SUBTYPE_BITS) & \
446 ((1 << _FP_VERSION_BITS) - 1);\
447 (subtype) = (osfp) & ((1 << _FP_SUBTYPE_BITS) - 1); \
449 #define PF_OSFP_PACK(osfp, class, version, subtype) do { \
450 (osfp) = ((class) & ((1 << _FP_CLASS_BITS) - 1)) << (_FP_VERSION_BITS \
451 + _FP_SUBTYPE_BITS); \
452 (osfp) |= ((version) & ((1 << _FP_VERSION_BITS) - 1)) << \
454 (osfp) |= (subtype) & ((1 << _FP_SUBTYPE_BITS) - 1); \
457 /* the fingerprint of an OSes TCP SYN packet */
458 typedef u_int64_t pf_tcpopts_t
;
459 struct pf_os_fingerprint
{
460 SLIST_HEAD(pf_osfp_enlist
, pf_osfp_entry
) fp_oses
; /* list of matches */
461 pf_tcpopts_t fp_tcpopts
; /* packed TCP options */
462 u_int16_t fp_wsize
; /* TCP window size */
463 u_int16_t fp_psize
; /* ip->ip_len */
464 u_int16_t fp_mss
; /* TCP MSS */
466 #define PF_OSFP_WSIZE_MOD 0x0001 /* Window modulus */
467 #define PF_OSFP_WSIZE_DC 0x0002 /* Window don't care */
468 #define PF_OSFP_WSIZE_MSS 0x0004 /* Window multiple of MSS */
469 #define PF_OSFP_WSIZE_MTU 0x0008 /* Window multiple of MTU */
470 #define PF_OSFP_PSIZE_MOD 0x0010 /* packet size modulus */
471 #define PF_OSFP_PSIZE_DC 0x0020 /* packet size don't care */
472 #define PF_OSFP_WSCALE 0x0040 /* TCP window scaling */
473 #define PF_OSFP_WSCALE_MOD 0x0080 /* TCP window scale modulus */
474 #define PF_OSFP_WSCALE_DC 0x0100 /* TCP window scale dont-care */
475 #define PF_OSFP_MSS 0x0200 /* TCP MSS */
476 #define PF_OSFP_MSS_MOD 0x0400 /* TCP MSS modulus */
477 #define PF_OSFP_MSS_DC 0x0800 /* TCP MSS dont-care */
478 #define PF_OSFP_DF 0x1000 /* IPv4 don't fragment bit */
479 #define PF_OSFP_TS0 0x2000 /* Zero timestamp */
480 #define PF_OSFP_INET6 0x4000 /* IPv6 */
481 u_int8_t fp_optcnt
; /* TCP option count */
482 u_int8_t fp_wscale
; /* TCP window scaling */
483 u_int8_t fp_ttl
; /* IPv4 TTL */
484 #define PF_OSFP_MAXTTL_OFFSET 40
485 /* TCP options packing */
486 #define PF_OSFP_TCPOPT_NOP 0x0 /* TCP NOP option */
487 #define PF_OSFP_TCPOPT_WSCALE 0x1 /* TCP window scaling option */
488 #define PF_OSFP_TCPOPT_MSS 0x2 /* TCP max segment size opt */
489 #define PF_OSFP_TCPOPT_SACK 0x3 /* TCP SACK OK option */
490 #define PF_OSFP_TCPOPT_TS 0x4 /* TCP timestamp option */
491 #define PF_OSFP_TCPOPT_BITS 3 /* bits used by each option */
492 #define PF_OSFP_MAX_OPTS \
493 (sizeof(((struct pf_os_fingerprint *)0)->fp_tcpopts) * 8) \
494 / PF_OSFP_TCPOPT_BITS
496 SLIST_ENTRY(pf_os_fingerprint
) fp_next
;
499 struct pf_osfp_ioctl
{
500 struct pf_osfp_entry fp_os
;
501 pf_tcpopts_t fp_tcpopts
; /* packed TCP options */
502 u_int16_t fp_wsize
; /* TCP window size */
503 u_int16_t fp_psize
; /* ip->ip_len */
504 u_int16_t fp_mss
; /* TCP MSS */
506 u_int8_t fp_optcnt
; /* TCP option count */
507 u_int8_t fp_wscale
; /* TCP window scaling */
508 u_int8_t fp_ttl
; /* IPv4 TTL */
510 int fp_getnum
; /* DIOCOSFPGET number */
519 #define PF_ANCHOR_NAME_SIZE 64
522 struct pf_rule_addr src
;
523 struct pf_rule_addr dst
;
524 #define PF_SKIP_IFP 0
525 #define PF_SKIP_DIR 1
527 #define PF_SKIP_PROTO 3
528 #define PF_SKIP_SRC_ADDR 4
529 #define PF_SKIP_SRC_PORT 5
530 #define PF_SKIP_DST_ADDR 6
531 #define PF_SKIP_DST_PORT 7
532 #define PF_SKIP_COUNT 8
533 union pf_rule_ptr skip
[PF_SKIP_COUNT
];
534 #define PF_RULE_LABEL_SIZE 64
535 char label
[PF_RULE_LABEL_SIZE
];
536 #define PF_QNAME_SIZE 64
537 char ifname
[IFNAMSIZ
];
538 char qname
[PF_QNAME_SIZE
];
539 char pqname
[PF_QNAME_SIZE
];
540 #define PF_TAG_NAME_SIZE 64
541 char tagname
[PF_TAG_NAME_SIZE
];
542 char match_tagname
[PF_TAG_NAME_SIZE
];
544 char overload_tblname
[PF_TABLE_NAME_SIZE
];
546 TAILQ_ENTRY(pf_rule
) entries
;
547 struct pf_pool rpool
;
549 u_int64_t evaluations
;
550 u_int64_t packets
[2];
554 struct pf_anchor
*anchor
;
555 struct pfr_ktable
*overload_tbl
;
557 pf_osfp_t os_fingerprint
;
560 u_int32_t timeout
[PFTM_MAX
];
562 u_int32_t max_states
;
564 u_int32_t max_src_nodes
;
565 u_int32_t max_src_states
;
566 u_int32_t max_src_conn
;
579 u_int16_t return_icmp
;
580 u_int16_t return_icmp6
;
585 struct pf_rule_uid uid
;
586 struct pf_rule_gid gid
;
595 u_int8_t match_tag_not
;
598 #define PF_STATE_NORMAL 0x1
599 #define PF_STATE_MODULATE 0x2
600 #define PF_STATE_SYNPROXY 0x3
613 u_int8_t anchor_relative
;
614 u_int8_t anchor_wildcard
;
616 #define PF_FLUSH 0x01
617 #define PF_FLUSH_GLOBAL 0x02
622 #define PFRULE_DROP 0x0000
623 #define PFRULE_RETURNRST 0x0001
624 #define PFRULE_FRAGMENT 0x0002
625 #define PFRULE_RETURNICMP 0x0004
626 #define PFRULE_RETURN 0x0008
627 #define PFRULE_NOSYNC 0x0010
628 #define PFRULE_SRCTRACK 0x0020 /* track source states */
629 #define PFRULE_RULESRCTRACK 0x0040 /* per rule */
632 #define PFRULE_NODF 0x0100
633 #define PFRULE_FRAGCROP 0x0200 /* non-buffering frag cache */
634 #define PFRULE_FRAGDROP 0x0400 /* drop funny fragments */
635 #define PFRULE_RANDOMID 0x0800
636 #define PFRULE_REASSEMBLE_TCP 0x1000
638 /* rule flags again */
639 #define PFRULE_IFBOUND 0x00010000 /* if-bound */
641 #define PFSTATE_HIWAT 10000 /* default state table size */
642 #define PFSTATE_ADAPT_START 6000 /* default adaptive timeout start */
643 #define PFSTATE_ADAPT_END 12000 /* default adaptive timeout end */
646 struct pf_threshold
{
648 #define PF_THRESHOLD_MULT 1000
649 #define PF_THRESHOLD_MAX 0xffffffff / PF_THRESHOLD_MULT
656 RB_ENTRY(pf_src_node
) entry
;
658 struct pf_addr raddr
;
659 union pf_rule_ptr rule
;
662 u_int64_t packets
[2];
665 struct pf_threshold conn_rate
;
672 #define PFSNODE_HIWAT 10000 /* default source node table size */
674 struct pf_state_scrub
{
675 struct timeval pfss_last
; /* time received last packet */
676 u_int32_t pfss_tsecr
; /* last echoed timestamp */
677 u_int32_t pfss_tsval
; /* largest timestamp */
678 u_int32_t pfss_tsval0
; /* original timestamp */
679 u_int16_t pfss_flags
;
680 #define PFSS_TIMESTAMP 0x0001 /* modulate timestamp */
681 #define PFSS_PAWS 0x0010 /* stricter PAWS checks */
682 #define PFSS_PAWS_IDLED 0x0020 /* was idle too long. no PAWS */
683 #define PFSS_DATA_TS 0x0040 /* timestamp on data packets */
684 #define PFSS_DATA_NOTS 0x0080 /* no timestamp on data packets */
685 u_int8_t pfss_ttl
; /* stashed TTL */
687 u_int32_t pfss_ts_mod
; /* timestamp modulation */
690 struct pf_state_host
{
696 struct pf_state_peer
{
697 u_int32_t seqlo
; /* Max sequence number sent */
698 u_int32_t seqhi
; /* Max the other end ACKd + win */
699 u_int32_t seqdiff
; /* Sequence number modulator */
700 u_int16_t max_win
; /* largest window (pre scaling) */
701 u_int8_t state
; /* active state level */
702 u_int8_t wscale
; /* window scaling factor */
703 u_int16_t mss
; /* Maximum segment size option */
704 u_int8_t tcp_est
; /* Did we reach TCPS_ESTABLISHED */
705 struct pf_state_scrub
*scrub
; /* state is scrubbed */
709 TAILQ_HEAD(pf_state_queue
, pf_state
);
711 /* keep synced with struct pf_state_key, used in RB_FIND */
712 struct pf_state_key_cmp
{
713 struct pf_state_host lan
;
714 struct pf_state_host gwy
;
715 struct pf_state_host ext
;
722 TAILQ_HEAD(pf_statelist
, pf_state
);
724 struct pf_state_key
{
725 struct pf_state_host lan
;
726 struct pf_state_host gwy
;
727 struct pf_state_host ext
;
733 RB_ENTRY(pf_state_key
) entry_lan_ext
;
734 RB_ENTRY(pf_state_key
) entry_ext_gwy
;
735 struct pf_statelist states
;
736 u_short refcnt
; /* same size as if_index */
740 /* keep synced with struct pf_state, used in RB_FIND */
741 struct pf_state_cmp
{
752 TAILQ_ENTRY(pf_state
) entry_list
;
753 TAILQ_ENTRY(pf_state
) next
;
754 RB_ENTRY(pf_state
) entry_id
;
755 struct pf_state_peer src
;
756 struct pf_state_peer dst
;
757 union pf_rule_ptr rule
;
758 union pf_rule_ptr anchor
;
759 union pf_rule_ptr nat_rule
;
760 struct pf_addr rt_addr
;
761 struct pf_state_key
*state_key
;
763 struct pfi_kif
*rt_kif
;
764 struct pf_src_node
*src_node
;
765 struct pf_src_node
*nat_src_node
;
766 u_int64_t packets
[2];
770 u_int32_t pfsync_time
;
776 #define PFSTATE_NOSYNC 0x01
777 #define PFSTATE_FROMSYNC 0x02
778 #define PFSTATE_STALE 0x04
782 * Unified state structures for pulling states out of the kernel
783 * used by pfsync(4) and the pf(4) ioctl.
785 struct pfsync_state_scrub
{
786 u_int16_t pfss_flags
;
787 u_int8_t pfss_ttl
; /* stashed TTL */
788 #define PFSYNC_SCRUB_FLAG_VALID 0x01
790 u_int32_t pfss_ts_mod
; /* timestamp modulation */
793 struct pfsync_state_host
{
799 struct pfsync_state_peer
{
800 struct pfsync_state_scrub scrub
; /* state is scrubbed */
801 u_int32_t seqlo
; /* Max sequence number sent */
802 u_int32_t seqhi
; /* Max the other end ACKd + win */
803 u_int32_t seqdiff
; /* Sequence number modulator */
804 u_int16_t max_win
; /* largest window (pre scaling) */
805 u_int16_t mss
; /* Maximum segment size option */
806 u_int8_t state
; /* active state level */
807 u_int8_t wscale
; /* window scaling factor */
811 struct pfsync_state
{
813 char ifname
[IFNAMSIZ
];
814 struct pfsync_state_host lan
;
815 struct pfsync_state_host gwy
;
816 struct pfsync_state_host ext
;
817 struct pfsync_state_peer src
;
818 struct pfsync_state_peer dst
;
819 struct pf_addr rt_addr
;
825 u_int32_t packets
[2][2];
826 u_int32_t bytes
[2][2];
838 #define PFSYNC_FLAG_COMPRESS 0x01
839 #define PFSYNC_FLAG_STALE 0x02
840 #define PFSYNC_FLAG_SRCNODE 0x04
841 #define PFSYNC_FLAG_NATSRCNODE 0x08
843 /* for copies to/from userland via pf_ioctl() */
844 #define pf_state_peer_to_pfsync(s,d) do { \
845 (d)->seqlo = (s)->seqlo; \
846 (d)->seqhi = (s)->seqhi; \
847 (d)->seqdiff = (s)->seqdiff; \
848 (d)->max_win = (s)->max_win; \
849 (d)->mss = (s)->mss; \
850 (d)->state = (s)->state; \
851 (d)->wscale = (s)->wscale; \
853 (d)->scrub.pfss_flags = \
854 (s)->scrub->pfss_flags & PFSS_TIMESTAMP; \
855 (d)->scrub.pfss_ttl = (s)->scrub->pfss_ttl; \
856 (d)->scrub.pfss_ts_mod = (s)->scrub->pfss_ts_mod; \
857 (d)->scrub.scrub_flag = PFSYNC_SCRUB_FLAG_VALID; \
861 #define pf_state_peer_from_pfsync(s,d) do { \
862 (d)->seqlo = (s)->seqlo; \
863 (d)->seqhi = (s)->seqhi; \
864 (d)->seqdiff = (s)->seqdiff; \
865 (d)->max_win = (s)->max_win; \
866 (d)->mss = ntohs((s)->mss); \
867 (d)->state = (s)->state; \
868 (d)->wscale = (s)->wscale; \
869 if ((s)->scrub.scrub_flag == PFSYNC_SCRUB_FLAG_VALID && \
870 (d)->scrub != NULL) { \
871 (d)->scrub->pfss_flags = \
872 ntohs((s)->scrub.pfss_flags) & PFSS_TIMESTAMP; \
873 (d)->scrub->pfss_ttl = (s)->scrub.pfss_ttl; \
874 (d)->scrub->pfss_ts_mod = (s)->scrub.pfss_ts_mod; \
878 #define pf_state_counter_to_pfsync(s,d) do { \
879 d[0] = (s>>32)&0xffffffff; \
880 d[1] = s&0xffffffff; \
883 #define pf_state_counter_from_pfsync(s) \
884 (((u_int64_t)(s[0])<<32) | (u_int64_t)(s[1]))
888 TAILQ_HEAD(pf_rulequeue
, pf_rule
);
894 struct pf_rulequeue queues
[2];
896 struct pf_rulequeue
*ptr
;
897 struct pf_rule
**ptr_array
;
902 } rules
[PF_RULESET_MAX
];
903 struct pf_anchor
*anchor
;
909 RB_HEAD(pf_anchor_global
, pf_anchor
);
910 RB_HEAD(pf_anchor_node
, pf_anchor
);
912 RB_ENTRY(pf_anchor
) entry_global
;
913 RB_ENTRY(pf_anchor
) entry_node
;
914 struct pf_anchor
*parent
;
915 struct pf_anchor_node children
;
916 char name
[PF_ANCHOR_NAME_SIZE
];
917 char path
[MAXPATHLEN
];
918 struct pf_ruleset ruleset
;
919 int refcnt
; /* anchor rules */
922 RB_PROTOTYPE(pf_anchor_global
, pf_anchor
, entry_global
, pf_anchor_compare
);
923 RB_PROTOTYPE(pf_anchor_node
, pf_anchor
, entry_node
, pf_anchor_compare
);
925 #define PF_RESERVED_ANCHOR "_pf"
927 #define PFR_TFLAG_PERSIST 0x00000001
928 #define PFR_TFLAG_CONST 0x00000002
929 #define PFR_TFLAG_ACTIVE 0x00000004
930 #define PFR_TFLAG_INACTIVE 0x00000008
931 #define PFR_TFLAG_REFERENCED 0x00000010
932 #define PFR_TFLAG_REFDANCHOR 0x00000020
933 #define PFR_TFLAG_USRMASK 0x00000003
934 #define PFR_TFLAG_SETMASK 0x0000003C
935 #define PFR_TFLAG_ALLMASK 0x0000003F
938 char pfrt_anchor
[MAXPATHLEN
];
939 char pfrt_name
[PF_TABLE_NAME_SIZE
];
940 u_int32_t pfrt_flags
;
944 enum { PFR_FB_NONE
, PFR_FB_MATCH
, PFR_FB_ADDED
, PFR_FB_DELETED
,
945 PFR_FB_CHANGED
, PFR_FB_CLEARED
, PFR_FB_DUPLICATE
,
946 PFR_FB_NOTMATCH
, PFR_FB_CONFLICT
, PFR_FB_MAX
};
950 struct in_addr _pfra_ip4addr
;
951 struct in6_addr _pfra_ip6addr
;
958 #define pfra_ip4addr pfra_u._pfra_ip4addr
959 #define pfra_ip6addr pfra_u._pfra_ip6addr
961 enum { PFR_DIR_IN
, PFR_DIR_OUT
, PFR_DIR_MAX
};
962 enum { PFR_OP_BLOCK
, PFR_OP_PASS
, PFR_OP_ADDR_MAX
, PFR_OP_TABLE_MAX
};
963 #define PFR_OP_XPASS PFR_OP_ADDR_MAX
966 struct pfr_addr pfras_a
;
967 u_int64_t pfras_packets
[PFR_DIR_MAX
][PFR_OP_ADDR_MAX
];
968 u_int64_t pfras_bytes
[PFR_DIR_MAX
][PFR_OP_ADDR_MAX
];
972 enum { PFR_REFCNT_RULE
, PFR_REFCNT_ANCHOR
, PFR_REFCNT_MAX
};
975 struct pfr_table pfrts_t
;
976 u_int64_t pfrts_packets
[PFR_DIR_MAX
][PFR_OP_TABLE_MAX
];
977 u_int64_t pfrts_bytes
[PFR_DIR_MAX
][PFR_OP_TABLE_MAX
];
978 u_int64_t pfrts_match
;
979 u_int64_t pfrts_nomatch
;
982 int pfrts_refcnt
[PFR_REFCNT_MAX
];
984 #define pfrts_name pfrts_t.pfrt_name
985 #define pfrts_flags pfrts_t.pfrt_flags
987 SLIST_HEAD(pfr_kentryworkq
, pfr_kentry
);
989 struct radix_node pfrke_node
[2];
990 union sockaddr_union pfrke_sa
;
991 u_int64_t pfrke_packets
[PFR_DIR_MAX
][PFR_OP_ADDR_MAX
];
992 u_int64_t pfrke_bytes
[PFR_DIR_MAX
][PFR_OP_ADDR_MAX
];
993 SLIST_ENTRY(pfr_kentry
) pfrke_workq
;
999 u_int8_t pfrke_intrpool
;
1002 SLIST_HEAD(pfr_ktableworkq
, pfr_ktable
);
1003 RB_HEAD(pfr_ktablehead
, pfr_ktable
);
1005 struct pfr_tstats pfrkt_ts
;
1006 RB_ENTRY(pfr_ktable
) pfrkt_tree
;
1007 SLIST_ENTRY(pfr_ktable
) pfrkt_workq
;
1008 struct radix_node_head
*pfrkt_ip4
;
1009 struct radix_node_head
*pfrkt_ip6
;
1010 struct pfr_ktable
*pfrkt_shadow
;
1011 struct pfr_ktable
*pfrkt_root
;
1012 struct pf_ruleset
*pfrkt_rs
;
1016 #define pfrkt_t pfrkt_ts.pfrts_t
1017 #define pfrkt_name pfrkt_t.pfrt_name
1018 #define pfrkt_anchor pfrkt_t.pfrt_anchor
1019 #define pfrkt_ruleset pfrkt_t.pfrt_ruleset
1020 #define pfrkt_flags pfrkt_t.pfrt_flags
1021 #define pfrkt_cnt pfrkt_ts.pfrts_cnt
1022 #define pfrkt_refcnt pfrkt_ts.pfrts_refcnt
1023 #define pfrkt_packets pfrkt_ts.pfrts_packets
1024 #define pfrkt_bytes pfrkt_ts.pfrts_bytes
1025 #define pfrkt_match pfrkt_ts.pfrts_match
1026 #define pfrkt_nomatch pfrkt_ts.pfrts_nomatch
1027 #define pfrkt_tzero pfrkt_ts.pfrts_tzero
1029 RB_HEAD(pf_state_tree_lan_ext
, pf_state_key
);
1030 RB_PROTOTYPE(pf_state_tree_lan_ext
, pf_state_key
,
1031 entry_lan_ext
, pf_state_compare_lan_ext
);
1033 RB_HEAD(pf_state_tree_ext_gwy
, pf_state_key
);
1034 RB_PROTOTYPE(pf_state_tree_ext_gwy
, pf_state_key
,
1035 entry_ext_gwy
, pf_state_compare_ext_gwy
);
1037 RB_HEAD(pfi_ifhead
, pfi_kif
);
1040 extern struct pf_state_tree_lan_ext pf_statetbl_lan_ext
;
1041 extern struct pf_state_tree_ext_gwy pf_statetbl_ext_gwy
;
1043 /* keep synced with pfi_kif, used in RB_FIND */
1044 struct pfi_kif_cmp
{
1045 char pfik_name
[IFNAMSIZ
];
1049 char pfik_name
[IFNAMSIZ
];
1050 RB_ENTRY(pfi_kif
) pfik_tree
;
1051 u_int64_t pfik_packets
[2][2][2];
1052 u_int64_t pfik_bytes
[2][2][2];
1053 u_int32_t pfik_tzero
;
1055 void *pfik_ah_cookie
;
1056 struct ifnet
*pfik_ifp
;
1057 struct ifg_group
*pfik_group
;
1060 TAILQ_HEAD(, pfi_dynaddr
) pfik_dynaddrs
;
1069 #define PFI_IFLAG_SKIP 0x0100 /* skip filtering on interface */
1078 u_int64_t tot_len
; /* Make Mickey money */
1084 struct icmp6_hdr
*icmp6
;
1088 struct pf_addr baddr
; /* address before translation */
1089 struct pf_addr naddr
; /* address after translation */
1090 struct pf_rule
*nat_rule
; /* nat/rdr rule applied to packet */
1091 struct pf_addr
*src
;
1092 struct pf_addr
*dst
;
1096 u_int32_t p_len
; /* total length of payload */
1097 u_int16_t flags
; /* Let SCRUB trigger behavior in
1098 * state code. Easier than tags */
1099 #define PFDESC_TCP_NORM 0x0001 /* TCP shall be statefully scrubbed */
1100 #define PFDESC_IP_REAS 0x0002 /* IP frags would've been reassembled */
1106 /* flags for RDR options */
1107 #define PF_DPORT_RANGE 0x01 /* Dest port uses range */
1108 #define PF_RPORT_RANGE 0x02 /* RDR'ed port uses range */
1110 /* Reasons code for passing/dropping a packet */
1111 #define PFRES_MATCH 0 /* Explicit match of a rule */
1112 #define PFRES_BADOFF 1 /* Bad offset for pull_hdr */
1113 #define PFRES_FRAG 2 /* Dropping following fragment */
1114 #define PFRES_SHORT 3 /* Dropping short packet */
1115 #define PFRES_NORM 4 /* Dropping by normalizer */
1116 #define PFRES_MEMORY 5 /* Dropped due to lacking mem */
1117 #define PFRES_TS 6 /* Bad TCP Timestamp (RFC1323) */
1118 #define PFRES_CONGEST 7 /* Congestion (of ipintrq) */
1119 #define PFRES_IPOPTIONS 8 /* IP option */
1120 #define PFRES_PROTCKSUM 9 /* Protocol checksum invalid */
1121 #define PFRES_BADSTATE 10 /* State mismatch */
1122 #define PFRES_STATEINS 11 /* State insertion failure */
1123 #define PFRES_MAXSTATES 12 /* State limit */
1124 #define PFRES_SRCLIMIT 13 /* Source node/conn limit */
1125 #define PFRES_SYNPROXY 14 /* SYN proxy */
1126 #define PFRES_MAX 15 /* total+1 */
1128 #define PFRES_NAMES { \
1147 /* Counters for other things we want to keep track of */
1148 #define LCNT_STATES 0 /* states */
1149 #define LCNT_SRCSTATES 1 /* max-src-states */
1150 #define LCNT_SRCNODES 2 /* max-src-nodes */
1151 #define LCNT_SRCCONN 3 /* max-src-conn */
1152 #define LCNT_SRCCONNRATE 4 /* max-src-conn-rate */
1153 #define LCNT_OVERLOAD_TABLE 5 /* entry added to overload table */
1154 #define LCNT_OVERLOAD_FLUSH 6 /* state entries flushed */
1155 #define LCNT_MAX 7 /* total+1 */
1157 #define LCNT_NAMES { \
1158 "max states per rule", \
1162 "max-src-conn-rate", \
1163 "overload table insertion", \
1164 "overload flush states", \
1168 /* UDP state enumeration */
1169 #define PFUDPS_NO_TRAFFIC 0
1170 #define PFUDPS_SINGLE 1
1171 #define PFUDPS_MULTIPLE 2
1173 #define PFUDPS_NSTATES 3 /* number of state levels */
1175 #define PFUDPS_NAMES { \
1182 /* Other protocol state enumeration */
1183 #define PFOTHERS_NO_TRAFFIC 0
1184 #define PFOTHERS_SINGLE 1
1185 #define PFOTHERS_MULTIPLE 2
1187 #define PFOTHERS_NSTATES 3 /* number of state levels */
1189 #define PFOTHERS_NAMES { \
1196 #define FCNT_STATE_SEARCH 0
1197 #define FCNT_STATE_INSERT 1
1198 #define FCNT_STATE_REMOVALS 2
1201 #define SCNT_SRC_NODE_SEARCH 0
1202 #define SCNT_SRC_NODE_INSERT 1
1203 #define SCNT_SRC_NODE_REMOVALS 2
1206 #define ACTION_SET(a, x) \
1212 #define REASON_SET(a, x) \
1216 if (x < PFRES_MAX) \
1217 pf_status.counters[x]++; \
1221 u_int64_t counters
[PFRES_MAX
];
1222 u_int64_t lcounters
[LCNT_MAX
]; /* limit counters */
1223 u_int64_t fcounters
[FCNT_MAX
];
1224 u_int64_t scounters
[SCNT_MAX
];
1225 u_int64_t pcounters
[2][2][3];
1226 u_int64_t bcounters
[2][2];
1230 u_int32_t src_nodes
;
1234 char ifname
[IFNAMSIZ
];
1235 u_int8_t pf_chksum
[PF_MD5_DIGEST_LENGTH
];
1255 /* real-time service curve */
1256 u_int rtsc_m1
; /* slope of the 1st segment in bps */
1257 u_int rtsc_d
; /* the x-projection of m1 in msec */
1258 u_int rtsc_m2
; /* slope of the 2nd segment in bps */
1259 /* link-sharing service curve */
1263 /* upper-limit service curve */
1271 char ifname
[IFNAMSIZ
];
1273 void *altq_disc
; /* discipline-specific state */
1274 TAILQ_ENTRY(pf_altq
) entries
;
1276 /* scheduler spec */
1277 u_int8_t scheduler
; /* scheduler type */
1278 u_int16_t tbrsize
; /* tokenbucket regulator size */
1279 u_int32_t ifbandwidth
; /* interface bandwidth */
1282 char qname
[PF_QNAME_SIZE
]; /* queue name */
1283 char parent
[PF_QNAME_SIZE
]; /* parent name */
1284 u_int32_t parent_qid
; /* parent queue id */
1285 u_int32_t bandwidth
; /* queue bandwidth */
1286 u_int8_t priority
; /* priority */
1287 u_int16_t qlimit
; /* queue size limit */
1288 u_int16_t flags
; /* misc flags */
1290 struct cbq_opts cbq_opts
;
1291 struct priq_opts priq_opts
;
1292 struct hfsc_opts hfsc_opts
;
1295 u_int32_t qid
; /* return value */
1299 u_int16_t tag
; /* tag id */
1303 TAILQ_ENTRY(pf_tagname
) entries
;
1304 char name
[PF_TAG_NAME_SIZE
];
1309 #define PFFRAG_FRENT_HIWAT 5000 /* Number of fragment entries */
1310 #define PFFRAG_FRAG_HIWAT 1000 /* Number of fragmented packets */
1311 #define PFFRAG_FRCENT_HIWAT 50000 /* Number of fragment cache entries */
1312 #define PFFRAG_FRCACHE_HIWAT 10000 /* Number of fragment descriptors */
1314 #define PFR_KTABLE_HIWAT 1000 /* Number of tables */
1315 #define PFR_KENTRY_HIWAT 200000 /* Number of table entries */
1316 #define PFR_KENTRY_HIWAT_SMALL 100000 /* Number of table entries (tiny hosts) */
1319 * ioctl parameter structures
1322 struct pfioc_pooladdr
{
1330 char anchor
[MAXPATHLEN
];
1331 struct pf_pooladdr addr
;
1337 u_int32_t pool_ticket
;
1339 char anchor
[MAXPATHLEN
];
1340 char anchor_call
[MAXPATHLEN
];
1341 struct pf_rule rule
;
1344 struct pfioc_natlook
{
1345 struct pf_addr saddr
;
1346 struct pf_addr daddr
;
1347 struct pf_addr rsaddr
;
1348 struct pf_addr rdaddr
;
1358 struct pfioc_state
{
1363 struct pfioc_src_node_kill
{
1364 /* XXX returns the number of src nodes killed in psnk_af */
1365 sa_family_t psnk_af
;
1366 struct pf_rule_addr psnk_src
;
1367 struct pf_rule_addr psnk_dst
;
1370 struct pfioc_state_kill
{
1371 /* XXX returns the number of states killed in psk_af */
1374 struct pf_rule_addr psk_src
;
1375 struct pf_rule_addr psk_dst
;
1376 char psk_ifname
[IFNAMSIZ
];
1379 struct pfioc_states
{
1383 struct pfsync_state
*psu_states
;
1385 #define ps_buf ps_u.psu_buf
1386 #define ps_states ps_u.psu_states
1389 struct pfioc_src_nodes
{
1393 struct pf_src_node
*psu_src_nodes
;
1395 #define psn_buf psn_u.psu_buf
1396 #define psn_src_nodes psn_u.psu_src_nodes
1400 char ifname
[IFNAMSIZ
];
1408 struct pfioc_limit
{
1417 struct pf_altq altq
;
1420 struct pfioc_qstats
{
1428 struct pfioc_ruleset
{
1430 char path
[MAXPATHLEN
];
1431 char name
[PF_ANCHOR_NAME_SIZE
];
1434 #define PF_RULESET_ALTQ (PF_RULESET_MAX)
1435 #define PF_RULESET_TABLE (PF_RULESET_MAX+1)
1436 struct pfioc_trans
{
1437 int size
; /* number of elements */
1438 int esize
; /* size of each element in bytes */
1439 struct pfioc_trans_e
{
1441 char anchor
[MAXPATHLEN
];
1446 #define PFR_FLAG_ATOMIC 0x00000001
1447 #define PFR_FLAG_DUMMY 0x00000002
1448 #define PFR_FLAG_FEEDBACK 0x00000004
1449 #define PFR_FLAG_CLSTATS 0x00000008
1450 #define PFR_FLAG_ADDRSTOO 0x00000010
1451 #define PFR_FLAG_REPLACE 0x00000020
1452 #define PFR_FLAG_ALLRSETS 0x00000040
1453 #define PFR_FLAG_ALLMASK 0x0000007F
1455 #define PFR_FLAG_USERIOCTL 0x10000000
1458 struct pfioc_table
{
1459 struct pfr_table pfrio_table
;
1468 u_int32_t pfrio_ticket
;
1470 #define pfrio_exists pfrio_nadd
1471 #define pfrio_nzero pfrio_nadd
1472 #define pfrio_nmatch pfrio_nadd
1473 #define pfrio_naddr pfrio_size2
1474 #define pfrio_setflag pfrio_size2
1475 #define pfrio_clrflag pfrio_nadd
1477 struct pfioc_iface
{
1478 char pfiio_name
[IFNAMSIZ
];
1491 #define DIOCSTART _IO ('D', 1)
1492 #define DIOCSTOP _IO ('D', 2)
1493 #define DIOCADDRULE _IOWR('D', 4, struct pfioc_rule)
1494 #define DIOCGETRULES _IOWR('D', 6, struct pfioc_rule)
1495 #define DIOCGETRULE _IOWR('D', 7, struct pfioc_rule)
1496 /* XXX cut 8 - 17 */
1497 #define DIOCCLRSTATES _IOWR('D', 18, struct pfioc_state_kill)
1498 #define DIOCGETSTATE _IOWR('D', 19, struct pfioc_state)
1499 #define DIOCSETSTATUSIF _IOWR('D', 20, struct pfioc_if)
1500 #define DIOCGETSTATUS _IOWR('D', 21, struct pf_status)
1501 #define DIOCCLRSTATUS _IO ('D', 22)
1502 #define DIOCNATLOOK _IOWR('D', 23, struct pfioc_natlook)
1503 #define DIOCSETDEBUG _IOWR('D', 24, u_int32_t)
1504 #define DIOCGETSTATES _IOWR('D', 25, struct pfioc_states)
1505 #define DIOCCHANGERULE _IOWR('D', 26, struct pfioc_rule)
1506 /* XXX cut 26 - 28 */
1507 #define DIOCSETTIMEOUT _IOWR('D', 29, struct pfioc_tm)
1508 #define DIOCGETTIMEOUT _IOWR('D', 30, struct pfioc_tm)
1509 #define DIOCADDSTATE _IOWR('D', 37, struct pfioc_state)
1510 #define DIOCCLRRULECTRS _IO ('D', 38)
1511 #define DIOCGETLIMIT _IOWR('D', 39, struct pfioc_limit)
1512 #define DIOCSETLIMIT _IOWR('D', 40, struct pfioc_limit)
1513 #define DIOCKILLSTATES _IOWR('D', 41, struct pfioc_state_kill)
1514 #define DIOCSTARTALTQ _IO ('D', 42)
1515 #define DIOCSTOPALTQ _IO ('D', 43)
1516 #define DIOCADDALTQ _IOWR('D', 45, struct pfioc_altq)
1517 #define DIOCGETALTQS _IOWR('D', 47, struct pfioc_altq)
1518 #define DIOCGETALTQ _IOWR('D', 48, struct pfioc_altq)
1519 #define DIOCCHANGEALTQ _IOWR('D', 49, struct pfioc_altq)
1520 #define DIOCGETQSTATS _IOWR('D', 50, struct pfioc_qstats)
1521 #define DIOCBEGINADDRS _IOWR('D', 51, struct pfioc_pooladdr)
1522 #define DIOCADDADDR _IOWR('D', 52, struct pfioc_pooladdr)
1523 #define DIOCGETADDRS _IOWR('D', 53, struct pfioc_pooladdr)
1524 #define DIOCGETADDR _IOWR('D', 54, struct pfioc_pooladdr)
1525 #define DIOCCHANGEADDR _IOWR('D', 55, struct pfioc_pooladdr)
1526 /* XXX cut 55 - 57 */
1527 #define DIOCGETRULESETS _IOWR('D', 58, struct pfioc_ruleset)
1528 #define DIOCGETRULESET _IOWR('D', 59, struct pfioc_ruleset)
1529 #define DIOCRCLRTABLES _IOWR('D', 60, struct pfioc_table)
1530 #define DIOCRADDTABLES _IOWR('D', 61, struct pfioc_table)
1531 #define DIOCRDELTABLES _IOWR('D', 62, struct pfioc_table)
1532 #define DIOCRGETTABLES _IOWR('D', 63, struct pfioc_table)
1533 #define DIOCRGETTSTATS _IOWR('D', 64, struct pfioc_table)
1534 #define DIOCRCLRTSTATS _IOWR('D', 65, struct pfioc_table)
1535 #define DIOCRCLRADDRS _IOWR('D', 66, struct pfioc_table)
1536 #define DIOCRADDADDRS _IOWR('D', 67, struct pfioc_table)
1537 #define DIOCRDELADDRS _IOWR('D', 68, struct pfioc_table)
1538 #define DIOCRSETADDRS _IOWR('D', 69, struct pfioc_table)
1539 #define DIOCRGETADDRS _IOWR('D', 70, struct pfioc_table)
1540 #define DIOCRGETASTATS _IOWR('D', 71, struct pfioc_table)
1541 #define DIOCRCLRASTATS _IOWR('D', 72, struct pfioc_table)
1542 #define DIOCRTSTADDRS _IOWR('D', 73, struct pfioc_table)
1543 #define DIOCRSETTFLAGS _IOWR('D', 74, struct pfioc_table)
1544 #define DIOCRINADEFINE _IOWR('D', 77, struct pfioc_table)
1545 #define DIOCOSFPFLUSH _IO('D', 78)
1546 #define DIOCOSFPADD _IOWR('D', 79, struct pf_osfp_ioctl)
1547 #define DIOCOSFPGET _IOWR('D', 80, struct pf_osfp_ioctl)
1548 #define DIOCXBEGIN _IOWR('D', 81, struct pfioc_trans)
1549 #define DIOCXCOMMIT _IOWR('D', 82, struct pfioc_trans)
1550 #define DIOCXROLLBACK _IOWR('D', 83, struct pfioc_trans)
1551 #define DIOCGETSRCNODES _IOWR('D', 84, struct pfioc_src_nodes)
1552 #define DIOCCLRSRCNODES _IO('D', 85)
1553 #define DIOCSETHOSTID _IOWR('D', 86, u_int32_t)
1554 #define DIOCIGETIFACES _IOWR('D', 87, struct pfioc_iface)
1555 #define DIOCSETIFFLAG _IOWR('D', 89, struct pfioc_iface)
1556 #define DIOCCLRIFFLAG _IOWR('D', 90, struct pfioc_iface)
1557 #define DIOCKILLSRCNODES _IOWR('D', 91, struct pfioc_src_node_kill)
1560 RB_HEAD(pf_src_tree
, pf_src_node
);
1561 RB_PROTOTYPE(pf_src_tree
, pf_src_node
, entry
, pf_src_compare
);
1562 extern struct pf_src_tree tree_src_tracking
;
1564 RB_HEAD(pf_state_tree_id
, pf_state
);
1565 RB_PROTOTYPE(pf_state_tree_id
, pf_state
,
1566 entry_id
, pf_state_compare_id
);
1567 extern struct pf_state_tree_id tree_id
;
1568 extern struct pf_state_queue state_list
;
1570 TAILQ_HEAD(pf_poolqueue
, pf_pool
);
1571 extern struct pf_poolqueue pf_pools
[2];
1572 TAILQ_HEAD(pf_altqqueue
, pf_altq
);
1573 extern struct pf_altqqueue pf_altqs
[2];
1574 extern struct pf_palist pf_pabuf
;
1576 extern u_int32_t ticket_altqs_active
;
1577 extern u_int32_t ticket_altqs_inactive
;
1578 extern int altqs_inactive_open
;
1579 extern u_int32_t ticket_pabuf
;
1580 extern struct pf_altqqueue
*pf_altqs_active
;
1581 extern struct pf_altqqueue
*pf_altqs_inactive
;
1582 extern struct pf_poolqueue
*pf_pools_active
;
1583 extern struct pf_poolqueue
*pf_pools_inactive
;
1584 extern int pf_tbladdr_setup(struct pf_ruleset
*,
1585 struct pf_addr_wrap
*);
1586 extern void pf_tbladdr_remove(struct pf_addr_wrap
*);
1587 extern void pf_tbladdr_copyout(struct pf_addr_wrap
*);
1588 extern void pf_calc_skip_steps(struct pf_rulequeue
*);
1589 extern struct pool pf_src_tree_pl
, pf_rule_pl
;
1590 extern struct pool pf_state_pl
, pf_state_key_pl
, pf_altq_pl
,
1592 extern struct pool pf_state_scrub_pl
;
1593 extern void pf_purge_thread(void *);
1594 extern void pf_purge_expired_src_nodes(int);
1595 extern void pf_purge_expired_states(u_int32_t
);
1596 extern void pf_unlink_state(struct pf_state
*);
1597 extern void pf_free_state(struct pf_state
*);
1598 extern int pf_insert_state(struct pfi_kif
*,
1600 extern int pf_insert_src_node(struct pf_src_node
**,
1601 struct pf_rule
*, struct pf_addr
*,
1603 void pf_src_tree_remove_state(struct pf_state
*);
1604 extern struct pf_state
*pf_find_state_byid(struct pf_state_cmp
*);
1605 extern struct pf_state
*pf_find_state_all(struct pf_state_key_cmp
*,
1607 extern void pf_print_state(struct pf_state
*);
1608 extern void pf_print_flags(u_int8_t
);
1609 extern u_int16_t
pf_cksum_fixup(u_int16_t
, u_int16_t
, u_int16_t
,
1612 extern struct ifnet
*sync_ifp
;
1613 extern struct pf_rule pf_default_rule
;
1614 extern void pf_addrcpy(struct pf_addr
*,
1615 const struct pf_addr
*, u_int8_t
);
1616 void pf_rm_rule(struct pf_rulequeue
*,
1620 int pf_test(int, struct ifnet
*, struct mbuf
**, struct ether_header
*);
1624 int pf_test6(int, struct ifnet
*, struct mbuf
**, struct ether_header
*);
1625 void pf_poolmask(struct pf_addr
*, struct pf_addr
*,
1626 struct pf_addr
*, const struct pf_addr
*, u_int8_t
);
1627 void pf_addr_inc(struct pf_addr
*, sa_family_t
);
1630 void *pf_pull_hdr(struct mbuf
*, int, void *, int, u_short
*, u_short
*,
1632 void pf_change_a(void *, u_int16_t
*, u_int32_t
, u_int8_t
);
1633 int pflog_packet(struct pfi_kif
*, struct mbuf
*, sa_family_t
, u_int8_t
,
1634 u_int8_t
, struct pf_rule
*, struct pf_rule
*, struct pf_ruleset
*,
1636 int pf_match_addr(u_int8_t
, struct pf_addr
*, struct pf_addr
*,
1637 struct pf_addr
*, sa_family_t
);
1638 int pf_match(u_int8_t
, u_int32_t
, u_int32_t
, u_int32_t
);
1639 int pf_match_port(u_int8_t
, u_int16_t
, u_int16_t
, u_int16_t
);
1640 int pf_match_uid(u_int8_t
, uid_t
, uid_t
, uid_t
);
1641 int pf_match_gid(u_int8_t
, gid_t
, gid_t
, gid_t
);
1643 void pf_normalize_init(void);
1644 int pf_normalize_ip(struct mbuf
**, int, struct pfi_kif
*, u_short
*,
1646 int pf_normalize_ip6(struct mbuf
**, int, struct pfi_kif
*, u_short
*,
1648 int pf_normalize_tcp(int, struct pfi_kif
*, struct mbuf
*, int, int, void *,
1650 void pf_normalize_tcp_cleanup(struct pf_state
*);
1651 int pf_normalize_tcp_init(struct mbuf
*, int, struct pf_pdesc
*,
1652 struct tcphdr
*, struct pf_state_peer
*, struct pf_state_peer
*);
1653 int pf_normalize_tcp_stateful(struct mbuf
*, int, struct pf_pdesc
*,
1654 u_short
*, struct tcphdr
*, struct pf_state
*,
1655 struct pf_state_peer
*, struct pf_state_peer
*, int *);
1657 pf_state_expires(const struct pf_state
*);
1658 void pf_purge_expired_fragments(void);
1659 int pf_routable(struct pf_addr
*addr
, sa_family_t af
, struct pfi_kif
*);
1660 int pf_rtlabel_match(struct pf_addr
*, sa_family_t
, struct pf_addr_wrap
*);
1661 int pf_socket_lookup(int, struct pf_pdesc
*);
1662 struct pf_state_key
*
1663 pf_alloc_state_key(struct pf_state
*);
1664 void pfr_initialize(void);
1665 int pfr_match_addr(struct pfr_ktable
*, struct pf_addr
*, sa_family_t
);
1666 void pfr_update_stats(struct pfr_ktable
*, struct pf_addr
*, sa_family_t
,
1667 u_int64_t
, int, int, int);
1668 int pfr_pool_get(struct pfr_ktable
*, int *, struct pf_addr
*,
1669 struct pf_addr
**, struct pf_addr
**, sa_family_t
);
1670 void pfr_dynaddr_update(struct pfr_ktable
*, struct pfi_dynaddr
*);
1672 pfr_attach_table(struct pf_ruleset
*, char *);
1673 void pfr_detach_table(struct pfr_ktable
*);
1674 int pfr_clr_tables(struct pfr_table
*, int *, int);
1675 int pfr_add_tables(struct pfr_table
*, int, int *, int);
1676 int pfr_del_tables(struct pfr_table
*, int, int *, int);
1677 int pfr_get_tables(struct pfr_table
*, struct pfr_table
*, int *, int);
1678 int pfr_get_tstats(struct pfr_table
*, struct pfr_tstats
*, int *, int);
1679 int pfr_clr_tstats(struct pfr_table
*, int, int *, int);
1680 int pfr_set_tflags(struct pfr_table
*, int, int, int, int *, int *, int);
1681 int pfr_clr_addrs(struct pfr_table
*, int *, int);
1682 int pfr_insert_kentry(struct pfr_ktable
*, struct pfr_addr
*, long);
1683 int pfr_add_addrs(struct pfr_table
*, struct pfr_addr
*, int, int *,
1685 int pfr_del_addrs(struct pfr_table
*, struct pfr_addr
*, int, int *,
1687 int pfr_set_addrs(struct pfr_table
*, struct pfr_addr
*, int, int *,
1688 int *, int *, int *, int, u_int32_t
);
1689 int pfr_get_addrs(struct pfr_table
*, struct pfr_addr
*, int *, int);
1690 int pfr_get_astats(struct pfr_table
*, struct pfr_astats
*, int *, int);
1691 int pfr_clr_astats(struct pfr_table
*, struct pfr_addr
*, int, int *,
1693 int pfr_tst_addrs(struct pfr_table
*, struct pfr_addr
*, int, int *,
1695 int pfr_ina_begin(struct pfr_table
*, u_int32_t
*, int *, int);
1696 int pfr_ina_rollback(struct pfr_table
*, u_int32_t
, int *, int);
1697 int pfr_ina_commit(struct pfr_table
*, u_int32_t
, int *, int *, int);
1698 int pfr_ina_define(struct pfr_table
*, struct pfr_addr
*, int, int *,
1699 int *, u_int32_t
, int);
1701 extern struct pfi_kif
*pfi_all
;
1703 void pfi_initialize(void);
1704 struct pfi_kif
*pfi_kif_get(const char *);
1705 void pfi_kif_ref(struct pfi_kif
*, enum pfi_kif_refs
);
1706 void pfi_kif_unref(struct pfi_kif
*, enum pfi_kif_refs
);
1707 int pfi_kif_match(struct pfi_kif
*, struct pfi_kif
*);
1708 void pfi_attach_ifnet(struct ifnet
*);
1709 void pfi_detach_ifnet(struct ifnet
*);
1710 void pfi_attach_ifgroup(struct ifg_group
*);
1711 void pfi_detach_ifgroup(struct ifg_group
*);
1712 void pfi_group_change(const char *);
1713 int pfi_match_addr(struct pfi_dynaddr
*, struct pf_addr
*,
1715 int pfi_dynaddr_setup(struct pf_addr_wrap
*, sa_family_t
);
1716 void pfi_dynaddr_remove(struct pf_addr_wrap
*);
1717 void pfi_dynaddr_copyout(struct pf_addr_wrap
*);
1718 void pfi_fill_oldstatus(struct pf_status
*);
1719 int pfi_clr_istats(const char *);
1720 int pfi_get_ifaces(const char *, struct pfi_kif
*, int *);
1721 int pfi_set_flags(const char *, int);
1722 int pfi_clear_flags(const char *, int);
1724 u_int16_t
pf_tagname2tag(char *);
1725 void pf_tag2tagname(u_int16_t
, char *);
1726 void pf_tag_ref(u_int16_t
);
1727 void pf_tag_unref(u_int16_t
);
1728 int pf_tag_packet(struct mbuf
*, int, int);
1729 u_int32_t
pf_qname2qid(char *);
1730 void pf_qid2qname(u_int32_t
, char *);
1731 void pf_qid_unref(u_int32_t
);
1733 extern struct pf_status pf_status
;
1734 extern struct pool pf_frent_pl
, pf_frag_pl
;
1736 extern krwlock_t pf_consistency_lock
;
1738 extern struct rwlock pf_consistency_lock
;
1739 #endif /* !__NetBSD__ */
1741 struct pf_pool_limit
{
1745 extern struct pf_pool_limit pf_pool_limits
[PF_LIMIT_MAX
];
1748 * misc compatibility definitions
1750 #if !defined(PRIu32)
1751 #define PRIu32 "u" /* XXX */
1754 #if !defined(NO_PID)
1755 #define NO_PID (PID_MAX + 1)
1758 #if defined(__NetBSD__)
1759 /* rwlock compatibility definitions */
1760 #define rw_enter_write(a) rw_enter((a), (RW_WRITER))
1761 #define rw_exit_write(a) rw_exit((a))
1762 #define rw_enter_read(a) rw_enter((a), (RW_READER))
1763 #define rw_exit_read(a) rw_exit((a))
1764 #endif /* __NetBSD__ */
1766 #endif /* _KERNEL */
1768 extern struct pf_anchor_global pf_anchors
;
1769 extern struct pf_anchor pf_main_anchor
;
1770 #define pf_main_ruleset pf_main_anchor.ruleset
1772 /* these ruleset functions can be linked into userland programs (pfctl) */
1773 int pf_get_ruleset_number(u_int8_t
);
1774 void pf_init_ruleset(struct pf_ruleset
*);
1775 int pf_anchor_setup(struct pf_rule
*,
1776 const struct pf_ruleset
*, const char *);
1777 int pf_anchor_copyout(const struct pf_ruleset
*,
1778 const struct pf_rule
*, struct pfioc_rule
*);
1779 void pf_anchor_remove(struct pf_rule
*);
1780 void pf_remove_if_empty_ruleset(struct pf_ruleset
*);
1781 struct pf_anchor
*pf_find_anchor(const char *);
1782 struct pf_ruleset
*pf_find_ruleset(const char *);
1783 struct pf_ruleset
*pf_find_or_create_ruleset(const char *);
1784 void pf_rs_initialize(void);
1787 int pf_anchor_copyout(const struct pf_ruleset
*,
1788 const struct pf_rule
*, struct pfioc_rule
*);
1789 void pf_anchor_remove(struct pf_rule
*);
1791 #endif /* _KERNEL */
1793 /* The fingerprint functions can be linked into userland programs (tcpdump) */
1794 int pf_osfp_add(struct pf_osfp_ioctl
*);
1796 struct pf_osfp_enlist
*
1797 pf_osfp_fingerprint(struct pf_pdesc
*, struct mbuf
*, int,
1798 const struct tcphdr
*);
1799 #endif /* _KERNEL */
1800 struct pf_osfp_enlist
*
1801 pf_osfp_fingerprint_hdr(const struct ip
*, const struct ip6_hdr
*,
1802 const struct tcphdr
*);
1803 void pf_osfp_flush(void);
1804 int pf_osfp_get(struct pf_osfp_ioctl
*);
1805 void pf_osfp_initialize(void);
1806 int pf_osfp_match(struct pf_osfp_enlist
*, pf_osfp_t
);
1807 struct pf_os_fingerprint
*
1808 pf_osfp_validate(void);
1811 #endif /* _NET_PFVAR_H_ */