Electroneum
infra.h
Go to the documentation of this file.
1 /*
2  * services/cache/infra.h - infrastructure cache, server rtt and capabilities
3  *
4  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5  *
6  * This software is open source.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * Neither the name of the NLNET LABS nor the names of its contributors may
20  * be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
45 #ifndef SERVICES_CACHE_INFRA_H
46 #define SERVICES_CACHE_INFRA_H
47 #include "util/storage/lruhash.h"
48 #include "util/storage/dnstree.h"
49 #include "util/rtt.h"
50 #include "util/netevent.h"
51 #include "util/data/msgreply.h"
52 struct slabhash;
53 struct config_file;
54 
58 struct infra_key {
62  socklen_t addrlen;
66  size_t namelen;
69 };
70 
75 struct infra_data {
77  time_t ttl;
78 
80  time_t probedelay;
82  struct rtt_info rtt;
83 
90 
100 
107 };
108 
112 struct infra_cache {
114  struct slabhash* hosts;
116  int host_ttl;
123 };
124 
126 extern int infra_dp_ratelimit;
127 
135  int lim;
137  int below;
138 };
139 
143 struct rate_key {
149  size_t namelen;
150 };
151 
153 extern int infra_ip_ratelimit;
154 
158 struct ip_rate_key {
164  socklen_t addrlen;
165 };
166 
168 #define RATE_WINDOW 2
169 
177 struct rate_data {
183 };
184 
185 #define ip_rate_data rate_data
186 
188 #define INFRA_HOST_STARTSIZE 32
189 
190 #define INFRA_BYTES_NAME 14
191 
197 struct infra_cache* infra_create(struct config_file* cfg);
198 
203 void infra_delete(struct infra_cache* infra);
204 
213 struct infra_cache* infra_adjust(struct infra_cache* infra,
214  struct config_file* cfg);
215 
226 struct lruhash_entry* infra_lookup_nottl(struct infra_cache* infra,
227  struct sockaddr_storage* addr, socklen_t addrlen, uint8_t* name,
228  size_t namelen, int wr);
229 
248 int infra_host(struct infra_cache* infra, struct sockaddr_storage* addr,
249  socklen_t addrlen, uint8_t* name, size_t namelen,
250  time_t timenow, int* edns_vs, uint8_t* edns_lame_known, int* to);
251 
267 int infra_set_lame(struct infra_cache* infra,
268  struct sockaddr_storage* addr, socklen_t addrlen,
269  uint8_t* name, size_t namelen, time_t timenow, int dnsseclame,
270  int reclame, uint16_t qtype);
271 
287 int infra_rtt_update(struct infra_cache* infra, struct sockaddr_storage* addr,
288  socklen_t addrlen, uint8_t* name, size_t namelen, int qtype,
289  int roundtrip, int orig_rtt, time_t timenow);
290 
299 void infra_update_tcp_works(struct infra_cache* infra,
300  struct sockaddr_storage* addr, socklen_t addrlen,
301  uint8_t* name, size_t namelen);
302 
315 int infra_edns_update(struct infra_cache* infra,
316  struct sockaddr_storage* addr, socklen_t addrlen,
317  uint8_t* name, size_t namelen, int edns_version, time_t timenow);
318 
337 int infra_get_lame_rtt(struct infra_cache* infra,
338  struct sockaddr_storage* addr, socklen_t addrlen,
339  uint8_t* name, size_t namelen, uint16_t qtype,
340  int* lame, int* dnsseclame, int* reclame, int* rtt, time_t timenow);
341 
358 long long infra_get_host_rto(struct infra_cache* infra,
359  struct sockaddr_storage* addr, socklen_t addrlen, uint8_t* name,
360  size_t namelen, struct rtt_info* rtt, int* delay, time_t timenow,
361  int* tA, int* tAAAA, int* tother);
362 
373 int infra_ratelimit_inc(struct infra_cache* infra, uint8_t* name,
374  size_t namelen, time_t timenow);
375 
386 void infra_ratelimit_dec(struct infra_cache* infra, uint8_t* name,
387  size_t namelen, time_t timenow);
388 
399  size_t namelen, time_t timenow);
400 
402 int infra_rate_max(void* data, time_t now);
403 
405 int infra_find_ratelimit(struct infra_cache* infra, uint8_t* name,
406  size_t namelen);
407 
415 int infra_ip_ratelimit_inc(struct infra_cache* infra,
416  struct comm_reply* repinfo, time_t timenow);
417 
423 size_t infra_get_mem(struct infra_cache* infra);
424 
427 size_t infra_sizefunc(void* k, void* d);
428 
430 int infra_compfunc(void* key1, void* key2);
431 
433 void infra_delkeyfunc(void* k, void* arg);
434 
436 void infra_deldatafunc(void* d, void* arg);
437 
439 size_t rate_sizefunc(void* k, void* d);
440 
442 int rate_compfunc(void* key1, void* key2);
443 
445 void rate_delkeyfunc(void* k, void* arg);
446 
448 void rate_deldatafunc(void* d, void* arg);
449 
450 /* calculate size for the client ip hashtable */
451 size_t ip_rate_sizefunc(void* k, void* d);
452 
453 /* compare two addresses */
454 int ip_rate_compfunc(void* key1, void* key2);
455 
456 /* delete key, and destroy the lock */
457 void ip_rate_delkeyfunc(void* d, void* arg);
458 
459 /* delete data */
460 #define ip_rate_deldatafunc rate_deldatafunc
461 
462 #endif /* SERVICES_CACHE_INFRA_H */
socklen_t addrlen
Definition: infra.h:164
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)
size_t infra_sizefunc(void *k, void *d)
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)
size_t rate_sizefunc(void *k, void *d)
struct infra_cache * infra_adjust(struct infra_cache *infra, struct config_file *cfg)
void * data
Definition: lruhash.h:222
uint8_t timeout_A
Definition: infra.h:102
int infra_rate_max(void *data, time_t now)
int infra_ratelimit_inc(struct infra_cache *infra, uint8_t *name, size_t namelen, time_t timenow)
int infra_ip_ratelimit
unsigned short uint16_t
Definition: stdint.h:125
uint8_t timeout_other
Definition: infra.h:106
unsigned char uint8_t
Definition: stdint.h:124
struct lruhash_entry entry
Definition: infra.h:160
rbtree_type domain_limits
Definition: infra.h:120
int infra_compfunc(void *key1, void *key2)
const char * name
struct slabhash * client_ip_rates
Definition: infra.h:122
size_t namelen
Definition: infra.h:149
uint8_t isdnsseclame
Definition: infra.h:93
int edns_version
Definition: infra.h:85
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)
struct slabhash * domain_rates
Definition: infra.h:118
int ip_rate_compfunc(void *key1, void *key2)
struct lruhash_entry entry
Definition: infra.h:145
int infra_find_ratelimit(struct infra_cache *infra, uint8_t *name, size_t namelen)
void rate_deldatafunc(void *d, void *arg)
struct sockaddr_storage addr
Definition: infra.h:162
time_t timestamp[RATE_WINDOW]
Definition: infra.h:182
uint8_t * name
Definition: infra.h:147
uint8_t timeout_AAAA
Definition: infra.h:104
int infra_ratelimit_exceeded(struct infra_cache *infra, uint8_t *name, size_t namelen, time_t timenow)
int rate_compfunc(void *key1, void *key2)
time_t probedelay
Definition: infra.h:80
struct slabhash * hosts
Definition: infra.h:114
uint8_t * zonename
Definition: infra.h:64
uint8_t lame_type_A
Definition: infra.h:97
int infra_dp_ratelimit
struct name_tree_node node
Definition: infra.h:133
uint8_t lame_other
Definition: infra.h:99
size_t namelen
Definition: infra.h:66
struct rtt_info rtt
Definition: infra.h:82
uint8_t rec_lame
Definition: infra.h:95
int infra_ip_ratelimit_inc(struct infra_cache *infra, struct comm_reply *repinfo, time_t timenow)
Definition: rtt.h:49
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)
void infra_delkeyfunc(void *k, void *arg)
size_t ip_rate_sizefunc(void *k, void *d)
void infra_update_tcp_works(struct infra_cache *infra, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t *name, size_t namelen)
void ip_rate_delkeyfunc(void *d, void *arg)
void rate_delkeyfunc(void *k, void *arg)
uint8_t edns_lame_known
Definition: infra.h:89
time_t ttl
Definition: infra.h:77
int host_ttl
Definition: infra.h:116
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)
void infra_delete(struct infra_cache *infra)
int qps[RATE_WINDOW]
Definition: infra.h:179
Definition: lruhash.h:203
struct lruhash_entry entry
Definition: infra.h:68
struct sockaddr_storage addr
Definition: infra.h:60
#define RATE_WINDOW
Definition: infra.h:168
void infra_ratelimit_dec(struct infra_cache *infra, uint8_t *name, size_t namelen, time_t timenow)
size_t infra_get_mem(struct infra_cache *infra)
struct infra_cache * infra_create(struct config_file *cfg)
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_deldatafunc(void *d, void *arg)
socklen_t addrlen
Definition: infra.h:62