Commit c693a851 authored by Geliang Tang's avatar Geliang Tang Committed by David S. Miller

mptcp: use mptcp_set_state

This patch replaces all the 'inet_sk_state_store()' calls under net/mptcp
with the new helper mptcp_set_state().

Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/460Signed-off-by: default avatarGeliang Tang <geliang.tang@linux.dev>
Acked-by: default avatarPaolo Abeni <pabeni@redhat.com>
Reviewed-by: default avatarMatthieu Baerts <matttbe@kernel.org>
Signed-off-by: default avatarMatthieu Baerts <matttbe@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d9cd27b8
...@@ -1048,6 +1048,11 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk, ...@@ -1048,6 +1048,11 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
if (err) if (err)
return err; return err;
/* We don't use mptcp_set_state() here because it needs to be called
* under the msk socket lock. For the moment, that will not bring
* anything more than only calling inet_sk_state_store(), because the
* old status is known (TCP_CLOSE).
*/
inet_sk_state_store(newsk, TCP_LISTEN); inet_sk_state_store(newsk, TCP_LISTEN);
lock_sock(ssk); lock_sock(ssk);
err = __inet_listen_sk(ssk, backlog); err = __inet_listen_sk(ssk, backlog);
......
...@@ -429,11 +429,11 @@ static void mptcp_check_data_fin_ack(struct sock *sk) ...@@ -429,11 +429,11 @@ static void mptcp_check_data_fin_ack(struct sock *sk)
switch (sk->sk_state) { switch (sk->sk_state) {
case TCP_FIN_WAIT1: case TCP_FIN_WAIT1:
inet_sk_state_store(sk, TCP_FIN_WAIT2); mptcp_set_state(sk, TCP_FIN_WAIT2);
break; break;
case TCP_CLOSING: case TCP_CLOSING:
case TCP_LAST_ACK: case TCP_LAST_ACK:
inet_sk_state_store(sk, TCP_CLOSE); mptcp_set_state(sk, TCP_CLOSE);
break; break;
} }
...@@ -594,13 +594,13 @@ static bool mptcp_check_data_fin(struct sock *sk) ...@@ -594,13 +594,13 @@ static bool mptcp_check_data_fin(struct sock *sk)
switch (sk->sk_state) { switch (sk->sk_state) {
case TCP_ESTABLISHED: case TCP_ESTABLISHED:
inet_sk_state_store(sk, TCP_CLOSE_WAIT); mptcp_set_state(sk, TCP_CLOSE_WAIT);
break; break;
case TCP_FIN_WAIT1: case TCP_FIN_WAIT1:
inet_sk_state_store(sk, TCP_CLOSING); mptcp_set_state(sk, TCP_CLOSING);
break; break;
case TCP_FIN_WAIT2: case TCP_FIN_WAIT2:
inet_sk_state_store(sk, TCP_CLOSE); mptcp_set_state(sk, TCP_CLOSE);
break; break;
default: default:
/* Other states not expected */ /* Other states not expected */
...@@ -775,7 +775,7 @@ static bool __mptcp_subflow_error_report(struct sock *sk, struct sock *ssk) ...@@ -775,7 +775,7 @@ static bool __mptcp_subflow_error_report(struct sock *sk, struct sock *ssk)
*/ */
ssk_state = inet_sk_state_load(ssk); ssk_state = inet_sk_state_load(ssk);
if (ssk_state == TCP_CLOSE && !sock_flag(sk, SOCK_DEAD)) if (ssk_state == TCP_CLOSE && !sock_flag(sk, SOCK_DEAD))
inet_sk_state_store(sk, ssk_state); mptcp_set_state(sk, ssk_state);
WRITE_ONCE(sk->sk_err, -err); WRITE_ONCE(sk->sk_err, -err);
/* This barrier is coupled with smp_rmb() in mptcp_poll() */ /* This barrier is coupled with smp_rmb() in mptcp_poll() */
...@@ -2463,7 +2463,7 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, ...@@ -2463,7 +2463,7 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
inet_sk_state_load(msk->first) == TCP_CLOSE) { inet_sk_state_load(msk->first) == TCP_CLOSE) {
if (sk->sk_state != TCP_ESTABLISHED || if (sk->sk_state != TCP_ESTABLISHED ||
msk->in_accept_queue || sock_flag(sk, SOCK_DEAD)) { msk->in_accept_queue || sock_flag(sk, SOCK_DEAD)) {
inet_sk_state_store(sk, TCP_CLOSE); mptcp_set_state(sk, TCP_CLOSE);
mptcp_close_wake_up(sk); mptcp_close_wake_up(sk);
} else { } else {
mptcp_start_tout_timer(sk); mptcp_start_tout_timer(sk);
...@@ -2558,7 +2558,7 @@ static void mptcp_check_fastclose(struct mptcp_sock *msk) ...@@ -2558,7 +2558,7 @@ static void mptcp_check_fastclose(struct mptcp_sock *msk)
WRITE_ONCE(sk->sk_err, ECONNRESET); WRITE_ONCE(sk->sk_err, ECONNRESET);
} }
inet_sk_state_store(sk, TCP_CLOSE); mptcp_set_state(sk, TCP_CLOSE);
WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK); WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
smp_mb__before_atomic(); /* SHUTDOWN must be visible first */ smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags); set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags);
...@@ -2693,7 +2693,7 @@ static void mptcp_do_fastclose(struct sock *sk) ...@@ -2693,7 +2693,7 @@ static void mptcp_do_fastclose(struct sock *sk)
struct mptcp_subflow_context *subflow, *tmp; struct mptcp_subflow_context *subflow, *tmp;
struct mptcp_sock *msk = mptcp_sk(sk); struct mptcp_sock *msk = mptcp_sk(sk);
inet_sk_state_store(sk, TCP_CLOSE); mptcp_set_state(sk, TCP_CLOSE);
mptcp_for_each_subflow_safe(msk, subflow, tmp) mptcp_for_each_subflow_safe(msk, subflow, tmp)
__mptcp_close_ssk(sk, mptcp_subflow_tcp_sock(subflow), __mptcp_close_ssk(sk, mptcp_subflow_tcp_sock(subflow),
subflow, MPTCP_CF_FASTCLOSE); subflow, MPTCP_CF_FASTCLOSE);
...@@ -2911,7 +2911,7 @@ static int mptcp_close_state(struct sock *sk) ...@@ -2911,7 +2911,7 @@ static int mptcp_close_state(struct sock *sk)
int next = (int)new_state[sk->sk_state]; int next = (int)new_state[sk->sk_state];
int ns = next & TCP_STATE_MASK; int ns = next & TCP_STATE_MASK;
inet_sk_state_store(sk, ns); mptcp_set_state(sk, ns);
return next & TCP_ACTION_FIN; return next & TCP_ACTION_FIN;
} }
...@@ -3022,7 +3022,7 @@ bool __mptcp_close(struct sock *sk, long timeout) ...@@ -3022,7 +3022,7 @@ bool __mptcp_close(struct sock *sk, long timeout)
if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) { if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) {
mptcp_check_listen_stop(sk); mptcp_check_listen_stop(sk);
inet_sk_state_store(sk, TCP_CLOSE); mptcp_set_state(sk, TCP_CLOSE);
goto cleanup; goto cleanup;
} }
...@@ -3065,7 +3065,7 @@ bool __mptcp_close(struct sock *sk, long timeout) ...@@ -3065,7 +3065,7 @@ bool __mptcp_close(struct sock *sk, long timeout)
* state, let's not keep resources busy for no reasons * state, let's not keep resources busy for no reasons
*/ */
if (subflows_alive == 0) if (subflows_alive == 0)
inet_sk_state_store(sk, TCP_CLOSE); mptcp_set_state(sk, TCP_CLOSE);
sock_hold(sk); sock_hold(sk);
pr_debug("msk=%p state=%d", sk, sk->sk_state); pr_debug("msk=%p state=%d", sk, sk->sk_state);
...@@ -3131,7 +3131,7 @@ static int mptcp_disconnect(struct sock *sk, int flags) ...@@ -3131,7 +3131,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)
return -EBUSY; return -EBUSY;
mptcp_check_listen_stop(sk); mptcp_check_listen_stop(sk);
inet_sk_state_store(sk, TCP_CLOSE); mptcp_set_state(sk, TCP_CLOSE);
mptcp_stop_rtx_timer(sk); mptcp_stop_rtx_timer(sk);
mptcp_stop_tout_timer(sk); mptcp_stop_tout_timer(sk);
...@@ -3219,7 +3219,7 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk, ...@@ -3219,7 +3219,7 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk,
/* this can't race with mptcp_close(), as the msk is /* this can't race with mptcp_close(), as the msk is
* not yet exposted to user-space * not yet exposted to user-space
*/ */
inet_sk_state_store(nsk, TCP_ESTABLISHED); mptcp_set_state(nsk, TCP_ESTABLISHED);
/* The msk maintain a ref to each subflow in the connections list */ /* The msk maintain a ref to each subflow in the connections list */
WRITE_ONCE(msk->first, ssk); WRITE_ONCE(msk->first, ssk);
...@@ -3640,7 +3640,7 @@ static int mptcp_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) ...@@ -3640,7 +3640,7 @@ static int mptcp_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
if (IS_ERR(ssk)) if (IS_ERR(ssk))
return PTR_ERR(ssk); return PTR_ERR(ssk);
inet_sk_state_store(sk, TCP_SYN_SENT); mptcp_set_state(sk, TCP_SYN_SENT);
subflow = mptcp_subflow_ctx(ssk); subflow = mptcp_subflow_ctx(ssk);
#ifdef CONFIG_TCP_MD5SIG #ifdef CONFIG_TCP_MD5SIG
/* no MPTCP if MD5SIG is enabled on this socket or we may run out of /* no MPTCP if MD5SIG is enabled on this socket or we may run out of
...@@ -3690,7 +3690,7 @@ static int mptcp_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) ...@@ -3690,7 +3690,7 @@ static int mptcp_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
if (unlikely(err)) { if (unlikely(err)) {
/* avoid leaving a dangling token in an unconnected socket */ /* avoid leaving a dangling token in an unconnected socket */
mptcp_token_destroy(msk); mptcp_token_destroy(msk);
inet_sk_state_store(sk, TCP_CLOSE); mptcp_set_state(sk, TCP_CLOSE);
return err; return err;
} }
...@@ -3779,13 +3779,13 @@ static int mptcp_listen(struct socket *sock, int backlog) ...@@ -3779,13 +3779,13 @@ static int mptcp_listen(struct socket *sock, int backlog)
goto unlock; goto unlock;
} }
inet_sk_state_store(sk, TCP_LISTEN); mptcp_set_state(sk, TCP_LISTEN);
sock_set_flag(sk, SOCK_RCU_FREE); sock_set_flag(sk, SOCK_RCU_FREE);
lock_sock(ssk); lock_sock(ssk);
err = __inet_listen_sk(ssk, backlog); err = __inet_listen_sk(ssk, backlog);
release_sock(ssk); release_sock(ssk);
inet_sk_state_store(sk, inet_sk_state_load(ssk)); mptcp_set_state(sk, inet_sk_state_load(ssk));
if (!err) { if (!err) {
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
...@@ -3863,7 +3863,7 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock, ...@@ -3863,7 +3863,7 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
__mptcp_close_ssk(newsk, msk->first, __mptcp_close_ssk(newsk, msk->first,
mptcp_subflow_ctx(msk->first), 0); mptcp_subflow_ctx(msk->first), 0);
if (unlikely(list_is_singular(&msk->conn_list))) if (unlikely(list_is_singular(&msk->conn_list)))
inet_sk_state_store(newsk, TCP_CLOSE); mptcp_set_state(newsk, TCP_CLOSE);
} }
} else { } else {
MPTCP_INC_STATS(sock_net(ssk), MPTCP_INC_STATS(sock_net(ssk),
......
...@@ -425,7 +425,7 @@ void __mptcp_sync_state(struct sock *sk, int state) ...@@ -425,7 +425,7 @@ void __mptcp_sync_state(struct sock *sk, int state)
__mptcp_propagate_sndbuf(sk, msk->first); __mptcp_propagate_sndbuf(sk, msk->first);
if (sk->sk_state == TCP_SYN_SENT) { if (sk->sk_state == TCP_SYN_SENT) {
inet_sk_state_store(sk, state); mptcp_set_state(sk, state);
sk->sk_state_change(sk); sk->sk_state_change(sk);
} }
} }
......
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