Electroneum
authzone.h
Go to the documentation of this file.
1 /*
2  * services/authzone.h - authoritative zone that is locally hosted.
3  *
4  * Copyright (c) 2017, 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 
44 #ifndef SERVICES_AUTHZONE_H
45 #define SERVICES_AUTHZONE_H
46 #include "util/rbtree.h"
47 #include "util/locks.h"
48 #include "services/mesh.h"
49 struct ub_packed_rrset_key;
50 struct regional;
51 struct config_file;
52 struct config_auth;
53 struct query_info;
54 struct dns_msg;
55 struct edns_data;
56 struct module_env;
57 struct worker;
58 struct comm_point;
59 struct comm_timer;
60 struct comm_reply;
61 struct auth_rrset;
62 struct auth_nextprobe;
63 struct auth_probe;
64 struct auth_transfer;
65 struct auth_master;
66 struct auth_chunk;
67 
71 struct auth_zones {
81  size_t num_query_up;
84 };
85 
90 struct auth_zone {
93 
97  size_t namelen;
99  int namelabs;
103 
109 
113 
115  char* zonefile;
133 };
134 
138 struct auth_data {
144  size_t namelen;
146  int namelabs;
153 };
154 
158 struct auth_rrset {
160  struct auth_rrset* next;
165 };
166 
180 struct auth_xfer {
183 
192 
196  size_t namelen;
198  int namelabs;
202 
207 
210 
215 
233 
234  /* protected by the lock on the structure, information about
235  * the loaded authority zone. */
241 
246  time_t retry;
249  time_t refresh;
253  time_t expiry;
254 
258  time_t lease_time;
259 };
260 
271  /* Worker pointer. NULL means unowned. */
272  struct worker* worker;
273  /* module env for this task */
274  struct module_env* env;
275 
277  time_t backoff;
279  time_t next_probe;
282  struct comm_timer* timer;
283 };
284 
296 struct auth_probe {
297  /* Worker pointer. NULL means unowned. */
298  struct worker* worker;
299  /* module env for this task */
300  struct module_env* env;
301 
304 
312 
321 
326  struct comm_point* cp;
329  struct comm_timer* timer;
331  int timeout;
332 };
333 
340  /* Worker pointer. NULL means unowned. */
341  struct worker* worker;
342  /* module env for this task */
343  struct module_env* env;
344 
350 
353 
358 
371 
379  int on_ixfr;
384  size_t rr_scan_num;
390 
395  struct comm_point* cp;
396 };
397 
399 struct auth_addr {
401  struct auth_addr* next;
405  socklen_t addrlen;
406 };
407 
409 struct auth_master {
411  struct auth_master* next;
413  char* host;
415  char* file;
417  int http;
419  int ixfr;
424  int ssl;
426  int port;
428  struct auth_addr* list;
429 };
430 
432 struct auth_chunk {
434  struct auth_chunk* next;
440  size_t len;
441 };
442 
446 struct auth_zones* auth_zones_create(void);
447 
455 int auth_zones_apply_cfg(struct auth_zones* az, struct config_file* cfg,
456  int setup);
457 
463 void auth_xfer_pickup_initial(struct auth_zones* az, struct module_env* env);
464 
470 void auth_zones_cleanup(struct auth_zones* az);
471 
475 void auth_zones_delete(struct auth_zones* az);
476 
480 int auth_zone_write_file(struct auth_zone* z, const char* fname);
481 
501 int auth_zones_lookup(struct auth_zones* az, struct query_info* qinfo,
502  struct regional* region, struct dns_msg** msg, int* fallback,
503  uint8_t* dp_nm, size_t dp_nmlen);
504 
515 int auth_zones_answer(struct auth_zones* az, struct module_env* env,
516  struct query_info* qinfo, struct edns_data* edns, struct sldns_buffer* buf,
517  struct regional* temp);
518 
529 struct auth_zone* auth_zones_find_zone(struct auth_zones* az,
530  uint8_t* name, size_t name_len, uint16_t dclass);
531 
533 struct auth_zone* auth_zone_find(struct auth_zones* az, uint8_t* nm,
534  size_t nmlen, uint16_t dclass);
535 
537 struct auth_xfer* auth_xfer_find(struct auth_zones* az, uint8_t* nm,
538  size_t nmlen, uint16_t dclass);
539 
542 struct auth_zone* auth_zone_create(struct auth_zones* az, uint8_t* nm,
543  size_t nmlen, uint16_t dclass);
544 
546 int auth_zone_set_zonefile(struct auth_zone* z, char* zonefile);
547 
550 int auth_zone_set_fallback(struct auth_zone* z, char* fallbackstr);
551 
561 int auth_zones_can_fallback(struct auth_zones* az, uint8_t* nm, size_t nmlen,
562  uint16_t dclass);
563 
582 int auth_zones_notify(struct auth_zones* az, struct module_env* env,
583  uint8_t* nm, size_t nmlen, uint16_t dclass,
584  struct sockaddr_storage* addr, socklen_t addrlen, int has_serial,
585  uint32_t serial, int* refused);
586 
589 int auth_zone_parse_notify_serial(struct sldns_buffer* pkt, uint32_t *serial);
590 
592 int auth_zone_read_zonefile(struct auth_zone* z);
593 
595 int auth_zone_get_serial(struct auth_zone* z, uint32_t* serial);
596 
598 int auth_zone_cmp(const void* z1, const void* z2);
599 
601 int auth_data_cmp(const void* z1, const void* z2);
602 
604 int auth_xfer_cmp(const void* z1, const void* z2);
605 
612 struct auth_xfer* auth_xfer_create(struct auth_zones* az, struct auth_zone* z);
613 
621 int xfer_set_masters(struct auth_master** list, struct config_auth* c,
622  int with_http);
623 
625 void auth_xfer_timer(void* arg);
626 
628 int auth_xfer_probe_udp_callback(struct comm_point* c, void* arg, int err,
629  struct comm_reply* repinfo);
631 int auth_xfer_transfer_tcp_callback(struct comm_point* c, void* arg, int err,
632  struct comm_reply* repinfo);
634 int auth_xfer_transfer_http_callback(struct comm_point* c, void* arg, int err,
635  struct comm_reply* repinfo);
637 void auth_xfer_probe_timer_callback(void* arg);
639 void auth_xfer_probe_lookup_callback(void* arg, int rcode,
640  struct sldns_buffer* buf, enum sec_status sec, char* why_bogus);
642 void auth_xfer_transfer_lookup_callback(void* arg, int rcode,
643  struct sldns_buffer* buf, enum sec_status sec, char* why_bogus);
644 
645 /*
646  * Compares two 32-bit serial numbers as defined in RFC1982. Returns
647  * <0 if a < b, 0 if a == b, and >0 if a > b. The result is undefined
648  * if a != b but neither is greater or smaller (see RFC1982 section
649  * 3.2.).
650  */
652 
653 #endif /* SERVICES_AUTHZONE_H */
int compare_serial(uint32_t a, uint32_t b)
rbtree_type ztree
Definition: authzone.h:75
int allow_notify
Definition: authzone.h:422
int have_downstream
Definition: authzone.h:79
struct auth_xfer * auth_xfer_create(struct auth_zones *az, struct auth_zone *z)
Definition: dns.h:61
struct auth_master * masters
Definition: authzone.h:303
struct comm_timer * timer
Definition: authzone.h:329
int auth_zone_read_zonefile(struct auth_zone *z)
int xfer_set_masters(struct auth_master **list, struct config_auth *c, int with_http)
lock_rw_type lock
Definition: authzone.h:73
int auth_zones_can_fallback(struct auth_zones *az, uint8_t *nm, size_t nmlen, uint16_t dclass)
size_t num_query_up
Definition: authzone.h:81
struct auth_chunk * next
Definition: authzone.h:434
rbnode_type node
Definition: authzone.h:140
struct worker * worker
Definition: authzone.h:341
int auth_zone_cmp(const void *z1, const void *z2)
struct auth_addr * next
Definition: authzone.h:401
struct auth_rrset * next
Definition: authzone.h:160
uint16_t type
Definition: authzone.h:162
int auth_xfer_transfer_http_callback(struct comm_point *c, void *arg, int err, struct comm_reply *repinfo)
uint32_t incoming_xfr_serial
Definition: authzone.h:389
void auth_xfer_probe_timer_callback(void *arg)
int auth_xfer_cmp(const void *z1, const void *z2)
time_t lease_time
Definition: authzone.h:258
void auth_xfer_timer(void *arg)
struct auth_chunk * chunks_first
Definition: authzone.h:347
rbnode_type node
Definition: authzone.h:182
unsigned short uint16_t
Definition: stdint.h:125
time_t retry
Definition: authzone.h:246
int auth_zone_parse_notify_serial(struct sldns_buffer *pkt, uint32_t *serial)
int auth_zones_notify(struct auth_zones *az, struct module_env *env, uint8_t *nm, size_t nmlen, uint16_t dclass, struct sockaddr_storage *addr, socklen_t addrlen, int has_serial, uint32_t serial, int *refused)
int auth_xfer_probe_udp_callback(struct comm_point *c, void *arg, int err, struct comm_reply *repinfo)
struct comm_timer * timer
Definition: authzone.h:282
size_t namelen
Definition: authzone.h:144
uint16_t id
Definition: authzone.h:323
unsigned char uint8_t
Definition: stdint.h:124
rbtree_type data
Definition: authzone.h:112
int got_xfr_serial
Definition: authzone.h:382
uint16_t dclass
Definition: authzone.h:201
const char * name
struct auth_master * allow_notify_list
Definition: authzone.h:232
struct auth_zone * auth_zone_find(struct auth_zones *az, uint8_t *nm, size_t nmlen, uint16_t dclass)
lock_rw_type lock
Definition: authzone.h:108
struct auth_master * lookup_target
Definition: authzone.h:306
int zone_expired
Definition: authzone.h:120
struct auth_nextprobe * task_nextprobe
Definition: authzone.h:206
int lookup_aaaa
Definition: authzone.h:308
int lookup_aaaa
Definition: authzone.h:357
struct auth_addr * scan_addr
Definition: authzone.h:320
struct worker * worker
Definition: authzone.h:272
time_t next_probe
Definition: authzone.h:279
struct comm_point * cp
Definition: authzone.h:326
int auth_zone_write_file(struct auth_zone *z, const char *fname)
uint16_t id
Definition: authzone.h:392
size_t num_query_down
Definition: authzone.h:83
uint8_t * name
Definition: authzone.h:142
struct auth_master * scan_target
Definition: authzone.h:364
int timeout
Definition: authzone.h:331
void auth_xfer_transfer_lookup_callback(void *arg, int rcode, struct sldns_buffer *buf, enum sec_status sec, char *why_bogus)
rbnode_type node
Definition: authzone.h:92
int zone_is_slave
Definition: authzone.h:122
struct auth_master * master
Definition: authzone.h:370
struct worker * worker
Definition: authzone.h:298
char * host
Definition: authzone.h:413
unsigned int uint32_t
Definition: stdint.h:126
int for_downstream
Definition: authzone.h:125
time_t backoff
Definition: authzone.h:277
void auth_zones_cleanup(struct auth_zones *az)
int lock_basic_type
Definition: locks.h:269
size_t namelen
Definition: authzone.h:97
struct auth_xfer * auth_xfer_find(struct auth_zones *az, uint8_t *nm, size_t nmlen, uint16_t dclass)
sec_status
Definition: packed_rrset.h:176
void auth_xfer_probe_lookup_callback(void *arg, int rcode, struct sldns_buffer *buf, enum sec_status sec, char *why_bogus)
rbtree_type xtree
Definition: authzone.h:77
struct module_env * env
Definition: authzone.h:343
socklen_t addrlen
Definition: authzone.h:405
lock_basic_type lock
Definition: authzone.h:191
struct auth_chunk * chunks_last
Definition: authzone.h:349
struct auth_zone * auth_zones_find_zone(struct auth_zones *az, uint8_t *name, size_t name_len, uint16_t dclass)
int fallback_enabled
Definition: authzone.h:117
void auth_xfer_pickup_initial(struct auth_zones *az, struct module_env *env)
struct sockaddr_storage addr
Definition: authzone.h:403
const char * buf
Definition: slow_memmem.cpp:74
struct auth_master * masters
Definition: authzone.h:352
int namelabs
Definition: authzone.h:99
time_t expiry
Definition: authzone.h:253
int auth_zone_set_fallback(struct auth_zone *z, char *fallbackstr)
int auth_zones_answer(struct auth_zones *az, struct module_env *env, struct query_info *qinfo, struct edns_data *edns, struct sldns_buffer *buf, struct regional *temp)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
int on_ixfr_is_axfr
Definition: authzone.h:386
int notify_has_serial
Definition: authzone.h:226
size_t len
Definition: authzone.h:440
int auth_zones_lookup(struct auth_zones *az, struct query_info *qinfo, struct regional *region, struct dns_msg **msg, int *fallback, uint8_t *dp_nm, size_t dp_nmlen)
uint32_t notify_serial
Definition: authzone.h:228
struct auth_transfer * task_transfer
Definition: authzone.h:214
int namelabs
Definition: authzone.h:146
size_t rr_scan_num
Definition: authzone.h:384
struct packed_rrset_data * data
Definition: authzone.h:164
struct auth_master * scan_specific
Definition: authzone.h:315
int have_zone
Definition: authzone.h:240
struct auth_probe * task_probe
Definition: authzone.h:209
int auth_data_cmp(const void *z1, const void *z2)
size_t namelen
Definition: authzone.h:196
int auth_zone_set_zonefile(struct auth_zone *z, char *zonefile)
int zone_expired
Definition: authzone.h:238
struct auth_zone * delete_next
Definition: authzone.h:132
char * file
Definition: authzone.h:415
int notify_received
Definition: authzone.h:224
int only_lookup
Definition: authzone.h:311
struct auth_master * scan_specific
Definition: authzone.h:361
struct auth_zone * auth_zone_create(struct auth_zones *az, uint8_t *nm, size_t nmlen, uint16_t dclass)
struct auth_addr * list
Definition: authzone.h:428
struct auth_addr * scan_addr
Definition: authzone.h:367
time_t refresh
Definition: authzone.h:249
uint8_t * data
Definition: authzone.h:438
char * zonefile
Definition: authzone.h:115
uint8_t * name
Definition: authzone.h:194
uint32_t serial
Definition: authzone.h:243
struct module_env * env
Definition: authzone.h:300
int auth_xfer_transfer_tcp_callback(struct comm_point *c, void *arg, int err, struct comm_reply *repinfo)
Definition: worker.h:82
struct auth_master * scan_target
Definition: authzone.h:318
struct auth_rrset * rrsets
Definition: authzone.h:152
uint16_t dclass
Definition: authzone.h:102
int zone_deleted
Definition: authzone.h:130
uint8_t * name
Definition: authzone.h:95
struct comm_point * cp
Definition: authzone.h:395
struct auth_master * next
Definition: authzone.h:411
void auth_zones_delete(struct auth_zones *az)
struct module_env * env
Definition: authzone.h:274
int for_upstream
Definition: authzone.h:128
struct auth_master * lookup_target
Definition: authzone.h:355
int auth_zones_apply_cfg(struct auth_zones *az, struct config_file *cfg, int setup)
struct auth_zones * auth_zones_create(void)
int lock_rw_type
Definition: locks.h:261
int auth_zone_get_serial(struct auth_zone *z, uint32_t *serial)
int namelabs
Definition: authzone.h:198