[En-Nut-Discussion] [PATCH] Implement TCP sequence number wraparound
Marti Raudsepp
marti at voicecom.ee
Wed Mar 24 17:37:00 CET 2010
Hi list,
It seems that neither Ethernut 4.8 nor 4.9 currently attempt to handle
TCP sequence number wraparound. This means that each TCP connection is
limited to transmitting/receiving 4 GB of data in the best case.
Technically it's in violation of the TCP spec.
Transmitting at the maximum rate of our application (1.10 MB/s both
ways by our measurements) means that we can hit this limit in just 1
hour.
Further, since the initial TX sequence number is initialized from
NutGetMillis(), the maximum TCP session lifetime approaches 0 as
uptime approaches 49.71 days. Nut/OS has no control at all over RX
sequence numbers which are assigned by the other endpoint.
So I went through every sequence number comparison in the TCP code and
changed it. My initial approach was to change all sequence number
values to signed int32_t and change comparisons of style "a > b" into
"a - b > 0", but I figured it might be confusing to people, because
sequence numbers are usually represented as positive integers and the
two comparisons would seem equivalent mathematically.
In the end I settled for adding two macros to tcputil.h:
#define SeqIsAfter(x, low) \
((int32_t)(x - low) > 0)
#define SeqIsBetween(x, low, high) \
((uint32_t)(x - low) <= (uint32_t)(high - low))
SeqIsBetween is my replacement for the IsInLimits function; the macro
is very simple, so a function seemed like overkill.
The patch applies cleanly to both 4.8.6 and 4.9.8, but I have only
tested with 4.8.6 on AT91SAM7X. So far I have tested wraparound in the
common case (no packet loss). I feel confident that I haven't broken
anything that worked before. But no guarantees, test and scrutinize it
yourself. :)
However, testing wraparound around packet loss/reordering edge cases
is pretty complicated, and Nut/OS's short TCP window doesn't help.
I'll see what I can do with Linux netem network emulator.
----
Hereby I submit 3 patches for review:
https://sourceforge.net/tracker/?func=detail&aid=2976001&group_id=34079&atid=410689
01_tcp_seqno_wraparound.patch:
Implements handling of TCP sequence number wraparound. This is the
actual patch that I described above.
02_remove_bogus_todo.patch:
This just removes a bogus TODO item that has already been implemented.
03_tcp_ntohl_to_htonl.patch:
I found a few places in the TCP code where the "htonl" macro was used
insteasd of "ntohl". Since these operations are intechangeable, it's a
coding style fix only.
Regards,
Marti Raudsepp
voicecom.ee
More information about the En-Nut-Discussion
mailing list