selftests: mptcp: diag: use mptcp_lib_get_info_value
authorGeliang Tang <tanggeliang@kylinos.cn>
Mon, 21 Apr 2025 17:07:14 +0000 (19:07 +0200)
committerJakub Kicinski <kuba@kernel.org>
Wed, 23 Apr 2025 23:27:58 +0000 (16:27 -0700)
When running diag.sh in a loop, chk_dump_one will report the following
"grep: write error":

 13 ....chk 2 cestab                                  [ OK ]
 grep: write error
 14 ....chk dump_one                                  [ OK ]
 15 ....chk 2->0 msk in use after flush               [ OK ]
 16 ....chk 2->0 cestab after flush                   [ OK ]

This error is caused by a broken pipe. When the output of 'ss' is processed
by grep, 'head -n 1' will exit immediately after getting the first line,
causing the subsequent pipe to close. At this time, if 'grep' is still
trying to write data to the closed pipe, it will trigger a SIGPIPE signal,
causing a write error.

One solution is not to use this problematic "head -n 1" command, but to use
mptcp_lib_get_info_value() helper defined in mptcp_lib.sh to get the value
of 'token'.

Fixes: ba2400166570 ("selftests: mptcp: add a test for mptcp_diag_dump_one")
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Tested-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20250421-net-mptcp-pm-defer-freeing-v1-2-e731dc6e86b9@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/mptcp/diag.sh

index 4f55477ffe087721ad13774e82a5e2b1e6cec7c4..e7a75341f0f32304ff4e58c9b2500d405124dc74 100755 (executable)
@@ -206,9 +206,8 @@ chk_dump_one()
        local token
        local msg
 
-       ss_token="$(ss -inmHMN $ns | grep 'token:' |\
-                   head -n 1 |\
-                   sed 's/.*token:\([0-9a-f]*\).*/\1/')"
+       ss_token="$(ss -inmHMN $ns |
+                   mptcp_lib_get_info_value "token" "token")"
 
        token="$(ip netns exec $ns ./mptcp_diag -t $ss_token |\
                 awk -F':[ \t]+' '/^token/ {print $2}')"