1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2001 Daniel Hartmeier 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * - Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * - Redistributions in binary form must reproduce the above 14 * copyright notice, this list of conditions and the following 15 * disclaimer in the documentation and/or other materials provided 16 * with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 * 31 * $OpenBSD: pfvar.h,v 1.282 2009/01/29 15:12:28 pyr Exp $ 32 */ 33 34 #ifndef _NET_PF_H_ 35 #define _NET_PF_H_ 36 37 #include <sys/tree.h> 38 39 #define PF_TCPS_PROXY_SRC ((TCP_NSTATES)+0) 40 #define PF_TCPS_PROXY_DST ((TCP_NSTATES)+1) 41 42 #define PF_MD5_DIGEST_LENGTH 16 43 #ifdef MD5_DIGEST_LENGTH 44 #if PF_MD5_DIGEST_LENGTH != MD5_DIGEST_LENGTH 45 #error 46 #endif 47 #endif 48 49 enum { PF_INOUT, PF_IN, PF_OUT }; 50 enum { PF_PASS, PF_DROP, PF_SCRUB, PF_NOSCRUB, PF_NAT, PF_NONAT, 51 PF_BINAT, PF_NOBINAT, PF_RDR, PF_NORDR, PF_SYNPROXY_DROP, PF_DEFER, 52 PF_MATCH, PF_AFRT }; 53 enum { PF_RULESET_SCRUB, PF_RULESET_FILTER, PF_RULESET_NAT, 54 PF_RULESET_BINAT, PF_RULESET_RDR, PF_RULESET_MAX }; 55 enum { PF_OP_NONE, PF_OP_IRG, PF_OP_EQ, PF_OP_NE, PF_OP_LT, 56 PF_OP_LE, PF_OP_GT, PF_OP_GE, PF_OP_XRG, PF_OP_RRG }; 57 enum { PF_DEBUG_NONE, PF_DEBUG_URGENT, PF_DEBUG_MISC, PF_DEBUG_NOISY }; 58 enum { PF_CHANGE_NONE, PF_CHANGE_ADD_HEAD, PF_CHANGE_ADD_TAIL, 59 PF_CHANGE_ADD_BEFORE, PF_CHANGE_ADD_AFTER, 60 PF_CHANGE_REMOVE, PF_CHANGE_GET_TICKET }; 61 enum { PF_GET_NONE, PF_GET_CLR_CNTR }; 62 enum { PF_SK_WIRE, PF_SK_STACK, PF_SK_BOTH }; 63 enum { PF_PEER_SRC, PF_PEER_DST, PF_PEER_BOTH }; 64 65 /* 66 * Note about PFTM_*: real indices into pf_rule.timeout[] come before 67 * PFTM_MAX, special cases afterwards. See pf_state_expires(). 68 */ 69 enum { 70 PFTM_TCP_FIRST_PACKET = 0, 71 PFTM_TCP_OPENING = 1, 72 PFTM_TCP_ESTABLISHED = 2, 73 PFTM_TCP_CLOSING = 3, 74 PFTM_TCP_FIN_WAIT = 4, 75 PFTM_TCP_CLOSED = 5, 76 PFTM_UDP_FIRST_PACKET = 6, 77 PFTM_UDP_SINGLE = 7, 78 PFTM_UDP_MULTIPLE = 8, 79 PFTM_ICMP_FIRST_PACKET = 9, 80 PFTM_ICMP_ERROR_REPLY = 10, 81 PFTM_OTHER_FIRST_PACKET = 11, 82 PFTM_OTHER_SINGLE = 12, 83 PFTM_OTHER_MULTIPLE = 13, 84 PFTM_FRAG = 14, 85 PFTM_INTERVAL = 15, 86 PFTM_ADAPTIVE_START = 16, 87 PFTM_ADAPTIVE_END = 17, 88 PFTM_SRC_NODE = 18, 89 PFTM_TS_DIFF = 19, 90 PFTM_OLD_MAX = 20, /* Legacy limit, for binary compatibility with old kernels. */ 91 PFTM_SCTP_FIRST_PACKET = 20, 92 PFTM_SCTP_OPENING = 21, 93 PFTM_SCTP_ESTABLISHED = 22, 94 PFTM_SCTP_CLOSING = 23, 95 PFTM_SCTP_CLOSED = 24, 96 PFTM_MAX = 25, 97 PFTM_PURGE = 26, 98 PFTM_UNLINKED = 27, 99 }; 100 101 /* PFTM default values */ 102 #define PFTM_TCP_FIRST_PACKET_VAL 120 /* First TCP packet */ 103 #define PFTM_TCP_OPENING_VAL 30 /* No response yet */ 104 #define PFTM_TCP_ESTABLISHED_VAL 24*60*60/* Established */ 105 #define PFTM_TCP_CLOSING_VAL 15 * 60 /* Half closed */ 106 #define PFTM_TCP_FIN_WAIT_VAL 45 /* Got both FINs */ 107 #define PFTM_TCP_CLOSED_VAL 90 /* Got a RST */ 108 #define PFTM_UDP_FIRST_PACKET_VAL 60 /* First UDP packet */ 109 #define PFTM_UDP_SINGLE_VAL 30 /* Unidirectional */ 110 #define PFTM_UDP_MULTIPLE_VAL 60 /* Bidirectional */ 111 #define PFTM_ICMP_FIRST_PACKET_VAL 20 /* First ICMP packet */ 112 #define PFTM_ICMP_ERROR_REPLY_VAL 10 /* Got error response */ 113 #define PFTM_OTHER_FIRST_PACKET_VAL 60 /* First packet */ 114 #define PFTM_OTHER_SINGLE_VAL 30 /* Unidirectional */ 115 #define PFTM_OTHER_MULTIPLE_VAL 60 /* Bidirectional */ 116 #define PFTM_FRAG_VAL 30 /* Fragment expire */ 117 #define PFTM_INTERVAL_VAL 10 /* Expire interval */ 118 #define PFTM_SRC_NODE_VAL 0 /* Source tracking */ 119 #define PFTM_TS_DIFF_VAL 30 /* Allowed TS diff */ 120 121 enum { PF_NOPFROUTE, PF_FASTROUTE, PF_ROUTETO, PF_DUPTO, PF_REPLYTO }; 122 enum { PF_LIMIT_STATES, PF_LIMIT_SRC_NODES, PF_LIMIT_FRAGS, 123 PF_LIMIT_TABLE_ENTRIES, PF_LIMIT_MAX }; 124 #define PF_POOL_IDMASK 0x0f 125 enum { PF_POOL_NONE, PF_POOL_BITMASK, PF_POOL_RANDOM, 126 PF_POOL_SRCHASH, PF_POOL_ROUNDROBIN }; 127 enum { PF_ADDR_ADDRMASK, PF_ADDR_NOROUTE, PF_ADDR_DYNIFTL, 128 PF_ADDR_TABLE, PF_ADDR_URPFFAILED, 129 PF_ADDR_RANGE, PF_ADDR_NONE }; 130 #define PF_POOL_TYPEMASK 0x0f 131 #define PF_POOL_STICKYADDR 0x20 132 #define PF_POOL_ENDPI 0x40 133 #define PF_WSCALE_FLAG 0x80 134 #define PF_WSCALE_MASK 0x0f 135 136 #define PF_LOG 0x01 137 #define PF_LOG_ALL 0x02 138 #define PF_LOG_SOCKET_LOOKUP 0x04 139 #define PF_LOG_FORCE 0x08 140 #define PF_LOG_MATCHES 0x10 141 142 /* Reasons code for passing/dropping a packet */ 143 #define PFRES_MATCH 0 /* Explicit match of a rule */ 144 #define PFRES_BADOFF 1 /* Bad offset for pull_hdr */ 145 #define PFRES_FRAG 2 /* Dropping following fragment */ 146 #define PFRES_SHORT 3 /* Dropping short packet */ 147 #define PFRES_NORM 4 /* Dropping by normalizer */ 148 #define PFRES_MEMORY 5 /* Dropped due to lacking mem */ 149 #define PFRES_TS 6 /* Bad TCP Timestamp (RFC1323) */ 150 #define PFRES_CONGEST 7 /* Congestion (of ipintrq) */ 151 #define PFRES_IPOPTIONS 8 /* IP option */ 152 #define PFRES_PROTCKSUM 9 /* Protocol checksum invalid */ 153 #define PFRES_BADSTATE 10 /* State mismatch */ 154 #define PFRES_STATEINS 11 /* State insertion failure */ 155 #define PFRES_MAXSTATES 12 /* State limit */ 156 #define PFRES_SRCLIMIT 13 /* Source node/conn limit */ 157 #define PFRES_SYNPROXY 14 /* SYN proxy */ 158 #define PFRES_MAPFAILED 15 /* pf_map_addr() failed */ 159 #define PFRES_MAX 16 /* total+1 */ 160 161 #define PFRES_NAMES { \ 162 "match", \ 163 "bad-offset", \ 164 "fragment", \ 165 "short", \ 166 "normalize", \ 167 "memory", \ 168 "bad-timestamp", \ 169 "congestion", \ 170 "ip-option", \ 171 "proto-cksum", \ 172 "state-mismatch", \ 173 "state-insert", \ 174 "state-limit", \ 175 "src-limit", \ 176 "synproxy", \ 177 "map-failed", \ 178 NULL \ 179 } 180 181 /* Counters for other things we want to keep track of */ 182 #define LCNT_STATES 0 /* states */ 183 #define LCNT_SRCSTATES 1 /* max-src-states */ 184 #define LCNT_SRCNODES 2 /* max-src-nodes */ 185 #define LCNT_SRCCONN 3 /* max-src-conn */ 186 #define LCNT_SRCCONNRATE 4 /* max-src-conn-rate */ 187 #define LCNT_OVERLOAD_TABLE 5 /* entry added to overload table */ 188 #define LCNT_OVERLOAD_FLUSH 6 /* state entries flushed */ 189 #define LCNT_MAX 7 /* total+1 */ 190 /* Only available via the nvlist-based API */ 191 #define KLCNT_SYNFLOODS 7 /* synfloods detected */ 192 #define KLCNT_SYNCOOKIES_SENT 8 /* syncookies sent */ 193 #define KLCNT_SYNCOOKIES_VALID 9 /* syncookies validated */ 194 #define KLCNT_MAX 10 /* total+1 */ 195 196 #define LCNT_NAMES { \ 197 "max states per rule", \ 198 "max-src-states", \ 199 "max-src-nodes", \ 200 "max-src-conn", \ 201 "max-src-conn-rate", \ 202 "overload table insertion", \ 203 "overload flush states", \ 204 NULL \ 205 } 206 #define KLCNT_NAMES { \ 207 "max states per rule", \ 208 "max-src-states", \ 209 "max-src-nodes", \ 210 "max-src-conn", \ 211 "max-src-conn-rate", \ 212 "overload table insertion", \ 213 "overload flush states", \ 214 "synfloods detected", \ 215 "syncookies sent", \ 216 "syncookies validated", \ 217 NULL \ 218 } 219 220 /* state operation counters */ 221 #define FCNT_STATE_SEARCH 0 222 #define FCNT_STATE_INSERT 1 223 #define FCNT_STATE_REMOVALS 2 224 #define FCNT_MAX 3 225 226 #ifdef _KERNEL 227 #define FCNT_NAMES { \ 228 "searches", \ 229 "inserts", \ 230 "removals", \ 231 NULL \ 232 } 233 #endif 234 235 /* src_node operation counters */ 236 #define SCNT_SRC_NODE_SEARCH 0 237 #define SCNT_SRC_NODE_INSERT 1 238 #define SCNT_SRC_NODE_REMOVALS 2 239 #define SCNT_MAX 3 240 241 #define PF_TABLE_NAME_SIZE 32 242 #define PF_QNAME_SIZE 64 243 244 struct pfioc_nv { 245 void *data; 246 size_t len; /* The length of the nvlist data. */ 247 size_t size; /* The total size of the data buffer. */ 248 }; 249 250 struct pf_rule; 251 252 /* keep synced with pfi_kif, used in RB_FIND */ 253 struct pfi_kif_cmp { 254 char pfik_name[IFNAMSIZ]; 255 }; 256 257 struct pfi_kif { 258 char pfik_name[IFNAMSIZ]; 259 union { 260 RB_ENTRY(pfi_kif) pfik_tree; 261 LIST_ENTRY(pfi_kif) pfik_list; 262 }; 263 u_int64_t pfik_packets[2][2][2]; 264 u_int64_t pfik_bytes[2][2][2]; 265 u_int32_t pfik_tzero; 266 u_int pfik_flags; 267 struct ifnet *pfik_ifp; 268 struct ifg_group *pfik_group; 269 u_int pfik_rulerefs; 270 TAILQ_HEAD(, pfi_dynaddr) pfik_dynaddrs; 271 }; 272 273 struct pf_status { 274 uint64_t counters[PFRES_MAX]; 275 uint64_t lcounters[LCNT_MAX]; 276 uint64_t fcounters[FCNT_MAX]; 277 uint64_t scounters[SCNT_MAX]; 278 uint64_t pcounters[2][2][3]; 279 uint64_t bcounters[2][2]; 280 uint32_t running; 281 uint32_t states; 282 uint32_t src_nodes; 283 uint32_t since; 284 uint32_t debug; 285 uint32_t hostid; 286 char ifname[IFNAMSIZ]; 287 uint8_t pf_chksum[PF_MD5_DIGEST_LENGTH]; 288 }; 289 290 #define PF_REASS_ENABLED 0x01 291 #define PF_REASS_NODF 0x02 292 293 struct pf_addr { 294 union { 295 struct in_addr v4; 296 struct in6_addr v6; 297 u_int8_t addr8[16]; 298 u_int16_t addr16[8]; 299 u_int32_t addr32[4]; 300 }; /* 128-bit address */ 301 }; 302 303 #define PFI_AFLAG_NETWORK 0x01 304 #define PFI_AFLAG_BROADCAST 0x02 305 #define PFI_AFLAG_PEER 0x04 306 #define PFI_AFLAG_MODEMASK 0x07 307 #define PFI_AFLAG_NOALIAS 0x08 308 309 struct pf_addr_wrap { 310 union { 311 struct { 312 struct pf_addr addr; 313 struct pf_addr mask; 314 } a; 315 char ifname[IFNAMSIZ]; 316 char tblname[PF_TABLE_NAME_SIZE]; 317 } v; 318 union { 319 struct pfi_dynaddr *dyn; 320 struct pfr_ktable *tbl; 321 int dyncnt; 322 int tblcnt; 323 } p; 324 u_int8_t type; /* PF_ADDR_* */ 325 u_int8_t iflags; /* PFI_AFLAG_* */ 326 }; 327 328 union pf_rule_ptr { 329 struct pf_rule *ptr; 330 u_int32_t nr; 331 }; 332 333 struct pf_rule_uid { 334 uid_t uid[2]; 335 u_int8_t op; 336 }; 337 338 struct pf_rule_gid { 339 uid_t gid[2]; 340 u_int8_t op; 341 }; 342 343 struct pf_rule_addr { 344 struct pf_addr_wrap addr; 345 u_int16_t port[2]; 346 u_int8_t neg; 347 u_int8_t port_op; 348 }; 349 350 struct pf_pooladdr { 351 struct pf_addr_wrap addr; 352 TAILQ_ENTRY(pf_pooladdr) entries; 353 char ifname[IFNAMSIZ]; 354 struct pfi_kif *kif; 355 }; 356 357 TAILQ_HEAD(pf_palist, pf_pooladdr); 358 359 struct pf_poolhashkey { 360 union { 361 u_int8_t key8[16]; 362 u_int16_t key16[8]; 363 u_int32_t key32[4]; 364 }; /* 128-bit hash key */ 365 }; 366 367 struct pf_mape_portset { 368 u_int8_t offset; 369 u_int8_t psidlen; 370 u_int16_t psid; 371 }; 372 373 struct pf_pool { 374 struct pf_palist list; 375 struct pf_pooladdr *cur; 376 struct pf_poolhashkey key; 377 struct pf_addr counter; 378 int tblidx; 379 u_int16_t proxy_port[2]; 380 u_int8_t opts; 381 }; 382 383 /* A packed Operating System description for fingerprinting */ 384 typedef u_int32_t pf_osfp_t; 385 #define PF_OSFP_ANY ((pf_osfp_t)0) 386 #define PF_OSFP_UNKNOWN ((pf_osfp_t)-1) 387 #define PF_OSFP_NOMATCH ((pf_osfp_t)-2) 388 389 struct pf_osfp_entry { 390 SLIST_ENTRY(pf_osfp_entry) fp_entry; 391 pf_osfp_t fp_os; 392 int fp_enflags; 393 #define PF_OSFP_EXPANDED 0x001 /* expanded entry */ 394 #define PF_OSFP_GENERIC 0x002 /* generic signature */ 395 #define PF_OSFP_NODETAIL 0x004 /* no p0f details */ 396 #define PF_OSFP_LEN 32 397 char fp_class_nm[PF_OSFP_LEN]; 398 char fp_version_nm[PF_OSFP_LEN]; 399 char fp_subtype_nm[PF_OSFP_LEN]; 400 }; 401 #define PF_OSFP_ENTRY_EQ(a, b) \ 402 ((a)->fp_os == (b)->fp_os && \ 403 memcmp((a)->fp_class_nm, (b)->fp_class_nm, PF_OSFP_LEN) == 0 && \ 404 memcmp((a)->fp_version_nm, (b)->fp_version_nm, PF_OSFP_LEN) == 0 && \ 405 memcmp((a)->fp_subtype_nm, (b)->fp_subtype_nm, PF_OSFP_LEN) == 0) 406 407 /* handle pf_osfp_t packing */ 408 #define _FP_RESERVED_BIT 1 /* For the special negative #defines */ 409 #define _FP_UNUSED_BITS 1 410 #define _FP_CLASS_BITS 10 /* OS Class (Windows, Linux) */ 411 #define _FP_VERSION_BITS 10 /* OS version (95, 98, NT, 2.4.54, 3.2) */ 412 #define _FP_SUBTYPE_BITS 10 /* patch level (NT SP4, SP3, ECN patch) */ 413 #define PF_OSFP_UNPACK(osfp, class, version, subtype) do { \ 414 (class) = ((osfp) >> (_FP_VERSION_BITS+_FP_SUBTYPE_BITS)) & \ 415 ((1 << _FP_CLASS_BITS) - 1); \ 416 (version) = ((osfp) >> _FP_SUBTYPE_BITS) & \ 417 ((1 << _FP_VERSION_BITS) - 1);\ 418 (subtype) = (osfp) & ((1 << _FP_SUBTYPE_BITS) - 1); \ 419 } while(0) 420 #define PF_OSFP_PACK(osfp, class, version, subtype) do { \ 421 (osfp) = ((class) & ((1 << _FP_CLASS_BITS) - 1)) << (_FP_VERSION_BITS \ 422 + _FP_SUBTYPE_BITS); \ 423 (osfp) |= ((version) & ((1 << _FP_VERSION_BITS) - 1)) << \ 424 _FP_SUBTYPE_BITS; \ 425 (osfp) |= (subtype) & ((1 << _FP_SUBTYPE_BITS) - 1); \ 426 } while(0) 427 428 /* the fingerprint of an OSes TCP SYN packet */ 429 typedef u_int64_t pf_tcpopts_t; 430 struct pf_os_fingerprint { 431 SLIST_HEAD(pf_osfp_enlist, pf_osfp_entry) fp_oses; /* list of matches */ 432 pf_tcpopts_t fp_tcpopts; /* packed TCP options */ 433 u_int16_t fp_wsize; /* TCP window size */ 434 u_int16_t fp_psize; /* ip->ip_len */ 435 u_int16_t fp_mss; /* TCP MSS */ 436 u_int16_t fp_flags; 437 #define PF_OSFP_WSIZE_MOD 0x0001 /* Window modulus */ 438 #define PF_OSFP_WSIZE_DC 0x0002 /* Window don't care */ 439 #define PF_OSFP_WSIZE_MSS 0x0004 /* Window multiple of MSS */ 440 #define PF_OSFP_WSIZE_MTU 0x0008 /* Window multiple of MTU */ 441 #define PF_OSFP_PSIZE_MOD 0x0010 /* packet size modulus */ 442 #define PF_OSFP_PSIZE_DC 0x0020 /* packet size don't care */ 443 #define PF_OSFP_WSCALE 0x0040 /* TCP window scaling */ 444 #define PF_OSFP_WSCALE_MOD 0x0080 /* TCP window scale modulus */ 445 #define PF_OSFP_WSCALE_DC 0x0100 /* TCP window scale dont-care */ 446 #define PF_OSFP_MSS 0x0200 /* TCP MSS */ 447 #define PF_OSFP_MSS_MOD 0x0400 /* TCP MSS modulus */ 448 #define PF_OSFP_MSS_DC 0x0800 /* TCP MSS dont-care */ 449 #define PF_OSFP_DF 0x1000 /* IPv4 don't fragment bit */ 450 #define PF_OSFP_TS0 0x2000 /* Zero timestamp */ 451 #define PF_OSFP_INET6 0x4000 /* IPv6 */ 452 u_int8_t fp_optcnt; /* TCP option count */ 453 u_int8_t fp_wscale; /* TCP window scaling */ 454 u_int8_t fp_ttl; /* IPv4 TTL */ 455 #define PF_OSFP_MAXTTL_OFFSET 40 456 /* TCP options packing */ 457 #define PF_OSFP_TCPOPT_NOP 0x0 /* TCP NOP option */ 458 #define PF_OSFP_TCPOPT_WSCALE 0x1 /* TCP window scaling option */ 459 #define PF_OSFP_TCPOPT_MSS 0x2 /* TCP max segment size opt */ 460 #define PF_OSFP_TCPOPT_SACK 0x3 /* TCP SACK OK option */ 461 #define PF_OSFP_TCPOPT_TS 0x4 /* TCP timestamp option */ 462 #define PF_OSFP_TCPOPT_BITS 3 /* bits used by each option */ 463 #define PF_OSFP_MAX_OPTS \ 464 (sizeof(((struct pf_os_fingerprint *)0)->fp_tcpopts) * 8) \ 465 / PF_OSFP_TCPOPT_BITS 466 467 SLIST_ENTRY(pf_os_fingerprint) fp_next; 468 }; 469 470 struct pf_osfp_ioctl { 471 struct pf_osfp_entry fp_os; 472 pf_tcpopts_t fp_tcpopts; /* packed TCP options */ 473 u_int16_t fp_wsize; /* TCP window size */ 474 u_int16_t fp_psize; /* ip->ip_len */ 475 u_int16_t fp_mss; /* TCP MSS */ 476 u_int16_t fp_flags; 477 u_int8_t fp_optcnt; /* TCP option count */ 478 u_int8_t fp_wscale; /* TCP window scaling */ 479 u_int8_t fp_ttl; /* IPv4 TTL */ 480 481 int fp_getnum; /* DIOCOSFPGET number */ 482 }; 483 484 #define PF_ANCHOR_NAME_SIZE 64 485 486 struct pf_rule { 487 struct pf_rule_addr src; 488 struct pf_rule_addr dst; 489 #define PF_SKIP_IFP 0 490 #define PF_SKIP_DIR 1 491 #define PF_SKIP_AF 2 492 #define PF_SKIP_PROTO 3 493 #define PF_SKIP_SRC_ADDR 4 494 #define PF_SKIP_DST_ADDR 5 495 #define PF_SKIP_SRC_PORT 6 496 #define PF_SKIP_DST_PORT 7 497 #define PF_SKIP_COUNT 8 498 union pf_rule_ptr skip[PF_SKIP_COUNT]; 499 #define PF_RULE_LABEL_SIZE 64 500 #define PF_RULE_MAX_LABEL_COUNT 5 501 char label[PF_RULE_LABEL_SIZE]; 502 char ifname[IFNAMSIZ]; 503 char qname[PF_QNAME_SIZE]; 504 char pqname[PF_QNAME_SIZE]; 505 #define PF_TAG_NAME_SIZE 64 506 char tagname[PF_TAG_NAME_SIZE]; 507 char match_tagname[PF_TAG_NAME_SIZE]; 508 509 char overload_tblname[PF_TABLE_NAME_SIZE]; 510 511 TAILQ_ENTRY(pf_rule) entries; 512 struct pf_pool rpool; 513 514 u_int64_t evaluations; 515 u_int64_t packets[2]; 516 u_int64_t bytes[2]; 517 518 struct pfi_kif *kif; 519 struct pf_anchor *anchor; 520 struct pfr_ktable *overload_tbl; 521 522 pf_osfp_t os_fingerprint; 523 524 int rtableid; 525 u_int32_t timeout[PFTM_OLD_MAX]; 526 u_int32_t max_states; 527 u_int32_t max_src_nodes; 528 u_int32_t max_src_states; 529 u_int32_t max_src_conn; 530 struct { 531 u_int32_t limit; 532 u_int32_t seconds; 533 } max_src_conn_rate; 534 u_int32_t qid; 535 u_int32_t pqid; 536 u_int32_t rt_listid; 537 u_int32_t nr; 538 u_int32_t prob; 539 uid_t cuid; 540 pid_t cpid; 541 542 counter_u64_t states_cur; 543 counter_u64_t states_tot; 544 counter_u64_t src_nodes; 545 546 u_int16_t return_icmp; 547 u_int16_t return_icmp6; 548 u_int16_t max_mss; 549 u_int16_t tag; 550 u_int16_t match_tag; 551 u_int16_t scrub_flags; 552 553 struct pf_rule_uid uid; 554 struct pf_rule_gid gid; 555 556 u_int32_t rule_flag; 557 u_int8_t action; 558 u_int8_t direction; 559 u_int8_t log; 560 u_int8_t logif; 561 u_int8_t quick; 562 u_int8_t ifnot; 563 u_int8_t match_tag_not; 564 u_int8_t natpass; 565 566 #define PF_STATE_NORMAL 0x1 567 #define PF_STATE_MODULATE 0x2 568 #define PF_STATE_SYNPROXY 0x3 569 u_int8_t keep_state; 570 sa_family_t af; 571 u_int8_t proto; 572 u_int8_t type; 573 u_int8_t code; 574 u_int8_t flags; 575 u_int8_t flagset; 576 u_int8_t min_ttl; 577 u_int8_t allow_opts; 578 u_int8_t rt; 579 u_int8_t return_ttl; 580 u_int8_t tos; 581 u_int8_t set_tos; 582 u_int8_t anchor_relative; 583 u_int8_t anchor_wildcard; 584 585 #define PF_FLUSH 0x01 586 #define PF_FLUSH_GLOBAL 0x02 587 u_int8_t flush; 588 #define PF_PRIO_ZERO 0xff /* match "prio 0" packets */ 589 #define PF_PRIO_MAX 7 590 u_int8_t prio; 591 u_int8_t set_prio[2]; 592 593 struct { 594 struct pf_addr addr; 595 u_int16_t port; 596 } divert; 597 598 uint64_t u_states_cur; 599 uint64_t u_states_tot; 600 uint64_t u_src_nodes; 601 }; 602 603 /* pf_krule->rule_flag and old-style scrub flags */ 604 #define PFRULE_DROP 0x00000000 605 #define PFRULE_RETURNRST 0x00000001 606 #define PFRULE_FRAGMENT 0x00000002 607 #define PFRULE_RETURNICMP 0x00000004 608 #define PFRULE_RETURN 0x00000008 609 #define PFRULE_NOSYNC 0x00000010 610 #define PFRULE_SRCTRACK 0x00000020 /* track source states */ 611 #define PFRULE_RULESRCTRACK 0x00000040 /* per rule */ 612 #define PFRULE_NODF 0x00000100 613 #define PFRULE_FRAGMENT_NOREASS 0x00000200 614 #define PFRULE_RANDOMID 0x00000800 615 #define PFRULE_REASSEMBLE_TCP 0x00001000 616 #define PFRULE_SET_TOS 0x00002000 617 #define PFRULE_IFBOUND 0x00010000 /* if-bound */ 618 #define PFRULE_STATESLOPPY 0x00020000 /* sloppy state tracking */ 619 #define PFRULE_PFLOW 0x00040000 620 621 #ifdef _KERNEL 622 #define PFRULE_REFS 0x0080 /* rule has references */ 623 #endif 624 625 /* pf_rule_actions->dnflags */ 626 #define PFRULE_DN_IS_PIPE 0x0040 627 #define PFRULE_DN_IS_QUEUE 0x0080 628 629 /* pf_state->state_flags, pf_rule_actions->flags, pf_krule->scrub_flags */ 630 #define PFSTATE_ALLOWOPTS 0x0001 631 #define PFSTATE_SLOPPY 0x0002 632 #define PFSTATE_PFLOW 0x0004 633 #define PFSTATE_NOSYNC 0x0008 634 #define PFSTATE_ACK 0x0010 635 #define PFSTATE_NODF 0x0020 636 #define PFSTATE_SETTOS 0x0040 637 #define PFSTATE_RANDOMID 0x0080 638 #define PFSTATE_SCRUB_TCP 0x0100 639 #define PFSTATE_SETPRIO 0x0200 640 /* was PFSTATE_INP_UNLINKED 0x0400 */ 641 /* FreeBSD-specific flags are added from the end to keep space for porting 642 * flags from OpenBSD */ 643 #define PFSTATE_DN_IS_PIPE 0x4000 644 #define PFSTATE_DN_IS_QUEUE 0x8000 645 #define PFSTATE_SCRUBMASK (PFSTATE_NODF|PFSTATE_RANDOMID|PFSTATE_SCRUB_TCP) 646 #define PFSTATE_SETMASK (PFSTATE_SETTOS|PFSTATE_SETPRIO) 647 648 #define PFSTATE_HIWAT 100000 /* default state table size */ 649 #define PFSTATE_ADAPT_START 60000 /* default adaptive timeout start */ 650 #define PFSTATE_ADAPT_END 120000 /* default adaptive timeout end */ 651 652 653 struct pf_threshold { 654 u_int32_t limit; 655 #define PF_THRESHOLD_MULT 1000 656 #define PF_THRESHOLD_MAX 0xffffffff / PF_THRESHOLD_MULT 657 u_int32_t seconds; 658 u_int32_t count; 659 u_int32_t last; 660 }; 661 662 struct pf_src_node { 663 LIST_ENTRY(pf_src_node) entry; 664 struct pf_addr addr; 665 struct pf_addr raddr; 666 union pf_rule_ptr rule; 667 struct pfi_kif *kif; 668 u_int64_t bytes[2]; 669 u_int64_t packets[2]; 670 u_int32_t states; 671 u_int32_t conn; 672 struct pf_threshold conn_rate; 673 u_int32_t creation; 674 u_int32_t expire; 675 sa_family_t af; 676 sa_family_t naf; 677 u_int8_t ruletype; 678 }; 679 680 #define PFSNODE_HIWAT 10000 /* default source node table size */ 681 682 TAILQ_HEAD(pf_rulequeue, pf_rule); 683 684 struct pf_anchor; 685 686 struct pf_ruleset { 687 struct { 688 struct pf_rulequeue queues[2]; 689 struct { 690 struct pf_rulequeue *ptr; 691 struct pf_rule **ptr_array; 692 u_int32_t rcount; 693 u_int32_t ticket; 694 int open; 695 } active, inactive; 696 } rules[PF_RULESET_MAX]; 697 struct pf_anchor *anchor; 698 u_int32_t tticket; 699 int tables; 700 int topen; 701 }; 702 703 RB_HEAD(pf_anchor_global, pf_anchor); 704 RB_HEAD(pf_anchor_node, pf_anchor); 705 struct pf_anchor { 706 RB_ENTRY(pf_anchor) entry_global; 707 RB_ENTRY(pf_anchor) entry_node; 708 struct pf_anchor *parent; 709 struct pf_anchor_node children; 710 char name[PF_ANCHOR_NAME_SIZE]; 711 char path[MAXPATHLEN]; 712 struct pf_ruleset ruleset; 713 int refcnt; /* anchor rules */ 714 int match; /* XXX: used for pfctl black magic */ 715 }; 716 RB_PROTOTYPE(pf_anchor_global, pf_anchor, entry_global, pf_anchor_compare); 717 RB_PROTOTYPE(pf_anchor_node, pf_anchor, entry_node, pf_anchor_compare); 718 719 int pf_get_ruleset_number(u_int8_t); 720 721 #endif /* _NET_PF_H_ */ 722