|
Electroneum
|
#include "util/storage/lruhash.h"#include "util/storage/dnstree.h"#include "util/rtt.h"#include "util/netevent.h"#include "util/data/msgreply.h"
Go to the source code of this file.
Classes | |
| struct | infra_key |
| struct | infra_data |
| struct | infra_cache |
| struct | domain_limit_data |
| struct | rate_key |
| struct | ip_rate_key |
| struct | rate_data |
Macros | |
| #define | RATE_WINDOW 2 |
| #define | ip_rate_data rate_data |
| #define | INFRA_HOST_STARTSIZE 32 |
| #define | INFRA_BYTES_NAME 14 |
| #define | ip_rate_deldatafunc rate_deldatafunc |
Functions | |
| struct infra_cache * | infra_create (struct config_file *cfg) |
| void | infra_delete (struct infra_cache *infra) |
| struct infra_cache * | infra_adjust (struct infra_cache *infra, struct config_file *cfg) |
| struct lruhash_entry * | infra_lookup_nottl (struct infra_cache *infra, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t *name, size_t namelen, int wr) |
| int | infra_host (struct infra_cache *infra, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t *name, size_t namelen, time_t timenow, int *edns_vs, uint8_t *edns_lame_known, int *to) |
| int | infra_set_lame (struct infra_cache *infra, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t *name, size_t namelen, time_t timenow, int dnsseclame, int reclame, uint16_t qtype) |
| int | infra_rtt_update (struct infra_cache *infra, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t *name, size_t namelen, int qtype, int roundtrip, int orig_rtt, time_t timenow) |
| void | infra_update_tcp_works (struct infra_cache *infra, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t *name, size_t namelen) |
| int | infra_edns_update (struct infra_cache *infra, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t *name, size_t namelen, int edns_version, time_t timenow) |
| int | infra_get_lame_rtt (struct infra_cache *infra, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t *name, size_t namelen, uint16_t qtype, int *lame, int *dnsseclame, int *reclame, int *rtt, time_t timenow) |
| long long | infra_get_host_rto (struct infra_cache *infra, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t *name, size_t namelen, struct rtt_info *rtt, int *delay, time_t timenow, int *tA, int *tAAAA, int *tother) |
| int | infra_ratelimit_inc (struct infra_cache *infra, uint8_t *name, size_t namelen, time_t timenow) |
| void | infra_ratelimit_dec (struct infra_cache *infra, uint8_t *name, size_t namelen, time_t timenow) |
| int | infra_ratelimit_exceeded (struct infra_cache *infra, uint8_t *name, size_t namelen, time_t timenow) |
| int | infra_rate_max (void *data, time_t now) |
| int | infra_find_ratelimit (struct infra_cache *infra, uint8_t *name, size_t namelen) |
| int | infra_ip_ratelimit_inc (struct infra_cache *infra, struct comm_reply *repinfo, time_t timenow) |
| size_t | infra_get_mem (struct infra_cache *infra) |
| size_t | infra_sizefunc (void *k, void *d) |
| int | infra_compfunc (void *key1, void *key2) |
| void | infra_delkeyfunc (void *k, void *arg) |
| void | infra_deldatafunc (void *d, void *arg) |
| size_t | rate_sizefunc (void *k, void *d) |
| int | rate_compfunc (void *key1, void *key2) |
| void | rate_delkeyfunc (void *k, void *arg) |
| void | rate_deldatafunc (void *d, void *arg) |
| size_t | ip_rate_sizefunc (void *k, void *d) |
| int | ip_rate_compfunc (void *key1, void *key2) |
| void | ip_rate_delkeyfunc (void *d, void *arg) |
Variables | |
| int | infra_dp_ratelimit |
| int | infra_ip_ratelimit |
This file contains the infrastructure cache, as well as rate limiting. Note that there are two sorts of rate-limiting here:
Definition in file infra.h.
| #define INFRA_BYTES_NAME 14 |
| #define INFRA_HOST_STARTSIZE 32 |
| #define ip_rate_deldatafunc rate_deldatafunc |
| struct infra_cache* infra_adjust | ( | struct infra_cache * | infra, |
| struct config_file * | cfg | ||
| ) |
Adjust infra cache to use updated configuration settings. This may clean the cache. Operates a bit like realloc. There may be no threading or use by other threads.
| infra | existing cache. If NULL a new infra cache is returned. |
| cfg | config options. |
| int infra_compfunc | ( | void * | key1, |
| void * | key2 | ||
| ) |
compare two addresses, returns -1, 0, or +1
| struct infra_cache* infra_create | ( | struct config_file * | cfg | ) |
Create infra cache.
| cfg | config parameters or NULL for defaults. |
| void infra_deldatafunc | ( | void * | d, |
| void * | arg | ||
| ) |
delete data and destroy the lameness hashtable
| void infra_delete | ( | struct infra_cache * | infra | ) |
Delete infra cache.
| infra | infrastructure cache to delete. |
| void infra_delkeyfunc | ( | void * | k, |
| void * | arg | ||
| ) |
delete key, and destroy the lock
| int infra_edns_update | ( | struct infra_cache * | infra, |
| struct sockaddr_storage * | addr, | ||
| socklen_t | addrlen, | ||
| uint8_t * | name, | ||
| size_t | namelen, | ||
| int | edns_version, | ||
| time_t | timenow | ||
| ) |
Update edns information for the host.
| infra | infrastructure cache. |
| addr | host address. |
| addrlen | length of addr. |
| name | name of zone |
| namelen | length of name |
| edns_version | the version that it publishes. If it is known to support EDNS then no-EDNS is not stored over it. |
| timenow | what time it is now. |
| int infra_find_ratelimit | ( | struct infra_cache * | infra, |
| uint8_t * | name, | ||
| size_t | namelen | ||
| ) |
find the ratelimit in qps for a domain. 0 if no limit for domain.
| long long infra_get_host_rto | ( | struct infra_cache * | infra, |
| struct sockaddr_storage * | addr, | ||
| socklen_t | addrlen, | ||
| uint8_t * | name, | ||
| size_t | namelen, | ||
| struct rtt_info * | rtt, | ||
| int * | delay, | ||
| time_t | timenow, | ||
| int * | tA, | ||
| int * | tAAAA, | ||
| int * | tother | ||
| ) |
Get additional (debug) info on timing.
| infra | infra cache. |
| addr | host address. |
| addrlen | length of addr. |
| name | zone name |
| namelen | zone name length |
| rtt | the rtt_info is copied into here (caller alloced return struct). |
| delay | probe delay (if any). |
| timenow | what time it is now. |
| tA | timeout counter on type A. |
| tAAAA | timeout counter on type AAAA. |
| tother | timeout counter on type other. |
| int infra_get_lame_rtt | ( | struct infra_cache * | infra, |
| struct sockaddr_storage * | addr, | ||
| socklen_t | addrlen, | ||
| uint8_t * | name, | ||
| size_t | namelen, | ||
| uint16_t | qtype, | ||
| int * | lame, | ||
| int * | dnsseclame, | ||
| int * | reclame, | ||
| int * | rtt, | ||
| time_t | timenow | ||
| ) |
Get Lameness information and average RTT if host is in the cache. This information is to be used for server selection.
| infra | infrastructure cache. |
| addr | host address. |
| addrlen | length of addr. |
| name | zone name. |
| namelen | zone name length. |
| qtype | the query to be made. |
| lame | if function returns true, this returns lameness of the zone. |
| dnsseclame | if function returns true, this returns if the zone is dnssec-lame. |
| reclame | if function returns true, this is if it is recursion lame. |
| rtt | if function returns true, this returns avg rtt of the server. The rtt value is unclamped and reflects recent timeouts. |
| timenow | what time it is now. |
| size_t infra_get_mem | ( | struct infra_cache * | infra | ) |
Get memory used by the infra cache.
| infra | infrastructure cache. |
| int infra_host | ( | struct infra_cache * | infra, |
| struct sockaddr_storage * | addr, | ||
| socklen_t | addrlen, | ||
| uint8_t * | name, | ||
| size_t | namelen, | ||
| time_t | timenow, | ||
| int * | edns_vs, | ||
| uint8_t * | edns_lame_known, | ||
| int * | to | ||
| ) |
Find host information to send a packet. Creates new entry if not found. Lameness is empty. EDNS is 0 (try with first), and rtt is returned for the first message to it. Use this to send a packet only, because it also locks out others when probing is restricted.
| infra | infrastructure cache. |
| addr | host address. |
| addrlen | length of addr. |
| name | domain name of zone. |
| namelen | length of domain name. |
| timenow | what time it is now. |
| edns_vs | edns version it supports, is returned. |
| edns_lame_known | if EDNS lame (EDNS is dropped in transit) has already been probed, is returned. |
| to | timeout to use, is returned. |
| int infra_ip_ratelimit_inc | ( | struct infra_cache * | infra, |
| struct comm_reply * | repinfo, | ||
| time_t | timenow | ||
| ) |
Update query ratelimit hash and decide whether or not a query should be dropped.
| infra | infra cache |
| repinfo | information about client |
| timenow | what time it is now. |
| struct lruhash_entry* infra_lookup_nottl | ( | struct infra_cache * | infra, |
| struct sockaddr_storage * | addr, | ||
| socklen_t | addrlen, | ||
| uint8_t * | name, | ||
| size_t | namelen, | ||
| int | wr | ||
| ) |
Plain find infra data function (used by the the other functions)
| infra | infrastructure cache. |
| addr | host address. |
| addrlen | length of addr. |
| name | domain name of zone. |
| namelen | length of domain name. |
| wr | if true, writelock, else readlock. |
| int infra_rate_max | ( | void * | data, |
| time_t | now | ||
| ) |
find the maximum rate stored, not too old. 0 if no information.
| void infra_ratelimit_dec | ( | struct infra_cache * | infra, |
| uint8_t * | name, | ||
| size_t | namelen, | ||
| time_t | timenow | ||
| ) |
Decrement the query rate counter for a delegation point. Because the reply received for the delegation point was pleasant, we do not charge this delegation point with it (i.e. it was a referral). Should call it with same second as when inc() was called.
| infra | infra cache. |
| name | zone name |
| namelen | zone name length |
| timenow | what time it is now. |
| int infra_ratelimit_exceeded | ( | struct infra_cache * | infra, |
| uint8_t * | name, | ||
| size_t | namelen, | ||
| time_t | timenow | ||
| ) |
See if the query rate counter for a delegation point is exceeded. So, no queries are going to be allowed.
| infra | infra cache. |
| name | zone name |
| namelen | zone name length |
| timenow | what time it is now. |
| int infra_ratelimit_inc | ( | struct infra_cache * | infra, |
| uint8_t * | name, | ||
| size_t | namelen, | ||
| time_t | timenow | ||
| ) |
Increment the query rate counter for a delegation point.
| infra | infra cache. |
| name | zone name |
| namelen | zone name length |
| timenow | what time it is now. |
| int infra_rtt_update | ( | struct infra_cache * | infra, |
| struct sockaddr_storage * | addr, | ||
| socklen_t | addrlen, | ||
| uint8_t * | name, | ||
| size_t | namelen, | ||
| int | qtype, | ||
| int | roundtrip, | ||
| int | orig_rtt, | ||
| time_t | timenow | ||
| ) |
Update rtt information for the host.
| infra | infrastructure cache. |
| addr | host address. |
| addrlen | length of addr. |
| name | zone name |
| namelen | zone name length |
| qtype | query type. |
| roundtrip | estimate of roundtrip time in milliseconds or -1 for timeout. |
| orig_rtt | original rtt for the query that timed out (roundtrip==-1). ignored if roundtrip != -1. |
| timenow | what time it is now. |
| int infra_set_lame | ( | struct infra_cache * | infra, |
| struct sockaddr_storage * | addr, | ||
| socklen_t | addrlen, | ||
| uint8_t * | name, | ||
| size_t | namelen, | ||
| time_t | timenow, | ||
| int | dnsseclame, | ||
| int | reclame, | ||
| uint16_t | qtype | ||
| ) |
Set a host to be lame for the given zone.
| infra | infrastructure cache. |
| addr | host address. |
| addrlen | length of addr. |
| name | domain name of zone apex. |
| namelen | length of domain name. |
| timenow | what time it is now. |
| dnsseclame | if true the host is set dnssec lame. if false, the host is marked lame (not serving the zone). |
| reclame | if true host is a recursor not AA server. if false, dnsseclame or marked lame. |
| qtype | the query type for which it is lame. |
| size_t infra_sizefunc | ( | void * | k, |
| void * | d | ||
| ) |
calculate size for the hashtable, does not count size of lameness, so the hashtable is a fixed number of items
| void infra_update_tcp_works | ( | struct infra_cache * | infra, |
| struct sockaddr_storage * | addr, | ||
| socklen_t | addrlen, | ||
| uint8_t * | name, | ||
| size_t | namelen | ||
| ) |
Update information for the host, store that a TCP transaction works.
| infra | infrastructure cache. |
| addr | host address. |
| addrlen | length of addr. |
| name | name of zone |
| namelen | length of name |
| int ip_rate_compfunc | ( | void * | key1, |
| void * | key2 | ||
| ) |
| void ip_rate_delkeyfunc | ( | void * | d, |
| void * | arg | ||
| ) |
| size_t ip_rate_sizefunc | ( | void * | k, |
| void * | d | ||
| ) |
| int rate_compfunc | ( | void * | key1, |
| void * | key2 | ||
| ) |
compare two names, returns -1, 0, or +1
| void rate_deldatafunc | ( | void * | d, |
| void * | arg | ||
| ) |
delete data
| void rate_delkeyfunc | ( | void * | k, |
| void * | arg | ||
| ) |
delete key, and destroy the lock
| size_t rate_sizefunc | ( | void * | k, |
| void * | d | ||
| ) |
calculate size for the hashtable
| int infra_dp_ratelimit |
ratelimit, unless overridden by domain_limits, 0 is off
| int infra_ip_ratelimit |
ip ratelimit, 0 is off