#include <config.h>
#include <isc/mem.h>
#include <isc/net.h>
#include <isc/netaddr.h>
#include <isc/print.h>
#include <dns/result.h>
#include <dns/rcode.h>
#include <dns/rdatatype.h>
#include <dns/rdataclass.h>
#include <dns/log.h>
#include <dns/rrl.h>
#include <dns/view.h>
Go to the source code of this file.
Defines | |
#define | ADD_LOG_CSTR(eb, s) add_log_str(eb, s, sizeof(s)-1) |
Functions | |
static void | log_end (dns_rrl_t *rrl, dns_rrl_entry_t *e, isc_boolean_t early, char *log_buf, unsigned int log_buf_len) |
static int | hash_divisor (unsigned int initial) |
static int | delta_rrl_time (isc_stdtime_t ts, isc_stdtime_t now) |
static int | get_age (const dns_rrl_t *rrl, const dns_rrl_entry_t *e, isc_stdtime_t now) |
static void | 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 new) |
static dns_rrl_bin_t * | get_bin (dns_rrl_hash_t *hash, unsigned int hval) |
static void | free_old_hash (dns_rrl_t *rrl) |
static isc_result_t | 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) |
static isc_boolean_t | key_cmp (const dns_rrl_key_t *a, const dns_rrl_key_t *b) |
static isc_uint32_t | hash_key (const dns_rrl_key_t *key) |
static void | make_key (const dns_rrl_t *rrl, dns_rrl_key_t *key, const isc_sockaddr_t *client_addr, dns_rdatatype_t qtype, dns_name_t *qname, dns_rdataclass_t qclass, dns_rrl_rtype_t rtype) |
static dns_rrl_rate_t * | 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) |
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, dns_name_t *qname, dns_rrl_rtype_t rtype, isc_stdtime_t now, isc_boolean_t create, char *log_buf, unsigned int log_buf_len) |
static void | debit_log (const dns_rrl_entry_t *e, int age, const char *action) |
static 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) |
static dns_rrl_qname_buf_t * | get_qname (dns_rrl_t *rrl, const dns_rrl_entry_t *e) |
static void | 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) |
static void | make_log_buf (dns_rrl_t *rrl, dns_rrl_entry_t *e, const char *str1, const char *str2, isc_boolean_t plural, dns_name_t *qname, isc_boolean_t save_qname, dns_rrl_result_t rrl_result, isc_result_t resp_result, char *log_buf, unsigned int log_buf_len) |
static void | log_stops (dns_rrl_t *rrl, isc_stdtime_t now, int limit, char *log_buf, unsigned int log_buf_len) |
dns_rrl_result_t | dns_rrl (dns_view_t *view, const isc_sockaddr_t *client_addr, isc_boolean_t is_tcp, dns_rdataclass_t qclass, dns_rdatatype_t qtype, dns_name_t *qname, isc_result_t resp_result, isc_stdtime_t now, isc_boolean_t wouldlog, char *log_buf, unsigned int log_buf_len) |
void | 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) |
Definition in file rrl.c.
static void log_end | ( | dns_rrl_t * | rrl, | |
dns_rrl_entry_t * | e, | |||
isc_boolean_t | early, | |||
char * | log_buf, | |||
unsigned int | log_buf_len | |||
) | [static] |
Definition at line 945 of file rrl.c.
References dns_lctx, DNS_LOGCATEGORY_RRL, DNS_LOGMODULE_REQUEST, DNS_RRL_LOG_DROP, DNS_RRL_RESULT_OK, free_qname(), ISC_FALSE, isc_log_write(), ISC_R_SUCCESS, ISC_TRUE, dns_rrl::log_only, dns_rrl_entry::logged, make_log_buf(), and dns_rrl::num_logged.
Referenced by get_entry(), and log_stops().
static int hash_divisor | ( | unsigned int | initial | ) | [static] |
Definition at line 52 of file rrl.c.
References dns_lctx, DNS_LOGCATEGORY_RRL, DNS_LOGMODULE_REQUEST, DNS_RRL_LOG_DEBUG3, isc_log_wouldlog(), isc_log_write(), and tries.
Referenced by expand_rrl_hash().
static int delta_rrl_time | ( | isc_stdtime_t | ts, | |
isc_stdtime_t | now | |||
) | [inline, static] |
Definition at line 114 of file rrl.c.
References DNS_RRL_FOREVER, and DNS_RRL_MAX_TIME_TRAVEL.
Referenced by dns_rrl(), get_age(), get_entry(), and ref_entry().
static int get_age | ( | const dns_rrl_t * | rrl, | |
const dns_rrl_entry_t * | e, | |||
isc_stdtime_t | now | |||
) | [inline, static] |
Definition at line 134 of file rrl.c.
References delta_rrl_time(), DNS_RRL_FOREVER, dns_rrl_entry::ts, dns_rrl::ts_bases, dns_rrl_entry::ts_gen, and dns_rrl_entry::ts_valid.
Referenced by debit_rrl_entry(), get_entry(), and log_stops().
static void set_age | ( | dns_rrl_t * | rrl, | |
dns_rrl_entry_t * | e, | |||
isc_stdtime_t | now | |||
) | [inline, static] |
Definition at line 141 of file rrl.c.
References dns_lctx, DNS_LOGCATEGORY_RRL, DNS_LOGMODULE_REQUEST, DNS_RRL_FOREVER, DNS_RRL_LOG_DEBUG1, DNS_RRL_MAX_TIME_TRAVEL, DNS_RRL_MAX_TS, DNS_RRL_TS_BASES, ISC_FALSE, ISC_LINK_LINKED, ISC_LIST_PREV, ISC_LIST_TAIL, isc_log_write(), ISC_TRUE, dns_rrl_entry::ts, dns_rrl::ts_bases, dns_rrl_entry::ts_gen, dns_rrl::ts_gen, and dns_rrl_entry::ts_valid.
Referenced by debit_rrl_entry(), and dns_rrl().
static isc_result_t expand_entries | ( | dns_rrl_t * | rrl, | |
int | new | |||
) | [static] |
Definition at line 199 of file rrl.c.
References dns_lctx, DNS_LOGCATEGORY_RRL, DNS_LOGMODULE_REQUEST, DNS_RRL_LOG_DROP, DNS_RRL_LOG_FAIL, dns_rrl_block::entries, dns_rrl::hash, ISC_LINK_INIT, ISC_LIST_INITANDAPPEND, isc_log_wouldlog(), isc_log_write(), isc_mem_get, ISC_R_NOMEMORY, ISC_R_SUCCESS, dns_rrl_hash::length, dns_rrl::max_entries, dns_rrl::mctx, dns_rrl::num_entries, dns_rrl::probes, dns_rrl::searches, and dns_rrl_block::size.
Referenced by dns_rrl_init(), and get_entry().
static dns_rrl_bin_t* get_bin | ( | dns_rrl_hash_t * | hash, | |
unsigned int | hval | |||
) | [inline, static] |
Definition at line 255 of file rrl.c.
References dns_rrl_hash::bins, INSIST, and dns_rrl_hash::length.
Referenced by get_entry().
static void free_old_hash | ( | dns_rrl_t * | rrl | ) | [static] |
Definition at line 261 of file rrl.c.
References dns_rrl_hash::bins, ISC_LINK_INIT, ISC_LIST_HEAD, ISC_LIST_NEXT, isc_mem_put, dns_rrl_hash::length, dns_rrl::mctx, and dns_rrl::old_hash.
Referenced by expand_rrl_hash(), and get_entry().
static isc_result_t expand_rrl_hash | ( | dns_rrl_t * | rrl, | |
isc_stdtime_t | now | |||
) | [static] |
Definition at line 284 of file rrl.c.
References dns_rrl_hash::bins, dns_rrl_hash::check_time, dns_lctx, DNS_LOGCATEGORY_RRL, DNS_LOGMODULE_REQUEST, DNS_RRL_LOG_DROP, DNS_RRL_LOG_FAIL, free_old_hash(), dns_rrl_hash::gen, dns_rrl::hash, hash, hash_divisor(), dns_rrl::hash_gen, isc_log_wouldlog(), isc_log_write(), isc_mem_get, ISC_R_NOMEMORY, ISC_R_SUCCESS, dns_rrl_hash::length, dns_rrl::mctx, dns_rrl::num_entries, dns_rrl::old_hash, dns_rrl::probes, and dns_rrl::searches.
Referenced by dns_rrl_init(), and ref_entry().
static void ref_entry | ( | dns_rrl_t * | rrl, | |
dns_rrl_entry_t * | e, | |||
int | probes, | |||
isc_stdtime_t | now | |||
) | [static] |
Definition at line 337 of file rrl.c.
References dns_rrl_hash::check_time, delta_rrl_time(), expand_rrl_hash(), dns_rrl::hash, ISC_LIST_HEAD, ISC_LIST_PREPEND, ISC_LIST_PREV, ISC_LIST_UNLINK, dns_rrl::last_logged, dns_rrl::probes, and dns_rrl::searches.
Referenced by get_entry().
static isc_boolean_t key_cmp | ( | const dns_rrl_key_t * | a, | |
const dns_rrl_key_t * | b | |||
) | [inline, static] |
Definition at line 367 of file rrl.c.
References ISC_FALSE, and ISC_TRUE.
Referenced by get_entry().
static isc_uint32_t hash_key | ( | const dns_rrl_key_t * | key | ) | [inline, static] |
Definition at line 374 of file rrl.c.
References dns_rrl_key::w.
Referenced by debit_log(), and get_entry().
static void make_key | ( | const dns_rrl_t * | rrl, | |
dns_rrl_key_t * | key, | |||
const isc_sockaddr_t * | client_addr, | |||
dns_rdatatype_t | qtype, | |||
dns_name_t * | qname, | |||
dns_rdataclass_t | qclass, | |||
dns_rrl_rtype_t | rtype | |||
) | [static] |
Definition at line 395 of file rrl.c.
References AF_INET6, dns_name::attributes, dns_name_countlabels(), dns_name_getlabelsequence(), dns_name_hashbylabel(), dns_name_init(), DNS_NAMEATTR_WILDCARD, DNS_RRL_MAX_PREFIX, DNS_RRL_RTYPE_NODATA, DNS_RRL_RTYPE_QUERY, DNS_RRL_RTYPE_REFERRAL, dns_rrl_key::ip, dns_rrl::ipv4_mask, dns_rrl_key::ipv6, dns_rrl::ipv6_mask, ISC_FALSE, ISC_TRUE, dns_name::labels, dns_rrl_key::qclass, dns_rrl_key::qname_hash, dns_rrl_key::qtype, dns_rrl_key::rtype, dns_rrl_key::s, isc_sockaddr::sa, isc_sockaddr::sin, isc_sockaddr::sin6, sockaddr_in6::sin6_addr, and isc_sockaddr::type.
Referenced by get_entry().
static dns_rrl_rate_t* get_rate | ( | dns_rrl_t * | rrl, | |
dns_rrl_rtype_t | rtype | |||
) | [inline, static] |
Definition at line 452 of file rrl.c.
References dns_rrl::all_per_second, DNS_RRL_RTYPE_ALL, DNS_RRL_RTYPE_ERROR, DNS_RRL_RTYPE_NODATA, DNS_RRL_RTYPE_NXDOMAIN, DNS_RRL_RTYPE_QUERY, DNS_RRL_RTYPE_REFERRAL, dns_rrl::errors_per_second, INSIST, dns_rrl::nodata_per_second, dns_rrl::nxdomains_per_second, dns_rrl::referrals_per_second, and dns_rrl::responses_per_second.
Referenced by debit_rrl_entry(), and response_balance().
static int response_balance | ( | dns_rrl_t * | rrl, | |
const dns_rrl_entry_t * | e, | |||
int | age | |||
) | [static] |
Definition at line 473 of file rrl.c.
References DNS_RRL_RTYPE_TCP, get_rate(), dns_rrl_entry::key, dns_rrl_entry::responses, dns_rrl_key::rtype, dns_rrl_key::s, and dns_rrl_rate::scaled.
Referenced by get_entry(), and log_stops().
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, | |||
dns_name_t * | qname, | |||
dns_rrl_rtype_t | rtype, | |||
isc_stdtime_t | now, | |||
isc_boolean_t | create, | |||
char * | log_buf, | |||
unsigned int | log_buf_len | |||
) | [static] |
Definition at line 494 of file rrl.c.
References dns_rrl_hash::check_time, delta_rrl_time(), expand_entries(), free_old_hash(), get_age(), get_bin(), dns_rrl::hash, hash, dns_rrl::hash_gen, dns_rrl_entry::hash_gen, hash_key(), ISC_FALSE, ISC_LINK_LINKED, ISC_LIST_HEAD, ISC_LIST_NEXT, ISC_LIST_PREPEND, ISC_LIST_PREV, ISC_LIST_TAIL, ISC_LIST_UNLINK, ISC_MIN, ISC_TRUE, dns_rrl_entry::key, key, key_cmp(), log_end(), dns_rrl_entry::logged, make_key(), dns_rrl::num_entries, dns_rrl::old_hash, ref_entry(), response_balance(), dns_rrl_entry::ts_valid, and dns_rrl::window.
Referenced by debit_rrl_entry(), and dns_rrl().
static void debit_log | ( | const dns_rrl_entry_t * | e, | |
int | age, | |||
const char * | action | |||
) | [static] |
Definition at line 595 of file rrl.c.
References dns_lctx, DNS_LOGCATEGORY_RRL, DNS_LOGMODULE_REQUEST, DNS_RRL_FOREVER, DNS_RRL_LOG_DEBUG3, hash_key(), isc_log_write(), dns_rrl_entry::key, and dns_rrl_entry::responses.
Referenced by debit_rrl_entry().
static 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 | |||
) | [inline, static] |
Definition at line 612 of file rrl.c.
References debit_log(), dns_lctx, DNS_LOGCATEGORY_RRL, DNS_LOGMODULE_REQUEST, DNS_RRL_LOG_DEBUG1, DNS_RRL_LOG_DEBUG3, DNS_RRL_MAX_LOG_SECS, DNS_RRL_RESULT_DROP, DNS_RRL_RESULT_OK, DNS_RRL_RESULT_SLIP, DNS_RRL_RTYPE_ALL, DNS_RRL_RTYPE_TCP, get_age(), get_entry(), get_rate(), ISC_FALSE, isc_log_wouldlog(), isc_log_write(), dns_rrl_entry::key, dns_rrl_entry::log_secs, dns_rrl_entry::logged, dns_rrl_rate::r, dns_rrl_entry::responses, dns_rrl_key::rtype, dns_rrl_key::s, dns_rrl_rate::scaled, set_age(), dns_rrl::slip, dns_rrl_entry::slip_cnt, dns_rrl_rate::str, and dns_rrl::window.
Referenced by dns_rrl().
static dns_rrl_qname_buf_t* get_qname | ( | dns_rrl_t * | rrl, | |
const dns_rrl_entry_t * | e | |||
) | [inline, static] |
Definition at line 750 of file rrl.c.
References dns_rrl_qname_buf::e, dns_rrl_entry::log_qname, and dns_rrl::qnames.
Referenced by free_qname(), and make_log_buf().
static void free_qname | ( | dns_rrl_t * | rrl, | |
dns_rrl_entry_t * | e | |||
) | [inline, static] |
Definition at line 760 of file rrl.c.
References dns_rrl_qname_buf::e, get_qname(), and ISC_LIST_APPEND.
static void add_log_str | ( | isc_buffer_t * | lb, | |
const char * | str, | |||
unsigned int | str_len | |||
) | [static] |
Definition at line 771 of file rrl.c.
References isc_region::base, isc_buffer_add, isc_buffer_availableregion, and isc_region::length.
Referenced by make_log_buf().
static void make_log_buf | ( | dns_rrl_t * | rrl, | |
dns_rrl_entry_t * | e, | |||
const char * | str1, | |||
const char * | str2, | |||
isc_boolean_t | plural, | |||
dns_name_t * | qname, | |||
isc_boolean_t | save_qname, | |||
dns_rrl_result_t | rrl_result, | |||
isc_result_t | resp_result, | |||
char * | log_buf, | |||
unsigned int | log_buf_len | |||
) | [static] |
Definition at line 790 of file rrl.c.
References ADD_LOG_CSTR, add_log_str(), AF_INET6, dns_fixedname_init, dns_fixedname_name, dns_lctx, DNS_LOGCATEGORY_RRL, DNS_LOGMODULE_REQUEST, dns_name_copy(), dns_name_isabsolute(), dns_name_totext(), dns_rdataclass_totext(), dns_rdatatype_totext(), DNS_RRL_LOG_FAIL, DNS_RRL_QNAMES, DNS_RRL_RESULT_DROP, DNS_RRL_RESULT_OK, DNS_RRL_RESULT_SLIP, DNS_RRL_RTYPE_ALL, DNS_RRL_RTYPE_ERROR, DNS_RRL_RTYPE_NODATA, DNS_RRL_RTYPE_NXDOMAIN, DNS_RRL_RTYPE_QUERY, DNS_RRL_RTYPE_REFERRAL, dns_rrl_qname_buf::e, isc_netaddr::family, get_qname(), isc_netaddr::in, isc_netaddr::in6, dns_rrl_qname_buf::index, INSIST, dns_rrl_key::ip, dns_rrl::ipv4_prefixlen, dns_rrl_key::ipv6, dns_rrl::ipv6_prefixlen, isc_buffer_init, isc_buffer_usedlength, ISC_LINK_INIT, ISC_LIST_TAIL, ISC_LIST_UNLINK, isc_log_write(), ISC_MAX, isc_mem_get, isc_netaddr_totext(), ISC_R_SUCCESS, isc_result_totext(), ISC_TRUE, dns_rrl_entry::key, dns_rrl_entry::log_qname, dns_rrl::mctx, dns_rrl::num_qnames, dns_rrl_key::qclass, dns_rrl_qname_buf::qname, dns_rrl_key::qname_hash, dns_rrl::qnames, dns_rrl_key::qtype, dns_rrl_key::rtype, dns_rrl_key::s, and isc_netaddr::type.
static void log_stops | ( | dns_rrl_t * | rrl, | |
isc_stdtime_t | now, | |||
int | limit, | |||
char * | log_buf, | |||
unsigned int | log_buf_len | |||
) | [static] |
Definition at line 969 of file rrl.c.
References DNS_RRL_STOP_LOG_SECS, get_age(), INSIST, ISC_LIST_PREV, dns_rrl::last_logged, log_end(), dns_rrl::log_stops_time, dns_rrl_entry::logged, dns_rrl::num_logged, and response_balance().
Referenced by dns_rrl(), and dns_rrl_view_destroy().
dns_rrl_result_t dns_rrl | ( | dns_view_t * | view, | |
const isc_sockaddr_t * | client_addr, | |||
isc_boolean_t | is_tcp, | |||
dns_rdataclass_t | qclass, | |||
dns_rdatatype_t | qtype, | |||
dns_name_t * | qname, | |||
isc_result_t | resp_result, | |||
isc_stdtime_t | now, | |||
isc_boolean_t | wouldlog, | |||
char * | log_buf, | |||
unsigned int | log_buf_len | |||
) |
Definition at line 1008 of file rrl.c.
References dns_view::aclenv, dns_rrl::all_per_second, debit_rrl_entry(), delta_rrl_time(), dns_acl_match(), dns_lctx, DNS_LOGCATEGORY_RRL, DNS_LOGMODULE_REQUEST, DNS_R_DELEGATION, DNS_R_NXDOMAIN, DNS_R_NXRRSET, DNS_RRL_LOG_DEBUG1, DNS_RRL_LOG_DEBUG2, DNS_RRL_LOG_DEBUG3, DNS_RRL_LOG_DROP, DNS_RRL_MAX_LOG_SECS, DNS_RRL_RESULT_OK, DNS_RRL_RTYPE_ALL, DNS_RRL_RTYPE_ERROR, DNS_RRL_RTYPE_NODATA, DNS_RRL_RTYPE_NXDOMAIN, DNS_RRL_RTYPE_QUERY, DNS_RRL_RTYPE_REFERRAL, DNS_RRL_RTYPE_TCP, dns_rrl::exempt, free_qname(), get_entry(), INSIST, ISC_FALSE, isc_log_wouldlog(), isc_log_write(), isc_netaddr_fromsockaddr(), ISC_R_SUCCESS, ISC_TRUE, dns_rrl::last_logged, dns_rrl::lock, LOCK, dns_rrl::log_only, dns_rrl_entry::log_secs, log_stops(), dns_rrl::log_stops_time, dns_rrl_entry::logged, make_log_buf(), dns_rrl::num_logged, dns_rrl::qps, dns_rrl::qps_responses, dns_rrl::qps_scale, dns_rrl::qps_time, dns_rrl_rate::r, dns_rrl_entry::responses, dns_view::rrl, set_age(), UNLOCK, and dns_rrl::window.
Referenced by ns_client_error(), and query_find().
void dns_rrl_view_destroy | ( | dns_view_t * | view | ) |
Definition at line 1242 of file rrl.c.
References dns_rrl_hash::bins, DESTROYLOCK, dns_acl_detach(), DNS_RRL_LOG_BUF_LEN, DNS_RRL_QNAMES, dns_rrl::exempt, dns_rrl::hash, ISC_INT32_MAX, ISC_LIST_EMPTY, ISC_LIST_HEAD, ISC_LIST_UNLINK, isc_mem_put, isc_mem_putanddetach, dns_rrl_hash::length, dns_rrl::lock, log_stops(), dns_rrl::mctx, dns_rrl::num_logged, dns_rrl::old_hash, dns_rrl::qnames, dns_view::rrl, and dns_rrl_block::size.
Referenced by configure_rrl(), destroy(), and dns_rrl_init().
isc_result_t dns_rrl_init | ( | dns_rrl_t ** | rrlp, | |
dns_view_t * | view, | |||
int | min_entries | |||
) |
Definition at line 1292 of file rrl.c.
References dns_rrl_view_destroy(), expand_entries(), expand_rrl_hash(), isc_mem_attach(), isc_mem_get, isc_mem_putanddetach, isc_mutex_init, ISC_R_NOMEMORY, ISC_R_SUCCESS, isc_stdtime_get(), dns_rrl::lock, dns_rrl::mctx, dns_view::mctx, dns_view::rrl, and dns_rrl::ts_bases.
Referenced by configure_rrl().