Skip to contentSkip to conversation

selftests: mptcp: add tests for increasing

PATCH In review Gang Yan 3 participants 7 messages Feb 24, 2025

Subsystems (3)
lore
Share & tools
lore

Gang Yan

author
#0 lore raw

v4 cover selftests: mptcp: add tests for increasing

These patches provide a method to verify the 'mptcp_diag_dump_one' function, and the new tool 'mptcp_diag' can get the specific mptcp_info through multi msks.

Hi Matt:

Thank you for your suggestions regarding these patches, they have been very useful to me. Sorry for the misunderstanding caused by my misuse of the 'CLOSE' keyword. Currently, I have used the 'Link' instead. These patches are designed for 'mptcp_dump_one'.

There may need another test case for 'subflow_get_info_size'. I will continue to work on resolving this issue.

Best wishes!

Gang Yan (2):
selftests: mptcp: Add a tool to get specific msk_info
selftests: mptcp: add a test for mptcp_diag_dump_one

 tools/testing/selftests/net/mptcp/Makefile    |   2 +-
 tools/testing/selftests/net/mptcp/diag.sh     |  27 ++
 .../testing/selftests/net/mptcp/mptcp_diag.c  | 271 ++++++++++++++++++
 3 files changed, 299 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/net/mptcp/mptcp_diag.c
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v4 1/2 selftests: mptcp: Add a tool to get specific msk_info

This patch enables the retrieval of the mptcp_info structure corresponding to a specified MPTCP socket (msk). When multiple MPTCP connections are present, specific information can be obtained for a given connection through the 'mptcp_diag_dump_one' by using the 'token' associated with the msk.

---
Notes:
- v4:
- With reference to include/uapi/linux/mptcp.h, the structure members of mptcp_info have been supplemented.
- Improve the code style of 'print_info_msg'
- With reference to iproute2, make 'parse_nlmsg' compatible with older kernel versions.
- Check argc in 'parse_opts' to make sure '-t' is passed.

---
 tools/testing/selftests/net/mptcp/Makefile    |   2 +-
 .../testing/selftests/net/mptcp/mptcp_diag.c  | 271 ++++++++++++++++++
 2 files changed, 272 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/net/mptcp/mptcp_diag.c
tools/testing/selftests/net/mptcp/Makefile +1 -1
index c76525fe2b84..340e1a777e16 100644
@@ -7,7 +7,7 @@ CFLAGS += -Wall -Wl,--no-as-needed -O2 -g -I$(top_srcdir)/usr/include $(KHDR_INC
 TEST_PROGS := mptcp_connect.sh pm_netlink.sh mptcp_join.sh diag.sh \
 	      simult_flows.sh mptcp_sockopt.sh userspace_pm.sh
 
-TEST_GEN_FILES = mptcp_connect pm_nl_ctl mptcp_sockopt mptcp_inq
+TEST_GEN_FILES = mptcp_connect pm_nl_ctl mptcp_sockopt mptcp_inq mptcp_diag
 
 TEST_FILES := mptcp_lib.sh settings
 
tools/testing/selftests/net/mptcp/mptcp_diag.c new file +271 -0

271 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#3 lore raw

PATCH v4 2/2 selftests: mptcp: add a test for mptcp_diag_dump_one

In reply to Gang Yan

This patch introduces a new 'chk_diag' test in diag.sh. It retrieves the token for a specified MPTCP socket (msk) using the 'ss' command and then accesses the 'mptcp_diag_dump_one' in kernel via ./mptcp_diag to verify if the correct token is returned.

---
Notes:
- v4:
- Optimized the check logic for 'ss_token' and 'token′, and before that,first check if 'ss_token' is empty.

---
 tools/testing/selftests/net/mptcp/diag.sh | 27 +++++++++++++++++++++++
 1 file changed, 27 insertions(+)
tools/testing/selftests/net/mptcp/diag.sh +27 -0
index 2bd0c1eb70c5..4f55477ffe08 100755
@@ -200,6 +200,32 @@ chk_msk_cestab()
 		 "${expected}" "${msg}" ""
 }
 
