mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
apply the modified style
This commit is contained in:
181
lib/dns/rrl.c
181
lib/dns/rrl.c
@@ -34,9 +34,8 @@
|
||||
#include <dns/rrl.h>
|
||||
#include <dns/view.h>
|
||||
|
||||
static void
|
||||
log_end(dns_rrl_t *rrl, dns_rrl_entry_t *e, bool early, char *log_buf,
|
||||
unsigned int log_buf_len);
|
||||
static void log_end(dns_rrl_t *rrl, dns_rrl_entry_t *e, bool early,
|
||||
char *log_buf, unsigned int log_buf_len);
|
||||
|
||||
/*
|
||||
* Get a modulus for a hash function that is tolerably likely to be
|
||||
@@ -47,8 +46,7 @@ log_end(dns_rrl_t *rrl, dns_rrl_entry_t *e, bool early, char *log_buf,
|
||||
* times the square of the last prime and better than a multiplicative hash.
|
||||
*/
|
||||
static int
|
||||
hash_divisor(unsigned int initial)
|
||||
{
|
||||
hash_divisor(unsigned int initial) {
|
||||
static uint16_t primes[] = {
|
||||
3,
|
||||
5,
|
||||
@@ -89,9 +87,9 @@ hash_divisor(unsigned int initial)
|
||||
929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009,
|
||||
#endif /* if 0 */
|
||||
};
|
||||
int divisions, tries;
|
||||
int divisions, tries;
|
||||
unsigned int result;
|
||||
uint16_t * pp, p;
|
||||
uint16_t *pp, p;
|
||||
|
||||
result = initial;
|
||||
|
||||
@@ -135,8 +133,7 @@ hash_divisor(unsigned int initial)
|
||||
* Convert a timestamp to a number of seconds in the past.
|
||||
*/
|
||||
static inline int
|
||||
delta_rrl_time(isc_stdtime_t ts, isc_stdtime_t now)
|
||||
{
|
||||
delta_rrl_time(isc_stdtime_t ts, isc_stdtime_t now) {
|
||||
int delta;
|
||||
|
||||
delta = now - ts;
|
||||
@@ -158,8 +155,7 @@ delta_rrl_time(isc_stdtime_t ts, isc_stdtime_t now)
|
||||
}
|
||||
|
||||
static inline int
|
||||
get_age(const dns_rrl_t *rrl, const dns_rrl_entry_t *e, isc_stdtime_t now)
|
||||
{
|
||||
get_age(const dns_rrl_t *rrl, const dns_rrl_entry_t *e, isc_stdtime_t now) {
|
||||
if (!e->ts_valid) {
|
||||
return (DNS_RRL_FOREVER);
|
||||
}
|
||||
@@ -167,11 +163,10 @@ get_age(const dns_rrl_t *rrl, const dns_rrl_entry_t *e, isc_stdtime_t now)
|
||||
}
|
||||
|
||||
static inline void
|
||||
set_age(dns_rrl_t *rrl, dns_rrl_entry_t *e, isc_stdtime_t now)
|
||||
{
|
||||
set_age(dns_rrl_t *rrl, dns_rrl_entry_t *e, isc_stdtime_t now) {
|
||||
dns_rrl_entry_t *e_old;
|
||||
unsigned int ts_gen;
|
||||
int i, ts;
|
||||
unsigned int ts_gen;
|
||||
int i, ts;
|
||||
|
||||
ts_gen = rrl->ts_gen;
|
||||
ts = now - rrl->ts_bases[ts_gen];
|
||||
@@ -200,7 +195,8 @@ set_age(dns_rrl_t *rrl, dns_rrl_entry_t *e, isc_stdtime_t now)
|
||||
for (e_old = ISC_LIST_TAIL(rrl->lru), i = 0;
|
||||
e_old != NULL && (e_old->ts_gen == ts_gen ||
|
||||
!ISC_LINK_LINKED(e_old, hlink));
|
||||
e_old = ISC_LIST_PREV(e_old, lru), ++i) {
|
||||
e_old = ISC_LIST_PREV(e_old, lru), ++i)
|
||||
{
|
||||
e_old->ts_valid = false;
|
||||
}
|
||||
if (i != 0) {
|
||||
@@ -225,13 +221,12 @@ set_age(dns_rrl_t *rrl, dns_rrl_entry_t *e, isc_stdtime_t now)
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
expand_entries(dns_rrl_t *rrl, int newsize)
|
||||
{
|
||||
unsigned int bsize;
|
||||
expand_entries(dns_rrl_t *rrl, int newsize) {
|
||||
unsigned int bsize;
|
||||
dns_rrl_block_t *b;
|
||||
dns_rrl_entry_t *e;
|
||||
double rate;
|
||||
int i;
|
||||
double rate;
|
||||
int i;
|
||||
|
||||
if (rrl->num_entries + newsize >= rrl->max_entries &&
|
||||
rrl->max_entries != 0) {
|
||||
@@ -276,22 +271,21 @@ expand_entries(dns_rrl_t *rrl, int newsize)
|
||||
}
|
||||
|
||||
static inline dns_rrl_bin_t *
|
||||
get_bin(dns_rrl_hash_t *hash, unsigned int hval)
|
||||
{
|
||||
get_bin(dns_rrl_hash_t *hash, unsigned int hval) {
|
||||
INSIST(hash != NULL);
|
||||
return (&hash->bins[hval % hash->length]);
|
||||
}
|
||||
|
||||
static void
|
||||
free_old_hash(dns_rrl_t *rrl)
|
||||
{
|
||||
dns_rrl_hash_t * old_hash;
|
||||
dns_rrl_bin_t * old_bin;
|
||||
free_old_hash(dns_rrl_t *rrl) {
|
||||
dns_rrl_hash_t *old_hash;
|
||||
dns_rrl_bin_t *old_bin;
|
||||
dns_rrl_entry_t *e, *e_next;
|
||||
|
||||
old_hash = rrl->old_hash;
|
||||
for (old_bin = &old_hash->bins[0];
|
||||
old_bin < &old_hash->bins[old_hash->length]; ++old_bin) {
|
||||
old_bin < &old_hash->bins[old_hash->length]; ++old_bin)
|
||||
{
|
||||
for (e = ISC_LIST_HEAD(*old_bin); e != NULL; e = e_next) {
|
||||
e_next = ISC_LIST_NEXT(e, hlink);
|
||||
ISC_LINK_INIT(e, hlink);
|
||||
@@ -305,11 +299,10 @@ free_old_hash(dns_rrl_t *rrl)
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
expand_rrl_hash(dns_rrl_t *rrl, isc_stdtime_t now)
|
||||
{
|
||||
expand_rrl_hash(dns_rrl_t *rrl, isc_stdtime_t now) {
|
||||
dns_rrl_hash_t *hash;
|
||||
int old_bins, new_bins, hsize;
|
||||
double rate;
|
||||
int old_bins, new_bins, hsize;
|
||||
double rate;
|
||||
|
||||
if (rrl->old_hash != NULL) {
|
||||
free_old_hash(rrl);
|
||||
@@ -355,8 +348,7 @@ expand_rrl_hash(dns_rrl_t *rrl, isc_stdtime_t now)
|
||||
}
|
||||
|
||||
static void
|
||||
ref_entry(dns_rrl_t *rrl, dns_rrl_entry_t *e, int probes, isc_stdtime_t now)
|
||||
{
|
||||
ref_entry(dns_rrl_t *rrl, dns_rrl_entry_t *e, int probes, isc_stdtime_t now) {
|
||||
/*
|
||||
* Make the entry most recently used.
|
||||
*/
|
||||
@@ -388,8 +380,7 @@ ref_entry(dns_rrl_t *rrl, dns_rrl_entry_t *e, int probes, isc_stdtime_t now)
|
||||
}
|
||||
|
||||
static inline bool
|
||||
key_cmp(const dns_rrl_key_t *a, const dns_rrl_key_t *b)
|
||||
{
|
||||
key_cmp(const dns_rrl_key_t *a, const dns_rrl_key_t *b) {
|
||||
if (memcmp(a, b, sizeof(dns_rrl_key_t)) == 0) {
|
||||
return (true);
|
||||
}
|
||||
@@ -397,10 +388,9 @@ key_cmp(const dns_rrl_key_t *a, const dns_rrl_key_t *b)
|
||||
}
|
||||
|
||||
static inline uint32_t
|
||||
hash_key(const dns_rrl_key_t *key)
|
||||
{
|
||||
hash_key(const dns_rrl_key_t *key) {
|
||||
uint32_t hval;
|
||||
int i;
|
||||
int i;
|
||||
|
||||
hval = key->w[0];
|
||||
for (i = sizeof(key->w) / sizeof(key->w[0]) - 1; i >= 0; --i) {
|
||||
@@ -422,11 +412,10 @@ static void
|
||||
make_key(const dns_rrl_t *rrl, dns_rrl_key_t *key,
|
||||
const isc_sockaddr_t *client_addr, dns_rdatatype_t qtype,
|
||||
const dns_name_t *qname, dns_rdataclass_t qclass,
|
||||
dns_rrl_rtype_t rtype)
|
||||
{
|
||||
dns_name_t base;
|
||||
dns_rrl_rtype_t rtype) {
|
||||
dns_name_t base;
|
||||
dns_offsets_t base_offsets;
|
||||
int labels, i;
|
||||
int labels, i;
|
||||
|
||||
memset(key, 0, sizeof(*key));
|
||||
|
||||
@@ -448,7 +437,8 @@ make_key(const dns_rrl_t *rrl, dns_rrl_key_t *key,
|
||||
* Ignore the first label of wildcards.
|
||||
*/
|
||||
if ((qname->attributes & DNS_NAMEATTR_WILDCARD) != 0 &&
|
||||
(labels = dns_name_countlabels(qname)) > 1) {
|
||||
(labels = dns_name_countlabels(qname)) > 1)
|
||||
{
|
||||
dns_name_init(&base, base_offsets);
|
||||
dns_name_getlabelsequence(qname, 1, labels - 1, &base);
|
||||
key->s.qname_hash = dns_name_fullhash(&base, false);
|
||||
@@ -474,8 +464,7 @@ make_key(const dns_rrl_t *rrl, dns_rrl_key_t *key,
|
||||
}
|
||||
|
||||
static inline dns_rrl_rate_t *
|
||||
get_rate(dns_rrl_t *rrl, dns_rrl_rtype_t rtype)
|
||||
{
|
||||
get_rate(dns_rrl_t *rrl, dns_rrl_rtype_t rtype) {
|
||||
switch (rtype) {
|
||||
case DNS_RRL_RTYPE_QUERY:
|
||||
return (&rrl->responses_per_second);
|
||||
@@ -496,10 +485,9 @@ get_rate(dns_rrl_t *rrl, dns_rrl_rtype_t rtype)
|
||||
}
|
||||
|
||||
static int
|
||||
response_balance(dns_rrl_t *rrl, const dns_rrl_entry_t *e, int age)
|
||||
{
|
||||
response_balance(dns_rrl_t *rrl, const dns_rrl_entry_t *e, int age) {
|
||||
dns_rrl_rate_t *ratep;
|
||||
int balance, rate;
|
||||
int balance, rate;
|
||||
|
||||
if (e->key.s.rtype == DNS_RRL_RTYPE_TCP) {
|
||||
rate = 1;
|
||||
@@ -522,14 +510,13 @@ static dns_rrl_entry_t *
|
||||
get_entry(dns_rrl_t *rrl, const isc_sockaddr_t *client_addr,
|
||||
dns_rdataclass_t qclass, dns_rdatatype_t qtype,
|
||||
const dns_name_t *qname, dns_rrl_rtype_t rtype, isc_stdtime_t now,
|
||||
bool create, char *log_buf, unsigned int log_buf_len)
|
||||
{
|
||||
dns_rrl_key_t key;
|
||||
uint32_t hval;
|
||||
bool create, char *log_buf, unsigned int log_buf_len) {
|
||||
dns_rrl_key_t key;
|
||||
uint32_t hval;
|
||||
dns_rrl_entry_t *e;
|
||||
dns_rrl_hash_t * hash;
|
||||
dns_rrl_bin_t * new_bin, *old_bin;
|
||||
int probes, age;
|
||||
dns_rrl_hash_t *hash;
|
||||
dns_rrl_bin_t *new_bin, *old_bin;
|
||||
int probes, age;
|
||||
|
||||
make_key(rrl, &key, client_addr, qtype, qname, qclass, rtype);
|
||||
hval = hash_key(&key);
|
||||
@@ -585,8 +572,8 @@ get_entry(dns_rrl_t *rrl, const isc_sockaddr_t *client_addr,
|
||||
* Try to make more entries if none are idle.
|
||||
* Steal the oldest entry if we cannot create more.
|
||||
*/
|
||||
for (e = ISC_LIST_TAIL(rrl->lru); e != NULL;
|
||||
e = ISC_LIST_PREV(e, lru)) {
|
||||
for (e = ISC_LIST_TAIL(rrl->lru); e != NULL; e = ISC_LIST_PREV(e, lru))
|
||||
{
|
||||
if (!ISC_LINK_LINKED(e, hlink)) {
|
||||
break;
|
||||
}
|
||||
@@ -624,9 +611,8 @@ get_entry(dns_rrl_t *rrl, const isc_sockaddr_t *client_addr,
|
||||
}
|
||||
|
||||
static void
|
||||
debit_log(const dns_rrl_entry_t *e, int age, const char *action)
|
||||
{
|
||||
char buf[sizeof("age=2147483647")];
|
||||
debit_log(const dns_rrl_entry_t *e, int age, const char *action) {
|
||||
char buf[sizeof("age=2147483647")];
|
||||
const char *age_str;
|
||||
|
||||
if (age == DNS_RRL_FOREVER) {
|
||||
@@ -643,9 +629,8 @@ debit_log(const dns_rrl_entry_t *e, int age, const char *action)
|
||||
static inline dns_rrl_result_t
|
||||
debit_rrl_entry(dns_rrl_t *rrl, dns_rrl_entry_t *e, double qps, double scale,
|
||||
const isc_sockaddr_t *client_addr, isc_stdtime_t now,
|
||||
char *log_buf, unsigned int log_buf_len)
|
||||
{
|
||||
int rate, new_rate, slip, new_slip, age, log_secs, min;
|
||||
char *log_buf, unsigned int log_buf_len) {
|
||||
int rate, new_rate, slip, new_slip, age, log_secs, min;
|
||||
dns_rrl_rate_t *ratep;
|
||||
dns_rrl_entry_t const *credit_e;
|
||||
|
||||
@@ -785,8 +770,7 @@ debit_rrl_entry(dns_rrl_t *rrl, dns_rrl_entry_t *e, double qps, double scale,
|
||||
}
|
||||
|
||||
static inline dns_rrl_qname_buf_t *
|
||||
get_qname(dns_rrl_t *rrl, const dns_rrl_entry_t *e)
|
||||
{
|
||||
get_qname(dns_rrl_t *rrl, const dns_rrl_entry_t *e) {
|
||||
dns_rrl_qname_buf_t *qbuf;
|
||||
|
||||
qbuf = rrl->qnames[e->log_qname];
|
||||
@@ -797,8 +781,7 @@ get_qname(dns_rrl_t *rrl, const dns_rrl_entry_t *e)
|
||||
}
|
||||
|
||||
static inline void
|
||||
free_qname(dns_rrl_t *rrl, dns_rrl_entry_t *e)
|
||||
{
|
||||
free_qname(dns_rrl_t *rrl, dns_rrl_entry_t *e) {
|
||||
dns_rrl_qname_buf_t *qbuf;
|
||||
|
||||
qbuf = get_qname(rrl, e);
|
||||
@@ -809,8 +792,7 @@ free_qname(dns_rrl_t *rrl, dns_rrl_entry_t *e)
|
||||
}
|
||||
|
||||
static void
|
||||
add_log_str(isc_buffer_t *lb, const char *str, unsigned int str_len)
|
||||
{
|
||||
add_log_str(isc_buffer_t *lb, const char *str, unsigned int str_len) {
|
||||
isc_region_t region;
|
||||
|
||||
isc_buffer_availableregion(lb, ®ion);
|
||||
@@ -833,13 +815,13 @@ static void
|
||||
make_log_buf(dns_rrl_t *rrl, dns_rrl_entry_t *e, const char *str1,
|
||||
const char *str2, bool plural, const dns_name_t *qname,
|
||||
bool save_qname, dns_rrl_result_t rrl_result,
|
||||
isc_result_t resp_result, char *log_buf, unsigned int log_buf_len)
|
||||
{
|
||||
isc_buffer_t lb;
|
||||
isc_result_t resp_result, char *log_buf,
|
||||
unsigned int log_buf_len) {
|
||||
isc_buffer_t lb;
|
||||
dns_rrl_qname_buf_t *qbuf;
|
||||
isc_netaddr_t cidr;
|
||||
char strbuf[ISC_MAX(sizeof("/123"), sizeof(" (12345678)"))];
|
||||
const char * rstr;
|
||||
isc_netaddr_t cidr;
|
||||
char strbuf[ISC_MAX(sizeof("/123"), sizeof(" (12345678)"))];
|
||||
const char *rstr;
|
||||
isc_result_t msg_result;
|
||||
|
||||
if (log_buf_len <= 1) {
|
||||
@@ -926,7 +908,8 @@ make_log_buf(dns_rrl_t *rrl, dns_rrl_entry_t *e, const char *str1,
|
||||
if (e->key.s.rtype == DNS_RRL_RTYPE_QUERY ||
|
||||
e->key.s.rtype == DNS_RRL_RTYPE_REFERRAL ||
|
||||
e->key.s.rtype == DNS_RRL_RTYPE_NODATA ||
|
||||
e->key.s.rtype == DNS_RRL_RTYPE_NXDOMAIN) {
|
||||
e->key.s.rtype == DNS_RRL_RTYPE_NXDOMAIN)
|
||||
{
|
||||
qbuf = get_qname(rrl, e);
|
||||
if (save_qname && qbuf == NULL && qname != NULL &&
|
||||
dns_name_isabsolute(qname)) {
|
||||
@@ -983,8 +966,7 @@ make_log_buf(dns_rrl_t *rrl, dns_rrl_entry_t *e, const char *str1,
|
||||
|
||||
static void
|
||||
log_end(dns_rrl_t *rrl, dns_rrl_entry_t *e, bool early, char *log_buf,
|
||||
unsigned int log_buf_len)
|
||||
{
|
||||
unsigned int log_buf_len) {
|
||||
if (e->logged) {
|
||||
make_log_buf(rrl, e, early ? "*" : NULL,
|
||||
rrl->log_only ? "would stop limiting "
|
||||
@@ -1005,10 +987,9 @@ log_end(dns_rrl_t *rrl, dns_rrl_entry_t *e, bool early, char *log_buf,
|
||||
*/
|
||||
static void
|
||||
log_stops(dns_rrl_t *rrl, isc_stdtime_t now, int limit, char *log_buf,
|
||||
unsigned int log_buf_len)
|
||||
{
|
||||
unsigned int log_buf_len) {
|
||||
dns_rrl_entry_t *e;
|
||||
int age;
|
||||
int age;
|
||||
|
||||
for (e = rrl->last_logged; e != NULL; e = ISC_LIST_PREV(e, lru)) {
|
||||
if (!e->logged) {
|
||||
@@ -1049,16 +1030,15 @@ dns_rrl_result_t
|
||||
dns_rrl(dns_view_t *view, const isc_sockaddr_t *client_addr, bool is_tcp,
|
||||
dns_rdataclass_t qclass, dns_rdatatype_t qtype, const dns_name_t *qname,
|
||||
isc_result_t resp_result, isc_stdtime_t now, bool wouldlog,
|
||||
char *log_buf, unsigned int log_buf_len)
|
||||
{
|
||||
dns_rrl_t * rrl;
|
||||
dns_rrl_rtype_t rtype;
|
||||
char *log_buf, unsigned int log_buf_len) {
|
||||
dns_rrl_t *rrl;
|
||||
dns_rrl_rtype_t rtype;
|
||||
dns_rrl_entry_t *e;
|
||||
isc_netaddr_t netclient;
|
||||
int secs;
|
||||
double qps, scale;
|
||||
int exempt_match;
|
||||
isc_result_t result;
|
||||
isc_netaddr_t netclient;
|
||||
int secs;
|
||||
double qps, scale;
|
||||
int exempt_match;
|
||||
isc_result_t result;
|
||||
dns_rrl_result_t rrl_result;
|
||||
|
||||
INSIST(log_buf != NULL && log_buf_len > 0);
|
||||
@@ -1227,7 +1207,8 @@ dns_rrl(dns_view_t *view, const isc_sockaddr_t *client_addr, bool is_tcp,
|
||||
* Log occassionally in the rate-limit category.
|
||||
*/
|
||||
if ((!e->logged || e->log_secs >= DNS_RRL_MAX_LOG_SECS) &&
|
||||
isc_log_wouldlog(dns_lctx, DNS_RRL_LOG_DROP)) {
|
||||
isc_log_wouldlog(dns_lctx, DNS_RRL_LOG_DROP))
|
||||
{
|
||||
make_log_buf(rrl, e, rrl->log_only ? "would " : NULL,
|
||||
e->logged ? "continue limiting " : "limit ", true,
|
||||
qname, true, DNS_RRL_RESULT_OK, resp_result,
|
||||
@@ -1278,13 +1259,12 @@ dns_rrl(dns_view_t *view, const isc_sockaddr_t *client_addr, bool is_tcp,
|
||||
}
|
||||
|
||||
void
|
||||
dns_rrl_view_destroy(dns_view_t *view)
|
||||
{
|
||||
dns_rrl_t * rrl;
|
||||
dns_rrl_view_destroy(dns_view_t *view) {
|
||||
dns_rrl_t *rrl;
|
||||
dns_rrl_block_t *b;
|
||||
dns_rrl_hash_t * h;
|
||||
char log_buf[DNS_RRL_LOG_BUF_LEN];
|
||||
int i;
|
||||
dns_rrl_hash_t *h;
|
||||
char log_buf[DNS_RRL_LOG_BUF_LEN];
|
||||
int i;
|
||||
|
||||
rrl = view->rrl;
|
||||
if (rrl == NULL) {
|
||||
@@ -1335,9 +1315,8 @@ dns_rrl_view_destroy(dns_view_t *view)
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_rrl_init(dns_rrl_t **rrlp, dns_view_t *view, int min_entries)
|
||||
{
|
||||
dns_rrl_t * rrl;
|
||||
dns_rrl_init(dns_rrl_t **rrlp, dns_view_t *view, int min_entries) {
|
||||
dns_rrl_t *rrl;
|
||||
isc_result_t result;
|
||||
|
||||
*rrlp = NULL;
|
||||
|
Reference in New Issue
Block a user