Page MenuHomeFreeBSD

D61039.1796479743.diff
No OneTemporary

Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None

D61039.1796479743.diff

diff --git a/sys/modules/pf/Makefile b/sys/modules/pf/Makefile
--- a/sys/modules/pf/Makefile
+++ b/sys/modules/pf/Makefile
@@ -5,7 +5,7 @@
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
--- a/sys/netinet6/ip6_fastfwd.c
+++ b/sys/netinet6/ip6_fastfwd.c
@@ -198,6 +198,16 @@
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 @@
*/
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 @@
}
}
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
--- a/sys/netpfil/pf/pf_norm.c
+++ b/sys/netpfil/pf/pf_norm.c
@@ -31,6 +31,7 @@
#include <sys/cdefs.h>
#include "opt_inet.h"
#include "opt_inet6.h"
+#include "opt_ipstealth.h"
#include "opt_pf.h"
#include <sys/param.h>
@@ -1142,6 +1143,21 @@
}
} 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
--- a/tests/sys/netpfil/pf/forward.sh
+++ b/tests/sys/netpfil/pf/forward.sh
@@ -211,9 +211,76 @@
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
--- a/tests/sys/netpfil/pf/fragmentation_pass.sh
+++ b/tests/sys/netpfil/pf/fragmentation_pass.sh
@@ -202,6 +202,20 @@
# 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()

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 5, 2:09 PM (10 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42232155
Default Alt Text
D61039.1796479743.diff (5 KB)

Event Timeline