Page MenuHomeFreeBSD

D61672.1795025535.diff
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

D61672.1795025535.diff

diff --git a/sys/netinet6/ip6_fastfwd.c b/sys/netinet6/ip6_fastfwd.c
--- a/sys/netinet6/ip6_fastfwd.c
+++ b/sys/netinet6/ip6_fastfwd.c
@@ -186,8 +186,17 @@
bcopy((fwd_tag + 1), &dst, sizeof(dst));
m->m_flags &= ~M_IP6_NEXTHOP;
m_tag_delete(m, fwd_tag);
- } else {
- /* Update dst since pfil could change it */
+ } else if (!IN6_ARE_ADDR_EQUAL(&dst.sin6_addr, &ip6->ip6_dst)) {
+ /*
+ * A hook rewrote the destination (pf rdr). If it is now one
+ * of our addresses, ip6_input() delivers the packet; the
+ * route to a local address would send it out the loopback
+ * interface instead.
+ */
+ if (in6_localip_fib(&ip6->ip6_dst, M_GETFIB(m))) {
+ m->m_flags |= M_FASTFWD_OURS;
+ return (m);
+ }
dst.sin6_addr = ip6->ip6_dst;
}
passin:
@@ -290,8 +299,14 @@
bcopy((fwd_tag + 1), &dst, sizeof(dst));
m->m_flags &= ~M_IP6_NEXTHOP;
m_tag_delete(m, fwd_tag);
- } else
+ } else {
+ /* As after the inbound hooks. */
+ if (in6_localip_fib(&ip6->ip6_dst, M_GETFIB(m))) {
+ m->m_flags |= M_FASTFWD_OURS;
+ return (m);
+ }
dst.sin6_addr = ip6->ip6_dst;
+ }
/*
* Redo route lookup with new destination address
*/
diff --git a/tests/sys/netpfil/pf/forward.sh b/tests/sys/netpfil/pf/forward.sh
--- a/tests/sys/netpfil/pf/forward.sh
+++ b/tests/sys/netpfil/pf/forward.sh
@@ -342,6 +342,46 @@
pft_cleanup
}
+atf_test_case "v6_rdr_local" "cleanup"
+v6_rdr_local_head()
+{
+ atf_set descr 'Test that a packet pf redirects to a local address is delivered'
+ atf_set require.user root
+}
+
+v6_rdr_local_body()
+{
+ pft_init
+
+ epair=$(vnet_mkepair)
+
+ ifconfig ${epair}a inet6 2001:db8:42::1/64 up no_dad -ifdisabled
+ vnet_mkjail alcatraz ${epair}b
+ jexec alcatraz ifconfig ${epair}b inet6 2001:db8:42::2/64 up no_dad
+ jexec alcatraz sysctl net.inet6.ip6.forwarding=1
+ route add -6 2001:db8:43::/64 2001:db8:42::2
+
+ # Nothing passes on lo0: the redirected packet must not be routed
+ # through it.
+ jexec alcatraz pfctl -e
+ pft_set_rules alcatraz \
+ "rdr on ${epair}b inet6 from any to 2001:db8:43::1 -> 2001:db8:42::2" \
+ "block" \
+ "pass on ${epair}b inet6"
+
+ for redirect in 0 1; do
+ jexec alcatraz sysctl net.inet6.ip6.redirect=${redirect}
+ atf_check -o ignore ping -6 -c 1 2001:db8:43::1
+ # The packet is not forwarded, so a hop limit of 1 will do.
+ atf_check -o ignore ping -6 -c 1 -m 1 2001:db8:43::1
+ done
+}
+
+v6_rdr_local_cleanup()
+{
+ pft_cleanup
+}
+
atf_init_test_cases()
{
atf_add_test_case "v4"
@@ -349,4 +389,5 @@
atf_add_test_case "v6_hlim"
atf_add_test_case "v6_hlim_decrement"
atf_add_test_case "v6_route_to_discards"
+ atf_add_test_case "v6_rdr_local"
}

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 18, 6:12 PM (23 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41825927
Default Alt Text
D61672.1795025535.diff (2 KB)

Event Timeline