Lines Matching defs:iq

84 static void target_count_increase_nx(struct iter_qstate* iq, int num);
130 struct iter_qstate* iq = (struct iter_qstate*)regional_alloc(
132 qstate->minfo[id] = iq;
133 if(!iq)
135 memset(iq, 0, sizeof(*iq));
136 iq->state = INIT_REQUEST_STATE;
137 iq->final_state = FINISHED_STATE;
138 iq->an_prepend_list = NULL;
139 iq->an_prepend_last = NULL;
140 iq->ns_prepend_list = NULL;
141 iq->ns_prepend_last = NULL;
142 iq->dp = NULL;
143 iq->depth = 0;
144 iq->num_target_queries = 0;
145 iq->num_current_queries = 0;
146 iq->query_restart_count = 0;
147 iq->referral_count = 0;
148 iq->sent_count = 0;
149 iq->ratelimit_ok = 0;
150 iq->target_count = NULL;
151 iq->dp_target_count = 0;
152 iq->wait_priming_stub = 0;
153 iq->refetch_glue = 0;
154 iq->dnssec_expected = 0;
155 iq->dnssec_lame_query = 0;
156 iq->chase_flags = qstate->query_flags;
158 iq->qchase = qstate->qinfo;
159 outbound_list_init(&iq->outlist);
160 iq->minimise_count = 0;
161 iq->timeout_count = 0;
163 iq->minimisation_state = INIT_MINIMISE_STATE;
165 iq->minimisation_state = DONOT_MINIMISE_STATE;
167 memset(&iq->qinfo_out, 0, sizeof(struct query_info));
175 * @param iq: iterator query state
182 next_state(struct iter_qstate* iq, enum iter_state nextstate)
187 if(iq->response == NULL) {
192 iq->state = nextstate;
204 * @param iq: iterator query state
209 final_state(struct iter_qstate* iq)
211 return next_state(iq, iq->final_state);
383 iter_prepend(struct iter_qstate* iq, struct dns_msg* msg,
389 for(p = iq->an_prepend_list; p; p = p->next)
391 for(p = iq->ns_prepend_list; p; p = p->next)
404 for(p = iq->an_prepend_list; p; p = p->next) {
416 for(p = iq->ns_prepend_list; p; p = p->next) {
446 * @param iq: iterator query state.
451 iter_find_rrset_in_prepend_answer(struct iter_qstate* iq,
454 struct iter_prep_list* p = iq->an_prepend_list;
469 * @param iq: iterator query state.
474 iter_add_prepend_answer(struct module_qstate* qstate, struct iter_qstate* iq,
484 if(iq->an_prepend_last)
485 iq->an_prepend_last->next = p;
486 else iq->an_prepend_list = p;
487 iq->an_prepend_last = p;
494 * @param iq: iterator query state.
499 iter_add_prepend_auth(struct module_qstate* qstate, struct iter_qstate* iq,
509 if(iq->ns_prepend_last)
510 iq->ns_prepend_last->next = p;
511 else iq->ns_prepend_list = p;
512 iq->ns_prepend_last = p;
524 * @param iq: iterator query state.
531 handle_cname_response(struct module_qstate* qstate, struct iter_qstate* iq,
536 *mname = iq->qchase.qname;
537 *mname_len = iq->qchase.qname_len;
549 !iter_find_rrset_in_prepend_answer(iq, r)) {
550 if(!iter_add_prepend_answer(qstate, iq, r))
557 !iter_find_rrset_in_prepend_answer(iq, r)) {
559 if(!iter_add_prepend_answer(qstate, iq, r))
573 if(!iter_add_prepend_auth(qstate, iq, r))
582 fill_fail_addr(struct iter_qstate* iq, struct sockaddr_storage* addr,
586 iq->fail_addr_type = 0;
590 iq->fail_addr_type = 4;
591 memcpy(&iq->fail_addr.in,
593 sizeof(iq->fail_addr.in));
597 iq->fail_addr_type = 6;
598 memcpy(&iq->fail_addr.in6,
600 sizeof(iq->fail_addr.in6));
604 iq->fail_addr_type = 0;
610 print_fail_addr(struct iter_qstate* iq, char* buf, size_t len)
612 if(iq->fail_addr_type == 4) {
613 if(inet_ntop(AF_INET, &iq->fail_addr.in, buf,
618 else if(iq->fail_addr_type == 6) {
619 if(inet_ntop(AF_INET6, &iq->fail_addr.in6, buf,
630 errinf_reply(struct module_qstate* qstate, struct iter_qstate* iq)
635 (iq->fail_addr_type != 0)) {
642 print_fail_addr(iq, from, sizeof(from));
646 if(iq->scrub_failures || iq->parse_failures) {
647 if(iq->scrub_failures)
649 if(iq->parse_failures)
651 } else if(iq->response == NULL && iq->timeout_count != 0) {
653 } else if(iq->response == NULL) {
655 if(iq->dp) {
656 if(iq->dp->target_list == NULL)
659 if(iq->dp->nslist == NULL)
661 if(iq->dp->bogus)
665 if(iq->response && iq->response->rep) {
666 if(FLAGS_GET_RCODE(iq->response->rep->flags) != 0) {
669 FLAGS_GET_RCODE(iq->response->rep->flags),
675 if(iq->response->rep->an_numrrsets == 0) {
723 is_caps_whitelisted(struct iter_env* ie, struct iter_qstate* iq)
726 return name_tree_lookup(ie->caps_white, iq->qchase.qname,
727 iq->qchase.qname_len, dname_count_labels(iq->qchase.qname),
728 iq->qchase.qclass) != NULL;
736 target_count_create(struct iter_qstate* iq)
738 if(!iq->target_count) {
739 iq->target_count = (int*)calloc(TARGET_COUNT_MAX, sizeof(int));
741 if(iq->target_count) {
742 iq->target_count[TARGET_COUNT_REF] = 1;
743 iq->nxns_dp = (uint8_t**)calloc(1, sizeof(uint8_t*));
749 target_count_increase(struct iter_qstate* iq, int num)
751 target_count_create(iq);
752 if(iq->target_count)
753 iq->target_count[TARGET_COUNT_QUERIES] += num;
754 iq->dp_target_count++;
758 target_count_increase_nx(struct iter_qstate* iq, int num)
760 target_count_create(iq);
761 if(iq->target_count)
762 iq->target_count[TARGET_COUNT_NX] += num;
766 target_count_increase_global_quota(struct iter_qstate* iq, int num)
768 target_count_create(iq);
769 if(iq->target_count)
770 iq->target_count[TARGET_COUNT_GLOBAL_QUOTA] += num;
785 * @param iq: The iterator state that is generating this event.
799 struct iter_qstate* iq, enum iter_state initial_state,
863 target_count_create(iq);
864 subiq->target_count = iq->target_count;
865 if(iq->target_count) {
866 iq->target_count[TARGET_COUNT_REF] ++; /* extra reference */
867 subiq->nxns_dp = iq->nxns_dp;
871 subiq->depth = iq->depth+1;
890 * @param iq: iterator query state.
896 prime_root(struct module_qstate* qstate, struct iter_qstate* iq, int id,
913 qclass, qstate, id, iq, QUERYTARGETS_STATE, PRIME_RESP_STATE,
952 * @param iq: iterator query state.
962 prime_stub(struct module_qstate* qstate, struct iter_qstate* iq, int id,
973 stub = hints_lookup_stub(qstate->env->hints, qname, qclass, iq->dp,
980 if(!iq->auth_zone_avoid && iq->dp && iq->dp->auth_dp &&
981 query_dname_compare(iq->dp->name, stub_dp->name) == 0) {
989 if(iq->dp == NULL) r = 2;
992 iq->dp = delegpt_copy(stub_dp, qstate->region);
994 if(!iq->dp) {
1000 log_nametypeclass(VERB_DETAIL, "use stub", iq->dp->name,
1012 LDNS_RR_TYPE_NS, qclass, qstate, id, iq,
1058 auth_zone_delegpt(struct module_qstate* qstate, struct iter_qstate* iq,
1062 if(iq->auth_zone_avoid)
1065 delname = iq->qchase.qname;
1066 delnamelen = iq->qchase.qname_len;
1078 if(iq->dp && query_dname_compare(z->name, iq->dp->name) == 0
1079 && iq->dp->auth_dp && qstate->blacklist &&
1091 iq->dp = NULL;
1094 if(iq->dp==NULL || dname_subdomain_c(z->name, iq->dp->name)) {
1137 iq->dp = dp;
1150 * @param iq: iterator query state.
1154 generate_a_aaaa_check(struct module_qstate* qstate, struct iter_qstate* iq,
1160 struct reply_info* rep = iq->response->rep;
1162 log_assert(iq->dp);
1164 if(iq->depth == ie->max_dependency_depth)
1191 qstate, id, iq,
1205 * @param iq: iterator query state.
1209 generate_ns_check(struct module_qstate* qstate, struct iter_qstate* iq, int id)
1213 log_assert(iq->dp);
1215 if(iq->depth == ie->max_dependency_depth)
1217 if(!can_have_last_resort(qstate->env, iq->dp->name, iq->dp->namelen,
1218 iq->qchase.qclass, NULL, NULL, NULL))
1222 query_dname_compare(iq->dp->name, qstate->qinfo.qname)==0 &&
1225 generate_a_aaaa_check(qstate, iq, id);
1233 iq->dp->name, LDNS_RR_TYPE_NS, iq->qchase.qclass);
1234 if(!generate_sub_request(iq->dp->name, iq->dp->namelen,
1235 LDNS_RR_TYPE_NS, iq->qchase.qclass, qstate, id, iq,
1247 subiq->dp = delegpt_copy(iq->dp, subq->region);
1271 * @param iq: iterator query state.
1276 struct iter_qstate* iq, int id)
1279 log_assert(iq->dp);
1283 query_dname_compare(iq->dp->name, qstate->qinfo.qname)==0 &&
1299 iq->dp->name, LDNS_RR_TYPE_DNSKEY, iq->qchase.qclass);
1300 if(!generate_sub_request(iq->dp->name, iq->dp->namelen,
1301 LDNS_RR_TYPE_DNSKEY, iq->qchase.qclass, qstate, id, iq,
1312 subiq->dp = delegpt_copy(iq->dp, subq->region);
1321 * @param iq: iterator query state.
1323 * If returns true but, iq->dp is NULL then a malloc failure occurred.
1326 forward_request(struct module_qstate* qstate, struct iter_qstate* iq)
1329 uint8_t* delname = iq->qchase.qname;
1330 size_t delnamelen = iq->qchase.qname_len;
1332 if(iq->refetch_glue && iq->dp) {
1333 delname = iq->dp->name;
1334 delnamelen = iq->dp->namelen;
1337 if( (iq->qchase.qtype == LDNS_RR_TYPE_DS || iq->refetch_glue)
1338 && !dname_is_root(iq->qchase.qname))
1340 dp = forwards_lookup(qstate->env->fwds, delname, iq->qchase.qclass,
1344 iq->chase_flags |= BIT_RD;
1345 iq->dp = delegpt_copy(dp, qstate->region);
1347 /* iq->dp checked by caller */
1364 * @param iq: iterator query state.
1371 processInitRequest(struct module_qstate* qstate, struct iter_qstate* iq,
1384 if(iq->query_restart_count > ie->max_query_restarts) {
1386 " of query restarts with %d", iq->query_restart_count);
1389 if(iq->qchase.qname)
1390 errinf_dname(qstate, "stop at", iq->qchase.qname);
1398 verbose(VERB_ALGO, "request has dependency depth of %d", iq->depth);
1399 if(iq->depth > ie->max_dependency_depth) {
1401 "dependency depth with depth of %d", iq->depth);
1409 iq->qchase.qclass = 0;
1410 return next_state(iq, COLLECT_CLASS_STATE);
1416 * we won’t try to re-fetch glue if the iq->dp is null.
1418 if (iq->refetch_glue &&
1419 iq->dp &&
1420 !can_have_last_resort(qstate->env, iq->dp->name,
1421 iq->dp->namelen, iq->qchase.qclass, NULL, NULL, NULL)) {
1422 iq->refetch_glue = 0;
1434 rpz_callback_from_iterator_cname(qstate, iq);
1440 forged_response->rep, iq->qchase.qname,
1441 iq->qchase.qname_len, LDNS_RR_TYPE_CNAME,
1442 iq->qchase.qclass) &&
1443 iq->qchase.qtype != LDNS_RR_TYPE_CNAME &&
1446 if(!handle_cname_response(qstate, iq, forged_response,
1451 iq->qchase.qname = sname;
1452 iq->qchase.qname_len = slen;
1454 rpz_callback_from_iterator_cname(qstate, iq);
1460 iq->response = forged_response;
1461 next_state(iq, FINISHED_STATE);
1462 if(!iter_prepend(iq, qstate->return_msg, qstate->region)) {
1470 iq->dp = NULL;
1471 iq->refetch_glue = 0;
1472 iq->query_restart_count++;
1473 iq->sent_count = 0;
1474 iq->dp_target_count = 0;
1477 iq->minimisation_state = INIT_MINIMISE_STATE;
1478 return next_state(iq, INIT_REQUEST_STATE);
1482 if (iter_stub_fwd_no_cache(qstate, &iq->qchase, &dpname, &dpnamelen,
1495 msg = dns_cache_lookup(qstate->env, iq->qchase.qname,
1496 iq->qchase.qname_len, iq->qchase.qtype,
1497 iq->qchase.qclass, qstate->query_flags,
1501 iter_qname_indicates_dnssec(qstate->env, &iq->qchase)) {
1504 msg = val_neg_getmsg(qstate->env->neg_cache, &iq->qchase,
1513 iq->qchase.qname) != 0)
1519 &iq->qchase);
1533 if(!handle_cname_response(qstate, iq, msg,
1540 iq->qchase.qname = sname;
1541 iq->qchase.qname_len = slen;
1544 iq->dp = NULL;
1545 iq->refetch_glue = 0;
1546 iq->query_restart_count++;
1547 iq->sent_count = 0;
1548 iq->dp_target_count = 0;
1551 iq->minimisation_state = INIT_MINIMISE_STATE;
1552 return next_state(iq, INIT_REQUEST_STATE);
1561 iq->response = msg;
1562 return final_state(iq);
1566 if(forward_request(qstate, iq))
1568 if(!iq->dp) {
1573 if(!cache_fill_missing(qstate->env, iq->qchase.qclass,
1574 qstate->region, iq->dp, 0)) {
1591 iq->refetch_glue = 0;
1592 iq->minimisation_state = DONOT_MINIMISE_STATE;
1596 return next_state(iq, QUERYTARGETS_STATE);
1605 if(iq->refetch_glue) {
1606 if(!iq->dp) {
1611 delname = iq->dp->name;
1612 delnamelen = iq->dp->namelen;
1614 delname = iq->qchase.qname;
1615 delnamelen = iq->qchase.qname_len;
1617 if(iq->qchase.qtype == LDNS_RR_TYPE_DS || iq->refetch_glue ||
1618 (iq->qchase.qtype == LDNS_RR_TYPE_NS && qstate->prefetch_leeway
1619 && can_have_last_resort(qstate->env, delname, delnamelen, iq->qchase.qclass, NULL, NULL, NULL))) {
1625 if(dname_is_root(delname) && (iq->refetch_glue ||
1626 (iq->qchase.qtype == LDNS_RR_TYPE_NS &&
1637 iq->dp = dns_cache_find_delegation(qstate->env, delname,
1638 delnamelen, iq->qchase.qtype, iq->qchase.qclass,
1639 qstate->region, &iq->deleg_msg,
1642 else iq->dp = NULL;
1646 if(iq->dp == NULL) {
1650 if(!auth_zone_delegpt(qstate, iq, delname, delnamelen))
1653 if(iq->dp) /* use auth zone dp */
1654 return next_state(iq, INIT_REQUEST_2_STATE);
1656 r = prime_stub(qstate, iq, id, delname,
1657 iq->qchase.qclass);
1663 iq->qchase.qclass, nolock)) {
1667 iq->dp = hints_find_root(qstate->env->hints,
1668 iq->qchase.qclass, nolock);
1669 if(!iq->dp) {
1675 iq->dp = delegpt_copy(iq->dp, qstate->region);
1677 if(!iq->dp) {
1683 return next_state(iq, INIT_REQUEST_2_STATE);
1687 if(!prime_root(qstate, iq, id, iq->qchase.qclass))
1697 if(!iq->ratelimit_ok && qstate->prefetch_leeway)
1698 iq->ratelimit_ok = 1; /* allow prefetches, this keeps
1714 iq->dp, ie->supports_ipv4, ie->supports_ipv6,
1717 if(!can_have_last_resort(qstate->env, iq->dp->name, iq->dp->namelen, iq->qchase.qclass, &have_dp, &iq->dp, qstate->region)) {
1722 if(have_dp && !iq->dp) {
1733 delegpt_log(VERB_ALGO, iq->dp);
1736 errinf_dname(qstate, "for zone", iq->dp->name);
1740 if(dname_is_root(iq->dp->name)) {
1745 iq->dp = hints_find_root(qstate->env->hints,
1746 iq->qchase.qclass, nolock);
1749 if(!iq->dp) {
1754 iq->dp = delegpt_copy(iq->dp, qstate->region);
1756 if(!iq->dp) {
1766 delegpt_log(VERB_ALGO, iq->dp);
1768 delname = iq->dp->name;
1769 delnamelen = iq->dp->namelen;
1776 delegpt_log(VERB_ALGO, iq->dp);
1780 return next_state(iq, INIT_REQUEST_2_STATE);
1793 * @param iq: iterator query state.
1799 processInitRequest2(struct module_qstate* qstate, struct iter_qstate* iq,
1807 delname = iq->qchase.qname;
1808 delnamelen = iq->qchase.qname_len;
1809 if(iq->refetch_glue) {
1812 if(!iq->dp) {
1820 qstate->env->hints, iq->qchase.qname, iq->qchase.qclass,
1821 iq->dp, nolock);
1823 dname_subdomain_c(iq->dp->name, stub->dp->name)) {
1824 delname = iq->dp->name;
1825 delnamelen = iq->dp->namelen;
1830 if(iq->qchase.qtype == LDNS_RR_TYPE_DS || iq->refetch_glue) {
1833 iq->refetch_glue = 0; /* if CNAME causes restart, no refetch */
1838 if(!auth_zone_delegpt(qstate, iq, delname, delnamelen))
1842 if(prime_stub(qstate, iq, id, delname, iq->qchase.qclass)) {
1848 return next_state(iq, INIT_REQUEST_3_STATE);
1858 * @param iq: iterator query state.
1863 processInitRequest3(struct module_qstate* qstate, struct iter_qstate* iq,
1870 iq->dnssec_expected = iter_indicates_dnssec(qstate->env, iq->dp,
1871 iq->deleg_msg, iq->qchase.qclass);
1875 if(!(qstate->query_flags & BIT_RD) && iq->deleg_msg) {
1876 iq->response = iq->deleg_msg;
1877 if(verbosity >= VERB_ALGO && iq->response)
1879 &iq->response->qinfo, iq->response->rep);
1882 return final_state(iq);
1886 iq->chase_flags &= ~BIT_RD;
1889 if(iq->dnssec_expected && qstate->env->cfg->prefetch_key &&
1891 generate_dnskey_prefetch(qstate, iq, id);
1898 return next_state(iq, QUERYTARGETS_STATE);
1907 * @param iq: iterator query state.
1917 struct iter_qstate* iq, int id, uint8_t* name, size_t namelen,
1922 id, iq, INIT_REQUEST_STATE, FINISHED_STATE, &subq, 0, 0))
1930 if(dname_subdomain_c(name, iq->dp->name)) {
1931 subiq->dp = delegpt_copy(iq->dp, subq->region);
1960 * @param iq: iterator query state.
1969 generate_target_query(struct module_qstate* qstate, struct iter_qstate* iq,
1974 id, iq, INIT_REQUEST_STATE, FINISHED_STATE, &subq, 0, 0))
1985 * @param iq: iterator query state.
1996 query_for_targets(struct module_qstate* qstate, struct iter_qstate* iq,
2004 iter_mark_cycle_targets(qstate, iq->dp);
2005 missing = (int)delegpt_count_missing_targets(iq->dp, NULL);
2021 if(iq->depth == ie->max_dependency_depth)
2023 if(iq->depth > 0 && iq->target_count &&
2024 iq->target_count[TARGET_COUNT_QUERIES] > MAX_TARGET_COUNT) {
2029 iq->target_count[TARGET_COUNT_QUERIES]);
2032 if(iq->dp_target_count > MAX_DP_TARGET_COUNT) {
2037 s, iq->dp_target_count);
2045 for(ns = iq->dp->nslist; ns; ns = ns->next) {
2061 if(!generate_target_query(qstate, iq, id,
2063 LDNS_RR_TYPE_AAAA, iq->qchase.qclass)) {
2091 if(!generate_target_query(qstate, iq, id,
2093 LDNS_RR_TYPE_A, iq->qchase.qclass)) {
2130 * @param iq: iterator query state.
2137 processLastResort(struct module_qstate* qstate, struct iter_qstate* iq,
2143 log_assert(iq->dp);
2145 if(!can_have_last_resort(qstate->env, iq->dp->name, iq->dp->namelen,
2146 iq->qchase.qclass, NULL, NULL, NULL)) {
2150 errinf_dname(qstate, "at zone", iq->dp->name);
2151 errinf_reply(qstate, iq);
2156 if(!cache_fill_missing(qstate->env, iq->qchase.qclass,
2157 qstate->region, iq->dp, PACKED_RRSET_UNVERIFIED_GLUE))
2159 if(iq->dp->usable_list) {
2161 return next_state(iq, QUERYTARGETS_STATE);
2164 if(!iq->dp->has_parent_side_NS && dname_is_root(iq->dp->name)) {
2168 iq->qchase.qclass, nolock);
2171 iq->chase_flags &= ~BIT_RD; /* go to authorities */
2173 (void)delegpt_add_ns(iq->dp, qstate->region,
2178 (void)delegpt_add_addr(iq->dp, qstate->region,
2184 iq->dp->has_parent_side_NS = 1;
2185 } else if(!iq->dp->has_parent_side_NS) {
2186 if(!iter_lookup_parent_NS_from_cache(qstate->env, iq->dp,
2188 || !iq->dp->has_parent_side_NS) {
2192 iq->store_parent_NS = iq->dp;
2193 iq->chase_flags &= ~BIT_RD; /* go to authorities */
2194 iq->deleg_msg = NULL;
2195 iq->refetch_glue = 1;
2196 iq->query_restart_count++;
2197 iq->sent_count = 0;
2198 iq->dp_target_count = 0;
2200 iq->minimisation_state = INIT_MINIMISE_STATE;
2201 return next_state(iq, INIT_REQUEST_STATE);
2205 if(!cache_fill_missing(qstate->env, iq->qchase.qclass,
2206 qstate->region, iq->dp, 0))
2208 if(iq->dp->usable_list) {
2210 return next_state(iq, QUERYTARGETS_STATE);
2213 if(iter_lookup_parent_glue_from_cache(qstate->env, iq->dp,
2217 return next_state(iq, QUERYTARGETS_STATE);
2220 if(delegpt_count_missing_targets(iq->dp, NULL) > 0) {
2223 if((ret=query_for_targets(qstate, iq, ie, id, 1, &qs))!=0) {
2225 errinf_dname(qstate, "at zone", iq->dp->name);
2230 iq->num_target_queries += qs;
2231 target_count_increase(iq, qs);
2237 if(iq->depth == ie->max_dependency_depth) {
2242 if(iq->depth > 0 && iq->target_count &&
2243 iq->target_count[TARGET_COUNT_QUERIES] > MAX_TARGET_COUNT) {
2248 iq->target_count[TARGET_COUNT_QUERIES]);
2253 iter_mark_pside_cycle_targets(qstate, iq->dp);
2256 for(ns = iq->dp->nslist; ns; ns = ns->next) {
2262 iq->qchase.qclass, NULL, NULL, NULL)) {
2265 ns->name, LDNS_RR_TYPE_NS, iq->qchase.qclass);
2273 if(!generate_parentside_target_query(qstate, iq, id,
2275 LDNS_RR_TYPE_AAAA, iq->qchase.qclass)) {
2286 iq->num_target_queries += query_count;
2287 target_count_increase(iq, query_count);
2294 if(!generate_parentside_target_query(qstate, iq, id,
2296 LDNS_RR_TYPE_A, iq->qchase.qclass)) {
2306 iq->num_target_queries += query_count;
2307 target_count_increase(iq, query_count);
2315 if(!qstate->no_cache_store && iq->query_for_pside_glue
2316 && !iq->pside_glue)
2318 iq->deleg_msg?iq->deleg_msg->rep:
2319 (iq->response?iq->response->rep:NULL));
2322 errinf_dname(qstate, "at zone", iq->dp->name);
2323 errinf_reply(qstate, iq);
2338 * @param iq: iterator query state.
2345 processDSNSFind(struct module_qstate* qstate, struct iter_qstate* iq, int id)
2350 if(!iq->dsns_point) {
2352 iq->dsns_point = iq->qchase.qname;
2353 iq->dsns_point_len = iq->qchase.qname_len;
2356 if(!dname_subdomain_c(iq->dsns_point, iq->dp->name)) {
2357 errinf_dname(qstate, "for DS query parent-child nameserver search the query is not under the zone", iq->dp->name);
2362 dname_remove_label(&iq->dsns_point, &iq->dsns_point_len);
2363 if(query_dname_compare(iq->dsns_point, iq->dp->name) == 0) {
2367 iq->state = QUERYTARGETS_STATE;
2370 iq->state = DSNS_FIND_STATE;
2374 iq->dsns_point, LDNS_RR_TYPE_NS, iq->qchase.qclass);
2375 if(!generate_sub_request(iq->dsns_point, iq->dsns_point_len,
2376 LDNS_RR_TYPE_NS, iq->qchase.qclass, qstate, id, iq,
2378 errinf_dname(qstate, "for DS query parent-child nameserver search, could not generate NS lookup for", iq->dsns_point);
2390 check_waiting_queries(struct iter_qstate* iq, struct module_qstate* qstate,
2393 if(iq->num_target_queries>0 && iq->num_current_queries>0) {
2396 "respond", iq->num_target_queries,
2397 iq->num_current_queries);
2399 } else if(iq->num_target_queries>0) {
2401 "resolve", iq->num_target_queries);
2406 iq->num_current_queries);
2420 * @param iq: iterator query state.
2428 processQueryTargets(struct module_qstate* qstate, struct iter_qstate* iq,
2449 "currentqueries %d sentcount %d", iq->num_target_queries,
2450 iq->num_current_queries, iq->sent_count);
2453 if(iq->referral_count > MAX_REFERRAL_COUNT) {
2455 "number of referrrals with %d", iq->referral_count);
2459 if(iq->sent_count > ie->max_sent_count) {
2461 "number of sends with %d", iq->sent_count);
2467 if(iq->target_count && !*iq->nxns_dp &&
2468 iq->target_count[TARGET_COUNT_NX] > MAX_TARGET_NX) {
2471 if(iq->num_target_queries>0 || iq->num_current_queries>0) {
2472 check_waiting_queries(iq, qstate, id);
2477 MAX_TARGET_NX, iq->target_count[TARGET_COUNT_NX]);
2479 if(!iq->dp) {
2488 if(iq->dp->has_parent_side_NS) {
2499 for(ns=iq->dp->nslist; ns; ns=ns->next) {
2505 *iq->nxns_dp = malloc(iq->dp->namelen);
2506 if(!*iq->nxns_dp) {
2513 memcpy(*iq->nxns_dp, iq->dp->name, iq->dp->namelen);
2514 } else if(iq->target_count && *iq->nxns_dp) {
2517 if(iq->num_target_queries>0 || iq->num_current_queries>0) {
2518 check_waiting_queries(iq, qstate, id);
2522 if(!iq->dp) {
2530 if(iq->target_count[TARGET_COUNT_NX] > MAX_TARGET_NX_FALLBACK) {
2534 iq->target_count[TARGET_COUNT_NX]);
2539 if(!iq->dp->has_parent_side_NS) {
2541 if(!dname_canonical_compare(*iq->nxns_dp, iq->dp->name)) {
2545 for(ns=iq->dp->nslist; ns; ns=ns->next) {
2554 if(!iq->dp) {
2560 delegpt_no_ipv6(iq->dp);
2562 delegpt_no_ipv4(iq->dp);
2563 delegpt_log(VERB_ALGO, iq->dp);
2565 if(iq->num_current_queries>0) {
2574 if(iq->minimisation_state == INIT_MINIMISE_STATE
2575 && !(iq->chase_flags & BIT_RD)) {
2580 if(!(iq->qinfo_out.qname_len
2581 && dname_subdomain_c(iq->qchase.qname,
2582 iq->qinfo_out.qname)
2583 && dname_subdomain_c(iq->qinfo_out.qname,
2584 iq->dp->name))) {
2585 iq->qinfo_out.qname = iq->dp->name;
2586 iq->qinfo_out.qname_len = iq->dp->namelen;
2587 iq->qinfo_out.qtype = LDNS_RR_TYPE_A;
2588 iq->qinfo_out.qclass = iq->qchase.qclass;
2589 iq->qinfo_out.local_alias = NULL;
2590 iq->minimise_count = 0;
2593 iq->minimisation_state = MINIMISE_STATE;
2595 if(iq->minimisation_state == MINIMISE_STATE) {
2596 int qchaselabs = dname_count_labels(iq->qchase.qname);
2598 dname_count_labels(iq->qinfo_out.qname);
2600 qout_orig = iq->qinfo_out.qname;
2601 qout_orig_len = iq->qinfo_out.qname_len;
2602 iq->qinfo_out.qname = iq->qchase.qname;
2603 iq->qinfo_out.qname_len = iq->qchase.qname_len;
2604 iq->minimise_count++;
2605 iq->timeout_count = 0;
2607 iter_dec_attempts(iq->dp, 1, ie->outbound_msg_retry);
2614 iq->minimise_count > MINIMISE_ONE_LAB) {
2615 if(iq->minimise_count < MAX_MINIMISE_COUNT) {
2621 if (MAX_MINIMISE_COUNT - iq->minimise_count >=
2640 dname_remove_labels(&iq->qinfo_out.qname,
2641 &iq->qinfo_out.qname_len,
2645 && (iq->qchase.qtype == LDNS_RR_TYPE_DS
2646 || iq->qchase.qtype == LDNS_RR_TYPE_A)))
2648 iq->minimisation_state = DONOT_MINIMISE_STATE;
2651 iq->qinfo_out.qname, iq->qinfo_out.qname_len,
2652 iq->qinfo_out.qtype, iq->qinfo_out.qclass,
2654 qstate->env->scratch, 0, iq->dp->name,
2655 iq->dp->namelen);
2666 iq->response = msg;
2667 return final_state(iq);
2672 iq->qinfo_out.qname,
2673 iq->qinfo_out.qname_len,
2674 iq->qinfo_out.qtype,
2675 iq->qinfo_out.qclass,
2676 qstate, id, iq,
2693 if(iq->minimisation_state == SKIP_MINIMISE_STATE) {
2694 if(iq->timeout_count < MAX_MINIMISE_TIMEOUT_COUNT)
2697 iq->minimisation_state = MINIMISE_STATE;
2701 iq->minimisation_state = DONOT_MINIMISE_STATE;
2703 if(iq->minimisation_state == DONOT_MINIMISE_STATE)
2704 iq->qinfo_out = iq->qchase;
2710 if(!iq->auth_zone_avoid && qstate->blacklist) {
2712 iq->dp->name, iq->dp->namelen, iq->qinfo_out.qclass)) {
2716 iq->auth_zone_avoid = 1;
2719 if(iq->auth_zone_avoid) {
2720 iq->auth_zone_avoid = 0;
2722 } else if(auth_zones_lookup(qstate->env->auth_zones, &iq->qinfo_out,
2723 qstate->region, &iq->response, &auth_fallback, iq->dp->name,
2724 iq->dp->namelen)) {
2728 &iq->response->qinfo, iq->response->rep);
2730 if((iq->chase_flags&BIT_RD) && !(iq->response->rep->flags&BIT_AA)) {
2734 iq->num_current_queries++;
2735 iq->chase_to_rd = 0;
2736 iq->dnssec_lame_query = 0;
2737 iq->auth_zone_response = 1;
2738 return next_state(iq, QUERY_RESP_STATE);
2741 iq->auth_zone_response = 0;
2750 if(iq->dp->auth_dp) {
2753 iq->auth_zone_avoid = 1;
2754 return next_state(iq, INIT_REQUEST_STATE);
2763 if(iq->depth < ie->max_dependency_depth
2764 && iq->num_target_queries == 0
2765 && (!iq->target_count || iq->target_count[TARGET_COUNT_NX]==0)
2766 && iq->sent_count < TARGET_FETCH_STOP) {
2772 tf_policy = ie->target_fetch_policy[iq->depth];
2776 if(iq->caps_fallback) {
2779 if((ret=query_for_targets(qstate, iq, ie, id, -1, &extra))!=0) {
2785 iq->num_target_queries += extra;
2786 target_count_increase(iq, extra);
2787 if(iq->num_target_queries > 0) {
2793 if(qout_orig && iq->minimise_count > 0) {
2794 iq->minimise_count--;
2795 iq->qinfo_out.qname = qout_orig;
2796 iq->qinfo_out.qname_len = qout_orig_len;
2801 delegpt_count_addr(iq->dp, &naddr, &nres, &navail);
2805 if(iq->caps_server+1 >= naddr*3 ||
2806 iq->caps_server*2+2 >= (size_t)ie->max_sent_count) {
2811 (int)iq->caps_server+1, (int)naddr*3);
2812 iq->response = iq->caps_response;
2813 iq->caps_fallback = 0;
2814 iter_dec_attempts(iq->dp, 3, ie->outbound_msg_retry); /* space for fallback */
2815 iq->num_current_queries++; /* RespState decrements it*/
2816 iq->referral_count++; /* make sure we don't loop */
2817 iq->sent_count = 0;
2818 iq->dp_target_count = 0;
2819 iq->state = QUERY_RESP_STATE;
2823 (int)iq->caps_server);
2833 (void)query_for_targets(qstate, iq, ie, id, tf_policy, &extra);
2836 iq->num_target_queries += extra;
2837 target_count_increase(iq, extra);
2841 delegpt_add_unused_targets(iq->dp);
2848 struct dns_msg* forged_response = rpz_callback_from_iterator_module(qstate, iq);
2851 forged_response->rep, iq->qchase.qname,
2852 iq->qchase.qname_len, LDNS_RR_TYPE_CNAME,
2853 iq->qchase.qclass) &&
2854 iq->qchase.qtype != LDNS_RR_TYPE_CNAME &&
2857 if(!handle_cname_response(qstate, iq, forged_response,
2862 iq->qchase.qname = sname;
2863 iq->qchase.qname_len = snamelen;
2865 rpz_callback_from_iterator_cname(qstate, iq);
2870 iq->deleg_msg = NULL;
2871 iq->dp = NULL;
2872 iq->dsns_point = NULL;
2873 iq->auth_zone_response = 0;
2874 iq->refetch_glue = 0;
2875 iq->query_restart_count++;
2876 iq->sent_count = 0;
2877 iq->dp_target_count = 0;
2879 iq->minimisation_state = INIT_MINIMISE_STATE;
2880 outbound_list_clear(&iq->outlist);
2881 iq->num_current_queries = 0;
2885 iq->num_target_queries = 0;
2886 return next_state(iq, INIT_REQUEST_STATE);
2893 iq->response = forged_response;
2894 next_state(iq, FINISHED_STATE);
2895 if(!iter_prepend(iq, qstate->return_msg, qstate->region)) {
2904 target = iter_server_selection(ie, qstate->env, iq->dp,
2905 iq->dp->name, iq->dp->namelen, iq->qchase.qtype,
2906 &iq->dnssec_lame_query, &iq->chase_to_rd,
2907 iq->num_target_queries, qstate->blacklist,
2921 if(iq->num_target_queries==0 && iq->num_current_queries==0) {
2925 if(delegpt_count_missing_targets(iq->dp, NULL) > 0) {
2929 if((ret=query_for_targets(qstate, iq, ie, id,
2932 errinf_dname(qstate, "at zone", iq->dp->name);
2940 delegpt_count_missing_targets(iq->dp, NULL) == 0){
2955 errinf_dname(qstate, "at zone", iq->dp->name);
2959 iq->num_target_queries += qs;
2960 target_count_increase(iq, qs);
2964 if(iq->num_target_queries == 0) {
2968 if(iq->caps_fallback && iq->caps_reply) {
2973 (int)iq->caps_server+1);
2974 iq->response = iq->caps_response;
2975 iq->caps_fallback = 0;
2976 iter_dec_attempts(iq->dp, 3, ie->outbound_msg_retry); /* space for fallback */
2977 iq->num_current_queries++; /* RespState decrements it*/
2978 iq->referral_count++; /* make sure we don't loop */
2979 iq->sent_count = 0;
2980 iq->dp_target_count = 0;
2981 iq->state = QUERY_RESP_STATE;
2984 return processLastResort(qstate, iq, ie, id);
2991 check_waiting_queries(iq, qstate, id);
2994 if(qout_orig && iq->minimise_count > 0) {
2995 iq->minimise_count--;
2996 iq->qinfo_out.qname = qout_orig;
2997 iq->qinfo_out.qname_len = qout_orig_len;
3007 if(can_do_promisc && tf_policy == 0 && iq->depth == 0
3008 && iq->depth < ie->max_dependency_depth
3009 && ie->target_fetch_policy[iq->depth] != 0
3010 && iq->dp_target_count == 0
3015 (void)query_for_targets(qstate, iq, ie, id, 1, &extra);
3019 iq->num_target_queries += extra;
3020 target_count_increase(iq, extra);
3021 check_waiting_queries(iq, qstate, id);
3024 if(qout_orig && iq->minimise_count > 0) {
3025 iq->minimise_count--;
3026 iq->qinfo_out.qname = qout_orig;
3027 iq->qinfo_out.qname_len = qout_orig_len;
3033 target_count_increase_global_quota(iq, 1);
3034 if(iq->target_count && iq->target_count[TARGET_COUNT_GLOBAL_QUOTA]
3040 iq->target_count[TARGET_COUNT_GLOBAL_QUOTA]);
3046 sq_check_ratelimit = (!(iq->chase_flags & BIT_RD) && !iq->ratelimit_ok);
3049 log_query_info(VERB_QUERY, "sending query:", &iq->qinfo_out);
3050 log_name_addr(VERB_QUERY, "sending to target:", iq->dp->name,
3053 iq->dnssec_expected?"expected": "not expected",
3054 iq->dnssec_lame_query?" but lame_query anyway": "");
3065 iq->dp->name, &real_addr, real_addrlen);
3069 outq = (*qstate->env->send_query)(&iq->qinfo_out,
3070 iq->chase_flags | (iq->chase_to_rd?BIT_RD:0),
3075 ((iq->chase_to_rd||(iq->chase_flags&BIT_RD)!=0)&&
3077 &iq->qinfo_out)||target->attempts==1)?0:BIT_CD),
3078 iq->dnssec_expected, iq->caps_fallback || is_caps_whitelisted(
3079 ie, iq), sq_check_ratelimit, &real_addr, real_addrlen,
3080 iq->dp->name, iq->dp->namelen,
3081 (iq->dp->tcp_upstream || qstate->env->cfg->tcp_upstream),
3082 (iq->dp->ssl_upstream || qstate->env->cfg->ssl_upstream),
3092 iq->dp->name);
3098 iq->minimisation_state = SKIP_MINIMISE_STATE;
3099 return next_state(iq, QUERYTARGETS_STATE);
3101 outbound_list_insert(&iq->outlist, outq);
3102 iq->num_current_queries++;
3103 iq->sent_count++;
3129 * @param iq: iterator query state.
3137 processQueryResponse(struct module_qstate* qstate, struct iter_qstate* iq,
3143 iq->num_current_queries--;
3145 if(!inplace_cb_query_response_call(qstate->env, qstate, iq->response))
3148 if(iq->response == NULL) {
3151 iq->minimisation_state = SKIP_MINIMISE_STATE;
3153 iq->timeout_count++;
3154 iq->chase_to_rd = 0;
3155 iq->dnssec_lame_query = 0;
3157 return next_state(iq, QUERYTARGETS_STATE);
3159 iq->timeout_count = 0;
3160 orig_empty_nodata_found = iq->empty_nodata_found;
3162 (int)((iq->chase_flags&BIT_RD) || iq->chase_to_rd),
3163 iq->response, &iq->qinfo_out, iq->dp, &iq->empty_nodata_found);
3164 iq->chase_to_rd = 0;
3166 iq->response->rep->flags &= ~BIT_TC;
3167 if(orig_empty_nodata_found != iq->empty_nodata_found &&
3168 iq->empty_nodata_found < EMPTY_NODATA_RETRY_COUNT) {
3172 iq->dp, &qstate->reply->remote_addr,
3177 return next_state(iq, QUERYTARGETS_STATE);
3179 if(type == RESPONSE_TYPE_REFERRAL && (iq->chase_flags&BIT_RD) &&
3180 !iq->auth_zone_response) {
3185 if(!qstate->env->cfg->disable_dnssec_lame_check && iq->dnssec_expected
3186 && !iq->dnssec_lame_query &&
3187 !(iq->chase_flags&BIT_RD)
3188 && iq->sent_count < DNSSEC_LAME_DETECT_COUNT
3195 if(!iter_msg_has_dnssec(iq->response)) {
3202 iq->dp, &qstate->reply->remote_addr,
3209 if(!iter_msg_from_zone(iq->response, iq->dp, type,
3210 iq->qchase.qclass))
3215 } else iq->dnssec_lame_query = 0;
3219 iq->response->rep, iq->response->rep->an_numrrsets,
3220 iq->response->rep->an_numrrsets
3221 + iq->response->rep->ns_numrrsets);
3222 if(!ns) ns = find_NS(iq->response->rep, 0,
3223 iq->response->rep->an_numrrsets);
3224 if(!ns || !dname_strict_subdomain_c(ns->rk.dname, iq->dp->name)
3225 || !dname_subdomain_c(iq->qchase.qname, ns->rk.dname)){
3229 iter_scrub_ds(iq->response, ns, iq->dp->name);
3230 } else iter_scrub_ds(iq->response, NULL, NULL);
3232 FLAGS_GET_RCODE(iq->response->rep->flags) == LDNS_RCODE_YXDOMAIN) {
3238 if(type == RESPONSE_TYPE_CNAME && iq->response->rep->an_numrrsets >= 1
3239 && ntohs(iq->response->rep->rrsets[0]->rk.type) == LDNS_RR_TYPE_DNAME) {
3242 get_cname_target(iq->response->rep->rrsets[0], &sname,
3244 if(snamelen && dname_subdomain_c(sname, iq->response->rep->rrsets[0]->rk.dname)) {
3250 iq->qchase.qtype == LDNS_RR_TYPE_CNAME &&
3251 iq->minimisation_state == MINIMISE_STATE &&
3252 query_dname_compare(iq->qchase.qname, iq->qinfo_out.qname) == 0) {
3266 FLAGS_GET_RCODE(iq->response->rep->flags)
3268 (iq->response->rep->an_numrrsets?"ANSWER":
3273 if(iq->qchase.qtype == LDNS_RR_TYPE_DS && !iq->dsns_point
3274 && !(iq->chase_flags&BIT_RD)
3275 && iter_ds_toolow(iq->response, iq->dp)
3276 && iter_dp_cangodown(&iq->qchase, iq->dp)) {
3278 outbound_list_clear(&iq->outlist);
3279 iq->num_current_queries = 0;
3283 iq->num_target_queries = 0;
3284 return processDSNSFind(qstate, iq, id);
3286 if(iq->qchase.qtype == LDNS_RR_TYPE_DNSKEY && SERVE_EXPIRED
3288 reply_find_answer_rrset(&iq->qchase, iq->response->rep) != NULL) {
3294 iter_make_minimal(iq->response->rep);
3297 iter_dns_store(qstate->env, &iq->response->qinfo,
3298 iq->response->rep,
3299 iq->qchase.qtype != iq->response->qinfo.qtype,
3301 iq->dp&&iq->dp->has_parent_side_NS,
3305 outbound_list_clear(&iq->outlist);
3306 iq->num_current_queries = 0;
3310 iq->num_target_queries = 0;
3315 if(iq->minimisation_state != DONOT_MINIMISE_STATE
3316 && !(iq->chase_flags & BIT_RD)) {
3317 if(FLAGS_GET_RCODE(iq->response->rep->flags) !=
3320 if(FLAGS_GET_RCODE(iq->response->rep->flags) ==
3322 iter_scrub_nxdomain(iq->response);
3323 return final_state(iq);
3331 iq->minimisation_state = DONOT_MINIMISE_STATE;
3333 if(FLAGS_GET_RCODE(iq->response->rep->flags) ==
3342 if(iq->dnssec_expected)
3343 return final_state(iq);
3352 &iq->response->qinfo);
3354 iq->response->qinfo.qname,
3355 iq->response->qinfo.qname_len,
3356 iq->response->qinfo.qtype,
3357 iq->response->qinfo.qclass,
3358 qstate, id, iq,
3366 return next_state(iq, QUERYTARGETS_STATE);
3368 return final_state(iq);
3385 reply_find_rrset_section_ns(iq->response->rep,
3386 iq->qchase.qname, iq->qchase.qname_len,
3387 LDNS_RR_TYPE_NS, iq->qchase.qclass)
3388 || reply_find_rrset_section_an(iq->response->rep,
3389 iq->qchase.qname, iq->qchase.qname_len,
3390 LDNS_RR_TYPE_NS, iq->qchase.qclass)
3395 iter_dns_store(qstate->env, &iq->response->qinfo,
3396 iq->response->rep, 1, 0, 0, NULL, 0,
3398 if(iq->store_parent_NS)
3400 iq->response->rep);
3403 iq->response->rep, iq->dp->name);
3406 if(!qstate->no_cache_store && iq->query_for_pside_glue
3407 && !iq->pside_glue) {
3408 iq->pside_glue = reply_find_rrset(iq->response->rep,
3409 iq->qchase.qname, iq->qchase.qname_len,
3410 iq->qchase.qtype, iq->qchase.qclass);
3411 if(iq->pside_glue) {
3413 "glue", iq->pside_glue);
3415 iq->pside_glue);
3421 iq->deleg_msg = iq->response;
3423 old_dp = iq->dp;
3424 iq->dp = delegpt_from_message(iq->response, qstate->region);
3426 iq->minimisation_state = INIT_MINIMISE_STATE;
3427 if(!iq->dp) {
3431 if(old_dp->namelabs + 1 < iq->dp->namelabs) {
3438 uint8_t* qname = iq->dp->name;
3439 size_t qnamelen = iq->dp->namelen;
3442 iq->qchase.qclass, *qstate->env->now,
3445 if(!cache_fill_missing(qstate->env, iq->qchase.qclass,
3446 qstate->region, iq->dp, 0)) {
3450 if(iq->store_parent_NS && query_dname_compare(iq->dp->name,
3451 iq->store_parent_NS->name) == 0)
3452 iter_merge_retry_counts(iq->dp, iq->store_parent_NS,
3454 delegpt_log(VERB_ALGO, iq->dp);
3456 iq->referral_count++;
3457 iq->sent_count = 0;
3458 iq->dp_target_count = 0;
3461 iq->dnssec_expected = iter_indicates_dnssec(qstate->env,
3462 iq->dp, iq->response, iq->qchase.qclass);
3464 if(iq->dnssec_expected && qstate->env->cfg->prefetch_key &&
3466 generate_dnskey_prefetch(qstate, iq, id);
3473 generate_ns_check(qstate, iq, id);
3479 outbound_list_clear(&iq->outlist);
3480 iq->num_current_queries = 0;
3484 iq->num_target_queries = 0;
3485 iq->response = NULL;
3486 iq->fail_addr_type = 0;
3488 return next_state(iq, QUERYTARGETS_STATE);
3497 log_dns_msg("cname msg", &iq->response->qinfo,
3498 iq->response->rep);
3501 if(iq->qchase.qtype == LDNS_RR_TYPE_DS && !iq->dsns_point
3502 && !(iq->chase_flags&BIT_RD)
3503 && iter_ds_toolow(iq->response, iq->dp)
3504 && iter_dp_cangodown(&iq->qchase, iq->dp)) {
3505 outbound_list_clear(&iq->outlist);
3506 iq->num_current_queries = 0;
3510 iq->num_target_queries = 0;
3511 return processDSNSFind(qstate, iq, id);
3514 if(!handle_cname_response(qstate, iq, iq->response,
3524 iter_dns_store(qstate->env, &iq->response->qinfo,
3525 iq->response->rep, 1, qstate->prefetch_leeway,
3526 iq->dp&&iq->dp->has_parent_side_NS, NULL,
3530 iq->qchase.qname = sname;
3531 iq->qchase.qname_len = snamelen;
3535 rpz_callback_from_iterator_cname(qstate, iq);
3538 forged_response->rep, iq->qchase.qname,
3539 iq->qchase.qname_len, LDNS_RR_TYPE_CNAME,
3540 iq->qchase.qclass) &&
3541 iq->qchase.qtype != LDNS_RR_TYPE_CNAME &&
3544 if(!handle_cname_response(qstate, iq, forged_response,
3549 iq->qchase.qname = sname;
3550 iq->qchase.qname_len = snamelen;
3552 rpz_callback_from_iterator_cname(qstate, iq);
3558 iq->response = forged_response;
3559 next_state(iq, FINISHED_STATE);
3560 if(!iter_prepend(iq, qstate->return_msg, qstate->region)) {
3569 iq->deleg_msg = NULL;
3570 iq->dp = NULL;
3571 iq->dsns_point = NULL;
3572 iq->auth_zone_response = 0;
3573 iq->sent_count = 0;
3574 iq->dp_target_count = 0;
3575 if(iq->minimisation_state != MINIMISE_STATE)
3578 iq->query_restart_count++;
3580 iq->minimisation_state = INIT_MINIMISE_STATE;
3586 outbound_list_clear(&iq->outlist);
3587 iq->num_current_queries = 0;
3591 iq->num_target_queries = 0;
3598 return next_state(iq, INIT_REQUEST_STATE);
3603 if(!dname_subdomain_c(iq->qchase.qname, iq->dp->name)) {
3612 iq->dp->name, iq->dp->namelen,
3614 iq->qchase.qtype))
3621 if(!dname_subdomain_c(iq->qchase.qname, iq->dp->name)) {
3631 iq->dp->name, iq->dp->namelen,
3632 *qstate->env->now, 0, 1, iq->qchase.qtype))
3651 iq->minimisation_state = DONOT_MINIMISE_STATE;
3652 if(iq->auth_zone_response) {
3654 iq->auth_zone_response = 0;
3656 iq->dp->name, iq->dp->namelen, qstate->qinfo.qclass)) {
3660 "for auth zone", iq->dp->name);
3665 iq->auth_zone_avoid = 1;
3666 if(iq->dp->auth_dp) {
3669 iq->dp = NULL;
3670 return next_state(iq, INIT_REQUEST_STATE);
3673 return next_state(iq, QUERYTARGETS_STATE);
3741 struct iter_qstate* iq = (struct iter_qstate*)qstate->minfo[id];
3743 iq->response->rep->flags &= ~(BIT_RD|BIT_RA); /* ignore rec-lame */
3745 (int)((iq->chase_flags&BIT_RD) || iq->chase_to_rd),
3746 iq->response, &iq->qchase, iq->dp, NULL);
3749 qstate->return_msg = iq->response;
3768 qstate->qinfo.qclass, qstate, id, iq,
3772 generate_a_aaaa_check(qstate, iq, id);
3798 struct iter_qstate* iq = (struct iter_qstate*)qstate->minfo[id];
3827 /* if iq->query_for_pside_glue then add the pside_glue (marked lame) */
3828 if(iq->pside_glue) {
3833 iq->pside_glue);
3835 iq->pside_glue, 1, NULL))
3844 rrset = reply_find_answer_rrset(&iq->qchase, qstate->return_msg->rep);
3897 /* if the finished (iq->response) query has no NS set: continue
4037 struct iter_qstate* iq = (struct iter_qstate*)qstate->minfo[id];
4043 if(iq->qchase.qclass == 0) {
4045 iq->qchase.qclass = LDNS_RR_CLASS_ANY;
4053 c, qstate, id, iq, INIT_REQUEST_STATE,
4062 iq->num_current_queries ++;
4068 if(iq->num_current_queries == 0) {
4084 * @param iq: iterator query state.
4090 processFinished(struct module_qstate* qstate, struct iter_qstate* iq,
4097 if(!qstate->no_cache_store && iq->query_for_pside_glue
4098 && !iq->pside_glue)
4100 iq->deleg_msg?iq->deleg_msg->rep:
4101 (iq->response?iq->response->rep:NULL));
4102 if(!iq->response) {
4110 iq->response->rep->flags |= BIT_RA;
4114 iq->response->rep->flags &= ~BIT_AA;
4117 iq->response->rep->flags |= BIT_QR;
4120 iq->response->rep->reason_bogus_str = NULL;
4127 iq->response->rep->reason_bogus_str = err_str;
4138 if(iq->an_prepend_list || iq->ns_prepend_list) {
4139 if(!iter_prepend(iq, iq->response, qstate->region)) {
4144 iq->response->qinfo = qstate->qinfo;
4146 iq->response->rep->security = sec_status_unchecked;
4152 iq->response->rep, 0, qstate->prefetch_leeway,
4153 iq->dp&&iq->dp->has_parent_side_NS,
4159 qstate->return_msg = iq->response;
4198 * @param iq: iterator query state.
4202 iter_handle(struct module_qstate* qstate, struct iter_qstate* iq,
4208 iter_state_to_string(iq->state));
4209 switch(iq->state) {
4211 cont = processInitRequest(qstate, iq, ie, id);
4214 cont = processInitRequest2(qstate, iq, id);
4217 cont = processInitRequest3(qstate, iq, id);
4220 cont = processQueryTargets(qstate, iq, ie, id);
4223 cont = processQueryResponse(qstate, iq, ie, id);
4232 cont = processDSNSFind(qstate, iq, id);
4235 cont = processFinished(qstate, iq, id);
4239 iq->state);
4251 * @param iq: iterator query state.
4255 process_request(struct module_qstate* qstate, struct iter_qstate* iq,
4260 iq->state = INIT_REQUEST_STATE;
4261 iq->final_state = FINISHED_STATE;
4263 iter_handle(qstate, iq, ie, id);
4268 process_response(struct module_qstate* qstate, struct iter_qstate* iq,
4277 iq->response = NULL;
4278 iq->state = QUERY_RESP_STATE;
4280 if(event == module_event_noreply && iq->timeout_count >= 3 &&
4282 !iq->caps_fallback && !is_caps_whitelisted(ie, iq)) {
4284 iq->caps_fallback = 1;
4285 iq->caps_server = 0;
4286 iq->caps_reply = NULL;
4287 iq->caps_response = NULL;
4288 iq->caps_minimisation_state = DONOT_MINIMISE_STATE;
4289 iq->state = QUERYTARGETS_STATE;
4290 iq->num_current_queries--;
4293 iter_dec_attempts(iq->dp, 3, ie->outbound_msg_retry);
4302 outbound_list_remove(&iq->outlist, outbound);
4309 fill_fail_addr(iq, &qstate->reply->remote_addr,
4324 iq->parse_failures++;
4330 iq->parse_failures++;
4354 if(!scrub_message(pkt, prs, &iq->qinfo_out, iq->dp->name,
4357 if(event == module_event_capsfail && !iq->caps_fallback) {
4358 iq->caps_fallback = 1;
4359 iq->caps_server = 0;
4360 iq->caps_reply = NULL;
4361 iq->caps_response = NULL;
4362 iq->caps_minimisation_state = DONOT_MINIMISE_STATE;
4363 iq->state = QUERYTARGETS_STATE;
4364 iq->num_current_queries--;
4367 iq->scrub_failures++;
4372 iq->response = dns_alloc_msg(pkt, prs, qstate->region);
4373 if(!iq->response)
4376 log_name_addr(VERB_DETAIL, "reply from", iq->dp->name,
4379 log_dns_msg("incoming scrubbed packet:", &iq->response->qinfo,
4380 iq->response->rep);
4383 limit_nsec_ttl(iq->response);
4385 if(event == module_event_capsfail || iq->caps_fallback) {
4387 iq->minimisation_state != DONOT_MINIMISE_STATE) {
4390 iq->minimisation_state = SKIP_MINIMISE_STATE;
4394 caps_strip_reply(iq->response->rep);
4396 if(iq->caps_fallback &&
4397 iq->caps_minimisation_state != iq->minimisation_state) {
4400 iq->caps_fallback = 0;
4403 if(!iq->caps_fallback) {
4405 iq->caps_fallback = 1;
4406 iq->caps_server = 0;
4407 iq->caps_reply = iq->response->rep;
4408 iq->caps_response = iq->response;
4409 iq->caps_minimisation_state = iq->minimisation_state;
4410 iq->state = QUERYTARGETS_STATE;
4411 iq->num_current_queries--;
4416 if(!iq->caps_reply) {
4417 iq->caps_reply = iq->response->rep;
4418 iq->caps_response = iq->response;
4419 iq->caps_server = -1; /*become zero at ++,
4421 } else if(caps_failed_rcode(iq->caps_reply) &&
4422 !caps_failed_rcode(iq->response->rep)) {
4424 iq->caps_reply = iq->response->rep;
4425 iq->caps_response = iq->response;
4426 } else if(!caps_failed_rcode(iq->caps_reply) &&
4427 caps_failed_rcode(iq->response->rep)) {
4432 } else if(caps_failed_rcode(iq->caps_reply) &&
4433 caps_failed_rcode(iq->response->rep)) {
4436 } else if(!reply_equal(iq->response->rep, iq->caps_reply,
4440 outbound_list_remove(&iq->outlist, outbound);
4447 iq->caps_server++;
4448 iq->state = QUERYTARGETS_STATE;
4449 iq->num_current_queries--;
4455 iq->caps_fallback = 0; /* if we were in fallback, 0x20 is OK now */
4458 outbound_list_remove(&iq->outlist, outbound);
4459 iter_handle(qstate, iq, ie, id);
4467 struct iter_qstate* iq = (struct iter_qstate*)qstate->minfo[id];
4470 if(iq) log_query_info(VERB_QUERY, "iterator operate: query",
4472 if(iq && qstate->qinfo.qname != iq->qchase.qname)
4474 &iq->qchase);
4478 iq == NULL) {
4484 iq = (struct iter_qstate*)qstate->minfo[id];
4485 process_request(qstate, iq, ie, id);
4488 if(iq && event == module_event_pass) {
4489 iter_handle(qstate, iq, ie, id);
4492 if(iq && outbound) {
4493 process_response(qstate, iq, ie, id, outbound, event);
4511 struct iter_qstate* iq;
4514 iq = (struct iter_qstate*)qstate->minfo[id];
4515 if(iq) {
4516 outbound_list_clear(&iq->outlist);
4517 if(iq->target_count && --iq->target_count[TARGET_COUNT_REF] == 0) {
4518 free(iq->target_count);
4519 if(*iq->nxns_dp) free(*iq->nxns_dp);
4520 free(iq->nxns_dp);
4522 iq->num_current_queries = 0;