Skip to content

Commit 65a3f0d

Browse files
Geliang TangMartin KaFai Lau
authored andcommitted
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: Geliang Tang <tanggeliang@kylinos.cn> Link: https://lore.kernel.org/r/e0ae6b790ac0abc7193aadfb2660c8c9eb0fe1f0.1714907662.git.tanggeliang@kylinos.cn Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
1 parent 5059c73 commit 65a3f0d

1 file changed

Lines changed: 5 additions & 33 deletions

File tree

tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,6 @@
1818
#include "cgroup_helpers.h"
1919
#include "network_helpers.h"
2020

21-
static int connect_to_server(const struct sockaddr *addr, socklen_t len)
22-
{
23-
int fd = -1;
24-
25-
fd = socket(addr->sa_family, SOCK_STREAM, 0);
26-
if (fd == -1) {
27-
log_err("Failed to create client socket");
28-
goto out;
29-
}
30-
31-
if (connect(fd, (const struct sockaddr *)addr, len) == -1) {
32-
log_err("Fail to connect to server");
33-
goto close_out;
34-
}
35-
36-
goto out;
37-
38-
close_out:
39-
close(fd);
40-
fd = -1;
41-
out:
42-
return fd;
43-
}
44-
4521
static int get_map_fd_by_prog_id(int prog_id, bool *xdp)
4622
{
4723
struct bpf_prog_info info = {};
@@ -80,8 +56,7 @@ static int get_map_fd_by_prog_id(int prog_id, bool *xdp)
8056
return map_fd;
8157
}
8258

83-
static int run_test(int server_fd, int results_fd, bool xdp,
84-
const struct sockaddr *addr, socklen_t len)
59+
static int run_test(int server_fd, int results_fd, bool xdp)
8560
{
8661
int client = -1, srv_client = -1;
8762
int ret = 0;
@@ -107,7 +82,7 @@ static int run_test(int server_fd, int results_fd, bool xdp,
10782
goto err;
10883
}
10984

110-
client = connect_to_server(addr, len);
85+
client = connect_to_fd(server_fd, 0);
11186
if (client == -1)
11287
goto err;
11388

@@ -254,16 +229,13 @@ int main(int argc, char **argv)
254229
if (server_dual == -1 || !get_port(server_dual, &addr4dual.sin_port))
255230
goto err;
256231

257-
if (run_test(server, results, xdp,
258-
(const struct sockaddr *)&addr4, sizeof(addr4)))
232+
if (run_test(server, results, xdp))
259233
goto err;
260234

261-
if (run_test(server_v6, results, xdp,
262-
(const struct sockaddr *)&addr6, sizeof(addr6)))
235+
if (run_test(server_v6, results, xdp))
263236
goto err;
264237

265-
if (run_test(server_dual, results, xdp,
266-
(const struct sockaddr *)&addr4dual, sizeof(addr4dual)))
238+
if (run_test(server_dual, results, xdp))
267239
goto err;
268240

269241
printf("ok\n");

0 commit comments

Comments
 (0)