49#define XFRD_TSIG_MAX_UNSIGNED 100
51static const char* xfrd_str =
"xfrd";
55static void xfrd_make_request(
xfrd_type* xfrd);
57static 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);
78static void xfrd_udp_obtain(
xfrd_type* xfrd);
79static void xfrd_udp_read(
xfrd_type* xfrd);
80static void xfrd_udp_release(
xfrd_type* xfrd);
81static int xfrd_udp_read_packet(
xfrd_type* xfrd);
83static int xfrd_udp_send_request_ixfr(
xfrd_type* xfrd);
86static void xfrd_set_timer(
xfrd_type* xfrd, time_t t);
87static void xfrd_set_timer_time(
xfrd_type* xfrd, time_t t);
88static void xfrd_unset_timer(
xfrd_type* xfrd);
96xfrd_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 pthread_mutex_init(&xfrd->
rw_lock, NULL);
357 memset(&xfrd->
soa, 0,
sizeof(xfrd->
soa));
372 xfrd_set_timer_time(xfrd, 0);
385 ods_log_assert(xfrd);
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);
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);
442xfrd_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,
508xfrd_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 pthread_mutex_lock(&xfrd->
rw_lock);
674 fd = ods_fopen(xfrfile, NULL,
"a");
675 free((
void*)xfrfile);
677 fprintf(fd,
";;ENDPACKET\n");
680 pthread_mutex_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,
710 schedule_scheduletask(engine->taskq, TASK_FORCEREAD, zone->
name, zone, &zone->
zone_lock, schedule_IMMEDIATELY);
717 pthread_mutex_unlock(&xfrd->
rw_lock);
730 char* xfrfile = NULL;
732 ldns_pkt* pkt = NULL;
733 ldns_status status = LDNS_STATUS_OK;
734 ods_log_assert(buffer);
735 ods_log_assert(xfrd);
737 ods_log_assert(zone);
738 ods_log_assert(zone->
name);
740 if (status != LDNS_STATUS_OK) {
741 ods_log_crit(
"[%s] unable to dump packet zone %s: ldns_wire2pkt() "
742 "failed (%s)", xfrd_str, zone->
name,
743 ldns_get_errorstr_by_id(status));
747 xfrfile = ods_build_path(zone->
name,
".xfrd", 0, 1);
749 ods_log_crit(
"[%s] unable to dump packet zone %s: build path failed",
750 xfrd_str, zone->
name);
753 pthread_mutex_lock(&xfrd->
rw_lock);
755 fd = ods_fopen(xfrfile, NULL,
"w");
757 fd = ods_fopen(xfrfile, NULL,
"a");
759 free((
void*) xfrfile);
761 ods_log_crit(
"[%s] unable to dump packet zone %s: ods_fopen() failed "
762 "(%s)", xfrd_str, zone->
name, strerror(errno));
763 pthread_mutex_unlock(&xfrd->
rw_lock);
768 fprintf(fd,
";;BEGINPACKET\n");
770 ldns_rr_list_print(fd, ldns_pkt_answer(pkt));
772 pthread_mutex_unlock(&xfrd->
rw_lock);
785 size_t rdlength_pos = 0;
786 uint16_t rdlength = 0;
787 ods_log_assert(xfrd);
788 ods_log_assert(buffer);
790 ods_log_assert(zone);
791 ods_log_assert(zone->
apex);
816 uint16_t mname_pos, uint16_t rname_pos,
817 uint32_t refresh, uint32_t retry, uint32_t expire, uint32_t minimum)
820 ods_log_assert(xfrd);
821 ods_log_assert(buffer);
823 ods_log_assert(zone);
824 ods_log_assert(zone->
apex);
851 unsigned update, uint32_t t, uint32_t* soa_serial)
853 ldns_rr_type type = LDNS_RR_TYPE_SOA;
854 uint16_t mname_pos = 0;
855 uint16_t rname_pos = 0;
858 uint32_t refresh = 0;
861 uint32_t minimum = 0;
863 ods_log_assert(xfrd);
864 ods_log_assert(buffer);
869 ods_log_debug(
"[%s] unable to parse soa: rr too short",
874 if (type != LDNS_RR_TYPE_SOA) {
875 ods_log_debug(
"[%s] unable to parse soa: rrtype %u != soa",
876 xfrd_str, (
unsigned) type);
883 ods_log_debug(
"[%s] unable to parse soa: rdata too short",
891 ods_log_debug(
"[%s] unable to parse soa: bad mname",
898 ods_log_debug(
"[%s] unable to parse soa: bad rname",
909 *soa_serial = serial;
912 xfrd_update_soa(xfrd, buffer, ttl, mname_pos, rname_pos,
913 refresh, retry, expire, minimum);
928 ldns_rr_type type = 0;
932 uint32_t tmp_serial = 0;
934 ods_log_assert(xfrd);
935 ods_log_assert(buffer);
936 ods_log_assert(done);
939 return ODS_STATUS_OK;
942 return ODS_STATUS_SKIPDNAME;
945 return ODS_STATUS_BUFAVAIL;
953 return ODS_STATUS_BUFAVAIL;
955 if (type == LDNS_RR_TYPE_SOA) {
956 if (!xfrd_parse_soa(xfrd, buffer, 1, 0, ttl, &serial)) {
957 return ODS_STATUS_PARSESOA;
966 return ODS_STATUS_REQAXFR;
971 return ODS_STATUS_INSERIAL;
987 return ODS_STATUS_INSERIAL;
989 if (util_serial_gt(tmp_serial, serial)) {
991 return ODS_STATUS_INSERIAL;
1000 return ODS_STATUS_OK;
1012 uint16_t qdcount = 0;
1013 uint16_t ancount = 0;
1014 uint16_t ancount_todo = 0;
1015 uint16_t rrcount = 0;
1016 uint32_t serial = 0;
1018 ods_status status = ODS_STATUS_OK;
1019 ods_log_assert(buffer);
1020 ods_log_assert(xfrd);
1021 ods_log_assert(xfrd->
master);
1024 ods_log_assert(zone);
1025 ods_log_assert(zone->
name);
1028 ods_log_error(
"[%s] unable to parse packet: zone %s received bad "
1029 "packet from %s (too small)", xfrd_str, zone->
name,
1035 ods_log_error(
"[%s] bad packet: zone %s received bad query id "
1036 "%u from %s (expected %u)", xfrd_str, zone->
name,
1042 ods_log_error(
"[%s] bad packet: zone %s received error code %s from %s",
1052 if (!xfrd_tsig_process(xfrd, buffer)) {
1053 ods_log_error(
"[%s] bad packet: zone %s received bad tsig "
1060 for (rrcount = 0; rrcount < qdcount; rrcount++) {
1062 ods_log_error(
"[%s] bad packet: zone %s received bad "
1063 "question section from %s (bad rr)", xfrd_str, zone->
name,
1072 ods_log_info(
"[%s] zone %s received tc from %s, retry tcp",
1076 ods_log_error(
"[%s] bad packet: zone %s received bad xfr packet "
1081 ancount_todo = ancount;
1085 !xfrd_parse_soa(xfrd, buffer, 0, 1, 0, &serial)) {
1086 ods_log_error(
"[%s] bad packet: zone %s received bad xfr "
1087 "packet from %s (bad soa)", xfrd_str, zone->
name,
1095 ods_log_info(
"[%s] zone %s got update indicating current "
1096 "serial %u from %s", xfrd_str, zone->
name, serial,
1105 ods_log_debug(
"[%s] zone %s wait refresh time", xfrd_str,
1111 ods_log_debug(
"[%s] zone %s try next master", xfrd_str,
1119 ods_log_info(
"[%s] zone %s ignoring old serial %u from %s "
1120 "(have %u)", xfrd_str, zone->
name, serial,
1140 ancount_todo = ancount - 1;
1144 ods_log_info(
"[%s] zone %s received tc from %s, retry tcp",
1148 if (xfrd->
tcp_conn == -1 && ancount < 2) {
1150 ods_log_info(
"[%s] zone %s received too short udp reply from %s, "
1154 status = xfrd_parse_rrs(xfrd, buffer, ancount_todo, &done);
1155 if (status != ODS_STATUS_OK) {
1156 ods_log_error(
"[%s] bad packet: zone %s received bad xfr packet "
1158 ods_status2str(status));
1161 if (xfrd->
tcp_conn == -1 && !done) {
1162 ods_log_error(
"[%s] bad packet: zone %s received bad xfr packet "
1163 "(xfr over udp incomplete)", xfrd_str, zone->
name);
1182 ods_log_assert(xfrd);
1183 ods_log_assert(xfrd->
master);
1186 ods_log_assert(zone);
1187 ods_log_assert(zone->
name);
1188 res = xfrd_parse_packet(xfrd, buffer);
1189 ods_log_debug(
"[%s] zone %s xfr packet parsed (res %d)", xfrd_str,
1208 ods_log_info(
"[%s] zone %s xfr rollback", xfrd_str,
1216 xfrd_dump_packet(xfrd, buffer);
1227 xfrd_commit_packet(xfrd);
1231 ods_log_info(
"[%s] zone %s transfer done [notify acquired %lu, serial on "
1232 "disk %u, notify serial %u]", xfrd_str, zone->
name,
1238 ods_log_verbose(
"[%s] zone %s reset notify acquired", xfrd_str,
1243 ods_log_debug(
"[%s] zone %s xfr done", xfrd_str, zone->
name);
1251 ods_log_info(
"[%s] zone %s try get newer serial", xfrd_str, zone->
name);
1272 ods_log_assert(set);
1273 ods_log_assert(xfrd);
1274 ods_log_assert(xfrd->
tcp_conn != -1);
1276 ods_log_assert(zone);
1277 ods_log_assert(zone->
name);
1282 len =
sizeof(error);
1283 if (getsockopt(tcp->
fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
1286 if (error == EINPROGRESS || error == EWOULDBLOCK) {
1287 ods_log_debug(
"[%s] zone %s zero write, write again later (%s)",
1288 xfrd_str, zone->
name, strerror(error));
1292 ods_log_error(
"[%s] zone %s cannot tcp connect to %s: %s",
1295 xfrd_tcp_release(xfrd, set, 1);
1301 ods_log_error(
"[%s] zone %s cannot tcp write to %s: %s",
1304 xfrd_tcp_release(xfrd, set, 1);
1308 ods_log_debug(
"[%s] zone %s zero write, write again later",
1309 xfrd_str, zone->
name);
1313 ods_log_debug(
"[%s] zone %s done writing, get ready for reading",
1314 xfrd_str, zone->
name);
1318 xfrd_tcp_read(xfrd, set);
1329 int fd, family, conn;
1330 struct sockaddr_storage to;
1334 ods_log_assert(set);
1335 ods_log_assert(xfrd);
1336 ods_log_assert(xfrd->
tcp_conn != -1);
1337 ods_log_assert(xfrd->
master);
1340 ods_log_assert(zone);
1341 ods_log_assert(zone->
name);
1342 ods_log_debug(
"[%s] zone %s open tcp connection to %s", xfrd_str,
1352 fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
1355 ods_log_error(
"[%s] zone %s cannot create tcp socket to %s: %s",
1358 xfrd_tcp_release(xfrd, set, 0);
1361 if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) {
1362 ods_log_error(
"[%s] zone %s cannot fcntl tcp socket: %s",
1363 xfrd_str, zone->
name, strerror(errno));
1365 xfrd_tcp_release(xfrd, set, 0);
1370 interface_type interface = xfrd->xfrhandler->engine->dnshandler->interfaces->interfaces[0];
1371 if (!interface.address) {
1372 ods_log_error(
"[%s] unable to get the address of interface", xfrd_str);
1376 struct sockaddr_in addr;
1378 addr.sin_addr = interface.addr.addr;
1380 if (bind(fd, (
struct sockaddr *) &addr,
sizeof(addr)) != 0) {
1381 ods_log_error(
"[%s] unable to bind address %s: bind failed %s", xfrd_str, interface.address, strerror(errno));
1386 struct sockaddr_in6 addr6;
1388 addr6.sin6_addr = interface.addr.addr6;
1389 addr6.sin6_port = 0;
1390 if (bind(fd, (
struct sockaddr *) &addr6,
sizeof(addr6)) != 0) {
1391 ods_log_error(
"[%s] unable to bind address %s: bind failed %s", xfrd_str, interface.address, strerror(errno));
1396 conn = connect(fd, (
struct sockaddr*)&to, to_len);
1397 if (conn == -1 && errno != EINPROGRESS) {
1398 ods_log_error(
"[%s] zone %s cannot connect tcp socket to %s: %s",
1401 xfrd_tcp_release(xfrd, set, 0);
1421 ods_log_assert(set);
1422 ods_log_assert(xfrd);
1423 ods_log_assert(xfrd->
tcp_conn == -1);
1435 ods_log_assert(xfrd->
tcp_conn != -1);
1439 xfrd_udp_release(xfrd);
1441 if (!xfrd_tcp_open(xfrd, set)) {
1444 xfrd_tcp_xfr(xfrd, set);
1448 ods_log_verbose(
"[%s] max number of tcp connections (%d) reached",
1451 xfrd_unset_timer(xfrd);
1470 ods_log_assert(set);
1471 ods_log_assert(xfrd);
1473 ods_log_assert(zone);
1474 ods_log_assert(zone->
name);
1475 ods_log_assert(xfrd->
tcp_conn != -1);
1477 ods_log_assert(xfrd->
master);
1484 ods_log_info(
"[%s] zone %s request axfr to %s", xfrd_str,
1489 ods_log_info(
"[%s] zone %s request tcp/ixfr=%u to %s", xfrd_str,
1494 xfrd_write_soa(xfrd, tcp->
packet);
1503 xfrd_tsig_sign(xfrd, tcp->
packet);
1506 ods_log_verbose(
"[%s] zone %s sending tcp query id=%d", xfrd_str,
1522 ods_log_assert(set);
1523 ods_log_assert(xfrd);
1524 ods_log_assert(xfrd->
tcp_conn != -1);
1529 xfrd_tcp_release(xfrd, set, 1);
1537 ret = xfrd_handle_packet(xfrd, tcp->
packet);
1544 ods_log_verbose(
"[%s] tcp read %s: release connection", xfrd_str,
1546 xfrd_tcp_release(xfrd, set, 1);
1551 ods_log_verbose(
"[%s] disable ixfr requests for %s from now (%lu)",
1556 ods_log_debug(
"[%s] tcp read %s: release connection", xfrd_str,
1558 xfrd_tcp_release(xfrd, set, 1);
1559 xfrd_make_request(xfrd);
1577 ods_log_assert(set);
1578 ods_log_assert(xfrd);
1579 ods_log_assert(xfrd->
master);
1581 ods_log_assert(xfrd->
tcp_conn != -1);
1584 ods_log_debug(
"[%s] zone %s release tcp connection to %s", xfrd_str,
1599 if (!open_waiting)
return;
1618 xfrd_udp_release(waiting_xfrd);
1624 if (xfrd_tcp_open(waiting_xfrd, set)) {
1625 xfrd_tcp_xfr(waiting_xfrd, set);
1641 struct sockaddr_storage to;
1642 socklen_t to_len = 0;
1646 ods_log_assert(buffer);
1647 ods_log_assert(xfrd);
1648 ods_log_assert(xfrd->
master);
1657 fd = socket(family, SOCK_DGRAM, IPPROTO_UDP);
1659 ods_log_error(
"[%s] unable to send data over udp to %s: "
1667 ods_log_deeebug(
"[%s] send %lu bytes over udp to %s", xfrd_str,
1670 (
struct sockaddr*)&to, to_len);
1672 ods_log_error(
"[%s] unable to send data over udp to %s: "
1687xfrd_udp_send_request_ixfr(
xfrd_type* xfrd)
1692 ods_log_assert(xfrd);
1693 ods_log_assert(xfrd->
master);
1696 ods_log_assert(zone);
1697 ods_log_assert(zone->
name);
1700 ods_log_error(
"[%s] unable to transfer zone %s: tried to send "
1701 "udp while tcp obtained", xfrd_str, zone->
name);
1706 ods_log_assert(xfrhandler);
1716 xfrd_write_soa(xfrd, xfrhandler->
packet);
1717 xfrd_tsig_sign(xfrd, xfrhandler->
packet);
1720 ods_log_info(
"[%s] zone %s request udp/ixfr=%u to %s", xfrd_str,
1722 if((fd = xfrd_udp_send(xfrd, xfrhandler->
packet)) == -1) {
1736 ods_log_assert(xfrd);
1742 xfrd_tcp_release(xfrd, xfrhandler->
tcp_set, 1);
1746 xfrd->
handler.
fd = xfrd_udp_send_request_ixfr(xfrd);
1762 xfrd_unset_timer(xfrd);
1774 ssize_t received = 0;
1775 ods_log_assert(xfrd);
1777 ods_log_assert(xfrhandler);
1782 if (received == -1) {
1783 ods_log_error(
"[%s] unable to read packet: recvfrom() failed fd %d "
1784 "(%s)", xfrd_str, xfrd->
handler.
fd, strerror(errno));
1802 ods_log_assert(xfrd);
1804 ods_log_assert(zone);
1805 ods_log_assert(zone->
name);
1806 ods_log_debug(
"[%s] zone %s read data from udp", xfrd_str,
1808 if (!xfrd_udp_read_packet(xfrd)) {
1809 ods_log_error(
"[%s] unable to read data from udp zone %s: "
1810 "xfrd_udp_read_packet() failed", xfrd_str, zone->
name);
1811 xfrd_udp_release(xfrd);
1815 ods_log_assert(xfrhandler);
1816 res = xfrd_handle_packet(xfrd, xfrhandler->
packet);
1819 ods_log_verbose(
"[%s] truncation from %s",
1821 xfrd_udp_release(xfrd);
1823 xfrd_tcp_obtain(xfrd, xfrhandler->
tcp_set);
1827 ods_log_verbose(
"[%s] xfr/newlease from %s",
1831 xfrd_udp_release(xfrd);
1835 ods_log_verbose(
"[%s] disable ixfr requests for %s from now (%lu)",
1840 ods_log_debug(
"[%s] bad ixfr packet from %s",
1842 xfrd_udp_release(xfrd);
1843 xfrd_make_request(xfrd);
1858 ods_log_assert(xfrd);
1864 ods_log_assert(xfrhandler);
1878 wf->
handler.
fd = xfrd_udp_send_request_ixfr(wf);
1905 ods_log_assert(zone);
1906 ods_log_assert(zone->
name);
1941 ods_log_verbose(
"[%s] zone %s make request wait retry",
1942 xfrd_str, zone->
name);
1947 ods_log_debug(
"[%s] unable to make request for zone %s: no master",
1948 xfrd_str, zone->
name);
1957 ods_log_verbose(
"[%s] clear negative caching ixfr disabled for "
1959 ods_log_debug(
"[%s] clear negative caching calc: %lu + %lu <= %lu",
1961 (
unsigned long) xfrd_time(xfrd));
1969 ods_log_verbose(
"[%s] zone %s make request [udp round %d master %s:%u]",
1972 xfrd_udp_obtain(xfrd);
1976 ods_log_assert(xfrhandler);
1983 ods_log_verbose(
"[%s] zone %s make request [tcp round %d master %s:%u]",
1986 xfrd_tcp_obtain(xfrd, xfrhandler->
tcp_set);
1996xfrd_handle_zone(
netio_type* ATTR_UNUSED(netio),
2006 ods_log_assert(xfrd);
2008 ods_log_assert(zone);
2009 ods_log_assert(zone->
name);
2014 ods_log_assert(xfrhandler);
2016 ods_log_deeebug(
"[%s] zone %s event tcp read", xfrd_str, zone->
name);
2018 xfrd_tcp_read(xfrd, xfrhandler->
tcp_set);
2021 ods_log_deeebug(
"[%s] zone %s event tcp write", xfrd_str,
2024 xfrd_tcp_write(xfrd, xfrhandler->
tcp_set);
2028 ods_log_deeebug(
"[%s] zone %s event tcp timeout", xfrd_str,
2030 xfrd_tcp_release(xfrd, xfrhandler->
tcp_set, 1);
2038 ods_log_deeebug(
"[%s] zone %s event udp read", xfrd_str,
2041 xfrd_udp_read(xfrd);
2046 ods_log_deeebug(
"[%s] zone %s timeout", xfrd_str, zone->
name);
2047 if (handler->
fd != -1) {
2048 ods_log_assert(xfrd->
tcp_conn == -1);
2049 xfrd_udp_release(xfrd);
2052 ods_log_deeebug(
"[%s] zone %s skips retry: tcp connections full",
2053 xfrd_str, zone->
name);
2054 xfrd_unset_timer(xfrd);
2058 ods_log_deeebug(
"[%s] zone %s skips retry: udp connections full",
2059 xfrd_str, zone->
name);
2060 xfrd_unset_timer(xfrd);
2064 xfrd_make_request(xfrd);
2073xfrd_backup_dname(FILE* out, uint8_t* dname)
2075 uint8_t* d= dname+1;
2083 ods_log_assert(d - (dname+1) <= dname[0]);
2084 for (i=0; i<len; i++) {
2086 if (isalnum(ch) || ch ==
'-' || ch ==
'_') {
2087 fprintf(out,
"%c", ch);
2088 }
else if (ch ==
'.' || ch ==
'\\') {
2089 fprintf(out,
"\\%c", ch);
2091 fprintf(out,
"\\%03u", (
unsigned int)ch);
2112 if (zone && zone->
name) {
2113 file = ods_build_path(zone->
name,
".xfrd-state", 0, 1);
2115 fd = ods_fopen(file, NULL,
"w");
2118 timeout = xfrd->
timeout.tv_sec;
2120 fprintf(fd,
"%s\n", ODS_SE_FILE_MAGIC_V3);
2121 fprintf(fd,
";;Zone: name %s ttl %u mname ",
2123 (
unsigned) xfrd->
soa.
ttl);
2124 xfrd_backup_dname(fd, xfrd->
soa.
mname),
2125 fprintf(fd,
" rname ");
2126 xfrd_backup_dname(fd, xfrd->
soa.
rname),
2127 fprintf(fd,
" serial %u refresh %u retry %u expire %u "
2134 fprintf(fd,
";;Master: num %d next %d round %d timeout %d\n",
2139 fprintf(fd,
";;Serial: xfr %u %u notify %u %u disk %u %u\n",
2146 fprintf(fd,
"%s\n", ODS_SE_FILE_MAGIC_V3);
2164 if (zone && zone->
name) {
2165 ods_log_info(
"[%s] unlink zone %s xfrd state", xfrd_str, zone->
name);
2166 file = ods_build_path(zone->
name,
".xfrd-state", 0, 1);
2194 pthread_mutex_destroy(&xfrd->
rw_lock);
int acl_parse_family(const char *a)
int backup_read_uint32_t(FILE *in, uint32_t *v)
int backup_read_int(FILE *in, int *v)
int backup_read_time_t(FILE *in, time_t *v)
int backup_read_check_str(FILE *in, const char *str)
int backup_read_str(FILE *in, const char **str)
int buffer_available(buffer_type *buffer, size_t count)
uint16_t buffer_pkt_qdcount(buffer_type *buffer)
void buffer_clear(buffer_type *buffer)
int buffer_skip_rr(buffer_type *buffer, unsigned qrr)
uint32_t buffer_read_u32(buffer_type *buffer)
uint16_t buffer_read_u16(buffer_type *buffer)
uint8_t * buffer_current(buffer_type *buffer)
void buffer_set_limit(buffer_type *buffer, size_t limit)
void buffer_set_position(buffer_type *buffer, size_t pos)
uint8_t * buffer_begin(buffer_type *buffer)
ldns_pkt_rcode buffer_pkt_rcode(buffer_type *buffer)
void buffer_flip(buffer_type *buffer)
size_t buffer_position(buffer_type *buffer)
uint16_t buffer_pkt_arcount(buffer_type *buffer)
void buffer_pkt_set_nscount(buffer_type *buffer, uint16_t count)
void buffer_write(buffer_type *buffer, const void *data, size_t count)
void buffer_write_rdf(buffer_type *buffer, ldns_rdf *rdf)
void buffer_write_u16_at(buffer_type *buffer, size_t at, uint16_t data)
void buffer_skip(buffer_type *buffer, ssize_t count)
int buffer_pkt_tc(buffer_type *buffer)
int buffer_skip_dname(buffer_type *buffer)
size_t buffer_remaining(buffer_type *buffer)
void buffer_write_u32(buffer_type *buffer, uint32_t data)
void buffer_pkt_query(buffer_type *buffer, ldns_rdf *qname, ldns_rr_type qtype, ldns_rr_class qclass)
void buffer_write_u16(buffer_type *buffer, uint16_t data)
size_t buffer_read_dname(buffer_type *buffer, uint8_t *dname, unsigned allow_pointers)
size_t buffer_limit(buffer_type *buffer)
uint16_t buffer_pkt_ancount(buffer_type *buffer)
void buffer_pkt_set_arcount(buffer_type *buffer, uint16_t count)
uint16_t buffer_pkt_id(buffer_type *buffer)
#define BUFFER_PKT_HEADER_SIZE
void log_dname(ldns_rdf *rdf, const char *pre, int level)
void engine_wakeup_workers(engine_type *engine)
enum netio_events_enum netio_events_type
union acl_addr_storage addr
struct timespec * timeout
netio_events_type event_types
netio_event_handler_type event_handler
uint8_t rname[MAXDOMAINLEN+2]
uint8_t mname[MAXDOMAINLEN+2]
xfrd_type * tcp_waiting_first
tcp_conn_type * tcp_conn[TCPSET_MAX]
size_t update_since_last_prepare
uint16_t original_query_id
time_t serial_disk_acquired
xfrhandler_type * xfrhandler
netio_handler_type handler
pthread_mutex_t serial_lock
uint8_t msg_do_retransfer
time_t serial_notify_acquired
xfrd_type * udp_waiting_next
xfrd_type * tcp_waiting_next
uint8_t serial_retransfer
time_t serial_xfr_acquired
xfrd_type * udp_waiting_first
xfrd_type * udp_waiting_last
xfrd_type * tcp_waiting_first
pthread_mutex_t zone_lock
void tcp_conn_ready(tcp_conn_type *tcp)
int tcp_conn_read(tcp_conn_type *tcp)
int tcp_conn_write(tcp_conn_type *tcp)
void tsig_rr_cleanup(tsig_rr_type *trr)
const char * tsig_strerror(uint16_t error)
int tsig_rr_verify(tsig_rr_type *trr)
void tsig_rr_append(tsig_rr_type *trr, buffer_type *buffer)
void tsig_rr_sign(tsig_rr_type *trr)
void tsig_rr_reset(tsig_rr_type *trr, tsig_algo_type *algo, tsig_key_type *key)
void tsig_rr_update(tsig_rr_type *trr, buffer_type *buffer, size_t length)
void tsig_rr_prepare(tsig_rr_type *trr)
tsig_rr_type * tsig_rr_create()
int tsig_rr_find(tsig_rr_type *trr, buffer_type *buffer)
tsig_algo_type * tsig_lookup_algo(const char *name)
void xfrd_set_timer_retry(xfrd_type *xfrd)
void xfrd_set_timer_refresh(xfrd_type *xfrd)
void xfrd_set_timer_now(xfrd_type *xfrd)
socklen_t xfrd_acl_sockaddr_to(acl_type *acl, struct sockaddr_storage *to)
xfrd_type * xfrd_create(xfrhandler_type *xfrhandler, zone_type *zone)
void xfrd_cleanup(xfrd_type *xfrd, int backup)
#define XFRD_TSIG_MAX_UNSIGNED
#define XFRD_NO_IXFR_CACHE
enum xfrd_pkt_enum xfrd_pkt_status
time_t xfrhandler_time(xfrhandler_type *xfrhandler)