Search code examples
tcpssilwip

lwip tcp/ip checksum error


LWIP: SSI output lengths may cause TCP/IP checksum errors

I am using LWIP 1.4.1 running on an ARM LPC4357 (LPCOpen 2.1.12, date 5/15/2014). I am using httpserver_raw and have added a few SSI handlers.

I find that the system is sensitive to both the size of the line that contains the tag and the number of bytes the SSI handler outputs. The tag is included in output. When expanding the tag:

\r\n
spacespace<!--#s_add-->\r\n

(two spaces proceed the tag, forum formatting!) The browser fails to receive the output & Wireshark reports a checksum error when the tag is expanded with 1, 3, 5, 7 etc characters. The browser receives the output & Wireshark reports OK when the tag is expanded with 2, 4, 6, 8 etc characters.

If I remove a space from before the tag then the situation is reveresed. Additionally if the tag is greater than 129 characters (suspect 122) then output is always ok (not seen a fault yet).

When the SSI output is >=129 bytes then http_write() function is being called with lengths 122 (header and tag), 122 (initial part of SSI) and 7 (remaining part of SSI). Having the second tcp_write() of 122 seems to cure the checksum problem. (Splitting the SSI output into segments is itself an oddity. The sending in chunks of upto 122 seems to be driven by the size of the resource file upto the tag).

I have inspected the SSI output using UART printf()'s and in Wireshark and all appears to be correct, there are no corruptions in the output. http_write() lengths are correct as is the output.

I have tracked as far as tcp_write() at which point I start to doubt myself; surely tcp_write() cannot be broke? Has anyone used LWIP SSI on an embedded target or indeed tcp_write()?


Solution

  • Commenting/removing: #define LWIP_CHECKSUM_ON_COPY seems to resolve.