+chk_dump_one()
+{
+	local ss_token
+	local token
+	local msg
+
+	ss_token="$(ss -inmHMN $ns | grep 'token:' |\
+		    head -n 1 |\
+		    sed 's/.*token:\([0-9a-f]*\).*/\1/')"
+
+	token="$(ip netns exec $ns ./mptcp_diag -t $ss_token |\
+		 awk -F':[ \t]+' '/^token/ {print $2}')"
+
+	msg="....chk dump_one"
+
+	mptcp_lib_print_title "$msg"
+	if [ -n "$ss_token" ] && [ "$ss_token" = "$token" ]; then
+		mptcp_lib_pr_ok
+		mptcp_lib_result_pass "${msg}"
+	else
+		mptcp_lib_pr_fail "expected $ss_token found $token"
+		mptcp_lib_result_fail "${msg}"
+		ret=${KSFT_FAIL}
+	fi
+}
+
 msk_info_get_value()
 {
 	local port="${1}"
@@ -290,6 +316,7 @@ chk_msk_remote_key_nr 2 "....chk remote_key"
 chk_msk_fallback_nr 0 "....chk no fallback"
 chk_msk_inuse 2
 chk_msk_cestab 2
+chk_dump_one
 flush_pids
 
 chk_msk_inuse 0 "2->0"
Signature · 1 line
2.43.0
#4 lore raw
In reply to Gang Yan

Hi Gang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/13494531915

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/07791475cb37
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=936949

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)

maintainer Reviewed-by on the v4 series
#5 lore raw
In reply to Gang Yan

Hi Gang Yan,

Quoted 3 lines · Gang Yan

These patches provide a method to verify the 'mptcp_diag_dump_one' function, and the new tool 'mptcp_diag' can get the specific mptcp_info through multi msks.

Thank you for the update.

It looks good to me, just 2 small comments, but I can do the modifications when applying the patches, no need to send a v5 just for that.

Quoted 9 lines

Hi Matt:

Thank you for your suggestions regarding these patches, they have been very useful to me. Sorry for the misunderstanding caused by my misuse of the 'CLOSE' keyword. Currently, I have used the 'Link' instead. These patches are designed for 'mptcp_dump_one'.

There may need another test case for 'subflow_get_info_size'. I will continue to work on resolving this issue.

OK, Great!

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
maintainer
#2 lore raw

Re: [mptcp-next v4 1/2] selftests: mptcp: Add a tool to get specific msk_info

In reply to Gang Yan

Hi Gang Yan,

Quoted 5 lines · Gang Yan

This patch enables the retrieval of the mptcp_info structure corresponding to a specified MPTCP socket (msk). When multiple MPTCP connections are present, specific information can be obtained for a given connection through the 'mptcp_diag_dump_one' by using the 'token' associated with the msk.

(...)

