diff options
Diffstat (limited to 'net/ipv4/tcp.c')
-rw-r--r-- | net/ipv4/tcp.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 34085e3a4096..a0d373bd9065 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c | |||
@@ -1652,6 +1652,41 @@ recv_urg: | |||
1652 | goto out; | 1652 | goto out; |
1653 | } | 1653 | } |
1654 | 1654 | ||
1655 | void tcp_set_state(struct sock *sk, int state) | ||
1656 | { | ||
1657 | int oldstate = sk->sk_state; | ||
1658 | |||
1659 | switch (state) { | ||
1660 | case TCP_ESTABLISHED: | ||
1661 | if (oldstate != TCP_ESTABLISHED) | ||
1662 | TCP_INC_STATS(TCP_MIB_CURRESTAB); | ||
1663 | break; | ||
1664 | |||
1665 | case TCP_CLOSE: | ||
1666 | if (oldstate == TCP_CLOSE_WAIT || oldstate == TCP_ESTABLISHED) | ||
1667 | TCP_INC_STATS(TCP_MIB_ESTABRESETS); | ||
1668 | |||
1669 | sk->sk_prot->unhash(sk); | ||
1670 | if (inet_csk(sk)->icsk_bind_hash && | ||
1671 | !(sk->sk_userlocks & SOCK_BINDPORT_LOCK)) | ||
1672 | inet_put_port(&tcp_hashinfo, sk); | ||
1673 | /* fall through */ | ||
1674 | default: | ||
1675 | if (oldstate==TCP_ESTABLISHED) | ||
1676 | TCP_DEC_STATS(TCP_MIB_CURRESTAB); | ||
1677 | } | ||
1678 | |||
1679 | /* Change state AFTER socket is unhashed to avoid closed | ||
1680 | * socket sitting in hash tables. | ||
1681 | */ | ||
1682 | sk->sk_state = state; | ||
1683 | |||
1684 | #ifdef STATE_TRACE | ||
1685 | SOCK_DEBUG(sk, "TCP sk=%p, State %s -> %s\n",sk, statename[oldstate],statename[state]); | ||
1686 | #endif | ||
1687 | } | ||
1688 | EXPORT_SYMBOL_GPL(tcp_set_state); | ||
1689 | |||
1655 | /* | 1690 | /* |
1656 | * State processing on a close. This implements the state shift for | 1691 | * State processing on a close. This implements the state shift for |
1657 | * sending our FIN frame. Note that we only send a FIN for some | 1692 | * sending our FIN frame. Note that we only send a FIN for some |