Skip to contentSkip to conversation

mptcp: fix endpoints with 'signal' and 'subflow' flags

PATCH Superseded Matthieu Baerts (NGI0) 4 participants 18 messages Jun 21, 2024 – Jul 10, 2024

Subsystems (3)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Matthieu Baerts (NGI0)

author maintainer
#0 lore raw

cover mptcp: fix endpoints with 'signal' and 'subflow' flags

When looking at improving the user experience around the MPTCP endpoints setup, I noticed that setting an endpoint with both the 'signal' and the 'subflow' flags -- as it has been done in the past by users according to bug reports we got -- were resulting on only announcing the endpoint, but not using it to create subflows: the 'subflow' flag was then ignored.

My initial thought was to modify IPRoute2 to warn the user when the two flags were set, but it doesn't sound normal to ignore one of them. I then looked at modifying the kernel not to allow having the two flags set, but when discussing about that with Mat, we thought it was maybe not ideal to do that, as there might be use-cases, we might break some configs, and it was working before apparently. So instead, I fixed the support by splitting the previously shared 'available IDs' bitmap.

While at it, I added a new selftest (patch 4) to validate this case -- including a modification of the chk_add_nr helper to inverse the sides were the counters are checked (patch 3) -- and allowed ADD_ADDR echo just after the MP_JOIN 3WHS.

The selftests modification don't have a Fixes tag, because backporting will not be easy: on some versions, the backport will not generate conflicts, but the test will fail because some helpers are not available. That's OK, many CIs will use the selftests from the last stable version to validate previous stable releases.

---
Matthieu Baerts (NGI0) (4):
mptcp: fully established after ADD_ADDR echo on MPJ
mptcp: split id_avail_bitmap per target
selftests: mptcp: join: ability to invert ADD_ADDR check
selftests: mptcp: join: test both signal & subflow

 net/mptcp/options.c                             |  3 +-
 net/mptcp/pm.c                                  |  3 +-
 net/mptcp/pm_netlink.c                          | 20 +++++----
 net/mptcp/protocol.h                            |  5 ++-
 tools/testing/selftests/net/mptcp/mptcp_join.sh | 55 ++++++++++++++++++-------
 5 files changed, 60 insertions(+), 26 deletions(-)

---
base-commit: e6b62d29168e1aef6aa328f8956e5e0aadffe3d5
change-id: 20240620-mptcp-pm-avail-f5e3957be441

Best regards,

Signature · 1 line
Matthieu Baerts (NGI0) <[email protected]>
author maintainer
#1 lore raw

PATCH 1/4 mptcp: fully established after ADD_ADDR echo on MPJ

Before this patch, receiving an ADD_ADDR echo on the just connected MP_JOIN subflow -- initiator side, after the MP_JOIN 3WHS -- was resulting in an MP_RESET. That's because only ACKs with a DSS or ADD_ADDRs without the echo bit were allowed.

Not allowing the ADD_ADDR echo after an MP_CAPABLE 3WHS makes sense, as we are not supposed to send an ADD_ADDR before because it requires to be in full established mode first. For the MP_JOIN 3WHS, that's different:
the ADD_ADDR can be sent on a previous subflow, and the ADD_ADDR echo can be received on the recently created one. The other peer will already be in fully established, so it is allowed to send that.

We can then relax the conditions here to accept the ADD_ADDR echo for MPJ subflows.

Fixes 67b12f792d5e ("mptcp: full fully established support after ADD_ADDR")
---
 net/mptcp/options.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/mptcp/options.c +2 -1
index c0832df3b0a3..4ee2e3605f5b 100644
@@ -958,7 +958,8 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
 
 	if (subflow->remote_key_valid &&
 	    (((mp_opt->suboptions & OPTION_MPTCP_DSS) && mp_opt->use_ack) ||
-	     ((mp_opt->suboptions & OPTION_MPTCP_ADD_ADDR) && !mp_opt->echo))) {
+	     ((mp_opt->suboptions & OPTION_MPTCP_ADD_ADDR) &&
+	      (!mp_opt->echo || subflow->mp_join)))) {
 		/* subflows are fully established as soon as we get any
 		 * additional ack, including ADD_ADDR.
 		 */
Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH 2/4 mptcp: split id_avail_bitmap per target

In reply to Matthieu Baerts (NGI0)

Up to the 'Fixes' commit, having an endpoint with both the 'signal' and 'subflow' flags, resulted in the creation of a subflow and an address announcement using the address linked to this endpoint. After this commit, only the address announcement was done, ignoring the 'subflow' flag.

That's because the same bitmap was used for the two flags. It is easy to split it in two: one for 'signal', and one for 'subflow'.

It is unusual to set the two flags together: creating a new subflow using a new local address will implicitly advertise it to the other peer. So in theory, no need to advertise it explicitly as well. Maybe there are use-cases -- the subflow might not reach the other peer that way, we can ask the other peer to try initiating the new subflow without delay -- or very likely the user is confused, and put both flags "just to be sure at least the right one is set". Still, the kernel should do what has been asked: using this endpoint to announce the address and to create a new subflow from it.

An alternative is to forbid the use of the two flags together, but that's probably too late, and there are maybe use-cases. This patch will avoid people complaining subflows are not created using the endpoint they added with the 'subflow' and 'signal' flag.

Fixes 86e39e04482b ("mptcp: keep track of local endpoint still available for each msk")
---
 net/mptcp/pm.c         |  3 ++-
 net/mptcp/pm_netlink.c | 20 ++++++++++++--------
 net/mptcp/protocol.h   |  5 +++--
 3 files changed, 17 insertions(+), 11 deletions(-)
net/mptcp/pm.c +2 -1
index 55406720c607..d29fb35bb927 100644
@@ -543,7 +543,8 @@ void mptcp_pm_data_reset(struct mptcp_sock *msk)
 	WRITE_ONCE(pm->addr_signal, 0);
 	WRITE_ONCE(pm->remote_deny_join_id0, false);
 	pm->status = 0;
-	bitmap_fill(msk->pm.id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
+	bitmap_fill(msk->pm.id_avail_signals_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
+	bitmap_fill(msk->pm.id_avail_subflows_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
 }
 
 void mptcp_pm_data_init(struct mptcp_sock *msk)
net/mptcp/pm_netlink.c +12 -8
index ea9e5817b9e9..4805452d05a2 100644
@@ -156,7 +156,7 @@ select_local_address(const struct pm_nl_pernet *pernet,
 		if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW))
 			continue;
 
-		if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap))
+		if (!test_bit(entry->addr.id, msk->pm.id_avail_subflows_bitmap))
 			continue;
 
 		ret = entry;
@@ -178,10 +178,10 @@ select_signal_address(struct pm_nl_pernet *pernet, const struct mptcp_sock *msk)
 	 * can lead to additional addresses not being announced.
 	 */
 	list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
-		if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap))
+		if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL))
 			continue;
 
-		if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL))
+		if (!test_bit(entry->addr.id, msk->pm.id_avail_signals_bitmap))
 			continue;
 
 		ret = entry;
