fix) with ESMTPS id 4dZgwS6Hh7z3SNX for ; Mon, 22 Dec 2025 14:47:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1766414856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=j/JpBwvUgz0Ha5D26T3PV0HtT3DF/kiFyyF4pJZFFZo=; b=wFxapTE24fmA5EplX/ZgVS4S1D3QCCuT+IDdRQ9KtCD8SGAUaV6IDHEm0peu1fzSQpR8Oy kLO8eyEfX2j61OlsR0IJvvhHJEjVQkBSXYMpnVflw7+XBBtnBDka5XXwvQyh6gR6y8qFMJ w65er4yb3wwRU3hNQcELAfWYHSZtMRxb68MXrP4SIdmgUxpax+aWfEw9GnnBbHYsS/ol0d HhGHu0ipocNQL46Jw+FC/LhlU18smchhg/qatK3ZYCiLpHAmslHPPyJWjOAe0OpIyd89lt Ip/Dv2GzzkJ9eYrpVS1T6tdm59Yot0uHGduU2pZ3Yw+OaIWy9n1iY4D1GLFngA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1766414856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=j/JpBwvUgz0Ha5D26T3PV0HtT3DF/kiFyyF4pJZFFZo=; b=I4f+R0CGglj43WOrqNhwF5+bOPUONgpwPvNTkh0SijK8X9pXN4Kd/MXqbLBBAYHVjhq7Cb AyOnZQ/7fo93u3tps4vNZhfIPne3YFw5fgTwljCGQqUUMooy+ofpX574mhF990ueZUyhSp +4Vwp7drZfEGDUm/E9xcPvbFWFyBF6ImrHndtHAg+cvQJBMIMzLW1vLPTjGLVaCh/S5mwa 0H3KtcUc4+nEHF/wZ5GpSYBeJPOQAjF0p4Xs/6Ph2org/76lJ4BDzKBntjfYjYeDSJXFpV B/ISz7reGzMfWPWY80ZVXuynq0ctQNQTMX0y0tsklVJDqtT/Qnq3C0erHHja6w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1766414856; a=rsa-sha256; cv=none; b=SmNbkCH2tztxImNcVaViiU+PJq7NqxTQPnsueot30i7B3rgu6ZF3fco3d5nTlNaomI6fjt 8Y3cgww5iUr6WUX59L820J63ClMDAWzBIewrhDvxfKwlXx1yfbHO0o7ID5iCHAxMcpsd+q RuVQChiUlSfhYXJA7apZiM5LucH1mV6dUenFMnf7M3yKNbcy3let/mv3GyXA9trgYhJ2Rp NZDI2nC5M7Tfl9n0+pgBekeZn4g+yA6vWxB/M98NJ4NiJ67SriwNZLq+mUA+lxec1rNX4k a3LlnkdTgjgEFI6Nis+edf5wzCxTR1JxBRzrNIL2zWBbQG1wFJB+aWOk95cL+g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dZgwS5MRzzVpQ for ; Mon, 22 Dec 2025 14:47:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 40f0c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 22 Dec 2025 14:47:36 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 15178d8ed290 - main - pf: Fix state handling when ICMP packets are diverted List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 15178d8ed2904d5c4fa31a1531e60dcb1e0f9209 Auto-Submitted: auto-generated Date: Mon, 22 Dec 2025 14:47:36 +0000 Message-Id: <69495a08.40f0c.397e3ac0@gitrepo.freebsd.org> The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=15178d8ed2904d5c4fa31a1531e60dcb1e0f9209 commit 15178d8ed2904d5c4fa31a1531e60dcb1e0f9209 Author: Mark Johnston AuthorDate: 2025-12-20 18:18:50 +0000 Commit: Mark Johnston CommitDate: 2025-12-22 14:47:27 +0000 pf: Fix state handling when ICMP packets are diverted Commit 66f2f1c83247 ("pf: handle divert packets") missed a case that I happened to hit while testing something. Add a regression test for the ICMP case, based on the existing test. Fix a buglet in the existing test (missing whitespace after "["). Reviewed by: kp Sponsored by: OPNsense Sponsored by: Klara, Inc. MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D54321 --- sys/netpfil/pf/pf.c | 10 ++++++---- tests/sys/netpfil/pf/divert-to.sh | 40 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 2ebaf61a165f..755b87bcfeb7 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -11178,10 +11178,12 @@ pf_test(sa_family_t af, int dir, int pflags, struct ifnet *ifp, struct mbuf **m0 } action = pf_test_state_icmp(&s, &pd, &reason); if (action == PF_PASS || action == PF_AFRT) { - if (V_pfsync_update_state_ptr != NULL) - V_pfsync_update_state_ptr(s); - r = s->rule; - a = s->anchor; + if (s != NULL) { + if (V_pfsync_update_state_ptr != NULL) + V_pfsync_update_state_ptr(s); + r = s->rule; + a = s->anchor; + } } else if (s == NULL) action = pf_test_rule(&r, &s, &pd, &a, &ruleset, &reason, inp, &match_rules); diff --git a/tests/sys/netpfil/pf/divert-to.sh b/tests/sys/netpfil/pf/divert-to.sh index 153136199311..3028c9e75afd 100644 --- a/tests/sys/netpfil/pf/divert-to.sh +++ b/tests/sys/netpfil/pf/divert-to.sh @@ -402,8 +402,7 @@ pr260867_body() "pass in on ${epair}b proto tcp from any to port 7 divert-to 0.0.0.0 port 1001" reply=$(echo "foo" | nc -N 192.0.2.2 7) - if ["${reply}" != "foo" ]; - then + if [ "${reply}" != "foo" ]; then atf_fail "Did not receive echo reply" fi } @@ -413,6 +412,42 @@ pr260867_cleanup() pft_cleanup } +atf_test_case "pr260867_icmp" "cleanup" +pr260867_icmp_head() +{ + atf_set descr 'Variant of the PR260867 test' + atf_set require.user root +} + +pr260867_icmp_body() +{ + pft_init + divert_init + + epair=$(vnet_mkepair) + + atf_check ifconfig ${epair}a 192.0.2.1/24 up + + vnet_mkjail alcatraz ${epair}b + jexec alcatraz ifconfig ${epair}b 192.0.2.2/24 up + + # Sanity check + atf_check -s exit:0 -o ignore ping -c3 192.0.2.2 + + jexec alcatraz $(atf_get_srcdir)/../common/divapp 1001 divert-back & + + jexec alcatraz pfctl -e + pft_set_rules alcatraz \ + "pass in on ${epair}b proto icmp from any to any divert-to 0.0.0.0 port 1001" + + atf_check -o ignore ping -c 3 192.0.2.2 +} + +pr260867_icmp_cleanup() +{ + pft_cleanup +} + atf_init_test_cases() { atf_add_test_case "in_div" @@ -426,4 +461,5 @@ atf_init_test_cases() atf_add_test_case "in_dn_in_div_in_out_div_out_dn_out" atf_add_test_case "pr260867" + atf_add_test_case "pr260867_icmp" }