xref: /netbsd/external/bsd/nsd/dist/xfrd.h (revision 66a1527d)
1688d4060Schristos /*
2688d4060Schristos  * xfrd.h - XFR (transfer) Daemon header file. Coordinates SOA updates.
3688d4060Schristos  *
4688d4060Schristos  * Copyright (c) 2001-2006, NLnet Labs. All rights reserved.
5688d4060Schristos  *
6688d4060Schristos  * See LICENSE for the license.
7688d4060Schristos  *
8688d4060Schristos  */
9688d4060Schristos 
10688d4060Schristos #ifndef XFRD_H
11688d4060Schristos #define XFRD_H
12688d4060Schristos 
13688d4060Schristos #ifndef USE_MINI_EVENT
14688d4060Schristos #  ifdef HAVE_EVENT_H
15688d4060Schristos #    include <event.h>
16688d4060Schristos #  else
17688d4060Schristos #    include <event2/event.h>
18688d4060Schristos #    include "event2/event_struct.h"
19688d4060Schristos #    include "event2/event_compat.h"
20688d4060Schristos #  endif
21688d4060Schristos #else
22688d4060Schristos #  include "mini_event.h"
23688d4060Schristos #endif
24688d4060Schristos #include "rbtree.h"
25688d4060Schristos #include "namedb.h"
26688d4060Schristos #include "options.h"
27688d4060Schristos #include "dns.h"
28688d4060Schristos #include "tsig.h"
29688d4060Schristos 
30688d4060Schristos struct nsd;
31688d4060Schristos struct region;
32688d4060Schristos struct buffer;
33688d4060Schristos struct xfrd_tcp;
34688d4060Schristos struct xfrd_tcp_set;
35df8774c2Schristos struct notify_zone;
36688d4060Schristos struct udb_ptr;
37df8774c2Schristos typedef struct xfrd_state xfrd_state_type;
38*66a1527dSchristos typedef struct xfrd_xfr xfrd_xfr_type;
39df8774c2Schristos typedef struct xfrd_zone xfrd_zone_type;
40df8774c2Schristos typedef struct xfrd_soa xfrd_soa_type;
41688d4060Schristos /*
42688d4060Schristos  * The global state for the xfrd daemon process.
43688d4060Schristos  * The time_t times are epochs in secs since 1970, absolute times.
44688d4060Schristos  */
45688d4060Schristos struct xfrd_state {
46688d4060Schristos 	/* time when daemon was last started */
47688d4060Schristos 	time_t xfrd_start_time;
48688d4060Schristos 	struct region* region;
49688d4060Schristos 	struct event_base* event_base;
50688d4060Schristos 	struct nsd* nsd;
51688d4060Schristos 
52688d4060Schristos 	struct xfrd_tcp_set* tcp_set;
53688d4060Schristos 	/* packet buffer for udp packets */
54688d4060Schristos 	struct buffer* packet;
55688d4060Schristos 	/* udp waiting list, double linked list */
56688d4060Schristos 	struct xfrd_zone *udp_waiting_first, *udp_waiting_last;
57688d4060Schristos 	/* number of udp sockets (for sending queries) in use */
58688d4060Schristos 	size_t udp_use_num;
59688d4060Schristos 	/* activated waiting list, double linked list */
60688d4060Schristos 	struct xfrd_zone *activated_first;
61688d4060Schristos 
62688d4060Schristos 	/* current time is cached */
63688d4060Schristos 	uint8_t got_time;
64688d4060Schristos 	time_t current_time;
65688d4060Schristos 
66688d4060Schristos 	/* counter for xfr file numbers */
67688d4060Schristos 	uint64_t xfrfilenumber;
68688d4060Schristos 
69688d4060Schristos 	/* the zonestat array size that we last saw and is safe to use */
70688d4060Schristos 	unsigned zonestat_safe;
71688d4060Schristos 	/* size currently of the clear array */
72688d4060Schristos 	size_t zonestat_clear_num;
73688d4060Schristos 	/* array of malloced entries with cumulative cleared stat values */
74688d4060Schristos 	struct nsdst** zonestat_clear;
75688d4060Schristos 
76688d4060Schristos 	/* timer for NSD reload */
77688d4060Schristos 	struct timeval reload_timeout;
78688d4060Schristos 	struct event reload_handler;
79688d4060Schristos 	int reload_added;
80688d4060Schristos 	/* last reload must have caught all zone updates before this time */
81688d4060Schristos 	time_t reload_cmd_last_sent;
82*66a1527dSchristos 	time_t reload_cmd_first_sent;
83*66a1527dSchristos 	uint8_t reload_failed;
84688d4060Schristos 	uint8_t can_send_reload;
85688d4060Schristos 	pid_t reload_pid;
86688d4060Schristos 	/* timeout for lost sigchild and reaping children */
87688d4060Schristos 	struct event child_timer;
88688d4060Schristos 	int child_timer_added;
89688d4060Schristos 
90688d4060Schristos 	/* timeout event for zonefiles_write events */
91688d4060Schristos 	struct event write_timer;
92688d4060Schristos 	/* set to 1 if zones have received xfrs since the last write_timer */
93688d4060Schristos 	int write_zonefile_needed;
94688d4060Schristos 
95688d4060Schristos 	/* communication channel with server_main */
96688d4060Schristos 	struct event ipc_handler;
97688d4060Schristos 	int ipc_handler_flags;
98688d4060Schristos 	struct xfrd_tcp *ipc_conn;
99688d4060Schristos 	struct buffer* ipc_pass;
100688d4060Schristos 	/* sending ipc to server_main */
101688d4060Schristos 	uint8_t need_to_send_shutdown;
102688d4060Schristos 	uint8_t need_to_send_reload;
103688d4060Schristos 	uint8_t need_to_send_stats;
104688d4060Schristos 	uint8_t need_to_send_quit;
105688d4060Schristos 	uint8_t	ipc_send_blocked;
106688d4060Schristos 	struct udb_ptr* last_task;
107688d4060Schristos 
108688d4060Schristos 	/* xfrd shutdown flag */
109688d4060Schristos 	uint8_t shutdown;
110688d4060Schristos 
111df8774c2Schristos 	/* tree of zones, by apex name, contains xfrd_zone_type*. Only secondary zones. */
112df8774c2Schristos 	rbtree_type *zones;
113688d4060Schristos 
114df8774c2Schristos 	/* tree of zones, by apex name, contains notify_zone*. All zones. */
115df8774c2Schristos 	rbtree_type *notify_zones;
116df8774c2Schristos 	/* number of notify_zone active using UDP socket */
117688d4060Schristos 	int notify_udp_num;
118df8774c2Schristos 	/* first and last notify_zone* entries waiting for a UDP socket */
119df8774c2Schristos 	struct notify_zone *notify_waiting_first, *notify_waiting_last;
120688d4060Schristos };
121688d4060Schristos 
122688d4060Schristos /*
123688d4060Schristos  * XFR daemon SOA information kept in network format.
124688d4060Schristos  * This is in packet order.
125688d4060Schristos  */
126688d4060Schristos struct xfrd_soa {
127688d4060Schristos 	/* name of RR is zone apex dname */
128688d4060Schristos 	uint16_t type; /* = TYPE_SOA */
129688d4060Schristos 	uint16_t klass; /* = CLASS_IN */
130688d4060Schristos 	uint32_t ttl;
131688d4060Schristos 	uint16_t rdata_count; /* = 7 */
132688d4060Schristos 	/* format is 1 octet length, + wireformat dname.
133688d4060Schristos 	   one more octet since parse_dname_wire_from_packet needs it.
134688d4060Schristos 	   maximum size is allocated to avoid memory alloc/free. */
135688d4060Schristos 	uint8_t prim_ns[MAXDOMAINLEN + 2];
136688d4060Schristos 	uint8_t email[MAXDOMAINLEN + 2];
137688d4060Schristos 	uint32_t serial;
138688d4060Schristos 	uint32_t refresh;
139688d4060Schristos 	uint32_t retry;
140688d4060Schristos 	uint32_t expire;
141688d4060Schristos 	uint32_t minimum;
142df8774c2Schristos } ATTR_PACKED;
143688d4060Schristos 
144688d4060Schristos 
145688d4060Schristos /*
146688d4060Schristos  * XFRD state for a single zone
147688d4060Schristos  */
148688d4060Schristos struct xfrd_zone {
149df8774c2Schristos 	rbnode_type node;
150688d4060Schristos 
151688d4060Schristos 	/* name of the zone */
152688d4060Schristos 	const dname_type* apex;
153688d4060Schristos 	const char* apex_str;
154688d4060Schristos 
155688d4060Schristos 	/* Three types of soas:
156688d4060Schristos 	 * NSD: in use by running server
157688d4060Schristos 	 * disk: stored on disk in db/diff file
158688d4060Schristos 	 * notified: from notification, could be available on a master.
159688d4060Schristos 	 * And the time the soa was acquired (start time for timeouts).
160688d4060Schristos 	 * If the time==0, no SOA is available.
161688d4060Schristos 	 */
162df8774c2Schristos 	xfrd_soa_type soa_nsd;
163688d4060Schristos 	time_t soa_nsd_acquired;
164df8774c2Schristos 	xfrd_soa_type soa_disk;
165688d4060Schristos 	time_t soa_disk_acquired;
166df8774c2Schristos 	xfrd_soa_type soa_notified;
167688d4060Schristos 	time_t soa_notified_acquired;
168688d4060Schristos 
169688d4060Schristos 	enum xfrd_zone_state {
170688d4060Schristos 		xfrd_zone_ok,
171688d4060Schristos 		xfrd_zone_refreshing,
172688d4060Schristos 		xfrd_zone_expired
173688d4060Schristos 	} state;
174688d4060Schristos 
175688d4060Schristos 	/* master to try to transfer from, number for persistence */
176df8774c2Schristos 	struct acl_options* master;
177688d4060Schristos 	int master_num;
178688d4060Schristos 	int next_master; /* -1 or set by notify where to try next */
179688d4060Schristos 	/* round of xfrattempts, -1 is waiting for timeout */
180688d4060Schristos 	int round_num;
181df8774c2Schristos 	struct zone_options* zone_options;
182688d4060Schristos 	int fresh_xfr_timeout;
183688d4060Schristos 
184688d4060Schristos 	/* handler for timeouts */
185688d4060Schristos 	struct timeval timeout;
186688d4060Schristos 	struct event zone_handler;
187688d4060Schristos 	int zone_handler_flags;
188688d4060Schristos 	int event_added;
189688d4060Schristos 
190688d4060Schristos 	/* tcp connection zone is using, or -1 */
191688d4060Schristos 	int tcp_conn;
192688d4060Schristos 	/* zone is waiting for a tcp connection */
193688d4060Schristos 	uint8_t tcp_waiting;
194688d4060Schristos 	/* next zone in waiting list */
195df8774c2Schristos 	xfrd_zone_type* tcp_waiting_next;
196df8774c2Schristos 	xfrd_zone_type* tcp_waiting_prev;
197688d4060Schristos 	/* zone is in its tcp send queue */
198688d4060Schristos 	uint8_t in_tcp_send;
199688d4060Schristos 	/* next zone in tcp send queue */
200df8774c2Schristos 	xfrd_zone_type* tcp_send_next;
201df8774c2Schristos 	xfrd_zone_type* tcp_send_prev;
202688d4060Schristos 	/* zone is waiting for a udp connection (tcp is preferred) */
203688d4060Schristos 	uint8_t udp_waiting;
204688d4060Schristos 	/* next zone in waiting list for UDP */
205df8774c2Schristos 	xfrd_zone_type* udp_waiting_next;
206df8774c2Schristos 	xfrd_zone_type* udp_waiting_prev;
207688d4060Schristos 	/* zone has been activated to run now (after the other events
208688d4060Schristos 	 * but before blocking in select again) */
209688d4060Schristos 	uint8_t is_activated;
210df8774c2Schristos 	xfrd_zone_type* activated_next;
211df8774c2Schristos 	xfrd_zone_type* activated_prev;
212688d4060Schristos 
213688d4060Schristos 	/* xfr message handling data */
214688d4060Schristos 	/* query id */
215688d4060Schristos 	uint16_t query_id;
216*66a1527dSchristos 	xfrd_xfr_type *latest_xfr;
217*66a1527dSchristos 
218*66a1527dSchristos 	int multi_master_first_master; /* >0: first check master_num */
219*66a1527dSchristos 	int multi_master_update_check; /* -1: not update >0: last update master_num */
220*66a1527dSchristos } ATTR_PACKED;
221*66a1527dSchristos 
222*66a1527dSchristos /*
223*66a1527dSchristos  * State for a single zone XFR
224*66a1527dSchristos  */
225*66a1527dSchristos struct xfrd_xfr {
226*66a1527dSchristos 	xfrd_xfr_type *next;
227*66a1527dSchristos 	xfrd_xfr_type *prev;
2285004c526Schristos 	uint16_t query_type;
229*66a1527dSchristos 	uint8_t sent; /* written to tasklist (tri-state) */
230*66a1527dSchristos 	time_t acquired; /* time xfr was acquired */
231688d4060Schristos 	uint32_t msg_seq_nr; /* number of messages already handled */
232688d4060Schristos 	uint32_t msg_old_serial, msg_new_serial; /* host byte order */
233688d4060Schristos 	size_t msg_rr_count;
234688d4060Schristos 	uint8_t msg_is_ixfr; /* 1:IXFR detected. 2:middle IXFR SOA seen. */
235688d4060Schristos 	tsig_record_type tsig; /* tsig state for IXFR/AXFR */
236688d4060Schristos 	uint64_t xfrfilenumber; /* identifier for file to store xfr into,
237688d4060Schristos 	                           valid if msg_seq_nr nonzero */
238*66a1527dSchristos };
239688d4060Schristos 
240688d4060Schristos enum xfrd_packet_result {
241688d4060Schristos 	xfrd_packet_bad, /* drop the packet/connection */
242688d4060Schristos 	xfrd_packet_drop, /* drop the connection, but not report bad */
243688d4060Schristos 	xfrd_packet_more, /* more packets to follow on tcp */
244688d4060Schristos 	xfrd_packet_notimpl, /* server responded with NOTIMPL or FORMATERR */
245688d4060Schristos 	xfrd_packet_tcp, /* try tcp connection */
246688d4060Schristos 	xfrd_packet_transfer, /* server responded with transfer*/
247688d4060Schristos 	xfrd_packet_newlease /* no changes, soa OK */
248688d4060Schristos };
249688d4060Schristos 
250688d4060Schristos /*
251688d4060Schristos    Division of the (portably: 1024) max number of sockets that can be open.
252688d4060Schristos    The sum of the below numbers should be below the user limit for sockets
253688d4060Schristos    open, or you see errors in your logfile.
254688d4060Schristos    And it should be below FD_SETSIZE, to be able to select() on replies.
255688d4060Schristos    Note that also some sockets are used for writing the ixfr.db, xfrd.state
256688d4060Schristos    files and for the pipes to the main parent process.
257*66a1527dSchristos 
258*66a1527dSchristos    For xfrd_tcp_max, 128 is the default number of TCP AXFR/IXFR concurrent
259*66a1527dSchristos    connections. Each entry has 64Kb buffer preallocated.
260688d4060Schristos */
261df8774c2Schristos #define XFRD_MAX_UDP 128 /* max number of UDP sockets at a time for IXFR */
262df8774c2Schristos #define XFRD_MAX_UDP_NOTIFY 128 /* max concurrent UDP sockets for NOTIFY */
263688d4060Schristos 
264688d4060Schristos #define XFRD_TRANSFER_TIMEOUT_START 10 /* empty zone timeout is between x and 2*x seconds */
265688d4060Schristos #define XFRD_TRANSFER_TIMEOUT_MAX 86400 /* empty zone timeout max expbackoff */
2665004c526Schristos #define XFRD_LOWERBOUND_REFRESH 1 /* seconds, smallest refresh timeout */
2675004c526Schristos #define XFRD_LOWERBOUND_RETRY 1 /* seconds, smallest retry timeout */
2685004c526Schristos 
2695004c526Schristos /*
2705004c526Schristos  * return refresh period
2715004c526Schristos  * within configured and defined lower and upper bounds
2725004c526Schristos  */
2735004c526Schristos static inline time_t
within_refresh_bounds(xfrd_zone_type * zone,time_t refresh)2745004c526Schristos within_refresh_bounds(xfrd_zone_type* zone, time_t refresh)
2755004c526Schristos {
2765004c526Schristos 	return (time_t)zone->zone_options->pattern->max_refresh_time < refresh
2775004c526Schristos 	     ? (time_t)zone->zone_options->pattern->max_refresh_time
2785004c526Schristos 	     : (time_t)zone->zone_options->pattern->min_refresh_time > refresh
2795004c526Schristos 	     ? (time_t)zone->zone_options->pattern->min_refresh_time
2805004c526Schristos 	     : XFRD_LOWERBOUND_REFRESH > refresh
2815004c526Schristos 	     ? XFRD_LOWERBOUND_REFRESH : refresh;
2825004c526Schristos }
2835004c526Schristos 
2845004c526Schristos /*
2855004c526Schristos  * return the zone's refresh period (from the on disk stored SOA)
2865004c526Schristos  * within configured and defined lower and upper bounds
2875004c526Schristos  */
2885004c526Schristos static inline time_t
bound_soa_disk_refresh(xfrd_zone_type * zone)2895004c526Schristos bound_soa_disk_refresh(xfrd_zone_type* zone)
2905004c526Schristos {
2915004c526Schristos 	return within_refresh_bounds(zone, ntohl(zone->soa_disk.refresh));
2925004c526Schristos }
2935004c526Schristos 
2945004c526Schristos /*
2955004c526Schristos  * return retry period
2965004c526Schristos  * within configured and defined lower and upper bounds
2975004c526Schristos  */
2985004c526Schristos static inline time_t
within_retry_bounds(xfrd_zone_type * zone,time_t retry)2995004c526Schristos within_retry_bounds(xfrd_zone_type* zone, time_t retry)
3005004c526Schristos {
3015004c526Schristos 	return (time_t)zone->zone_options->pattern->max_retry_time < retry
3025004c526Schristos 	     ? (time_t)zone->zone_options->pattern->max_retry_time
3035004c526Schristos 	     : (time_t)zone->zone_options->pattern->min_retry_time > retry
3045004c526Schristos 	     ? (time_t)zone->zone_options->pattern->min_retry_time
3055004c526Schristos 	     : XFRD_LOWERBOUND_RETRY > retry
3065004c526Schristos 	     ? XFRD_LOWERBOUND_RETRY : retry;
3075004c526Schristos }
3085004c526Schristos 
3095004c526Schristos /*
3105004c526Schristos  * return the zone's retry period (from the on disk stored SOA)
3115004c526Schristos  * within configured and defined lower and upper bounds
3125004c526Schristos  */
3135004c526Schristos static inline time_t
bound_soa_disk_retry(xfrd_zone_type * zone)3145004c526Schristos bound_soa_disk_retry(xfrd_zone_type* zone)
3155004c526Schristos {
3165004c526Schristos 	return within_retry_bounds(zone, ntohl(zone->soa_disk.retry));
3175004c526Schristos }
3185004c526Schristos 
3195004c526Schristos /*
3205004c526Schristos  * return expire period
3215004c526Schristos  * within configured and defined lower bounds
3225004c526Schristos  */
3235004c526Schristos static inline time_t
within_expire_bounds(xfrd_zone_type * zone,time_t expire)3245004c526Schristos within_expire_bounds(xfrd_zone_type* zone, time_t expire)
3255004c526Schristos {
3265004c526Schristos 	switch (zone->zone_options->pattern->min_expire_time_expr) {
3275004c526Schristos 	case EXPIRE_TIME_HAS_VALUE:
3285004c526Schristos 		return (time_t)zone->zone_options->pattern->min_expire_time > expire
3295004c526Schristos 		     ? (time_t)zone->zone_options->pattern->min_expire_time : expire;
3305004c526Schristos 
3315004c526Schristos 	case REFRESHPLUSRETRYPLUS1:
3325004c526Schristos 		return bound_soa_disk_refresh(zone) + bound_soa_disk_retry(zone) + 1 > expire
3335004c526Schristos 		     ? bound_soa_disk_refresh(zone) + bound_soa_disk_retry(zone) + 1 : expire;
3345004c526Schristos 	default:
3355004c526Schristos 		return expire;
3365004c526Schristos 	}
3375004c526Schristos }
3385004c526Schristos 
3395004c526Schristos /* return the zone's expire period (from the on disk stored SOA) */
3405004c526Schristos static inline time_t
bound_soa_disk_expire(xfrd_zone_type * zone)3415004c526Schristos bound_soa_disk_expire(xfrd_zone_type* zone)
3425004c526Schristos {
3435004c526Schristos 	return within_expire_bounds(zone, ntohl(zone->soa_disk.expire));
3445004c526Schristos }
345688d4060Schristos 
346*66a1527dSchristos /* return the zone's expire period (from the SOA in use by the running server) */
347*66a1527dSchristos static inline time_t
bound_soa_nsd_expire(xfrd_zone_type * zone)348*66a1527dSchristos bound_soa_nsd_expire(xfrd_zone_type* zone)
349*66a1527dSchristos {
350*66a1527dSchristos 	return within_expire_bounds(zone, ntohl(zone->soa_nsd.expire));
351*66a1527dSchristos }
352*66a1527dSchristos 
353df8774c2Schristos extern xfrd_state_type* xfrd;
354688d4060Schristos 
355688d4060Schristos /* start xfrd, new start. Pass socket to server_main. */
356688d4060Schristos void xfrd_init(int socket, struct nsd* nsd, int shortsoa, int reload_active,
357688d4060Schristos 	pid_t nsd_pid);
358688d4060Schristos 
359688d4060Schristos /* add new slave zone, dname(from zone_opt) and given options */
360df8774c2Schristos void xfrd_init_slave_zone(xfrd_state_type* xfrd, struct zone_options* zone_opt);
361688d4060Schristos 
362688d4060Schristos /* delete slave zone */
363df8774c2Schristos void xfrd_del_slave_zone(xfrd_state_type* xfrd, const dname_type* dname);
364688d4060Schristos 
365688d4060Schristos /* disable ixfr for a while for zone->master */
366df8774c2Schristos void xfrd_disable_ixfr(xfrd_zone_type* zone);
367688d4060Schristos 
368688d4060Schristos /* get the current time epoch. Cached for speed. */
369688d4060Schristos time_t xfrd_time(void);
370688d4060Schristos 
371688d4060Schristos /*
372688d4060Schristos  * Handle final received packet from network.
373688d4060Schristos  * returns enum of packet discovery results
374688d4060Schristos  */
375688d4060Schristos enum xfrd_packet_result xfrd_handle_received_xfr_packet(
376df8774c2Schristos 	xfrd_zone_type* zone, buffer_type* packet);
377688d4060Schristos 
378688d4060Schristos /* set timer to specific value */
379df8774c2Schristos void xfrd_set_timer(xfrd_zone_type* zone, time_t t);
380688d4060Schristos /* set refresh timer of zone to refresh at time now */
381df8774c2Schristos void xfrd_set_refresh_now(xfrd_zone_type* zone);
382688d4060Schristos /* unset the timer - no more timeouts, for when zone is queued */
383df8774c2Schristos void xfrd_unset_timer(xfrd_zone_type* zone);
384688d4060Schristos /* remove the 'refresh now', remove it from the activated list */
385df8774c2Schristos void xfrd_deactivate_zone(xfrd_zone_type* z);
386688d4060Schristos 
387688d4060Schristos /*
388688d4060Schristos  * Make a new request to next master server.
389688d4060Schristos  * uses next_master if set (and a fresh set of rounds).
390*66a1527dSchristos  * otherwise, starts new round of requests if none started already.
391688d4060Schristos  * starts next round of requests if at last master.
392688d4060Schristos  * if too many rounds of requests, sets timer for next retry.
393688d4060Schristos  */
394df8774c2Schristos void xfrd_make_request(xfrd_zone_type* zone);
395688d4060Schristos 
396688d4060Schristos /*
397688d4060Schristos  * send packet via udp (returns UDP fd source socket) to acl addr.
398688d4060Schristos  * returns -1 on failure.
399688d4060Schristos  */
400df8774c2Schristos int xfrd_send_udp(struct acl_options* acl, buffer_type* packet,
401df8774c2Schristos 	struct acl_options* ifc);
402688d4060Schristos 
403688d4060Schristos /*
404688d4060Schristos  * read from udp port packet into buffer, returns 0 on failure
405688d4060Schristos  */
406df8774c2Schristos int xfrd_udp_read_packet(buffer_type* packet, int fd, struct sockaddr* src,
407df8774c2Schristos 	socklen_t* srclen);
408688d4060Schristos 
409688d4060Schristos /*
410688d4060Schristos  * Release udp socket that a zone is using
411688d4060Schristos  */
412df8774c2Schristos void xfrd_udp_release(xfrd_zone_type* zone);
413688d4060Schristos 
414688d4060Schristos /*
415688d4060Schristos  * Get a static buffer for temporary use (to build a packet).
416688d4060Schristos  */
417688d4060Schristos struct buffer* xfrd_get_temp_buffer(void);
418688d4060Schristos 
419688d4060Schristos /*
420688d4060Schristos  * TSIG sign outgoing request. Call if acl has a key.
421688d4060Schristos  */
422688d4060Schristos void xfrd_tsig_sign_request(buffer_type* packet, struct tsig_record* tsig,
423df8774c2Schristos         struct acl_options* acl);
424688d4060Schristos 
425688d4060Schristos /* handle incoming soa information (NSD is running it, time acquired=guess).
426688d4060Schristos    Pass soa=NULL,acquired=now if NSD has nothing loaded for the zone
427688d4060Schristos    (i.e. zonefile was deleted). */
428df8774c2Schristos void xfrd_handle_incoming_soa(xfrd_zone_type* zone, xfrd_soa_type* soa,
429688d4060Schristos 	time_t acquired);
430688d4060Schristos /* handle a packet passed along ipc route. acl is the one that accepted
431688d4060Schristos    the packet. The packet is the network blob received. acl_xfr is
432688d4060Schristos    provide-xfr acl matching notify sender or -1 */
433688d4060Schristos void xfrd_handle_passed_packet(buffer_type* packet,
434688d4060Schristos 	int acl_num, int acl_xfr);
435688d4060Schristos 
436688d4060Schristos /* try to reopen the logfile. */
437688d4060Schristos void xfrd_reopen_logfile(void);
438688d4060Schristos 
439688d4060Schristos /* free namedb for xfrd usage */
440688d4060Schristos void xfrd_free_namedb(struct nsd* nsd);
441688d4060Schristos 
442688d4060Schristos /* copy SOA info from rr to soa struct. */
443df8774c2Schristos void xfrd_copy_soa(xfrd_soa_type* soa, rr_type* rr);
444688d4060Schristos 
445688d4060Schristos /* check for failed updates - it is assumed that now the reload has
446688d4060Schristos    finished, and all zone SOAs have been sent. */
447688d4060Schristos void xfrd_check_failed_updates(void);
448688d4060Schristos 
449*66a1527dSchristos void
450*66a1527dSchristos xfrd_prepare_updates_for_reload(void);
451*66a1527dSchristos 
452688d4060Schristos /*
453688d4060Schristos  * Prepare zones for a reload, this sets the times on the zones to be
454688d4060Schristos  * before the current time, so the reload happens after.
455688d4060Schristos  */
456688d4060Schristos void xfrd_prepare_zones_for_reload(void);
457688d4060Schristos 
458688d4060Schristos /* Bind a local interface to a socket descriptor, return 1 on success */
459df8774c2Schristos int xfrd_bind_local_interface(int sockd, struct acl_options* ifc,
460df8774c2Schristos 	struct acl_options* acl, int tcp);
461688d4060Schristos 
462688d4060Schristos /* process results and soa info from reload */
463df8774c2Schristos void xfrd_process_task_result(xfrd_state_type* xfrd, struct udb_base* taskudb);
464688d4060Schristos 
465688d4060Schristos /* set to reload right away (for user controlled reload events) */
466df8774c2Schristos void xfrd_set_reload_now(xfrd_state_type* xfrd);
467688d4060Schristos 
468688d4060Schristos /* send expiry notifications to nsd */
469df8774c2Schristos void xfrd_send_expire_notification(xfrd_zone_type* zone);
470688d4060Schristos 
471688d4060Schristos /* handle incoming notify (soa or NULL) and start zone xfr if necessary */
472df8774c2Schristos void xfrd_handle_notify_and_start_xfr(xfrd_zone_type* zone, xfrd_soa_type* soa);
473688d4060Schristos 
474688d4060Schristos /* handle zone timeout, event */
475688d4060Schristos void xfrd_handle_zone(int fd, short event, void* arg);
476688d4060Schristos 
477688d4060Schristos const char* xfrd_pretty_time(time_t v);
478688d4060Schristos 
479*66a1527dSchristos xfrd_xfr_type *xfrd_prepare_zone_xfr(xfrd_zone_type *zone, uint16_t query_type);
480*66a1527dSchristos 
481*66a1527dSchristos void xfrd_delete_zone_xfr(xfrd_zone_type *zone, xfrd_xfr_type *xfr);
482*66a1527dSchristos 
483688d4060Schristos #endif /* XFRD_H */
484