@@ -228,7 +228,9 @@ bool mptcp_pm_nl_check_work_pending(struct mptcp_sock *msk)
 	struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
 
 	if (msk->pm.subflows == mptcp_pm_get_subflows_max(msk) ||
-	    (find_next_and_bit(pernet->id_bitmap, msk->pm.id_avail_bitmap,
+	    (find_next_and_bit(pernet->id_bitmap, msk->pm.id_avail_signals_bitmap,
+			       MPTCP_PM_MAX_ADDR_ID + 1, 0) == MPTCP_PM_MAX_ADDR_ID + 1) ||
+	    (find_next_and_bit(pernet->id_bitmap, msk->pm.id_avail_subflows_bitmap,
 			       MPTCP_PM_MAX_ADDR_ID + 1, 0) == MPTCP_PM_MAX_ADDR_ID + 1)) {
 		WRITE_ONCE(msk->pm.work_pending, false);
 		return false;
@@ -537,7 +539,8 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 		rcu_read_lock();
 		entry = __lookup_addr(pernet, &mpc_addr);
 		if (entry) {
-			__clear_bit(entry->addr.id, msk->pm.id_avail_bitmap);
+			__clear_bit(entry->addr.id, msk->pm.id_avail_signals_bitmap);
+			__clear_bit(entry->addr.id, msk->pm.id_avail_subflows_bitmap);
 			msk->mpc_endpoint_id = entry->addr.id;
 			backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP);
 		}
@@ -570,7 +573,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 
 		if (local) {
 			if (mptcp_pm_alloc_anno_list(msk, &local->addr)) {
-				__clear_bit(local->addr.id, msk->pm.id_avail_bitmap);
+				__clear_bit(local->addr.id, msk->pm.id_avail_signals_bitmap);
 				msk->pm.add_addr_signaled++;
 				mptcp_pm_announce_addr(msk, &local->addr, false);
 				mptcp_pm_nl_addr_send_ack(msk);
@@ -592,7 +595,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 		fullmesh = !!(local->flags & MPTCP_PM_ADDR_FLAG_FULLMESH);
 
 		msk->pm.local_addr_used++;
-		__clear_bit(local->addr.id, msk->pm.id_avail_bitmap);
+		__clear_bit(local->addr.id, msk->pm.id_avail_subflows_bitmap);
 		nr = fill_remote_addresses_vec(msk, &local->addr, fullmesh, addrs);
 		if (nr == 0)
 			continue;
@@ -822,7 +825,8 @@ static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk,
 				__MPTCP_INC_STATS(sock_net(sk), rm_type);
 		}
 		if (rm_type == MPTCP_MIB_RMSUBFLOW)
-			__set_bit(rm_id ? rm_id : msk->mpc_endpoint_id, msk->pm.id_avail_bitmap);
+			__set_bit(rm_id ? rm_id : msk->mpc_endpoint_id,
+				  msk->pm.id_avail_subflows_bitmap);
 		else if (rm_type == MPTCP_MIB_RMADDR)
 			__MPTCP_INC_STATS(sock_net(sk), rm_type);
 		if (!removed)
net/mptcp/protocol.h +3 -2
index 19d60b6d5b45..cbb430108823 100644
@@ -187,7 +187,7 @@ enum mptcp_pm_status {
 	MPTCP_PM_SUBFLOW_ESTABLISHED,
 	MPTCP_PM_ALREADY_ESTABLISHED,	/* persistent status, set after ESTABLISHED event */
 	MPTCP_PM_MPC_ENDPOINT_ACCOUNTED /* persistent status, set after MPC local address is
-					 * accounted int id_avail_bitmap
+					 * accounted in id_avail_*_bitmap
 					 */
 };
 
@@ -231,7 +231,8 @@ struct mptcp_pm_data {
 	u8		pm_type;
 	u8		subflows;
 	u8		status;
-	DECLARE_BITMAP(id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
+	DECLARE_BITMAP(id_avail_signals_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
+	DECLARE_BITMAP(id_avail_subflows_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
 	struct mptcp_rm_list rm_list_tx;
 	struct mptcp_rm_list rm_list_rx;
 };
Signature · 1 line
2.43.0
maintainer
#3 lore raw

Re: [PATCH mptcp-next 2/4] mptcp: split id_avail_bitmap per target

Quoted 94 lines · On Fri, 21 Jun 2024, Matthieu Baerts (NGI0) wrote:

Up to the 'Fixes' commit, having an endpoint with both the 'signal' and 'subflow' flags, resulted in the creation of a subflow and an address announcement using the address linked to this endpoint. After this commit, only the address announcement was done, ignoring the 'subflow' flag.

That's because the same bitmap was used for the two flags. It is easy to split it in two: one for 'signal', and one for 'subflow'.

It is unusual to set the two flags together: creating a new subflow using a new local address will implicitly advertise it to the other peer. So in theory, no need to advertise it explicitly as well. Maybe there are use-cases -- the subflow might not reach the other peer that way, we can ask the other peer to try initiating the new subflow without delay -- or very likely the user is confused, and put both flags "just to be sure at least the right one is set". Still, the kernel should do what has been asked: using this endpoint to announce the address and to create a new subflow from it.

An alternative is to forbid the use of the two flags together, but that's probably too late, and there are maybe use-cases. This patch will avoid people complaining subflows are not created using the endpoint they added with the 'subflow' and 'signal' flag.

Fixes 86e39e04482b ("mptcp: keep track of local endpoint still available for each msk")

---

net/mptcp/pm.c         |  3 ++-
net/mptcp/pm_netlink.c | 20 ++++++++++++--------
net/mptcp/protocol.h   |  5 +++--
3 files changed, 17 insertions(+), 11 deletions(-)
net/mptcp/pm.c +2 -1
index 55406720c607..d29fb35bb927 100644
@@ -543,7 +543,8 @@ void mptcp_pm_data_reset(struct mptcp_sock *msk)
 	WRITE_ONCE(pm->addr_signal, 0);
 	WRITE_ONCE(pm->remote_deny_join_id0, false);
 	pm->status = 0;
-	bitmap_fill(msk->pm.id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
+	bitmap_fill(msk->pm.id_avail_signals_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
+	bitmap_fill(msk->pm.id_avail_subflows_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
 }
 
 void mptcp_pm_data_init(struct mptcp_sock *msk)
net/mptcp/pm_netlink.c +8 -5
index ea9e5817b9e9..4805452d05a2 100644
@@ -156,7 +156,7 @@ select_local_address(const struct pm_nl_pernet *pernet,
 		if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW))
 			continue;
 
-		if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap))
+		if (!test_bit(entry->addr.id, msk->pm.id_avail_subflows_bitmap))
 			continue;
 
 		ret = entry;
@@ -178,10 +178,10 @@ select_signal_address(struct pm_nl_pernet *pernet, const struct mptcp_sock *msk)
 	 * can lead to additional addresses not being announced.
 	 */
 	list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
-		if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap))
+		if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL))
 			continue;
 
-		if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL))
+		if (!test_bit(entry->addr.id, msk->pm.id_avail_signals_bitmap))
 			continue;
 
 		ret = entry;
