diff mbox series

[net,1/6] mptcp: do not wait for bare sockets' timeout

Message ID 20230207-upstream-net-20230207-various-fix-6-2-v1-1-2031b495c7cc@tessares.net (mailing list archive)
State Accepted
Commit d4e85922e3e7ef2071f91f65e61629b60f3a9cf4
Headers show
Series mptcp: fixes for v6.2 | expand

Commit Message

Matthieu Baerts Feb. 7, 2023, 1:04 p.m. UTC
From: Paolo Abeni <pabeni@redhat.com>

If the peer closes all the existing subflows for a given
mptcp socket and later the application closes it, the current
implementation let it survive until the timewait timeout expires.

While the above is allowed by the protocol specification it
consumes resources for almost no reason and additionally
causes sporadic self-tests failures.

Let's move the mptcp socket to the TCP_CLOSE state when there are
no alive subflows at close time, so that the allocated resources
will be freed immediately.

Fixes: e16163b6e2b7 ("mptcp: refactor shutdown and close")
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
 net/mptcp/protocol.c | 9 +++++++++
 1 file changed, 9 insertions(+)
diff mbox series


diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 8cd6cc67c2c5..bc6c1f62a690 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2897,6 +2897,7 @@  bool __mptcp_close(struct sock *sk, long timeout)
 	struct mptcp_subflow_context *subflow;
 	struct mptcp_sock *msk = mptcp_sk(sk);
 	bool do_cancel_work = false;
+	int subflows_alive = 0;
 	sk->sk_shutdown = SHUTDOWN_MASK;
@@ -2922,6 +2923,8 @@  bool __mptcp_close(struct sock *sk, long timeout)
 		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
 		bool slow = lock_sock_fast_nested(ssk);
+		subflows_alive += ssk->sk_state != TCP_CLOSE;
 		/* since the close timeout takes precedence on the fail one,
 		 * cancel the latter
@@ -2937,6 +2940,12 @@  bool __mptcp_close(struct sock *sk, long timeout)
+	/* all the subflows are closed, only timeout can change the msk
+	 * state, let's not keep resources busy for no reasons
+	 */
+	if (subflows_alive == 0)
+		inet_sk_state_store(sk, TCP_CLOSE);
 	pr_debug("msk=%p state=%d", sk, sk->sk_state);
 	if (msk->token)