From nobody Wed Nov 20 21:41:20 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 4Xtvv50c96z5dnJX; Wed, 20 Nov 2024 21:41:21 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Xtvv43tJTz4vtq; Wed, 20 Nov 2024 21:41:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732138880; 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=rn+X7PwaU7KeyHmz2NcEr+X6ajAfKAx2mgaXLfN5vGE=; b=FBudMDGTu8LRc1Wud0S8PWoHOez74iBMxpY5wfUCrymUGtnWrJqIMbtPaUnc8oTUXK/vLo xVW3Pecz2lUw5dF9gbegp3mDuROSXJKMjCsKGL6M3Hy0JXo44Q/KdrtiGDLtgnu5TvoyWs HfRbT17umbyAKqL/zzri3qswwUIF8UFhvqQ3nbm9UMRPvUJyNQx7kTz/4hlsj7OtdS5tDc cw52aX0GrZ1XtJbtPOUjbkAyFykRz4GDvze5/hCnCZMjNUWMIX5YaRRQX/37Dx/LDOPUpi bSDy3MTlN2jS4cm0Bj2JHnz2SjhoE6MudaJEp3RoHMFbTxfaNg6cXxNgdlNM3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732138880; 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=rn+X7PwaU7KeyHmz2NcEr+X6ajAfKAx2mgaXLfN5vGE=; b=IYzrLSyCZfjipcDzDCvo/b9JUbatZNw16UhZQjwDDkqrQMUOlZTqC63W4PDhTv9qBBxmQm kAbTAMlnvaLFsNEILOPM2tww2dJutZ9CEdJdTPrxmp8UgTMBuA6J+3IVECiim16JEsOa3W NLvpYT6mecvNcdFH9CG1JpUSvy4rXouSiSFxRAY+mD/vJmKFKWXT2y5jppfoKgssEkhA0r hCf+LjKbI0sBZRHOlenb6LBSjlp1RKOZdUMhFbVz5DFj3pE4RrgJSy7bakbKt1xwoxpbE4 2LvAznDZIMp4KGn+C7Abyv3Px3CJKlqtLQJeuYiLAJHzi4pMK+Bvik5LnDT/YA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732138880; a=rsa-sha256; cv=none; b=FfL4HeQgd50mfklelqmiCuQpjYhqT6vIdKzYJXL6AbdHkUG2JIhMOCIHLiB5iAPkSFLXJU MzgOo2idHwUbu6BJAy3XlfcxqKGIZ00uJvcoVHhuloIbr15ovp3mMbsms5VTjjwOXDQpE9 BYln+YTkxcNiOc4YA9+mKds8EIy0pzLkn0pQ3qKeyhScL2Nbczogc7/DRldieT1lEYJHQ7 ej3I6nCAAi3wfSn6PFQFENB8EUDRVEj54cxLixZY0rYjB+yzSJYToedIfhWpX+6Tz5E26i sO+2GEYfhCs5TX/lebSdLeqDtiQQsv0vCi896gg1VNvFSOCXOC7/1tG03NwClw== 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 4Xtvv41v1zz19rG; Wed, 20 Nov 2024 21:41:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4AKLfKYD022128; Wed, 20 Nov 2024 21:41:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AKLfK72022123; Wed, 20 Nov 2024 21:41:20 GMT (envelope-from git) Date: Wed, 20 Nov 2024 21:41:20 GMT Message-Id: <202411202141.4AKLfK72022123@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 30d40692531d - stable/14 - pf: Add a TCP rdr test on IPv6 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 30d40692531dd79a74ed5e356e68063caeb8803f Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=30d40692531dd79a74ed5e356e68063caeb8803f commit 30d40692531dd79a74ed5e356e68063caeb8803f Author: Tom Jones AuthorDate: 2023-10-06 13:19:31 +0000 Commit: Mark Johnston CommitDate: 2024-11-20 21:41:08 +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 (cherry picked from commit b9870ba93ea90a12f5a5727c80f7958b17f9afcc) --- 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 085cdf043606..cc61a48f80ea 100644 --- a/tests/sys/netpfil/pf/Makefile +++ b/tests/sys/netpfil/pf/Makefile @@ -28,6 +28,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" +}