From nobody Thu Sep 10 09:14:14 2026 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hgX6t3yftz6rj8Y for ; Thu, 10 Sep 2026 09:14:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hgX6t2FNQz4T6f for ; Thu, 10 Sep 2026 09:14:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789031654; 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=ZeXUmOWlcsNNVGIGzOG+wWxATrKxDzuYIlCzWxtEI34=; b=iLgq8H6CUBvskvrSA+C7/NVP7BBqMEO3Er0DU84T5arU9VWsddPeQRsxkB9FP6/22gmGOW T149KUPG6VUUUBPD3NJIH84C1psi9D5AKRXFEs7E3SthlVSdbr5h2yi+r8K91B4gwGNcIV hKlXtAFc8Ui/2u6sZCriNB228ILflmBPw1BBY7l0MLCVoIBCFPL0Wfqz6GhoqbUZY7V6Po UJsyo8ax+whaNtgYgUB2+XJskWXePC6BCfLepVtbsxdMBNBe9uLKXX4lZb7pua9/6AiSh3 6dD2wocQVibqus9cfofK70D0qZeESbRDckslfWDVkpLPqrJCSYsf5Qy+hpzqMw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1789031654; b=g83tZb84PjhRQuSpqRu22U4fuH4pAw+wLaJ0DasRE9cJlF6F/WobzsabcvGeThzsXfmaCv QVlJ61QqiP/ff9Fz7I7Jbxo/4igQuBxMAV2dk3NAdUl4aAWWVGxGqZGxZ8LJcUFsIGpHhQ obyQFxgRKB3TreJinCn1J4Q47qpYEFwvHBvLhF49mSwpHBmllSrJqPF8PJy0reXuRh++1L p+2rukl7pwNJjxoYMuIy4dPzneh0Ea07//2mLygMqKqXuVAXSq53r3J9qDZKboBE7xd0w1 dsu6KsYc0812THrzi24o+u/VB61gjXU8pqt5FFXnX4uYXmM/YjUM9FPilooZyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789031654; 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=ZeXUmOWlcsNNVGIGzOG+wWxATrKxDzuYIlCzWxtEI34=; b=w33Jovqo9/xi7+MJ6emtYGZemoJpC/tt+V94SX83JDnFVEvUEbT2GPHyvaK3ronjQaQ3V4 r89Kf2xsAh5XSpYUCH+RkjygHZ8n64WG+3u1RVHhZJKn3Q20cs+ZCgFzAQRkxUM2DTo5RU +nKRzkTmb/hflSWhu7dlPm0vB+nCVWaSeWyE3bQbgDuPrQJ2/NDkpAwQ1okY6TZ2ESn91x 5rhlscmTC17ihB81+u6WSqNYDfFoVP4rMJA15Xk/8tMYbVpzRhqEv8engFU6t52dYziP3a ysXA8t3jLRji1wHimoxt0y3R1eYvKI544B5OQI1TS53bF3aawu6S8CC5z7ZZdg== 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 4hgX6t1KCWzLFR for ; Thu, 10 Sep 2026 09:14:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 22dac by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 10 Sep 2026 09:14:14 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 971d24f203dd - stable/15 - pf: Fix fallout from the STATE_LOOKUP macro removal List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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/stable/15 X-Git-Reftype: branch X-Git-Commit: 971d24f203dd8b6aaf14d674db7453c7f4f29e55 Auto-Submitted: auto-generated Date: Thu, 10 Sep 2026 09:14:14 +0000 Message-Id: <6aa274e6.22dac.5e7f773c@gitrepo.freebsd.org> The branch stable/15 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=971d24f203dd8b6aaf14d674db7453c7f4f29e55 commit 971d24f203dd8b6aaf14d674db7453c7f4f29e55 Author: Mark Johnston AuthorDate: 2026-08-27 13:02:37 +0000 Commit: Mark Johnston CommitDate: 2026-09-10 07:51:49 +0000 pf: Fix fallout from the STATE_LOOKUP macro removal Commit 8572367b6814 ("pf: remove STATE_LOOKUP") introduced two seemingly unintentional changes with respect to divert(4)-injected packets (i.e., the PACKET_LOOPED case): we no longer return the matching state, and direct callers of pf_find_state() now treat matches of diverted packets the same as having no matching state at all. This seems inadvertent, and breaks certain rulesets which use divert-to. Fix them, and add a regression test case. Fixes: 8572367b6814 ("pf: remove STATE_LOOKUP") Reviewed by: kp MFC after: 2 weeks Sponsored by: OPNsense Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D59015 (cherry picked from commit 00a793def743b5be8fcbdd39fc1dfa61534ed66c) --- sys/netpfil/pf/pf.c | 17 +++------ tests/sys/netpfil/pf/route_to.sh | 82 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 11 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 8b17abb81b09..6092d0b5566e 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -1985,14 +1985,9 @@ out: return (PF_DROP); } } - if (PACKET_LOOPED(pd)) { - PF_STATE_UNLOCK(s); - return (PF_PASS); - } *state = s; - - return (PF_MATCH); + return (PACKET_LOOPED(pd) ? PF_PASS : PF_MATCH); } /* @@ -7880,7 +7875,7 @@ pf_icmp_state_lookup(struct pf_state_key_cmp *key, struct pf_pdesc *pd, return (PF_DROP); action = pf_find_state(pd, key, state); - if (action != PF_MATCH) + if (action != PF_MATCH && action != PF_PASS) return (action); if ((*state)->state_flags & PFSTATE_SLOPPY) @@ -8205,7 +8200,7 @@ pf_test_state_icmp(struct pf_kstate **state, struct pf_pdesc *pd, key.port[pd2.didx] = th->th_dport; action = pf_find_state(&pd2, &key, state); - if (action != PF_MATCH) + if (action != PF_MATCH && action != PF_PASS) return (action); if (pd->dir == (*state)->direction) { @@ -8400,7 +8395,7 @@ pf_test_state_icmp(struct pf_kstate **state, struct pf_pdesc *pd, key.port[pd2.didx] = uh->uh_dport; action = pf_find_state(&pd2, &key, state); - if (action != PF_MATCH) + if (action != PF_MATCH && action != PF_PASS) return (action); /* translate source/destination address, if necessary */ @@ -8532,7 +8527,7 @@ pf_test_state_icmp(struct pf_kstate **state, struct pf_pdesc *pd, key.port[pd2.didx] = sh->dest_port; action = pf_find_state(&pd2, &key, state); - if (action != PF_MATCH) + if (action != PF_MATCH && action != PF_PASS) return (action); if (pd->dir == (*state)->direction) { @@ -8918,7 +8913,7 @@ pf_test_state_icmp(struct pf_kstate **state, struct pf_pdesc *pd, key.port[0] = key.port[1] = 0; action = pf_find_state(&pd2, &key, state); - if (action != PF_MATCH) + if (action != PF_MATCH && action != PF_PASS) return (action); /* translate source/destination address, if necessary */ diff --git a/tests/sys/netpfil/pf/route_to.sh b/tests/sys/netpfil/pf/route_to.sh index 99387aa3802d..b81447a54a5e 100644 --- a/tests/sys/netpfil/pf/route_to.sh +++ b/tests/sys/netpfil/pf/route_to.sh @@ -1643,6 +1643,87 @@ prefer_ipv6_nexthop_ipv4_random_prefix_ipv6_cleanup() pft_cleanup } +atf_test_case "divert_to" "cleanup" +divert_to_head() +{ + atf_set descr 'Test that route-to is applied to divert-injected packets' + atf_set require.user root + atf_set require.kmods ipdivert +} +divert_to_body() +{ + pft_init + + # Set up our topology: + # + # client <--> firewall <--> gateway <--> server + # + # The firewall has no default route. route-to forces TCP port 8080 + # traffic via epair_wan to the gateway; without it the firewall has no + # route to 10.4.4.2 and drops the packet. + + epair_cl=$(vnet_mkepair) + epair_wan=$(vnet_mkepair) + epair_srv=$(vnet_mkepair) + + vnet_mkjail client ${epair_cl}a + vnet_mkjail firewall ${epair_cl}b ${epair_wan}a + vnet_mkjail gateway ${epair_wan}b ${epair_srv}a + vnet_mkjail server ${epair_srv}b + + # Client + atf_check jexec client ifconfig ${epair_cl}a 10.1.1.2/24 up + atf_check -o ignore jexec client route add default 10.1.1.1 + + # Firewall: no default route; route-to sends traffic out via epair_wan + atf_check jexec firewall ifconfig ${epair_cl}b 10.1.1.1/24 up + atf_check jexec firewall ifconfig ${epair_wan}a 10.3.3.1/30 up + atf_check -o ignore jexec firewall sysctl net.inet.ip.forwarding=1 + + # Gateway: routes between firewall and server + atf_check jexec gateway ifconfig ${epair_wan}b 10.3.3.2/30 up + atf_check jexec gateway ifconfig ${epair_srv}a 10.4.4.1/24 up + atf_check -o ignore jexec gateway sysctl net.inet.ip.forwarding=1 + atf_check -o ignore jexec gateway route add -net 10.1.1.0/24 10.3.3.1 + + # Server + atf_check jexec server ifconfig ${epair_srv}b 10.4.4.2/24 up + atf_check -o ignore jexec server route add default 10.4.4.1 + + atf_check -o ignore jexec client ping -c 1 10.1.1.1 + + jexec server nc -l 8080 > $(pwd)/out & + server_pid=$! + + # Firewall pf: divert the flow and route-to via wan + jexec firewall pfctl -e + pft_set_rules firewall \ + "pass in quick on ${epair_cl}b \ + route-to (${epair_wan}a 10.3.3.2) \ + inet proto tcp from 10.1.1.0/24 to 10.4.4.2 port 8080 \ + keep state divert-to 8000" \ + "pass in all" \ + "pass out all" + + # Divert daemon: receives the SYN and re-injects it + jexec firewall ${common_dir}/divapp 8000 divert-back & + divapp_pid=$! + sleep 1 + + # The connection must succeed: route-to must be applied to the + # re-injected packet for it to reach the server. + echo "hello there" >$(pwd)/in + atf_check jexec client nc -N -w 3 10.4.4.2 8080 < $(pwd)/in + + wait $divapp_pid + wait $server_pid + atf_check -o match:"hello there" cat $(pwd)/out +} +divert_to_cleanup() +{ + pft_cleanup +} + atf_init_test_cases() { atf_add_test_case "v4" @@ -1662,6 +1743,7 @@ atf_init_test_cases() atf_add_test_case "sticky" atf_add_test_case "ttl" atf_add_test_case "empty_pool" + atf_add_test_case "divert_to" # Tests for pf_map_addr() without prefer-ipv6-nexthop atf_add_test_case "table_loop" atf_add_test_case "roundrobin"