@@ -228,7 +228,9 @@ bool mptcp_pm_nl_check_work_pending(struct mptcp_sock *msk)
 	struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
 
 	if (msk->pm.subflows == mptcp_pm_get_subflows_max(msk) ||
-	    (find_next_and_bit(pernet->id_bitmap, msk->pm.id_avail_bitmap,
+	    (find_next_and_bit(pernet->id_bitmap, msk->pm.id_avail_signals_bitmap,
+			       MPTCP_PM_MAX_ADDR_ID + 1, 0) == MPTCP_PM_MAX_ADDR_ID + 1) ||
+	    (find_next_and_bit(pernet->id_bitmap, msk->pm.id_avail_subflows_bitmap,
 			       MPTCP_PM_MAX_ADDR_ID + 1, 0) == MPTCP_PM_MAX_ADDR_ID + 1)) {
 		WRITE_ONCE(msk->pm.work_pending, false);
 		return false;
@@ -537,7 +539,8 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 		rcu_read_lock();
 		entry = __lookup_addr(pernet, &mpc_addr);
 		if (entry) {
-			__clear_bit(entry->addr.id, msk->pm.id_avail_bitmap);
+			__clear_bit(entry->addr.id, msk->pm.id_avail_signals_bitmap);
+			__clear_bit(entry->addr.id, msk->pm.id_avail_subflows_bitmap);
 			msk->mpc_endpoint_id = entry->addr.id;
 			backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP);
 		}

net/mptcp/pm_netlink.c static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) · line 576

Quoted 5 lines
net/mptcp/pm_netlink.c +1 -1
@@ -570,7 +573,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 
 		if (local) {
 			if (mptcp_pm_alloc_anno_list(msk, &local->addr)) {
-				__clear_bit(local->addr.id, msk->pm.id_avail_bitmap);
+				__clear_bit(local->addr.id, msk->pm.id_avail_signals_bitmap);

Hi Matthieu -

I don't see anywhere that __set_bit(id, msk->pm.id_avail_signals_bitmap) is ever called, so it looks like once an id is announced it is never available to announce again.

I think it would work to set that bit whenever an announce list entry is removed using remove_anno_list_by_saddr()? The idea would be to keep id_avail_signals_bitmap consistent with the anno_list, and id_avail_subflows_bitmap consistent with the connected subflows.

- Mat

Quoted 51 lines
net/mptcp/pm_netlink.c +3 -2
 				msk->pm.add_addr_signaled++;
 				mptcp_pm_announce_addr(msk, &local->addr, false);
 				mptcp_pm_nl_addr_send_ack(msk);
@@ -592,7 +595,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 		fullmesh = !!(local->flags & MPTCP_PM_ADDR_FLAG_FULLMESH);
 
 		msk->pm.local_addr_used++;
-		__clear_bit(local->addr.id, msk->pm.id_avail_bitmap);
+		__clear_bit(local->addr.id, msk->pm.id_avail_subflows_bitmap);
 		nr = fill_remote_addresses_vec(msk, &local->addr, fullmesh, addrs);
 		if (nr == 0)
 			continue;
@@ -822,7 +825,8 @@ static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk,
 				__MPTCP_INC_STATS(sock_net(sk), rm_type);
 		}
 		if (rm_type == MPTCP_MIB_RMSUBFLOW)
-			__set_bit(rm_id ? rm_id : msk->mpc_endpoint_id, msk->pm.id_avail_bitmap);
+			__set_bit(rm_id ? rm_id : msk->mpc_endpoint_id,
+				  msk->pm.id_avail_subflows_bitmap);
 		else if (rm_type == MPTCP_MIB_RMADDR)
 			__MPTCP_INC_STATS(sock_net(sk), rm_type);
 		if (!removed)
net/mptcp/protocol.h +3 -2
index 19d60b6d5b45..cbb430108823 100644
@@ -187,7 +187,7 @@ enum mptcp_pm_status {
 	MPTCP_PM_SUBFLOW_ESTABLISHED,
 	MPTCP_PM_ALREADY_ESTABLISHED,	/* persistent status, set after ESTABLISHED event */
 	MPTCP_PM_MPC_ENDPOINT_ACCOUNTED /* persistent status, set after MPC local address is
-					 * accounted int id_avail_bitmap
+					 * accounted in id_avail_*_bitmap
 					 */
 };
 
@@ -231,7 +231,8 @@ struct mptcp_pm_data {
 	u8		pm_type;
 	u8		subflows;
 	u8		status;
-	DECLARE_BITMAP(id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
+	DECLARE_BITMAP(id_avail_signals_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
+	DECLARE_BITMAP(id_avail_subflows_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
 	struct mptcp_rm_list rm_list_tx;
 	struct mptcp_rm_list rm_list_rx;
 };
Signature · 2 lines
-- 
2.43.0
author maintainer
#4 lore raw

Re: [PATCH mptcp-next 2/4] mptcp: split id_avail_bitmap per target

Hi Mat,

Note: I forgot to change the topic to 'mptcp-net'...

Quoted 115 lines · Mat Martineau
Quoted 113 lines · On Fri, 21 Jun 2024, Matthieu Baerts (NGI0) wrote:

Up to the 'Fixes' commit, having an endpoint with both the 'signal' and 'subflow' flags, resulted in the creation of a subflow and an address announcement using the address linked to this endpoint. After this commit, only the address announcement was done, ignoring the 'subflow' flag.

That's because the same bitmap was used for the two flags. It is easy to split it in two: one for 'signal', and one for 'subflow'.

It is unusual to set the two flags together: creating a new subflow using a new local address will implicitly advertise it to the other peer. So in theory, no need to advertise it explicitly as well. Maybe there are use-cases -- the subflow might not reach the other peer that way, we can ask the other peer to try initiating the new subflow without delay -- or very likely the user is confused, and put both flags "just to be sure at least the right one is set". Still, the kernel should do what has been asked: using this endpoint to announce the address and to create a new subflow from it.

An alternative is to forbid the use of the two flags together, but that's probably too late, and there are maybe use-cases. This patch will avoid people complaining subflows are not created using the endpoint they added with the 'subflow' and 'signal' flag.

Fixes 86e39e04482b ("mptcp: keep track of local endpoint still

available for each msk")

---
net/mptcp/pm.c         |  3 ++-
net/mptcp/pm_netlink.c | 20 ++++++++++++--------
net/mptcp/protocol.h   |  5 +++--

3 files changed, 17 insertions(+), 11 deletions(-)
net/mptcp/pm.c +3 -1
index 55406720c607..d29fb35bb927 100644
@@ -543,7 +543,8 @@ void mptcp_pm_data_reset(struct mptcp_sock *msk)
     WRITE_ONCE(pm->addr_signal, 0);
     WRITE_ONCE(pm->remote_deny_join_id0, false);
     pm->status = 0;
-    bitmap_fill(msk->pm.id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
+    bitmap_fill(msk->pm.id_avail_signals_bitmap, MPTCP_PM_MAX_ADDR_ID
+ 1);
+    bitmap_fill(msk->pm.id_avail_subflows_bitmap,
 MPTCP_PM_MAX_ADDR_ID + 1);
 }

void mptcp_pm_data_init(struct mptcp_sock *msk)

net/mptcp/pm_netlink.c +1 -1
index ea9e5817b9e9..4805452d05a2 100644
@@ -156,7 +156,7 @@ select_local_address(const struct pm_nl_pernet
 *pernet,
         if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW))
             continue;
 
-        if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap))
+        if (!test_bit(entry->addr.id, msk->pm.id_avail_subflows_bitmap))
             continue;
 

        ret = entry;

net/mptcp/pm_netlink.c +2 -2
@@ -178,10 +178,10 @@ select_signal_address(struct pm_nl_pernet
 *pernet, const struct mptcp_sock *msk)
      * can lead to additional addresses not being announced.
      */
     list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
-        if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap))
+        if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL))
             continue;
 
-        if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL))
+        if (!test_bit(entry->addr.id, msk->pm.id_avail_signals_bitmap))
             continue;
 

        ret = entry;

