From patchwork Tue Jul 23 22:22:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13740425 X-Patchwork-Delegate: bpf@iogearbox.net 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 2BA2314882E; Tue, 23 Jul 2024 22:23:36 +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=1721773417; cv=none; b=PkrIdVBQaJriToeBhY5IwEsziLw561g0Ukxtjfylom/PKgnX8p8k+9NJrW4WCUcVIj7X/k0MeqEkYB7PuWn1ZKLGIIeotDXIXvH47SpwVF/fFWdA4yTsrLVcfHdga1Ef/IsmiLjfVXz3a63bgM8F9hmi8XZzDF/z0DnO7bbtBbU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773417; c=relaxed/simple; bh=2LU2vjg3f906UWyhDzXWAXiRIxOItrklwjsTG1UwTzg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tj6e+difzErR9AGCYdaswD5E+x3ikGi/JgwITSl/QlXHJb+VOw+sUbKnsdRF2at7NoXQ+IKsRIVfxQTF+56s2yPHZlDARaFEfQ56qKiiVaPRRYkU/AcFcFTd1VPAAhSNRPwG94pmTisLkfYGKTNe/nX8p9sHqfD5lvZ9m/RVYdg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=N8SJcWOc; 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="N8SJcWOc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FE91C4AF0A; Tue, 23 Jul 2024 22:23:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773416; bh=2LU2vjg3f906UWyhDzXWAXiRIxOItrklwjsTG1UwTzg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N8SJcWOcfw58BTkjnpuO9e88EIkrHRbhQYDvakVuO9wjJUpl05HoggBxvEo/AHBMD Lg/PYxevuKR8H79Ec3+G3UFaPxfb+FSyjUczU4ZKorr9kITUU7JPwph3cxPttMR5jk wHZSFhlZL5VTq/wp4bAqBOzV1C1X/1QlD0s5QgjeK8qY6I3/eTbYBnDTERCjJpwqkG nz7wKRbrgdkdJbUzseBGLgmkmgzd8jFjhz6rqqNGC/8s66gADq7Vpvv8uG3tKNLwzj yHAiPQIsr/NCjE1aLdxe1eh6PhzUYlQLD9AaCsnb/cnBmTgITjJESJ+AeSIsWHNQQM LDPz4Qr/7KYmA== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next 14/15] selftests/bpf: Clear type bits for start_server_addr Date: Wed, 24 Jul 2024 06:22:20 +0800 Message-ID: <2bdf858ce89445fa66ef15b0159425649cfe1ffa.1721771340.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang The types "sotype | SOCK_NONBLOCK" are passed to socket_loopback_reuseport by some tests in sockmap_listen.c, so they must be handled in helper start_server_addr() too. This patch uses SOCK_TYPE_MASK to clear useless bits of "type" before check whether it supports listen for connections. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 6b6734b893e4..919b691c2699 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -28,6 +28,9 @@ #define IPPROTO_MPTCP 262 #endif +#define SOCK_MAX (SOCK_PACKET + 1) +#define SOCK_TYPE_MASK 0xf + #define clean_errno() (errno == 0 ? "None" : strerror(errno)) #define log_err(MSG, ...) ({ \ int __save = errno; \ @@ -121,6 +124,9 @@ int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t a goto error_close; } + if (type > SOCK_MAX) + type &= SOCK_TYPE_MASK; + if (!opts->nolisten && listen_support(type)) { if (listen(fd, opts->backlog ? MAX(opts->backlog, 0) : 1) < 0) { log_err("Failed to listed on socket");