From nobody Tue Feb 27 15:26:00 2024 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 4TkhCF1Km9z5Btg5; Tue, 27 Feb 2024 15:26:01 +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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TkhCF0bmrz4XMY; Tue, 27 Feb 2024 15:26:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1709047561; 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=YLTn1AzBBSI6CGpciPeOOim21garxuo03PxdOYSG+ew=; b=Mq4yaF3wk/IwFRnof29D0LzI2UiBHAVoBiwnkGEp0ZaLiaGyjmrpLd4qksi4v2SgnWGoON oZT5M9xOQJYgxYWII8Iar6JnPneNuZD4NBW3m9U9gJxm7+LLHIyJAAqIwh9OHAcl/2b0Jc 0FO6ehvsidX+bZ8MS+gBr5kmNKQ5VQaVXCWTw0MuYX+tsMv01ymKiQD6hzoYLyAbch+MLd F/2ud+CKmj3Hu7UJWEKLmafyeE69efLBq1AZW7VOE873Nee7aDm9bQSwb4Pz9mXk6TtBu9 009OvEOf4BcprHYoyZcN88Sp2BsS4jGNsRT0vqVkqW0q/mlIzslI5fsB9omdPw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1709047561; a=rsa-sha256; cv=none; b=uFyBCiuIN/F7n48XOKW/igoH4sv/0H2HIEz0YEeUrUg+MEBDoiaT9jInR33kG4ZQGUnrhe sOwynOSV/yMPw8eZn6dYESyyi/SyWmaizxFoGiX/JjJsKjHp4z6BL/0inTHKTkjP5+WoXn 0L/30KZKtiLW8tW1yA2PZiua7YZiJXhed8KrAvJcFbIz4BvNkFYpdhRS6FqQ1oKxYanC+m XKGYJCWHMLeVA5TYCDJ49CrRATSnwBP/DCUrp1J9h5lpkAVl8hfBGwJJ+J+/Am+g9QNCxq 4QxvSd/BfQwzqNLX2d3d+LuhlmLP/q/qAQSI/CX3pWwPj6uCCQjO3pWzTw1PuQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1709047561; 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=YLTn1AzBBSI6CGpciPeOOim21garxuo03PxdOYSG+ew=; b=xlIm0Ki5Zoj+MD+zccSExosMHeKRwM+9F6rqUSOmdbIrKQllCQToZmF/aVSfpZWcx0W8TF jTaB5hukzWGGjDopo+utZZaCuWRFjjnwxlWEQE5L69mRebx9OInC+TKZdJ6yRoMDIjsjyD jVze4K9aZYIrTXpYwlAJpQx6+jzP1VgfvhlrdM8mPaStmO40tw8lO/CMmRn3njfEMbwN1+ ddONDYPqeklFLHNDwyR6Ys5htdDIHpmpiPwshnkfjABZC8HFZzaw4Pt+jkaxNpdL5UNmvp 52+9V+Fpd2NRHVhezrUTjw4nMQErYsfNQSlxew0vLXyL4W4gmf9pf5cgOzKYlA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TkhCD6lNnzHkh; Tue, 27 Feb 2024 15:26:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41RFQ0Qx052743; Tue, 27 Feb 2024 15:26:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41RFQ05Q052740; Tue, 27 Feb 2024 15:26:00 GMT (envelope-from git) Date: Tue, 27 Feb 2024 15:26:00 GMT Message-Id: <202402271526.41RFQ05Q052740@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 9566d9272600 - main - pf: fix packet-to-big for route-to as well List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9566d9272600a472be3a608ea79197c57cad1dc3 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=9566d9272600a472be3a608ea79197c57cad1dc3 commit 9566d9272600a472be3a608ea79197c57cad1dc3 Author: Kristof Provost AuthorDate: 2024-02-27 13:24:25 +0000 Commit: Kristof Provost CommitDate: 2024-02-27 13:38:38 +0000 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: 54c62e3e5d8cd90c5571a1d4c8c5f062d580480e See also: f1c0030bb05cfa01bdd500e50befbb425fecc4c4 See also: https://redmine.pfsense.org/issues/14290 Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/netpfil/pf/pf.c | 4 ++-- tests/sys/netpfil/pf/nat66.py | 47 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 8bfda12b2b2e..46f01f986d05 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -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; diff --git a/tests/sys/netpfil/pf/nat66.py b/tests/sys/netpfil/pf/nat66.py index 006ab5afee7f..12d3cb25af0a 100644 --- a/tests/sys/netpfil/pf/nat66.py +++ b/tests/sys/netpfil/pf/nat66.py @@ -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 @@ class TestNAT66(VnetTestTemplate): # 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 @@ class TestNAT66(VnetTestTemplate): 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 @@ class TestNAT66(VnetTestTemplate): # 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 @@ class TestNAT66(VnetTestTemplate): # 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")