Skip to content

Commit 4bcf88f

Browse files
TropicaoKernel Patches Daemon
authored andcommitted
selftests/bpf: use start_server_str rather than start_reuseport_server in tc_tunnel
Now that start_server_str enforces SO_REUSEADDR, there's no need to keep using start_reusport_server in tc_tunnel, especially since it only uses one server at a time. Replace start_reuseport_server with start_server_str in tc_tunnel test. Signed-off-by: Alexis Lothoré (eBPF Foundation) <[email protected]>
1 parent c8054d0 commit 4bcf88f

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

tools/testing/selftests/bpf/prog_tests/test_tc_tunnel.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct subtest_cfg {
6969
int client_egress_prog_fd;
7070
int server_ingress_prog_fd;
7171
char extra_decap_mod_args[TUNNEL_ARGS_MAX_LEN];
72-
int *server_fd;
72+
int server_fd;
7373
};
7474

7575
struct connection {
@@ -135,24 +135,26 @@ static int run_server(struct subtest_cfg *cfg)
135135
{
136136
int family = cfg->ipproto == 6 ? AF_INET6 : AF_INET;
137137
struct nstoken *nstoken;
138+
struct network_helper_opts opts = {
139+
.timeout_ms = TIMEOUT_MS
140+
};
138141

139142
nstoken = open_netns(SERVER_NS);
140143
if (!ASSERT_OK_PTR(nstoken, "open server ns"))
141144
return -1;
142145

143-
cfg->server_fd = start_reuseport_server(family, SOCK_STREAM,
144-
cfg->server_addr, TEST_PORT,
145-
TIMEOUT_MS, 1);
146+
cfg->server_fd = start_server_str(family, SOCK_STREAM, cfg->server_addr,
147+
TEST_PORT, &opts);
146148
close_netns(nstoken);
147-
if (!ASSERT_OK_PTR(cfg->server_fd, "start server"))
149+
if (!ASSERT_OK_FD(cfg->server_fd, "start server"))
148150
return -1;
149151

150152
return 0;
151153
}
152154

153155
static void stop_server(struct subtest_cfg *cfg)
154156
{
155-
free_fds(cfg->server_fd, 1);
157+
close(cfg->server_fd);
156158
}
157159

158160
static int check_server_rx_data(struct subtest_cfg *cfg,
@@ -188,7 +190,7 @@ static struct connection *connect_client_to_server(struct subtest_cfg *cfg)
188190
return NULL;
189191
}
190192

191-
server_fd = accept(*cfg->server_fd, NULL, NULL);
193+
server_fd = accept(cfg->server_fd, NULL, NULL);
192194
if (server_fd < 0) {
193195
close(client_fd);
194196
free(conn);
@@ -394,29 +396,30 @@ static void run_test(struct subtest_cfg *cfg)
394396

395397
/* Basic communication must work */
396398
if (!ASSERT_OK(send_and_test_data(cfg, true), "connect without any encap"))
397-
goto fail;
399+
goto fail_close_server;
398400

399401
/* Attach encapsulation program to client */
400402
if (!ASSERT_OK(configure_encapsulation(cfg), "configure encapsulation"))
401-
goto fail;
403+
goto fail_close_server;
402404

403405
/* If supported, insert kernel decap module, connection must succeed */
404406
if (!cfg->expect_kern_decap_failure) {
405407
if (!ASSERT_OK(configure_kernel_decapsulation(cfg),
406408
"configure kernel decapsulation"))
407-
goto fail;
409+
goto fail_close_server;
408410
if (!ASSERT_OK(send_and_test_data(cfg, true),
409411
"connect with encap prog and kern decap"))
410-
goto fail;
412+
goto fail_close_server;
411413
}
412414

413415
/* Replace kernel decapsulation with BPF decapsulation, test must pass */
414416
if (!ASSERT_OK(configure_ebpf_decapsulation(cfg), "configure ebpf decapsulation"))
415-
goto fail;
417+
goto fail_close_server;
416418
ASSERT_OK(send_and_test_data(cfg, true), "connect with encap and decap progs");
417419

418420
fail:
419421
stop_server(cfg);
422+
fail_close_server:
420423
close_netns(nstoken);
421424
}
422425

0 commit comments

Comments
 (0)