All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH mptcp-next 0/3] set_flags port support
@ 2022-01-13  9:12 Geliang Tang
  2022-01-13  9:12 ` [PATCH mptcp-next 1/3] mptcp: allow to use port and non-signal in set_flags Geliang Tang
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Geliang Tang @ 2022-01-13  9:12 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang

This series added the port support for set_flags:

  pm_nl_ctl set 10.0.2.1 flags backup port 10100

- depends on:
  the "fullmesh flag setting support" series.

Geliang Tang (3):
  mptcp: allow to use port and non-signal in set_flags
  selftests: mptcp: add the port argument for set_flags
  selftests: mptcp: add backup with port testcase

 net/mptcp/pm_netlink.c                        | 13 +++---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 45 ++++++++++++++++---
 tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 14 +++++-
 3 files changed, 59 insertions(+), 13 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH mptcp-next 1/3] mptcp: allow to use port and non-signal in set_flags
  2022-01-13  9:12 [PATCH mptcp-next 0/3] set_flags port support Geliang Tang
@ 2022-01-13  9:12 ` Geliang Tang
  2022-01-13  9:12 ` [PATCH mptcp-next 2/3] selftests: mptcp: add the port argument for set_flags Geliang Tang
  2022-01-13  9:12 ` [PATCH mptcp-next 3/3] selftests: mptcp: add backup with port testcase Geliang Tang
  2 siblings, 0 replies; 4+ messages in thread
From: Geliang Tang @ 2022-01-13  9:12 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang

It's illegal to use both port and non-signal flags for adding address.
But it's legal to use both of them for setting flags, which always uses
non-signal flags, backup or fullmesh.

This patch moves this non-signal flag with port check from
mptcp_pm_parse_addr() to mptcp_nl_cmd_add_addr(). Do the check only when
adding addresses, not setting flags or deleting addresses.

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 net/mptcp/pm_netlink.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 8c5a4be21e3d..d28e9f5d2780 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -1162,14 +1162,8 @@ static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,
 	if (tb[MPTCP_PM_ADDR_ATTR_FLAGS])
 		entry->flags = nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]);
 
-	if (tb[MPTCP_PM_ADDR_ATTR_PORT]) {
-		if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
-			NL_SET_ERR_MSG_ATTR(info->extack, attr,
-					    "flags must have signal when using port");
-			return -EINVAL;
-		}
+	if (tb[MPTCP_PM_ADDR_ATTR_PORT])
 		entry->addr.port = htons(nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_PORT]));
-	}
 
 	return 0;
 }
@@ -1216,6 +1210,11 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info)
 	if (ret < 0)
 		return ret;
 
