From nobody Fri Aug 11 12:13: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 4RMjPc1912z4TjRJ; Fri, 11 Aug 2023 12:13:40 +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 4RMjPb6rbhz4CX6; Fri, 11 Aug 2023 12:13:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691756020; 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=ZH4aumL1l+N1P8eYJXZisJwjvI5ixwHU0lsvJsCQZJ4=; b=czODAisneQHEkn7hhr2dw9kzMzfsoeSWoXgiTLTuABD1P0HQcb8y4NqZaBbWosSWj+4/HB J8+Nb/tsa/nn5wn4rgO8PPZswEb3zHsN/2uiorRQQUxN66ejEdh1FnBvuth/s17u0CiuDR AmF+LxV2T0ti6epW+IfEJ59idy3L+HeBCmBUzUIR5npgeAXCGWFkJ7KlHonGJGs/xFmbRt rSfSpO28dbHGqvA0VXL8BreUFoUAYS69n4cy4FpwjQOoIDbjy+VM1PA4T/FxmgzpeVJbZU WBO0gQymfGZYXnESDmZheVOHaQV+YJtJ/GHIat3BwdsgMzC09OnpLjV2KuXM6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691756020; 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=ZH4aumL1l+N1P8eYJXZisJwjvI5ixwHU0lsvJsCQZJ4=; b=trvMen1KNIbii73jV5Ji7CFrfI0ZF5jGuSBKJapvGP1cHL3JVnOz5OiGn3oX7bbHs3lDS7 GF0ge8g/jyBssP2hs8o727hukgHFN6nnFJQgUcu/m14Lz7wy5pHH8HhqYd0Rxu5L478g9G cU0eq21DzR+f+d205zKHcY1AGmcq2Sv8Oyq1t3NRlimSm3G7rEEf0mZ9jMkvEkheGmmqvo 2Eq5R2HbQMjnHo4eZnhjwMDEV01ByoG5SII6Od4CZRa/y+MNdW2GgV6X7yFym1Bl5uprz/ zZ5GtEMIEbF498/4LFApbBcrUMSAmhS9J2k78ho2/gXHwXYNb1mh58DrkBUFIQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1691756020; a=rsa-sha256; cv=none; b=ByO4s4PrWXBjluG4zeFbEu9Jl9837wU2d5dplsX0tq0Gd/6sda2490SjorMYQxJPHUwmd1 RgoxRWIvAfxq8CPRnC5cbhD6ygQMP2uZRdZ3x2bRzMCpHIJeukUdo6Wx5ywhZcfR4WKDOi H3VLYMQu6pI7rBEJzVOys649DgeamGzsBZPZ6jZkWa41lnbsJ5mXw6Y8D/xK1vapao9+n+ zyfRXYZFE8GoPgiXg2QcBlWauSLGpJnk4CO1YVMp+UgnZ6ibF23d4Y/8LH7iyBc7FRWVA2 vc7Q8MkebgpFWYagx3RycfPzq9IrWo3roGo9SAeINsY/AH3sdJIUKVJNX0Tg6Q== 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 4RMjPb5q6Xzdms; Fri, 11 Aug 2023 12:13: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 37BCDdFC008813; Fri, 11 Aug 2023 12:13:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37BCDdYa008810; Fri, 11 Aug 2023 12:13:39 GMT (envelope-from git) Date: Fri, 11 Aug 2023 12:13:39 GMT Message-Id: <202308111213.37BCDdYa008810@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: d77d4c6a0419 - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: d77d4c6a04192859dabee22ce49d8e115a20d45c Auto-Submitted: auto-generated The branch stable/13 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=d77d4c6a04192859dabee22ce49d8e115a20d45c commit d77d4c6a04192859dabee22ce49d8e115a20d45c Author: Kristof Provost AuthorDate: 2023-06-07 09:55:06 +0000 Commit: Kristof Provost CommitDate: 2023-08-11 12:13:10 +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 (cherry picked from commit b7a9a5773a0fdf9b9c7839d79d76dbc6b69a6c4b) --- 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" }