Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2083854lqb; Mon, 27 May 2024 07:23:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUfNrZtJUXhtcS1xym7M6i42OzwIW4Y6NFjBcyMWpQRITNZDH0EXm3phShnyPpSDQIDUvyuWMIZqiRcF4R3Qdto+Ab+p5PFmSBMCdIqEg== X-Google-Smtp-Source: AGHT+IGLbyZG3x3jU7T/+3yOiPhuJRsdyasGrLrDhtE2Ita5Swm1zNPpxt+NBA+76+AhpgdQQyld X-Received: by 2002:ac8:580e:0:b0:437:bec6:7354 with SMTP id d75a77b69052e-43fb0e6d5c7mr104650761cf.28.1716819806663; Mon, 27 May 2024 07:23:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716819806; cv=pass; d=google.com; s=arc-20160816; b=s39TR+aOSjLkM7QCoFKMCrEOwW4l/8ZlhhEO5BKRM9DDKz6R9PhNPvC7YPmqwYrquO EbbapVZEfAnxt+Re4YzyMpLiE9PrnjYR41z9U+nhEzZHLjr7AsEH2SHrsSaGF0sTEg9J twxpaBTvqtriKOXkcNTLbegdPOKrRKLK+4YIS6IawSHW/bpHzlKVNrXgog6Vj/9+PeXk z2b3G4KEsLWM53eBzGf0HyUGt386eIWrgEsyPGRw4DkSQAcPegb49XZb040eAF+v50O3 X0r61ZsmjnZiRKaFTNTyboVVLOthIRmbL4GLF2pgbGZhUq9oGNMYC40UGJNV+t1NA7VM C8sg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dB9GYu0HZi1hEkp22e/rvHhJs9b6QUM81H6pFhDfqWE=; fh=P9NLqTI0CviI4AjIYpjS56yunXETqo1qCQK6J8i5cSU=; b=kr/Sy75Fplubcw+Nn7MiMVh83KVxYq9ythTOWF0WA2u6MJ+wl7vztSWXbmnsGQAM0F 6aQjBnRb6fHs2Wxk7XcekuoF8DzPr0VC/Q4KzjHj/dCOLmU9dzkjvuC1c7iSG8BiSvDj iQ8FGa3jQSLxtAhqP8zeSZ/DY1ayzSV/Sx/8JKtQuxFxjoHBY9liO1XwOrwqczPgrkL+ V22CxG735FrF9HWQexgMlt8xlwc+210+AajfvcKunZnB1gS3cNNe3OZU6zbNj2HDzA5V cu/F+bedFiTYtxcrytAL8bZ8HoKVvzRm0gCzRGymfU2xSFLxF9kfnsVc3tMeh36FaVSa GIEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Cu8bRAz3; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190838-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190838-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43fb18a6c7esi78646811cf.279.2024.05.27.07.23.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 07:23:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190838-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Cu8bRAz3; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190838-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190838-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4ADB51C22255 for ; Mon, 27 May 2024 14:22:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF4AD161322; Mon, 27 May 2024 14:14:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Cu8bRAz3" 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 D15D0160862; Mon, 27 May 2024 14:14:21 +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=1716819261; cv=none; b=h4XAtvUgcVYj1ohrN4woh1ARaBb7RIZ3Cfc2gUbQkYN83Bjjy8Us6hFHPMfIwGH6P+z/Abxvr0X+fNuy9G1WUkhFt2C5Avl9MPbeR88/Uivr+BuDTXhtbLBFD2O8F4x0+vmiMJ1mYKQ50G29u4QwwnIfKq0IA9P8Lanhc46Kga8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819261; c=relaxed/simple; bh=XJT5PosjIpIPOtzXYX+0KCa2o6P9JjTzNvWXyP20SQQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h81H1Oy4dkWecap4NxOHTkGnrwpVklQNol1XLQOUC+pnxGJXJgE0hK3sk2sok89wbFimGzEjd1BuzZU9YQDuazibNIvCbCq0csTb4lO7hmPMKLCnMOT3drdLtWAFzqjfA/WYBYyQNJgy+PTzpYNkHmvjuHXDlLa4QI+BpWC2HRc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Cu8bRAz3; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 411B0C2BBFC; Mon, 27 May 2024 14:14:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716819261; bh=XJT5PosjIpIPOtzXYX+0KCa2o6P9JjTzNvWXyP20SQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cu8bRAz3XczMj8LsxapXxD2HP+F9abQIeXWgb4rIRIAjEXjTblZaE9JLZWGVET3/O 1RvNt5MB2sAcamrPJXFEtyYyH8wSOHLrjirBEEwFkTsYU4qqgef/sWphcWYOgzQ55z Q7j1UL0sPq1eK3rWKQKlUuk68DKz/HlBT4JfahL9TE4QKNVwGjQBrkO4rtTmHCiBED zBOnO1q7XbSzbyMBlNcvJ+jQnGfu059A+PFQe4V4MFZmxYyeiCNKVFDpeIGzqbe+11 klBHSZAx4RnnOAQjqHm2OSF49ezSQvgfqpyvIsHoG5rSHiBXyppCwXlTDJNt0AHkGd tmLcaxb2QQ8ug== 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.8 02/30] selftests/bpf: Prevent client connect before server bind in test_tc_tunnel.sh Date: Mon, 27 May 2024 10:13:11 -0400 Message-ID: <20240527141406.3852821-2-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240527141406.3852821-1-sashal@kernel.org> References: <20240527141406.3852821-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@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.8.11 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