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

@ -62,7 +62,7 @@ void ICMP_Analyzer::DeliverPacket(int len, const u_char* data,
break;
case IPPROTO_ICMPV6:
chksum = icmp6_checksum(icmpp, ip->IP6_Hdr(), len);
chksum = icmp6_checksum(icmpp, ip, len);
break;
default:

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);

View file

@ -65,18 +65,17 @@ inline int seq_delta(uint32 a, uint32 b)
}
class IPAddr;
class IP_Hdr;
// Returns the ones-complement checksum of a chunk of b short-aligned bytes.
extern int ones_complement_checksum(const void* p, int b, uint32 sum);
extern int ones_complement_checksum(const IPAddr& a, uint32 sum);
extern int icmp6_checksum(const struct icmp* icmpp, const struct ip6_hdr* ip6,
int len);
extern int icmp6_checksum(const struct icmp* icmpp, const IP_Hdr* ip, int len);
extern int icmp_checksum(const struct icmp* icmpp, int len);
#ifdef ENABLE_MOBILE_IPV6
class IP_Hdr;
extern int mobility_header_checksum(const IP_Hdr* ip);
#endif