git: fb9969ca61ca - main - netinet6: Keep a pfil-chosen next hop in ip6_tryforward()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 18 Nov 2026 21:38:04 UTC
The branch main has been updated by rcm:
URL: https://cgit.FreeBSD.org/src/commit/?id=fb9969ca61cae271240879390c1b6dde1b4c97bf
commit fb9969ca61cae271240879390c1b6dde1b4c97bf
Author: R. Christian McDonald <rcm@FreeBSD.org>
AuthorDate: 2026-11-18 21:36:32 +0000
Commit: R. Christian McDonald <rcm@FreeBSD.org>
CommitDate: 2026-11-18 21:36:32 +0000
netinet6: Keep a pfil-chosen next hop in ip6_tryforward()
When an inbound pfil hook chooses the next hop (ipfw fwd),
ip6_tryforward() looks up the route to it. After the outbound hooks it
decides whether they changed the destination by comparing the packet's
destination with the address it looked up, which is that next hop. The
two differ, so it looks up the route to the packet's destination again
and the fwd rule is lost. ipfw always installs an outbound hook, so
every packet such a rule matches goes the wrong way while
net.inet6.ip6.redirect is 0.
Compare with the destination as it was before the outbound hooks, as
ip6_forward() does.
Reviewed by: 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/D61038
---
sys/netinet6/ip6_fastfwd.c | 4 +++-
tests/sys/netpfil/ipfw/fwd.sh | 56 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 1 deletion(-)
diff --git a/sys/netinet6/ip6_fastfwd.c b/sys/netinet6/ip6_fastfwd.c
index 4e60e18a8067..6256631c78f3 100644
--- a/sys/netinet6/ip6_fastfwd.c
+++ b/sys/netinet6/ip6_fastfwd.c
@@ -95,6 +95,7 @@ struct mbuf*
ip6_tryforward(struct mbuf *m)
{
struct sockaddr_in6 dst;
+ struct in6_addr odst;
struct nhop_object *nh;
struct m_tag *fwd_tag;
struct ip6_hdr *ip6;
@@ -218,6 +219,7 @@ passin:
/*
* Outgoing packet firewall processing.
*/
+ odst = ip6->ip6_dst;
if (pfil_mbuf_fwd(V_inet6_pfil_head, &m, nh->nh_ifp,
NULL) != PFIL_PASS)
goto dropout;
@@ -258,7 +260,7 @@ passin:
fwd_tag = NULL;
if (fwd_tag != NULL ||
- !IN6_ARE_ADDR_EQUAL(&dst.sin6_addr, &ip6->ip6_dst)) {
+ !IN6_ARE_ADDR_EQUAL(&odst, &ip6->ip6_dst)) {
if (fwd_tag != NULL) {
bcopy((fwd_tag + 1), &dst, sizeof(dst));
m->m_flags &= ~M_IP6_NEXTHOP;
diff --git a/tests/sys/netpfil/ipfw/fwd.sh b/tests/sys/netpfil/ipfw/fwd.sh
index b7aa37795706..fc97c922e17d 100755
--- a/tests/sys/netpfil/ipfw/fwd.sh
+++ b/tests/sys/netpfil/ipfw/fwd.sh
@@ -64,7 +64,63 @@ local_cleanup()
firewall_cleanup $1
}
+atf_test_case "nexthop_v6" "cleanup"
+nexthop_v6_head()
+{
+ atf_set descr 'Test that an inbound IPv6 fwd rule chooses the next hop'
+ atf_set require.user root
+}
+
+nexthop_v6_body()
+{
+ firewall_init "ipfw"
+
+ epair_c=$(vnet_mkepair)
+ epair_1=$(vnet_mkepair)
+ epair_2=$(vnet_mkepair)
+
+ vnet_mkjail rtr ${epair_c}b ${epair_1}a ${epair_2}a
+ vnet_mkjail srv1 ${epair_1}b
+ vnet_mkjail srv2 ${epair_2}b
+
+ atf_check ifconfig ${epair_c}a inet6 2001:db8:1::2/64 up no_dad \
+ -ifdisabled
+ atf_check -o ignore route add -6 2001:db8:4::/64 2001:db8:1::1
+
+ atf_check ifconfig -j rtr ${epair_c}b inet6 2001:db8:1::1/64 up no_dad
+ atf_check ifconfig -j rtr ${epair_1}a inet6 2001:db8:2::1/64 up no_dad
+ atf_check ifconfig -j rtr ${epair_2}a inet6 2001:db8:3::1/64 up no_dad
+ atf_check -o ignore sysctl -j rtr net.inet6.ip6.forwarding=1
+ atf_check -o ignore route -j rtr add -6 2001:db8:4::/64 2001:db8:2::2
+
+ # 2001:db8:4::1 lives on srv2, but the route points to srv1.
+ atf_check ifconfig -j srv1 ${epair_1}b inet6 2001:db8:2::2/64 up no_dad
+ atf_check ifconfig -j srv2 ${epair_2}b inet6 2001:db8:3::2/64 up no_dad
+ atf_check ifconfig -j srv2 lo0 inet6 2001:db8:4::1/128 up
+ atf_check -o ignore route -j srv2 add -6 default 2001:db8:3::1
+
+ firewall_config rtr ipfw ipfw \
+ "ipfw add 20 allow all from any to any"
+ atf_check -s exit:2 -o ignore ping -6 -c 1 -W 1 2001:db8:4::1
+
+ firewall_config rtr ipfw ipfw \
+ "ipfw add 10 fwd 2001:db8:3::2 ip6 from any to 2001:db8:4::1 in via ${epair_c}b" \
+ "ipfw add 20 allow all from any to any"
+
+ for redirect in 0 1; do
+ atf_check -o ignore \
+ sysctl -j rtr net.inet6.ip6.redirect=${redirect}
+ atf_check -o ignore ping -6 -c 1 -W 1 2001:db8:4::1
+ done
+}
+
+nexthop_v6_cleanup()
+{
+ firewall_cleanup $1
+}
+
atf_init_test_cases()
{
atf_add_test_case "local"
+ atf_add_test_case "nexthop_v6"
}