Skip to contentSkip to conversation

remove id 0 address

PATCH In review Geliang Tang 3 participants 8 messages Mar 4, 2021 – Mar 6, 2021

Subsystems (3)
lore
Share & tools
lore

Geliang Tang

author
#0 lore raw

v6 cover remove id 0 address

v6:
- add addr argument for del_addr.
- tag: export/20210226T185626
- need to apply the squash-to patchset "avoid passing rm_list as a struct"
or the single patch "avoid passing rm_list as a struct" in v5 first.

v5:
- add patch 1 "avoid passing rm_list as a struct".
- re-use MPTCP_MIB_RMADDR/MPTCP_MIB_RMSUBFLOW in patch 3.
- use (id == 0) instead of (!id) in patch 4.

v4:
- add new function mptcp_nl_remove_id_zero_address.
- add new testcases.

v3:
- print subflow ids in patch 1;
- add the initial subflow's ids check in patch 2;
- update the test in patch 3;

v2:
- drop __mptcp_wr_shutdown in v1.

Geliang Tang (5):
mptcp: remove all subflows involving id 0 address
mptcp: unify RM_ADDR and RM_SUBFLOW receiving
mptcp: remove id 0 address
selftests: mptcp: add addr argument for del_addr
selftests: mptcp: remove id 0 address testcases

 net/mptcp/pm_netlink.c                        | 127 ++++++++++--------
 .../testing/selftests/net/mptcp/mptcp_join.sh |  35 ++++-
 tools/testing/selftests/net/mptcp/pm_nl_ctl.c |  33 ++++-
 3 files changed, 137 insertions(+), 58 deletions(-)
Signature · 1 line
2.29.2
author
#1 lore raw

PATCH v6 1/5 mptcp: remove all subflows involving id 0 address

There's only one subflow involving the non-zero id address, but there may be multi subflows involving the id 0 address.

Here's an example:

local_id=0, remote_id=0
local_id=1, remote_id=0
local_id=0, remote_id=1

If the removing address id is 0, all the subflows involving the id 0 address need to be removed.

In mptcp_pm_nl_rm_addr_received/mptcp_pm_nl_rm_subflow_received, the "break" prevents the iteration to the next subflow, so this patch dropped them.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/pm_netlink.c | 4 ----
 1 file changed, 4 deletions(-)
net/mptcp/pm_netlink.c +0 -4
index fa1dd6b8ec2f..12e75ad29dc4 100644
@@ -629,8 +629,6 @@ static void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk)
 			WRITE_ONCE(msk->pm.accept_addr, true);
 
 			__MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMADDR);
-
-			break;
 		}
 	}
 }
@@ -703,8 +701,6 @@ void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk,
 			msk->pm.subflows--;
 
 			__MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMSUBFLOW);
-
-			break;
 		}
 	}
 }
Signature · 1 line
2.29.2
author
#2 lore raw

PATCH v6 2/5 mptcp: unify RM_ADDR and RM_SUBFLOW receiving

There are some duplicate code in mptcp_pm_nl_rm_addr_received and mptcp_pm_nl_rm_subflow_received. This patch unifies them into a new function named mptcp_pm_nl_rm_addr_or_subflow. In it, use the input parameter rm_type to identify it's now removing an address or a subflow.

Suggested-by Paolo Abeni <pabeni(a)redhat.com>
Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/pm_netlink.c | 82 +++++++++++++++++-------------------------
 1 file changed, 33 insertions(+), 49 deletions(-)
net/mptcp/pm_netlink.c +33 -49
index 12e75ad29dc4..2bd61d55186b 100644
@@ -594,45 +594,68 @@ int mptcp_pm_nl_mp_prio_send_ack(struct mptcp_sock *msk,
 	return -EINVAL;
 }
 
