google / netstack

IPv4 and IPv6 userland network stack
Apache License 2.0
3.08k stars 278 forks source link

ICMPv4 EchoReply packet's checksum is wrong #26

Closed buptczq closed 5 years ago

buptczq commented 5 years ago

60971295-6778dd80-a356-11e9-8078-b867f449333d

The checksum of echo packet is set here for raw socket: https://github.com/google/netstack/blob/fe7dc3818d9b08d736b27c462a7de273c0fdbd27/tcpip/network/ipv4/icmp.go#L91-L93

The checksum of reply packet is calculated here without clearing the checksum in header: https://github.com/google/netstack/blob/fe7dc3818d9b08d736b27c462a7de273c0fdbd27/tcpip/network/ipv4/icmp.go#L99-L101

Is it should be written as the following?

        pkt.SetType(header.ICMPv4EchoReply)
        // Clear the checksum
        pkt.SetChecksum(0)
        pkt.SetChecksum(^header.Checksum(pkt, header.ChecksumVV(vv, 0)))
hbhasker commented 5 years ago

Do you mind refiling this under github.com/google/gvisor. This repo is a read-only fork of the netstack included in gVisor. This repo is not usually actively monitored nor do we directly commit to this repo.