Subject: Re: TCP checksum error on local device

From: Kevin Spiteri <[email-masked]>
Date: Wed, 09 Jul 2008 17:28:54 +0200

Kristof Provost wrote:
> On 2008-07-09 16:34:32 (+0200), Kevin Spiteri <[email-masked]> wrote:
>   
>> When I send TCP data from localhost to localhost (either on 127.0.0.1
>> or on the public IP of the machine), the TCP checksum is wrong.
>>
>>     
> I suspect this is intended and expected behaviour. The checksum is quite
> useless as the packet never travels over the network and can't be
> corrupted. 
>   
Probably.

I saw the behaviour as strange because only the segment containing data 
had an incorrect TCP checksum, all other segments (SYN, SYN ACK, ACKs 
without data and FIN ACK) had a correct TCP checksum.

Also, the incorrect checksum field seems to depend on the IP address and 
the packet length, but not on the port number, sequence/acknowledgement 
number or data content. Thus, the incorrect checksum is the same when 
the sample is run repeatedly, it only changes when the data length 
and/or IP address are changed.
> The transmit code in net/ipv4/ip_output.c seems to mark packets for the
> loopback interface with CHECKSUM_UNNECESSARY.
>   
The same happens when I bind the server socket on the public IP (e.g. 
10.111.110.71:12345) and connect from a socket on the same IP 
(10.111.110.71). But then, although the IP is for device eth0 rather 
than for device lo, the packet still never has to be transmitted and the 
checksum is still unnecessary.
> I guess the connection over loopback still carries the data like you'd
> expect right?
>   
Yes, the data was still received and correct.

Kevin