git: f4fe4c3d17f9 - main - pf: Remove a table entry regardless of its mark
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 15 Oct 2026 18:10:32 UTC
The branch main has been updated by rcm:
URL: https://cgit.FreeBSD.org/src/commit/?id=f4fe4c3d17f9bb523981b88a01d7c0f0c0f00c36
commit f4fe4c3d17f9bb523981b88a01d7c0f0c0f00c36
Author: R. Christian McDonald <rcm@FreeBSD.org>
AuthorDate: 2026-10-15 18:10:11 +0000
Commit: R. Christian McDonald <rcm@FreeBSD.org>
CommitDate: 2026-10-15 18:10:11 +0000
pf: Remove a table entry regardless of its mark
pfr_remove_kentry() returns without removing an entry whose mark is
set. The mark is scratch space for the operations that handle a list
of addresses: each resets it before use and leaves it set on the
entries it kept, so after "pfctl -T replace" or "pfctl -T zero" of an
address the entry stays marked. An address a source limiter put in
its table is then never taken out again when the source falls below
the low-water mark.
Remove the entry whether it is marked or not; nothing else is in the
work queue.
Add a regression test.
Reviewed by: kp
Fixes: 461648121230 ("pf: introduce source and state limiters")
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D60530
---
sys/netpfil/pf/pf_table.c | 4 ---
tests/sys/netpfil/pf/limiters.sh | 56 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/sys/netpfil/pf/pf_table.c b/sys/netpfil/pf/pf_table.c
index 2450feddaded..b1bb68935ab5 100644
--- a/sys/netpfil/pf/pf_table.c
+++ b/sys/netpfil/pf/pf_table.c
@@ -902,10 +902,6 @@ pfr_remove_kentry(struct pfr_ktable *kt, struct pfr_addr *ad)
if (p == NULL || p->pfrke_not)
return (ESRCH);
- if (p->pfrke_mark)
- return (0);
-
- p->pfrke_mark = 1;
SLIST_INSERT_HEAD(&workq, p, pfrke_workq);
pfr_remove_kentries(kt, &workq);
diff --git a/tests/sys/netpfil/pf/limiters.sh b/tests/sys/netpfil/pf/limiters.sh
index d109fa424d22..a593adac10c0 100644
--- a/tests/sys/netpfil/pf/limiters.sh
+++ b/tests/sys/netpfil/pf/limiters.sh
@@ -365,6 +365,61 @@ source_table_cleanup()
pft_cleanup
}
+atf_test_case "source_table_marked" "cleanup"
+source_table_marked_head()
+{
+ atf_set descr 'Test the removal of a source from a table after a replace'
+ atf_set require.user root
+}
+
+source_table_marked_body()
+{
+ pft_init
+
+ epair=$(vnet_mkepair)
+
+ ifconfig ${epair}a 192.0.2.2/24 up
+
+ vnet_mkjail alcatraz ${epair}b
+ jexec alcatraz ifconfig ${epair}b 192.0.2.1/24 up
+
+ # Sanity check
+ atf_check -s exit:0 -o ignore \
+ ping -c 1 192.0.2.1
+
+ jexec alcatraz pfctl -e
+
+ pft_set_rules alcatraz \
+ "set timeout icmp.error 120" \
+ "table <many> persist" \
+ "source limiter \"server\" id 1 entries 128 limit 100 table <many> above 2 below 2" \
+ "pass in proto icmp source limiter \"server\""
+
+ # Three states put the source in the table.
+ atf_check -s exit:0 -o ignore ping -c 1 192.0.2.1
+ atf_check -s exit:0 -o ignore ping -c 1 192.0.2.1
+ atf_check -s exit:0 -o ignore ping -c 1 192.0.2.1
+ sleep 1
+ atf_check -s exit:0 -o "match:192.0.2.2" \
+ jexec alcatraz pfctl -t many -T show
+
+ # A replace that keeps the address leaves its entry marked.
+ atf_check -s exit:0 -e ignore \
+ jexec alcatraz pfctl -t many -T replace 192.0.2.2 192.0.2.99
+
+ # The marked entry used to be skipped when the source was removed.
+ atf_check -s exit:0 -e ignore \
+ jexec alcatraz pfctl -F states
+ sleep 1
+ atf_check -s exit:0 -o "not-match:192.0.2.2" -o "match:192.0.2.99" \
+ jexec alcatraz pfctl -t many -T show
+}
+
+source_table_marked_cleanup()
+{
+ pft_cleanup
+}
+
atf_test_case "out" "cleanup"
out_head()
{
@@ -418,5 +473,6 @@ atf_init_test_cases()
atf_add_test_case "state_multiple"
atf_add_test_case "source_basic"
atf_add_test_case "source_table"
+ atf_add_test_case "source_table_marked"
atf_add_test_case "out"
}