netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mat Martineau <mathew.j.martineau@linux.intel.com>
To: netdev@vger.kernel.org
Cc: Geliang Tang <geliangtang@gmail.com>,
	davem@davemloft.net, kuba@kernel.org, mptcp@lists.01.org,
	Mat Martineau <mathew.j.martineau@linux.intel.com>
Subject: [PATCH net-next v2 13/15] selftests: mptcp: add port argument for pm_nl_ctl
Date: Mon,  1 Feb 2021 15:09:18 -0800	[thread overview]
Message-ID: <20210201230920.66027-14-mathew.j.martineau@linux.intel.com> (raw)
In-Reply-To: <20210201230920.66027-1-mathew.j.martineau@linux.intel.com>

From: Geliang Tang <geliangtang@gmail.com>

This patch adds a new argument for pm_nl_ctl tool. We can use it like
this:

 # pm_nl_ctl add 10.0.2.1 flags signal port 10100
 # pm_nl_ctl dump
 id 1 flags signal 10.0.2.1 10100

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
---
 tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 24 +++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/pm_nl_ctl.c b/tools/testing/selftests/net/mptcp/pm_nl_ctl.c
index abc269e96a07..7b4167f3f9a2 100644
--- a/tools/testing/selftests/net/mptcp/pm_nl_ctl.c
+++ b/tools/testing/selftests/net/mptcp/pm_nl_ctl.c
@@ -177,8 +177,8 @@ int add_addr(int fd, int pm_family, int argc, char *argv[])
 		  1024];
 	struct rtattr *rta, *nest;
 	struct nlmsghdr *nh;
+	u_int32_t flags = 0;
 	u_int16_t family;
-	u_int32_t flags;
 	int nest_start;
 	u_int8_t id;
 	int off = 0;
@@ -224,7 +224,6 @@ int add_addr(int fd, int pm_family, int argc, char *argv[])
 			char *tok, *str;
 
 			/* flags */
-			flags = 0;
 			if (++arg >= argc)
 				error(1, 0, " missing flags value");
 
@@ -272,6 +271,20 @@ int add_addr(int fd, int pm_family, int argc, char *argv[])
 			rta->rta_len = RTA_LENGTH(4);
 			memcpy(RTA_DATA(rta), &ifindex, 4);
 			off += NLMSG_ALIGN(rta->rta_len);
+		} else if (!strcmp(argv[arg], "port")) {
+			u_int16_t port;
+
+			if (++arg >= argc)
+				error(1, 0, " missing port value");
+			if (!(flags & MPTCP_PM_ADDR_FLAG_SIGNAL))
+				error(1, 0, " flags must be signal when using port");
+
+			port = atoi(argv[arg]);
+			rta = (void *)(data + off);
+			rta->rta_type = MPTCP_PM_ADDR_ATTR_PORT;
+			rta->rta_len = RTA_LENGTH(2);
+			memcpy(RTA_DATA(rta), &port, 2);
+			off += NLMSG_ALIGN(rta->rta_len);
 		} else
 			error(1, 0, "unknown keyword %s", argv[arg]);
 	}
@@ -324,6 +337,7 @@ int del_addr(int fd, int pm_family, int argc, char *argv[])
 static void print_addr(struct rtattr *attrs, int len)
 {
 	uint16_t family = 0;
+	uint16_t port = 0;
 	char str[1024];
 	uint32_t flags;
 	uint8_t id;
@@ -331,12 +345,16 @@ static void print_addr(struct rtattr *attrs, int len)
 	while (RTA_OK(attrs, len)) {
 		if (attrs->rta_type == MPTCP_PM_ADDR_ATTR_FAMILY)
 			memcpy(&family, RTA_DATA(attrs), 2);
+		if (attrs->rta_type == MPTCP_PM_ADDR_ATTR_PORT)
+			memcpy(&port, RTA_DATA(attrs), 2);
 		if (attrs->rta_type == MPTCP_PM_ADDR_ATTR_ADDR4) {
 			if (family != AF_INET)
 				error(1, errno, "wrong IP (v4) for family %d",
 				      family);
 			inet_ntop(AF_INET, RTA_DATA(attrs), str, sizeof(str));
 			printf("%s", str);
+			if (port)
+				printf(" %d", port);
 		}
 		if (attrs->rta_type == MPTCP_PM_ADDR_ATTR_ADDR6) {
 			if (family != AF_INET6)
@@ -344,6 +362,8 @@ static void print_addr(struct rtattr *attrs, int len)
 				      family);
 			inet_ntop(AF_INET6, RTA_DATA(attrs), str, sizeof(str));
 			printf("%s", str);
+			if (port)
+				printf(" %d", port);
 		}
 		if (attrs->rta_type == MPTCP_PM_ADDR_ATTR_ID) {
 			memcpy(&id, RTA_DATA(attrs), 1);
-- 
2.30.0


  parent reply	other threads:[~2021-02-01 23:17 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-01 23:09 [PATCH net-next v2 00/15] mptcp: ADD_ADDR enhancements Mat Martineau
2021-02-01 23:09 ` [PATCH net-next v2 01/15] mptcp: use WRITE_ONCE for the pernet *_max Mat Martineau
2021-02-01 23:09 ` [PATCH net-next v2 02/15] mptcp: drop *_max fields in mptcp_pm_data Mat Martineau
2021-02-01 23:09 ` [PATCH net-next v2 03/15] mptcp: create subflow or signal addr for newly added address Mat Martineau
2021-02-01 23:09 ` [PATCH net-next v2 04/15] mptcp: send ack for every add_addr Mat Martineau
2021-02-01 23:09 ` [PATCH net-next v2 05/15] selftests: mptcp: use minus values for removing address numbers Mat Martineau
2021-02-01 23:09 ` [PATCH net-next v2 06/15] selftests: mptcp: add testcases for newly added addresses Mat Martineau
2021-02-01 23:09 ` [PATCH net-next v2 07/15] mptcp: create the listening socket for new port Mat Martineau
2021-02-01 23:09 ` [PATCH net-next v2 08/15] mptcp: drop unused skb in subflow_token_join_request Mat Martineau
2021-02-01 23:09 ` [PATCH net-next v2 09/15] mptcp: add a new helper subflow_req_create_thmac Mat Martineau
2021-02-01 23:09 ` [PATCH net-next v2 10/15] mptcp: add port number check for MP_JOIN Mat Martineau
2021-02-01 23:09 ` [PATCH net-next v2 11/15] mptcp: enable use_port when invoke addresses_equal Mat Martineau
2021-02-01 23:09 ` [PATCH net-next v2 12/15] mptcp: deal with MPTCP_PM_ADDR_ATTR_PORT in PM netlink Mat Martineau
2021-02-01 23:09 ` Mat Martineau [this message]
2021-02-01 23:09 ` [PATCH net-next v2 14/15] mptcp: add the mibs for ADD_ADDR with port Mat Martineau
2021-02-01 23:09 ` [PATCH net-next v2 15/15] selftests: mptcp: add testcases " Mat Martineau
2021-02-03  3:10 ` [PATCH net-next v2 00/15] mptcp: ADD_ADDR enhancements patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210201230920.66027-14-mathew.j.martineau@linux.intel.com \
    --to=mathew.j.martineau@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=geliangtang@gmail.com \
    --cc=kuba@kernel.org \
    --cc=mptcp@lists.01.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).