TCP连接状态说明

参考了网上一些文章,最终发现wireshark的wiki写的比较好,以此为基准,说明TCP在连接和断开时的状态迁移过程。

全局的TCP连接和断开的状态变更如下图所示:

复制代码

TCP 3-way handshake

We assume that both host (A) and server (B) side start from CLOSED status.

复制代码
  1. The server process create a TCB 1 and use TCB prepares to accept the host's request. After TCB born the server change status to LISTEN.

  2. The host does the same thing, create a TCB and use this TCB to send request, set the "SYN=1" in the request header, and initates a arbitrary sequence number, seq=x . SYN paccket (which means SYN=1) can not take any data content, but it will consume a sequence number. After request sent, the host goes into SYN-SENT status.

  3. After receiving the host's request:

    1. i. If the server accept to this connection, it will send back a confirm response. In the response both SYN and ACK bits should be '1', and server side also initiates a SEQ number, seq=y . The server will send its sequence number within packet which is used to be acknowledged to the clinet's SYN packet. This packet can not take any data content either, but it consumes a sequence number . So in this packet seq=y, ack=x+1. And the server goes into SYN-RCVD status.

    2. ii. If the server rejects the connection, it just responses a RST packet to reset the connection.

  4. After the host received the server's response, it will send back also a confirm packet with ACK bit sets to '1' and seq=x+1, ack=y+1. 2

After that, both side gose into ESTABLISHED status. This is what we called three-way handshake.

Example

复制代码

Capture Example

3-way handshake.pcap

1. TCB---Transmission Control Block, something like PCB, it stores some significant info like, TCP connectio table, the pointer for the sending and receiving buffer, retransmission queue pointer, the current sequence number and acknowledge number and ext.

2. ACK packet could take data content, if not, this packet will not consume SYN number. So the sequence number of the confirm packet is seq=x+1 . But in practice, at times, TCP 3-way handshake not only just initiates the connection, but also negotiate some very important parameters. MSS (maximum segment size) negotiation occurs in this steps.

TCP 4-times close

复制代码
  1. Client send finish datagram to the server, indicated that client will close the transmission from client to server. This is called active close. (FIN=1, seq=u)

  2. Server acknowledged the FIN datagram. (ACK=1, seq=v, ack=u+1)

  3. Server contiues to transmit, if the server finishs the transmission it will close transmission from server to client. This is called passive close.(FIN=1, ACK=1, seq=w, ack=u+1)

  4. Client acknowledged the FIN datagram to the server.1 (ACK=1, seq=u+1, ack=w+1)

1. After the ACK send, the client will not release the resource immediately, it will turn into TIME-WAIT status and wait 2-MSL (Maximum Segment Lifetime) time to release resource.

Example

复制代码

Capture Example

4 times close.pcap

状态迁移图

复制代码
相关推荐
养海绵宝宝的小蜗13 分钟前
LVS(Linux Virtual Server)项目知识点总结
linux·运维·lvs
发量惊人的中年网工34 分钟前
工业视觉云边 AI 推理总是卡顿?SD-WAN 打通边缘算力互联
网络·人工智能·网络安全·云计算
AC赳赳老秦44 分钟前
软著公开信息批量采集:OpenClaw 抓取软件著作权公开数据,分析企业技术布局方向
大数据·网络·人工智能·python·php·deepseek·openclaw
liuyunshengsir1 小时前
perftest 工具集ib_write_bw中的 RDMA Write 带宽测试工具手册
网络·rdma
tjjingpan1 小时前
HCIP-Datacom Core Technology V1.0_20 IPv6概述
linux·服务器·网络
我命由我123451 小时前
Android 开发 - 广播组件(标准广播、有序广播、静态注册广播、分钟到达广播、网络变更广播...)
android·java·开发语言·网络·java-ee·android studio·android-studio
MartinYeung51 小时前
[论文学习]WASP:面向提示注入攻击的Web代理安全性基准测试
前端·网络·学习
joopthd1 小时前
打破进口垄断:TDLAS/UV-DOAS/FTIR 全光谱检测国产器件全产业链布局(江苏旭海光电技术梳理)
运维·人工智能·uv·激光气体检测
数字融合1 小时前
透明化时空联合无缝追踪,构筑无断点全域态势感知网络专项技术
网络·人工智能·virtualenv
云泽8081 小时前
Linux基础开发工具(三):Vim高级配置、Swap恢复机制与Sudo权限白名单详解
linux·运维·vim