checksum: Fix calculation for ICMP checksum on IPv4

We need to zero out the checksum field before calculating the
checksum, of course. I have no idea how this passed the "icmp" test
set, looking into it.

Reported-by: Paul Holzinger <pholzing@redhat.com>
Fixes: 67ab617172 ("Add csum_icmp4() helper for calculating ICMP checksums")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Stefano Brivio 2022-10-25 18:01:11 +02:00
parent c11277b94f
commit e67039f712

View file

@ -160,10 +160,13 @@ void csum_udp4(struct udphdr *udp4hr, in_addr_t saddr, in_addr_t daddr,
*/ */
void csum_icmp4(struct icmphdr *icmp4hr, const void *payload, size_t len) void csum_icmp4(struct icmphdr *icmp4hr, const void *payload, size_t len)
{ {
/* Partial checksum for ICMP header alone */ uint32_t psum;
uint32_t psum = sum_16b(icmp4hr, sizeof(*icmp4hr));
icmp4hr->checksum = 0; icmp4hr->checksum = 0;
/* Partial checksum for ICMP header alone */
psum = sum_16b(icmp4hr, sizeof(*icmp4hr));
icmp4hr->checksum = csum_unaligned(payload, len, psum); icmp4hr->checksum = csum_unaligned(payload, len, psum);
} }