Skip to content

Commit 218cc16

Browse files
Paolo Abenikuba-moo
authored andcommitted
selftests: mptcp: avoid spurious errors on disconnect
The disconnect test-case generates spurious errors: INFO: disconnect INFO: extra options: -I 3 -i /tmp/tmp.r43niviyoI 01 ns1 MPTCP -> ns1 (10.0.1.1:10000 ) MPTCP (duration 140ms) [FAIL] file received by server does not match (in, out): Unexpected revents: POLLERR/POLLNVAL(19) -rw-r--r-- 1 root root 10028676 Jan 10 10:47 /tmp/tmp.r43niviyoI.disconnect Trailing bytes are: ��\����R���!8��u2��5N% -rw------- 1 root root 9992290 Jan 10 10:47 /tmp/tmp.Os4UbnWbI1 Trailing bytes are: ��\����R���!8��u2��5N% 02 ns1 MPTCP -> ns1 (dead:beef:1::1:10001) MPTCP (duration 206ms) [ OK ] 03 ns1 MPTCP -> ns1 (dead:beef:1::1:10002) TCP (duration 31ms) [ OK ] 04 ns1 TCP -> ns1 (dead:beef:1::1:10003) MPTCP (duration 26ms) [ OK ] [FAIL] Tests of the full disconnection have failed Time: 2 seconds The root cause is actually in the user-space bits: the test program currently disconnects as soon as all the pending data has been spooled, generating an FASTCLOSE. If such option reaches the peer before the latter has reached the closed status, the msk socket will report an error to the user-space, as per protocol specification, causing the above failure. Address the issue explicitly waiting for all the relevant sockets to reach a closed status before performing the disconnect. Fixes: 05be5e2 ("selftests: mptcp: add disconnect tests") Cc: [email protected] Signed-off-by: Paolo Abeni <[email protected]> Reviewed-by: Matthieu Baerts (NGI0) <[email protected]> Signed-off-by: Matthieu Baerts (NGI0) <[email protected]> Link: https://patch.msgid.link/20250113-net-mptcp-connect-st-flakes-v1-3-0d986ee7b1b6@kernel.org Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e226d92 commit 218cc16

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

tools/testing/selftests/net/mptcp/mptcp_connect.c

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <sys/types.h>
2626
#include <sys/mman.h>
2727

28+
#include <arpa/inet.h>
29+
2830
#include <netdb.h>
2931
#include <netinet/in.h>
3032

@@ -1211,23 +1213,42 @@ static void parse_setsock_options(const char *name)
12111213
exit(1);
12121214
}
12131215

1214-
void xdisconnect(int fd, int addrlen)
1216+
void xdisconnect(int fd)
12151217
{
1216-
struct sockaddr_storage empty;
1218+
socklen_t addrlen = sizeof(struct sockaddr_storage);
1219+
struct sockaddr_storage addr, empty;
12171220
int msec_sleep = 10;
1218-
int queued = 1;
1219-
int i;
1221+
void *raw_addr;
1222+
int i, cmdlen;
1223+
char cmd[128];
1224+
1225+
/* get the local address and convert it to string */
1226+
if (getsockname(fd, (struct sockaddr *)&addr, &addrlen) < 0)
1227+
xerror("getsockname");
1228+
1229+
if (addr.ss_family == AF_INET)
1230+
raw_addr = &(((struct sockaddr_in *)&addr)->sin_addr);
1231+
else if (addr.ss_family == AF_INET6)
1232+
raw_addr = &(((struct sockaddr_in6 *)&addr)->sin6_addr);
1233+
else
1234+
xerror("bad family");
1235+
1236+
strcpy(cmd, "ss -M | grep -q ");
1237+
cmdlen = strlen(cmd);
1238+
if (!inet_ntop(addr.ss_family, raw_addr, &cmd[cmdlen],
1239+
sizeof(cmd) - cmdlen))
1240+
xerror("inet_ntop");
12201241

12211242
shutdown(fd, SHUT_WR);
12221243

1223-
/* while until the pending data is completely flushed, the later
1244+
/*
1245+
* wait until the pending data is completely flushed and all
1246+
* the MPTCP sockets reached the closed status.
12241247
* disconnect will bypass/ignore/drop any pending data.
12251248
*/
12261249
for (i = 0; ; i += msec_sleep) {
1227-
if (ioctl(fd, SIOCOUTQ, &queued) < 0)
1228-
xerror("can't query out socket queue: %d", errno);
1229-
1230-
if (!queued)
1250+
/* closed socket are not listed by 'ss' */
1251+
if (system(cmd) != 0)
12311252
break;
12321253

12331254
if (i > poll_timeout)
@@ -1281,9 +1302,9 @@ int main_loop(void)
12811302
return ret;
12821303

12831304
if (cfg_truncate > 0) {
1284-
xdisconnect(fd, peer->ai_addrlen);
1305+
xdisconnect(fd);
12851306
} else if (--cfg_repeat > 0) {
1286-
xdisconnect(fd, peer->ai_addrlen);
1307+
xdisconnect(fd);
12871308

12881309
/* the socket could be unblocking at this point, we need the
12891310
* connect to be blocking

0 commit comments

Comments
 (0)