From nobody Fri Aug 11 12:13:32 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 4RMjPT2mhTz4q17S; Fri, 11 Aug 2023 12:13:33 +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 4RMjPT12Pmz3gJ0; Fri, 11 Aug 2023 12:13:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691756013; 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=pbIfv2T8oNRIxtfSbMw455O2lR42L/bi+tt1Qh6Wii8=; b=dGGYfFEXHOwd0ZQhhnptlAgNAt3Fx+GAk2Y7cVAJ2j5ge+hfwFnagS1ZM7WJL5jxh3JA+5 eRMlAHA/KwtH6OVoXoE3mXw8bwK1qiTbXwadyxXqUVKwz4HUnqeJl63T0ZxF9csJ+pez6/ 9EEr5U+aG0Z8T0MhXPgmImkGikR+oGqOhk1bs88V2DYDlUI/Bmy0t7gbR1Su7U45let1Iz r0RGW7qaz3/wM5ncxR9lRS0mqq4cP8EUekWTQwbgeoxnPANjPUOxEf0/kYorFq6T+P4ZUD Y82hi+lUpSwBUFjqxdHUi6LISOgi1RE0Wnab1lgrdUFH+7CXrAwHWJQ1HYTe6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691756013; 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=pbIfv2T8oNRIxtfSbMw455O2lR42L/bi+tt1Qh6Wii8=; b=vcxw2ntX3AcXi/CiLrLsv+zYCvLRQHyq2A2AY93uhuW3+oEm1HTkPFsCnEvqwlPM7TLlYO YGGfIIkC4dlZhVjX2/WKbt67U9KfcqkyuxMHK9kvmXsxo+8pp0ohmXCGn8YD32RQtzHk3V alcz37cC9yRxzv4ySH+qs9R9H5aSRPu0DC8JlS+EDG5xSuzWaE4mts5VBf19vXwRez66tQ dvZsNUdg4BgsooCyGd/zwqK0Hus+OE1ihNaGiHMA3IvWoN+UoFi5gcrux2x5J5fp1foBV9 xEWRqx5qjj1YzFCI6NinHeTzkrWHCF/BA1FXV5jb4izmb5FclxvIcOUXzzKpWA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1691756013; a=rsa-sha256; cv=none; b=EPB+8WeXEVkSuGw4LKC1ZWXQKD2N9tSEPvRpfDp1FjhjGJBig+edC3W4wtfiT8r+rP36g2 pVjMl1wiMD8TKbV9iVD+eHCx98pTp8wGCBZp3aRcl+8dDJ4HYiq6yK4Vw2qku3Pnoe2Pd5 pCvU9oC+yxNF5vD5SIYobcwENI0D3QtnPpPCxPyXgE0xuoor/5NmAdHKJz2e7pzWjRPKla dN+CEmwXuvzHXsQVjNBz8mmcjeNGwOgRZYi0IStb8oJzjJcx0dhwK1dvIZNquy08bocbum dUqCjMtIwH0CC6q+Vzj7fASy2kE9DQlxU3V2GqhxGS0yuQo2M9Ar594NBIG5vg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4RMjPT02KQzfRD; Fri, 11 Aug 2023 12:13:33 +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 37BCDWDf008543; Fri, 11 Aug 2023 12:13:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37BCDWwK008540; Fri, 11 Aug 2023 12:13:32 GMT (envelope-from git) Date: Fri, 11 Aug 2023 12:13:32 GMT Message-Id: <202308111213.37BCDWwK008540@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: a9e6ca87f104 - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: a9e6ca87f104bb127b324b9c30ddf507d112d235 Auto-Submitted: auto-generated The branch stable/13 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=a9e6ca87f104bb127b324b9c30ddf507d112d235 commit a9e6ca87f104bb127b324b9c30ddf507d112d235 Author: Kristof Provost AuthorDate: 2023-04-27 09:13:40 +0000 Commit: Kristof Provost CommitDate: 2023-08-11 12:13:09 +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 (cherry picked from commit 95363473793986eeecf19f7ed78d05f25cfa7b87) --- 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 26e5710d6f81..0ea2bd60e7da 100644 --- a/tests/sys/netpfil/pf/Makefile +++ b/tests/sys/netpfil/pf/Makefile @@ -24,6 +24,7 @@ ATF_TESTS_SH+= altq \ ridentifier \ route_to \ rules_counter \ + 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" +}