43 #define AXFR_TSIG_SIGN_EVERY_NTH 96
57 ldns_rdf* prev = NULL;
58 ldns_rdf* orig = NULL;
61 ldns_status status = LDNS_STATUS_OK;
67 ods_log_assert(q->
zone);
69 ods_log_assert(engine);
70 xfrfile = ods_build_path(q->
zone->
name,
".axfr", 0, 1);
72 fd = ods_fopen(xfrfile, NULL,
"r");
75 ods_log_error(
"[%s] unable to open file %s for zone %s",
88 rr =
addns_read_rr(fd, line, &orig, &prev, &ttl, &status, &l);
91 ods_log_error(
"[%s] bad axfr zone %s, corrupted file",
axfr_str,
98 if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_SOA) {
99 ods_log_error(
"[%s] bad axfr zone %s, first rr is not soa",
109 expire += ldns_rdf2native_int32(ldns_rr_rdf(rr, SE_SOA_RDATA_EXPIRE));
110 if (expire < time_now()) {
111 ods_log_warning(
"[%s] zone %s expired at %lld, and it is now %lld: "
112 "not serving soa",
axfr_str, q->
zone->
name, (
long long)expire, (
long long)time_now());
121 ods_log_debug(
"[%s] set soa in response %s",
axfr_str,
127 ods_log_error(
"[%s] soa does not fit in response %s",
154 char* xfrfile = NULL;
156 ldns_rdf* prev = NULL;
157 ldns_rdf* orig = NULL;
158 uint16_t total_added = 0;
161 ldns_status status = LDNS_STATUS_OK;
167 ods_log_assert(q->
buffer);
168 ods_log_assert(q->
zone);
170 ods_log_assert(engine);
172 ods_log_debug(
"[%s] zone transfer %s completed",
axfr_str,
192 xfrfile = ods_build_path(q->
zone->
name,
".axfr", 0, 1);
194 q->
axfr_fd = ods_fopen(xfrfile, NULL,
"r");
197 ods_log_error(
"[%s] unable to open axfr file %s for zone %s",
199 free((
void*)xfrfile);
203 free((
void*)xfrfile);
212 ods_log_error(
"[%s] unable to read axfr for zone %s: "
222 ods_log_error(
"[%s] bad axfr zone %s, corrupted file",
230 if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_SOA) {
231 ods_log_error(
"[%s] bad axfr zone %s, first rr is not soa",
242 expire += ldns_rdf2native_int32(ldns_rr_rdf(rr, SE_SOA_RDATA_EXPIRE));
243 if (expire < time_now()) {
244 ods_log_warning(
"[%s] zone %s expired, not transferring zone",
255 ods_log_debug(
"[%s] set soa in axfr zone %s",
axfr_str,
263 ods_log_error(
"[%s] soa does not fit in axfr zone %s",
274 ods_log_debug(
"[%s] subsequent axfr packet zone %s",
axfr_str,
284 ods_log_error(
"[%s] unable to read axfr for zone %s: "
293 &status, &l)) != NULL) {
294 ods_log_deeebug(
"[%s] read rr at line %d",
axfr_str, l);
295 if (status != LDNS_STATUS_OK) {
298 ods_log_error(
"[%s] error reading rr at line %i (%s): %s",
299 axfr_str, l, ldns_get_errorstr_by_id(status), line);
307 ods_log_deeebug(
"[%s] add rr at line %d",
axfr_str, l);
312 ods_log_error(
"[%s] unable to read axfr for zone %s: "
323 ods_log_deeebug(
"[%s] rr at line %d does not fit",
axfr_str, l);
326 if (fseek(q->
axfr_fd, fpos, SEEK_SET) != 0) {
327 ods_log_error(
"[%s] unable to reset file position in axfr "
328 "file: fseek() failed (%s)",
axfr_str, strerror(errno));
348 ods_log_debug(
"[%s] return part axfr zone %s",
axfr_str,
363 ods_log_error(
"[%s] zone transfer %s not tcp",
axfr_str,
378 ods_log_debug(
"[%s] zone transfer %s udp overflow",
axfr_str,
391 char* xfrfile = NULL;
393 ldns_rdf* prev = NULL;
394 ldns_rdf* orig = NULL;
395 uint16_t total_added = 0;
398 ldns_status status = LDNS_STATUS_OK;
403 uint32_t new_serial = 0;
404 unsigned del_mode = 0;
405 unsigned soa_found = 0;
406 ods_log_assert(engine);
408 ods_log_assert(q->
buffer);
409 ods_log_assert(q->
zone);
427 xfrfile = ods_build_path(q->
zone->
name,
".ixfr", 0, 1);
429 q->
axfr_fd = ods_fopen(xfrfile, NULL,
"r");
432 ods_log_error(
"[%s] unable to open ixfr file %s for zone %s",
434 ods_log_info(
"[%s] axfr fallback zone %s",
axfr_str,
436 free((
void*)xfrfile);
438 return axfr(q, engine, 1);
440 free((
void*)xfrfile);
449 ods_log_error(
"[%s] unable to read ixfr for zone %s: ftell() "
451 ods_log_info(
"[%s] axfr fallback zone %s",
axfr_str,
456 return axfr(q, engine, 1);
462 ods_log_error(
"[%s] bad ixfr zone %s, corrupted file",
468 if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_SOA) {
469 ods_log_error(
"[%s] bad ixfr zone %s, first rr is not soa",
478 expire += ldns_rdf2native_int32(ldns_rr_rdf(rr, SE_SOA_RDATA_EXPIRE));
479 if (expire < time_now()) {
480 ods_log_warning(
"[%s] zone %s expired, not transferring zone",
490 new_serial = ldns_rdf2native_int32(
491 ldns_rr_rdf(rr, SE_SOA_RDATA_SERIAL));
495 ods_log_debug(
"[%s] set soa in ixfr zone %s",
axfr_str,
503 ods_log_error(
"[%s] soa does not fit in ixfr zone %s",
510 if (util_serial_gt(q->
serial, new_serial)) {
515 ods_log_debug(
"[%s] subsequent ixfr packet zone %s",
axfr_str,
526 ods_log_error(
"[%s] unable to read ixfr for zone %s: ftell() failed "
528 ods_log_info(
"[%s] axfr fallback zone %s",
axfr_str,
533 return axfr(q, engine, 1);
536 &status, &l)) != NULL) {
537 ods_log_deeebug(
"[%s] read rr at line %d",
axfr_str, l);
538 if (status != LDNS_STATUS_OK) {
541 ods_log_error(
"[%s] error reading rr at line %i (%s): %s",
542 axfr_str, l, ldns_get_errorstr_by_id(status), line);
545 if (ldns_rr_get_type(rr) == LDNS_RR_TYPE_SOA) {
546 del_mode = !del_mode;
549 if (del_mode && ldns_rr_get_type(rr) == LDNS_RR_TYPE_SOA &&
550 q->
serial == ldns_rdf2native_int32(
551 ldns_rr_rdf(rr, SE_SOA_RDATA_SERIAL))) {
554 ods_log_deeebug(
"[%s] soa serial %u not found for rr at line %d",
563 ods_log_deeebug(
"[%s] add rr at line %d",
axfr_str, l);
568 ods_log_error(
"[%s] unable to read ixfr for zone %s: ftell() "
570 ods_log_info(
"[%s] axfr fallback zone %s",
axfr_str,
575 return axfr(q, engine, 1);
580 ods_log_deeebug(
"[%s] rr at line %d does not fit",
axfr_str, l);
583 if (fseek(q->
axfr_fd, fpos, SEEK_SET) != 0) {
584 ods_log_error(
"[%s] unable to reset file position in ixfr "
585 "file: fseek() failed (%s)",
axfr_str, strerror(errno));
596 ods_log_warning(
"[%s] zone %s journal not found for serial %u",
628 return axfr(q, engine, 1);
ldns_rr * addns_read_rr(FILE *fd, char *line, ldns_rdf **orig, ldns_rdf **prev, uint32_t *ttl, ldns_status *status, unsigned int *l)
#define SE_ADFILE_MAXLINE
query_state ixfr(query_type *q, engine_type *engine)
query_state axfr(query_type *q, engine_type *engine, int fallback)
query_state soa_request(query_type *q, engine_type *engine)
#define AXFR_TSIG_SIGN_EVERY_NTH
#define AXFR_MAX_MESSAGE_LEN
void buffer_pkt_set_rcode(buffer_type *buffer, ldns_pkt_rcode rcode)
void buffer_set_limit(buffer_type *buffer, size_t limit)
void buffer_set_position(buffer_type *buffer, size_t pos)
size_t buffer_position(buffer_type *buffer)
void buffer_pkt_set_nscount(buffer_type *buffer, uint16_t count)
void buffer_pkt_set_ancount(buffer_type *buffer, uint16_t count)
void buffer_pkt_set_aa(buffer_type *buffer)
uint16_t buffer_pkt_ancount(buffer_type *buffer)
void buffer_pkt_set_arcount(buffer_type *buffer, uint16_t count)
void buffer_pkt_set_qdcount(buffer_type *buffer, uint16_t count)
#define BUFFER_PKT_HEADER_SIZE
void query_prepare(query_type *q)
int query_add_rr(query_type *q, ldns_rr *rr)
enum query_enum query_state
size_t update_since_last_prepare
time_t serial_xfr_acquired