From nobody Wed Nov 18 21:43: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 4jVFV80JLHz71KXJ for ; Wed, 18 Nov 2026 21:44: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 4jVFV768y1z4Ld3 for ; Wed, 18 Nov 2026 21:43:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795038239; 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=rF/HZXhMkIo4euI4ANNmvP78by3dP0KkSjgxbM0W+p4=; b=AvjZrXU034Rn1zAH/xXAzVACRp+IcjStwIdR3mH0SIE4e9gK8mCEhzRhWFqUu4/RqGEEdM kfTOtL9tFV2oQ4ywLg7fHB7ZK/HF8KsHRdTM+H3/MtpnPNl/6O7V+8MZWtSBv8OQhj2Iyw BuaL7Ciy1BNPE3IZZA/5TdvMmLYs1e0Q0TTr7o33T3X3tDXlo0Yh/oQMPtt54w8U4FrY6S mGMgEU3aRJgoHKRXh/klsRWAqztL6YEmALYEhZ1ZNZinreH3ZZ4uDgBnyfm4iaCuvQ9/6R RW7To2tF3ixY63rDJB8BiAZ+B4d89+BlH3c/bHaTKRpgXg/FgzqdMsyQBvoH+Q== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1795038239; b=od67qZvq0BRmOfwegT8sHWclvRnmR692dQ63wetwYFdJXXtQknPyWytoSIx2poqL5s+gFC gQYkHMPvIdNFzqR5GvT3njiwFDU54WWsdjyUJz2JOd1/G5lIY1nd8TlFW6A7/5C2Rw2AMK AIz0nMzn46wB491Yz/gtmDLTh2YAH53JLXp715mR1YVk5cnzfY7gfsw2rBU41TJ8DLCtbm sdkDpDREJS3j87tlPYTL5qZtrCGe1qGFoB0kr51s5/aLSsz9fscpzKoMNfY4lQJYcPekeL /lk+B+2f6rPV8b+pb94+ygBJyZFWNJzlifrkbXxhCbO2GrqvBPC5XNkbgTkSaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795038239; 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=rF/HZXhMkIo4euI4ANNmvP78by3dP0KkSjgxbM0W+p4=; b=Ff5mnq6Kb8TLHqN0UtmVzRwo3spS2exzltUXVKLNGpPxSfFz/KZc2oem1tPKZQ9NkcGAOe 01hxy/tMiZr5wgjapVUGQ1/Vjo1xgUZF+GmEjerXNDpC0mHxz8Rm3IFmFF4QCjxoywXzP4 PuO0lTwa2z48YUxfZVriPpaCqizVoTZj/+4k9jth3XY9okJSBPELydOxIft/oaCZqb14BF SlPmkix1z9W9VxKTOSnQkbtfqIeHDXpcW97FIaSniPasOXGj3l/TG1HYSlfUGa0ai7zDo7 kDjiGzV5G7C5Yv/hAYpTqpvfyKMHsSjWmDMUTcw5ots1IhdstW2ShRc7jOoUrw== 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 4jVFV75q3FzXJT for ; Wed, 18 Nov 2026 21:43:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 4915 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 18 Nov 2026 21:43: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: 20e652ba25b2 - main - netinet6: Do not count a packet a hook consumed as discarded 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: 20e652ba25b2ecdd2382aa10b0b5b2c183bef13f Auto-Submitted: auto-generated Date: Wed, 18 Nov 2026 21:43:59 +0000 Message-Id: <6afe1c1f.4915.54a920c4@gitrepo.freebsd.org> The branch main has been updated by rcm: URL: https://cgit.FreeBSD.org/src/commit/?id=20e652ba25b2ecdd2382aa10b0b5b2c183bef13f commit 20e652ba25b2ecdd2382aa10b0b5b2c183bef13f Author: R. Christian McDonald AuthorDate: 2026-11-18 21:42:50 +0000 Commit: R. Christian McDonald CommitDate: 2026-11-18 21:42:50 +0000 netinet6: Do not count a packet a hook consumed as discarded in ip6_tryforward() ip6_tryforward() treats every pfil result but PFIL_PASS as a drop: it counts a discard on the receiving interface after the inbound hooks and on the outgoing interface after the outbound hooks. A hook that consumes the packet returns PFIL_CONSUMED instead: pf sends a packet a route-to rule matches out itself, and sends a packet it reassembled on in fragments. Those packets were forwarded, yet netstat -s -I shows them as discarded, in the outbound case on the interface the route lookup chose, which route-to did not even use. ip6_forward() and ip_tryforward() count nothing for a consumed packet. Return without counting when a hook consumed the packet. The new forward:v6_route_to_discards test checks both passes. Its rules keep no state: pf reports a packet it sent from the inbound hook as dropped when its own outbound pass created a state, and that packet is still counted. Reviewed by: kp, glebius, 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/D61042 --- sys/netinet6/ip6_fastfwd.c | 23 +++++++++++--- tests/sys/netpfil/pf/forward.sh | 66 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 4 deletions(-) diff --git a/sys/netinet6/ip6_fastfwd.c b/sys/netinet6/ip6_fastfwd.c index 2328a020531e..3c970be1d1b0 100644 --- a/sys/netinet6/ip6_fastfwd.c +++ b/sys/netinet6/ip6_fastfwd.c @@ -156,9 +156,15 @@ ip6_tryforward(struct mbuf *m) */ if (!PFIL_HOOKED_IN(V_inet6_pfil_head)) goto passin; - if (pfil_mbuf_in(V_inet6_pfil_head, &m, rcvif, NULL) != - PFIL_PASS) + switch (pfil_mbuf_in(V_inet6_pfil_head, &m, rcvif, NULL)) { + case PFIL_PASS: + break; + case PFIL_CONSUMED: + /* A hook sent the packet on itself (pf route-to). */ + return (NULL); + default: goto dropin; + } /* * If packet filter sets the M_FASTFWD_OURS flag, this means * that new destination or next hop is our local address. @@ -230,9 +236,18 @@ passin: * Outgoing packet firewall processing. */ odst = ip6->ip6_dst; - if (pfil_mbuf_fwd(V_inet6_pfil_head, &m, nh->nh_ifp, - NULL) != PFIL_PASS) + switch (pfil_mbuf_fwd(V_inet6_pfil_head, &m, nh->nh_ifp, NULL)) { + case PFIL_PASS: + break; + case PFIL_CONSUMED: + /* + * A hook sent the packet on itself (pf route-to) or in + * fragments (pf refragmentation). + */ + return (NULL); + default: goto dropout; + } /* * We used slow path processing for packets with scoped addresses. diff --git a/tests/sys/netpfil/pf/forward.sh b/tests/sys/netpfil/pf/forward.sh index 5e4a53cea5c3..4524a32dc392 100644 --- a/tests/sys/netpfil/pf/forward.sh +++ b/tests/sys/netpfil/pf/forward.sh @@ -277,10 +277,76 @@ v6_hlim_decrement_cleanup() pft_cleanup } +atf_test_case "v6_route_to_discards" "cleanup" +v6_route_to_discards_head() +{ + atf_set descr 'Test that packets pf sends on with route-to are not counted as discarded' + atf_set require.user root +} + +v6_route_to_discards_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 + # ip6_tryforward() only forwards while redirects are off. + jexec alcatraz sysctl net.inet6.ip6.redirect=0 + 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:666::/64 2001:db8:42::2 + + jexec alcatraz pfctl -e + + # pf sends the packet on itself and tells ip6_tryforward() that it + # consumed it: in the inbound hook for route-to on the inbound pass, in + # the outbound hook, after the route lookup chose ${epair_recv}b, for + # route-to on the outbound pass. Neither is a discard. + # + # The rules do not keep state: when the outbound pass that pf runs from + # the inbound hook creates a state, pf reports the packet it sent as + # dropped. + # + # The host's MLD reports are for a group alcatraz has not joined, and + # ip6_input() would count them as discarded. Block them. + for dir in in out; do + pft_set_rules alcatraz \ + "block in quick inet6 to ff02::16" \ + "pass no state" \ + "pass ${dir} quick route-to (${epair_route}b 2001:db8:44::3) inet6 to 2001:db8:666::1 no state" + in_discards=$(jexec alcatraz netstat -s -p ip6 -I ${epair_send}b | + awk '/input datagrams? discarded/ { print $1 }') + atf_check -s exit:2 -o ignore ping -6 -c 1 -W 1 2001:db8:666::1 + atf_check -o match:"[[:space:]]${in_discards} input datagrams? discarded" \ + jexec alcatraz netstat -s -p ip6 -I ${epair_send}b + atf_check -o match:"[[:space:]]0 total discarded output datagrams" \ + jexec alcatraz netstat -s -p ip6 -I ${epair_recv}b + done +} + +v6_route_to_discards_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" + atf_add_test_case "v6_route_to_discards" }