Commit e76c8ef5 authored by Paolo Abeni's avatar Paolo Abeni Committed by Jakub Kicinski

mptcp: refactor mptcp_stream_accept()

Rewrite the mptcp socket accept op, leveraging the new
__inet_accept() helper.

This way we can avoid acquiring the new socket lock twice
and we can avoid a couple of indirect calls.
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
Reviewed-by: default avatarMatthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: default avatarMat Martineau <martineau@kernel.org>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 711bdd51
...@@ -3747,6 +3747,7 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock, ...@@ -3747,6 +3747,7 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
{ {
struct mptcp_sock *msk = mptcp_sk(sock->sk); struct mptcp_sock *msk = mptcp_sk(sock->sk);
struct socket *ssock; struct socket *ssock;
struct sock *newsk;
int err; int err;
pr_debug("msk=%p", msk); pr_debug("msk=%p", msk);
...@@ -3758,17 +3759,20 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock, ...@@ -3758,17 +3759,20 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
if (!ssock) if (!ssock)
return -EINVAL; return -EINVAL;
err = ssock->ops->accept(sock, newsock, flags, kern); newsk = mptcp_accept(sock->sk, flags, &err, kern);
if (err == 0 && !mptcp_is_tcpsk(newsock->sk)) { if (!newsk)
struct mptcp_sock *msk = mptcp_sk(newsock->sk); return err;
lock_sock(newsk);
__inet_accept(sock, newsock, newsk);
if (!mptcp_is_tcpsk(newsock->sk)) {
struct mptcp_sock *msk = mptcp_sk(newsk);
struct mptcp_subflow_context *subflow; struct mptcp_subflow_context *subflow;
struct sock *newsk = newsock->sk;
set_bit(SOCK_CUSTOM_SOCKOPT, &newsock->flags); set_bit(SOCK_CUSTOM_SOCKOPT, &newsock->flags);
msk->in_accept_queue = 0; msk->in_accept_queue = 0;
lock_sock(newsk);
/* set ssk->sk_socket of accept()ed flows to mptcp socket. /* set ssk->sk_socket of accept()ed flows to mptcp socket.
* This is needed so NOSPACE flag can be set from tcp stack. * This is needed so NOSPACE flag can be set from tcp stack.
*/ */
...@@ -3789,11 +3793,10 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock, ...@@ -3789,11 +3793,10 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
if (unlikely(list_empty(&msk->conn_list))) if (unlikely(list_empty(&msk->conn_list)))
inet_sk_state_store(newsk, TCP_CLOSE); inet_sk_state_store(newsk, TCP_CLOSE);
} }
release_sock(newsk);
} }
release_sock(newsk);
return err; return 0;
} }
static __poll_t mptcp_check_writeable(struct mptcp_sock *msk) static __poll_t mptcp_check_writeable(struct mptcp_sock *msk)
......
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