Commit 2d121c9a authored by Geliang Tang's avatar Geliang Tang Committed by David S. Miller

selftests: mptcp: add addr argument for del_addr

For the id 0 address, different MPTCP connections could be using
different IP addresses for id 0.

This patch added an extra argument IP address for del_addr when
using id 0.
Reviewed-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarGeliang Tang <geliangtang@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6254ad40
...@@ -26,7 +26,7 @@ static void syntax(char *argv[]) ...@@ -26,7 +26,7 @@ static void syntax(char *argv[])
{ {
fprintf(stderr, "%s add|get|set|del|flush|dump|accept [<args>]\n", argv[0]); fprintf(stderr, "%s add|get|set|del|flush|dump|accept [<args>]\n", argv[0]);
fprintf(stderr, "\tadd [flags signal|subflow|backup] [id <nr>] [dev <name>] <ip>\n"); fprintf(stderr, "\tadd [flags signal|subflow|backup] [id <nr>] [dev <name>] <ip>\n");
fprintf(stderr, "\tdel <id>\n"); fprintf(stderr, "\tdel <id> [<ip>]\n");
fprintf(stderr, "\tget <id>\n"); fprintf(stderr, "\tget <id>\n");
fprintf(stderr, "\tset <ip> [flags backup|nobackup]\n"); fprintf(stderr, "\tset <ip> [flags backup|nobackup]\n");
fprintf(stderr, "\tflush\n"); fprintf(stderr, "\tflush\n");
...@@ -301,6 +301,7 @@ int del_addr(int fd, int pm_family, int argc, char *argv[]) ...@@ -301,6 +301,7 @@ int del_addr(int fd, int pm_family, int argc, char *argv[])
1024]; 1024];
struct rtattr *rta, *nest; struct rtattr *rta, *nest;
struct nlmsghdr *nh; struct nlmsghdr *nh;
u_int16_t family;
int nest_start; int nest_start;
u_int8_t id; u_int8_t id;
int off = 0; int off = 0;
...@@ -310,11 +311,14 @@ int del_addr(int fd, int pm_family, int argc, char *argv[]) ...@@ -310,11 +311,14 @@ int del_addr(int fd, int pm_family, int argc, char *argv[])
off = init_genl_req(data, pm_family, MPTCP_PM_CMD_DEL_ADDR, off = init_genl_req(data, pm_family, MPTCP_PM_CMD_DEL_ADDR,
MPTCP_PM_VER); MPTCP_PM_VER);
/* the only argument is the address id */ /* the only argument is the address id (nonzero) */
if (argc != 3) if (argc != 3 && argc != 4)
syntax(argv); syntax(argv);
id = atoi(argv[2]); id = atoi(argv[2]);
/* zero id with the IP address */
if (!id && argc != 4)
syntax(argv);
nest_start = off; nest_start = off;
nest = (void *)(data + off); nest = (void *)(data + off);
...@@ -328,6 +332,30 @@ int del_addr(int fd, int pm_family, int argc, char *argv[]) ...@@ -328,6 +332,30 @@ int del_addr(int fd, int pm_family, int argc, char *argv[])
rta->rta_len = RTA_LENGTH(1); rta->rta_len = RTA_LENGTH(1);
memcpy(RTA_DATA(rta), &id, 1); memcpy(RTA_DATA(rta), &id, 1);
off += NLMSG_ALIGN(rta->rta_len); off += NLMSG_ALIGN(rta->rta_len);
if (!id) {
/* addr data */
rta = (void *)(data + off);
if (inet_pton(AF_INET, argv[3], RTA_DATA(rta))) {
family = AF_INET;
rta->rta_type = MPTCP_PM_ADDR_ATTR_ADDR4;
rta->rta_len = RTA_LENGTH(4);
} else if (inet_pton(AF_INET6, argv[3], RTA_DATA(rta))) {
family = AF_INET6;
rta->rta_type = MPTCP_PM_ADDR_ATTR_ADDR6;
rta->rta_len = RTA_LENGTH(16);
} else {
error(1, errno, "can't parse ip %s", argv[3]);
}
off += NLMSG_ALIGN(rta->rta_len);
/* family */
rta = (void *)(data + off);
rta->rta_type = MPTCP_PM_ADDR_ATTR_FAMILY;
rta->rta_len = RTA_LENGTH(2);
memcpy(RTA_DATA(rta), &family, 2);
off += NLMSG_ALIGN(rta->rta_len);
}
nest->rta_len = off - nest_start; nest->rta_len = off - nest_start;
do_nl_req(fd, nh, off, 0); do_nl_req(fd, nh, off, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment