Re: Incremental update of TCP Checksum

Leo Mauro
2003-09-16T20:47:48Z

On Tuesday 16 September 2003 04:32 pm, Vishwas Raman wrote:

> As mentioned in RFC1624, I did the following.
> void changePacket(struct sk_buff* skb)
> {
> struct tcphdr *tcpHdr = skb->h.th;
>
> // Verifying the tcp checksum works here...
>
> __u16 oldDoff = tcpHeader->doff;
> tcpHeader->doff += 1;
>
> // Formula from RFC1624 is HC' = ~(C + (-m) + m')
> // where HC - old checksum in header
> // C - one's complement sum of old header
> // HC' - new checksum in header
> // C' - one's complement sum of new header
> // m - old value of a 16-bit field
> // m' - new value of a 16-bit field
>
> long cksum = (~(tcpHdr->check))&0xffff;
> cksum += (__u16)~oldDoff;
^ should be a -

> cksum += tcpHeader->doff;
> while (cksum >> 16)
> {
> cksum = (cksum & 0xffff) + (cksum >> 16);
> }
> tcpHeader->check = ~cksum;
>
> // Verifying tcp checksum here fails with bad cksum
> }

--
Leo Mauro
Network Security
Simon Bolivar University
Caracas, Venezuela