tst_checksum_get - Return the IPV6_CHECKSUM socket option from kernel
To check whether the IPV6_CHECKSUM option can be used with getsockopt() to where the checksum is located.
./tst_checksum_get [-tooloption ...] -tooloption : v6api tool option
1. Create an IPv6 socket with SOCK_RAW type 2. Get the value of IPV6_CHECKSUM option 3. Check A: The value of IPV6_CHECKSUM option is -1 4. Set the value of IPV6_CHECKSUM option to 2 5. Get the value of IPV6_CHECKSUM option 6. Check B: The value of IPV6_CHECKSUM option is 2 7. Create an IPv6 socket with SOCK_STREAM type 8. Get the value of IPV6_CHECKSUM option 9. Check C: An attempt to get IPV6_CHECKSUM will fail 10.Create an IPv6 socket with SOCK_DGRAM type 11.Get the value of IPV6_CHECKSUM option 12.Check D: An attempt to get IPV6_CHECKSUM will fail
None
RFC 3542
3.1. Checksums
The kernel will calculate and insert the ICMPv6 checksum for ICMPv6 raw sockets, since this checksum is mandatory.
For other raw IPv6 sockets (that is, for raw IPv6 sockets created with a third argument other than IPPROTO_ICMPV6), the application must set the new IPV6_CHECKSUM socket option to have the kernel (1) compute and store a checksum for output, and (2) verify the received checksum on input, discarding the packet if the checksum is in error. This option prevents applications from having to perform source address selection on the packets they send. The checksum will incorporate the IPv6 pseudo-header, defined in Section 8.1 of [RFC- 2460]. This new socket option also specifies an integer offset into the user data of where the checksum is located.
int offset = 2; setsockopt(fd, IPPROTO_IPV6, IPV6_CHECKSUM, &offset, sizeof(offset));
By default, this socket option is disabled. Setting the offset to -1 also disables the option. By disabled we mean (1) the kernel will not calculate and store a checksum for outgoing packets, and (2) the kernel will not verify a checksum for received packets.
This option assumes the use of the 16-bit one's complement of the one's complement sum as the checksum algorithm and that the checksum field is aligned on a 16-bit boundary. Thus, specifying a positive odd value as offset is invalid, and setsockopt() will fail for such offset values.
An attempt to set IPV6_CHECKSUM for an ICMPv6 socket will fail. Also, an attempt to set or get IPV6_CHECKSUM for a non-raw IPv6 socket will fail.
(Note: Since the checksum is always calculated by the kernel for an ICMPv6 socket, applications are not able to generate ICMPv6 packets with incorrect checksums (presumably for testing purposes) using this API.)