Skip to content

Commit c693a85

Browse files
Geliang Tangdavem330
authored andcommitted
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: multipath-tcp/mptcp_net-next#460 Signed-off-by: Geliang Tang <[email protected]> Acked-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 d9cd27b commit c693a85

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

net/mptcp/pm_netlink.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,11 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
10481048
if (err)
10491049
return err;
10501050

1051+
/* We don't use mptcp_set_state() here because it needs to be called
1052+
* under the msk socket lock. For the moment, that will not bring
1053+
* anything more than only calling inet_sk_state_store(), because the
1054+
* old status is known (TCP_CLOSE).
1055+
*/
10511056
inet_sk_state_store(newsk, TCP_LISTEN);
10521057
lock_sock(ssk);
10531058
err = __inet_listen_sk(ssk, backlog);

net/mptcp/protocol.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,11 @@ static void mptcp_check_data_fin_ack(struct sock *sk)
429429

430430
switch (sk->sk_state) {
431431
case TCP_FIN_WAIT1:
432-
inet_sk_state_store(sk, TCP_FIN_WAIT2);
432+
mptcp_set_state(sk, TCP_FIN_WAIT2);
433433
break;
434434
case TCP_CLOSING:
435435
case TCP_LAST_ACK:
436-
inet_sk_state_store(sk, TCP_CLOSE);
436+
mptcp_set_state(sk, TCP_CLOSE);
437437
break;
438438
}
439439

@@ -594,13 +594,13 @@ static bool mptcp_check_data_fin(struct sock *sk)
594594

595595
switch (sk->sk_state) {
596596
case TCP_ESTABLISHED:
597-
inet_sk_state_store(sk, TCP_CLOSE_WAIT);
597+
mptcp_set_state(sk, TCP_CLOSE_WAIT);
598598
break;
599599
case TCP_FIN_WAIT1:
600-
inet_sk_state_store(sk, TCP_CLOSING);
600+
mptcp_set_state(sk, TCP_CLOSING);
601601
break;
602602
case TCP_FIN_WAIT2:
603-
inet_sk_state_store(sk, TCP_CLOSE);
603+
mptcp_set_state(sk, TCP_CLOSE);
604604
break;
605605
default:
606606
/* Other states not expected */
@@ -775,7 +775,7 @@ static bool __mptcp_subflow_error_report(struct sock *sk, struct sock *ssk)
775775
*/
776776
ssk_state = inet_sk_state_load(ssk);
777777
if (ssk_state == TCP_CLOSE && !sock_flag(sk, SOCK_DEAD))
778-
inet_sk_state_store(sk, ssk_state);
778+
mptcp_set_state(sk, ssk_state);
779779
WRITE_ONCE(sk->sk_err, -err);
780780

781781
/* 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,
24632463
inet_sk_state_load(msk->first) == TCP_CLOSE) {
24642464
if (sk->sk_state != TCP_ESTABLISHED ||
24652465
msk->in_accept_queue || sock_flag(sk, SOCK_DEAD)) {
2466-
inet_sk_state_store(sk, TCP_CLOSE);
2466+
mptcp_set_state(sk, TCP_CLOSE);
24672467
mptcp_close_wake_up(sk);
24682468
} else {
24692469
mptcp_start_tout_timer(sk);
@@ -2558,7 +2558,7 @@ static void mptcp_check_fastclose(struct mptcp_sock *msk)
25582558
WRITE_ONCE(sk->sk_err, ECONNRESET);
25592559
}
25602560

2561-
inet_sk_state_store(sk, TCP_CLOSE);
2561+
mptcp_set_state(sk, TCP_CLOSE);
25622562
WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
25632563
smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
25642564
set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags);
@@ -2693,7 +2693,7 @@ static void mptcp_do_fastclose(struct sock *sk)
26932693
struct mptcp_subflow_context *subflow, *tmp;
26942694
struct mptcp_sock *msk = mptcp_sk(sk);
26952695

2696-
inet_sk_state_store(sk, TCP_CLOSE);
2696+
mptcp_set_state(sk, TCP_CLOSE);
26972697
mptcp_for_each_subflow_safe(msk, subflow, tmp)
26982698
__mptcp_close_ssk(sk, mptcp_subflow_tcp_sock(subflow),
26992699
subflow, MPTCP_CF_FASTCLOSE);
@@ -2911,7 +2911,7 @@ static int mptcp_close_state(struct sock *sk)
29112911
int next = (int)new_state[sk->sk_state];
29122912
int ns = next & TCP_STATE_MASK;
29132913

2914-
inet_sk_state_store(sk, ns);
2914+
mptcp_set_state(sk, ns);
29152915

29162916
return next & TCP_ACTION_FIN;
29172917
}
@@ -3022,7 +3022,7 @@ bool __mptcp_close(struct sock *sk, long timeout)
30223022

30233023
if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) {
30243024
mptcp_check_listen_stop(sk);
3025-
inet_sk_state_store(sk, TCP_CLOSE);
3025+
mptcp_set_state(sk, TCP_CLOSE);
30263026
goto cleanup;
30273027
}
30283028

@@ -3065,7 +3065,7 @@ bool __mptcp_close(struct sock *sk, long timeout)
30653065
* state, let's not keep resources busy for no reasons
30663066
*/
30673067
if (subflows_alive == 0)
3068-
inet_sk_state_store(sk, TCP_CLOSE);
3068+
mptcp_set_state(sk, TCP_CLOSE);
30693069

30703070
sock_hold(sk);
30713071
pr_debug("msk=%p state=%d", sk, sk->sk_state);
@@ -3131,7 +3131,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)
31313131
return -EBUSY;
31323132

