xref: /freebsd/contrib/unbound/services/authzone.h (revision 6419bb52)
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 
36 /**
37  * \file
38  *
39  * This file contains the functions for an authority zone.  This zone
40  * is queried by the iterator, just like a stub or forward zone, but then
41  * the data is locally held.
42  */
43 
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 #include "services/rpz.h"
50 struct ub_packed_rrset_key;
51 struct regional;
52 struct config_file;
53 struct config_auth;
54 struct query_info;
55 struct dns_msg;
56 struct edns_data;
57 struct module_env;
58 struct worker;
59 struct comm_point;
60 struct comm_timer;
61 struct comm_reply;
62 struct auth_rrset;
63 struct auth_nextprobe;
64 struct auth_probe;
65 struct auth_transfer;
66 struct auth_master;
67 struct auth_chunk;
68 
69 /**
70  * Authoritative zones, shared.
71  */
72 struct auth_zones {
73 	/** lock on the authzone trees */
74 	lock_rw_type lock;
75 	/** rbtree of struct auth_zone */
76 	rbtree_type ztree;
77 	/** rbtree of struct auth_xfer */
78 	rbtree_type xtree;
79 	/** do we have downstream enabled */
80 	int have_downstream;
81 	/** number of queries upstream */
82 	size_t num_query_up;
83 	/** number of queries downstream */
84 	size_t num_query_down;
85 	/** first rpz item in linked list */
86 	struct rpz* rpz_first;
87 	/** rw lock for rpz linked list, needed when iterating or editing linked
88 	 * list. */
89 	lock_rw_type rpz_lock;
90 };
91 
92 /**
93  * Auth zone.  Authoritative data, that is fetched from instead of sending
94  * packets to the internet.
95  */
96 struct auth_zone {
97 	/** rbtree node, key is name and class */
98 	rbnode_type node;
99 
100 	/** zone name, in uncompressed wireformat */
101 	uint8_t* name;
102 	/** length of zone name */
103 	size_t namelen;
104 	/** number of labels in zone name */
105 	int namelabs;
106 	/** the class of this zone, in host byteorder.
107 	 * uses 'dclass' to not conflict with c++ keyword class. */
108 	uint16_t dclass;
109 
110 	/** lock on the data in the structure
111 	 * For the node, parent, name, namelen, namelabs, dclass, you
112 	 * need to also hold the zones_tree lock to change them (or to
113 	 * delete this zone) */
114 	lock_rw_type lock;
115 
116 	/** auth data for this zone
117 	 * rbtree of struct auth_data */
118 	rbtree_type data;
119 
120 	/** zonefile name (or NULL for no zonefile) */
121 	char* zonefile;
122 	/** fallback to the internet on failure or ttl-expiry of auth zone */
123 	int fallback_enabled;
124 	/** the zone has expired (enabled by the xfer worker), fallback
125 	 * happens if that option is enabled. */
126 	int zone_expired;
127 	/** zone is a slave zone (it has masters) */
128 	int zone_is_slave;
129 	/** for downstream: this zone answers queries towards the downstream
130 	 * clients */
131 	int for_downstream;
132 	/** for upstream: this zone answers queries that unbound intends to
133 	 * send upstream. */
134 	int for_upstream;
135 	/** RPZ zones */
136 	struct rpz* rpz;
137 	/** zone has been deleted */
138 	int zone_deleted;
139 	/** deletelist pointer, unused normally except during delete */
140 	struct auth_zone* delete_next;
141 };
142 
143 /**
144  * Auth data. One domain name, and the RRs to go with it.
145  */
146 struct auth_data {
147 	/** rbtree node, key is name only */
148 	rbnode_type node;
149 	/** domain name */
150 	uint8_t* name;
151 	/** length of name */
152 	size_t namelen;
153 	/** number of labels in name */
154 	int namelabs;
155 	/** the data rrsets, with different types, linked list.
156 	 * if the list if NULL the node would be an empty non-terminal,
157 	 * but in this data structure such nodes that represent an empty
158 	 * non-terminal are not needed; they just don't exist.
159 	 */
160 	struct auth_rrset* rrsets;
161 };
162 
163 /**
164  * A auth data RRset
165  */
166 struct auth_rrset {
167 	/** next in list */
168 	struct auth_rrset* next;
169 	/** RR type in host byteorder */
170 	uint16_t type;
171 	/** RRset data item */
172 	struct packed_rrset_data* data;
173 };
174 
175 /**
176  * Authoritative zone transfer structure.
177  * Create and destroy needs the auth_zones* biglock.
178  * The structure consists of different tasks.  Each can be unowned (-1) or
179  * owner by a worker (worker-num).  A worker can pick up a task and then do
180  * it.  This means the events (timeouts, sockets) are for that worker.
181  *
182  * (move this to tasks).
183  * They don't have locks themselves, the worker (that owns it) uses it,
184  * also as part of callbacks, hence it has separate zonename pointers for
185  * lookup in the main zonetree.  If the zone has no transfers, this
186  * structure is not created.
187  */
188 struct auth_xfer {
189 	/** rbtree node, key is name and class */
190 	rbnode_type node;
191 
192 	/** lock on this structure, and on the workernum elements of the
193 	 * tasks.  First hold the tree-lock in auth_zones, find the auth_xfer,
194 	 * lock this lock.  Then a worker can reassign itself to fill up
195 	 * one of the tasks.
196 	 * Once it has the task assigned to it, the worker can access the
197 	 * other elements of the task structure without a lock, because that
198 	 * is necessary for the eventloop and callbacks from that. */
199 	lock_basic_type lock;
200 
201 	/** zone name, in uncompressed wireformat */
202 	uint8_t* name;
203 	/** length of zone name */
204 	size_t namelen;
205 	/** number of labels in zone name */
206 	int namelabs;
207 	/** the class of this zone, in host byteorder.
208 	 * uses 'dclass' to not conflict with c++ keyword class. */
209 	uint16_t dclass;
210 
211 	/** task to wait for next-probe-timeout,
212 	 * once timeouted, see if a SOA probe is needed, or already
213 	 * in progress */
214 	struct auth_nextprobe* task_nextprobe;
215 
216 	/** task for SOA probe.  Check if the zone can be updated */
217 	struct auth_probe* task_probe;
218 
219 	/** Task for transfer.  Transferring and updating the zone.  This
220 	 * includes trying (potentially) several upstream masters.  Downloading
221 	 * and storing the zone */
222 	struct auth_transfer* task_transfer;
223 
224 	/** a notify was received, but a zone transfer or probe was already
225 	 * acted on.
226 	 * However, the zone transfer could signal a newer serial number.
227 	 * The serial number of that notify is saved below.  The transfer and
228 	 * probe tasks should check this once done to see if they need to
229 	 * restart the transfer task for the newer notify serial.
230 	 * Hold the lock to access this member (and the serial).
231 	 */
232 	int notify_received;
233 	/** true if the notify_received has a serial number */
234 	int notify_has_serial;
235 	/** serial number of the notify */
236 	uint32_t notify_serial;
237 	/** the list of masters for checking notifies.  This list is
238 	 * empty on start, and a copy of the list from the probe_task when
239 	 * it is done looking them up. */
240 	struct auth_master* allow_notify_list;
241 
242 	/* protected by the lock on the structure, information about
243 	 * the loaded authority zone. */
244 	/** is the zone currently considered expired? after expiry also older
245          * serial numbers are allowed (not just newer) */
246 	int zone_expired;
247 	/** do we have a zone (if 0, no zone data at all) */
248 	int have_zone;
249 
250 	/** current serial (from SOA), if we have no zone, 0 */
251 	uint32_t serial;
252 	/** retry time (from SOA), time to wait with next_probe
253 	 * if no master responds */
254 	time_t retry;
255 	/** refresh time (from SOA), time to wait with next_probe
256 	 * if everything is fine */
257 	time_t refresh;
258 	/** expiry time (from SOA), time until zone data is not considered
259 	 * valid any more, if no master responds within this time, either
260 	 * with the current zone or a new zone. */
261 	time_t expiry;
262 
263 	/** zone lease start time (start+expiry is expiration time).
264 	 * this is renewed every SOA probe and transfer.  On zone load
265 	 * from zonefile it is also set (with probe set soon to check) */
266 	time_t lease_time;
267 };
268 
269 /**
270  * The next probe task.
271  * This task consists of waiting for the probetimeout.  It is a task because
272  * it needs an event in the eventtable.  Once the timeout has passed, that
273  * worker can (potentially) become the auth_probe worker, or if another worker
274  * is already doing that, do nothing.  Tasks becomes unowned.
275  * The probe worker, if it detects nothing has to be done picks up this task,
276  * if unowned.
277  */
278 struct auth_nextprobe {
279 	/* Worker pointer. NULL means unowned. */
280 	struct worker* worker;
281 	/* module env for this task */
282 	struct module_env* env;
283 
284 	/** increasing backoff for failures */
285 	time_t backoff;
286 	/** Timeout for next probe (for SOA) */
287 	time_t next_probe;
288 	/** timeout callback for next_probe or expiry(if that is sooner).
289 	 * it is on the worker's event_base */
290 	struct comm_timer* timer;
291 };
292 
293 /**
294  * The probe task.
295  * Send a SOA UDP query to see if the zone needs to be updated (or similar,
296  * potential, HTTP probe query) and check serial number.
297  * If yes, start the auth_transfer task.  If no, make sure auth_nextprobe
298  * timeout wait task is running.
299  * Needs to be a task, because the UDP query needs an event entry.
300  * This task could also be started by eg. a NOTIFY being received, even though
301  * another worker is performing the nextprobe task (and that worker keeps
302  * waiting uninterrupted).
303  */
304 struct auth_probe {
305 	/* Worker pointer. NULL means unowned. */
306 	struct worker* worker;
307 	/* module env for this task */
308 	struct module_env* env;
309 
310 	/** list of upstream masters for this zone, from config */
311 	struct auth_master* masters;
312 
313 	/** for the hostname lookups, which master is current */
314 	struct auth_master* lookup_target;
315 	/** are we looking up A or AAAA, first A, then AAAA (if ip6 enabled) */
316 	int lookup_aaaa;
317 	/** we only want to do lookups for making config work (for notify),
318 	 * don't proceed with UDP SOA probe queries */
319 	int only_lookup;
320 	/** we have seen a new lease this scan, because one of the masters
321 	 * replied with the current SOA serial version */
322 	int have_new_lease;
323 
324 	/** once notified, or the timeout has been reached. a scan starts. */
325 	/** the scan specific target (notify source), or NULL if none */
326 	struct auth_master* scan_specific;
327 	/** scan tries all the upstream masters. the scan current target.
328 	 * or NULL if not working on sequential scan */
329 	struct auth_master* scan_target;
330 	/** if not NULL, the specific addr for the current master */
331 	struct auth_addr* scan_addr;
332 
333 	/** dns id of packet in flight */
334 	uint16_t id;
335 	/** the SOA probe udp event.
336 	 * on the workers event base. */
337 	struct comm_point* cp;
338 	/** is the cp for ip6 or ip4 */
339 	int cp_is_ip6;
340 	/** timeout for packets.
341 	 * on the workers event base. */
342 	struct comm_timer* timer;
343 	/** timeout in msec */
344 	int timeout;
345 };
346 
347 /**
348  * The transfer task.
349  * Once done, make sure the nextprobe waiting task is running, whether done
350  * with failure or success.  If failure, use shorter timeout for wait time.
351  */
352 struct auth_transfer {
353 	/* Worker pointer. NULL means unowned. */
354 	struct worker* worker;
355 	/* module env for this task */
356 	struct module_env* env;
357 
358 	/** xfer data that has been transferred, the data is applied
359 	 * once the transfer has completed correctly */
360 	struct auth_chunk* chunks_first;
361 	/** last element in chunks list (to append new data at the end) */
362 	struct auth_chunk* chunks_last;
363 
364 	/** list of upstream masters for this zone, from config */
365 	struct auth_master* masters;
366 
367 	/** for the hostname lookups, which master is current */
368 	struct auth_master* lookup_target;
369 	/** are we looking up A or AAAA, first A, then AAAA (if ip6 enabled) */
370 	int lookup_aaaa;
371 
372 	/** once notified, or the timeout has been reached. a scan starts. */
373 	/** the scan specific target (notify source), or NULL if none */
374 	struct auth_master* scan_specific;
375 	/** scan tries all the upstream masters. the scan current target.
376 	 * or NULL if not working on sequential scan */
377 	struct auth_master* scan_target;
378 	/** what address we are scanning for the master, or NULL if the
379 	 * master is in IP format itself */
380 	struct auth_addr* scan_addr;
381 	/** the zone transfer in progress (or NULL if in scan).  It is
382 	 * from this master */
383 	struct auth_master* master;
384 
385 	/** failed ixfr transfer, retry with axfr (to the current master),
386 	 * the IXFR was 'REFUSED', 'SERVFAIL', 'NOTIMPL' or the contents of
387 	 * the IXFR did not apply cleanly (out of sync, delete of nonexistent
388 	 * data or add of duplicate data).  Flag is cleared once the retry
389 	 * with axfr is done. */
390 	int ixfr_fail;
391 	/** we saw an ixfr-indicating timeout, count of them */
392 	int ixfr_possible_timeout_count;
393 	/** we are doing IXFR right now */
394 	int on_ixfr;
395 	/** did we detect the current AXFR/IXFR serial number yet, 0 not yet,
396 	 * 1 we saw the first, 2 we saw the second, 3 must be last SOA in xfr*/
397 	int got_xfr_serial;
398 	/** number of RRs scanned for AXFR/IXFR detection */
399 	size_t rr_scan_num;
400 	/** we are doing an IXFR but we detected an AXFR contents */
401 	int on_ixfr_is_axfr;
402 	/** the serial number for the current AXFR/IXFR incoming reply,
403 	 * for IXFR, the outermost SOA records serial */
404 	uint32_t incoming_xfr_serial;
405 
406 	/** dns id of AXFR query */
407 	uint16_t id;
408 	/** the transfer (TCP) to the master.
409 	 * on the workers event base. */
410 	struct comm_point* cp;
411 	/** timeout for the transfer.
412 	 * on the workers event base. */
413 	struct comm_timer* timer;
414 };
415 
416 /** list of addresses */
417 struct auth_addr {
418 	/** next in list */
419 	struct auth_addr* next;
420 	/** IP address */
421 	struct sockaddr_storage addr;
422 	/** addr length */
423 	socklen_t addrlen;
424 };
425 
426 /** auth zone master upstream, and the config settings for it */
427 struct auth_master {
428 	/** next master in list */
429 	struct auth_master* next;
430 	/** master IP address (and port), or hostname, string */
431 	char* host;
432 	/** for http, filename */
433 	char* file;
434 	/** use HTTP for this master */
435 	int http;
436 	/** use IXFR for this master */
437 	int ixfr;
438 	/** this is an allow notify member, the master can send notifies
439 	 * to us, but we don't send SOA probes, or zone transfer from it */
440 	int allow_notify;
441 	/** use ssl for channel */
442 	int ssl;
443 	/** the port number (for urls) */
444 	int port;
445 	/** if the host is a hostname, the list of resolved addrs, if any*/
446 	struct auth_addr* list;
447 };
448 
449 /** auth zone master zone transfer data chunk */
450 struct auth_chunk {
451 	/** next chunk in list */
452 	struct auth_chunk* next;
453 	/** the data from this chunk, this is what was received.
454 	 * for an IXFR that means results from comm_net tcp actions,
455 	 * packets. also for an AXFR. For HTTP a zonefile chunk. */
456 	uint8_t* data;
457 	/** length of allocated data */
458 	size_t len;
459 };
460 
461 /**
462  * Create auth zones structure
463  */
464 struct auth_zones* auth_zones_create(void);
465 
466 /**
467  * Apply configuration to auth zones.  Reads zonefiles.
468  * @param az: auth zones structure
469  * @param cfg: config to apply.
470  * @param setup: if true, also sets up values in the auth zones structure
471  * @param is_rpz: set to 1 if at least one RPZ zone is configured.
472  * @return false on failure.
473  */
474 int auth_zones_apply_cfg(struct auth_zones* az, struct config_file* cfg,
475 	int setup, int* is_rpz);
476 
477 /** initial pick up of worker timeouts, ties events to worker event loop
478  * @param az: auth zones structure
479  * @param env: worker env, of first worker that receives the events (if any)
480  * 	in its eventloop.
481  */
482 void auth_xfer_pickup_initial(struct auth_zones* az, struct module_env* env);
483 
484 /**
485  * Cleanup auth zones.  This removes all events from event bases.
486  * Stops the xfr tasks.  But leaves zone data.
487  * @param az: auth zones structure.
488  */
489 void auth_zones_cleanup(struct auth_zones* az);
490 
491 /**
492  * Delete auth zones structure
493  */
494 void auth_zones_delete(struct auth_zones* az);
495 
496 /**
497  * Write auth zone data to file, in zonefile format.
498  */
499 int auth_zone_write_file(struct auth_zone* z, const char* fname);
500 
501 /**
502  * Use auth zones to lookup the answer to a query.
503  * The query is from the iterator.  And the auth zones attempts to provide
504  * the answer instead of going to the internet.
505  *
506  * @param az: auth zones structure.
507  * @param qinfo: query info to lookup.
508  * @param region: region to use to allocate the reply in.
509  * @param msg: reply is stored here (if one).
510  * @param fallback: if true, fallback to making a query to the internet.
511  * @param dp_nm: name of delegation point to look for.  This zone is used
512  *	to answer the query.
513  *	If the dp_nm is not found, fallback is set to true and false returned.
514  * @param dp_nmlen: length of dp_nm.
515  * @return 0: failure (an error of some sort, like servfail).
516  *         if 0 and fallback is true, fallback to the internet.
517  *         if 0 and fallback is false, like getting servfail.
518  *         If true, an answer is available.
519  */
520 int auth_zones_lookup(struct auth_zones* az, struct query_info* qinfo,
521 	struct regional* region, struct dns_msg** msg, int* fallback,
522 	uint8_t* dp_nm, size_t dp_nmlen);
523 
524 /**
525  * Answer query from auth zone.  Create authoritative answer.
526  * @param az: auth zones structure.
527  * @param env: the module environment.
528  * @param qinfo: query info (parsed).
529  * @param edns: edns info (parsed).
530  * @param buf: buffer with query ID and flags, also for reply.
531  * @param repinfo: reply information for a communication point.
532  * @param temp: temporary storage region.
533  * @return false if not answered
534  */
535 int auth_zones_answer(struct auth_zones* az, struct module_env* env,
536 	struct query_info* qinfo, struct edns_data* edns,
537 	struct comm_reply* repinfo, struct sldns_buffer* buf, struct regional* temp);
538 
539 /**
540  * Find the auth zone that is above the given qname.
541  * Return NULL when there is no auth_zone above the give name, otherwise
542  * returns the closest auth_zone above the qname that pertains to it.
543  * @param az: auth zones structure.
544  * @param name: query to look up for.
545  * @param name_len: length of name.
546  * @param dclass: class of zone to find.
547  * @return NULL or auth_zone that pertains to the query.
548  */
549 struct auth_zone* auth_zones_find_zone(struct auth_zones* az,
550 	uint8_t* name, size_t name_len, uint16_t dclass);
551 
552 /** find an auth zone by name (exact match by name or NULL returned) */
553 struct auth_zone* auth_zone_find(struct auth_zones* az, uint8_t* nm,
554 	size_t nmlen, uint16_t dclass);
555 
556 /** find an xfer zone by name (exact match by name or NULL returned) */
557 struct auth_xfer* auth_xfer_find(struct auth_zones* az, uint8_t* nm,
558 	size_t nmlen, uint16_t dclass);
559 
560 /** create an auth zone. returns wrlocked zone. caller must have wrlock
561  * on az. returns NULL on malloc failure */
562 struct auth_zone* auth_zone_create(struct auth_zones* az, uint8_t* nm,
563 	size_t nmlen, uint16_t dclass);
564 
565 /** set auth zone zonefile string. caller must have lock on zone */
566 int auth_zone_set_zonefile(struct auth_zone* z, char* zonefile);
567 
568 /** set auth zone fallback. caller must have lock on zone.
569  * fallbackstr is "yes" or "no". false on parse failure. */
570 int auth_zone_set_fallback(struct auth_zone* z, char* fallbackstr);
571 
572 /** see if the auth zone for the name can fallback
573  * @param az: auth zones
574  * @param nm: name of delegation point.
575  * @param nmlen: length of nm.
576  * @param dclass: class of zone to look for.
577  * @return true if fallback_enabled is true. false if not.
578  * if the zone does not exist, fallback is true (more lenient)
579  * also true if zone does not do upstream requests.
580  */
581 int auth_zones_can_fallback(struct auth_zones* az, uint8_t* nm, size_t nmlen,
582 	uint16_t dclass);
583 
584 /** process notify for auth zones.
585  * first checks the access list.  Then processes the notify. This starts
586  * the probe sequence or it notes the serial number (if any)
587  * @param az: auth zones structure.
588  * @param env: module env of the worker that is handling the notify. it will
589  * 	pick up the task probe (or transfer), unless already in progress by
590  * 	another worker.
591  * @param nm: name of the zone.  Uncompressed. from query.
592  * @param nmlen: length of name.
593  * @param dclass: class of zone.
594  * @param addr: source address of notify
595  * @param addrlen: length of addr.
596  * @param has_serial: if true, the notify has a serial attached.
597  * @param serial: the serial number, if has_serial is true.
598  * @param refused: is set to true on failure to note refused access.
599  * @return fail on failures (refused is false) and when access is
600  * 	denied (refused is true).  True when processed.
601  */
602 int auth_zones_notify(struct auth_zones* az, struct module_env* env,
603 	uint8_t* nm, size_t nmlen, uint16_t dclass,
604 	struct sockaddr_storage* addr, socklen_t addrlen, int has_serial,
605 	uint32_t serial, int* refused);
606 
607 /** process notify packet and read serial number from SOA.
608  * returns 0 if no soa record in the notify */
609 int auth_zone_parse_notify_serial(struct sldns_buffer* pkt, uint32_t *serial);
610 
611 /** for the zone and if not already going, starts the probe sequence.
612  * false if zone cannot be found.  This is like a notify arrived and was
613  * accepted for that zone. */
614 int auth_zones_startprobesequence(struct auth_zones* az,
615 	struct module_env* env, uint8_t* nm, size_t nmlen, uint16_t dclass);
616 
617 /** read auth zone from zonefile. caller must lock zone. false on failure */
618 int auth_zone_read_zonefile(struct auth_zone* z, struct config_file* cfg);
619 
620 /** find serial number of zone or false if none (no SOA record) */
621 int auth_zone_get_serial(struct auth_zone* z, uint32_t* serial);
622 
623 /** compare auth_zones for sorted rbtree */
624 int auth_zone_cmp(const void* z1, const void* z2);
625 
626 /** compare auth_data for sorted rbtree */
627 int auth_data_cmp(const void* z1, const void* z2);
628 
629 /** compare auth_xfer for sorted rbtree */
630 int auth_xfer_cmp(const void* z1, const void* z2);
631 
632 /** Create auth_xfer structure.
633  * Caller must have wrlock on az. Returns locked xfer zone.
634  * @param az: zones structure.
635  * @param z: zone with name and class
636  * @return xfer zone or NULL
637  */
638 struct auth_xfer* auth_xfer_create(struct auth_zones* az, struct auth_zone* z);
639 
640 /**
641  * Set masters in auth xfer structure from config.
642  * @param list: pointer to start of list.  The malloced list is returned here.
643  * @param c: the config items to copy over.
644  * @param with_http: if true, http urls are also included, before the masters.
645  * @return false on failure.
646  */
647 int xfer_set_masters(struct auth_master** list, struct config_auth* c,
648 	int with_http);
649 
650 /** xfer nextprobe timeout callback, this is part of task_nextprobe */
651 void auth_xfer_timer(void* arg);
652 
653 /** callback for commpoint udp replies to task_probe */
654 int auth_xfer_probe_udp_callback(struct comm_point* c, void* arg, int err,
655         struct comm_reply* repinfo);
656 /** callback for task_transfer tcp connections */
657 int auth_xfer_transfer_tcp_callback(struct comm_point* c, void* arg, int err,
658         struct comm_reply* repinfo);
659 /** callback for task_transfer http connections */
660 int auth_xfer_transfer_http_callback(struct comm_point* c, void* arg, int err,
661         struct comm_reply* repinfo);
662 /** xfer probe timeout callback, part of task_probe */
663 void auth_xfer_probe_timer_callback(void* arg);
664 /** xfer transfer timeout callback, part of task_transfer */
665 void auth_xfer_transfer_timer_callback(void* arg);
666 /** mesh callback for task_probe on lookup of host names */
667 void auth_xfer_probe_lookup_callback(void* arg, int rcode,
668 	struct sldns_buffer* buf, enum sec_status sec, char* why_bogus,
669 	int was_ratelimited);
670 /** mesh callback for task_transfer on lookup of host names */
671 void auth_xfer_transfer_lookup_callback(void* arg, int rcode,
672 	struct sldns_buffer* buf, enum sec_status sec, char* why_bogus,
673 	int was_ratelimited);
674 
675 /*
676  * Compares two 32-bit serial numbers as defined in RFC1982.  Returns
677  * <0 if a < b, 0 if a == b, and >0 if a > b.  The result is undefined
678  * if a != b but neither is greater or smaller (see RFC1982 section
679  * 3.2.).
680  */
681 int compare_serial(uint32_t a, uint32_t b);
682 
683 #endif /* SERVICES_AUTHZONE_H */
684