* [PATCH mptcp-next v2] selftests: mptcp: print stats before socket closure
@ 2026-08-14 18:34 Matthieu Baerts (NGI0)
2026-08-14 18:44 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-08-14 18:34 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
In case of poll timeout, it might be too late to print the stats after
the socket closure.
Now, in case of poll timeout, 'ss' and 'nstat' are invoked from
mptcp_connect to print the stats before exiting. This should help
debugging poll timeout issues.
Note: for this "workaround", system() is used for debugging purposes
only. The returned result can then be safely ignored, hence the (void)!
to avoid unused-result warnings.
Also, 'nstat *Tcp*' will print '#kernel' at the top, but that's OK, and
it seems better to avoid using a pipe here.
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Changes in v2:
- use 'ip netns identify' to avoid a warning from AI reviews
- use 'nstat -s *Tcp*' instead of using grep
- add a note about (void)!
- Link to v1: https://patch.msgid.link/20260814-sft-mptcp-stats-b4-close-v1-1-2945a591be7e@kernel.org
---
tools/testing/selftests/net/mptcp/mptcp_connect.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c
index ea4cb6c1bd5e..e906abcd5409 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
@@ -210,6 +210,19 @@ static void xgetaddrinfo(const char *node, const char *service,
}
}
+static void print_err_stats(void)
+{
+ char cmd[128];
+
+ snprintf(cmd, sizeof(cmd), "ss -Menitam -o '%cport = :%s' >&2",
+ listen_mode ? 's' : 'd', cfg_port);
+
+ fprintf(stderr, "socket stats before socket closure:\n");
+ (void)!system(cmd);
+ (void)!system("NSTAT_HISTORY='/tmp/$(ip netns identify).nstat' "
+ "nstat -s '*Tcp*' >&2");
+}
+
static void set_rcvbuf(int fd, unsigned int size)
{
int err;
@@ -656,6 +669,7 @@ static int copyfd_io_poll(int infd, int peerfd, int outfd,
fprintf(stderr, "%s: poll timed out (events: "
"POLLIN %u, POLLOUT %u)\n", __func__,
fds.events & POLLIN, fds.events & POLLOUT);
+ print_err_stats();
return 2;
}
@@ -1194,6 +1208,7 @@ int main_loop_s(int listensock)
return 1;
case 0:
fprintf(stderr, "%s: timed out\n", __func__);
+ print_err_stats();
close(listensock);
return 2;
}
---
base-commit: d536472a82d18356d323227213acb5603bb9050c
change-id: 20260814-sft-mptcp-stats-b4-close-20964ff6a6ba
Best regards,
--
Matthieu Baerts (NGI0) <matttbe@kernel.org>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH mptcp-next v2] selftests: mptcp: print stats before socket closure
2026-08-14 18:34 [PATCH mptcp-next v2] selftests: mptcp: print stats before socket closure Matthieu Baerts (NGI0)
@ 2026-08-14 18:44 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-08-14 18:44 UTC (permalink / raw)
To: Matthieu Baerts (NGI0); +Cc: mptcp
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Shell command substitution inside single quotes prevents evaluation in system() call
--
--- Patch [1]: [PATCH mptcp-next v2] selftests: mptcp: print stats before socket closure ---
commit 3f1a40cd885883e270f0fd3544c47bf2dc166581
Author: Matthieu Baerts (NGI0) <matttbe@kernel.org>
selftests: mptcp: print stats before socket closure
In case of a poll timeout, this commit invokes 'ss' and 'nstat' via
system() to print debug stats before exiting mptcp_connect.
Link: https://patch.msgid.link/20260814-sft-mptcp-stats-b4-close-v1-1-2945a591be7e@kernel.org
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c
> index ea4cb6c1bd5e2..e906abcd54096 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
> +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
> @@ -210,6 +210,19 @@ static void xgetaddrinfo(const char *node, const char *service,
> }
> }
>
> +static void print_err_stats(void)
> +{
> + char cmd[128];
> +
> + snprintf(cmd, sizeof(cmd), "ss -Menitam -o '%cport = :%s' >&2",
> + listen_mode ? 's' : 'd', cfg_port);
> +
> + fprintf(stderr, "socket stats before socket closure:\n");
> + (void)!system(cmd);
> + (void)!system("NSTAT_HISTORY='/tmp/$(ip netns identify).nstat' "
> + "nstat -s '*Tcp*' >&2");
[Severity: Medium]
Will this shell command substitution be evaluated properly?
Because the path is enclosed in single quotes, it appears NSTAT_HISTORY
will be set to the literal string '/tmp/$(ip netns identify).nstat' instead
of being evaluated by the shell.
If the shell does not evaluate the command substitution, could this cause
nstat to look for a non-existent history file and print absolute stats
instead of the expected differential stats?
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260814-sft-mptcp-stats-b4-close-v2-1-b7a8ab3ddae8@kernel.org?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-14 18:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-14 18:34 [PATCH mptcp-next v2] selftests: mptcp: print stats before socket closure Matthieu Baerts (NGI0)
2026-08-14 18:44 ` sashiko-bot
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.