图解TCP状态机

原文地址:http://blog.csdn.net/zhangskd/article/details/8493804

States

 

TCP includes 11 states, they are:

LISTEN

SYN_SENT

SYN_RECV

ESTABLISHED

FIN_WAIT1

CLOSE_WAIT

FIN_WAIT2

LAST_ACK

TIME_WAIT

CLOSED

CLOSING

 

@include/net/tcp_states.h:

/* Definitions for the TCP protocol sk_state field. */

#ifndef _LINUX_TCP_STATES_H
#define _LINUX_TCP_STATES_H

enum {
    TCP_ESTABLISHED = 1,
    TCP_SYN_SENT,
    TCP_SYN_RECV,
    TCP_FIN_WAIT1,
    TCP_FIN_WAIT2,
    TCP_TIME_WAIT,
    TCP_CLOSE,
    TCP_CLOSE_WAIT,
    TCP_LAST_ACK,
    TCP_LISTEN,
    TCP_CLOSING,    /* Now a valid state */

    TCP_MAX_STATES    /* leave at the end! */
};

#define TCP_STATE_MASK 0xF
#define TCP_ACTION_FIN (1 << 7)

enum {
    TCPF_ESTABLISHED = (1 << 1),
    TCPF_SYN_SENT = (1 << 2),
    TCPF_SYN_RECV = (1 << 3),
    TCPF_FIN_WAIT1 = (1 << 4),
    TCPF_FIN_WAIT2 = (1 << 5),
    TCPF_TIME_WAIT = (1 << 6),
    TCPF_CLOSE = (1 << 7),
    TCP_CLOSE_WAIT = (1 << 8),
    TCP_LAST_ACK = (1 << 9),
    TCP_LISTEN = (1 << 10),
    TCP_CLOSING = (1 << 11)
};

#endif /* _LINUX_TCP_STATES_H */


 

View of Server

 

Passive open and passive close often performed by Server, the normal routine is illustrated as follow.

I denote the passive open/close transitions with a blue line (normal transitions are in bold).

 

View of Client

 

Ative open and Active close often performed by Client, the normal routine is illustrated as follow.

I denote the active open/close transitions with a green line (normal transitions are in bold).

 

As a whole

 

We know while most TCP state transitions are normal, it also has some unnormal transitions, including:

simultaneous open

simultaneous close

RST and etc.

I use dashed line to denote this kind of transitions.

 

 

 

 

 

Sequence chart

 

(1)Normal sequence chart (including active open/close, passive open/close)

 

 

(2)simultaneous open

 

 

 (3)simultaneous close

 

      

 

Author

 

zhangskd @ csdn blog

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值