Skip to content

Commit f755be0

Browse files
matttbekuba-moo
authored andcommitted
mptcp: propagate shutdown to subflows when possible
When the MPTCP DATA FIN have been ACKed, there is no more MPTCP related metadata to exchange, and all subflows can be safely shutdown. Before this patch, the subflows were actually terminated at 'close()' time. That's certainly fine most of the time, but not when the userspace 'shutdown()' a connection, without close()ing it. When doing so, the subflows were staying in LAST_ACK state on one side -- and consequently in FIN_WAIT2 on the other side -- until the 'close()' of the MPTCP socket. Now, when the DATA FIN have been ACKed, all subflows are shutdown. A consequence of this is that the TCP 'FIN' flag can be set earlier now, but the end result is the same. This affects the packetdrill tests looking at the end of the MPTCP connections, but for a good reason. Note that tcp_shutdown() will check the subflow state, so no need to do that again before calling it. Fixes: 3721b9b ("mptcp: Track received DATA_FIN sequence number and add related helpers") Cc: stable@vger.kernel.org Fixes: 16a9a9d ("mptcp: Add helper to process acks of DATA_FIN") Reviewed-by: Mat Martineau <martineau@kernel.org> Reviewed-by: Geliang Tang <geliang@kernel.org> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> Link: https://patch.msgid.link/20250912-net-mptcp-fix-sft-connect-v1-1-d40e77cbbf02@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 71379e1 commit f755be0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

net/mptcp/protocol.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,20 @@ static void mptcp_close_wake_up(struct sock *sk)
371371
sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
372372
}
373373

374+
static void mptcp_shutdown_subflows(struct mptcp_sock *msk)
375+
{
376+
struct mptcp_subflow_context *subflow;
377+
378+
mptcp_for_each_subflow(msk, subflow) {
379+
struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
380+
bool slow;
381+
382+
slow = lock_sock_fast(ssk);
383+
tcp_shutdown(ssk, SEND_SHUTDOWN);
384+
unlock_sock_fast(ssk, slow);
385+
}
386+
}
387+
374388
/* called under the msk socket lock */
375389
static bool mptcp_pending_data_fin_ack(struct sock *sk)
376390
{
@@ -395,6 +409,7 @@ static void mptcp_check_data_fin_ack(struct sock *sk)
395409
break;
396410
case TCP_CLOSING:
397411
case TCP_LAST_ACK:
412+
mptcp_shutdown_subflows(msk);
398413
mptcp_set_state(sk, TCP_CLOSE);
399414
break;
400415
}
@@ -563,6 +578,7 @@ static bool mptcp_check_data_fin(struct sock *sk)
563578
mptcp_set_state(sk, TCP_CLOSING);
564579
break;
565580
case TCP_FIN_WAIT2:
581+
mptcp_shutdown_subflows(msk);
566582
mptcp_set_state(sk, TCP_CLOSE);
567583
break;
568584
default:

0 commit comments

Comments
 (0)