diff options
Diffstat (limited to 'tests/test-csum.c')
-rw-r--r-- | tests/test-csum.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test-csum.c b/tests/test-csum.c index e25fb3d67..97638b916 100644 --- a/tests/test-csum.c +++ b/tests/test-csum.c @@ -20,11 +20,13 @@ #include <assert.h> #include <inttypes.h> #include <netinet/in.h> +#include <netinet/ip.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "crc32c.h" #include "ovstest.h" +#include "packets.h" #include "random.h" #include "unaligned.h" #include "util.h" @@ -175,6 +177,37 @@ test_crc32c(void) mark('#'); } +/* Check the IP pseudoheader calculation. */ +static void +test_pseudo(void) +{ + ovs_be16 csum; + /* Try an IP header similar to one that the tunnel code + * might generate. */ + struct ip_header ip = { + .ip_ihl_ver = IP_IHL_VER(5, 4), + .ip_tos = 0, + .ip_tot_len = htons(134), + .ip_id = 0, + .ip_frag_off = htons(IP_DF), + .ip_ttl = 64, + .ip_proto = IPPROTO_UDP, + .ip_csum = htons(0x1265), + .ip_src = { .hi = htons(0x1400), .lo = htons(0x0002) }, + .ip_dst = { .hi = htons(0x1400), .lo = htons(0x0001) } + }; + + csum = csum_finish(packet_csum_pseudoheader(&ip)); + assert(csum == htons(0xd779)); + + /* And also test something totally different to check for + * corner cases. */ + memset(&ip, 0xff, sizeof ip); + csum = csum_finish(packet_csum_pseudoheader(&ip)); + assert(csum == htons(0xff3c)); + + mark('#'); +} static void test_csum_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) @@ -239,6 +272,7 @@ test_csum_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) test_rfc1624(); test_crc32c(); + test_pseudo(); /* Test recalc_csum16(). */ for (i = 0; i < 32; i++) { |