From nobody Wed Nov 18 21:40:59 2026 X-Original-To: dev-commits-src-all@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 4jVFQh0pLfz71Kb3 for ; Wed, 18 Nov 2026 21:41:00 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jVFQg2Tqxz4Kn0 for ; Wed, 18 Nov 2026 21:40:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795038059; 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=2FdY/E9KWdiJ51or5re18U+ithRjRVucoPoEK7D59Tw=; b=ozlToQBng2BD8XNabnwYj5FBn/vlGEwi1V4KN7lx3uJT3PL8MF/dj4FyE28KR68flj9+Kl KMfj500uJsE+5FT59+5jRp5jn/BteUpDGSRwfpTa4q7gr+UFKdxYHRLKmgIl0gwkYq4ZOR YTF0JfqDupyV7Kmu8Dr/B1Ypg6ecMHG2i6uREswXH8B+Otd6kex9zEeh020KM5xX2Qbscd Rullg0dicxMvMVE9wHiWK5VgucHe0tONXbUgR3v04EuntSe5VgB2DyWpVi0Hy6zmQLAWSn Uay11l/qe9ADC14k6wEPl64LdAvcEEP2JFcaY2DHFLXaV9LwkZTWLeaUxC6WZg== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1795038059; b=jCzjOEJa0AcjWSsRfJoeH4H+LbU6OPiVd497a9zuHjCoyUZYW3OuChQ7cZKabOben8QkqP Ddj+02Tlgt4Ncajkl/DBDSFoNelRyk1ETv47R7/+xTKnGJRTsZB1+ugLHQRnQp9fpJ9ZzT yeX0DsmYTAoTLSOYCpotkSNVMntnC57+xlWY39DnsUcbNRnPwEoS+S9bbHBUEn/8sfVhdw kvZnzygQWjSdvl21/X6X2WXDIWy2L57kMJN7hOuwc3n2SJ5YI34tfKIo+cHoNb4lwvIcVQ mz6G6Qb9WgT2sL2YTLkiwKyg0dILkABF3BzIIS9JDpWXdZUBq9lkvjV0fDEONQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795038059; 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=2FdY/E9KWdiJ51or5re18U+ithRjRVucoPoEK7D59Tw=; b=fzIdm/3jymM5D3kFB7lUzQu8dutWHslYWAwvUDekD4mWkLR5a8KiYyMCi0TjNgLkp7KMVR qk8Z6oFst2wqLFILsUGK8U35tRr7dfKdAcVf74c1vJ7KIxPlXYwQEtBEePLV8DCj7uL1TE ZsXOJLn2Y0POi6FZU8HfOS6vrLCxLb6AJe5blTwVOnLkFTgEwwdyg/oFWcFmF8FFQzxHrH /+qW1WXUNXq248M9hhbu5QCjBLWcg/MOAxuEyqwv9R4ZEr+Nn+L7Mg8pS3EOfHlGP+qc6W PmVBzSdOxLAr/EWlamxAMUWFAqCyfNyWZVVdrL1LkEE5nNlO+1yglZLqcDUg3w== 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 4jVFQg1vD8zWDg for ; Wed, 18 Nov 2026 21:40:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 4831 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 18 Nov 2026 21:40:59 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: R. Christian McDonald Subject: git: bf8783a32faf - main - netinet6: Decrement the hop limit before the outbound hooks in ip6_tryforward() List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository 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: rcm X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: bf8783a32faf5eed6d4165c4763febf5916f25e7 Auto-Submitted: auto-generated Date: Wed, 18 Nov 2026 21:40:59 +0000 Message-Id: <6afe1b6b.4831.617b3af3@gitrepo.freebsd.org> The branch main has been updated by rcm: URL: https://cgit.FreeBSD.org/src/commit/?id=bf8783a32faf5eed6d4165c4763febf5916f25e7 commit bf8783a32faf5eed6d4165c4763febf5916f25e7 Author: R. Christian McDonald AuthorDate: 2026-11-18 21:39:38 +0000 Commit: R. Christian McDonald CommitDate: 2026-11-18 21:39:38 +0000 netinet6: Decrement the hop limit before the outbound hooks in ip6_tryforward() ip6_tryforward() decrements the hop limit after the outbound pfil hooks, whereas ip_tryforward() and ip6_forward() do it before them. The hooks therefore see a packet one hop older than the one that leaves, and a hook that transmits the packet itself does not decrement it at all: pf's route-to and reply-to on an outbound state send it on with the hop limit it arrived with. Decrement it right after the check, before the route lookup, as the other two paths do. Errors sent after that point quote the decremented value, as they do on those paths. pf_refragment6() hands the fragments of a forwarded packet it reassembled to ip6_forward(), which decrements the hop limit again, so on the slow path such a packet has always lost two hops at this router, and with this change it would on the fast path as well. Give the hop back before ip6_forward(), unless ip6stealth is on, in which case neither path decrements, or the hop limit is 255, which a scrub (min-ttl 255) rule sets and which has no room for it; such a packet leaves with 254, as it did before. fragmentation_pass:v6_refrag_hlim checks both paths, and that such a packet still gets through. Reviewed by: kp, pouria Fixes: 5a1842a2 ("Add ip6_tryforward() - a run to completion ...") MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D61039 --- sys/modules/pf/Makefile | 2 +- sys/netinet6/ip6_fastfwd.c | 20 +++++---- sys/netpfil/pf/pf_norm.c | 16 +++++++ tests/sys/netpfil/pf/forward.sh | 67 ++++++++++++++++++++++++++++++ tests/sys/netpfil/pf/fragmentation_pass.sh | 14 +++++++ 5 files changed, 110 insertions(+), 9 deletions(-) diff --git a/sys/modules/pf/Makefile b/sys/modules/pf/Makefile index ad9790704cf1..0ca117bd3d83 100644 --- a/sys/modules/pf/Makefile +++ b/sys/modules/pf/Makefile @@ -5,7 +5,7 @@ SRCS= pf.c pf_if.c pf_lb.c pf_osfp.c pf_ioctl.c pf_norm.c pf_table.c \ pf_ruleset.c pf_nl.c pf_nv.c pf_syncookies.c in4_cksum.c inet_nat64.c \ bus_if.h device_if.h \ opt_pf.h opt_inet.h opt_inet6.h opt_bpf.h opt_sctp.h opt_global.h \ - opt_kern_tls.h + opt_ipstealth.h opt_kern_tls.h .if !defined(KERNBUILDDIR) # pflog can be loaded as a module, have the additional checks turned on diff --git a/sys/netinet6/ip6_fastfwd.c b/sys/netinet6/ip6_fastfwd.c index 6256631c78f3..2328a020531e 100644 --- a/sys/netinet6/ip6_fastfwd.c +++ b/sys/netinet6/ip6_fastfwd.c @@ -198,6 +198,16 @@ passin: m = NULL; goto dropin; } + /* + * Decrement it here, before the route lookup and the outbound hooks, + * as ip_tryforward() and ip6_forward() do: the hooks then see the + * hop limit the packet leaves with, and a hook that transmits the + * packet itself (pf route-to) does not skip the decrement. + */ +#ifdef IPSTEALTH + if (!V_ip6stealth) +#endif + ip6->ip6_hlim -= IPV6_HLIMDEC; /* * Find route to destination. */ @@ -245,8 +255,8 @@ passin: */ if (m->m_flags & M_FASTFWD_OURS) { /* - * XXX: we did one hop and should decrement hop limit. But - * now we are the destination and just don't pay attention. + * The hop limit is already decremented, but now we are + * the destination and ip6_input() does not look at it. */ return (m); } @@ -276,12 +286,6 @@ passin: } } passout: -#ifdef IPSTEALTH - if (!V_ip6stealth) -#endif - { - ip6->ip6_hlim -= IPV6_HLIMDEC; - } /* * If TCP/UDP header still needs a valid checksum and interface will not diff --git a/sys/netpfil/pf/pf_norm.c b/sys/netpfil/pf/pf_norm.c index c3c2e9c47fe4..4683078acd48 100644 --- a/sys/netpfil/pf/pf_norm.c +++ b/sys/netpfil/pf/pf_norm.c @@ -31,6 +31,7 @@ #include #include "opt_inet.h" #include "opt_inet6.h" +#include "opt_ipstealth.h" #include "opt_pf.h" #include @@ -1142,6 +1143,21 @@ pf_refragment6(struct ifnet *ifp, struct mbuf **m0, struct m_tag *mtag, } } else if (forward) { MPASS(m->m_pkthdr.rcvif != NULL); + /* + * The forwarding path decremented the hop limit before + * its outbound hooks, and ip6_forward() would do it + * again, so give the hop back. A hop limit raised to + * the maximum (scrub min-ttl 255) has no room for it, + * and the packet leaves with one less. + */ +#ifdef IPSTEALTH + if (!V_ip6stealth) +#endif + { + hdr = mtod(m, struct ip6_hdr *); + if (hdr->ip6_hlim < IPV6_MAXHLIM) + hdr->ip6_hlim += IPV6_HLIMDEC; + } ip6_forward(m, 0); } else { (void)ip6_output(m, NULL, NULL, 0, NULL, NULL, diff --git a/tests/sys/netpfil/pf/forward.sh b/tests/sys/netpfil/pf/forward.sh index a01da5f62e7a..5e4a53cea5c3 100644 --- a/tests/sys/netpfil/pf/forward.sh +++ b/tests/sys/netpfil/pf/forward.sh @@ -211,9 +211,76 @@ v6_hlim_cleanup() pft_cleanup } +atf_test_case "v6_hlim_decrement" "cleanup" +v6_hlim_decrement_head() +{ + atf_set descr 'Test that forwarded packets leave with the hop limit decremented once' + atf_set require.user root + atf_set require.progs python3 scapy +} + +v6_hlim_decrement_body() +{ + pft_init + + epair_send=$(vnet_mkepair) + epair_recv=$(vnet_mkepair) + epair_route=$(vnet_mkepair) + + ifconfig ${epair_send}a inet6 2001:db8:42::1/64 up no_dad -ifdisabled + ifconfig ${epair_recv}a up + ifconfig ${epair_route}a up + + vnet_mkjail alcatraz ${epair_send}b ${epair_recv}b ${epair_route}b + + jexec alcatraz ifconfig ${epair_send}b inet6 2001:db8:42::2/64 up no_dad + jexec alcatraz ifconfig ${epair_recv}b inet6 2001:db8:43::2/64 up no_dad + jexec alcatraz ifconfig ${epair_route}b inet6 2001:db8:44::2/64 up no_dad + jexec alcatraz sysctl net.inet6.ip6.forwarding=1 + jexec alcatraz ndp -s 2001:db8:43::3 00:01:02:03:04:05 + jexec alcatraz ndp -s 2001:db8:44::3 00:01:02:03:04:06 + jexec alcatraz route add -6 2001:db8:666::/64 2001:db8:43::3 + route add -6 2001:db8:43::/64 2001:db8:42::2 + route add -6 2001:db8:666::/64 2001:db8:42::2 + + jexec alcatraz pfctl -e + + # Forwarded by the stack, with and without the fast path. + pft_set_rules alcatraz "pass" + for redirect in 0 1; do + jexec alcatraz sysctl net.inet6.ip6.redirect=${redirect} + atf_check -s exit:0 ${common_dir}/pft_ping.py \ + --sendif ${epair_send}a \ + --to 2001:db8:43::3 \ + --recvif ${epair_recv}a \ + --send-hlim 5 \ + --expect-hlim 4 + done + + # Transmitted by pf's outbound pass (route-to), same expectation. + pft_set_rules alcatraz \ + "pass in" \ + "pass out route-to (${epair_route}b 2001:db8:44::3) inet6 to 2001:db8:666::1" + for redirect in 0 1; do + jexec alcatraz sysctl net.inet6.ip6.redirect=${redirect} + atf_check -s exit:0 ${common_dir}/pft_ping.py \ + --sendif ${epair_send}a \ + --to 2001:db8:666::1 \ + --recvif ${epair_route}a \ + --send-hlim 5 \ + --expect-hlim 4 + done +} + +v6_hlim_decrement_cleanup() +{ + pft_cleanup +} + atf_init_test_cases() { atf_add_test_case "v4" atf_add_test_case "v6" atf_add_test_case "v6_hlim" + atf_add_test_case "v6_hlim_decrement" } diff --git a/tests/sys/netpfil/pf/fragmentation_pass.sh b/tests/sys/netpfil/pf/fragmentation_pass.sh index d5310d6eeb58..f523ec2dd1d9 100644 --- a/tests/sys/netpfil/pf/fragmentation_pass.sh +++ b/tests/sys/netpfil/pf/fragmentation_pass.sh @@ -202,6 +202,20 @@ v6_refrag_hlim_body() # The fast path: pf must refragment through ip6_forward(). refrag_hlim 0 + # The slow path: ip6_forward() has already decremented the hop limit, + # and pf must not have it decremented again. + refrag_hlim 1 + + # A rule that raises the hop limit to the maximum leaves no room to + # give the hop back, but the packet must still get through. + pft_set_rules alcatraz \ + "set reassemble yes" \ + "pass in" \ + "pass out scrub (min-ttl 255)" + for redirect in 0 1; do + jexec alcatraz sysctl net.inet6.ip6.redirect=${redirect} + atf_check -o ignore ping -6 -c 1 -s 4500 2001:db8:43::3 + done } v6_refrag_hlim_cleanup()