我正在尝试捕获数据包并重新组织数据包以获取原始HTTP请求。
我正在使用 IPQUEUE(使用 iptables 规则)捕获数据包,我发现数据包没有按顺序捕获。
我已经知道在TCP协议中,数据包必须重新排序,所以我尝试按序列号对数据包重新排序。
根据维基百科,TCP的序列号是一个32位的数字。那么,如果序列号达到最大32位数字会发生什么呢?
因为SYN数据包的序列号是一个随机数,所以我认为这个限制可以很快达到。
来自 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 为模
简单来说,32位无符号数将环绕:
...
0xFFFFFFFE
0xFFFFFFFF
0x00000000
0x00000001
...
查看 https://en.wikipedia.org/wiki/Transmission_Control_Protocol
的 TCP 时间戳部分