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?


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?


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.

|improve this answer|||||
  • 1
    "Unlike the UDP checksum (see Section, the TCP checksum is never optional. The sender MUST generate it and the receiver MUST check it. " - quote from freesoft.org/CIE/RFC/1122/93.htm – Lorenzo Von Matterhorn Mar 18 '13 at 23:28
  • 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? – user138126 Mar 18 '13 at 23:31
  • 1
    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. – Wayne Johnston Mar 18 '13 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.