How is TCP/UDP checksum working?

10,685

The UDP checksum is optional for IPv4. Setting the checksum to 0 indicates that it's not used. See the Wikipedia article for details.

TCP, UDP, and IP checksum calculation can be offloaded to the NIC. The NIC will calculate the checksum in hardware. This is much quicker than doing it in software. Again Wikipedia knows all.

The checksum is recalculated by the router after it decrements the TTL or otherwise changes the packet (for all protocols that update the packet). This must be done at the router. The destination machine could not use a packet with an invalid checksum and somehow determine that it was correct when it started at the source. The destination can only reject packets with an invalid checksum.

Share:
10,685

Related videos on Youtube

user138126
Author by

user138126

Updated on September 18, 2022

Comments

  • user138126
    user138126 over 1 year

    I used raw socket to create some UDP packets and then send them to a UDP server

    I notice that when I put a wrong UDP checksum number the UDP server doesn't accept it, but if I put all 0 on the checksum, the UDP server accepts it?

    Why?

    Also, I notice a pheonomenum: checksum offloading I checked my machine:

    [root@kit temp]# ethtool --show-offload  eth0
    Offload parameters for eth0:
    rx-checksumming: on
    tx-checksumming: on
    scatter-gather: on
    tcp-segmentation-offload: off
    udp-fragmentation-offload: off
    generic-segmentation-offload: on
    generic-receive-offload: on
    large-receive-offload: off
    rx-vlan-offload: on
    tx-vlan-offload: on
    ntuple-filters: off
    receive-hashing: on
    

    It seems there is checksum offloading on my machine. If I randomly set the TCP checksum value, the NIC can modify it to a correct value if checksum offloading is enabled?

    Finally, packets may get modified when they are in transmission for example, TTL will decrease by number of hops NAT may also modify the source IP addresses, then the checksum will be obsolete, in these cases, how checksum works? The router will modify the checksum accordingly? Or the destination machine can smartly detect these and calculate the checksum accordingly?

  • user138126
    user138126 about 11 years
    so you mean 1 UDP checksum can't be offloaded or usually not offloaded? 2 routers can modify UDP and TCP checksum? 3 if I randomly set the TCP checksum value, the NIC can modify it to a correct value if checksum offloading is enabled?
  • Wayne Johnston
    Wayne Johnston about 11 years
    For (1) and (2) see the modified answer. For (3) I don't know. I've always let the IP stack take care of this for me.