#include <inttypes.h>
#include <netinet/in.h>
#include <netinet/ip.h>
+#include <netinet/ip6.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
mark('#');
}
+/* Check the IPv6 pseudoheader calculation. */
+static void
+test_pseudov6(void)
+{
+ ovs_be16 csum;
+ /* Try an IPv6 header similar to one that the tunnel code
+ * might generate. */
+ struct ovs_16aligned_ip6_hdr ip6 = {
+ .ip6_vfc = 0x60,
+ .ip6_hlim = 64,
+ .ip6_nxt = IPPROTO_UDP,
+ .ip6_plen = htons(1410),
+ .ip6_src = { .be16 = { htons(0x2001), htons(0xcafe), 0, 0, 0, 0, 0, htons(0x92) } },
+ .ip6_dst = { .be16 = { htons(0x2001), htons(0xcafe), 0, 0, 0, 0, 0, htons(0x91) } }
+ };
+
+ csum = csum_finish(packet_csum_pseudoheader6(&ip6, htonl(1410)));
+ assert(csum == htons(0x234a));
+
+ /* And also test something totally different to check for
+ * corner cases. */
+ memset(&ip6, 0xff, sizeof ip6);
+ csum = csum_finish(packet_csum_pseudoheader6(&ip6, htonl(0xffff)));
+ assert(csum == htons(0xff00));
+
+ /* Test 0 sum */
+ memset(&ip6, 0x00, sizeof ip6);
+ csum = csum_finish(packet_csum_pseudoheader6(&ip6, htonl(0x0000)));
+ assert(csum == htons(0xffff));
+
+ /* Test 0xffff sum */
+ memset(&ip6, 0x00, sizeof ip6);
+ csum = csum_finish(packet_csum_pseudoheader6(&ip6, htonl(0xffff)));
+ assert(csum == htons(0x0000));
+
+ mark('#');
+}
+
static void
test_csum_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
{
test_rfc1624();
test_crc32c();
test_pseudo();
+ test_pseudov6();
/* Test recalc_csum16(). */
for (i = 0; i < 32; i++) {