Quoted 42 lines
tools/testing/selftests/net/mptcp/mptcp_diag.c new file +36 -0
new file mode 100644
index 000000000000..6dc53ab867c5
@@ -0,0 +1,271 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2025, Kylin Software */
+
+#include <linux/sock_diag.h>
+#include <linux/rtnetlink.h>
+#include <linux/inet_diag.h>
+#include <linux/netlink.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <linux/tcp.h>
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+
+#ifndef IPPROTO_MPTCP
+#define IPPROTO_MPTCP 262
+#endif
+
+struct mptcp_info {
+	__u8    mptcpi_subflows;
+	__u8    mptcpi_add_addr_signal;
+	__u8    mptcpi_add_addr_accepted;
+	__u8    mptcpi_subflows_max;
+	__u8    mptcpi_add_addr_signal_max;
+	__u8    mptcpi_add_addr_accepted_max;
+	__u32   mptcpi_flags;
+	__u32   mptcpi_token;
+	__u64   mptcpi_write_seq;
+	__u64   mptcpi_snd_una;
+	__u64   mptcpi_rcv_nxt;
+	__u8    mptcpi_local_addr_used;
+	__u8    mptcpi_local_addr_max;
+	__u8    mptcpi_csum_enabled;

tools/testing/selftests/net/mptcp/mptcp_diag.c line 46

Quoted 10 lines
tools/testing/selftests/net/mptcp/mptcp_diag.c new file +10 -0
+	__u32   mptcpi_retransmits;
+	__u64   mptcpi_bytes_retrans;
+	__u64   mptcpi_bytes_sent;
+	__u64   mptcpi_bytes_received;
+	__u64   mptcpi_bytes_acked;
+	__u8	mptcpi_subflows_total;
+	__u8	reserved[3];
+	__u32	mptcpi_last_data_sent;
+	__u32	mptcpi_last_data_recv;
+	__u32	mptcpi_last_ack_recv;

Small detail: some fields are aligned with spaces, others with tabs. Can you pick only one please? tabs?

(...)

Quoted 20 lines
tools/testing/selftests/net/mptcp/mptcp_diag.c new file +20 -0
+static void print_info_msg(struct mptcp_info *info)
+{
+	printf("Token & Flags\n");
+	printf("token:	       %x\n", info->mptcpi_token);
+	printf("flags:	       %x\n", info->mptcpi_flags);
+	printf("csum_enabled:  %u\n", info->mptcpi_csum_enabled);
+
+	printf("\nBasic Info\n");
+	printf("subflows:		%u\n", info->mptcpi_subflows);
+	printf("subflows_max:		%u\n", info->mptcpi_subflows_max);
+	printf("subflows_total:		%u\n", info->mptcpi_subflows_total);
+	printf("local_addr_used:	%u\n", info->mptcpi_local_addr_used);
+	printf("local_addr_max:		%u\n", info->mptcpi_local_addr_max);
+	printf("add_addr_signal:	%u\n", info->mptcpi_add_addr_signal);
+	printf("add_addr_accepted:	%u\n", info->mptcpi_add_addr_accepted);
+	printf("add_addr_signal_max:	%u\n", info->mptcpi_add_addr_signal_max);
+	printf("add_addr_accepted_max:	%u\n", info->mptcpi_add_addr_accepted_max);
+
+	printf("\nTransmission Info\n");
+	printf("write_seq:	  %llx\n", info->mptcpi_write_seq);

tools/testing/selftests/net/mptcp/mptcp_diag.c line 159

Quoted 10 lines
tools/testing/selftests/net/mptcp/mptcp_diag.c new file +10 -0
+	printf("snd_una:	  %llx\n", info->mptcpi_snd_una);
+	printf("rcv_nxt:	  %llx\n", info->mptcpi_rcv_nxt);
+	printf("last_data_sent:	  %x\n", info->mptcpi_last_data_sent);
+	printf("last_data_recv:	  %x\n", info->mptcpi_last_data_recv);
+	printf("last_ack_recv:	  %x\n", info->mptcpi_last_ack_recv);
+	printf("retransmits:	  %u\n", info->mptcpi_retransmits);
+	printf("retransmit bytes: %llu\n", info->mptcpi_bytes_retrans);
+	printf("bytes_sent:	  %llu\n", info->mptcpi_bytes_sent);
+	printf("bytes_received:   %llu\n", info->mptcpi_bytes_received);
+	printf("bytes_acked:	  %llu\n", info->mptcpi_bytes_acked);

Small detail: probably best to do the alignment only with spaces and not a mix of both because I don't think it would look nice depending on how the tabs are being printed.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
maintainer
#6 lore raw
In reply to Matthieu Baerts
Quoted 7 lines · Matthieu Baerts

Hi Gang Yan,

Quoted 3 lines · Gang Yan

These patches provide a method to verify the 'mptcp_diag_dump_one' function, and the new tool 'mptcp_diag' can get the specific mptcp_info through multi msks.

Quoted 6 lines

Thank you for the update.

It looks good to me, just 2 small comments, but I can do the modifications when applying the patches, no need to send a v5 just for that.

Now in our tree:

New patches for t/upstream:
- 07774a3ae41c: selftests: mptcp: Add a tool to get specific msk_info
- 24f7b212d821: selftests: mptcp: add a test for mptcp_diag_dump_one
- Results: 192ee51a45e8..3716d837622e (export)

Tests are now in progress:

- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/e839bf51efe24a9e4f30676f620777d253e6add3/checks

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.