Change ICMPv6 checksum calculation to use IP_Hdr wrapper.

So that src/dst addresses used in pseudo-header are correct when
there's certain extension headers (routing/destination).

Add ICMP/ICMPv6 checksum unit tests.
This commit is contained in:
Jon Siwek 2012-04-10 11:37:08 -05:00
parent 958c6c7cf4
commit 27ba3118c1
12 changed files with 19 additions and 7 deletions

View file

@ -80,7 +80,7 @@ int mobility_header_checksum(const IP_Hdr* ip)
}
#endif
int icmp6_checksum(const struct icmp* icmpp, const struct ip6_hdr* ip6, int len)
int icmp6_checksum(const struct icmp* icmpp, const IP_Hdr* ip, int len)
{
// ICMP6 uses the same checksum function as ICMP4 but a different
// pseudo-header over which it is computed.
@ -93,8 +93,8 @@ int icmp6_checksum(const struct icmp* icmpp, const struct ip6_hdr* ip6, int len)
sum = 0;
// Pseudo-header as for UDP over IPv6 above.
sum = ones_complement_checksum((void*) ip6->ip6_src.s6_addr, 16, sum);
sum = ones_complement_checksum((void*) ip6->ip6_dst.s6_addr, 16, sum);
sum = ones_complement_checksum(ip->SrcAddr(), sum);
sum = ones_complement_checksum(ip->DstAddr(), sum);
uint32 l = htonl(len);
sum = ones_complement_checksum((void*) &l, 4, sum);