TCP 序列号

TCP 序列号

我想知道如果两个具有相同序列号的段到达目的地,哪个段会被接受?

例如:

客户端向服务器发送数据包并等待确认。但它没有在时间线内收到确认(由于某些网络问题,此段需要时间才能到达服务器),因此开始再次发送相同的段。现在在服务器端,如果两个数据包同时到达会发生什么。

答案1

一个数据包被标记为重复并被丢弃。由于它们是相同的,所以哪一个是重复的并不重要。参见https://stackoverflow.com/questions/12871760/packet-loss-and-packet-duplication

答案2

两个段同时到达的前提毫无意义。一个段总是会先于另一个段到达。但在下一个段到达之前,该数据可能尚未传送到应用程序。

根据RFC 793将使用第一段的数据。

段按顺序处理。到达时的初始测试用于丢弃旧的重复项,但进一步的处理按 SEG.SEQ 顺序进行。如果段的内容跨越新旧边界,则只应处理新部分。

话虽如此,不难想象现实中的实现会有所不同。特别是部分重叠的片段可能会非常有趣。

答案3

基本上,最先处理的将被接受,后续重复的将被删除。

https://www.rfc-editor.org/rfc/rfc793.txt

...首先检查序列号

  SYN-RECEIVED STATE
  ESTABLISHED STATE
  FIN-WAIT-1 STATE
  FIN-WAIT-2 STATE
  CLOSE-WAIT STATE
  CLOSING STATE
  LAST-ACK STATE
  TIME-WAIT STATE

    Segments are processed in sequence.  Initial tests on arrival
    are used to discard old duplicates, but further processing is
    done in SEG.SEQ order.  If a segment's contents straddle the
    boundary between old and new, only the new parts should be
    processed.

    There are four cases for the acceptability test for an incoming
    segment:

    Segment Receive  Test
    Length  Window
    ------- -------  -------------------------------------------

       0       0     SEG.SEQ = RCV.NXT

       0      >0     RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND

      >0       0     not acceptable

      >0      >0     RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND
                  or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND

    If the RCV.WND is zero, no segments will be acceptable, but
    special allowance should be made to accept valid ACKs, URGs and
    RSTs.

    If an incoming segment is not acceptable, an acknowledgment
    should be sent in reply (unless the RST bit is set, if so drop
    the segment and return):

      <SEQ=SND.NXT><ACK=RCV.NXT><CTL=ACK>

    After sending the acknowledgment, drop the unacceptable segment
    and return...

相关内容