From nobody Fri Jul 21 10:32:39 2023 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 4R6m8l2d5sz4pG4v; Fri, 21 Jul 2023 10:32:39 +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 4R6m8l1pJ8z3q31; Fri, 21 Jul 2023 10:32:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689935559; 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=HHVI0Ze1OfcD3Z1PX87LIRRer+tFZWueKfEVXMEp5rI=; b=bx5QNAJGw0HsZ3+XUZfFTvUtOk38h3DYZ/2Z/GrZtvxN9fQfG8lr3rXIquWt8fJeAOp9PW uNvUZEMO/lPHh72dCIdfXKzPcOrNowkjKmYuN8KSbYOd8YH4HwVpx6vRnSZVAjEAzun/ZH lPK2LVKYDx2esC3jtI6CsWtv2q/4fgZ2mt+yNf2BhHq2C55Qzzc9xMP8xOyenH0ZN3UV0j s04cAJKySuE7kPwDXkdNoIBAgFx5KDv+C+iYJkPMq2Zwi8BP+z/NNUgBtLYN2gmPoVma+P XLrdj/SXgMSqDvA2drIh0SKOfCWWFrS+Y/2+M2B+OWxp35Id3q6LEE5bBac8Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689935559; 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=HHVI0Ze1OfcD3Z1PX87LIRRer+tFZWueKfEVXMEp5rI=; b=Wyiwbi773bgt3SI/UNoVAd2Ml3roUICCKJYLDsJYXD5P2ihb2zD/SyGqfWB9+c85NLWF4O chHXZloK+5plvAo8Kp184BfXlmFdkcMjuyMC2q6ge6fkyNoe0GmgpAld6NMMeiRcdLe1Kr 4YLIAhhVn7RFC1piuWV5MUwlxJ5VLyxUixsMMpPaWzl21W39POMYLOPracLA0HLPu/mx77 NRnv/Hrle09ZHsjFj/opTlhk+YQ6KoIKP9LADKOI188DUqZG16PRfC9RzQTCSjWJrD5RuF H/nWoFY3yGSFGMrlxl+u7H/MfGHQqx3XnMWaY8o9OSxDsQlKxHmgko4OVYR02w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1689935559; a=rsa-sha256; cv=none; b=mP6XjDjymsOd6qObOTvuSWgjeVUAUDIDiqAZzQZMyAa1vXofPMM+eujMdoq/a9eYhqg9Vs YX9JSpKWdM32M3mfflmkzBAEIbo1C/c/CvTKgf72Pdpq1OKwKg125sSbbiIgsmLhuenU5u ySrcWFyVdUnO6ca42yWOjvryYW+68PmPQRdPOjk1WR7Vdw3t4XjgzXPqZVY35dbV702Zba /jmV+NWClrSNuzxtyxsC4Dw4rlXIwc3kIHGOBlv+5RfkPmR7UanbLForrdujEHFoliLxLg /fh9yiq86oImra+oSuYd1fXrK+3bPQ/e9DX1j3V3mxQzwB4nFyHl4JRzWWJD+w== 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 4R6m8l0vgqz183n; Fri, 21 Jul 2023 10:32:39 +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 36LAWdHd010533; Fri, 21 Jul 2023 10:32:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 36LAWd93010532; Fri, 21 Jul 2023 10:32:39 GMT (envelope-from git) Date: Fri, 21 Jul 2023 10:32:39 GMT Message-Id: <202307211032.36LAWd93010532@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: 953634737939 - main - pf tests: basic SCTP connection test 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: 95363473793986eeecf19f7ed78d05f25cfa7b87 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=95363473793986eeecf19f7ed78d05f25cfa7b87 commit 95363473793986eeecf19f7ed78d05f25cfa7b87 Author: Kristof Provost AuthorDate: 2023-04-27 09:13:40 +0000 Commit: Kristof Provost CommitDate: 2023-07-21 10:32:18 +0000 pf tests: basic SCTP connection test pf can now inspect SCTP. Check that we can set up a connection. IPv4 and IPv6 tests. MFC after: 3 weeks Sponsored by: Orange Business Services Differential Revision: https://reviews.freebsd.org/D40863 --- tests/sys/netpfil/pf/Makefile | 1 + tests/sys/netpfil/pf/sctp.sh | 190 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) diff --git a/tests/sys/netpfil/pf/Makefile b/tests/sys/netpfil/pf/Makefile index 8e923b6971b8..19c87486d8bb 100644 --- a/tests/sys/netpfil/pf/Makefile +++ b/tests/sys/netpfil/pf/Makefile @@ -31,6 +31,7 @@ ATF_TESTS_SH+= altq \ rules_counter \ scrub_compat \ scrub_pass \ + sctp \ set_skip \ set_tos \ src_track \ diff --git a/tests/sys/netpfil/pf/sctp.sh b/tests/sys/netpfil/pf/sctp.sh new file mode 100644 index 000000000000..5064fe316e5e --- /dev/null +++ b/tests/sys/netpfil/pf/sctp.sh @@ -0,0 +1,190 @@ +# $FreeBSD$ +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright © 2023 Orange Business Services +# +# 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 + +sctp_init() +{ + pft_init + if ! kldstat -q -m sctp; then + atf_skip "This test requires SCTP" + fi +} + +atf_test_case "basic_v4" "cleanup" +basic_v4_head() +{ + atf_set descr 'Basic SCTP connection over IPv4 passthrough' + atf_set require.user root +} + +basic_v4_body() +{ + sctp_init + + j="sctp:basic_v4" + epair=$(vnet_mkepair) + + vnet_mkjail ${j}a ${epair}a + vnet_mkjail ${j}b ${epair}b + + jexec ${j}a ifconfig ${epair}a 192.0.2.1/24 up + jexec ${j}b ifconfig ${epair}b 192.0.2.2/24 up + # Sanity check + atf_check -s exit:0 -o ignore \ + jexec ${j}a ping -c 1 192.0.2.2 + + jexec ${j}a pfctl -e + pft_set_rules ${j}a \ + "block" \ + "pass in proto sctp to port 1234" + + echo "foo" | jexec ${j}a nc --sctp -N -l 1234 & + + # Wait for the server to start + sleep 1 + + out=$(jexec ${j}b nc --sctp -N -w 3 192.0.2.1 1234) + if [ "$out" != "foo" ]; then + atf_fail "SCTP connection failed" + fi + + # Now with scrub rules present, so normalization is done + pft_set_rules ${j}a \ + "scrub on ${j}a" \ + "block" \ + "pass in proto sctp to port 1234" + + echo "foo" | jexec ${j}a nc --sctp -N -l 1234 & + sleep 1 + + out=$(jexec ${j}b nc --sctp -N -w 3 192.0.2.1 1234) + if [ "$out" != "foo" ]; then + atf_fail "SCTP connection failed" + fi + + # Now fail with a blocked port + echo "foo" | jexec ${j}a nc --sctp -N -l 1235 & + sleep 1 + + out=$(jexec ${j}b nc --sctp -N -w 3 192.0.2.1 1235) + if [ "$out" == "foo" ]; then + atf_fail "SCTP port block failed" + fi + + # Now fail with a blocked port but passing source port + out=$(jexec ${j}b nc --sctp -N -w 3 -p 1234 192.0.2.1 1235) + if [ "$out" == "foo" ]; then + atf_fail "SCTP port block failed" + fi +} + +basic_v4_cleanup() +{ + pft_cleanup +} + +atf_test_case "basic_v6" "cleanup" +basic_v6_head() +{ + atf_set descr 'Basic SCTP connection over IPv6' + atf_set require.user root +} + +basic_v6_body() +{ + sctp_init + + j="sctp:basic_v6" + epair=$(vnet_mkepair) + + vnet_mkjail ${j}a ${epair}a + vnet_mkjail ${j}b ${epair}b + + jexec ${j}a ifconfig ${epair}a inet6 2001:db8::a/64 up no_dad + jexec ${j}b ifconfig ${epair}b inet6 2001:db8::b/64 up no_dad + + # Sanity check + atf_check -s exit:0 -o ignore \ + jexec ${j}a ping -6 -c 1 2001:db8::b + + jexec ${j}a pfctl -e + pft_set_rules ${j}a \ + "block proto sctp" \ + "pass in proto sctp to port 1234" + + echo "foo" | jexec ${j}a nc -6 --sctp -N -l 1234 & + + # Wait for the server to start + sleep 1 + + out=$(jexec ${j}b nc --sctp -N -w 3 2001:db8::a 1234) + if [ "$out" != "foo" ]; then + atf_fail "SCTP connection failed" + fi + + # Now with scrub rules present, so normalization is done + pft_set_rules ${j}a \ + "scrub on ${j}a" \ + "block proto sctp" \ + "pass in proto sctp to port 1234" + + echo "foo" | jexec ${j}a nc -6 --sctp -N -l 1234 & + sleep 1 + + out=$(jexec ${j}b nc --sctp -N -w 3 2001:db8::a 1234) + if [ "$out" != "foo" ]; then + atf_fail "SCTP connection failed" + fi + + # Now fail with a blocked port + echo "foo" | jexec ${j}a nc -6 --sctp -N -l 1235 & + sleep 1 + + out=$(jexec ${j}b nc --sctp -N -w 3 2001:db8::a 1235) + if [ "$out" == "foo" ]; then + atf_fail "SCTP port block failed" + fi + + # Now fail with a blocked port but passing source port + out=$(jexec ${j}b nc --sctp -N -w 3 -p 1234 2001:db8::a 1235) + if [ "$out" == "foo" ]; then + atf_fail "SCTP port block failed" + fi +} + +basic_v6_cleanup() +{ + pft_cleanup +} + + +atf_init_test_cases() +{ + atf_add_test_case "basic_v4" + atf_add_test_case "basic_v6" +}