Skip to content

Commit d46e416

Browse files
lxindavem330
authored andcommitted
sctp: sctp should change socket state when shutdown is received
Now sctp doesn't change socket state upon shutdown reception. It changes just the assoc state, even though it's a TCP-style socket. For some cases, if we really need to check sk->sk_state, it's necessary to fix this issue, at least when we use ss or netstat to dump, we can get a more exact information. As an improvement, we will change sk->sk_state when we change asoc->state to SHUTDOWN_RECEIVED, and also do it in sctp_shutdown to keep consistent with sctp_close. Signed-off-by: Xin Long <lucien.xin@gmail.com> Acked-by: Marcelo R. Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d6cf3a8 commit d46e416

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

net/sctp/sm_sideeffect.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,8 +806,10 @@ static void sctp_cmd_new_state(sctp_cmd_seq_t *cmds,
806806

807807
/* Set the RCV_SHUTDOWN flag when a SHUTDOWN is received. */
808808
if (sctp_state(asoc, SHUTDOWN_RECEIVED) &&
809-
sctp_sstate(sk, ESTABLISHED))
809+
sctp_sstate(sk, ESTABLISHED)) {
810+
sk->sk_state = SCTP_SS_CLOSING;
810811
sk->sk_shutdown |= RCV_SHUTDOWN;
812+
}
811813
}
812814

813815
if (sctp_state(asoc, COOKIE_WAIT)) {

net/sctp/socket.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4195,6 +4195,7 @@ static void sctp_shutdown(struct sock *sk, int how)
41954195
return;
41964196

41974197
if (how & SEND_SHUTDOWN) {
4198+
sk->sk_state = SCTP_SS_CLOSING;
41984199
ep = sctp_sk(sk)->ep;
41994200
if (!list_empty(&ep->asocs)) {
42004201
asoc = list_entry(ep->asocs.next,
@@ -7566,10 +7567,13 @@ static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
75667567
/* If the association on the newsk is already closed before accept()
75677568
* is called, set RCV_SHUTDOWN flag.
75687569
*/
7569-
if (sctp_state(assoc, CLOSED) && sctp_style(newsk, TCP))
7570+
if (sctp_state(assoc, CLOSED) && sctp_style(newsk, TCP)) {
7571+
newsk->sk_state = SCTP_SS_CLOSING;
75707572
newsk->sk_shutdown |= RCV_SHUTDOWN;
7573+
} else {
7574+
newsk->sk_state = SCTP_SS_ESTABLISHED;
7575+
}
75717576

7572-
newsk->sk_state = SCTP_SS_ESTABLISHED;
75737577
release_sock(newsk);
75747578
}
75757579

0 commit comments

Comments
 (0)