1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2021 Rubicon Communications, LLC (Netgate) 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 32 #ifndef _PFCTL_IOCTL_H_ 33 #define _PFCTL_IOCTL_H_ 34 35 #include <netpfil/pf/pf.h> 36 37 struct pfctl_anchor; 38 struct pfctl_eth_anchor; 39 40 struct pfctl_status_counter { 41 uint64_t id; 42 uint64_t counter; 43 char *name; 44 45 TAILQ_ENTRY(pfctl_status_counter) entry; 46 }; 47 TAILQ_HEAD(pfctl_status_counters, pfctl_status_counter); 48 49 struct pfctl_status { 50 bool running; 51 uint32_t since; 52 uint32_t debug; 53 uint32_t hostid; 54 uint64_t states; 55 uint64_t src_nodes; 56 char ifname[IFNAMSIZ]; 57 uint8_t pf_chksum[PF_MD5_DIGEST_LENGTH]; 58 bool syncookies_active; 59 uint32_t reass; 60 61 struct pfctl_status_counters counters; 62 struct pfctl_status_counters lcounters; 63 struct pfctl_status_counters fcounters; 64 struct pfctl_status_counters scounters; 65 struct pfctl_status_counters ncounters; 66 uint64_t fragments; 67 uint64_t pcounters[2][2][2]; 68 uint64_t bcounters[2][2]; 69 }; 70 71 struct pfctl_eth_rulesets_info { 72 uint32_t nr; 73 }; 74 75 struct pfctl_eth_rules_info { 76 uint32_t nr; 77 uint32_t ticket; 78 }; 79 80 struct pfctl_eth_addr { 81 uint8_t addr[ETHER_ADDR_LEN]; 82 uint8_t mask[ETHER_ADDR_LEN]; 83 bool neg; 84 bool isset; 85 }; 86 87 struct pfctl_eth_rule { 88 uint32_t nr; 89 90 char label[PF_RULE_MAX_LABEL_COUNT][PF_RULE_LABEL_SIZE]; 91 uint32_t ridentifier; 92 93 bool quick; 94 95 /* Filter */ 96 char ifname[IFNAMSIZ]; 97 uint8_t ifnot; 98 uint8_t direction; 99 uint16_t proto; 100 struct pfctl_eth_addr src, dst; 101 struct pf_rule_addr ipsrc, ipdst; 102 char match_tagname[PF_TAG_NAME_SIZE]; 103 uint16_t match_tag; 104 bool match_tag_not; 105 106 /* Stats */ 107 uint64_t evaluations; 108 uint64_t packets[2]; 109 uint64_t bytes[2]; 110 time_t last_active_timestamp; 111 112 /* Action */ 113 char qname[PF_QNAME_SIZE]; 114 char tagname[PF_TAG_NAME_SIZE]; 115 uint16_t dnpipe; 116 uint32_t dnflags; 117 char bridge_to[IFNAMSIZ]; 118 uint8_t action; 119 120 struct pfctl_eth_anchor *anchor; 121 uint8_t anchor_relative; 122 uint8_t anchor_wildcard; 123 124 TAILQ_ENTRY(pfctl_eth_rule) entries; 125 }; 126 TAILQ_HEAD(pfctl_eth_rules, pfctl_eth_rule); 127 128 struct pfctl_eth_ruleset_info { 129 uint32_t nr; 130 char name[PF_ANCHOR_NAME_SIZE]; 131 char path[MAXPATHLEN]; 132 }; 133 134 struct pfctl_eth_ruleset { 135 struct pfctl_eth_rules rules; 136 struct pfctl_eth_anchor *anchor; 137 }; 138 139 struct pfctl_eth_anchor { 140 struct pfctl_eth_anchor *parent; 141 char name[PF_ANCHOR_NAME_SIZE]; 142 char path[MAXPATHLEN]; 143 struct pfctl_eth_ruleset ruleset; 144 int refcnt; /* anchor rules */ 145 int match; /* XXX: used for pfctl black magic */ 146 }; 147 148 struct pfctl_pooladdr { 149 struct pf_addr_wrap addr; 150 TAILQ_ENTRY(pfctl_pooladdr) entries; 151 char ifname[IFNAMSIZ]; 152 sa_family_t af; 153 }; 154 155 TAILQ_HEAD(pfctl_palist, pfctl_pooladdr); 156 157 struct pfctl_pool { 158 struct pfctl_palist list; 159 struct pfctl_pooladdr *cur; 160 struct pf_poolhashkey key; 161 struct pf_addr counter; 162 struct pf_mape_portset mape; 163 int tblidx; 164 uint16_t proxy_port[2]; 165 uint8_t opts; 166 }; 167 168 struct pfctl_rules_info { 169 uint32_t nr; 170 uint32_t ticket; 171 }; 172 173 struct pfctl_threshold { 174 uint32_t limit; 175 uint32_t seconds; 176 uint32_t count; 177 uint32_t last; 178 }; 179 180 struct pfctl_rule { 181 struct pf_rule_addr src; 182 struct pf_rule_addr dst; 183 union pf_rule_ptr skip[PF_SKIP_COUNT]; 184 char label[PF_RULE_MAX_LABEL_COUNT][PF_RULE_LABEL_SIZE]; 185 uint32_t ridentifier; 186 char ifname[IFNAMSIZ]; 187 char qname[PF_QNAME_SIZE]; 188 char pqname[PF_QNAME_SIZE]; 189 char tagname[PF_TAG_NAME_SIZE]; 190 char match_tagname[PF_TAG_NAME_SIZE]; 191 192 char overload_tblname[PF_TABLE_NAME_SIZE]; 193 194 TAILQ_ENTRY(pfctl_rule) entries; 195 struct pfctl_pool nat; 196 union { 197 /* Alias old and new names. */ 198 struct pfctl_pool rpool; 199 struct pfctl_pool rdr; 200 }; 201 struct pfctl_pool route; 202 struct pfctl_threshold pktrate; 203 204 uint64_t evaluations; 205 uint64_t packets[2]; 206 uint64_t bytes[2]; 207 time_t last_active_timestamp; 208 209 struct pfi_kif *kif; 210 struct pfctl_anchor *anchor; 211 struct pfr_ktable *overload_tbl; 212 213 pf_osfp_t os_fingerprint; 214 215 int rtableid; 216 uint32_t timeout[PFTM_MAX]; 217 uint32_t max_states; 218 uint32_t max_src_nodes; 219 uint32_t max_src_states; 220 uint32_t max_src_conn; 221 struct { 222 uint32_t limit; 223 uint32_t seconds; 224 } max_src_conn_rate; 225 uint16_t max_pkt_size; 226 uint32_t qid; 227 uint32_t pqid; 228 uint16_t dnpipe; 229 uint16_t dnrpipe; 230 uint32_t free_flags; 231 uint32_t nr; 232 uint32_t prob; 233 uid_t cuid; 234 pid_t cpid; 235 236 uint64_t states_cur; 237 uint64_t states_tot; 238 uint64_t src_nodes; 239 uint64_t src_nodes_type[PF_SN_MAX]; 240 241 uint16_t return_icmp; 242 uint16_t return_icmp6; 243 uint16_t max_mss; 244 uint16_t tag; 245 uint16_t match_tag; 246 uint16_t scrub_flags; 247 248 struct pf_rule_uid uid; 249 struct pf_rule_gid gid; 250 char rcv_ifname[IFNAMSIZ]; 251 bool rcvifnot; 252 struct { 253 uint8_t id; 254 int limiter_action; 255 } statelim; 256 struct { 257 uint8_t id; 258 int limiter_action; 259 } sourcelim; 260 261 uint32_t rule_flag; 262 uint8_t action; 263 uint8_t direction; 264 uint8_t log; 265 uint8_t logif; 266 uint8_t quick; 267 uint8_t ifnot; 268 uint8_t match_tag_not; 269 uint8_t natpass; 270 271 uint8_t keep_state; 272 sa_family_t af; 273 uint8_t proto; 274 uint16_t type; 275 uint16_t code; 276 uint8_t flags; 277 uint8_t flagset; 278 uint8_t min_ttl; 279 uint8_t allow_opts; 280 uint8_t rt; 281 uint8_t return_ttl; 282 uint8_t tos; 283 uint8_t set_tos; 284 uint8_t anchor_relative; 285 uint8_t anchor_wildcard; 286 287 uint8_t flush; 288 uint8_t prio; 289 uint8_t set_prio[2]; 290 sa_family_t naf; 291 292 struct { 293 struct pf_addr addr; 294 uint16_t port; 295 } divert; 296 297 time_t exptime; 298 }; 299 300 TAILQ_HEAD(pfctl_rulequeue, pfctl_rule); 301 302 struct pfctl_ruleset { 303 struct { 304 struct pfctl_rulequeue queues[2]; 305 struct { 306 struct pfctl_rulequeue *ptr; 307 struct pfctl_rule **ptr_array; 308 uint32_t rcount; 309 uint32_t ticket; 310 int open; 311 } active, inactive; 312 } rules[PF_RULESET_MAX]; 313 struct pfctl_anchor *anchor; 314 uint32_t tticket; 315 int tables; 316 int topen; 317 }; 318 319 RB_HEAD(pfctl_anchor_global, pfctl_anchor); 320 RB_HEAD(pfctl_anchor_node, pfctl_anchor); 321 struct pfctl_anchor { 322 RB_ENTRY(pfctl_anchor) entry_global; 323 RB_ENTRY(pfctl_anchor) entry_node; 324 struct pfctl_anchor *parent; 325 struct pfctl_anchor_node children; 326 char name[PF_ANCHOR_NAME_SIZE]; 327 char path[MAXPATHLEN]; 328 struct pfctl_ruleset ruleset; 329 int refcnt; /* anchor rules */ 330 int match; /* XXX: used for pfctl black magic */ 331 }; 332 RB_PROTOTYPE(pfctl_anchor_global, pfctl_anchor, entry_global, 333 pf_anchor_compare); 334 RB_PROTOTYPE(pfctl_anchor_node, pfctl_anchor, entry_node, 335 pf_anchor_compare); 336 337 struct pfctl_state_cmp { 338 uint64_t id; 339 uint32_t creatorid; 340 uint8_t direction; 341 }; 342 343 struct pfctl_kill { 344 struct pfctl_state_cmp cmp; 345 sa_family_t af; 346 int proto; 347 struct pf_rule_addr src; 348 struct pf_rule_addr dst; 349 struct pf_rule_addr rt_addr; 350 char ifname[IFNAMSIZ]; 351 char label[PF_RULE_LABEL_SIZE]; 352 bool kill_match; 353 bool nat; 354 }; 355 356 struct pfctl_state_peer { 357 uint32_t seqlo; 358 uint32_t seqhi; 359 uint32_t seqdiff; 360 uint8_t state; 361 uint8_t wscale; 362 }; 363 364 struct pfctl_state_key { 365 struct pf_addr addr[2]; 366 uint16_t port[2]; 367 sa_family_t af; 368 uint8_t proto; 369 }; 370 371 struct pfctl_state { 372 TAILQ_ENTRY(pfctl_state) entry; 373 374 uint64_t id; 375 uint32_t creatorid; 376 uint8_t direction; 377 378 struct pfctl_state_peer src; 379 struct pfctl_state_peer dst; 380 381 uint32_t rule; 382 uint32_t anchor; 383 uint32_t nat_rule; 384 struct pf_addr rt_addr; 385 struct pfctl_state_key key[2]; /* addresses stack and wire */ 386 char ifname[IFNAMSIZ]; 387 char orig_ifname[IFNAMSIZ]; 388 uint64_t packets[2]; 389 uint64_t bytes[2]; 390 uint32_t creation; 391 uint32_t expire; 392 uint32_t pfsync_time; 393 uint16_t state_flags; 394 uint32_t sync_flags; 395 uint16_t qid; 396 uint16_t pqid; 397 uint16_t dnpipe; 398 uint16_t dnrpipe; 399 uint8_t log; 400 int32_t rtableid; 401 uint8_t min_ttl; 402 uint8_t set_tos; 403 uint16_t max_mss; 404 uint8_t set_prio[2]; 405 uint8_t rt; 406 char rt_ifname[IFNAMSIZ]; 407 sa_family_t rt_af; 408 uint8_t src_node_flags; 409 struct pfctl_rule created_by_rule; 410 }; 411 412 TAILQ_HEAD(pfctl_statelist, pfctl_state); 413 struct pfctl_states { 414 struct pfctl_statelist states; 415 }; 416 417 enum pfctl_syncookies_mode { 418 PFCTL_SYNCOOKIES_NEVER, 419 PFCTL_SYNCOOKIES_ALWAYS, 420 PFCTL_SYNCOOKIES_ADAPTIVE 421 }; 422 extern const char* PFCTL_SYNCOOKIES_MODE_NAMES[]; 423 424 struct pfctl_syncookies { 425 enum pfctl_syncookies_mode mode; 426 uint8_t highwater; /* Percent */ 427 uint8_t lowwater; /* Percent */ 428 uint32_t halfopen_states; 429 }; 430 431 struct pfctl_src_node { 432 struct pf_addr addr; 433 struct pf_addr raddr; 434 int rule; 435 uint64_t bytes[2]; 436 uint64_t packets[2]; 437 uint32_t states; 438 uint32_t conn; 439 sa_family_t af; 440 sa_family_t raf; 441 uint8_t ruletype; 442 uint64_t creation; 443 uint64_t expire; 444 struct pfctl_threshold conn_rate; 445 pf_sn_types_t type; 446 }; 447 448 #define PF_DEVICE "/dev/pf" 449 450 struct pfctl_handle; 451 struct pfctl_handle *pfctl_open(const char *pf_device); 452 void pfctl_close(struct pfctl_handle *); 453 int pfctl_fd(struct pfctl_handle *); 454 455 int pfctl_startstop(struct pfctl_handle *h, int start); 456 struct pfctl_status* pfctl_get_status_h(struct pfctl_handle *h); 457 struct pfctl_status* pfctl_get_status(int dev); 458 int pfctl_clear_status(struct pfctl_handle *h); 459 uint64_t pfctl_status_counter(struct pfctl_status *status, int id); 460 uint64_t pfctl_status_lcounter(struct pfctl_status *status, int id); 461 uint64_t pfctl_status_fcounter(struct pfctl_status *status, int id); 462 uint64_t pfctl_status_scounter(struct pfctl_status *status, int id); 463 void pfctl_free_status(struct pfctl_status *status); 464 465 int pfctl_get_eth_rulesets_info(int dev, 466 struct pfctl_eth_rulesets_info *ri, const char *path); 467 int pfctl_get_eth_ruleset(int dev, const char *path, int nr, 468 struct pfctl_eth_ruleset_info *ri); 469 int pfctl_get_eth_rules_info(int dev, struct pfctl_eth_rules_info *rules, 470 const char *path); 471 int pfctl_get_eth_rule(int dev, uint32_t nr, uint32_t ticket, 472 const char *path, struct pfctl_eth_rule *rule, bool clear, 473 char *anchor_call); 474 int pfctl_add_eth_rule(int dev, const struct pfctl_eth_rule *r, 475 const char *anchor, const char *anchor_call, uint32_t ticket); 476 int pfctl_get_rules_info_h(struct pfctl_handle *h, 477 struct pfctl_rules_info *rules, uint32_t ruleset, 478 const char *path); 479 int pfctl_get_rules_info(int dev, struct pfctl_rules_info *rules, 480 uint32_t ruleset, const char *path); 481 int pfctl_get_rule(int dev, uint32_t nr, uint32_t ticket, 482 const char *anchor, uint32_t ruleset, struct pfctl_rule *rule, 483 char *anchor_call); 484 int pfctl_get_rule_h(struct pfctl_handle *h, uint32_t nr, uint32_t ticket, 485 const char *anchor, uint32_t ruleset, struct pfctl_rule *rule, 486 char *anchor_call); 487 int pfctl_get_clear_rule(int dev, uint32_t nr, uint32_t ticket, 488 const char *anchor, uint32_t ruleset, struct pfctl_rule *rule, 489 char *anchor_call, bool clear); 490 int pfctl_get_clear_rule_h(struct pfctl_handle *h, uint32_t nr, uint32_t ticket, 491 const char *anchor, uint32_t ruleset, struct pfctl_rule *rule, 492 char *anchor_call, bool clear); 493 int pfctl_add_rule(int dev, const struct pfctl_rule *r, 494 const char *anchor, const char *anchor_call, uint32_t ticket, 495 uint32_t pool_ticket); 496 int pfctl_add_rule_h(struct pfctl_handle *h, const struct pfctl_rule *r, 497 const char *anchor, const char *anchor_call, uint32_t ticket, 498 uint32_t pool_ticket); 499 int pfctl_set_keepcounters(int dev, bool keep); 500 int pfctl_get_creatorids(struct pfctl_handle *h, uint32_t *creators, size_t *len); 501 502 struct pfctl_state_filter { 503 char ifname[IFNAMSIZ]; 504 uint16_t proto; 505 sa_family_t af; 506 struct pf_addr addr; 507 struct pf_addr mask; 508 bool include_rule; 509 }; 510 typedef int (*pfctl_get_state_fn)(struct pfctl_state *, void *); 511 int pfctl_get_states_iter(pfctl_get_state_fn f, void *arg); 512 int pfctl_get_states_h(struct pfctl_handle *h, struct pfctl_state_filter *filter, pfctl_get_state_fn f, void *arg); 513 int pfctl_get_filtered_states_iter(struct pfctl_state_filter *filter, pfctl_get_state_fn f, void *arg); 514 int pfctl_get_states(int dev, struct pfctl_states *states); 515 void pfctl_free_states(struct pfctl_states *states); 516 int pfctl_clear_states(int dev, const struct pfctl_kill *kill, 517 unsigned int *killed); 518 int pfctl_kill_states(int dev, const struct pfctl_kill *kill, 519 unsigned int *killed); 520 int pfctl_clear_states_h(struct pfctl_handle *h, const struct pfctl_kill *kill, 521 unsigned int *killed); 522 int pfctl_kill_states_h(struct pfctl_handle *h, const struct pfctl_kill *kill, 523 unsigned int *killed); 524 int pfctl_clear_rules(int dev, const char *anchorname); 525 int pfctl_clear_nat(int dev, const char *anchorname); 526 int pfctl_clear_eth_rules(int dev, const char *anchorname); 527 int pfctl_set_syncookies(int dev, const struct pfctl_syncookies *s); 528 int pfctl_get_syncookies(int dev, struct pfctl_syncookies *s); 529 int pfctl_table_add_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl, struct pfr_addr 530 *addr, int size, int *nadd, int flags); 531 int pfctl_table_add_addrs(int dev, struct pfr_table *tbl, struct pfr_addr 532 *addr, int size, int *nadd, int flags); 533 int pfctl_table_del_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl, 534 struct pfr_addr *addr, int size, int *ndel, int flags); 535 int pfctl_table_del_addrs(int dev, struct pfr_table *tbl, struct pfr_addr 536 *addr, int size, int *ndel, int flags); 537 int pfctl_table_set_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl, 538 struct pfr_addr *addr, int size, int *nadd, int *ndel, 539 int *nchange, int flags); 540 int pfctl_table_set_addrs(int dev, struct pfr_table *tbl, struct pfr_addr 541 *addr, int size, int *size2, int *nadd, int *ndel, int *nchange, 542 int flags); 543 int pfctl_table_get_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl, struct pfr_addr *addr, 544 int *size, int flags); 545 int pfctl_table_get_addrs(int dev, struct pfr_table *tbl, struct pfr_addr 546 *addr, int *size, int flags); 547 int pfctl_set_statusif(struct pfctl_handle *h, const char *ifname); 548 549 struct pfctl_natlook_key { 550 sa_family_t af; 551 uint8_t direction; 552 uint8_t proto; 553 struct pf_addr saddr; 554 struct pf_addr daddr; 555 uint16_t sport; 556 uint16_t dport; 557 }; 558 struct pfctl_natlook { 559 struct pf_addr saddr; 560 struct pf_addr daddr; 561 uint16_t sport; 562 uint16_t dport; 563 }; 564 int pfctl_natlook(struct pfctl_handle *h, 565 const struct pfctl_natlook_key *k, struct pfctl_natlook *r); 566 int pfctl_set_debug(struct pfctl_handle *h, uint32_t level); 567 int pfctl_set_timeout(struct pfctl_handle *h, uint32_t timeout, uint32_t seconds); 568 int pfctl_get_timeout(struct pfctl_handle *h, uint32_t timeout, uint32_t *seconds); 569 int pfctl_set_limit(struct pfctl_handle *h, const int index, const uint limit); 570 int pfctl_get_limit(struct pfctl_handle *h, const int index, uint *limit); 571 int pfctl_begin_addrs(struct pfctl_handle *h, uint32_t *ticket); 572 int pfctl_add_addr(struct pfctl_handle *h, const struct pfioc_pooladdr *pa, int which); 573 int pfctl_get_addrs(struct pfctl_handle *h, uint32_t ticket, uint32_t r_num, 574 uint8_t r_action, const char *anchor, uint32_t *nr, int which); 575 int pfctl_get_addr(struct pfctl_handle *h, uint32_t ticket, uint32_t r_num, 576 uint8_t r_action, const char *anchor, uint32_t nr, struct pfioc_pooladdr *pa, 577 int which); 578 int pfctl_get_rulesets(struct pfctl_handle *h, const char *path, uint32_t *nr); 579 int pfctl_get_ruleset(struct pfctl_handle *h, const char *path, uint32_t nr, struct pfioc_ruleset *rs); 580 typedef int (*pfctl_get_srcnode_fn)(struct pfctl_src_node*, void *); 581 int pfctl_get_srcnodes(struct pfctl_handle *h, pfctl_get_srcnode_fn fn, void *arg); 582 583 int pfctl_clear_tables(struct pfctl_handle *h, struct pfr_table *filter, 584 int *ndel, int flags); 585 int pfctl_add_table(struct pfctl_handle *h, struct pfr_table *table, 586 int *nadd, int flags); 587 int pfctl_del_table(struct pfctl_handle *h, struct pfr_table *table, 588 int *ndel, int flags); 589 590 typedef int (*pfctl_get_tstats_fn)(const struct pfr_tstats *t, void *arg); 591 int pfctl_get_tstats(struct pfctl_handle *h, const struct pfr_table *filter, 592 pfctl_get_tstats_fn fn, void *arg); 593 int pfctl_clear_tstats(struct pfctl_handle *h, const struct pfr_table *filter, 594 int *nzero, int flags); 595 int pfctl_clear_addrs(struct pfctl_handle *h, const struct pfr_table *filter, 596 int *ndel, int flags); 597 598 int pfctl_get_astats(struct pfctl_handle *h, const struct pfr_table *tbl, 599 struct pfr_astats *addr, int *size, int flags); 600 int pfctl_clr_astats(struct pfctl_handle *h, const struct pfr_table *tbl, 601 struct pfr_addr *addr, int size, int *nzero, int flags); 602 int pfctl_test_addrs(struct pfctl_handle *h, const struct pfr_table *tbl, 603 struct pfr_addr *addr, int size, int *nmatch, int flags); 604 605 struct pfctl_limit_rate { 606 unsigned int limit; 607 unsigned int seconds; 608 }; 609 610 struct pfctl_state_lim { 611 uint32_t ticket; 612 char name[PF_STATELIM_NAME_LEN]; 613 uint32_t id; 614 unsigned int limit; 615 616 struct pfctl_limit_rate rate; 617 618 char description[PF_STATELIM_DESCR_LEN]; 619 620 unsigned int inuse; 621 uint64_t admitted; 622 uint64_t hardlimited; 623 uint64_t ratelimited; 624 }; 625 626 int pfctl_state_limiter_nget(struct pfctl_handle *h, struct pfctl_state_lim *lim); 627 int pfctl_state_limiter_add(struct pfctl_handle *h, struct pfctl_state_lim *lim); 628 629 struct pfctl_source_lim { 630 uint32_t ticket; 631 632 char name[PF_SOURCELIM_NAME_LEN]; 633 uint32_t id; 634 635 /* limit on the total number of address entries */ 636 unsigned int entries; 637 638 /* limit on the number of states per address entry */ 639 unsigned int limit; 640 641 /* rate limit on the creation of states by an address entry */ 642 struct pfctl_limit_rate rate; 643 644 /* 645 * when the number of states on an entry exceeds hwm, add 646 * the address to the specified table. when the number of 647 * states goes below lwm, remove it from the table. 648 */ 649 char overload_tblname[PF_TABLE_NAME_SIZE]; 650 unsigned int overload_hwm; 651 unsigned int overload_lwm; 652 653 /* 654 * mask addresses before they're used for entries. /64s 655 * everywhere for inet6 makes it easy to use too much memory. 656 */ 657 unsigned int inet_prefix; 658 unsigned int inet6_prefix; 659 660 char description[PF_SOURCELIM_DESCR_LEN]; 661 662 unsigned int nentries; 663 unsigned int inuse; 664 665 uint64_t addrallocs; 666 uint64_t addrnomem; 667 uint64_t admitted; 668 uint64_t addrlimited; 669 uint64_t hardlimited; 670 uint64_t ratelimited; 671 }; 672 673 int pfctl_source_limiter_get(struct pfctl_handle *h, struct pfctl_source_lim *lim); 674 int pfctl_source_limiter_nget(struct pfctl_handle *h, struct pfctl_source_lim *lim); 675 int pfctl_source_limiter_add(struct pfctl_handle *h, struct pfctl_source_lim *lim); 676 677 struct pfctl_source { 678 sa_family_t af; 679 unsigned int rdomain; 680 struct pf_addr addr; 681 682 unsigned int inet_prefix; 683 unsigned int inet6_prefix; 684 685 unsigned int limit; 686 unsigned int inuse; 687 uint64_t admitted; 688 uint64_t hardlimited; 689 uint64_t ratelimited; 690 }; 691 typedef int (*pfctl_get_source_fn)(struct pfctl_source *, void *); 692 int pfctl_source_get(struct pfctl_handle *h, int id, 693 pfctl_get_source_fn fn, void *arg); 694 695 struct pfctl_source_clear { 696 char name[PF_SOURCELIM_NAME_LEN]; 697 uint32_t id; 698 sa_family_t af; 699 unsigned int rdomain; 700 struct pf_addr addr; 701 }; 702 int pfctl_source_clear(struct pfctl_handle *h, struct pfctl_source_clear *); 703 704 #endif 705