Skip to contentSkip to conversation

mptcp: pm: in-kernel: fullmesh: re-add of the initial subflow endp

PATCH Superseded Abdul Wasey 3 participants 6 messages Oct 19 – Oct 21

Subsystems (4)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v4 cover mptcp: pm: in-kernel: fullmesh: re-add of the initial subflow endp

With fullmesh endpoints, removing and re-adding the endpoint used by the initial subflow never creates a new subflow from it: the closed initial subflow stays in the conn_list, and makes the PM think the remote ID 0 is already used, or picks its reset remote address.

Patch 1 fixes that, patch 2 adds tests for it.

Found with a router flapping one of its links: the link carrying the initial subflow never rejoined the existing connections. Tested on top of export-net: the new tests fail without patch 1, and the whole mptcp_join.sh passes with it. Patch 2 uses iptables like the other tests
there: when merged with net-next, it will need the same conversion to nftables as the others.

Changes in v4:
- Patch 2: only check the joins when the iptables rule has been added (Sashiko).
- v3: https://lore.kernel.org/mptcp/[email protected]/

Changes in v3:
- Patch 2: use iptables instead of init_nftables(), which is only in net-next (Sashiko).
- v2: https://lore.kernel.org/mptcp/[email protected]/

Changes in v2:
- Patch 1: also skip the subflows in TCP_CLOSE: the initial subflow can be disconnected and its context reset, clearing the 'closing' flag and zeroing its remote address (Sashiko).
- Patch 2: validate this case too, by resetting the initial subflow before removing its endpoint.
- v1: https://lore.kernel.org/mptcp/[email protected]/

