当 sysctl tcp_retries1 设置为 3 时,TCP 数据包被重传 7 次 - 为什么?

Hod*_*odB 9 kernel tcp linux-networking sysctl ubuntu-12.04

Ubuntu 12.04

我试图更好地了解 TCP 在未收到目的地收到的确认时将尝试重新传输数据包的次数。阅读tcp 手册页后,似乎很明显这是由 sysctl tcp_retries1 控制的:

tcp_retries1 (integer; default: 3)
           The number of times TCP will attempt to retransmit a  packet  on
           an  established connection normally, without the extra effort of
           getting the network layers involved.  Once we exceed this number
           of retransmits, we first have the network layer update the route
           if possible before each new retransmit.  The default is the  RFC
           specified minimum of 3.
Run Code Online (Sandbox Code Playgroud)

我的系统设置为默认值 3:

# cat /proc/sys/net/ipv4/tcp_retries1 
3
Run Code Online (Sandbox Code Playgroud)

为了对此进行测试,我通过 ssh 从系统 A (172.16.249.138) 连接到系统 B (172.16.249.137) 并在控制台上启动了一个简单的打印循环。然后,在进行此通信时,我突然断开了 B 与网络的连接。

在另一个终端中,我在系统 A 上运行 'tcpdump host 172.16.249.137'。以下是输出中的相关行(为清楚起见添加了行号)。

00: ...
01: 13:29:46.994715 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [.], ack 5989441, win 80, options [nop,nop,TS val 1957286 ecr 4294962520], length 0
02: 13:29:46.995084 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [.], ack 5989441, win 186, options [nop,nop,TS val 1957286 ecr 4294962520], length 0    
03: 13:29:47.040360 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [P.], seq 29136:29184, ack 5989441, win 186, options [nop,nop,TS val 1957298 ecr 4294962520], length 48
04: 13:29:47.086552 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [.], ack 5989441, win 376, options [nop,nop,TS val 1957309 ecr 4294962520], length 0
05: 13:29:47.680608 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [P.], seq 29136:29184, ack 5989441, win 376, options [nop,nop,TS val 1957458 ecr 4294962520], length 48
06: 13:29:48.963721 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [P.], seq 29136:29184, ack 5989441, win 376, options [nop,nop,TS val 1957779 ecr 4294962520], length 48
07: 13:29:51.528564 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [P.], seq 29136:29184, ack 5989441, win 376, options [nop,nop,TS val 1958420 ecr 4294962520], length 48
08: 13:29:56.664384 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [P.], seq 29136:29184, ack 5989441, win 376, options [nop,nop,TS val 1959704 ecr 4294962520], length 48
09: 13:30:06.936480 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [P.], seq 29136:29184, ack 5989441, win 376, options [nop,nop,TS val 1962272 ecr 4294962520], length 48
10: 13:30:27.480381 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [P.], seq 29136:29184, ack 5989441, win 376, options [nop,nop,TS val 1967408 ecr 4294962520], length 48
11: 13:31:08.504033 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [P.], seq 29136:29184, ack 5989441, win 376, options [nop,nop,TS val 1977664 ecr 4294962520], length 48
12: 13:31:13.512437 ARP, Request who-has 172.16.249.137 tell 172.16.249.138, length 28
13: 13:31:14.512336 ARP, Request who-has 172.16.249.137 tell 172.16.249.138, length 28
14: 13:31:15.512241 ARP, Request who-has 172.16.249.137 tell 172.16.249.138, length 28
Run Code Online (Sandbox Code Playgroud)

如果我正确地解释了这一点(我可能不是),系统 B 永远不会确认第 3 行的数据包。然后 A 然后重试发送此数据包 7 次(第 5-11 行),每次增加其重传计时器(大约每次增加一倍)时间)。

为什么数据包被重传 7 次而不是 3 次?

注意:我注意到一些 pcap 文件在 HTTP 连接上重传发生了 6-7 次后执行了这个正式测试,因此重传次数似乎不是特定于 SSH 的。

And*_*w S 5

我相信您通过终止 .137 服务器上的连接创建了一个孤立套接字。因此,使用的内核参数将是 tcp_orphan_retries - 它的通用 linux 默认值为 7。

您可以在此处获得对您创建的条件和结果的描述:http : //www.linuxinsight.com/proc_sys_net_ipv4_tcp_orphan_retries.html