* [PATCH bpf-next 0/2] selftests/bpf: enfoce SO_REUSEADDR in basic test servers
@ 2025-11-05 8:22 Alexis Lothoré (eBPF Foundation)
2025-11-05 8:22 ` [PATCH bpf-next 1/2] selftests/bpf: systematically add SO_REUSEADDR in start_server_addr Alexis Lothoré (eBPF Foundation)
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Alexis Lothoré (eBPF Foundation) @ 2025-11-05 8:22 UTC (permalink / raw)
To: Andrii Nakryiko, Eduard Zingerman, Alexei Starovoitov,
Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Shuah Khan
Cc: ebpf, Bastien Curutchet, Thomas Petazzoni, bpf, linux-kselftest,
linux-kernel, Alexis Lothoré (eBPF Foundation)
Hello,
This small series is another follow-up to [1], in which I misunderstood
Martin's initial feedback (see [2]). I proposed to make tc-tunnel apply
SO_REUSEPORT once server is brought up. This series updates
start_server_addr to really apply Martin's proposal after his
clarification [3]
[1] https://lore.kernel.org/bpf/20251031-tc_tunnel_improv-v1-0-0ffe44d27eda@bootlin.com/
[2] https://lore.kernel.org/bpf/efa3540a-1f52-46ca-9f49-e631a5e3e48c@linux.dev/
[3] https://lore.kernel.org/bpf/4cbabdf1-af2c-490a-a41a-b40c1539c1cb@linux.dev/
Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
---
Alexis Lothoré (eBPF Foundation) (2):
selftests/bpf: systematically add SO_REUSEADDR in start_server_addr
selftests/bpf: use start_server_str rather than start_reuseport_server in tc_tunnel
tools/testing/selftests/bpf/network_helpers.c | 9 +++++++-
.../selftests/bpf/prog_tests/test_tc_tunnel.c | 27 ++++++++++++----------
2 files changed, 23 insertions(+), 13 deletions(-)
---
base-commit: de0745f7cc98146c70a020bc3a1b73c7f3405282
change-id: 20251104-start-server-soreuseaddr-e442446e2d37
Best regards,
--
Alexis Lothoré, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH bpf-next 1/2] selftests/bpf: systematically add SO_REUSEADDR in start_server_addr
2025-11-05 8:22 [PATCH bpf-next 0/2] selftests/bpf: enfoce SO_REUSEADDR in basic test servers Alexis Lothoré (eBPF Foundation)
@ 2025-11-05 8:22 ` Alexis Lothoré (eBPF Foundation)
2025-11-05 8:22 ` [PATCH bpf-next 2/2] selftests/bpf: use start_server_str rather than start_reuseport_server in tc_tunnel Alexis Lothoré (eBPF Foundation)
2025-11-06 23:30 ` [PATCH bpf-next 0/2] selftests/bpf: enfoce SO_REUSEADDR in basic test servers patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: Alexis Lothoré (eBPF Foundation) @ 2025-11-05 8:22 UTC (permalink / raw)
To: Andrii Nakryiko, Eduard Zingerman, Alexei Starovoitov,
Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Shuah Khan
Cc: ebpf, Bastien Curutchet, Thomas Petazzoni, bpf, linux-kselftest,
linux-kernel, Alexis Lothoré (eBPF Foundation)
Some tests have to stop/start a server multiple time with the same
listening address. Doing so without SO_REUSADDR leads to failures due to
the socket still being in TIME_WAIT right after the first instance
stop/before the second instance start. Instead of letting each test
manually set SO_REUSEADDR on their servers, it can be done automatically
by start_server_addr for all tests (and without any major downside).
Enforce SO_REUSEADDR in start_server_addr for all tests.
Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
---
tools/testing/selftests/bpf/network_helpers.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index 8bb09167399a..e99b9c5e66a3 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -97,7 +97,8 @@ int settimeo(int fd, int timeout_ms)
int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t addrlen,
const struct network_helper_opts *opts)
{
- int fd;
+
+ int on = 1, fd;
if (!opts)
opts = &default_opts;
@@ -111,6 +112,12 @@ int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t a
if (settimeo(fd, opts->timeout_ms))
goto error_close;
+ if (type == SOCK_STREAM &&
+ setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) {
+ log_err("Failed to enable SO_REUSEADDR");
+ goto error_close;
+ }
+
if (opts->post_socket_cb &&
opts->post_socket_cb(fd, opts->cb_opts)) {
log_err("Failed to call post_socket_cb");
--
2.51.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH bpf-next 2/2] selftests/bpf: use start_server_str rather than start_reuseport_server in tc_tunnel
2025-11-05 8:22 [PATCH bpf-next 0/2] selftests/bpf: enfoce SO_REUSEADDR in basic test servers Alexis Lothoré (eBPF Foundation)
2025-11-05 8:22 ` [PATCH bpf-next 1/2] selftests/bpf: systematically add SO_REUSEADDR in start_server_addr Alexis Lothoré (eBPF Foundation)
@ 2025-11-05 8:22 ` Alexis Lothoré (eBPF Foundation)
2025-11-06 23:29 ` Martin KaFai Lau
2025-11-06 23:30 ` [PATCH bpf-next 0/2] selftests/bpf: enfoce SO_REUSEADDR in basic test servers patchwork-bot+netdevbpf
2 siblings, 1 reply; 5+ messages in thread
From: Alexis Lothoré (eBPF Foundation) @ 2025-11-05 8:22 UTC (permalink / raw)
To: Andrii Nakryiko, Eduard Zingerman, Alexei Starovoitov,
Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Shuah Khan
Cc: ebpf, Bastien Curutchet, Thomas Petazzoni, bpf, linux-kselftest,
linux-kernel, Alexis Lothoré (eBPF Foundation)
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) <alexis.lothore@bootlin.com>
---
.../selftests/bpf/prog_tests/test_tc_tunnel.c | 27 ++++++++++++----------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/test_tc_tunnel.c b/tools/testing/selftests/bpf/prog_tests/test_tc_tunnel.c
index deea90aaefad..4d29256d8714 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_tc_tunnel.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_tc_tunnel.c
@@ -69,7 +69,7 @@ struct subtest_cfg {
int client_egress_prog_fd;
int server_ingress_prog_fd;
char extra_decap_mod_args[TUNNEL_ARGS_MAX_LEN];
- int *server_fd;
+ int server_fd;
};
struct connection {
@@ -135,16 +135,18 @@ static int run_server(struct subtest_cfg *cfg)
{
int family = cfg->ipproto == 6 ? AF_INET6 : AF_INET;
struct nstoken *nstoken;
+ struct network_helper_opts opts = {
+ .timeout_ms = TIMEOUT_MS
+ };
nstoken = open_netns(SERVER_NS);
if (!ASSERT_OK_PTR(nstoken, "open server ns"))
return -1;
- cfg->server_fd = start_reuseport_server(family, SOCK_STREAM,
- cfg->server_addr, TEST_PORT,
- TIMEOUT_MS, 1);
+ cfg->server_fd = start_server_str(family, SOCK_STREAM, cfg->server_addr,
+ TEST_PORT, &opts);
close_netns(nstoken);
- if (!ASSERT_OK_PTR(cfg->server_fd, "start server"))
+ if (!ASSERT_OK_FD(cfg->server_fd, "start server"))
return -1;
return 0;
@@ -152,7 +154,7 @@ static int run_server(struct subtest_cfg *cfg)
static void stop_server(struct subtest_cfg *cfg)
{
- free_fds(cfg->server_fd, 1);
+ close(cfg->server_fd);
}
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)
return NULL;
}
- server_fd = accept(*cfg->server_fd, NULL, NULL);
+ server_fd = accept(cfg->server_fd, NULL, NULL);
if (server_fd < 0) {
close(client_fd);
free(conn);
@@ -394,29 +396,30 @@ static void run_test(struct subtest_cfg *cfg)
/* Basic communication must work */
if (!ASSERT_OK(send_and_test_data(cfg, true), "connect without any encap"))
- goto fail;
+ goto fail_close_server;
/* Attach encapsulation program to client */
if (!ASSERT_OK(configure_encapsulation(cfg), "configure encapsulation"))
- goto fail;
+ goto fail_close_server;
/* If supported, insert kernel decap module, connection must succeed */
if (!cfg->expect_kern_decap_failure) {
if (!ASSERT_OK(configure_kernel_decapsulation(cfg),
"configure kernel decapsulation"))
- goto fail;
+ goto fail_close_server;
if (!ASSERT_OK(send_and_test_data(cfg, true),
"connect with encap prog and kern decap"))
- goto fail;
+ goto fail_close_server;
}
/* Replace kernel decapsulation with BPF decapsulation, test must pass */
if (!ASSERT_OK(configure_ebpf_decapsulation(cfg), "configure ebpf decapsulation"))
- goto fail;
+ goto fail_close_server;
ASSERT_OK(send_and_test_data(cfg, true), "connect with encap and decap progs");
fail:
stop_server(cfg);
+fail_close_server:
close_netns(nstoken);
}
--
2.51.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next 2/2] selftests/bpf: use start_server_str rather than start_reuseport_server in tc_tunnel
2025-11-05 8:22 ` [PATCH bpf-next 2/2] selftests/bpf: use start_server_str rather than start_reuseport_server in tc_tunnel Alexis Lothoré (eBPF Foundation)
@ 2025-11-06 23:29 ` Martin KaFai Lau
0 siblings, 0 replies; 5+ messages in thread
From: Martin KaFai Lau @ 2025-11-06 23:29 UTC (permalink / raw)
To: Alexis Lothoré (eBPF Foundation)
Cc: Andrii Nakryiko, Eduard Zingerman, Alexei Starovoitov,
Daniel Borkmann, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Shuah Khan,
ebpf, Bastien Curutchet, Thomas Petazzoni, bpf, linux-kselftest,
linux-kernel
On 11/5/25 12:22 AM, Alexis Lothoré (eBPF Foundation) wrote:
> 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) <alexis.lothore@bootlin.com>
> ---
> .../selftests/bpf/prog_tests/test_tc_tunnel.c | 27 ++++++++++++----------
> 1 file changed, 15 insertions(+), 12 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/test_tc_tunnel.c b/tools/testing/selftests/bpf/prog_tests/test_tc_tunnel.c
> index deea90aaefad..4d29256d8714 100644
> --- a/tools/testing/selftests/bpf/prog_tests/test_tc_tunnel.c
> +++ b/tools/testing/selftests/bpf/prog_tests/test_tc_tunnel.c
> @@ -69,7 +69,7 @@ struct subtest_cfg {
> int client_egress_prog_fd;
> int server_ingress_prog_fd;
> char extra_decap_mod_args[TUNNEL_ARGS_MAX_LEN];
> - int *server_fd;
> + int server_fd;
> };
>
> struct connection {
> @@ -135,16 +135,18 @@ static int run_server(struct subtest_cfg *cfg)
> {
> int family = cfg->ipproto == 6 ? AF_INET6 : AF_INET;
> struct nstoken *nstoken;
> + struct network_helper_opts opts = {
> + .timeout_ms = TIMEOUT_MS
> + };
>
> nstoken = open_netns(SERVER_NS);
> if (!ASSERT_OK_PTR(nstoken, "open server ns"))
> return -1;
>
> - cfg->server_fd = start_reuseport_server(family, SOCK_STREAM,
> - cfg->server_addr, TEST_PORT,
> - TIMEOUT_MS, 1);
> + cfg->server_fd = start_server_str(family, SOCK_STREAM, cfg->server_addr,
> + TEST_PORT, &opts);
> close_netns(nstoken);
> - if (!ASSERT_OK_PTR(cfg->server_fd, "start server"))
> + if (!ASSERT_OK_FD(cfg->server_fd, "start server"))
> return -1;
>
> return 0;
> @@ -152,7 +154,7 @@ static int run_server(struct subtest_cfg *cfg)
>
> static void stop_server(struct subtest_cfg *cfg)
> {
> - free_fds(cfg->server_fd, 1);
> + close(cfg->server_fd);
> }
>
> 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)
> return NULL;
> }
>
> - server_fd = accept(*cfg->server_fd, NULL, NULL);
> + server_fd = accept(cfg->server_fd, NULL, NULL);
> if (server_fd < 0) {
> close(client_fd);
> free(conn);
> @@ -394,29 +396,30 @@ static void run_test(struct subtest_cfg *cfg)
>
> /* Basic communication must work */
> if (!ASSERT_OK(send_and_test_data(cfg, true), "connect without any encap"))
> - goto fail;
> + goto fail_close_server;
>
> /* Attach encapsulation program to client */
> if (!ASSERT_OK(configure_encapsulation(cfg), "configure encapsulation"))
> - goto fail;
> + goto fail_close_server;
>
> /* If supported, insert kernel decap module, connection must succeed */
> if (!cfg->expect_kern_decap_failure) {
> if (!ASSERT_OK(configure_kernel_decapsulation(cfg),
> "configure kernel decapsulation"))
> - goto fail;
> + goto fail_close_server;
> if (!ASSERT_OK(send_and_test_data(cfg, true),
> "connect with encap prog and kern decap"))
> - goto fail;
> + goto fail_close_server;
> }
>
> /* Replace kernel decapsulation with BPF decapsulation, test must pass */
> if (!ASSERT_OK(configure_ebpf_decapsulation(cfg), "configure ebpf decapsulation"))
> - goto fail;
> + goto fail_close_server;
> ASSERT_OK(send_and_test_data(cfg, true), "connect with encap and decap progs");
>
> fail:
> stop_server(cfg);
> +fail_close_server:
The "fail" and "fail_close_server" ordering is incorrect. I took this
chance to simplify it by doing run_server() before open_netns().
Applied. Thanks.
> close_netns(nstoken);
> }
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next 0/2] selftests/bpf: enfoce SO_REUSEADDR in basic test servers
2025-11-05 8:22 [PATCH bpf-next 0/2] selftests/bpf: enfoce SO_REUSEADDR in basic test servers Alexis Lothoré (eBPF Foundation)
2025-11-05 8:22 ` [PATCH bpf-next 1/2] selftests/bpf: systematically add SO_REUSEADDR in start_server_addr Alexis Lothoré (eBPF Foundation)
2025-11-05 8:22 ` [PATCH bpf-next 2/2] selftests/bpf: use start_server_str rather than start_reuseport_server in tc_tunnel Alexis Lothoré (eBPF Foundation)
@ 2025-11-06 23:30 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-11-06 23:30 UTC (permalink / raw)
To: =?utf-8?q?Alexis_Lothor=C3=A9_=28eBPF_Foundation=29_=3Calexis=2Elothore=40bo?=,
=?utf-8?q?otlin=2Ecom=3E?=
Cc: andrii, eddyz87, ast, daniel, martin.lau, song, yonghong.song,
john.fastabend, kpsingh, sdf, haoluo, jolsa, shuah, ebpf,
bastien.curutchet, thomas.petazzoni, bpf, linux-kselftest,
linux-kernel
Hello:
This series was applied to bpf/bpf-next.git (master)
by Martin KaFai Lau <martin.lau@kernel.org>:
On Wed, 05 Nov 2025 09:22:47 +0100 you wrote:
> Hello,
> This small series is another follow-up to [1], in which I misunderstood
> Martin's initial feedback (see [2]). I proposed to make tc-tunnel apply
> SO_REUSEPORT once server is brought up. This series updates
> start_server_addr to really apply Martin's proposal after his
> clarification [3]
>
> [...]
Here is the summary with links:
- [bpf-next,1/2] selftests/bpf: systematically add SO_REUSEADDR in start_server_addr
https://git.kernel.org/bpf/bpf-next/c/38e36514fcb0
- [bpf-next,2/2] selftests/bpf: use start_server_str rather than start_reuseport_server in tc_tunnel
https://git.kernel.org/bpf/bpf-next/c/5b7d6c91986e
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-11-06 23:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-05 8:22 [PATCH bpf-next 0/2] selftests/bpf: enfoce SO_REUSEADDR in basic test servers Alexis Lothoré (eBPF Foundation)
2025-11-05 8:22 ` [PATCH bpf-next 1/2] selftests/bpf: systematically add SO_REUSEADDR in start_server_addr Alexis Lothoré (eBPF Foundation)
2025-11-05 8:22 ` [PATCH bpf-next 2/2] selftests/bpf: use start_server_str rather than start_reuseport_server in tc_tunnel Alexis Lothoré (eBPF Foundation)
2025-11-06 23:29 ` Martin KaFai Lau
2025-11-06 23:30 ` [PATCH bpf-next 0/2] selftests/bpf: enfoce SO_REUSEADDR in basic test servers patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox