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 --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;