Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why there is separate checksum in TCP and IP headers?

Tags:

networking

What is the need for having checksum at various layers ? For eg, there is a checksum in TCP layer and again in IP layer and also Ethernet layer has it. Is not it sufficient to have checksum at one layer ?

like image 586
sasian Avatar asked Jan 29 '11 09:01

sasian


People also ask

Why the checksum in TCP is calculated only for header justify?

This is because while traveling on network a data packet can become corrupt and there has to be a way at the receiving end to know that data is corrupted or not. This is the reason the checksum field is added to the header. At the source side, the checksum is calculated and set in header as a field.

Does TCP have checksum?

TCP has a checksum that covers the TCP pseudo header and payload. It is optional for UDP on IPv4, but mandatory for UDP on IPv6. Other transport protocols may have error detection, and others may not. If a transport protocols does not have error detection, it is up to the application to check for errors.

Why the checksum in IP covers only the header and not the data?

First, all higher-level protocols that encapsulate data in the IPv4 datagram have a checksum field that covers the whole packet. Therefore, the checksum for the IPv4 datagram does not have to check the encapsulated data. Second, the header of the IPv4 packet changes with each visited router, but the data do not.

Is TCP checksum necessary or could TCP allow IP to checksum the data?

TCP checksums are identical to UDP checksums, with the exception that checksums are mandatory with TCP (instead of being optional, as they are with UDP). Furthermore, their usage is mandatory for both the sending and receiving systems.


2 Answers

All three layers are needed, for multiple reasons:

  • IP does not always run over ethernet (imagine IP over RS-232 serial, something every Cisco and Unix box can do)

  • IP does not checksum the data

  • TCP packets can be reassembled incorrectly from IP packets and fragments that each have perfect checksums

  • Even if reassembled correctly, software or other errors could be introduced in the layers between IP and TCP

  • Even if all software functions correctly, and TCP/IP is over ethernet, the limited size of the checksums can be accidently correct (and will be at some point, given enough packets) in the face of persistent errors, so having more than one checksum is helpful.

  • Every time a new header is introduced there is more to checksum, and the new layer can't see the header bits of the layer below.

like image 129
DigitalRoss Avatar answered Feb 07 '23 04:02

DigitalRoss


Ethernet checksum is a hop to hop checksum - meaning that it is recomputed everytime the Ethernet header fields change. TCP/UDP checksum is a end-to-end checksum meaning it is computed by the sender and verified by the receiver. TCP/UDP checksums cover the entire segment. IP checksum covers only the header. Ethernet CRC covers the entire frame.

like image 39
user138645 Avatar answered Feb 07 '23 04:02

user138645