Summary: LWIP_CHECKSUM_ON_COPY causes wrong checksum (0xFFFF)
Project: lwIP - A Lightweight TCP/IP stack
Submitted by: basti
Submitted on: Mon 13 Aug 2018 10:55:16 AM UTC
Severity: 3 - Normal
Item Group: Faulty Behaviour
Assigned to: None
Discussion Lock: Any
Planned Release: None
lwIP version: git head
I am currently using lwIP (HEAD) on x86-64 with a custom OS and an Intel
e1000(e) ethernet adapter to transfer data via TCP.
For debugging purposes I implemented an echoserver (sending and receiving
about 2 GiB of random data @ ~ 20 MiB/s) and used the following config
After some time Wireshark shows TCP packages (sent by lwIP) that have an
invalid TCP checksum of 0xFFFF.
#define TCP_CHECKSUM_ON_COPY_SANITY_CHECK 1
the assertion in line
is triggered whenever the precalculated checksum of the segment (seg->chksum)
is exactly the same as the checksum of the header (acc). In this case
apperently the overall checksum (seg->tcphdr->chksum) should be 0x0 (but is
Either of the patches attached worked for me. Although I am not entirely sure,
whether these patches will work for all weird architectures out there.
If required I can also provide a Wireshark capture of the problem or a patch
that prints more debugging information (during the checksum-on-copy
I think the correct version of the fix is to invert back 'acc' (as it is
returned inverted by ip_chksum_pseudo_partial()), then do the calculation and
fold and then inverting it again. As that is the same what's already done, it
should be portable.