From nobody Fri Jul 21 10:32:45 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 4R6m8x44xRz4pG2k; Fri, 21 Jul 2023 10:32:47 +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 4R6m8t17K4z3qDH; Fri, 21 Jul 2023 10:32:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689935566; 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=ImG1X9YsZaUxI4VkH6ekOiF6MzW3Cko6OjAyHWRhuqU=; b=VBJAu36xZEsKZdpx6xotLv/hiedN342q0z8F+q4E7Wc7KBoKXk8mF4ezly9BBJI0DR6cOe B7OAkKO2mcLnZQ7hQmUSGZuOexaYbO5DBI4HyClqKWKfxLCWPsG+G4z9njUDvWtn9Wff+W xVKRIi+GquPX2OdcGUD5WgS6yjM01th4Dl3WGN9S7jE/6hXwdZhEpj3oBEl0fWqyNpcZuD kGMoShru+bWOdBRZusfBpfOJEMLHdyCdtDZUJe15rqw4h3N0FdadmxDzQ8wqvadRu/bxlF g5JIcvcSGm+xExGSq1hfhgF2+GMS7R0ik87mCWySSRgOA7iNF/6J4LwXQDNcEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689935566; 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=ImG1X9YsZaUxI4VkH6ekOiF6MzW3Cko6OjAyHWRhuqU=; b=rsTwICfEmEFz9atpiLdRTE2xUgPdec7CMFngmWXl9akXNdOvIhaFptoFHHf5QyGDOAXo+k whIJxOehO3d6aOnig+wOTly0rnHolCTrFKbxyvSmsLIHQcjr47PnKJYmjdw5NE9fKW7Kl1 9n1GgB1LMt/Eud89G1Fti+pbZcvPj/8W5P6ecwzJIqS/Rp4Mz8TWjDgH+Ud5lKjVAgRcL8 sPpqyfVBLCLhMJfBNGPg1iw7S6u6L1JxeuYbT2UJF/EOLJlVYhN51iu/oQsRCiDbmApvlw e8Y1DPBSeYrCXbJdVZ8ONkeZZeWbFfwmqLtR/i/0E8FJIf76Ck3JYyxVytKHGQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1689935566; a=rsa-sha256; cv=none; b=V5Jc6j4fzRfgKKeRvYaqPkzPYiogaNvFzfsf2OtUu2Enf+VSUO9+mbbrI9PL0tOk9vVAIs eP4Q8qZ0rGe5OXX6lwKR5+T8MksPY2Mcv0tFUl3L9qlmKoml1WGztB2G2f2JUeiyOMr53x uUyJriA29JabMeGrKApLcjiLaHr81J1/8geKiq1D7GkANq6h/iWVtuF2bXGuUEt0gXXVVC 2gKMjRjLjAL7FCibIeG5k35G6z2WlFy+JyAiw7N1Ib1QltSdI/0Kqdf379+tK+nMZ83asB 0uCMeda8RbkDDlfVlLxtjQTusrg+xXv+pzAuK5wzD89R/kGa1pCmXkptE9Lazg== 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 4R6m8s5yKkz18G8; Fri, 21 Jul 2023 10:32:45 +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 36LAWjQm010655; Fri, 21 Jul 2023 10:32:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 36LAWjXh010654; Fri, 21 Jul 2023 10:32:45 GMT (envelope-from git) Date: Fri, 21 Jul 2023 10:32:45 GMT Message-Id: <202307211032.36LAWjXh010654@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: b7a9a5773a0f - main - pf tests: test SCTP pfsync 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: b7a9a5773a0fdf9b9c7839d79d76dbc6b69a6c4b Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=b7a9a5773a0fdf9b9c7839d79d76dbc6b69a6c4b commit b7a9a5773a0fdf9b9c7839d79d76dbc6b69a6c4b Author: Kristof Provost AuthorDate: 2023-06-07 09:55:06 +0000 Commit: Kristof Provost CommitDate: 2023-07-21 10:32:19 +0000 pf tests: test SCTP pfsync Ensure that SCTP connections survive a failover to the backup pf instance. MFC after: 3 weeks Sponsored by: Orange Business Services Differential Revision: https://reviews.freebsd.org/D40869 --- tests/sys/netpfil/pf/sctp.sh | 188 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) diff --git a/tests/sys/netpfil/pf/sctp.sh b/tests/sys/netpfil/pf/sctp.sh index 2c736017f9fa..ec131a6384cc 100644 --- a/tests/sys/netpfil/pf/sctp.sh +++ b/tests/sys/netpfil/pf/sctp.sh @@ -469,6 +469,193 @@ rdr_v4_cleanup() pft_cleanup } +atf_test_case "pfsync" "cleanup" +pfsync_head() +{ + atf_set descr 'Test pfsync-ing SCTP connections' + atf_set require.user root +} + +pfsync_body() +{ + # + Builds bellow topology and initiate an SCTP connection + # from client to server. + # + Tests that the connection remains open when we fail over from + # router one to router two. + # + # ┌──────┐ + # │client│ + # └───┬──┘ + # │ + # ┌───┴───┐ + # │bridge0│ + # └┬─────┬┘ + # │ │ + # ┌────────────────┴─┐ ┌─┴────────────────┐ + # │ one ├─┤ two │ + # └────────────────┬─┘ └─┬────────────────┘ + # │ │ + # ┌┴─────┴┐ + # │bridge1│ + # └───┬───┘ + # │ + # ┌───┴──┐ + # │server│ + # └──────┘ + + sctp_init + pfsynct_init + if ! kldstat -q -m carp + then + atf_skip "This test requires carp" + fi + + j="sctp:pfsync" + + tmp=`pwd` + + bridge0=$(vnet_mkbridge) + bridge1=$(vnet_mkbridge) + + epair_c=$(vnet_mkepair) + epair_one0=$(vnet_mkepair) + epair_two0=$(vnet_mkepair) + epair_sync=$(vnet_mkepair) + epair_one1=$(vnet_mkepair) + epair_two1=$(vnet_mkepair) + epair_srv=$(vnet_mkepair) + + ifconfig ${bridge0} addm ${epair_c}a addm ${epair_one0}a addm ${epair_two0}a + ifconfig ${epair_one0}a up + ifconfig ${epair_two0}a up + ifconfig ${epair_c}a up + ifconfig ${bridge0} up + + ifconfig ${bridge1} addm ${epair_srv}a addm ${epair_one1}a addm ${epair_two1}a + ifconfig ${epair_one1}a up + ifconfig ${epair_two1}a up + ifconfig ${epair_srv}a up + ifconfig ${bridge1} up + + vnet_mkjail ${j}c ${epair_c}b + jexec ${j}c ifconfig ${epair_c}b 192.0.2.2/24 up + jexec ${j}c route add default 192.0.2.1 + + vnet_mkjail ${j}one ${epair_one0}b ${epair_one1}b ${epair_sync}a + jexec ${j}one ifconfig ${epair_one0}b 192.0.2.3/24 up + jexec ${j}one ifconfig ${epair_one0}b \ + alias 192.0.2.1/32 vhid 1 pass 1234 + jexec ${j}one ifconfig ${epair_one1}b 198.51.100.3/24 up + jexec ${j}one ifconfig ${epair_one1}b \ + alias 198.51.100.2/32 vhid 2 pass 4321 + jexec ${j}one ifconfig ${epair_sync}a 203.0.113.1/24 up + jexec ${j}one ifconfig pfsync0 \ + syncdev ${epair_sync}a \ + maxupd 1 \ + up + jexec ${j}one sysctl net.inet.ip.forwarding=1 + + vnet_mkjail ${j}two ${epair_two0}b ${epair_two1}b ${epair_sync}b + jexec ${j}two ifconfig ${epair_two0}b 192.0.2.4/24 up + jexec ${j}two ifconfig ${epair_two0}b \ + alias 192.0.2.1/32 vhid 1 pass 1234 + jexec ${j}two ifconfig ${epair_two1}b 198.51.100.4/24 up + jexec ${j}two ifconfig ${epair_two1}b \ + alias 198.51.100.2/32 vhid 2 pass 4321 + jexec ${j}two ifconfig ${epair_sync}b 203.0.113.2/24 up + jexec ${j}two ifconfig pfsync0 \ + syncdev ${epair_sync}b \ + maxupd 1 \ + up + jexec ${j}two sysctl net.inet.ip.forwarding=1 + + vnet_mkjail ${j}srv ${epair_srv}b + jexec ${j}srv ifconfig ${epair_srv}b 198.51.100.1/24 up + jexec ${j}srv route add default 198.51.100.2 + + # Demote two, to avoid dealing with asymmetric routing + jexec ${j}two sysctl net.inet.carp.demotion=50 + + jexec ${j}one pfctl -e + pft_set_rules ${j}one \ + "block all" \ + "pass proto { icmp, pfsync, carp }" \ + "pass proto sctp to port 1234" \ + "pass proto tcp to port 1234" + + jexec ${j}two pfctl -e + pft_set_rules ${j}two \ + "block all" \ + "pass proto { icmp, pfsync, carp }" \ + "pass proto sctp to port 1234" \ + "pass proto tcp to port 1234" + + # Give carp time to get set up + sleep 2 + + # Sanity check + atf_check -s exit:0 -o ignore \ + jexec ${j}c ping -c 1 198.51.100.1 + + # Now start up an SCTP connection + touch ${tmp}/input + tail -F ${tmp}/input | jexec ${j}srv nc --sctp -l 1234 & + sleep 1 + + jexec ${j}c nc --sctp 198.51.100.1 1234 > ${tmp}/output & + echo "1" >> ${tmp}/input + + # Give time for the traffic to arrive + sleep 1 + line=$(tail -n -1 ${tmp}/output) + if [ "${line}" != "1" ]; + then + echo "Found ${line}" + cat ${tmp}/output + atf_fail "Initial SCTP connection failed" + fi + + # Verify that two has the connection too + state=$(jexec ${j}two pfctl -ss | grep sctp) + if [ -z "${state}" ]; + then + jexec ${j}two pfctl -ss + atf_fail "Failed to find SCTP state on secondary pfsync host" + fi + + # Now fail over (both carp IPs should switch here) + jexec ${j}one sysctl net.inet.carp.demotion=100 + + while ! jexec ${j}one ifconfig ${epair_one0}b | grep MASTER; + do + sleep 1 + done + while ! jexec ${j}one ifconfig ${epair_one1}b | grep MASTER; + do + sleep 1 + done + + # Sanity check + atf_check -s exit:0 -o ignore \ + jexec ${j}c ping -c 1 198.51.100.1 + + # And check that the connection is still live + echo "2" >> ${tmp}/input + sleep 1 + line=$(tail -n -1 ${tmp}/output) + if [ "${line}" != "2" ]; + then + echo "Found ${line}" + cat ${tmp}/output + atf_fail "SCTP failover failed" + fi +} + +pfsync_cleanup() +{ + pfsynct_cleanup +} + atf_init_test_cases() { atf_add_test_case "basic_v4" @@ -478,4 +665,5 @@ atf_init_test_cases() atf_add_test_case "nat_v4" atf_add_test_case "nat_v6" atf_add_test_case "rdr_v4" + atf_add_test_case "pfsync" }