Commit 65a3f0df authored by Geliang Tang's avatar Geliang Tang Committed by Martin KaFai Lau

selftests/bpf: Use connect_to_fd in test_tcp_check_syncookie

This patch uses public helper connect_to_fd() exported in network_helpers.h
instead of the local defined function connect_to_server() in
test_tcp_check_syncookie_user.c. This can avoid duplicate code.

Then the arguments "addr" and "len" of run_test() become useless, drop them
too.
Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
Link: https://lore.kernel.org/r/e0ae6b790ac0abc7193aadfb2660c8c9eb0fe1f0.1714907662.git.tanggeliang@kylinos.cnSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
parent 5059c73e
...@@ -18,30 +18,6 @@ ...@@ -18,30 +18,6 @@
#include "cgroup_helpers.h" #include "cgroup_helpers.h"
#include "network_helpers.h" #include "network_helpers.h"
static int connect_to_server(const struct sockaddr *addr, socklen_t len)
{
int fd = -1;
fd = socket(addr->sa_family, SOCK_STREAM, 0);
if (fd == -1) {
log_err("Failed to create client socket");
goto out;
}
if (connect(fd, (const struct sockaddr *)addr, len) == -1) {
log_err("Fail to connect to server");
goto close_out;
}
goto out;
close_out:
close(fd);
fd = -1;
out:
return fd;
}
static int get_map_fd_by_prog_id(int prog_id, bool *xdp) static int get_map_fd_by_prog_id(int prog_id, bool *xdp)
{ {
struct bpf_prog_info info = {}; struct bpf_prog_info info = {};
...@@ -80,8 +56,7 @@ static int get_map_fd_by_prog_id(int prog_id, bool *xdp) ...@@ -80,8 +56,7 @@ static int get_map_fd_by_prog_id(int prog_id, bool *xdp)
return map_fd; return map_fd;
} }
static int run_test(int server_fd, int results_fd, bool xdp, static int run_test(int server_fd, int results_fd, bool xdp)
const struct sockaddr *addr, socklen_t len)
{ {
int client = -1, srv_client = -1; int client = -1, srv_client = -1;
int ret = 0; int ret = 0;
...@@ -107,7 +82,7 @@ static int run_test(int server_fd, int results_fd, bool xdp, ...@@ -107,7 +82,7 @@ static int run_test(int server_fd, int results_fd, bool xdp,
goto err; goto err;
} }
client = connect_to_server(addr, len); client = connect_to_fd(server_fd, 0);
if (client == -1) if (client == -1)
goto err; goto err;
...@@ -254,16 +229,13 @@ int main(int argc, char **argv) ...@@ -254,16 +229,13 @@ int main(int argc, char **argv)
if (server_dual == -1 || !get_port(server_dual, &addr4dual.sin_port)) if (server_dual == -1 || !get_port(server_dual, &addr4dual.sin_port))
goto err; goto err;
if (run_test(server, results, xdp, if (run_test(server, results, xdp))
(const struct sockaddr *)&addr4, sizeof(addr4)))
goto err; goto err;
if (run_test(server_v6, results, xdp, if (run_test(server_v6, results, xdp))
(const struct sockaddr *)&addr6, sizeof(addr6)))
goto err; goto err;
if (run_test(server_dual, results, xdp, if (run_test(server_dual, results, xdp))
(const struct sockaddr *)&addr4dual, sizeof(addr4dual)))
goto err; goto err;
printf("ok\n"); printf("ok\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment