1 /* $OpenBSD: pfctl.c,v 1.278 2008/08/31 20:18:17 jmc Exp $ */
4 * SPDX-License-Identifier: BSD-2-Clause
6 * Copyright (c) 2001 Daniel Hartmeier
7 * Copyright (c) 2002,2003 Henning Brauer
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * - Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials provided
19 * with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
39 #include <sys/types.h>
40 #include <sys/ioctl.h>
41 #include <sys/socket.h>
43 #include <sys/endian.h>
46 #include <netinet/in.h>
47 #include <net/pfvar.h>
48 #include <arpa/inet.h>
49 #include <net/altq/altq.h>
50 #include <sys/sysctl.h>
63 #include "pfctl_parser.h"
67 int pfctl_enable(int, int);
68 int pfctl_disable(int, int);
69 int pfctl_clear_stats(int, int);
70 int pfctl_get_skip_ifaces(void);
71 int pfctl_check_skip_ifaces(char *);
72 int pfctl_clear_skip_ifaces(struct pfctl *);
73 int pfctl_clear_interface_flags(int, int);
74 int pfctl_clear_rules(int, int, char *);
75 int pfctl_clear_nat(int, int, char *);
76 int pfctl_clear_altq(int, int);
77 int pfctl_clear_src_nodes(int, int);
78 int pfctl_clear_states(int, const char *, int);
79 void pfctl_addrprefix(char *, struct pf_addr *);
80 int pfctl_kill_src_nodes(int, const char *, int);
81 int pfctl_net_kill_states(int, const char *, int);
82 int pfctl_label_kill_states(int, const char *, int);
83 int pfctl_id_kill_states(int, const char *, int);
84 void pfctl_init_options(struct pfctl *);
85 int pfctl_load_options(struct pfctl *);
86 int pfctl_load_limit(struct pfctl *, unsigned int, unsigned int);
87 int pfctl_load_timeout(struct pfctl *, unsigned int, unsigned int);
88 int pfctl_load_debug(struct pfctl *, unsigned int);
89 int pfctl_load_logif(struct pfctl *, char *);
90 int pfctl_load_hostid(struct pfctl *, u_int32_t);
91 int pfctl_get_pool(int, struct pf_pool *, u_int32_t, u_int32_t, int,
93 void pfctl_print_rule_counters(struct pf_rule *, int);
94 int pfctl_show_rules(int, char *, int, enum pfctl_show, char *, int);
95 int pfctl_show_nat(int, int, char *);
96 int pfctl_show_src_nodes(int, int);
97 int pfctl_show_states(int, const char *, int);
98 int pfctl_show_status(int, int);
99 int pfctl_show_timeouts(int, int);
100 int pfctl_show_limits(int, int);
101 void pfctl_debug(int, u_int32_t, int);
102 int pfctl_test_altqsupport(int, int);
103 int pfctl_show_anchors(int, int, char *);
104 int pfctl_ruleset_trans(struct pfctl *, char *, struct pf_anchor *);
105 int pfctl_load_ruleset(struct pfctl *, char *,
106 struct pf_ruleset *, int, int);
107 int pfctl_load_rule(struct pfctl *, char *, struct pf_rule *, int);
108 const char *pfctl_lookup_option(char *, const char * const *);
110 static struct pf_anchor_global pf_anchors;
111 static struct pf_anchor pf_main_anchor;
112 static struct pfr_buffer skip_b;
114 static const char *clearopt;
115 static char *rulesopt;
116 static const char *showopt;
117 static const char *debugopt;
118 static char *anchoropt;
119 static const char *optiopt = NULL;
120 static const char *pf_device = "/dev/pf";
121 static char *ifaceopt;
122 static char *tableopt;
123 static const char *tblcmdopt;
124 static int src_node_killers;
125 static char *src_node_kill[2];
126 static int state_killers;
127 static char *state_kill[2];
132 static int first_title = 1;
133 static int labels = 0;
135 #define INDENT(d, o) do { \
138 for (i=0; i < d; i++) \
144 static const struct {
148 { "states", PF_LIMIT_STATES },
149 { "src-nodes", PF_LIMIT_SRC_NODES },
150 { "frags", PF_LIMIT_FRAGS },
151 { "table-entries", PF_LIMIT_TABLE_ENTRIES },
159 static const struct pf_hint pf_hint_normal[] = {
160 { "tcp.first", 2 * 60 },
161 { "tcp.opening", 30 },
162 { "tcp.established", 24 * 60 * 60 },
163 { "tcp.closing", 15 * 60 },
164 { "tcp.finwait", 45 },
165 { "tcp.closed", 90 },
166 { "tcp.tsdiff", 30 },
169 static const struct pf_hint pf_hint_satellite[] = {
170 { "tcp.first", 3 * 60 },
171 { "tcp.opening", 30 + 5 },
172 { "tcp.established", 24 * 60 * 60 },
173 { "tcp.closing", 15 * 60 + 5 },
174 { "tcp.finwait", 45 + 5 },
175 { "tcp.closed", 90 + 5 },
176 { "tcp.tsdiff", 60 },
179 static const struct pf_hint pf_hint_conservative[] = {
180 { "tcp.first", 60 * 60 },
181 { "tcp.opening", 15 * 60 },
182 { "tcp.established", 5 * 24 * 60 * 60 },
183 { "tcp.closing", 60 * 60 },
184 { "tcp.finwait", 10 * 60 },
185 { "tcp.closed", 3 * 60 },
186 { "tcp.tsdiff", 60 },
189 static const struct pf_hint pf_hint_aggressive[] = {
191 { "tcp.opening", 5 },
192 { "tcp.established", 5 * 60 * 60 },
193 { "tcp.closing", 60 },
194 { "tcp.finwait", 30 },
195 { "tcp.closed", 30 },
196 { "tcp.tsdiff", 10 },
200 static const struct {
202 const struct pf_hint *hint;
204 { "normal", pf_hint_normal },
205 { "satellite", pf_hint_satellite },
206 { "high-latency", pf_hint_satellite },
207 { "conservative", pf_hint_conservative },
208 { "aggressive", pf_hint_aggressive },
212 static const char * const clearopt_list[] = {
213 "nat", "queue", "rules", "Sources",
214 "states", "info", "Tables", "osfp", "all", NULL
217 static const char * const showopt_list[] = {
218 "nat", "queue", "rules", "Anchors", "Sources", "states", "info",
219 "Interfaces", "labels", "timeouts", "memory", "Tables", "osfp",
223 static const char * const tblcmdopt_list[] = {
224 "kill", "flush", "add", "delete", "load", "replace", "show",
225 "test", "zero", "expire", NULL
228 static const char * const debugopt_list[] = {
229 "none", "urgent", "misc", "loud", NULL
232 static const char * const optiopt_list[] = {
233 "none", "basic", "profile", NULL
239 extern char *__progname;
242 "usage: %s [-AdeghmNnOPqRrvz] [-a anchor] [-D macro=value] [-F modifier]\n"
243 "\t[-f file] [-i interface] [-K host | network]\n"
244 "\t[-k host | network | label | id] [-o level] [-p device]\n"
245 "\t[-s modifier] [-t table -T command [address ...]] [-x level]\n",
252 pfctl_enable(int dev, int opts)
254 if (ioctl(dev, DIOCSTART)) {
256 errx(1, "pf already enabled");
257 else if (errno == ESRCH)
258 errx(1, "pfil registeration failed");
262 if ((opts & PF_OPT_QUIET) == 0)
263 fprintf(stderr, "pf enabled\n");
265 if (altqsupport && ioctl(dev, DIOCSTARTALTQ))
267 err(1, "DIOCSTARTALTQ");
273 pfctl_disable(int dev, int opts)
275 if (ioctl(dev, DIOCSTOP)) {
277 errx(1, "pf not enabled");
281 if ((opts & PF_OPT_QUIET) == 0)
282 fprintf(stderr, "pf disabled\n");
284 if (altqsupport && ioctl(dev, DIOCSTOPALTQ))
286 err(1, "DIOCSTOPALTQ");
292 pfctl_clear_stats(int dev, int opts)
294 if (ioctl(dev, DIOCCLRSTATUS))
295 err(1, "DIOCCLRSTATUS");
296 if ((opts & PF_OPT_QUIET) == 0)
297 fprintf(stderr, "pf: statistics cleared\n");
302 pfctl_get_skip_ifaces(void)
304 bzero(&skip_b, sizeof(skip_b));
305 skip_b.pfrb_type = PFRB_IFACES;
307 pfr_buf_grow(&skip_b, skip_b.pfrb_size);
308 skip_b.pfrb_size = skip_b.pfrb_msize;
309 if (pfi_get_ifaces(NULL, skip_b.pfrb_caddr, &skip_b.pfrb_size))
310 err(1, "pfi_get_ifaces");
311 if (skip_b.pfrb_size <= skip_b.pfrb_msize)
318 pfctl_check_skip_ifaces(char *ifname)
322 PFRB_FOREACH(p, &skip_b)
323 if ((p->pfik_flags & PFI_IFLAG_SKIP) && !strcmp(ifname, p->pfik_name))
324 p->pfik_flags &= ~PFI_IFLAG_SKIP;
329 pfctl_clear_skip_ifaces(struct pfctl *pf)
333 PFRB_FOREACH(p, &skip_b)
334 if (p->pfik_flags & PFI_IFLAG_SKIP)
335 pfctl_set_interface_flags(pf, p->pfik_name, PFI_IFLAG_SKIP, 0);
340 pfctl_clear_interface_flags(int dev, int opts)
342 struct pfioc_iface pi;
344 if ((opts & PF_OPT_NOACTION) == 0) {
345 bzero(&pi, sizeof(pi));
346 pi.pfiio_flags = PFI_IFLAG_SKIP;
348 if (ioctl(dev, DIOCCLRIFFLAG, &pi))
349 err(1, "DIOCCLRIFFLAG");
350 if ((opts & PF_OPT_QUIET) == 0)
351 fprintf(stderr, "pf: interface flags reset\n");
357 pfctl_clear_rules(int dev, int opts, char *anchorname)
361 memset(&t, 0, sizeof(t));
362 t.pfrb_type = PFRB_TRANS;
363 if (pfctl_add_trans(&t, PF_RULESET_SCRUB, anchorname) ||
364 pfctl_add_trans(&t, PF_RULESET_FILTER, anchorname) ||
365 pfctl_trans(dev, &t, DIOCXBEGIN, 0) ||
366 pfctl_trans(dev, &t, DIOCXCOMMIT, 0))
367 err(1, "pfctl_clear_rules");
368 if ((opts & PF_OPT_QUIET) == 0)
369 fprintf(stderr, "rules cleared\n");
374 pfctl_clear_nat(int dev, int opts, char *anchorname)
378 memset(&t, 0, sizeof(t));
379 t.pfrb_type = PFRB_TRANS;
380 if (pfctl_add_trans(&t, PF_RULESET_NAT, anchorname) ||
381 pfctl_add_trans(&t, PF_RULESET_BINAT, anchorname) ||
382 pfctl_add_trans(&t, PF_RULESET_RDR, anchorname) ||
383 pfctl_trans(dev, &t, DIOCXBEGIN, 0) ||
384 pfctl_trans(dev, &t, DIOCXCOMMIT, 0))
385 err(1, "pfctl_clear_nat");
386 if ((opts & PF_OPT_QUIET) == 0)
387 fprintf(stderr, "nat cleared\n");
392 pfctl_clear_altq(int dev, int opts)
398 memset(&t, 0, sizeof(t));
399 t.pfrb_type = PFRB_TRANS;
400 if (pfctl_add_trans(&t, PF_RULESET_ALTQ, "") ||
401 pfctl_trans(dev, &t, DIOCXBEGIN, 0) ||
402 pfctl_trans(dev, &t, DIOCXCOMMIT, 0))
403 err(1, "pfctl_clear_altq");
404 if ((opts & PF_OPT_QUIET) == 0)
405 fprintf(stderr, "altq cleared\n");
410 pfctl_clear_src_nodes(int dev, int opts)
412 if (ioctl(dev, DIOCCLRSRCNODES))
413 err(1, "DIOCCLRSRCNODES");
414 if ((opts & PF_OPT_QUIET) == 0)
415 fprintf(stderr, "source tracking entries cleared\n");
420 pfctl_clear_states(int dev, const char *iface, int opts)
422 struct pfioc_state_kill psk;
424 memset(&psk, 0, sizeof(psk));
425 if (iface != NULL && strlcpy(psk.psk_ifname, iface,
426 sizeof(psk.psk_ifname)) >= sizeof(psk.psk_ifname))
427 errx(1, "invalid interface: %s", iface);
429 if (ioctl(dev, DIOCCLRSTATES, &psk))
430 err(1, "DIOCCLRSTATES");
431 if ((opts & PF_OPT_QUIET) == 0)
432 fprintf(stderr, "%d states cleared\n", psk.psk_killed);
437 pfctl_addrprefix(char *addr, struct pf_addr *mask)
441 int prefix, ret_ga, q, r;
442 struct addrinfo hints, *res;
444 if ((p = strchr(addr, '/')) == NULL)
448 prefix = strtonum(p, 0, 128, &errstr);
450 errx(1, "prefix is %s: %s", errstr, p);
452 bzero(&hints, sizeof(hints));
453 /* prefix only with numeric addresses */
454 hints.ai_flags |= AI_NUMERICHOST;
456 if ((ret_ga = getaddrinfo(addr, NULL, &hints, &res))) {
457 errx(1, "getaddrinfo: %s", gai_strerror(ret_ga));
461 if (res->ai_family == AF_INET && prefix > 32)
462 errx(1, "prefix too long for AF_INET");
463 else if (res->ai_family == AF_INET6 && prefix > 128)
464 errx(1, "prefix too long for AF_INET6");
468 switch (res->ai_family) {
470 bzero(&mask->v4, sizeof(mask->v4));
471 mask->v4.s_addr = htonl((u_int32_t)
472 (0xffffffffffULL << (32 - prefix)));
475 bzero(&mask->v6, sizeof(mask->v6));
477 memset((void *)&mask->v6, 0xff, q);
479 *((u_char *)&mask->v6 + q) =
480 (0xff00 >> r) & 0xff;
487 pfctl_kill_src_nodes(int dev, const char *iface, int opts)
489 struct pfioc_src_node_kill psnk;
490 struct addrinfo *res[2], *resp[2];
491 struct sockaddr last_src, last_dst;
492 int killed, sources, dests;
495 killed = sources = dests = 0;
497 memset(&psnk, 0, sizeof(psnk));
498 memset(&psnk.psnk_src.addr.v.a.mask, 0xff,
499 sizeof(psnk.psnk_src.addr.v.a.mask));
500 memset(&last_src, 0xff, sizeof(last_src));
501 memset(&last_dst, 0xff, sizeof(last_dst));
503 pfctl_addrprefix(src_node_kill[0], &psnk.psnk_src.addr.v.a.mask);
505 if ((ret_ga = getaddrinfo(src_node_kill[0], NULL, NULL, &res[0]))) {
506 errx(1, "getaddrinfo: %s", gai_strerror(ret_ga));
509 for (resp[0] = res[0]; resp[0]; resp[0] = resp[0]->ai_next) {
510 if (resp[0]->ai_addr == NULL)
512 /* We get lots of duplicates. Catch the easy ones */
513 if (memcmp(&last_src, resp[0]->ai_addr, sizeof(last_src)) == 0)
515 last_src = *(struct sockaddr *)resp[0]->ai_addr;
517 psnk.psnk_af = resp[0]->ai_family;
520 if (psnk.psnk_af == AF_INET)
521 psnk.psnk_src.addr.v.a.addr.v4 =
522 ((struct sockaddr_in *)resp[0]->ai_addr)->sin_addr;
523 else if (psnk.psnk_af == AF_INET6)
524 psnk.psnk_src.addr.v.a.addr.v6 =
525 ((struct sockaddr_in6 *)resp[0]->ai_addr)->
528 errx(1, "Unknown address family %d", psnk.psnk_af);
530 if (src_node_killers > 1) {
532 memset(&psnk.psnk_dst.addr.v.a.mask, 0xff,
533 sizeof(psnk.psnk_dst.addr.v.a.mask));
534 memset(&last_dst, 0xff, sizeof(last_dst));
535 pfctl_addrprefix(src_node_kill[1],
536 &psnk.psnk_dst.addr.v.a.mask);
537 if ((ret_ga = getaddrinfo(src_node_kill[1], NULL, NULL,
539 errx(1, "getaddrinfo: %s",
540 gai_strerror(ret_ga));
543 for (resp[1] = res[1]; resp[1];
544 resp[1] = resp[1]->ai_next) {
545 if (resp[1]->ai_addr == NULL)
547 if (psnk.psnk_af != resp[1]->ai_family)
550 if (memcmp(&last_dst, resp[1]->ai_addr,
551 sizeof(last_dst)) == 0)
553 last_dst = *(struct sockaddr *)resp[1]->ai_addr;
557 if (psnk.psnk_af == AF_INET)
558 psnk.psnk_dst.addr.v.a.addr.v4 =
559 ((struct sockaddr_in *)resp[1]->
561 else if (psnk.psnk_af == AF_INET6)
562 psnk.psnk_dst.addr.v.a.addr.v6 =
563 ((struct sockaddr_in6 *)resp[1]->
566 errx(1, "Unknown address family %d",
569 if (ioctl(dev, DIOCKILLSRCNODES, &psnk))
570 err(1, "DIOCKILLSRCNODES");
571 killed += psnk.psnk_killed;
573 freeaddrinfo(res[1]);
575 if (ioctl(dev, DIOCKILLSRCNODES, &psnk))
576 err(1, "DIOCKILLSRCNODES");
577 killed += psnk.psnk_killed;
581 freeaddrinfo(res[0]);
583 if ((opts & PF_OPT_QUIET) == 0)
584 fprintf(stderr, "killed %d src nodes from %d sources and %d "
585 "destinations\n", killed, sources, dests);
590 pfctl_net_kill_states(int dev, const char *iface, int opts)
592 struct pfioc_state_kill psk;
593 struct addrinfo *res[2], *resp[2];
594 struct sockaddr last_src, last_dst;
595 int killed, sources, dests;
598 killed = sources = dests = 0;
600 memset(&psk, 0, sizeof(psk));
601 memset(&psk.psk_src.addr.v.a.mask, 0xff,
602 sizeof(psk.psk_src.addr.v.a.mask));
603 memset(&last_src, 0xff, sizeof(last_src));
604 memset(&last_dst, 0xff, sizeof(last_dst));
605 if (iface != NULL && strlcpy(psk.psk_ifname, iface,
606 sizeof(psk.psk_ifname)) >= sizeof(psk.psk_ifname))
607 errx(1, "invalid interface: %s", iface);
609 pfctl_addrprefix(state_kill[0], &psk.psk_src.addr.v.a.mask);
611 if ((ret_ga = getaddrinfo(state_kill[0], NULL, NULL, &res[0]))) {
612 errx(1, "getaddrinfo: %s", gai_strerror(ret_ga));
615 for (resp[0] = res[0]; resp[0]; resp[0] = resp[0]->ai_next) {
616 if (resp[0]->ai_addr == NULL)
618 /* We get lots of duplicates. Catch the easy ones */
619 if (memcmp(&last_src, resp[0]->ai_addr, sizeof(last_src)) == 0)
621 last_src = *(struct sockaddr *)resp[0]->ai_addr;
623 psk.psk_af = resp[0]->ai_family;
626 if (psk.psk_af == AF_INET)
627 psk.psk_src.addr.v.a.addr.v4 =
628 ((struct sockaddr_in *)resp[0]->ai_addr)->sin_addr;
629 else if (psk.psk_af == AF_INET6)
630 psk.psk_src.addr.v.a.addr.v6 =
631 ((struct sockaddr_in6 *)resp[0]->ai_addr)->
634 errx(1, "Unknown address family %d", psk.psk_af);
636 if (state_killers > 1) {
638 memset(&psk.psk_dst.addr.v.a.mask, 0xff,
639 sizeof(psk.psk_dst.addr.v.a.mask));
640 memset(&last_dst, 0xff, sizeof(last_dst));
641 pfctl_addrprefix(state_kill[1],
642 &psk.psk_dst.addr.v.a.mask);
643 if ((ret_ga = getaddrinfo(state_kill[1], NULL, NULL,
645 errx(1, "getaddrinfo: %s",
646 gai_strerror(ret_ga));
649 for (resp[1] = res[1]; resp[1];
650 resp[1] = resp[1]->ai_next) {
651 if (resp[1]->ai_addr == NULL)
653 if (psk.psk_af != resp[1]->ai_family)
656 if (memcmp(&last_dst, resp[1]->ai_addr,
657 sizeof(last_dst)) == 0)
659 last_dst = *(struct sockaddr *)resp[1]->ai_addr;
663 if (psk.psk_af == AF_INET)
664 psk.psk_dst.addr.v.a.addr.v4 =
665 ((struct sockaddr_in *)resp[1]->
667 else if (psk.psk_af == AF_INET6)
668 psk.psk_dst.addr.v.a.addr.v6 =
669 ((struct sockaddr_in6 *)resp[1]->
672 errx(1, "Unknown address family %d",
675 if (ioctl(dev, DIOCKILLSTATES, &psk))
676 err(1, "DIOCKILLSTATES");
677 killed += psk.psk_killed;
679 freeaddrinfo(res[1]);
681 if (ioctl(dev, DIOCKILLSTATES, &psk))
682 err(1, "DIOCKILLSTATES");
683 killed += psk.psk_killed;
687 freeaddrinfo(res[0]);
689 if ((opts & PF_OPT_QUIET) == 0)
690 fprintf(stderr, "killed %d states from %d sources and %d "
691 "destinations\n", killed, sources, dests);
696 pfctl_label_kill_states(int dev, const char *iface, int opts)
698 struct pfioc_state_kill psk;
700 if (state_killers != 2 || (strlen(state_kill[1]) == 0)) {
701 warnx("no label specified");
704 memset(&psk, 0, sizeof(psk));
705 if (iface != NULL && strlcpy(psk.psk_ifname, iface,
706 sizeof(psk.psk_ifname)) >= sizeof(psk.psk_ifname))
707 errx(1, "invalid interface: %s", iface);
709 if (strlcpy(psk.psk_label, state_kill[1], sizeof(psk.psk_label)) >=
710 sizeof(psk.psk_label))
711 errx(1, "label too long: %s", state_kill[1]);
713 if (ioctl(dev, DIOCKILLSTATES, &psk))
714 err(1, "DIOCKILLSTATES");
716 if ((opts & PF_OPT_QUIET) == 0)
717 fprintf(stderr, "killed %d states\n", psk.psk_killed);
723 pfctl_id_kill_states(int dev, const char *iface, int opts)
725 struct pfioc_state_kill psk;
727 if (state_killers != 2 || (strlen(state_kill[1]) == 0)) {
728 warnx("no id specified");
732 memset(&psk, 0, sizeof(psk));
733 if ((sscanf(state_kill[1], "%jx/%x",
734 &psk.psk_pfcmp.id, &psk.psk_pfcmp.creatorid)) == 2)
735 HTONL(psk.psk_pfcmp.creatorid);
736 else if ((sscanf(state_kill[1], "%jx", &psk.psk_pfcmp.id)) == 1) {
737 psk.psk_pfcmp.creatorid = 0;
739 warnx("wrong id format specified");
742 if (psk.psk_pfcmp.id == 0) {
743 warnx("cannot kill id 0");
747 psk.psk_pfcmp.id = htobe64(psk.psk_pfcmp.id);
748 if (ioctl(dev, DIOCKILLSTATES, &psk))
749 err(1, "DIOCKILLSTATES");
751 if ((opts & PF_OPT_QUIET) == 0)
752 fprintf(stderr, "killed %d states\n", psk.psk_killed);
758 pfctl_get_pool(int dev, struct pf_pool *pool, u_int32_t nr,
759 u_int32_t ticket, int r_action, char *anchorname)
761 struct pfioc_pooladdr pp;
762 struct pf_pooladdr *pa;
765 memset(&pp, 0, sizeof(pp));
766 memcpy(pp.anchor, anchorname, sizeof(pp.anchor));
767 pp.r_action = r_action;
770 if (ioctl(dev, DIOCGETADDRS, &pp)) {
771 warn("DIOCGETADDRS");
775 TAILQ_INIT(&pool->list);
776 for (pnr = 0; pnr < mpnr; ++pnr) {
778 if (ioctl(dev, DIOCGETADDR, &pp)) {
782 pa = calloc(1, sizeof(struct pf_pooladdr));
785 bcopy(&pp.addr, pa, sizeof(struct pf_pooladdr));
786 TAILQ_INSERT_TAIL(&pool->list, pa, entries);
793 pfctl_move_pool(struct pf_pool *src, struct pf_pool *dst)
795 struct pf_pooladdr *pa;
797 while ((pa = TAILQ_FIRST(&src->list)) != NULL) {
798 TAILQ_REMOVE(&src->list, pa, entries);
799 TAILQ_INSERT_TAIL(&dst->list, pa, entries);
804 pfctl_clear_pool(struct pf_pool *pool)
806 struct pf_pooladdr *pa;
808 while ((pa = TAILQ_FIRST(&pool->list)) != NULL) {
809 TAILQ_REMOVE(&pool->list, pa, entries);
815 pfctl_print_rule_counters(struct pf_rule *rule, int opts)
817 if (opts & PF_OPT_DEBUG) {
818 const char *t[PF_SKIP_COUNT] = { "i", "d", "f",
819 "p", "sa", "sp", "da", "dp" };
822 printf(" [ Skip steps: ");
823 for (i = 0; i < PF_SKIP_COUNT; ++i) {
824 if (rule->skip[i].nr == rule->nr + 1)
827 if (rule->skip[i].nr == -1)
830 printf("%u ", rule->skip[i].nr);
834 printf(" [ queue: qname=%s qid=%u pqname=%s pqid=%u ]\n",
835 rule->qname, rule->qid, rule->pqname, rule->pqid);
837 if (opts & PF_OPT_VERBOSE) {
838 printf(" [ Evaluations: %-8llu Packets: %-8llu "
839 "Bytes: %-10llu States: %-6ju]\n",
840 (unsigned long long)rule->evaluations,
841 (unsigned long long)(rule->packets[0] +
843 (unsigned long long)(rule->bytes[0] +
844 rule->bytes[1]), (uintmax_t)rule->u_states_cur);
845 if (!(opts & PF_OPT_DEBUG))
846 printf(" [ Inserted: uid %u pid %u "
847 "State Creations: %-6ju]\n",
848 (unsigned)rule->cuid, (unsigned)rule->cpid,
849 (uintmax_t)rule->u_states_tot);
854 pfctl_print_title(char *title)
859 printf("%s\n", title);
863 pfctl_show_rules(int dev, char *path, int opts, enum pfctl_show format,
864 char *anchorname, int depth)
866 struct pfioc_rule pr;
867 u_int32_t nr, mnr, header = 0;
868 int rule_numbers = opts & (PF_OPT_VERBOSE2 | PF_OPT_DEBUG);
869 int numeric = opts & PF_OPT_NUMERIC;
870 int len = strlen(path);
875 snprintf(&path[len], MAXPATHLEN - len, "/%s", anchorname);
877 snprintf(&path[len], MAXPATHLEN - len, "%s", anchorname);
879 memset(&pr, 0, sizeof(pr));
880 memcpy(pr.anchor, path, sizeof(pr.anchor));
881 if (opts & PF_OPT_SHOWALL) {
882 pr.rule.action = PF_PASS;
883 if (ioctl(dev, DIOCGETRULES, &pr)) {
884 warn("DIOCGETRULES");
889 pr.rule.action = PF_SCRUB;
890 if (ioctl(dev, DIOCGETRULES, &pr)) {
891 warn("DIOCGETRULES");
894 if (opts & PF_OPT_SHOWALL) {
895 if (format == PFCTL_SHOW_RULES && (pr.nr > 0 || header))
896 pfctl_print_title("FILTER RULES:");
897 else if (format == PFCTL_SHOW_LABELS && labels)
898 pfctl_print_title("LABEL COUNTERS:");
901 if (opts & PF_OPT_CLRRULECTRS)
902 pr.action = PF_GET_CLR_CNTR;
904 for (nr = 0; nr < mnr; ++nr) {
906 if (ioctl(dev, DIOCGETRULE, &pr)) {
911 if (pfctl_get_pool(dev, &pr.rule.rpool,
912 nr, pr.ticket, PF_SCRUB, path) != 0)
916 case PFCTL_SHOW_LABELS:
918 case PFCTL_SHOW_RULES:
919 if (pr.rule.label[0] && (opts & PF_OPT_SHOWALL))
921 print_rule(&pr.rule, pr.anchor_call, rule_numbers, numeric);
923 pfctl_print_rule_counters(&pr.rule, opts);
925 case PFCTL_SHOW_NOTHING:
928 pfctl_clear_pool(&pr.rule.rpool);
930 pr.rule.action = PF_PASS;
931 if (ioctl(dev, DIOCGETRULES, &pr)) {
932 warn("DIOCGETRULES");
936 for (nr = 0; nr < mnr; ++nr) {
938 if (ioctl(dev, DIOCGETRULE, &pr)) {
943 if (pfctl_get_pool(dev, &pr.rule.rpool,
944 nr, pr.ticket, PF_PASS, path) != 0)
948 case PFCTL_SHOW_LABELS:
949 if (pr.rule.label[0]) {
950 printf("%s %llu %llu %llu %llu"
951 " %llu %llu %llu %ju\n",
953 (unsigned long long)pr.rule.evaluations,
954 (unsigned long long)(pr.rule.packets[0] +
956 (unsigned long long)(pr.rule.bytes[0] +
958 (unsigned long long)pr.rule.packets[0],
959 (unsigned long long)pr.rule.bytes[0],
960 (unsigned long long)pr.rule.packets[1],
961 (unsigned long long)pr.rule.bytes[1],
962 (uintmax_t)pr.rule.u_states_tot);
965 case PFCTL_SHOW_RULES:
967 if (pr.rule.label[0] && (opts & PF_OPT_SHOWALL))
969 INDENT(depth, !(opts & PF_OPT_VERBOSE));
970 if (pr.anchor_call[0] &&
971 ((((p = strrchr(pr.anchor_call, '_')) != NULL) &&
972 ((void *)p == (void *)pr.anchor_call ||
973 *(--p) == '/')) || (opts & PF_OPT_RECURSE))) {
975 if ((p = strrchr(pr.anchor_call, '/')) !=
979 p = &pr.anchor_call[0];
981 p = &pr.anchor_call[0];
983 print_rule(&pr.rule, p, rule_numbers, numeric);
988 pfctl_print_rule_counters(&pr.rule, opts);
990 pfctl_show_rules(dev, path, opts, format,
992 INDENT(depth, !(opts & PF_OPT_VERBOSE));
996 case PFCTL_SHOW_NOTHING:
999 pfctl_clear_pool(&pr.rule.rpool);
1010 pfctl_show_nat(int dev, int opts, char *anchorname)
1012 struct pfioc_rule pr;
1014 static int nattype[3] = { PF_NAT, PF_RDR, PF_BINAT };
1015 int i, dotitle = opts & PF_OPT_SHOWALL;
1017 memset(&pr, 0, sizeof(pr));
1018 memcpy(pr.anchor, anchorname, sizeof(pr.anchor));
1019 for (i = 0; i < 3; i++) {
1020 pr.rule.action = nattype[i];
1021 if (ioctl(dev, DIOCGETRULES, &pr)) {
1022 warn("DIOCGETRULES");
1026 for (nr = 0; nr < mnr; ++nr) {
1028 if (ioctl(dev, DIOCGETRULE, &pr)) {
1029 warn("DIOCGETRULE");
1032 if (pfctl_get_pool(dev, &pr.rule.rpool, nr,
1033 pr.ticket, nattype[i], anchorname) != 0)
1036 pfctl_print_title("TRANSLATION RULES:");
1039 print_rule(&pr.rule, pr.anchor_call,
1040 opts & PF_OPT_VERBOSE2, opts & PF_OPT_NUMERIC);
1042 pfctl_print_rule_counters(&pr.rule, opts);
1043 pfctl_clear_pool(&pr.rule.rpool);
1050 pfctl_show_src_nodes(int dev, int opts)
1052 struct pfioc_src_nodes psn;
1053 struct pf_src_node *p;
1054 char *inbuf = NULL, *newinbuf = NULL;
1055 unsigned int len = 0;
1058 memset(&psn, 0, sizeof(psn));
1062 newinbuf = realloc(inbuf, len);
1063 if (newinbuf == NULL)
1065 psn.psn_buf = inbuf = newinbuf;
1067 if (ioctl(dev, DIOCGETSRCNODES, &psn) < 0) {
1068 warn("DIOCGETSRCNODES");
1072 if (psn.psn_len + sizeof(struct pfioc_src_nodes) < len)
1074 if (len == 0 && psn.psn_len == 0)
1076 if (len == 0 && psn.psn_len != 0)
1078 if (psn.psn_len == 0)
1079 goto done; /* no src_nodes */
1082 p = psn.psn_src_nodes;
1083 if (psn.psn_len > 0 && (opts & PF_OPT_SHOWALL))
1084 pfctl_print_title("SOURCE TRACKING NODES:");
1085 for (i = 0; i < psn.psn_len; i += sizeof(*p)) {
1086 print_src_node(p, opts);
1095 pfctl_show_states(int dev, const char *iface, int opts)
1097 struct pfioc_states ps;
1098 struct pfsync_state *p;
1099 char *inbuf = NULL, *newinbuf = NULL;
1100 unsigned int len = 0;
1101 int i, dotitle = (opts & PF_OPT_SHOWALL);
1103 memset(&ps, 0, sizeof(ps));
1107 newinbuf = realloc(inbuf, len);
1108 if (newinbuf == NULL)
1110 ps.ps_buf = inbuf = newinbuf;
1112 if (ioctl(dev, DIOCGETSTATES, &ps) < 0) {
1113 warn("DIOCGETSTATES");
1117 if (ps.ps_len + sizeof(struct pfioc_states) < len)
1119 if (len == 0 && ps.ps_len == 0)
1121 if (len == 0 && ps.ps_len != 0)
1124 goto done; /* no states */
1128 for (i = 0; i < ps.ps_len; i += sizeof(*p), p++) {
1129 if (iface != NULL && strcmp(p->ifname, iface))
1132 pfctl_print_title("STATES:");
1135 print_state(p, opts);
1143 pfctl_show_status(int dev, int opts)
1145 struct pf_status status;
1147 if (ioctl(dev, DIOCGETSTATUS, &status)) {
1148 warn("DIOCGETSTATUS");
1151 if (opts & PF_OPT_SHOWALL)
1152 pfctl_print_title("INFO:");
1153 print_status(&status, opts);
1158 pfctl_show_timeouts(int dev, int opts)
1163 if (opts & PF_OPT_SHOWALL)
1164 pfctl_print_title("TIMEOUTS:");
1165 memset(&pt, 0, sizeof(pt));
1166 for (i = 0; pf_timeouts[i].name; i++) {
1167 pt.timeout = pf_timeouts[i].timeout;
1168 if (ioctl(dev, DIOCGETTIMEOUT, &pt))
1169 err(1, "DIOCGETTIMEOUT");
1170 printf("%-20s %10d", pf_timeouts[i].name, pt.seconds);
1171 if (pf_timeouts[i].timeout >= PFTM_ADAPTIVE_START &&
1172 pf_timeouts[i].timeout <= PFTM_ADAPTIVE_END)
1183 pfctl_show_limits(int dev, int opts)
1185 struct pfioc_limit pl;
1188 if (opts & PF_OPT_SHOWALL)
1189 pfctl_print_title("LIMITS:");
1190 memset(&pl, 0, sizeof(pl));
1191 for (i = 0; pf_limits[i].name; i++) {
1192 pl.index = pf_limits[i].index;
1193 if (ioctl(dev, DIOCGETLIMIT, &pl))
1194 err(1, "DIOCGETLIMIT");
1195 printf("%-13s ", pf_limits[i].name);
1196 if (pl.limit == UINT_MAX)
1197 printf("unlimited\n");
1199 printf("hard limit %8u\n", pl.limit);
1204 /* callbacks for rule/nat/rdr/addr */
1206 pfctl_add_pool(struct pfctl *pf, struct pf_pool *p, sa_family_t af)
1208 struct pf_pooladdr *pa;
1210 if ((pf->opts & PF_OPT_NOACTION) == 0) {
1211 if (ioctl(pf->dev, DIOCBEGINADDRS, &pf->paddr))
1212 err(1, "DIOCBEGINADDRS");
1216 TAILQ_FOREACH(pa, &p->list, entries) {
1217 memcpy(&pf->paddr.addr, pa, sizeof(struct pf_pooladdr));
1218 if ((pf->opts & PF_OPT_NOACTION) == 0) {
1219 if (ioctl(pf->dev, DIOCADDADDR, &pf->paddr))
1220 err(1, "DIOCADDADDR");
1227 pfctl_add_rule(struct pfctl *pf, struct pf_rule *r, const char *anchor_call)
1230 struct pf_rule *rule;
1231 struct pf_ruleset *rs;
1234 rs_num = pf_get_ruleset_number(r->action);
1235 if (rs_num == PF_RULESET_MAX)
1236 errx(1, "Invalid rule type %d", r->action);
1238 rs = &pf->anchor->ruleset;
1240 if (anchor_call[0] && r->anchor == NULL) {
1242 * Don't make non-brace anchors part of the main anchor pool.
1244 if ((r->anchor = calloc(1, sizeof(*r->anchor))) == NULL)
1245 err(1, "pfctl_add_rule: calloc");
1247 pf_init_ruleset(&r->anchor->ruleset);
1248 r->anchor->ruleset.anchor = r->anchor;
1249 if (strlcpy(r->anchor->path, anchor_call,
1250 sizeof(rule->anchor->path)) >= sizeof(rule->anchor->path))
1251 errx(1, "pfctl_add_rule: strlcpy");
1252 if ((p = strrchr(anchor_call, '/')) != NULL) {
1254 err(1, "pfctl_add_rule: bad anchor name %s",
1257 p = (char *)anchor_call;
1258 if (strlcpy(r->anchor->name, p,
1259 sizeof(rule->anchor->name)) >= sizeof(rule->anchor->name))
1260 errx(1, "pfctl_add_rule: strlcpy");
1263 if ((rule = calloc(1, sizeof(*rule))) == NULL)
1265 bcopy(r, rule, sizeof(*rule));
1266 TAILQ_INIT(&rule->rpool.list);
1267 pfctl_move_pool(&r->rpool, &rule->rpool);
1269 TAILQ_INSERT_TAIL(rs->rules[rs_num].active.ptr, rule, entries);
1274 pfctl_ruleset_trans(struct pfctl *pf, char *path, struct pf_anchor *a)
1276 int osize = pf->trans->pfrb_size;
1278 if ((pf->loadopt & PFCTL_FLAG_NAT) != 0) {
1279 if (pfctl_add_trans(pf->trans, PF_RULESET_NAT, path) ||
1280 pfctl_add_trans(pf->trans, PF_RULESET_BINAT, path) ||
1281 pfctl_add_trans(pf->trans, PF_RULESET_RDR, path))
1284 if (a == pf->astack[0] && ((altqsupport &&
1285 (pf->loadopt & PFCTL_FLAG_ALTQ) != 0))) {
1286 if (pfctl_add_trans(pf->trans, PF_RULESET_ALTQ, path))
1289 if ((pf->loadopt & PFCTL_FLAG_FILTER) != 0) {
1290 if (pfctl_add_trans(pf->trans, PF_RULESET_SCRUB, path) ||
1291 pfctl_add_trans(pf->trans, PF_RULESET_FILTER, path))
1294 if (pf->loadopt & PFCTL_FLAG_TABLE)
1295 if (pfctl_add_trans(pf->trans, PF_RULESET_TABLE, path))
1297 if (pfctl_trans(pf->dev, pf->trans, DIOCXBEGIN, osize))
1304 pfctl_load_ruleset(struct pfctl *pf, char *path, struct pf_ruleset *rs,
1305 int rs_num, int depth)
1308 int error, len = strlen(path);
1311 pf->anchor = rs->anchor;
1314 snprintf(&path[len], MAXPATHLEN - len, "/%s", pf->anchor->name);
1316 snprintf(&path[len], MAXPATHLEN - len, "%s", pf->anchor->name);
1319 if (TAILQ_FIRST(rs->rules[rs_num].active.ptr) != NULL) {
1321 if (pf->opts & PF_OPT_VERBOSE)
1323 if ((pf->opts & PF_OPT_NOACTION) == 0 &&
1324 (error = pfctl_ruleset_trans(pf,
1325 path, rs->anchor))) {
1326 printf("pfctl_load_rulesets: "
1327 "pfctl_ruleset_trans %d\n", error);
1330 } else if (pf->opts & PF_OPT_VERBOSE)
1335 if (pf->optimize && rs_num == PF_RULESET_FILTER)
1336 pfctl_optimize_ruleset(pf, rs);
1338 while ((r = TAILQ_FIRST(rs->rules[rs_num].active.ptr)) != NULL) {
1339 TAILQ_REMOVE(rs->rules[rs_num].active.ptr, r, entries);
1340 if ((error = pfctl_load_rule(pf, path, r, depth)))
1343 if ((error = pfctl_load_ruleset(pf, path,
1344 &r->anchor->ruleset, rs_num, depth + 1)))
1346 } else if (pf->opts & PF_OPT_VERBOSE)
1350 if (brace && pf->opts & PF_OPT_VERBOSE) {
1351 INDENT(depth - 1, (pf->opts & PF_OPT_VERBOSE));
1364 pfctl_load_rule(struct pfctl *pf, char *path, struct pf_rule *r, int depth)
1366 u_int8_t rs_num = pf_get_ruleset_number(r->action);
1368 struct pfioc_rule pr;
1369 int len = strlen(path);
1371 bzero(&pr, sizeof(pr));
1372 /* set up anchor before adding to path for anchor_call */
1373 if ((pf->opts & PF_OPT_NOACTION) == 0)
1374 pr.ticket = pfctl_get_ticket(pf->trans, rs_num, path);
1375 if (strlcpy(pr.anchor, path, sizeof(pr.anchor)) >= sizeof(pr.anchor))
1376 errx(1, "pfctl_load_rule: strlcpy");
1379 if (r->anchor->match) {
1381 snprintf(&path[len], MAXPATHLEN - len,
1382 "/%s", r->anchor->name);
1384 snprintf(&path[len], MAXPATHLEN - len,
1385 "%s", r->anchor->name);
1386 name = r->anchor->name;
1388 name = r->anchor->path;
1392 if ((pf->opts & PF_OPT_NOACTION) == 0) {
1393 if (pfctl_add_pool(pf, &r->rpool, r->af))
1395 pr.pool_ticket = pf->paddr.ticket;
1396 memcpy(&pr.rule, r, sizeof(pr.rule));
1397 if (r->anchor && strlcpy(pr.anchor_call, name,
1398 sizeof(pr.anchor_call)) >= sizeof(pr.anchor_call))
1399 errx(1, "pfctl_load_rule: strlcpy");
1400 if (ioctl(pf->dev, DIOCADDRULE, &pr))
1401 err(1, "DIOCADDRULE");
1404 if (pf->opts & PF_OPT_VERBOSE) {
1405 INDENT(depth, !(pf->opts & PF_OPT_VERBOSE2));
1406 print_rule(r, r->anchor ? r->anchor->name : "",
1407 pf->opts & PF_OPT_VERBOSE2,
1408 pf->opts & PF_OPT_NUMERIC);
1411 pfctl_clear_pool(&r->rpool);
1416 pfctl_add_altq(struct pfctl *pf, struct pf_altq *a)
1419 (loadopt & PFCTL_FLAG_ALTQ) != 0) {
1420 memcpy(&pf->paltq->altq, a, sizeof(struct pf_altq));
1421 if ((pf->opts & PF_OPT_NOACTION) == 0) {
1422 if (ioctl(pf->dev, DIOCADDALTQ, pf->paltq)) {
1424 errx(1, "qtype not configured");
1425 else if (errno == ENODEV)
1426 errx(1, "%s: driver does not support "
1429 err(1, "DIOCADDALTQ");
1432 pfaltq_store(&pf->paltq->altq);
1438 pfctl_rules(int dev, char *filename, int opts, int optimize,
1439 char *anchorname, struct pfr_buffer *trans)
1441 #define ERR(x) do { warn(x); goto _error; } while(0)
1442 #define ERRX(x) do { warnx(x); goto _error; } while(0)
1444 struct pfr_buffer *t, buf;
1445 struct pfioc_altq pa;
1447 struct pf_ruleset *rs;
1448 struct pfr_table trs;
1452 RB_INIT(&pf_anchors);
1453 memset(&pf_main_anchor, 0, sizeof(pf_main_anchor));
1454 pf_init_ruleset(&pf_main_anchor.ruleset);
1455 pf_main_anchor.ruleset.anchor = &pf_main_anchor;
1456 if (trans == NULL) {
1457 bzero(&buf, sizeof(buf));
1458 buf.pfrb_type = PFRB_TRANS;
1463 osize = t->pfrb_size;
1466 memset(&pa, 0, sizeof(pa));
1467 memset(&pf, 0, sizeof(pf));
1468 memset(&trs, 0, sizeof(trs));
1469 if ((path = calloc(1, MAXPATHLEN)) == NULL)
1470 ERRX("pfctl_rules: calloc");
1471 if (strlcpy(trs.pfrt_anchor, anchorname,
1472 sizeof(trs.pfrt_anchor)) >= sizeof(trs.pfrt_anchor))
1473 ERRX("pfctl_rules: strlcpy");
1476 pf.optimize = optimize;
1477 pf.loadopt = loadopt;
1479 /* non-brace anchor, create without resolving the path */
1480 if ((pf.anchor = calloc(1, sizeof(*pf.anchor))) == NULL)
1481 ERRX("pfctl_rules: calloc");
1482 rs = &pf.anchor->ruleset;
1483 pf_init_ruleset(rs);
1484 rs->anchor = pf.anchor;
1485 if (strlcpy(pf.anchor->path, anchorname,
1486 sizeof(pf.anchor->path)) >= sizeof(pf.anchor->path))
1487 errx(1, "pfctl_add_rule: strlcpy");
1488 if (strlcpy(pf.anchor->name, anchorname,
1489 sizeof(pf.anchor->name)) >= sizeof(pf.anchor->name))
1490 errx(1, "pfctl_add_rule: strlcpy");
1493 pf.astack[0] = pf.anchor;
1496 pf.loadopt &= ~PFCTL_FLAG_ALTQ;
1499 pfctl_init_options(&pf);
1501 if ((opts & PF_OPT_NOACTION) == 0) {
1503 * XXX For the time being we need to open transactions for
1504 * the main ruleset before parsing, because tables are still
1505 * loaded at parse time.
1507 if (pfctl_ruleset_trans(&pf, anchorname, pf.anchor))
1508 ERRX("pfctl_rules");
1509 if (altqsupport && (pf.loadopt & PFCTL_FLAG_ALTQ))
1511 pfctl_get_ticket(t, PF_RULESET_ALTQ, anchorname);
1512 if (pf.loadopt & PFCTL_FLAG_TABLE)
1513 pf.astack[0]->ruleset.tticket =
1514 pfctl_get_ticket(t, PF_RULESET_TABLE, anchorname);
1517 if (parse_config(filename, &pf) < 0) {
1518 if ((opts & PF_OPT_NOACTION) == 0)
1519 ERRX("Syntax error in config file: "
1520 "pf rules not loaded");
1524 if (loadopt & PFCTL_FLAG_OPTION)
1525 pfctl_clear_skip_ifaces(&pf);
1527 if ((pf.loadopt & PFCTL_FLAG_FILTER &&
1528 (pfctl_load_ruleset(&pf, path, rs, PF_RULESET_SCRUB, 0))) ||
1529 (pf.loadopt & PFCTL_FLAG_NAT &&
1530 (pfctl_load_ruleset(&pf, path, rs, PF_RULESET_NAT, 0) ||
1531 pfctl_load_ruleset(&pf, path, rs, PF_RULESET_RDR, 0) ||
1532 pfctl_load_ruleset(&pf, path, rs, PF_RULESET_BINAT, 0))) ||
1533 (pf.loadopt & PFCTL_FLAG_FILTER &&
1534 pfctl_load_ruleset(&pf, path, rs, PF_RULESET_FILTER, 0))) {
1535 if ((opts & PF_OPT_NOACTION) == 0)
1536 ERRX("Unable to load rules into kernel");
1541 if ((altqsupport && (pf.loadopt & PFCTL_FLAG_ALTQ) != 0))
1542 if (check_commit_altq(dev, opts) != 0)
1543 ERRX("errors in altq config");
1545 /* process "load anchor" directives */
1547 if (pfctl_load_anchors(dev, &pf, t) == -1)
1548 ERRX("load anchors");
1550 if (trans == NULL && (opts & PF_OPT_NOACTION) == 0) {
1552 if (pfctl_load_options(&pf))
1554 if (pfctl_trans(dev, t, DIOCXCOMMIT, osize))
1561 if (trans == NULL) { /* main ruleset */
1562 if ((opts & PF_OPT_NOACTION) == 0)
1563 if (pfctl_trans(dev, t, DIOCXROLLBACK, osize))
1564 err(1, "DIOCXROLLBACK");
1566 } else { /* sub ruleset */
1576 pfctl_fopen(const char *name, const char *mode)
1581 fp = fopen(name, mode);
1584 if (fstat(fileno(fp), &st)) {
1588 if (S_ISDIR(st.st_mode)) {
1597 pfctl_init_options(struct pfctl *pf)
1600 pf->timeout[PFTM_TCP_FIRST_PACKET] = PFTM_TCP_FIRST_PACKET_VAL;
1601 pf->timeout[PFTM_TCP_OPENING] = PFTM_TCP_OPENING_VAL;
1602 pf->timeout[PFTM_TCP_ESTABLISHED] = PFTM_TCP_ESTABLISHED_VAL;
1603 pf->timeout[PFTM_TCP_CLOSING] = PFTM_TCP_CLOSING_VAL;
1604 pf->timeout[PFTM_TCP_FIN_WAIT] = PFTM_TCP_FIN_WAIT_VAL;
1605 pf->timeout[PFTM_TCP_CLOSED] = PFTM_TCP_CLOSED_VAL;
1606 pf->timeout[PFTM_UDP_FIRST_PACKET] = PFTM_UDP_FIRST_PACKET_VAL;
1607 pf->timeout[PFTM_UDP_SINGLE] = PFTM_UDP_SINGLE_VAL;
1608 pf->timeout[PFTM_UDP_MULTIPLE] = PFTM_UDP_MULTIPLE_VAL;
1609 pf->timeout[PFTM_ICMP_FIRST_PACKET] = PFTM_ICMP_FIRST_PACKET_VAL;
1610 pf->timeout[PFTM_ICMP_ERROR_REPLY] = PFTM_ICMP_ERROR_REPLY_VAL;
1611 pf->timeout[PFTM_OTHER_FIRST_PACKET] = PFTM_OTHER_FIRST_PACKET_VAL;
1612 pf->timeout[PFTM_OTHER_SINGLE] = PFTM_OTHER_SINGLE_VAL;
1613 pf->timeout[PFTM_OTHER_MULTIPLE] = PFTM_OTHER_MULTIPLE_VAL;
1614 pf->timeout[PFTM_FRAG] = PFTM_FRAG_VAL;
1615 pf->timeout[PFTM_INTERVAL] = PFTM_INTERVAL_VAL;
1616 pf->timeout[PFTM_SRC_NODE] = PFTM_SRC_NODE_VAL;
1617 pf->timeout[PFTM_TS_DIFF] = PFTM_TS_DIFF_VAL;
1618 pf->timeout[PFTM_ADAPTIVE_START] = PFSTATE_ADAPT_START;
1619 pf->timeout[PFTM_ADAPTIVE_END] = PFSTATE_ADAPT_END;
1621 pf->limit[PF_LIMIT_STATES] = PFSTATE_HIWAT;
1622 pf->limit[PF_LIMIT_FRAGS] = PFFRAG_FRENT_HIWAT;
1623 pf->limit[PF_LIMIT_SRC_NODES] = PFSNODE_HIWAT;
1624 pf->limit[PF_LIMIT_TABLE_ENTRIES] = PFR_KENTRY_HIWAT;
1626 pf->debug = PF_DEBUG_URGENT;
1630 pfctl_load_options(struct pfctl *pf)
1634 if ((loadopt & PFCTL_FLAG_OPTION) == 0)
1638 for (i = 0; i < PF_LIMIT_MAX; i++) {
1639 if ((pf->opts & PF_OPT_MERGE) && !pf->limit_set[i])
1641 if (pfctl_load_limit(pf, i, pf->limit[i]))
1646 * If we've set the limit, but haven't explicitly set adaptive
1647 * timeouts, do it now with a start of 60% and end of 120%.
1649 if (pf->limit_set[PF_LIMIT_STATES] &&
1650 !pf->timeout_set[PFTM_ADAPTIVE_START] &&
1651 !pf->timeout_set[PFTM_ADAPTIVE_END]) {
1652 pf->timeout[PFTM_ADAPTIVE_START] =
1653 (pf->limit[PF_LIMIT_STATES] / 10) * 6;
1654 pf->timeout_set[PFTM_ADAPTIVE_START] = 1;
1655 pf->timeout[PFTM_ADAPTIVE_END] =
1656 (pf->limit[PF_LIMIT_STATES] / 10) * 12;
1657 pf->timeout_set[PFTM_ADAPTIVE_END] = 1;
1661 for (i = 0; i < PFTM_MAX; i++) {
1662 if ((pf->opts & PF_OPT_MERGE) && !pf->timeout_set[i])
1664 if (pfctl_load_timeout(pf, i, pf->timeout[i]))
1669 if (!(pf->opts & PF_OPT_MERGE) || pf->debug_set)
1670 if (pfctl_load_debug(pf, pf->debug))
1674 if (!(pf->opts & PF_OPT_MERGE) || pf->ifname_set)
1675 if (pfctl_load_logif(pf, pf->ifname))
1679 if (!(pf->opts & PF_OPT_MERGE) || pf->hostid_set)
1680 if (pfctl_load_hostid(pf, pf->hostid))
1687 pfctl_set_limit(struct pfctl *pf, const char *opt, unsigned int limit)
1692 for (i = 0; pf_limits[i].name; i++) {
1693 if (strcasecmp(opt, pf_limits[i].name) == 0) {
1694 pf->limit[pf_limits[i].index] = limit;
1695 pf->limit_set[pf_limits[i].index] = 1;
1699 if (pf_limits[i].name == NULL) {
1700 warnx("Bad pool name.");
1704 if (pf->opts & PF_OPT_VERBOSE)
1705 printf("set limit %s %d\n", opt, limit);
1711 pfctl_load_limit(struct pfctl *pf, unsigned int index, unsigned int limit)
1713 struct pfioc_limit pl;
1715 memset(&pl, 0, sizeof(pl));
1718 if (ioctl(pf->dev, DIOCSETLIMIT, &pl)) {
1720 warnx("Current pool size exceeds requested hard limit");
1722 warnx("DIOCSETLIMIT");
1729 pfctl_set_timeout(struct pfctl *pf, const char *opt, int seconds, int quiet)
1733 if ((loadopt & PFCTL_FLAG_OPTION) == 0)
1736 for (i = 0; pf_timeouts[i].name; i++) {
1737 if (strcasecmp(opt, pf_timeouts[i].name) == 0) {
1738 pf->timeout[pf_timeouts[i].timeout] = seconds;
1739 pf->timeout_set[pf_timeouts[i].timeout] = 1;
1744 if (pf_timeouts[i].name == NULL) {
1745 warnx("Bad timeout name.");
1750 if (pf->opts & PF_OPT_VERBOSE && ! quiet)
1751 printf("set timeout %s %d\n", opt, seconds);
1757 pfctl_load_timeout(struct pfctl *pf, unsigned int timeout, unsigned int seconds)
1761 memset(&pt, 0, sizeof(pt));
1762 pt.timeout = timeout;
1763 pt.seconds = seconds;
1764 if (ioctl(pf->dev, DIOCSETTIMEOUT, &pt)) {
1765 warnx("DIOCSETTIMEOUT");
1772 pfctl_set_optimization(struct pfctl *pf, const char *opt)
1774 const struct pf_hint *hint;
1777 if ((loadopt & PFCTL_FLAG_OPTION) == 0)
1780 for (i = 0; pf_hints[i].name; i++)
1781 if (strcasecmp(opt, pf_hints[i].name) == 0)
1784 hint = pf_hints[i].hint;
1786 warnx("invalid state timeouts optimization");
1790 for (i = 0; hint[i].name; i++)
1791 if ((r = pfctl_set_timeout(pf, hint[i].name,
1792 hint[i].timeout, 1)))
1795 if (pf->opts & PF_OPT_VERBOSE)
1796 printf("set optimization %s\n", opt);
1802 pfctl_set_logif(struct pfctl *pf, char *ifname)
1805 if ((loadopt & PFCTL_FLAG_OPTION) == 0)
1808 if (!strcmp(ifname, "none")) {
1812 pf->ifname = strdup(ifname);
1814 errx(1, "pfctl_set_logif: strdup");
1818 if (pf->opts & PF_OPT_VERBOSE)
1819 printf("set loginterface %s\n", ifname);
1825 pfctl_load_logif(struct pfctl *pf, char *ifname)
1829 memset(&pi, 0, sizeof(pi));
1830 if (ifname && strlcpy(pi.ifname, ifname,
1831 sizeof(pi.ifname)) >= sizeof(pi.ifname)) {
1832 warnx("pfctl_load_logif: strlcpy");
1835 if (ioctl(pf->dev, DIOCSETSTATUSIF, &pi)) {
1836 warnx("DIOCSETSTATUSIF");
1843 pfctl_set_hostid(struct pfctl *pf, u_int32_t hostid)
1845 if ((loadopt & PFCTL_FLAG_OPTION) == 0)
1850 pf->hostid = hostid;
1853 if (pf->opts & PF_OPT_VERBOSE)
1854 printf("set hostid 0x%08x\n", ntohl(hostid));
1860 pfctl_load_hostid(struct pfctl *pf, u_int32_t hostid)
1862 if (ioctl(dev, DIOCSETHOSTID, &hostid)) {
1863 warnx("DIOCSETHOSTID");
1870 pfctl_set_debug(struct pfctl *pf, char *d)
1874 if ((loadopt & PFCTL_FLAG_OPTION) == 0)
1877 if (!strcmp(d, "none"))
1878 pf->debug = PF_DEBUG_NONE;
1879 else if (!strcmp(d, "urgent"))
1880 pf->debug = PF_DEBUG_URGENT;
1881 else if (!strcmp(d, "misc"))
1882 pf->debug = PF_DEBUG_MISC;
1883 else if (!strcmp(d, "loud"))
1884 pf->debug = PF_DEBUG_NOISY;
1886 warnx("unknown debug level \"%s\"", d);
1893 if ((pf->opts & PF_OPT_NOACTION) == 0)
1894 if (ioctl(dev, DIOCSETDEBUG, &level))
1895 err(1, "DIOCSETDEBUG");
1897 if (pf->opts & PF_OPT_VERBOSE)
1898 printf("set debug %s\n", d);
1904 pfctl_load_debug(struct pfctl *pf, unsigned int level)
1906 if (ioctl(pf->dev, DIOCSETDEBUG, &level)) {
1907 warnx("DIOCSETDEBUG");
1914 pfctl_set_interface_flags(struct pfctl *pf, char *ifname, int flags, int how)
1916 struct pfioc_iface pi;
1918 if ((loadopt & PFCTL_FLAG_OPTION) == 0)
1921 bzero(&pi, sizeof(pi));
1923 pi.pfiio_flags = flags;
1925 if (strlcpy(pi.pfiio_name, ifname, sizeof(pi.pfiio_name)) >=
1926 sizeof(pi.pfiio_name))
1927 errx(1, "pfctl_set_interface_flags: strlcpy");
1929 if ((pf->opts & PF_OPT_NOACTION) == 0) {
1931 if (ioctl(pf->dev, DIOCCLRIFFLAG, &pi))
1932 err(1, "DIOCCLRIFFLAG");
1934 if (ioctl(pf->dev, DIOCSETIFFLAG, &pi))
1935 err(1, "DIOCSETIFFLAG");
1936 pfctl_check_skip_ifaces(ifname);
1943 pfctl_debug(int dev, u_int32_t level, int opts)
1945 if (ioctl(dev, DIOCSETDEBUG, &level))
1946 err(1, "DIOCSETDEBUG");
1947 if ((opts & PF_OPT_QUIET) == 0) {
1948 fprintf(stderr, "debug level set to '");
1951 fprintf(stderr, "none");
1953 case PF_DEBUG_URGENT:
1954 fprintf(stderr, "urgent");
1957 fprintf(stderr, "misc");
1959 case PF_DEBUG_NOISY:
1960 fprintf(stderr, "loud");
1963 fprintf(stderr, "<invalid>");
1966 fprintf(stderr, "'\n");
1971 pfctl_test_altqsupport(int dev, int opts)
1973 struct pfioc_altq pa;
1975 if (ioctl(dev, DIOCGETALTQS, &pa)) {
1976 if (errno == ENODEV) {
1977 if (opts & PF_OPT_VERBOSE)
1978 fprintf(stderr, "No ALTQ support in kernel\n"
1979 "ALTQ related functions disabled\n");
1982 err(1, "DIOCGETALTQS");
1988 pfctl_show_anchors(int dev, int opts, char *anchorname)
1990 struct pfioc_ruleset pr;
1993 memset(&pr, 0, sizeof(pr));
1994 memcpy(pr.path, anchorname, sizeof(pr.path));
1995 if (ioctl(dev, DIOCGETRULESETS, &pr)) {
1996 if (errno == EINVAL)
1997 fprintf(stderr, "Anchor '%s' not found.\n",
2000 err(1, "DIOCGETRULESETS");
2004 for (nr = 0; nr < mnr; ++nr) {
2005 char sub[MAXPATHLEN];
2008 if (ioctl(dev, DIOCGETRULESET, &pr))
2009 err(1, "DIOCGETRULESET");
2010 if (!strcmp(pr.name, PF_RESERVED_ANCHOR))
2014 strlcat(sub, pr.path, sizeof(sub));
2015 strlcat(sub, "/", sizeof(sub));
2017 strlcat(sub, pr.name, sizeof(sub));
2018 if (sub[0] != '_' || (opts & PF_OPT_VERBOSE))
2019 printf(" %s\n", sub);
2020 if ((opts & PF_OPT_VERBOSE) && pfctl_show_anchors(dev, opts, sub))
2027 pfctl_lookup_option(char *cmd, const char * const *list)
2029 if (cmd != NULL && *cmd)
2030 for (; *list; list++)
2031 if (!strncmp(cmd, *list, strlen(cmd)))
2037 main(int argc, char *argv[])
2041 int mode = O_RDONLY;
2043 int optimize = PF_OPTIMIZE_BASIC;
2044 char anchorname[MAXPATHLEN];
2050 while ((ch = getopt(argc, argv,
2051 "a:AdD:eqf:F:ghi:k:K:mnNOo:Pp:rRs:t:T:vx:z")) != -1) {
2057 opts |= PF_OPT_DISABLE;
2061 if (pfctl_cmdline_symset(optarg) < 0)
2062 warnx("could not parse macro definition %s",
2066 opts |= PF_OPT_ENABLE;
2070 opts |= PF_OPT_QUIET;
2073 clearopt = pfctl_lookup_option(optarg, clearopt_list);
2074 if (clearopt == NULL) {
2075 warnx("Unknown flush modifier '%s'", optarg);
2084 if (state_killers >= 2) {
2085 warnx("can only specify -k twice");
2089 state_kill[state_killers++] = optarg;
2093 if (src_node_killers >= 2) {
2094 warnx("can only specify -K twice");
2098 src_node_kill[src_node_killers++] = optarg;
2102 opts |= PF_OPT_MERGE;
2105 opts |= PF_OPT_NOACTION;
2108 loadopt |= PFCTL_FLAG_NAT;
2111 opts |= PF_OPT_USEDNS;
2118 opts |= PF_OPT_DEBUG;
2121 loadopt |= PFCTL_FLAG_ALTQ;
2124 loadopt |= PFCTL_FLAG_FILTER;
2127 optiopt = pfctl_lookup_option(optarg, optiopt_list);
2128 if (optiopt == NULL) {
2129 warnx("Unknown optimization '%s'", optarg);
2132 opts |= PF_OPT_OPTIMIZE;
2135 loadopt |= PFCTL_FLAG_OPTION;
2141 opts |= PF_OPT_NUMERIC;
2144 showopt = pfctl_lookup_option(optarg, showopt_list);
2145 if (showopt == NULL) {
2146 warnx("Unknown show modifier '%s'", optarg);
2154 tblcmdopt = pfctl_lookup_option(optarg, tblcmdopt_list);
2155 if (tblcmdopt == NULL) {
2156 warnx("Unknown table command '%s'", optarg);
2161 if (opts & PF_OPT_VERBOSE)
2162 opts |= PF_OPT_VERBOSE2;
2163 opts |= PF_OPT_VERBOSE;
2166 debugopt = pfctl_lookup_option(optarg, debugopt_list);
2167 if (debugopt == NULL) {
2168 warnx("Unknown debug level '%s'", optarg);
2174 opts |= PF_OPT_CLRRULECTRS;
2185 if (tblcmdopt != NULL) {
2190 loadopt |= PFCTL_FLAG_TABLE;
2193 mode = strchr("acdefkrz", ch) ? O_RDWR : O_RDONLY;
2194 } else if (argc != optind) {
2195 warnx("unknown command line argument: %s ...", argv[optind]);
2202 if ((path = calloc(1, MAXPATHLEN)) == NULL)
2203 errx(1, "pfctl: calloc");
2204 memset(anchorname, 0, sizeof(anchorname));
2205 if (anchoropt != NULL) {
2206 int len = strlen(anchoropt);
2208 if (anchoropt[len - 1] == '*') {
2209 if (len >= 2 && anchoropt[len - 2] == '/')
2210 anchoropt[len - 2] = '\0';
2212 anchoropt[len - 1] = '\0';
2213 opts |= PF_OPT_RECURSE;
2215 if (strlcpy(anchorname, anchoropt,
2216 sizeof(anchorname)) >= sizeof(anchorname))
2217 errx(1, "anchor name '%s' too long",
2219 loadopt &= PFCTL_FLAG_FILTER|PFCTL_FLAG_NAT|PFCTL_FLAG_TABLE;
2222 if ((opts & PF_OPT_NOACTION) == 0) {
2223 dev = open(pf_device, mode);
2225 err(1, "%s", pf_device);
2226 altqsupport = pfctl_test_altqsupport(dev, opts);
2228 dev = open(pf_device, O_RDONLY);
2230 opts |= PF_OPT_DUMMYACTION;
2231 /* turn off options */
2232 opts &= ~ (PF_OPT_DISABLE | PF_OPT_ENABLE);
2233 clearopt = showopt = debugopt = NULL;
2234 #if !defined(ENABLE_ALTQ)
2241 if (opts & PF_OPT_DISABLE)
2242 if (pfctl_disable(dev, opts))
2245 if (showopt != NULL) {
2248 pfctl_show_anchors(dev, opts, anchorname);
2251 pfctl_load_fingerprints(dev, opts);
2252 pfctl_show_rules(dev, path, opts, PFCTL_SHOW_RULES,
2256 pfctl_load_fingerprints(dev, opts);
2257 pfctl_show_rules(dev, path, opts, PFCTL_SHOW_LABELS,
2261 pfctl_load_fingerprints(dev, opts);
2262 pfctl_show_nat(dev, opts, anchorname);
2265 pfctl_show_altq(dev, ifaceopt, opts,
2266 opts & PF_OPT_VERBOSE2);
2269 pfctl_show_states(dev, ifaceopt, opts);
2272 pfctl_show_src_nodes(dev, opts);
2275 pfctl_show_status(dev, opts);
2278 pfctl_show_timeouts(dev, opts);
2281 pfctl_show_limits(dev, opts);
2284 opts |= PF_OPT_SHOWALL;
2285 pfctl_load_fingerprints(dev, opts);
2287 pfctl_show_nat(dev, opts, anchorname);
2288 pfctl_show_rules(dev, path, opts, 0, anchorname, 0);
2289 pfctl_show_altq(dev, ifaceopt, opts, 0);
2290 pfctl_show_states(dev, ifaceopt, opts);
2291 pfctl_show_src_nodes(dev, opts);
2292 pfctl_show_status(dev, opts);
2293 pfctl_show_rules(dev, path, opts, 1, anchorname, 0);
2294 pfctl_show_timeouts(dev, opts);
2295 pfctl_show_limits(dev, opts);
2296 pfctl_show_tables(anchorname, opts);
2297 pfctl_show_fingerprints(opts);
2300 pfctl_show_tables(anchorname, opts);
2303 pfctl_load_fingerprints(dev, opts);
2304 pfctl_show_fingerprints(opts);
2307 pfctl_show_ifaces(ifaceopt, opts);
2312 if ((opts & PF_OPT_CLRRULECTRS) && showopt == NULL)
2313 pfctl_show_rules(dev, path, opts, PFCTL_SHOW_NOTHING,
2316 if (clearopt != NULL) {
2317 if (anchorname[0] == '_' || strstr(anchorname, "/_") != NULL)
2318 errx(1, "anchor names beginning with '_' cannot "
2319 "be modified from the command line");
2321 switch (*clearopt) {
2323 pfctl_clear_rules(dev, opts, anchorname);
2326 pfctl_clear_nat(dev, opts, anchorname);
2329 pfctl_clear_altq(dev, opts);
2332 pfctl_clear_states(dev, ifaceopt, opts);
2335 pfctl_clear_src_nodes(dev, opts);
2338 pfctl_clear_stats(dev, opts);
2341 pfctl_clear_rules(dev, opts, anchorname);
2342 pfctl_clear_nat(dev, opts, anchorname);
2343 pfctl_clear_tables(anchorname, opts);
2345 pfctl_clear_altq(dev, opts);
2346 pfctl_clear_states(dev, ifaceopt, opts);
2347 pfctl_clear_src_nodes(dev, opts);
2348 pfctl_clear_stats(dev, opts);
2349 pfctl_clear_fingerprints(dev, opts);
2350 pfctl_clear_interface_flags(dev, opts);
2354 pfctl_clear_fingerprints(dev, opts);
2357 pfctl_clear_tables(anchorname, opts);
2361 if (state_killers) {
2362 if (!strcmp(state_kill[0], "label"))
2363 pfctl_label_kill_states(dev, ifaceopt, opts);
2364 else if (!strcmp(state_kill[0], "id"))
2365 pfctl_id_kill_states(dev, ifaceopt, opts);
2367 pfctl_net_kill_states(dev, ifaceopt, opts);
2370 if (src_node_killers)
2371 pfctl_kill_src_nodes(dev, ifaceopt, opts);
2373 if (tblcmdopt != NULL) {
2374 error = pfctl_command_tables(argc, argv, tableopt,
2375 tblcmdopt, rulesopt, anchorname, opts);
2378 if (optiopt != NULL) {
2384 optimize |= PF_OPTIMIZE_BASIC;
2388 optimize |= PF_OPTIMIZE_PROFILE;
2393 if ((rulesopt != NULL) && (loadopt & PFCTL_FLAG_OPTION) &&
2395 if (pfctl_get_skip_ifaces())
2398 if (rulesopt != NULL && !(opts & (PF_OPT_MERGE|PF_OPT_NOACTION)) &&
2399 !anchorname[0] && (loadopt & PFCTL_FLAG_OPTION))
2400 if (pfctl_file_fingerprints(dev, opts, PF_OSFP_FILE))
2403 if (rulesopt != NULL) {
2404 if (anchorname[0] == '_' || strstr(anchorname, "/_") != NULL)
2405 errx(1, "anchor names beginning with '_' cannot "
2406 "be modified from the command line");
2407 if (pfctl_rules(dev, rulesopt, opts, optimize,
2410 else if (!(opts & PF_OPT_NOACTION) &&
2411 (loadopt & PFCTL_FLAG_TABLE))
2412 warn_namespace_collision(NULL);
2415 if (opts & PF_OPT_ENABLE)
2416 if (pfctl_enable(dev, opts))
2419 if (debugopt != NULL) {
2420 switch (*debugopt) {
2422 pfctl_debug(dev, PF_DEBUG_NONE, opts);
2425 pfctl_debug(dev, PF_DEBUG_URGENT, opts);
2428 pfctl_debug(dev, PF_DEBUG_MISC, opts);
2431 pfctl_debug(dev, PF_DEBUG_NOISY, opts);