[comp.protocols.tcp-ip] TCP-IP zero checksum

freiss@nixpbe.uucp (03/10/89)

Mink writes:
>Can anyone tell me why the checksum in the TCP header isn't allowed to
>be zero ? I can't find it documented in any RFC. Also I can't find this
>conversion back in the tcp_input routine

Hmmm... RFC 793 says (page 16):

...While computing the checksum, the checksum field itself is replaced
with zeros.

Maybe a checksum of zero therefore is regarded as 'something broke while
the checksum was computed' and replaced by the one's complement of zero.
This doesn't sound like a very intelligent way of errorchecking though.
  Anybody have a better idea?

-Martin

--
 Martin Freiss
 Nixdorf Computer AG, Dept. ET2
 Pontanusstr. 55                    USA: ..!uunet!linus!nixbur!freiss.pad
 D-4792 Paderborn, FRG             !USA: ..!mcvax!unido!nixpbe!freiss.pad

Dave_Katz@UM.CC.UMICH.EDU (03/10/89)

> The reason for jamming in 0xFFFF into the checksum field when the computed sum
> is zero is to allow the receiving machine to be able to distinguish between
> an incoming TCP packet that has a checksum to verify against a packet that had
> not computed the checksum before putting it out on the net.
 
The spec calls for the "ones complement of the ones complement sum."  Ones
complement arithmetic never results in -0 (0xFFFF) as a result, so the
ones complement of that never results in 0.  If you can really do ones
complement arithmetic (don't throw away those PDP 11s!), there's no
"jamming" involved;  it just comes out that way.  This is handy for
detecting a zero checksum (if the semantics of that are meaningful),
but it's also handy because you can verify the checksum of a received
packet by running the algorithm with the received checksum in place;
a result of zero means that the checksum was valid.

zweig@p.cs.uiuc.edu (03/14/89)

> /* Written  6:42 pm  Mar  7, 1989 by cdh@bbn.com 
> I think the rational about always using the FFFF version of 0 in the
> ones-complement checksum of TCP was that it prevented an all-zeros
> packet from being legal.  Therefore, if some interface or memory
> fed you a packet containing all zeros, you knew it was illegal, since
> a correct all-zeros packet would have checksum FFFF.
> 
> Of course, I could be wrong.
> 
> Carl

That's why the definition is the complement of the sum of all the 16-bit
words in the datagram. All 0's add to 0000 which then gets complemented
to FFFF. A packet that contained 0000FFFF0000FFFF0000FFFF... might be
the result of some hardware messup (half the data lines jammed on a memory
board) but seems unlikely. Still only has a 50/50 chance of getting 0000
as a checksum.

Ignoring checksums in TCP/IP is like giving a bucket o' pork ribs to
someone to celebrate a barmitzvah -- it runs counter to the principle
of reliable stream transport.


Johnny Zweig
University of Illinois at Urbana-Champaign
Department of Computer Science
--------------------------------Disclaimer:------------------------------------
   Rule 1: Don't believe everything you read.
   Rule 2: Don't believe anything you read.
   Rule 3: There is no Rule 3.
-------------------------------------------------------------------------------