Skip to content

Commit a7109e1

Browse files
Dwyane-Yanintel-lab-lkp
authored andcommitted
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 can enhance the enhancing clarity of the code, and prepare for the dump_subflow_info. Co-developed-by: Geliang Tang <[email protected]> Signed-off-by: Geliang Tang <[email protected]> Signed-off-by: Gang Yan <[email protected]>
1 parent 4194212 commit a7109e1

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static void die_usage(int r)
6262
exit(r);
6363
}
6464

65-
static void send_query(int fd, __u32 token)
65+
static void send_query(int fd, struct inet_diag_req_v2 *r)
6666
{
6767
struct sockaddr_nl nladdr = {
6868
.nl_family = AF_NETLINK
@@ -76,19 +76,13 @@ static void send_query(int fd, __u32 token)
7676
.nlmsg_type = SOCK_DIAG_BY_FAMILY,
7777
.nlmsg_flags = NLM_F_REQUEST
7878
},
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
8580
};
8681
struct rtattr rta_proto;
8782
struct iovec iov[6];
8883
int iovlen = 1;
8984
__u32 proto;
9085

91-
req.r.idiag_ext |= (1 << (INET_DIAG_INFO - 1));
9286
proto = IPPROTO_MPTCP;
9387
rta_proto.rta_type = INET_DIAG_REQ_PROTOCOL;
9488
rta_proto.rta_len = RTA_LENGTH(sizeof(proto));
@@ -229,13 +223,20 @@ static void recv_nlmsg(int fd)
229223

230224
static void get_mptcpinfo(__u32 token)
231225
{
226+
struct inet_diag_req_v2 r = {
227+
.sdiag_family = AF_INET,
228+
/* Real proto is set via INET_DIAG_REQ_PROTOCOL */
229+
.sdiag_protocol = IPPROTO_TCP,
230+
.idiag_ext = 1 << (INET_DIAG_INFO - 1),
231+
.id.idiag_cookie[0] = token,
232+
};
232233
int fd;
233234

234235
fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG);
235236
if (fd < 0)
236237
die_perror("Netlink socket");
237238

238-
send_query(fd, token);
239+
send_query(fd, &r);
239240
recv_nlmsg(fd);
240241

241242
close(fd);

0 commit comments

Comments
 (0)