net/mptcp/pm_netlink.c +0 -0
@@ -228,7 +228,9 @@ bool mptcp_pm_nl_check_work_pending(struct
 mptcp_sock *msk)
     struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
 

    if (msk->pm.subflows == mptcp_pm_get_subflows_max(msk) || -        (find_next_and_bit(pernet->id_bitmap, msk->pm.id_avail_bitmap, +        (find_next_and_bit(pernet->id_bitmap, msk-

Quoted 1 line

pm.id_avail_signals_bitmap,

+                   MPTCP_PM_MAX_ADDR_ID + 1, 0) == MPTCP_PM_MAX_ADDR_ID + 1) ||
+        (find_next_and_bit(pernet->id_bitmap, msk-

Quoted 1 line

pm.id_avail_subflows_bitmap,

                   MPTCP_PM_MAX_ADDR_ID + 1, 0) == MPTCP_PM_MAX_ADDR_ID + 1)) { WRITE_ONCE(msk->pm.work_pending, false); return false;

net/mptcp/pm_netlink.c +2 -1
@@ -537,7 +539,8 @@ static void
 mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
         rcu_read_lock();
         entry = __lookup_addr(pernet, &mpc_addr);
         if (entry) {
-            __clear_bit(entry->addr.id, msk->pm.id_avail_bitmap);
+            __clear_bit(entry->addr.id, msk-
 >pm.id_avail_signals_bitmap);
+            __clear_bit(entry->addr.id, msk-
 >pm.id_avail_subflows_bitmap);

            msk->mpc_endpoint_id = entry->addr.id; backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); }

net/mptcp/pm_netlink.c +1 -1
@@ -570,7 +573,7 @@ static void
 mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 
         if (local) {
             if (mptcp_pm_alloc_anno_list(msk, &local->addr)) {
-                __clear_bit(local->addr.id, msk->pm.id_avail_bitmap);
+                __clear_bit(local->addr.id, msk-
Quoted 7 lines

net/mptcp/pm_netlink.c static void · line 578

Quoted 1 line
net/mptcp/pm_netlink.c +0 -0
 >pm.id_avail_signals_bitmap);

Hi Matthieu -

I don't see anywhere that __set_bit(id, msk->pm.id_avail_signals_bitmap) is ever called, so it looks like once an id is announced it is never available to announce again.

Good point! It looks like it was already the case before: we only mark an ID as available again in mptcp_pm_nl_rm_addr_or_subflow(), but only when we found a matching local subflow. If the local ID was not used locally -- e.g. the other peer didn't establish a new subflow -- the ID was not marked as available again.

Quoted 4 lines

I think it would work to set that bit whenever an announce list entry is removed using remove_anno_list_by_saddr()? The idea would be to keep id_avail_signals_bitmap consistent with the anno_list, and id_avail_subflows_bitmap consistent with the connected subflows.

Yes, either in remove_anno_list_by_saddr() or mptcp_pm_remove_addr(). But then it is now linked to Paolo's series :)

https://lore.kernel.org/r/[email protected]

Maybe better to do that there?

It might be clearer to keep the suggested modification in mptcp_pm_nl_rm_addr_or_subflow(): only set the ID as available for the subflows bitmap. Then in another patch, set the ID as available for the signal bitmap in remove_anno_list_by_saddr() or mptcp_pm_remove_addr(). WDYT?

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author maintainer
#5 lore raw

PATCH 3/4 selftests: mptcp: join: ability to invert ADD_ADDR check

In reply to Matthieu Baerts (NGI0)

In the following commit, the client will initiate the ADD_ADDR, instead of the server. We need to way to verify the ADD_ADDR have been correctly sent.

Note: the default expected counters for when the port number is given are never changed by the caller, no need to accept them as parameter then.

---
 tools/testing/selftests/net/mptcp/mptcp_join.sh | 40 ++++++++++++++++---------
 1 file changed, 26 insertions(+), 14 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +26 -14
index 108aeeb84ef1..5f5e498bbb75 100755
@@ -1415,18 +1415,28 @@ chk_add_nr()
 	local add_nr=$1
 	local echo_nr=$2
 	local port_nr=${3:-0}
-	local syn_nr=${4:-$port_nr}
-	local syn_ack_nr=${5:-$port_nr}
-	local ack_nr=${6:-$port_nr}
-	local mis_syn_nr=${7:-0}
-	local mis_ack_nr=${8:-0}
+	local ns_invert=${4:-""}
+	local syn_nr=$port_nr
+	local syn_ack_nr=$port_nr
+	local ack_nr=$port_nr
+	local mis_syn_nr=0
+	local mis_ack_nr=0
+	local ns_tx=$ns1
+	local ns_rx=$ns2
+	local extra_msg=""
 	local count
 	local timeout
 
-	timeout=$(ip netns exec $ns1 sysctl -n net.mptcp.add_addr_timeout)
+	if [[ $ns_invert = "invert" ]]; then
+		ns_tx=$ns2
+		ns_rx=$ns1
+		extra_msg="invert"
+	fi
+
+	timeout=$(ip netns exec ${ns_tx} sysctl -n net.mptcp.add_addr_timeout)
 
 	print_check "add"
-	count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtAddAddr")
+	count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtAddAddr")
 	if [ -z "$count" ]; then
 		print_skip
 	# if the test configured a short timeout tolerate greater then expected
@@ -1438,7 +1448,7 @@ chk_add_nr()
 	fi
 
 	print_check "echo"
-	count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtEchoAdd")
+	count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtEchoAdd")
 	if [ -z "$count" ]; then
 		print_skip
 	elif [ "$count" != "$echo_nr" ]; then
@@ -1449,7 +1459,7 @@ chk_add_nr()
 
 	if [ $port_nr -gt 0 ]; then
 		print_check "pt"
-		count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtPortAdd")
+		count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtPortAdd")
 		if [ -z "$count" ]; then
 			print_skip
 		elif [ "$count" != "$port_nr" ]; then
@@ -1459,7 +1469,7 @@ chk_add_nr()
 		fi
 
 		print_check "syn"
-		count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinPortSynRx")
+		count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPJoinPortSynRx")
 		if [ -z "$count" ]; then
 			print_skip
 		elif [ "$count" != "$syn_nr" ]; then
@@ -1470,7 +1480,7 @@ chk_add_nr()
 		fi
 
 		print_check "synack"
-		count=$(mptcp_lib_get_counter ${ns2} "MPTcpExtMPJoinPortSynAckRx")
+		count=$(mptcp_lib_get_counter ${ns_rx} "MPTcpExtMPJoinPortSynAckRx")
 		if [ -z "$count" ]; then
 			print_skip
 		elif [ "$count" != "$syn_ack_nr" ]; then
@@ -1481,7 +1491,7 @@ chk_add_nr()
 		fi
 
 		print_check "ack"
-		count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinPortAckRx")
+		count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMPJoinPortAckRx")
 		if [ -z "$count" ]; then
 			print_skip
 		elif [ "$count" != "$ack_nr" ]; then
@@ -1492,7 +1502,7 @@ chk_add_nr()
 		fi
 
 		print_check "syn"
-		count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMismatchPortSynRx")
+		count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMismatchPortSynRx")
 		if [ -z "$count" ]; then
 			print_skip
 		elif [ "$count" != "$mis_syn_nr" ]; then
@@ -1503,7 +1513,7 @@ chk_add_nr()
 		fi
 
 		print_check "ack"
-		count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMismatchPortAckRx")
+		count=$(mptcp_lib_get_counter ${ns_tx} "MPTcpExtMismatchPortAckRx")
 		if [ -z "$count" ]; then
 			print_skip
 		elif [ "$count" != "$mis_ack_nr" ]; then
@@ -1513,6 +1523,8 @@ chk_add_nr()
 			print_ok
 		fi
 	fi
+
+	print_info "$extra_msg"
 }
 
 chk_add_tx_nr()
Signature · 1 line
2.43.0
author maintainer
#6 lore raw

PATCH 4/4 selftests: mptcp: join: test both signal & subflow

In reply to Matthieu Baerts (NGI0)

It should be quite uncommon to set both the subflow and the signal
flags: the initiator of the connection is typically the one creating new subflows, not the other peer, then no need to announce additional local addresses, and use it to create subflows.

But some people might be confused about the flags, and set both "just to be sure at least the right one is set". To verify the previous fix, and avoid future regressions, this specific case is now validated: the client announces a new address, and initiates a new subflow from the same address.

While working on this, another bug has been noticed, where the client reset the new subflow because an ADD_ADDR echo got received as the 3rd
ACK: check that no RST have been sent by the client and server.

---
 tools/testing/selftests/net/mptcp/mptcp_join.sh | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_join.sh +15 -0
index 5f5e498bbb75..b8c0b69db527 100755
@@ -1967,6 +1967,21 @@ signal_address_tests()
 		chk_add_nr 1 1
 	fi
 
+	# uncommon: subflow and signal flags on the same endpoint
+	# or because the user wrongly picked both, but still expects the client
+	# to create additional subflows
+	if reset "subflow and signal together"; then
+		pm_nl_set_limits $ns1 0 2
+		pm_nl_set_limits $ns2 0 2
+		pm_nl_add_endpoint $ns2 10.0.3.2 flags signal,subflow
+		run_tests $ns1 $ns2 10.0.1.1
+		chk_join_nr 1 1 1
+		chk_add_nr 1 1 0 invert  # only initiated by ns2
+		chk_add_nr 0 0 0         # none initiated by ns1
+		chk_rst_nr 0 0 invert    # no RST sent by the client
+		chk_rst_nr 0 0           # no RST sent by the server
+	fi
+
 	# accept and use add_addr with additional subflows
 	if reset "multiple subflows and signal"; then
 		pm_nl_set_limits $ns1 0 3
Signature · 1 line
2.43.0
maintainer
#7 lore raw

Re: [PATCH mptcp-next 4/4] selftests: mptcp: join: test both signal & subflow

Quoted 36 lines · On Fri, 21 Jun 2024, Matthieu Baerts (NGI0) wrote:

It should be quite uncommon to set both the subflow and the signal
flags: the initiator of the connection is typically the one creating new subflows, not the other peer, then no need to announce additional local addresses, and use it to create subflows.

But some people might be confused about the flags, and set both "just to be sure at least the right one is set". To verify the previous fix, and avoid future regressions, this specific case is now validated: the client announces a new address, and initiates a new subflow from the same address.

While working on this, another bug has been noticed, where the client reset the new subflow because an ADD_ADDR echo got received as the 3rd
ACK: check that no RST have been sent by the client and server.

---
tools/testing/selftests/net/mptcp/mptcp_join.sh | 15 +++++++++++++++

1 file changed, 15 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_join.sh +8 -0
index 5f5e498bbb75..b8c0b69db527 100755
@@ -1967,6 +1967,21 @@ signal_address_tests()
 		chk_add_nr 1 1
 	fi
 
+	# uncommon: subflow and signal flags on the same endpoint
+	# or because the user wrongly picked both, but still expects the client
+	# to create additional subflows
+	if reset "subflow and signal together"; then
+		pm_nl_set_limits $ns1 0 2
+		pm_nl_set_limits $ns2 0 2
+		pm_nl_add_endpoint $ns2 10.0.3.2 flags signal,subflow
+		run_tests $ns1 $ns2 10.0.1.1

tools/testing/selftests/net/mptcp/mptcp_join.sh signal_address_tests() · line 1987

Quoted 10 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +7 -0
+		chk_join_nr 1 1 1
+		chk_add_nr 1 1 0 invert  # only initiated by ns2
+		chk_add_nr 0 0 0         # none initiated by ns1
+		chk_rst_nr 0 0 invert    # no RST sent by the client
+		chk_rst_nr 0 0           # no RST sent by the server
+	fi
+
 	# accept and use add_addr with additional subflows
 	if reset "multiple subflows and signal"; then
 		pm_nl_set_limits $ns1 0 3

Matthieu -

Related to my feedback on patch 2, it would be good to add a test to confirm that announced addr_ids can be reused after they are removed.

- Mat

#8 lore raw
In reply to Matthieu Baerts (NGI0)

Hi Matthieu,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/9613128523

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/5b1c305d4d2d
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=864250

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)

maintainer
#9 lore raw
In reply to Matthieu Baerts (NGI0)

Hi,

Quoted 20 lines · On Fri, 2024-06-21 at 13:39 +0200, Matthieu Baerts (NGI0) wrote:

When looking at improving the user experience around the MPTCP endpoints setup, I noticed that setting an endpoint with both the 'signal' and the 'subflow' flags -- as it has been done in the past by users according to bug reports we got -- were resulting on only announcing the endpoint, but not using it to create subflows: the 'subflow' flag was then ignored.

My initial thought was to modify IPRoute2 to warn the user when the two flags were set, but it doesn't sound normal to ignore one of them. I then looked at modifying the kernel not to allow having the two flags set, but when discussing about that with Mat, we thought it was maybe not ideal to do that, as there might be use-cases, we might break some configs, and it was working before apparently. So instead, I fixed the support by splitting the previously shared 'available IDs' bitmap.

While at it, I added a new selftest (patch 4) to validate this case -- including a modification of the chk_add_nr helper to inverse the sides were the counters are checked (patch 3) -- and allowed ADD_ADDR echo just after the MP_JOIN 3WHS.

Quoted 5 lines

The selftests modification don't have a Fixes tag, because backporting will not be easy: on some versions, the backport will not generate conflicts, but the test will fail because some helpers are not available. That's OK, many CIs will use the selftests from the last stable version to validate previous stable releases.

I'm sorry for the large latency.

I think the above is more a new feature than a fix, I would avoid including fixes tag, to prevent stable backports.

I am a bit doubtful about having endpoint with both subflow | signal, do we want encourage such bogus setup? What if the endpoint specify a port, too?

AFAICS it can not work, as the port-based signal endpoint will create a listener on <IP>:<port> and later on the 'subflow' flag will try to bind on the same <IP>:<port>, failing, while creating the outgoing connection.

What about just documenting the existing behavior?

Thanks,

Paolo

author maintainer
#10 lore raw

Hi Paolo,

Quoted 23 lines · Paolo Abeni

Hi,

Quoted 20 lines · On Fri, 2024-06-21 at 13:39 +0200, Matthieu Baerts (NGI0) wrote:

When looking at improving the user experience around the MPTCP endpoints setup, I noticed that setting an endpoint with both the 'signal' and the 'subflow' flags -- as it has been done in the past by users according to bug reports we got -- were resulting on only announcing the endpoint, but not using it to create subflows: the 'subflow' flag was then ignored.

My initial thought was to modify IPRoute2 to warn the user when the two flags were set, but it doesn't sound normal to ignore one of them. I then looked at modifying the kernel not to allow having the two flags set, but when discussing about that with Mat, we thought it was maybe not ideal to do that, as there might be use-cases, we might break some configs, and it was working before apparently. So instead, I fixed the support by splitting the previously shared 'available IDs' bitmap.

While at it, I added a new selftest (patch 4) to validate this case -- including a modification of the chk_add_nr helper to inverse the sides were the counters are checked (patch 3) -- and allowed ADD_ADDR echo just after the MP_JOIN 3WHS.

Quoted 7 lines
Quoted 5 lines

The selftests modification don't have a Fixes tag, because backporting will not be easy: on some versions, the backport will not generate conflicts, but the test will fail because some helpers are not available. That's OK, many CIs will use the selftests from the last stable version to validate previous stable releases.

I'm sorry for the large latency.

No problem, thank you for your reply!

Quoted 2 lines

I think the above is more a new feature than a fix, I would avoid including fixes tag, to prevent stable backports.

My main goal here is to reduce frustration from users who are (certainly "badly") setting both the 'signal' and 'subflow' flags on new endpoints. In the different doc we have, we mention what does 'signal' and 'subflow', but nothing about using them together. For us, it seems obvious not to set the two flags together. But if you are new to MPTCP, I can understand that "signalling doesn't seem to hurt", and both 'subflow' and 'signal' flags are used.

(Note that in the mptcp.org implementation, the fullmesh PM was sending ADD_ADDR and establishing new subflows, just because "it doesn't hurt to announce all addresses" :) )

Currently, if we use the two flags together, the 'subflow' flag is ignored. I added the Fixes tag in patch 2, because it sounds like a bug not to create subflows when the 'subflow' flag is set. And also because it was working before the mentioned 'Fixes' commit which has accidentally removed this support.

I understand this can be seen as a feature, but I'm not sure how to better fix that to avoid this frustration from users when the 'subflow' flag is ignored. Or we change the kernel not to accept setting the two flags together?

Quoted 8 lines

I am a bit doubtful about having endpoint with both subflow | signal, do we want encourage such bogus setup? What if the endpoint specify a port, too?

AFAICS it can not work, as the port-based signal endpoint will create a listener on <IP>:<port> and later on the 'subflow' flag will try to bind on the same <IP>:<port>, failing, while creating the outgoing connection.

What about returning an error when a port is given with the 'subflow' flag?

Currently, we do:

  if (addr.addr.port && !(addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL))
      return -EINVAL;

We could add "(... || addr.flags & MPTCP_PM_ADDR_FLAG_SUBLFOW)".

Quoted 1 line

What about just documenting the existing behavior?

I don't think we should document that "setting both the 'signal' and 'subflow' flags is allowed, but in fact the 'subflow' flag is ignored in

Quoted 1 line

= 5.17 versions", no? :)

I initially looked at adding a warning in IPRoute2, but then I failed to explain when setting these two flags can be justified. (And the new warning would take time to arrive in Linux distro currently ignoring the 'subflow' flag in this case.)

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
maintainer
#11 lore raw
Quoted 51 lines · Matthieu Baerts

Hi Paolo,

Quoted 23 lines · Paolo Abeni

Hi,

Quoted 20 lines · On Fri, 2024-06-21 at 13:39 +0200, Matthieu Baerts (NGI0) wrote:

When looking at improving the user experience around the MPTCP endpoints setup, I noticed that setting an endpoint with both the 'signal' and the 'subflow' flags -- as it has been done in the past by users according to bug reports we got -- were resulting on only announcing the endpoint, but not using it to create subflows: the 'subflow' flag was then ignored.

My initial thought was to modify IPRoute2 to warn the user when the two flags were set, but it doesn't sound normal to ignore one of them. I then looked at modifying the kernel not to allow having the two flags set, but when discussing about that with Mat, we thought it was maybe not ideal to do that, as there might be use-cases, we might break some configs, and it was working before apparently. So instead, I fixed the support by splitting the previously shared 'available IDs' bitmap.

While at it, I added a new selftest (patch 4) to validate this case -- including a modification of the chk_add_nr helper to inverse the sides were the counters are checked (patch 3) -- and allowed ADD_ADDR echo just after the MP_JOIN 3WHS.

Quoted 7 lines
Quoted 5 lines

The selftests modification don't have a Fixes tag, because backporting will not be easy: on some versions, the backport will not generate conflicts, but the test will fail because some helpers are not available. That's OK, many CIs will use the selftests from the last stable version to validate previous stable releases.

I'm sorry for the large latency.

No problem, thank you for your reply!

Quoted 2 lines

I think the above is more a new feature than a fix, I would avoid including fixes tag, to prevent stable backports.

My main goal here is to reduce frustration from users who are (certainly "badly") setting both the 'signal' and 'subflow' flags on new endpoints. In the different doc we have, we mention what does 'signal' and 'subflow', but nothing about using them together. For us, it seems obvious not to set the two flags together. But if you are new to MPTCP, I can understand that "signalling doesn't seem to hurt", and both 'subflow' and 'signal' flags are used.

(Note that in the mptcp.org implementation, the fullmesh PM was sending ADD_ADDR and establishing new subflows, just because "it doesn't hurt to announce all addresses" :) )

