How do I validate the ICMPv6 checksum? (Why am do I keep getting a checksum of 0x3fff?)

前端 未结 3 1783
不知归路
不知归路 2021-01-13 05:05

I\'m working on a Linux userspace program that receives IPv6 router advertisement packets. As part of RFC4861 I need to verify the ICMPv6 checksum. Based on my research, mos

3条回答
  •  花落未央
    2021-01-13 06:04

    If this is running on a little-endian machine then I think you need (much) more byte swapping while accumulating the checksum.

    For example on a little endian machine the s6_addr16[0] element of a typical IPv6 address starting 2001: will contain 0x0120, and not 0x2001. This will put your carry bits in the wrong place.

    The length code appears OK since you are using htonl() there, but the 0x00 0x00 0x00 0x58 and subsequent message accumulation logic does not. I think any left over bits should end up in the high byte too, not the low byte as happens in your code.

    Also, using 0x0000 for the pseudo header checksum bytes is what you should do when generating the checksum. To validate the checksum use the actual checksum bytes received in the IPv6 RA, and then you should get 0xffff as the eventual value.

提交回复
热议问题