Skip to content

Commit 29a1320

Browse files
Paolo Abeniintel-lab-lkp
authored andcommitted
selftests: mptcp: avoid spurious errors on disconnect
The disconnect test-case generates spurious errors: NFO: disconnect INFO: extra options: -I 3 -i /tmp/tmp.r43niviyoI 01 ns1 MPTCP -> ns1 (10.0.1.1:10000 ) MPTCP Unexpected revents: POLLERR/POLLNVAL(19) (duration 140ms) [FAIL] file received by server does not match (in, out): -rw-r--r-- 1 root root 10028676 Jan 10 10:47 /tmp/tmp.r43niviyoI.disconnect Trailing bytes are: ��\����R���!8��u2��5N%w------- 1 root root 9992290 Jan 10 10:47 /tmp/tmp.Os4UbnWbI1 Trailing bytes are: ��\����R���!8��u2��5N%2 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 that 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") Signed-off-by: Paolo Abeni <[email protected]>
1 parent 508b5ff commit 29a1320

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

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

Lines changed: 33 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,43 @@ 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 ");
1237+
cmdlen = strlen(cmd);
1238+
if (!inet_ntop(addr.ss_family , raw_addr, &cmd[cmdlen],
1239+
sizeof(cmd) - cmdlen))
1240+
xerror("inet_ntop");
1241+
strcat(cmd, " >/dev/null");
12201242

12211243
shutdown(fd, SHUT_WR);
12221244

1223-
/* while until the pending data is completely flushed, the later
1245+
/*
1246+
* wait until the pending data is completely flushed and all
1247+
* the MPTCP sockets reached the closed status.
12241248
* disconnect will bypass/ignore/drop any pending data.
12251249
*/
12261250
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)
1251+
/* closed socket are not listed by 'ss' */
1252+
if (system(cmd))
12311253
break;
12321254

12331255
if (i > poll_timeout)
@@ -1281,9 +1303,9 @@ int main_loop(void)
12811303
return ret;
12821304

12831305
if (cfg_truncate > 0) {
1284-
xdisconnect(fd, peer->ai_addrlen);
1306+
xdisconnect(fd);
12851307
} else if (--cfg_repeat > 0) {
1286-
xdisconnect(fd, peer->ai_addrlen);
1308+
xdisconnect(fd);
12871309

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

0 commit comments

Comments
 (0)