From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F33A317557E; Wed, 3 Jul 2024 11:04:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720004641; cv=none; b=fvXEuFHWqZQG5WA4jufJ7byb6adItjkAHVAFHr4p/ILVOlO5TbxnVNUM72zy63yNjeqQPvnkRWJg8CbF74i5seSAqmt6i+2IDnuwlayIKHDKHApUF/uA2UR0FyfK5T3J4AW9FF69ACHkBm1fVX7z6fxjBh0lYOPrxGlFeeSPESE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720004641; c=relaxed/simple; bh=z9E4SyypIyGeGteifZr0nKTOopD/2GqhIFCaFziLEAk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RLQ3evFJ0mqT3biq/6SvUEk1CGuZIVRqZIBonae94zImNs3p6jhr5KTZS59/BCVqLs/BS9K1L2tN6sjiKZ6ULDecLBIBZgytLehRwscpSqW0VXOL8tJTWRRpb/v25WBzUelOZdcvKSdKS8y1pluYXTTX8SOdLaSedBQS1+Veko4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Dd0C3Gcv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Dd0C3Gcv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76B11C2BD10; Wed, 3 Jul 2024 11:04:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1720004640; bh=z9E4SyypIyGeGteifZr0nKTOopD/2GqhIFCaFziLEAk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dd0C3Gcv+yMjAhIeFxQBCa6q6pWC2obTWjpiUsbc1iXQM4DNRRwJfsnqbGsUoNrW6 LNTQbTy7+UZ429JzBKMACbJPilaeuFOC+95toRNkJC+5Thyu9vf/kViUTjTRQlde3s CEr3wDw6+VFepDCddRnP5Mn0elRdC6uyx4pmQCqk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Alessandro Carminati (Red Hat)" , Andrii Nakryiko , Sasha Levin Subject: [PATCH 5.10 109/290] selftests/bpf: Prevent client connect before server bind in test_tc_tunnel.sh Date: Wed, 3 Jul 2024 12:38:10 +0200 Message-ID: <20240703102908.311319183@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240703102904.170852981@linuxfoundation.org> References: <20240703102904.170852981@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alessandro Carminati (Red Hat) [ Upstream commit f803bcf9208a2540acb4c32bdc3616673169f490 ] In some systems, the netcat server can incur in delay to start listening. When this happens, the test can randomly fail in various points. This is an example error message: # ip gre none gso # encap 192.168.1.1 to 192.168.1.2, type gre, mac none len 2000 # test basic connectivity # Ncat: Connection refused. The issue stems from a race condition between the netcat client and server. The test author had addressed this problem by implementing a sleep, which I have removed in this patch. This patch introduces a function capable of sleeping for up to two seconds. However, it can terminate the waiting period early if the port is reported to be listening. Signed-off-by: Alessandro Carminati (Red Hat) Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20240314105911.213411-1-alessandro.carminati@gmail.com Signed-off-by: Sasha Levin --- tools/testing/selftests/bpf/test_tc_tunnel.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/test_tc_tunnel.sh b/tools/testing/selftests/bpf/test_tc_tunnel.sh index 7c76b841b17bb..21bde60c95230 100755 --- a/tools/testing/selftests/bpf/test_tc_tunnel.sh +++ b/tools/testing/selftests/bpf/test_tc_tunnel.sh @@ -71,7 +71,6 @@ cleanup() { server_listen() { ip netns exec "${ns2}" nc "${netcat_opt}" -l -p "${port}" > "${outfile}" & server_pid=$! - sleep 0.2 } client_connect() { @@ -92,6 +91,16 @@ verify_data() { fi } +wait_for_port() { + for i in $(seq 20); do + if ip netns exec "${ns2}" ss ${2:--4}OHntl | grep -q "$1"; then + return 0 + fi + sleep 0.1 + done + return 1 +} + set -e # no arguments: automated test, run all @@ -183,6 +192,7 @@ setup # basic communication works echo "test basic connectivity" server_listen +wait_for_port ${port} ${netcat_opt} client_connect verify_data @@ -194,6 +204,7 @@ ip netns exec "${ns1}" tc filter add dev veth1 egress \ section "encap_${tuntype}_${mac}" echo "test bpf encap without decap (expect failure)" server_listen +wait_for_port ${port} ${netcat_opt} ! client_connect if [[ "$tuntype" =~ "udp" ]]; then -- 2.43.0