-static void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk)
+static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk,
+					   const struct mptcp_rm_list *rm_list,
+					   enum linux_mptcp_mib_field rm_type)
 {
 	struct mptcp_subflow_context *subflow, *tmp;
 	struct sock *sk = (struct sock *)msk;
 	u8 i;
 
-	pr_debug("address rm_list_nr %d", msk->pm.rm_list_rx.nr);
+	pr_debug("%s rm_list_nr %d",
+		 rm_type == MPTCP_MIB_RMADDR ? "address" : "subflow", rm_list->nr);
 
 	msk_owned_by_me(msk);
 
-	if (!msk->pm.rm_list_rx.nr)
+	if (!rm_list->nr)
 		return;
 
 	if (list_empty(&msk->conn_list))
 		return;
 
-	for (i = 0; i < msk->pm.rm_list_rx.nr; i++) {
+	for (i = 0; i < rm_list->nr; i++) {
 		list_for_each_entry_safe(subflow, tmp, &msk->conn_list, node) {
 			struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
 			int how = RCV_SHUTDOWN | SEND_SHUTDOWN;
+			u8 id = subflow->local_id;
+
+			if (rm_type == MPTCP_MIB_RMADDR)
+				id = subflow->remote_id;
 
-			if (msk->pm.rm_list_rx.ids[i] != subflow->remote_id)
+			if (rm_list->ids[i] != id)
 				continue;
 
-			pr_debug(" -> address rm_list_ids[%d]=%u", i, msk->pm.rm_list_rx.ids[i]);
+			pr_debug(" -> %s rm_list_ids[%d]=%u local_id=%u remote_id=%u",
+				 rm_type == MPTCP_MIB_RMADDR ? "address" : "subflow",
+				 i, rm_list->ids[i], subflow->local_id, subflow->remote_id);
 			spin_unlock_bh(&msk->pm.lock);
 			mptcp_subflow_shutdown(sk, ssk, how);
 			mptcp_close_ssk(sk, ssk, subflow);
 			spin_lock_bh(&msk->pm.lock);
 
-			msk->pm.add_addr_accepted--;
+			if (rm_type == MPTCP_MIB_RMADDR) {
+				msk->pm.add_addr_accepted--;
+				WRITE_ONCE(msk->pm.accept_addr, true);
+			} else if (rm_type == MPTCP_MIB_RMSUBFLOW) {
+				msk->pm.local_addr_used--;
+			}
 			msk->pm.subflows--;
-			WRITE_ONCE(msk->pm.accept_addr, true);
-
-			__MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMADDR);
+			__MPTCP_INC_STATS(sock_net(sk), rm_type);
 		}
 	}
 }
 
+static void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk)
+{
+	mptcp_pm_nl_rm_addr_or_subflow(msk, &msk->pm.rm_list_rx, MPTCP_MIB_RMADDR);
+}
+
+void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk,
+				     const struct mptcp_rm_list *rm_list)
+{
+	mptcp_pm_nl_rm_addr_or_subflow(msk, rm_list, MPTCP_MIB_RMSUBFLOW);
+}
+
 void mptcp_pm_nl_work(struct mptcp_sock *msk)
 {
 	struct mptcp_pm_data *pm = &msk->pm;
@@ -666,45 +689,6 @@ void mptcp_pm_nl_work(struct mptcp_sock *msk)
 	spin_unlock_bh(&msk->pm.lock);
 }
 
-void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk,
-				     const struct mptcp_rm_list *rm_list)
-{
-	struct mptcp_subflow_context *subflow, *tmp;
-	struct sock *sk = (struct sock *)msk;
-	u8 i;
-
-	pr_debug("subflow rm_list_nr %d", rm_list->nr);
-
-	msk_owned_by_me(msk);
-
-	if (!rm_list->nr)
-		return;
-
-	if (list_empty(&msk->conn_list))
-		return;
-
-	for (i = 0; i < rm_list->nr; i++) {
-		list_for_each_entry_safe(subflow, tmp, &msk->conn_list, node) {
-			struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
-			int how = RCV_SHUTDOWN | SEND_SHUTDOWN;
-
-			if (rm_list->ids[i] != subflow->local_id)
-				continue;
-
-			pr_debug(" -> subflow rm_list_ids[%d]=%u", i, rm_list->ids[i]);
-			spin_unlock_bh(&msk->pm.lock);
-			mptcp_subflow_shutdown(sk, ssk, how);
-			mptcp_close_ssk(sk, ssk, subflow);
-			spin_lock_bh(&msk->pm.lock);
-
-			msk->pm.local_addr_used--;
-			msk->pm.subflows--;
-
-			__MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMSUBFLOW);
-		}
-	}
-}
-
 static bool address_use_port(struct mptcp_pm_addr_entry *entry)
 {
 	return (entry->addr.flags &
Signature · 1 line
2.29.2
author
#3 lore raw

PATCH v6 3/5 mptcp: remove id 0 address

This patch added a new function mptcp_nl_remove_id_zero_address to remove the id 0 address.

In this function, traverse all the existing msk sockets to find the msk matched the input IP address. Then fill the removing list with id 0, and pass it to mptcp_pm_remove_addr and mptcp_pm_remove_subflow.

Suggested-by Paolo Abeni <pabeni(a)redhat.com>
Suggested-by Matthieu Baerts <matthieu.baerts(a)tessares.net>
Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 net/mptcp/pm_netlink.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
net/mptcp/pm_netlink.c +41 -0
index 2bd61d55186b..c73b7cfc7ae9 100644
@@ -1164,6 +1164,39 @@ static void mptcp_pm_free_addr_entry(struct mptcp_pm_addr_entry *entry)
 	}
 }
 
