1 /* $OpenBSD: pfctl.c,v 1.278 2008/08/31 20:18:17 jmc Exp $ */
4 * Copyright (c) 2001 Daniel Hartmeier
5 * Copyright (c) 2002,2003 Henning Brauer
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include <sys/types.h>
38 #include <sys/ioctl.h>
39 #include <sys/socket.h>
43 #include <sys/endian.h>
47 #include <netinet/in.h>
48 #include <net/pfvar.h>
49 #include <arpa/inet.h>
50 #include <altq/altq.h>
51 #include <sys/sysctl.h>
64 #include "pfctl_parser.h"
68 int pfctl_enable(int, int);
69 int pfctl_disable(int, int);
70 int pfctl_clear_stats(int, int);
71 int pfctl_get_skip_ifaces(void);
72 int pfctl_check_skip_ifaces(char *);
73 int pfctl_clear_skip_ifaces(struct pfctl *);
74 int pfctl_clear_interface_flags(int, int);
75 int pfctl_clear_rules(int, int, char *);
76 int pfctl_clear_nat(int, int, char *);
77 int pfctl_clear_altq(int, int);
78 int pfctl_clear_src_nodes(int, int);
79 int pfctl_clear_states(int, const char *, int);
80 void pfctl_addrprefix(char *, struct pf_addr *);
81 int pfctl_kill_src_nodes(int, const char *, int);
82 int pfctl_net_kill_states(int, const char *, int);
83 int pfctl_label_kill_states(int, const char *, int);
84 int pfctl_id_kill_states(int, const char *, int);
85 void pfctl_init_options(struct pfctl *);
86 int pfctl_load_options(struct pfctl *);
87 int pfctl_load_limit(struct pfctl *, unsigned int, unsigned int);
88 int pfctl_load_timeout(struct pfctl *, unsigned int, unsigned int);
89 int pfctl_load_debug(struct pfctl *, unsigned int);
90 int pfctl_load_logif(struct pfctl *, char *);
91 int pfctl_load_hostid(struct pfctl *, unsigned int);
92 int pfctl_get_pool(int, struct pf_pool *, u_int32_t, u_int32_t, int,
94 void pfctl_print_rule_counters(struct pf_rule *, int);
95 int pfctl_show_rules(int, char *, int, enum pfctl_show, char *, int);
96 int pfctl_show_nat(int, int, char *);
97 int pfctl_show_src_nodes(int, int);
98 int pfctl_show_states(int, const char *, int);
99 int pfctl_show_status(int, int);
100 int pfctl_show_timeouts(int, int);
101 int pfctl_show_limits(int, int);
102 void pfctl_debug(int, u_int32_t, int);
103 int pfctl_test_altqsupport(int, int);
104 int pfctl_show_anchors(int, int, char *);
105 int pfctl_ruleset_trans(struct pfctl *, char *, struct pf_anchor *);
106 int pfctl_load_ruleset(struct pfctl *, char *,
107 struct pf_ruleset *, int, int);
108 int pfctl_load_rule(struct pfctl *, char *, struct pf_rule *, int);
109 const char *pfctl_lookup_option(char *, const char **);
111 struct pf_anchor_global pf_anchors;
112 struct pf_anchor pf_main_anchor;
113 static struct pfr_buffer skip_b;
115 const char *clearopt;
118 const char *debugopt;
120 const char *optiopt = NULL;
121 char *pf_device = "/dev/pf";
124 const char *tblcmdopt;
125 int src_node_killers;
126 char *src_node_kill[2];
136 #define INDENT(d, o) do { \
139 for (i=0; i < d; i++) \
145 static const struct {
149 { "states", PF_LIMIT_STATES },
150 { "src-nodes", PF_LIMIT_SRC_NODES },
151 { "frags", PF_LIMIT_FRAGS },
152 { "table-entries", PF_LIMIT_TABLE_ENTRIES },
160 static const struct pf_hint pf_hint_normal[] = {
161 { "tcp.first", 2 * 60 },
162 { "tcp.opening", 30 },
163 { "tcp.established", 24 * 60 * 60 },
164 { "tcp.closing", 15 * 60 },
165 { "tcp.finwait", 45 },
166 { "tcp.closed", 90 },
167 { "tcp.tsdiff", 30 },
170 static const struct pf_hint pf_hint_satellite[] = {
171 { "tcp.first", 3 * 60 },
172 { "tcp.opening", 30 + 5 },
173 { "tcp.established", 24 * 60 * 60 },
174 { "tcp.closing", 15 * 60 + 5 },
175 { "tcp.finwait", 45 + 5 },
176 { "tcp.closed", 90 + 5 },
177 { "tcp.tsdiff", 60 },
180 static const struct pf_hint pf_hint_conservative[] = {
181 { "tcp.first", 60 * 60 },
182 { "tcp.opening", 15 * 60 },
183 { "tcp.established", 5 * 24 * 60 * 60 },
184 { "tcp.closing", 60 * 60 },
185 { "tcp.finwait", 10 * 60 },
186 { "tcp.closed", 3 * 60 },
187 { "tcp.tsdiff", 60 },
190 static const struct pf_hint pf_hint_aggressive[] = {
192 { "tcp.opening", 5 },
193 { "tcp.established", 5 * 60 * 60 },
194 { "tcp.closing", 60 },
195 { "tcp.finwait", 30 },
196 { "tcp.closed", 30 },
197 { "tcp.tsdiff", 10 },
201 static const struct {
203 const struct pf_hint *hint;
205 { "normal", pf_hint_normal },
206 { "satellite", pf_hint_satellite },
207 { "high-latency", pf_hint_satellite },
208 { "conservative", pf_hint_conservative },
209 { "aggressive", pf_hint_aggressive },
213 static const char *clearopt_list[] = {
214 "nat", "queue", "rules", "Sources",
215 "states", "info", "Tables", "osfp", "all", NULL
218 static const char *showopt_list[] = {
219 "nat", "queue", "rules", "Anchors", "Sources", "states", "info",
220 "Interfaces", "labels", "timeouts", "memory", "Tables", "osfp",
224 static const char *tblcmdopt_list[] = {
225 "kill", "flush", "add", "delete", "load", "replace", "show",
226 "test", "zero", "expire", NULL
229 static const char *debugopt_list[] = {
230 "none", "urgent", "misc", "loud", NULL
233 static const char *optiopt_list[] = {
234 "none", "basic", "profile", NULL
240 extern char *__progname;
242 fprintf(stderr, "usage: %s [-AdeghmNnOPqRrvz] ", __progname);
243 fprintf(stderr, "[-a anchor] [-D macro=value] [-F modifier]\n");
244 fprintf(stderr, "\t[-f file] [-i interface] [-K host | network]\n");
245 fprintf(stderr, "\t[-k host | network | label | id] ");
246 fprintf(stderr, "[-o level] [-p device]\n");
247 fprintf(stderr, "\t[-s modifier] ");
248 fprintf(stderr, "[-t table -T command [address ...]] [-x level]\n");
253 pfctl_enable(int dev, int opts)
255 if (ioctl(dev, DIOCSTART)) {
257 errx(1, "pf already enabled");
259 else if (errno == ESRCH)
260 errx(1, "pfil registeration failed");
265 if ((opts & PF_OPT_QUIET) == 0)
266 fprintf(stderr, "pf enabled\n");
268 if (altqsupport && ioctl(dev, DIOCSTARTALTQ))
270 err(1, "DIOCSTARTALTQ");
276 pfctl_disable(int dev, int opts)
278 if (ioctl(dev, DIOCSTOP)) {
280 errx(1, "pf not enabled");
284 if ((opts & PF_OPT_QUIET) == 0)
285 fprintf(stderr, "pf disabled\n");
287 if (altqsupport && ioctl(dev, DIOCSTOPALTQ))
289 err(1, "DIOCSTOPALTQ");
295 pfctl_clear_stats(int dev, int opts)
297 if (ioctl(dev, DIOCCLRSTATUS))
298 err(1, "DIOCCLRSTATUS");
299 if ((opts & PF_OPT_QUIET) == 0)
300 fprintf(stderr, "pf: statistics cleared\n");
305 pfctl_get_skip_ifaces(void)
307 bzero(&skip_b, sizeof(skip_b));
308 skip_b.pfrb_type = PFRB_IFACES;
310 pfr_buf_grow(&skip_b, skip_b.pfrb_size);
311 skip_b.pfrb_size = skip_b.pfrb_msize;
312 if (pfi_get_ifaces(NULL, skip_b.pfrb_caddr, &skip_b.pfrb_size))
313 err(1, "pfi_get_ifaces");
314 if (skip_b.pfrb_size <= skip_b.pfrb_msize)
321 pfctl_check_skip_ifaces(char *ifname)
325 PFRB_FOREACH(p, &skip_b)
326 if ((p->pfik_flags & PFI_IFLAG_SKIP) && !strcmp(ifname, p->pfik_name))
327 p->pfik_flags &= ~PFI_IFLAG_SKIP;
332 pfctl_clear_skip_ifaces(struct pfctl *pf)
336 PFRB_FOREACH(p, &skip_b)
337 if (p->pfik_flags & PFI_IFLAG_SKIP)
338 pfctl_set_interface_flags(pf, p->pfik_name, PFI_IFLAG_SKIP, 0);
343 pfctl_clear_interface_flags(int dev, int opts)
345 struct pfioc_iface pi;
347 if ((opts & PF_OPT_NOACTION) == 0) {
348 bzero(&pi, sizeof(pi));
349 pi.pfiio_flags = PFI_IFLAG_SKIP;
351 if (ioctl(dev, DIOCCLRIFFLAG, &pi))
352 err(1, "DIOCCLRIFFLAG");
353 if ((opts & PF_OPT_QUIET) == 0)
354 fprintf(stderr, "pf: interface flags reset\n");
360 pfctl_clear_rules(int dev, int opts, char *anchorname)
364 memset(&t, 0, sizeof(t));
365 t.pfrb_type = PFRB_TRANS;
366 if (pfctl_add_trans(&t, PF_RULESET_SCRUB, anchorname) ||
367 pfctl_add_trans(&t, PF_RULESET_FILTER, anchorname) ||
368 pfctl_trans(dev, &t, DIOCXBEGIN, 0) ||
369 pfctl_trans(dev, &t, DIOCXCOMMIT, 0))
370 err(1, "pfctl_clear_rules");
371 if ((opts & PF_OPT_QUIET) == 0)
372 fprintf(stderr, "rules cleared\n");
377 pfctl_clear_nat(int dev, int opts, char *anchorname)
381 memset(&t, 0, sizeof(t));
382 t.pfrb_type = PFRB_TRANS;
383 if (pfctl_add_trans(&t, PF_RULESET_NAT, anchorname) ||
384 pfctl_add_trans(&t, PF_RULESET_BINAT, anchorname) ||
385 pfctl_add_trans(&t, PF_RULESET_RDR, anchorname) ||
386 pfctl_trans(dev, &t, DIOCXBEGIN, 0) ||
387 pfctl_trans(dev, &t, DIOCXCOMMIT, 0))
388 err(1, "pfctl_clear_nat");
389 if ((opts & PF_OPT_QUIET) == 0)
390 fprintf(stderr, "nat cleared\n");
395 pfctl_clear_altq(int dev, int opts)
401 memset(&t, 0, sizeof(t));
402 t.pfrb_type = PFRB_TRANS;
403 if (pfctl_add_trans(&t, PF_RULESET_ALTQ, "") ||
404 pfctl_trans(dev, &t, DIOCXBEGIN, 0) ||
405 pfctl_trans(dev, &t, DIOCXCOMMIT, 0))
406 err(1, "pfctl_clear_altq");
407 if ((opts & PF_OPT_QUIET) == 0)
408 fprintf(stderr, "altq cleared\n");
413 pfctl_clear_src_nodes(int dev, int opts)
415 if (ioctl(dev, DIOCCLRSRCNODES))
416 err(1, "DIOCCLRSRCNODES");
417 if ((opts & PF_OPT_QUIET) == 0)
418 fprintf(stderr, "source tracking entries cleared\n");
423 pfctl_clear_states(int dev, const char *iface, int opts)
425 struct pfioc_state_kill psk;
427 memset(&psk, 0, sizeof(psk));
428 if (iface != NULL && strlcpy(psk.psk_ifname, iface,
429 sizeof(psk.psk_ifname)) >= sizeof(psk.psk_ifname))
430 errx(1, "invalid interface: %s", iface);
432 if (ioctl(dev, DIOCCLRSTATES, &psk))
433 err(1, "DIOCCLRSTATES");
434 if ((opts & PF_OPT_QUIET) == 0)
435 fprintf(stderr, "%d states cleared\n", psk.psk_killed);
440 pfctl_addrprefix(char *addr, struct pf_addr *mask)
444 int prefix, ret_ga, q, r;
445 struct addrinfo hints, *res;
447 if ((p = strchr(addr, '/')) == NULL)
451 prefix = strtonum(p, 0, 128, &errstr);
453 errx(1, "prefix is %s: %s", errstr, p);
455 bzero(&hints, sizeof(hints));
456 /* prefix only with numeric addresses */
457 hints.ai_flags |= AI_NUMERICHOST;
459 if ((ret_ga = getaddrinfo(addr, NULL, &hints, &res))) {
460 errx(1, "getaddrinfo: %s", gai_strerror(ret_ga));
464 if (res->ai_family == AF_INET && prefix > 32)
465 errx(1, "prefix too long for AF_INET");
466 else if (res->ai_family == AF_INET6 && prefix > 128)
467 errx(1, "prefix too long for AF_INET6");
471 switch (res->ai_family) {
473 bzero(&mask->v4, sizeof(mask->v4));
474 mask->v4.s_addr = htonl((u_int32_t)
475 (0xffffffffffULL << (32 - prefix)));
478 bzero(&mask->v6, sizeof(mask->v6));
480 memset((void *)&mask->v6, 0xff, q);
482 *((u_char *)&mask->v6 + q) =
483 (0xff00 >> r) & 0xff;
490 pfctl_kill_src_nodes(int dev, const char *iface, int opts)
492 struct pfioc_src_node_kill psnk;
493 struct addrinfo *res[2], *resp[2];
494 struct sockaddr last_src, last_dst;
495 int killed, sources, dests;
498 killed = sources = dests = 0;
500 memset(&psnk, 0, sizeof(psnk));
501 memset(&psnk.psnk_src.addr.v.a.mask, 0xff,
502 sizeof(psnk.psnk_src.addr.v.a.mask));
503 memset(&last_src, 0xff, sizeof(last_src));
504 memset(&last_dst, 0xff, sizeof(last_dst));
506 pfctl_addrprefix(src_node_kill[0], &psnk.psnk_src.addr.v.a.mask);
508 if ((ret_ga = getaddrinfo(src_node_kill[0], NULL, NULL, &res[0]))) {
509 errx(1, "getaddrinfo: %s", gai_strerror(ret_ga));
512 for (resp[0] = res[0]; resp[0]; resp[0] = resp[0]->ai_next) {
513 if (resp[0]->ai_addr == NULL)
515 /* We get lots of duplicates. Catch the easy ones */
516 if (memcmp(&last_src, resp[0]->ai_addr, sizeof(last_src)) == 0)
518 last_src = *(struct sockaddr *)resp[0]->ai_addr;
520 psnk.psnk_af = resp[0]->ai_family;
523 if (psnk.psnk_af == AF_INET)
524 psnk.psnk_src.addr.v.a.addr.v4 =
525 ((struct sockaddr_in *)resp[0]->ai_addr)->sin_addr;
526 else if (psnk.psnk_af == AF_INET6)
527 psnk.psnk_src.addr.v.a.addr.v6 =
528 ((struct sockaddr_in6 *)resp[0]->ai_addr)->
531 errx(1, "Unknown address family %d", psnk.psnk_af);
533 if (src_node_killers > 1) {
535 memset(&psnk.psnk_dst.addr.v.a.mask, 0xff,
536 sizeof(psnk.psnk_dst.addr.v.a.mask));
537 memset(&last_dst, 0xff, sizeof(last_dst));
538 pfctl_addrprefix(src_node_kill[1],
539 &psnk.psnk_dst.addr.v.a.mask);
540 if ((ret_ga = getaddrinfo(src_node_kill[1], NULL, NULL,
542 errx(1, "getaddrinfo: %s",
543 gai_strerror(ret_ga));
546 for (resp[1] = res[1]; resp[1];
547 resp[1] = resp[1]->ai_next) {
548 if (resp[1]->ai_addr == NULL)
550 if (psnk.psnk_af != resp[1]->ai_family)
553 if (memcmp(&last_dst, resp[1]->ai_addr,
554 sizeof(last_dst)) == 0)
556 last_dst = *(struct sockaddr *)resp[1]->ai_addr;
560 if (psnk.psnk_af == AF_INET)
561 psnk.psnk_dst.addr.v.a.addr.v4 =
562 ((struct sockaddr_in *)resp[1]->
564 else if (psnk.psnk_af == AF_INET6)
565 psnk.psnk_dst.addr.v.a.addr.v6 =
566 ((struct sockaddr_in6 *)resp[1]->
569 errx(1, "Unknown address family %d",
572 if (ioctl(dev, DIOCKILLSRCNODES, &psnk))
573 err(1, "DIOCKILLSRCNODES");
574 killed += psnk.psnk_killed;
576 freeaddrinfo(res[1]);
578 if (ioctl(dev, DIOCKILLSRCNODES, &psnk))
579 err(1, "DIOCKILLSRCNODES");
580 killed += psnk.psnk_killed;
584 freeaddrinfo(res[0]);
586 if ((opts & PF_OPT_QUIET) == 0)
587 fprintf(stderr, "killed %d src nodes from %d sources and %d "
588 "destinations\n", killed, sources, dests);
593 pfctl_net_kill_states(int dev, const char *iface, int opts)
595 struct pfioc_state_kill psk;
596 struct addrinfo *res[2], *resp[2];
597 struct sockaddr last_src, last_dst;
598 int killed, sources, dests;
601 killed = sources = dests = 0;
603 memset(&psk, 0, sizeof(psk));
604 memset(&psk.psk_src.addr.v.a.mask, 0xff,
605 sizeof(psk.psk_src.addr.v.a.mask));
606 memset(&last_src, 0xff, sizeof(last_src));
607 memset(&last_dst, 0xff, sizeof(last_dst));
608 if (iface != NULL && strlcpy(psk.psk_ifname, iface,
609 sizeof(psk.psk_ifname)) >= sizeof(psk.psk_ifname))
610 errx(1, "invalid interface: %s", iface);
612 pfctl_addrprefix(state_kill[0], &psk.psk_src.addr.v.a.mask);
614 if ((ret_ga = getaddrinfo(state_kill[0], NULL, NULL, &res[0]))) {
615 errx(1, "getaddrinfo: %s", gai_strerror(ret_ga));
618 for (resp[0] = res[0]; resp[0]; resp[0] = resp[0]->ai_next) {
619 if (resp[0]->ai_addr == NULL)
621 /* We get lots of duplicates. Catch the easy ones */
622 if (memcmp(&last_src, resp[0]->ai_addr, sizeof(last_src)) == 0)
624 last_src = *(struct sockaddr *)resp[0]->ai_addr;
626 psk.psk_af = resp[0]->ai_family;
629 if (psk.psk_af == AF_INET)
630 psk.psk_src.addr.v.a.addr.v4 =
631 ((struct sockaddr_in *)resp[0]->ai_addr)->sin_addr;
632 else if (psk.psk_af == AF_INET6)
633 psk.psk_src.addr.v.a.addr.v6 =
634 ((struct sockaddr_in6 *)resp[0]->ai_addr)->
637 errx(1, "Unknown address family %d", psk.psk_af);
639 if (state_killers > 1) {
641 memset(&psk.psk_dst.addr.v.a.mask, 0xff,
642 sizeof(psk.psk_dst.addr.v.a.mask));
643 memset(&last_dst, 0xff, sizeof(last_dst));
644 pfctl_addrprefix(state_kill[1],
645 &psk.psk_dst.addr.v.a.mask);
646 if ((ret_ga = getaddrinfo(state_kill[1], NULL, NULL,
648 errx(1, "getaddrinfo: %s",
649 gai_strerror(ret_ga));
652 for (resp[1] = res[1]; resp[1];
653 resp[1] = resp[1]->ai_next) {
654 if (resp[1]->ai_addr == NULL)
656 if (psk.psk_af != resp[1]->ai_family)
659 if (memcmp(&last_dst, resp[1]->ai_addr,
660 sizeof(last_dst)) == 0)
662 last_dst = *(struct sockaddr *)resp[1]->ai_addr;
666 if (psk.psk_af == AF_INET)
667 psk.psk_dst.addr.v.a.addr.v4 =
668 ((struct sockaddr_in *)resp[1]->
670 else if (psk.psk_af == AF_INET6)
671 psk.psk_dst.addr.v.a.addr.v6 =
672 ((struct sockaddr_in6 *)resp[1]->
675 errx(1, "Unknown address family %d",
678 if (ioctl(dev, DIOCKILLSTATES, &psk))
679 err(1, "DIOCKILLSTATES");
680 killed += psk.psk_killed;
682 freeaddrinfo(res[1]);
684 if (ioctl(dev, DIOCKILLSTATES, &psk))
685 err(1, "DIOCKILLSTATES");
686 killed += psk.psk_killed;
690 freeaddrinfo(res[0]);
692 if ((opts & PF_OPT_QUIET) == 0)
693 fprintf(stderr, "killed %d states from %d sources and %d "
694 "destinations\n", killed, sources, dests);
699 pfctl_label_kill_states(int dev, const char *iface, int opts)
701 struct pfioc_state_kill psk;
703 if (state_killers != 2 || (strlen(state_kill[1]) == 0)) {
704 warnx("no label specified");
707 memset(&psk, 0, sizeof(psk));
708 if (iface != NULL && strlcpy(psk.psk_ifname, iface,
709 sizeof(psk.psk_ifname)) >= sizeof(psk.psk_ifname))
710 errx(1, "invalid interface: %s", iface);
712 if (strlcpy(psk.psk_label, state_kill[1], sizeof(psk.psk_label)) >=
713 sizeof(psk.psk_label))
714 errx(1, "label too long: %s", state_kill[1]);
716 if (ioctl(dev, DIOCKILLSTATES, &psk))
717 err(1, "DIOCKILLSTATES");
719 if ((opts & PF_OPT_QUIET) == 0)
720 fprintf(stderr, "killed %d states\n", psk.psk_killed);
726 pfctl_id_kill_states(int dev, const char *iface, int opts)
728 struct pfioc_state_kill psk;
730 if (state_killers != 2 || (strlen(state_kill[1]) == 0)) {
731 warnx("no id specified");
735 memset(&psk, 0, sizeof(psk));
736 if ((sscanf(state_kill[1], "%jx/%x",
737 &psk.psk_pfcmp.id, &psk.psk_pfcmp.creatorid)) == 2)
738 HTONL(psk.psk_pfcmp.creatorid);
739 else if ((sscanf(state_kill[1], "%jx", &psk.psk_pfcmp.id)) == 1) {
740 psk.psk_pfcmp.creatorid = 0;
742 warnx("wrong id format specified");
745 if (psk.psk_pfcmp.id == 0) {
746 warnx("cannot kill id 0");
750 psk.psk_pfcmp.id = htobe64(psk.psk_pfcmp.id);
751 if (ioctl(dev, DIOCKILLSTATES, &psk))
752 err(1, "DIOCKILLSTATES");
754 if ((opts & PF_OPT_QUIET) == 0)
755 fprintf(stderr, "killed %d states\n", psk.psk_killed);
761 pfctl_get_pool(int dev, struct pf_pool *pool, u_int32_t nr,
762 u_int32_t ticket, int r_action, char *anchorname)
764 struct pfioc_pooladdr pp;
765 struct pf_pooladdr *pa;
768 memset(&pp, 0, sizeof(pp));
769 memcpy(pp.anchor, anchorname, sizeof(pp.anchor));
770 pp.r_action = r_action;
773 if (ioctl(dev, DIOCGETADDRS, &pp)) {
774 warn("DIOCGETADDRS");
778 TAILQ_INIT(&pool->list);
779 for (pnr = 0; pnr < mpnr; ++pnr) {
781 if (ioctl(dev, DIOCGETADDR, &pp)) {
785 pa = calloc(1, sizeof(struct pf_pooladdr));
788 bcopy(&pp.addr, pa, sizeof(struct pf_pooladdr));
789 TAILQ_INSERT_TAIL(&pool->list, pa, entries);
796 pfctl_move_pool(struct pf_pool *src, struct pf_pool *dst)
798 struct pf_pooladdr *pa;
800 while ((pa = TAILQ_FIRST(&src->list)) != NULL) {
801 TAILQ_REMOVE(&src->list, pa, entries);
802 TAILQ_INSERT_TAIL(&dst->list, pa, entries);
807 pfctl_clear_pool(struct pf_pool *pool)
809 struct pf_pooladdr *pa;
811 while ((pa = TAILQ_FIRST(&pool->list)) != NULL) {
812 TAILQ_REMOVE(&pool->list, pa, entries);
818 pfctl_print_rule_counters(struct pf_rule *rule, int opts)
820 if (opts & PF_OPT_DEBUG) {
821 const char *t[PF_SKIP_COUNT] = { "i", "d", "f",
822 "p", "sa", "sp", "da", "dp" };
825 printf(" [ Skip steps: ");
826 for (i = 0; i < PF_SKIP_COUNT; ++i) {
827 if (rule->skip[i].nr == rule->nr + 1)
830 if (rule->skip[i].nr == -1)
833 printf("%u ", rule->skip[i].nr);
837 printf(" [ queue: qname=%s qid=%u pqname=%s pqid=%u ]\n",
838 rule->qname, rule->qid, rule->pqname, rule->pqid);
840 if (opts & PF_OPT_VERBOSE) {
841 printf(" [ Evaluations: %-8llu Packets: %-8llu "
842 "Bytes: %-10llu States: %-6ju]\n",
843 (unsigned long long)rule->evaluations,
844 (unsigned long long)(rule->packets[0] +
846 (unsigned long long)(rule->bytes[0] +
847 rule->bytes[1]), (uintmax_t)rule->u_states_cur);
848 if (!(opts & PF_OPT_DEBUG))
849 printf(" [ Inserted: uid %u pid %u "
850 "State Creations: %-6ju]\n",
851 (unsigned)rule->cuid, (unsigned)rule->cpid,
852 (uintmax_t)rule->u_states_tot);
857 pfctl_print_title(char *title)
862 printf("%s\n", title);
866 pfctl_show_rules(int dev, char *path, int opts, enum pfctl_show format,
867 char *anchorname, int depth)
869 struct pfioc_rule pr;
870 u_int32_t nr, mnr, header = 0;
871 int rule_numbers = opts & (PF_OPT_VERBOSE2 | PF_OPT_DEBUG);
872 int numeric = opts & PF_OPT_NUMERIC;
873 int len = strlen(path);
878 snprintf(&path[len], MAXPATHLEN - len, "/%s", anchorname);
880 snprintf(&path[len], MAXPATHLEN - len, "%s", anchorname);
882 memset(&pr, 0, sizeof(pr));
883 memcpy(pr.anchor, path, sizeof(pr.anchor));
884 if (opts & PF_OPT_SHOWALL) {
885 pr.rule.action = PF_PASS;
886 if (ioctl(dev, DIOCGETRULES, &pr)) {
887 warn("DIOCGETRULES");
892 pr.rule.action = PF_SCRUB;
893 if (ioctl(dev, DIOCGETRULES, &pr)) {
894 warn("DIOCGETRULES");
897 if (opts & PF_OPT_SHOWALL) {
898 if (format == PFCTL_SHOW_RULES && (pr.nr > 0 || header))
899 pfctl_print_title("FILTER RULES:");
900 else if (format == PFCTL_SHOW_LABELS && labels)
901 pfctl_print_title("LABEL COUNTERS:");
904 if (opts & PF_OPT_CLRRULECTRS)
905 pr.action = PF_GET_CLR_CNTR;
907 for (nr = 0; nr < mnr; ++nr) {
909 if (ioctl(dev, DIOCGETRULE, &pr)) {
914 if (pfctl_get_pool(dev, &pr.rule.rpool,
915 nr, pr.ticket, PF_SCRUB, path) != 0)
919 case PFCTL_SHOW_LABELS:
921 case PFCTL_SHOW_RULES:
922 if (pr.rule.label[0] && (opts & PF_OPT_SHOWALL))
924 print_rule(&pr.rule, pr.anchor_call, rule_numbers, numeric);
926 pfctl_print_rule_counters(&pr.rule, opts);
928 case PFCTL_SHOW_NOTHING:
931 pfctl_clear_pool(&pr.rule.rpool);
933 pr.rule.action = PF_PASS;
934 if (ioctl(dev, DIOCGETRULES, &pr)) {
935 warn("DIOCGETRULES");
939 for (nr = 0; nr < mnr; ++nr) {
941 if (ioctl(dev, DIOCGETRULE, &pr)) {
946 if (pfctl_get_pool(dev, &pr.rule.rpool,
947 nr, pr.ticket, PF_PASS, path) != 0)
951 case PFCTL_SHOW_LABELS:
952 if (pr.rule.label[0]) {
953 printf("%s %llu %llu %llu %llu"
954 " %llu %llu %llu %ju\n",
956 (unsigned long long)pr.rule.evaluations,
957 (unsigned long long)(pr.rule.packets[0] +
959 (unsigned long long)(pr.rule.bytes[0] +
961 (unsigned long long)pr.rule.packets[0],
962 (unsigned long long)pr.rule.bytes[0],
963 (unsigned long long)pr.rule.packets[1],
964 (unsigned long long)pr.rule.bytes[1],
965 (uintmax_t)pr.rule.u_states_tot);
968 case PFCTL_SHOW_RULES:
970 if (pr.rule.label[0] && (opts & PF_OPT_SHOWALL))
972 INDENT(depth, !(opts & PF_OPT_VERBOSE));
973 if (pr.anchor_call[0] &&
974 ((((p = strrchr(pr.anchor_call, '_')) != NULL) &&
975 ((void *)p == (void *)pr.anchor_call ||
976 *(--p) == '/')) || (opts & PF_OPT_RECURSE))) {
978 if ((p = strrchr(pr.anchor_call, '/')) !=
982 p = &pr.anchor_call[0];
984 p = &pr.anchor_call[0];
986 print_rule(&pr.rule, p, rule_numbers, numeric);
991 pfctl_print_rule_counters(&pr.rule, opts);
993 pfctl_show_rules(dev, path, opts, format,
995 INDENT(depth, !(opts & PF_OPT_VERBOSE));
999 case PFCTL_SHOW_NOTHING:
1002 pfctl_clear_pool(&pr.rule.rpool);
1013 pfctl_show_nat(int dev, int opts, char *anchorname)
1015 struct pfioc_rule pr;
1017 static int nattype[3] = { PF_NAT, PF_RDR, PF_BINAT };
1018 int i, dotitle = opts & PF_OPT_SHOWALL;
1020 memset(&pr, 0, sizeof(pr));
1021 memcpy(pr.anchor, anchorname, sizeof(pr.anchor));
1022 for (i = 0; i < 3; i++) {
1023 pr.rule.action = nattype[i];
1024 if (ioctl(dev, DIOCGETRULES, &pr)) {
1025 warn("DIOCGETRULES");
1029 for (nr = 0; nr < mnr; ++nr) {
1031 if (ioctl(dev, DIOCGETRULE, &pr)) {
1032 warn("DIOCGETRULE");
1035 if (pfctl_get_pool(dev, &pr.rule.rpool, nr,
1036 pr.ticket, nattype[i], anchorname) != 0)
1039 pfctl_print_title("TRANSLATION RULES:");
1042 print_rule(&pr.rule, pr.anchor_call,
1043 opts & PF_OPT_VERBOSE2, opts & PF_OPT_NUMERIC);
1045 pfctl_print_rule_counters(&pr.rule, opts);
1046 pfctl_clear_pool(&pr.rule.rpool);
1053 pfctl_show_src_nodes(int dev, int opts)
1055 struct pfioc_src_nodes psn;
1056 struct pf_src_node *p;
1057 char *inbuf = NULL, *newinbuf = NULL;
1058 unsigned int len = 0;
1061 memset(&psn, 0, sizeof(psn));
1065 newinbuf = realloc(inbuf, len);
1066 if (newinbuf == NULL)
1068 psn.psn_buf = inbuf = newinbuf;
1070 if (ioctl(dev, DIOCGETSRCNODES, &psn) < 0) {
1071 warn("DIOCGETSRCNODES");
1075 if (psn.psn_len + sizeof(struct pfioc_src_nodes) < len)
1077 if (len == 0 && psn.psn_len == 0)
1079 if (len == 0 && psn.psn_len != 0)
1081 if (psn.psn_len == 0)
1082 goto done; /* no src_nodes */
1085 p = psn.psn_src_nodes;
1086 if (psn.psn_len > 0 && (opts & PF_OPT_SHOWALL))
1087 pfctl_print_title("SOURCE TRACKING NODES:");
1088 for (i = 0; i < psn.psn_len; i += sizeof(*p)) {
1089 print_src_node(p, opts);
1098 pfctl_show_states(int dev, const char *iface, int opts)
1100 struct pfioc_states ps;
1101 struct pfsync_state *p;
1102 char *inbuf = NULL, *newinbuf = NULL;
1103 unsigned int len = 0;
1104 int i, dotitle = (opts & PF_OPT_SHOWALL);
1106 memset(&ps, 0, sizeof(ps));
1110 newinbuf = realloc(inbuf, len);
1111 if (newinbuf == NULL)
1113 ps.ps_buf = inbuf = newinbuf;
1115 if (ioctl(dev, DIOCGETSTATES, &ps) < 0) {
1116 warn("DIOCGETSTATES");
1120 if (ps.ps_len + sizeof(struct pfioc_states) < len)
1122 if (len == 0 && ps.ps_len == 0)
1124 if (len == 0 && ps.ps_len != 0)
1127 goto done; /* no states */
1131 for (i = 0; i < ps.ps_len; i += sizeof(*p), p++) {
1132 if (iface != NULL && strcmp(p->ifname, iface))
1135 pfctl_print_title("STATES:");
1138 print_state(p, opts);
1146 pfctl_show_status(int dev, int opts)
1148 struct pf_status status;
1150 if (ioctl(dev, DIOCGETSTATUS, &status)) {
1151 warn("DIOCGETSTATUS");
1154 if (opts & PF_OPT_SHOWALL)
1155 pfctl_print_title("INFO:");
1156 print_status(&status, opts);
1161 pfctl_show_timeouts(int dev, int opts)
1166 if (opts & PF_OPT_SHOWALL)
1167 pfctl_print_title("TIMEOUTS:");
1168 memset(&pt, 0, sizeof(pt));
1169 for (i = 0; pf_timeouts[i].name; i++) {
1170 pt.timeout = pf_timeouts[i].timeout;
1171 if (ioctl(dev, DIOCGETTIMEOUT, &pt))
1172 err(1, "DIOCGETTIMEOUT");
1173 printf("%-20s %10d", pf_timeouts[i].name, pt.seconds);
1174 if (pf_timeouts[i].timeout >= PFTM_ADAPTIVE_START &&
1175 pf_timeouts[i].timeout <= PFTM_ADAPTIVE_END)
1186 pfctl_show_limits(int dev, int opts)
1188 struct pfioc_limit pl;
1191 if (opts & PF_OPT_SHOWALL)
1192 pfctl_print_title("LIMITS:");
1193 memset(&pl, 0, sizeof(pl));
1194 for (i = 0; pf_limits[i].name; i++) {
1195 pl.index = pf_limits[i].index;
1196 if (ioctl(dev, DIOCGETLIMIT, &pl))
1197 err(1, "DIOCGETLIMIT");
1198 printf("%-13s ", pf_limits[i].name);
1199 if (pl.limit == UINT_MAX)
1200 printf("unlimited\n");
1202 printf("hard limit %8u\n", pl.limit);
1207 /* callbacks for rule/nat/rdr/addr */
1209 pfctl_add_pool(struct pfctl *pf, struct pf_pool *p, sa_family_t af)
1211 struct pf_pooladdr *pa;
1213 if ((pf->opts & PF_OPT_NOACTION) == 0) {
1214 if (ioctl(pf->dev, DIOCBEGINADDRS, &pf->paddr))
1215 err(1, "DIOCBEGINADDRS");
1219 TAILQ_FOREACH(pa, &p->list, entries) {
1220 memcpy(&pf->paddr.addr, pa, sizeof(struct pf_pooladdr));
1221 if ((pf->opts & PF_OPT_NOACTION) == 0) {
1222 if (ioctl(pf->dev, DIOCADDADDR, &pf->paddr))
1223 err(1, "DIOCADDADDR");
1230 pfctl_add_rule(struct pfctl *pf, struct pf_rule *r, const char *anchor_call)
1233 struct pf_rule *rule;
1234 struct pf_ruleset *rs;
1237 rs_num = pf_get_ruleset_number(r->action);
1238 if (rs_num == PF_RULESET_MAX)
1239 errx(1, "Invalid rule type %d", r->action);
1241 rs = &pf->anchor->ruleset;
1243 if (anchor_call[0] && r->anchor == NULL) {
1245 * Don't make non-brace anchors part of the main anchor pool.
1247 if ((r->anchor = calloc(1, sizeof(*r->anchor))) == NULL)
1248 err(1, "pfctl_add_rule: calloc");
1250 pf_init_ruleset(&r->anchor->ruleset);
1251 r->anchor->ruleset.anchor = r->anchor;
1252 if (strlcpy(r->anchor->path, anchor_call,
1253 sizeof(rule->anchor->path)) >= sizeof(rule->anchor->path))
1254 errx(1, "pfctl_add_rule: strlcpy");
1255 if ((p = strrchr(anchor_call, '/')) != NULL) {
1257 err(1, "pfctl_add_rule: bad anchor name %s",
1260 p = (char *)anchor_call;
1261 if (strlcpy(r->anchor->name, p,
1262 sizeof(rule->anchor->name)) >= sizeof(rule->anchor->name))
1263 errx(1, "pfctl_add_rule: strlcpy");
1266 if ((rule = calloc(1, sizeof(*rule))) == NULL)
1268 bcopy(r, rule, sizeof(*rule));
1269 TAILQ_INIT(&rule->rpool.list);
1270 pfctl_move_pool(&r->rpool, &rule->rpool);
1272 TAILQ_INSERT_TAIL(rs->rules[rs_num].active.ptr, rule, entries);
1277 pfctl_ruleset_trans(struct pfctl *pf, char *path, struct pf_anchor *a)
1279 int osize = pf->trans->pfrb_size;
1281 if ((pf->loadopt & PFCTL_FLAG_NAT) != 0) {
1282 if (pfctl_add_trans(pf->trans, PF_RULESET_NAT, path) ||
1283 pfctl_add_trans(pf->trans, PF_RULESET_BINAT, path) ||
1284 pfctl_add_trans(pf->trans, PF_RULESET_RDR, path))
1287 if (a == pf->astack[0] && ((altqsupport &&
1288 (pf->loadopt & PFCTL_FLAG_ALTQ) != 0))) {
1289 if (pfctl_add_trans(pf->trans, PF_RULESET_ALTQ, path))
1292 if ((pf->loadopt & PFCTL_FLAG_FILTER) != 0) {
1293 if (pfctl_add_trans(pf->trans, PF_RULESET_SCRUB, path) ||
1294 pfctl_add_trans(pf->trans, PF_RULESET_FILTER, path))
1297 if (pf->loadopt & PFCTL_FLAG_TABLE)
1298 if (pfctl_add_trans(pf->trans, PF_RULESET_TABLE, path))
1300 if (pfctl_trans(pf->dev, pf->trans, DIOCXBEGIN, osize))
1307 pfctl_load_ruleset(struct pfctl *pf, char *path, struct pf_ruleset *rs,
1308 int rs_num, int depth)
1311 int error, len = strlen(path);
1314 pf->anchor = rs->anchor;
1317 snprintf(&path[len], MAXPATHLEN - len, "/%s", pf->anchor->name);
1319 snprintf(&path[len], MAXPATHLEN - len, "%s", pf->anchor->name);
1322 if (TAILQ_FIRST(rs->rules[rs_num].active.ptr) != NULL) {
1324 if (pf->opts & PF_OPT_VERBOSE)
1326 if ((pf->opts & PF_OPT_NOACTION) == 0 &&
1327 (error = pfctl_ruleset_trans(pf,
1328 path, rs->anchor))) {
1329 printf("pfctl_load_rulesets: "
1330 "pfctl_ruleset_trans %d\n", error);
1333 } else if (pf->opts & PF_OPT_VERBOSE)
1338 if (pf->optimize && rs_num == PF_RULESET_FILTER)
1339 pfctl_optimize_ruleset(pf, rs);
1341 while ((r = TAILQ_FIRST(rs->rules[rs_num].active.ptr)) != NULL) {
1342 TAILQ_REMOVE(rs->rules[rs_num].active.ptr, r, entries);
1343 if ((error = pfctl_load_rule(pf, path, r, depth)))
1346 if ((error = pfctl_load_ruleset(pf, path,
1347 &r->anchor->ruleset, rs_num, depth + 1)))
1349 } else if (pf->opts & PF_OPT_VERBOSE)
1353 if (brace && pf->opts & PF_OPT_VERBOSE) {
1354 INDENT(depth - 1, (pf->opts & PF_OPT_VERBOSE));
1367 pfctl_load_rule(struct pfctl *pf, char *path, struct pf_rule *r, int depth)
1369 u_int8_t rs_num = pf_get_ruleset_number(r->action);
1371 struct pfioc_rule pr;
1372 int len = strlen(path);
1374 bzero(&pr, sizeof(pr));
1375 /* set up anchor before adding to path for anchor_call */
1376 if ((pf->opts & PF_OPT_NOACTION) == 0)
1377 pr.ticket = pfctl_get_ticket(pf->trans, rs_num, path);
1378 if (strlcpy(pr.anchor, path, sizeof(pr.anchor)) >= sizeof(pr.anchor))
1379 errx(1, "pfctl_load_rule: strlcpy");
1382 if (r->anchor->match) {
1384 snprintf(&path[len], MAXPATHLEN - len,
1385 "/%s", r->anchor->name);
1387 snprintf(&path[len], MAXPATHLEN - len,
1388 "%s", r->anchor->name);
1391 name = r->anchor->path;
1395 if ((pf->opts & PF_OPT_NOACTION) == 0) {
1396 if (pfctl_add_pool(pf, &r->rpool, r->af))
1398 pr.pool_ticket = pf->paddr.ticket;
1399 memcpy(&pr.rule, r, sizeof(pr.rule));
1400 if (r->anchor && strlcpy(pr.anchor_call, name,
1401 sizeof(pr.anchor_call)) >= sizeof(pr.anchor_call))
1402 errx(1, "pfctl_load_rule: strlcpy");
1403 if (ioctl(pf->dev, DIOCADDRULE, &pr))
1404 err(1, "DIOCADDRULE");
1407 if (pf->opts & PF_OPT_VERBOSE) {
1408 INDENT(depth, !(pf->opts & PF_OPT_VERBOSE2));
1409 print_rule(r, r->anchor ? r->anchor->name : "",
1410 pf->opts & PF_OPT_VERBOSE2,
1411 pf->opts & PF_OPT_NUMERIC);
1414 pfctl_clear_pool(&r->rpool);
1419 pfctl_add_altq(struct pfctl *pf, struct pf_altq *a)
1422 (loadopt & PFCTL_FLAG_ALTQ) != 0) {
1423 memcpy(&pf->paltq->altq, a, sizeof(struct pf_altq));
1424 if ((pf->opts & PF_OPT_NOACTION) == 0) {
1425 if (ioctl(pf->dev, DIOCADDALTQ, pf->paltq)) {
1427 errx(1, "qtype not configured");
1428 else if (errno == ENODEV)
1429 errx(1, "%s: driver does not support "
1432 err(1, "DIOCADDALTQ");
1435 pfaltq_store(&pf->paltq->altq);
1441 pfctl_rules(int dev, char *filename, int opts, int optimize,
1442 char *anchorname, struct pfr_buffer *trans)
1444 #define ERR(x) do { warn(x); goto _error; } while(0)
1445 #define ERRX(x) do { warnx(x); goto _error; } while(0)
1447 struct pfr_buffer *t, buf;
1448 struct pfioc_altq pa;
1450 struct pf_ruleset *rs;
1451 struct pfr_table trs;
1455 RB_INIT(&pf_anchors);
1456 memset(&pf_main_anchor, 0, sizeof(pf_main_anchor));
1457 pf_init_ruleset(&pf_main_anchor.ruleset);
1458 pf_main_anchor.ruleset.anchor = &pf_main_anchor;
1459 if (trans == NULL) {
1460 bzero(&buf, sizeof(buf));
1461 buf.pfrb_type = PFRB_TRANS;
1466 osize = t->pfrb_size;
1469 memset(&pa, 0, sizeof(pa));
1470 memset(&pf, 0, sizeof(pf));
1471 memset(&trs, 0, sizeof(trs));
1472 if ((path = calloc(1, MAXPATHLEN)) == NULL)
1473 ERRX("pfctl_rules: calloc");
1474 if (strlcpy(trs.pfrt_anchor, anchorname,
1475 sizeof(trs.pfrt_anchor)) >= sizeof(trs.pfrt_anchor))
1476 ERRX("pfctl_rules: strlcpy");
1479 pf.optimize = optimize;
1480 pf.loadopt = loadopt;
1482 /* non-brace anchor, create without resolving the path */
1483 if ((pf.anchor = calloc(1, sizeof(*pf.anchor))) == NULL)
1484 ERRX("pfctl_rules: calloc");
1485 rs = &pf.anchor->ruleset;
1486 pf_init_ruleset(rs);
1487 rs->anchor = pf.anchor;
1488 if (strlcpy(pf.anchor->path, anchorname,
1489 sizeof(pf.anchor->path)) >= sizeof(pf.anchor->path))
1490 errx(1, "pfctl_add_rule: strlcpy");
1491 if (strlcpy(pf.anchor->name, anchorname,
1492 sizeof(pf.anchor->name)) >= sizeof(pf.anchor->name))
1493 errx(1, "pfctl_add_rule: strlcpy");
1496 pf.astack[0] = pf.anchor;
1499 pf.loadopt &= ~PFCTL_FLAG_ALTQ;
1502 pfctl_init_options(&pf);
1504 if ((opts & PF_OPT_NOACTION) == 0) {
1506 * XXX For the time being we need to open transactions for
1507 * the main ruleset before parsing, because tables are still
1508 * loaded at parse time.
1510 if (pfctl_ruleset_trans(&pf, anchorname, pf.anchor))
1511 ERRX("pfctl_rules");
1512 if (altqsupport && (pf.loadopt & PFCTL_FLAG_ALTQ))
1514 pfctl_get_ticket(t, PF_RULESET_ALTQ, anchorname);
1515 if (pf.loadopt & PFCTL_FLAG_TABLE)
1516 pf.astack[0]->ruleset.tticket =
1517 pfctl_get_ticket(t, PF_RULESET_TABLE, anchorname);
1520 if (parse_config(filename, &pf) < 0) {
1521 if ((opts & PF_OPT_NOACTION) == 0)
1522 ERRX("Syntax error in config file: "
1523 "pf rules not loaded");
1527 if (loadopt & PFCTL_FLAG_OPTION)
1528 pfctl_clear_skip_ifaces(&pf);
1530 if ((pf.loadopt & PFCTL_FLAG_FILTER &&
1531 (pfctl_load_ruleset(&pf, path, rs, PF_RULESET_SCRUB, 0))) ||
1532 (pf.loadopt & PFCTL_FLAG_NAT &&
1533 (pfctl_load_ruleset(&pf, path, rs, PF_RULESET_NAT, 0) ||
1534 pfctl_load_ruleset(&pf, path, rs, PF_RULESET_RDR, 0) ||
1535 pfctl_load_ruleset(&pf, path, rs, PF_RULESET_BINAT, 0))) ||
1536 (pf.loadopt & PFCTL_FLAG_FILTER &&
1537 pfctl_load_ruleset(&pf, path, rs, PF_RULESET_FILTER, 0))) {
1538 if ((opts & PF_OPT_NOACTION) == 0)
1539 ERRX("Unable to load rules into kernel");
1544 if ((altqsupport && (pf.loadopt & PFCTL_FLAG_ALTQ) != 0))
1545 if (check_commit_altq(dev, opts) != 0)
1546 ERRX("errors in altq config");
1548 /* process "load anchor" directives */
1550 if (pfctl_load_anchors(dev, &pf, t) == -1)
1551 ERRX("load anchors");
1553 if (trans == NULL && (opts & PF_OPT_NOACTION) == 0) {
1555 if (pfctl_load_options(&pf))
1557 if (pfctl_trans(dev, t, DIOCXCOMMIT, osize))
1563 if (trans == NULL) { /* main ruleset */
1564 if ((opts & PF_OPT_NOACTION) == 0)
1565 if (pfctl_trans(dev, t, DIOCXROLLBACK, osize))
1566 err(1, "DIOCXROLLBACK");
1568 } else { /* sub ruleset */
1577 pfctl_fopen(const char *name, const char *mode)
1582 fp = fopen(name, mode);
1585 if (fstat(fileno(fp), &st)) {
1589 if (S_ISDIR(st.st_mode)) {
1598 pfctl_init_options(struct pfctl *pf)
1601 pf->timeout[PFTM_TCP_FIRST_PACKET] = PFTM_TCP_FIRST_PACKET_VAL;
1602 pf->timeout[PFTM_TCP_OPENING] = PFTM_TCP_OPENING_VAL;
1603 pf->timeout[PFTM_TCP_ESTABLISHED] = PFTM_TCP_ESTABLISHED_VAL;
1604 pf->timeout[PFTM_TCP_CLOSING] = PFTM_TCP_CLOSING_VAL;
1605 pf->timeout[PFTM_TCP_FIN_WAIT] = PFTM_TCP_FIN_WAIT_VAL;
1606 pf->timeout[PFTM_TCP_CLOSED] = PFTM_TCP_CLOSED_VAL;
1607 pf->timeout[PFTM_UDP_FIRST_PACKET] = PFTM_UDP_FIRST_PACKET_VAL;
1608 pf->timeout[PFTM_UDP_SINGLE] = PFTM_UDP_SINGLE_VAL;
1609 pf->timeout[PFTM_UDP_MULTIPLE] = PFTM_UDP_MULTIPLE_VAL;
1610 pf->timeout[PFTM_ICMP_FIRST_PACKET] = PFTM_ICMP_FIRST_PACKET_VAL;
1611 pf->timeout[PFTM_ICMP_ERROR_REPLY] = PFTM_ICMP_ERROR_REPLY_VAL;
1612 pf->timeout[PFTM_OTHER_FIRST_PACKET] = PFTM_OTHER_FIRST_PACKET_VAL;
1613 pf->timeout[PFTM_OTHER_SINGLE] = PFTM_OTHER_SINGLE_VAL;
1614 pf->timeout[PFTM_OTHER_MULTIPLE] = PFTM_OTHER_MULTIPLE_VAL;
1615 pf->timeout[PFTM_FRAG] = PFTM_FRAG_VAL;
1616 pf->timeout[PFTM_INTERVAL] = PFTM_INTERVAL_VAL;
1617 pf->timeout[PFTM_SRC_NODE] = PFTM_SRC_NODE_VAL;
1618 pf->timeout[PFTM_TS_DIFF] = PFTM_TS_DIFF_VAL;
1619 pf->timeout[PFTM_ADAPTIVE_START] = PFSTATE_ADAPT_START;
1620 pf->timeout[PFTM_ADAPTIVE_END] = PFSTATE_ADAPT_END;
1622 pf->limit[PF_LIMIT_STATES] = PFSTATE_HIWAT;
1623 pf->limit[PF_LIMIT_FRAGS] = PFFRAG_FRENT_HIWAT;
1624 pf->limit[PF_LIMIT_SRC_NODES] = PFSNODE_HIWAT;
1625 pf->limit[PF_LIMIT_TABLE_ENTRIES] = PFR_KENTRY_HIWAT;
1627 pf->debug = PF_DEBUG_URGENT;
1631 pfctl_load_options(struct pfctl *pf)
1635 if ((loadopt & PFCTL_FLAG_OPTION) == 0)
1639 for (i = 0; i < PF_LIMIT_MAX; i++) {
1640 if ((pf->opts & PF_OPT_MERGE) && !pf->limit_set[i])
1642 if (pfctl_load_limit(pf, i, pf->limit[i]))
1647 * If we've set the limit, but haven't explicitly set adaptive
1648 * timeouts, do it now with a start of 60% and end of 120%.
1650 if (pf->limit_set[PF_LIMIT_STATES] &&
1651 !pf->timeout_set[PFTM_ADAPTIVE_START] &&
1652 !pf->timeout_set[PFTM_ADAPTIVE_END]) {
1653 pf->timeout[PFTM_ADAPTIVE_START] =
1654 (pf->limit[PF_LIMIT_STATES] / 10) * 6;
1655 pf->timeout_set[PFTM_ADAPTIVE_START] = 1;
1656 pf->timeout[PFTM_ADAPTIVE_END] =
1657 (pf->limit[PF_LIMIT_STATES] / 10) * 12;
1658 pf->timeout_set[PFTM_ADAPTIVE_END] = 1;
1662 for (i = 0; i < PFTM_MAX; i++) {
1663 if ((pf->opts & PF_OPT_MERGE) && !pf->timeout_set[i])
1665 if (pfctl_load_timeout(pf, i, pf->timeout[i]))
1670 if (!(pf->opts & PF_OPT_MERGE) || pf->debug_set)
1671 if (pfctl_load_debug(pf, pf->debug))
1675 if (!(pf->opts & PF_OPT_MERGE) || pf->ifname_set)
1676 if (pfctl_load_logif(pf, pf->ifname))
1680 if (!(pf->opts & PF_OPT_MERGE) || pf->hostid_set)
1681 if (pfctl_load_hostid(pf, pf->hostid))
1688 pfctl_set_limit(struct pfctl *pf, const char *opt, unsigned int limit)
1693 for (i = 0; pf_limits[i].name; i++) {
1694 if (strcasecmp(opt, pf_limits[i].name) == 0) {
1695 pf->limit[pf_limits[i].index] = limit;
1696 pf->limit_set[pf_limits[i].index] = 1;
1700 if (pf_limits[i].name == NULL) {
1701 warnx("Bad pool name.");
1705 if (pf->opts & PF_OPT_VERBOSE)
1706 printf("set limit %s %d\n", opt, limit);
1712 pfctl_load_limit(struct pfctl *pf, unsigned int index, unsigned int limit)
1714 struct pfioc_limit pl;
1716 memset(&pl, 0, sizeof(pl));
1719 if (ioctl(pf->dev, DIOCSETLIMIT, &pl)) {
1721 warnx("Current pool size exceeds requested hard limit");
1723 warnx("DIOCSETLIMIT");
1730 pfctl_set_timeout(struct pfctl *pf, const char *opt, int seconds, int quiet)
1734 if ((loadopt & PFCTL_FLAG_OPTION) == 0)
1737 for (i = 0; pf_timeouts[i].name; i++) {
1738 if (strcasecmp(opt, pf_timeouts[i].name) == 0) {
1739 pf->timeout[pf_timeouts[i].timeout] = seconds;
1740 pf->timeout_set[pf_timeouts[i].timeout] = 1;
1745 if (pf_timeouts[i].name == NULL) {
1746 warnx("Bad timeout name.");
1751 if (pf->opts & PF_OPT_VERBOSE && ! quiet)
1752 printf("set timeout %s %d\n", opt, seconds);
1758 pfctl_load_timeout(struct pfctl *pf, unsigned int timeout, unsigned int seconds)
1762 memset(&pt, 0, sizeof(pt));
1763 pt.timeout = timeout;
1764 pt.seconds = seconds;
1765 if (ioctl(pf->dev, DIOCSETTIMEOUT, &pt)) {
1766 warnx("DIOCSETTIMEOUT");
1773 pfctl_set_optimization(struct pfctl *pf, const char *opt)
1775 const struct pf_hint *hint;
1778 if ((loadopt & PFCTL_FLAG_OPTION) == 0)
1781 for (i = 0; pf_hints[i].name; i++)
1782 if (strcasecmp(opt, pf_hints[i].name) == 0)
1785 hint = pf_hints[i].hint;
1787 warnx("invalid state timeouts optimization");
1791 for (i = 0; hint[i].name; i++)
1792 if ((r = pfctl_set_timeout(pf, hint[i].name,
1793 hint[i].timeout, 1)))
1796 if (pf->opts & PF_OPT_VERBOSE)
1797 printf("set optimization %s\n", opt);
1803 pfctl_set_logif(struct pfctl *pf, char *ifname)
1806 if ((loadopt & PFCTL_FLAG_OPTION) == 0)
1809 if (!strcmp(ifname, "none")) {
1813 pf->ifname = strdup(ifname);
1815 errx(1, "pfctl_set_logif: strdup");
1819 if (pf->opts & PF_OPT_VERBOSE)
1820 printf("set loginterface %s\n", ifname);
1826 pfctl_load_logif(struct pfctl *pf, char *ifname)
1830 memset(&pi, 0, sizeof(pi));
1831 if (ifname && strlcpy(pi.ifname, ifname,
1832 sizeof(pi.ifname)) >= sizeof(pi.ifname)) {
1833 warnx("pfctl_load_logif: strlcpy");
1836 if (ioctl(pf->dev, DIOCSETSTATUSIF, &pi)) {
1837 warnx("DIOCSETSTATUSIF");
1844 pfctl_set_hostid(struct pfctl *pf, u_int32_t hostid)
1846 if ((loadopt & PFCTL_FLAG_OPTION) == 0)
1851 pf->hostid = hostid;
1854 if (pf->opts & PF_OPT_VERBOSE)
1855 printf("set hostid 0x%08x\n", ntohl(hostid));
1861 pfctl_load_hostid(struct pfctl *pf, u_int32_t hostid)
1863 if (ioctl(dev, DIOCSETHOSTID, &hostid)) {
1864 warnx("DIOCSETHOSTID");
1871 pfctl_set_debug(struct pfctl *pf, char *d)
1875 if ((loadopt & PFCTL_FLAG_OPTION) == 0)
1878 if (!strcmp(d, "none"))
1879 pf->debug = PF_DEBUG_NONE;
1880 else if (!strcmp(d, "urgent"))
1881 pf->debug = PF_DEBUG_URGENT;
1882 else if (!strcmp(d, "misc"))
1883 pf->debug = PF_DEBUG_MISC;
1884 else if (!strcmp(d, "loud"))
1885 pf->debug = PF_DEBUG_NOISY;
1887 warnx("unknown debug level \"%s\"", d);
1894 if ((pf->opts & PF_OPT_NOACTION) == 0)
1895 if (ioctl(dev, DIOCSETDEBUG, &level))
1896 err(1, "DIOCSETDEBUG");
1898 if (pf->opts & PF_OPT_VERBOSE)
1899 printf("set debug %s\n", d);
1905 pfctl_load_debug(struct pfctl *pf, unsigned int level)
1907 if (ioctl(pf->dev, DIOCSETDEBUG, &level)) {
1908 warnx("DIOCSETDEBUG");
1915 pfctl_set_interface_flags(struct pfctl *pf, char *ifname, int flags, int how)
1917 struct pfioc_iface pi;
1919 if ((loadopt & PFCTL_FLAG_OPTION) == 0)
1922 bzero(&pi, sizeof(pi));
1924 pi.pfiio_flags = flags;
1926 if (strlcpy(pi.pfiio_name, ifname, sizeof(pi.pfiio_name)) >=
1927 sizeof(pi.pfiio_name))
1928 errx(1, "pfctl_set_interface_flags: strlcpy");
1930 if ((pf->opts & PF_OPT_NOACTION) == 0) {
1932 if (ioctl(pf->dev, DIOCCLRIFFLAG, &pi))
1933 err(1, "DIOCCLRIFFLAG");
1935 if (ioctl(pf->dev, DIOCSETIFFLAG, &pi))
1936 err(1, "DIOCSETIFFLAG");
1937 pfctl_check_skip_ifaces(ifname);
1944 pfctl_debug(int dev, u_int32_t level, int opts)
1946 if (ioctl(dev, DIOCSETDEBUG, &level))
1947 err(1, "DIOCSETDEBUG");
1948 if ((opts & PF_OPT_QUIET) == 0) {
1949 fprintf(stderr, "debug level set to '");
1952 fprintf(stderr, "none");
1954 case PF_DEBUG_URGENT:
1955 fprintf(stderr, "urgent");
1958 fprintf(stderr, "misc");
1960 case PF_DEBUG_NOISY:
1961 fprintf(stderr, "loud");
1964 fprintf(stderr, "<invalid>");
1967 fprintf(stderr, "'\n");
1972 pfctl_test_altqsupport(int dev, int opts)
1974 struct pfioc_altq pa;
1976 if (ioctl(dev, DIOCGETALTQS, &pa)) {
1977 if (errno == ENODEV) {
1978 if (opts & PF_OPT_VERBOSE)
1979 fprintf(stderr, "No ALTQ support in kernel\n"
1980 "ALTQ related functions disabled\n");
1983 err(1, "DIOCGETALTQS");
1989 pfctl_show_anchors(int dev, int opts, char *anchorname)
1991 struct pfioc_ruleset pr;
1994 memset(&pr, 0, sizeof(pr));
1995 memcpy(pr.path, anchorname, sizeof(pr.path));
1996 if (ioctl(dev, DIOCGETRULESETS, &pr)) {
1997 if (errno == EINVAL)
1998 fprintf(stderr, "Anchor '%s' not found.\n",
2001 err(1, "DIOCGETRULESETS");
2005 for (nr = 0; nr < mnr; ++nr) {
2006 char sub[MAXPATHLEN];
2009 if (ioctl(dev, DIOCGETRULESET, &pr))
2010 err(1, "DIOCGETRULESET");
2011 if (!strcmp(pr.name, PF_RESERVED_ANCHOR))
2015 strlcat(sub, pr.path, sizeof(sub));
2016 strlcat(sub, "/", sizeof(sub));
2018 strlcat(sub, pr.name, sizeof(sub));
2019 if (sub[0] != '_' || (opts & PF_OPT_VERBOSE))
2020 printf(" %s\n", sub);
2021 if ((opts & PF_OPT_VERBOSE) && pfctl_show_anchors(dev, opts, sub))
2028 pfctl_lookup_option(char *cmd, const char **list)
2030 if (cmd != NULL && *cmd)
2031 for (; *list; list++)
2032 if (!strncmp(cmd, *list, strlen(cmd)))
2038 main(int argc, char *argv[])
2042 int mode = O_RDONLY;
2044 int optimize = PF_OPTIMIZE_BASIC;
2045 char anchorname[MAXPATHLEN];
2051 while ((ch = getopt(argc, argv,
2052 "a:AdD:eqf:F:ghi:k:K:mnNOo:Pp:rRs:t:T:vx:z")) != -1) {
2058 opts |= PF_OPT_DISABLE;
2062 if (pfctl_cmdline_symset(optarg) < 0)
2063 warnx("could not parse macro definition %s",
2067 opts |= PF_OPT_ENABLE;
2071 opts |= PF_OPT_QUIET;
2074 clearopt = pfctl_lookup_option(optarg, clearopt_list);
2075 if (clearopt == NULL) {
2076 warnx("Unknown flush modifier '%s'", optarg);
2085 if (state_killers >= 2) {
2086 warnx("can only specify -k twice");
2090 state_kill[state_killers++] = optarg;
2094 if (src_node_killers >= 2) {
2095 warnx("can only specify -K twice");
2099 src_node_kill[src_node_killers++] = optarg;
2103 opts |= PF_OPT_MERGE;
2106 opts |= PF_OPT_NOACTION;
2109 loadopt |= PFCTL_FLAG_NAT;
2112 opts |= PF_OPT_USEDNS;
2119 opts |= PF_OPT_DEBUG;
2122 loadopt |= PFCTL_FLAG_ALTQ;
2125 loadopt |= PFCTL_FLAG_FILTER;
2128 optiopt = pfctl_lookup_option(optarg, optiopt_list);
2129 if (optiopt == NULL) {
2130 warnx("Unknown optimization '%s'", optarg);
2133 opts |= PF_OPT_OPTIMIZE;
2136 loadopt |= PFCTL_FLAG_OPTION;
2142 opts |= PF_OPT_NUMERIC;
2145 showopt = pfctl_lookup_option(optarg, showopt_list);
2146 if (showopt == NULL) {
2147 warnx("Unknown show modifier '%s'", optarg);
2155 tblcmdopt = pfctl_lookup_option(optarg, tblcmdopt_list);
2156 if (tblcmdopt == NULL) {
2157 warnx("Unknown table command '%s'", optarg);
2162 if (opts & PF_OPT_VERBOSE)
2163 opts |= PF_OPT_VERBOSE2;
2164 opts |= PF_OPT_VERBOSE;
2167 debugopt = pfctl_lookup_option(optarg, debugopt_list);
2168 if (debugopt == NULL) {
2169 warnx("Unknown debug level '%s'", optarg);
2175 opts |= PF_OPT_CLRRULECTRS;
2186 if (tblcmdopt != NULL) {
2191 loadopt |= PFCTL_FLAG_TABLE;
2194 mode = strchr("acdefkrz", ch) ? O_RDWR : O_RDONLY;
2195 } else if (argc != optind) {
2196 warnx("unknown command line argument: %s ...", argv[optind]);
2203 if ((path = calloc(1, MAXPATHLEN)) == NULL)
2204 errx(1, "pfctl: calloc");
2205 memset(anchorname, 0, sizeof(anchorname));
2206 if (anchoropt != NULL) {
2207 int len = strlen(anchoropt);
2209 if (anchoropt[len - 1] == '*') {
2210 if (len >= 2 && anchoropt[len - 2] == '/')
2211 anchoropt[len - 2] = '\0';
2213 anchoropt[len - 1] = '\0';
2214 opts |= PF_OPT_RECURSE;
2216 if (strlcpy(anchorname, anchoropt,
2217 sizeof(anchorname)) >= sizeof(anchorname))
2218 errx(1, "anchor name '%s' too long",
2220 loadopt &= PFCTL_FLAG_FILTER|PFCTL_FLAG_NAT|PFCTL_FLAG_TABLE;
2223 if ((opts & PF_OPT_NOACTION) == 0) {
2224 dev = open(pf_device, mode);
2226 err(1, "%s", pf_device);
2227 altqsupport = pfctl_test_altqsupport(dev, opts);
2229 dev = open(pf_device, O_RDONLY);
2231 opts |= PF_OPT_DUMMYACTION;
2232 /* turn off options */
2233 opts &= ~ (PF_OPT_DISABLE | PF_OPT_ENABLE);
2234 clearopt = showopt = debugopt = NULL;
2235 #if defined(__FreeBSD__) && !defined(ENABLE_ALTQ)
2242 if (opts & PF_OPT_DISABLE)
2243 if (pfctl_disable(dev, opts))
2246 if (showopt != NULL) {
2249 pfctl_show_anchors(dev, opts, anchorname);
2252 pfctl_load_fingerprints(dev, opts);
2253 pfctl_show_rules(dev, path, opts, PFCTL_SHOW_RULES,
2257 pfctl_load_fingerprints(dev, opts);
2258 pfctl_show_rules(dev, path, opts, PFCTL_SHOW_LABELS,
2262 pfctl_load_fingerprints(dev, opts);
2263 pfctl_show_nat(dev, opts, anchorname);
2266 pfctl_show_altq(dev, ifaceopt, opts,
2267 opts & PF_OPT_VERBOSE2);
2270 pfctl_show_states(dev, ifaceopt, opts);
2273 pfctl_show_src_nodes(dev, opts);
2276 pfctl_show_status(dev, opts);
2279 pfctl_show_timeouts(dev, opts);
2282 pfctl_show_limits(dev, opts);
2285 opts |= PF_OPT_SHOWALL;
2286 pfctl_load_fingerprints(dev, opts);
2288 pfctl_show_nat(dev, opts, anchorname);
2289 pfctl_show_rules(dev, path, opts, 0, anchorname, 0);
2290 pfctl_show_altq(dev, ifaceopt, opts, 0);
2291 pfctl_show_states(dev, ifaceopt, opts);
2292 pfctl_show_src_nodes(dev, opts);
2293 pfctl_show_status(dev, opts);
2294 pfctl_show_rules(dev, path, opts, 1, anchorname, 0);
2295 pfctl_show_timeouts(dev, opts);
2296 pfctl_show_limits(dev, opts);
2297 pfctl_show_tables(anchorname, opts);
2298 pfctl_show_fingerprints(opts);
2301 pfctl_show_tables(anchorname, opts);
2304 pfctl_load_fingerprints(dev, opts);
2305 pfctl_show_fingerprints(opts);
2308 pfctl_show_ifaces(ifaceopt, opts);
2313 if ((opts & PF_OPT_CLRRULECTRS) && showopt == NULL)
2314 pfctl_show_rules(dev, path, opts, PFCTL_SHOW_NOTHING,
2317 if (clearopt != NULL) {
2318 if (anchorname[0] == '_' || strstr(anchorname, "/_") != NULL)
2319 errx(1, "anchor names beginning with '_' cannot "
2320 "be modified from the command line");
2322 switch (*clearopt) {
2324 pfctl_clear_rules(dev, opts, anchorname);
2327 pfctl_clear_nat(dev, opts, anchorname);
2330 pfctl_clear_altq(dev, opts);
2333 pfctl_clear_states(dev, ifaceopt, opts);
2336 pfctl_clear_src_nodes(dev, opts);
2339 pfctl_clear_stats(dev, opts);
2342 pfctl_clear_rules(dev, opts, anchorname);
2343 pfctl_clear_nat(dev, opts, anchorname);
2344 pfctl_clear_tables(anchorname, opts);
2346 pfctl_clear_altq(dev, opts);
2347 pfctl_clear_states(dev, ifaceopt, opts);
2348 pfctl_clear_src_nodes(dev, opts);
2349 pfctl_clear_stats(dev, opts);
2350 pfctl_clear_fingerprints(dev, opts);
2351 pfctl_clear_interface_flags(dev, opts);
2355 pfctl_clear_fingerprints(dev, opts);
2358 pfctl_clear_tables(anchorname, opts);
2362 if (state_killers) {
2363 if (!strcmp(state_kill[0], "label"))
2364 pfctl_label_kill_states(dev, ifaceopt, opts);
2365 else if (!strcmp(state_kill[0], "id"))
2366 pfctl_id_kill_states(dev, ifaceopt, opts);
2368 pfctl_net_kill_states(dev, ifaceopt, opts);
2371 if (src_node_killers)
2372 pfctl_kill_src_nodes(dev, ifaceopt, opts);
2374 if (tblcmdopt != NULL) {
2375 error = pfctl_command_tables(argc, argv, tableopt,
2376 tblcmdopt, rulesopt, anchorname, opts);
2379 if (optiopt != NULL) {
2385 optimize |= PF_OPTIMIZE_BASIC;
2389 optimize |= PF_OPTIMIZE_PROFILE;
2394 if ((rulesopt != NULL) && (loadopt & PFCTL_FLAG_OPTION) &&
2396 if (pfctl_get_skip_ifaces())
2399 if (rulesopt != NULL && !(opts & (PF_OPT_MERGE|PF_OPT_NOACTION)) &&
2400 !anchorname[0] && (loadopt & PFCTL_FLAG_OPTION))
2401 if (pfctl_file_fingerprints(dev, opts, PF_OSFP_FILE))
2404 if (rulesopt != NULL) {
2405 if (anchorname[0] == '_' || strstr(anchorname, "/_") != NULL)
2406 errx(1, "anchor names beginning with '_' cannot "
2407 "be modified from the command line");
2408 if (pfctl_rules(dev, rulesopt, opts, optimize,
2411 else if (!(opts & PF_OPT_NOACTION) &&
2412 (loadopt & PFCTL_FLAG_TABLE))
2413 warn_namespace_collision(NULL);
2416 if (opts & PF_OPT_ENABLE)
2417 if (pfctl_enable(dev, opts))
2420 if (debugopt != NULL) {
2421 switch (*debugopt) {
2423 pfctl_debug(dev, PF_DEBUG_NONE, opts);
2426 pfctl_debug(dev, PF_DEBUG_URGENT, opts);
2429 pfctl_debug(dev, PF_DEBUG_MISC, opts);
2432 pfctl_debug(dev, PF_DEBUG_NOISY, opts);