diff mbox series

[bpf-next,13/15] selftests/bpf: Check listen support for start_server_addr

Message ID b2ab8c367cd621743f74bf7bc7aa81a98fe571e2.1721771340.git.tanggeliang@kylinos.cn
State New
Headers show
Series [bpf-next,01/15] selftests/bpf: Use start_server_str in skc_to_unix_sock | expand

Commit Message

Geliang Tang July 23, 2024, 10:22 p.m. UTC
From: Geliang Tang <tanggeliang@kylinos.cn>

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 <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/bpf/network_helpers.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
diff mbox series

Patch

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;