Incorrect UDP checksum on IPv4 calculation if the checksum is 0
- Dominant language
- Go
- Stars
- 6.8k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
UDP on IPv4 is optional, and uses a 0 checksum to indicate no checksum is present. Per [RFC 768](https://tools.ietf.org/html/rfc768), if a computed checksum yields 0, it should be sent as all ones (essentially adding a second one's complement). gopacket does not do this, and will send a 0 checksum.
I believe this is because the UDP checksum simply re-uses the [TCP checksum implementation](https://github.com/google/gopacket/blob/d26664f9dcd3d61e328bc0bd3ad94eac7ce49ecb/layers/tcpip.go#L72), which does not have this special case.
It looks like the easiest way to solve this would be to add a check in the [UDP serialization code right before assigning the computed value](https://github.com/google/gopacket/blob/a35e09f9f224786863ce609de910bc82fc4d4faf/layers/udp.go#L92). However, the documentation for the [TCP checksum implementation](https://github.com/google/gopacket/blob/d26664f9dcd3d61e328bc0bd3ad94eac7ce49ecb/layers/tcpip.go#L72) states that it also computes UDP checksums, which means the fix should probably actually go [before the checksum is returned](https://github.com/google/gopacket/blob/d26664f9dcd3d61e328bc0bd3ad94eac7ce49ecb/layers/tcpip.go#L87).
Thoughts?
Contributor guide
Assessment
This issue has not been assessed yet.