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 9480416C691; Mon, 27 May 2024 14:16:06 +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=1716819366; cv=none; b=V7CCYym4rxF9I+PS0OEDETWFj+CDQvIUjsWHj1KqkXelAeGf8Du9RAso4jESy+2G5ymSHOgSXaOrzqT5QP/rSv94lhrBpz+em4u+bvDqho3h/BruTg/fcnhEKu3fqbJUVLGyjdWsw/JpapqfScXy9kQOrgtNRGfFMSjnjdUD6k4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819366; c=relaxed/simple; bh=XJT5PosjIpIPOtzXYX+0KCa2o6P9JjTzNvWXyP20SQQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i35A3TtoJ8fQ+VBtVZeiYy8JqBoUhzRQALv7xy+QPcSNnQoozGa3+K9sPXSH3tgphUeSe6XDx+yX2ZTvqxKhsCQf0oinBiCDaouAwgwA0rbIR750UQHV4fulQFfTY852pMBQ4Kd88lxwam4WQ4PZjNHorxdMu23R9oR9CIu1tZg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UAARm4qd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UAARm4qd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 403CFC32781; Mon, 27 May 2024 14:16:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716819366; bh=XJT5PosjIpIPOtzXYX+0KCa2o6P9JjTzNvWXyP20SQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UAARm4qdD6t5Mps5Nm/w4D4UUD3sPTmLvcXngcgzzAPC82gfHw4cvhTATXHa3vTY7 0Unw4kinIV9VTGLPJzSBjcS3c8jFM5HWKU/w+wbqa18iQ1wzvWe9POOzW9GJutf4FU g4y8IF7z4ZUWoP2jpa9bHoP91RvZO/39ep9t5xJsy6fFxfF+TbY3fPeNKSI96xoLWn 0noHF4pG/Y0BZi6EHnNFv3553tTrPTcDevapttcH/OPQQlA7YGnlB0kg7qv9WWVm/K GOowr60kzEzv4P867eSEIgoNtD1Cu3xdLmNl1lzs0muFA1Q3VGSr4TUsJ2tRqMzHgS f4e1b9ic+jqaA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Alessandro Carminati (Red Hat)" , Andrii Nakryiko , Sasha Levin , ast@kernel.org, daniel@iogearbox.net, eddyz87@gmail.com, shuah@kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH AUTOSEL 6.6 02/21] selftests/bpf: Prevent client connect before server bind in test_tc_tunnel.sh Date: Mon, 27 May 2024 10:15:13 -0400 Message-ID: <20240527141551.3853516-2-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240527141551.3853516-1-sashal@kernel.org> References: <20240527141551.3853516-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.32 Content-Transfer-Encoding: 8bit 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 910044f08908a..7989ec6084545 100755 --- a/tools/testing/selftests/bpf/test_tc_tunnel.sh +++ b/tools/testing/selftests/bpf/test_tc_tunnel.sh @@ -72,7 +72,6 @@ cleanup() { server_listen() { ip netns exec "${ns2}" nc "${netcat_opt}" -l "${port}" > "${outfile}" & server_pid=$! - sleep 0.2 } client_connect() { @@ -93,6 +92,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 @@ -193,6 +202,7 @@ setup # basic communication works echo "test basic connectivity" server_listen +wait_for_port ${port} ${netcat_opt} client_connect verify_data @@ -204,6 +214,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