]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
tests/rrl: check endian-independent hash input
authorMark Karpilovskij <mark.karpilovskij@nic.cz>
Thu, 14 Mar 2019 14:42:42 +0000 (15:42 +0100)
committerDaniel Salzman <daniel.salzman@nic.cz>
Tue, 2 Apr 2019 16:39:56 +0000 (18:39 +0200)
tests/modules/test_rrl.c

index bbcc5be8677b1276a55a7f909613397f3e145b79..432bb9f17c52de9c04f69b4d864f023afe5dae9f 100644 (file)
@@ -21,6 +21,7 @@
 #include "libknot/libknot.h"
 #include "contrib/sockaddr.h"
 #include "knot/modules/rrl/functions.c"
+#include "stdio.h"
 
 /* Enable time-dependent tests. */
 //#define ENABLE_TIMED_TESTS
@@ -125,7 +126,7 @@ int main(int argc, char *argv[])
        rrl_table_t *rrl = rrl_create(RRL_SIZE, rate);
        ok(rrl != NULL, "rrl: create");
 
-       /* 4. N unlimited requests. */
+       /* 2. N unlimited requests. */
        knot_dname_t *zone = knot_dname_from_str_alloc("rrl.");
 
        struct sockaddr_storage addr;
@@ -142,6 +143,16 @@ int main(int argc, char *argv[])
        }
        is_int(0, ret, "rrl: unlimited IPv4/v6 requests");
 
+       /* 3. Endian-independent hash input buffer. */
+       uint8_t buf[RRL_CLSBLK_MAXLEN];
+       // CLS_LARGE + remote + dname wire length + dname wire.
+       uint8_t expectedv4[] = "\x10\x01\x02\x03\x00\x00\x00\x00\x00\x06\x00\x04""beef";
+       rrl_classify(buf, sizeof(buf), &addr, &rq, qname);
+       is_int(0, memcmp(buf, expectedv4, sizeof(expectedv4)), "rrl: IPv4 hash input buffer");
+       uint8_t expectedv6[] = "\x10\x11\x22\x33\x44\x55\x66\x77\x00\x06\x00\x04""beef";
+       rrl_classify(buf, sizeof(buf), &addr6, &rq, qname);
+       is_int(0, memcmp(buf, expectedv6, sizeof(expectedv6)), "rrl: IPv6 hash input buffer");
+
 #ifdef ENABLE_TIMED_TESTS
        /* 5. limited request */
        ret = rrl_query(rrl, &addr, &rq, zone, NULL);