Quoted 5 lines

Currently, if we use the two flags together, the 'subflow' flag is ignored. I added the Fixes tag in patch 2, because it sounds like a bug not to create subflows when the 'subflow' flag is set. And also because it was working before the mentioned 'Fixes' commit which has accidentally removed this support.

Ah, my bad! I underlooked the commit message and missed this part.

Quoted 9 lines
Quoted 8 lines

I am a bit doubtful about having endpoint with both subflow | signal, do we want encourage such bogus setup? What if the endpoint specify a port, too?

AFAICS it can not work, as the port-based signal endpoint will create a listener on <IP>:<port> and later on the 'subflow' flag will try to bind on the same <IP>:<port>, failing, while creating the outgoing connection.

Quoted 8 lines

What about returning an error when a port is given with the 'subflow' flag?

Currently, we do:

  if (addr.addr.port && !(addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL))
      return -EINVAL;

We could add "(... || addr.flags & MPTCP_PM_ADDR_FLAG_SUBLFOW)".

IMHO if we deny SIGNAL | SUBFLOW for a subset of the possible configuration, than is better to be consistent and deny them for all the conf.

Quoted 5 lines
Quoted 1 line

What about just documenting the existing behavior?

I don't think we should document that "setting both the 'signal' and 'subflow' flags is allowed, but in fact the 'subflow' flag is ignored in

