Skip to content

Commit 5b7d6c9

Browse files
TropicaoMartin KaFai Lau
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]> Signed-off-by: Martin KaFai Lau <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 38e3651 commit 5b7d6c9

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

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

Lines changed: 13 additions & 15 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,26 +135,23 @@ 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

153-
static void stop_server(struct subtest_cfg *cfg)
154-
{
155-
free_fds(cfg->server_fd, 1);
156-
}
157-
158155
static int check_server_rx_data(struct subtest_cfg *cfg,
159156
struct connection *conn, int len)
160157
{
@@ -188,7 +185,7 @@ static struct connection *connect_client_to_server(struct subtest_cfg *cfg)
188185
return NULL;
189186
}
190187

191-
server_fd = accept(*cfg->server_fd, NULL, NULL);
188+
server_fd = accept(cfg->server_fd, NULL, NULL);
192189
if (server_fd < 0) {
193190
close(client_fd);
194191
free(conn);
@@ -384,12 +381,13 @@ static int configure_ebpf_decapsulation(struct subtest_cfg *cfg)
384381

385382
static void run_test(struct subtest_cfg *cfg)
386383
{
387-
struct nstoken *nstoken = open_netns(CLIENT_NS);
384+
struct nstoken *nstoken;
388385

389-
if (!ASSERT_OK_PTR(nstoken, "open client ns"))
386+
if (!ASSERT_OK(run_server(cfg), "run server"))
390387
return;
391388

392-
if (!ASSERT_OK(run_server(cfg), "run server"))
389+
nstoken = open_netns(CLIENT_NS);
390+
if (!ASSERT_OK_PTR(nstoken, "open client ns"))
393391
goto fail;
394392

395393
/* Basic communication must work */
@@ -416,8 +414,8 @@ static void run_test(struct subtest_cfg *cfg)
416414
ASSERT_OK(send_and_test_data(cfg, true), "connect with encap and decap progs");
417415

418416
fail:
419-
stop_server(cfg);
420417
close_netns(nstoken);
418+
close(cfg->server_fd);
421419
}
422420

423421
static int setup(void)

0 commit comments

Comments
 (0)