Skip to content

Commit

Permalink
mptcp: factor out __mptcp_close() without socket lock
Browse files Browse the repository at this point in the history
Factor out __mptcp_close() from mptcp_close(). The caller of
__mptcp_close() should hold the socket lock, and cancel mptcp work when
__mptcp_close() returns true.

This function will be used in the next commit.

Fixes: f296234 ("mptcp: Add handling of incoming MP_JOIN requests")
Fixes: 6aeed90 ("mptcp: fix race on unaccepted mptcp sockets")
Cc: [email protected]
Reviewed-by: Jiang Biao <[email protected]>
Reviewed-by: Mengen Sun <[email protected]>
Acked-by: Paolo Abeni <[email protected]>
Signed-off-by: Menglong Dong <[email protected]>
Signed-off-by: Mat Martineau <[email protected]>
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
menglongdong authored and kuba-moo committed Sep 29, 2022
1 parent 3e1308a commit 26d3e21
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions net/mptcp/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -2802,13 +2802,12 @@ static void __mptcp_destroy_sock(struct sock *sk)
sock_put(sk);
}

static void mptcp_close(struct sock *sk, long timeout)
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;

lock_sock(sk);
sk->sk_shutdown = SHUTDOWN_MASK;

if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) {
Expand Down Expand Up @@ -2850,6 +2849,17 @@ static void mptcp_close(struct sock *sk, long timeout)
} else {
mptcp_reset_timeout(msk, 0);
}

return do_cancel_work;
}

static void mptcp_close(struct sock *sk, long timeout)
{
bool do_cancel_work;

lock_sock(sk);

do_cancel_work = __mptcp_close(sk, timeout);
release_sock(sk);
if (do_cancel_work)
mptcp_cancel_work(sk);
Expand Down
1 change: 1 addition & 0 deletions net/mptcp/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ void mptcp_subflow_reset(struct sock *ssk);
void mptcp_subflow_queue_clean(struct sock *ssk);
void mptcp_sock_graft(struct sock *sk, struct socket *parent);
struct socket *__mptcp_nmpc_socket(const struct mptcp_sock *msk);
bool __mptcp_close(struct sock *sk, long timeout);

bool mptcp_addresses_equal(const struct mptcp_addr_info *a,
const struct mptcp_addr_info *b, bool use_port);
Expand Down

0 comments on commit 26d3e21

Please sign in to comment.