mptcp: pm: avoid sending RM_ADDR over the same subflow
Subsystems (3)
Matthieu Baerts (NGI0)
maintainercover mptcp: pm: avoid sending RM_ADDR over the same subflow
This should close the issue 612 reported by Frank Lorenz:
- Patch 1: avoid sending RM_ADDR over the same subflow as the one going to be removed.
- Patch 2: validate that in the MPTCP Join selftest.
---
Matthieu Baerts (NGI0) (2):
mptcp: pm: avoid sending RM_ADDR over same subflow
mptcp: pm: avoid sending RM_ADDR over same subflow
net/mptcp/pm.c | 52 +++++++++++++++++++------ tools/testing/selftests/net/mptcp/mptcp_join.sh | 36 +++++++++++++++++ 2 files changed, 77 insertions(+), 11 deletions(-)
---
base-commit: 9bf535999bf8e23b5f38fffb1a7ae7ee73115e98
change-id: 20260219-mptcp-issue-612-d94095f11d0e
Best regards,
Signature · 1 line
Matthieu Baerts (NGI0) <[email protected]>
Matthieu Baerts (NGI0)
maintainerPATCH 1/2 mptcp: pm: avoid sending RM_ADDR over same subflow
RM_ADDR are sent over an active subflow, the first one in the subflows list. There is then a high chance the initial subflow is picked. With the in-kernel PM, when an endpoint is removed, a RM_ADDR is sent, then linked subflows are closed. This is done for each active MPTCP connection.
MPTCP endpoints are likely removed because the attached network is no longer available or usable. In this case, it is better to avoid sending this RM_ADDR over the subflow that is going to be removed, but prefer sending it over another active and non stale subflow, if any.
This modification avoids situations where the other end is not notified when a subflow is no longer usable: typically when the endpoint linked to the initial subflow is removed, especially on the server side.
--- net/mptcp/pm.c | 52 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 11 deletions(-)
net/mptcp/pm.c +41 -11
@@ -212,9 +212,24 @@ void mptcp_pm_send_ack(struct mptcp_sock *msk,spin_lock_bh (&msk->pm.lock); } -void mptcp_pm_addr_send_ack (struct mptcp_sock *msk) +static bool subflow_in_rlist (const struct mptcp_subflow_context *subflow, +const struct mptcp_rm_list *rlist) { -struct mptcp_subflow_context *subflow, *alt =NULL ; +u8 i, id =subflow_get_local_id (subflow); + +for (i =0 ; i < rlist->nr; i++) { +if (rlist->ids[i] == id) +return true; + } + +return false; +} + +static void +mptcp_pm_addr_send_ack_avoid_list (struct mptcp_sock *msk, +const struct mptcp_rm_list *rlist) +{ +struct mptcp_subflow_context *subflow, *stale =NULL , *same_id =NULL ;msk_owned_by_me (msk);lockdep_assert_held (&msk->pm.lock);
@@ -225,18 +240,33 @@ void mptcp_pm_addr_send_ack(struct mptcp_sock *msk)mptcp_for_each_subflow (msk, subflow) {if (__mptcp_subflow_active (subflow)) { -if (!subflow->stale) { -mptcp_pm_send_ack (msk, subflow, false, false); -return ; +if (unlikely (subflow->stale)) { +if (!stale) + stale = subflow; + }else if (unlikely (rlist && +subflow_in_rlist (subflow, rlist))) { +if (!same_id) + same_id = subflow; + }else { + goto send_ack; } - -if (!alt) - alt = subflow; } } -if (alt) -mptcp_pm_send_ack (msk, alt, false, false); +if (same_id) + subflow = same_id; +else if (stale) + subflow = stale; +else +return ; + +send_ack: +mptcp_pm_send_ack (msk, subflow, false, false); +} + +void mptcp_pm_addr_send_ack (struct mptcp_sock *msk) +{ +mptcp_pm_addr_send_ack_avoid_list (msk,NULL ); } int mptcp_pm_mp_prio_send_ack(struct mptcp_sock *msk,
@@ -470,7 +500,7 @@ int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_ msk->pm.rm_list_tx = *rm_list; rm_addr |=BIT (MPTCP_RM_ADDR_SIGNAL );WRITE_ONCE (msk->pm.addr_signal, rm_addr); -mptcp_pm_addr_send_ack (msk); +mptcp_pm_addr_send_ack_avoid_list (msk, rm_list);return 0 ; }
Signature · 1 line
2.51.0
Matthieu Baerts
maintainerRe: [PATCH mptcp-net 1/2] mptcp: pm: avoid sending RM_ADDR over same subflow
Quoted 55 lines · On 19/02/2026 20:01, Matthieu Baerts (NGI0) wrote:
RM_ADDRare sent over an active subflow, the first one in the subflows list. There is then a high chance the initial subflow is picked. With the in-kernel PM, when an endpoint is removed, aRM_ADDRis sent, then linked subflows are closed. This is done for each active MPTCP connection.MPTCP endpoints are likely removed because the attached network is no longer available or usable. In this case, it is better to avoid sending this
RM_ADDRover the subflow that is going to be removed, but prefer sending it over another active and non stale subflow, if any.This modification avoids situations where the other end is not notified when a subflow is no longer usable: typically when the endpoint linked to the initial subflow is removed, especially on the server side.
Fixes 8dd5efb1f91b ("mptcp: send ack for rm_addr")Reported-by Frank LorenzSigned-off-by Matthieu Baerts (NGI0) <[email protected]>--- net/mptcp/pm.c | 52 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 11 deletions(-)net/mptcp/pm.c +17
-2@@ -212,9 +212,24 @@ void mptcp_pm_send_ack(struct mptcp_sock *msk,spin_lock_bh (&msk->pm.lock); } -void mptcp_pm_addr_send_ack (struct mptcp_sock *msk) +static bool subflow_in_rlist (const struct mptcp_subflow_context *subflow, +const struct mptcp_rm_list *rlist) { -struct mptcp_subflow_context *subflow, *alt =NULL ; +u8 i, id =subflow_get_local_id (subflow); + +for (i =0 ; i < rlist->nr; i++) { +if (rlist->ids[i] == id) +return true; + } + +return false; +} + +static void +mptcp_pm_addr_send_ack_avoid_list (struct mptcp_sock *msk, +const struct mptcp_rm_list *rlist) +{ +struct mptcp_subflow_context *subflow, *stale =NULL , *same_id =NULL ;msk_owned_by_me (msk);lockdep_assert_held (&msk->pm.lock);
net/mptcp/pm.c void mptcp_pm_addr_send_ack(struct mptcp_sock *msk) · line 242
Quoted 3 lines
net/mptcp/pm.c +0
-0@@ -225,18 +240,33 @@ void mptcp_pm_addr_send_ack(struct mptcp_sock *msk)mptcp_for_each_subflow (msk, subflow) {if (__mptcp_subflow_active (subflow)) {
I should probably remove one level by doing:
if (!__mptcp_subflow_active(subflow))
continue;
I can send a v2 later, but feel free to review, it doesn't change the fix here.
Quoted 15 lines
net/mptcp/pm.c +9
-5-if (!subflow->stale) { -mptcp_pm_send_ack (msk, subflow, false, false); -return ; +if (unlikely (subflow->stale)) { +if (!stale) + stale = subflow; + }else if (unlikely (rlist && +subflow_in_rlist (subflow, rlist))) { +if (!same_id) + same_id = subflow; + }else { + goto send_ack; } - -if (!alt)
net/mptcp/pm.c void mptcp_pm_addr_send_ack(struct mptcp_sock *msk) · line 259
Quoted 10 lines
net/mptcp/pm.c +4
-3- alt = subflow; } } -if (alt) -mptcp_pm_send_ack (msk, alt, false, false); +if (same_id) + subflow = same_id; +else if (stale) + subflow = stale;
Note: in my initial version, I only used one alternative for both "stale" and "same id" subflows. I guess it is better to send over the same subflow than a stale one, hence the priority, but there are then a few more lines of code. To be discussed.
Quoted 15 lines
net/mptcp/pm.c +10
-0+else +return ; + +send_ack: +mptcp_pm_send_ack (msk, subflow, false, false); +} + +void mptcp_pm_addr_send_ack (struct mptcp_sock *msk) +{ +mptcp_pm_addr_send_ack_avoid_list (msk,NULL ); } int mptcp_pm_mp_prio_send_ack(struct mptcp_sock *msk,
net/mptcp/pm.c int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_ · line 506
Quoted 8 lines
net/mptcp/pm.c +1
-1@@ -470,7 +500,7 @@ int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_ msk->pm.rm_list_tx = *rm_list; rm_addr |=BIT (MPTCP_RM_ADDR_SIGNAL );WRITE_ONCE (msk->pm.addr_signal, rm_addr); -mptcp_pm_addr_send_ack (msk); +mptcp_pm_addr_send_ack_avoid_list (msk, rm_list);return 0 ; }
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts (NGI0)
maintainerPATCH 2/2 mptcp: pm: avoid sending RM_ADDR over same subflow
In reply to Matthieu Baerts (NGI0)RM_ADDR are sent over an active subflow, the first one in the subflows list. There is then a high chance the initial subflow is picked. With the in-kernel PM, when an endpoint is removed, a RM_ADDR is sent, then linked subflows are closed. This is done for each active MPTCP connection.
MPTCP endpoints are likely removed because the attached network is no longer available or usable. In this case, it is better to avoid sending this RM_ADDR over the subflow that is going to be removed, but prefer sending it over another active and non stale subflow, if any.
This modification avoids situations where the other end is not notified when a subflow is no longer usable: typically when the endpoint linked to the initial subflow is removed, especially on the server side.
--- tools/testing/selftests/net/mptcp/mptcp_join.sh | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_join.sh +36 -0
@@ -104,6 +104,24 @@ CBPF_MPTCP_SUBOPTION_ADD_ADDR="14, 6 0 0 65535, 6 0 0 0" +# IPv4: TCP hdr of 48B, a first suboption of 12B (DACK8), the RM_ADDR suboption +# generated using "nfbpf_compile '(ip[32] & 0xf0) == 0xc0 && ip[53] == 0x0c && +# (ip[66] & 0xf0) == 0x40'" +CBPF_MPTCP_SUBOPTION_RM_ADDR="13, + 48 0 0 0, + 84 0 0 240, + 21 0 9 64, + 48 0 0 32, + 84 0 0 240, + 21 0 6 192, + 48 0 0 53, + 21 0 4 12, + 48 0 0 66, + 84 0 0 240, + 21 0 1 64, + 6 0 0 65535, + 6 0 0 0" + init_partial() { capout=$(mktemp)
@@ -4217,6 +4235,14 @@ endpoint_tests() chk_subflow_nr "after no reject" 3 chk_mptcp_info subflows 2 subflows 2 + # To make sure RM_ADDR are sent over a different subflow, but + # allow the rest to quickly and cleanly close the subflow + local ipt=1 + ip netns exec "${ns2}" ${iptables} -I OUTPUT -s "10.0.1.2" \ + -p tcp -m tcp --tcp-option 30 \ + -m bpf --bytecode \ + "$CBPF_MPTCP_SUBOPTION_RM_ADDR" \ + -j DROP || ipt=0 local i for i in $(seq 3); do pm_nl_del_endpoint $ns2 1 10.0.1.2
@@ -4229,6 +4255,7 @@ endpoint_tests() chk_subflow_nr "after re-add id 0 ($i)" 3 chk_mptcp_info subflows 3 subflows 3 done + [ ${ipt} = 1 ] && ip netns exec "${ns2}" ${iptables} -D OUTPUT 1 mptcp_lib_kill_group_wait $tests_pid
@@ -4288,11 +4315,20 @@ endpoint_tests() chk_mptcp_info subflows 2 subflows 2 chk_mptcp_info add_addr_signal 2 add_addr_accepted 2 + # To make sure RM_ADDR are sent over a different subflow, but + # allow the rest to quickly and cleanly close the subflow + local ipt=1 + ip netns exec "${ns1}" ${iptables} -I OUTPUT -s "10.0.1.1" \ + -p tcp -m tcp --tcp-option 30 \ + -m bpf --bytecode \ + "$CBPF_MPTCP_SUBOPTION_RM_ADDR" \ + -j DROP || ipt=0 pm_nl_del_endpoint $ns1 42 10.0.1.1 sleep 0.5 chk_subflow_nr "after delete ID 0" 2 chk_mptcp_info subflows 2 subflows 2 chk_mptcp_info add_addr_signal 2 add_addr_accepted 2 + [ ${ipt} = 1 ] && ip netns exec "${ns1}" ${iptables} -D OUTPUT 1 pm_nl_add_endpoint $ns1 10.0.1.1 id 99 flags signal wait_mpj 4
Signature · 1 line
2.51.0
Hi Matthieu,
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! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/22196601516
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/b9e12177fa11
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1055636
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-normalFor 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)