Lines Matching defs:iq
80 static void target_count_increase_nx(struct iter_qstate* iq, int num);
139 struct iter_qstate* iq = (struct iter_qstate*)regional_alloc(
141 qstate->minfo[id] = iq;
142 if(!iq)
144 memset(iq, 0, sizeof(*iq));
145 iq->state = INIT_REQUEST_STATE;
146 iq->final_state = FINISHED_STATE;
147 iq->an_prepend_list = NULL;
148 iq->an_prepend_last = NULL;
149 iq->ns_prepend_list = NULL;
150 iq->ns_prepend_last = NULL;
151 iq->dp = NULL;
152 iq->depth = 0;
153 iq->num_target_queries = 0;
154 iq->num_current_queries = 0;
155 iq->query_restart_count = 0;
156 iq->referral_count = 0;
157 iq->sent_count = 0;
158 iq->ratelimit_ok = 0;
159 iq->target_count = NULL;
160 iq->dp_target_count = 0;
161 iq->wait_priming_stub = 0;
162 iq->refetch_glue = 0;
163 iq->dnssec_expected = 0;
164 iq->dnssec_lame_query = 0;
165 iq->chase_flags = qstate->query_flags;
167 iq->qchase = qstate->qinfo;
168 outbound_list_init(&iq->outlist);
169 iq->minimise_count = 0;
170 iq->timeout_count = 0;
172 iq->minimisation_state = INIT_MINIMISE_STATE;
174 iq->minimisation_state = DONOT_MINIMISE_STATE;
176 memset(&iq->qinfo_out, 0, sizeof(struct query_info));
184 * @param iq: iterator query state
191 next_state(struct iter_qstate* iq, enum iter_state nextstate)
196 if(iq->response == NULL) {
201 iq->state = nextstate;
213 * @param iq: iterator query state
218 final_state(struct iter_qstate* iq)
220 return next_state(iq, iq->final_state);
387 iter_prepend(struct iter_qstate* iq, struct dns_msg* msg,
393 for(p = iq->an_prepend_list; p; p = p->next)
395 for(p = iq->ns_prepend_list; p; p = p->next)
408 for(p = iq->an_prepend_list; p; p = p->next) {
417 for(p = iq->ns_prepend_list; p; p = p->next) {
444 * @param iq: iterator query state.
449 iter_find_rrset_in_prepend_answer(struct iter_qstate* iq,
452 struct iter_prep_list* p = iq->an_prepend_list;
467 * @param iq: iterator query state.
472 iter_add_prepend_answer(struct module_qstate* qstate, struct iter_qstate* iq,
482 if(iq->an_prepend_last)
483 iq->an_prepend_last->next = p;
484 else iq->an_prepend_list = p;
485 iq->an_prepend_last = p;
492 * @param iq: iterator query state.
497 iter_add_prepend_auth(struct module_qstate* qstate, struct iter_qstate* iq,
507 if(iq->ns_prepend_last)
508 iq->ns_prepend_last->next = p;
509 else iq->ns_prepend_list = p;
510 iq->ns_prepend_last = p;
522 * @param iq: iterator query state.
529 handle_cname_response(struct module_qstate* qstate, struct iter_qstate* iq,
534 *mname = iq->qchase.qname;
535 *mname_len = iq->qchase.qname_len;
547 !iter_find_rrset_in_prepend_answer(iq, r)) {
548 if(!iter_add_prepend_answer(qstate, iq, r))
555 !iter_find_rrset_in_prepend_answer(iq, r)) {
557 if(!iter_add_prepend_answer(qstate, iq, r))
571 if(!iter_add_prepend_auth(qstate, iq, r))
580 fill_fail_addr(struct iter_qstate* iq, struct sockaddr_storage* addr,
584 iq->fail_addr_type = 0;
588 iq->fail_addr_type = 4;
589 memcpy(&iq->fail_addr.in,
591 sizeof(iq->fail_addr.in));
595 iq->fail_addr_type = 6;
596 memcpy(&iq->fail_addr.in6,
598 sizeof(iq->fail_addr.in6));
602 iq->fail_addr_type = 0;
608 print_fail_addr(struct iter_qstate* iq, char* buf, size_t len)
610 if(iq->fail_addr_type == 4) {
611 if(inet_ntop(AF_INET, &iq->fail_addr.in, buf,
616 else if(iq->fail_addr_type == 6) {
617 if(inet_ntop(AF_INET6, &iq->fail_addr.in6, buf,
628 errinf_reply(struct module_qstate* qstate, struct iter_qstate* iq)
633 (iq->fail_addr_type != 0)) {
640 print_fail_addr(iq, from, sizeof(from));
644 if(iq->scrub_failures || iq->parse_failures) {
645 if(iq->scrub_failures)
647 if(iq->parse_failures)
649 } else if(iq->response == NULL && iq->timeout_count != 0) {
651 } else if(iq->response == NULL) {
653 if(iq->dp) {
654 if(iq->dp->target_list == NULL)
657 if(iq->dp->nslist == NULL)
659 if(iq->dp->bogus)
663 if(iq->response && iq->response->rep) {
664 if(FLAGS_GET_RCODE(iq->response->rep->flags) != 0) {
667 FLAGS_GET_RCODE(iq->response->rep->flags),
673 if(iq->response->rep->an_numrrsets == 0) {
721 is_caps_whitelisted(struct iter_env* ie, struct iter_qstate* iq)
724 return name_tree_lookup(ie->caps_white, iq->qchase.qname,
725 iq->qchase.qname_len, dname_count_labels(iq->qchase.qname),
726 iq->qchase.qclass) != NULL;
734 target_count_create(struct iter_qstate* iq)
736 if(!iq->target_count) {
737 iq->target_count = (int*)calloc(TARGET_COUNT_MAX, sizeof(int));
739 if(iq->target_count) {
740 iq->target_count[TARGET_COUNT_REF] = 1;
741 iq->nxns_dp = (uint8_t**)calloc(1, sizeof(uint8_t*));
747 target_count_increase(struct iter_qstate* iq, int num)
749 target_count_create(iq);
750 if(iq->target_count)
751 iq->target_count[TARGET_COUNT_QUERIES] += num;
752 iq->dp_target_count++;
756 target_count_increase_nx(struct iter_qstate* iq, int num)
758 target_count_create(iq);
759 if(iq->target_count)
760 iq->target_count[TARGET_COUNT_NX] += num;
764 target_count_increase_global_quota(struct iter_qstate* iq, int num)
766 target_count_create(iq);
767 if(iq->target_count)
768 iq->target_count[TARGET_COUNT_GLOBAL_QUOTA] += num;
783 * @param iq: The iterator state that is generating this event.
797 struct iter_qstate* iq, enum iter_state initial_state,
861 target_count_create(iq);
862 subiq->target_count = iq->target_count;
863 if(iq->target_count) {
864 iq->target_count[TARGET_COUNT_REF] ++; /* extra reference */
865 subiq->nxns_dp = iq->nxns_dp;
869 subiq->depth = iq->depth+1;
888 * @param iq: iterator query state.
894 prime_root(struct module_qstate* qstate, struct iter_qstate* iq, int id,
911 qclass, qstate, id, iq, QUERYTARGETS_STATE, PRIME_RESP_STATE,
950 * @param iq: iterator query state.
960 prime_stub(struct module_qstate* qstate, struct iter_qstate* iq, int id,
971 stub = hints_lookup_stub(qstate->env->hints, qname, qclass, iq->dp,
978 if(!iq->auth_zone_avoid && iq->dp && iq->dp->auth_dp &&
979 query_dname_compare(iq->dp->name, stub_dp->name) == 0) {
987 if(iq->dp == NULL) r = 2;
990 iq->dp = delegpt_copy(stub_dp, qstate->region);
992 if(!iq->dp) {
998 log_nametypeclass(VERB_DETAIL, "use stub", iq->dp->name,
1010 LDNS_RR_TYPE_NS, qclass, qstate, id, iq,
1056 auth_zone_delegpt(struct module_qstate* qstate, struct iter_qstate* iq,
1060 if(iq->auth_zone_avoid)
1063 delname = iq->qchase.qname;
1064 delnamelen = iq->qchase.qname_len;
1076 if(iq->dp && query_dname_compare(z->name, iq->dp->name) == 0
1077 && iq->dp->auth_dp && qstate->blacklist &&
1089 iq->dp = NULL;
1092 if(iq->dp==NULL || dname_subdomain_c(z->name, iq->dp->name)) {
1135 iq->dp = dp;
1148 * @param iq: iterator query state.
1152 generate_a_aaaa_check(struct module_qstate* qstate, struct iter_qstate* iq,
1158 struct reply_info* rep = iq->response->rep;
1160 log_assert(iq->dp);
1162 if(iq->depth == ie->max_dependency_depth)
1189 qstate, id, iq,
1203 * @param iq: iterator query state.
1207 generate_ns_check(struct module_qstate* qstate, struct iter_qstate* iq, int id)
1211 log_assert(iq->dp);
1213 if(iq->depth == ie->max_dependency_depth)
1215 if(!can_have_last_resort(qstate->env, iq->dp->name, iq->dp->namelen,
1216 iq->qchase.qclass, NULL, NULL, NULL))
1220 query_dname_compare(iq->dp->name, qstate->qinfo.qname)==0 &&
1223 generate_a_aaaa_check(qstate, iq, id);
1231 iq->dp->name, LDNS_RR_TYPE_NS, iq->qchase.qclass);
1232 if(!generate_sub_request(iq->dp->name, iq->dp->namelen,
1233 LDNS_RR_TYPE_NS, iq->qchase.qclass, qstate, id, iq,
1245 subiq->dp = delegpt_copy(iq->dp, subq->region);
1269 * @param iq: iterator query state.
1274 struct iter_qstate* iq, int id)
1277 log_assert(iq->dp);
1281 query_dname_compare(iq->dp->name, qstate->qinfo.qname)==0 &&
1297 iq->dp->name, LDNS_RR_TYPE_DNSKEY, iq->qchase.qclass);
1298 if(!generate_sub_request(iq->dp->name, iq->dp->namelen,
1299 LDNS_RR_TYPE_DNSKEY, iq->qchase.qclass, qstate, id, iq,
1310 subiq->dp = delegpt_copy(iq->dp, subq->region);
1319 * @param iq: iterator query state.
1321 * If returns true but, iq->dp is NULL then a malloc failure occurred.
1324 forward_request(struct module_qstate* qstate, struct iter_qstate* iq)
1327 uint8_t* delname = iq->qchase.qname;
1328 size_t delnamelen = iq->qchase.qname_len;
1330 if(iq->refetch_glue && iq->dp) {
1331 delname = iq->dp->name;
1332 delnamelen = iq->dp->namelen;
1335 if( (iq->qchase.qtype == LDNS_RR_TYPE_DS || iq->refetch_glue)
1336 && !dname_is_root(iq->qchase.qname))
1338 dp = forwards_lookup(qstate->env->fwds, delname, iq->qchase.qclass,
1342 iq->chase_flags |= BIT_RD;
1343 iq->dp = delegpt_copy(dp, qstate->region);
1345 /* iq->dp checked by caller */
1362 * @param iq: iterator query state.
1369 processInitRequest(struct module_qstate* qstate, struct iter_qstate* iq,
1382 if(iq->query_restart_count > ie->max_query_restarts) {
1384 " of query restarts with %d", iq->query_restart_count);
1387 if(iq->qchase.qname)
1388 errinf_dname(qstate, "stop at", iq->qchase.qname);
1396 verbose(VERB_ALGO, "request has dependency depth of %d", iq->depth);
1397 if(iq->depth > ie->max_dependency_depth) {
1399 "dependency depth with depth of %d", iq->depth);
1407 iq->qchase.qclass = 0;
1408 return next_state(iq, COLLECT_CLASS_STATE);
1414 * we won’t try to re-fetch glue if the iq->dp is null.
1416 if (iq->refetch_glue &&
1417 iq->dp &&
1418 !can_have_last_resort(qstate->env, iq->dp->name,
1419 iq->dp->namelen, iq->qchase.qclass, NULL, NULL, NULL)) {
1420 iq->refetch_glue = 0;
1432 rpz_callback_from_iterator_cname(qstate, iq);
1438 forged_response->rep, iq->qchase.qname,
1439 iq->qchase.qname_len, LDNS_RR_TYPE_CNAME,
1440 iq->qchase.qclass) &&
1441 iq->qchase.qtype != LDNS_RR_TYPE_CNAME &&
1444 if(!handle_cname_response(qstate, iq, forged_response,
1449 iq->qchase.qname = sname;
1450 iq->qchase.qname_len = slen;
1452 rpz_callback_from_iterator_cname(qstate, iq);
1458 iq->response = forged_response;
1459 next_state(iq, FINISHED_STATE);
1460 if(!iter_prepend(iq, qstate->return_msg, qstate->region)) {
1468 iq->dp = NULL;
1469 iq->refetch_glue = 0;
1470 iq->query_restart_count++;
1471 iq->sent_count = 0;
1472 iq->dp_target_count = 0;
1475 iq->minimisation_state = INIT_MINIMISE_STATE;
1476 return next_state(iq, INIT_REQUEST_STATE);
1480 if (iter_stub_fwd_no_cache(qstate, &iq->qchase, &dpname, &dpnamelen,
1493 msg = dns_cache_lookup(qstate->env, iq->qchase.qname,
1494 iq->qchase.qname_len, iq->qchase.qtype,
1495 iq->qchase.qclass, qstate->query_flags,
1499 iter_qname_indicates_dnssec(qstate->env, &iq->qchase)) {
1502 msg = val_neg_getmsg(qstate->env->neg_cache, &iq->qchase,
1511 iq->qchase.qname) != 0)
1517 &iq->qchase);
1531 if(!handle_cname_response(qstate, iq, msg,
1538 iq->qchase.qname = sname;
1539 iq->qchase.qname_len = slen;
1542 iq->dp = NULL;
1543 iq->refetch_glue = 0;
1544 iq->query_restart_count++;
1545 iq->sent_count = 0;
1546 iq->dp_target_count = 0;
1549 iq->minimisation_state = INIT_MINIMISE_STATE;
1550 return next_state(iq, INIT_REQUEST_STATE);
1559 iq->response = msg;
1560 return final_state(iq);
1564 if(forward_request(qstate, iq))
1566 if(!iq->dp) {
1571 if(!cache_fill_missing(qstate->env, iq->qchase.qclass,
1572 qstate->region, iq->dp)) {
1589 iq->refetch_glue = 0;
1590 iq->minimisation_state = DONOT_MINIMISE_STATE;
1594 return next_state(iq, QUERYTARGETS_STATE);
1603 if(iq->refetch_glue) {
1604 if(!iq->dp) {
1609 delname = iq->dp->name;
1610 delnamelen = iq->dp->namelen;
1612 delname = iq->qchase.qname;
1613 delnamelen = iq->qchase.qname_len;
1615 if(iq->qchase.qtype == LDNS_RR_TYPE_DS || iq->refetch_glue ||
1616 (iq->qchase.qtype == LDNS_RR_TYPE_NS && qstate->prefetch_leeway
1617 && can_have_last_resort(qstate->env, delname, delnamelen, iq->qchase.qclass, NULL, NULL, NULL))) {
1623 if(dname_is_root(delname) && (iq->refetch_glue ||
1624 (iq->qchase.qtype == LDNS_RR_TYPE_NS &&
1635 iq->dp = dns_cache_find_delegation(qstate->env, delname,
1636 delnamelen, iq->qchase.qtype, iq->qchase.qclass,
1637 qstate->region, &iq->deleg_msg,
1640 else iq->dp = NULL;
1644 if(iq->dp == NULL) {
1648 if(!auth_zone_delegpt(qstate, iq, delname, delnamelen))
1651 if(iq->dp) /* use auth zone dp */
1652 return next_state(iq, INIT_REQUEST_2_STATE);
1654 r = prime_stub(qstate, iq, id, delname,
1655 iq->qchase.qclass);
1661 iq->qchase.qclass, nolock)) {
1665 iq->dp = hints_find_root(qstate->env->hints,
1666 iq->qchase.qclass, nolock);
1667 if(!iq->dp) {
1673 iq->dp = delegpt_copy(iq->dp, qstate->region);
1675 if(!iq->dp) {
1681 return next_state(iq, INIT_REQUEST_2_STATE);
1685 if(!prime_root(qstate, iq, id, iq->qchase.qclass))
1695 if(!iq->ratelimit_ok && qstate->prefetch_leeway)
1696 iq->ratelimit_ok = 1; /* allow prefetches, this keeps
1712 iq->dp, ie->supports_ipv4, ie->supports_ipv6,
1715 if(!can_have_last_resort(qstate->env, iq->dp->name, iq->dp->namelen, iq->qchase.qclass, &have_dp, &iq->dp, qstate->region)) {
1720 if(have_dp && !iq->dp) {
1731 delegpt_log(VERB_ALGO, iq->dp);
1734 errinf_dname(qstate, "for zone", iq->dp->name);
1738 if(dname_is_root(iq->dp->name)) {
1743 iq->dp = hints_find_root(qstate->env->hints,
1744 iq->qchase.qclass, nolock);
1747 if(!iq->dp) {
1752 iq->dp = delegpt_copy(iq->dp, qstate->region);
1754 if(!iq->dp) {
1764 delegpt_log(VERB_ALGO, iq->dp);
1766 delname = iq->dp->name;
1767 delnamelen = iq->dp->namelen;
1774 delegpt_log(VERB_ALGO, iq->dp);
1778 return next_state(iq, INIT_REQUEST_2_STATE);
1791 * @param iq: iterator query state.
1797 processInitRequest2(struct module_qstate* qstate, struct iter_qstate* iq,
1805 delname = iq->qchase.qname;
1806 delnamelen = iq->qchase.qname_len;
1807 if(iq->refetch_glue) {
1810 if(!iq->dp) {
1818 qstate->env->hints, iq->qchase.qname, iq->qchase.qclass,
1819 iq->dp, nolock);
1821 dname_subdomain_c(iq->dp->name, stub->dp->name)) {
1822 delname = iq->dp->name;
1823 delnamelen = iq->dp->namelen;
1828 if(iq->qchase.qtype == LDNS_RR_TYPE_DS || iq->refetch_glue) {
1831 iq->refetch_glue = 0; /* if CNAME causes restart, no refetch */
1836 if(!auth_zone_delegpt(qstate, iq, delname, delnamelen))
1840 if(prime_stub(qstate, iq, id, delname, iq->qchase.qclass)) {
1846 return next_state(iq, INIT_REQUEST_3_STATE);
1856 * @param iq: iterator query state.
1861 processInitRequest3(struct module_qstate* qstate, struct iter_qstate* iq,
1868 iq->dnssec_expected = iter_indicates_dnssec(qstate->env, iq->dp,
1869 iq->deleg_msg, iq->qchase.qclass);
1873 if(!(qstate->query_flags & BIT_RD) && iq->deleg_msg) {
1874 iq->response = iq->deleg_msg;
1875 if(verbosity >= VERB_ALGO && iq->response)
1877 &iq->response->qinfo, iq->response->rep);
1880 return final_state(iq);
1884 iq->chase_flags &= ~BIT_RD;
1887 if(iq->dnssec_expected && qstate->env->cfg->prefetch_key &&
1889 generate_dnskey_prefetch(qstate, iq, id);
1896 return next_state(iq, QUERYTARGETS_STATE);
1905 * @param iq: iterator query state.
1915 struct iter_qstate* iq, int id, uint8_t* name, size_t namelen,
1920 id, iq, INIT_REQUEST_STATE, FINISHED_STATE, &subq, 0, 0))
1928 if(dname_subdomain_c(name, iq->dp->name)) {
1929 subiq->dp = delegpt_copy(iq->dp, subq->region);
1958 * @param iq: iterator query state.
1967 generate_target_query(struct module_qstate* qstate, struct iter_qstate* iq,
1972 id, iq, INIT_REQUEST_STATE, FINISHED_STATE, &subq, 0, 0))
1983 * @param iq: iterator query state.
1994 query_for_targets(struct module_qstate* qstate, struct iter_qstate* iq,
2002 iter_mark_cycle_targets(qstate, iq->dp);
2003 missing = (int)delegpt_count_missing_targets(iq->dp, NULL);
2019 if(iq->depth == ie->max_dependency_depth)
2021 if(iq->depth > 0 && iq->target_count &&
2022 iq->target_count[TARGET_COUNT_QUERIES] > MAX_TARGET_COUNT) {
2027 iq->target_count[TARGET_COUNT_QUERIES]);
2030 if(iq->dp_target_count > MAX_DP_TARGET_COUNT) {
2035 s, iq->dp_target_count);
2043 for(ns = iq->dp->nslist; ns; ns = ns->next) {
2059 if(!generate_target_query(qstate, iq, id,
2061 LDNS_RR_TYPE_AAAA, iq->qchase.qclass)) {
2089 if(!generate_target_query(qstate, iq, id,
2091 LDNS_RR_TYPE_A, iq->qchase.qclass)) {
2128 * @param iq: iterator query state.
2135 processLastResort(struct module_qstate* qstate, struct iter_qstate* iq,
2141 log_assert(iq->dp);
2143 if(!can_have_last_resort(qstate->env, iq->dp->name, iq->dp->namelen,
2144 iq->qchase.qclass, NULL, NULL, NULL)) {
2148 errinf_dname(qstate, "at zone", iq->dp->name);
2149 errinf_reply(qstate, iq);
2153 if(!iq->dp->has_parent_side_NS && dname_is_root(iq->dp->name)) {
2157 iq->qchase.qclass, nolock);
2160 iq->chase_flags &= ~BIT_RD; /* go to authorities */
2162 (void)delegpt_add_ns(iq->dp, qstate->region,
2167 (void)delegpt_add_addr(iq->dp, qstate->region,
2173 iq->dp->has_parent_side_NS = 1;
2174 } else if(!iq->dp->has_parent_side_NS) {
2175 if(!iter_lookup_parent_NS_from_cache(qstate->env, iq->dp,
2177 || !iq->dp->has_parent_side_NS) {
2181 iq->store_parent_NS = iq->dp;
2182 iq->chase_flags &= ~BIT_RD; /* go to authorities */
2183 iq->deleg_msg = NULL;
2184 iq->refetch_glue = 1;
2185 iq->query_restart_count++;
2186 iq->sent_count = 0;
2187 iq->dp_target_count = 0;
2189 iq->minimisation_state = INIT_MINIMISE_STATE;
2190 return next_state(iq, INIT_REQUEST_STATE);
2194 if(!cache_fill_missing(qstate->env, iq->qchase.qclass,
2195 qstate->region, iq->dp))
2197 if(iq->dp->usable_list) {
2199 return next_state(iq, QUERYTARGETS_STATE);
2202 if(iter_lookup_parent_glue_from_cache(qstate->env, iq->dp,
2206 return next_state(iq, QUERYTARGETS_STATE);
2209 if(delegpt_count_missing_targets(iq->dp, NULL) > 0) {
2212 if((ret=query_for_targets(qstate, iq, ie, id, 1, &qs))!=0) {
2214 errinf_dname(qstate, "at zone", iq->dp->name);
2219 iq->num_target_queries += qs;
2220 target_count_increase(iq, qs);
2226 if(iq->depth == ie->max_dependency_depth) {
2231 if(iq->depth > 0 && iq->target_count &&
2232 iq->target_count[TARGET_COUNT_QUERIES] > MAX_TARGET_COUNT) {
2237 iq->target_count[TARGET_COUNT_QUERIES]);
2242 iter_mark_pside_cycle_targets(qstate, iq->dp);
2245 for(ns = iq->dp->nslist; ns; ns = ns->next) {
2251 iq->qchase.qclass, NULL, NULL, NULL)) {
2254 ns->name, LDNS_RR_TYPE_NS, iq->qchase.qclass);
2262 if(!generate_parentside_target_query(qstate, iq, id,
2264 LDNS_RR_TYPE_AAAA, iq->qchase.qclass)) {
2275 iq->num_target_queries += query_count;
2276 target_count_increase(iq, query_count);
2283 if(!generate_parentside_target_query(qstate, iq, id,
2285 LDNS_RR_TYPE_A, iq->qchase.qclass)) {
2295 iq->num_target_queries += query_count;
2296 target_count_increase(iq, query_count);
2304 if(!qstate->no_cache_store && iq->query_for_pside_glue
2305 && !iq->pside_glue)
2307 iq->deleg_msg?iq->deleg_msg->rep:
2308 (iq->response?iq->response->rep:NULL));
2311 errinf_dname(qstate, "at zone", iq->dp->name);
2312 errinf_reply(qstate, iq);
2327 * @param iq: iterator query state.
2334 processDSNSFind(struct module_qstate* qstate, struct iter_qstate* iq, int id)
2339 if(!iq->dsns_point) {
2341 iq->dsns_point = iq->qchase.qname;
2342 iq->dsns_point_len = iq->qchase.qname_len;
2345 if(!dname_subdomain_c(iq->dsns_point, iq->dp->name)) {
2346 errinf_dname(qstate, "for DS query parent-child nameserver search the query is not under the zone", iq->dp->name);
2351 dname_remove_label(&iq->dsns_point, &iq->dsns_point_len);
2352 if(query_dname_compare(iq->dsns_point, iq->dp->name) == 0) {
2356 iq->state = QUERYTARGETS_STATE;
2359 iq->state = DSNS_FIND_STATE;
2363 iq->dsns_point, LDNS_RR_TYPE_NS, iq->qchase.qclass);
2364 if(!generate_sub_request(iq->dsns_point, iq->dsns_point_len,
2365 LDNS_RR_TYPE_NS, iq->qchase.qclass, qstate, id, iq,
2367 errinf_dname(qstate, "for DS query parent-child nameserver search, could not generate NS lookup for", iq->dsns_point);
2379 check_waiting_queries(struct iter_qstate* iq, struct module_qstate* qstate,
2382 if(iq->num_target_queries>0 && iq->num_current_queries>0) {
2385 "respond", iq->num_target_queries,
2386 iq->num_current_queries);
2388 } else if(iq->num_target_queries>0) {
2390 "resolve", iq->num_target_queries);
2395 iq->num_current_queries);
2409 * @param iq: iterator query state.
2417 processQueryTargets(struct module_qstate* qstate, struct iter_qstate* iq,
2438 "currentqueries %d sentcount %d", iq->num_target_queries,
2439 iq->num_current_queries, iq->sent_count);
2442 if(iq->referral_count > MAX_REFERRAL_COUNT) {
2444 "number of referrrals with %d", iq->referral_count);
2448 if(iq->sent_count > ie->max_sent_count) {
2450 "number of sends with %d", iq->sent_count);
2456 if(iq->target_count && !*iq->nxns_dp &&
2457 iq->target_count[TARGET_COUNT_NX] > MAX_TARGET_NX) {
2460 if(iq->num_target_queries>0 || iq->num_current_queries>0) {
2461 check_waiting_queries(iq, qstate, id);
2466 MAX_TARGET_NX, iq->target_count[TARGET_COUNT_NX]);
2468 if(!iq->dp) {
2477 if(iq->dp->has_parent_side_NS) {
2488 for(ns=iq->dp->nslist; ns; ns=ns->next) {
2494 *iq->nxns_dp = malloc(iq->dp->namelen);
2495 if(!*iq->nxns_dp) {
2502 memcpy(*iq->nxns_dp, iq->dp->name, iq->dp->namelen);
2503 } else if(iq->target_count && *iq->nxns_dp) {
2506 if(iq->num_target_queries>0 || iq->num_current_queries>0) {
2507 check_waiting_queries(iq, qstate, id);
2511 if(!iq->dp) {
2519 if(iq->target_count[TARGET_COUNT_NX] > MAX_TARGET_NX_FALLBACK) {
2523 iq->target_count[TARGET_COUNT_NX]);
2528 if(!iq->dp->has_parent_side_NS) {
2530 if(!dname_canonical_compare(*iq->nxns_dp, iq->dp->name)) {
2534 for(ns=iq->dp->nslist; ns; ns=ns->next) {
2543 if(!iq->dp) {
2549 delegpt_no_ipv6(iq->dp);
2551 delegpt_no_ipv4(iq->dp);
2552 delegpt_log(VERB_ALGO, iq->dp);
2554 if(iq->num_current_queries>0) {
2563 if(iq->minimisation_state == INIT_MINIMISE_STATE
2564 && !(iq->chase_flags & BIT_RD)) {
2569 if(!(iq->qinfo_out.qname_len
2570 && dname_subdomain_c(iq->qchase.qname,
2571 iq->qinfo_out.qname)
2572 && dname_subdomain_c(iq->qinfo_out.qname,
2573 iq->dp->name))) {
2574 iq->qinfo_out.qname = iq->dp->name;
2575 iq->qinfo_out.qname_len = iq->dp->namelen;
2576 iq->qinfo_out.qtype = LDNS_RR_TYPE_A;
2577 iq->qinfo_out.qclass = iq->qchase.qclass;
2578 iq->qinfo_out.local_alias = NULL;
2579 iq->minimise_count = 0;
2582 iq->minimisation_state = MINIMISE_STATE;
2584 if(iq->minimisation_state == MINIMISE_STATE) {
2585 int qchaselabs = dname_count_labels(iq->qchase.qname);
2587 dname_count_labels(iq->qinfo_out.qname);
2589 qout_orig = iq->qinfo_out.qname;
2590 qout_orig_len = iq->qinfo_out.qname_len;
2591 iq->qinfo_out.qname = iq->qchase.qname;
2592 iq->qinfo_out.qname_len = iq->qchase.qname_len;
2593 iq->minimise_count++;
2594 iq->timeout_count = 0;
2596 iter_dec_attempts(iq->dp, 1, ie->outbound_msg_retry);
2603 iq->minimise_count > MINIMISE_ONE_LAB) {
2604 if(iq->minimise_count < MAX_MINIMISE_COUNT) {
2610 if (MAX_MINIMISE_COUNT - iq->minimise_count >=
2629 dname_remove_labels(&iq->qinfo_out.qname,
2630 &iq->qinfo_out.qname_len,
2634 && (iq->qchase.qtype == LDNS_RR_TYPE_DS
2635 || iq->qchase.qtype == LDNS_RR_TYPE_A)))
2637 iq->minimisation_state = DONOT_MINIMISE_STATE;
2640 iq->qinfo_out.qname, iq->qinfo_out.qname_len,
2641 iq->qinfo_out.qtype, iq->qinfo_out.qclass,
2643 qstate->env->scratch, 0, iq->dp->name,
2644 iq->dp->namelen);
2655 iq->response = msg;
2656 return final_state(iq);
2661 iq->qinfo_out.qname,
2662 iq->qinfo_out.qname_len,
2663 iq->qinfo_out.qtype,
2664 iq->qinfo_out.qclass,
2665 qstate, id, iq,
2682 if(iq->minimisation_state == SKIP_MINIMISE_STATE) {
2683 if(iq->timeout_count < MAX_MINIMISE_TIMEOUT_COUNT)
2686 iq->minimisation_state = MINIMISE_STATE;
2690 iq->minimisation_state = DONOT_MINIMISE_STATE;
2692 if(iq->minimisation_state == DONOT_MINIMISE_STATE)
2693 iq->qinfo_out = iq->qchase;
2699 if(!iq->auth_zone_avoid && qstate->blacklist) {
2701 iq->dp->name, iq->dp->namelen, iq->qinfo_out.qclass)) {
2705 iq->auth_zone_avoid = 1;
2708 if(iq->auth_zone_avoid) {
2709 iq->auth_zone_avoid = 0;
2711 } else if(auth_zones_lookup(qstate->env->auth_zones, &iq->qinfo_out,
2712 qstate->region, &iq->response, &auth_fallback, iq->dp->name,
2713 iq->dp->namelen)) {
2717 &iq->response->qinfo, iq->response->rep);
2719 if((iq->chase_flags&BIT_RD) && !(iq->response->rep->flags&BIT_AA)) {
2725 iq->num_current_queries++;
2726 iq->chase_to_rd = 0;
2727 iq->dnssec_lame_query = 0;
2728 iq->auth_zone_response = 1;
2729 return next_state(iq, QUERY_RESP_STATE);
2732 iq->auth_zone_response = 0;
2741 if(iq->dp->auth_dp) {
2744 iq->auth_zone_avoid = 1;
2745 return next_state(iq, INIT_REQUEST_STATE);
2754 if(iq->depth < ie->max_dependency_depth
2755 && iq->num_target_queries == 0
2756 && (!iq->target_count || iq->target_count[TARGET_COUNT_NX]==0)
2757 && iq->sent_count < TARGET_FETCH_STOP) {
2763 tf_policy = ie->target_fetch_policy[iq->depth];
2767 if(iq->caps_fallback) {
2770 if((ret=query_for_targets(qstate, iq, ie, id, -1, &extra))!=0) {
2776 iq->num_target_queries += extra;
2777 target_count_increase(iq, extra);
2778 if(iq->num_target_queries > 0) {
2784 if(qout_orig && iq->minimise_count > 0) {
2785 iq->minimise_count--;
2786 iq->qinfo_out.qname = qout_orig;
2787 iq->qinfo_out.qname_len = qout_orig_len;
2792 delegpt_count_addr(iq->dp, &naddr, &nres, &navail);
2796 if(iq->caps_server+1 >= naddr*3 ||
2797 iq->caps_server*2+2 >= (size_t)ie->max_sent_count) {
2802 (int)iq->caps_server+1, (int)naddr*3);
2803 iq->response = iq->caps_response;
2804 iq->caps_fallback = 0;
2805 iter_dec_attempts(iq->dp, 3, ie->outbound_msg_retry); /* space for fallback */
2806 iq->num_current_queries++; /* RespState decrements it*/
2807 iq->referral_count++; /* make sure we don't loop */
2808 iq->sent_count = 0;
2809 iq->dp_target_count = 0;
2810 iq->state = QUERY_RESP_STATE;
2814 (int)iq->caps_server);
2824 (void)query_for_targets(qstate, iq, ie, id, tf_policy, &extra);
2827 iq->num_target_queries += extra;
2828 target_count_increase(iq, extra);
2832 delegpt_add_unused_targets(iq->dp);
2839 struct dns_msg* forged_response = rpz_callback_from_iterator_module(qstate, iq);
2842 forged_response->rep, iq->qchase.qname,
2843 iq->qchase.qname_len, LDNS_RR_TYPE_CNAME,
2844 iq->qchase.qclass) &&
2845 iq->qchase.qtype != LDNS_RR_TYPE_CNAME &&
2848 if(!handle_cname_response(qstate, iq, forged_response,
2853 iq->qchase.qname = sname;
2854 iq->qchase.qname_len = snamelen;
2856 rpz_callback_from_iterator_cname(qstate, iq);
2861 iq->deleg_msg = NULL;
2862 iq->dp = NULL;
2863 iq->dsns_point = NULL;
2864 iq->auth_zone_response = 0;
2865 iq->refetch_glue = 0;
2866 iq->query_restart_count++;
2867 iq->sent_count = 0;
2868 iq->dp_target_count = 0;
2870 iq->minimisation_state = INIT_MINIMISE_STATE;
2871 outbound_list_clear(&iq->outlist);
2872 iq->num_current_queries = 0;
2876 iq->num_target_queries = 0;
2877 return next_state(iq, INIT_REQUEST_STATE);
2884 iq->response = forged_response;
2885 next_state(iq, FINISHED_STATE);
2886 if(!iter_prepend(iq, qstate->return_msg, qstate->region)) {
2895 target = iter_server_selection(ie, qstate->env, iq->dp,
2896 iq->dp->name, iq->dp->namelen, iq->qchase.qtype,
2897 &iq->dnssec_lame_query, &iq->chase_to_rd,
2898 iq->num_target_queries, qstate->blacklist,
2912 if(iq->num_target_queries==0 && iq->num_current_queries==0) {
2916 if(delegpt_count_missing_targets(iq->dp, NULL) > 0) {
2920 if((ret=query_for_targets(qstate, iq, ie, id,
2923 errinf_dname(qstate, "at zone", iq->dp->name);
2931 delegpt_count_missing_targets(iq->dp, NULL) == 0){
2946 errinf_dname(qstate, "at zone", iq->dp->name);
2950 iq->num_target_queries += qs;
2951 target_count_increase(iq, qs);
2955 if(iq->num_target_queries == 0) {
2959 if(iq->caps_fallback && iq->caps_reply) {
2964 (int)iq->caps_server+1);
2965 iq->response = iq->caps_response;
2966 iq->caps_fallback = 0;
2967 iter_dec_attempts(iq->dp, 3, ie->outbound_msg_retry); /* space for fallback */
2968 iq->num_current_queries++; /* RespState decrements it*/
2969 iq->referral_count++; /* make sure we don't loop */
2970 iq->sent_count = 0;
2971 iq->dp_target_count = 0;
2972 iq->state = QUERY_RESP_STATE;
2975 return processLastResort(qstate, iq, ie, id);
2982 check_waiting_queries(iq, qstate, id);
2985 if(qout_orig && iq->minimise_count > 0) {
2986 iq->minimise_count--;
2987 iq->qinfo_out.qname = qout_orig;
2988 iq->qinfo_out.qname_len = qout_orig_len;
2998 if(can_do_promisc && tf_policy == 0 && iq->depth == 0
2999 && iq->depth < ie->max_dependency_depth
3000 && ie->target_fetch_policy[iq->depth] != 0
3001 && iq->dp_target_count == 0
3006 (void)query_for_targets(qstate, iq, ie, id, 1, &extra);
3010 iq->num_target_queries += extra;
3011 target_count_increase(iq, extra);
3012 check_waiting_queries(iq, qstate, id);
3015 if(qout_orig && iq->minimise_count > 0) {
3016 iq->minimise_count--;
3017 iq->qinfo_out.qname = qout_orig;
3018 iq->qinfo_out.qname_len = qout_orig_len;
3024 target_count_increase_global_quota(iq, 1);
3025 if(iq->target_count && iq->target_count[TARGET_COUNT_GLOBAL_QUOTA]
3031 iq->target_count[TARGET_COUNT_GLOBAL_QUOTA]);
3037 sq_check_ratelimit = (!(iq->chase_flags & BIT_RD) && !iq->ratelimit_ok);
3040 log_query_info(VERB_QUERY, "sending query:", &iq->qinfo_out);
3041 log_name_addr(VERB_QUERY, "sending to target:", iq->dp->name,
3044 iq->dnssec_expected?"expected": "not expected",
3045 iq->dnssec_lame_query?" but lame_query anyway": "");
3056 iq->dp->name, &real_addr, real_addrlen);
3060 outq = (*qstate->env->send_query)(&iq->qinfo_out,
3061 iq->chase_flags | (iq->chase_to_rd?BIT_RD:0),
3066 ((iq->chase_to_rd||(iq->chase_flags&BIT_RD)!=0)&&
3068 &iq->qinfo_out)||target->attempts==1)?0:BIT_CD),
3069 iq->dnssec_expected, iq->caps_fallback || is_caps_whitelisted(
3070 ie, iq), sq_check_ratelimit, &real_addr, real_addrlen,
3071 iq->dp->name, iq->dp->namelen,
3072 (iq->dp->tcp_upstream || qstate->env->cfg->tcp_upstream),
3073 (iq->dp->ssl_upstream || qstate->env->cfg->ssl_upstream),
3083 iq->dp->name);
3089 iq->minimisation_state = SKIP_MINIMISE_STATE;
3090 return next_state(iq, QUERYTARGETS_STATE);
3092 outbound_list_insert(&iq->outlist, outq);
3093 iq->num_current_queries++;
3094 iq->sent_count++;
3120 * @param iq: iterator query state.
3128 processQueryResponse(struct module_qstate* qstate, struct iter_qstate* iq,
3134 iq->num_current_queries--;
3136 if(!inplace_cb_query_response_call(qstate->env, qstate, iq->response))
3139 if(iq->response == NULL) {
3142 iq->minimisation_state = SKIP_MINIMISE_STATE;
3144 iq->timeout_count++;
3145 iq->chase_to_rd = 0;
3146 iq->dnssec_lame_query = 0;
3148 return next_state(iq, QUERYTARGETS_STATE);
3150 iq->timeout_count = 0;
3151 orig_empty_nodata_found = iq->empty_nodata_found;
3153 (int)((iq->chase_flags&BIT_RD) || iq->chase_to_rd),
3154 iq->response, &iq->qinfo_out, iq->dp, &iq->empty_nodata_found);
3155 iq->chase_to_rd = 0;
3157 iq->response->rep->flags &= ~BIT_TC;
3158 if(orig_empty_nodata_found != iq->empty_nodata_found &&
3159 iq->empty_nodata_found < EMPTY_NODATA_RETRY_COUNT) {
3163 iq->dp, &qstate->reply->remote_addr,
3168 return next_state(iq, QUERYTARGETS_STATE);
3170 if(type == RESPONSE_TYPE_REFERRAL && (iq->chase_flags&BIT_RD) &&
3171 !iq->auth_zone_response) {
3176 if(!qstate->env->cfg->disable_dnssec_lame_check && iq->dnssec_expected
3177 && !iq->dnssec_lame_query &&
3178 !(iq->chase_flags&BIT_RD)
3179 && iq->sent_count < DNSSEC_LAME_DETECT_COUNT
3186 if(!iter_msg_has_dnssec(iq->response)) {
3193 iq->dp, &qstate->reply->remote_addr,
3200 if(!iter_msg_from_zone(iq->response, iq->dp, type,
3201 iq->qchase.qclass))
3206 } else iq->dnssec_lame_query = 0;
3210 iq->response->rep, iq->response->rep->an_numrrsets,
3211 iq->response->rep->an_numrrsets
3212 + iq->response->rep->ns_numrrsets);
3213 if(!ns) ns = find_NS(iq->response->rep, 0,
3214 iq->response->rep->an_numrrsets);
3215 if(!ns || !dname_strict_subdomain_c(ns->rk.dname, iq->dp->name)
3216 || !dname_subdomain_c(iq->qchase.qname, ns->rk.dname)){
3220 iter_scrub_ds(iq->response, ns, iq->dp->name);
3221 } else iter_scrub_ds(iq->response, NULL, NULL);
3223 FLAGS_GET_RCODE(iq->response->rep->flags) == LDNS_RCODE_YXDOMAIN) {
3229 if(type == RESPONSE_TYPE_CNAME && iq->response->rep->an_numrrsets >= 1
3230 && ntohs(iq->response->rep->rrsets[0]->rk.type) == LDNS_RR_TYPE_DNAME) {
3233 get_cname_target(iq->response->rep->rrsets[0], &sname,
3235 if(snamelen && dname_subdomain_c(sname, iq->response->rep->rrsets[0]->rk.dname)) {
3241 iq->qchase.qtype == LDNS_RR_TYPE_CNAME &&
3242 iq->minimisation_state == MINIMISE_STATE &&
3243 query_dname_compare(iq->qchase.qname, iq->qinfo_out.qname) == 0) {
3257 FLAGS_GET_RCODE(iq->response->rep->flags)
3259 (iq->response->rep->an_numrrsets?"ANSWER":
3264 if(iq->qchase.qtype == LDNS_RR_TYPE_DS && !iq->dsns_point
3265 && !(iq->chase_flags&BIT_RD)
3266 && iter_ds_toolow(iq->response, iq->dp)
3267 && iter_dp_cangodown(&iq->qchase, iq->dp)) {
3269 outbound_list_clear(&iq->outlist);
3270 iq->num_current_queries = 0;
3274 iq->num_target_queries = 0;
3275 return processDSNSFind(qstate, iq, id);
3278 iter_dns_store(qstate->env, &iq->response->qinfo,
3279 iq->response->rep,
3280 iq->qchase.qtype != iq->response->qinfo.qtype,
3282 iq->dp&&iq->dp->has_parent_side_NS,
3286 outbound_list_clear(&iq->outlist);
3287 iq->num_current_queries = 0;
3291 iq->num_target_queries = 0;
3296 if(iq->minimisation_state != DONOT_MINIMISE_STATE
3297 && !(iq->chase_flags & BIT_RD)) {
3298 if(FLAGS_GET_RCODE(iq->response->rep->flags) !=
3301 if(FLAGS_GET_RCODE(iq->response->rep->flags) ==
3303 iter_scrub_nxdomain(iq->response);
3304 return final_state(iq);
3312 iq->minimisation_state = DONOT_MINIMISE_STATE;
3314 if(FLAGS_GET_RCODE(iq->response->rep->flags) ==
3323 if(iq->dnssec_expected)
3324 return final_state(iq);
3333 &iq->response->qinfo);
3335 iq->response->qinfo.qname,
3336 iq->response->qinfo.qname_len,
3337 iq->response->qinfo.qtype,
3338 iq->response->qinfo.qclass,
3339 qstate, id, iq,
3347 return next_state(iq, QUERYTARGETS_STATE);
3349 return final_state(iq);
3366 reply_find_rrset_section_ns(iq->response->rep,
3367 iq->qchase.qname, iq->qchase.qname_len,
3368 LDNS_RR_TYPE_NS, iq->qchase.qclass)
3369 || reply_find_rrset_section_an(iq->response->rep,
3370 iq->qchase.qname, iq->qchase.qname_len,
3371 LDNS_RR_TYPE_NS, iq->qchase.qclass)
3376 iter_dns_store(qstate->env, &iq->response->qinfo,
3377 iq->response->rep, 1, 0, 0, NULL, 0,
3379 if(iq->store_parent_NS)
3381 iq->response->rep);
3384 iq->response->rep, iq->dp->name);
3387 if(!qstate->no_cache_store && iq->query_for_pside_glue
3388 && !iq->pside_glue) {
3389 iq->pside_glue = reply_find_rrset(iq->response->rep,
3390 iq->qchase.qname, iq->qchase.qname_len,
3391 iq->qchase.qtype, iq->qchase.qclass);
3392 if(iq->pside_glue) {
3394 "glue", iq->pside_glue);
3396 iq->pside_glue);
3402 iq->deleg_msg = iq->response;
3404 old_dp = iq->dp;
3405 iq->dp = delegpt_from_message(iq->response, qstate->region);
3407 iq->minimisation_state = INIT_MINIMISE_STATE;
3408 if(!iq->dp) {
3412 if(old_dp->namelabs + 1 < iq->dp->namelabs) {
3419 uint8_t* qname = iq->dp->name;
3420 size_t qnamelen = iq->dp->namelen;
3423 iq->qchase.qclass, *qstate->env->now,
3426 if(!cache_fill_missing(qstate->env, iq->qchase.qclass,
3427 qstate->region, iq->dp)) {
3431 if(iq->store_parent_NS && query_dname_compare(iq->dp->name,
3432 iq->store_parent_NS->name) == 0)
3433 iter_merge_retry_counts(iq->dp, iq->store_parent_NS,
3435 delegpt_log(VERB_ALGO, iq->dp);
3437 iq->referral_count++;
3438 iq->sent_count = 0;
3439 iq->dp_target_count = 0;
3442 iq->dnssec_expected = iter_indicates_dnssec(qstate->env,
3443 iq->dp, iq->response, iq->qchase.qclass);
3445 if(iq->dnssec_expected && qstate->env->cfg->prefetch_key &&
3447 generate_dnskey_prefetch(qstate, iq, id);
3454 generate_ns_check(qstate, iq, id);
3460 outbound_list_clear(&iq->outlist);
3461 iq->num_current_queries = 0;
3465 iq->num_target_queries = 0;
3466 iq->response = NULL;
3467 iq->fail_addr_type = 0;
3469 return next_state(iq, QUERYTARGETS_STATE);
3478 log_dns_msg("cname msg", &iq->response->qinfo,
3479 iq->response->rep);
3482 if(iq->qchase.qtype == LDNS_RR_TYPE_DS && !iq->dsns_point
3483 && !(iq->chase_flags&BIT_RD)
3484 && iter_ds_toolow(iq->response, iq->dp)
3485 && iter_dp_cangodown(&iq->qchase, iq->dp)) {
3486 outbound_list_clear(&iq->outlist);
3487 iq->num_current_queries = 0;
3491 iq->num_target_queries = 0;
3492 return processDSNSFind(qstate, iq, id);
3495 if(!handle_cname_response(qstate, iq, iq->response,
3505 iter_dns_store(qstate->env, &iq->response->qinfo,
3506 iq->response->rep, 1, qstate->prefetch_leeway,
3507 iq->dp&&iq->dp->has_parent_side_NS, NULL,
3510 iq->qchase.qname = sname;
3511 iq->qchase.qname_len = snamelen;
3515 rpz_callback_from_iterator_cname(qstate, iq);
3518 forged_response->rep, iq->qchase.qname,
3519 iq->qchase.qname_len, LDNS_RR_TYPE_CNAME,
3520 iq->qchase.qclass) &&
3521 iq->qchase.qtype != LDNS_RR_TYPE_CNAME &&
3524 if(!handle_cname_response(qstate, iq, forged_response,
3529 iq->qchase.qname = sname;
3530 iq->qchase.qname_len = snamelen;
3532 rpz_callback_from_iterator_cname(qstate, iq);
3538 iq->response = forged_response;
3539 next_state(iq, FINISHED_STATE);
3540 if(!iter_prepend(iq, qstate->return_msg, qstate->region)) {
3549 iq->deleg_msg = NULL;
3550 iq->dp = NULL;
3551 iq->dsns_point = NULL;
3552 iq->auth_zone_response = 0;
3553 iq->sent_count = 0;
3554 iq->dp_target_count = 0;
3555 if(iq->minimisation_state != MINIMISE_STATE)
3558 iq->query_restart_count++;
3560 iq->minimisation_state = INIT_MINIMISE_STATE;
3566 outbound_list_clear(&iq->outlist);
3567 iq->num_current_queries = 0;
3571 iq->num_target_queries = 0;
3578 return next_state(iq, INIT_REQUEST_STATE);
3583 if(!dname_subdomain_c(iq->qchase.qname, iq->dp->name)) {
3592 iq->dp->name, iq->dp->namelen,
3594 iq->qchase.qtype))
3601 if(!dname_subdomain_c(iq->qchase.qname, iq->dp->name)) {
3611 iq->dp->name, iq->dp->namelen,
3612 *qstate->env->now, 0, 1, iq->qchase.qtype))
3631 iq->minimisation_state = DONOT_MINIMISE_STATE;
3632 if(iq->auth_zone_response) {
3634 iq->auth_zone_response = 0;
3636 iq->dp->name, iq->dp->namelen, qstate->qinfo.qclass)) {
3640 "for auth zone", iq->dp->name);
3645 iq->auth_zone_avoid = 1;
3646 if(iq->dp->auth_dp) {
3649 iq->dp = NULL;
3650 return next_state(iq, INIT_REQUEST_STATE);
3653 return next_state(iq, QUERYTARGETS_STATE);
3721 struct iter_qstate* iq = (struct iter_qstate*)qstate->minfo[id];
3723 iq->response->rep->flags &= ~(BIT_RD|BIT_RA); /* ignore rec-lame */
3725 (int)((iq->chase_flags&BIT_RD) || iq->chase_to_rd),
3726 iq->response, &iq->qchase, iq->dp, NULL);
3729 qstate->return_msg = iq->response;
3748 qstate->qinfo.qclass, qstate, id, iq,
3752 generate_a_aaaa_check(qstate, iq, id);
3778 struct iter_qstate* iq = (struct iter_qstate*)qstate->minfo[id];
3807 /* if iq->query_for_pside_glue then add the pside_glue (marked lame) */
3808 if(iq->pside_glue) {
3813 iq->pside_glue);
3815 iq->pside_glue, 1, NULL))
3824 rrset = reply_find_answer_rrset(&iq->qchase, qstate->return_msg->rep);
3877 /* if the finished (iq->response) query has no NS set: continue
4015 struct iter_qstate* iq = (struct iter_qstate*)qstate->minfo[id];
4021 if(iq->qchase.qclass == 0) {
4023 iq->qchase.qclass = LDNS_RR_CLASS_ANY;
4031 c, qstate, id, iq, INIT_REQUEST_STATE,
4040 iq->num_current_queries ++;
4046 if(iq->num_current_queries == 0) {
4062 * @param iq: iterator query state.
4068 processFinished(struct module_qstate* qstate, struct iter_qstate* iq,
4075 if(!qstate->no_cache_store && iq->query_for_pside_glue
4076 && !iq->pside_glue)
4078 iq->deleg_msg?iq->deleg_msg->rep:
4079 (iq->response?iq->response->rep:NULL));
4080 if(!iq->response) {
4088 iq->response->rep->flags |= BIT_RA;
4092 iq->response->rep->flags &= ~BIT_AA;
4095 iq->response->rep->flags |= BIT_QR;
4098 iq->response->rep->reason_bogus_str = NULL;
4105 iq->response->rep->reason_bogus_str = err_str;
4116 if(iq->an_prepend_list || iq->ns_prepend_list) {
4117 if(!iter_prepend(iq, iq->response, qstate->region)) {
4122 iq->response->qinfo = qstate->qinfo;
4124 iq->response->rep->security = sec_status_unchecked;
4130 iq->response->rep, 0, qstate->prefetch_leeway,
4131 iq->dp&&iq->dp->has_parent_side_NS,
4137 qstate->return_msg = iq->response;
4176 * @param iq: iterator query state.
4180 iter_handle(struct module_qstate* qstate, struct iter_qstate* iq,
4186 iter_state_to_string(iq->state));
4187 switch(iq->state) {
4189 cont = processInitRequest(qstate, iq, ie, id);
4192 cont = processInitRequest2(qstate, iq, id);
4195 cont = processInitRequest3(qstate, iq, id);
4198 cont = processQueryTargets(qstate, iq, ie, id);
4201 cont = processQueryResponse(qstate, iq, ie, id);
4210 cont = processDSNSFind(qstate, iq, id);
4213 cont = processFinished(qstate, iq, id);
4217 iq->state);
4229 * @param iq: iterator query state.
4233 process_request(struct module_qstate* qstate, struct iter_qstate* iq,
4238 iq->state = INIT_REQUEST_STATE;
4239 iq->final_state = FINISHED_STATE;
4241 iter_handle(qstate, iq, ie, id);
4246 process_response(struct module_qstate* qstate, struct iter_qstate* iq,
4255 iq->response = NULL;
4256 iq->state = QUERY_RESP_STATE;
4258 if(event == module_event_noreply && iq->timeout_count >= 3 &&
4260 !iq->caps_fallback && !is_caps_whitelisted(ie, iq)) {
4262 iq->caps_fallback = 1;
4263 iq->caps_server = 0;
4264 iq->caps_reply = NULL;
4265 iq->caps_response = NULL;
4266 iq->caps_minimisation_state = DONOT_MINIMISE_STATE;
4267 iq->state = QUERYTARGETS_STATE;
4268 iq->num_current_queries--;
4271 iter_dec_attempts(iq->dp, 3, ie->outbound_msg_retry);
4280 outbound_list_remove(&iq->outlist, outbound);
4287 fill_fail_addr(iq, &qstate->reply->remote_addr,
4302 iq->parse_failures++;
4308 iq->parse_failures++;
4331 if(!scrub_message(pkt, prs, &iq->qinfo_out, iq->dp->name,
4334 if(event == module_event_capsfail && !iq->caps_fallback) {
4335 iq->caps_fallback = 1;
4336 iq->caps_server = 0;
4337 iq->caps_reply = NULL;
4338 iq->caps_response = NULL;
4339 iq->caps_minimisation_state = DONOT_MINIMISE_STATE;
4340 iq->state = QUERYTARGETS_STATE;
4341 iq->num_current_queries--;
4344 iq->scrub_failures++;
4349 iq->response = dns_alloc_msg(pkt, prs, qstate->region);
4350 if(!iq->response)
4353 log_name_addr(VERB_DETAIL, "reply from", iq->dp->name,
4356 log_dns_msg("incoming scrubbed packet:", &iq->response->qinfo,
4357 iq->response->rep);
4359 if(event == module_event_capsfail || iq->caps_fallback) {
4361 iq->minimisation_state != DONOT_MINIMISE_STATE) {
4364 iq->minimisation_state = SKIP_MINIMISE_STATE;
4368 caps_strip_reply(iq->response->rep);
4370 if(iq->caps_fallback &&
4371 iq->caps_minimisation_state != iq->minimisation_state) {
4374 iq->caps_fallback = 0;
4377 if(!iq->caps_fallback) {
4379 iq->caps_fallback = 1;
4380 iq->caps_server = 0;
4381 iq->caps_reply = iq->response->rep;
4382 iq->caps_response = iq->response;
4383 iq->caps_minimisation_state = iq->minimisation_state;
4384 iq->state = QUERYTARGETS_STATE;
4385 iq->num_current_queries--;
4390 if(!iq->caps_reply) {
4391 iq->caps_reply = iq->response->rep;
4392 iq->caps_response = iq->response;
4393 iq->caps_server = -1; /*become zero at ++,
4395 } else if(caps_failed_rcode(iq->caps_reply) &&
4396 !caps_failed_rcode(iq->response->rep)) {
4398 iq->caps_reply = iq->response->rep;
4399 iq->caps_response = iq->response;
4400 } else if(!caps_failed_rcode(iq->caps_reply) &&
4401 caps_failed_rcode(iq->response->rep)) {
4406 } else if(caps_failed_rcode(iq->caps_reply) &&
4407 caps_failed_rcode(iq->response->rep)) {
4410 } else if(!reply_equal(iq->response->rep, iq->caps_reply,
4414 outbound_list_remove(&iq->outlist, outbound);
4421 iq->caps_server++;
4422 iq->state = QUERYTARGETS_STATE;
4423 iq->num_current_queries--;
4429 iq->caps_fallback = 0; /* if we were in fallback, 0x20 is OK now */
4432 outbound_list_remove(&iq->outlist, outbound);
4433 iter_handle(qstate, iq, ie, id);
4441 struct iter_qstate* iq = (struct iter_qstate*)qstate->minfo[id];
4444 if(iq) log_query_info(VERB_QUERY, "iterator operate: query",
4446 if(iq && qstate->qinfo.qname != iq->qchase.qname)
4448 &iq->qchase);
4452 iq == NULL) {
4458 iq = (struct iter_qstate*)qstate->minfo[id];
4459 process_request(qstate, iq, ie, id);
4462 if(iq && event == module_event_pass) {
4463 iter_handle(qstate, iq, ie, id);
4466 if(iq && outbound) {
4467 process_response(qstate, iq, ie, id, outbound, event);
4485 struct iter_qstate* iq;
4488 iq = (struct iter_qstate*)qstate->minfo[id];
4489 if(iq) {
4490 outbound_list_clear(&iq->outlist);
4491 if(iq->target_count && --iq->target_count[TARGET_COUNT_REF] == 0) {
4492 free(iq->target_count);
4493 if(*iq->nxns_dp) free(*iq->nxns_dp);
4494 free(iq->nxns_dp);
4496 iq->num_current_queries = 0;