OpenDNSSEC-signer  1.4.10
xfrd.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 NLNet Labs. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
19  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
21  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
23  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  */
26 
32 #include "config.h"
33 #include "daemon/engine.h"
34 #include "daemon/xfrhandler.h"
35 #include "shared/duration.h"
36 #include "shared/file.h"
37 #include "shared/log.h"
38 #include "shared/status.h"
39 #include "shared/util.h"
40 #include "signer/backup.h"
41 #include "signer/domain.h"
42 #include "signer/zone.h"
43 #include "wire/tcpset.h"
44 #include "wire/xfrd.h"
45 
46 #include <unistd.h>
47 #include <fcntl.h>
48 
49 #define XFRD_TSIG_MAX_UNSIGNED 100
50 
51 static const char* xfrd_str = "xfrd";
52 
53 static void xfrd_handle_zone(netio_type* netio,
54  netio_handler_type* handler, netio_events_type event_types);
55 static void xfrd_make_request(xfrd_type* xfrd);
56 
57 static socklen_t xfrd_acl_sockaddr(acl_type* acl, unsigned int port,
58  struct sockaddr_storage *sck);
59 
60 static void xfrd_write_soa(xfrd_type* xfrd, buffer_type* buffer);
61 static int xfrd_parse_soa(xfrd_type* xfrd, buffer_type* buffer,
62  unsigned rdata_only, unsigned update, uint32_t t,
63  uint32_t* serial);
64 static ods_status xfrd_parse_rrs(xfrd_type* xfrd, buffer_type* buffer,
65  uint16_t count, int* done);
66 static xfrd_pkt_status xfrd_parse_packet(xfrd_type* xfrd,
67  buffer_type* buffer);
68 static xfrd_pkt_status xfrd_handle_packet(xfrd_type* xfrd,
69  buffer_type* buffer);
70 
71 static void xfrd_tcp_obtain(xfrd_type* xfrd, tcp_set_type* set);
72 static void xfrd_tcp_read(xfrd_type* xfrd, tcp_set_type* set);
73 static void xfrd_tcp_release(xfrd_type* xfrd, tcp_set_type* set, int open_waiting);
74 static void xfrd_tcp_write(xfrd_type* xfrd, tcp_set_type* set);
75 static void xfrd_tcp_xfr(xfrd_type* xfrd, tcp_set_type* set);
76 static int xfrd_tcp_open(xfrd_type* xfrd, tcp_set_type* set);
77 
78 static void xfrd_udp_obtain(xfrd_type* xfrd);
79 static void xfrd_udp_read(xfrd_type* xfrd);
80 static void xfrd_udp_release(xfrd_type* xfrd);
81 static int xfrd_udp_read_packet(xfrd_type* xfrd);
82 static int xfrd_udp_send(xfrd_type* xfrd, buffer_type* buffer);
83 static int xfrd_udp_send_request_ixfr(xfrd_type* xfrd);
84 
85 static time_t xfrd_time(xfrd_type* xfrd);
86 static void xfrd_set_timer(xfrd_type* xfrd, time_t t);
87 static void xfrd_set_timer_time(xfrd_type* xfrd, time_t t);
88 static void xfrd_unset_timer(xfrd_type* xfrd);
89 
90 
95 static uint8_t
96 xfrd_recover_dname(uint8_t* dname, const char* name)
97 {
98  const uint8_t *s = (const uint8_t *) name;
99  uint8_t *h;
100  uint8_t *p;
101  uint8_t *d = dname;
102  size_t label_length;
103 
104  if (strcmp(name, ".") == 0) {
105  /* Root domain. */
106  dname[0] = 0;
107  return 1;
108  }
109  for (h = d, p = h + 1; *s; ++s, ++p) {
110  if (p - dname >= MAXDOMAINLEN) {
111  return 0;
112  }
113  switch (*s) {
114  case '.':
115  if (p == h + 1) {
116  /* Empty label. */
117  return 0;
118  } else {
119  label_length = p - h - 1;
120  if (label_length > MAXLABELLEN) {
121  return 0;
122  }
123  *h = label_length;
124  h = p;
125  }
126  break;
127  case '\\':
128  /* Handle escaped characters (RFC1035 5.1) */
129  if (isdigit(s[1]) && isdigit(s[2]) && isdigit(s[3])) {
130  int val = (ldns_hexdigit_to_int(s[1]) * 100 +
131  ldns_hexdigit_to_int(s[2]) * 10 +
132  ldns_hexdigit_to_int(s[3]));
133  if (0 <= val && val <= 255) {
134  s += 3;
135  *p = val;
136  } else {
137  *p = *++s;
138  }
139  } else if (s[1] != '\0') {
140  *p = *++s;
141  }
142  break;
143  default:
144  *p = *s;
145  break;
146  }
147  }
148  if (p != h + 1) {
149  /* Terminate last label. */
150  label_length = p - h - 1;
151  if (label_length > MAXLABELLEN) {
152  return 0;
153  }
154  *h = label_length;
155  h = p;
156  }
157  /* Add root label. */
158  *h = 0;
159  return p-dname;
160 }
161 
162 
167 static void
168 xfrd_recover(xfrd_type* xfrd)
169 {
170  zone_type* zone = (zone_type*) xfrd->zone;
171  char* file = NULL;
172  FILE* fd = NULL;
173  int round_num = 0;
174  int master_num = 0;
175  int next_master = 0;
176  uint32_t timeout = 0;
177  uint32_t serial_xfr = 0;
178  uint32_t serial_notify = 0;
179  uint32_t serial_disk = 0;
180  time_t serial_xfr_acquired = 0;
181  time_t serial_notify_acquired = 0;
182  time_t serial_disk_acquired = 0;
183  uint32_t soa_ttl = 0;
184  uint32_t soa_serial = 0;
185  uint32_t soa_refresh = 0;
186  uint32_t soa_retry = 0;
187  uint32_t soa_expire = 0;
188  uint32_t soa_minimum = 0;
189  const char* soa_mname = NULL;
190  const char* soa_rname = NULL;
191 
192  if (zone && zone->name && zone->db &&
193  zone->db->is_initialized && zone->db->have_serial) {
194  file = ods_build_path(zone->name, ".xfrd-state", 0, 1);
195  if (file) {
196  ods_log_verbose("[%s] recover xfrd.state file %s zone %s", xfrd_str,
197  file, zone->name);
198  fd = ods_fopen(file, NULL, "r");
199  if (fd) {
200  if (!backup_read_check_str(fd, ODS_SE_FILE_MAGIC_V3)) {
201  ods_log_error("[%s] corrupted state file zone %s: read "
202  "magic (start) error", xfrd_str, zone->name);
203  goto xfrd_recover_error;
204  }
205  if (!backup_read_check_str(fd, ";;Zone:") |
206  !backup_read_check_str(fd, "name") |
207  !backup_read_check_str(fd, zone->name) |
208  !backup_read_check_str(fd, "ttl") |
209  !backup_read_uint32_t(fd, &soa_ttl) |
210  !backup_read_check_str(fd, "mname") |
211  !backup_read_str(fd, &soa_mname) |
212  !backup_read_check_str(fd, "rname") |
213  !backup_read_str(fd, &soa_rname) |
214  !backup_read_check_str(fd, "serial") |
215  !backup_read_uint32_t(fd, &soa_serial) |
216  !backup_read_check_str(fd, "refresh") |
217  !backup_read_uint32_t(fd, &soa_refresh) |
218  !backup_read_check_str(fd, "retry") |
219  !backup_read_uint32_t(fd, &soa_retry) |
220  !backup_read_check_str(fd, "expire") |
221  !backup_read_uint32_t(fd, &soa_expire) |
222  !backup_read_check_str(fd, "minimum") |
223  !backup_read_uint32_t(fd, &soa_minimum)) {
224  ods_log_error("[%s] corrupted state file zone %s: read "
225  ";;Zone error", xfrd_str, zone->name);
226  goto xfrd_recover_error;
227  }
228  if (!backup_read_check_str(fd, ";;Master:") |
229  !backup_read_check_str(fd, "num") |
230  !backup_read_int(fd, &master_num) |
231  !backup_read_check_str(fd, "next") |
232  !backup_read_int(fd, &next_master) |
233  !backup_read_check_str(fd, "round") |
234  !backup_read_int(fd, &round_num) |
235  !backup_read_check_str(fd, "timeout") |
236  !backup_read_uint32_t(fd, &timeout)) {
237  ods_log_error("[%s] corrupt state file zone %s: read "
238  ";;Master error", xfrd_str, zone->name);
239  goto xfrd_recover_error;
240  }
241  if (!backup_read_check_str(fd, ";;Serial:") |
242  !backup_read_check_str(fd, "xfr") |
243  !backup_read_uint32_t(fd, &serial_xfr) |
244  !backup_read_time_t(fd, &serial_xfr_acquired) |
245  !backup_read_check_str(fd, "notify") |
246  !backup_read_uint32_t(fd, &serial_notify) |
247  !backup_read_time_t(fd, &serial_notify_acquired) |
248  !backup_read_check_str(fd, "disk") |
249  !backup_read_uint32_t(fd, &serial_disk) |
250  !backup_read_time_t(fd, &serial_disk_acquired)) {
251  ods_log_error("[%s] corrupt state file zone %s: read "
252  ";;Serial error", xfrd_str, zone->name);
253  goto xfrd_recover_error;
254  }
255  if (!backup_read_check_str(fd, ODS_SE_FILE_MAGIC_V3)) {
256  ods_log_error("[%s] corrupt state file zone %s: read "
257  "magic (end) error", xfrd_str, zone->name);
258  goto xfrd_recover_error;
259  }
260 
261  /* all ok */
262  xfrd->master_num = master_num;
263  xfrd->next_master = next_master;
264  xfrd->round_num = round_num;
265  xfrd->timeout.tv_sec = timeout;
266  xfrd->timeout.tv_nsec = 0;
267  xfrd->master = NULL; /* acl_find_num(...) */
268  xfrd->soa.ttl = soa_ttl;
269  xfrd->soa.serial = soa_serial;
270  xfrd->soa.refresh = soa_refresh;
271  xfrd->soa.retry = soa_retry;
272  xfrd->soa.expire = soa_expire;
273  xfrd->soa.minimum = soa_minimum;
274  xfrd->soa.mname[0] = xfrd_recover_dname(xfrd->soa.mname+1,
275  soa_mname);
276  xfrd->soa.rname[0] = xfrd_recover_dname(xfrd->soa.rname+1,
277  soa_rname);
278  xfrd->serial_xfr = serial_xfr;
279  xfrd->serial_xfr_acquired = serial_xfr_acquired;
280  xfrd->serial_notify = serial_notify;
281  xfrd->serial_notify_acquired = serial_notify_acquired;
282  xfrd->serial_disk = serial_disk;
283  xfrd->serial_disk_acquired = serial_disk_acquired;
284  if (!timeout || serial_notify_acquired ||
285  (serial_disk_acquired &&
286  (uint32_t)xfrd_time(xfrd) - serial_disk_acquired >
287  soa_refresh)) {
289  }
290  if (serial_disk_acquired &&
291  ((uint32_t)xfrd_time(xfrd) - serial_disk_acquired >
292  soa_expire)) {
294  }
295 
296 xfrd_recover_error:
297  free((void*)soa_mname);
298  free((void*)soa_rname);
299  ods_fclose(fd);
300  }
301  free(file);
302  }
303  } else {
304  ods_log_verbose("[%s] did not recover xfrd.state file zone %s", xfrd_str,
305  (zone && zone->name)?zone->name:"(null)");
306  }
307  return;
308 }
309 
310 
315 xfrd_type*
316 xfrd_create(void* xfrhandler, void* zone)
317 {
318  xfrd_type* xfrd = NULL;
319  allocator_type* allocator = NULL;
320  if (!xfrhandler || !zone) {
321  return NULL;
322  }
323  allocator = allocator_create(malloc, free);
324  if (!allocator) {
325  ods_log_error("[%s] unable to create zone xfr structure: "
326  "allocator_create() failed", xfrd_str);
327  return NULL;
328  }
329  xfrd = (xfrd_type*) allocator_alloc(allocator, sizeof(xfrd_type));
330  if (!xfrd) {
331  ods_log_error("[%s] unable to create zone xfr structure: "
332  " allocator_alloc() failed", xfrd_str);
333  allocator_cleanup(allocator);
334  return NULL;
335  }
337  lock_basic_init(&xfrd->rw_lock);
338 
339  xfrd->allocator = allocator;
340  xfrd->xfrhandler = xfrhandler;
341  xfrd->zone = zone;
342  xfrd->tcp_conn = -1;
343  xfrd->round_num = -1;
344  xfrd->master_num = 0;
345  xfrd->next_master = -1;
346  xfrd->master = NULL;
348  xfrd->serial_xfr = 0;
349  xfrd->serial_disk = 0;
350  xfrd->serial_notify = 0;
351  xfrd->serial_xfr_acquired = 0;
352  xfrd->serial_disk_acquired = 0;
353  xfrd->serial_notify_acquired = 0;
354  xfrd->serial_retransfer = 0;
356  xfrd->query_id = 0;
357  xfrd->msg_seq_nr = 0;
358  xfrd->msg_rr_count = 0;
359  xfrd->msg_old_serial = 0;
360  xfrd->msg_new_serial = 0;
361  xfrd->msg_is_ixfr = 0;
362  xfrd->msg_do_retransfer = 0;
363  xfrd->udp_waiting = 0;
364  xfrd->udp_waiting_next = NULL;
365  xfrd->tcp_waiting = 0;
366  xfrd->tcp_waiting_next = NULL;
367  xfrd->tsig_rr = tsig_rr_create(allocator);
368  if (!xfrd->tsig_rr) {
369  xfrd_cleanup(xfrd, 0);
370  return NULL;
371  }
372  memset(&xfrd->soa, 0, sizeof(xfrd->soa));
373  xfrd->soa.ttl = 0;
374  xfrd->soa.mname[0] = 1;
375  xfrd->soa.rname[0] = 1;
376  xfrd->soa.serial = 0;
377  xfrd->soa.refresh = 3600;
378  xfrd->soa.retry = 300;
379  xfrd->soa.expire = 604800;
380  xfrd->soa.minimum = 3600;
381  xfrd->handler.fd = -1;
382  xfrd->handler.user_data = (void*) xfrd;
383  xfrd->handler.timeout = 0;
384  xfrd->handler.event_types =
386  xfrd->handler.event_handler = xfrd_handle_zone;
387  xfrd_set_timer_time(xfrd, 0);
388  xfrd_recover(xfrd);
389  return xfrd;
390 }
391 
392 
397 static time_t
398 xfrd_time(xfrd_type* xfrd)
399 {
400  ods_log_assert(xfrd);
401  ods_log_assert(xfrd->xfrhandler);
402  return xfrhandler_time((xfrhandler_type*) xfrd->xfrhandler);
403 }
404 
405 
410 static void
411 xfrd_set_timer(xfrd_type* xfrd, time_t t)
412 {
413  if (!xfrd || !xfrd->xfrhandler) {
414  return;
415  }
420  if(t > xfrd_time(xfrd) + 10) {
421  time_t extra = t - xfrd_time(xfrd);
422  time_t base = extra*9/10;
423 #ifdef HAVE_ARC4RANDOM_UNIFORM
424  t = xfrd_time(xfrd) + base +
425  arc4random_uniform(extra-base);
426 #elif HAVE_ARC4RANDOM
427  t = xfrd_time(xfrd) + base +
428  arc4random()%(extra-base);
429 #else
430  t = xfrd_time(xfrd) + base +
431  random()%(extra-base);
432 #endif
433  }
434  xfrd->handler.timeout = &xfrd->timeout;
435  xfrd->timeout.tv_sec = t;
436  xfrd->timeout.tv_nsec = 0;
437  return;
438 }
439 
440 
445 static void
446 xfrd_unset_timer(xfrd_type* xfrd)
447 {
448  ods_log_assert(xfrd);
449  xfrd->handler.timeout = NULL;
450  return;
451 }
452 
453 
458 static void
459 xfrd_set_timer_time(xfrd_type* xfrd, time_t t)
460 {
461  ods_log_assert(xfrd);
462  xfrd_set_timer(xfrd, xfrd_time(xfrd) + t);
463  return;
464 }
465 
466 
471 void
473 {
474  zone_type* zone = NULL;
475  if (!xfrd || !xfrd->zone || !xfrd->xfrhandler) {
476  return;
477  }
478  zone = (zone_type*) xfrd->zone;
479  ods_log_debug("[%s] zone %s sets timer timeout now", xfrd_str,
480  zone->name);
481  xfrd_set_timer_time(xfrd, 0);
482  return;
483 }
484 
485 
490 void
492 {
493  zone_type* zone = NULL;
494  if (!xfrd || !xfrd->zone || !xfrd->xfrhandler) {
495  return;
496  }
497  zone = (zone_type*) xfrd->zone;
498  ods_log_debug("[%s] zone %s sets timer timeout retry %u", xfrd_str,
499  zone->name, (unsigned) xfrd->soa.retry);
500  xfrd_set_timer_time(xfrd, xfrd->soa.retry);
501  return;
502 }
503 
504 
509 void
511 {
512  zone_type* zone = NULL;
513  if (!xfrd || !xfrd->zone || !xfrd->xfrhandler) {
514  return;
515  }
516  zone = (zone_type*) xfrd->zone;
517  ods_log_debug("[%s] zone %s sets timer timeout refresh %u", xfrd_str,
518  zone->name, (unsigned) xfrd->soa.refresh);
519  xfrd_set_timer_time(xfrd, xfrd->soa.refresh);
520  return;
521 }
522 
523 
528 static socklen_t
529 xfrd_acl_sockaddr(acl_type* acl, unsigned int port,
530  struct sockaddr_storage *sck)
531 {
532  ods_log_assert(acl);
533  ods_log_assert(sck);
534  ods_log_assert(port);
535  memset(sck, 0, sizeof(struct sockaddr_storage));
536  if (acl->family == AF_INET6) {
537  struct sockaddr_in6* sa = (struct sockaddr_in6*)sck;
538  sa->sin6_family = AF_INET6;
539  sa->sin6_port = htons(port);
540  sa->sin6_addr = acl->addr.addr6;
541  return sizeof(struct sockaddr_in6);
542  } else {
543  struct sockaddr_in* sa = (struct sockaddr_in*)sck;
544  sa->sin_family = AF_INET;
545  sa->sin_port = htons(port);
546  sa->sin_addr = acl->addr.addr;
547  return sizeof(struct sockaddr_in);
548  }
549  return 0;
550 }
551 
552 
557 socklen_t
558 xfrd_acl_sockaddr_to(acl_type* acl, struct sockaddr_storage *to)
559 {
560  unsigned int port = 0;
561  if (!acl || !to) {
562  return 0;
563  }
564  port = acl->port ? acl->port : (unsigned) atoi(DNS_PORT_STRING);
565  return xfrd_acl_sockaddr(acl, port, to);
566 }
567 
568 
573 static void
574 xfrd_tsig_sign(xfrd_type* xfrd, buffer_type* buffer)
575 {
576  tsig_algo_type* algo = NULL;
577  if (!xfrd || !xfrd->tsig_rr || !xfrd->master || !xfrd->master->tsig ||
578  !xfrd->master->tsig->key || !buffer) {
579  return; /* no tsig configured */
580  }
581  algo = tsig_lookup_algo(xfrd->master->tsig->algorithm);
582  if (!algo) {
583  ods_log_error("[%s] unable to sign request: tsig unknown algorithm "
584  "%s", xfrd_str, xfrd->master->tsig->algorithm);
585  return;
586  }
587  ods_log_assert(algo);
588  tsig_rr_reset(xfrd->tsig_rr, algo, xfrd->master->tsig->key);
589  xfrd->tsig_rr->original_query_id = buffer_pkt_id(buffer);
590  xfrd->tsig_rr->algo_name = ldns_rdf_clone(xfrd->tsig_rr->algo->wf_name);
591  xfrd->tsig_rr->key_name = ldns_rdf_clone(xfrd->tsig_rr->key->dname);
592  log_dname(xfrd->tsig_rr->key_name, "tsig sign query with key", LOG_DEBUG);
593  log_dname(xfrd->tsig_rr->algo_name, "tsig sign query with algorithm",
594  LOG_DEBUG);
595  tsig_rr_prepare(xfrd->tsig_rr);
596  tsig_rr_update(xfrd->tsig_rr, buffer, buffer_position(buffer));
597  tsig_rr_sign(xfrd->tsig_rr);
598  ods_log_debug("[%s] tsig append rr to request id=%u", xfrd_str,
599  buffer_pkt_id(buffer));
600  tsig_rr_append(xfrd->tsig_rr, buffer);
601  buffer_pkt_set_arcount(buffer, buffer_pkt_arcount(buffer)+1);
602  tsig_rr_prepare(xfrd->tsig_rr);
603  return;
604 }
605 
606 
611 static int
612 xfrd_tsig_process(xfrd_type* xfrd, buffer_type* buffer)
613 {
614  zone_type* zone = NULL;
615  int have_tsig = 0;
616  if (!xfrd || !xfrd->tsig_rr || !xfrd->master || !xfrd->master->tsig ||
617  !xfrd->master->tsig->key || !buffer) {
618  return 1; /* no tsig configured */
619  }
620  zone = (zone_type*) xfrd->zone;
621  ods_log_assert(zone);
622  ods_log_assert(zone->name);
623  ods_log_assert(xfrd->master->address);
624  if (!tsig_rr_find(xfrd->tsig_rr, buffer)) {
625  ods_log_error("[%s] unable to process tsig: xfr zone %s from %s "
626  "has malformed tsig rr", xfrd_str, zone->name,
627  xfrd->master->address);
628  return 0;
629  }
630  if (xfrd->tsig_rr->status == TSIG_OK) {
631  have_tsig = 1;
632  if (xfrd->tsig_rr->error_code != LDNS_RCODE_NOERROR) {
633  ods_log_error("[%s] zone %s, from %s has tsig error (%s)",
634  xfrd_str, zone->name, xfrd->master->address,
636  }
637  /* strip the TSIG resource record off... */
638  buffer_set_limit(buffer, xfrd->tsig_rr->position);
639  buffer_pkt_set_arcount(buffer, buffer_pkt_arcount(buffer)-1);
640  }
641  /* keep running the TSIG hash */
642  tsig_rr_update(xfrd->tsig_rr, buffer, buffer_limit(buffer));
643  if (have_tsig) {
644  if (!tsig_rr_verify(xfrd->tsig_rr)) {
645  ods_log_error("[%s] unable to process tsig: xfr zone %s from %s "
646  "has bad tsig signature", xfrd_str, zone->name,
647  xfrd->master->address);
648  return 0;
649  }
650  /* prepare for next tsigs */
651  tsig_rr_prepare(xfrd->tsig_rr);
652  } else if (xfrd->tsig_rr->update_since_last_prepare >
654  /* we allow a number of non-tsig signed packets */
655  ods_log_error("[%s] unable to process tsig: xfr zone %s, from %s "
656  "has too many consecutive packets without tsig", xfrd_str,
657  zone->name, xfrd->master->address);
658  return 0;
659  }
660  if (!have_tsig && xfrd->msg_seq_nr == 0) {
661  ods_log_error("[%s] unable to process tsig: xfr zone %s from %s "
662  "has no tsig in first packet of reply", xfrd_str,
663  zone->name, xfrd->master->address);
664  return 0;
665  }
666  /* process TSIG ok */
667  return 1;
668 }
669 
670 
675 static void
676 xfrd_commit_packet(xfrd_type* xfrd)
677 {
678  zone_type* zone = NULL;
679  char* xfrfile = NULL;
680  FILE* fd = NULL;
681  time_t serial_disk_acq = 0;
682  ods_log_assert(xfrd);
683  zone = (zone_type*) xfrd->zone;
684  xfrfile = ods_build_path(zone->name, ".xfrd", 0, 1);
685  if (!xfrfile) {
686  ods_log_crit("[%s] unable to commit xfr zone %s: build path failed",
687  xfrd_str, zone->name);
688  return;
689  }
690  ods_log_assert(zone);
691  ods_log_assert(zone->name);
692  lock_basic_lock(&zone->zone_lock);
693  lock_basic_lock(&xfrd->rw_lock);
695  /* mark end packet */
696  fd = ods_fopen(xfrfile, NULL, "a");
697  free((void*)xfrfile);
698  if (fd) {
699  fprintf(fd, ";;ENDPACKET\n");
700  ods_fclose(fd);
701  } else {
702  lock_basic_unlock(&xfrd->rw_lock);
705  ods_log_crit("[%s] unable to commit xfr zone %s: ods_fopen() failed "
706  "(%s)", xfrd_str, zone->name, strerror(errno));
707  return;
708  }
709  /* update soa serial management */
710  xfrd->serial_disk = xfrd->msg_new_serial;
711  serial_disk_acq = xfrd->serial_disk_acquired;
712  xfrd->serial_disk_acquired = xfrd_time(xfrd);
713  /* ensure newer time */
714  if (xfrd->serial_disk_acquired == serial_disk_acq) {
715  xfrd->serial_disk_acquired++;
716  }
717  xfrd->soa.serial = xfrd->serial_disk;
718  if (xfrd->msg_do_retransfer ||
719  (util_serial_gt(xfrd->serial_disk, xfrd->serial_xfr) &&
720  xfrd->serial_disk_acquired > xfrd->serial_xfr_acquired)) {
721  /* reschedule task */
722  int ret = 0;
723  xfrhandler_type* xfrhandler = (xfrhandler_type*) xfrd->xfrhandler;
724  engine_type* engine = (engine_type*) xfrhandler->engine;
725  ods_log_assert(xfrhandler);
726  ods_log_assert(engine);
727  ods_log_debug("[%s] reschedule task for zone %s: disk serial=%u "
728  "acquired=%u, memory serial=%u acquired=%u", xfrd_str,
729  zone->name, xfrd->serial_disk,
730  xfrd->serial_disk_acquired, xfrd->serial_xfr,
731  xfrd->serial_xfr_acquired);
732  ret = zone_reschedule_task(zone, engine->taskq, TASK_READ);
733  if (ret != ODS_STATUS_OK) {
734  ods_log_crit("[%s] unable to reschedule task for zone %s: %s",
735  xfrd_str, zone->name, ods_status2str(ret));
736  } else {
737  engine_wakeup_workers(engine);
738  }
739  }
740  /* reset retransfer */
741  xfrd->msg_do_retransfer = 0;
742 
744  lock_basic_unlock(&xfrd->rw_lock);
746  return;
747 }
748 
749 
754 static void
755 xfrd_dump_packet(xfrd_type* xfrd, buffer_type* buffer)
756 {
757  zone_type* zone = NULL;
758  char* xfrfile = NULL;
759  FILE* fd = NULL;
760  ldns_pkt* pkt = NULL;
761  ldns_status status = LDNS_STATUS_OK;
762  ods_log_assert(buffer);
763  ods_log_assert(xfrd);
764  zone = (zone_type*) xfrd->zone;
765  ods_log_assert(zone);
766  ods_log_assert(zone->name);
767  status = ldns_wire2pkt(&pkt, buffer_begin(buffer), buffer_limit(buffer));
768  if (status != LDNS_STATUS_OK) {
769  ods_log_crit("[%s] unable to dump packet zone %s: ldns_wire2pkt() "
770  "failed (%s)", xfrd_str, zone->name,
771  ldns_get_errorstr_by_id(status));
772  return;
773  }
774  ods_log_assert(pkt);
775  xfrfile = ods_build_path(zone->name, ".xfrd", 0, 1);
776  if (!xfrfile) {
777  ods_log_crit("[%s] unable to dump packet zone %s: build path failed",
778  xfrd_str, zone->name);
779  return;
780  }
781  lock_basic_lock(&xfrd->rw_lock);
782  if (xfrd->msg_do_retransfer && !xfrd->msg_seq_nr && !xfrd->msg_is_ixfr) {
783  fd = ods_fopen(xfrfile, NULL, "w");
784  } else {
785  fd = ods_fopen(xfrfile, NULL, "a");
786  }
787  free((void*) xfrfile);
788  if (!fd) {
789  ods_log_crit("[%s] unable to dump packet zone %s: ods_fopen() failed "
790  "(%s)", xfrd_str, zone->name, strerror(errno));
791  lock_basic_unlock(&xfrd->rw_lock);
792  return;
793  }
794  ods_log_assert(fd);
795  if (xfrd->msg_seq_nr == 0) {
796  fprintf(fd, ";;BEGINPACKET\n");
797  }
798  ldns_rr_list_print(fd, ldns_pkt_answer(pkt));
799  ods_fclose(fd);
800  lock_basic_unlock(&xfrd->rw_lock);
801  ldns_pkt_free(pkt);
802  return;
803 }
804 
805 
810 static void
811 xfrd_write_soa(xfrd_type* xfrd, buffer_type* buffer)
812 {
813  zone_type* zone = NULL;
814  size_t rdlength_pos = 0;
815  uint16_t rdlength = 0;
816  ods_log_assert(xfrd);
817  ods_log_assert(buffer);
818  zone = (zone_type*) xfrd->zone;
819  ods_log_assert(zone);
820  ods_log_assert(zone->apex);
821  buffer_write_rdf(buffer, zone->apex);
822  buffer_write_u16(buffer, (uint16_t) LDNS_RR_TYPE_SOA);
823  buffer_write_u16(buffer, (uint16_t) zone->klass);
824  buffer_write_u32(buffer, xfrd->soa.ttl);
825  rdlength_pos = buffer_position(buffer);
826  buffer_skip(buffer, sizeof(rdlength));
827  buffer_write(buffer, xfrd->soa.mname+1, xfrd->soa.mname[0]);
828  buffer_write(buffer, xfrd->soa.rname+1, xfrd->soa.rname[0]);
829  buffer_write_u32(buffer, xfrd->soa.serial);
830  buffer_write_u32(buffer, xfrd->soa.refresh);
831  buffer_write_u32(buffer, xfrd->soa.retry);
832  buffer_write_u32(buffer, xfrd->soa.expire);
833  buffer_write_u32(buffer, xfrd->soa.minimum);
834  rdlength = buffer_position(buffer) - rdlength_pos - sizeof(rdlength);
835  buffer_write_u16_at(buffer, rdlength_pos, rdlength);
836  return;
837 }
838 
839 
844 static void
845 xfrd_update_soa(xfrd_type* xfrd, buffer_type* buffer, uint32_t ttl,
846  uint16_t mname_pos, uint16_t rname_pos,
847  uint32_t refresh, uint32_t retry, uint32_t expire, uint32_t minimum)
848 {
849  zone_type* zone = NULL;
850  ods_log_assert(xfrd);
851  ods_log_assert(buffer);
852  zone = (zone_type*) xfrd->zone;
853  ods_log_assert(zone);
854  ods_log_assert(zone->apex);
855  xfrd->soa.ttl = ttl;
856  xfrd->soa.refresh = refresh;
857  xfrd->soa.retry = retry;
858  xfrd->soa.expire = expire;
859  xfrd->soa.minimum = minimum;
860  buffer_set_position(buffer, mname_pos);
861  if (!(xfrd->soa.mname[0] =
862  buffer_read_dname(buffer, xfrd->soa.mname+1, 1))) {
863  xfrd->soa.mname[0] = 1;
864  xfrd->soa.mname[1] = 0;
865  }
866  buffer_set_position(buffer, rname_pos);
867  if (!(xfrd->soa.rname[0] =
868  buffer_read_dname(buffer, xfrd->soa.rname+1, 1))) {
869  xfrd->soa.rname[0] = 1;
870  xfrd->soa.rname[1] = 0;
871  }
872  return;
873 }
874 
875 
880 static int
881 xfrd_parse_soa(xfrd_type* xfrd, buffer_type* buffer, unsigned rdata_only,
882  unsigned update, uint32_t t, uint32_t* soa_serial)
883 {
884  ldns_rr_type type = LDNS_RR_TYPE_SOA;
885  uint16_t mname_pos = 0;
886  uint16_t rname_pos = 0;
887  uint16_t pos = 0;
888  uint32_t serial = 0;
889  uint32_t refresh = 0;
890  uint32_t retry = 0;
891  uint32_t expire = 0;
892  uint32_t minimum = 0;
893  uint32_t ttl = t;
894  ods_log_assert(xfrd);
895  ods_log_assert(buffer);
896 
897  /* type class ttl */
898  if (!rdata_only) {
899  if (!buffer_available(buffer, 10)) {
900  ods_log_debug("[%s] unable to parse soa: rr too short",
901  xfrd_str);
902  return 0;
903  }
904  type = (ldns_rr_type) buffer_read_u16(buffer);
905  if (type != LDNS_RR_TYPE_SOA) {
906  ods_log_debug("[%s] unable to parse soa: rrtype %u != soa",
907  xfrd_str, (unsigned) type);
908  return 0;
909  }
910  (void)buffer_read_u16(buffer); /* class */
911  ttl = buffer_read_u32(buffer);
912  /* rdata length */
913  if (!buffer_available(buffer, buffer_read_u16(buffer))) {
914  ods_log_debug("[%s] unable to parse soa: rdata too short",
915  xfrd_str);
916  return 0;
917  }
918  }
919  /* MNAME */
920  mname_pos = buffer_position(buffer);
921  if (!buffer_skip_dname(buffer)) {
922  ods_log_debug("[%s] unable to parse soa: bad mname",
923  xfrd_str);
924  return 0;
925  }
926  /* RNAME */
927  rname_pos = buffer_position(buffer);
928  if (!buffer_skip_dname(buffer)) {
929  ods_log_debug("[%s] unable to parse soa: bad rname",
930  xfrd_str);
931  return 0;
932  }
933  serial = buffer_read_u32(buffer);
934  refresh = buffer_read_u32(buffer);
935  retry = buffer_read_u32(buffer);
936  expire = buffer_read_u32(buffer);
937  minimum = buffer_read_u32(buffer);
938  pos = buffer_position(buffer);
939  if (soa_serial) {
940  *soa_serial = serial;
941  }
942  if (update) {
943  xfrd_update_soa(xfrd, buffer, ttl, mname_pos, rname_pos,
944  refresh, retry, expire, minimum);
945  }
946  buffer_set_position(buffer, pos);
947  return 1;
948 }
949 
950 
955 static ods_status
956 xfrd_parse_rrs(xfrd_type* xfrd, buffer_type* buffer, uint16_t count,
957  int* done)
958 {
959  ldns_rr_type type = 0;
960  uint16_t rrlen = 0;
961  uint32_t ttl = 0;
962  uint32_t serial = 0;
963  uint32_t tmp_serial = 0;
964  size_t i = 0;
965  ods_log_assert(xfrd);
966  ods_log_assert(buffer);
967  ods_log_assert(done);
968  for (i=0; i < count; ++i, ++xfrd->msg_rr_count) {
969  if (*done) {
970  return ODS_STATUS_OK;
971  }
972  if (!buffer_skip_dname(buffer)) {
973  return ODS_STATUS_SKIPDNAME;
974  }
975  if (!buffer_available(buffer, 10)) {
976  return ODS_STATUS_BUFAVAIL;
977  }
978  (void)buffer_position(buffer);
979  type = (ldns_rr_type) buffer_read_u16(buffer);
980  (void)buffer_read_u16(buffer); /* class */
981  ttl = buffer_read_u32(buffer);
982  rrlen = buffer_read_u16(buffer);
983  if (!buffer_available(buffer, rrlen)) {
984  return ODS_STATUS_BUFAVAIL;
985  }
986  if (type == LDNS_RR_TYPE_SOA) {
987  if (!xfrd_parse_soa(xfrd, buffer, 1, 0, ttl, &serial)) {
988  return ODS_STATUS_PARSESOA;
989  }
990  if (xfrd->msg_rr_count == 1 && serial != xfrd->msg_new_serial) {
991  /* 2nd RR is SOA with different serial, this is an IXFR */
992  xfrd->msg_is_ixfr = 1;
994  if (!xfrd->serial_disk_acquired) {
996  /* got IXFR but need AXFR */
997  return ODS_STATUS_REQAXFR;
998  }
999  if (!xfrd->msg_do_retransfer && serial != xfrd->serial_disk) {
1001  /* bad start serial in IXFR */
1002  return ODS_STATUS_INSERIAL;
1003  }
1005  xfrd->msg_old_serial = serial;
1006  tmp_serial = serial;
1007  } else if (serial == xfrd->msg_new_serial) {
1008  /* saw another SOA of new serial. */
1009  if (xfrd->msg_is_ixfr == 1) {
1010  xfrd->msg_is_ixfr = 2; /* seen middle SOA in ixfr */
1011  } else {
1012  *done = 1; /* final axfr/ixfr soa */
1013  }
1014  } else if (xfrd->msg_is_ixfr) {
1015  /* some additional checks */
1016  if (util_serial_gt(serial, xfrd->msg_new_serial)) {
1017  /* bad middle serial in IXFR (too high) */
1018  return ODS_STATUS_INSERIAL;
1019  }
1020  if (util_serial_gt(tmp_serial, serial)) {
1021  /* middle serial decreases in IXFR */
1022  return ODS_STATUS_INSERIAL;
1023  }
1024  /* serial ok, update tmp serial */
1025  tmp_serial = serial;
1026  }
1027  } else {
1028  buffer_skip(buffer, rrlen);
1029  }
1030  }
1031  return ODS_STATUS_OK;
1032 }
1033 
1034 
1039 static xfrd_pkt_status
1040 xfrd_parse_packet(xfrd_type* xfrd, buffer_type* buffer)
1041 {
1042  zone_type* zone = NULL;
1043  uint16_t qdcount = 0;
1044  uint16_t ancount = 0;
1045  uint16_t ancount_todo = 0;
1046  uint16_t rrcount = 0;
1047  uint32_t serial = 0;
1048  int done = 0;
1049  ods_status status = ODS_STATUS_OK;
1050  ods_log_assert(buffer);
1051  ods_log_assert(xfrd);
1052  ods_log_assert(xfrd->master);
1053  ods_log_assert(xfrd->master->address);
1054  zone = (zone_type*) xfrd->zone;
1055  ods_log_assert(zone);
1056  ods_log_assert(zone->name);
1057  /* check packet size */
1058  if (!buffer_available(buffer, BUFFER_PKT_HEADER_SIZE)) {
1059  ods_log_error("[%s] unable to parse packet: zone %s received bad "
1060  "packet from %s (too small)", xfrd_str, zone->name,
1061  xfrd->master->address);
1062  return XFRD_PKT_BAD;
1063  }
1064  /* check query id */
1065  if (buffer_pkt_id(buffer) != xfrd->query_id) {
1066  ods_log_error("[%s] bad packet: zone %s received bad query id "
1067  "%u from %s (expected %u)", xfrd_str, zone->name,
1068  buffer_pkt_id(buffer), xfrd->master->address, xfrd->query_id);
1069  return XFRD_PKT_BAD;
1070  }
1071  /* check rcode */
1072  if (buffer_pkt_rcode(buffer) != LDNS_RCODE_NOERROR) {
1073  ods_log_error("[%s] bad packet: zone %s received error code %s from %s",
1074  xfrd_str, zone->name, ldns_pkt_rcode2str(buffer_pkt_rcode(buffer)),
1075  xfrd->master->address);
1076  if (buffer_pkt_rcode(buffer) == LDNS_RCODE_NOTIMPL) {
1077  return XFRD_PKT_NOTIMPL;
1078  } else if (buffer_pkt_rcode(buffer) != LDNS_RCODE_NOTAUTH) {
1079  return XFRD_PKT_BAD;
1080  }
1081  }
1082  /* check tsig */
1083  if (!xfrd_tsig_process(xfrd, buffer)) {
1084  ods_log_error("[%s] bad packet: zone %s received bad tsig "
1085  "from %s", xfrd_str, zone->name, xfrd->master->address);
1086  return XFRD_PKT_BAD;
1087  }
1088  /* skip header and question section */
1090  qdcount = buffer_pkt_qdcount(buffer);
1091  for (rrcount = 0; rrcount < qdcount; rrcount++) {
1092  if (!buffer_skip_rr(buffer, 1)) {
1093  ods_log_error("[%s] bad packet: zone %s received bad "
1094  "question section from %s (bad rr)", xfrd_str, zone->name,
1095  xfrd->master->address);
1096  return XFRD_PKT_BAD;
1097  }
1098  }
1099  /* answer section */
1100  ancount = buffer_pkt_ancount(buffer);
1101  if (xfrd->msg_rr_count == 0 && ancount == 0) {
1102  if (xfrd->tcp_conn == -1 && buffer_pkt_tc(buffer)) {
1103  ods_log_info("[%s] zone %s received tc from %s, retry tcp",
1104  xfrd_str, zone->name, xfrd->master->address);
1105  return XFRD_PKT_TC;
1106  }
1107  ods_log_error("[%s] bad packet: zone %s received bad xfr packet "
1108  "from %s (nodata)", xfrd_str, zone->name, xfrd->master->address);
1109  return XFRD_PKT_BAD;
1110  }
1111 
1112  ancount_todo = ancount;
1113  if (xfrd->msg_rr_count == 0) {
1114  /* parse the first RR, see if it is a SOA */
1115  if (!buffer_skip_dname(buffer) ||
1116  !xfrd_parse_soa(xfrd, buffer, 0, 1, 0, &serial)) {
1117  ods_log_error("[%s] bad packet: zone %s received bad xfr "
1118  "packet from %s (bad soa)", xfrd_str, zone->name,
1119  xfrd->master->address);
1120  return XFRD_PKT_BAD;
1121  }
1122  /* check serial */
1123  lock_basic_lock(&xfrd->serial_lock);
1124  if (!xfrd->msg_do_retransfer &&
1125  xfrd->serial_disk_acquired && xfrd->serial_disk == serial) {
1126  ods_log_info("[%s] zone %s got update indicating current "
1127  "serial %u from %s", xfrd_str, zone->name, serial,
1128  xfrd->master->address);
1129  xfrd->serial_disk_acquired = xfrd_time(xfrd);
1130  if (xfrd->serial_xfr == serial) {
1132  if (!xfrd->serial_notify_acquired) {
1133  /* not notified or anything, so stop asking around */
1134  xfrd->round_num = -1; /* next try start a new round */
1135  xfrd_set_timer_refresh(xfrd);
1136  ods_log_debug("[%s] zone %s wait refresh time", xfrd_str,
1137  zone->name);
1139  return XFRD_PKT_NEWLEASE;
1140  }
1141  /* try next master */
1142  ods_log_debug("[%s] zone %s try next master", xfrd_str,
1143  zone->name);
1145  return XFRD_PKT_BAD;
1146  }
1147  }
1148  if (!xfrd->msg_do_retransfer && xfrd->serial_disk_acquired &&
1149  !util_serial_gt(serial, xfrd->serial_disk)) {
1150  ods_log_info("[%s] zone %s ignoring old serial %u from %s "
1151  "(have %u)", xfrd_str, zone->name, serial,
1152  xfrd->master->address, xfrd->serial_disk);
1154  return XFRD_PKT_BAD;
1155  }
1156 
1157  xfrd->msg_new_serial = serial;
1158  if (!xfrd->msg_do_retransfer && xfrd->serial_disk_acquired) {
1159  xfrd->msg_old_serial = xfrd->serial_disk;
1160  } else {
1161  xfrd->msg_old_serial = 0;
1162  }
1163  /* update notify serial if this xfr is newer */
1164  if (ancount > 1 && xfrd->serial_notify_acquired &&
1165  util_serial_gt(serial, xfrd->serial_notify)) {
1166  xfrd->serial_notify = serial;
1167  }
1169  xfrd->msg_rr_count = 1;
1170  xfrd->msg_is_ixfr = 0;
1171  ancount_todo = ancount - 1;
1172  }
1173  /* check tc bit */
1174  if (xfrd->tcp_conn == -1 && buffer_pkt_tc(buffer)) {
1175  ods_log_info("[%s] zone %s received tc from %s, retry tcp",
1176  xfrd_str, zone->name, xfrd->master->address);
1177  return XFRD_PKT_TC;
1178  }
1179  if (xfrd->tcp_conn == -1 && ancount < 2) {
1180  /* too short to be a real ixfr/axfr data transfer */
1181  ods_log_info("[%s] zone %s received too short udp reply from %s, "
1182  "retry tcp", xfrd_str, zone->name, xfrd->master->address);
1183  return XFRD_PKT_TC;
1184  }
1185  status = xfrd_parse_rrs(xfrd, buffer, ancount_todo, &done);
1186  if (status != ODS_STATUS_OK) {
1187  ods_log_error("[%s] bad packet: zone %s received bad xfr packet "
1188  "from %s (%s)", xfrd_str, zone->name, xfrd->master->address,
1189  ods_status2str(status));
1190  return XFRD_PKT_BAD;
1191  }
1192  if (xfrd->tcp_conn == -1 && !done) {
1193  ods_log_error("[%s] bad packet: zone %s received bad xfr packet "
1194  "(xfr over udp incomplete)", xfrd_str, zone->name,
1195  xfrd->master->address);
1196  return XFRD_PKT_BAD;
1197  }
1198  if (!done) {
1199  return XFRD_PKT_MORE;
1200  }
1201  return XFRD_PKT_XFR;
1202 }
1203 
1204 
1209 static xfrd_pkt_status
1210 xfrd_handle_packet(xfrd_type* xfrd, buffer_type* buffer)
1211 {
1213  zone_type* zone = NULL;
1214  ods_log_assert(xfrd);
1215  ods_log_assert(xfrd->master);
1216  ods_log_assert(xfrd->master->address);
1217  zone = (zone_type*) xfrd->zone;
1218  ods_log_assert(zone);
1219  ods_log_assert(zone->name);
1220  res = xfrd_parse_packet(xfrd, buffer);
1221  ods_log_debug("[%s] zone %s xfr packet parsed (res %d)", xfrd_str,
1222  zone->name, res);
1223 
1224  switch (res) {
1225  case XFRD_PKT_MORE:
1226  case XFRD_PKT_XFR:
1227  /* continue with commit */
1228  break;
1229  case XFRD_PKT_NEWLEASE:
1230  case XFRD_PKT_TC:
1231  return res;
1232  break;
1233  case XFRD_PKT_NOTIMPL:
1234  case XFRD_PKT_BAD:
1235  default:
1236  /* rollback */
1237  if (xfrd->msg_seq_nr > 0) {
1238  buffer_clear(buffer);
1239  ods_log_info("[%s] zone %s xfr rollback", xfrd_str,
1240  zone->name);
1241  buffer_flip(buffer);
1242  }
1243  return res;
1244  break;
1245  }
1246  /* dump reply on disk to diff file */
1247  xfrd_dump_packet(xfrd, buffer);
1248  /* more? */
1249  xfrd->msg_seq_nr++;
1250  if (res == XFRD_PKT_MORE) {
1251  /* wait for more */
1252  return XFRD_PKT_MORE;
1253  }
1254  /* done */
1255  buffer_clear(buffer);
1256  buffer_flip(buffer);
1257  /* commit packet */
1258  xfrd_commit_packet(xfrd);
1259  /* next time */
1260  lock_basic_lock(&xfrd->serial_lock);
1261 
1262  ods_log_info("[%s] zone %s transfer done [notify acquired %u, serial on "
1263  "disk %u, notify serial %u]", xfrd_str, zone->name,
1264  xfrd->serial_notify_acquired, xfrd->serial_disk,
1265  xfrd->serial_notify);
1266 
1267  if (xfrd->serial_notify_acquired &&
1268  !util_serial_gt(xfrd->serial_notify, xfrd->serial_disk)) {
1269  ods_log_verbose("[%s] zone %s reset notify acquired", xfrd_str,
1270  zone->name);
1271  xfrd->serial_notify_acquired = 0;
1272  }
1273  if (!xfrd->serial_notify_acquired) {
1274  ods_log_debug("[%s] zone %s xfr done", xfrd_str, zone->name);
1275  xfrd->round_num = -1; /* next try start anew */
1276  xfrd_set_timer_refresh(xfrd);
1278  return XFRD_PKT_XFR;
1279  }
1281  /* try to get an even newer serial */
1282  ods_log_info("[%s] zone %s try get newer serial", xfrd_str, zone->name);
1283  return XFRD_PKT_BAD;
1284 }
1285 
1286 
1294 static void
1295 xfrd_tcp_write(xfrd_type* xfrd, tcp_set_type* set)
1296 {
1297  zone_type* zone = NULL;
1298  tcp_conn_type* tcp = NULL;
1299  int ret = 0;
1300  int error = 0;
1301  socklen_t len = 0;
1302 
1303  ods_log_assert(set);
1304  ods_log_assert(xfrd);
1305  ods_log_assert(xfrd->tcp_conn != -1);
1306  zone = (zone_type*) xfrd->zone;
1307  ods_log_assert(zone);
1308  ods_log_assert(zone->name);
1309  tcp = set->tcp_conn[xfrd->tcp_conn];
1310  if (tcp->total_bytes == 0) {
1311  /* check for pending error from nonblocking connect */
1312  /* from Stevens, unix network programming, vol1, 3rd ed, p450 */
1313  len = sizeof(error);
1314  if (getsockopt(tcp->fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
1315  error = errno; /* on solaris errno is error */
1316  }
1317  if (error == EINPROGRESS || error == EWOULDBLOCK) {
1318  ods_log_debug("[%s] zone %s zero write, write again later (%s)",
1319  xfrd_str, zone->name, strerror(error));
1320  return; /* try again later */
1321  }
1322  if (error != 0) {
1323  ods_log_error("[%s] zone %s cannot tcp connect to %s: %s",
1324  xfrd_str, zone->name, xfrd->master->address, strerror(errno));
1325  xfrd_set_timer_now(xfrd);
1326  xfrd_tcp_release(xfrd, set, 1);
1327  return;
1328  }
1329  }
1330  ret = tcp_conn_write(tcp);
1331  if(ret == -1) {
1332  ods_log_error("[%s] zone %s cannot tcp write to %s: %s",
1333  xfrd_str, zone->name, xfrd->master->address, strerror(errno));
1334  xfrd_set_timer_now(xfrd);
1335  xfrd_tcp_release(xfrd, set, 1);
1336  return;
1337  }
1338  if (ret == 0) {
1339  ods_log_debug("[%s] zone %s zero write, write again later",
1340  xfrd_str, zone->name);
1341  return; /* write again later */
1342  }
1343  /* done writing, get ready for reading */
1344  ods_log_debug("[%s] zone %s done writing, get ready for reading",
1345  xfrd_str, zone->name);
1346  tcp->is_reading = 1;
1347  tcp_conn_ready(tcp);
1349  xfrd_tcp_read(xfrd, set);
1350  return;
1351 }
1352 
1353 
1358 static int
1359 xfrd_tcp_open(xfrd_type* xfrd, tcp_set_type* set)
1360 {
1361  int fd, family, conn;
1362  struct sockaddr_storage to;
1363  socklen_t to_len;
1364  zone_type* zone = NULL;
1365 
1366  ods_log_assert(set);
1367  ods_log_assert(xfrd);
1368  ods_log_assert(xfrd->tcp_conn != -1);
1369  ods_log_assert(xfrd->master);
1370  ods_log_assert(xfrd->master->address);
1371  zone = (zone_type*) xfrd->zone;
1372  ods_log_assert(zone);
1373  ods_log_assert(zone->name);
1374  ods_log_debug("[%s] zone %s open tcp connection to %s", xfrd_str,
1375  zone->name, xfrd->master->address);
1376  set->tcp_conn[xfrd->tcp_conn]->is_reading = 0;
1377  set->tcp_conn[xfrd->tcp_conn]->total_bytes = 0;
1378  set->tcp_conn[xfrd->tcp_conn]->msglen = 0;
1379  if (xfrd->master->family == AF_INET6) {
1380  family = PF_INET6;
1381  } else {
1382  family = PF_INET;
1383  }
1384  fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
1385  set->tcp_conn[xfrd->tcp_conn]->fd = fd;
1386  if (fd == -1) {
1387  ods_log_error("[%s] zone %s cannot create tcp socket to %s: %s",
1388  xfrd_str, zone->name, xfrd->master->address, strerror(errno));
1389  xfrd_set_timer_now(xfrd);
1390  xfrd_tcp_release(xfrd, set, 0);
1391  return 0;
1392  }
1393  if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) {
1394  ods_log_error("[%s] zone %s cannot fcntl tcp socket to %s: %s",
1395  xfrd_str, zone->name, xfrd->master->address, strerror(errno));
1396  xfrd_set_timer_now(xfrd);
1397  xfrd_tcp_release(xfrd, set, 0);
1398  return 0;
1399  }
1400  to_len = xfrd_acl_sockaddr_to(xfrd->master, &to);
1401  /* bind it? */
1402 
1403  conn = connect(fd, (struct sockaddr*)&to, to_len);
1404  if (conn == -1 && errno != EINPROGRESS) {
1405  ods_log_error("[%s] zone %s cannot connect tcp socket to %s: %s",
1406  xfrd_str, zone->name, xfrd->master->address, strerror(errno));
1407  xfrd_set_timer_now(xfrd);
1408  xfrd_tcp_release(xfrd, set, 0);
1409  return 0;
1410  }
1411  xfrd->handler.fd = fd;
1413  xfrd_set_timer(xfrd, xfrd_time(xfrd) + XFRD_TCP_TIMEOUT);
1414  return 1;
1415 }
1416 
1417 
1422 static void
1423 xfrd_tcp_obtain(xfrd_type* xfrd, tcp_set_type* set)
1424 {
1425  xfrhandler_type* xfrhandler;
1426  int i = 0;
1427 
1428  ods_log_assert(set);
1429  ods_log_assert(xfrd);
1430  ods_log_assert(xfrd->tcp_conn == -1);
1431  ods_log_assert(xfrd->tcp_waiting == 0);
1432  if (set->tcp_count < TCPSET_MAX) {
1433  ods_log_assert(!set->tcp_waiting_first);
1434  set->tcp_count ++;
1435  /* find a free tcp_buffer */
1436  for (i=0; i < TCPSET_MAX; i++) {
1437  if (set->tcp_conn[i]->fd == -1) {
1438  xfrd->tcp_conn = i;
1439  break;
1440  }
1441  }
1442  ods_log_assert(xfrd->tcp_conn != -1);
1443  xfrd->tcp_waiting = 0;
1444  /* stop udp use (if any) */
1445  if (xfrd->handler.fd != -1) {
1446  xfrd_udp_release(xfrd);
1447  }
1448  if (!xfrd_tcp_open(xfrd, set)) {
1449  return;
1450  }
1451  xfrd_tcp_xfr(xfrd, set);
1452  return;
1453  }
1454  /* wait, at end of line */
1455  ods_log_verbose("[%s] max number of tcp connections (%d) reached",
1456  xfrd_str, TCPSET_MAX);
1457  xfrd->tcp_waiting = 1;
1458  xfrd_unset_timer(xfrd);
1459 
1460  /* add it to the waiting queue */
1461  xfrhandler = (xfrhandler_type*) xfrd->xfrhandler;
1462  xfrd->tcp_waiting_next = xfrhandler->tcp_waiting_first;
1463  xfrhandler->tcp_waiting_first = xfrd;
1464 }
1465 
1466 
1471 static void
1472 xfrd_tcp_xfr(xfrd_type* xfrd, tcp_set_type* set)
1473 {
1474  tcp_conn_type* tcp = NULL;
1475  zone_type* zone = NULL;
1476 
1477  ods_log_assert(set);
1478  ods_log_assert(xfrd);
1479  zone = (zone_type*) xfrd->zone;
1480  ods_log_assert(zone);
1481  ods_log_assert(zone->name);
1482  ods_log_assert(xfrd->tcp_conn != -1);
1483  ods_log_assert(xfrd->tcp_waiting == 0);
1484  ods_log_assert(xfrd->master);
1485  ods_log_assert(xfrd->master->address);
1486  /* start AXFR or IXFR for the zone */
1487  tcp = set->tcp_conn[xfrd->tcp_conn];
1488 
1489  if (xfrd->msg_do_retransfer || xfrd->serial_xfr_acquired <= 0 ||
1490  xfrd->master->ixfr_disabled) {
1491  ods_log_info("[%s] zone %s request axfr to %s", xfrd_str,
1492  zone->name, xfrd->master->address);
1493  buffer_pkt_query(tcp->packet, zone->apex, LDNS_RR_TYPE_AXFR,
1494  zone->klass);
1495  } else {
1496  ods_log_info("[%s] zone %s request tcp/ixfr=%u to %s", xfrd_str,
1497  zone->name, xfrd->soa.serial, xfrd->master->address);
1498  buffer_pkt_query(tcp->packet, zone->apex, LDNS_RR_TYPE_IXFR,
1499  zone->klass);
1500  buffer_pkt_set_nscount(tcp->packet, 1);
1501  xfrd_write_soa(xfrd, tcp->packet);
1502  }
1503  /* make packet */
1504  xfrd->query_id = buffer_pkt_id(tcp->packet);
1505  xfrd->msg_seq_nr = 0;
1506  xfrd->msg_rr_count = 0;
1507  xfrd->msg_old_serial = 0;
1508  xfrd->msg_new_serial = 0;
1509  xfrd->msg_is_ixfr = 0;
1510  xfrd_tsig_sign(xfrd, tcp->packet);
1511  buffer_flip(tcp->packet);
1512  tcp->msglen = buffer_limit(tcp->packet);
1513  ods_log_verbose("[%s] zone %s sending tcp query id=%d", xfrd_str,
1514  zone->name, xfrd->query_id);
1515  /* wait for select to complete connect before write */
1516  return;
1517 }
1518 
1519 
1524 static void
1525 xfrd_tcp_read(xfrd_type* xfrd, tcp_set_type* set)
1526 {
1527  tcp_conn_type* tcp = NULL;
1528  int ret = 0;
1529 
1530  ods_log_assert(set);
1531  ods_log_assert(xfrd);
1532  ods_log_assert(xfrd->tcp_conn != -1);
1533  tcp = set->tcp_conn[xfrd->tcp_conn];
1534  ret = tcp_conn_read(tcp);
1535  if (ret == -1) {
1536  xfrd_set_timer_now(xfrd);
1537  xfrd_tcp_release(xfrd, set, 1);
1538  return;
1539  }
1540  if (ret == 0) {
1541  return;
1542  }
1543  /* completed msg */
1544  buffer_flip(tcp->packet);
1545  ret = xfrd_handle_packet(xfrd, tcp->packet);
1546  switch (ret) {
1547  case XFRD_PKT_MORE:
1548  tcp_conn_ready(tcp);
1549  break;
1550  case XFRD_PKT_XFR:
1551  case XFRD_PKT_NEWLEASE:
1552  ods_log_verbose("[%s] tcp read %s: release connection", xfrd_str,
1553  XFRD_PKT_XFR?"xfr":"newlease");
1554  xfrd_tcp_release(xfrd, set, 1);
1555  ods_log_assert(xfrd->round_num == -1);
1556  break;
1557  case XFRD_PKT_NOTIMPL:
1558  xfrd->master->ixfr_disabled = time_now();
1559  ods_log_verbose("[%s] disable ixfr requests for %s from now (%u)",
1560  xfrd_str, xfrd->master->address, xfrd->master->ixfr_disabled);
1561  /* break; */
1562  case XFRD_PKT_BAD:
1563  default:
1564  ods_log_debug("[%s] tcp read %s: release connection", xfrd_str,
1565  ret==XFRD_PKT_BAD?"bad":"notimpl");
1566  xfrd_tcp_release(xfrd, set, 1);
1567  xfrd_make_request(xfrd);
1568  break;
1569  }
1570  return;
1571 }
1572 
1573 
1579 static void
1580 xfrd_tcp_release(xfrd_type* xfrd, tcp_set_type* set, int open_waiting)
1581 {
1582  xfrhandler_type* xfrhandler;
1583  int conn = 0;
1584  zone_type* zone = NULL;
1585 
1586  ods_log_assert(set);
1587  ods_log_assert(xfrd);
1588  ods_log_assert(xfrd->master);
1589  ods_log_assert(xfrd->master->address);
1590  ods_log_assert(xfrd->tcp_conn != -1);
1591  ods_log_assert(xfrd->tcp_waiting == 0);
1592  zone = (zone_type*) xfrd->zone;
1593  ods_log_debug("[%s] zone %s release tcp connection to %s", xfrd_str,
1594  zone->name, xfrd->master->address);
1595  conn = xfrd->tcp_conn;
1596  xfrd->tcp_conn = -1;
1597  xfrd->tcp_waiting = 0;
1598  xfrd->handler.fd = -1;
1600 
1601  if (set->tcp_conn[conn]->fd != -1) {
1602  close(set->tcp_conn[conn]->fd);
1603  }
1604  set->tcp_conn[conn]->fd = -1;
1605  set->tcp_count --;
1606 
1607  /* see if there are any connections waiting for a slot. Or return. */
1608  if (!open_waiting) return;
1609  xfrhandler = (xfrhandler_type*) xfrd->xfrhandler;
1610  while (xfrhandler->tcp_waiting_first && set->tcp_count < TCPSET_MAX) {
1611  int i;
1612  xfrd_type* waiting_xfrd = xfrhandler->tcp_waiting_first;
1613  xfrhandler->tcp_waiting_first = waiting_xfrd->tcp_waiting_next;
1614  waiting_xfrd->tcp_waiting_next = NULL;
1615 
1616  /* find a free tcp_buffer */
1617  for (i=0; i < TCPSET_MAX; i++) {
1618  if (set->tcp_conn[i]->fd == -1) {
1619  waiting_xfrd->tcp_conn = i;
1620  set->tcp_count++;
1621  break;
1622  }
1623  }
1624  waiting_xfrd->tcp_waiting = 0;
1625  /* stop udp use (if any) */
1626  if (waiting_xfrd->handler.fd != -1) {
1627  xfrd_udp_release(waiting_xfrd);
1628  }
1629  /* if xfrd_tcp_open() fails its slot in set->tcp_conn[]
1630  * is released. Continue to next. We don't put it back in the
1631  * waiting queue, it would keep the signer busy retrying, making
1632  * things only worse. */
1633  if (xfrd_tcp_open(waiting_xfrd, set)) {
1634  xfrd_tcp_xfr(waiting_xfrd, set);
1635  }
1636  }
1637 }
1638 
1639 
1647 static int
1648 xfrd_udp_send(xfrd_type* xfrd, buffer_type* buffer)
1649 {
1650  struct sockaddr_storage to;
1651  socklen_t to_len = 0;
1652  int fd = -1;
1653  int family = PF_INET;
1654  ssize_t nb = -1;
1655  ods_log_assert(buffer);
1656  ods_log_assert(xfrd);
1657  ods_log_assert(xfrd->master);
1658  ods_log_assert(xfrd->master->address);
1659  /* this will set the remote port to acl->port or TCP_PORT */
1660  to_len = xfrd_acl_sockaddr_to(xfrd->master, &to);
1661  /* get the address family of the remote host */
1662  if (xfrd->master->family == AF_INET6) {
1663  family = PF_INET6;
1664  }
1665  /* create socket */
1666  fd = socket(family, SOCK_DGRAM, IPPROTO_UDP);
1667  if (fd == -1) {
1668  ods_log_error("[%s] unable to send data over udp to %s: "
1669  "socket() failed (%s)", xfrd_str, xfrd->master->address,
1670  strerror(errno));
1671  return -1;
1672  }
1673  /* bind it? */
1674 
1675  /* send it (udp) */
1676  ods_log_deeebug("[%s] send %d bytes over udp to %s", xfrd_str,
1677  buffer_remaining(buffer), xfrd->master->address);
1678  nb = sendto(fd, buffer_current(buffer), buffer_remaining(buffer), 0,
1679  (struct sockaddr*)&to, to_len);
1680  if (nb == -1) {
1681  ods_log_error("[%s] unable to send data over udp to %s: "
1682  "sendto() failed (%s)", xfrd_str, xfrd->master->address,
1683  strerror(errno));
1684  close(fd);
1685  return -1;
1686  }
1687  return fd;
1688 }
1689 
1690 
1695 static int
1696 xfrd_udp_send_request_ixfr(xfrd_type* xfrd)
1697 {
1698  int fd;
1699  xfrhandler_type* xfrhandler = NULL;
1700  zone_type* zone = NULL;
1701  ods_log_assert(xfrd);
1702  ods_log_assert(xfrd->master);
1703  ods_log_assert(xfrd->master->address);
1704  zone = (zone_type*) xfrd->zone;
1705  ods_log_assert(zone);
1706  ods_log_assert(zone->name);
1707  if (xfrd->tcp_conn != -1) {
1708  /* tcp is using the handler.fd */
1709  ods_log_error("[%s] unable to transfer zone %s: tried to send "
1710  "udp while tcp obtained", xfrd_str, zone->name);
1711  return -1;
1712  }
1713  /* make packet */
1714  xfrhandler = (xfrhandler_type*) xfrd->xfrhandler;
1715  ods_log_assert(xfrhandler);
1716  buffer_pkt_query(xfrhandler->packet, zone->apex, LDNS_RR_TYPE_IXFR,
1717  zone->klass);
1718  xfrd->query_id = buffer_pkt_id(xfrhandler->packet);
1719  xfrd->msg_seq_nr = 0;
1720  xfrd->msg_rr_count = 0;
1721  xfrd->msg_old_serial = 0;
1722  xfrd->msg_new_serial = 0;
1723  xfrd->msg_is_ixfr = 0;
1724  buffer_pkt_set_nscount(xfrhandler->packet, 1);
1725  xfrd_write_soa(xfrd, xfrhandler->packet);
1726  xfrd_tsig_sign(xfrd, xfrhandler->packet);
1727  buffer_flip(xfrhandler->packet);
1728  xfrd_set_timer(xfrd, xfrd_time(xfrd) + XFRD_UDP_TIMEOUT);
1729  ods_log_info("[%s] zone %s request udp/ixfr=%u to %s", xfrd_str,
1730  zone->name, xfrd->soa.serial, xfrd->master->address);
1731  if((fd = xfrd_udp_send(xfrd, xfrhandler->packet)) == -1) {
1732  return -1;
1733  }
1734  return fd;
1735 }
1736 
1741 static void
1742 xfrd_udp_obtain(xfrd_type* xfrd)
1743 {
1744  xfrhandler_type* xfrhandler = NULL;
1745  ods_log_assert(xfrd);
1746  ods_log_assert(xfrd->xfrhandler);
1747  ods_log_assert(xfrd->udp_waiting == 0);
1748  xfrhandler = (void*) xfrd->xfrhandler;
1749  if (xfrd->tcp_conn != -1) {
1750  /* no tcp and udp at the same time */
1751  xfrd_tcp_release(xfrd, xfrhandler->tcp_set, 1);
1752  }
1753  if (xfrhandler->udp_use_num < XFRD_MAX_UDP) {
1754  xfrhandler->udp_use_num++;
1755  xfrd->handler.fd = xfrd_udp_send_request_ixfr(xfrd);
1756  if (xfrd->handler.fd == -1) {
1757  xfrhandler->udp_use_num--;
1758  }
1759  return;
1760  }
1761  /* queue the zone as last */
1762  xfrd->udp_waiting = 1;
1763  xfrd->udp_waiting_next = NULL;
1764  if (!xfrhandler->udp_waiting_first) {
1765  xfrhandler->udp_waiting_first = xfrd;
1766  }
1767  if (xfrhandler->udp_waiting_last) {
1768  xfrhandler->udp_waiting_last->udp_waiting_next = xfrd;
1769  }
1770  xfrhandler->udp_waiting_last = xfrd;
1771  xfrd_unset_timer(xfrd);
1772  return;
1773 }
1774 
1775 
1780 static int
1781 xfrd_udp_read_packet(xfrd_type* xfrd)
1782 {
1783  xfrhandler_type* xfrhandler = NULL;
1784  ssize_t received = 0;
1785  ods_log_assert(xfrd);
1786  xfrhandler = (xfrhandler_type*) xfrd->xfrhandler;
1787  ods_log_assert(xfrhandler);
1788  /* read the data */
1789  buffer_clear(xfrhandler->packet);
1790  received = recvfrom(xfrd->handler.fd, buffer_begin(xfrhandler->packet),
1791  buffer_remaining(xfrhandler->packet), 0, NULL, NULL);
1792  if (received == -1) {
1793  ods_log_error("[%s] unable to read packet: recvfrom() failed fd %d "
1794  "(%s)", xfrd_str, xfrd->handler.fd, strerror(errno));
1795  return 0;
1796  }
1797  buffer_set_limit(xfrhandler->packet, received);
1798  return 1;
1799 }
1800 
1801 
1806 static void
1807 xfrd_udp_read(xfrd_type* xfrd)
1808 {
1809  xfrhandler_type* xfrhandler = NULL;
1810  zone_type* zone = NULL;
1812  ods_log_assert(xfrd);
1813  zone = (zone_type*) xfrd->zone;
1814  ods_log_assert(zone);
1815  ods_log_assert(zone->name);
1816  ods_log_debug("[%s] zone %s read data from udp", xfrd_str,
1817  zone->name);
1818  if (!xfrd_udp_read_packet(xfrd)) {
1819  ods_log_error("[%s] unable to read data from udp zone %s: "
1820  "xfrd_udp_read_packet() failed", xfrd_str, zone->name);
1821  xfrd_udp_release(xfrd);
1822  return;
1823  }
1824  xfrhandler = (xfrhandler_type*) xfrd->xfrhandler;
1825  ods_log_assert(xfrhandler);
1826  res = xfrd_handle_packet(xfrd, xfrhandler->packet);
1827  switch (res) {
1828  case XFRD_PKT_TC:
1829  ods_log_verbose("[%s] truncation from %s",
1830  xfrd_str, xfrd->master->address);
1831  xfrd_udp_release(xfrd);
1832  xfrd_set_timer(xfrd, xfrd_time(xfrd) + XFRD_TCP_TIMEOUT);
1833  xfrd_tcp_obtain(xfrd, xfrhandler->tcp_set);
1834  break;
1835  case XFRD_PKT_XFR:
1836  case XFRD_PKT_NEWLEASE:
1837  ods_log_verbose("[%s] xfr/newlease from %s",
1838  xfrd_str, xfrd->master->address);
1839  /* nothing more to do */
1840  ods_log_assert(xfrd->round_num == -1);
1841  xfrd_udp_release(xfrd);
1842  break;
1843  case XFRD_PKT_NOTIMPL:
1844  xfrd->master->ixfr_disabled = time_now();
1845  ods_log_verbose("[%s] disable ixfr requests for %s from now (%u)",
1846  xfrd_str, xfrd->master->address, xfrd->master->ixfr_disabled);
1847  /* break; */
1848  case XFRD_PKT_BAD:
1849  default:
1850  ods_log_debug("[%s] bad ixfr packet from %s",
1851  xfrd_str, xfrd->master->address);
1852  xfrd_udp_release(xfrd);
1853  xfrd_make_request(xfrd);
1854  break;
1855  }
1856  return;
1857 }
1858 
1859 
1864 static void
1865 xfrd_udp_release(xfrd_type* xfrd)
1866 {
1867  xfrhandler_type* xfrhandler = NULL;
1868 
1869  ods_log_assert(xfrd);
1870  ods_log_assert(xfrd->udp_waiting == 0);
1871  if(xfrd->handler.fd != -1)
1872  close(xfrd->handler.fd);
1873  xfrd->handler.fd = -1;
1874  xfrhandler = (xfrhandler_type*) xfrd->xfrhandler;
1875  ods_log_assert(xfrhandler);
1876  /* see if there are waiting zones */
1877  if (xfrhandler->udp_use_num == XFRD_MAX_UDP) {
1878  while (xfrhandler->udp_waiting_first) {
1879  /* snip off waiting list */
1880  xfrd_type* wf = xfrhandler->udp_waiting_first;
1882  wf->udp_waiting = 0;
1883  xfrhandler->udp_waiting_first = wf->udp_waiting_next;
1884  if (xfrhandler->udp_waiting_last == wf) {
1885  xfrhandler->udp_waiting_last = NULL;
1886  }
1887  /* see if this zone needs udp connection */
1888  if (wf->tcp_conn == -1) {
1889  wf->handler.fd = xfrd_udp_send_request_ixfr(wf);
1890  if (wf->handler.fd != -1) {
1891  return;
1892  }
1893  }
1894  }
1895  }
1896  /* no waiting zones */
1897  if (xfrhandler->udp_use_num > 0) {
1898  xfrhandler->udp_use_num --;
1899  }
1900  return;
1901 }
1902 
1903 
1908 static void
1909 xfrd_make_request(xfrd_type* xfrd)
1910 {
1911  zone_type* zone = NULL;
1912  dnsin_type* dnsin = NULL;
1913  if (!xfrd || !xfrd->xfrhandler) {
1914  return;
1915  }
1916  zone = (zone_type*) xfrd->zone;
1917  ods_log_assert(zone);
1918  ods_log_assert(zone->name);
1919  ods_log_assert(zone->adinbound);
1922 
1923  dnsin = (dnsin_type*) zone->adinbound->config;
1924  if (xfrd->next_master != -1) {
1925  /* we are told to use this next master */
1926  xfrd->master_num = xfrd->next_master;
1927  xfrd->master = NULL; /* acl_find_num(...) */
1928  /* if there is no next master, fallback to use the first one */
1929  if (!xfrd->master) {
1930  xfrd->master = dnsin->request_xfr;
1931  xfrd->master_num = 0;
1932  }
1933  /* fallback to cycle master */
1934  xfrd->next_master = -1;
1935  xfrd->round_num = 0; /* fresh set of retries after notify */
1936  } else {
1937  /* cycle master */
1938  if (xfrd->round_num != -1 && xfrd->master &&
1939  xfrd->master->next) {
1940  /* try the next master */
1941  xfrd->master = xfrd->master->next;
1942  xfrd->master_num++;
1943  } else {
1944  /* start a new round */
1945  xfrd->master = dnsin->request_xfr;
1946  xfrd->master_num = 0;
1947  xfrd->round_num++;
1948  }
1949  if (xfrd->round_num >= XFRD_MAX_ROUNDS) {
1950  /* tried all servers that many times, wait */
1951  xfrd->round_num = -1;
1952  xfrd_set_timer_retry(xfrd);
1953  ods_log_verbose("[%s] zone %s make request wait retry",
1954  xfrd_str, zone->name);
1955  return;
1956  }
1957  }
1958  if (!xfrd->master) {
1959  ods_log_debug("[%s] unable to make request for zone %s: no master",
1960  xfrd_str, zone->name);
1961  xfrd->round_num = -1;
1962  xfrd_set_timer_retry(xfrd);
1963  return;
1964  }
1965  /* cache ixfr_disabled only for XFRD_NO_IXFR_CACHE time */
1966  if (xfrd->master->ixfr_disabled &&
1968  xfrd_time(xfrd)) {
1969  ods_log_verbose("[%s] clear negative caching ixfr disabled for "
1970  "master %s", xfrd_str, xfrd->master->address);
1971  ods_log_debug("[%s] clear negative caching calc: %u + %u <= %u",
1972  xfrd_str, xfrd->master->ixfr_disabled, XFRD_NO_IXFR_CACHE,
1973  xfrd_time(xfrd));
1974  xfrd->master->ixfr_disabled = 0;
1975  }
1976  /* perform xfr request */
1977  if (xfrd->serial_xfr_acquired && !xfrd->master->ixfr_disabled &&
1978  !xfrd->serial_retransfer) {
1979  xfrd_set_timer(xfrd, xfrd_time(xfrd) + XFRD_UDP_TIMEOUT);
1980 
1981  ods_log_verbose("[%s] zone %s make request [udp round %d master %s:%u]",
1982  xfrd_str, zone->name, xfrd->round_num, xfrd->master->address,
1983  xfrd->master->port);
1984  xfrd_udp_obtain(xfrd);
1985  } else if (!xfrd->serial_xfr_acquired || xfrd->master->ixfr_disabled ||
1986  xfrd->serial_retransfer) {
1987  xfrhandler_type* xfrhandler = (xfrhandler_type*) xfrd->xfrhandler;
1988  ods_log_assert(xfrhandler);
1989  if (xfrd->serial_retransfer) {
1990  xfrd->msg_do_retransfer = 1;
1991  xfrd->serial_retransfer = 0;
1992  }
1993  xfrd_set_timer(xfrd, xfrd_time(xfrd) + XFRD_TCP_TIMEOUT);
1994 
1995  ods_log_verbose("[%s] zone %s make request [tcp round %d master %s:%u]",
1996  xfrd_str, zone->name, xfrd->round_num, xfrd->master->address,
1997  xfrd->master->port);
1998  xfrd_tcp_obtain(xfrd, xfrhandler->tcp_set);
1999  }
2000  return;
2001 }
2002 
2003 
2008 static void
2009 xfrd_handle_zone(netio_type* ATTR_UNUSED(netio),
2010  netio_handler_type* handler, netio_events_type event_types)
2011 {
2012  xfrd_type* xfrd = NULL;
2013  zone_type* zone = NULL;
2014 
2015  if (!handler) {
2016  return;
2017  }
2018  xfrd = (xfrd_type*) handler->user_data;
2019  ods_log_assert(xfrd);
2020  zone = (zone_type*) xfrd->zone;
2021  ods_log_assert(zone);
2022  ods_log_assert(zone->name);
2023 
2024  if (xfrd->tcp_conn != -1) {
2025  /* busy in tcp transaction */
2026  xfrhandler_type* xfrhandler = (xfrhandler_type*) xfrd->xfrhandler;
2027  ods_log_assert(xfrhandler);
2028  if (event_types & NETIO_EVENT_READ) {
2029  ods_log_deeebug("[%s] zone %s event tcp read", xfrd_str, zone->name);
2030  xfrd_set_timer(xfrd, xfrd_time(xfrd) + XFRD_TCP_TIMEOUT);
2031  xfrd_tcp_read(xfrd, xfrhandler->tcp_set);
2032  return;
2033  } else if (event_types & NETIO_EVENT_WRITE) {
2034  ods_log_deeebug("[%s] zone %s event tcp write", xfrd_str,
2035  zone->name);
2036  xfrd_set_timer(xfrd, xfrd_time(xfrd) + XFRD_TCP_TIMEOUT);
2037  xfrd_tcp_write(xfrd, xfrhandler->tcp_set);
2038  return;
2039  } else if (event_types & NETIO_EVENT_TIMEOUT) {
2040  /* tcp connection timed out. Stop it. */
2041  ods_log_deeebug("[%s] zone %s event tcp timeout", xfrd_str,
2042  zone->name);
2043  xfrd_tcp_release(xfrd, xfrhandler->tcp_set, 1);
2044  /* continue to retry; as if a timeout happened */
2045  event_types = NETIO_EVENT_TIMEOUT;
2046  }
2047  }
2048 
2049  if (event_types & NETIO_EVENT_READ) {
2050  /* busy in udp transaction */
2051  ods_log_deeebug("[%s] zone %s event udp read", xfrd_str,
2052  zone->name);
2053  xfrd_set_timer_now(xfrd);
2054  xfrd_udp_read(xfrd);
2055  return;
2056  }
2057 
2058  /* timeout */
2059  ods_log_deeebug("[%s] zone %s timeout", xfrd_str, zone->name);
2060  if (handler->fd != -1) {
2061  ods_log_assert(xfrd->tcp_conn == -1);
2062  xfrd_udp_release(xfrd);
2063  }
2064  if (xfrd->tcp_waiting) {
2065  ods_log_deeebug("[%s] zone %s skips retry: tcp connections full",
2066  xfrd_str, zone->name);
2067  xfrd_unset_timer(xfrd);
2068  return;
2069  }
2070  if (xfrd->udp_waiting) {
2071  ods_log_deeebug("[%s] zone %s skips retry: udp connections full",
2072  xfrd_str, zone->name);
2073  xfrd_unset_timer(xfrd);
2074  return;
2075  }
2076  /* make a new request */
2077  xfrd_make_request(xfrd);
2078  return;
2079 }
2080 
2081 
2086 static void
2087 xfrd_backup_dname(FILE* out, uint8_t* dname)
2088 {
2089  uint8_t* d= dname+1;
2090  uint8_t len = *d++;
2091  uint8_t i;
2092  if (dname[0]<=1) {
2093  fprintf(out, ".");
2094  return;
2095  }
2096  while (len) {
2097  ods_log_assert(d - (dname+1) <= dname[0]);
2098  for (i=0; i<len; i++) {
2099  uint8_t ch = *d++;
2100  if (isalnum(ch) || ch == '-' || ch == '_') {
2101  fprintf(out, "%c", ch);
2102  } else if (ch == '.' || ch == '\\') {
2103  fprintf(out, "\\%c", ch);
2104  } else {
2105  fprintf(out, "\\%03u", (unsigned int)ch);
2106  }
2107  }
2108  fprintf(out, ".");
2109  len = *d++;
2110  }
2111  return;
2112 }
2113 
2114 
2119 static void
2120 xfrd_backup(xfrd_type* xfrd)
2121 {
2122  zone_type* zone = (zone_type*) xfrd->zone;
2123  char* file = NULL;
2124  int timeout = 0;
2125  FILE* fd = NULL;
2126  if (zone && zone->name) {
2127  file = ods_build_path(zone->name, ".xfrd-state", 0, 1);
2128  if (file) {
2129  fd = ods_fopen(file, NULL, "w");
2130  if (fd) {
2131  if (xfrd->handler.timeout) {
2132  timeout = xfrd->timeout.tv_sec;
2133  }
2134  fprintf(fd, "%s\n", ODS_SE_FILE_MAGIC_V3);
2135  fprintf(fd, ";;Zone: name %s ttl %u mname ",
2136  zone->name,
2137  (unsigned) xfrd->soa.ttl);
2138  xfrd_backup_dname(fd, xfrd->soa.mname),
2139  fprintf(fd, " rname ");
2140  xfrd_backup_dname(fd, xfrd->soa.rname),
2141  fprintf(fd, " serial %u refresh %u retry %u expire %u "
2142  "minimum %u\n",
2143  (unsigned) xfrd->soa.serial,
2144  (unsigned) xfrd->soa.refresh,
2145  (unsigned) xfrd->soa.retry,
2146  (unsigned) xfrd->soa.expire,
2147  (unsigned) xfrd->soa.minimum);
2148  fprintf(fd, ";;Master: num %d next %d round %d timeout %d\n",
2149  xfrd->master_num,
2150  xfrd->next_master,
2151  xfrd->round_num,
2152  timeout);
2153  fprintf(fd, ";;Serial: xfr %u %u notify %u %u disk %u %u\n",
2154  (unsigned) xfrd->serial_xfr,
2155  (unsigned) xfrd->serial_xfr_acquired,
2156  (unsigned) xfrd->serial_notify,
2157  (unsigned) xfrd->serial_notify_acquired,
2158  (unsigned) xfrd->serial_disk,
2159  (unsigned) xfrd->serial_disk_acquired);
2160  fprintf(fd, "%s\n", ODS_SE_FILE_MAGIC_V3);
2161  ods_fclose(fd);
2162  }
2163  free(file);
2164  }
2165  }
2166  return;
2167 }
2168 
2169 
2174 static void
2175 xfrd_unlink(xfrd_type* xfrd)
2176 {
2177  zone_type* zone = (zone_type*) xfrd->zone;
2178  char* file = NULL;
2179  if (zone && zone->name) {
2180  ods_log_info("[%s] unlink zone %s xfrd state", xfrd_str, zone->name);
2181  file = ods_build_path(zone->name, ".xfrd-state", 0, 1);
2182  if (file) {
2183  (void)unlink(file);
2184  free(file);
2185  }
2186  }
2187  return;
2188 }
2189 
2190 
2195 void
2196 xfrd_cleanup(xfrd_type* xfrd, int backup)
2197 {
2198  allocator_type* allocator = NULL;
2199  lock_basic_type serial_lock;
2200  lock_basic_type rw_lock;
2201  if (!xfrd) {
2202  return;
2203  }
2204  /* backup */
2205  if (backup) {
2206  xfrd_backup(xfrd);
2207  } else {
2208  xfrd_unlink(xfrd);
2209  }
2210 
2211  allocator = xfrd->allocator;
2212  serial_lock = xfrd->serial_lock;
2213  rw_lock = xfrd->rw_lock;
2214  tsig_rr_cleanup(xfrd->tsig_rr);
2215  allocator_deallocate(allocator, (void*) xfrd);
2216  allocator_cleanup(allocator);
2217  lock_basic_destroy(&serial_lock);
2218  lock_basic_destroy(&rw_lock);
2219  return;
2220 }
#define XFRD_TSIG_MAX_UNSIGNED
Definition: xfrd.c:49
int backup_read_str(FILE *in, const char **str)
Definition: backup.c:97
tsig_algo_type * algo
Definition: tsig.h:131
int next_master
Definition: xfrd.h:103
void tsig_rr_update(tsig_rr_type *trr, buffer_type *buffer, size_t length)
Definition: tsig.c:605
#define PF_INET6
Definition: netio.h:61
tsig_status status
Definition: tsig.h:126
void engine_wakeup_workers(engine_type *engine)
Definition: engine.c:444
#define XFRD_MAX_ROUNDS
Definition: xfrd.h:47
xfrd_type * udp_waiting_first
Definition: xfrhandler.h:62
xfrd_type * udp_waiting_last
Definition: xfrhandler.h:63
#define DNS_PORT_STRING
Definition: listener.h:51
void * config
Definition: adapter.h:61
#define XFRD_UDP_TIMEOUT
Definition: xfrd.h:51
void ods_log_debug(const char *format,...)
Definition: log.c:270
xfrd_type * tcp_waiting_next
Definition: xfrd.h:135
void xfrd_set_timer_refresh(xfrd_type *xfrd)
Definition: xfrd.c:510
#define lock_basic_destroy(lock)
Definition: locks.h:93
uint16_t buffer_pkt_arcount(buffer_type *buffer)
Definition: buffer.c:1136
xfrd_type * tcp_waiting_first
Definition: xfrhandler.h:61
#define XFRD_TCP_TIMEOUT
Definition: xfrd.h:50
#define BUFFER_PKT_HEADER_SIZE
Definition: buffer.h:43
void * allocator_alloc(allocator_type *allocator, size_t size)
Definition: allocator.c:66
uint16_t error_code
Definition: tsig.h:144
const char * tsig_strerror(uint16_t error)
Definition: tsig.c:829
time_t serial_xfr_acquired
Definition: xfrd.h:113
uint32_t serial_notify
Definition: xfrd.h:110
uint16_t buffer_pkt_qdcount(buffer_type *buffer)
Definition: buffer.c:1061
buffer_type * packet
Definition: xfrhandler.h:60
void buffer_skip(buffer_type *buffer, ssize_t count)
Definition: buffer.c:186
size_t msg_rr_count
Definition: xfrd.h:130
uint16_t buffer_read_u16(buffer_type *buffer)
Definition: buffer.c:781
int buffer_skip_rr(buffer_type *buffer, unsigned qrr)
Definition: buffer.c:380
unsigned have_serial
Definition: namedb.h:59
void buffer_flip(buffer_type *buffer)
Definition: buffer.c:133
#define XFRD_NO_IXFR_CACHE
Definition: xfrd.h:49
void buffer_clear(buffer_type *buffer)
Definition: buffer.c:119
int round_num
Definition: xfrd.h:101
void ods_log_info(const char *format,...)
Definition: log.c:302
time_t serial_notify_acquired
Definition: xfrd.h:116
int backup_read_time_t(FILE *in, time_t *v)
Definition: backup.c:114
allocator_type * allocator
Definition: xfrd.h:93
void * zone
Definition: xfrd.h:95
uint8_t mname[MAXDOMAINLEN+2]
Definition: xfrd.h:77
enum ods_enum_status ods_status
Definition: status.h:90
enum netio_events_enum netio_events_type
Definition: netio.h:76
lock_basic_type zone_lock
Definition: zone.h:95
socklen_t xfrd_acl_sockaddr_to(acl_type *acl, struct sockaddr_storage *to)
Definition: xfrd.c:558
time_t ixfr_disabled
Definition: acl.h:71
tsig_algo_type * tsig_lookup_algo(const char *name)
Definition: tsig.c:289
void ods_log_error(const char *format,...)
Definition: log.c:334
acl_type * next
Definition: acl.h:59
const char * ods_status2str(ods_status status)
Definition: status.c:111
adapter_mode type
Definition: adapter.h:58
int tcp_conn_write(tcp_conn_type *tcp)
Definition: tcpset.c:185
int family
Definition: acl.h:63
union acl_addr_storage addr
Definition: acl.h:64
ldns_rdf * wf_name
Definition: tsig.h:92
int backup_read_int(FILE *in, int *v)
Definition: backup.c:165
buffer_type * packet
Definition: tcpset.h:56
void tsig_rr_reset(tsig_rr_type *trr, tsig_algo_type *algo, tsig_key_type *key)
Definition: tsig.c:333
void tsig_rr_append(tsig_rr_type *trr, buffer_type *buffer)
Definition: tsig.c:721
#define MAXLABELLEN
Definition: buffer.h:45
uint32_t msg_seq_nr
Definition: xfrd.h:127
uint32_t retry
Definition: xfrd.h:81
size_t update_since_last_prepare
Definition: tsig.h:129
void buffer_write(buffer_type *buffer, const void *data, size_t count)
Definition: buffer.c:592
uint16_t buffer_pkt_id(buffer_type *buffer)
Definition: buffer.c:811
lock_basic_type serial_lock
Definition: xfrd.h:96
uint8_t * buffer_current(buffer_type *buffer)
Definition: buffer.c:489
#define XFRD_MAX_UDP
Definition: xfrd.h:48
uint32_t ttl
Definition: xfrd.h:75
FILE * ods_fopen(const char *file, const char *dir, const char *mode)
Definition: file.c:190
const char * algorithm
Definition: tsig.h:114
void * user_data
Definition: netio.h:119
unsigned tcp_waiting
Definition: xfrd.h:137
int util_serial_gt(uint32_t serial_new, uint32_t serial_old)
Definition: util.c:72
uint16_t buffer_pkt_ancount(buffer_type *buffer)
Definition: buffer.c:1086
size_t buffer_limit(buffer_type *buffer)
Definition: buffer.c:411
xfrd_type * udp_waiting_next
Definition: xfrd.h:136
void tsig_rr_prepare(tsig_rr_type *trr)
Definition: tsig.c:580
tsig_key_type * key
Definition: tsig.h:116
void ods_log_crit(const char *format,...)
Definition: log.c:350
time_t xfrhandler_time(xfrhandler_type *xfrhandler)
Definition: xfrhandler.c:157
uint32_t refresh
Definition: xfrd.h:80
#define lock_basic_lock(lock)
Definition: locks.h:94
namedb_type * db
Definition: zone.h:86
size_t udp_use_num
Definition: xfrhandler.h:64
void buffer_pkt_set_nscount(buffer_type *buffer, uint16_t count)
Definition: buffer.c:1123
ldns_rdf * key_name
Definition: tsig.h:136
void buffer_set_limit(buffer_type *buffer, size_t limit)
Definition: buffer.c:423
allocator_type * allocator_create(void *(*allocator)(size_t size), void(*deallocator)(void *))
Definition: allocator.c:47
Definition: task.h:43
uint32_t msg_new_serial
Definition: xfrd.h:129
unsigned is_initialized
Definition: namedb.h:55
acl_type * master
Definition: xfrd.h:104
int lock_basic_type
Definition: locks.h:91
netio_event_handler_type event_handler
Definition: netio.h:131
tcp_set_type * tcp_set
Definition: xfrhandler.h:59
Definition: tsig.h:58
void tsig_rr_cleanup(tsig_rr_type *trr)
Definition: tsig.c:884
adapter_type * adinbound
Definition: zone.h:81
void xfrd_set_timer_retry(xfrd_type *xfrd)
Definition: xfrd.c:491
int buffer_skip_dname(buffer_type *buffer)
Definition: buffer.c:348
void log_dname(ldns_rdf *rdf, const char *pre, int level)
Definition: domain.c:48
int tcp_conn
Definition: xfrd.h:100
uint16_t msglen
Definition: tcpset.h:54
uint32_t buffer_read_u32(buffer_type *buffer)
Definition: buffer.c:796
void xfrd_cleanup(xfrd_type *xfrd, int backup)
Definition: xfrd.c:2196
uint32_t minimum
Definition: xfrd.h:83
tsig_rr_type * tsig_rr
Definition: xfrd.h:133
tsig_key_type * key
Definition: tsig.h:132
void buffer_pkt_query(buffer_type *buffer, ldns_rdf *qname, ldns_rr_type qtype, ldns_rr_class qclass)
Definition: buffer.c:1192
int tsig_rr_verify(tsig_rr_type *trr)
Definition: tsig.c:699
void buffer_write_u16(buffer_type *buffer, uint16_t data)
Definition: buffer.c:621
size_t buffer_read_dname(buffer_type *buffer, uint8_t *dname, unsigned allow_pointers)
Definition: buffer.c:284
ldns_rdf * dname
Definition: tsig.h:80
acl_type * request_xfr
Definition: addns.h:52
char * address
Definition: acl.h:61
void buffer_write_u32(buffer_type *buffer, uint32_t data)
Definition: buffer.c:635
ods_status zone_reschedule_task(zone_type *zone, schedule_type *taskq, task_id what)
Definition: zone.c:187
tsig_rr_type * tsig_rr_create(allocator_type *allocator)
Definition: tsig.c:306
uint32_t expire
Definition: xfrd.h:82
char * ods_build_path(const char *file, const char *suffix, int dir, int no_slash)
Definition: file.c:125
uint8_t rname[MAXDOMAINLEN+2]
Definition: xfrd.h:78
uint32_t total_bytes
Definition: tcpset.h:52
uint32_t msg_old_serial
Definition: xfrd.h:128
struct timespec timeout
Definition: xfrd.h:122
unsigned is_reading
Definition: tcpset.h:58
int tcp_conn_read(tcp_conn_type *tcp)
Definition: tcpset.c:111
void ods_log_verbose(const char *format,...)
Definition: log.c:286
ldns_rr_class klass
Definition: zone.h:69
size_t position
Definition: tsig.h:127
void buffer_write_u16_at(buffer_type *buffer, size_t at, uint16_t data)
Definition: buffer.c:564
void buffer_set_position(buffer_type *buffer, size_t pos)
Definition: buffer.c:172
#define lock_basic_init(lock)
Definition: locks.h:92
int tsig_rr_find(tsig_rr_type *trr, buffer_type *buffer)
Definition: tsig.c:478
void ods_fclose(FILE *fd)
Definition: file.c:250
void xfrd_set_timer_now(xfrd_type *xfrd)
Definition: xfrd.c:472
netio_events_type event_types
Definition: netio.h:124
uint8_t msg_is_ixfr
Definition: xfrd.h:131
int buffer_available(buffer_type *buffer, size_t count)
Definition: buffer.c:538
#define MAXDOMAINLEN
Definition: buffer.h:44
void allocator_cleanup(allocator_type *allocator)
Definition: allocator.c:151
const char * name
Definition: zone.h:76
#define PF_INET
Definition: netio.h:58
uint8_t serial_retransfer
Definition: xfrd.h:118
int backup_read_check_str(FILE *in, const char *str)
Definition: backup.c:77
size_t buffer_remaining(buffer_type *buffer)
Definition: buffer.c:514
void ods_log_deeebug(const char *format,...)
Definition: log.c:254
uint32_t serial_xfr
Definition: xfrd.h:107
uint16_t query_id
Definition: xfrd.h:126
void * xfrhandler
Definition: xfrd.h:94
void buffer_write_rdf(buffer_type *buffer, ldns_rdf *rdf)
Definition: buffer.c:649
int master_num
Definition: xfrd.h:102
void tsig_rr_sign(tsig_rr_type *trr)
Definition: tsig.c:677
void allocator_deallocate(allocator_type *allocator, void *data)
Definition: allocator.c:135
#define TCPSET_MAX
Definition: tcpset.h:42
lock_basic_type rw_lock
Definition: xfrd.h:97
#define LOG_DEBUG
Definition: log.h:51
unsigned int port
Definition: acl.h:62
void tcp_conn_ready(tcp_conn_type *tcp)
Definition: tcpset.c:96
unsigned udp_waiting
Definition: xfrd.h:138
size_t buffer_position(buffer_type *buffer)
Definition: buffer.c:160
ldns_rdf * algo_name
Definition: tsig.h:137
uint32_t serial
Definition: xfrd.h:79
void buffer_pkt_set_arcount(buffer_type *buffer, uint16_t count)
Definition: buffer.c:1148
struct in_addr addr
Definition: listener.h:60
struct timespec * timeout
Definition: netio.h:115
#define ods_log_assert(x)
Definition: log.h:154
netio_handler_type handler
Definition: xfrd.h:123
soa_type soa
Definition: xfrd.h:119
xfrd_type * xfrd_create(void *xfrhandler, void *zone)
Definition: xfrd.c:316
#define lock_basic_unlock(lock)
Definition: locks.h:95
uint16_t original_query_id
Definition: tsig.h:143
tsig_type * tsig
Definition: acl.h:69
enum xfrd_pkt_enum xfrd_pkt_status
Definition: xfrd.h:65
ldns_rdf * apex
Definition: zone.h:68
time_t serial_disk_acquired
Definition: xfrd.h:117
struct in6_addr addr6
Definition: listener.h:61
uint8_t * buffer_begin(buffer_type *buffer)
Definition: buffer.c:465
time_t time_now(void)
Definition: duration.c:513
uint32_t serial_disk
Definition: xfrd.h:112
ldns_pkt_rcode buffer_pkt_rcode(buffer_type *buffer)
Definition: buffer.c:1020
int backup_read_uint32_t(FILE *in, uint32_t *v)
Definition: backup.c:233
int buffer_pkt_tc(buffer_type *buffer)
Definition: buffer.c:960
uint8_t msg_do_retransfer
Definition: xfrd.h:132
Definition: acl.h:58