Say I have a client that successfully receives packets from server in the following bytes ranges: 0-99, 100-199, 200-299. The next packet 300-399 gets lost but the final one 400-499 is successfully received.
When the client parses packet 400-499, it realizes that the previous segment of 300-399 is missing.
This is a simplified example that could be solved by having:
- 1 number tracking the in-order read data,
- another number the next expected in-order data,
- third number would keep track of the first greater out of order number and
- fourth, the last greatest out of order number.
I think this would work for a case where all the missing packets are contiguous and there is only 1 gap in TCP stream. What kind of data structure could keep track of multiple segments of missing packets that are not contiguous? How is this implemented at the OS level? It would help me understnad SACK implementation. SACK can has at most 4 blocks and it pre-pads with "NOPs" each block up to bytes divisible by 4 in TCP options. I am yet to see a pcap with more than 1 SACK option.
My question is about how the underlying technology keeps track of the numbers needed to construct the SACK, not the implementation of SACK itself.