Message ID | abe63ed463788d59150d7fbf04f6975821f66d08.1722502941.git.tanggeliang@kylinos.cn (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Matthieu Baerts |
Headers | show |
Series | add io thread mode tests | expand |
Context | Check | Description |
---|---|---|
matttbe/build | success | Build and static analysis OK |
matttbe/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 63 lines checked |
matttbe/shellcheck | success | MPTCP selftests files have not been modified |
matttbe/KVM_Validation__normal | success | Success! ✅ |
matttbe/KVM_Validation__debug | warning | Unstable: 2 failed test(s): mptcp_connect_mmap selftest_mptcp_join |
matttbe/KVM_Validation__btf__only_bpftest_all_ | success | Success! ✅ |
Hi Geliang, On 01/08/2024 11:21, Geliang Tang wrote: > From: Geliang Tang <tanggeliang@kylinos.cn> > > This patch adds a new helper settimeo(), which comes from BPF selftests > network_helpers.c, into MPTCP selftests tool mptcp_connect, to set > SO_RCVTIMEO and SO_SNDTIMEO options of the given socket. Can you add a (very) brief description explaining *why* it is interesting to set these options in our tests? (e.g. mention why the 'timeout' command we use when launching 'mptcp_connect' is not enough) > Add a new mptcp_connect option "-O" to pass a timeout value and a new > cfg cfg_timeo to store this value. Please also update the 'usage()' helper with this new option. > Invoke this new helper in sock_connect_mptcp() when cfg_timeo is set. Cheers, Matt
diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c index 4209b9569039..ce261a4bb324 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c @@ -75,6 +75,7 @@ static char *cfg_input; static int cfg_repeat = 1; static int cfg_truncate; static int cfg_rcv_trunc; +static int cfg_timeo; struct cfg_cmsg_types { unsigned int cmsg_enabled:1; @@ -249,6 +250,30 @@ static void set_mptfo(int fd, int pf) perror("TCP_FASTOPEN"); } +static int settimeo(int fd, int timeout_ms) +{ + struct timeval timeout = { .tv_sec = 3 }; + + if (timeout_ms > 0) { + timeout.tv_sec = timeout_ms / 1000; + timeout.tv_usec = (timeout_ms % 1000) * 1000; + } + + if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, + sizeof(timeout))) { + perror("set SO_RCVTIMEO"); + return -1; + } + + if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &timeout, + sizeof(timeout))) { + perror("set SO_SNDTIMEO"); + return -1; + } + + return 0; +} + static int do_ulp_so(int sock, const char *name) { return setsockopt(sock, IPPROTO_TCP, TCP_ULP, name, strlen(name)); @@ -376,6 +401,9 @@ static int sock_connect_mptcp(const char * const remoteaddr, if (cfg_mark) set_mark(sock, cfg_mark); + if (cfg_timeo) + settimeo(sock, cfg_timeo); + if (cfg_sockopt_types.mptfo) { if (!winfo->total_len) winfo->total_len = winfo->len = read(infd, winfo->buf, @@ -1384,7 +1412,7 @@ static void parse_opts(int argc, char **argv) { int c; - while ((c = getopt(argc, argv, "6c:f:hi:I:jlm:M:o:p:P:r:R:s:S:t:T:w:")) != -1) { + while ((c = getopt(argc, argv, "6c:f:hi:I:jlm:M:o:p:P:r:R:s:S:t:T:w:O:")) != -1) { switch (c) { case 'f': cfg_truncate = atoi(optarg); @@ -1462,6 +1490,9 @@ static void parse_opts(int argc, char **argv) case 'o': parse_setsock_options(optarg); break; + case 'O': + cfg_timeo = strtol(optarg, NULL, 0); + break; } }