1 | These patches provide a method to verify the 'mptcp_diag_dump_one' | 1 | These patches provide a method to verify the 'mptcp_diag_dump_one' |
---|---|---|---|
2 | function, and the new tool 'mptcp_diag' can get the specific mptcp_info | 2 | function, and the new tool 'mptcp_diag' can get the specific mptcp_info |
3 | through multi msks. | 3 | through multi msks. |
4 | |||
5 | Hi Matt: | ||
6 | |||
7 | Thank you for your suggestions regarding these patches, they have been | ||
8 | very useful to me. Sorry for the misunderstanding caused by my misuse of | ||
9 | the 'CLOSE' keyword. Currently, I have used the 'Link' instead. These | ||
10 | patches are designed for 'mptcp_dump_one'. | ||
11 | |||
12 | There may need another test case for 'subflow_get_info_size'. I will | ||
13 | continue to work on resolving this issue. | ||
14 | |||
15 | Best wishes! | ||
4 | 16 | ||
5 | Gang Yan (2): | 17 | Gang Yan (2): |
6 | selftests: mptcp: Add a tool to get specific msk_info | 18 | selftests: mptcp: Add a tool to get specific msk_info |
7 | selftests: mptcp: add a test for mptcp_diag_dump_one | 19 | selftests: mptcp: add a test for mptcp_diag_dump_one |
8 | 20 | ||
9 | tools/testing/selftests/net/mptcp/Makefile | 2 +- | 21 | tools/testing/selftests/net/mptcp/Makefile | 2 +- |
10 | tools/testing/selftests/net/mptcp/diag.sh | 27 ++ | 22 | tools/testing/selftests/net/mptcp/diag.sh | 27 ++ |
11 | .../testing/selftests/net/mptcp/mptcp_diag.c | 258 ++++++++++++++++++ | 23 | .../testing/selftests/net/mptcp/mptcp_diag.c | 271 ++++++++++++++++++ |
12 | 3 files changed, 286 insertions(+), 1 deletion(-) | 24 | 3 files changed, 299 insertions(+), 1 deletion(-) |
13 | create mode 100644 tools/testing/selftests/net/mptcp/mptcp_diag.c | 25 | create mode 100644 tools/testing/selftests/net/mptcp/mptcp_diag.c |
14 | 26 | ||
15 | -- | 27 | -- |
16 | 2.25.1 | 28 | 2.43.0 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
3 | present, specific information can be obtained for a given connection | 3 | present, specific information can be obtained for a given connection |
4 | through the 'mptcp_diag_dump_one' by using the 'token' associated with | 4 | through the 'mptcp_diag_dump_one' by using the 'token' associated with |
5 | the msk. | 5 | the msk. |
6 | 6 | ||
7 | Signed-off-by: Gang Yan <yangang@kylinos.cn> | 7 | Signed-off-by: Gang Yan <yangang@kylinos.cn> |
8 | |||
9 | --- | ||
10 | Notes: | ||
11 | - v4: | ||
12 | - With reference to include/uapi/linux/mptcp.h, the structure members | ||
13 | of mptcp_info have been supplemented. | ||
14 | - Improve the code style of 'print_info_msg' | ||
15 | - With reference to iproute2, make 'parse_nlmsg' compatible with older | ||
16 | kernel versions. | ||
17 | - Check argc in 'parse_opts' to make sure '-t' is passed. | ||
8 | --- | 18 | --- |
9 | tools/testing/selftests/net/mptcp/Makefile | 2 +- | 19 | tools/testing/selftests/net/mptcp/Makefile | 2 +- |
10 | .../testing/selftests/net/mptcp/mptcp_diag.c | 258 ++++++++++++++++++ | 20 | .../testing/selftests/net/mptcp/mptcp_diag.c | 271 ++++++++++++++++++ |
11 | 2 files changed, 259 insertions(+), 1 deletion(-) | 21 | 2 files changed, 272 insertions(+), 1 deletion(-) |
12 | create mode 100644 tools/testing/selftests/net/mptcp/mptcp_diag.c | 22 | create mode 100644 tools/testing/selftests/net/mptcp/mptcp_diag.c |
13 | 23 | ||
14 | diff --git a/tools/testing/selftests/net/mptcp/Makefile b/tools/testing/selftests/net/mptcp/Makefile | 24 | diff --git a/tools/testing/selftests/net/mptcp/Makefile b/tools/testing/selftests/net/mptcp/Makefile |
15 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/tools/testing/selftests/net/mptcp/Makefile | 26 | --- a/tools/testing/selftests/net/mptcp/Makefile |
... | ... | ||
49 | + | 59 | + |
50 | +#ifndef IPPROTO_MPTCP | 60 | +#ifndef IPPROTO_MPTCP |
51 | +#define IPPROTO_MPTCP 262 | 61 | +#define IPPROTO_MPTCP 262 |
52 | +#endif | 62 | +#endif |
53 | + | 63 | + |
54 | +#ifndef MPTCP_INFO | ||
55 | +struct mptcp_info { | 64 | +struct mptcp_info { |
56 | + __u8 mptcpi_subflows; | 65 | + __u8 mptcpi_subflows; |
57 | + __u8 mptcpi_add_addr_signal; | 66 | + __u8 mptcpi_add_addr_signal; |
58 | + __u8 mptcpi_add_addr_accepted; | 67 | + __u8 mptcpi_add_addr_accepted; |
59 | + __u8 mptcpi_subflows_max; | 68 | + __u8 mptcpi_subflows_max; |
... | ... | ||
70 | + __u32 mptcpi_retransmits; | 79 | + __u32 mptcpi_retransmits; |
71 | + __u64 mptcpi_bytes_retrans; | 80 | + __u64 mptcpi_bytes_retrans; |
72 | + __u64 mptcpi_bytes_sent; | 81 | + __u64 mptcpi_bytes_sent; |
73 | + __u64 mptcpi_bytes_received; | 82 | + __u64 mptcpi_bytes_received; |
74 | + __u64 mptcpi_bytes_acked; | 83 | + __u64 mptcpi_bytes_acked; |
84 | + __u8 mptcpi_subflows_total; | ||
85 | + __u8 reserved[3]; | ||
86 | + __u32 mptcpi_last_data_sent; | ||
87 | + __u32 mptcpi_last_data_recv; | ||
88 | + __u32 mptcpi_last_ack_recv; | ||
75 | +}; | 89 | +}; |
76 | + | ||
77 | +#define MPTCP_INFO 1 | ||
78 | +#endif | ||
79 | + | 90 | + |
80 | +static void die_perror(const char *msg) | 91 | +static void die_perror(const char *msg) |
81 | +{ | 92 | +{ |
82 | + perror(msg); | 93 | + perror(msg); |
83 | + exit(1); | 94 | + exit(1); |
... | ... | ||
164 | + printf("token: %x\n", info->mptcpi_token); | 175 | + printf("token: %x\n", info->mptcpi_token); |
165 | + printf("flags: %x\n", info->mptcpi_flags); | 176 | + printf("flags: %x\n", info->mptcpi_flags); |
166 | + printf("csum_enabled: %u\n", info->mptcpi_csum_enabled); | 177 | + printf("csum_enabled: %u\n", info->mptcpi_csum_enabled); |
167 | + | 178 | + |
168 | + printf("\nBasic Info\n"); | 179 | + printf("\nBasic Info\n"); |
169 | + printf("subflows: %-5u subflows_max: %u\n", | 180 | + printf("subflows: %u\n", info->mptcpi_subflows); |
170 | + info->mptcpi_subflows, | 181 | + printf("subflows_max: %u\n", info->mptcpi_subflows_max); |
171 | + info->mptcpi_subflows_max); | 182 | + printf("subflows_total: %u\n", info->mptcpi_subflows_total); |
172 | + printf("local_addr_used: %-5u local_addr_max: %u\n", | 183 | + printf("local_addr_used: %u\n", info->mptcpi_local_addr_used); |
173 | + info->mptcpi_local_addr_used, | 184 | + printf("local_addr_max: %u\n", info->mptcpi_local_addr_max); |
174 | + info->mptcpi_local_addr_max); | 185 | + printf("add_addr_signal: %u\n", info->mptcpi_add_addr_signal); |
175 | + printf("add_addr_signal: %-5u add_addr_accepted: %u\n", | 186 | + printf("add_addr_accepted: %u\n", info->mptcpi_add_addr_accepted); |
176 | + info->mptcpi_add_addr_signal, | 187 | + printf("add_addr_signal_max: %u\n", info->mptcpi_add_addr_signal_max); |
177 | + info->mptcpi_add_addr_accepted); | 188 | + printf("add_addr_accepted_max: %u\n", info->mptcpi_add_addr_accepted_max); |
178 | + printf("add_addr_signal_max: %-5u add_addr_accepted_max: %u\n", | ||
179 | + info->mptcpi_add_addr_signal_max, | ||
180 | + info->mptcpi_add_addr_accepted_max); | ||
181 | + | 189 | + |
182 | + printf("\nTransmission Info\n"); | 190 | + printf("\nTransmission Info\n"); |
183 | + printf("write_seq: %llx\n", info->mptcpi_write_seq); | 191 | + printf("write_seq: %llx\n", info->mptcpi_write_seq); |
184 | + printf("snd_una: %llx\n", info->mptcpi_snd_una); | 192 | + printf("snd_una: %llx\n", info->mptcpi_snd_una); |
185 | + printf("rcv_nxt: %llx\n", info->mptcpi_rcv_nxt); | 193 | + printf("rcv_nxt: %llx\n", info->mptcpi_rcv_nxt); |
194 | + printf("last_data_sent: %x\n", info->mptcpi_last_data_sent); | ||
195 | + printf("last_data_recv: %x\n", info->mptcpi_last_data_recv); | ||
196 | + printf("last_ack_recv: %x\n", info->mptcpi_last_ack_recv); | ||
186 | + printf("retransmits: %u\n", info->mptcpi_retransmits); | 197 | + printf("retransmits: %u\n", info->mptcpi_retransmits); |
187 | + printf("retransmit bytes: %llu\n", info->mptcpi_bytes_retrans); | 198 | + printf("retransmit bytes: %llu\n", info->mptcpi_bytes_retrans); |
188 | + printf("bytes_sent: %llu\n", info->mptcpi_bytes_sent); | 199 | + printf("bytes_sent: %llu\n", info->mptcpi_bytes_sent); |
189 | + printf("bytes_received: %llu\n", info->mptcpi_bytes_received); | 200 | + printf("bytes_received: %llu\n", info->mptcpi_bytes_received); |
190 | + printf("bytes_acked: %llu\n", info->mptcpi_bytes_acked); | 201 | + printf("bytes_acked: %llu\n", info->mptcpi_bytes_acked); |
191 | +} | 202 | +} |
192 | + | 203 | + |
193 | +static void parse_nlmsg(struct nlmsghdr *nlh) | 204 | +static void parse_nlmsg(struct nlmsghdr *nlh) |
194 | +{ | 205 | +{ |
195 | + struct inet_diag_msg *r = NLMSG_DATA(nlh); | 206 | + struct inet_diag_msg *r = NLMSG_DATA(nlh); |
196 | + struct rtattr *tb[INET_DIAG_MAX + 1]; | 207 | + struct rtattr *tb[INET_DIAG_MAX + 1]; |
197 | + struct mptcp_info *info; | ||
198 | + | 208 | + |
199 | + parse_rtattr_flags(tb, INET_DIAG_MAX, (struct rtattr *)(r + 1), | 209 | + parse_rtattr_flags(tb, INET_DIAG_MAX, (struct rtattr *)(r + 1), |
200 | + nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)), | 210 | + nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)), |
201 | + NLA_F_NESTED); | 211 | + NLA_F_NESTED); |
202 | + | 212 | + |
203 | + if (tb[INET_DIAG_INFO]) { | 213 | + if (tb[INET_DIAG_INFO]) { |
204 | + info = RTA_DATA(tb[INET_DIAG_INFO]); | 214 | + struct mptcp_info *info; |
215 | + int len; | ||
216 | + | ||
217 | + len = RTA_PAYLOAD(tb[INET_DIAG_INFO]); | ||
218 | + /* workaround fort older kernels with less fields */ | ||
219 | + if (len < sizeof(*info)) { | ||
220 | + info = alloca(sizeof(*info)); | ||
221 | + memcpy(info, RTA_DATA(tb[INET_DIAG_INFO]), len); | ||
222 | + memset((char *)info + len, 0, sizeof(*info) - len); | ||
223 | + } else | ||
224 | + info = RTA_DATA(tb[INET_DIAG_INFO]); | ||
205 | + print_info_msg(info); | 225 | + print_info_msg(info); |
206 | + } | 226 | + } |
207 | +} | 227 | +} |
208 | + | 228 | + |
209 | +static void recv_nlmsg(int fd, struct nlmsghdr *nlh) | 229 | +static void recv_nlmsg(int fd, struct nlmsghdr *nlh) |
... | ... | ||
261 | + | 281 | + |
262 | +static void parse_opts(int argc, char **argv, __u32 *target_token) | 282 | +static void parse_opts(int argc, char **argv, __u32 *target_token) |
263 | +{ | 283 | +{ |
264 | + int c; | 284 | + int c; |
265 | + | 285 | + |
286 | + if (argc < 2) | ||
287 | + die_usage(1); | ||
288 | + | ||
266 | + while ((c = getopt(argc, argv, "ht:")) != -1) { | 289 | + while ((c = getopt(argc, argv, "ht:")) != -1) { |
267 | + switch (c) { | 290 | + switch (c) { |
268 | + case 'h': | 291 | + case 'h': |
269 | + die_usage(0); | 292 | + die_usage(0); |
270 | + break; | 293 | + break; |
... | ... | ||
287 | + | 310 | + |
288 | + return 0; | 311 | + return 0; |
289 | +} | 312 | +} |
290 | + | 313 | + |
291 | -- | 314 | -- |
292 | 2.25.1 | 315 | 2.43.0 | diff view generated by jsdifflib |
1 | This patch introduces a new 'chk_diag' test in diag.sh. It retrieves | 1 | This patch introduces a new 'chk_diag' test in diag.sh. It retrieves |
---|---|---|---|
2 | the token for a specified MPTCP socket (msk) using the 'ss' command and | 2 | the token for a specified MPTCP socket (msk) using the 'ss' command and |
3 | then accesses the 'mptcp_diag_dump_one' in kernel via ./mptcp_diag | 3 | then accesses the 'mptcp_diag_dump_one' in kernel via ./mptcp_diag |
4 | to verify if the correct token is returned. | 4 | to verify if the correct token is returned. |
5 | 5 | ||
6 | Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/524 | 6 | Link: https://github.com/multipath-tcp/mptcp_net-next/issues/524 |
7 | Signed-off-by: Gang Yan <yangang@kylinos.cn> | 7 | Signed-off-by: Gang Yan <yangang@kylinos.cn> |
8 | |||
9 | --- | ||
10 | Notes: | ||
11 | - v4: | ||
12 | - Optimized the check logic for 'ss_token' and 'token′, and before | ||
13 | that,first check if 'ss_token' is empty. | ||
8 | --- | 14 | --- |
9 | tools/testing/selftests/net/mptcp/diag.sh | 27 +++++++++++++++++++++++ | 15 | tools/testing/selftests/net/mptcp/diag.sh | 27 +++++++++++++++++++++++ |
10 | 1 file changed, 27 insertions(+) | 16 | 1 file changed, 27 insertions(+) |
11 | 17 | ||
12 | diff --git a/tools/testing/selftests/net/mptcp/diag.sh b/tools/testing/selftests/net/mptcp/diag.sh | 18 | diff --git a/tools/testing/selftests/net/mptcp/diag.sh b/tools/testing/selftests/net/mptcp/diag.sh |
... | ... | ||
31 | + awk -F':[ \t]+' '/^token/ {print $2}')" | 37 | + awk -F':[ \t]+' '/^token/ {print $2}')" |
32 | + | 38 | + |
33 | + msg="....chk dump_one" | 39 | + msg="....chk dump_one" |
34 | + | 40 | + |
35 | + mptcp_lib_print_title "$msg" | 41 | + mptcp_lib_print_title "$msg" |
36 | + if [ "$ss_token" != "$token" ]; then | 42 | + if [ -n "$ss_token" ] && [ "$ss_token" = "$token" ]; then |
43 | + mptcp_lib_pr_ok | ||
44 | + mptcp_lib_result_pass "${msg}" | ||
45 | + else | ||
37 | + mptcp_lib_pr_fail "expected $ss_token found $token" | 46 | + mptcp_lib_pr_fail "expected $ss_token found $token" |
38 | + mptcp_lib_result_fail "${msg}" | 47 | + mptcp_lib_result_fail "${msg}" |
39 | + ret=${KSFT_FAIL} | 48 | + ret=${KSFT_FAIL} |
40 | + else | ||
41 | + mptcp_lib_pr_ok | ||
42 | + mptcp_lib_result_pass "${msg}" | ||
43 | + fi | 49 | + fi |
44 | +} | 50 | +} |
45 | + | 51 | + |
46 | msk_info_get_value() | 52 | msk_info_get_value() |
47 | { | 53 | { |
... | ... | ||
53 | +chk_dump_one | 59 | +chk_dump_one |
54 | flush_pids | 60 | flush_pids |
55 | 61 | ||
56 | chk_msk_inuse 0 "2->0" | 62 | chk_msk_inuse 0 "2->0" |
57 | -- | 63 | -- |
58 | 2.25.1 | 64 | 2.43.0 |
65 | diff view generated by jsdifflib |