Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2093905lqb; Mon, 27 May 2024 07:41:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUGnWCuTAgvfHk+a3lk82yNf0nwGzOjmoFU0110z8pz3rk0rN0I3JxqyTeBl+3dkXHvb0Vwz+nkpSUdx5d6XBJTVx8o4H/qMNd1USqdOw== X-Google-Smtp-Source: AGHT+IHNI7FNppvInHQlRiNPOyitskByFbjjEcR9vhAmWdVZcJgrVd4YVAQ9qcpkKyROnJeRBUCF X-Received: by 2002:a17:907:72c4:b0:a62:f56e:3263 with SMTP id a640c23a62f3a-a62f56e3364mr212725366b.53.1716820909631; Mon, 27 May 2024 07:41:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716820909; cv=pass; d=google.com; s=arc-20160816; b=zvzAHNSBFchAE1HgGbS8D3pJm0lqP4f1x6RqjtRVyVWZW/+VtS9MVAXoOIUjyMWYaA FF9JtTzviH8pbJiym+O3mgxD+1l7D4cVstj3yZXMKDHrBNye3oRttmrOm6x4/JmBvFD9 ALScghu9unmfBgn4of8VJYmX21hzTtY04Asqv2QDmgxovJbtghn6I/foHG7ctaaWggbB mLN3h9N0tqUL/noG7iruTmGXmebrrHpPAhvKSwYTIOnry9R9nuZv0Mig/bAzg3lIl0+p a1Z9ncLMxpruVllwKPMa2851zjdEqI1hNLcCiJkQvLORALaMIFTfZD6jOxeWqBbKcJ/W xjyA== 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=jO0t+omEAdNtonWU8n8rI5fFa2MHOP6u0G7A0l0M13o=; fh=P9NLqTI0CviI4AjIYpjS56yunXETqo1qCQK6J8i5cSU=; b=QkIkC9uw+UswawZYscwODfeTpVJvD0mOxt2ZAfqT5xwLhwZtJa5ewvANXha+7rYxb+ O5ckTbPy/v4lbLWKVX61FaSPX6mnaanwxiqQhqlE3wt1BoGY3hTJny4f6zaqH5twnrYM qFK+qxeCbT2ovSC3o31WY7SvhI8YTvd+7gm7r45GSTDR8TnWiuENhI2bmozfoAL7c90n 1Y76/+E8gAHHapQlm45/5y2Cw3tMEOKmqlHhFYU8Ec1C985y2vvOc6thQDGTHETUlFkN 4TsTGCiIpZOm7NEoTbFo/bDbYgJIp7tOwfS4OW+u6yhdYl/egTyXwcKzwtkfRDR7q3Aq kOtA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IY80prSB; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190912-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190912-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a62898bc0e9si320357566b.661.2024.05.27.07.41.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 07:41:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190912-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IY80prSB; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190912-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190912-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 5F5A01F2275F for ; Mon, 27 May 2024 14:41:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 203E016DEBC; Mon, 27 May 2024 14:18:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IY80prSB" 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 3A7DD15F41C; Mon, 27 May 2024 14:18: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=1716819502; cv=none; b=Ifn/4nJmIExsBUkBAtBJzQt8/GUoG897AYxdbI2s4YvFEHcgVw/8a86KJZhmdcHnrbW++wXFh+j+Aw8RJ3o41oP/LoQOleLb361ujmh7qlnDZWwrvV1vQpc8I2G4HCpDljtXgcbJDrCfuh2FJC4umG9FYLAU1DVgULDAZajkZi4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819502; c=relaxed/simple; bh=mPtOXgq3B+AB3yz0KIoLJj3lbMa70xltwRQpL80b65U=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Gsb1CW7/LxeDEcpEMXdeowkGfjtoAeVDcGPmGstsAihp6/hSK5uJJbnpySVQuTuvIiYlhXiFOPElB8ODqExEL2Ays3EkV/N96IHWKgxAr/rVnhmsBqOk7pFZyW5az6gWBUgBvgssXaoH1vc67ibjwlkENpRpfIzQpx4fHDerzRI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IY80prSB; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CF0AC2BBFC; Mon, 27 May 2024 14:18:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716819501; bh=mPtOXgq3B+AB3yz0KIoLJj3lbMa70xltwRQpL80b65U=; h=From:To:Cc:Subject:Date:From; b=IY80prSBTNYm4SiT0QE+6v2VwH64vcljiKGHA+S1d1qJE0kMAYZOnD+RZpUpDi8K+ llF1dJcwbtyQ7NSleAMD8IWXHC+uSBhkHg7038NHFpraJuKaIqeEIYpfjKB08x+JTq TiV1A8Hv7uZWAxhnewBLYTY38O/WJYc9MH3ZehrVjJYjTCb2Opet6A3ZLLBMATPgYM rV1xqFHVVh6x3sxOUN12uZOadF/vrWgx5hSq3R+oYpICDow74tdQP8leGUg+nPgUSE 8mZHbXz2uqi2/Io3fxShwL7Y4dovAzQAZNHyYaKs/zjse0/UoVPaW5ytUmQ5k+GWZD DSh/JmN8c3M6g== 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 5.15 01/13] selftests/bpf: Prevent client connect before server bind in test_tc_tunnel.sh Date: Mon, 27 May 2024 10:17:55 -0400 Message-ID: <20240527141819.3854376-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.15.160 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 088fcad138c98..38c6e9f16f41e 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 "${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 @@ -189,6 +198,7 @@ setup # basic communication works echo "test basic connectivity" server_listen +wait_for_port ${port} ${netcat_opt} client_connect verify_data @@ -200,6 +210,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