From: Mark Karpilovskij Date: Thu, 14 Mar 2019 14:42:42 +0000 (+0100) Subject: tests/rrl: check endian-independent hash input X-Git-Tag: v2.9.0~299^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8b22f15adbadcb48751ad0a360687dfd151b64b;p=thirdparty%2Fknot-dns.git tests/rrl: check endian-independent hash input --- diff --git a/tests/modules/test_rrl.c b/tests/modules/test_rrl.c index bbcc5be867..432bb9f17c 100644 --- a/tests/modules/test_rrl.c +++ b/tests/modules/test_rrl.c @@ -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);