Commit 71bce246 authored by Daniel Salzman's avatar Daniel Salzman

rrl: tiny code cleanup

parent e9a141bb
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 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
......@@ -98,7 +98,7 @@ static uint8_t rrl_clsid(rrl_req_t *p)
}
/* Check if answered from a qname */
if (ret == CLS_NORMAL && p->flags & RRL_WILDCARD) {
if (ret == CLS_NORMAL && p->flags & RRL_REQ_WILDCARD) {
return CLS_WILDCARD;
}
......@@ -385,10 +385,13 @@ rrl_item_t *rrl_hash(rrl_table_t *t, const struct sockaddr_storage *a, rrl_req_t
/* Find an exact match in <id, id + HOP_LEN). */
uint16_t *qname = (uint16_t *)(buf + sizeof(uint8_t) + sizeof(uint64_t));
rrl_item_t match = {
0, *((uint64_t *)(buf + 1)), /* hop, netblk */
t->rate * RRL_CAPACITY, /* ntok */
buf[0], RRL_BF_NULL, /* cls, flags */
hash((char *)(qname + 1), *qname), stamp /* qname, time */
.hop = 0,
.netblk = *((uint64_t *)(buf + 1)),
.ntok = t->rate * RRL_CAPACITY,
.cls = buf[0],
.flags = RRL_BF_NULL,
.qname = hash((char *)(qname + 1), *qname),
.time = stamp
};
unsigned d = find_match(t, id, &match);
......
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 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
......@@ -27,12 +27,6 @@
#define RRL_SLIP_MAX 100
#define RRL_LOCK_GRANULARITY 32 /* Last digit granularity */
/*! \brief RRL flags. */
enum {
RRL_NOFLAG = 0 << 0, /*!< No flags. */
RRL_WILDCARD = 1 << 1 /*!< Query to wildcard name. */
};
/*!
* \brief RRL hash bucket.
*/
......@@ -68,13 +62,19 @@ typedef struct {
rrl_item_t arr[]; /* Buckets. */
} rrl_table_t;
/*! \brief RRL request flags. */
typedef enum {
RRL_REQ_NOFLAG = 0 << 0, /*!< No flags. */
RRL_REQ_WILDCARD = 1 << 1 /*!< Query to wildcard name. */
} rrl_req_flag_t;
/*!
* \brief RRL request descriptor.
*/
typedef struct {
const uint8_t *w;
uint16_t len;
unsigned flags;
rrl_req_flag_t flags;
knot_pkt_t *query;
} rrl_req_t;
......
......@@ -103,7 +103,7 @@ static int ratelimit_apply(int state, knot_pkt_t *pkt, struct query_data *qdata,
};
if (!EMPTY_LIST(qdata->wildcards)) {
req.flags = RRL_WILDCARD;
req.flags = RRL_REQ_WILDCARD;
}
// Take the zone name if known.
......
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