From: Martin KaFai Lau <martin.lau@linux.dev>
To: "Alexis Lothoré (eBPF Foundation)" <alexis.lothore@bootlin.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
ebpf@linuxfoundation.org,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org,
Bastien Curutchet <bastien.curutchet@bootlin.com>
Subject: Re: [PATCH bpf-next 3/3] selftests/bpf: use start_server_str rather than start_reuseport_server in tc_tunnel
Date: Mon, 3 Nov 2025 13:31:51 -0800 [thread overview]
Message-ID: <4cbabdf1-af2c-490a-a41a-b40c1539c1cb@linux.dev> (raw)
In-Reply-To: <20251031-tc_tunnel_improv-v1-3-0ffe44d27eda@bootlin.com>
On 10/31/25 2:01 AM, Alexis Lothoré (eBPF Foundation) wrote:
> test_tc_tunnel currently uses start_reuseport_server because it needs to
> frequently start and stop the server, so we need SO_REUSEPORT to avoid
> getting errors on server restart due to the socket being in TIME_WAIT
> state. But the test is only using one server at a time, so it is a bit
> confusing to use this API.
>
> Replace start_reuseport with start_sever_str, and provided the relevant
> callback to set SO_REUSEPORT.
>
> Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
> ---
> .../selftests/bpf/prog_tests/test_tc_tunnel.c | 24 +++++++++++++++-------
> 1 file changed, 17 insertions(+), 7 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..8e3fe6dc6221 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 {
> @@ -131,20 +131,30 @@ static void set_subtest_addresses(struct subtest_cfg *cfg)
> }
> }
>
> +static int reuseport_cb(int fd, void *opts)
> +{
> + int one = 1;
> +
> + return setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one));
> +}
> +
> static int run_server(struct subtest_cfg *cfg)
> {
> int family = cfg->ipproto == 6 ? AF_INET6 : AF_INET;
> + struct network_helper_opts opts = {
> + .timeout_ms = TIMEOUT_MS,
> + .post_socket_cb = reuseport_cb,
> + };
> struct nstoken *nstoken;
>
> 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);
I meant to directly enable SO_REUSE"ADDR" in the start_server_addr()
instead of each individual test using SO_REUSEPORT. I think all tcp server
in test_progs should have it enabled. Something like this:
diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index 8bb09167399a..e8b33d902bbc 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -97,7 +97,7 @@ 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 fd, on = 1;
if (!opts)
opts = &default_opts;
@@ -111,6 +111,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");
I have applied patch 1 and 2.
next prev parent reply other threads:[~2025-11-03 21:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-31 9:01 [PATCH bpf-next 0/3] selftests/bpf: small improvements on tc_tunnel Alexis Lothoré (eBPF Foundation)
2025-10-31 9:01 ` [PATCH bpf-next 1/3] selftests/bpf: skip tc_tunnel subtest if its setup fails Alexis Lothoré (eBPF Foundation)
2025-10-31 9:01 ` [PATCH bpf-next 2/3] selftests/bpf: add checks in tc_tunnel when entering net namespaces Alexis Lothoré (eBPF Foundation)
2025-10-31 9:01 ` [PATCH bpf-next 3/3] selftests/bpf: use start_server_str rather than start_reuseport_server in tc_tunnel Alexis Lothoré (eBPF Foundation)
2025-11-03 21:31 ` Martin KaFai Lau [this message]
2025-11-03 21:33 ` [PATCH bpf-next 0/3] selftests/bpf: small improvements on tc_tunnel patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4cbabdf1-af2c-490a-a41a-b40c1539c1cb@linux.dev \
--to=martin.lau@linux.dev \
--cc=alexis.lothore@bootlin.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bastien.curutchet@bootlin.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=ebpf@linuxfoundation.org \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=thomas.petazzoni@bootlin.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox