]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mptcp: propagate shutdown to subflows when possible
authorMatthieu Baerts (NGI0) <matttbe@kernel.org>
Mon, 22 Sep 2025 01:46:30 +0000 (21:46 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 2 Oct 2025 11:35:44 +0000 (13:35 +0200)
[ Upstream commit f755be0b1ff429a2ecf709beeb1bcd7abc111c2b ]

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: 3721b9b64676 ("mptcp: Track received DATA_FIN sequence number and add related helpers")
Cc: stable@vger.kernel.org
Fixes: 16a9a9da1723 ("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>
[ Adjust context ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/mptcp/protocol.c

index f33c3150e6909190fa69841bbe6a46a75813e759..1342c31df0c4023b6ed9dc7c95217d32f97b9288 100644 (file)
@@ -326,6 +326,20 @@ static void mptcp_stop_timer(struct sock *sk)
        mptcp_sk(sk)->timer_ival = 0;
 }
 
+static void mptcp_shutdown_subflows(struct mptcp_sock *msk)
+{
+       struct mptcp_subflow_context *subflow;
+
+       mptcp_for_each_subflow(msk, subflow) {
+               struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+               bool slow;
+
+               slow = lock_sock_fast(ssk);
+               tcp_shutdown(ssk, SEND_SHUTDOWN);
+               unlock_sock_fast(ssk, slow);
+       }
+}
+
 static void mptcp_check_data_fin_ack(struct sock *sk)
 {
        struct mptcp_sock *msk = mptcp_sk(sk);
@@ -348,6 +362,7 @@ static void mptcp_check_data_fin_ack(struct sock *sk)
                        break;
                case TCP_CLOSING:
                case TCP_LAST_ACK:
+                       mptcp_shutdown_subflows(msk);
                        inet_sk_state_store(sk, TCP_CLOSE);
                        sk->sk_state_change(sk);
                        break;
@@ -430,6 +445,7 @@ static void mptcp_check_data_fin(struct sock *sk)
                        inet_sk_state_store(sk, TCP_CLOSING);
                        break;
                case TCP_FIN_WAIT2:
+                       mptcp_shutdown_subflows(msk);
                        inet_sk_state_store(sk, TCP_CLOSE);
                        // @@ Close subflows now?
                        break;