Skip to contentSkip to conversation

set_flags port support

PATCH Superseded Geliang Tang 1 participant 4 messages Jan 13, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover set_flags port support

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(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/3 mptcp: allow to use port and non-signal in set_flags

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.

---
 net/mptcp/pm_netlink.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
net/mptcp/pm_netlink.c +6 -7
index 8c5a4be21e3d..d28e9f5d2780 100644
@@ -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");
Signature · 1 line
2.31.1
#2 lore raw

PATCH 2/3 selftests: mptcp: add the port argument for set_flags

In reply to 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
---
 tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
tools/testing/selftests/net/mptcp/pm_nl_ctl.c +13 -1
index 9b6db9d77223..3c449158d821 100644
@@ -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]);
 		}
Signature · 1 line
2.31.1
#3 lore raw

PATCH 3/3 selftests: mptcp: add backup with port testcase

In reply to 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.

---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 45 ++++++++++++++++---
 1 file changed, 40 insertions(+), 5 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +40 -5
index 25725be98342..1a751c86d956 100755
@@ -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()
Signature · 1 line
2.31.1