Commit 62a58e3d authored by Geliang Tang's avatar Geliang Tang
Browse files

selftests: mptcp: add token for dump_addr

mainline inclusion
from mainline-v6.9-rc1
commit 950c332125f66d7419a24fc933f05606ae199b40
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I9VYQ9
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=950c332125f66d7419a24fc933f05606ae199b40



--------------------------------

The command dump_addr() of pm_nl_ctl can be used like this in in-kernel PM:

        pm_nl_ctl dump

This patch adds token argument for it to support userspace PM:

        pm_nl_ctl dump token $token

If 'token $token' is passed to dump_addr(), copy it into the kernel
netlink.

Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Reviewed-by: default avatarMat Martineau <martineau@kernel.org>
Signed-off-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Reviewed-by: default avatarJackie Liu <liuyun01@kylinos.cn>
Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
parent 21f2825a
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -1127,8 +1127,16 @@ int dump_addrs(int fd, int pm_family, int argc, char *argv[])
		  1024];
	pid_t pid = getpid();
	struct nlmsghdr *nh;
	u_int32_t token = 0;
	struct rtattr *rta;
	int off = 0;

	if (argc != 2 && argc != 4)
		syntax(argv);

	if (argc == 4 && !strcmp(argv[2], "token"))
		token = strtoul(argv[3], NULL, 10);

	memset(data, 0, sizeof(data));
	nh = (void *)data;
	off = init_genl_req(data, pm_family, MPTCP_PM_CMD_GET_ADDR,
@@ -1138,6 +1146,15 @@ int dump_addrs(int fd, int pm_family, int argc, char *argv[])
	nh->nlmsg_pid = pid;
	nh->nlmsg_len = off;

	/* token */
	if (token) {
		rta = (void *)(data + off);
		rta->rta_type = MPTCP_PM_ATTR_TOKEN;
		rta->rta_len = RTA_LENGTH(4);
		memcpy(RTA_DATA(rta), &token, 4);
		off += NLMSG_ALIGN(rta->rta_len);
	}

	print_addrs(nh, pm_family, do_nl_req(fd, nh, off, sizeof(data)));
	return 0;
}