From nobody Fri Feb 23 13:47:52 2024 X-Original-To: dev-commits-src-main@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 4ThBCr4j2Qz5CTtD; Fri, 23 Feb 2024 13:47:52 +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 4ThBCr44jZz42Lp; Fri, 23 Feb 2024 13:47:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708696072; 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=ElCn8S9Tz4aaTzHs0qL78yJwvPj147wSGk7mqs+KvqE=; b=yE5eIafB9AJtY5ucAO/IJv7y1t44MWshFP4oUVtuODLY2BNBVy7Kt8UI71goSPwT0mAtDz xHEkUfjGYTLeOI2pNEuU1CZ/LalD4tceZ4U2OqhCr4nh6pTLg+DTGQFnUPgfSZ+uGRLPXT N7pi6C/X5JCqyvv1ONWK0T4n/MIfexdrqn1PZLMwlCcdPyN3g1O7FPrf8iYvIHnERBQ1UM FhBt8T+EoVDsKCBGW34/6H6Gcp1j4eFpgExEvs9nqmsNH99ee8cyKdznTI+I9mcchLSqUs gbobQETo8ckE04tPsOpGBCHAg9hvMKCSCiuoursZVFa85Ihf91tc6YZrcO09EQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708696072; a=rsa-sha256; cv=none; b=XvdpWmg23VoPcWd2MhPwcwW06Ox0TY0cw6A1tOcYFuOLMG/boFtZONLZmLKE3GbGTW02rL Helv0xU8JUVsren5g4SP5FpM2U7UrpTu2awD+W6AlYbqv7LQmZBLHKpPqOF3QAZ8UM9R7B Tu8p7pBf+dIjskBFj+u+UOZI2N9QahVDvW1ig4tywPzGAysrLiUg6sBcVm2sZ4IbrhzGJU bzhxtdZu4G1yDm1d+PyOj4s2HDuXfcrlgYAtvpShWY/fDCo/fFIArj2RcV783RMzftnJ9h bf3tFeZPDUQIXVWlbxK+PXvvF/zSMoDsqZf8y78CwLQk79U+y4TSlWX0pWYOTg== 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=1708696072; 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=ElCn8S9Tz4aaTzHs0qL78yJwvPj147wSGk7mqs+KvqE=; b=ewx1NhV470spMIn1/ieQa23VG1LEMnzWSUZaPAAN5ykgc4KvP64ZeH8WZYmw6e1sFc3wCP d6GtpdbQV5Q5HkAGSZ7VQ2m0yoDdJLv7hnvlNLih4RFtU1tM/riA9TxyftxoLsyGjA7+nX 8krjj3Y9RZ2Jd2qB36FBuLIGy3l04S+GDR55Oq3KTlXw/VSRNaGIJHn8yd7e3ijMQDfKIA gtz8906phCysjy0M+1fIVKJ6TnU8IcwnA8pKUdQD6SMr2TllfpdmWx7ELmVHr1jMzRPSa8 tlJEGdD4Gf5uuPSC9Mkxp09OK61bG4mqu3NOPloNsbFTBVn0bEkgEtgyENp5tQ== 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 4ThBCr2qxTzJ9P; Fri, 23 Feb 2024 13:47:52 +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 41NDlqnP088034; Fri, 23 Feb 2024 13:47:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41NDlqCv088031; Fri, 23 Feb 2024 13:47:52 GMT (envelope-from git) Date: Fri, 23 Feb 2024 13:47:52 GMT Message-Id: <202402231347.41NDlqCv088031@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Tom Jones Subject: git: b9870ba93ea9 - main - pf: Add a TCP rdr test on IPv6 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: thj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b9870ba93ea90a12f5a5727c80f7958b17f9afcc Auto-Submitted: auto-generated The branch main has been updated by thj: URL: https://cgit.FreeBSD.org/src/commit/?id=b9870ba93ea90a12f5a5727c80f7958b17f9afcc commit b9870ba93ea90a12f5a5727c80f7958b17f9afcc Author: Tom Jones AuthorDate: 2023-10-06 13:19:31 +0000 Commit: Tom Jones CommitDate: 2024-02-23 13:47:35 +0000 pf: Add a TCP rdr test on IPv6 Reviewed by: kp Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D42105 --- tests/sys/netpfil/pf/Makefile | 1 + tests/sys/netpfil/pf/rdr.sh | 127 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) diff --git a/tests/sys/netpfil/pf/Makefile b/tests/sys/netpfil/pf/Makefile index 30099fdc4c17..ce718c4ba900 100644 --- a/tests/sys/netpfil/pf/Makefile +++ b/tests/sys/netpfil/pf/Makefile @@ -29,6 +29,7 @@ ATF_TESTS_SH+= altq \ pfsync \ prio \ proxy \ + rdr \ ridentifier \ route_to \ rtable \ diff --git a/tests/sys/netpfil/pf/rdr.sh b/tests/sys/netpfil/pf/rdr.sh new file mode 100644 index 000000000000..efa3750e8f42 --- /dev/null +++ b/tests/sys/netpfil/pf/rdr.sh @@ -0,0 +1,127 @@ +# +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright © 2023 Tom Jones +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +. $(atf_get_srcdir)/utils.subr + +atf_test_case "tcp_v6" "cleanup" +tcp_v6_head() +{ + atf_set descr 'TCP rdr with IPv6' + atf_set require.user root + atf_set require.progs scapy python3 +} + +# +# Test that rdr works for TCP with IPv6. +# +# a <-----> b <-----> c +# +# Test configures three jails (a, b and c) and connects them together with b as +# a router between a and c. +# +# TCP traffic to b on port 80 is redirected to c on port 8000 +# +# Test for incorrect checksums after the rewrite by looking at a packet capture (see bug 210860) +# +tcp_v6_body() +{ + pft_init + + j="rdr:tcp_v6" + epair_one=$(vnet_mkepair) + epair_two=$(vnet_mkepair) + + echo $epair_one + echo $epair_two + + vnet_mkjail ${j}a ${epair_one}b + vnet_mkjail ${j}b ${epair_one}a ${epair_two}a + vnet_mkjail ${j}c ${epair_two}b + + # configure addresses for b + jexec ${j}b ifconfig lo0 up + jexec ${j}b ifconfig ${epair_one}a inet6 2001:db8:a::1/64 up no_dad + jexec ${j}b ifconfig ${epair_two}a inet6 2001:db8:b::1/64 up no_dad + + # configure addresses for a + jexec ${j}a ifconfig lo0 up + jexec ${j}a ifconfig ${epair_one}b inet6 2001:db8:a::2/64 up no_dad + + # configure addresses for c + jexec ${j}c ifconfig lo0 up + jexec ${j}c ifconfig ${epair_two}b inet6 2001:db8:b::2/64 up no_dad + + # enable forwarding in the b jail + jexec ${j}b sysctl net.inet6.ip6.forwarding=1 + + # add routes so a and c can find each other + jexec ${j}a route add -inet6 2001:db8:b::0/64 2001:db8:a::1 + jexec ${j}c route add -inet6 2001:db8:a::0/64 2001:db8:b::1 + + jexec ${j}b pfctl -e + + pft_set_rules ${j}b \ + "rdr on ${epair_one}a proto tcp from any to any port 80 -> 2001:db8:b::2 port 8000" + + # Check that a can reach c over the router + atf_check -s exit:0 -o ignore \ + jexec ${j}a ping -6 -c 1 2001:db8:b::2 + + # capture packets on c so we can look for incorrect checksums + jexec ${j}c tcpdump --immediate-mode -w ${j}.pcap tcp and port 8000 & + tcpdumppid=$! + + # start a web server and give it a second to start + jexec ${j}c python3 -m http.server & + sleep 1 + + # http directly from a to c -> a ---> b + atf_check -s exit:0 -o ignore \ + jexec ${j}a fetch -T 1 -o /dev/null -q "http://[2001:db8:b::2]:8000" + + # http from a to b with a redirect -> a ---> b + atf_check -s exit:0 -o ignore \ + jexec ${j}a fetch -T 1 -o /dev/null -q "http://[2001:db8:a::1]:80" + + # ask tcpdump to stop so we can check the packet capture + jexec ${j}c kill -s SIGINT $tcpdumppid + + # Check for 'incorrect' in packet capture, this should tell us if + # checksums are bad with rdr rules + count=$(jexec ${j}c tcpdump -vvvv -r ${j}.pcap | grep incorrect | wc -l) + atf_check_equal " 0" "$count" +} + +tcp_v6_cleanup() +{ + pft_cleanup +} + +atf_init_test_cases() +{ + atf_add_test_case "tcp_v6" +}