49 #define XFRD_TSIG_MAX_UNSIGNED 100 51 static const char* xfrd_str =
"xfrd";
53 static void xfrd_handle_zone(
netio_type* netio,
55 static void xfrd_make_request(
xfrd_type* xfrd);
57 static socklen_t xfrd_acl_sockaddr(
acl_type* acl,
unsigned int port,
58 struct sockaddr_storage *sck);
62 unsigned rdata_only,
unsigned update, uint32_t t,
65 uint16_t count,
int* done);
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);
83 static int xfrd_udp_send_request_ixfr(
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);
96 xfrd_recover_dname(uint8_t* dname,
const char* name)
98 const uint8_t *s = (
const uint8_t *) name;
104 if (strcmp(name,
".") == 0) {
109 for (h = d, p = h + 1; *s; ++s, ++p) {
119 label_length = p - h - 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) {
139 }
else if (s[1] !=
'\0') {
150 label_length = p - h - 1;
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;
192 if (zone && zone->
name && zone->
db &&
194 file = ods_build_path(zone->
name,
".xfrd-state", 0, 1);
196 ods_log_verbose(
"[%s] recover xfrd.state file %s zone %s", xfrd_str,
198 fd = ods_fopen(file, NULL,
"r");
201 ods_log_error(
"[%s] corrupted state file zone %s: read " 202 "magic (start) error", xfrd_str, zone->
name);
203 goto xfrd_recover_error;
224 ods_log_error(
"[%s] corrupted state file zone %s: read " 225 ";;Zone error", xfrd_str, zone->
name);
226 goto xfrd_recover_error;
237 ods_log_error(
"[%s] corrupt state file zone %s: read " 238 ";;Master error", xfrd_str, zone->
name);
239 goto xfrd_recover_error;
251 ods_log_error(
"[%s] corrupt state file zone %s: read " 252 ";;Serial error", xfrd_str, zone->
name);
253 goto xfrd_recover_error;
256 ods_log_error(
"[%s] corrupt state file zone %s: read " 257 "magic (end) error", xfrd_str, zone->
name);
258 goto xfrd_recover_error;
265 xfrd->
timeout.tv_sec = timeout;
284 if (!timeout || serial_notify_acquired ||
285 (serial_disk_acquired &&
286 (uint32_t)xfrd_time(xfrd) - serial_disk_acquired >
290 if (serial_disk_acquired &&
291 ((uint32_t)xfrd_time(xfrd) - serial_disk_acquired >
297 free((
void*)soa_mname);
298 free((
void*)soa_rname);
304 ods_log_verbose(
"[%s] did not recover xfrd.state file zone %s", xfrd_str,
305 (zone && zone->
name)?zone->
name:
"(null)");
318 if (!xfrhandler || !zone) {
323 lock_basic_init(&xfrd->
rw_lock);
357 memset(&xfrd->
soa, 0,
sizeof(xfrd->
soa));
372 xfrd_set_timer_time(xfrd, 0);
385 ods_log_assert(xfrd);
396 xfrd_set_timer(
xfrd_type* xfrd, time_t t)
405 if(t > xfrd_time(xfrd) + 10) {
406 time_t extra = t - xfrd_time(xfrd);
407 time_t base = extra*9/10;
408 #ifdef HAVE_ARC4RANDOM_UNIFORM 409 t = xfrd_time(xfrd) + base +
410 arc4random_uniform(extra-base);
411 #elif HAVE_ARC4RANDOM 412 t = xfrd_time(xfrd) + base +
413 arc4random()%(extra-base);
415 t = xfrd_time(xfrd) + base +
416 random()%(extra-base);
432 ods_log_assert(xfrd);
442 xfrd_set_timer_time(
xfrd_type* xfrd, time_t t)
444 ods_log_assert(xfrd);
445 xfrd_set_timer(xfrd, xfrd_time(xfrd) + t);
461 ods_log_debug(
"[%s] zone %s sets timer timeout now", xfrd_str,
463 xfrd_set_timer_time(xfrd, 0);
479 ods_log_debug(
"[%s] zone %s sets timer timeout retry %u", xfrd_str,
481 xfrd_set_timer_time(xfrd, xfrd->
soa.
retry);
497 ods_log_debug(
"[%s] zone %s sets timer timeout refresh %u", xfrd_str,
508 xfrd_acl_sockaddr(
acl_type* acl,
unsigned int port,
509 struct sockaddr_storage *sck)
513 ods_log_assert(port);
514 memset(sck, 0,
sizeof(
struct sockaddr_storage));
515 if (acl->
family == AF_INET6) {
516 struct sockaddr_in6* sa = (
struct sockaddr_in6*)sck;
517 sa->sin6_family = AF_INET6;
518 sa->sin6_port = htons(port);
520 return sizeof(
struct sockaddr_in6);
522 struct sockaddr_in* sa = (
struct sockaddr_in*)sck;
523 sa->sin_family = AF_INET;
524 sa->sin_port = htons(port);
526 return sizeof(
struct sockaddr_in);
539 unsigned int port = 0;
544 return xfrd_acl_sockaddr(acl, port, to);
562 ods_log_error(
"[%s] unable to sign request: tsig unknown algorithm " 566 ods_log_assert(algo);
577 ods_log_debug(
"[%s] tsig append rr to request id=%u", xfrd_str,
599 ods_log_assert(zone);
600 ods_log_assert(zone->
name);
603 ods_log_error(
"[%s] unable to process tsig: xfr zone %s from %s " 604 "has malformed tsig rr", xfrd_str, zone->
name,
611 ods_log_error(
"[%s] zone %s, from %s has tsig error (%s)",
623 ods_log_error(
"[%s] unable to process tsig: xfr zone %s from %s " 624 "has bad tsig signature", xfrd_str, zone->
name,
633 ods_log_error(
"[%s] unable to process tsig: xfr zone %s, from %s " 634 "has too many consecutive packets without tsig", xfrd_str,
639 ods_log_error(
"[%s] unable to process tsig: xfr zone %s from %s " 640 "has no tsig in first packet of reply", xfrd_str,
657 char* xfrfile = NULL;
659 time_t serial_disk_acq = 0;
660 ods_log_assert(xfrd);
662 xfrfile = ods_build_path(zone->
name,
".xfrd", 0, 1);
664 ods_log_crit(
"[%s] unable to commit xfr zone %s: build path failed",
665 xfrd_str, zone->
name);
668 ods_log_assert(zone);
669 ods_log_assert(zone->
name);
671 lock_basic_lock(&xfrd->
rw_lock);
674 fd = ods_fopen(xfrfile, NULL,
"a");
675 free((
void*)xfrfile);
677 fprintf(fd,
";;ENDPACKET\n");
680 lock_basic_unlock(&xfrd->
rw_lock);
683 ods_log_crit(
"[%s] unable to commit xfr zone %s: ods_fopen() failed " 684 "(%s)", xfrd_str, zone->
name, strerror(errno));
703 ods_log_assert(xfrhandler);
704 ods_log_assert(engine);
705 ods_log_debug(
"[%s] reschedule task for zone %s: disk serial=%u " 706 "acquired=%lu, memory serial=%u acquired=%lu", xfrd_str,
711 if (ret != ODS_STATUS_OK) {
712 ods_log_crit(
"[%s] unable to reschedule task for zone %s: %s",
713 xfrd_str, zone->
name, ods_status2str(ret));
722 lock_basic_unlock(&xfrd->
rw_lock);
735 char* xfrfile = NULL;
737 ldns_pkt* pkt = NULL;
738 ldns_status status = LDNS_STATUS_OK;
739 ods_log_assert(buffer);
740 ods_log_assert(xfrd);
742 ods_log_assert(zone);
743 ods_log_assert(zone->
name);
745 if (status != LDNS_STATUS_OK) {
746 ods_log_crit(
"[%s] unable to dump packet zone %s: ldns_wire2pkt() " 747 "failed (%s)", xfrd_str, zone->
name,
748 ldns_get_errorstr_by_id(status));
752 xfrfile = ods_build_path(zone->
name,
".xfrd", 0, 1);
754 ods_log_crit(
"[%s] unable to dump packet zone %s: build path failed",
755 xfrd_str, zone->
name);
758 lock_basic_lock(&xfrd->
rw_lock);
760 fd = ods_fopen(xfrfile, NULL,
"w");
762 fd = ods_fopen(xfrfile, NULL,
"a");
764 free((
void*) xfrfile);
766 ods_log_crit(
"[%s] unable to dump packet zone %s: ods_fopen() failed " 767 "(%s)", xfrd_str, zone->
name, strerror(errno));
768 lock_basic_unlock(&xfrd->
rw_lock);
773 fprintf(fd,
";;BEGINPACKET\n");
775 ldns_rr_list_print(fd, ldns_pkt_answer(pkt));
777 lock_basic_unlock(&xfrd->
rw_lock);
790 size_t rdlength_pos = 0;
791 uint16_t rdlength = 0;
792 ods_log_assert(xfrd);
793 ods_log_assert(buffer);
795 ods_log_assert(zone);
796 ods_log_assert(zone->
apex);
821 uint16_t mname_pos, uint16_t rname_pos,
822 uint32_t refresh, uint32_t retry, uint32_t expire, uint32_t minimum)
825 ods_log_assert(xfrd);
826 ods_log_assert(buffer);
828 ods_log_assert(zone);
829 ods_log_assert(zone->
apex);
856 unsigned update, uint32_t t, uint32_t* soa_serial)
858 ldns_rr_type type = LDNS_RR_TYPE_SOA;
859 uint16_t mname_pos = 0;
860 uint16_t rname_pos = 0;
863 uint32_t refresh = 0;
866 uint32_t minimum = 0;
868 ods_log_assert(xfrd);
869 ods_log_assert(buffer);
874 ods_log_debug(
"[%s] unable to parse soa: rr too short",
879 if (type != LDNS_RR_TYPE_SOA) {
880 ods_log_debug(
"[%s] unable to parse soa: rrtype %u != soa",
881 xfrd_str, (
unsigned) type);
888 ods_log_debug(
"[%s] unable to parse soa: rdata too short",
896 ods_log_debug(
"[%s] unable to parse soa: bad mname",
903 ods_log_debug(
"[%s] unable to parse soa: bad rname",
914 *soa_serial = serial;
917 xfrd_update_soa(xfrd, buffer, ttl, mname_pos, rname_pos,
918 refresh, retry, expire, minimum);
933 ldns_rr_type type = 0;
937 uint32_t tmp_serial = 0;
939 ods_log_assert(xfrd);
940 ods_log_assert(buffer);
941 ods_log_assert(done);
944 return ODS_STATUS_OK;
947 return ODS_STATUS_SKIPDNAME;
950 return ODS_STATUS_BUFAVAIL;
958 return ODS_STATUS_BUFAVAIL;
960 if (type == LDNS_RR_TYPE_SOA) {
961 if (!xfrd_parse_soa(xfrd, buffer, 1, 0, ttl, &serial)) {
962 return ODS_STATUS_PARSESOA;
971 return ODS_STATUS_REQAXFR;
976 return ODS_STATUS_INSERIAL;
992 return ODS_STATUS_INSERIAL;
994 if (util_serial_gt(tmp_serial, serial)) {
996 return ODS_STATUS_INSERIAL;
1005 return ODS_STATUS_OK;
1017 uint16_t qdcount = 0;
1018 uint16_t ancount = 0;
1019 uint16_t ancount_todo = 0;
1020 uint16_t rrcount = 0;
1021 uint32_t serial = 0;
1023 ods_status status = ODS_STATUS_OK;
1024 ods_log_assert(buffer);
1025 ods_log_assert(xfrd);
1026 ods_log_assert(xfrd->
master);
1029 ods_log_assert(zone);
1030 ods_log_assert(zone->
name);
1033 ods_log_error(
"[%s] unable to parse packet: zone %s received bad " 1034 "packet from %s (too small)", xfrd_str, zone->
name,
1040 ods_log_error(
"[%s] bad packet: zone %s received bad query id " 1041 "%u from %s (expected %u)", xfrd_str, zone->
name,
1047 ods_log_error(
"[%s] bad packet: zone %s received error code %s from %s",
1057 if (!xfrd_tsig_process(xfrd, buffer)) {
1058 ods_log_error(
"[%s] bad packet: zone %s received bad tsig " 1065 for (rrcount = 0; rrcount < qdcount; rrcount++) {
1067 ods_log_error(
"[%s] bad packet: zone %s received bad " 1068 "question section from %s (bad rr)", xfrd_str, zone->
name,
1077 ods_log_info(
"[%s] zone %s received tc from %s, retry tcp",
1081 ods_log_error(
"[%s] bad packet: zone %s received bad xfr packet " 1086 ancount_todo = ancount;
1090 !xfrd_parse_soa(xfrd, buffer, 0, 1, 0, &serial)) {
1091 ods_log_error(
"[%s] bad packet: zone %s received bad xfr " 1092 "packet from %s (bad soa)", xfrd_str, zone->
name,
1100 ods_log_info(
"[%s] zone %s got update indicating current " 1101 "serial %u from %s", xfrd_str, zone->
name, serial,
1110 ods_log_debug(
"[%s] zone %s wait refresh time", xfrd_str,
1116 ods_log_debug(
"[%s] zone %s try next master", xfrd_str,
1124 ods_log_info(
"[%s] zone %s ignoring old serial %u from %s " 1125 "(have %u)", xfrd_str, zone->
name, serial,
1145 ancount_todo = ancount - 1;
1149 ods_log_info(
"[%s] zone %s received tc from %s, retry tcp",
1153 if (xfrd->
tcp_conn == -1 && ancount < 2) {
1155 ods_log_info(
"[%s] zone %s received too short udp reply from %s, " 1159 status = xfrd_parse_rrs(xfrd, buffer, ancount_todo, &done);
1160 if (status != ODS_STATUS_OK) {
1161 ods_log_error(
"[%s] bad packet: zone %s received bad xfr packet " 1163 ods_status2str(status));
1166 if (xfrd->
tcp_conn == -1 && !done) {
1167 ods_log_error(
"[%s] bad packet: zone %s received bad xfr packet " 1168 "(xfr over udp incomplete)", xfrd_str, zone->
name);
1187 ods_log_assert(xfrd);
1188 ods_log_assert(xfrd->
master);
1191 ods_log_assert(zone);
1192 ods_log_assert(zone->
name);
1193 res = xfrd_parse_packet(xfrd, buffer);
1194 ods_log_debug(
"[%s] zone %s xfr packet parsed (res %d)", xfrd_str,
1212 ods_log_info(
"[%s] zone %s xfr rollback", xfrd_str,
1220 xfrd_dump_packet(xfrd, buffer);
1231 xfrd_commit_packet(xfrd);
1235 ods_log_info(
"[%s] zone %s transfer done [notify acquired %lu, serial on " 1236 "disk %u, notify serial %u]", xfrd_str, zone->
name,
1242 ods_log_verbose(
"[%s] zone %s reset notify acquired", xfrd_str,
1247 ods_log_debug(
"[%s] zone %s xfr done", xfrd_str, zone->
name);
1255 ods_log_info(
"[%s] zone %s try get newer serial", xfrd_str, zone->
name);
1276 ods_log_assert(
set);
1277 ods_log_assert(xfrd);
1278 ods_log_assert(xfrd->
tcp_conn != -1);
1280 ods_log_assert(zone);
1281 ods_log_assert(zone->
name);
1282 tcp =
set->tcp_conn[xfrd->
tcp_conn];
1286 len =
sizeof(error);
1287 if (getsockopt(tcp->
fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
1290 if (error == EINPROGRESS || error == EWOULDBLOCK) {
1291 ods_log_debug(
"[%s] zone %s zero write, write again later (%s)",
1292 xfrd_str, zone->
name, strerror(error));
1296 ods_log_error(
"[%s] zone %s cannot tcp connect to %s: %s",
1299 xfrd_tcp_release(xfrd,
set, 1);
1305 ods_log_error(
"[%s] zone %s cannot tcp write to %s: %s",
1308 xfrd_tcp_release(xfrd,
set, 1);
1312 ods_log_debug(
"[%s] zone %s zero write, write again later",
1313 xfrd_str, zone->
name);
1317 ods_log_debug(
"[%s] zone %s done writing, get ready for reading",
1318 xfrd_str, zone->
name);
1322 xfrd_tcp_read(xfrd,
set);
1333 int fd, family, conn;
1334 struct sockaddr_storage to;
1338 ods_log_assert(
set);
1339 ods_log_assert(xfrd);
1340 ods_log_assert(xfrd->
tcp_conn != -1);
1341 ods_log_assert(xfrd->
master);
1344 ods_log_assert(zone);
1345 ods_log_assert(zone->
name);
1346 ods_log_debug(
"[%s] zone %s open tcp connection to %s", xfrd_str,
1348 set->tcp_conn[xfrd->
tcp_conn]->is_reading = 0;
1349 set->tcp_conn[xfrd->
tcp_conn]->total_bytes = 0;
1350 set->tcp_conn[xfrd->
tcp_conn]->msglen = 0;
1356 fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
1357 set->tcp_conn[xfrd->
tcp_conn]->fd = fd;
1359 ods_log_error(
"[%s] zone %s cannot create tcp socket to %s: %s",
1362 xfrd_tcp_release(xfrd,
set, 0);
1365 if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) {
1366 ods_log_error(
"[%s] zone %s cannot fcntl tcp socket: %s",
1367 xfrd_str, zone->
name, strerror(errno));
1369 xfrd_tcp_release(xfrd,
set, 0);
1375 conn = connect(fd, (
struct sockaddr*)&to, to_len);
1376 if (conn == -1 && errno != EINPROGRESS) {
1377 ods_log_error(
"[%s] zone %s cannot connect tcp socket to %s: %s",
1380 xfrd_tcp_release(xfrd,
set, 0);
1400 ods_log_assert(
set);
1401 ods_log_assert(xfrd);
1402 ods_log_assert(xfrd->
tcp_conn == -1);
1405 ods_log_assert(!set->tcp_waiting_first);
1409 if (set->tcp_conn[i]->fd == -1) {
1414 ods_log_assert(xfrd->
tcp_conn != -1);
1418 xfrd_udp_release(xfrd);
1420 if (!xfrd_tcp_open(xfrd,
set)) {
1423 xfrd_tcp_xfr(xfrd,
set);
1427 ods_log_verbose(
"[%s] max number of tcp connections (%d) reached",
1430 xfrd_unset_timer(xfrd);
1449 ods_log_assert(
set);
1450 ods_log_assert(xfrd);
1452 ods_log_assert(zone);
1453 ods_log_assert(zone->
name);
1454 ods_log_assert(xfrd->
tcp_conn != -1);
1456 ods_log_assert(xfrd->
master);
1459 tcp =
set->tcp_conn[xfrd->
tcp_conn];
1463 ods_log_info(
"[%s] zone %s request axfr to %s", xfrd_str,
1468 ods_log_info(
"[%s] zone %s request tcp/ixfr=%u to %s", xfrd_str,
1473 xfrd_write_soa(xfrd, tcp->
packet);
1482 xfrd_tsig_sign(xfrd, tcp->
packet);
1485 ods_log_verbose(
"[%s] zone %s sending tcp query id=%d", xfrd_str,
1501 ods_log_assert(
set);
1502 ods_log_assert(xfrd);
1503 ods_log_assert(xfrd->
tcp_conn != -1);
1504 tcp =
set->tcp_conn[xfrd->
tcp_conn];
1508 xfrd_tcp_release(xfrd,
set, 1);
1516 ret = xfrd_handle_packet(xfrd, tcp->
packet);
1523 ods_log_verbose(
"[%s] tcp read %s: release connection", xfrd_str,
1525 xfrd_tcp_release(xfrd,
set, 1);
1530 ods_log_verbose(
"[%s] disable ixfr requests for %s from now (%lu)",
1535 ods_log_debug(
"[%s] tcp read %s: release connection", xfrd_str,
1537 xfrd_tcp_release(xfrd,
set, 1);
1538 xfrd_make_request(xfrd);
1556 ods_log_assert(
set);
1557 ods_log_assert(xfrd);
1558 ods_log_assert(xfrd->
master);
1560 ods_log_assert(xfrd->
tcp_conn != -1);
1563 ods_log_debug(
"[%s] zone %s release tcp connection to %s", xfrd_str,
1571 if (set->tcp_conn[conn]->fd != -1) {
1572 close(set->tcp_conn[conn]->fd);
1574 set->tcp_conn[conn]->fd = -1;
1578 if (!open_waiting)
return;
1588 if (set->tcp_conn[i]->fd == -1) {
1597 xfrd_udp_release(waiting_xfrd);
1603 if (xfrd_tcp_open(waiting_xfrd,
set)) {
1604 xfrd_tcp_xfr(waiting_xfrd,
set);
1620 struct sockaddr_storage to;
1621 socklen_t to_len = 0;
1625 ods_log_assert(buffer);
1626 ods_log_assert(xfrd);
1627 ods_log_assert(xfrd->
master);
1636 fd = socket(family, SOCK_DGRAM, IPPROTO_UDP);
1638 ods_log_error(
"[%s] unable to send data over udp to %s: " 1646 ods_log_deeebug(
"[%s] send %lu bytes over udp to %s", xfrd_str,
1649 (
struct sockaddr*)&to, to_len);
1651 ods_log_error(
"[%s] unable to send data over udp to %s: " 1666 xfrd_udp_send_request_ixfr(
xfrd_type* xfrd)
1671 ods_log_assert(xfrd);
1672 ods_log_assert(xfrd->
master);
1675 ods_log_assert(zone);
1676 ods_log_assert(zone->
name);
1679 ods_log_error(
"[%s] unable to transfer zone %s: tried to send " 1680 "udp while tcp obtained", xfrd_str, zone->
name);
1685 ods_log_assert(xfrhandler);
1695 xfrd_write_soa(xfrd, xfrhandler->
packet);
1696 xfrd_tsig_sign(xfrd, xfrhandler->
packet);
1699 ods_log_info(
"[%s] zone %s request udp/ixfr=%u to %s", xfrd_str,
1701 if((fd = xfrd_udp_send(xfrd, xfrhandler->
packet)) == -1) {
1715 ods_log_assert(xfrd);
1721 xfrd_tcp_release(xfrd, xfrhandler->
tcp_set, 1);
1725 xfrd->
handler.
fd = xfrd_udp_send_request_ixfr(xfrd);
1741 xfrd_unset_timer(xfrd);
1753 ssize_t received = 0;
1754 ods_log_assert(xfrd);
1756 ods_log_assert(xfrhandler);
1761 if (received == -1) {
1762 ods_log_error(
"[%s] unable to read packet: recvfrom() failed fd %d " 1763 "(%s)", xfrd_str, xfrd->
handler.
fd, strerror(errno));
1781 ods_log_assert(xfrd);
1783 ods_log_assert(zone);
1784 ods_log_assert(zone->
name);
1785 ods_log_debug(
"[%s] zone %s read data from udp", xfrd_str,
1787 if (!xfrd_udp_read_packet(xfrd)) {
1788 ods_log_error(
"[%s] unable to read data from udp zone %s: " 1789 "xfrd_udp_read_packet() failed", xfrd_str, zone->
name);
1790 xfrd_udp_release(xfrd);
1794 ods_log_assert(xfrhandler);
1795 res = xfrd_handle_packet(xfrd, xfrhandler->
packet);
1798 ods_log_verbose(
"[%s] truncation from %s",
1800 xfrd_udp_release(xfrd);
1802 xfrd_tcp_obtain(xfrd, xfrhandler->
tcp_set);
1806 ods_log_verbose(
"[%s] xfr/newlease from %s",
1810 xfrd_udp_release(xfrd);
1814 ods_log_verbose(
"[%s] disable ixfr requests for %s from now (%lu)",
1819 ods_log_debug(
"[%s] bad ixfr packet from %s",
1821 xfrd_udp_release(xfrd);
1822 xfrd_make_request(xfrd);
1837 ods_log_assert(xfrd);
1843 ods_log_assert(xfrhandler);
1857 wf->
handler.
fd = xfrd_udp_send_request_ixfr(wf);
1884 ods_log_assert(zone);
1885 ods_log_assert(zone->
name);
1920 ods_log_verbose(
"[%s] zone %s make request wait retry",
1921 xfrd_str, zone->
name);
1926 ods_log_debug(
"[%s] unable to make request for zone %s: no master",
1927 xfrd_str, zone->
name);
1936 ods_log_verbose(
"[%s] clear negative caching ixfr disabled for " 1938 ods_log_debug(
"[%s] clear negative caching calc: %lu + %lu <= %lu",
1940 (
unsigned long) xfrd_time(xfrd));
1948 ods_log_verbose(
"[%s] zone %s make request [udp round %d master %s:%u]",
1951 xfrd_udp_obtain(xfrd);
1955 ods_log_assert(xfrhandler);
1962 ods_log_verbose(
"[%s] zone %s make request [tcp round %d master %s:%u]",
1965 xfrd_tcp_obtain(xfrd, xfrhandler->
tcp_set);
1975 xfrd_handle_zone(
netio_type* ATTR_UNUSED(netio),
1985 ods_log_assert(xfrd);
1987 ods_log_assert(zone);
1988 ods_log_assert(zone->
name);
1993 ods_log_assert(xfrhandler);
1995 ods_log_deeebug(
"[%s] zone %s event tcp read", xfrd_str, zone->
name);
1997 xfrd_tcp_read(xfrd, xfrhandler->
tcp_set);
2000 ods_log_deeebug(
"[%s] zone %s event tcp write", xfrd_str,
2003 xfrd_tcp_write(xfrd, xfrhandler->
tcp_set);
2007 ods_log_deeebug(
"[%s] zone %s event tcp timeout", xfrd_str,
2009 xfrd_tcp_release(xfrd, xfrhandler->
tcp_set, 1);
2017 ods_log_deeebug(
"[%s] zone %s event udp read", xfrd_str,
2020 xfrd_udp_read(xfrd);
2025 ods_log_deeebug(
"[%s] zone %s timeout", xfrd_str, zone->
name);
2026 if (handler->
fd != -1) {
2027 ods_log_assert(xfrd->
tcp_conn == -1);
2028 xfrd_udp_release(xfrd);
2031 ods_log_deeebug(
"[%s] zone %s skips retry: tcp connections full",
2032 xfrd_str, zone->
name);
2033 xfrd_unset_timer(xfrd);
2037 ods_log_deeebug(
"[%s] zone %s skips retry: udp connections full",
2038 xfrd_str, zone->
name);
2039 xfrd_unset_timer(xfrd);
2043 xfrd_make_request(xfrd);
2052 xfrd_backup_dname(FILE* out, uint8_t* dname)
2054 uint8_t* d= dname+1;
2062 ods_log_assert(d - (dname+1) <= dname[0]);
2063 for (i=0; i<len; i++) {
2065 if (isalnum(ch) || ch ==
'-' || ch ==
'_') {
2066 fprintf(out,
"%c", ch);
2067 }
else if (ch ==
'.' || ch ==
'\\') {
2068 fprintf(out,
"\\%c", ch);
2070 fprintf(out,
"\\%03u", (
unsigned int)ch);
2091 if (zone && zone->
name) {
2092 file = ods_build_path(zone->
name,
".xfrd-state", 0, 1);
2094 fd = ods_fopen(file, NULL,
"w");
2097 timeout = xfrd->
timeout.tv_sec;
2099 fprintf(fd,
"%s\n", ODS_SE_FILE_MAGIC_V3);
2100 fprintf(fd,
";;Zone: name %s ttl %u mname ",
2102 (
unsigned) xfrd->
soa.
ttl);
2103 xfrd_backup_dname(fd, xfrd->
soa.
mname),
2104 fprintf(fd,
" rname ");
2105 xfrd_backup_dname(fd, xfrd->
soa.
rname),
2106 fprintf(fd,
" serial %u refresh %u retry %u expire %u " 2113 fprintf(fd,
";;Master: num %d next %d round %d timeout %d\n",
2118 fprintf(fd,
";;Serial: xfr %u %u notify %u %u disk %u %u\n",
2125 fprintf(fd,
"%s\n", ODS_SE_FILE_MAGIC_V3);
2143 if (zone && zone->
name) {
2144 ods_log_info(
"[%s] unlink zone %s xfrd state", xfrd_str, zone->
name);
2145 file = ods_build_path(zone->
name,
".xfrd-state", 0, 1);
2173 lock_basic_destroy(&xfrd->
rw_lock);
#define XFRD_TSIG_MAX_UNSIGNED
int backup_read_str(FILE *in, const char **str)
void tsig_rr_update(tsig_rr_type *trr, buffer_type *buffer, size_t length)
void engine_wakeup_workers(engine_type *engine)
xfrd_type * udp_waiting_first
xfrd_type * udp_waiting_last
xfrd_type * tcp_waiting_next
void xfrd_set_timer_refresh(xfrd_type *xfrd)
uint16_t buffer_pkt_arcount(buffer_type *buffer)
xfrd_type * tcp_waiting_first
#define BUFFER_PKT_HEADER_SIZE
const char * tsig_strerror(uint16_t error)
time_t serial_xfr_acquired
uint16_t buffer_pkt_qdcount(buffer_type *buffer)
void buffer_skip(buffer_type *buffer, ssize_t count)
uint16_t buffer_read_u16(buffer_type *buffer)
int buffer_skip_rr(buffer_type *buffer, unsigned qrr)
void buffer_flip(buffer_type *buffer)
#define XFRD_NO_IXFR_CACHE
void buffer_clear(buffer_type *buffer)
time_t serial_notify_acquired
int backup_read_time_t(FILE *in, time_t *v)
uint8_t mname[MAXDOMAINLEN+2]
enum netio_events_enum netio_events_type
lock_basic_type zone_lock
socklen_t xfrd_acl_sockaddr_to(acl_type *acl, struct sockaddr_storage *to)
tsig_algo_type * tsig_lookup_algo(const char *name)
int tcp_conn_write(tcp_conn_type *tcp)
union acl_addr_storage addr
int backup_read_int(FILE *in, int *v)
void tsig_rr_reset(tsig_rr_type *trr, tsig_algo_type *algo, tsig_key_type *key)
void tsig_rr_append(tsig_rr_type *trr, buffer_type *buffer)
xfrd_type * xfrd_create(xfrhandler_type *xfrhandler, zone_type *zone)
size_t update_since_last_prepare
void buffer_write(buffer_type *buffer, const void *data, size_t count)
uint16_t buffer_pkt_id(buffer_type *buffer)
lock_basic_type serial_lock
xfrhandler_type * xfrhandler
uint8_t * buffer_current(buffer_type *buffer)
uint16_t buffer_pkt_ancount(buffer_type *buffer)
size_t buffer_limit(buffer_type *buffer)
xfrd_type * udp_waiting_next
tsig_rr_type * tsig_rr_create()
void tsig_rr_prepare(tsig_rr_type *trr)
time_t xfrhandler_time(xfrhandler_type *xfrhandler)
void buffer_pkt_set_nscount(buffer_type *buffer, uint16_t count)
void buffer_set_limit(buffer_type *buffer, size_t limit)
netio_event_handler_type event_handler
void tsig_rr_cleanup(tsig_rr_type *trr)
void xfrd_set_timer_retry(xfrd_type *xfrd)
int buffer_skip_dname(buffer_type *buffer)
void log_dname(ldns_rdf *rdf, const char *pre, int level)
uint32_t buffer_read_u32(buffer_type *buffer)
void xfrd_cleanup(xfrd_type *xfrd, int backup)
void buffer_pkt_query(buffer_type *buffer, ldns_rdf *qname, ldns_rr_type qtype, ldns_rr_class qclass)
int tsig_rr_verify(tsig_rr_type *trr)
void buffer_write_u16(buffer_type *buffer, uint16_t data)
size_t buffer_read_dname(buffer_type *buffer, uint8_t *dname, unsigned allow_pointers)
void buffer_write_u32(buffer_type *buffer, uint32_t data)
ods_status zone_reschedule_task(zone_type *zone, schedule_type *taskq, task_id what)
uint8_t rname[MAXDOMAINLEN+2]
int tcp_conn_read(tcp_conn_type *tcp)
void buffer_write_u16_at(buffer_type *buffer, size_t at, uint16_t data)
void buffer_set_position(buffer_type *buffer, size_t pos)
int tsig_rr_find(tsig_rr_type *trr, buffer_type *buffer)
void xfrd_set_timer_now(xfrd_type *xfrd)
netio_events_type event_types
int buffer_available(buffer_type *buffer, size_t count)
uint8_t serial_retransfer
int backup_read_check_str(FILE *in, const char *str)
size_t buffer_remaining(buffer_type *buffer)
void buffer_write_rdf(buffer_type *buffer, ldns_rdf *rdf)
void tsig_rr_sign(tsig_rr_type *trr)
void tcp_conn_ready(tcp_conn_type *tcp)
size_t buffer_position(buffer_type *buffer)
void buffer_pkt_set_arcount(buffer_type *buffer, uint16_t count)
struct timespec * timeout
netio_handler_type handler
uint16_t original_query_id
enum xfrd_pkt_enum xfrd_pkt_status
time_t serial_disk_acquired
uint8_t * buffer_begin(buffer_type *buffer)
ldns_pkt_rcode buffer_pkt_rcode(buffer_type *buffer)
int backup_read_uint32_t(FILE *in, uint32_t *v)
int buffer_pkt_tc(buffer_type *buffer)
uint8_t msg_do_retransfer