Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: mptcp: refactor send_query parameters for code clarity

This patch use 'inet_diag_req_v2' instead of 'token' as parameters of
send_query, and construct the req in 'get_mptcpinfo'.

This modification enhances the clarity of the code, and prepare for the
dump_subflow_info.

Co-developed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Gang Yan <yangang@kylinos.cn>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20250502-net-next-mptcp-sft-inc-cover-v1-4-68eec95898fb@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Gang Yan and committed by
Jakub Kicinski
3fea468d cd732d51

+10 -9
+10 -9
tools/testing/selftests/net/mptcp/mptcp_diag.c
··· 62 62 exit(r); 63 63 } 64 64 65 - static void send_query(int fd, __u32 token) 65 + static void send_query(int fd, struct inet_diag_req_v2 *r) 66 66 { 67 67 struct sockaddr_nl nladdr = { 68 68 .nl_family = AF_NETLINK ··· 76 76 .nlmsg_type = SOCK_DIAG_BY_FAMILY, 77 77 .nlmsg_flags = NLM_F_REQUEST 78 78 }, 79 - .r = { 80 - .sdiag_family = AF_INET, 81 - /* Real proto is set via INET_DIAG_REQ_PROTOCOL */ 82 - .sdiag_protocol = IPPROTO_TCP, 83 - .id.idiag_cookie[0] = token, 84 - } 79 + .r = *r 85 80 }; 86 81 struct rtattr rta_proto; 87 82 struct iovec iov[6]; 88 83 int iovlen = 1; 89 84 __u32 proto; 90 85 91 - req.r.idiag_ext |= (1 << (INET_DIAG_INFO - 1)); 92 86 proto = IPPROTO_MPTCP; 93 87 rta_proto.rta_type = INET_DIAG_REQ_PROTOCOL; 94 88 rta_proto.rta_len = RTA_LENGTH(sizeof(proto)); ··· 223 229 224 230 static void get_mptcpinfo(__u32 token) 225 231 { 232 + struct inet_diag_req_v2 r = { 233 + .sdiag_family = AF_INET, 234 + /* Real proto is set via INET_DIAG_REQ_PROTOCOL */ 235 + .sdiag_protocol = IPPROTO_TCP, 236 + .idiag_ext = 1 << (INET_DIAG_INFO - 1), 237 + .id.idiag_cookie[0] = token, 238 + }; 226 239 int fd; 227 240 228 241 fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG); 229 242 if (fd < 0) 230 243 die_perror("Netlink socket"); 231 244 232 - send_query(fd, token); 245 + send_query(fd, &r); 233 246 recv_nlmsg(fd); 234 247 235 248 close(fd);