+static int mptcp_nl_remove_id_zero_address(struct net *net,
+					   struct mptcp_addr_info *addr)
+{
+	struct mptcp_sock *msk;
+	long s_slot = 0, s_num = 0;
+	struct mptcp_rm_list list = { .nr = 0 };
+
+	list.ids[list.nr++] = 0;
+
+	while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num)) != NULL) {
+		struct sock *sk = (struct sock *)msk;
+		struct mptcp_addr_info msk_local;
+
+		if (list_empty(&msk->conn_list))
+			goto next;
+
+		local_address((struct sock_common *)msk, &msk_local);
+		if (!addresses_equal(&msk_local, addr, addr->port))
+			goto next;
+
+		lock_sock(sk);
+		mptcp_pm_remove_addr(msk, &list);
+		mptcp_pm_remove_subflow(msk, &list);
+		release_sock(sk);
+
+next:
+		sock_put(sk);
+		cond_resched();
+	}
+
+	return 0;
+}
+
 static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)
 {
 	struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
@@ -1176,6 +1209,14 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)
 	if (ret < 0)
 		return ret;
 
+	/* the zero id address is special: the first address used by the msk
+	 * always gets such an id, so different subflows can have different zero
+	 * id addresses. Additionally zero id is not accounted for in id_bitmap.
+	 * Let's use an 'mptcp_rm_list' instead of the common remove code.
+	 */
+	if (addr.addr.id == 0)
+		return mptcp_nl_remove_id_zero_address(sock_net(skb->sk), &addr.addr);
+
 	spin_lock_bh(&pernet->lock);
 	entry = __lookup_addr_by_id(pernet, addr.addr.id);
 	if (!entry) {
Signature · 1 line
2.29.2
author
#4 lore raw

PATCH v6 4/5 selftests: mptcp: add addr argument for del_addr

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.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 33 +++++++++++++++++--
 1 file changed, 30 insertions(+), 3 deletions(-)
tools/testing/selftests/net/mptcp/pm_nl_ctl.c +30 -3
index 7b4167f3f9a2..3a627895e03d 100644
@@ -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,29 @@ 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);
Signature · 1 line
2.29.2
author
#5 lore raw

PATCH v6 5/5 selftests: mptcp: remove id 0 address testcases

This patch added the testcases for removing the id 0 subflow and the id 0 address.

In do_transfer, use the removing addresses number '9' for deleting the id 0 address.

Signed-off-by Geliang Tang <geliangtang(a)gmail.com>
---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 35 +++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +33 -2
index 96379ede5925..1ee9b66dcded 100755
@@ -315,9 +315,12 @@ do_transfer()
 					let id+=1
 				done
 			fi
-		else
+		elif [ $rm_nr_ns1 -eq 8 ]; then
 			sleep 1
 			ip netns exec ${listener_ns} ./pm_nl_ctl flush
+		elif [ $rm_nr_ns1 -eq 9 ]; then
+			sleep 1
+			ip netns exec ${listener_ns} ./pm_nl_ctl del 0 ${connect_addr}
 		fi
 	fi
 
@@ -354,9 +357,18 @@ do_transfer()
 					let id+=1
 				done
 			fi
-		else
+		elif [ $rm_nr_ns2 -eq 8 ]; then
 			sleep 1
 			ip netns exec ${connector_ns} ./pm_nl_ctl flush
+		elif [ $rm_nr_ns2 -eq 9 ]; then
+			local addr
+			if is_v6 "${connect_addr}"; then
+				addr="dead:beef:1::2"
+			else
+				addr="10.0.1.2"
+			fi
+			sleep 1
+			ip netns exec ${connector_ns} ./pm_nl_ctl del 0 $addr
 		fi
 	fi
 
