Commit bffa4eb4 authored by Mark Karpilovskij's avatar Mark Karpilovskij Committed by Daniel Salzman

mod-rrl: remove unnecessary qname length from hash

parent a8b22f15
......@@ -188,14 +188,11 @@ static int rrl_classify(uint8_t *dst, size_t maxlen, const struct sockaddr_stora
blklen += sizeof(netblk);
/* Name */
uint16_t *len_pos = (uint16_t *)(dst + blklen);
blklen += sizeof(uint16_t);
int ret = rrl_clsname(dst + blklen, maxlen - blklen, cls, req, name);
if (ret < 0) {
return ret;
}
uint16_t len = ret;
memcpy(len_pos, &len, sizeof(len));
uint8_t len = ret;
blklen += len;
return blklen;
......@@ -391,7 +388,7 @@ static rrl_item_t *rrl_hash(rrl_table_t *tbl, const struct sockaddr_storage *rem
pthread_mutex_lock(&tbl->ll);
/* Find an exact match in <id, id + HOP_LEN). */
uint8_t *qname = buf + sizeof(uint8_t) + sizeof(uint64_t);
knot_dname_t *qname = buf + sizeof(uint8_t) + sizeof(uint64_t);
uint64_t netblk;
memcpy(&netblk, buf + sizeof(uint8_t), sizeof(netblk));
rrl_item_t match = {
......@@ -400,7 +397,7 @@ static rrl_item_t *rrl_hash(rrl_table_t *tbl, const struct sockaddr_storage *rem
.ntok = tbl->rate * RRL_CAPACITY,
.cls = buf[0],
.flags = RRL_BF_NULL,
.qname = SipHash24(&tbl->key, qname + 1, qname[0]),
.qname = SipHash24(&tbl->key, qname, knot_dname_size(qname)),
.time = stamp
};
......
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -146,10 +146,10 @@ int main(int argc, char *argv[])
/* 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";
uint8_t expectedv4[] = "\x10\x01\x02\x03\x00\x00\x00\x00\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";
uint8_t expectedv6[] = "\x10\x11\x22\x33\x44\x55\x66\x77\x00\x04""beef";
rrl_classify(buf, sizeof(buf), &addr6, &rq, qname);
is_int(0, memcmp(buf, expectedv6, sizeof(expectedv6)), "rrl: IPv6 hash input buffer");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment