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