Skip to contentSkip to conversation

add the id argument for set_flags

PATCH In review Geliang Tang 2 participants 4 messages Jan 22, 2022 – Jan 25, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover add the id argument for set_flags

v2:
- make standalone patches, instead of squash-to ones.
- add test cases in pm_netlink.sh, instead of mptcp_join.sh

Add the id argument for 'pm_nl_ctl set', and allow to use the port keyword with the non-signal flags for the setting flags in 'ip mptcp endpoint change', more commands can be used to set the address flags:

pm_nl_ctl set 10.0.2.1 flags backup port 10100 pm_nl_ctl set id 1 flags backup
ip mptcp endpoint change id 1 backup
ip mptcp endpoint change 10.0.2.1 backup port 10100

Geliang Tang (2):
selftests: mptcp: add the id argument for set_flags
selftests: mptcp: add set_flags tests in pm_netlink.sh

 .../testing/selftests/net/mptcp/pm_netlink.sh | 10 +++
 tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 64 +++++++++++++------
 2 files changed, 53 insertions(+), 21 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH v2 1/2 selftests: mptcp: add the id argument for set_flags

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

Usage:

pm_nl_ctl set id 1 flags backup

---
 tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 64 +++++++++++++------
 1 file changed, 43 insertions(+), 21 deletions(-)
tools/testing/selftests/net/mptcp/pm_nl_ctl.c +43 -21
index 2a57462764d0..e554928487f8 100644
@@ -28,7 +28,8 @@ 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] [port <nr>]\n");
+	fprintf(stderr, "\tset [<ip>] [id <nr>] [flags backup|nobackup|fullmesh|nofullmesh]\n");
+	fprintf(stderr, "\t                                                     [port <nr>]\n");
 	fprintf(stderr, "\tflush\n");
 	fprintf(stderr, "\tdump\n");
 	fprintf(stderr, "\tlimits [<rcv addr max> <subflow max>]\n");
@@ -657,8 +658,10 @@ int set_flags(int fd, int pm_family, int argc, char *argv[])
 	u_int32_t flags = 0;
 	u_int16_t family;
 	int nest_start;
+	int use_id = 0;
+	u_int8_t id;
 	int off = 0;
-	int arg;
+	int arg = 2;
 
 	memset(data, 0, sizeof(data));
 	nh = (void *)data;
@@ -674,29 +677,45 @@ int set_flags(int fd, int pm_family, int argc, char *argv[])
 	nest->rta_len = RTA_LENGTH(0);
 	off += NLMSG_ALIGN(nest->rta_len);
 
-	/* addr data */
-	rta = (void *)(data + off);
-	if (inet_pton(AF_INET, argv[2], 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[2], RTA_DATA(rta))) {
-		family = AF_INET6;
-		rta->rta_type = MPTCP_PM_ADDR_ATTR_ADDR6;
-		rta->rta_len = RTA_LENGTH(16);
+	if (!strcmp(argv[arg], "id")) {
+		if (++arg >= argc)
+			error(1, 0, " missing id value");
+
+		use_id = 1;
+		id = atoi(argv[arg]);
+		rta = (void *)(data + off);
+		rta->rta_type = MPTCP_PM_ADDR_ATTR_ID;
+		rta->rta_len = RTA_LENGTH(1);
+		memcpy(RTA_DATA(rta), &id, 1);
+		off += NLMSG_ALIGN(rta->rta_len);
 	} else {
-		error(1, errno, "can't parse ip %s", argv[2]);
+		/* addr data */
+		rta = (void *)(data + off);
+		if (inet_pton(AF_INET, argv[arg], 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[arg], 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[arg]);
+		}
+		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);
 	}
-	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);
+	if (++arg >= argc)
+		error(1, 0, " missing flags keyword");
 
-	for (arg = 3; arg < argc; arg++) {
+	for (; arg < argc; arg++) {
 		if (!strcmp(argv[arg], "flags")) {
 			char *tok, *str;
 
@@ -724,6 +743,9 @@ int set_flags(int fd, int pm_family, int argc, char *argv[])
 		} else if (!strcmp(argv[arg], "port")) {
 			u_int16_t port;
 
+			if (use_id)
+				error(1, 0, " port can't be used with id");
+
 			if (++arg >= argc)
 				error(1, 0, " missing port value");
 
Signature · 1 line
2.31.1
#2 lore raw

PATCH v2 2/2 selftests: mptcp: add set_flags tests in pm_netlink.sh

In reply to Geliang Tang

This patch added the setting flags test cases, using both addr-based and id-based lookups for the setting address.

---
 tools/testing/selftests/net/mptcp/pm_netlink.sh | 10 ++++++++++
 1 file changed, 10 insertions(+)
tools/testing/selftests/net/mptcp/pm_netlink.sh +10 -0
index cbacf9f6538b..55df8b4e33fa 100755
@@ -164,4 +164,14 @@ id 253 flags  10.0.0.5
 id 254 flags  10.0.0.2
 id 255 flags  10.0.0.3" "wrap-around ids"
 
+ip netns exec $ns1 ./pm_nl_ctl flush
+ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.1 flags subflow
+ip netns exec $ns1 ./pm_nl_ctl set 10.0.1.1 flags backup
+ip netns exec $ns1 ./pm_nl_ctl set 10.0.1.1 flags nobackup
+ip netns exec $ns1 ./pm_nl_ctl set id 1 flags fullmesh
+ip netns exec $ns1 ./pm_nl_ctl set id 1 flags nofullmesh
+ip netns exec $ns1 ./pm_nl_ctl set id 1 flags backup,fullmesh
+check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags \
+subflow,backup,fullmesh 10.0.1.1" "set flags"
+
 exit $ret
Signature · 1 line
2.31.1
#3 lore raw

Re: [PATCH mptcp-next v2 2/2] selftests: mptcp: add set_flags tests in pm_netlink.sh

Quoted 16 lines · Geliang Tang

This patch added the setting flags test cases, using both addr-based and id-based lookups for the setting address.

---
tools/testing/selftests/net/mptcp/pm_netlink.sh | 10 ++++++++++

1 file changed, 10 insertions(+)
tools/testing/selftests/net/mptcp/pm_netlink.sh +0 -0
index cbacf9f6538b..55df8b4e33fa 100755
@@ -164,4 +164,14 @@ id 253 flags  10.0.0.5

id 254 flags 10.0.0.2
id 255 flags 10.0.0.3" "wrap-around ids"

tools/testing/selftests/net/mptcp/pm_netlink.sh id 253 flags 10.0.0.5 · line 176

Quoted 10 lines
tools/testing/selftests/net/mptcp/pm_netlink.sh +10 -0
+ip netns exec $ns1 ./pm_nl_ctl flush
+ip netns exec $ns1 ./pm_nl_ctl add 10.0.1.1 flags subflow
+ip netns exec $ns1 ./pm_nl_ctl set 10.0.1.1 flags backup
+ip netns exec $ns1 ./pm_nl_ctl set 10.0.1.1 flags nobackup
+ip netns exec $ns1 ./pm_nl_ctl set id 1 flags fullmesh
+ip netns exec $ns1 ./pm_nl_ctl set id 1 flags nofullmesh
+ip netns exec $ns1 ./pm_nl_ctl set id 1 flags backup,fullmesh
+check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags \
+subflow,backup,fullmesh 10.0.1.1" "set flags"
+

I think it would be worth it to check more of the intermediate states with "pm_nl_ctl dump", not just after the last command. The first four 'set' commands could have been broken and that wouldn't be detected.

--
Mat Martineau
Intel