From: Geliang Tang tanggeliang@kylinos.cn
This patch adds a struct member "nolisten" for network_helper_opts, which is used to control whether to invoke listen() or not in start_server_addr().
Also print out a warning if backlog is set for a type not support listen for connections.
Signed-off-by: Geliang Tang tanggeliang@kylinos.cn --- tools/testing/selftests/bpf/network_helpers.c | 5 ++++- tools/testing/selftests/bpf/network_helpers.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 8f39adbc2c16..f140a76d3d7f 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -109,11 +109,14 @@ int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t a goto error_close; }
- if (type == SOCK_STREAM) { + if (!opts->nolisten && type == SOCK_STREAM) { if (listen(fd, opts->backlog ? MAX(opts->backlog, 0) : 1) < 0) { log_err("Failed to listed on socket"); goto error_close; } + } else if (opts->backlog) { + log_err("Useless network helper opts: backlog %d", + opts->backlog); }
return fd; diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index ebed1fb1bd49..16f266c53b61 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -34,6 +34,7 @@ struct network_helper_opts { * changing the "tcp_syncookies" sysctl from 1 to 2. */ int backlog; + bool nolisten; int (*post_socket_cb)(int fd, void *opts); void *cb_opts; };