0

Have been working on simulating "Router Advertisement" in OVS for certain requests, for that I constructed a ICMPv6 pkt with all the fields correct except the checksum, wireshark gives an error on the checksum part.

ICMP6 checksum should include src + dst + icmp_length + next_header but following code is calculating incorrectly. Am I missing something ? appreciate the help guys.

struct nd_router_advert *ra; 
struct ofpbuf *ra_rsp;
struct ovs_16aligned_ip6_hdr *nh;
.
.
.
.
.
ofpbuf_set_l3(ra_rsp, nh);
nh->ip6_vfc = 0x60;
nh->ip6_plen = htons(sizeof(*ra));
nh->ip6_nxt = IPPROTO_ICMPV6;
.
.
ofpbuf_set_l4(ra_rsp, ra);
ra->nd_ra_type = ND_ROUTER_ADVERT;
ra->nd_ra_code = 0; 
ra->nd_ra_cksum = htons(0);
ra->nd_ra_curhoplimit = 255; 
ra->nd_ra_flags_reserved = 0; 
ra->nd_ra_router_lifetime = htons(9000);
ra->nd_ra_reachable = htons(0);
ra->nd_ra_retransmit = htons(0);

packet_set_ipv6(ra_rsp, IPPROTO_ICMPV6, src, dst, 0, 0, 212);
ra->nd_ra_cksum = recalc_csum16(ra->nd_ra_cksum, 0, htons(sizeof(*ra)));
ra->nd_ra_cksum = recalc_csum32(ra->nd_ra_cksum, 0, IPPROTO_ICMPV6);
vindyz
  • 1,079
  • 2
  • 11
  • 23

1 Answers1

1

The ICMPv6 checksum is calculated over the the sum of the entire ICMPv6 message. The definition of how to calculate the checksum is in RFC 4441, ICMPv6 (ICMP for IPv6), Section 2.3, Message Checksum Calculation:

2.3. Message Checksum Calculation

The checksum is the 16-bit one's complement of the one's complement sum of the entire ICMPv6 message, starting with the ICMPv6 message type field, and prepended with a "pseudo-header" of IPv6 header fields, as specified in [IPv6, Section 8.1]. The Next Header value used in the pseudo-header is 58. (The inclusion of a pseudo-header in the ICMPv6 checksum is a change from IPv4; see [IPv6] for the rationale for this change.)

For computing the checksum, the checksum field is first set to zero.

Community
  • 1
  • 1
Ron Maupin
  • 6,180
  • 4
  • 29
  • 36