Lines Matching +full:num +full:- +full:transfer +full:- +full:bits

2  * services/authzone.c - authoritative zone that is locally hosted.
85 /* auth transfer timeout for TCP connections, in msec */
87 /* auth transfer max backoff for failed transfers and probes */
99 /** pick up nextprobe task to start waiting to perform transfer actions */
106 * or transfer task if nothing to probe, or false if already in progress */
120 msg->qinfo.qname = regional_alloc_init(region, qinfo->qname, in msg_create()
121 qinfo->qname_len); in msg_create()
122 if(!msg->qinfo.qname) in msg_create()
124 msg->qinfo.qname_len = qinfo->qname_len; in msg_create()
125 msg->qinfo.qtype = qinfo->qtype; in msg_create()
126 msg->qinfo.qclass = qinfo->qclass; in msg_create()
127 msg->qinfo.local_alias = NULL; in msg_create()
128 /* non-packed reply_info, because it needs to grow the array */ in msg_create()
129 msg->rep = (struct reply_info*)regional_alloc_zero(region, in msg_create()
130 sizeof(struct reply_info)-sizeof(struct rrset_ref)); in msg_create()
131 if(!msg->rep) in msg_create()
133 msg->rep->flags = (uint16_t)(BIT_QR | BIT_AA); in msg_create()
134 msg->rep->authoritative = 1; in msg_create()
135 msg->rep->reason_bogus = LDNS_EDE_NONE; in msg_create()
136 msg->rep->qdcount = 1; in msg_create()
145 if(msg->rep->rrsets == NULL) { in msg_grow_array()
146 msg->rep->rrsets = regional_alloc_zero(region, in msg_grow_array()
147 sizeof(struct ub_packed_rrset_key*)*(msg->rep->rrset_count+1)); in msg_grow_array()
148 if(!msg->rep->rrsets) in msg_grow_array()
151 struct ub_packed_rrset_key** rrsets_old = msg->rep->rrsets; in msg_grow_array()
152 msg->rep->rrsets = regional_alloc_zero(region, in msg_grow_array()
153 sizeof(struct ub_packed_rrset_key*)*(msg->rep->rrset_count+1)); in msg_grow_array()
154 if(!msg->rep->rrsets) in msg_grow_array()
156 memmove(msg->rep->rrsets, rrsets_old, in msg_grow_array()
157 sizeof(struct ub_packed_rrset_key*)*msg->rep->rrset_count); in msg_grow_array()
167 k->entry.data; in get_rrset_ttl()
168 return d->ttl; in get_rrset_ttl()
171 /** Copy rrset into region from domain-datanode and packet rrset */
179 key.entry.data = rrset->data; in auth_packed_rrset_copy_region()
180 key.rk.dname = node->name; in auth_packed_rrset_copy_region()
181 key.rk.dname_len = node->namelen; in auth_packed_rrset_copy_region()
182 key.rk.type = htons(rrset->type); in auth_packed_rrset_copy_region()
183 key.rk.rrset_class = htons(z->dclass); in auth_packed_rrset_copy_region()
188 /** fix up msg->rep TTL and prefetch ttl */
192 if(msg->rep->rrset_count == 0) return; in msg_ttl()
193 if(msg->rep->rrset_count == 1) { in msg_ttl()
194 msg->rep->ttl = get_rrset_ttl(msg->rep->rrsets[0]); in msg_ttl()
195 msg->rep->prefetch_ttl = PREFETCH_TTL_CALC(msg->rep->ttl); in msg_ttl()
196 msg->rep->serve_expired_ttl = msg->rep->ttl + SERVE_EXPIRED_TTL; in msg_ttl()
197 } else if(get_rrset_ttl(msg->rep->rrsets[msg->rep->rrset_count-1]) < in msg_ttl()
198 msg->rep->ttl) { in msg_ttl()
199 msg->rep->ttl = get_rrset_ttl(msg->rep->rrsets[ in msg_ttl()
200 msg->rep->rrset_count-1]); in msg_ttl()
201 msg->rep->prefetch_ttl = PREFETCH_TTL_CALC(msg->rep->ttl); in msg_ttl()
202 msg->rep->serve_expired_ttl = msg->rep->ttl + SERVE_EXPIRED_TTL; in msg_ttl()
212 for(i=0; i<msg->rep->rrset_count; i++) { in msg_rrset_duplicate()
213 struct ub_packed_rrset_key* k = msg->rep->rrsets[i]; in msg_rrset_duplicate()
214 if(ntohs(k->rk.type) == type && k->rk.dname_len == nmlen && in msg_rrset_duplicate()
215 ntohs(k->rk.rrset_class) == dclass && in msg_rrset_duplicate()
216 query_dname_compare(k->rk.dname, nm) == 0) in msg_rrset_duplicate()
227 log_assert(msg->rep->ns_numrrsets == 0); in msg_add_rrset_an()
228 log_assert(msg->rep->ar_numrrsets == 0); in msg_add_rrset_an()
231 if(msg_rrset_duplicate(msg, node->name, node->namelen, rrset->type, in msg_add_rrset_an()
232 z->dclass)) in msg_add_rrset_an()
238 if(!(msg->rep->rrsets[msg->rep->rrset_count] = in msg_add_rrset_an()
241 msg->rep->rrset_count++; in msg_add_rrset_an()
242 msg->rep->an_numrrsets++; in msg_add_rrset_an()
252 log_assert(msg->rep->ar_numrrsets == 0); in msg_add_rrset_ns()
255 if(msg_rrset_duplicate(msg, node->name, node->namelen, rrset->type, in msg_add_rrset_ns()
256 z->dclass)) in msg_add_rrset_ns()
262 if(!(msg->rep->rrsets[msg->rep->rrset_count] = in msg_add_rrset_ns()
265 msg->rep->rrset_count++; in msg_add_rrset_ns()
266 msg->rep->ns_numrrsets++; in msg_add_rrset_ns()
278 if(msg_rrset_duplicate(msg, node->name, node->namelen, rrset->type, in msg_add_rrset_ar()
279 z->dclass)) in msg_add_rrset_ar()
285 if(!(msg->rep->rrsets[msg->rep->rrset_count] = in msg_add_rrset_ar()
288 msg->rep->rrset_count++; in msg_add_rrset_ar()
289 msg->rep->ar_numrrsets++; in msg_add_rrset_ar()
301 rbtree_init(&az->ztree, &auth_zone_cmp); in auth_zones_create()
302 rbtree_init(&az->xtree, &auth_xfer_cmp); in auth_zones_create()
303 lock_rw_init(&az->lock); in auth_zones_create()
304 lock_protect(&az->lock, &az->ztree, sizeof(az->ztree)); in auth_zones_create()
305 lock_protect(&az->lock, &az->xtree, sizeof(az->xtree)); in auth_zones_create()
307 lock_rw_init(&az->rpz_lock); in auth_zones_create()
308 lock_protect(&az->rpz_lock, &az->rpz_first, sizeof(az->rpz_first)); in auth_zones_create()
319 if(a->dclass != b->dclass) { in auth_zone_cmp()
320 if(a->dclass < b->dclass) in auth_zone_cmp()
321 return -1; in auth_zone_cmp()
326 return dname_lab_cmp(a->name, a->namelabs, b->name, b->namelabs, &m); in auth_zone_cmp()
335 return dname_canon_lab_cmp(a->name, a->namelabs, b->name, in auth_data_cmp()
336 b->namelabs, &m); in auth_data_cmp()
346 if(a->dclass != b->dclass) { in auth_xfer_cmp()
347 if(a->dclass < b->dclass) in auth_xfer_cmp()
348 return -1; in auth_xfer_cmp()
353 return dname_lab_cmp(a->name, a->namelabs, b->name, b->namelabs, &m); in auth_xfer_cmp()
361 free(rrset->data); in auth_rrset_delete()
371 p = n->rrsets; in auth_data_delete()
373 np = p->next; in auth_data_delete()
377 free(n->name); in auth_data_delete()
385 struct auth_data* z = (struct auth_data*)n->key; in auth_data_del()
394 lock_rw_destroy(&z->lock); in auth_zone_delete()
395 traverse_postorder(&z->data, auth_data_del, NULL); in auth_zone_delete()
397 if(az && z->rpz) { in auth_zone_delete()
399 lock_rw_wrlock(&az->rpz_lock); in auth_zone_delete()
400 if(z->rpz_az_prev) in auth_zone_delete()
401 z->rpz_az_prev->rpz_az_next = z->rpz_az_next; in auth_zone_delete()
403 az->rpz_first = z->rpz_az_next; in auth_zone_delete()
404 if(z->rpz_az_next) in auth_zone_delete()
405 z->rpz_az_next->rpz_az_prev = z->rpz_az_prev; in auth_zone_delete()
406 lock_rw_unlock(&az->rpz_lock); in auth_zone_delete()
408 if(z->rpz) in auth_zone_delete()
409 rpz_delete(z->rpz); in auth_zone_delete()
410 free(z->name); in auth_zone_delete()
411 free(z->zonefile); in auth_zone_delete()
423 z->node.key = z; in auth_zone_create()
424 z->dclass = dclass; in auth_zone_create()
425 z->namelen = nmlen; in auth_zone_create()
426 z->namelabs = dname_count_labels(nm); in auth_zone_create()
427 z->name = memdup(nm, nmlen); in auth_zone_create()
428 if(!z->name) { in auth_zone_create()
432 rbtree_init(&z->data, &auth_data_cmp); in auth_zone_create()
433 lock_rw_init(&z->lock); in auth_zone_create()
434 lock_protect(&z->lock, &z->name, sizeof(*z)-sizeof(rbnode_type)- in auth_zone_create()
435 sizeof(&z->rpz_az_next)-sizeof(&z->rpz_az_prev)); in auth_zone_create()
436 lock_rw_wrlock(&z->lock); in auth_zone_create()
438 * pointers, which are protected using az->lock */ in auth_zone_create()
439 if(!rbtree_insert(&az->ztree, &z->node)) { in auth_zone_create()
440 lock_rw_unlock(&z->lock); in auth_zone_create()
458 return (struct auth_zone*)rbtree_search(&az->ztree, &key); in auth_zone_find()
471 return (struct auth_xfer*)rbtree_search(&az->xtree, &key); in auth_xfer_find()
474 /** find an auth zone or sorted less-or-equal, return true if exact */
485 return rbtree_find_less_equal(&az->ztree, &key, (rbnode_type**)z); in auth_zone_find_less_equal()
501 /* less-or-nothing */ in auth_zones_find_zone()
505 nm = dname_get_shared_topdomain(z->name, name); in auth_zones_find_zone()
538 lock_rw_wrlock(&z->lock); in auth_zones_find_or_add_zone()
549 x = auth_xfer_find(az, z->name, z->namelen, z->dclass); in auth_zones_find_or_add_xfer()
554 lock_basic_lock(&x->lock); in auth_zones_find_or_add_xfer()
562 if(z->zonefile) free(z->zonefile); in auth_zone_set_zonefile()
564 z->zonefile = NULL; in auth_zone_set_zonefile()
566 z->zonefile = strdup(zonefile); in auth_zone_set_zonefile()
567 if(!z->zonefile) { in auth_zone_set_zonefile()
584 z->fallback_enabled = (strcmp(fallbackstr, "yes")==0); in auth_zone_set_fallback()
595 n->node.key = n; in az_domain_create()
596 n->name = memdup(nm, nmlen); in az_domain_create()
597 if(!n->name) { in az_domain_create()
601 n->namelen = nmlen; in az_domain_create()
602 n->namelabs = dname_count_labels(nm); in az_domain_create()
603 if(!rbtree_insert(&z->data, &n->node)) { in az_domain_create()
605 free(n->name); in az_domain_create()
621 return (struct auth_data*)rbtree_search(&z->data, &key); in az_find_name()
631 key.name = qinfo->qname; in az_find_domain()
632 key.namelen = qinfo->qname_len; in az_find_domain()
634 *node_exact = rbtree_find_less_equal(&z->data, &key, in az_find_domain()
656 rrset = n->rrsets; in az_domain_rrset()
658 if(rrset->type == t) in az_domain_rrset()
660 rrset = rrset->next; in az_domain_rrset()
672 rrset = node->rrsets; in domain_remove_rrset()
674 if(rrset->type == rr_type) { in domain_remove_rrset()
676 if(prev) prev->next = rrset->next; in domain_remove_rrset()
677 else node->rrsets = rrset->next; in domain_remove_rrset()
682 rrset = rrset->next; in domain_remove_rrset()
692 for(i=d->count; i<d->count + d->rrsig_count; i++) { in az_rrset_find_rrsig()
693 if(d->rr_len[i] != len) in az_rrset_find_rrsig()
695 if(memcmp(d->rr_data[i], rdata, len) == 0) { in az_rrset_find_rrsig()
708 for(i=0; i<d->count + d->rrsig_count; i++) { in rdata_duplicate()
709 if(d->rr_len[i] != len) in rdata_duplicate()
711 if(memcmp(d->rr_data[i], rdata, len) == 0) in rdata_duplicate()
735 struct packed_rrset_data* d, *old = rrset->data; in rrset_remove_rr()
737 if(index >= old->count + old->rrsig_count) in rrset_remove_rr()
739 d = (struct packed_rrset_data*)calloc(1, packed_rrset_sizeof(old) - ( in rrset_remove_rr()
741 old->rr_len[index])); in rrset_remove_rr()
746 d->ttl = old->ttl; in rrset_remove_rr()
747 d->count = old->count; in rrset_remove_rr()
748 d->rrsig_count = old->rrsig_count; in rrset_remove_rr()
749 if(index < d->count) d->count--; in rrset_remove_rr()
750 else d->rrsig_count--; in rrset_remove_rr()
751 d->trust = old->trust; in rrset_remove_rr()
752 d->security = old->security; in rrset_remove_rr()
755 d->rr_len = (size_t*)((uint8_t*)d + in rrset_remove_rr()
758 memmove(d->rr_len, old->rr_len, (index)*sizeof(size_t)); in rrset_remove_rr()
759 if(index+1 < old->count+old->rrsig_count) in rrset_remove_rr()
760 memmove(&d->rr_len[index], &old->rr_len[index+1], in rrset_remove_rr()
761 (old->count+old->rrsig_count - (index+1))*sizeof(size_t)); in rrset_remove_rr()
766 memmove(d->rr_ttl, old->rr_ttl, (index)*sizeof(time_t)); in rrset_remove_rr()
767 if(index+1 < old->count+old->rrsig_count) in rrset_remove_rr()
768 memmove(&d->rr_ttl[index], &old->rr_ttl[index+1], in rrset_remove_rr()
769 (old->count+old->rrsig_count - (index+1))*sizeof(time_t)); in rrset_remove_rr()
772 for(i=0; i<d->count+d->rrsig_count; i++) { in rrset_remove_rr()
776 memmove(d->rr_data[i], old->rr_data[oldi], d->rr_len[i]); in rrset_remove_rr()
780 if(d->count + d->rrsig_count > 0) in rrset_remove_rr()
781 d->ttl = d->rr_ttl[0]; in rrset_remove_rr()
782 for(i=0; i<d->count+d->rrsig_count; i++) { in rrset_remove_rr()
783 if(d->rr_ttl[i] < d->ttl) in rrset_remove_rr()
784 d->ttl = d->rr_ttl[i]; in rrset_remove_rr()
787 free(rrset->data); in rrset_remove_rr()
788 rrset->data = d; in rrset_remove_rr()
798 struct packed_rrset_data* d, *old = rrset->data; in rrset_add_rr()
811 d->count++; in rrset_add_rr()
813 d->rrsig_count++; in rrset_add_rr()
815 old_total = old->count + old->rrsig_count; in rrset_add_rr()
816 total = d->count + d->rrsig_count; in rrset_add_rr()
818 d->rr_len = (size_t*)((uint8_t*)d + in rrset_add_rr()
820 if(old->count != 0) in rrset_add_rr()
821 memmove(d->rr_len, old->rr_len, old->count*sizeof(size_t)); in rrset_add_rr()
822 if(old->rrsig_count != 0) in rrset_add_rr()
823 memmove(d->rr_len+d->count, old->rr_len+old->count, in rrset_add_rr()
824 old->rrsig_count*sizeof(size_t)); in rrset_add_rr()
826 d->rr_len[d->count-1] = rdatalen; in rrset_add_rr()
827 else d->rr_len[total-1] = rdatalen; in rrset_add_rr()
829 if((time_t)rr_ttl < d->ttl) in rrset_add_rr()
830 d->ttl = rr_ttl; in rrset_add_rr()
833 if(old->count != 0) { in rrset_add_rr()
834 memmove(d->rr_ttl, old->rr_ttl, old->count*sizeof(time_t)); in rrset_add_rr()
837 memmove(d->rr_data[0], old->rr_data[0], in rrset_add_rr()
838 (old->rr_data[old->count-1] - old->rr_data[0]) + in rrset_add_rr()
839 old->rr_len[old->count-1]); in rrset_add_rr()
841 if(old->rrsig_count != 0) { in rrset_add_rr()
842 memmove(d->rr_ttl+d->count, old->rr_ttl+old->count, in rrset_add_rr()
843 old->rrsig_count*sizeof(time_t)); in rrset_add_rr()
844 memmove(d->rr_data[d->count], old->rr_data[old->count], in rrset_add_rr()
845 (old->rr_data[old_total-1] - old->rr_data[old->count]) + in rrset_add_rr()
846 old->rr_len[old_total-1]); in rrset_add_rr()
851 d->rr_ttl[d->count-1] = rr_ttl; in rrset_add_rr()
852 memmove(d->rr_data[d->count-1], rdata, rdatalen); in rrset_add_rr()
854 d->rr_ttl[total-1] = rr_ttl; in rrset_add_rr()
855 memmove(d->rr_data[total-1], rdata, rdatalen); in rrset_add_rr()
858 rrset->data = d; in rrset_add_rr()
876 rrset->type = rr_type; in rrset_create()
887 rrset->data = d; in rrset_create()
888 d->ttl = rr_ttl; in rrset_create()
889 d->trust = rrset_trust_prim_noglue; in rrset_create()
890 d->rr_len = (size_t*)((uint8_t*)d + sizeof(struct packed_rrset_data)); in rrset_create()
891 d->rr_data = (uint8_t**)&(d->rr_len[1]); in rrset_create()
892 d->rr_ttl = (time_t*)&(d->rr_data[1]); in rrset_create()
893 d->rr_data[0] = (uint8_t*)&(d->rr_ttl[1]); in rrset_create()
896 d->rr_len[0] = rdatalen; in rrset_create()
897 d->rr_ttl[0] = rr_ttl; in rrset_create()
898 memmove(d->rr_data[0], rdata, rdatalen); in rrset_create()
899 d->count++; in rrset_create()
904 p = node->rrsets; in rrset_create()
905 while(p && p->type<=rr_type) { in rrset_create()
907 p = p->next; in rrset_create()
910 rrset->next = p; in rrset_create()
911 if(prev) prev->next = rrset; in rrset_create()
912 else node->rrsets = rrset; in rrset_create()
920 struct packed_rrset_data* d = rrsig->data; in rrsig_num_that_cover()
921 size_t i, num = 0; in rrsig_num_that_cover() local
923 log_assert(d && rrsig->type == LDNS_RR_TYPE_RRSIG); in rrsig_num_that_cover()
924 for(i=0; i<d->count+d->rrsig_count; i++) { in rrsig_num_that_cover()
925 if(rrsig_rdata_get_type_covered(d->rr_data[i], in rrsig_num_that_cover()
926 d->rr_len[i]) == rr_type) { in rrsig_num_that_cover()
927 num++; in rrsig_num_that_cover()
928 (*sigsz) += d->rr_len[i]; in rrsig_num_that_cover()
931 return num; in rrsig_num_that_cover()
940 struct packed_rrset_data* sigold = rrsig->data; in rrset_moveover_rrsigs()
941 struct packed_rrset_data* old = rrset->data; in rrset_moveover_rrsigs()
944 log_assert(rrset->type == rr_type); in rrset_moveover_rrsigs()
945 log_assert(rrsig->type == LDNS_RR_TYPE_RRSIG); in rrset_moveover_rrsigs()
962 total = old->count + old->rrsig_count; in rrset_moveover_rrsigs()
964 d->rrsig_count += sigs; in rrset_moveover_rrsigs()
966 d->rr_len = (size_t*)((uint8_t*)d + in rrset_moveover_rrsigs()
969 memmove(d->rr_len, old->rr_len, total*sizeof(size_t)); in rrset_moveover_rrsigs()
970 j = d->count+d->rrsig_count-sigs; in rrset_moveover_rrsigs()
971 for(i=0; i<sigold->count+sigold->rrsig_count; i++) { in rrset_moveover_rrsigs()
972 if(rrsig_rdata_get_type_covered(sigold->rr_data[i], in rrset_moveover_rrsigs()
973 sigold->rr_len[i]) == rr_type) { in rrset_moveover_rrsigs()
974 d->rr_len[j] = sigold->rr_len[i]; in rrset_moveover_rrsigs()
982 memmove(d->rr_ttl, old->rr_ttl, total*sizeof(time_t)); in rrset_moveover_rrsigs()
985 memmove(d->rr_data[0], old->rr_data[0], in rrset_moveover_rrsigs()
986 (old->rr_data[total-1] - old->rr_data[0]) + in rrset_moveover_rrsigs()
987 old->rr_len[total-1]); in rrset_moveover_rrsigs()
991 j = d->count+d->rrsig_count-sigs; in rrset_moveover_rrsigs()
992 for(i=0; i<sigold->count+sigold->rrsig_count; i++) { in rrset_moveover_rrsigs()
993 if(rrsig_rdata_get_type_covered(sigold->rr_data[i], in rrset_moveover_rrsigs()
994 sigold->rr_len[i]) == rr_type) { in rrset_moveover_rrsigs()
996 d->rr_ttl[j] = sigold->rr_ttl[i]; in rrset_moveover_rrsigs()
997 memmove(d->rr_data[j], sigold->rr_data[i], in rrset_moveover_rrsigs()
998 sigold->rr_len[i]); in rrset_moveover_rrsigs()
999 if(d->rr_ttl[j] < d->ttl) in rrset_moveover_rrsigs()
1000 d->ttl = d->rr_ttl[j]; in rrset_moveover_rrsigs()
1006 rrset->data = d; in rrset_moveover_rrsigs()
1010 if(sigold->count+sigold->rrsig_count == sigs) { in rrset_moveover_rrsigs()
1018 - sigs*(sizeof(size_t) + sizeof(uint8_t*) + sizeof(time_t)) in rrset_moveover_rrsigs()
1019 - sigsz); in rrset_moveover_rrsigs()
1022 * node->rrset structure */ in rrset_moveover_rrsigs()
1029 sigd->count -= sigs; in rrset_moveover_rrsigs()
1031 sigd->rr_len = (size_t*)((uint8_t*)sigd + in rrset_moveover_rrsigs()
1034 for(i=0; i<sigold->count+sigold->rrsig_count; i++) { in rrset_moveover_rrsigs()
1035 if(rrsig_rdata_get_type_covered(sigold->rr_data[i], in rrset_moveover_rrsigs()
1036 sigold->rr_len[i]) != rr_type) { in rrset_moveover_rrsigs()
1037 sigd->rr_len[j] = sigold->rr_len[i]; in rrset_moveover_rrsigs()
1045 for(i=0; i<sigold->count+sigold->rrsig_count; i++) { in rrset_moveover_rrsigs()
1046 if(rrsig_rdata_get_type_covered(sigold->rr_data[i], in rrset_moveover_rrsigs()
1047 sigold->rr_len[i]) != rr_type) { in rrset_moveover_rrsigs()
1049 sigd->rr_ttl[j] = sigold->rr_ttl[i]; in rrset_moveover_rrsigs()
1050 memmove(sigd->rr_data[j], sigold->rr_data[i], in rrset_moveover_rrsigs()
1051 sigold->rr_len[i]); in rrset_moveover_rrsigs()
1052 if(j==0) sigd->ttl = sigd->rr_ttl[j]; in rrset_moveover_rrsigs()
1054 if(sigd->rr_ttl[j] < sigd->ttl) in rrset_moveover_rrsigs()
1055 sigd->ttl = sigd->rr_ttl[j]; in rrset_moveover_rrsigs()
1062 rrsig->data = sigd; in rrset_moveover_rrsigs()
1075 if(rrset->data->rrsig_count == 0) in rrsigs_copy_from_rrset_to_rrsigset()
1080 for(i=rrset->data->count; in rrsigs_copy_from_rrset_to_rrsigset()
1081 i<rrset->data->count+rrset->data->rrsig_count; i++) { in rrsigs_copy_from_rrset_to_rrsigset()
1082 uint8_t* rdata = rrset->data->rr_data[i]; in rrsigs_copy_from_rrset_to_rrsigset()
1083 size_t rdatalen = rrset->data->rr_len[i]; in rrsigs_copy_from_rrset_to_rrsigset()
1084 time_t rr_ttl = rrset->data->rr_ttl[i]; in rrsigs_copy_from_rrset_to_rrsigset()
1086 if(rdata_duplicate(rrsigset->data, rdata, rdatalen)) { in rrsigs_copy_from_rrset_to_rrsigset()
1108 if(rdata_duplicate(rrset->data, rdata, rdatalen)) { in az_domain_add_rr()
1116 if(rdata_duplicate(rrset->data, rdata, rdatalen)) { in az_domain_add_rr()
1132 if(rdata_duplicate(rrset->data, rdata, rdatalen)) { in az_domain_add_rr()
1174 if(rr_class != z->dclass) { in az_insert_rr()
1187 if(z->rpz) { in az_insert_rr()
1188 if(!(rpz_insert_rr(z->rpz, z->name, z->namelen, dname, in az_insert_rr()
1207 if(packed_rrset_find_rr(rrset->data, rdata, rdatalen, &index)) { in az_domain_remove_rr()
1208 if(rrset->data->count == 1 && in az_domain_remove_rr()
1209 rrset->data->rrsig_count == 0) { in az_domain_remove_rr()
1212 } else if(rrset->data->count == 1 && in az_domain_remove_rr()
1213 rrset->data->rrsig_count != 0) { in az_domain_remove_rr()
1231 rrset->type = LDNS_RR_TYPE_RRSIG; in az_domain_remove_rr()
1232 rrset->data->count = rrset->data->rrsig_count; in az_domain_remove_rr()
1233 rrset->data->rrsig_count = 0; in az_domain_remove_rr()
1249 if(az_rrset_find_rrsig(rrset->data, rdata, rdatalen, in az_domain_remove_rr()
1251 /* rrsig should have d->count > 0, be in az_domain_remove_rr()
1282 if(rr_class != z->dclass) { in az_remove_rr()
1287 * zone transfer */ in az_remove_rr()
1304 if(node->rrsets == NULL) { in az_remove_rr()
1305 (void)rbtree_delete(&z->data, node); in az_remove_rr()
1308 if(z->rpz) { in az_remove_rr()
1309 rpz_remove_rr(z->rpz, z->name, z->namelen, dname, dname_len, in az_remove_rr()
1333 (size_t)(dname - sldns_buffer_current(&pktbuf))); in decompress_rr_into_buffer()
1352 if(rdlen > 0 && desc && desc->_dname_count > 0) { in decompress_rr_into_buffer()
1353 int count = (int)desc->_dname_count; in decompress_rr_into_buffer()
1360 switch(desc->_wireformat[rdf]) { in decompress_rr_into_buffer()
1363 (size_t)(rd - in decompress_rr_into_buffer()
1380 &pktbuf) - oldpos; in decompress_rr_into_buffer()
1382 rdlen -= compressed_len; in decompress_rr_into_buffer()
1383 count--; in decompress_rr_into_buffer()
1390 len = get_rdf_size(desc->_wireformat[rdf]); in decompress_rr_into_buffer()
1398 rdlen -= len; in decompress_rr_into_buffer()
1410 sldns_buffer_position(buf)-rdlenpos-2); in decompress_rr_into_buffer()
1467 * @param state: parse state with $ORIGIN, $TTL and 'prev-dname' and so on,
1482 state->lineno = 1; in az_parse_file()
1494 int lineno_orig = state->lineno; in az_parse_file()
1498 "exceeded", fname, state->lineno); in az_parse_file()
1505 if(cfg->chrootdir && cfg->chrootdir[0] && in az_parse_file()
1506 strncmp(incfile, cfg->chrootdir, in az_parse_file()
1507 strlen(cfg->chrootdir)) == 0) in az_parse_file()
1508 incfile += strlen(cfg->chrootdir); in az_parse_file()
1539 state->lineno = lineno_orig; in az_parse_file()
1545 state->lineno, LDNS_WIREPARSE_OFFSET(status), in az_parse_file()
1559 fname, state->lineno, buf); in az_parse_file()
1573 if(!z || !z->zonefile || z->zonefile[0]==0) in auth_zone_read_zonefile()
1576 zfilename = z->zonefile; in auth_zone_read_zonefile()
1577 if(cfg->chrootdir && cfg->chrootdir[0] && strncmp(zfilename, in auth_zone_read_zonefile()
1578 cfg->chrootdir, strlen(cfg->chrootdir)) == 0) in auth_zone_read_zonefile()
1579 zfilename += strlen(cfg->chrootdir); in auth_zone_read_zonefile()
1582 dname_str(z->name, nm); in auth_zone_read_zonefile()
1587 char* n = sldns_wire2str_dname(z->name, z->namelen); in auth_zone_read_zonefile()
1588 if(z->zone_is_slave && errno == ENOENT) { in auth_zone_read_zonefile()
1602 traverse_postorder(&z->data, auth_data_del, NULL); in auth_zone_read_zonefile()
1603 rbtree_init(&z->data, &auth_data_cmp); in auth_zone_read_zonefile()
1605 if(z->rpz) in auth_zone_read_zonefile()
1606 rpz_clear(z->rpz); in auth_zone_read_zonefile()
1612 if(z->namelen <= sizeof(state.origin)) { in auth_zone_read_zonefile()
1613 memcpy(state.origin, z->name, z->namelen); in auth_zone_read_zonefile()
1614 state.origin_len = z->namelen; in auth_zone_read_zonefile()
1618 char* n = sldns_wire2str_dname(z->name, z->namelen); in auth_zone_read_zonefile()
1627 if(z->rpz) in auth_zone_read_zonefile()
1628 rpz_finish_config(z->rpz); in auth_zone_read_zonefile()
1658 if(i >= data->count) tp = LDNS_RR_TYPE_RRSIG; in auth_rr_to_string()
1663 w += sldns_str_print(&s, &slen, "%lu\t", (unsigned long)data->rr_ttl[i]); in auth_rr_to_string()
1668 datlen = data->rr_len[i]-2; in auth_rr_to_string()
1669 dat = data->rr_data[i]+2; in auth_rr_to_string()
1674 sldns_calc_keytag_raw(data->rr_data[i]+2, in auth_rr_to_string()
1675 data->rr_len[i]-2)); in auth_rr_to_string()
1691 size_t i, count = r->data->count + r->data->rrsig_count; in auth_zone_write_rrset()
1694 if(!auth_rr_to_string(node->name, node->namelen, r->type, in auth_zone_write_rrset()
1695 z->dclass, r->data, i, buf, sizeof(buf))) { in auth_zone_write_rrset()
1711 if(z->namelen == n->namelen) { in auth_zone_write_domain()
1719 for(r = n->rrsets; r; r = r->next) { in auth_zone_write_domain()
1720 if(z->namelen == n->namelen && in auth_zone_write_domain()
1721 r->type == LDNS_RR_TYPE_SOA) in auth_zone_write_domain()
1738 RBTREE_FOR(n, struct auth_data*, &z->data) { in auth_zone_write_file()
1759 if(!z->zonemd_check) in zonemd_offline_verify()
1762 env.scratch_buffer = sldns_buffer_new(env.cfg->msg_buffer_size); in zonemd_offline_verify()
1790 lock_rw_wrlock(&az->lock); in auth_zones_read_zones()
1791 RBTREE_FOR(z, struct auth_zone*, &az->ztree) { in auth_zones_read_zones()
1792 lock_rw_wrlock(&z->lock); in auth_zones_read_zones()
1794 lock_rw_unlock(&z->lock); in auth_zones_read_zones()
1795 lock_rw_unlock(&az->lock); in auth_zones_read_zones()
1798 if(z->zonefile && z->zonefile[0]!=0 && env) in auth_zones_read_zones()
1800 lock_rw_unlock(&z->lock); in auth_zones_read_zones()
1802 lock_rw_unlock(&az->lock); in auth_zones_read_zones()
1813 if(i >= zonemd_rrset->data->count) in zonemd_fetch_parameters()
1815 rr_len = zonemd_rrset->data->rr_len[i]; in zonemd_fetch_parameters()
1818 rdata = zonemd_rrset->data->rr_data[i]; in zonemd_fetch_parameters()
1822 *hashlen = rr_len - 8; in zonemd_fetch_parameters()
1842 for(j=0; j<zonemd_rrset->data->count; j++) { in zonemd_is_duplicate_scheme_hash()
1888 region = env->scratch; in auth_zone_zonemd_check_hash()
1890 buf = env->scratch_buffer; in auth_zone_zonemd_check_hash()
1896 apex = az_find_name(z, z->name, z->namelen); in auth_zone_zonemd_check_hash()
1902 if(!zonemd_rrset || zonemd_rrset->data->count==0) { in auth_zone_zonemd_check_hash()
1908 for(i=0; i<zonemd_rrset->data->count; i++) { in auth_zone_zonemd_check_hash()
1946 dname_str(z->name, zstr); in auth_zone_zonemd_check_hash()
1947 …verbose(VERB_ALGO, "auth-zone %s ZONEMD %d %d is unsupported: %s", zstr, (int)scheme, (int)hashalg… in auth_zone_zonemd_check_hash()
1954 dname_str(z->name, zstr); in auth_zone_zonemd_check_hash()
1956 verbose(VERB_ALGO, "auth-zone %s ZONEMD hash is correct", zstr); in auth_zone_zonemd_check_hash()
1977 dname_str(z->name, zstr); in auth_zone_zonemd_check_hash()
1978 verbose(VERB_ALGO, "auth-zone %s ZONEMD failed: %s", zstr, *reason); in auth_zone_zonemd_check_hash()
1988 apex = az_find_name(z, z->name, z->namelen); in auth_zone_get_soa_rrset()
2001 apex = az_find_name(z, z->name, z->namelen); in auth_zone_get_serial()
2004 if(!soa || soa->data->count==0) in auth_zone_get_serial()
2006 if(soa->data->rr_len[0] < 2+4*5) return 0; /* SOA too short */ in auth_zone_get_serial()
2007 d = soa->data; in auth_zone_get_serial()
2008 *serial = sldns_read_uint32(d->rr_data[0]+(d->rr_len[0]-20)); in auth_zone_get_serial()
2019 apex = az_find_name(z, z->name, z->namelen); in xfr_find_soa()
2022 if(!soa || soa->data->count==0) in xfr_find_soa()
2024 if(soa->data->rr_len[0] < 2+4*5) return 0; /* SOA too short */ in xfr_find_soa()
2027 d = soa->data; in xfr_find_soa()
2028 xfr->have_zone = 1; in xfr_find_soa()
2029 xfr->serial = sldns_read_uint32(d->rr_data[0]+(d->rr_len[0]-20)); in xfr_find_soa()
2030 xfr->refresh = sldns_read_uint32(d->rr_data[0]+(d->rr_len[0]-16)); in xfr_find_soa()
2031 xfr->retry = sldns_read_uint32(d->rr_data[0]+(d->rr_len[0]-12)); in xfr_find_soa()
2032 xfr->expiry = sldns_read_uint32(d->rr_data[0]+(d->rr_len[0]-8)); in xfr_find_soa()
2033 /* soa minimum at d->rr_len[0]-4 */ in xfr_find_soa()
2054 /* nothing for probe, nextprobe and transfer tasks */ in auth_xfer_setup()
2068 lock_rw_wrlock(&az->lock); in auth_zones_setup_zones()
2069 RBTREE_FOR(z, struct auth_zone*, &az->ztree) { in auth_zones_setup_zones()
2070 lock_rw_wrlock(&z->lock); in auth_zones_setup_zones()
2071 x = auth_xfer_find(az, z->name, z->namelen, z->dclass); in auth_zones_setup_zones()
2073 lock_basic_lock(&x->lock); in auth_zones_setup_zones()
2077 lock_basic_unlock(&x->lock); in auth_zones_setup_zones()
2079 lock_rw_unlock(&z->lock); in auth_zones_setup_zones()
2080 lock_rw_unlock(&az->lock); in auth_zones_setup_zones()
2084 lock_basic_unlock(&x->lock); in auth_zones_setup_zones()
2086 lock_rw_unlock(&z->lock); in auth_zones_setup_zones()
2088 lock_rw_unlock(&az->lock); in auth_zones_setup_zones()
2100 if(c->isrpz) { in auth_zones_cfg()
2103 lock_rw_wrlock(&az->rpz_lock); in auth_zones_cfg()
2105 lock_rw_wrlock(&az->lock); in auth_zones_cfg()
2106 if(!(z=auth_zones_find_or_add_zone(az, c->name))) { in auth_zones_cfg()
2107 lock_rw_unlock(&az->lock); in auth_zones_cfg()
2108 if(c->isrpz) { in auth_zones_cfg()
2109 lock_rw_unlock(&az->rpz_lock); in auth_zones_cfg()
2113 if(c->masters || c->urls) { in auth_zones_cfg()
2115 lock_rw_unlock(&az->lock); in auth_zones_cfg()
2116 lock_rw_unlock(&z->lock); in auth_zones_cfg()
2117 if(c->isrpz) { in auth_zones_cfg()
2118 lock_rw_unlock(&az->rpz_lock); in auth_zones_cfg()
2123 if(c->for_downstream) in auth_zones_cfg()
2124 az->have_downstream = 1; in auth_zones_cfg()
2125 lock_rw_unlock(&az->lock); in auth_zones_cfg()
2128 z->zone_deleted = 0; in auth_zones_cfg()
2129 if(!auth_zone_set_zonefile(z, c->zonefile)) { in auth_zones_cfg()
2131 lock_basic_unlock(&x->lock); in auth_zones_cfg()
2133 lock_rw_unlock(&z->lock); in auth_zones_cfg()
2134 if(c->isrpz) { in auth_zones_cfg()
2135 lock_rw_unlock(&az->rpz_lock); in auth_zones_cfg()
2139 z->for_downstream = c->for_downstream; in auth_zones_cfg()
2140 z->for_upstream = c->for_upstream; in auth_zones_cfg()
2141 z->fallback_enabled = c->fallback_enabled; in auth_zones_cfg()
2142 z->zonemd_check = c->zonemd_check; in auth_zones_cfg()
2143 z->zonemd_reject_absence = c->zonemd_reject_absence; in auth_zones_cfg()
2144 if(c->isrpz && !z->rpz){ in auth_zones_cfg()
2145 if(!(z->rpz = rpz_create(c))){ in auth_zones_cfg()
2149 lock_protect(&z->lock, &z->rpz->local_zones, sizeof(*z->rpz)); in auth_zones_cfg()
2150 /* the az->rpz_lock is locked above */ in auth_zones_cfg()
2151 z->rpz_az_next = az->rpz_first; in auth_zones_cfg()
2152 if(az->rpz_first) in auth_zones_cfg()
2153 az->rpz_first->rpz_az_prev = z; in auth_zones_cfg()
2154 az->rpz_first = z; in auth_zones_cfg()
2155 } else if(c->isrpz && z->rpz) { in auth_zones_cfg()
2156 if(!rpz_config(z->rpz, c)) { in auth_zones_cfg()
2159 lock_basic_unlock(&x->lock); in auth_zones_cfg()
2161 lock_rw_unlock(&z->lock); in auth_zones_cfg()
2162 lock_rw_unlock(&az->rpz_lock); in auth_zones_cfg()
2166 if(c->isrpz) { in auth_zones_cfg()
2167 lock_rw_unlock(&az->rpz_lock); in auth_zones_cfg()
2172 z->zone_is_slave = 1; in auth_zones_cfg()
2174 if(!xfer_set_masters(&x->task_probe->masters, c, 0)) { in auth_zones_cfg()
2175 lock_basic_unlock(&x->lock); in auth_zones_cfg()
2176 lock_rw_unlock(&z->lock); in auth_zones_cfg()
2179 if(!xfer_set_masters(&x->task_transfer->masters, c, 1)) { in auth_zones_cfg()
2180 lock_basic_unlock(&x->lock); in auth_zones_cfg()
2181 lock_rw_unlock(&z->lock); in auth_zones_cfg()
2184 lock_basic_unlock(&x->lock); in auth_zones_cfg()
2187 lock_rw_unlock(&z->lock); in auth_zones_cfg()
2198 lock_rw_wrlock(&az->lock); in az_setall_deleted()
2199 RBTREE_FOR(z, struct auth_zone*, &az->ztree) { in az_setall_deleted()
2200 lock_rw_wrlock(&z->lock); in az_setall_deleted()
2201 z->zone_deleted = 1; in az_setall_deleted()
2202 lock_rw_unlock(&z->lock); in az_setall_deleted()
2204 lock_rw_unlock(&az->lock); in az_setall_deleted()
2216 lock_rw_wrlock(&az->lock); in az_delete_deleted_zones()
2217 RBTREE_FOR(z, struct auth_zone*, &az->ztree) { in az_delete_deleted_zones()
2218 lock_rw_wrlock(&z->lock); in az_delete_deleted_zones()
2219 if(z->zone_deleted) { in az_delete_deleted_zones()
2223 z->delete_next = delete_list; in az_delete_deleted_zones()
2226 lock_rw_unlock(&z->lock); in az_delete_deleted_zones()
2232 next = z->delete_next; in az_delete_deleted_zones()
2233 xfr = auth_xfer_find(az, z->name, z->namelen, z->dclass); in az_delete_deleted_zones()
2235 (void)rbtree_delete(&az->xtree, &xfr->node); in az_delete_deleted_zones()
2238 (void)rbtree_delete(&az->ztree, &z->node); in az_delete_deleted_zones()
2242 lock_rw_unlock(&az->lock); in az_delete_deleted_zones()
2251 for(p = cfg->auths; p; p = p->next) { in auth_zones_apply_cfg()
2252 if(!p->name || p->name[0] == 0) { in auth_zones_apply_cfg()
2253 log_warn("auth-zone without a name, skipped"); in auth_zones_apply_cfg()
2256 *is_rpz = (*is_rpz || p->isrpz); in auth_zones_apply_cfg()
2258 log_err("cannot config auth zone %s", p->name); in auth_zones_apply_cfg()
2273 * @param at: transfer structure with chunks list. The chunks and their
2279 if(at->chunks_first) { in auth_chunks_delete()
2281 c = at->chunks_first; in auth_chunks_delete()
2283 cn = c->next; in auth_chunks_delete()
2284 free(c->data); in auth_chunks_delete()
2289 at->chunks_first = NULL; in auth_chunks_delete()
2290 at->chunks_last = NULL; in auth_chunks_delete()
2299 n = list->next; in auth_free_master_addrs()
2311 n = list->next; in auth_free_masters()
2312 auth_free_master_addrs(list->list); in auth_free_masters()
2313 free(list->host); in auth_free_masters()
2314 free(list->file); in auth_free_masters()
2327 lock_basic_destroy(&xfr->lock); in auth_xfer_delete()
2328 free(xfr->name); in auth_xfer_delete()
2329 if(xfr->task_nextprobe) { in auth_xfer_delete()
2330 comm_timer_delete(xfr->task_nextprobe->timer); in auth_xfer_delete()
2331 free(xfr->task_nextprobe); in auth_xfer_delete()
2333 if(xfr->task_probe) { in auth_xfer_delete()
2334 auth_free_masters(xfr->task_probe->masters); in auth_xfer_delete()
2335 comm_point_delete(xfr->task_probe->cp); in auth_xfer_delete()
2336 comm_timer_delete(xfr->task_probe->timer); in auth_xfer_delete()
2337 free(xfr->task_probe); in auth_xfer_delete()
2339 if(xfr->task_transfer) { in auth_xfer_delete()
2340 auth_free_masters(xfr->task_transfer->masters); in auth_xfer_delete()
2341 comm_point_delete(xfr->task_transfer->cp); in auth_xfer_delete()
2342 comm_timer_delete(xfr->task_transfer->timer); in auth_xfer_delete()
2343 if(xfr->task_transfer->chunks_first) { in auth_xfer_delete()
2344 auth_chunks_delete(xfr->task_transfer); in auth_xfer_delete()
2346 free(xfr->task_transfer); in auth_xfer_delete()
2348 auth_free_masters(xfr->allow_notify_list); in auth_xfer_delete()
2356 struct auth_zone* z = (struct auth_zone*)n->key; in auth_zone_del()
2364 struct auth_xfer* z = (struct auth_xfer*)n->key; in auth_xfer_del()
2371 lock_rw_destroy(&az->lock); in auth_zones_delete()
2372 lock_rw_destroy(&az->rpz_lock); in auth_zones_delete()
2373 traverse_postorder(&az->ztree, auth_zone_del, NULL); in auth_zones_delete()
2374 traverse_postorder(&az->xtree, auth_xfer_del, NULL); in auth_zones_delete()
2382 struct auth_rrset* rrset = n->rrsets; in domain_has_only_nsec3()
2385 if(rrset->type == LDNS_RR_TYPE_NSEC3) { in domain_has_only_nsec3()
2387 } else if(rrset->type != LDNS_RR_TYPE_RRSIG) { in domain_has_only_nsec3()
2390 rrset = rrset->next; in domain_has_only_nsec3()
2413 uint8_t* nm = qinfo->qname; in az_find_wildcard()
2414 size_t nmlen = qinfo->qname_len; in az_find_wildcard()
2416 if(!dname_subdomain_c(nm, z->name)) in az_find_wildcard()
2420 if(nmlen == z->namelen) in az_find_wildcard()
2422 if(ce && nmlen == ce->namelen) in az_find_wildcard()
2440 nm = dname_get_shared_topdomain(qinfo->qname, n->name); in az_find_candidate_ce()
2442 nm = qinfo->qname; in az_find_candidate_ce()
2460 uint8_t* nm = n->name; in az_domain_go_up()
2461 size_t nmlen = n->namelen; in az_domain_go_up()
2499 /* no direct answer from nsec3-only domains */ in az_find_ce()
2510 if(n->namelen != z->namelen && in az_find_ce()
2513 (qinfo->qtype != LDNS_RR_TYPE_DS || in az_find_ce()
2514 n->namelen != qinfo->qname_len)) { in az_find_ce()
2522 if(n->namelen != qinfo->qname_len && in az_find_ce()
2549 struct packed_rrset_data* d = rrset->data; in az_add_additionals_from()
2552 for(i=0; i<d->count; i++) { in az_add_additionals_from()
2556 if(d->rr_len[i] < 2+offset) in az_add_additionals_from()
2558 if(!(dlen = dname_valid(d->rr_data[i]+2+offset, in az_add_additionals_from()
2559 d->rr_len[i]-2-offset))) in az_add_additionals_from()
2561 domain = az_find_name(z, d->rr_data[i]+2+offset, dlen); in az_add_additionals_from()
2585 struct auth_data* apex = az_find_name(z, z->name, z->namelen); in az_add_negative_soa()
2592 log_assert(msg->rep->rrset_count == 0); in az_add_negative_soa()
2595 d = (struct packed_rrset_data*)msg->rep->rrsets[msg->rep->rrset_count-1]->entry.data; in az_add_negative_soa()
2597 if(d->count == 0) return 0; in az_add_negative_soa()
2598 if(d->rr_len[0] < 2+4) return 0; in az_add_negative_soa()
2599 minimum = (time_t)sldns_read_uint32(d->rr_data[0]+(d->rr_len[0]-4)); in az_add_negative_soa()
2600 minimum = d->ttl<minimum?d->ttl:minimum; in az_add_negative_soa()
2601 d->ttl = minimum; in az_add_negative_soa()
2602 for(i=0; i < d->count + d->rrsig_count; i++) in az_add_negative_soa()
2603 d->rr_ttl[i] = minimum; in az_add_negative_soa()
2604 msg->rep->ttl = get_rrset_ttl(msg->rep->rrsets[0]); in az_add_negative_soa()
2605 msg->rep->prefetch_ttl = PREFETCH_TTL_CALC(msg->rep->ttl); in az_add_negative_soa()
2606 msg->rep->serve_expired_ttl = msg->rep->ttl + SERVE_EXPIRED_TTL; in az_add_negative_soa()
2622 next = (struct auth_data*)rbtree_first(&z->data); in az_empty_nonterminal()
2624 next = (struct auth_data*)rbtree_next(&node->node); in az_empty_nonterminal()
2626 while(next && (rbnode_type*)next != RBTREE_NULL && next->rrsets == NULL) { in az_empty_nonterminal()
2629 next = (struct auth_data*)rbtree_next(&node->node); in az_empty_nonterminal()
2638 if(dname_strict_subdomain_c(next->name, qinfo->qname)) in az_empty_nonterminal()
2648 size_t newlen = qname_len + dtarglen - dname_len; in synth_cname_buf()
2655 memcpy(buf, qname, qname_len-dname_len); in synth_cname_buf()
2656 memmove(buf+(qname_len-dname_len), dtarg, dtarglen); in synth_cname_buf()
2673 if(dname->data->count < 1) return 0; in create_synth_cname()
2674 if(dname->data->rr_len[0] < 3) return 0; /* at least rdatalen +1 */ in create_synth_cname()
2675 dtarg = dname->data->rr_data[0]+2; in create_synth_cname()
2676 dtarglen = dname->data->rr_len[0]-2; in create_synth_cname()
2677 if(sldns_read_uint16(dname->data->rr_data[0]) != dtarglen) in create_synth_cname()
2683 if(qname_len <= node->namelen) in create_synth_cname()
2687 newlen = synth_cname_buf(qname, qname_len, node->namelen, in create_synth_cname()
2698 memset(&(*cname)->entry, 0, sizeof((*cname)->entry)); in create_synth_cname()
2699 (*cname)->entry.key = (*cname); in create_synth_cname()
2700 (*cname)->rk.type = htons(LDNS_RR_TYPE_CNAME); in create_synth_cname()
2701 (*cname)->rk.rrset_class = htons(dclass); in create_synth_cname()
2702 (*cname)->rk.flags = 0; in create_synth_cname()
2703 (*cname)->rk.dname = regional_alloc_init(region, qname, qname_len); in create_synth_cname()
2704 if(!(*cname)->rk.dname) in create_synth_cname()
2706 (*cname)->rk.dname_len = qname_len; in create_synth_cname()
2707 (*cname)->entry.hash = rrset_key_hash(&(*cname)->rk); in create_synth_cname()
2714 (*cname)->entry.data = d; in create_synth_cname()
2715 d->ttl = dname->data->ttl; /* RFC6672: synth CNAME TTL == DNAME TTL */ in create_synth_cname()
2716 d->count = 1; in create_synth_cname()
2717 d->rrsig_count = 0; in create_synth_cname()
2718 d->trust = rrset_trust_ans_noAA; in create_synth_cname()
2719 d->rr_len = (size_t*)((uint8_t*)d + in create_synth_cname()
2721 d->rr_len[0] = newlen + sizeof(uint16_t); in create_synth_cname()
2723 d->rr_ttl[0] = d->ttl; in create_synth_cname()
2724 sldns_write_uint16(d->rr_data[0], newlen); in create_synth_cname()
2725 memmove(d->rr_data[0] + sizeof(uint16_t), buf, newlen); in create_synth_cname()
2738 z->dclass, &cname)) { in add_synth_cname()
2744 msg->rep->flags |= LDNS_RCODE_YXDOMAIN; in add_synth_cname()
2750 msg->rep->rrsets[msg->rep->rrset_count] = cname; in add_synth_cname()
2751 msg->rep->rrset_count++; in add_synth_cname()
2752 msg->rep->an_numrrsets++; in add_synth_cname()
2763 size_t start = 0, end = msg->rep->rrset_count; in az_change_dnames()
2764 if(!an_only) start = msg->rep->an_numrrsets; in az_change_dnames()
2765 if(an_only) end = msg->rep->an_numrrsets; in az_change_dnames()
2768 if(query_dname_compare(msg->rep->rrsets[i]->rk.dname, oldname) in az_change_dnames()
2770 msg->rep->rrsets[i]->rk.dname = newname; in az_change_dnames()
2771 msg->rep->rrsets[i]->rk.dname_len = newlen; in az_change_dnames()
2772 msg->rep->rrsets[i]->entry.hash = rrset_key_hash(&msg->rep->rrsets[i]->rk); in az_change_dnames()
2781 uint8_t* nm = (*node)->name; in az_find_nsec_cover()
2782 size_t nmlen = (*node)->namelen; in az_find_nsec_cover()
2784 /* find the NSEC for the smallest-or-equal node */ in az_find_nsec_cover()
2788 /* for empty nonterminals, the auth-data node should not exist, in az_find_nsec_cover()
2792 * Go up to find nonglue (previous) NSEC-holding nodes */ in az_find_nsec_cover()
2795 if(nmlen == z->namelen) return NULL; in az_find_nsec_cover()
2840 apex = az_find_name(z, z->name, z->namelen); in az_nsec3_param()
2843 if(!param || param->data->count==0) in az_nsec3_param()
2847 for(i=0; i<param->data->count; i++) { in az_nsec3_param()
2848 uint8_t* rdata = param->data->rr_data[i]+2; in az_nsec3_param()
2849 size_t rdatalen = param->data->rr_len[i]; in az_nsec3_param()
2878 * (salt has 0-255 length) */ in az_nsec3_hash()
2915 if(*hashnmlen < hlen*2+1+z->namelen) /* approx b32 as hexb16 */ in az_nsec3_hashname()
2918 (*hashnmlen)-1); in az_nsec3_hashname()
2923 if((*hashnmlen) - ret < z->namelen) in az_nsec3_hashname()
2925 memmove(hashname+ret, z->name, z->namelen); in az_nsec3_hashname()
2926 *hashnmlen = z->namelen+(size_t)ret; in az_nsec3_hashname()
2930 /** Find the datanode that covers the nsec3hash-name */
2944 /* but we may have to skip non-nsec3 nodes */ in az_nsec3_findnode()
2949 node = (struct auth_data*)rbtree_previous(&node->node); in az_nsec3_findnode()
2972 node = (struct auth_data*)rbtree_last(&z->data); in az_nsec3_find_cover()
2975 node = (struct auth_data*)rbtree_previous(&node->node); in az_nsec3_find_cover()
3007 int strip = qlabs - celabs -1; in az_nsec3_get_nextcloser()
3016 * updated cenm to the new name. If it went up no-exact-ce is true. */
3024 if(*cenmlen == z->namelen) { in az_nsec3_find_ce()
3055 * (for some sort of opt-out empty nonterminal cases).
3135 if(rrset->type == LDNS_RR_TYPE_MX) { in az_generate_positive_answer()
3138 } else if(rrset->type == LDNS_RR_TYPE_SRV) { in az_generate_positive_answer()
3141 } else if(rrset->type == LDNS_RR_TYPE_NS) { in az_generate_positive_answer()
3172 if(added == 0 && node && node->rrsets) { in az_generate_any_answer()
3174 node->rrsets)) return 0; in az_generate_any_answer()
3192 if(d->count == 0) break; /* no CNAME */ in follow_cname_chain()
3193 if(d->rr_len[0] < 2+1) break; /* too small */ in follow_cname_chain()
3194 if((clen=dname_valid(d->rr_data[0]+2, d->rr_len[0]-2))==0) in follow_cname_chain()
3196 if(!dname_subdomain_c(d->rr_data[0]+2, z->name)) in follow_cname_chain()
3198 if((node = az_find_name(z, d->rr_data[0]+2, clen))==NULL) in follow_cname_chain()
3209 d = rrset->data; in follow_cname_chain()
3222 if(!follow_cname_chain(z, qinfo->qtype, region, msg, rrset->data)) in az_generate_cname_answer()
3239 if(!az_add_nsec3_proof(z, region, msg, node->name, in az_generate_notype_answer()
3240 node->namelen, msg->qinfo.qname, in az_generate_notype_answer()
3241 msg->qinfo.qname_len, 1, 1, 0, 0)) in az_generate_notype_answer()
3255 msg->rep->flags &= ~BIT_AA; in az_generate_referral_answer()
3266 if(!az_add_nsec3_proof(z, region, msg, ce->name, in az_generate_referral_answer()
3267 ce->namelen, msg->qinfo.qname, in az_generate_referral_answer()
3268 msg->qinfo.qname_len, 1, 1, 0, 0)) in az_generate_referral_answer()
3286 if(!add_synth_cname(z, qinfo->qname, qinfo->qname_len, region, in az_generate_dname_answer()
3288 if(FLAGS_GET_RCODE(msg->rep->flags) == LDNS_RCODE_YXDOMAIN) in az_generate_dname_answer()
3290 if(msg->rep->rrset_count == 0 || in az_generate_dname_answer()
3291 !msg->rep->rrsets[msg->rep->rrset_count-1]) in az_generate_dname_answer()
3293 if(!follow_cname_chain(z, qinfo->qtype, region, msg, in az_generate_dname_answer()
3294 (struct packed_rrset_data*)msg->rep->rrsets[ in az_generate_dname_answer()
3295 msg->rep->rrset_count-1]->entry.data)) in az_generate_dname_answer()
3308 if((rrset=az_domain_rrset(wildcard, qinfo->qtype)) != NULL) { in az_generate_wildcard_answer()
3312 az_change_dnames(msg, wildcard->name, msg->qinfo.qname, in az_generate_wildcard_answer()
3313 msg->qinfo.qname_len, 1); in az_generate_wildcard_answer()
3318 az_change_dnames(msg, wildcard->name, msg->qinfo.qname, in az_generate_wildcard_answer()
3319 msg->qinfo.qname_len, 1); in az_generate_wildcard_answer()
3320 if(!follow_cname_chain(z, qinfo->qtype, region, msg, in az_generate_wildcard_answer()
3321 rrset->data)) in az_generate_wildcard_answer()
3323 } else if(qinfo->qtype == LDNS_RR_TYPE_ANY && wildcard->rrsets) { in az_generate_wildcard_answer()
3327 az_change_dnames(msg, wildcard->name, msg->qinfo.qname, in az_generate_wildcard_answer()
3328 msg->qinfo.qname_len, 1); in az_generate_wildcard_answer()
3344 uint8_t* wildup = wildcard->name; in az_generate_wildcard_answer()
3345 size_t wilduplen= wildcard->namelen; in az_generate_wildcard_answer()
3348 wilduplen, msg->qinfo.qname, in az_generate_wildcard_answer()
3349 msg->qinfo.qname_len, 0, insert_ce, 1, 0)) in az_generate_wildcard_answer()
3355 az_change_dnames(msg, wildcard->name, msg->qinfo.qname, in az_generate_wildcard_answer()
3356 msg->qinfo.qname_len, 0); in az_generate_wildcard_answer()
3366 msg->rep->flags |= LDNS_RCODE_NXDOMAIN; in az_generate_nxdomain_answer()
3370 if(ce && !az_nsec_wildcard_denial(z, region, msg, ce->name, in az_generate_nxdomain_answer()
3371 ce->namelen)) return 0; in az_generate_nxdomain_answer()
3373 if(!az_add_nsec3_proof(z, region, msg, ce->name, in az_generate_nxdomain_answer()
3374 ce->namelen, msg->qinfo.qname, in az_generate_nxdomain_answer()
3375 msg->qinfo.qname_len, 0, 1, 1, 1)) in az_generate_nxdomain_answer()
3388 if((rrset=az_domain_rrset(node, qinfo->qtype)) != NULL) { in az_generate_answer_with_node()
3397 if(qinfo->qtype == LDNS_RR_TYPE_ANY) { in az_generate_answer_with_node()
3404 /** Generate answer without an existing-node that we can use.
3415 if(ce && rrset && rrset->type == LDNS_RR_TYPE_NS) { in az_generate_answer_nonexistnode()
3418 if(ce && rrset && rrset->type == LDNS_RR_TYPE_DNAME) { in az_generate_answer_nonexistnode()
3445 *fallback = z->fallback_enabled; in auth_zone_generate_answer()
3452 * obscured by NS or DNAME or NSEC3-only), and also return the in auth_zone_generate_answer()
3453 * closest-encloser from that, closest node that should be used in auth_zone_generate_answer()
3460 sldns_wire2str_dname_buf(qinfo->qname, qinfo->qname_len, qname, in auth_zone_generate_answer()
3462 sldns_wire2str_type_buf(qinfo->qtype, tpstr, sizeof(tpstr)); in auth_zone_generate_answer()
3463 sldns_wire2str_dname_buf(z->name, z->namelen, zname, in auth_zone_generate_answer()
3466 sldns_wire2str_dname_buf(node->name, node->namelen, in auth_zone_generate_answer()
3470 sldns_wire2str_dname_buf(ce->name, ce->namelen, in auth_zone_generate_answer()
3473 if(rrset) sldns_wire2str_type_buf(rrset->type, rrstr, in auth_zone_generate_answer()
3498 lock_rw_rdlock(&az->lock); in auth_zones_lookup()
3499 z = auth_zone_find(az, dp_nm, dp_nmlen, qinfo->qclass); in auth_zones_lookup()
3501 lock_rw_unlock(&az->lock); in auth_zones_lookup()
3506 lock_rw_rdlock(&z->lock); in auth_zones_lookup()
3507 lock_rw_unlock(&az->lock); in auth_zones_lookup()
3510 if(!z->for_upstream) { in auth_zones_lookup()
3511 lock_rw_unlock(&z->lock); in auth_zones_lookup()
3515 if(z->zone_expired) { in auth_zones_lookup()
3516 *fallback = z->fallback_enabled; in auth_zones_lookup()
3517 lock_rw_unlock(&z->lock); in auth_zones_lookup()
3522 lock_rw_unlock(&z->lock); in auth_zones_lookup()
3533 udpsize = edns->udp_size; in auth_answer_encode()
3534 edns->edns_version = EDNS_ADVERTISED_VERSION; in auth_answer_encode()
3535 edns->udp_size = EDNS_ADVERTISED_SIZE; in auth_answer_encode()
3536 edns->ext_rcode = 0; in auth_answer_encode()
3537 edns->bits &= EDNS_DO; in auth_answer_encode()
3539 if(!inplace_cb_reply_local_call(env, qinfo, NULL, msg->rep, in auth_answer_encode()
3540 (int)FLAGS_GET_RCODE(msg->rep->flags), edns, repinfo, temp, env->now_tv) in auth_answer_encode()
3541 || !reply_info_answer_encode(qinfo, msg->rep, in auth_answer_encode()
3545 (int)(edns->bits&EDNS_DO), 0)) { in auth_answer_encode()
3558 edns->edns_version = EDNS_ADVERTISED_VERSION; in auth_error_encode()
3559 edns->udp_size = EDNS_ADVERTISED_SIZE; in auth_error_encode()
3560 edns->ext_rcode = 0; in auth_error_encode()
3561 edns->bits &= EDNS_DO; in auth_error_encode()
3564 rcode, edns, repinfo, temp, env->now_tv)) in auth_error_encode()
3565 edns->opt_list_inplace_cb_out = NULL; in auth_error_encode()
3580 lock_rw_rdlock(&az->lock); in auth_zones_answer()
3581 if(!az->have_downstream) { in auth_zones_answer()
3583 lock_rw_unlock(&az->lock); in auth_zones_answer()
3586 if(qinfo->qtype == LDNS_RR_TYPE_DS) { in auth_zones_answer()
3587 uint8_t* delname = qinfo->qname; in auth_zones_answer()
3588 size_t delnamelen = qinfo->qname_len; in auth_zones_answer()
3591 qinfo->qclass); in auth_zones_answer()
3593 z = auth_zones_find_zone(az, qinfo->qname, qinfo->qname_len, in auth_zones_answer()
3594 qinfo->qclass); in auth_zones_answer()
3598 lock_rw_unlock(&az->lock); in auth_zones_answer()
3601 lock_rw_rdlock(&z->lock); in auth_zones_answer()
3602 lock_rw_unlock(&az->lock); in auth_zones_answer()
3603 if(!z->for_downstream) { in auth_zones_answer()
3604 lock_rw_unlock(&z->lock); in auth_zones_answer()
3607 if(z->zone_expired) { in auth_zones_answer()
3608 if(z->fallback_enabled) { in auth_zones_answer()
3609 lock_rw_unlock(&z->lock); in auth_zones_answer()
3612 lock_rw_unlock(&z->lock); in auth_zones_answer()
3613 lock_rw_wrlock(&az->lock); in auth_zones_answer()
3614 az->num_query_down++; in auth_zones_answer()
3615 lock_rw_unlock(&az->lock); in auth_zones_answer()
3623 lock_rw_unlock(&z->lock); in auth_zones_answer()
3628 lock_rw_wrlock(&az->lock); in auth_zones_answer()
3629 az->num_query_down++; in auth_zones_answer()
3630 lock_rw_unlock(&az->lock); in auth_zones_answer()
3646 lock_rw_rdlock(&az->lock); in auth_zones_can_fallback()
3649 lock_rw_unlock(&az->lock); in auth_zones_can_fallback()
3653 lock_rw_rdlock(&z->lock); in auth_zones_can_fallback()
3654 lock_rw_unlock(&az->lock); in auth_zones_can_fallback()
3655 r = z->fallback_enabled || (!z->for_upstream); in auth_zones_can_fallback()
3656 lock_rw_unlock(&z->lock); in auth_zones_can_fallback()
3681 sldns_buffer_skip(pkt, (ssize_t)(rdlen-20)); in auth_zone_parse_notify_serial()
3694 port = ntohs((uint16_t)sa->sin6_port); in addr_port_to_str()
3697 port = ntohs((uint16_t)sa->sin_port); in addr_port_to_str()
3716 for(p=list; p; p=p->next) { in addr_in_list()
3717 if(sockaddr_cmp_addr(addr, addrlen, &p->addr, p->addrlen)==0) in addr_in_list()
3732 if(addr_in_list(master->list, addr, addrlen)) { in addr_matches_master()
3739 if(extstrtoaddr(master->host, &a, &alen, UNBOUND_DNS_PORT) && in addr_matches_master()
3746 if(master->allow_notify && !master->http && in addr_matches_master()
3747 strchr(master->host, '/') != NULL && in addr_matches_master()
3748 strchr(master->host, '/') == strrchr(master->host, '/') && in addr_matches_master()
3749 netblockstrtoaddr(master->host, UNBOUND_DNS_PORT, &a, &alen, in addr_matches_master()
3754 to send the probe or transfer with */ in addr_matches_master()
3767 for(p=xfr->allow_notify_list; p; p=p->next) { in az_xfr_allowed_notify()
3780 if(!xfr->have_zone) in xfr_serial_means_update()
3782 if(xfr->zone_expired) in xfr_serial_means_update()
3785 if(compare_serial(xfr->serial, serial) < 0) in xfr_serial_means_update()
3795 if(xfr->notify_received && xfr->notify_has_serial && has_serial) { in xfr_note_notify_serial()
3797 if(compare_serial(xfr->notify_serial, serial) < 0) in xfr_note_notify_serial()
3798 xfr->notify_serial = serial; in xfr_note_notify_serial()
3799 } else if(xfr->notify_received && xfr->notify_has_serial && in xfr_note_notify_serial()
3802 xfr->notify_has_serial = 0; in xfr_note_notify_serial()
3803 xfr->notify_serial = 0; in xfr_note_notify_serial()
3804 } else if(xfr->notify_received && !xfr->notify_has_serial) { in xfr_note_notify_serial()
3809 xfr->notify_received = 1; in xfr_note_notify_serial()
3810 xfr->notify_has_serial = has_serial; in xfr_note_notify_serial()
3811 xfr->notify_serial = serial; in xfr_note_notify_serial()
3823 lock_basic_unlock(&xfr->lock); in xfr_process_notify()
3830 lock_basic_unlock(&xfr->lock); in xfr_process_notify()
3832 /* successful end of start_probe unlocked xfr->lock */ in xfr_process_notify()
3843 lock_rw_rdlock(&az->lock); in auth_zones_notify()
3846 lock_rw_unlock(&az->lock); in auth_zones_notify()
3851 lock_basic_lock(&xfr->lock); in auth_zones_notify()
3852 lock_rw_unlock(&az->lock); in auth_zones_notify()
3856 lock_basic_unlock(&xfr->lock); in auth_zones_notify()
3871 lock_rw_rdlock(&az->lock); in auth_zones_startprobesequence()
3874 lock_rw_unlock(&az->lock); in auth_zones_startprobesequence()
3877 lock_basic_lock(&xfr->lock); in auth_zones_startprobesequence()
3878 lock_rw_unlock(&az->lock); in auth_zones_startprobesequence()
3892 lock_basic_lock(&xfr->lock); in auth_xfer_set_expired()
3893 xfr->zone_expired = expired; in auth_xfer_set_expired()
3894 lock_basic_unlock(&xfr->lock); in auth_xfer_set_expired()
3897 lock_rw_rdlock(&env->auth_zones->lock); in auth_xfer_set_expired()
3898 z = auth_zone_find(env->auth_zones, xfr->name, xfr->namelen, in auth_xfer_set_expired()
3899 xfr->dclass); in auth_xfer_set_expired()
3901 lock_rw_unlock(&env->auth_zones->lock); in auth_xfer_set_expired()
3904 lock_rw_wrlock(&z->lock); in auth_xfer_set_expired()
3905 lock_rw_unlock(&env->auth_zones->lock); in auth_xfer_set_expired()
3908 z->zone_expired = expired; in auth_xfer_set_expired()
3909 lock_rw_unlock(&z->lock); in auth_xfer_set_expired()
3917 for(p=list; p; p=p->next) { in find_master_by_host()
3918 if(strcmp(p->host, host) == 0) in find_master_by_host()
3929 for(m=list; m; m=m->next) { in xfr_masterlist_free_addrs()
3930 if(m->list) { in xfr_masterlist_free_addrs()
3931 auth_free_master_addrs(m->list); in xfr_masterlist_free_addrs()
3932 m->list = NULL; in xfr_masterlist_free_addrs()
3943 for(p=source; p; p=p->next) { in auth_addr_list_copy()
3950 a->next = NULL; in auth_addr_list_copy()
3951 if(last) last->next = a; in auth_addr_list_copy()
3969 m->next = NULL; in auth_master_copy()
3970 if(m->host) { in auth_master_copy()
3971 m->host = strdup(m->host); in auth_master_copy()
3972 if(!m->host) { in auth_master_copy()
3978 if(m->file) { in auth_master_copy()
3979 m->file = strdup(m->file); in auth_master_copy()
3980 if(!m->file) { in auth_master_copy()
3981 free(m->host); in auth_master_copy()
3987 if(m->list) { in auth_master_copy()
3988 m->list = auth_addr_list_copy(m->list); in auth_master_copy()
3989 if(!m->list) { in auth_master_copy()
3990 free(m->file); in auth_master_copy()
3991 free(m->host); in auth_master_copy()
4007 for(p = xfr->task_transfer->masters; p; p=p->next) { in probe_copy_masters_for_allow_notify()
4014 m->next = NULL; in probe_copy_masters_for_allow_notify()
4015 if(last) last->next = m; in probe_copy_masters_for_allow_notify()
4020 auth_free_masters(xfr->allow_notify_list); in probe_copy_masters_for_allow_notify()
4021 xfr->allow_notify_list = list; in probe_copy_masters_for_allow_notify()
4029 xfr->task_transfer->scan_addr = NULL; in xfr_transfer_start_lookups()
4030 xfr_masterlist_free_addrs(xfr->task_transfer->masters); in xfr_transfer_start_lookups()
4033 xfr->task_transfer->lookup_target = xfr->task_transfer->masters; in xfr_transfer_start_lookups()
4034 xfr->task_transfer->lookup_aaaa = 0; in xfr_transfer_start_lookups()
4041 if(!xfr->task_transfer->lookup_target) in xfr_transfer_move_to_next_lookup()
4043 if(!xfr->task_transfer->lookup_aaaa && env->cfg->do_ip6) { in xfr_transfer_move_to_next_lookup()
4045 xfr->task_transfer->lookup_aaaa = 1; in xfr_transfer_move_to_next_lookup()
4048 xfr->task_transfer->lookup_target = in xfr_transfer_move_to_next_lookup()
4049 xfr->task_transfer->lookup_target->next; in xfr_transfer_move_to_next_lookup()
4050 xfr->task_transfer->lookup_aaaa = 0; in xfr_transfer_move_to_next_lookup()
4051 if(!env->cfg->do_ip4 && xfr->task_transfer->lookup_target!=NULL) in xfr_transfer_move_to_next_lookup()
4052 xfr->task_transfer->lookup_aaaa = 1; in xfr_transfer_move_to_next_lookup()
4060 xfr->task_probe->scan_addr = NULL; in xfr_probe_start_lookups()
4061 xfr_masterlist_free_addrs(xfr->task_probe->masters); in xfr_probe_start_lookups()
4064 xfr->task_probe->lookup_target = xfr->task_probe->masters; in xfr_probe_start_lookups()
4065 xfr->task_probe->lookup_aaaa = 0; in xfr_probe_start_lookups()
4072 if(!xfr->task_probe->lookup_target) in xfr_probe_move_to_next_lookup()
4074 if(!xfr->task_probe->lookup_aaaa && env->cfg->do_ip6) { in xfr_probe_move_to_next_lookup()
4076 xfr->task_probe->lookup_aaaa = 1; in xfr_probe_move_to_next_lookup()
4079 xfr->task_probe->lookup_target = xfr->task_probe->lookup_target->next; in xfr_probe_move_to_next_lookup()
4080 xfr->task_probe->lookup_aaaa = 0; in xfr_probe_move_to_next_lookup()
4081 if(!env->cfg->do_ip4 && xfr->task_probe->lookup_target!=NULL) in xfr_probe_move_to_next_lookup()
4082 xfr->task_probe->lookup_aaaa = 1; in xfr_probe_move_to_next_lookup()
4090 xfr->task_transfer->scan_specific = find_master_by_host( in xfr_transfer_start_list()
4091 xfr->task_transfer->masters, spec->host); in xfr_transfer_start_list()
4092 if(xfr->task_transfer->scan_specific) { in xfr_transfer_start_list()
4093 xfr->task_transfer->scan_target = NULL; in xfr_transfer_start_list()
4094 xfr->task_transfer->scan_addr = NULL; in xfr_transfer_start_list()
4095 if(xfr->task_transfer->scan_specific->list) in xfr_transfer_start_list()
4096 xfr->task_transfer->scan_addr = in xfr_transfer_start_list()
4097 xfr->task_transfer->scan_specific->list; in xfr_transfer_start_list()
4102 xfr->task_transfer->scan_specific = NULL; in xfr_transfer_start_list()
4103 xfr->task_transfer->scan_addr = NULL; in xfr_transfer_start_list()
4105 xfr->task_transfer->scan_target = xfr->task_transfer->masters; in xfr_transfer_start_list()
4106 if(xfr->task_transfer->scan_target && xfr->task_transfer-> in xfr_transfer_start_list()
4107 scan_target->list) in xfr_transfer_start_list()
4108 xfr->task_transfer->scan_addr = in xfr_transfer_start_list()
4109 xfr->task_transfer->scan_target->list; in xfr_transfer_start_list()
4117 xfr->task_probe->scan_specific = find_master_by_host( in xfr_probe_start_list()
4118 xfr->task_probe->masters, spec->host); in xfr_probe_start_list()
4119 if(xfr->task_probe->scan_specific) { in xfr_probe_start_list()
4120 xfr->task_probe->scan_target = NULL; in xfr_probe_start_list()
4121 xfr->task_probe->scan_addr = NULL; in xfr_probe_start_list()
4122 if(xfr->task_probe->scan_specific->list) in xfr_probe_start_list()
4123 xfr->task_probe->scan_addr = in xfr_probe_start_list()
4124 xfr->task_probe->scan_specific->list; in xfr_probe_start_list()
4129 xfr->task_probe->scan_specific = NULL; in xfr_probe_start_list()
4130 xfr->task_probe->scan_addr = NULL; in xfr_probe_start_list()
4132 xfr->task_probe->scan_target = xfr->task_probe->masters; in xfr_probe_start_list()
4133 if(xfr->task_probe->scan_target && xfr->task_probe->scan_target->list) in xfr_probe_start_list()
4134 xfr->task_probe->scan_addr = in xfr_probe_start_list()
4135 xfr->task_probe->scan_target->list; in xfr_probe_start_list()
4142 if(xfr->task_transfer->scan_specific) in xfr_transfer_current_master()
4143 return xfr->task_transfer->scan_specific; in xfr_transfer_current_master()
4144 return xfr->task_transfer->scan_target; in xfr_transfer_current_master()
4151 if(xfr->task_probe->scan_specific) in xfr_probe_current_master()
4152 return xfr->task_probe->scan_specific; in xfr_probe_current_master()
4153 return xfr->task_probe->scan_target; in xfr_probe_current_master()
4160 return !xfr->task_transfer->scan_specific && in xfr_transfer_end_of_list()
4161 !xfr->task_transfer->scan_target; in xfr_transfer_end_of_list()
4168 return !xfr->task_probe->scan_specific && !xfr->task_probe->scan_target; in xfr_probe_end_of_list()
4175 if(!xfr->task_transfer->scan_specific && in xfr_transfer_nextmaster()
4176 !xfr->task_transfer->scan_target) in xfr_transfer_nextmaster()
4178 if(xfr->task_transfer->scan_addr) { in xfr_transfer_nextmaster()
4179 xfr->task_transfer->scan_addr = in xfr_transfer_nextmaster()
4180 xfr->task_transfer->scan_addr->next; in xfr_transfer_nextmaster()
4181 if(xfr->task_transfer->scan_addr) in xfr_transfer_nextmaster()
4184 if(xfr->task_transfer->scan_specific) { in xfr_transfer_nextmaster()
4185 xfr->task_transfer->scan_specific = NULL; in xfr_transfer_nextmaster()
4186 xfr->task_transfer->scan_target = xfr->task_transfer->masters; in xfr_transfer_nextmaster()
4187 if(xfr->task_transfer->scan_target && xfr->task_transfer-> in xfr_transfer_nextmaster()
4188 scan_target->list) in xfr_transfer_nextmaster()
4189 xfr->task_transfer->scan_addr = in xfr_transfer_nextmaster()
4190 xfr->task_transfer->scan_target->list; in xfr_transfer_nextmaster()
4193 if(!xfr->task_transfer->scan_target) in xfr_transfer_nextmaster()
4195 xfr->task_transfer->scan_target = xfr->task_transfer->scan_target->next; in xfr_transfer_nextmaster()
4196 if(xfr->task_transfer->scan_target && xfr->task_transfer-> in xfr_transfer_nextmaster()
4197 scan_target->list) in xfr_transfer_nextmaster()
4198 xfr->task_transfer->scan_addr = in xfr_transfer_nextmaster()
4199 xfr->task_transfer->scan_target->list; in xfr_transfer_nextmaster()
4207 if(!xfr->task_probe->scan_specific && !xfr->task_probe->scan_target) in xfr_probe_nextmaster()
4209 if(xfr->task_probe->scan_addr) { in xfr_probe_nextmaster()
4210 xfr->task_probe->scan_addr = xfr->task_probe->scan_addr->next; in xfr_probe_nextmaster()
4211 if(xfr->task_probe->scan_addr) in xfr_probe_nextmaster()
4214 if(xfr->task_probe->scan_specific) { in xfr_probe_nextmaster()
4215 xfr->task_probe->scan_specific = NULL; in xfr_probe_nextmaster()
4216 xfr->task_probe->scan_target = xfr->task_probe->masters; in xfr_probe_nextmaster()
4217 if(xfr->task_probe->scan_target && xfr->task_probe-> in xfr_probe_nextmaster()
4218 scan_target->list) in xfr_probe_nextmaster()
4219 xfr->task_probe->scan_addr = in xfr_probe_nextmaster()
4220 xfr->task_probe->scan_target->list; in xfr_probe_nextmaster()
4223 if(!xfr->task_probe->scan_target) in xfr_probe_nextmaster()
4225 xfr->task_probe->scan_target = xfr->task_probe->scan_target->next; in xfr_probe_nextmaster()
4226 if(xfr->task_probe->scan_target && xfr->task_probe-> in xfr_probe_nextmaster()
4227 scan_target->list) in xfr_probe_nextmaster()
4228 xfr->task_probe->scan_addr = in xfr_probe_nextmaster()
4229 xfr->task_probe->scan_target->list; in xfr_probe_nextmaster()
4241 qinfo.qname = xfr->name; in xfr_create_soa_probe_packet()
4242 qinfo.qname_len = xfr->namelen; in xfr_create_soa_probe_packet()
4244 qinfo.qclass = xfr->dclass; in xfr_create_soa_probe_packet()
4257 have_zone = xfr->have_zone; in xfr_create_ixfr_packet()
4258 serial = xfr->serial; in xfr_create_ixfr_packet()
4261 qinfo.qname = xfr->name; in xfr_create_ixfr_packet()
4262 qinfo.qname_len = xfr->namelen; in xfr_create_ixfr_packet()
4263 xfr->task_transfer->got_xfr_serial = 0; in xfr_create_ixfr_packet()
4264 xfr->task_transfer->rr_scan_num = 0; in xfr_create_ixfr_packet()
4265 xfr->task_transfer->incoming_xfr_serial = 0; in xfr_create_ixfr_packet()
4266 xfr->task_transfer->on_ixfr_is_axfr = 0; in xfr_create_ixfr_packet()
4267 xfr->task_transfer->on_ixfr = 1; in xfr_create_ixfr_packet()
4269 if(!have_zone || xfr->task_transfer->ixfr_fail || !master->ixfr) { in xfr_create_ixfr_packet()
4271 xfr->task_transfer->ixfr_fail = 0; in xfr_create_ixfr_packet()
4272 xfr->task_transfer->on_ixfr = 0; in xfr_create_ixfr_packet()
4275 qinfo.qclass = xfr->dclass; in xfr_create_ixfr_packet()
4316 if(LDNS_ID_WIRE(sldns_buffer_begin(pkt)) != xfr->task_probe->id) in check_packet_ok()
4319 /* check flag bits and rcode */ in check_packet_ok()
4331 if(sldns_buffer_remaining(pkt) < xfr->namelen) in check_packet_ok()
4333 if(query_dname_compare(sldns_buffer_current(pkt), xfr->name) != 0) in check_packet_ok()
4335 sldns_buffer_skip(pkt, (ssize_t)xfr->namelen); in check_packet_ok()
4342 if(sldns_buffer_read_u16(pkt) != xfr->dclass) in check_packet_ok()
4354 xfr->name) != 0) in check_packet_ok()
4363 if(sldns_buffer_read_u16(pkt) != xfr->dclass) in check_packet_ok()
4392 if(*chunk_pos < (*chunk)->len) { in chunkline_get_line()
4394 while(*chunk_pos < (*chunk)->len) { in chunkline_get_line()
4395 char c = (char)((*chunk)->data[*chunk_pos]); in chunkline_get_line()
4411 *chunk = (*chunk)->next; in chunkline_get_line()
4438 count --; in chunkline_count_parens()
4498 else sldns_buffer_write_u8_at(buf, sldns_buffer_position(buf)-1, 0); in chunkline_get_line_collated()
4509 else sldns_buffer_write_u8_at(buf, sldns_buffer_position(buf)-1, 0); in chunkline_get_line_collated()
4534 pstate->origin_len = sizeof(pstate->origin); in http_parse_origin()
4536 pstate->origin, &pstate->origin_len); in http_parse_origin()
4538 pstate->origin_len = 0; in http_parse_origin()
4555 pstate->default_ttl = sldns_str2period( in http_parse_ttl()
4606 if(xfr->namelen < sizeof(pstate.origin)) { in http_zonefile_syntax_check()
4607 pstate.origin_len = xfr->namelen; in http_zonefile_syntax_check()
4608 memmove(pstate.origin, xfr->name, xfr->namelen); in http_zonefile_syntax_check()
4610 chunk = xfr->task_transfer->chunks_first; in http_zonefile_syntax_check()
4627 if(sldns_wirerr_get_class(rr, rr_len, dname_len) != xfr->dclass) { in http_zonefile_syntax_check()
4641 for(p=list; p; p=p->next) { in chunklist_sum()
4642 s += p->len; in chunklist_sum()
4654 if(c == '\n' && i==end-1) { in chunkline_newline_removal()
4656 sldns_buffer_set_limit(buf, end-1); in chunkline_newline_removal()
4675 pstate->default_ttl, in http_parse_add_rr()
4676 pstate->origin_len?pstate->origin:NULL, pstate->origin_len, in http_parse_add_rr()
4677 pstate->prev_rr_len?pstate->prev_rr:NULL, pstate->prev_rr_len); in http_parse_add_rr()
4680 xfr->task_transfer->master->host, in http_parse_add_rr()
4681 xfr->task_transfer->master->file, in http_parse_add_rr()
4691 if(dname_len < sizeof(pstate->prev_rr)) { in http_parse_add_rr()
4692 memmove(pstate->prev_rr, rr, dname_len); in http_parse_add_rr()
4693 pstate->prev_rr_len = dname_len; in http_parse_add_rr()
4705 *rr_chunk = xfr->task_transfer->chunks_first; in chunk_rrlist_start()
4715 if(rr_chunk->len < LDNS_HEADER_SIZE) in chunk_rrlist_end()
4717 if(rr_num < (int)LDNS_ANCOUNT(rr_chunk->data)) in chunk_rrlist_end()
4721 rr_chunk = rr_chunk->next; in chunk_rrlist_end()
4736 if((*rr_chunk)->len >= LDNS_HEADER_SIZE && in chunk_rrlist_gonext()
4737 (*rr_num)+1 < (int)LDNS_ANCOUNT((*rr_chunk)->data)) { in chunk_rrlist_gonext()
4745 *rr_chunk = (*rr_chunk)->next; in chunk_rrlist_gonext()
4749 if((*rr_chunk)->len >= LDNS_HEADER_SIZE && in chunk_rrlist_gonext()
4750 LDNS_ANCOUNT((*rr_chunk)->data) > 0) { in chunk_rrlist_gonext()
4753 *rr_chunk = (*rr_chunk)->next; in chunk_rrlist_gonext()
4767 if(rr_chunk->len < LDNS_HEADER_SIZE) return 0; in chunk_rrlist_get_current()
4768 if(rr_num >= (int)LDNS_ANCOUNT(rr_chunk->data)) return 0; in chunk_rrlist_get_current()
4769 if(rr_pos >= rr_chunk->len) return 0; in chunk_rrlist_get_current()
4772 sldns_buffer_init_frm_data(&pkt, rr_chunk->data, rr_chunk->len); in chunk_rrlist_get_current()
4777 for(i=0; i<LDNS_QDCOUNT(rr_chunk->data); i++) { in chunk_rrlist_get_current()
4799 /** print log message where we are in parsing the zone transfer */
4809 sldns_buffer_init_frm_data(&pkt, rr_chunk->data, rr_chunk->len); in log_rrlist_position()
4810 sldns_buffer_set_position(&pkt, (size_t)(rr_dname - in log_rrlist_position()
4852 startserial = sldns_read_uint32(rr_rdata+rr_rdlen-20); in ixfr_start_serial()
4862 "in memory, rejecting the zone transfer", in ixfr_start_serial()
4912 serial = sldns_read_uint32(rr_rdata+rr_rdlen-20); in apply_ixfr()
4921 transfer_serial, xfr->serial)) { in apply_ixfr()
4942 xfr->serial = transfer_serial; in apply_ixfr()
4962 if(!az_remove_rr_decompress(z, rr_chunk->data, in apply_ixfr()
4963 rr_chunk->len, scratch_buffer, rr_dname, in apply_ixfr()
4982 if(!az_insert_rr_decompress(z, rr_chunk->data, in apply_ixfr()
4983 rr_chunk->len, scratch_buffer, rr_dname, in apply_ixfr()
5025 traverse_postorder(&z->data, auth_data_del, NULL); in apply_axfr()
5026 rbtree_init(&z->data, &auth_data_cmp); in apply_axfr()
5028 if(z->rpz) in apply_axfr()
5029 rpz_clear(z->rpz); in apply_axfr()
5031 xfr->have_zone = 0; in apply_axfr()
5032 xfr->serial = 0; in apply_axfr()
5054 serial = sldns_read_uint32(rr_rdata+rr_rdlen-20); in apply_axfr()
5058 if(!az_insert_rr_decompress(z, rr_chunk->data, rr_chunk->len, in apply_axfr()
5073 xfr->serial = serial; in apply_axfr()
5074 xfr->have_zone = 1; in apply_axfr()
5092 if(xfr->namelen < sizeof(pstate.origin)) { in apply_http()
5093 pstate.origin_len = xfr->namelen; in apply_http()
5094 memmove(pstate.origin, xfr->name, xfr->namelen); in apply_http()
5099 xfr->task_transfer->master->file, in apply_http()
5100 (int)chunklist_sum(xfr->task_transfer->chunks_first)); in apply_http()
5101 if(xfr->task_transfer->chunks_first && verbosity >= VERB_ALGO) { in apply_http()
5103 if(xfr->task_transfer->chunks_first->len+1 > sizeof(preview)) { in apply_http()
5104 memmove(preview, xfr->task_transfer->chunks_first->data, in apply_http()
5105 sizeof(preview)-1); in apply_http()
5106 preview[sizeof(preview)-1]=0; in apply_http()
5108 memmove(preview, xfr->task_transfer->chunks_first->data, in apply_http()
5109 xfr->task_transfer->chunks_first->len); in apply_http()
5110 preview[xfr->task_transfer->chunks_first->len]=0; in apply_http()
5119 "but got '%s'", xfr->task_transfer->master->host, in apply_http()
5120 xfr->task_transfer->master->file, in apply_http()
5126 traverse_postorder(&z->data, auth_data_del, NULL); in apply_http()
5127 rbtree_init(&z->data, &auth_data_cmp); in apply_http()
5129 if(z->rpz) in apply_http()
5130 rpz_clear(z->rpz); in apply_http()
5132 xfr->have_zone = 0; in apply_http()
5133 xfr->serial = 0; in apply_http()
5135 chunk = xfr->task_transfer->chunks_first; in apply_http()
5149 xfr->task_transfer->master->file, in apply_http()
5159 xfr->task_transfer->master->file, in apply_http()
5168 xfr->task_transfer->master->file, in apply_http()
5188 for(p = xfr->task_transfer->chunks_first; p ; p = p->next) { in auth_zone_write_chunks()
5189 if(!write_out(out, (char*)p->data, p->len)) { in auth_zone_write_chunks()
5203 struct config_file* cfg = env->cfg; in xfr_write_after_update()
5207 lock_basic_unlock(&xfr->lock); in xfr_write_after_update()
5211 lock_rw_rdlock(&env->auth_zones->lock); in xfr_write_after_update()
5212 z = auth_zone_find(env->auth_zones, xfr->name, xfr->namelen, in xfr_write_after_update()
5213 xfr->dclass); in xfr_write_after_update()
5215 lock_rw_unlock(&env->auth_zones->lock); in xfr_write_after_update()
5217 lock_basic_lock(&xfr->lock); in xfr_write_after_update()
5220 lock_rw_rdlock(&z->lock); in xfr_write_after_update()
5221 lock_basic_lock(&xfr->lock); in xfr_write_after_update()
5222 lock_rw_unlock(&env->auth_zones->lock); in xfr_write_after_update()
5224 if(z->zonefile == NULL || z->zonefile[0] == 0) { in xfr_write_after_update()
5225 lock_rw_unlock(&z->lock); in xfr_write_after_update()
5229 zfilename = z->zonefile; in xfr_write_after_update()
5230 if(cfg->chrootdir && cfg->chrootdir[0] && strncmp(zfilename, in xfr_write_after_update()
5231 cfg->chrootdir, strlen(cfg->chrootdir)) == 0) in xfr_write_after_update()
5232 zfilename += strlen(cfg->chrootdir); in xfr_write_after_update()
5235 dname_str(z->name, nm); in xfr_write_after_update()
5243 lock_rw_unlock(&z->lock); in xfr_write_after_update()
5248 if(xfr->task_transfer->master->http) { in xfr_write_after_update()
5252 lock_rw_unlock(&z->lock); in xfr_write_after_update()
5257 lock_rw_unlock(&z->lock); in xfr_write_after_update()
5267 lock_rw_unlock(&z->lock); in xfr_write_after_update()
5270 lock_rw_unlock(&z->lock); in xfr_write_after_update()
5278 /* release xfr lock, then, while holding az->lock grab both in xfr_process_reacquire_locks()
5279 * z->lock and xfr->lock */ in xfr_process_reacquire_locks()
5280 lock_rw_rdlock(&env->auth_zones->lock); in xfr_process_reacquire_locks()
5281 *z = auth_zone_find(env->auth_zones, xfr->name, xfr->namelen, in xfr_process_reacquire_locks()
5282 xfr->dclass); in xfr_process_reacquire_locks()
5284 lock_rw_unlock(&env->auth_zones->lock); in xfr_process_reacquire_locks()
5285 lock_basic_lock(&xfr->lock); in xfr_process_reacquire_locks()
5289 lock_rw_wrlock(&(*z)->lock); in xfr_process_reacquire_locks()
5290 lock_basic_lock(&xfr->lock); in xfr_process_reacquire_locks()
5291 lock_rw_unlock(&env->auth_zones->lock); in xfr_process_reacquire_locks()
5304 lock_basic_unlock(&xfr->lock); in xfr_process_chunk_list()
5312 if(xfr->task_transfer->master->http) { in xfr_process_chunk_list()
5313 if(!apply_http(xfr, z, env->scratch_buffer)) { in xfr_process_chunk_list()
5314 lock_rw_unlock(&z->lock); in xfr_process_chunk_list()
5316 xfr->task_transfer->master->host); in xfr_process_chunk_list()
5319 } else if(xfr->task_transfer->on_ixfr && in xfr_process_chunk_list()
5320 !xfr->task_transfer->on_ixfr_is_axfr) { in xfr_process_chunk_list()
5321 if(!apply_ixfr(xfr, z, env->scratch_buffer)) { in xfr_process_chunk_list()
5322 lock_rw_unlock(&z->lock); in xfr_process_chunk_list()
5324 " data", xfr->task_transfer->master->host); in xfr_process_chunk_list()
5329 if(!apply_axfr(xfr, z, env->scratch_buffer)) { in xfr_process_chunk_list()
5330 lock_rw_unlock(&z->lock); in xfr_process_chunk_list()
5332 " data", xfr->task_transfer->master->host); in xfr_process_chunk_list()
5336 xfr->zone_expired = 0; in xfr_process_chunk_list()
5337 z->zone_expired = 0; in xfr_process_chunk_list()
5339 lock_rw_unlock(&z->lock); in xfr_process_chunk_list()
5341 " (or malformed RR)", xfr->task_transfer->master->host); in xfr_process_chunk_list()
5347 lock_basic_unlock(&xfr->lock); in xfr_process_chunk_list()
5349 auth_zone_verify_zonemd(z, env, &env->mesh->mods, NULL, 0, 0); in xfr_process_chunk_list()
5350 if(z->zone_expired) { in xfr_process_chunk_list()
5356 lock_rw_unlock(&z->lock); in xfr_process_chunk_list()
5359 dname_str(xfr->name, zname); in xfr_process_chunk_list()
5360 …bose(VERB_ALGO, "xfr from %s: ZONEMD failed for %s, transfer is failed", xfr->task_transfer->maste… in xfr_process_chunk_list()
5361 xfr->zone_expired = 1; in xfr_process_chunk_list()
5362 lock_rw_unlock(&z->lock); in xfr_process_chunk_list()
5368 lock_rw_unlock(&z->lock); in xfr_process_chunk_list()
5373 if(xfr->have_zone) in xfr_process_chunk_list()
5374 xfr->lease_time = *env->now; in xfr_process_chunk_list()
5376 if(z->rpz) in xfr_process_chunk_list()
5377 rpz_finish_config(z->rpz); in xfr_process_chunk_list()
5380 lock_rw_unlock(&z->lock); in xfr_process_chunk_list()
5382 if(verbosity >= VERB_QUERY && xfr->have_zone) { in xfr_process_chunk_list()
5384 dname_str(xfr->name, zname); in xfr_process_chunk_list()
5386 (unsigned)xfr->serial); in xfr_process_chunk_list()
5398 comm_timer_delete(xfr->task_transfer->timer); in xfr_transfer_disown()
5399 xfr->task_transfer->timer = NULL; in xfr_transfer_disown()
5401 comm_point_delete(xfr->task_transfer->cp); in xfr_transfer_disown()
5402 xfr->task_transfer->cp = NULL; in xfr_transfer_disown()
5404 xfr->task_transfer->worker = NULL; in xfr_transfer_disown()
5405 xfr->task_transfer->env = NULL; in xfr_transfer_disown()
5414 struct auth_master* master = xfr->task_transfer->lookup_target; in xfr_transfer_lookup_host()
5419 sldns_buffer* buf = env->scratch_buffer; in xfr_transfer_lookup_host()
5421 if(extstrtoaddr(master->host, &addr, &addrlen, UNBOUND_DNS_PORT)) { in xfr_transfer_lookup_host()
5425 if(master->allow_notify) in xfr_transfer_lookup_host()
5426 return 0; /* allow-notifies are not transferred from, no in xfr_transfer_lookup_host()
5429 /* use mesh_new_callback to probe for non-addr hosts, in xfr_transfer_lookup_host()
5432 if(sldns_str2wire_dname_buf(master->host, dname, &qinfo.qname_len) in xfr_transfer_lookup_host()
5434 log_err("cannot parse host name of master %s", master->host); in xfr_transfer_lookup_host()
5438 qinfo.qclass = xfr->dclass; in xfr_transfer_lookup_host()
5440 if(xfr->task_transfer->lookup_aaaa) in xfr_transfer_lookup_host()
5446 dname_str(xfr->name, buf2); in xfr_transfer_lookup_host()
5454 edns.bits = EDNS_DO; in xfr_transfer_lookup_host()
5467 lock_basic_unlock(&xfr->lock); in xfr_transfer_lookup_host()
5468 if(!mesh_new_callback(env->mesh, &qinfo, qflags, &edns, buf, 0, in xfr_transfer_lookup_host()
5470 lock_basic_lock(&xfr->lock); in xfr_transfer_lookup_host()
5471 log_err("out of memory lookup up master %s", master->host); in xfr_transfer_lookup_host()
5474 lock_basic_lock(&xfr->lock); in xfr_transfer_lookup_host()
5485 struct auth_master* master = xfr->task_transfer->master; in xfr_transfer_init_fetch()
5490 if(master->allow_notify) return 0; /* only for notify */ in xfr_transfer_init_fetch()
5493 if(xfr->task_transfer->scan_addr) { in xfr_transfer_init_fetch()
5494 addrlen = xfr->task_transfer->scan_addr->addrlen; in xfr_transfer_init_fetch()
5495 memmove(&addr, &xfr->task_transfer->scan_addr->addr, addrlen); in xfr_transfer_init_fetch()
5497 if(!authextstrtoaddr(master->host, &addr, &addrlen, &auth_name)) { in xfr_transfer_init_fetch()
5502 dname_str(xfr->name, zname); in xfr_transfer_init_fetch()
5503 log_err("%s: failed lookup, cannot transfer from master %s", in xfr_transfer_init_fetch()
5504 zname, master->host); in xfr_transfer_init_fetch()
5510 if(xfr->task_transfer->cp) { in xfr_transfer_init_fetch()
5511 comm_point_delete(xfr->task_transfer->cp); in xfr_transfer_init_fetch()
5512 xfr->task_transfer->cp = NULL; in xfr_transfer_init_fetch()
5514 if(!xfr->task_transfer->timer) { in xfr_transfer_init_fetch()
5515 xfr->task_transfer->timer = comm_timer_create(env->worker_base, in xfr_transfer_init_fetch()
5517 if(!xfr->task_transfer->timer) { in xfr_transfer_init_fetch()
5528 if(master->http) { in xfr_transfer_init_fetch()
5532 xfr->task_transfer->on_ixfr = 0; in xfr_transfer_init_fetch()
5533 if(strchr(master->host, '@') == NULL) in xfr_transfer_init_fetch()
5534 sockaddr_store_port(&addr, addrlen, master->port); in xfr_transfer_init_fetch()
5535 xfr->task_transfer->cp = outnet_comm_point_for_http( in xfr_transfer_init_fetch()
5536 env->outnet, auth_xfer_transfer_http_callback, xfr, in xfr_transfer_init_fetch()
5537 &addr, addrlen, -1, master->ssl, master->host, in xfr_transfer_init_fetch()
5538 master->file, env->cfg); in xfr_transfer_init_fetch()
5539 if(!xfr->task_transfer->cp) { in xfr_transfer_init_fetch()
5541 dname_str(xfr->name, zname); in xfr_transfer_init_fetch()
5547 comm_timer_set(xfr->task_transfer->timer, &t); in xfr_transfer_init_fetch()
5550 dname_str(xfr->name, zname); in xfr_transfer_init_fetch()
5552 verbose(VERB_ALGO, "auth zone %s transfer next HTTP fetch from %s started", zname, as); in xfr_transfer_init_fetch()
5562 xfr->task_transfer->id = GET_RANDOM_ID(env->rnd); in xfr_transfer_init_fetch()
5563 xfr_create_ixfr_packet(xfr, env->scratch_buffer, in xfr_transfer_init_fetch()
5564 xfr->task_transfer->id, master); in xfr_transfer_init_fetch()
5567 xfr->task_transfer->cp = outnet_comm_point_for_tcp(env->outnet, in xfr_transfer_init_fetch()
5569 env->scratch_buffer, -1, in xfr_transfer_init_fetch()
5571 if(!xfr->task_transfer->cp) { in xfr_transfer_init_fetch()
5573 dname_str(xfr->name, zname); in xfr_transfer_init_fetch()
5579 comm_timer_set(xfr->task_transfer->timer, &t); in xfr_transfer_init_fetch()
5582 dname_str(xfr->name, zname); in xfr_transfer_init_fetch()
5584 verbose(VERB_ALGO, "auth zone %s transfer next %s fetch from %s started", zname, in xfr_transfer_init_fetch()
5585 (xfr->task_transfer->on_ixfr?"IXFR":"AXFR"), as); in xfr_transfer_init_fetch()
5590 /** perform next lookup, next transfer TCP, or end and resume wait time task */
5594 log_assert(xfr->task_transfer->worker == env->worker); in xfr_transfer_nexttarget_or_end()
5597 while(xfr->task_transfer->lookup_target) { in xfr_transfer_nexttarget_or_end()
5606 dname_str(xfr->name, zname); in xfr_transfer_nexttarget_or_end()
5607 verbose(VERB_ALGO, "auth zone %s transfer next target lookup", zname); in xfr_transfer_nexttarget_or_end()
5609 lock_basic_unlock(&xfr->lock); in xfr_transfer_nexttarget_or_end()
5618 xfr->task_transfer->master = xfr_transfer_current_master(xfr); in xfr_transfer_nexttarget_or_end()
5621 lock_basic_unlock(&xfr->lock); in xfr_transfer_nexttarget_or_end()
5629 dname_str(xfr->name, zname); in xfr_transfer_nexttarget_or_end()
5630 verbose(VERB_ALGO, "auth zone %s transfer failed, wait", zname); in xfr_transfer_nexttarget_or_end()
5638 if(xfr->task_nextprobe->worker == NULL) in xfr_transfer_nexttarget_or_end()
5640 lock_basic_unlock(&xfr->lock); in xfr_transfer_nexttarget_or_end()
5653 data = (struct packed_rrset_data*)rrset->entry.data; in xfr_master_add_addrs()
5654 for(i=0; i<data->count; i++) { in xfr_master_add_addrs()
5656 size_t len = data->rr_len[i] - 2; in xfr_master_add_addrs()
5657 uint8_t* rdata = data->rr_data[i]+2; in xfr_master_add_addrs()
5671 a->addrlen = (socklen_t)sizeof(*sa); in xfr_master_add_addrs()
5672 sa = (struct sockaddr_in*)&a->addr; in xfr_master_add_addrs()
5673 sa->sin_family = AF_INET; in xfr_master_add_addrs()
5674 sa->sin_port = (in_port_t)htons(UNBOUND_DNS_PORT); in xfr_master_add_addrs()
5675 memmove(&sa->sin_addr, rdata, INET_SIZE); in xfr_master_add_addrs()
5678 a->addrlen = (socklen_t)sizeof(*sa); in xfr_master_add_addrs()
5679 sa = (struct sockaddr_in6*)&a->addr; in xfr_master_add_addrs()
5680 sa->sin6_family = AF_INET6; in xfr_master_add_addrs()
5681 sa->sin6_port = (in_port_t)htons(UNBOUND_DNS_PORT); in xfr_master_add_addrs()
5682 memmove(&sa->sin6_addr, rdata, INET6_SIZE); in xfr_master_add_addrs()
5686 addr_port_to_str(&a->addr, a->addrlen, s, sizeof(s)); in xfr_master_add_addrs()
5688 m->host, s); in xfr_master_add_addrs()
5691 a->next = m->list; in xfr_master_add_addrs()
5692 m->list = a; in xfr_master_add_addrs()
5703 log_assert(xfr->task_transfer); in auth_xfer_transfer_lookup_callback()
5704 lock_basic_lock(&xfr->lock); in auth_xfer_transfer_lookup_callback()
5705 env = xfr->task_transfer->env; in auth_xfer_transfer_lookup_callback()
5706 if(!env || env->outnet->want_to_quit) { in auth_xfer_transfer_lookup_callback()
5707 lock_basic_unlock(&xfr->lock); in auth_xfer_transfer_lookup_callback()
5714 struct regional* temp = env->scratch; in auth_xfer_transfer_lookup_callback()
5717 if(xfr->task_transfer->lookup_aaaa) in auth_xfer_transfer_lookup_callback()
5722 FLAGS_GET_RCODE(rep->flags) == LDNS_RCODE_NOERROR) { in auth_xfer_transfer_lookup_callback()
5727 xfr_master_add_addrs(xfr->task_transfer-> in auth_xfer_transfer_lookup_callback()
5732 dname_str(xfr->name, zname); in auth_xfer_transfer_lookup_callback()
5733 …uth zone %s host %s type %s transfer lookup has nodata", zname, xfr->task_transfer->lookup_target- in auth_xfer_transfer_lookup_callback()
5739 dname_str(xfr->name, zname); in auth_xfer_transfer_lookup_callback()
5740 …h zone %s host %s type %s transfer lookup has no answer", zname, xfr->task_transfer->lookup_target in auth_xfer_transfer_lookup_callback()
5747 dname_str(xfr->name, zname); in auth_xfer_transfer_lookup_callback()
5748 …"auth zone %s host %s type %s transfer lookup failed", zname, xfr->task_transfer->lookup_target->h… in auth_xfer_transfer_lookup_callback()
5751 if(xfr->task_transfer->lookup_target->list && in auth_xfer_transfer_lookup_callback()
5752 xfr->task_transfer->lookup_target == xfr_transfer_current_master(xfr)) in auth_xfer_transfer_lookup_callback()
5753 xfr->task_transfer->scan_addr = xfr->task_transfer->lookup_target->list; in auth_xfer_transfer_lookup_callback()
5766 * return true with transferdone=true when the transfer has ended.
5776 xfr->task_transfer->master->host); in check_xfer_packet()
5781 xfr->task_transfer->master->host); in check_xfer_packet()
5786 xfr->task_transfer->master->host); in check_xfer_packet()
5790 if(LDNS_ID_WIRE(wire) != xfr->task_transfer->id) { in check_xfer_packet()
5792 xfr->task_transfer->master->host); in check_xfer_packet()
5800 if(xfr->task_transfer->on_ixfr) { in check_xfer_packet()
5807 xfr->task_transfer->master->host, in check_xfer_packet()
5809 xfr->task_transfer->ixfr_fail = 1; in check_xfer_packet()
5815 xfr->task_transfer->master->host, rcode); in check_xfer_packet()
5820 xfr->task_transfer->master->host); in check_xfer_packet()
5825 xfr->task_transfer->master->host, in check_xfer_packet()
5838 xfr->task_transfer->master->host); in check_xfer_packet()
5842 xfr->name) != 0) { in check_xfer_packet()
5845 xfr->task_transfer->master->host); in check_xfer_packet()
5851 xfr->task_transfer->master->host); in check_xfer_packet()
5856 if(qclass != xfr->dclass) { in check_xfer_packet()
5859 xfr->task_transfer->master->host); in check_xfer_packet()
5862 if(xfr->task_transfer->on_ixfr) { in check_xfer_packet()
5866 xfr->task_transfer->master->host); in check_xfer_packet()
5873 xfr->task_transfer->master->host); in check_xfer_packet()
5888 xfr->task_transfer->master->host); in check_xfer_packet()
5894 xfr->task_transfer->master->host); in check_xfer_packet()
5904 xfr->task_transfer->master->host); in check_xfer_packet()
5910 if(xfr->task_transfer->rr_scan_num == 0 && in check_xfer_packet()
5913 "malformed zone transfer, no start SOA", in check_xfer_packet()
5914 xfr->task_transfer->master->host); in check_xfer_packet()
5917 if(xfr->task_transfer->rr_scan_num == 1 && in check_xfer_packet()
5921 xfr->task_transfer->on_ixfr_is_axfr = 1; in check_xfer_packet()
5928 xfr->task_transfer->master->host); in check_xfer_packet()
5932 xfr->name) != 0) { in check_xfer_packet()
5935 xfr->task_transfer->master->host); in check_xfer_packet()
5941 sldns_buffer_position(pkt)+rdlen-20); in check_xfer_packet()
5944 if(xfr->task_transfer->on_ixfr && in check_xfer_packet()
5945 xfr->task_transfer->rr_scan_num == 0 && in check_xfer_packet()
5950 xfr->task_transfer->master->host, in check_xfer_packet()
5952 xfr->task_transfer->ixfr_fail = 1; in check_xfer_packet()
5958 if(xfr->task_transfer->got_xfr_serial == 0) { in check_xfer_packet()
5959 xfr->task_transfer->got_xfr_serial = 1; in check_xfer_packet()
5960 xfr->task_transfer->incoming_xfr_serial = in check_xfer_packet()
5964 xfr->task_transfer->master->host, in check_xfer_packet()
5967 } else if(!xfr->task_transfer->on_ixfr || in check_xfer_packet()
5968 xfr->task_transfer->on_ixfr_is_axfr) { in check_xfer_packet()
5973 xfr->task_transfer->master->host); in check_xfer_packet()
5975 } else if(xfr->task_transfer->incoming_xfr_serial == in check_xfer_packet()
5976 serial && xfr->task_transfer->got_xfr_serial in check_xfer_packet()
5978 xfr->task_transfer->got_xfr_serial++; in check_xfer_packet()
5981 } else if(xfr->task_transfer->incoming_xfr_serial == in check_xfer_packet()
5982 serial && xfr->task_transfer->got_xfr_serial in check_xfer_packet()
5985 xfr->task_transfer->master->host); in check_xfer_packet()
5988 * transfer is done */ in check_xfer_packet()
5991 xfr->task_transfer->rr_scan_num++; in check_xfer_packet()
6004 xfr->task_transfer->master->host); in check_xfer_packet()
6010 xfr->task_transfer->master->host); in check_xfer_packet()
6020 xfr->task_transfer->master->host); in check_xfer_packet()
6033 xfr->task_transfer->master->host); in check_xfer_packet()
6039 xfr->task_transfer->master->host); in check_xfer_packet()
6049 xfr->task_transfer->master->host); in check_xfer_packet()
6067 e->next = NULL; in xfer_link_data()
6068 e->len = sldns_buffer_limit(pkt); in xfer_link_data()
6069 e->data = memdup(sldns_buffer_begin(pkt), e->len); in xfer_link_data()
6070 if(!e->data) { in xfer_link_data()
6076 if(!xfr->task_transfer->chunks_first) in xfer_link_data()
6077 xfr->task_transfer->chunks_first = e; in xfer_link_data()
6078 if(xfr->task_transfer->chunks_last) in xfer_link_data()
6079 xfr->task_transfer->chunks_last->next = e; in xfer_link_data()
6080 xfr->task_transfer->chunks_last = e; in xfer_link_data()
6084 /** task transfer. the list of data is complete. process it and if failed
6085 * move to next master, if succeeded, end the task transfer */
6092 auth_chunks_delete(xfr->task_transfer); in process_list_end_transfer()
6097 if(xfr->notify_received && (!xfr->notify_has_serial || in process_list_end_transfer()
6098 (xfr->notify_has_serial && in process_list_end_transfer()
6099 xfr_serial_means_update(xfr, xfr->notify_serial)))) { in process_list_end_transfer()
6100 uint32_t sr = xfr->notify_serial; in process_list_end_transfer()
6101 int has_sr = xfr->notify_has_serial; in process_list_end_transfer()
6102 /* we received a notify while probe/transfer was in process_list_end_transfer()
6103 * in progress. start a new probe and transfer */ in process_list_end_transfer()
6104 xfr->notify_received = 0; in process_list_end_transfer()
6105 xfr->notify_has_serial = 0; in process_list_end_transfer()
6106 xfr->notify_serial = 0; in process_list_end_transfer()
6111 xfr->notify_received = 1; in process_list_end_transfer()
6112 xfr->notify_has_serial = has_sr; in process_list_end_transfer()
6113 xfr->notify_serial = sr; in process_list_end_transfer()
6114 lock_basic_unlock(&xfr->lock); in process_list_end_transfer()
6119 if(xfr->task_nextprobe->worker == NULL) in process_list_end_transfer()
6122 lock_basic_unlock(&xfr->lock); in process_list_end_transfer()
6127 auth_chunks_delete(xfr->task_transfer); in process_list_end_transfer()
6129 xfr->task_transfer->ixfr_fail = 1; in process_list_end_transfer()
6143 log_assert(xfr->task_transfer); in auth_xfer_transfer_timer_callback()
6144 lock_basic_lock(&xfr->lock); in auth_xfer_transfer_timer_callback()
6145 env = xfr->task_transfer->env; in auth_xfer_transfer_timer_callback()
6146 if(!env || env->outnet->want_to_quit) { in auth_xfer_transfer_timer_callback()
6147 lock_basic_unlock(&xfr->lock); in auth_xfer_transfer_timer_callback()
6152 xfr->task_transfer->master->host); in auth_xfer_transfer_timer_callback()
6155 if(xfr->task_transfer->on_ixfr) { in auth_xfer_transfer_timer_callback()
6156 xfr->task_transfer->ixfr_possible_timeout_count++; in auth_xfer_transfer_timer_callback()
6157 if(xfr->task_transfer->ixfr_possible_timeout_count >= in auth_xfer_transfer_timer_callback()
6161 xfr->task_transfer->master->host); in auth_xfer_transfer_timer_callback()
6162 xfr->task_transfer->ixfr_fail = 1; in auth_xfer_transfer_timer_callback()
6168 auth_chunks_delete(xfr->task_transfer); in auth_xfer_transfer_timer_callback()
6169 comm_point_delete(xfr->task_transfer->cp); in auth_xfer_transfer_timer_callback()
6170 xfr->task_transfer->cp = NULL; in auth_xfer_transfer_timer_callback()
6185 log_assert(xfr->task_transfer); in auth_xfer_transfer_tcp_callback()
6186 lock_basic_lock(&xfr->lock); in auth_xfer_transfer_tcp_callback()
6187 env = xfr->task_transfer->env; in auth_xfer_transfer_tcp_callback()
6188 if(!env || env->outnet->want_to_quit) { in auth_xfer_transfer_tcp_callback()
6189 lock_basic_unlock(&xfr->lock); in auth_xfer_transfer_tcp_callback()
6193 comm_timer_disable(xfr->task_transfer->timer); in auth_xfer_transfer_tcp_callback()
6197 /* stop this transfer, cleanup in auth_xfer_transfer_tcp_callback()
6200 xfr->task_transfer->master->host); in auth_xfer_transfer_tcp_callback()
6203 if(xfr->task_transfer->on_ixfr) { in auth_xfer_transfer_tcp_callback()
6204 xfr->task_transfer->ixfr_possible_timeout_count++; in auth_xfer_transfer_tcp_callback()
6205 if(xfr->task_transfer->ixfr_possible_timeout_count >= in auth_xfer_transfer_tcp_callback()
6209 xfr->task_transfer->master->host); in auth_xfer_transfer_tcp_callback()
6210 xfr->task_transfer->ixfr_fail = 1; in auth_xfer_transfer_tcp_callback()
6217 auth_chunks_delete(xfr->task_transfer); in auth_xfer_transfer_tcp_callback()
6218 comm_point_delete(xfr->task_transfer->cp); in auth_xfer_transfer_tcp_callback()
6219 xfr->task_transfer->cp = NULL; in auth_xfer_transfer_tcp_callback()
6226 if(xfr->task_transfer->on_ixfr) in auth_xfer_transfer_tcp_callback()
6227 xfr->task_transfer->ixfr_possible_timeout_count = 0; in auth_xfer_transfer_tcp_callback()
6230 /* if it fails, cleanup and end this transfer */ in auth_xfer_transfer_tcp_callback()
6232 if(!check_xfer_packet(c->buffer, xfr, &gonextonfail, &transferdone)) { in auth_xfer_transfer_tcp_callback()
6237 if(!xfer_link_data(c->buffer, xfr)) { in auth_xfer_transfer_tcp_callback()
6239 xfr->task_transfer->master->host); in auth_xfer_transfer_tcp_callback()
6242 /* if the transfer is done now, disconnect and process the list */ in auth_xfer_transfer_tcp_callback()
6244 comm_point_delete(xfr->task_transfer->cp); in auth_xfer_transfer_tcp_callback()
6245 xfr->task_transfer->cp = NULL; in auth_xfer_transfer_tcp_callback()
6252 lock_basic_unlock(&xfr->lock); in auth_xfer_transfer_tcp_callback()
6253 c->tcp_is_reading = 1; in auth_xfer_transfer_tcp_callback()
6254 sldns_buffer_clear(c->buffer); in auth_xfer_transfer_tcp_callback()
6255 comm_point_start_listening(c, -1, AUTH_TRANSFER_TIMEOUT); in auth_xfer_transfer_tcp_callback()
6266 log_assert(xfr->task_transfer); in auth_xfer_transfer_http_callback()
6267 lock_basic_lock(&xfr->lock); in auth_xfer_transfer_http_callback()
6268 env = xfr->task_transfer->env; in auth_xfer_transfer_http_callback()
6269 if(!env || env->outnet->want_to_quit) { in auth_xfer_transfer_http_callback()
6270 lock_basic_unlock(&xfr->lock); in auth_xfer_transfer_http_callback()
6273 verbose(VERB_ALGO, "auth zone transfer http callback"); in auth_xfer_transfer_http_callback()
6275 comm_timer_disable(xfr->task_transfer->timer); in auth_xfer_transfer_http_callback()
6279 /* stop this transfer, cleanup in auth_xfer_transfer_http_callback()
6282 xfr->task_transfer->master->host); in auth_xfer_transfer_http_callback()
6285 auth_chunks_delete(xfr->task_transfer); in auth_xfer_transfer_http_callback()
6286 if(repinfo) repinfo->c = NULL; /* signal cp deleted to in auth_xfer_transfer_http_callback()
6288 comm_point_delete(xfr->task_transfer->cp); in auth_xfer_transfer_http_callback()
6289 xfr->task_transfer->cp = NULL; in auth_xfer_transfer_http_callback()
6297 if(sldns_buffer_limit(c->buffer) > 0) { in auth_xfer_transfer_http_callback()
6299 (int)sldns_buffer_limit(c->buffer)); in auth_xfer_transfer_http_callback()
6300 if(!xfer_link_data(c->buffer, xfr)) { in auth_xfer_transfer_http_callback()
6302 xfr->task_transfer->master->host); in auth_xfer_transfer_http_callback()
6306 /* if the transfer is done now, disconnect and process the list */ in auth_xfer_transfer_http_callback()
6308 if(repinfo) repinfo->c = NULL; /* signal cp deleted to in auth_xfer_transfer_http_callback()
6310 comm_point_delete(xfr->task_transfer->cp); in auth_xfer_transfer_http_callback()
6311 xfr->task_transfer->cp = NULL; in auth_xfer_transfer_http_callback()
6318 lock_basic_unlock(&xfr->lock); in auth_xfer_transfer_http_callback()
6319 c->tcp_is_reading = 1; in auth_xfer_transfer_http_callback()
6320 sldns_buffer_clear(c->buffer); in auth_xfer_transfer_http_callback()
6321 comm_point_start_listening(c, -1, AUTH_TRANSFER_TIMEOUT); in auth_xfer_transfer_http_callback()
6326 /** start transfer task by this worker , xfr is locked. */
6331 log_assert(xfr->task_transfer != NULL); in xfr_start_transfer()
6332 log_assert(xfr->task_transfer->worker == NULL); in xfr_start_transfer()
6333 log_assert(xfr->task_transfer->chunks_first == NULL); in xfr_start_transfer()
6334 log_assert(xfr->task_transfer->chunks_last == NULL); in xfr_start_transfer()
6335 xfr->task_transfer->worker = env->worker; in xfr_start_transfer()
6336 xfr->task_transfer->env = env; in xfr_start_transfer()
6338 /* init transfer process */ in xfr_start_transfer()
6339 /* find that master in the transfer's list of masters? */ in xfr_start_transfer()
6341 /* start lookup for hostnames in transfer master list */ in xfr_start_transfer()
6353 comm_timer_delete(xfr->task_probe->timer); in xfr_probe_disown()
6354 xfr->task_probe->timer = NULL; in xfr_probe_disown()
6356 comm_point_delete(xfr->task_probe->cp); in xfr_probe_disown()
6357 xfr->task_probe->cp = NULL; in xfr_probe_disown()
6359 xfr->task_probe->worker = NULL; in xfr_probe_disown()
6360 xfr->task_probe->env = NULL; in xfr_probe_disown()
6375 if(master->allow_notify) return 0; /* only for notify */ in xfr_probe_send_probe()
6376 if(master->http) return 0; /* only masters get SOA UDP probe, in xfr_probe_send_probe()
6380 if(xfr->task_probe->scan_addr) { in xfr_probe_send_probe()
6381 addrlen = xfr->task_probe->scan_addr->addrlen; in xfr_probe_send_probe()
6382 memmove(&addr, &xfr->task_probe->scan_addr->addr, addrlen); in xfr_probe_send_probe()
6384 if(!authextstrtoaddr(master->host, &addr, &addrlen, &auth_name)) { in xfr_probe_send_probe()
6389 dname_str(xfr->name, zname); in xfr_probe_send_probe()
6391 zname, master->host); in xfr_probe_send_probe()
6396 && (int)ntohs(((struct sockaddr_in *)&addr)->sin_port) in xfr_probe_send_probe()
6397 == env->cfg->ssl_port) in xfr_probe_send_probe()
6398 ((struct sockaddr_in *)&addr)->sin_port in xfr_probe_send_probe()
6399 = htons((uint16_t)env->cfg->port); in xfr_probe_send_probe()
6401 && (int)ntohs(((struct sockaddr_in6 *)&addr)->sin6_port) in xfr_probe_send_probe()
6402 == env->cfg->ssl_port) in xfr_probe_send_probe()
6403 ((struct sockaddr_in6 *)&addr)->sin6_port in xfr_probe_send_probe()
6404 = htons((uint16_t)env->cfg->port); in xfr_probe_send_probe()
6412 xfr->task_probe->id = GET_RANDOM_ID(env->rnd); in xfr_probe_send_probe()
6413 xfr_create_soa_probe_packet(xfr, env->scratch_buffer, in xfr_probe_send_probe()
6414 xfr->task_probe->id); in xfr_probe_send_probe()
6416 if(xfr->task_probe->cp && in xfr_probe_send_probe()
6417 ((xfr->task_probe->cp_is_ip6 && !addr_is_ip6(&addr, addrlen)) || in xfr_probe_send_probe()
6418 (!xfr->task_probe->cp_is_ip6 && addr_is_ip6(&addr, addrlen))) in xfr_probe_send_probe()
6420 comm_point_delete(xfr->task_probe->cp); in xfr_probe_send_probe()
6421 xfr->task_probe->cp = NULL; in xfr_probe_send_probe()
6423 if(!xfr->task_probe->cp) { in xfr_probe_send_probe()
6425 xfr->task_probe->cp_is_ip6 = 1; in xfr_probe_send_probe()
6426 else xfr->task_probe->cp_is_ip6 = 0; in xfr_probe_send_probe()
6427 xfr->task_probe->cp = outnet_comm_point_for_udp(env->outnet, in xfr_probe_send_probe()
6429 if(!xfr->task_probe->cp) { in xfr_probe_send_probe()
6431 dname_str(xfr->name, zname); in xfr_probe_send_probe()
6438 if(!xfr->task_probe->timer) { in xfr_probe_send_probe()
6439 xfr->task_probe->timer = comm_timer_create(env->worker_base, in xfr_probe_send_probe()
6441 if(!xfr->task_probe->timer) { in xfr_probe_send_probe()
6448 if(!comm_point_send_udp_msg(xfr->task_probe->cp, env->scratch_buffer, in xfr_probe_send_probe()
6451 dname_str(xfr->name, zname); in xfr_probe_send_probe()
6459 dname_str(xfr->name, zname); in xfr_probe_send_probe()
6464 xfr->task_probe->timeout = timeout; in xfr_probe_send_probe()
6469 comm_timer_set(xfr->task_probe->timer, &t); in xfr_probe_send_probe()
6480 log_assert(xfr->task_probe); in auth_xfer_probe_timer_callback()
6481 lock_basic_lock(&xfr->lock); in auth_xfer_probe_timer_callback()
6482 env = xfr->task_probe->env; in auth_xfer_probe_timer_callback()
6483 if(!env || env->outnet->want_to_quit) { in auth_xfer_probe_timer_callback()
6484 lock_basic_unlock(&xfr->lock); in auth_xfer_probe_timer_callback()
6490 dname_str(xfr->name, zname); in auth_xfer_probe_timer_callback()
6493 if(xfr->task_probe->timeout <= AUTH_PROBE_TIMEOUT_STOP) { in auth_xfer_probe_timer_callback()
6495 if(xfr_probe_send_probe(xfr, env, xfr->task_probe->timeout*2)) { in auth_xfer_probe_timer_callback()
6496 lock_basic_unlock(&xfr->lock); in auth_xfer_probe_timer_callback()
6501 comm_point_delete(xfr->task_probe->cp); in auth_xfer_probe_timer_callback()
6502 xfr->task_probe->cp = NULL; in auth_xfer_probe_timer_callback()
6516 log_assert(xfr->task_probe); in auth_xfer_probe_udp_callback()
6517 lock_basic_lock(&xfr->lock); in auth_xfer_probe_udp_callback()
6518 env = xfr->task_probe->env; in auth_xfer_probe_udp_callback()
6519 if(!env || env->outnet->want_to_quit) { in auth_xfer_probe_udp_callback()
6520 lock_basic_unlock(&xfr->lock); in auth_xfer_probe_udp_callback()
6526 repinfo->c = NULL; in auth_xfer_probe_udp_callback()
6528 comm_timer_disable(xfr->task_probe->timer); in auth_xfer_probe_udp_callback()
6533 if(check_packet_ok(c->buffer, LDNS_RR_TYPE_SOA, xfr, in auth_xfer_probe_udp_callback()
6538 dname_str(xfr->name, buf); in auth_xfer_probe_udp_callback()
6545 /* if updated, start the transfer task, if needed */ in auth_xfer_probe_udp_callback()
6546 verbose(VERB_ALGO, "auth_zone updated, start transfer"); in auth_xfer_probe_udp_callback()
6547 if(xfr->task_transfer->worker == NULL) { in auth_xfer_probe_udp_callback()
6553 if(xfr->task_transfer->masters && in auth_xfer_probe_udp_callback()
6554 xfr->task_transfer->masters->http) in auth_xfer_probe_udp_callback()
6563 lock_basic_unlock(&xfr->lock); in auth_xfer_probe_udp_callback()
6572 xfr->task_probe->have_new_lease = 1; in auth_xfer_probe_udp_callback()
6577 dname_str(xfr->name, buf); in auth_xfer_probe_udp_callback()
6584 dname_str(xfr->name, buf); in auth_xfer_probe_udp_callback()
6591 comm_point_delete(xfr->task_probe->cp); in auth_xfer_probe_udp_callback()
6592 xfr->task_probe->cp = NULL; in auth_xfer_probe_udp_callback()
6607 struct auth_master* master = xfr->task_probe->lookup_target; in xfr_probe_lookup_host()
6612 sldns_buffer* buf = env->scratch_buffer; in xfr_probe_lookup_host()
6614 if(extstrtoaddr(master->host, &addr, &addrlen, UNBOUND_DNS_PORT)) { in xfr_probe_lookup_host()
6618 if(master->allow_notify && !master->http && in xfr_probe_lookup_host()
6619 strchr(master->host, '/') != NULL && in xfr_probe_lookup_host()
6620 strchr(master->host, '/') == strrchr(master->host, '/')) { in xfr_probe_lookup_host()
6624 /* use mesh_new_callback to probe for non-addr hosts, in xfr_probe_lookup_host()
6627 if(sldns_str2wire_dname_buf(master->host, dname, &qinfo.qname_len) in xfr_probe_lookup_host()
6629 log_err("cannot parse host name of master %s", master->host); in xfr_probe_lookup_host()
6633 qinfo.qclass = xfr->dclass; in xfr_probe_lookup_host()
6635 if(xfr->task_probe->lookup_aaaa) in xfr_probe_lookup_host()
6641 dname_str(xfr->name, buf2); in xfr_probe_lookup_host()
6649 edns.bits = EDNS_DO; in xfr_probe_lookup_host()
6662 lock_basic_unlock(&xfr->lock); in xfr_probe_lookup_host()
6663 if(!mesh_new_callback(env->mesh, &qinfo, qflags, &edns, buf, 0, in xfr_probe_lookup_host()
6665 lock_basic_lock(&xfr->lock); in xfr_probe_lookup_host()
6666 log_err("out of memory lookup up master %s", master->host); in xfr_probe_lookup_host()
6669 lock_basic_lock(&xfr->lock); in xfr_probe_lookup_host()
6678 while(xfr->task_probe->lookup_target) { in xfr_probe_send_or_end()
6687 dname_str(xfr->name, zname); in xfr_probe_send_or_end()
6690 lock_basic_unlock(&xfr->lock); in xfr_probe_send_or_end()
6700 dname_str(xfr->name, zname); in xfr_probe_send_or_end()
6703 if(xfr->task_probe->only_lookup) { in xfr_probe_send_or_end()
6705 xfr->task_probe->only_lookup = 0; in xfr_probe_send_or_end()
6708 dname_str(xfr->name, zname); in xfr_probe_send_or_end()
6712 if(xfr->task_nextprobe->worker == NULL) in xfr_probe_send_or_end()
6714 lock_basic_unlock(&xfr->lock); in xfr_probe_send_or_end()
6722 lock_basic_unlock(&xfr->lock); in xfr_probe_send_or_end()
6730 if(xfr->task_probe->have_new_lease) { in xfr_probe_send_or_end()
6734 dname_str(xfr->name, zname); in xfr_probe_send_or_end()
6738 if(xfr->have_zone) in xfr_probe_send_or_end()
6739 xfr->lease_time = *env->now; in xfr_probe_send_or_end()
6740 if(xfr->task_nextprobe->worker == NULL) in xfr_probe_send_or_end()
6745 dname_str(xfr->name, zname); in xfr_probe_send_or_end()
6752 if(xfr->task_nextprobe->worker == NULL) in xfr_probe_send_or_end()
6756 lock_basic_unlock(&xfr->lock); in xfr_probe_send_or_end()
6766 log_assert(xfr->task_probe); in auth_xfer_probe_lookup_callback()
6767 lock_basic_lock(&xfr->lock); in auth_xfer_probe_lookup_callback()
6768 env = xfr->task_probe->env; in auth_xfer_probe_lookup_callback()
6769 if(!env || env->outnet->want_to_quit) { in auth_xfer_probe_lookup_callback()
6770 lock_basic_unlock(&xfr->lock); in auth_xfer_probe_lookup_callback()
6777 struct regional* temp = env->scratch; in auth_xfer_probe_lookup_callback()
6780 if(xfr->task_probe->lookup_aaaa) in auth_xfer_probe_lookup_callback()
6785 FLAGS_GET_RCODE(rep->flags) == LDNS_RCODE_NOERROR) { in auth_xfer_probe_lookup_callback()
6790 xfr_master_add_addrs(xfr->task_probe-> in auth_xfer_probe_lookup_callback()
6795 dname_str(xfr->name, zname); in auth_xfer_probe_lookup_callback()
6796 …st %s type %s probe lookup has nodata", zname, xfr->task_probe->lookup_target->host, (xfr->task_pr… in auth_xfer_probe_lookup_callback()
6802 dname_str(xfr->name, zname); in auth_xfer_probe_lookup_callback()
6803 …s type %s probe lookup has no address", zname, xfr->task_probe->lookup_target->host, (xfr->task_pr… in auth_xfer_probe_lookup_callback()
6810 dname_str(xfr->name, zname); in auth_xfer_probe_lookup_callback()
6811 …s host %s type %s probe lookup failed", zname, xfr->task_probe->lookup_target->host, (xfr->task_pr… in auth_xfer_probe_lookup_callback()
6814 if(xfr->task_probe->lookup_target->list && in auth_xfer_probe_lookup_callback()
6815 xfr->task_probe->lookup_target == xfr_probe_current_master(xfr)) in auth_xfer_probe_lookup_callback()
6816 xfr->task_probe->scan_addr = xfr->task_probe->lookup_target->list; in auth_xfer_probe_lookup_callback()
6830 comm_timer_delete(xfr->task_nextprobe->timer); in xfr_nextprobe_disown()
6831 xfr->task_nextprobe->timer = NULL; in xfr_nextprobe_disown()
6832 xfr->task_nextprobe->next_probe = 0; in xfr_nextprobe_disown()
6834 xfr->task_nextprobe->worker = NULL; in xfr_nextprobe_disown()
6835 xfr->task_nextprobe->env = NULL; in xfr_nextprobe_disown()
6844 log_assert(xfr->task_nextprobe); in auth_xfer_timer()
6845 lock_basic_lock(&xfr->lock); in auth_xfer_timer()
6846 env = xfr->task_nextprobe->env; in auth_xfer_timer()
6847 if(!env || env->outnet->want_to_quit) { in auth_xfer_timer()
6848 lock_basic_unlock(&xfr->lock); in auth_xfer_timer()
6853 if(xfr->have_zone && !xfr->zone_expired && in auth_xfer_timer()
6854 *env->now >= xfr->lease_time + xfr->expiry) { in auth_xfer_timer()
6855 lock_basic_unlock(&xfr->lock); in auth_xfer_timer()
6857 lock_basic_lock(&xfr->lock); in auth_xfer_timer()
6864 lock_basic_unlock(&xfr->lock); in auth_xfer_timer()
6873 for(p=list; p; p = p->next) { in have_probe_targets()
6874 if(!p->allow_notify && p->host) in have_probe_targets()
6889 if(xfr->task_probe->worker == NULL) { in xfr_start_probe()
6890 if(!have_probe_targets(xfr->task_probe->masters) && in xfr_start_probe()
6891 !(xfr->task_probe->only_lookup && in xfr_start_probe()
6892 xfr->task_probe->masters != NULL)) { in xfr_start_probe()
6894 * probe. Instead attempt to pick up task transfer */ in xfr_start_probe()
6895 if(xfr->task_transfer->worker == NULL) { in xfr_start_probe()
6899 /* task transfer already in progress */ in xfr_start_probe()
6904 xfr->task_probe->worker = env->worker; in xfr_start_probe()
6905 xfr->task_probe->env = env; in xfr_start_probe()
6906 xfr->task_probe->cp = NULL; in xfr_start_probe()
6910 xfr->task_probe->have_new_lease = 0; in xfr_start_probe()
6913 * first and also transfer first from it */ in xfr_start_probe()
6936 log_assert(xfr->task_nextprobe != NULL); in xfr_set_timeout()
6937 log_assert(xfr->task_nextprobe->worker == NULL || in xfr_set_timeout()
6938 xfr->task_nextprobe->worker == env->worker); in xfr_set_timeout()
6942 xfr->task_nextprobe->next_probe = *env->now; in xfr_set_timeout()
6943 if(xfr->lease_time && !failure) in xfr_set_timeout()
6944 xfr->task_nextprobe->next_probe = xfr->lease_time; in xfr_set_timeout()
6947 xfr->task_nextprobe->backoff = 0; in xfr_set_timeout()
6949 if(xfr->task_nextprobe->backoff == 0) in xfr_set_timeout()
6950 xfr->task_nextprobe->backoff = 3; in xfr_set_timeout()
6951 else xfr->task_nextprobe->backoff *= 2; in xfr_set_timeout()
6952 if(xfr->task_nextprobe->backoff > AUTH_TRANSFER_MAX_BACKOFF) in xfr_set_timeout()
6953 xfr->task_nextprobe->backoff = in xfr_set_timeout()
6957 if(xfr->have_zone) { in xfr_set_timeout()
6958 time_t wait = xfr->refresh; in xfr_set_timeout()
6959 if(failure) wait = xfr->retry; in xfr_set_timeout()
6960 if(xfr->expiry < wait) in xfr_set_timeout()
6961 xfr->task_nextprobe->next_probe += xfr->expiry; in xfr_set_timeout()
6962 else xfr->task_nextprobe->next_probe += wait; in xfr_set_timeout()
6964 xfr->task_nextprobe->next_probe += in xfr_set_timeout()
6965 xfr->task_nextprobe->backoff; in xfr_set_timeout()
6967 if(xfr->lease_time && xfr->lease_time+xfr->expiry < in xfr_set_timeout()
6968 xfr->task_nextprobe->next_probe && in xfr_set_timeout()
6969 xfr->lease_time+xfr->expiry > *env->now) in xfr_set_timeout()
6970 xfr->task_nextprobe->next_probe = in xfr_set_timeout()
6971 xfr->lease_time+xfr->expiry; in xfr_set_timeout()
6973 xfr->task_nextprobe->next_probe += in xfr_set_timeout()
6974 xfr->task_nextprobe->backoff; in xfr_set_timeout()
6977 if(!xfr->task_nextprobe->timer) { in xfr_set_timeout()
6978 xfr->task_nextprobe->timer = comm_timer_create( in xfr_set_timeout()
6979 env->worker_base, auth_xfer_timer, xfr); in xfr_set_timeout()
6980 if(!xfr->task_nextprobe->timer) { in xfr_set_timeout()
6981 /* failed to malloc memory. likely zone transfer in xfr_set_timeout()
6984 dname_str(xfr->name, zname); in xfr_set_timeout()
6990 xfr->task_nextprobe->worker = env->worker; in xfr_set_timeout()
6991 xfr->task_nextprobe->env = env; in xfr_set_timeout()
6992 if(*(xfr->task_nextprobe->env->now) <= xfr->task_nextprobe->next_probe) in xfr_set_timeout()
6993 tv.tv_sec = xfr->task_nextprobe->next_probe - in xfr_set_timeout()
6994 *(xfr->task_nextprobe->env->now); in xfr_set_timeout()
6996 if(tv.tv_sec != 0 && lookup_only && xfr->task_probe->masters) { in xfr_set_timeout()
7000 if(xfr->task_probe->worker == NULL) in xfr_set_timeout()
7001 xfr->task_probe->only_lookup = 1; in xfr_set_timeout()
7005 dname_str(xfr->name, zname); in xfr_set_timeout()
7010 comm_timer_set(xfr->task_nextprobe->timer, &tv); in xfr_set_timeout()
7018 lock_rw_wrlock(&az->lock); in auth_xfer_pickup_initial()
7019 RBTREE_FOR(x, struct auth_xfer*, &az->xtree) { in auth_xfer_pickup_initial()
7020 lock_basic_lock(&x->lock); in auth_xfer_pickup_initial()
7024 if(x->have_zone) in auth_xfer_pickup_initial()
7025 x->lease_time = *env->now; in auth_xfer_pickup_initial()
7026 if(x->task_nextprobe && x->task_nextprobe->worker == NULL) { in auth_xfer_pickup_initial()
7029 lock_basic_unlock(&x->lock); in auth_xfer_pickup_initial()
7031 lock_rw_unlock(&az->lock); in auth_xfer_pickup_initial()
7037 lock_rw_wrlock(&az->lock); in auth_zones_cleanup()
7038 RBTREE_FOR(x, struct auth_xfer*, &az->xtree) { in auth_zones_cleanup()
7039 lock_basic_lock(&x->lock); in auth_zones_cleanup()
7040 if(x->task_nextprobe && x->task_nextprobe->worker != NULL) { in auth_zones_cleanup()
7043 if(x->task_probe && x->task_probe->worker != NULL) { in auth_zones_cleanup()
7046 if(x->task_transfer && x->task_transfer->worker != NULL) { in auth_zones_cleanup()
7047 auth_chunks_delete(x->task_transfer); in auth_zones_cleanup()
7050 lock_basic_unlock(&x->lock); in auth_zones_cleanup()
7052 lock_rw_unlock(&az->lock); in auth_zones_cleanup()
7065 xfr->name = memdup(z->name, z->namelen); in auth_xfer_new()
7066 if(!xfr->name) { in auth_xfer_new()
7070 xfr->node.key = xfr; in auth_xfer_new()
7071 xfr->namelen = z->namelen; in auth_xfer_new()
7072 xfr->namelabs = z->namelabs; in auth_xfer_new()
7073 xfr->dclass = z->dclass; in auth_xfer_new()
7075 xfr->task_nextprobe = (struct auth_nextprobe*)calloc(1, in auth_xfer_new()
7077 if(!xfr->task_nextprobe) { in auth_xfer_new()
7078 free(xfr->name); in auth_xfer_new()
7082 xfr->task_probe = (struct auth_probe*)calloc(1, in auth_xfer_new()
7084 if(!xfr->task_probe) { in auth_xfer_new()
7085 free(xfr->task_nextprobe); in auth_xfer_new()
7086 free(xfr->name); in auth_xfer_new()
7090 xfr->task_transfer = (struct auth_transfer*)calloc(1, in auth_xfer_new()
7092 if(!xfr->task_transfer) { in auth_xfer_new()
7093 free(xfr->task_probe); in auth_xfer_new()
7094 free(xfr->task_nextprobe); in auth_xfer_new()
7095 free(xfr->name); in auth_xfer_new()
7100 lock_basic_init(&xfr->lock); in auth_xfer_new()
7101 lock_protect(&xfr->lock, &xfr->name, sizeof(xfr->name)); in auth_xfer_new()
7102 lock_protect(&xfr->lock, &xfr->namelen, sizeof(xfr->namelen)); in auth_xfer_new()
7103 lock_protect(&xfr->lock, xfr->name, xfr->namelen); in auth_xfer_new()
7104 lock_protect(&xfr->lock, &xfr->namelabs, sizeof(xfr->namelabs)); in auth_xfer_new()
7105 lock_protect(&xfr->lock, &xfr->dclass, sizeof(xfr->dclass)); in auth_xfer_new()
7106 lock_protect(&xfr->lock, &xfr->notify_received, sizeof(xfr->notify_received)); in auth_xfer_new()
7107 lock_protect(&xfr->lock, &xfr->notify_serial, sizeof(xfr->notify_serial)); in auth_xfer_new()
7108 lock_protect(&xfr->lock, &xfr->zone_expired, sizeof(xfr->zone_expired)); in auth_xfer_new()
7109 lock_protect(&xfr->lock, &xfr->have_zone, sizeof(xfr->have_zone)); in auth_xfer_new()
7110 lock_protect(&xfr->lock, &xfr->serial, sizeof(xfr->serial)); in auth_xfer_new()
7111 lock_protect(&xfr->lock, &xfr->retry, sizeof(xfr->retry)); in auth_xfer_new()
7112 lock_protect(&xfr->lock, &xfr->refresh, sizeof(xfr->refresh)); in auth_xfer_new()
7113 lock_protect(&xfr->lock, &xfr->expiry, sizeof(xfr->expiry)); in auth_xfer_new()
7114 lock_protect(&xfr->lock, &xfr->lease_time, sizeof(xfr->lease_time)); in auth_xfer_new()
7115 lock_protect(&xfr->lock, &xfr->task_nextprobe->worker, in auth_xfer_new()
7116 sizeof(xfr->task_nextprobe->worker)); in auth_xfer_new()
7117 lock_protect(&xfr->lock, &xfr->task_probe->worker, in auth_xfer_new()
7118 sizeof(xfr->task_probe->worker)); in auth_xfer_new()
7119 lock_protect(&xfr->lock, &xfr->task_transfer->worker, in auth_xfer_new()
7120 sizeof(xfr->task_transfer->worker)); in auth_xfer_new()
7121 lock_basic_lock(&xfr->lock); in auth_xfer_new()
7127 * and sets the timeout, if a zone transfer is needed a short timeout is set.
7142 (void)rbtree_insert(&az->xtree, &xfr->node); in auth_xfer_create()
7159 (*list) = &(m->next); in auth_master_new()
7165 dup_prefix(char* str, size_t num) in dup_prefix() argument
7169 if(len < num) num = len; /* not more than strlen */ in dup_prefix()
7170 result = (char*)malloc(num+1); in dup_prefix()
7175 memmove(result, str, num); in dup_prefix()
7176 result[num] = 0; in dup_prefix()
7224 char* uri = dup_prefix(p, (size_t)(strstr(p, "://")-p)); in parse_url()
7236 *host = dup_prefix(p, (size_t)(end-p)); in parse_url()
7247 *host = dup_prefix(p, (size_t)(end-p)); in parse_url()
7284 list = &( (*list)->next ); in xfer_set_masters()
7287 for(p = c->urls; p; p = p->next) { in xfer_set_masters()
7290 m->http = 1; in xfer_set_masters()
7291 if(!parse_url(p->str, &m->host, &m->file, &m->port, &m->ssl)) in xfer_set_masters()
7294 for(p = c->masters; p; p = p->next) { in xfer_set_masters()
7297 m->ixfr = 1; /* this flag is not configurable */ in xfer_set_masters()
7298 m->host = strdup(p->str); in xfer_set_masters()
7299 if(!m->host) { in xfer_set_masters()
7304 for(p = c->allow_notify; p; p = p->next) { in xfer_set_masters()
7307 m->allow_notify = 1; in xfer_set_masters()
7308 m->host = strdup(p->str); in xfer_set_masters()
7309 if(!m->host) { in xfer_set_masters()
7321 const uint32_t cutoff = ((uint32_t) 1 << (SERIAL_BITS - 1)); in compare_serial()
7325 } else if ((a < b && b - a < cutoff) || (a > b && a - b > cutoff)) { in compare_serial()
7326 return -1; in compare_serial()
7424 size_t num = 0; in authdata_rrsets_to_list() local
7426 if(num >= arraysize) in authdata_rrsets_to_list()
7427 return num; in authdata_rrsets_to_list()
7428 array[num] = rrset; in authdata_rrsets_to_list()
7429 num++; in authdata_rrsets_to_list()
7430 rrset = rrset->next; in authdata_rrsets_to_list()
7432 return num; in authdata_rrsets_to_list()
7442 else t1 = r1->type; in rrlist_compare()
7444 else t2 = r2->type; in rrlist_compare()
7446 return -1; in rrlist_compare()
7475 key.entry.data = rrset->data; in zonemd_simple_rrset()
7476 key.rk.dname = node->name; in zonemd_simple_rrset()
7477 key.rk.dname_len = node->namelen; in zonemd_simple_rrset()
7478 key.rk.type = htons(rrset->type); in zonemd_simple_rrset()
7479 key.rk.rrset_class = htons(z->dclass); in zonemd_simple_rrset()
7502 for(j = 0; j<rrset->data->count; j++) { in zonemd_simple_count_rrsig()
7503 if(rrsig_rdata_get_type_covered(rrset->data-> in zonemd_simple_count_rrsig()
7504 rr_data[j], rrset->data->rr_len[j]) == in zonemd_simple_count_rrsig()
7506 query_dname_compare(z->name, node->name)==0) { in zonemd_simple_count_rrsig()
7514 if(rrlist[i] && rrlist[i]->type == LDNS_RR_TYPE_ZONEMD && in zonemd_simple_count_rrsig()
7515 query_dname_compare(z->name, node->name)==0) { in zonemd_simple_count_rrsig()
7519 count += (rrlist[i]?rrlist[i]->data->rrsig_count:0); in zonemd_simple_count_rrsig()
7528 data->rr_len = regional_alloc(region, sizeof(*data->rr_len) * count); in zonemd_simple_rrsig_allocs()
7529 if(!data->rr_len) { in zonemd_simple_rrsig_allocs()
7532 data->rr_ttl = regional_alloc(region, sizeof(*data->rr_ttl) * count); in zonemd_simple_rrsig_allocs()
7533 if(!data->rr_ttl) { in zonemd_simple_rrsig_allocs()
7536 data->rr_data = regional_alloc(region, sizeof(*data->rr_data) * count); in zonemd_simple_rrsig_allocs()
7537 if(!data->rr_data) { in zonemd_simple_rrsig_allocs()
7553 if(rrlist[i]->type == LDNS_RR_TYPE_ZONEMD && in add_rrlist_rrsigs_into_data()
7554 query_dname_compare(z->name, node->name)==0) { in add_rrlist_rrsigs_into_data()
7558 for(j = 0; j<rrlist[i]->data->rrsig_count; j++) { in add_rrlist_rrsigs_into_data()
7559 data->rr_len[*done] = rrlist[i]->data->rr_len[rrlist[i]->data->count + j]; in add_rrlist_rrsigs_into_data()
7560 data->rr_ttl[*done] = rrlist[i]->data->rr_ttl[rrlist[i]->data->count + j]; in add_rrlist_rrsigs_into_data()
7564 data->rr_data[*done] = rrlist[i]->data->rr_data[rrlist[i]->data->count + j]; in add_rrlist_rrsigs_into_data()
7576 for(j = 0; j<rrset->data->count; j++) { in add_rrset_into_data()
7577 if(rrsig_rdata_get_type_covered(rrset->data-> in add_rrset_into_data()
7578 rr_data[j], rrset->data->rr_len[j]) == in add_rrset_into_data()
7580 query_dname_compare(z->name, node->name)==0) { in add_rrset_into_data()
7584 data->rr_len[*done] = rrset->data->rr_len[j]; in add_rrset_into_data()
7585 data->rr_ttl[*done] = rrset->data->rr_ttl[j]; in add_rrset_into_data()
7589 data->rr_data[*done] = rrset->data->rr_data[j]; in add_rrset_into_data()
7620 key.rk.dname = node->name; in zonemd_simple_rrsig()
7621 key.rk.dname_len = node->namelen; in zonemd_simple_rrsig()
7623 key.rk.rrset_class = htons(z->dclass); in zonemd_simple_rrsig()
7661 if(!dname_subdomain_c(node->name, z->name)) in zonemd_simple_domain()
7664 rrnum = authdata_rrsets_to_list(rrlist, rrlistsize, node->rrsets); in zonemd_simple_domain()
7668 if(rrlist[i] && rrlist[i]->type == LDNS_RR_TYPE_ZONEMD && in zonemd_simple_domain()
7669 query_dname_compare(z->name, node->name) == 0) { in zonemd_simple_domain()
7673 if(rrlist[i] == NULL || rrlist[i]->type == in zonemd_simple_domain()
7694 RBTREE_FOR(n, struct auth_data*, &z->data) { in zonemd_simple_collate()
7813 if(m == -1) { in zonemd_dnssec_verify_rrset()
7814 auth_zone_log(z->name, VERB_ALGO, "zonemd dnssec verify: have " in zonemd_dnssec_verify_rrset()
7818 ve = (struct val_env*)env->modinfo[m]; in zonemd_dnssec_verify_rrset()
7822 pk.entry.data = rrset->data; in zonemd_dnssec_verify_rrset()
7823 pk.rk.dname = node->name; in zonemd_dnssec_verify_rrset()
7824 pk.rk.dname_len = node->namelen; in zonemd_dnssec_verify_rrset()
7825 pk.rk.type = htons(rrset->type); in zonemd_dnssec_verify_rrset()
7826 pk.rk.rrset_class = htons(z->dclass); in zonemd_dnssec_verify_rrset()
7830 sldns_wire2str_type_buf(rrset->type, typestr, sizeof(typestr)); in zonemd_dnssec_verify_rrset()
7831 auth_zone_log(z->name, VERB_ALGO, in zonemd_dnssec_verify_rrset()
7840 auth_zone_log(z->name, VERB_ALGO, "DNSSEC verify was bogus: %s", *why_bogus); in zonemd_dnssec_verify_rrset()
7848 int i, count = (int)nsec3->data->count; in nsec3_of_param_has_type()
7851 pk.entry.data = nsec3->data; in nsec3_of_param_has_type()
7897 pk.entry.data = nsec->data; in zonemd_check_dnssec_absence()
7902 auth_zone_log(z->name, VERB_ALGO, "zonemd DNSSEC NSEC verification of absence of ZONEMD secure"); in zonemd_check_dnssec_absence()
7921 match = az_nsec3_find_exact(z, z->name, z->namelen, algo, in zonemd_check_dnssec_absence()
7944 auth_zone_log(z->name, VERB_ALGO, "zonemd DNSSEC NSEC3 verification of absence of ZONEMD secure"); in zonemd_check_dnssec_absence()
7978 auth_zone_log(z->name, VERB_ALGO, "zonemd DNSSEC verification of SOA and ZONEMD RRsets secure"); in zonemd_check_dnssec_soazonemd()
7996 dname_str(z->name, zstr); in auth_zone_zonemd_fail()
8012 if(env->cfg->zonemd_permissive_mode) { in auth_zone_zonemd_fail()
8013 verbose(VERB_ALGO, "zonemd-permissive-mode enabled, " in auth_zone_zonemd_fail()
8020 z->zone_expired = 1; in auth_zone_zonemd_fail()
8049 apex = az_find_name(z, z->name, z->namelen); in auth_zone_verify_zonemd_with_key()
8054 if(!zonemd_rrset || zonemd_rrset->data->count==0) { in auth_zone_verify_zonemd_with_key()
8087 if(zonemd_absent && z->zonemd_reject_absence) { in auth_zone_verify_zonemd_with_key()
8092 auth_zone_log(z->name, VERB_ALGO, "DNSSEC verified nonexistence of ZONEMD"); in auth_zone_verify_zonemd_with_key()
8100 auth_zone_log(z->name, VERB_ALGO, "no ZONEMD present"); in auth_zone_verify_zonemd_with_key()
8116 auth_zone_log(z->name, VERB_ALGO, "ZONEMD %s", reason); in auth_zone_verify_zonemd_with_key()
8117 else auth_zone_log(z->name, VERB_ALGO, "ZONEMD verification successful"); in auth_zone_verify_zonemd_with_key()
8156 apex = az_find_name(z, z->name, z->namelen); in zonemd_get_dnskey_from_anchor()
8162 if(!dnskey_rrset || dnskey_rrset->data->count==0) { in zonemd_get_dnskey_from_anchor()
8168 if(m == -1) { in zonemd_get_dnskey_from_anchor()
8172 ve = (struct val_env*)env->modinfo[m]; in zonemd_get_dnskey_from_anchor()
8175 keystorage->entry.key = keystorage; in zonemd_get_dnskey_from_anchor()
8176 keystorage->entry.data = dnskey_rrset->data; in zonemd_get_dnskey_from_anchor()
8177 keystorage->rk.dname = apex->name; in zonemd_get_dnskey_from_anchor()
8178 keystorage->rk.dname_len = apex->namelen; in zonemd_get_dnskey_from_anchor()
8179 keystorage->rk.type = htons(LDNS_RR_TYPE_DNSKEY); in zonemd_get_dnskey_from_anchor()
8180 keystorage->rk.rrset_class = htons(z->dclass); in zonemd_get_dnskey_from_anchor()
8181 auth_zone_log(z->name, VERB_QUERY, in zonemd_get_dnskey_from_anchor()
8183 sec = val_verify_DNSKEY_with_TA(env, ve, keystorage, anchor->ds_rrset, in zonemd_get_dnskey_from_anchor()
8184 anchor->dnskey_rrset, NULL, why_bogus, NULL, NULL, reasonbuf, in zonemd_get_dnskey_from_anchor()
8186 regional_free_all(env->scratch); in zonemd_get_dnskey_from_anchor()
8197 auth_zone_log(z->name, VERB_ALGO, in zonemd_get_dnskey_from_anchor()
8218 apex = az_find_name(z, z->name, z->namelen); in auth_zone_verify_zonemd_key_with_ds()
8224 if(!dnskey_rrset || dnskey_rrset->data->count==0) { in auth_zone_verify_zonemd_key_with_ds()
8230 if(m == -1) { in auth_zone_verify_zonemd_key_with_ds()
8234 ve = (struct val_env*)env->modinfo[m]; in auth_zone_verify_zonemd_key_with_ds()
8237 keystorage->entry.key = keystorage; in auth_zone_verify_zonemd_key_with_ds()
8238 keystorage->entry.data = dnskey_rrset->data; in auth_zone_verify_zonemd_key_with_ds()
8239 keystorage->rk.dname = apex->name; in auth_zone_verify_zonemd_key_with_ds()
8240 keystorage->rk.dname_len = apex->namelen; in auth_zone_verify_zonemd_key_with_ds()
8241 keystorage->rk.type = htons(LDNS_RR_TYPE_DNSKEY); in auth_zone_verify_zonemd_key_with_ds()
8242 keystorage->rk.rrset_class = htons(z->dclass); in auth_zone_verify_zonemd_key_with_ds()
8243 auth_zone_log(z->name, VERB_QUERY, "zonemd: verify zone DNSKEY with DS"); in auth_zone_verify_zonemd_key_with_ds()
8246 regional_free_all(env->scratch); in auth_zone_verify_zonemd_key_with_ds()
8258 auth_zone_log(z->name, VERB_ALGO, in auth_zone_verify_zonemd_key_with_ds()
8278 lock_rw_wrlock(&z->lock); in auth_zonemd_dnskey_lookup_callback()
8279 env = z->zonemd_callback_env; in auth_zonemd_dnskey_lookup_callback()
8282 z->zonemd_callback_env = NULL; in auth_zonemd_dnskey_lookup_callback()
8283 if(!env || env->outnet->want_to_quit || z->zone_deleted) { in auth_zonemd_dnskey_lookup_callback()
8284 lock_rw_unlock(&z->lock); in auth_zonemd_dnskey_lookup_callback()
8287 if(z->zonemd_callback_qtype == LDNS_RR_TYPE_DS) in auth_zonemd_dnskey_lookup_callback()
8289 downprot = env->cfg->harden_algo_downgrade; in auth_zonemd_dnskey_lookup_callback()
8295 if(z->zonemd_callback_qtype == LDNS_RR_TYPE_DNSKEY) in auth_zonemd_dnskey_lookup_callback()
8299 auth_zone_log(z->name, VERB_ALGO, in auth_zonemd_dnskey_lookup_callback()
8302 uint16_t wanted_qtype = z->zonemd_callback_qtype; in auth_zonemd_dnskey_lookup_callback()
8303 struct regional* temp = env->scratch; in auth_zonemd_dnskey_lookup_callback()
8309 query_dname_compare(z->name, rq.qname) == 0 && in auth_zonemd_dnskey_lookup_callback()
8310 FLAGS_GET_RCODE(rep->flags) == LDNS_RCODE_NOERROR) { in auth_zonemd_dnskey_lookup_callback()
8315 if(z->zonemd_callback_qtype == LDNS_RR_TYPE_DNSKEY) in auth_zonemd_dnskey_lookup_callback()
8318 auth_zone_log(z->name, VERB_ALGO, in auth_zonemd_dnskey_lookup_callback()
8322 auth_zone_log(z->name, VERB_ALGO, in auth_zonemd_dnskey_lookup_callback()
8326 auth_zone_log(z->name, VERB_ALGO, in auth_zonemd_dnskey_lookup_callback()
8330 auth_zone_log(z->name, VERB_ALGO, in auth_zonemd_dnskey_lookup_callback()
8333 auth_zone_log(z->name, VERB_ALGO, in auth_zonemd_dnskey_lookup_callback()
8335 if(z->zonemd_callback_qtype == LDNS_RR_TYPE_DNSKEY) in auth_zonemd_dnskey_lookup_callback()
8340 query_dname_compare(z->name, rq.qname) == 0 && in auth_zonemd_dnskey_lookup_callback()
8341 FLAGS_GET_RCODE(rep->flags) == LDNS_RCODE_NXDOMAIN && in auth_zonemd_dnskey_lookup_callback()
8349 auth_zone_log(z->name, VERB_ALGO, in auth_zonemd_dnskey_lookup_callback()
8352 query_dname_compare(z->name, rq.qname) == 0 && in auth_zonemd_dnskey_lookup_callback()
8353 FLAGS_GET_RCODE(rep->flags) == LDNS_RCODE_NXDOMAIN && in auth_zonemd_dnskey_lookup_callback()
8356 auth_zone_log(z->name, VERB_ALGO, in auth_zonemd_dnskey_lookup_callback()
8359 query_dname_compare(z->name, rq.qname) == 0 && in auth_zonemd_dnskey_lookup_callback()
8360 FLAGS_GET_RCODE(rep->flags) == LDNS_RCODE_NXDOMAIN && in auth_zonemd_dnskey_lookup_callback()
8363 auth_zone_log(z->name, VERB_ALGO, in auth_zonemd_dnskey_lookup_callback()
8366 auth_zone_log(z->name, VERB_ALGO, in auth_zonemd_dnskey_lookup_callback()
8368 if(z->zonemd_callback_qtype == LDNS_RR_TYPE_DNSKEY) in auth_zonemd_dnskey_lookup_callback()
8373 auth_zone_log(z->name, VERB_ALGO, in auth_zonemd_dnskey_lookup_callback()
8375 if(z->zonemd_callback_qtype == LDNS_RR_TYPE_DNSKEY) in auth_zonemd_dnskey_lookup_callback()
8382 &env->mesh->mods, ds, &is_insecure, &ds_bogus, in auth_zonemd_dnskey_lookup_callback()
8391 lock_rw_unlock(&z->lock); in auth_zonemd_dnskey_lookup_callback()
8392 regional_free_all(env->scratch); in auth_zonemd_dnskey_lookup_callback()
8396 auth_zone_verify_zonemd_with_key(z, env, &env->mesh->mods, dnskey, in auth_zonemd_dnskey_lookup_callback()
8398 regional_free_all(env->scratch); in auth_zonemd_dnskey_lookup_callback()
8399 lock_rw_unlock(&z->lock); in auth_zonemd_dnskey_lookup_callback()
8409 sldns_buffer* buf = env->scratch_buffer; in zonemd_lookup_dnskey()
8412 if(!z->fallback_enabled) { in zonemd_lookup_dnskey()
8418 if(z->zonemd_callback_env) { in zonemd_lookup_dnskey()
8423 auth_zone_log(z->name, VERB_ALGO, in zonemd_lookup_dnskey()
8430 qinfo.qname_len = z->namelen; in zonemd_lookup_dnskey()
8431 qinfo.qname = z->name; in zonemd_lookup_dnskey()
8432 qinfo.qclass = z->dclass; in zonemd_lookup_dnskey()
8440 dname_str(z->name, buf2); in zonemd_lookup_dnskey()
8449 edns.bits = EDNS_DO; in zonemd_lookup_dnskey()
8457 /* store the worker-specific module env for the callback. in zonemd_lookup_dnskey()
8459 z->zonemd_callback_env = env; in zonemd_lookup_dnskey()
8460 z->zonemd_callback_qtype = qinfo.qtype; in zonemd_lookup_dnskey()
8462 lock_rw_unlock(&z->lock); in zonemd_lookup_dnskey()
8463 if(!mesh_new_callback(env->mesh, &qinfo, qflags, &edns, buf, 0, in zonemd_lookup_dnskey()
8465 lock_rw_wrlock(&z->lock); in zonemd_lookup_dnskey()
8470 lock_rw_wrlock(&z->lock); in zonemd_lookup_dnskey()
8485 if(!z->zonemd_check) in auth_zone_verify_zonemd()
8487 if(z->data.count == 0) in auth_zone_verify_zonemd()
8491 /* is it equal to trustanchor - get dnskey's verified */ in auth_zone_verify_zonemd()
8495 if(env->anchors) in auth_zone_verify_zonemd()
8496 anchor = anchors_lookup(env->anchors, z->name, z->namelen, in auth_zone_verify_zonemd()
8497 z->dclass); in auth_zone_verify_zonemd()
8498 if(anchor && anchor->numDS == 0 && anchor->numDNSKEY == 0) { in auth_zone_verify_zonemd()
8499 /* domain-insecure trust anchor for unsigned zones */ in auth_zone_verify_zonemd()
8500 lock_basic_unlock(&anchor->lock); in auth_zone_verify_zonemd()
8505 } else if(anchor && query_dname_compare(z->name, anchor->name) == 0) { in auth_zone_verify_zonemd()
8507 lock_basic_unlock(&anchor->lock); in auth_zone_verify_zonemd()
8514 lock_basic_unlock(&anchor->lock); in auth_zone_verify_zonemd()
8519 lock_basic_unlock(&anchor->lock); in auth_zone_verify_zonemd()
8539 regional_free_all(env->scratch); in auth_zone_verify_zonemd()
8545 regional_free_all(env->scratch); in auth_zone_verify_zonemd()
8556 lock_rw_rdlock(&az->lock); in auth_zones_pickup_zonemd_verify()
8557 RBTREE_FOR(z, struct auth_zone*, &az->ztree) { in auth_zones_pickup_zonemd_verify()
8558 lock_rw_wrlock(&z->lock); in auth_zones_pickup_zonemd_verify()
8559 if(!z->zonemd_check) { in auth_zones_pickup_zonemd_verify()
8560 lock_rw_unlock(&z->lock); in auth_zones_pickup_zonemd_verify()
8563 key.dclass = z->dclass; in auth_zones_pickup_zonemd_verify()
8564 key.namelabs = z->namelabs; in auth_zones_pickup_zonemd_verify()
8565 if(z->namelen > sizeof(savezname)) { in auth_zones_pickup_zonemd_verify()
8566 lock_rw_unlock(&z->lock); in auth_zones_pickup_zonemd_verify()
8570 savezname_len = z->namelen; in auth_zones_pickup_zonemd_verify()
8571 memmove(savezname, z->name, z->namelen); in auth_zones_pickup_zonemd_verify()
8572 lock_rw_unlock(&az->lock); in auth_zones_pickup_zonemd_verify()
8573 auth_zone_verify_zonemd(z, env, &env->mesh->mods, NULL, 0, 1); in auth_zones_pickup_zonemd_verify()
8574 lock_rw_unlock(&z->lock); in auth_zones_pickup_zonemd_verify()
8575 lock_rw_rdlock(&az->lock); in auth_zones_pickup_zonemd_verify()
8581 z = (struct auth_zone*)rbtree_search(&az->ztree, &key); in auth_zones_pickup_zonemd_verify()
8585 lock_rw_unlock(&az->lock); in auth_zones_pickup_zonemd_verify()