mirror of
https://github.com/freebsd/freebsd-src
synced 2024-07-21 18:27:22 +00:00
pf: fix packet-to-big for route-to as well
When we handle a packet via route-to (i.e. pf_route6()) we still need to verify the MTU. However, we only run that check in the forwarding case. Set the PFIL_FWD tag when running the pf_test6(PF_OUT) check from pf_route6(). We are in fact forwarding, so should call the test function as such. This will cause us to run the MTU check, and generate an ICMP6 packet-too-big error when required. See also:54c62e3e5d
See also:f1c0030bb0
See also: https://redmine.pfsense.org/issues/14290 Sponsored by: Rubicon Communications, LLC ("Netgate")
This commit is contained in:
parent
cce3a70a77
commit
9566d92726
|
@ -7333,7 +7333,7 @@ pf_route(struct mbuf **m, struct pf_krule *r, struct ifnet *oifp,
|
|||
goto bad;
|
||||
|
||||
if (pd->dir == PF_IN) {
|
||||
if (pf_test(PF_OUT, 0, ifp, &m0, inp, &pd->act) != PF_PASS)
|
||||
if (pf_test(PF_OUT, PFIL_FWD, ifp, &m0, inp, &pd->act) != PF_PASS)
|
||||
goto bad;
|
||||
else if (m0 == NULL)
|
||||
goto done;
|
||||
|
@ -7555,7 +7555,7 @@ pf_route6(struct mbuf **m, struct pf_krule *r, struct ifnet *oifp,
|
|||
goto bad;
|
||||
|
||||
if (pd->dir == PF_IN) {
|
||||
if (pf_test6(PF_OUT, 0, ifp, &m0, inp, &pd->act) != PF_PASS)
|
||||
if (pf_test6(PF_OUT, PFIL_FWD, ifp, &m0, inp, &pd->act) != PF_PASS)
|
||||
goto bad;
|
||||
else if (m0 == NULL)
|
||||
goto done;
|
||||
|
|
|
@ -59,21 +59,23 @@ class TestNAT66(VnetTestTemplate):
|
|||
def vnet2_handler(self, vnet):
|
||||
ifname = vnet.iface_alias_map["if1"].name
|
||||
ToolsHelper.print_output("/sbin/ifconfig %s mtu 9000" % ifname)
|
||||
outifname = vnet.iface_alias_map["if2"].name
|
||||
|
||||
ToolsHelper.print_output("/sbin/pfctl -e")
|
||||
ToolsHelper.pf_rules([
|
||||
"set reassemble yes",
|
||||
"binat inet6 from 2001:db8::/64 to 2001:db8:1::/64 -> 2001:db8:42::/64",
|
||||
"binat inet6 from 2001:db8:1::/64 to 2001:db8:42::/64 -> 2001:db8::/64",
|
||||
"pass inet6 proto icmp6"])
|
||||
"pass inet6 proto icmp6",
|
||||
"pass in route-to ( %s 2001:db8:1::2 ) inet6 from 2001:db8::3 to 2001:db8:1::/64" % outifname])
|
||||
|
||||
ToolsHelper.print_output("/sbin/sysctl net.inet6.ip6.forwarding=1")
|
||||
|
||||
def vnet3_handler(self, vnet):
|
||||
ToolsHelper.print_output("/sbin/route add -6 2001:db8:42::/64 2001:db8:1::1")
|
||||
|
||||
def check_icmp_too_big(self, sp, payload_size, frag_size=None):
|
||||
packet = sp.IPv6(src="2001:db8::2", dst="2001:db8:1::2") \
|
||||
def check_icmp_too_big(self, sp, payload_size, frag_size=None, src="2001:db8::2"):
|
||||
packet = sp.IPv6(src=src, dst="2001:db8:1::2") \
|
||||
/ sp.ICMPv6EchoRequest(data=sp.raw(bytes.fromhex('f0') * payload_size))
|
||||
|
||||
if frag_size is not None:
|
||||
|
@ -97,14 +99,14 @@ def check_icmp_too_big(self, sp, payload_size, frag_size=None):
|
|||
|
||||
# Error is from the router vnet
|
||||
assert ip6.src == "2001:db8::1"
|
||||
assert ip6.dst == "2001:db8::2"
|
||||
assert ip6.dst == src
|
||||
|
||||
# And the relevant MTU is 1500
|
||||
assert icmp6.mtu == 1500
|
||||
|
||||
# The icmp6 error contains our original IPv6 packet
|
||||
err = icmp6.getlayer(sp.IPerror6)
|
||||
assert err.src == "2001:db8::2"
|
||||
assert err.src == src
|
||||
assert err.dst == "2001:db8:1::2"
|
||||
assert err.nh == 58
|
||||
|
||||
|
@ -112,8 +114,8 @@ def check_icmp_too_big(self, sp, payload_size, frag_size=None):
|
|||
|
||||
assert found
|
||||
|
||||
def check_icmp_echo(self, sp, payload_size):
|
||||
packet = sp.IPv6(src="2001:db8::2", dst="2001:db8:1::2") \
|
||||
def check_icmp_echo(self, sp, payload_size, src="2001:db8::2"):
|
||||
packet = sp.IPv6(src=src, dst="2001:db8:1::2") \
|
||||
/ sp.ICMPv6EchoRequest(data=sp.raw(bytes.fromhex('f0') * payload_size))
|
||||
|
||||
# Delay the send so the sniffer is running when we transmit.
|
||||
|
@ -131,7 +133,7 @@ def check_icmp_echo(self, sp, payload_size):
|
|||
|
||||
# Error is from the router vnet
|
||||
assert ip6.src == "2001:db8:1::2"
|
||||
assert ip6.dst == "2001:db8::2"
|
||||
assert ip6.dst == src
|
||||
|
||||
found = True
|
||||
|
||||
|
@ -164,3 +166,32 @@ def test_npt_icmp(self):
|
|||
|
||||
# A ping that arrives fragmented
|
||||
self.check_icmp_too_big(sp, 12000, 5000)
|
||||
|
||||
@pytest.mark.require_user("root")
|
||||
def test_npt_route_to_icmp(self):
|
||||
cl_vnet = self.vnet_map["vnet1"]
|
||||
ifname = cl_vnet.iface_alias_map["if1"].name
|
||||
ToolsHelper.print_output("/sbin/ifconfig %s mtu 9000" % ifname)
|
||||
ToolsHelper.print_output("/sbin/ifconfig %s inet6 alias 2001:db8::3/64" % ifname)
|
||||
|
||||
ToolsHelper.print_output("/sbin/route add -6 2001:db8:1::/64 2001:db8::1")
|
||||
|
||||
# For unclear reasons vnet3 doesn't respond to the first ping.
|
||||
# Just send two for now.
|
||||
ToolsHelper.print_output("/sbin/ping -6 -c 1 -S 2001:db8::3 2001:db8:1::2")
|
||||
ToolsHelper.print_output("/sbin/ping -6 -c 1 -S 2001:db8::3 2001:db8:1::2")
|
||||
|
||||
# Import in the correct vnet, so at to not confuse Scapy
|
||||
import scapy.all as sp
|
||||
|
||||
# A ping that easily passes without fragmentation
|
||||
self.check_icmp_echo(sp, 128, src="2001:db8::3")
|
||||
|
||||
# Send a ping that just barely doesn't need to be fragmented
|
||||
self.check_icmp_echo(sp, 1452, src="2001:db8::3")
|
||||
|
||||
# Send a ping that just barely needs to be fragmented
|
||||
self.check_icmp_too_big(sp, 1453, src="2001:db8::3")
|
||||
|
||||
# A ping that arrives fragmented
|
||||
self.check_icmp_too_big(sp, 12000, 5000, src="2001:db8::3")
|
||||
|
|
Loading…
Reference in a new issue