* [PATCH bpf v5 0/2] selftest/bpf: make test_tc_tunnel and test_tc_edt more robust to CI load
@ 2026-08-14 7:11 Alexis Lothoré (eBPF Foundation)
2026-08-14 7:11 ` [PATCH bpf v5 1/2] bpf/selftests: fix comment style in network_helpers.c Alexis Lothoré (eBPF Foundation)
2026-08-14 7:11 ` [PATCH bpf v5 2/2] selftests/bpf: allocate a larger timeout for connection Alexis Lothoré (eBPF Foundation)
0 siblings, 2 replies; 7+ messages in thread
From: Alexis Lothoré (eBPF Foundation) @ 2026-08-14 7:11 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan,
Ihor Solodrai
Cc: ebpf, Bastien Curutchet, Thomas Petazzoni, bpf, linux-kselftest,
linux-kernel, Alexis Lothoré (eBPF Foundation)
Hello,
this is the v5 of the series aiming to reduce the flakyness of
tc_tunnel/tc_edt tests in CI. This revision just fixes multi-line
comments style, not only for the updated helper but for the whole
network_helpers.c file
Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
---
Changes in v5:
- reformat multi-line comments
- collect Ihor's Acked-by
- Link to v4: https://patch.msgid.link/20260813-tc_tunnel_flaky-v4-1-3534df3fe930@bootlin.com
Changes in v4:
- dropped the polling loop in favor of a larger, connect-specific timeout
- drop timeout configuration from tc_edt test
- Link to v3: https://patch.msgid.link/20260811-tc_tunnel_flaky-v3-0-876f4e0bc603@bootlin.com
Changes in v3:
- set errno before logging errors
- respect time budget set by
- respect opts->timeout_ms when polling: only poll for the remaining
time not already consume by connect()
- keep polling if poll returns with EINTR
- reorder early returns and add intermediate variables to clarify code
flow
- Link to v2: https://patch.msgid.link/20260803-tc_tunnel_flaky-v2-1-657b287dfa75@bootlin.com
Changes in v2:
- drop unneeded initialization
- add back error message for immediate connection failure, and slightly
reword the async connection failure error message
- Link to v1: https://patch.msgid.link/20260710-tc_tunnel_flaky-v1-1-42aab5399a49@bootlin.com
To: Alexei Starovoitov <ast@kernel.org>
To: Daniel Borkmann <daniel@iogearbox.net>
To: Andrii Nakryiko <andrii@kernel.org>
To: Eduard Zingerman <eddyz87@gmail.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: Martin KaFai Lau <martin.lau@linux.dev>
To: Song Liu <song@kernel.org>
To: Yonghong Song <yonghong.song@linux.dev>
To: Jiri Olsa <jolsa@kernel.org>
To: Emil Tsalapatis <emil@etsalapatis.com>
To: Ihor Solodrai <ihor.solodrai@linux.dev>
To: Shuah Khan <shuah@kernel.org>
Cc: ebpf@linuxfoundation.org
Cc: Bastien Curutchet <bastien.curutchet@bootlin.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: bpf@vger.kernel.org
Cc: linux-kselftest@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
Alexis Lothoré (eBPF Foundation) (2):
bpf/selftests: fix comment style in network_helpers.c
selftests/bpf: allocate a larger timeout for connection
tools/testing/selftests/bpf/network_helpers.c | 60 ++++++++++++++++++++++-----
1 file changed, 49 insertions(+), 11 deletions(-)
---
base-commit: 114cb6aa1571c30770715a1756553b812865b1ba
change-id: 20260710-tc_tunnel_flaky-27e9a191bd03
Best regards,
--
Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH bpf v5 1/2] bpf/selftests: fix comment style in network_helpers.c
2026-08-14 7:11 [PATCH bpf v5 0/2] selftest/bpf: make test_tc_tunnel and test_tc_edt more robust to CI load Alexis Lothoré (eBPF Foundation)
@ 2026-08-14 7:11 ` Alexis Lothoré (eBPF Foundation)
2026-08-14 7:49 ` bot+bpf-ci
2026-08-14 7:11 ` [PATCH bpf v5 2/2] selftests/bpf: allocate a larger timeout for connection Alexis Lothoré (eBPF Foundation)
1 sibling, 1 reply; 7+ messages in thread
From: Alexis Lothoré (eBPF Foundation) @ 2026-08-14 7:11 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan,
Ihor Solodrai
Cc: ebpf, Bastien Curutchet, Thomas Petazzoni, bpf, linux-kselftest,
linux-kernel, Alexis Lothoré (eBPF Foundation)
BPF subsystem requires multi-line comments to have the opening /* start
on its own line.
Update multi-line comments in network_helpers.c to follow this
requirement.
Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
---
tools/testing/selftests/bpf/network_helpers.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index db935a9d9fc1..cdf2d7d3ab32 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -424,7 +424,8 @@ int make_sockaddr(int family, const char *addr_str, __u16 port,
*len = sizeof(*sin6);
return 0;
} else if (family == AF_UNIX) {
- /* Note that we always use abstract unix sockets to avoid having
+ /*
+ * Note that we always use abstract unix sockets to avoid having
* to clean up leftover files.
*/
struct sockaddr_un *sun = (void *)addr;
@@ -865,7 +866,8 @@ static bool is_ethernet(const u_char *packet)
memcpy(&arphdr_type, packet + 8, 2);
arphdr_type = ntohs(arphdr_type);
- /* Except the following cases, the protocol type contains the
+ /*
+ * Except the following cases, the protocol type contains the
* Ethernet protocol type for the packet.
*
* https://www.tcpdump.org/linktypes/LINKTYPE_LINUX_SLL2.html
@@ -1033,19 +1035,22 @@ static void *traffic_monitor_thread(void *arg)
if (!packet)
continue;
- /* According to the man page of pcap_dump(), first argument
+ /*
+ * According to the man page of pcap_dump(), first argument
* is the pcap_dumper_t pointer even it's argument type is
* u_char *.
*/
pcap_dump((u_char *)dumper, &header, packet);
- /* Not sure what other types of packets look like. Here, we
+ /*
+ * Not sure what other types of packets look like. Here, we
* parse only Ethernet and compatible packets.
*/
if (!is_ethernet(packet))
continue;
- /* Skip SLL2 header
+ /*
+ * Skip SLL2 header
* https://www.tcpdump.org/linktypes/LINKTYPE_LINUX_SLL2.html
*
* Although the document doesn't mention that, the payload
@@ -1079,7 +1084,8 @@ static void *traffic_monitor_thread(void *arg)
return NULL;
}
-/* Prepare the pcap handle to capture packets.
+/*
+ * Prepare the pcap handle to capture packets.
*
* This pcap is non-blocking and immediate mode is enabled to receive
* captured packets as soon as possible. The snaplen is set to 1024 bytes
@@ -1150,7 +1156,8 @@ static void encode_test_name(char *buf, size_t len, const char *test_name, const
#define PCAP_DIR "/tmp/tmon_pcap"
-/* Start to monitor the network traffic in the given network namespace.
+/*
+ * Start to monitor the network traffic in the given network namespace.
*
* netns: the name of the network namespace to monitor. If NULL, the
* current network namespace is monitored.
@@ -1255,7 +1262,8 @@ static void traffic_monitor_release(struct tmonitor_ctx *ctx)
free(ctx);
}
-/* Stop the network traffic monitor.
+/*
+ * Stop the network traffic monitor.
*
* ctx: the context returned by traffic_monitor_start()
*/
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH bpf v5 2/2] selftests/bpf: allocate a larger timeout for connection
2026-08-14 7:11 [PATCH bpf v5 0/2] selftest/bpf: make test_tc_tunnel and test_tc_edt more robust to CI load Alexis Lothoré (eBPF Foundation)
2026-08-14 7:11 ` [PATCH bpf v5 1/2] bpf/selftests: fix comment style in network_helpers.c Alexis Lothoré (eBPF Foundation)
@ 2026-08-14 7:11 ` Alexis Lothoré (eBPF Foundation)
2026-08-14 7:49 ` bot+bpf-ci
2026-08-17 8:55 ` Daniel Borkmann
1 sibling, 2 replies; 7+ messages in thread
From: Alexis Lothoré (eBPF Foundation) @ 2026-08-14 7:11 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan,
Ihor Solodrai
Cc: ebpf, Bastien Curutchet, Thomas Petazzoni, bpf, linux-kselftest,
linux-kernel, Alexis Lothoré (eBPF Foundation)
Some tests, like tc_tunnel or tc_edt, sporadically fail in CI with the
following logs:
(network_helpers.c:309: errno: Operation now in progress) \
Failed to connect to server
send_and_test_data:FAIL:connect to server unexpected error: -115
This is due to SO_RCVTIMEO and SO_SNDTIMEO being set on the client
socket (see settimeo() in client_socket()), allowing connect() to return
an error and to set errno to EINPROGRESS instead of ETIMEDOUT.
Increasing the timeout value for those tests is likely not a good
solution (and it has already been done by commit 2790db208b44
("selftests/bpf: Improve tc_tunnel test reliability")): some tests
expect some data transfer to fail, and so the timeout value would
increase overall test execution duration again (not only the connection,
but any socket operation).
Another solution is to allocate a timeout budget specific to the
connection: we can apply a larger timeout only for connections, and once
the connection is established, set back the timeout configured through
opts->timeout_ms; this would allow connection to succeed under heavy CI
load, while keeping timeout reasonable for the rest of the test traffic.
Set a larger SO_SNDTIMEO/SO_RCVTIMEO for the connection step, and reset
it back to the timeout configured by the test once the connection has
succeeded.
Fixes: 99126abec5e5 ("bpf: selftests: A few improvements to network_helpers.c")
Acked-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
---
tools/testing/selftests/bpf/network_helpers.c | 36 ++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index cdf2d7d3ab32..8c9236c0a5a5 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -49,6 +49,8 @@
errno = __save; \
})
+#define CONNECT_MIN_TIMEOUT_MS 5000
+
struct ipv4_packet pkt_v4 = {
.eth.h_proto = __bpf_constant_htons(ETH_P_IP),
.iph.ihl = 5,
@@ -291,6 +293,12 @@ int client_socket(int family, int type,
return -1;
}
+static int connect_timeout_ms(const struct network_helper_opts *opts)
+{
+ /* Enforce a minimum connect timeout value */
+ return MAX(opts->timeout_ms, CONNECT_MIN_TIMEOUT_MS);
+}
+
int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t addrlen,
const struct network_helper_opts *opts)
{
@@ -305,13 +313,35 @@ int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add
return -1;
}
+ /*
+ * Override timeout configuration with a larger value for the
+ * connection
+ */
+ if (settimeo(fd, connect_timeout_ms(opts))) {
+ log_err("Failed to set connect timeout");
+ goto close;
+ }
+
if (connect(fd, (const struct sockaddr *)addr, addrlen)) {
- log_err("Failed to connect to server");
- save_errno_close(fd);
- return -1;
+ log_err("Failed to connect");
+ goto close;
+ }
+
+ /*
+ * If the timeout configured by the test is different from the
+ * connect timeout, restore it
+ */
+ if (opts->timeout_ms != CONNECT_MIN_TIMEOUT_MS &&
+ settimeo(fd, opts->timeout_ms)) {
+ log_err("Failed to set timeout for connected socket");
+ goto close;
}
return fd;
+
+close:
+ save_errno_close(fd);
+ return -1;
}
int connect_to_addr_str(int family, int type, const char *addr_str, __u16 port,
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH bpf v5 1/2] bpf/selftests: fix comment style in network_helpers.c
2026-08-14 7:11 ` [PATCH bpf v5 1/2] bpf/selftests: fix comment style in network_helpers.c Alexis Lothoré (eBPF Foundation)
@ 2026-08-14 7:49 ` bot+bpf-ci
0 siblings, 0 replies; 7+ messages in thread
From: bot+bpf-ci @ 2026-08-14 7:49 UTC (permalink / raw)
To: alexis.lothore, ast, daniel, andrii, eddyz87, memxor, martin.lau,
song, yonghong.song, jolsa, emil, shuah, ihor.solodrai
Cc: ebpf, bastien.curutchet, thomas.petazzoni, bpf, linux-kselftest,
linux-kernel, alexis.lothore, ast, andrii, daniel, martin.lau,
eddyz87, yonghong.song, clm, ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 839 bytes --]
> bpf/selftests: fix comment style in network_helpers.c
>
> BPF subsystem requires multi-line comments to have the opening /* start
> on its own line.
>
> Update multi-line comments in network_helpers.c to follow this
> requirement.
>
> Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
This isn't a bug, but would 'selftests/bpf:' be the expected subject
prefix here? The rest of the directory uses that convention (351
occurrences of 'selftests/bpf:' versus 0 of 'bpf/selftests:' in the
recent history), and the following patch in this series uses
'selftests/bpf:'.
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/31779510003
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf v5 2/2] selftests/bpf: allocate a larger timeout for connection
2026-08-14 7:11 ` [PATCH bpf v5 2/2] selftests/bpf: allocate a larger timeout for connection Alexis Lothoré (eBPF Foundation)
@ 2026-08-14 7:49 ` bot+bpf-ci
2026-08-17 8:55 ` Daniel Borkmann
1 sibling, 0 replies; 7+ messages in thread
From: bot+bpf-ci @ 2026-08-14 7:49 UTC (permalink / raw)
To: alexis.lothore, ast, daniel, andrii, eddyz87, memxor, martin.lau,
song, yonghong.song, jolsa, emil, shuah, ihor.solodrai
Cc: ebpf, bastien.curutchet, thomas.petazzoni, bpf, linux-kselftest,
linux-kernel, alexis.lothore, ast, andrii, daniel, martin.lau,
eddyz87, yonghong.song, clm, ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 2872 bytes --]
> diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
> index d311db786880..ed4aeee1555d 100644
> --- a/tools/testing/selftests/bpf/network_helpers.c
> +++ b/tools/testing/selftests/bpf/network_helpers.c
[ ... ]
> @@ -291,6 +293,12 @@ int client_socket(int family, int type,
> return -1;
> }
>
> +static int connect_timeout_ms(const struct network_helper_opts *opts)
> +{
> + /* Enforce a minimum connect timeout value */
> + return MAX(opts->timeout_ms, CONNECT_MIN_TIMEOUT_MS);
> +}
> +
> int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t addrlen,
> const struct network_helper_opts *opts)
> {
> @@ -305,13 +313,35 @@ int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add
> return -1;
> }
>
> + /*
> + * Override timeout configuration with a larger value for the
> + * connection
> + */
> + if (settimeo(fd, connect_timeout_ms(opts))) {
> + log_err("Failed to set connect timeout");
> + goto close;
> + }
> +
> if (connect(fd, (const struct sockaddr *)addr, addrlen)) {
> - log_err("Failed to connect to server");
> - save_errno_close(fd);
> - return -1;
> + log_err("Failed to connect");
> + goto close;
> + }
> +
> + /*
> + * If the timeout configured by the test is different from the
> + * connect timeout, restore it
> + */
> + if (opts->timeout_ms != CONNECT_MIN_TIMEOUT_MS &&
> + settimeo(fd, opts->timeout_ms)) {
> + log_err("Failed to set timeout for connected socket");
> + goto close;
^^^^
Does this condition match what the comment describes? The value applied
to the socket before connect() is connect_timeout_ms(opts), which returns
MAX(opts->timeout_ms, CONNECT_MIN_TIMEOUT_MS). The guard tests
opts->timeout_ms != CONNECT_MIN_TIMEOUT_MS, so the two expressions only
match when opts->timeout_ms <= CONNECT_MIN_TIMEOUT_MS.
When a test passes a timeout larger than the minimum, the guard fires even
though the socket already has the right value. For example,
prog_tests/xdp_synproxy.c calls connect_to_fd(server_fd, 10000).
connect_timeout_ms() returns 10000, settimeo() applies 10000, then the guard
(10000 != 5000) is true and settimeo() re-applies the same 10000 value the
socket already has.
Would opts->timeout_ms != connect_timeout_ms(opts) express the stated
intent? That guard would be false when opts->timeout_ms == 10000 (nothing
to restore), and true when opts->timeout_ms < CONNECT_MIN_TIMEOUT_MS
(restore the smaller value the test asked for).
> + }
> +
> return fd;
> +
> +close:
> + save_errno_close(fd);
> + return -1;
> }
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/31779510003
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf v5 2/2] selftests/bpf: allocate a larger timeout for connection
2026-08-14 7:11 ` [PATCH bpf v5 2/2] selftests/bpf: allocate a larger timeout for connection Alexis Lothoré (eBPF Foundation)
2026-08-14 7:49 ` bot+bpf-ci
@ 2026-08-17 8:55 ` Daniel Borkmann
2026-08-17 9:55 ` Alexis Lothoré
1 sibling, 1 reply; 7+ messages in thread
From: Daniel Borkmann @ 2026-08-17 8:55 UTC (permalink / raw)
To: Alexis Lothoré (eBPF Foundation), Alexei Starovoitov,
Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
Emil Tsalapatis, Shuah Khan, Ihor Solodrai
Cc: ebpf, Bastien Curutchet, Thomas Petazzoni, bpf, linux-kselftest,
linux-kernel
Hi Alexis,
On 8/14/26 9:11 AM, Alexis Lothoré (eBPF Foundation) wrote:
> Some tests, like tc_tunnel or tc_edt, sporadically fail in CI with the
> following logs:
>
> (network_helpers.c:309: errno: Operation now in progress) \
> Failed to connect to server
> send_and_test_data:FAIL:connect to server unexpected error: -115
>
> This is due to SO_RCVTIMEO and SO_SNDTIMEO being set on the client
> socket (see settimeo() in client_socket()), allowing connect() to return
> an error and to set errno to EINPROGRESS instead of ETIMEDOUT.
> Increasing the timeout value for those tests is likely not a good
> solution (and it has already been done by commit 2790db208b44
> ("selftests/bpf: Improve tc_tunnel test reliability")): some tests
> expect some data transfer to fail, and so the timeout value would
> increase overall test execution duration again (not only the connection,
> but any socket operation).
>
> Another solution is to allocate a timeout budget specific to the
> connection: we can apply a larger timeout only for connections, and once
> the connection is established, set back the timeout configured through
> opts->timeout_ms; this would allow connection to succeed under heavy CI
> load, while keeping timeout reasonable for the rest of the test traffic.
>
> Set a larger SO_SNDTIMEO/SO_RCVTIMEO for the connection step, and reset
> it back to the timeout configured by the test once the connection has
> succeeded.
>
> Fixes: 99126abec5e5 ("bpf: selftests: A few improvements to network_helpers.c")
> Acked-by: Ihor Solodrai <ihor.solodrai@linux.dev>
> Signed-off-by: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
> ---
> tools/testing/selftests/bpf/network_helpers.c | 36 ++++++++++++++++++++++++---
> 1 file changed, 33 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
> index cdf2d7d3ab32..8c9236c0a5a5 100644
> --- a/tools/testing/selftests/bpf/network_helpers.c
> +++ b/tools/testing/selftests/bpf/network_helpers.c
> @@ -49,6 +49,8 @@
> errno = __save; \
> })
>
> +#define CONNECT_MIN_TIMEOUT_MS 5000
> +
> struct ipv4_packet pkt_v4 = {
> .eth.h_proto = __bpf_constant_htons(ETH_P_IP),
> .iph.ihl = 5,
> @@ -291,6 +293,12 @@ int client_socket(int family, int type,
> return -1;
> }
>
> +static int connect_timeout_ms(const struct network_helper_opts *opts)
> +{
> + /* Enforce a minimum connect timeout value */
> + return MAX(opts->timeout_ms, CONNECT_MIN_TIMEOUT_MS);
> +}
> +
> int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t addrlen,
> const struct network_helper_opts *opts)
> {
> @@ -305,13 +313,35 @@ int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add
> return -1;
> }
>
> + /*
> + * Override timeout configuration with a larger value for the
> + * connection
> + */
> + if (settimeo(fd, connect_timeout_ms(opts))) {
> + log_err("Failed to set connect timeout");
> + goto close;
> + }
> +
> if (connect(fd, (const struct sockaddr *)addr, addrlen)) {
> - log_err("Failed to connect to server");
> - save_errno_close(fd);
> - return -1;
> + log_err("Failed to connect");
> + goto close;
> + }
> +
> + /*
> + * If the timeout configured by the test is different from the
> + * connect timeout, restore it
> + */
> + if (opts->timeout_ms != CONNECT_MIN_TIMEOUT_MS &&
> + settimeo(fd, opts->timeout_ms)) {
> + log_err("Failed to set timeout for connected socket");
> + goto close;
> }
Could you do one last spin? I'll get the comment fix applied, but the above
still has issues as pointed out by sashiko, so maybe this could be reworked
as follows (untested):
diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index 8c9236c0a5a5..ec209a744889 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -293,10 +293,27 @@ int client_socket(int family, int type,
return -1;
}
-static int connect_timeout_ms(const struct network_helper_opts *opts)
+static int connect_with_timeout(int fd, const struct sockaddr_storage *addr,
+ socklen_t addrlen, int timeout_ms)
{
- /* Enforce a minimum connect timeout value */
- return MAX(opts->timeout_ms, CONNECT_MIN_TIMEOUT_MS);
+ int connect_timeout_ms = MAX(timeout_ms, CONNECT_MIN_TIMEOUT_MS);
+
+ if (settimeo(fd, connect_timeout_ms)) {
+ log_err("Failed to set connect timeout");
+ return -1;
+ }
+
+ if (connect(fd, (const struct sockaddr *)addr, addrlen)) {
+ log_err("Failed to connect to server");
+ return -1;
+ }
+
+ if (connect_timeout_ms != timeout_ms && settimeo(fd, timeout_ms)) {
+ log_err("Failed to restore timeout for connected socket");
+ return -1;
+ }
+
+ return 0;
}
int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t addrlen,
@@ -313,35 +330,12 @@ int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add
return -1;
}
- /*
- * Override timeout configuration with a larger value for the
- * connection
- */
- if (settimeo(fd, connect_timeout_ms(opts))) {
- log_err("Failed to set connect timeout");
- goto close;
- }
-
- if (connect(fd, (const struct sockaddr *)addr, addrlen)) {
- log_err("Failed to connect");
- goto close;
- }
-
- /*
- * If the timeout configured by the test is different from the
- * connect timeout, restore it
- */
- if (opts->timeout_ms != CONNECT_MIN_TIMEOUT_MS &&
- settimeo(fd, opts->timeout_ms)) {
- log_err("Failed to set timeout for connected socket");
- goto close;
+ if (connect_with_timeout(fd, addr, addrlen, opts->timeout_ms)) {
+ save_errno_close(fd);
+ return -1;
}
return fd;
-
-close:
- save_errno_close(fd);
- return -1;
}
int connect_to_addr_str(int family, int type, const char *addr_str, __u16 port,
@@ -406,20 +400,12 @@ int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms)
struct sockaddr_storage addr;
socklen_t len = sizeof(addr);
- if (settimeo(client_fd, timeout_ms))
- return -1;
-
if (getsockname(server_fd, (struct sockaddr *)&addr, &len)) {
log_err("Failed to get server addr");
return -1;
}
- if (connect(client_fd, (const struct sockaddr *)&addr, len)) {
- log_err("Failed to connect to server");
- return -1;
- }
-
- return 0;
+ return connect_with_timeout(client_fd, &addr, len, timeout_ms);
}
int make_sockaddr(int family, const char *addr_str, __u16 port,
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH bpf v5 2/2] selftests/bpf: allocate a larger timeout for connection
2026-08-17 8:55 ` Daniel Borkmann
@ 2026-08-17 9:55 ` Alexis Lothoré
0 siblings, 0 replies; 7+ messages in thread
From: Alexis Lothoré @ 2026-08-17 9:55 UTC (permalink / raw)
To: Daniel Borkmann, Alexis Lothoré (eBPF Foundation),
Alexei Starovoitov, Andrii Nakryiko, Eduard Zingerman,
Kumar Kartikeya Dwivedi, Martin KaFai Lau, Song Liu,
Yonghong Song, Jiri Olsa, Emil Tsalapatis, Shuah Khan,
Ihor Solodrai
Cc: ebpf, Bastien Curutchet, Thomas Petazzoni, bpf, linux-kselftest,
linux-kernel
Hi Daniel,
On Mon Aug 17, 2026 at 10:55 AM CEST, Daniel Borkmann wrote:
> Hi Alexis,
>
> On 8/14/26 9:11 AM, Alexis Lothoré (eBPF Foundation) wrote:
[...]
>> + /*
>> + * If the timeout configured by the test is different from the
>> + * connect timeout, restore it
>> + */
>> + if (opts->timeout_ms != CONNECT_MIN_TIMEOUT_MS &&
>> + settimeo(fd, opts->timeout_ms)) {
>> + log_err("Failed to set timeout for connected socket");
>> + goto close;
>> }
>
> Could you do one last spin? I'll get the comment fix applied, but the above
> still has issues as pointed out by sashiko, so maybe this could be reworked
> as follows (untested):
Sure, I was planning to respin today with fixes to issues raised by the
CI bot (wrong patch subject and mishandling of timeouts larger than the
default connect timeout). I'll send it later today.
Thanks,
Alexis
--
Alexis Lothoré, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-08-17 9:56 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-14 7:11 [PATCH bpf v5 0/2] selftest/bpf: make test_tc_tunnel and test_tc_edt more robust to CI load Alexis Lothoré (eBPF Foundation)
2026-08-14 7:11 ` [PATCH bpf v5 1/2] bpf/selftests: fix comment style in network_helpers.c Alexis Lothoré (eBPF Foundation)
2026-08-14 7:49 ` bot+bpf-ci
2026-08-14 7:11 ` [PATCH bpf v5 2/2] selftests/bpf: allocate a larger timeout for connection Alexis Lothoré (eBPF Foundation)
2026-08-14 7:49 ` bot+bpf-ci
2026-08-17 8:55 ` Daniel Borkmann
2026-08-17 9:55 ` Alexis Lothoré
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.