Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178281609
D62342.1796416582.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D62342.1796416582.diff
View Options
diff --git a/sys/netinet/ip_fw.h b/sys/netinet/ip_fw.h
--- a/sys/netinet/ip_fw.h
+++ b/sys/netinet/ip_fw.h
@@ -1095,7 +1095,7 @@
#define IPFW_RCFLAG_USER (IPFW_RCFLAG_RANGE | IPFW_RCFLAG_ALL | \
IPFW_RCFLAG_SET | IPFW_RCFLAG_DYNAMIC)
/* Internally used flags */
-#define IPFW_RCFLAG_DEFAULT 0x0100 /* Do not skip default rule */
+#define IPFW_RCFLAG_DEFAULT 0x0100 /* Do not skip default rule/set */
typedef struct _ipfw_ta_tinfo {
uint32_t flags; /* Format flags */
diff --git a/sys/netpfil/ipfw/ip_fw_sockopt.c b/sys/netpfil/ipfw/ip_fw_sockopt.c
--- a/sys/netpfil/ipfw/ip_fw_sockopt.c
+++ b/sys/netpfil/ipfw/ip_fw_sockopt.c
@@ -602,7 +602,8 @@
return (0);
/* Don't match rules in reserved set for flush requests */
- if ((rt->flags & IPFW_RCFLAG_ALL) != 0 && rule->set == RESVD_SET)
+ if ((rt->flags & IPFW_RCFLAG_ALL) != 0 &&
+ (rt->flags & IPFW_RCFLAG_DEFAULT) == 0 && rule->set == RESVD_SET)
return (0);
/* If we're filtering by set, don't match other sets */
diff --git a/tests/sys/netpfil/ipfw/Makefile b/tests/sys/netpfil/ipfw/Makefile
--- a/tests/sys/netpfil/ipfw/Makefile
+++ b/tests/sys/netpfil/ipfw/Makefile
@@ -11,7 +11,8 @@
skipto \
table \
tcpmss \
- unmapped
+ unmapped \
+ zero
ATF_TESTS_C+= nat_getlog \
rule_check
diff --git a/tests/sys/netpfil/ipfw/zero.sh b/tests/sys/netpfil/ipfw/zero.sh
new file mode 100644
--- /dev/null
+++ b/tests/sys/netpfil/ipfw/zero.sh
@@ -0,0 +1,67 @@
+# Copyright (c) 2026 Maxim Konovalov <maxim@FreeBSD.org>
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+. $(atf_get_srcdir)/../common/utils.subr
+
+atf_test_case "zero_all" "cleanup"
+zero_all_head()
+{
+ atf_set descr 'ipfw zero without a rule number clears set 31 too'
+ atf_set require.user root
+}
+
+zero_all_body()
+{
+ firewall_init "ipfw"
+
+ epair=$(vnet_mkepair)
+ vnet_mkjail alcatraz ${epair}b
+ ifconfig ${epair}a 192.0.2.0/31 up
+ jexec alcatraz ifconfig ${epair}b 192.0.2.1/31 up
+
+ atf_check -o ignore \
+ jexec alcatraz sysctl net.inet.ip.fw.dyn_keep_states=1
+ # Rules 10 and 20 accept the replies and all IPv6 packets, so only
+ # the echo requests from 192.0.2.0 reach the rules under test.
+ jexec alcatraz ipfw -q add 10 allow ip from any to any out
+ jexec alcatraz ipfw -q add 20 allow ip6 from any to any
+ jexec alcatraz ipfw -q add 30 check-state
+ jexec alcatraz ipfw -q add 100 count ip from 192.0.2.0 to any
+ jexec alcatraz ipfw -q add 200 set 31 count ip from 192.0.2.0 to any
+
+ # The first request reaches the default rule. The second creates
+ # a state that the deletion of rule 300 orphans, and the third
+ # matches that state, so the orphaned dynamic states counter (the
+ # first of the two rules 65535) counts it.
+ atf_check -o ignore ping -c 1 -t 2 192.0.2.1
+ jexec alcatraz ipfw -q add 300 allow icmp from 192.0.2.0 to any \
+ keep-state
+ atf_check -o ignore ping -c 1 -t 2 192.0.2.1
+ jexec alcatraz ipfw -q delete 300
+ atf_check -o ignore ping -c 1 -t 2 192.0.2.1
+
+ atf_check -o match:"^00100 +2 " -o match:"^00200 +2 " \
+ -o match:"^65535 +1 .* // orphaned dynamic states counter$" \
+ -o match:"^65535 +1 +[0-9]+ allow ip from any to any$" \
+ jexec alcatraz ipfw show
+ atf_check -o ignore jexec alcatraz ipfw zero
+ atf_check -o match:"^00100 +0 +0 " -o match:"^00200 +0 +0 " \
+ -o match:"^65535 +0 +0 .* // orphaned dynamic states counter$" \
+ -o match:"^65535 +0 +0 allow ip from any to any$" \
+ jexec alcatraz ipfw show
+}
+
+zero_all_cleanup()
+{
+ # The VNET teardown does not free a rule that an orphaned state
+ # still holds, so remove the state first.
+ jexec alcatraz ipfw -q -D delete 300 2>/dev/null
+ firewall_cleanup "ipfw"
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case "zero_all"
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 4, 8:36 PM (3 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42200558
Default Alt Text
D62342.1796416582.diff (3 KB)
Attached To
Mode
D62342: ipfw: let zero and resetlog clear the rules in set 31
Attached
Detach File
Event Timeline