Quoted 1 line

= 5.17 versions", no? :)

Yup, I missed the regression part of it.

If possible, I would be happy to reduce complexity by preventing signal and subflow flags together.

Quoted 4 lines

I initially looked at adding a warning in IPRoute2, but then I failed to explain when setting these two flags can be justified. (And the new warning would take time to arrive in Linux distro currently ignoring the 'subflow' flag in this case.)

Well, distro problems are distro problems, I'm sure we can ignore the distro lifecycle problems here. Should be addressed by a completely different set of persons ;)

Indeed the ip-mptcp man page could help some significant rewording, what about starting from there?

PORT description implicitly refers to 'signal' endpoint without mentioning such fact. Also it has effect for subflow endpoint, not mentioned there

/P

author maintainer
#12 lore raw

4 Jul 2024 19:32:47 Paolo Abeni <[email protected]>:

Quoted 73 lines · Matthieu Baerts
Quoted 51 lines

Hi Paolo,

Quoted 23 lines · Paolo Abeni

Hi,

Quoted 20 lines · On Fri, 2024-06-21 at 13:39 +0200, Matthieu Baerts (NGI0) wrote:

When looking at improving the user experience around the MPTCP endpoints setup, I noticed that setting an endpoint with both the 'signal' and the 'subflow' flags -- as it has been done in the past by users according to bug reports we got -- were resulting on only announcing the endpoint, but not using it to create subflows: the 'subflow' flag was then ignored.

My initial thought was to modify IPRoute2 to warn the user when the two flags were set, but it doesn't sound normal to ignore one of them. I then looked at modifying the kernel not to allow having the two flags set, but when discussing about that with Mat, we thought it was maybe not ideal to do that, as there might be use-cases, we might break some configs, and it was working before apparently. So instead, I fixed the support by splitting the previously shared 'available IDs' bitmap.

While at it, I added a new selftest (patch 4) to validate this case -- including a modification of the chk_add_nr helper to inverse the sides were the counters are checked (patch 3) -- and allowed ADD_ADDR echo just after the MP_JOIN 3WHS.

Quoted 7 lines
Quoted 5 lines

The selftests modification don't have a Fixes tag, because backporting will not be easy: on some versions, the backport will not generate conflicts, but the test will fail because some helpers are not available. That's OK, many CIs will use the selftests from the last stable version to validate previous stable releases.

I'm sorry for the large latency.

No problem, thank you for your reply!

Quoted 2 lines

I think the above is more a new feature than a fix, I would avoid including fixes tag, to prevent stable backports.

My main goal here is to reduce frustration from users who are (certainly "badly") setting both the 'signal' and 'subflow' flags on new endpoints. In the different doc we have, we mention what does 'signal' and 'subflow', but nothing about using them together. For us, it seems obvious not to set the two flags together. But if you are new to MPTCP, I can understand that "signalling doesn't seem to hurt", and both 'subflow' and 'signal' flags are used.

(Note that in the mptcp.org implementation, the fullmesh PM was sending ADD_ADDR and establishing new subflows, just because "it doesn't hurt to announce all addresses" :) )

Quoted 5 lines

Currently, if we use the two flags together, the 'subflow' flag is ignored. I added the Fixes tag in patch 2, because it sounds like a bug not to create subflows when the 'subflow' flag is set. And also because it was working before the mentioned 'Fixes' commit which has accidentally removed this support.

Ah, my bad! I underlooked the commit message and missed this part.

Quoted 13 lines
Quoted 8 lines

I am a bit doubtful about having endpoint with both subflow | signal, do we want encourage such bogus setup? What if the endpoint specify a port, too?

AFAICS it can not work, as the port-based signal endpoint will create a listener on <IP>:<port> and later on the 'subflow' flag will try to bind on the same <IP>:<port>, failing, while creating the outgoing connection.

What about returning an error when a port is given with the 'subflow' flag?

Currently, we do:

