Fix ICMPv4 EchoReply packet checksum

The checksum was not being reset before being re-calculated and sent out.
This caused the sent checksum to always be `0x0800`.

Fixes #605.

PiperOrigin-RevId: 260965059
This commit is contained in:
Austin Kiekintveld 2019-07-31 11:25:25 -07:00 committed by gVisor bot
parent c6e6d92cb1
commit 12c4eb294a
2 changed files with 3 additions and 3 deletions

View File

@ -94,6 +94,7 @@ func (e *endpoint) handleICMP(r *stack.Route, netHeader buffer.View, vv buffer.V
pkt := header.ICMPv4(hdr.Prepend(header.ICMPv4MinimumSize))
copy(pkt, h)
pkt.SetType(header.ICMPv4EchoReply)
pkt.SetChecksum(0)
pkt.SetChecksum(^header.Checksum(pkt, header.ChecksumVV(vv, 0)))
sent := stats.ICMP.V4PacketsSent
if err := r.WritePacket(nil /* gso */, hdr, vv, header.ICMPv4ProtocolNumber, r.DefaultTTL()); err != nil {

View File

@ -470,9 +470,8 @@ void RawSocketICMPTest::ExpectICMPSuccess(const struct icmphdr& icmp) {
EXPECT_EQ(recvd_icmp->un.echo.id, icmp.un.echo.id);
// A couple are different.
EXPECT_EQ(recvd_icmp->type, ICMP_ECHOREPLY);
// The checksum is computed in such a way that it is guaranteed to have
// changed.
EXPECT_NE(recvd_icmp->checksum, icmp.checksum);
// The checksum computed over the reply should still be valid.
EXPECT_EQ(Checksum(recvd_icmp), 0);
break;
}
}