selftests: mptcp: add addr argument for del_addr
authorGeliang Tang <geliangtang@gmail.com>
Wed, 31 Mar 2021 00:08:55 +0000 (17:08 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 31 Mar 2021 00:42:23 +0000 (17:42 -0700)
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: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: Geliang Tang <geliangtang@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/testing/selftests/net/mptcp/pm_nl_ctl.c

index 7b4167f..115decf 100644 (file)
@@ -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, "\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, "\tset <ip> [flags backup|nobackup]\n");
        fprintf(stderr, "\tflush\n");
@@ -301,6 +301,7 @@ int del_addr(int fd, int pm_family, int argc, char *argv[])
                  1024];
        struct rtattr *rta, *nest;
        struct nlmsghdr *nh;
+       u_int16_t family;
        int nest_start;
        u_int8_t id;
        int off = 0;
@@ -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,
                            MPTCP_PM_VER);
 
-       /* the only argument is the address id */
-       if (argc != 3)
+       /* the only argument is the address id (nonzero) */
+       if (argc != 3 && argc != 4)
                syntax(argv);
 
        id = atoi(argv[2]);
+       /* zero id with the IP address */
+       if (!id && argc != 4)
+               syntax(argv);
 
        nest_start = off;
        nest = (void *)(data + off);
@@ -328,6 +332,30 @@ int del_addr(int fd, int pm_family, int argc, char *argv[])
        rta->rta_len = RTA_LENGTH(1);
        memcpy(RTA_DATA(rta), &id, 1);
        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;
 
        do_nl_req(fd, nh, off, 0);