31333133
mptcp_check_listen_stop(sk);
3134-
inet_sk_state_store(sk, TCP_CLOSE);
3134+
mptcp_set_state(sk, TCP_CLOSE);
31353135

31363136
mptcp_stop_rtx_timer(sk);
31373137
mptcp_stop_tout_timer(sk);
@@ -3219,7 +3219,7 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk,
32193219
/* this can't race with mptcp_close(), as the msk is
32203220
* not yet exposted to user-space
32213221
*/
3222-
inet_sk_state_store(nsk, TCP_ESTABLISHED);
3222+
mptcp_set_state(nsk, TCP_ESTABLISHED);
32233223

32243224
/* The msk maintain a ref to each subflow in the connections list */
32253225
WRITE_ONCE(msk->first, ssk);
@@ -3640,7 +3640,7 @@ static int mptcp_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
36403640
if (IS_ERR(ssk))
36413641
return PTR_ERR(ssk);
36423642

3643-
inet_sk_state_store(sk, TCP_SYN_SENT);
3643+
mptcp_set_state(sk, TCP_SYN_SENT);
36443644
subflow = mptcp_subflow_ctx(ssk);
36453645
#ifdef CONFIG_TCP_MD5SIG
36463646
/* 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)
36903690
if (unlikely(err)) {
36913691
/* avoid leaving a dangling token in an unconnected socket */
36923692
mptcp_token_destroy(msk);
3693-
inet_sk_state_store(sk, TCP_CLOSE);
3693+
mptcp_set_state(sk, TCP_CLOSE);
36943694
return err;
36953695
}
36963696

@@ -3779,13 +3779,13 @@ static int mptcp_listen(struct socket *sock, int backlog)
37793779
goto unlock;
37803780
}
37813781

3782-
inet_sk_state_store(sk, TCP_LISTEN);
3782+
mptcp_set_state(sk, TCP_LISTEN);
37833783
sock_set_flag(sk, SOCK_RCU_FREE);
37843784

37853785
lock_sock(ssk);
37863786
err = __inet_listen_sk(ssk, backlog);
37873787
release_sock(ssk);
3788-
inet_sk_state_store(sk, inet_sk_state_load(ssk));
3788+
mptcp_set_state(sk, inet_sk_state_load(ssk));
37893789

37903790
if (!err) {
37913791
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,
38633863
__mptcp_close_ssk(newsk, msk->first,
38643864
mptcp_subflow_ctx(msk->first), 0);
38653865
if (unlikely(list_is_singular(&msk->conn_list)))
3866-
inet_sk_state_store(newsk, TCP_CLOSE);
3866+
mptcp_set_state(newsk, TCP_CLOSE);
38673867
}
38683868
} else {
38693869
MPTCP_INC_STATS(sock_net(ssk),

net/mptcp/subflow.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ void __mptcp_sync_state(struct sock *sk, int state)
425425

426426
__mptcp_propagate_sndbuf(sk, msk->first);
427427
if (sk->sk_state == TCP_SYN_SENT) {
428-
inet_sk_state_store(sk, state);
428+
mptcp_set_state(sk, state);
429429
sk->sk_state_change(sk);
430430
}
431431
}

0 commit comments

Comments
 (0)