From patchwork Tue Jul 23 22:22:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 814061 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 C515D1422AB; Tue, 23 Jul 2024 22:23:32 +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=1721773412; cv=none; b=lwYpaSC5Wu+WitBD4eDPhIUwMQ0SFJA95hQ/2yHhpNxoxLjom9pjuQ2cG+snHLvcOtxGQwIe3KHnn9iYTkT5ONWwjJVEV6P70HSxYaHzrHDjq6wH5WXvw2mDAFGljw//KOYJ3hZfaVNYftmuW1QajGltr5QyoMGHuxCHmVQWlgg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721773412; c=relaxed/simple; bh=SDq3d/iEx9vI0ULJ3CqdeMcebgGgRTUsqukdR9Cpzt0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gkvjj482ayvwGMJJat4P/8be87AM0JAyRSoliDppt6yL3VqxLSpynIKR1TE03kGH0uJQhl3zLwOX4F4kbO4V67B78APqg8C+UUg/C2HHTDdw8BhdJhzF0ZliMoeeeRBE4mA43w9VJ3yGasgkyl6+RXDOnVgZnjYLbyS/JLljWiY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=beyXCFmY; 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="beyXCFmY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D36F3C4AF11; Tue, 23 Jul 2024 22:23:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721773412; bh=SDq3d/iEx9vI0ULJ3CqdeMcebgGgRTUsqukdR9Cpzt0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=beyXCFmYzzEJqASQWEOUEMS7X2fzUJfTjHTs865sGKFa3TAegi8BdhGYhQfZkW2c1 10osi/NmWRPS0Q1V0nJvHyGax8TKsNMh8EkzOwg5uWxQMW6j3JBKFD7ProQF0b/lm/ btpiEX64j+PVa3FgxNYBXW2zp1F9/FzVSQw62DozXZuWO7rbFmeQXunhJUvrndslDL XL2ejo/uWhnnDz4qj+6cBs/lEPyC4jAFybR7Kl+XK7P5YI+RTtFMR4F/k5UPhLEQHU 6HMiRFpIbw2GlH+yh0Mi2qUUTyaBdGJQos8Y3WhMAk96Br2QH1F9tX1HWtyyr576ml WYJi4FUbXRY3g== 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 13/15] selftests/bpf: Check listen support for start_server_addr Date: Wed, 24 Jul 2024 06:22:19 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang No only SOCK_STREAM type supports listen for connections on a socket, SOCK_SEQPACKET used in sockmap_listen.c supports it too. This patch adds a new helper listen_support() to check whether a given "type" supports listen for connections on a socket or not. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 8b06b0bf66ae..6b6734b893e4 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -82,6 +82,17 @@ int settimeo(int fd, int timeout_ms) #define save_errno_close(fd) ({ int __save = errno; close(fd); errno = __save; }) +static bool listen_support(int type) +{ + switch (type) { + case SOCK_STREAM: + case SOCK_SEQPACKET: + return true; + default: + return false; + } +} + int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t addrlen, const struct network_helper_opts *opts) { @@ -110,7 +121,7 @@ int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t a goto error_close; } - if (!opts->nolisten && type == SOCK_STREAM) { + if (!opts->nolisten && listen_support(type)) { if (listen(fd, opts->backlog ? MAX(opts->backlog, 0) : 1) < 0) { log_err("Failed to listed on socket"); goto error_close;