From nobody Tue Jan 20 21:54:47 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 4dwh201Gb8z6PCSf for ; Tue, 20 Jan 2026 21:54:48 +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 "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dwh1z5tlTz47rj for ; Tue, 20 Jan 2026 21:54:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768946087; 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=pnw0MbySWdCe3TVWR69+V2aMybB76qDbUG2lEMlJfso=; b=PnvyglKNkNw00lzDfe2+SMu8lSxB8Xrur3S/B2FWIPcc/DIVGkhoksVwVdZ9Lnj4mGekK8 XDb3qDlW3/LdAc2FmbT/Hw9XldQ/TB0NRvqjG/PGnjkm4Y0Q8H6Vc898/glyH2c4YKuywc 7rG3x2imyNq4Uo2kzHvzK/oKRJN+yDifCNEzf/y+tQefHlYA2WuCBPm2ztbJ7HCGYTvGyy 2XW4893hQkKWAPtmB8dJJSBu2ggWj9t/XC87KonWgWiInnOd2HCceftXBMFyv4d76ztPRg wmPb7w3QlLc1hhlfaWnVwsBMCKaGU0QVdkShumxsHnkIX8cnZGPbFw02vz8mzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768946087; 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=pnw0MbySWdCe3TVWR69+V2aMybB76qDbUG2lEMlJfso=; b=R9css1iRZdANH6HdEhiUeO+yaUsEUvZx53WmIAURWU0bnshbEirJCs63LpSRCaVI2a5Mak XCp3+QXOz+JL1W7UJcPQyMA13W12JqWD0v3nh1h1lVUL8q73SgKZAWhB3jF/k4kZNItIpV cfSgMR1XzW7DKHFa6C79AsSwI2whok23RtDpKC3RzOFib3ZIxW6jdTTQZflSS/6x0pfhG6 Zt3qpEZxysQqHZ0vqO8mdhQ4D5LIeXJ9smaI2vX/YdkwJthp8JEM+6pR+xo/P85NzEQ23z yCso081yKWHSdb+dLXWhStZ0lqdG/wsJU2yo6y93eHHGiJ36srDOiAbCq4SuOA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1768946087; a=rsa-sha256; cv=none; b=SEaTCN3EXGejbzcd6o5cNRxTe7sh8XPeHF3uT7LusUoVVA4EdMNO+3OHwYu4f+3wCQaslt yIInpkQtayXIMzqA2GnvZaSl7BsriX6SjL2ojhXGWPda3itg/xWgQXzMqX8voV7/KEs7OK XQx6ACX/vzA/wBtBGIcHPCSglzUpDviyQV6I0UimW/ZdwA28WcrG9dPZSse+JssoAHpP2X mLrM0veKbERtP+fQ3aPO7Jv8CiE5qKW2+OTAckyLAB2tQmdJ9jgLrYI9+rHAJL9T9uFc7O 1jCFodkZm8hIB1DfZv8+PFWSSJV0LqxWuTWM3QVNuTOGrKwNMUIkP7JkVJGrKw== 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 4dwh1z555Rz4Wt for ; Tue, 20 Jan 2026 21:54:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3230c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 20 Jan 2026 21:54:47 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: 2c42d62fd3a1 - stable/15 - pf: fix min-ttl and set-tos for nat64 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 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 2c42d62fd3a19d02e86271f7e2ac55413775a7af Auto-Submitted: auto-generated Date: Tue, 20 Jan 2026 21:54:47 +0000 Message-Id: <696ff9a7.3230c.75aecbe2@gitrepo.freebsd.org> The branch stable/15 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=2c42d62fd3a19d02e86271f7e2ac55413775a7af commit 2c42d62fd3a19d02e86271f7e2ac55413775a7af Author: Kristof Provost AuthorDate: 2025-12-15 14:26:57 +0000 Commit: Kristof Provost CommitDate: 2026-01-20 19:08:31 +0000 pf: fix min-ttl and set-tos for nat64 If we have both af-to and min-ttl or set-tos on a single rule we didn't apply the new ttl or tos. That's because the scrub code still applied the change, but we subsequently create a new header for the new address family. That's done based on the ttl/tos saved in the struct pf_pdesc, which are the values from the incoming packet, before the scrub modification(s). Also update the struct pf_pdesc values when we update packets. Reported by: Marek Zarychta Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit cdbc9b76ff4901816b5ebdca5d0b7e9947a015cb) --- sys/netpfil/pf/pf_norm.c | 6 ++-- tests/sys/netpfil/pf/nat64.sh | 69 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/sys/netpfil/pf/pf_norm.c b/sys/netpfil/pf/pf_norm.c index a684d778ab42..93d40641eb80 100644 --- a/sys/netpfil/pf/pf_norm.c +++ b/sys/netpfil/pf/pf_norm.c @@ -2232,14 +2232,14 @@ pf_scrub(struct pf_pdesc *pd) h->ip_ttl < pd->act.min_ttl) { u_int16_t ip_ttl = h->ip_ttl; - h->ip_ttl = pd->act.min_ttl; + pd->ttl = h->ip_ttl = pd->act.min_ttl; h->ip_sum = pf_cksum_fixup(h->ip_sum, ip_ttl, h->ip_ttl, 0); } #ifdef INET6 /* Enforce a minimum ttl, may cause endless packet loops */ if (pd->af == AF_INET6 && pd->act.min_ttl && h6->ip6_hlim < pd->act.min_ttl) - h6->ip6_hlim = pd->act.min_ttl; + pd->ttl = h6->ip6_hlim = pd->act.min_ttl; #endif /* INET6 */ /* Enforce tos */ if (pd->act.flags & PFSTATE_SETTOS) { @@ -2249,6 +2249,7 @@ pf_scrub(struct pf_pdesc *pd) ov = *(u_int16_t *)h; h->ip_tos = pd->act.set_tos | (h->ip_tos & IPTOS_ECN_MASK); + pd->tos = h->ip_tos & ~IPTOS_ECN_MASK; nv = *(u_int16_t *)h; h->ip_sum = pf_cksum_fixup(h->ip_sum, ov, nv, 0); @@ -2258,6 +2259,7 @@ pf_scrub(struct pf_pdesc *pd) case AF_INET6: h6->ip6_flow &= IPV6_FLOWLABEL_MASK | IPV6_VERSION_MASK; h6->ip6_flow |= htonl((pd->act.set_tos | IPV6_ECN(h6)) << 20); + pd->tos = IPV6_DSCP(h6); break; #endif /* INET6 */ } diff --git a/tests/sys/netpfil/pf/nat64.sh b/tests/sys/netpfil/pf/nat64.sh index 6631e3eca2c7..e2a87a6eee40 100644 --- a/tests/sys/netpfil/pf/nat64.sh +++ b/tests/sys/netpfil/pf/nat64.sh @@ -1179,6 +1179,74 @@ v6_gateway_cleanup() pft_cleanup } +atf_test_case "scrub_min_ttl" "cleanup" +scrub_min_ttl_head() +{ + atf_set descr 'Ensure scrub min-ttl applies to nat64 traffic' + atf_set require.user root +} + +scrub_min_ttl_body() +{ + pft_init + + epair=$(vnet_mkepair) + epair_link=$(vnet_mkepair) + epair_link_two=$(vnet_mkepair) + + ifconfig ${epair}a inet6 2001:db8::2/64 up no_dad + route -6 add default 2001:db8::1 + + vnet_mkjail rtr ${epair}b ${epair_link}a + jexec rtr ifconfig ${epair}b inet6 2001:db8::1/64 up no_dad + jexec rtr ifconfig ${epair_link}a 192.0.2.1/24 up + jexec rtr route add default 192.0.2.2 + + vnet_mkjail rtr2 ${epair_link}b ${epair_link_two}a + jexec rtr2 ifconfig ${epair_link}b 192.0.2.2/24 up + jexec rtr2 ifconfig ${epair_link_two}a 198.51.100.2/24 up + jexec rtr2 sysctl net.inet.ip.forwarding=1 + + vnet_mkjail dst ${epair_link_two}b + jexec dst ifconfig ${epair_link_two}b 198.51.100.1/24 up + jexec dst route add default 198.51.100.2 + + # Sanity checks + atf_check -s exit:0 -o ignore \ + ping6 -c 1 2001:db8::1 + atf_check -s exit:0 -o ignore \ + jexec rtr ping -c 1 192.0.2.2 + atf_check -s exit:0 -o ignore \ + jexec rtr ping -c 1 198.51.100.2 + atf_check -s exit:0 -o ignore \ + jexec rtr ping -c 1 198.51.100.1 + + jexec rtr pfctl -e + pft_set_rules rtr \ + "pass" \ + "pass in on ${epair}b inet6 from any to 64:ff9b::/96 af-to inet from (${epair_link}a)" + + # Ping works with a normal TTL + atf_check -s exit:0 -o ignore \ + ping6 -c 1 64:ff9b::198.51.100.1 + + # If we set a TTL of two the packet gets dropped + atf_check -s exit:2 -o ignore \ + ping6 -c 1 -m 2 64:ff9b::198.51.100.1 + + # But if we have pf enforce a minimum ttl of 10 the ping does pass + pft_set_rules rtr \ + "pass" \ + "pass in on ${epair}b inet6 from any to 64:ff9b::/96 af-to inet from (${epair_link}a) scrub (min-ttl 10)" + atf_check -s exit:0 -o ignore \ + ping6 -c 1 -m 2 64:ff9b::198.51.100.1 +} + +scub_min_ttl_cleanup() +{ + pft_cleanup +} + atf_init_test_cases() { atf_add_test_case "icmp_echo_in" @@ -1206,4 +1274,5 @@ atf_init_test_cases() atf_add_test_case "route_to" atf_add_test_case "reply_to" atf_add_test_case "v6_gateway" + atf_add_test_case "scrub_min_ttl" }