Commit 26d3e21c authored by Menglong Dong's avatar Menglong Dong Committed by Jakub Kicinski

mptcp: factor out __mptcp_close() without socket lock

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: f296234c ("mptcp: Add handling of incoming MP_JOIN requests")
Fixes: 6aeed904 ("mptcp: fix race on unaccepted mptcp sockets")
Cc: stable@vger.kernel.org
Reviewed-by: default avatarJiang Biao <benbjiang@tencent.com>
Reviewed-by: default avatarMengen Sun <mengensun@tencent.com>
Acked-by: default avatarPaolo Abeni <pabeni@redhat.com>
Signed-off-by: default avatarMenglong Dong <imagedong@tencent.com>
Signed-off-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 3e1308a7
...@@ -2802,13 +2802,12 @@ static void __mptcp_destroy_sock(struct sock *sk) ...@@ -2802,13 +2802,12 @@ static void __mptcp_destroy_sock(struct sock *sk)
sock_put(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_subflow_context *subflow;
struct mptcp_sock *msk = mptcp_sk(sk); struct mptcp_sock *msk = mptcp_sk(sk);
bool do_cancel_work = false; bool do_cancel_work = false;
lock_sock(sk);
sk->sk_shutdown = SHUTDOWN_MASK; sk->sk_shutdown = SHUTDOWN_MASK;
if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) { if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) {
...@@ -2850,6 +2849,17 @@ static void mptcp_close(struct sock *sk, long timeout) ...@@ -2850,6 +2849,17 @@ static void mptcp_close(struct sock *sk, long timeout)
} else { } else {
mptcp_reset_timeout(msk, 0); 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); release_sock(sk);
if (do_cancel_work) if (do_cancel_work)
mptcp_cancel_work(sk); mptcp_cancel_work(sk);
......
...@@ -612,6 +612,7 @@ void mptcp_subflow_reset(struct sock *ssk); ...@@ -612,6 +612,7 @@ void mptcp_subflow_reset(struct sock *ssk);
void mptcp_subflow_queue_clean(struct sock *ssk); void mptcp_subflow_queue_clean(struct sock *ssk);
void mptcp_sock_graft(struct sock *sk, struct socket *parent); void mptcp_sock_graft(struct sock *sk, struct socket *parent);
struct socket *__mptcp_nmpc_socket(const struct mptcp_sock *msk); 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, bool mptcp_addresses_equal(const struct mptcp_addr_info *a,
const struct mptcp_addr_info *b, bool use_port); const struct mptcp_addr_info *b, bool use_port);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment