我正在尝试捕获数据包并重新组织数据包以获取原始的HTTP请求。我使用IPQUEUE(通过iptables规则)来捕获数据包,但是我发现数据包的顺序不正确。我已经知道在TCP协议中,需要对数据包进行重新排序,因此我正在尝试按照序列号重新排序数据包。根据维基百科的介绍,TCP的序列号是32位数字。那么,当序列号达到最大的32位数字时会发生什么?由于SYN数据包的序列号是随机数,所以我认为这个限制很快就会被达到。如果有人对此有任何建议或有一些有用的链接,请给我留言。
From RFC-1185
Avoiding reuse of sequence numbers within the same connection is
simple in principle: enforce a segment lifetime shorter than the
time it takes to cycle the sequence space, whose size is
effectively 2**31.
If the maximum effective bandwidth at which TCP
is able to transmit over a particular path is B bytes per second,
then the following constraint must be satisfied for error-free
operation:
2**31 / B > MSL (secs)
简单来说,TCP会处理这个问题。除了这个条件之外,TCP还有时间戳的概念来处理序列号环绕的情况。这是从上述RFC中得出的。
Timestamps carried from sender to receiver in TCP Echo options can
also be used to prevent data corruption caused by sequence number
wrap-around, as this section describes.
具体来说,TCP使用PAWS机制来处理TCP包绕情况。您可以在RFC-1323中找到更多关于PAWS的信息。
RFC793第3.3节:
必须记住实际序列号空间是有限的,尽管非常大。该空间范围从0到2*32-1。 由于空间是有限的,所有涉及序列号的算术运算都必须执行模2*32。这种无符号算术保留了序列号的关系,因为它们从2**32-1再次循环到0。计算机模数算术存在一些微妙之处,因此在编程比较此类值时应格外小心。
对序列号进行的任何算术运算都是模2^32的。
...
0xFFFFFFFE
0xFFFFFFFF
0x00000000
0x00000001
...