Quoted 8 lines
Quoted 4 lines

  if (addr.addr.port && !(addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) return -EINVAL;

We could add "(... || addr.flags & MPTCP_PM_ADDR_FLAG_SUBLFOW)".

IMHO if we deny SIGNAL | SUBFLOW for a subset of the possible configuration, than is better to be consistent and deny them for all the conf.

I thought about denying them all, but I wonder if there are no use cases currently using that. I didn't want to break them. Do you think it would be OK?

For the moment, using signal + subflow + port doesn't work. But more importantly, it cannot work. This looks similar to signal + fullmesh that is currently denied. So maybe OK to deny only a subset?

Quoted 10 lines
Quoted 5 lines
Quoted 1 line

What about just documenting the existing behavior?

I don't think we should document that "setting both the 'signal' and 'subflow' flags is allowed, but in fact the 'subflow' flag is ignored in

Quoted 1 line

= 5.17 versions", no? :)

Yup, I missed the regression part of it.

If possible, I would be happy to reduce complexity by preventing signal and subflow flags together.

Do you think it would be OK to backport that? How to know if this configuration is not already used for valid use cases?

Quoted 8 lines
Quoted 4 lines

I initially looked at adding a warning in IPRoute2, but then I failed to explain when setting these two flags can be justified. (And the new warning would take time to arrive in Linux distro currently ignoring the 'subflow' flag in this case.)

Well, distro problems are distro problems, I'm sure we can ignore the distro lifecycle problems here. Should be addressed by a completely different set of persons ;)

That's our problem if people report issues to us :-P

Quoted 2 lines

Indeed the ip-mptcp man page could help some significant rewording, what about starting from there?

Yes I started to do that, I will look at the v2 :)

https://lore.kernel.org/mptcp/[email protected]/T/

Quoted 3 lines

PORT description implicitly refers to 'signal' endpoint without mentioning such fact. Also it has effect for subflow endpoint, not mentioned there

Good idea to mention that. I will look at adding that in the v2.

Cheers,
Matt

maintainer
#13 lore raw
Quoted 11 lines · Matthieu Baerts
Quoted 8 lines
Quoted 3 lines

I don't think we should document that "setting both the 'signal' and 'subflow' flags is allowed, but in fact the 'subflow' flag is ignored in

Quoted 1 line

= 5.17 versions", no? :)

Yup, I missed the regression part of it.

If possible, I would be happy to reduce complexity by preventing signal and subflow flags together.

Do you think it would be OK to backport that? How to know if this configuration is not already used for valid use cases?

I guess that what worry me most is the addition of another large field to the msk "just" to track (again) endpoints.

Thinking again about it, perhaps we don't need it. Something alike the following should be sufficient to replace patch 2/4 here:

---

net/mptcp/pm_netlink.c +30 -13
index ea9e5817b9e9..24e18cd43f48 100644
@@ -513,8 +513,8 @@ __lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info)
 
 static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 {
+	struct mptcp_pm_addr_entry *local, *signal_and_subflow = NULL;
 	struct sock *sk = (struct sock *)msk;
-	struct mptcp_pm_addr_entry *local;
 	unsigned int add_addr_signal_max;
 	unsigned int local_addr_max;
 	struct pm_nl_pernet *pernet;
@@ -568,14 +568,27 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 		if (msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_SIGNAL))
 			return;
 
-		if (local) {
-			if (mptcp_pm_alloc_anno_list(msk, &local->addr)) {
-				__clear_bit(local->addr.id, msk->pm.id_avail_bitmap);
-				msk->pm.add_addr_signaled++;
-				mptcp_pm_announce_addr(msk, &local->addr, false);
-				mptcp_pm_nl_addr_send_ack(msk);
-			}
-		}
+		if (!local)
+			continue;
+
+		/* If the allocation fails we are on memory pressure, it looks
+		 * not worthy try any forther later action, that will likely fail
+		 * And if local has both the SIGNAL and SUBFLOW flags, and the
+		 * by bad luck the later subflow creation is successfully, the
+		 * msk will end-up not signaling this address; not even
+		 * re-attempting to do it.
+		 * Likely worthy incrementing a new MIB here
+		 */
+		if (!mptcp_pm_alloc_anno_list(msk, &local->addr))
+			return;
+
+		__clear_bit(local->addr.id, msk->pm.id_avail_bitmap);
+		msk->pm.add_addr_signaled++;
+		mptcp_pm_announce_addr(msk, &local->addr, false);
+		mptcp_pm_nl_addr_send_ack(msk);
+		if (local->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)
+			signal_and_subflow = local;
+		break;
 	}
 
 	/* check if should create a new subflow */
@@ -585,9 +598,14 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 		bool fullmesh;
 		int i, nr;
 
-		local = select_local_address(pernet, msk);
-		if (!local)
-			break;
+		if (signal_and_subflow) {
+			local = signal_and_subflow;
+			signal_and_subflow = NULL;
+		} else {
+			local = select_local_address(pernet, msk);
+			if (!local)
+				break;
+		}
 
 		fullmesh = !!(local->flags & MPTCP_PM_ADDR_FLAG_FULLMESH);
---

that is, when we use a signal endpoint, if that has the subflow flag, use additionally to create the subflows, without doing an additional search.

WDYT?

Thanks!

Paolo

p.s. Jakubs report the upstream mptcp_connect() st are flacky:

https://netdev.bots.linux.dev/contest.html?executor=vmksft-mptcp-dbg&test=mptcp-connect-sh

can you see that in our CI?

author maintainer
#14 lore raw

Hi Paolo,

Quoted 45 lines · Paolo Abeni
Quoted 11 lines · Matthieu Baerts
Quoted 8 lines
Quoted 3 lines

I don't think we should document that "setting both the 'signal' and 'subflow' flags is allowed, but in fact the 'subflow' flag is ignored in

Quoted 1 line

= 5.17 versions", no? :)

Yup, I missed the regression part of it.

If possible, I would be happy to reduce complexity by preventing signal and subflow flags together.

Do you think it would be OK to backport that? How to know if this configuration is not already used for valid use cases?

I guess that what worry me most is the addition of another large field to the msk "just" to track (again) endpoints.

Thinking again about it, perhaps we don't need it. Something alike the following should be sufficient to replace patch 2/4 here:

---

net/mptcp/pm_netlink.c +1 -8
index ea9e5817b9e9..24e18cd43f48 100644
@@ -513,8 +513,8 @@ __lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info)
 
 static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 {
+	struct mptcp_pm_addr_entry *local, *signal_and_subflow = NULL;
 	struct sock *sk = (struct sock *)msk;
-	struct mptcp_pm_addr_entry *local;
 	unsigned int add_addr_signal_max;
 	unsigned int local_addr_max;
 	struct pm_nl_pernet *pernet;
@@ -568,14 +568,27 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 		if (msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_SIGNAL))
 			return;
 
-		if (local) {
-			if (mptcp_pm_alloc_anno_list(msk, &local->addr)) {
-				__clear_bit(local->addr.id, msk->pm.id_avail_bitmap);
-				msk->pm.add_addr_signaled++;
-				mptcp_pm_announce_addr(msk, &local->addr, false);
-				mptcp_pm_nl_addr_send_ack(msk);
-			}

net/mptcp/pm_netlink.c static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) · line 579

Quoted 10 lines
net/mptcp/pm_netlink.c +9 -1
-		}
+		if (!local)
+			continue;
+
+		/* If the allocation fails we are on memory pressure, it looks
+		 * not worthy try any forther later action, that will likely fail
+		 * And if local has both the SIGNAL and SUBFLOW flags, and the
+		 * by bad luck the later subflow creation is successfully, the
+		 * msk will end-up not signaling this address; not even
+		 * re-attempting to do it.

If the subflow creation is successful, the new address will be somehow advertised to the other peer. Should we not try to create the subflow anyway? That would reduce the diff as well.

net/mptcp/pm_netlink.c static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) · line 580

Quoted 1 line
net/mptcp/pm_netlink.c +1 -0
+		 * Likely worthy incrementing a new MIB here

I think there are many other places where we don't have such MIB counters for not being able to allocate memory. Do you think we would need one here?

Quoted 36 lines
net/mptcp/pm_netlink.c +19 -4
+		 */
+		if (!mptcp_pm_alloc_anno_list(msk, &local->addr))
+			return;
+
+		__clear_bit(local->addr.id, msk->pm.id_avail_bitmap);
+		msk->pm.add_addr_signaled++;
+		mptcp_pm_announce_addr(msk, &local->addr, false);
+		mptcp_pm_nl_addr_send_ack(msk);
+		if (local->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)
+			signal_and_subflow = local;
+		break;
 	}
 
 	/* check if should create a new subflow */