Abdul Wasey (2):
mptcp: pm: in-kernel: fullmesh: skip closed subflows
selftests: mptcp: join: re-add the initial subflow endp with fullmesh

 net/mptcp/pm_kernel.c                         | 19 +++++-
 .../testing/selftests/net/mptcp/mptcp_join.sh | 61 +++++++++++++++++++
 2 files changed, 79 insertions(+), 1 deletion(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v4 1/2 mptcp: pm: in-kernel: fullmesh: skip closed subflows

With fullmesh endpoints, if the endpoint used by the initial subflow is removed and then added back, no new subflow is created from it: the connection never uses this local address again.

The initial subflow is kept in the conn_list once closed. If it was still established when closed, it keeps the local ID 0, which is also the ID used by the re-added endpoint, and fill_remote_addresses_fullmesh() then marks its remote ID as unavailable. If it was already in TCP_CLOSE, e.g. after a reset, it is disconnected and its context is reset: the 'closing' flag and the remote ID are cleared, and its remote address and port are zeroed. It is then picked as a remote address, with the address 0.0.0.0, the port 0 and the ID 0, which also marks the remote ID 0 as unavailable. In both cases, when the peer has a single address, all subflows use the remote ID 0, and no valid remote address is left.

Skip the subflows being closed or in TCP_CLOSE state, both when looking for the remote IDs already in use and when picking the remote addresses. __mptcp_subflow_active() cannot be used here: subflows still being established have to keep their remote ID marked as in use, to avoid creating duplicated subflows.

Without the fullmesh flag, the remote address is taken from the MPTCP socket, so this issue is specific to fullmesh endpoints.

Fixes 045e9d812868 ("mptcp: fix duplicate subflow creation")
---
 net/mptcp/pm_kernel.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
net/mptcp/pm_kernel.c +18 -1
index 1a7750813..24cdb170b 100644
@@ -199,6 +199,16 @@ fill_remote_addr(struct mptcp_sock *msk, struct mptcp_addr_info *local,
 	return 1;
 }
 
+/* Closed subflows can stay in the conn_list, e.g. the initial one: their
+ * addresses and IDs are not reliable, possibly even reset.
+ */
+static bool mptcp_subflow_is_closed(struct mptcp_subflow_context *subflow)
+{
+	struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+
+	return subflow->closing || inet_sk_state_load(ssk) == TCP_CLOSE;
+}
+
 static unsigned int
 fill_remote_addresses_fullmesh(struct mptcp_sock *msk,
 			       struct mptcp_addr_info *local,
@@ -216,11 +226,18 @@ fill_remote_addresses_fullmesh(struct mptcp_sock *msk,
 	 * already created by incoming ADD_ADDR
 	 */
 	bitmap_zero(unavail_id, MPTCP_PM_MAX_ADDR_ID + 1);
-	mptcp_for_each_subflow(msk, subflow)
+	mptcp_for_each_subflow(msk, subflow) {
+		if (mptcp_subflow_is_closed(subflow))
+			continue;
+
 		if (READ_ONCE(subflow->local_id) == local->id)
 			__set_bit(subflow->remote_id, unavail_id);
+	}
 
 	mptcp_for_each_subflow(msk, subflow) {
+		if (mptcp_subflow_is_closed(subflow))
+			continue;
+
 		ssk = mptcp_subflow_tcp_sock(subflow);
 		mptcp_remote_address((struct sock_common *)ssk, &addrs[i]);
 		addrs[i].id = READ_ONCE(subflow->remote_id);
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH mptcp-net v4 1/2] mptcp: pm: in-kernel: fullmesh: skip closed subflows

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] The fix is incomplete, and it adds a regression in a transient window.
- [Low] The commit message is inaccurate.

--

mptcp: pm: in-kernel: fullmesh: skip closed subflows

With this commit, fill_remote_addresses_fullmesh() skips subflows that are closing or in TCP_CLOSE state. The skip applies both when collecting the remote IDs already in use and when picking remote addresses. The goal is to let the fullmesh endpoint used by the initial subflow create a new subflow after it is removed and added back.

Quoted 6 lines

If it was already in TCP_CLOSE,
e.g. after a reset, it is disconnected and its context is reset: the 'closing' flag and the remote ID are cleared, and its remote address and port are zeroed. It is then picked as a remote address, with the address 0.0.0.0, the port 0 and the ID 0, which also marks the remote ID 0 as unavailable.

[Severity: Low]
Is this description of the reset path accurate?

__mptcp_subflow_disconnect() calls tcp_disconnect() and then mptcp_subflow_ctx_reset(). tcp_disconnect() does:

net/ipv4/tcp.c:tcp_disconnect() {
    ...
	inet->inet_dport = 0;

	inet_bhash2_reset_saddr(sk);
    ...
}

inet_reset_saddr() clears only the source addresses (inet_saddr, inet_rcv_saddr and the IPv6 equivalents). Nothing here seems to clear skc_daddr or skc_v6_daddr. So mptcp_remote_address() would return the peer's real address with port 0 and ID 0, not 0.0.0.0.

The conclusion that remote ID 0 ends up marked unavailable still seems to hold. Could the message describe the mechanism more precisely?

Quoted 31 lines
net/mptcp/pm_kernel.c +14 -1
index 1a7750813235..24cdb170ba62 100644
@@ -199,6 +199,16 @@ fill_remote_addr(struct mptcp_sock *msk, struct mptcp_addr_info *local,
 	return 1;
 }
 
+/* Closed subflows can stay in the conn_list, e.g. the initial one: their
+ * addresses and IDs are not reliable, possibly even reset.
+ */
+static bool mptcp_subflow_is_closed(struct mptcp_subflow_context *subflow)
+{
+	struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+
+	return subflow->closing || inet_sk_state_load(ssk) == TCP_CLOSE;
+}
+
 static unsigned int
 fill_remote_addresses_fullmesh(struct mptcp_sock *msk,
 			       struct mptcp_addr_info *local,
@@ -216,11 +226,18 @@ fill_remote_addresses_fullmesh(struct mptcp_sock *msk,
 	 * already created by incoming ADD_ADDR
 	 */
 	bitmap_zero(unavail_id, MPTCP_PM_MAX_ADDR_ID + 1);
-	mptcp_for_each_subflow(msk, subflow)
+	mptcp_for_each_subflow(msk, subflow) {
+		if (mptcp_subflow_is_closed(subflow))
+			continue;
+
 		if (READ_ONCE(subflow->local_id) == local->id)

net/mptcp/pm_kernel.c fill_remote_addresses_fullmesh(struct mptcp_sock *msk, · line 243

Quoted 10 lines
net/mptcp/pm_kernel.c +4 -0
 			__set_bit(subflow->remote_id, unavail_id);
+	}
 
 	mptcp_for_each_subflow(msk, subflow) {
+		if (mptcp_subflow_is_closed(subflow))
+			continue;
+
 		ssk = mptcp_subflow_tcp_sock(subflow);
 		mptcp_remote_address((struct sock_common *)ssk, &addrs[i]);
 		addrs[i].id = READ_ONCE(subflow->remote_id);

[Severity: High]
What happens here if the closed initial subflow was the only subflow toward the peer's ID 0 address?

In the fullmesh path, this second loop is the only source of remote candidates. Unlike fill_remote_addr(), it never falls back to the msk's own remote address:

net/mptcp/pm_kernel.c:fill_remote_addr() {
    ...
	mptcp_remote_address((struct sock_common *)sk, &remote);
    ...
}

So when all such subflows are skipped, fill_remote_addresses_fullmesh() returns 0. By that point, mptcp_pm_create_subflow_or_signal_addr() has already consumed the endpoint:

		__clear_bit(local.addr.id, msk->pm.id_avail_bitmap);
		...
			msk->pm.local_addr_used++;

		nr = fill_remote_addresses_vec(msk, &local.addr, fullmesh,
					       addrs, ARRAY_SIZE(addrs));
		if (nr == 0)
			continue;

The endpoint is then never retried for this connection.

This seems to affect two cases.

First, the case in the commit message still looks reachable with a single fullmesh endpoint. Say the endpoint used by the initial subflow is removed and added back through mptcp_nl_add_subflow_or_signal_addr(), which sets mpc_endpoint_id so the local ID maps to 0. If no other live subflow carries remote ID 0, nr is still 0. The connection then has no subflow until the msk timeout started in __mptcp_close_ssk() fires. Before the patch nr was also 0 here. Does that mean the fix is incomplete for this case?

Second, after a graceful close of the initial subflow, __mptcp_close_ssk() sets closing = 1, and __mptcp_subflow_disconnect() only does:

	} else {
		tcp_shutdown(ssk, SEND_SHUTDOWN);
	}

In FIN_WAIT1 or FIN_WAIT2, the subflow keeps its real daddr, dport and remote_id 0. Before this patch, adding a different fullmesh endpoint in that window created a working subflow to the peer. Now mptcp_subflow_is_closed() returns true because subflow->closing is set, so no subflow is created and the endpoint stays consumed. Is this a regression for that window? It can last as long as the peer does not send its FIN.

The follow-up selftest seems to cover only the two-endpoint case, where a second live subflow carries remote ID 0. Neither case above is exercised.

Could the fullmesh path also offer the msk's remote address for ID 0 (still honoring deny_id0), as fill_remote_addr() does, when no live subflow carries it?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261019190558.465270-1-w453y.me%40gmail.com
#3 lore raw

PATCH v4 2/2 selftests: mptcp: join: re-add the initial subflow endp with fullmesh

In reply to Abdul Wasey

The "delete and re-add" test validates the removal and the re-addition of the endpoint used by the initial subflow, but without the fullmesh flag.

Do the same with the fullmesh flag, and also after a reset of the initial subflow, before the removal of its endpoint. Without the previous patch, no new subflow is created after the re-addition.

The 'Fixes' tag here below is the same as the one from the previous
commit: this patch here is not fixing anything wrong in the selftests, but it validates the previous fix for an issue introduced by this commit ID.

Fixes 045e9d812868 ("mptcp: fix duplicate subflow creation")
---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 61 +++++++++++++++++++
 1 file changed, 61 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_join.sh +61 -0
index 18ce7136a..25fedf5b1 100755
@@ -4445,6 +4445,67 @@ endpoint_tests()
 		chk_rm_nr 4 4
 	fi
 
+	# remove and re-add the endpoint of the initial subflow, with fullmesh
+	if reset_with_events "delete and re-add, fullmesh" &&
+	   continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then
+		pm_nl_set_limits $ns1 0 2
+		pm_nl_set_limits $ns2 0 2
+		pm_nl_add_endpoint $ns2 10.0.1.2 id 1 dev ns2eth1 flags subflow,fullmesh
+		pm_nl_add_endpoint $ns2 10.0.2.2 id 2 dev ns2eth2 flags subflow,fullmesh
+		{ timeout_test=120 test_linkfail=128 speed=5 \
+			run_tests $ns1 $ns2 10.0.1.1 & } 2>/dev/null
+		local tests_pid=$!
+
+		wait_event ns2 MPTCP_LIB_EVENT_ESTABLISHED 1
+		wait_mpj 1
+		chk_subflow_nr "before delete id 0" 2
+
+		pm_nl_del_endpoint $ns2 1 10.0.1.2
+		sleep 0.5
+		chk_subflow_nr "after delete id 0" 1
+
+		pm_nl_add_endpoint $ns2 10.0.1.2 id 1 dev ns2eth1 flags subflow,fullmesh
+		wait_mpj 2
+		chk_subflow_nr "after re-add id 0" 2
+
+		mptcp_lib_kill_group_wait $tests_pid
+		kill_events_pids
+
+		chk_join_nr 2 2 2
+		chk_rm_nr 1 1
+	fi
+
+	# same, but the initial subflow is reset before removing its endpoint
+	if reset_with_events "delete and re-add, fullmesh, after reset" &&
+	   continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then
+		pm_nl_set_limits $ns1 0 2
+		pm_nl_set_limits $ns2 0 2
+		pm_nl_add_endpoint $ns2 10.0.1.2 id 1 dev ns2eth1 flags subflow,fullmesh
+		pm_nl_add_endpoint $ns2 10.0.2.2 id 2 dev ns2eth2 flags subflow,fullmesh
+		{ timeout_test=120 test_linkfail=128 speed=5 \
+			run_tests $ns1 $ns2 10.0.1.1 & } 2>/dev/null
+		local tests_pid=$!
+
+		wait_event ns2 MPTCP_LIB_EVENT_ESTABLISHED 1
+		wait_mpj 1
+		chk_subflow_nr "before reset" 2
+
+		if ip netns exec "${ns1}" ${iptables} -A INPUT -s "10.0.1.2" \
+		      -p tcp --tcp-option 30 -j REJECT --reject-with tcp-reset; then
+			wait_event ns2 MPTCP_LIB_EVENT_SUB_CLOSED 1
+			ip netns exec "${ns1}" ${iptables} -F INPUT
+
+			pm_nl_del_endpoint $ns2 1 10.0.1.2
+			pm_nl_add_endpoint $ns2 10.0.1.2 id 1 dev ns2eth1 flags subflow,fullmesh
+			wait_mpj 2
+			chk_mptcp_info subflows 2 subflows 2
+			chk_join_nr 2 2 2
+		fi
+
+		mptcp_lib_kill_group_wait $tests_pid
+		kill_events_pids
+	fi
+
 	# remove and re-add
 	if reset_with_events "delete re-add signal" &&
 	   continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then
Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH mptcp-net v4 2/2] selftests: mptcp: join: re-add the initial subflow endp with fullmesh

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In endpoint_tests() (tools/testing/selftests/net/mptcp/mptcp_join.sh), the new subtest…
- [Low] The "delete and re-add, fullmesh, after reset" subtest in endpoint_tests() never checks that the initial subflow was actually…

--

selftests: mptcp: join: re-add the initial subflow endp with fullmesh

This adds two subtests to endpoint_tests() in mptcp_join.sh. Both delete and re-add the endpoint of the initial subflow with the fullmesh flag. The second one first resets the initial subflow with an iptables REJECT rule, to validate the fix for 045e9d812868 ("mptcp: fix duplicate subflow creation").

Quoted 5 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +0 -0
index 18ce7136a2b0..25fedf5b12ec 100755
@@ -4445,6 +4445,67 @@ endpoint_tests()

[ ... ]

Quoted 7 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +7 -0
+	# same, but the initial subflow is reset before removing its endpoint
+	if reset_with_events "delete and re-add, fullmesh, after reset" &&
+	   continue_if mptcp_lib_kallsyms_has "subflow_rebuild_header$"; then
+		pm_nl_set_limits $ns1 0 2
+		pm_nl_set_limits $ns2 0 2
+		pm_nl_add_endpoint $ns2 10.0.1.2 id 1 dev ns2eth1 flags subflow,fullmesh
+		pm_nl_add_endpoint $ns2 10.0.2.2 id 2 dev ns2eth2 flags subflow,fullmesh

tools/testing/selftests/net/mptcp/mptcp_join.sh endpoint_tests() · line 4494

Quoted 10 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +10 -0
+		{ timeout_test=120 test_linkfail=128 speed=5 \
+			run_tests $ns1 $ns2 10.0.1.1 & } 2>/dev/null
+		local tests_pid=$!
+
+		wait_event ns2 MPTCP_LIB_EVENT_ESTABLISHED 1
+		wait_mpj 1
+		chk_subflow_nr "before reset" 2
+
+		if ip netns exec "${ns1}" ${iptables} -A INPUT -s "10.0.1.2" \
+		      -p tcp --tcp-option 30 -j REJECT --reject-with tcp-reset; then

[Severity: Low]
What does this subtest report if the iptables rule can't be installed, for example because the REJECT target is missing or the iptables-nft backend has a problem?

This if has no else branch. The reset wait, the endpoint delete and re-add, wait_mpj 2, chk_mptcp_info and chk_join_nr would all be skipped. The only check left is chk_subflow_nr "before reset", so the subtest would pass without ever running the reset path.

reset_with_tcp_filter() in the same file handles this case:

	if ! ip netns exec "${ns}" ${iptables} \
			-A "${chain}" \
			...
		mark_as_skipped "unable to set the filter rules"
		return 1
	fi

The existing "userspace pm no dup close events after error" subtest has the same no-else pattern.

Could an else branch calling mark_as_skipped (or fail_test) be added here?

tools/testing/selftests/net/mptcp/mptcp_join.sh endpoint_tests() · line 4496

Quoted 2 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +2 -0
+			wait_event ns2 MPTCP_LIB_EVENT_SUB_CLOSED 1
+			ip netns exec "${ns1}" ${iptables} -F INPUT

[Severity: Low]
Does anything here check that the initial subflow was actually reset before its endpoint is deleted?

wait_event() gives up quietly when it times out:

	for _ in $(seq 100); do
		count=$(grep -cw "type:${evt}" "${evts}")
		[ "${count}" -ge "${exp}" ] && break
		sleep 0.1
	done

The checks below (wait_mpj 2, chk_mptcp_info subflows 2 subflows 2, chk_join_nr 2 2 2) give the same results whether or not the reset happened. The initial subflow doesn't change the extra-subflow counters.

If no RST arrives, pm_nl_del_endpoint acts on an established initial subflow. __mptcp_close_ssk() then sets subflow->closing, and that alone satisfies mptcp_subflow_is_closed() in net/mptcp/pm_kernel.c:

	return subflow->closing || inet_sk_state_load(ssk) == TCP_CLOSE;

In that case this subtest behaves like "delete and re-add, fullmesh". It would still pass if the TCP_CLOSE half were removed. Only the reset path needs that half, because mptcp_subflow_ctx_reset() clears closing.

The "userspace pm no dup close events after error" subtest checks the reset after its wait_event calls with:

chk_subflows_total 1 1

Could a similar check, such as chk_subflows_total, chk_rst_nr or chk_evt_nr on MPTCP_LIB_EVENT_SUB_CLOSED, be added after this wait_event?

Quoted 7 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +7 -0
+
+			pm_nl_del_endpoint $ns2 1 10.0.1.2
+			pm_nl_add_endpoint $ns2 10.0.1.2 id 1 dev ns2eth1 flags subflow,fullmesh
+			wait_mpj 2
+			chk_mptcp_info subflows 2 subflows 2
+			chk_join_nr 2 2 2
+		fi

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261019190558.465270-1-w453y.me%40gmail.com
#5 lore raw
In reply to Abdul Wasey

Hi Abdul,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal (except selftest_mptcp_join): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Success! ✅
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Perf: Critical: No conclusion ❓
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/39580202297

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

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)