+	if (addr.addr.port && !(addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
+		GENL_SET_ERR_MSG(info, "flags must have signal when using port");
+		return -EINVAL;
+	}
+
 	entry = kmalloc(sizeof(*entry), GFP_KERNEL);
 	if (!entry) {
 		GENL_SET_ERR_MSG(info, "can't allocate addr");
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH mptcp-next 2/3] selftests: mptcp: add the port argument for set_flags
  2022-01-13  9:12 [PATCH mptcp-next 0/3] set_flags port support Geliang Tang
  2022-01-13  9:12 ` [PATCH mptcp-next 1/3] mptcp: allow to use port and non-signal in set_flags Geliang Tang
@ 2022-01-13  9:12 ` Geliang Tang
  2022-01-13  9:12 ` [PATCH mptcp-next 3/3] selftests: mptcp: add backup with port testcase Geliang Tang
  2 siblings, 0 replies; 4+ messages in thread
From: Geliang Tang @ 2022-01-13  9:12 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang

This patch added the port argument for setting the address flags in
pm_nl_ctl.

Usage:

    pm_nl_ctl set 10.0.2.1 flags backup port 10100

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/mptcp/pm_nl_ctl.c b/tools/testing/selftests/net/mptcp/pm_nl_ctl.c
index 9b6db9d77223..3c449158d821 100644
--- a/tools/testing/selftests/net/mptcp/pm_nl_ctl.c
+++ b/tools/testing/selftests/net/mptcp/pm_nl_ctl.c
@@ -28,7 +28,7 @@ static void syntax(char *argv[])
 	fprintf(stderr, "\tadd [flags signal|subflow|backup|fullmesh] [id <nr>] [dev <name>] <ip>\n");
 	fprintf(stderr, "\tdel <id> [<ip>]\n");
 	fprintf(stderr, "\tget <id>\n");
-	fprintf(stderr, "\tset <ip> [flags backup|nobackup|fullmesh|nofullmesh]\n");
+	fprintf(stderr, "\tset <ip> [flags backup|nobackup|fullmesh|nofullmesh] [port <nr>]\n");
 	fprintf(stderr, "\tflush\n");
 	fprintf(stderr, "\tdump\n");
 	fprintf(stderr, "\tlimits [<rcv addr max> <subflow max>]\n");
@@ -722,6 +722,18 @@ int set_flags(int fd, int pm_family, int argc, char *argv[])
 			rta->rta_len = RTA_LENGTH(4);
 			memcpy(RTA_DATA(rta), &flags, 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");
+
+			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]);
 		}
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH mptcp-next 3/3] selftests: mptcp: add backup with port testcase
  2022-01-13  9:12 [PATCH mptcp-next 0/3] set_flags port support Geliang Tang
  2022-01-13  9:12 ` [PATCH mptcp-next 1/3] mptcp: allow to use port and non-signal in set_flags Geliang Tang
  2022-01-13  9:12 ` [PATCH mptcp-next 2/3] selftests: mptcp: add the port argument for set_flags Geliang Tang
@ 2022-01-13  9:12 ` Geliang Tang
  2 siblings, 0 replies; 4+ messages in thread
From: Geliang Tang @ 2022-01-13  9:12 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang

This patch added the backup testcase using an address with a port number.

The original backup tests only work for the output of 'pm_nl_ctl dump'
without the port number. It chooses the last item in the dump to parse
the address in it, and in this case, the address is showed at the end
of the item.

But it dosen't work for the dump with the port number, in this case, the
port number is showed at the end of the item, not the address.

This patch implemented a more flexible approach to get the address and
the port number from the dump to fit for the port number case.

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 45 ++++++++++++++++---
 1 file changed, 40 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh
index 25725be98342..1a751c86d956 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
@@ -239,6 +239,16 @@ is_v6()
 	[ -z "${1##*:*}" ]
 }
 
+is_addr()
+{
+	[ -z "${1##*[.:]*}" ]
+}
+
+is_number()
+{
+	[[ $1 == ?(-)+([0-9]) ]]
+}
+
 # $1: ns, $2: port
 wait_local_port_listen()
 {
@@ -464,11 +474,26 @@ do_transfer()
 	if [ ! -z $sflags ]; then
 		sleep 1
 		for netns in "$ns1" "$ns2"; do
-			dump=(`ip netns exec $netns ./pm_nl_ctl dump`)
-			if [ ${#dump[@]} -gt 0 ]; then
-				addr=${dump[${#dump[@]} - 1]}
-				ip netns exec $netns ./pm_nl_ctl set $addr flags $sflags
-			fi
+			ip netns exec $netns ./pm_nl_ctl dump | while read line; do
+				local arr=($line)
+				local addr
+				local port=0
+
+				for i in ${arr[@]}; do
+					if is_addr $i; then
+						addr=$i
+					fi
+					if is_number $i; then
+						if [ $i -gt 10000 ]; then
+							port=$i
+						fi
+					fi
+				done
+				if [ $port -gt 0 ]; then
+					_port="port $port"
+				fi
+				ip netns exec $netns ./pm_nl_ctl set $addr flags $sflags $_port
+			done
 		done
 	fi
 
@@ -1651,6 +1676,16 @@ backup_tests()
 	chk_add_nr 1 1
 	chk_prio_nr 1 0
 	chk_rm_nr 0 0
+
+	# single address with port, backup
+	reset
+	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
+	ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal port 10100
+	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
+	run_tests $ns1 $ns2 10.0.1.1 0 0 0 slow backup
+	chk_join_nr "single address with port, backup" 1 1 1
+	chk_add_nr 1 1
+	chk_prio_nr 1 0
 }
 
 add_addr_ports_tests()
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-01-13  9:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-13  9:12 [PATCH mptcp-next 0/3] set_flags port support Geliang Tang
2022-01-13  9:12 ` [PATCH mptcp-next 1/3] mptcp: allow to use port and non-signal in set_flags Geliang Tang
2022-01-13  9:12 ` [PATCH mptcp-next 2/3] selftests: mptcp: add the port argument for set_flags Geliang Tang
2022-01-13  9:12 ` [PATCH mptcp-next 3/3] selftests: mptcp: add backup with port testcase Geliang Tang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.