@@ -585,9 +598,14 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 		bool fullmesh;
 		int i, nr;
 
-		local = select_local_address(pernet, msk);
-		if (!local)
-			break;
+		if (signal_and_subflow) {
+			local = signal_and_subflow;
+			signal_and_subflow = NULL;
+		} else {
+			local = select_local_address(pernet, msk);
+			if (!local)
+				break;
+		}
 
 		fullmesh = !!(local->flags & MPTCP_PM_ADDR_FLAG_FULLMESH);
---

that is, when we use a signal endpoint, if that has the subflow flag, use additionally to create the subflows, without doing an additional search.

Quoted 1 line

WDYT?

Smart! Indeed, we can do that because we always mark the IDs as being used for one or the other from the same place!

I will update the v2 with your version!

Quoted 7 lines

Thanks!

Paolo

p.s. Jakubs report the upstream mptcp_connect() st are flacky:

https://netdev.bots.linux.dev/contest.html?executor=vmksft-mptcp-dbg&test=mptcp-connect-sh

I noticed that this morning too, but I didn't have a chance to look at the logs. Now I just did, and I think they are all linked to:

https://github.com/multipath-tcp/mptcp_net-next/issues/499

Quoted 1 line

can you see that in our CI?

No:

https://ci-results.mptcp.dev/flakes.html?branch=export
https://ci-results.mptcp.dev/flakes.html?branch=export-net

I only saw these issues on the Netdev CI, in debug mode, when the same IP is used for both the client and the server. I just updated this #499 issue with the two new occurrences.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
maintainer
#15 lore raw
Quoted 18 lines · Matthieu Baerts
Quoted 17 lines · Paolo Abeni
net/mptcp/pm_netlink.c +5 -8
@@ -568,14 +568,27 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 		if (msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_SIGNAL))
 			return;
 
-		if (local) {
-			if (mptcp_pm_alloc_anno_list(msk, &local->addr)) {
-				__clear_bit(local->addr.id, msk->pm.id_avail_bitmap);
-				msk->pm.add_addr_signaled++;
-				mptcp_pm_announce_addr(msk, &local->addr, false);
-				mptcp_pm_nl_addr_send_ack(msk);
-			}
-		}
+		if (!local)
+			continue;
+
+		/* If the allocation fails we are on memory pressure, it looks
+		 * not worthy try any forther later action, that will likely fail
Quoted 8 lines

net/mptcp/pm_netlink.c static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) · line 579

Quoted 4 lines
net/mptcp/pm_netlink.c +4 -0
+		 * And if local has both the SIGNAL and SUBFLOW flags, and the
+		 * by bad luck the later subflow creation is successfully, the
+		 * msk will end-up not signaling this address; not even
+		 * re-attempting to do it.

If the subflow creation is successful, the new address will be somehow advertised to the other peer. Should we not try to create the subflow anyway? That would reduce the diff as well.

The announce list requires a very small amount of memory from a single slab. A subflow creation will require a tcp socket, an mptcp context, and likely some lsm context, I think is very unlikely all of them will be successfully.

The diff reduction will be just mostly for the trimmed comment, am I correct? If so I think we can keep the code this way. Note that most/all of comment above could be moved into the commit message itself.

Quoted 5 lines

net/mptcp/pm_netlink.c static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) · line 580

Quoted 1 line
net/mptcp/pm_netlink.c +1 -0
+		 * Likely worthy incrementing a new MIB here

I think there are many other places where we don't have such MIB counters for not being able to allocate memory. Do you think we would need one here?

Thinking again about it, we don't need them. The warn in dmsg should be enough ;)

Thanks!

Paolo

author maintainer
#16 lore raw

Hi Paolo,

Thank you for your reply!

Quoted 28 lines · Paolo Abeni
Quoted 18 lines · Matthieu Baerts
Quoted 17 lines · Paolo Abeni
net/mptcp/pm_netlink.c +5 -8
@@ -568,14 +568,27 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 		if (msk->pm.addr_signal & BIT(MPTCP_ADD_ADDR_SIGNAL))
 			return;
 
-		if (local) {
-			if (mptcp_pm_alloc_anno_list(msk, &local->addr)) {
-				__clear_bit(local->addr.id, msk->pm.id_avail_bitmap);
-				msk->pm.add_addr_signaled++;
-				mptcp_pm_announce_addr(msk, &local->addr, false);
-				mptcp_pm_nl_addr_send_ack(msk);
-			}
-		}
+		if (!local)
+			continue;
+
+		/* If the allocation fails we are on memory pressure, it looks
+		 * not worthy try any forther later action, that will likely fail
Quoted 8 lines

net/mptcp/pm_netlink.c static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) · line 579

Quoted 4 lines
net/mptcp/pm_netlink.c +4 -0
+		 * And if local has both the SIGNAL and SUBFLOW flags, and the
+		 * by bad luck the later subflow creation is successfully, the
+		 * msk will end-up not signaling this address; not even
+		 * re-attempting to do it.

If the subflow creation is successful, the new address will be somehow advertised to the other peer. Should we not try to create the subflow anyway? That would reduce the diff as well.

Quoted 4 lines

The announce list requires a very small amount of memory from a single slab. A subflow creation will require a tcp socket, an mptcp context, and likely some lsm context, I think is very unlikely all of them will be successfully.

I agree, but I don't know if we should change the behaviour here with a return.

Note that mptcp_pm_alloc_anno_list() can also return 'false' if the address was already in the list. It should not happen, but I didn't check if there were cases we didn't handle correctly there.

Quoted 5 lines

The diff reduction will be just mostly for the trimmed comment, am I correct? If so I think we can keep the code this way. Note that most/all of comment above could be moved into the commit message itself.

For this fix, I would have only added these two lines after having called mptcp_pm_nl_addr_send_ack():

  if (local->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)
  	signal_and_subflow = local;

Or we take this opportunity to reduce the level of indentations, but we use a "continue" if mptcp_pm_alloc_anno_list() failed. WDYT?

Quoted 8 lines
Quoted 5 lines

net/mptcp/pm_netlink.c static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) · line 580

Quoted 1 line
net/mptcp/pm_netlink.c +1 -0
+		 * Likely worthy incrementing a new MIB here

I think there are many other places where we don't have such MIB counters for not being able to allocate memory. Do you think we would need one here?

Thinking again about it, we don't need them. The warn in dmsg should be enough ;)

Sounds good to me!

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
maintainer
#17 lore raw
Quoted 6 lines · Matthieu Baerts
Quoted 4 lines · Paolo Abeni

The announce list requires a very small amount of memory from a single slab. A subflow creation will require a tcp socket, an mptcp context, and likely some lsm context, I think is very unlikely all of them will be successfully.

Quoted 6 lines

I agree, but I don't know if we should change the behaviour here with a return.

Note that mptcp_pm_alloc_anno_list() can also return 'false' if the address was already in the list. It should not happen, but I didn't check if there were cases we didn't handle correctly there.

AFAICS, we should never enter that branch. In fact I think we could add a WARN_ON_ONCE there:

	if (WARN_ON_ONCE(mptcp_pm_is_kernel(msk)))
		return false;

because the bitmap should prevent us from adding an already announce address.

Quoted 7 lines
Quoted 6 lines

The diff reduction will be just mostly for the trimmed comment, am I correct? If so I think we can keep the code this way. Note that most/all of comment above could be moved into the commit message itself.

Quoted 8 lines

For this fix, I would have only added these two lines after having called mptcp_pm_nl_addr_send_ack():

  if (local->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)
  	signal_and_subflow = local;

Or we take this opportunity to reduce the level of indentations, but we use a "continue" if mptcp_pm_alloc_anno_list() failed. WDYT?

I would go for reducing the level of indentation.

I think that in practice the behavior will be the same with both 'continue' and 'return': on 'continue' the next iteration will very likely fail. Perhaps it's better to be avoid wasting cycles and/or put extreme memory pressure on the system and consistently 'return'?

Thanks!

Paolo