[comp.protocols.tcp-ip] TCP and UDP checksums

barrett@Daisy.EE.UND.AC.ZA (Alan P Barrett) (06/04/91)

Somebody asked:
> I'm interested in how common it is for TCP implementations to use all zeros
> for the TCP header checksum.  I know that some HP machines do this but 
> how common is this in the real world?

The TCP checksum is never optional (except in non-conforming
implementations, of course).  Here is an extract from RFC 1122, to add
weight to the requirement in RFC 793:

         4.2.2.7  TCP Checksum: RFC-793 Section 3.1

            Unlike the UDP checksum (see Section 4.1.3.4), the TCP
            checksum is never optional.  The sender MUST generate it and
            the receiver MUST check it.

The TCP checksum will sometimes be all zeros but will never be all ones,
if it is calculated according to the method given in RFC 793.  I don't
know if an implementation is permitted to transmit all ones instead of a
zero TCP checksum, but the discussion of UDP checksums in RFC 1122
suggests (to me) that a sending TCP would be permitted to do this.

A UDP checksum, on the other hand, is optional, and a zero in the
checksum field of the packet indicate that a checksum was not
calculated.  If a UDP checksum is calculated as zero, RFC 768 says that
it must be transmitted as all ones to distinguish this case from the
absence of a checksum.  RFC 1122 has this to say:

         4.1.3.4  UDP Checksums

            A host MUST implement the facility to generate and validate
            UDP checksums.  An application MAY optionally be able to
            control whether a UDP checksum will be generated, but it
            MUST default to checksumming on.

            If a UDP datagram is received with a checksum that is non-
            zero and invalid, UDP MUST silently discard the datagram.
            An application MAY optionally be able to control whether UDP
            datagrams without checksums should be discarded or passed to
            the application.

            DISCUSSION:
                 Some applications that normally run only across local
                 area networks have chosen to turn off UDP checksums for
                 efficiency.  As a result, numerous cases of undetected
                 errors have been reported.  The advisability of ever
                 turning off UDP checksumming is very controversial.

            IMPLEMENTATION:
                 There is a common implementation error in UDP
                 checksums.  Unlike the TCP checksum, the UDP checksum
                 is optional; the value zero is transmitted in the
                 checksum field of a UDP header to indicate the absence
                 of a checksum.  If the transmitter really calculates a
                 UDP checksum of zero, it must transmit the checksum as
                 all 1's (65535).  No special action is required at the
                 receiver, since zero and 65535 are equivalent in 1's
                 complement arithmetic.

--apb
Alan Barrett, Dept. of Electronic Eng., Univ. of Natal, Durban, South Africa
RFC822: barrett@ee.und.ac.za             Bang: m2xenix!quagga!undeed!barrett