appneta / tcpreplay

Pcap editing and replay tools for *NIX and Windows - Users please download source from
http://tcpreplay.appneta.com/wiki/installation.html#downloads
1.17k stars 268 forks source link

Fix UDP checksum recalculation #814

Closed green-nsk closed 9 months ago

green-nsk commented 1 year ago
If the computed  checksum  is zero,  it is transmitted  as all ones (the
equivalent  in one's complement  arithmetic).   An all zero  transmitted
checksum  value means that the transmitter  generated  no checksum  (for
debugging or for higher level protocols that don't care).

https://www.ietf.org/rfc/rfc768.txt

fklassen commented 9 months ago

Closing as invalid. As per the above spec, transmitting a checksum of 0 is valid (at least for IPv4) in cases where the protocol does not need a checksum. The only time you would do this is the COMPUTED checksum is zero.

I'll update my reasoning. A one's complement checksum will never be 0. A 0 value will become 0xffff. Therefore this change is redundant.

#define CHECKSUM_CARRY(x) (x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff))
green-nsk commented 9 months ago

I assume the whole point of computing the checksum it to transmit non-null value. Otherwise you could as well return 0;, it would also be technically valid