Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Jul 2007 09:49:35 -0400
From:      Raj <raj@thenewfront.us>
To:        <freebsd-net@freebsd.org>
Subject:   Tcp checksum calculation wrong by 2
Message-ID:  <C2C2412F.288B%raj@thenewfront.us>
In-Reply-To: <20070717120011.4E14D16A419@hub.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi Folks,

This problem is related to Mac OS X 10.3. Please accept my apologies for
posting here , as I thought this is one avenue I could explore to get an
answer and also OS X has some freebsd core too!

I am looking at a driver code for OS X 10.3 where the checksum is
being calculated on an inbound syn-ack. First by zeroing out the
checksum, then calculating the checksum of the pseudo header and
finally calculating the checksum. The checksum functions used are
available in the xnu sources.
Here is the snippet

   printf("tcplen =%x",tcplen);
   printf(" checksum Before=%x,\n",tcph->th_sum);
   tcph->th_sum=0;

    tcph->th_sum = in_pseudo(iph->ip_src.s_addr, iph->ip_dst.s_addr,
htonl((iph->ip_p << 16) | (tcplen & 0xffff)));

      tcph->th_sum = in_cksum_skip(mbuf, packet_len, iph->ip_hl << 2);

   printf("final checksum tcph=%x,\n",tcph->th_sum);

The  final checksum is less by 2 than the original. Here is the sample
output

tcplen=26
checksum before =7182
final checksum=7180
tcplen=26
checksum before =2d87
final checksum=2d85
tcplen=26
checksum before =5ab0
final checksum=5aae

I have also observed that the checksum is calculated correctly when
the length of the tcp segment in the packet is 40.

tcplen=40
checksum before =d1cf
final checksum=d1cf
tcplen=40
checksum before =e237
final checksum=e237

Can someone be kind enough to give me an idea on why I am getting the wrong
checksum? 
TIA
Raj





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?C2C2412F.288B%raj>