Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2098561lqb; Mon, 27 May 2024 07:50:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUnHHMnOKiYbf9i5Y9GwNVcfyf6bu84TT8y6RyvNJqrSZOkFw1tJbuE2DBCnRZKb1eBanFNaAhrd/iS+NGekzG4yVN77jROcVPYjIHYJw== X-Google-Smtp-Source: AGHT+IEL/bcwoSA2erzhCtUdc8QWJW5H3ouHRasiLJpuNKl0tozWkRTJARCyipW7bT+lpJp8fvBA X-Received: by 2002:ae9:f809:0:b0:792:bf2f:8b2f with SMTP id af79cd13be357-794ab08d8ddmr952291285a.2.1716821458999; Mon, 27 May 2024 07:50:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716821458; cv=pass; d=google.com; s=arc-20160816; b=HloBkVp9djlSaBHzY9RXYWgLvyhgeL1TDpHR1FJ4SRbnIjZT2ds9GuO/ehuSQffc1M znk80ECHZAUbxvhRIsJdfdiHtcNKul6npc/zpMoxjmHyOmio5X/tppTjbvEgCFpgh8GP eythx812fe/hz/LGRGhzvk7OOglyOJTOMWM+shnWEnaNtUUrNHueMlX3FYMhMX8PNjbe 7d0tD1wE/ticRhYJksjyQMXklOI5mLCRpqISduee9TNgOM2lmP0oqQYaZuH7D40aGGwQ uOxUndD3assqRsPW0NJRHwJeeL9CTR7nq6lt/eIOQ6wCRoju1vXakDXaVtQY3rD4MzPh Gz2A== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=xoaYLyulSGvR/oYAtMJZsBSIN1Nhyz7sj64Yjmw/gP0=; fh=66tJS3g2QuF2XaQwzxQwnallgsqKRQuqxt8t6lYY9zA=; b=wj48fyB5oeMZ7UUQxDlgQHBaa9sgHDs8X4ObwvtBHwq/Kp8sHiib+mgPdea+bkfgW4 7hZbpm3FKlLthlPfV6xTz7aJkCzZK0JShK28m7KFQrcwtc1DTXQHjITbvPtoZGUEIm6m FxR09tYNsiwCQD9vS0EtK8FJo4fFw2MxYECpIIITmGEC9HD18sybeJ+Hh1jz8eYJE3xB wvF7rHbyl60PHZi77l4wjAAKhypzCwlNW1Yr/h1qYoiCfgY/NEGAZHFKCUYQ4y/0cuzt aPiRX2MnUbPMe+FPosI9pz6XtU3v9gRZW1wDqmeMXNDgaPyU9DuSadygUjzL1Q9M9ZRT 6l0g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ljaiOn2P; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190938-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190938-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 af79cd13be357-794b038b101si747684985a.221.2024.05.27.07.50.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 07:50:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190938-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=ljaiOn2P; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190938-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190938-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 B4F0D1C217B2 for ; Mon, 27 May 2024 14:50:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 86550169AF5; Mon, 27 May 2024 14:19:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ljaiOn2P" 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 A5052169ADD; Mon, 27 May 2024 14:19:52 +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=1716819592; cv=none; b=Z24hleKr427PWELOK6gyJSySMc+xUGAPQMuHgWfYWM2TB2WPF2zKwb72RLf5WbnfitB/IuI+ybbeaaTjGoWorl2TOmh6BVfkXlzynCRJWulwz/plKRSMqPX2b/ME2Yhbp3Vw2gbz4DDwoaeQxvTgIjNyS7Dkqd5bROei33XQZ6I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819592; c=relaxed/simple; bh=egnv+4LYG9kf+MAFhOdp1ZtsU4oJCToVCs7HH+OYNpM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Oz3cOOSxUqMqyzKtk0/HV0ToEUuVl/Q2q1NM9kgRs0hWYd1squ9aFy9Ls65OARW755WV8eIcuADcj/gOBJzrA2rjcGLalFo6n8ITdrejENj/FWBvmG2zfXb6TKt6gBDB91Z0snTVu1Xj50ZELMCbfSJ7G6P0RWFRFsgZZtdW6K4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ljaiOn2P; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51524C2BBFC; Mon, 27 May 2024 14:19:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716819592; bh=egnv+4LYG9kf+MAFhOdp1ZtsU4oJCToVCs7HH+OYNpM=; h=From:To:Cc:Subject:Date:From; b=ljaiOn2PmkfYv6gOTLOT8ZuL5QBDlHtu3fs4MPkkJE9MI2Crwt8PZAjPsr6EPaxXd GQ89mz7LsMm81s0zqzkys7anU0pw8znASvtpcUcK8x9FzvhuPCfxVtHKRuArFzGOlL CxOHdl0/vodjnQlVOpYpSKZQHIYE4/1oBJAhdEoI9deU2ZxcRZSByyvcFRqcBu2lB5 C7rCIzghfwJ8EnnjUdVjjN+2d8wu+OKRn8f9PDArkt/UyW9c+IkxRtkn3tyQxyxVKK jHJcvf1aF+T0RezMYU2iDwLRf4uc4YDVtu4xfP7s8SwHlILS8dnxDI2VkT6QZ72coC 2uwXiCkEdnhwg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Alessandro Carminati (Red Hat)" , Andrii Nakryiko , Sasha Levin , eddyz87@gmail.com, ast@kernel.org, daniel@iogearbox.net, shuah@kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 1/6] selftests/bpf: Prevent client connect before server bind in test_tc_tunnel.sh Date: Mon, 27 May 2024 10:19:38 -0400 Message-ID: <20240527141950.3854993-1-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 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 5.4.277 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 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