@@ -1016,6 +1028,25 @@ remove_tests()
 	chk_join_nr "flush invalid addresses" 1 1 1
 	chk_add_nr 3 3
 	chk_rm_nr 3 1 invert
+
+	# remove id 0 subflow
+	reset
+	ip netns exec $ns1 ./pm_nl_ctl limits 0 1
+	ip netns exec $ns2 ./pm_nl_ctl limits 0 1
+	ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow
+	run_tests $ns1 $ns2 10.0.1.1 0 0 -9 slow
+	chk_join_nr "remove id 0 subflow" 1 1 1
+	chk_rm_nr 1 1
+
+	# remove id 0 address
+	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
+	ip netns exec $ns2 ./pm_nl_ctl limits 1 1
+	run_tests $ns1 $ns2 10.0.1.1 0 -9 0 slow
+	chk_join_nr "remove id 0 address" 1 1 1
+	chk_add_nr 1 1
+	chk_rm_nr 1 1 invert
 }
 
 add_tests()
Signature · 1 line
2.29.2
Reviewed-by on the v6 series
#6 lore raw
In reply to Geliang Tang
Quoted 6 lines · Geliang Tang

v6:
- add addr argument for del_addr.
- tag: export/20210226T185626
- need to apply the squash-to patchset "avoid passing rm_list as a struct" or the single patch "avoid passing rm_list as a struct" in v5 first.

Thanks, Geliang. v6 looks ready for the export branch.

Reviewed-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>

-Mat

Quoted 26 lines

v5:
- add patch 1 "avoid passing rm_list as a struct".
- re-use MPTCP_MIB_RMADDR/MPTCP_MIB_RMSUBFLOW in patch 3.
- use (id == 0) instead of (!id) in patch 4.

v4:
- add new function mptcp_nl_remove_id_zero_address.
- add new testcases.

v3:
- print subflow ids in patch 1;
- add the initial subflow's ids check in patch 2;
- update the test in patch 3;

v2:
- drop __mptcp_wr_shutdown in v1.

Geliang Tang (5):
mptcp: remove all subflows involving id 0 address
mptcp: unify RM_ADDR and RM_SUBFLOW receiving
mptcp: remove id 0 address
selftests: mptcp: add addr argument for del_addr
selftests: mptcp: remove id 0 address testcases

Quoted 11 lines
net/mptcp/pm_netlink.c                        | 127 ++++++++++--------
.../testing/selftests/net/mptcp/mptcp_join.sh |  35 ++++-
tools/testing/selftests/net/mptcp/pm_nl_ctl.c |  33 ++++-
3 files changed, 137 insertions(+), 58 deletions(-)
Signature · 4 lines
2.29.2
_______________________________________________
mptcp mailing list -- mptcp(a)lists.01.org
To unsubscribe send an email to mptcp-leave(a)lists.01.org

--
Mat Martineau
Intel

#7 lore raw
In reply to Geliang Tang

Hi Geliang, Mat,

Quoted 20 lines · Geliang Tang

v6:
- add addr argument for del_addr.
- tag: export/20210226T185626
- need to apply the squash-to patchset "avoid passing rm_list as a struct"
or the single patch "avoid passing rm_list as a struct" in v5 first.

v5:
- add patch 1 "avoid passing rm_list as a struct".
- re-use MPTCP_MIB_RMADDR/MPTCP_MIB_RMSUBFLOW in patch 3.
- use (id == 0) instead of (!id) in patch 4.

v4:
- add new function mptcp_nl_remove_id_zero_address.
- add new testcases.

v3:
- print subflow ids in patch 1;
- add the initial subflow's ids check in patch 2;
- update the test in patch 3;

Quoted 4 lines

v2:
- drop __mptcp_wr_shutdown in v1.

Thank you for the patches and reviews!

Just added in our tree with Mat's RvB tag and a small modification in patch 4/5 to remove a checkpatch warning.

- efa9a9885fe7: mptcp: remove all subflows involving id 0 address
- e753cdf39596: mptcp: unify RM_ADDR and RM_SUBFLOW receiving
- 01a0acddf9ee: mptcp: remove id 0 address
- 1cfe9d6a9351: selftests: mptcp: add addr argument for del_addr
- 52221e28e3ef: selftests: mptcp: remove id 0 address testcases
- Results: 31d85a0e0974..b6772f0348c6

Tests + export have been queued!

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net