Skip to content

Commit d4e8592

Browse files
Paolo Abenidavem330
authored andcommitted
mptcp: do not wait for bare sockets' timeout
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: e16163b ("mptcp: refactor shutdown and close") Cc: [email protected] Signed-off-by: Paolo Abeni <[email protected]> Reviewed-by: Matthieu Baerts <[email protected]> Signed-off-by: Matthieu Baerts <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1a3245f commit d4e8592

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

net/mptcp/protocol.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2897,6 +2897,7 @@ bool __mptcp_close(struct sock *sk, long timeout)
28972897
struct mptcp_subflow_context *subflow;
28982898
struct mptcp_sock *msk = mptcp_sk(sk);
28992899
bool do_cancel_work = false;
2900+
int subflows_alive = 0;
29002901

29012902
sk->sk_shutdown = SHUTDOWN_MASK;
29022903

@@ -2922,6 +2923,8 @@ bool __mptcp_close(struct sock *sk, long timeout)
29222923
struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
29232924
bool slow = lock_sock_fast_nested(ssk);
29242925

2926+
subflows_alive += ssk->sk_state != TCP_CLOSE;
2927+
29252928
/* since the close timeout takes precedence on the fail one,
29262929
* cancel the latter
29272930
*/
@@ -2937,6 +2940,12 @@ bool __mptcp_close(struct sock *sk, long timeout)
29372940
}
29382941
sock_orphan(sk);
29392942

2943+
/* all the subflows are closed, only timeout can change the msk
2944+
* state, let's not keep resources busy for no reasons
2945+
*/
2946+
if (subflows_alive == 0)
2947+
inet_sk_state_store(sk, TCP_CLOSE);
2948+
29402949
sock_hold(sk);
29412950
pr_debug("msk=%p state=%d", sk, sk->sk_state);
29422951
if (msk->token)

0 commit comments

Comments
 (0)