unbound: iterator/iterator.c File Reference

unbound 0.1

Functions | Variables
iterator.c File Reference

This file contains a module that performs recursive iterative DNS query processing. More...

`#include "config.h"`
`#include "iterator/iterator.h"`
`#include "iterator/iter_utils.h"`
`#include "iterator/iter_hints.h"`
`#include "iterator/iter_fwd.h"`
`#include "iterator/iter_donotq.h"`
`#include "iterator/iter_delegpt.h"`
`#include "iterator/iter_resptype.h"`
`#include "iterator/iter_scrub.h"`
`#include "iterator/iter_priv.h"`
`#include "validator/val_neg.h"`
`#include "services/cache/dns.h"`
`#include "services/cache/rrset.h"`
`#include "services/cache/infra.h"`
`#include "services/authzone.h"`
`#include "util/module.h"`
`#include "util/netevent.h"`
`#include "util/net_help.h"`
`#include "util/regional.h"`
`#include "util/data/dname.h"`
`#include "util/data/msgencode.h"`
`#include "util/fptr_wlist.h"`
`#include "util/config_file.h"`
`#include "util/random.h"`
`#include "sldns/rrdef.h"`
`#include "sldns/wire2str.h"`
`#include "sldns/str2wire.h"`
`#include "sldns/parseutil.h"`
`#include "sldns/sbuffer.h"`

## Functions
static void | target_count_increase_nx (struct iter_qstate *iq, int num)
int | iter_init (struct module_env *env, int id)
| iterator init
static void | caps_free (struct rbnode_type *n, void *ATTR_UNUSED(d))
| delete caps_whitelist element
void | iter_deinit (struct module_env *env, int id)
| iterator deinit
static int | iter_new (struct module_qstate *qstate, int id)
| new query for iterator
static int | next_state (struct iter_qstate *iq, enum iter_state nextstate)
| Transition to the next state.
static int | final_state (struct iter_qstate *iq)
| Transition an event to its final state.
static void | error_supers (struct module_qstate *qstate, int id, struct module_qstate *super)
| Callback routine to handle errors in parent query states.
static int | error_response (struct module_qstate *qstate, int id, int rcode)
| Return an error to the client.
static int | error_response_cache (struct module_qstate *qstate, int id, int rcode)
| Return an error to the client and cache the error code in the message cache (so per qname, qtype, qclass).
static int | prepend_is_duplicate (struct ub_packed_rrset_key **sets, size_t to, struct ub_packed_rrset_key *dup)
| check if prepend item is duplicate item
static int | iter_prepend (struct iter_qstate *iq, struct dns_msg *msg, struct regional *region)
| prepend the prepend list in the answer and authority section of dns_msg
static int | iter_find_rrset_in_prepend_answer (struct iter_qstate *iq, struct ub_packed_rrset_key *rrset)
| Find rrset in ANSWER prepend list.
static int | iter_add_prepend_answer (struct module_qstate *qstate, struct iter_qstate *iq, struct ub_packed_rrset_key *rrset)
| Add rrset to ANSWER prepend list.
static int | iter_add_prepend_auth (struct module_qstate *qstate, struct iter_qstate *iq, struct ub_packed_rrset_key *rrset)
| Add rrset to AUTHORITY prepend list.
static int | handle_cname_response (struct module_qstate *qstate, struct iter_qstate *iq, struct dns_msg *msg, uint8_t **mname, size_t *mname_len)
| Given a CNAME response (defined as a response containing a CNAME or DNAME that does not answer the request), process the response, modifying the state as necessary.
static void | fill_fail_addr (struct iter_qstate *iq, struct sockaddr_storage *addr, socklen_t addrlen)
| fill fail address for later recovery
static void | print_fail_addr (struct iter_qstate *iq, char *buf, size_t len)
| print fail addr to string
static void | errinf_reply (struct module_qstate *qstate, struct iter_qstate *iq)
| add response specific error information for log servfail
static int | can_have_last_resort (struct module_env *env, uint8_t *nm, size_t ATTR_UNUSED(nmlen), uint16_t qclass, int *have_dp, struct delegpt **retdp, struct regional *region)
| see if last resort is possible - does config allow queries to parent
static int | is_caps_whitelisted (struct iter_env *ie, struct iter_qstate *iq)
| see if target name is caps-for-id whitelisted
static void | target_count_create (struct iter_qstate *iq)
| Create target count structure for this query.
static void | target_count_increase (struct iter_qstate *iq, int num)
static void | target_count_increase_global_quota (struct iter_qstate *iq, int num)
static int | generate_sub_request (uint8_t *qname, size_t qnamelen, uint16_t qtype, uint16_t qclass, struct module_qstate *qstate, int id, struct iter_qstate *iq, enum iter_state initial_state, enum iter_state finalstate, struct module_qstate **subq_ret, int v, int detached)
| Generate a subrequest.
static int | prime_root (struct module_qstate *qstate, struct iter_qstate *iq, int id, uint16_t qclass)
| Generate and send a root priming request.
static int | prime_stub (struct module_qstate *qstate, struct iter_qstate *iq, int id, uint8_t *qname, uint16_t qclass)
| Generate and process a stub priming request.
static int | auth_zone_delegpt (struct module_qstate *qstate, struct iter_qstate *iq, uint8_t *delname, size_t delnamelen)
| Generate a delegation point for an auth zone (unless cached dp is better) false on alloc failure.
static void | generate_a_aaaa_check (struct module_qstate *qstate, struct iter_qstate *iq, int id)
| Generate A and AAAA checks for glue that is in-zone for the referral we just got to obtain authoritative information on the addresses.
static void | generate_ns_check (struct module_qstate *qstate, struct iter_qstate *iq, int id)
| Generate a NS check request to obtain authoritative information on an NS rrset.
static void | generate_dnskey_prefetch (struct module_qstate *qstate, struct iter_qstate *iq, int id)
| Generate a DNSKEY prefetch query to get the DNSKEY for the DS record we just got in a referral (where we have dnssec_expected, thus have trust anchors above it).
static int | forward_request (struct module_qstate *qstate, struct iter_qstate *iq)
| See if the query needs forwarding.
static int | processInitRequest (struct module_qstate *qstate, struct iter_qstate *iq, struct iter_env *ie, int id)
| Process the initial part of the request handling.
static int | processInitRequest2 (struct module_qstate *qstate, struct iter_qstate *iq, int id)
| Process the second part of the initial request handling.
static int | processInitRequest3 (struct module_qstate *qstate, struct iter_qstate *iq, int id)
| Process the third part of the initial request handling.
static int | generate_parentside_target_query (struct module_qstate *qstate, struct iter_qstate *iq, int id, uint8_t *name, size_t namelen, uint16_t qtype, uint16_t qclass)
| Given a basic query, generate a parent-side "target" query.
static int | generate_target_query (struct module_qstate *qstate, struct iter_qstate *iq, int id, uint8_t *name, size_t namelen, uint16_t qtype, uint16_t qclass)
| Given a basic query, generate a "target" query.
static int | query_for_targets (struct module_qstate *qstate, struct iter_qstate *iq, struct iter_env *ie, int id, int maxtargets, int *num)
| Given an event at a certain state, generate zero or more target queries for it's current delegation point.
static int | processLastResort (struct module_qstate *qstate, struct iter_qstate *iq, struct iter_env *ie, int id)
| Called by processQueryTargets when it would like extra targets to query but it seems to be out of options.
static int | processDSNSFind (struct module_qstate *qstate, struct iter_qstate *iq, int id)
| Try to find the NS record set that will resolve a qtype DS query.
static void | check_waiting_queries (struct iter_qstate *iq, struct module_qstate *qstate, int id)
| Check if we wait responses for sent queries and update the iterator's external state.
static int | processQueryTargets (struct module_qstate *qstate, struct iter_qstate *iq, struct iter_env *ie, int id)
| This is the request event state where the request will be sent to one of its current query targets.
static struct ub_packed_rrset_key * | find_NS (struct reply_info *rep, size_t from, size_t to)
| find NS rrset in given list
static int | processQueryResponse (struct module_qstate *qstate, struct iter_qstate *iq, struct iter_env *ie, int id)
| Process the query response.
static void | prime_supers (struct module_qstate *qstate, int id, struct module_qstate *forq)
| Return priming query results to interested super querystates.
static int | processPrimeResponse (struct module_qstate *qstate, int id)
| This handles the response to a priming query.
static void | processTargetResponse (struct module_qstate *qstate, int id, struct module_qstate *forq)
| Do final processing on responses to target queries.
static void | processDSNSResponse (struct module_qstate *qstate, int id, struct module_qstate *forq)
| Process response for DS NS Find queries, that attempt to find the delegation point where we ask the DS query from.
static void | processClassResponse (struct module_qstate *qstate, int id, struct module_qstate *forq)
| Process response for qclass=ANY queries for a particular class.
static int | processCollectClass (struct module_qstate *qstate, int id)
| Collect class ANY responses and make them into one response.
static int | processFinished (struct module_qstate *qstate, struct iter_qstate *iq, int id)
| This handles the final state for first-tier responses (i.e., responses to externally generated queries).
void | iter_inform_super (struct module_qstate *qstate, int id, struct module_qstate *super)
| Return priming query results to interested super querystates.
static void | iter_handle (struct module_qstate *qstate, struct iter_qstate *iq, struct iter_env *ie, int id)
| Handle iterator state.
static void | process_request (struct module_qstate *qstate, struct iter_qstate *iq, struct iter_env *ie, int id)
| This is the primary entry point for processing request events.
static void | process_response (struct module_qstate *qstate, struct iter_qstate *iq, struct iter_env *ie, int id, struct outbound_entry *outbound, enum module_ev event)
| process authoritative server reply
void | iter_operate (struct module_qstate *qstate, enum module_ev event, int id, struct outbound_entry *outbound)
| iterator operate on a query
void | iter_clear (struct module_qstate *qstate, int id)
| iterator cleanup query state
size_t | iter_get_mem (struct module_env *env, int id)
| iterator alloc size routine
struct module_func_block * | iter_get_funcblock (void)
| Get the iterator function block.
const char * | iter_state_to_string (enum iter_state state)
| Get iterator state as a string.
int | iter_state_is_responsestate (enum iter_state s)
| See if iterator state is a response state.

## Variables
int | UNKNOWN_SERVER_NICENESS = 376
| how nice is a server without further information, in msec Equals rtt initial timeout value.
int | USEFUL_SERVER_TOP_TIMEOUT = 120000
| maximum timeout before a host is deemed unsuitable, in msec.
int | BLACKLIST_PENALTY = (120000*4)
| penalty to validation failed blacklisted IPs Equals USEFUL_SERVER_TOP_TIMEOUT*4, and thus when RTT_MAX_TIMEOUT is overwritten by config infra_cache_max_rtt, it will be overwritten as well.
static struct module_func_block | iter_block
| The iterator function block.

## Detailed Description

This file contains a module that performs recursive iterative DNS query processing.

## Function Documentation

## ◆ next_state()

static int next_state | ( | struct iter_qstate * | iq,
|  | enum iter_state | nextstate )
| static

Transition to the next state.

This can be used to advance a currently processing event. It cannot be used to reactivate a forEvent.

Parameters

  iq | iterator query state
  nextstate | The state to transition to.

Returns
  true. This is so this can be called as the return value for the actual process*State() methods. (Transitioning to the next state implies further processing).

References iter_state_is_responsestate(), log_err(), iter_qstate::response, and iter_qstate::state.

Referenced by final_state(), processInitRequest(), processInitRequest2(), processInitRequest3(), processLastResort(), processQueryResponse(), processQueryTargets(), and respip_operate().

## ◆ final_state()

static int final_state | ( | struct iter_qstate * | iq | ) |
| static

Transition an event to its final state.

Final states always either return a result up the module chain, or reactivate a dependent event. Which final state to transition to is set in the module state for the event when it was created, and depends on the original purpose of the event.

The response is stored in the qstate->buf buffer.

Parameters

  iq | iterator query state

Returns
  false. This is so this method can be used as the return value for the processState methods. (Transitioning to the final state

References iter_qstate::final_state, and next_state().

Referenced by processInitRequest(), processInitRequest3(), processQueryResponse(), and processQueryTargets().

## ◆ error_supers()

static void error_supers | ( | struct module_qstate * | qstate,
|  | int | id,
|  | struct module_qstate * | super )
| static

Callback routine to handle errors in parent query states.

Parameters

  qstate | query state that failed.
  id | module id.
  super | super state.

References cache_fill_missing(), delegpt_find_ns(), delegpt_mark_neg(), iter_qstate::dp, module_qstate::env, delegpt_ns::got4, delegpt_ns::got6, LDNS_RR_TYPE_A, LDNS_RR_TYPE_AAAA, LDNS_RR_TYPE_NS, log_err(), log_query_info(), module_qstate::minfo, module_env::modinfo, iter_qstate::num_target_queries, iter_qstate::qchase, query_info::qclass, module_qstate::qinfo, query_info::qname, query_info::qname_len, query_info::qtype, QUERYTARGETS_STATE, module_qstate::region, delegpt_ns::resolved, iter_qstate::state, iter_env::supports_ipv4, iter_env::supports_ipv6, iter_env::use_nat64, VERB_ALGO, and verbose().

Referenced by iter_inform_super().

## ◆ error_response()

static int error_response | ( | struct module_qstate * | qstate,
|  | int | id,
|  | int | rcode )
| static

Return an error to the client.

Parameters

  qstate | our query state
  id | module id
  rcode | error code (DNS errcode).

Returns
  : 0 for use by caller, to make notation easy, like: return error_response(..).

References module_qstate::ext_state, module_finished, delegpt_ns::name, module_qstate::return_msg, module_qstate::return_rcode, sldns_rcodes, VERB_QUERY, and verbose().

Referenced by error_response_cache(), iter_operate(), prime_stub(), process_response(), processCollectClass(), processFinished(), processInitRequest(), processInitRequest2(), processLastResort(), processQueryResponse(), and processQueryTargets().

## ◆ error_response_cache()

static int error_response_cache | ( | struct module_qstate * | qstate,
|  | int | id,
|  | int | rcode )
| static

Return an error to the client and cache the error code in the message cache (so per qname, qtype, qclass).

Parameters

  qstate | our query state
  id | module id
  rcode | error code (DNS errcode).

Returns
  : 0 for use by caller, to make notation easy, like: return error_response(..).

References BIT_QR, BIT_RA, module_env::cfg, lruhash_entry::data, dns_cache_prefetch_adjust(), msgreply_entry::entry, module_qstate::env, error_response(), reply_info::flags, FLAGS_GET_RCODE, FLAGS_SET_RCODE, iter_dns_store(), lruhash_entry::lock, msg_cache_lookup(), module_qstate::no_cache_store, NORR_TTL, module_env::now, module_qstate::prefetch_leeway, reply_info::prefetch_ttl, PREFETCH_TTL_CALC, query_info::qclass, reply_info::qdcount, module_qstate::qinfo, query_info::qname, query_info::qname_len, module_qstate::qstarttime, query_info::qtype, module_qstate::query_flags, sec_status_indeterminate, reply_info::security, config_file::serve_expired, config_file::serve_expired_ttl, reply_info::serve_expired_ttl, config_file::serve_expired_ttl_reset, reply_info::ttl, VERB_ALGO, and verbose().

Referenced by process_response(), processCollectClass(), processDSNSFind(), processInitRequest(), processLastResort(), processQueryResponse(), and processQueryTargets().

## ◆ iter_find_rrset_in_prepend_answer()

static int iter_find_rrset_in_prepend_answer | ( | struct iter_qstate * | iq,
|  | struct ub_packed_rrset_key * | rrset )
| static

Find rrset in ANSWER prepend list.

to avoid duplicate DNAMEs when a DNAME is traversed twice.

Parameters

  iq | iterator query state.
  rrset | rrset to add.

Returns
  false if not found

References iter_qstate::an_prepend_list, lruhash_entry::data, ub_packed_rrset_key::entry, iter_prep_list::next, iter_prep_list::rrset, rrsetdata_equal(), and ub_rrset_compare().

Referenced by handle_cname_response().

## ◆ iter_add_prepend_answer()

static int iter_add_prepend_answer | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | struct ub_packed_rrset_key * | rrset )
| static

Add rrset to ANSWER prepend list.

Parameters

  qstate | query state.
  iq | iterator query state.
  rrset | rrset to add.

Returns
  false on failure (malloc).

References iter_qstate::an_prepend_last, iter_qstate::an_prepend_list, iter_prep_list::next, module_qstate::region, regional_alloc(), and iter_prep_list::rrset.

Referenced by handle_cname_response().

## ◆ iter_add_prepend_auth()

static int iter_add_prepend_auth | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | struct ub_packed_rrset_key * | rrset )
| static

Add rrset to AUTHORITY prepend list.

Parameters

  qstate | query state.
  iq | iterator query state.
  rrset | rrset to add.

Returns
  false on failure (malloc).

References iter_prep_list::next, iter_qstate::ns_prepend_last, iter_qstate::ns_prepend_list, module_qstate::region, regional_alloc(), and iter_prep_list::rrset.

Referenced by handle_cname_response().

## ◆ handle_cname_response()

static int handle_cname_response | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | struct dns_msg * | msg,
|  | uint8_t ** | mname,
|  | size_t * | mname_len )
| static

Given a CNAME response (defined as a response containing a CNAME or DNAME that does not answer the request), process the response, modifying the state as necessary.

This follows the CNAME/DNAME chain and returns the final query name.

sets the new query name, after following the CNAME/DNAME chain.

Parameters

  qstate | query state.
  iq | iterator query state.
  msg | the response.
  mname | returned target new query name.
  mname_len | length of mname.

Returns
  false on (malloc) error.

References reply_info::an_numrrsets, packed_rrset_key::dname, dname_strict_subdomain_c(), get_cname_target(), iter_add_prepend_answer(), iter_add_prepend_auth(), iter_find_rrset_in_prepend_answer(), LDNS_RR_TYPE_CNAME, LDNS_RR_TYPE_DNAME, reply_info::ns_numrrsets, iter_qstate::qchase, query_info::qname, query_info::qname_len, query_dname_compare(), dns_msg::rep, ub_packed_rrset_key::rk, reply_info::rrsets, and packed_rrset_key::type.

Referenced by processInitRequest(), processQueryResponse(), and processQueryTargets().

## ◆ target_count_create()

static void target_count_create | ( | struct iter_qstate * | iq | ) |
| static

Create target count structure for this query.

This is always explicitly created for the parent query.

References iter_qstate::nxns_dp, iter_qstate::target_count, TARGET_COUNT_MAX, and TARGET_COUNT_REF.

Referenced by generate_sub_request().

## ◆ generate_sub_request()

static int generate_sub_request | ( | uint8_t * | qname,
|  | size_t | qnamelen,
|  | uint16_t | qtype,
|  | uint16_t | qclass,
|  | struct module_qstate * | qstate,
|  | int | id,
|  | struct iter_qstate * | iq,
|  | enum iter_state | initial_state,
|  | enum iter_state | finalstate,
|  | struct module_qstate ** | subq_ret,
|  | int | v,
|  | int | detached )
| static

Generate a subrequest.

Generate a local request event. Local events are tied to this module, and have a corresponding (first tier) event that is waiting for this event to resolve to continue.

Parameters

  qname | The query name for this request.
  qnamelen | length of qname
  qtype | The query type for this request.
  qclass | The query class for this request.
  qstate | The event that is generating this event.
  id | module id.
  iq | The iterator state that is generating this event.
  initial_state | The initial response state (normally this is QUERY_RESP_STATE, unless it is known that the request won't need iterative processing
  finalstate | The final state for the response to this request.
  subq_ret | if newly allocated, the subquerystate, or NULL if it does not need initialisation.
  v | if true, validation is done on the subquery.
  detached | true if this qstate should not attach to the subquery

Returns
  false on error (malloc).

References module_env::add_sub, module_env::attach_sub, BIT_CD, BIT_RD, module_env::cfg, iter_qstate::chase_flags, module_qstate::curmod, iter_qstate::depth, DONOT_MINIMISE_STATE, iter_qstate::dp_target_count, module_qstate::env, module_qstate::ext_state, iter_qstate::final_state, fptr_ok, fptr_whitelist_modenv_add_sub(), fptr_whitelist_modenv_attach_sub(), fptr_whitelist_modenv_kill_sub(), INIT_MINIMISE_STATE, INIT_REQUEST_STATE, module_env::kill_sub, query_info::local_alias, log_err(), module_qstate::minfo, iter_qstate::minimisation_state, module_state_initial, iter_qstate::num_current_queries, iter_qstate::num_target_queries, iter_qstate::nxns_dp, outbound_list_init(), iter_qstate::outlist, PRIME_RESP_STATE, iter_qstate::qchase, query_info::qclass, module_qstate::qinfo, iter_qstate::qinfo_out, query_info::qname, query_info::qname_len, config_file::qname_minimisation, query_info::qtype, module_qstate::query_flags, iter_qstate::refetch_glue, module_qstate::region, regional_alloc(), iter_qstate::state, iter_qstate::target_count, target_count_create(), and TARGET_COUNT_REF.

Referenced by generate_a_aaaa_check(), generate_dnskey_prefetch(), generate_ns_check(), generate_parentside_target_query(), generate_target_query(), prime_root(), prime_stub(), processCollectClass(), processDSNSFind(), processPrimeResponse(), processQueryResponse(), and processQueryTargets().

## ◆ prime_root()

static int prime_root | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | int | id,
|  | uint16_t | qclass )
| static

Generate and send a root priming request.

Parameters

  qstate | the qtstate that triggered the need to prime.
  iq | iterator query state.
  id | module id.
  qclass | the class to prime.

Returns
  0 on failure

References delegpt_copy(), iter_qstate::dnssec_expected, iter_qstate::dp, module_qstate::env, module_qstate::ext_state, fptr_ok, fptr_whitelist_modenv_kill_sub(), generate_sub_request(), module_env::hints, hints_find_root(), iter_indicates_dnssec(), module_env::kill_sub, LDNS_RR_TYPE_NS, iter_hints::lock, log_err(), module_qstate::minfo, module_wait_subquery, iter_qstate::num_target_queries, PRIME_RESP_STATE, query_info::qclass, module_qstate::qinfo, QUERYTARGETS_STATE, module_qstate::region, sldns_rr_classes, VERB_ALGO, VERB_DETAIL, and verbose().

Referenced by processInitRequest().

## ◆ prime_stub()

static int prime_stub | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | int | id,
|  | uint8_t * | qname,
|  | uint16_t | qclass )
| static

Generate and process a stub priming request.

This method tests for the need to prime a stub zone, so it is safe to call for every request.

Parameters

  qstate | the qtstate that triggered the need to prime.
  iq | iterator query state.
  id | module id.
  qname | request name.
  qclass | request class.

Returns
  true if a priming subrequest was made, false if not. The will only issue a priming request if it detects an unprimed stub. Uses value of 2 to signal during stub-prime in root-prime situation that a noprime-stub is available and resolution can continue.

References delegpt::auth_dp, iter_qstate::auth_zone_avoid, delegpt_copy(), iter_qstate::dnssec_expected, iter_hints_stub::dp, iter_qstate::dp, module_qstate::env, errinf(), error_response(), module_qstate::ext_state, fptr_ok, fptr_whitelist_modenv_kill_sub(), generate_sub_request(), module_env::hints, hints_lookup_stub(), iter_indicates_dnssec(), module_env::kill_sub, LDNS_RR_TYPE_NS, iter_hints::lock, log_err(), log_nametypeclass(), module_qstate::minfo, module_wait_subquery, delegpt::name, delegpt::namelen, iter_hints_stub::noprime, iter_qstate::num_target_queries, PRIME_RESP_STATE, query_info::qclass, module_qstate::qinfo, query_dname_compare(), QUERYTARGETS_STATE, module_qstate::region, VERB_ALGO, VERB_DETAIL, verbose(), and iter_qstate::wait_priming_stub.

Referenced by processInitRequest(), and processInitRequest2().

## ◆ generate_a_aaaa_check()

static void generate_a_aaaa_check | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | int | id )
| static

Generate A and AAAA checks for glue that is in-zone for the referral we just got to obtain authoritative information on the addresses.

Parameters

  qstate | the qtstate that triggered the need to prime.
  iq | iterator query state.
  id | module id.

References reply_info::an_numrrsets, BIT_CD, BIT_RD, iter_qstate::depth, packed_rrset_key::dname, packed_rrset_key::dname_len, iter_qstate::dp, module_qstate::env, FINISHED_STATE, generate_sub_request(), INIT_REQUEST_STATE, LDNS_RR_TYPE_A, LDNS_RR_TYPE_AAAA, log_assert, log_nametypeclass(), iter_env::max_dependency_depth, module_env::modinfo, reply_info::ns_numrrsets, query_info::qclass, module_qstate::qinfo, query_info::qname, query_info::qtype, query_dname_compare(), module_qstate::query_flags, dns_msg::rep, iter_qstate::response, ub_packed_rrset_key::rk, packed_rrset_key::rrset_class, reply_info::rrsets, packed_rrset_key::type, VERB_ALGO, and verbose().

Referenced by generate_ns_check(), and processPrimeResponse().

## ◆ generate_ns_check()

static void generate_ns_check | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | int | id )
| static

Generate a NS check request to obtain authoritative information on an NS rrset.

Parameters

  qstate | the qstate that triggered the need to prime.
  iq | iterator query state.
  id | module id.

References BIT_CD, BIT_RD, can_have_last_resort(), delegpt_copy(), iter_qstate::depth, iter_qstate::dp, module_qstate::env, FINISHED_STATE, fptr_ok, fptr_whitelist_modenv_kill_sub(), generate_a_aaaa_check(), generate_sub_request(), INIT_REQUEST_STATE, module_env::kill_sub, LDNS_RR_TYPE_DS, LDNS_RR_TYPE_NS, log_assert, log_err(), log_nametypeclass(), iter_env::max_dependency_depth, module_qstate::minfo, module_env::modinfo, delegpt::name, delegpt::namelen, iter_qstate::qchase, query_info::qclass, module_qstate::qinfo, query_info::qname, query_info::qtype, query_dname_compare(), module_qstate::query_flags, iter_qstate::refetch_glue, module_qstate::region, VERB_ALGO, and verbose().

Referenced by processQueryResponse().

## ◆ generate_dnskey_prefetch()

static void generate_dnskey_prefetch | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | int | id )
| static

Generate a DNSKEY prefetch query to get the DNSKEY for the DS record we just got in a referral (where we have dnssec_expected, thus have trust anchors above it).

Note that right after calling this routine the iterator detached subqueries (because of following the referral), and thus the DNSKEY query becomes detached, its return stored in the cache for later lookup by the validator. This cache lookup by the validator avoids the roundtrip incurred by the DNSKEY query. The DNSKEY query is now performed at about the same time the original query is sent to the domain, thus the two answers are likely to be returned at about the same time, saving a roundtrip from the validated lookup.

Parameters

  qstate | the qtstate that triggered the need to prime.
  iq | iterator query state.
  id | module id.

References BIT_CD, BIT_RD, delegpt_copy(), iter_qstate::dp, module_qstate::env, FINISHED_STATE, generate_sub_request(), INIT_REQUEST_STATE, log_assert, log_nametypeclass(), module_env::mesh, mesh_jostle_exceeded(), module_qstate::minfo, delegpt::name, delegpt::namelen, iter_qstate::qchase, query_info::qclass, module_qstate::qinfo, query_info::qname, query_info::qtype, query_dname_compare(), module_qstate::query_flags, module_qstate::region, VERB_ALGO, and verbose().

Referenced by processInitRequest3(), and processQueryResponse().

## ◆ forward_request()

static int forward_request | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq )
| static

See if the query needs forwarding.

Parameters

  qstate | query state.
  iq | iterator query state.

Returns
  true if the request is forwarded, false if not. If returns true but, iq->dp is NULL then a malloc failure occurred.

References BIT_RD, iter_qstate::chase_flags, delegpt_copy(), dname_is_root(), dname_remove_label(), iter_qstate::dp, module_qstate::env, forwards_lookup(), module_env::fwds, LDNS_RR_TYPE_DS, iter_forwards::lock, delegpt::name, delegpt::namelen, iter_qstate::qchase, query_info::qclass, query_info::qname, query_info::qname_len, query_info::qtype, iter_qstate::refetch_glue, module_qstate::region, VERB_ALGO, and verbose().

Referenced by processInitRequest().

## ◆ processInitRequest()

static int processInitRequest | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | struct iter_env * | ie,
|  | int | id )
| static

Process the initial part of the request handling.

This state roughly corresponds to resolver algorithms steps 1 (find answer in cache) and 2 (find the best servers to ask).

Note that all requests start here, and query restarts revisit this state.

This state either generates: 1) a response, from cache or error, 2) a priming event, or 3) forwards the request to the next state (init2, generally).

Parameters

  qstate | query state.
  iq | iterator query state.
  ie | iterator shared global environment.
  id | module id.

Returns
  true if the event needs more request processing immediately, false if not.

References auth_zone_delegpt(), module_env::auth_zones, BIT_RD, module_qstate::blacklist, cache_fill_missing(), can_have_last_resort(), module_env::cfg, COLLECT_CLASS_STATE, iter_qstate::deleg_msg, delegpt_copy(), delegpt_log(), iter_qstate::depth, dname_is_root(), dname_remove_label(), dns_cache_find_delegation(), dns_cache_lookup(), DONOT_MINIMISE_STATE, iter_qstate::dp, iter_qstate::dp_target_count, module_qstate::env, errinf(), errinf_dname(), error_response(), error_response_cache(), module_qstate::ext_state, final_state(), FINISHED_STATE, reply_info::flags, FLAGS_GET_RCODE, forward_request(), forwards_lookup_root(), module_env::fwds, handle_cname_response(), module_env::hints, hints_find_root(), INIT_MINIMISE_STATE, INIT_REQUEST_2_STATE, INIT_REQUEST_STATE, iter_dp_is_useless(), iter_prepend(), iter_qname_indicates_dnssec(), iter_stub_fwd_no_cache(), LDNS_MAX_DOMAINLEN, LDNS_RR_CLASS_ANY, LDNS_RR_TYPE_CNAME, LDNS_RR_TYPE_DS, LDNS_RR_TYPE_NS, iter_forwards::lock, iter_hints::lock, log_dns_msg(), log_err(), log_query_info(), iter_env::max_dependency_depth, iter_env::max_query_restarts, iter_qstate::minimisation_state, module_finished, delegpt::name, delegpt::namelen, module_env::neg_cache, next_state(), module_qstate::no_cache_lookup, module_qstate::no_cache_store, module_env::now, module_qstate::prefetch_leeway, reply_info::prefetch_ttl, prime_root(), prime_stub(), iter_qstate::qchase, query_info::qclass, dns_msg::qinfo, module_qstate::qinfo, query_info::qname, query_info::qname_len, config_file::qname_minimisation, query_info::qtype, query_dname_compare(), module_qstate::query_flags, iter_qstate::query_restart_count, QUERYTARGETS_STATE, iter_qstate::ratelimit_ok, iter_qstate::refetch_glue, module_qstate::region, dns_msg::rep, reply_find_rrset_section_an(), module_qstate::reply_origin, iter_qstate::response, RESPONSE_TYPE_CNAME, response_type_from_cache(), module_qstate::return_msg, module_qstate::return_rcode, rpz_callback_from_iterator_cname(), module_env::rrset_cache, module_env::scratch, module_env::scratch_buffer, sec_status_unchecked, reply_info::security, iter_qstate::sent_count, sock_list_insert(), iter_env::supports_ipv4, iter_env::supports_ipv6, reply_info::ttl, iter_env::use_nat64, val_neg_getmsg(), VERB_ALGO, VERB_DETAIL, VERB_QUERY, verbose(), and verbosity.

Referenced by iter_handle().

## ◆ processInitRequest2()

static int processInitRequest2 | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | int | id )
| static

Process the second part of the initial request handling.

This state basically exists so that queries that generate root priming events have the same init processing as ones that do not. Request events that reach this state must have a valid currentDelegationPoint set.

This part is primarily handling stub zone priming. Events that reach this state must have a current delegation point.

Parameters

  qstate | query state.
  iq | iterator query state.
  id | module id.

Returns
  true if the event needs more request processing immediately, false if not.

References auth_zone_delegpt(), dname_is_root(), dname_remove_label(), dname_subdomain_c(), iter_hints_stub::dp, iter_qstate::dp, module_qstate::env, errinf(), error_response(), delegpt::has_parent_side_NS, module_env::hints, hints_lookup_stub(), INIT_REQUEST_3_STATE, LDNS_RR_TYPE_DS, iter_hints::lock, log_err(), log_query_info(), delegpt::name, delegpt::namelen, next_state(), prime_stub(), iter_qstate::qchase, query_info::qclass, module_qstate::qinfo, query_info::qname, query_info::qname_len, query_info::qtype, iter_qstate::refetch_glue, and VERB_QUERY.

Referenced by iter_handle().

## ◆ processInitRequest3()

static int processInitRequest3 | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | int | id )
| static

Process the third part of the initial request handling.

This state exists as a separate state so that queries that generate stub priming events will get the tail end of the init process but not repeat the stub priming check.

Parameters

  qstate | query state.
  iq | iterator query state.
  id | module id.

Returns
  true, advancing the event to the QUERYTARGETS_STATE.

References BIT_CD, BIT_RD, module_env::cfg, iter_qstate::chase_flags, iter_qstate::deleg_msg, module_env::detach_subs, iter_qstate::dnssec_expected, iter_qstate::dp, module_qstate::env, final_state(), fptr_ok, fptr_whitelist_modenv_detach_subs(), generate_dnskey_prefetch(), iter_indicates_dnssec(), log_dns_msg(), log_query_info(), next_state(), config_file::prefetch_key, iter_qstate::qchase, query_info::qclass, dns_msg::qinfo, module_qstate::qinfo, module_qstate::query_flags, QUERYTARGETS_STATE, module_qstate::region, dns_msg::rep, module_qstate::reply_origin, iter_qstate::response, sock_list_insert(), VERB_ALGO, VERB_QUERY, and verbosity.

Referenced by iter_handle().

## ◆ generate_parentside_target_query()

static int generate_parentside_target_query | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | int | id,
|  | uint8_t * | name,
|  | size_t | namelen,
|  | uint16_t | qtype,
|  | uint16_t | qclass )
| static

Given a basic query, generate a parent-side "target" query.

These are subordinate queries for missing delegation point target addresses, for which only the parent of the delegation provides correct IP addresses.

Parameters

  qstate | query state.
  iq | iterator query state.
  id | module id.
  name | target qname.
  namelen | target qname length.
  qtype | target qtype (either A or AAAA).
  qclass | target qclass.

Returns
  true on success, false on failure.

References module_qstate::blacklist, iter_qstate::deleg_msg, delegpt_copy(), dname_subdomain_c(), dns_cache_find_delegation(), iter_qstate::dnssec_expected, iter_qstate::dp, module_qstate::env, FINISHED_STATE, generate_sub_request(), INIT_REQUEST_STATE, iter_indicates_dnssec(), log_nametypeclass(), module_qstate::minfo, delegpt::name, module_env::now, module_qstate::prefetch_leeway, query_info::qclass, module_qstate::qinfo, iter_qstate::query_for_pside_glue, iter_qstate::refetch_glue, module_qstate::region, sock_list_insert(), and VERB_QUERY.

Referenced by processLastResort().

## ◆ generate_target_query()

static int generate_target_query | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | int | id,
|  | uint8_t * | name,
|  | size_t | namelen,
|  | uint16_t | qtype,
|  | uint16_t | qclass )
| static

Given a basic query, generate a "target" query.

These are subordinate queries for missing delegation point target addresses.

Parameters

  qstate | query state.
  iq | iterator query state.
  id | module id.
  name | target qname.
  namelen | target qname length.
  qtype | target qtype (either A or AAAA).
  qclass | target qclass.

Returns
  true on success, false on failure.

References FINISHED_STATE, generate_sub_request(), INIT_REQUEST_STATE, log_nametypeclass(), and VERB_QUERY.

Referenced by query_for_targets().

## ◆ query_for_targets()

static int query_for_targets | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | struct iter_env * | ie,
|  | int | id,
|  | int | maxtargets,
|  | int * | num )
| static

Given an event at a certain state, generate zero or more target queries for it's current delegation point.

Parameters

  qstate | query state.
  iq | iterator query state.
  ie | iterator shared global environment.
  id | module id.
  maxtargets | The maximum number of targets to query for. if it is negative, there is no maximum number of targets.
  num | returns the number of queries generated and processed, which may be zero if there were no missing targets.

Returns
  0 on success, nonzero on error. 1 means temporary failure and 2 means the failure can be cached.

References delegpt_count_missing_targets(), iter_qstate::depth, dname_str(), delegpt_ns::done_pside4, delegpt_ns::done_pside6, iter_qstate::dp, iter_qstate::dp_target_count, module_qstate::env, module_qstate::ext_state, generate_target_query(), delegpt_ns::got4, delegpt_ns::got6, iter_mark_cycle_targets(), iter_ns_probability(), delegpt_ns::lame, LDNS_MAX_DOMAINLEN, LDNS_RR_TYPE_A, LDNS_RR_TYPE_AAAA, log_assert, iter_env::max_dependency_depth, MAX_DP_TARGET_COUNT, MAX_TARGET_COUNT, module_env::mesh, mesh_jostle_exceeded(), module_wait_subquery, delegpt_ns::name, delegpt_ns::namelen, delegpt_ns::next, delegpt::nslist, iter_qstate::qchase, query_info::qclass, module_qstate::qinfo, query_info::qname, delegpt_ns::resolved, module_env::rnd, iter_env::supports_ipv4, iter_env::supports_ipv6, iter_qstate::target_count, TARGET_COUNT_QUERIES, iter_env::use_nat64, VERB_QUERY, and verbose().

Referenced by processLastResort(), and processQueryTargets().

## ◆ processLastResort()

static int processLastResort | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | struct iter_env * | ie,
|  | int | id )
| static

Called by processQueryTargets when it would like extra targets to query but it seems to be out of options.

At last resort some less appealing options are explored. If there are no more options, the result is SERVFAIL

Parameters

  qstate | query state.
  iq | iterator query state.
  ie | iterator shared global environment.
  id | module id.

Returns
  true if the event requires more request processing immediately, false if not.

References delegpt_addr::addr, delegpt_addr::addrlen, delegpt_addr::bogus, cache_fill_missing(), can_have_last_resort(), module_env::cfg, iter_qstate::chase_flags, iter_qstate::deleg_msg, delegpt_add_addr(), delegpt_add_ns(), delegpt_count_missing_targets(), iter_qstate::depth, dname_is_root(), dname_str(), delegpt_ns::done_pside4, delegpt_ns::done_pside6, iter_qstate::dp, iter_qstate::dp_target_count, module_qstate::env, errinf(), errinf_dname(), errinf_reply(), error_response(), error_response_cache(), module_qstate::ext_state, generate_parentside_target_query(), delegpt::has_parent_side_NS, module_env::hints, hints_find_root(), INIT_MINIMISE_STATE, INIT_REQUEST_STATE, iter_lookup_parent_glue_from_cache(), iter_lookup_parent_NS_from_cache(), iter_mark_pside_cycle_targets(), iter_store_parentside_neg(), delegpt_addr::lame, delegpt_ns::lame, LDNS_MAX_DOMAINLEN, LDNS_RR_TYPE_A, LDNS_RR_TYPE_AAAA, LDNS_RR_TYPE_NS, iter_hints::lock, log_assert, log_err(), log_nametypeclass(), iter_env::max_dependency_depth, MAX_TARGET_COUNT, module_env::mesh, mesh_jostle_exceeded(), iter_qstate::minimisation_state, module_wait_subquery, delegpt::name, delegpt_ns::name, delegpt::namelen, delegpt_ns::namelen, delegpt_ns::next, next_state(), delegpt_addr::next_target, module_qstate::no_cache_store, delegpt::nslist, iter_qstate::num_target_queries, delegpt_ns::port, iter_qstate::pside_glue, iter_qstate::qchase, query_info::qclass, module_qstate::qinfo, query_info::qname, config_file::qname_minimisation, iter_qstate::query_for_pside_glue, query_for_targets(), iter_qstate::query_restart_count, QUERYTARGETS_STATE, iter_qstate::refetch_glue, module_qstate::region, dns_msg::rep, iter_qstate::response, iter_qstate::sent_count, iter_qstate::store_parent_NS, iter_env::supports_ipv4, iter_env::supports_ipv6, iter_qstate::target_count, TARGET_COUNT_QUERIES, delegpt::target_list, delegpt_addr::tls_auth_name, delegpt_ns::tls_auth_name, delegpt::usable_list, iter_env::use_nat64, VERB_ALGO, VERB_QUERY, and verbose().

Referenced by processQueryTargets().

## ◆ processDSNSFind()

static int processDSNSFind | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | int | id )
| static

Try to find the NS record set that will resolve a qtype DS query.

Due to grandparent/grandchild reasons we did not get a proper lookup right away. We need to create type NS queries until we get the right parent for this lookup. We remove labels from the query to find the right point. If we end up at the old dp name, then there is no solution.

Parameters

  qstate | query state.
  iq | iterator query state.
  id | module id.

Returns
  true if the event requires more immediate processing, false if not. This is generally only true when forwarding the request to the final state (i.e., on answer).

References dname_remove_label(), dname_subdomain_c(), iter_qstate::dp, DSNS_FIND_STATE, iter_qstate::dsns_point, iter_qstate::dsns_point_len, errinf_dname(), error_response_cache(), FINISHED_STATE, generate_sub_request(), INIT_REQUEST_STATE, LDNS_RR_TYPE_NS, log_nametypeclass(), delegpt::name, iter_qstate::qchase, query_info::qclass, query_info::qname, query_info::qname_len, query_dname_compare(), QUERYTARGETS_STATE, iter_qstate::state, VERB_ALGO, and verbose().

Referenced by iter_handle(), and processQueryResponse().

## ◆ processQueryTargets()

static int processQueryTargets | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | struct iter_env * | ie,
|  | int | id )
| static

This is the request event state where the request will be sent to one of its current query targets.

This state also handles issuing target lookup queries for missing target IP addresses. Queries typically iterate on this state, both when they are just trying different targets for a given delegation point, and when they change delegation points. This state roughly corresponds to RFC 1034 algorithm steps 3 and 4.

Parameters

  qstate | query state.
  iq | iterator query state.
  ie | iterator shared global environment.
  id | module id.

Returns
  true if the event requires more request processing immediately, false if not. This state only returns true when it is generating a SERVFAIL response because the query has hit a dead end.

References delegpt_addr::addr, addr_to_nat64(), delegpt_addr::addrlen, delegpt_addr::attempts, delegpt::auth_dp, iter_qstate::auth_zone_avoid, iter_qstate::auth_zone_response, module_env::auth_zones, auth_zones_can_fallback(), auth_zones_lookup(), BIT_AA, BIT_CD, BIT_RD, module_qstate::blacklist, iter_qstate::caps_fallback, iter_qstate::caps_reply, iter_qstate::caps_server, module_env::cfg, iter_qstate::chase_flags, iter_qstate::chase_to_rd, check_waiting_queries(), iter_qstate::deleg_msg, delegpt_add_unused_targets(), delegpt_count_addr(), delegpt_count_missing_targets(), delegpt_log(), delegpt_no_ipv4(), delegpt_no_ipv6(), iter_qstate::depth, module_env::detach_subs, config_file::disable_edns_do, dname_canonical_compare(), dname_count_labels(), dname_remove_labels(), dname_str(), dname_subdomain_c(), dns_cache_lookup(), iter_qstate::dnssec_expected, iter_qstate::dnssec_lame_query, DONOT_MINIMISE_STATE, iter_qstate::dp, iter_qstate::dp_target_count, iter_qstate::dsns_point, EDNS_DO, module_qstate::env, errinf(), errinf_dname(), error_response(), error_response_cache(), module_qstate::ext_state, final_state(), FINISHED_STATE, reply_info::flags, FLAGS_GET_RCODE, fptr_ok, fptr_whitelist_modenv_detach_subs(), fptr_whitelist_modenv_send_query(), generate_sub_request(), handle_cname_response(), config_file::harden_below_nxdomain, delegpt::has_parent_side_NS, INIT_MINIMISE_STATE, INIT_REQUEST_STATE, is_caps_whitelisted(), iter_dec_attempts(), iter_prepend(), iter_qname_indicates_dnssec(), iter_server_selection(), LDNS_MAX_DOMAINLEN, LDNS_RR_TYPE_A, LDNS_RR_TYPE_CNAME, LDNS_RR_TYPE_DS, query_info::local_alias, auth_zones::lock, log_addr(), log_dns_msg(), log_err(), log_name_addr(), log_query_info(), iter_env::max_dependency_depth, MAX_GLOBAL_QUOTA, MAX_MINIMISE_COUNT, iter_env::max_query_restarts, MAX_REFERRAL_COUNT, iter_env::max_sent_count, MAX_TARGET_NX, MAX_TARGET_NX_FALLBACK, module_env::mesh, mesh_jostle_exceeded(), iter_qstate::minimisation_state, iter_qstate::minimise_count, MINIMISE_ONE_LAB, MINIMISE_STATE, module_finished, module_wait_reply, delegpt::name, delegpt::namelen, iter_env::nat64_prefix_addr, iter_env::nat64_prefix_addrlen, iter_env::nat64_prefix_net, module_env::need_to_validate, delegpt_ns::next, next_state(), module_qstate::no_cache_lookup, delegpt::nslist, iter_qstate::num_current_queries, iter_env::num_queries_ratelimited, auth_zones::num_query_up, iter_qstate::num_target_queries, iter_qstate::nxns_dp, outbound_list_clear(), outbound_list_insert(), iter_env::outbound_msg_retry, iter_qstate::outlist, module_qstate::prefetch_leeway, processLastResort(), iter_qstate::qchase, query_info::qclass, dns_msg::qinfo, module_qstate::qinfo, iter_qstate::qinfo_out, query_info::qname, query_info::qname_len, config_file::qname_minimisation, config_file::qname_minimisation_strict, query_info::qtype, iter_env::queries_ratelimit_lock, module_qstate::query_flags, query_for_targets(), QUERY_RESP_STATE, iter_qstate::query_restart_count, QUERYTARGETS_STATE, iter_qstate::ratelimit_ok, iter_qstate::referral_count, iter_qstate::refetch_glue, module_qstate::region, dns_msg::rep, reply_find_rrset_section_an(), delegpt_ns::resolved, iter_qstate::response, module_qstate::return_msg, module_qstate::return_rcode, module_env::rnd, rpz_callback_from_iterator_cname(), rpz_callback_from_iterator_module(), module_env::scratch, sec_status_secure, sec_status_unchecked, reply_info::security, module_env::send_query, iter_qstate::sent_count, SKIP_MINIMISE_STATE, config_file::ssl_upstream, delegpt::ssl_upstream, iter_qstate::state, iter_env::supports_ipv4, iter_env::supports_ipv6, iter_qstate::target_count, TARGET_COUNT_GLOBAL_QUOTA, TARGET_COUNT_NX, iter_env::target_fetch_policy, TARGET_FETCH_STOP, config_file::tcp_upstream, delegpt::tcp_upstream, iter_qstate::timeout_count, delegpt_addr::tls_auth_name, ub_random_max(), iter_env::use_nat64, VERB_ALGO, VERB_QUERY, verbose(), verbosity, and module_qstate::was_ratelimited.

Referenced by iter_handle().

## ◆ processQueryResponse()

static int processQueryResponse | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | struct iter_env * | ie,
|  | int | id )
| static

Process the query response.

All queries end up at this state first. This process generally consists of analyzing the response and routing the event to the next state (either bouncing it back to a request state, or terminating the processing for this event).

Parameters

  qstate | query state.
  iq | iterator query state.
  ie | iterator shared global environment.
  id | module id.

Returns
  true if the event requires more immediate processing, false if not. This is generally only true when forwarding the request to the final state (i.e., on answer).

References reply_info::an_numrrsets, delegpt::auth_dp, iter_qstate::auth_zone_avoid, iter_qstate::auth_zone_response, module_env::auth_zones, auth_zones_can_fallback(), BIT_CD, BIT_RD, cache_fill_missing(), module_env::cfg, iter_qstate::chase_flags, iter_qstate::chase_to_rd, iter_qstate::deleg_msg, delegpt_find_addr(), delegpt_from_message(), delegpt_log(), module_env::detach_subs, config_file::disable_dnssec_lame_check, packed_rrset_key::dname, dname_strict_subdomain_c(), dname_subdomain_c(), iter_qstate::dnssec_expected, DNSSEC_LAME_DETECT_COUNT, iter_qstate::dnssec_lame_query, delegpt_addr::dnsseclame, DONOT_MINIMISE_STATE, iter_qstate::dp, iter_qstate::dp_target_count, iter_qstate::dsns_point, iter_qstate::empty_nodata_found, EMPTY_NODATA_RETRY_COUNT, module_qstate::env, errinf(), errinf_dname(), error_response(), error_response_cache(), module_qstate::ext_state, iter_qstate::fail_addr_type, final_state(), find_NS(), FINISHED_STATE, reply_info::flags, FLAGS_GET_RCODE, fptr_ok, fptr_whitelist_modenv_detach_subs(), generate_dnskey_prefetch(), generate_ns_check(), generate_sub_request(), get_cname_target(), handle_cname_response(), config_file::harden_below_nxdomain, config_file::harden_referral_path, delegpt::has_parent_side_NS, module_env::infra_cache, infra_set_lame(), INIT_MINIMISE_STATE, INIT_REQUEST_STATE, inplace_cb_query_response_call(), iter_dns_store(), iter_dp_cangodown(), iter_ds_toolow(), iter_indicates_dnssec(), iter_merge_retry_counts(), iter_msg_from_zone(), iter_msg_has_dnssec(), iter_prepend(), iter_scrub_ds(), iter_scrub_nxdomain(), iter_store_parentside_NS(), iter_store_parentside_rrset(), delegpt_addr::lame, LDNS_RR_TYPE_CNAME, LDNS_RR_TYPE_DNAME, LDNS_RR_TYPE_DS, LDNS_RR_TYPE_NS, log_dns_msg(), log_err(), log_query_info(), log_rrset_key(), log_warn(), iter_env::max_query_restarts, iter_qstate::minimisation_state, MINIMISE_STATE, module_finished, delegpt::name, delegpt::namelabs, delegpt::namelen, module_env::need_to_validate, module_env::neg_cache, next_state(), module_qstate::no_cache_store, module_env::now, reply_info::ns_numrrsets, iter_qstate::num_current_queries, iter_qstate::num_target_queries, outbound_list_clear(), iter_env::outbound_msg_retry, iter_qstate::outlist, config_file::prefetch_key, module_qstate::prefetch_leeway, processDSNSFind(), iter_qstate::pside_glue, iter_qstate::qchase, query_info::qclass, dns_msg::qinfo, module_qstate::qinfo, iter_qstate::qinfo_out, query_info::qname, query_info::qname_len, config_file::qname_minimisation, config_file::qname_minimisation_strict, module_qstate::qstarttime, query_info::qtype, query_dname_compare(), module_qstate::query_flags, iter_qstate::query_for_pside_glue, iter_qstate::query_restart_count, QUERYTARGETS_STATE, iter_qstate::referral_count, module_qstate::region, comm_reply::remote_addr, comm_reply::remote_addrlen, dns_msg::rep, module_qstate::reply, reply_find_rrset(), reply_find_rrset_section_an(), reply_find_rrset_section_ns(), module_qstate::reply_origin, iter_qstate::response, RESPONSE_TYPE_ANSWER, RESPONSE_TYPE_CNAME, response_type_from_server(), RESPONSE_TYPE_LAME, RESPONSE_TYPE_REC_LAME, RESPONSE_TYPE_REFERRAL, RESPONSE_TYPE_THROWAWAY, RESPONSE_TYPE_UNTYPED, module_qstate::return_msg, module_qstate::return_rcode, ub_packed_rrset_key::rk, rpz_callback_from_iterator_cname(), module_env::rrset_cache, rrset_cache_remove_above(), reply_info::rrsets, iter_qstate::sent_count, SKIP_MINIMISE_STATE, sock_list_insert(), iter_qstate::store_parent_NS, iter_qstate::timeout_count, packed_rrset_key::type, val_neg_addreferral(), VERB_ALGO, VERB_DETAIL, VERB_QUERY, verbose(), and verbosity.

Referenced by iter_handle().

## ◆ prime_supers()

static void prime_supers | ( | struct module_qstate * | qstate,
|  | int | id,
|  | struct module_qstate * | forq )
| static

Return priming query results to interested super querystates.

Sets the delegation point and delegation message (not nonRD queries). This is a callback from walk_supers.

Parameters

  qstate | priming query state that finished.
  id | module id.
  forq | the qstate for which priming has been done.

References iter_qstate::deleg_msg, delegpt_from_message(), delegpt_log(), dns_copy_msg(), iter_qstate::dp, INIT_REQUEST_2_STATE, INIT_REQUEST_3_STATE, module_qstate::is_priming, log_assert, log_err(), log_query_info(), module_qstate::minfo, module_qstate::qinfo, QUERYTARGETS_STATE, module_qstate::region, module_qstate::return_msg, module_qstate::return_rcode, iter_qstate::state, VERB_ALGO, VERB_DETAIL, verbose(), and iter_qstate::wait_priming_stub.

Referenced by iter_inform_super().

## ◆ processPrimeResponse()

static int processPrimeResponse | ( | struct module_qstate * | qstate,
|  | int | id )
| static

This handles the response to a priming query.

This is used to handle both root and stub priming responses. This is basically the equivalent of the QUERY_RESP_STATE, but will not handle CNAME responses and will treat REFERRALs as ANSWERS. It will also update and reactivate the originating event.

Parameters

  qstate | query state.
  id | module id.

Returns
  true if the event needs more immediate processing, false if not. This state always returns false.

References BIT_RA, BIT_RD, module_env::cfg, iter_qstate::chase_flags, iter_qstate::chase_to_rd, iter_qstate::dp, module_qstate::env, errinf(), errinf_dname(), module_qstate::ext_state, FINISHED_STATE, reply_info::flags, generate_a_aaaa_check(), generate_sub_request(), config_file::harden_referral_path, INIT_REQUEST_STATE, log_nametypeclass(), module_qstate::minfo, module_finished, iter_qstate::qchase, query_info::qclass, module_qstate::qinfo, query_info::qname, query_info::qname_len, query_info::qtype, dns_msg::rep, iter_qstate::response, RESPONSE_TYPE_ANSWER, response_type_from_server(), module_qstate::return_msg, module_qstate::return_rcode, VERB_ALGO, and verbose().

Referenced by iter_handle().

## ◆ processTargetResponse()

static void processTargetResponse | ( | struct module_qstate * | qstate,
|  | int | id,
|  | struct module_qstate * | forq )
| static

Do final processing on responses to target queries.

Events reach this state after the iterative resolution algorithm terminates. This state is responsible for reactivating the original event, and housekeeping related to received target responses (caching, updating the current delegation point, etc). Callback from walk_supers for every super state that is interested in the results from this query.

Parameters

  qstate | query state.
  id | module id.
  forq | super query state.

References delegpt_add_ns(), delegpt_add_rrset(), delegpt_find_ns(), delegpt_log(), delegpt_mark_neg(), packed_rrset_key::dname, packed_rrset_key::dname_len, iter_qstate::dp, module_qstate::env, delegpt_ns::got4, delegpt_ns::got6, delegpt_ns::lame, sock_list::len, log_assert, log_err(), log_query_info(), log_rrset_key(), module_qstate::minfo, module_env::modinfo, iter_qstate::num_target_queries, delegpt_ns::port, iter_qstate::pside_glue, iter_qstate::qchase, module_qstate::qinfo, query_info::qname, query_info::qname_len, query_info::qtype, QUERYTARGETS_STATE, module_qstate::region, dns_msg::rep, reply_find_answer_rrset(), module_qstate::reply_origin, delegpt_ns::resolved, module_qstate::return_msg, module_qstate::return_rcode, ub_packed_rrset_key::rk, iter_qstate::state, iter_env::supports_ipv4, iter_env::supports_ipv6, delegpt_ns::tls_auth_name, iter_env::use_nat64, VERB_ALGO, and verbose().

Referenced by iter_inform_super().

## ◆ processDSNSResponse()

static void processDSNSResponse | ( | struct module_qstate * | qstate,
|  | int | id,
|  | struct module_qstate * | forq )
| static

Process response for DS NS Find queries, that attempt to find the delegation point where we ask the DS query from.

Parameters

  qstate | query state.
  id | module id.
  forq | super query state.

References delegpt_from_message(), iter_qstate::dp, errinf(), LDNS_RR_TYPE_NS, log_err(), module_qstate::minfo, query_info::qclass, module_qstate::qinfo, query_info::qname, query_info::qname_len, QUERYTARGETS_STATE, module_qstate::region, dns_msg::rep, reply_find_rrset(), module_qstate::return_msg, module_qstate::return_rcode, and iter_qstate::state.

Referenced by iter_inform_super().

## ◆ processClassResponse()

static void processClassResponse | ( | struct module_qstate * | qstate,
|  | int | id,
|  | struct module_qstate * | forq )
| static

Process response for qclass=ANY queries for a particular class.

Append to result or error-exit.

Parameters

  qstate | query state.
  id | module id.
  forq | super query state.

References reply_info::an_numrrsets, reply_info::ar_numrrsets, reply_info::authoritative, dns_copy_msg(), FINISHED_STATE, reply_info::flags, log_err(), log_query_info(), module_qstate::minfo, reply_info::ns_numrrsets, iter_qstate::num_current_queries, reply_info::prefetch_ttl, query_info::qclass, reply_info::qdcount, dns_msg::qinfo, module_qstate::qinfo, module_qstate::region, regional_alloc(), dns_msg::rep, iter_qstate::response, module_qstate::return_msg, module_qstate::return_rcode, RR_COUNT_MAX, reply_info::rrset_count, reply_info::rrsets, reply_info::security, reply_info::serve_expired_ttl, iter_qstate::state, reply_info::ttl, and VERB_ALGO.

Referenced by iter_inform_super().

## ◆ processCollectClass()

static int processCollectClass | ( | struct module_qstate * | qstate,
|  | int | id )
| static

Collect class ANY responses and make them into one response.

This state is started and it creates queries for all classes (that have root hints). The answers are then collected.

Parameters

  qstate | query state.
  id | module id.

Returns
  true if the event needs more immediate processing, false if not.

References BIT_CD, module_qstate::env, errinf(), error_response(), error_response_cache(), FINISHED_STATE, module_env::fwds, generate_sub_request(), module_env::hints, INIT_REQUEST_STATE, iter_get_next_root(), LDNS_RR_CLASS_ANY, log_nametypeclass(), module_qstate::minfo, iter_qstate::num_current_queries, iter_qstate::qchase, query_info::qclass, module_qstate::qinfo, query_info::qname, query_info::qname_len, query_info::qtype, module_qstate::query_flags, VERB_ALGO, and verbose().

Referenced by iter_handle().

## ◆ processFinished()

static int processFinished | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | int | id )
| static

This handles the final state for first-tier responses (i.e., responses to externally generated queries).

Parameters

  qstate | query state.
  iq | iterator query state.
  id | module id.

Returns
  true if the event needs more processing, false if not. Since this is the final state for an event, it always returns false.

References iter_qstate::an_prepend_list, BIT_QR, BIT_RA, BIT_RD, module_env::cfg, iter_qstate::deleg_msg, iter_qstate::dp, module_qstate::env, errinf(), module_qstate::errinf, errinf_to_str_misc(), error_response(), module_qstate::ext_state, reply_info::flags, delegpt::has_parent_side_NS, iter_dns_store(), iter_prepend(), iter_store_parentside_neg(), log_err(), log_query_info(), config_file::log_servfail, module_finished, module_qstate::no_cache_store, iter_qstate::ns_prepend_list, module_qstate::prefetch_leeway, iter_qstate::pside_glue, dns_msg::qinfo, module_qstate::qinfo, module_qstate::qstarttime, module_qstate::query_flags, iter_qstate::query_for_pside_glue, reply_info::reason_bogus_str, module_qstate::region, dns_msg::rep, iter_qstate::response, module_qstate::return_msg, module_qstate::return_rcode, sec_status_unchecked, reply_info::security, config_file::val_log_level, config_file::val_log_squelch, VERB_ALGO, VERB_QUERY, and verbose().

Referenced by iter_handle().

## ◆ iter_inform_super()

void iter_inform_super | ( | struct module_qstate * | qstate,
|  | int | id,
|  | struct module_qstate * | super )

Return priming query results to interested super querystates.

Sets the delegation point and delegation message (not nonRD queries). This is a callback from walk_supers.

Parameters

  qstate | query state that finished.
  id | module id.
  super | the qstate to inform.

References DSNS_FIND_STATE, error_supers(), module_qstate::is_priming, LDNS_RR_CLASS_ANY, LDNS_RR_TYPE_DS, module_qstate::minfo, prime_supers(), processClassResponse(), processDSNSResponse(), processTargetResponse(), query_info::qclass, module_qstate::qinfo, query_info::qtype, and module_qstate::return_rcode.

Referenced by fptr_whitelist_mod_inform_super().

## ◆ iter_handle()

static void iter_handle | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | struct iter_env * | ie,
|  | int | id )
| static

Handle iterator state.

Handle events. This is the real processing loop for events, responsible for moving events through the various states. If a processing method returns true, then it will be advanced to the next state. If false, then processing will stop.

Parameters

  qstate | query state.
  ie | iterator shared global environment.
  iq | iterator query state.
  id | module id.

References COLLECT_CLASS_STATE, DSNS_FIND_STATE, FINISHED_STATE, INIT_REQUEST_2_STATE, INIT_REQUEST_3_STATE, INIT_REQUEST_STATE, iter_state_to_string(), log_warn(), PRIME_RESP_STATE, processCollectClass(), processDSNSFind(), processFinished(), processInitRequest(), processInitRequest2(), processInitRequest3(), processPrimeResponse(), processQueryResponse(), processQueryTargets(), QUERY_RESP_STATE, QUERYTARGETS_STATE, iter_qstate::state, VERB_ALGO, and verbose().

Referenced by iter_operate(), process_request(), and process_response().

## ◆ process_request()

static void process_request | ( | struct module_qstate * | qstate,
|  | struct iter_qstate * | iq,
|  | struct iter_env * | ie,
|  | int | id )
| static

This is the primary entry point for processing request events.

Note that this method should only be used by external modules.

Parameters

  qstate | query state.
  ie | iterator shared global environment.
  iq | iterator query state.
  id | module id.

References iter_qstate::final_state, FINISHED_STATE, INIT_REQUEST_STATE, iter_handle(), iter_qstate::state, VERB_ALGO, and verbose().

Referenced by iter_operate().

## ◆ iter_get_funcblock()

struct module_func_block * iter_get_funcblock | ( | void |  | ) |

Get the iterator function block.

Returns
  : function block with function pointers to iterator methods.

References iter_block.

Referenced by checkconf(), and module_funcs_avail().

## ◆ iter_state_to_string()

const char * iter_state_to_string | ( | enum iter_state | state | ) |

Get iterator state as a string.

Parameters

  state | to convert

Returns
  constant string that is printable.

References COLLECT_CLASS_STATE, DSNS_FIND_STATE, FINISHED_STATE, INIT_REQUEST_2_STATE, INIT_REQUEST_3_STATE, INIT_REQUEST_STATE, PRIME_RESP_STATE, QUERY_RESP_STATE, and QUERYTARGETS_STATE.

Referenced by iter_handle().

## ◆ iter_state_is_responsestate()

int iter_state_is_responsestate | ( | enum iter_state | s | ) |

See if iterator state is a response state.

Parameters

  s | to inspect

Returns
  true if response state.

References COLLECT_CLASS_STATE, INIT_REQUEST_2_STATE, INIT_REQUEST_3_STATE, INIT_REQUEST_STATE, and QUERYTARGETS_STATE.

Referenced by next_state().

## Variable Documentation

## ◆ USEFUL_SERVER_TOP_TIMEOUT

int USEFUL_SERVER_TOP_TIMEOUT = 120000

maximum timeout before a host is deemed unsuitable, in msec.

After host_ttl this will be timed out and the host will be tried again. Equals RTT_MAX_TIMEOUT, and thus when RTT_MAX_TIMEOUT is overwritten by config infra_cache_max_rtt, it will be overwritten as well.

Referenced by config_apply(), config_set_option(), dump_infra_host(), infra_get_lame_rtt(), infra_host(), infra_rtt_update(), iter_filter_order(), iter_filter_unsuitable(), iter_server_selection(), and print_dp_details().

## ◆ iter_block

struct module_func_block iter_block
| static

Initial value:
= {
"iterator",
NULL, NULL, &iter_init, &iter_deinit, &iter_operate,
&iter_inform_super, &iter_clear, &iter_get_mem
}
iter_get_mem
size_t iter_get_mem(struct module_env *env, int id)
iterator alloc size routine
Definition iterator.c:4502
iter_init
int iter_init(struct module_env *env, int id)
iterator init
Definition iterator.c:83
iter_inform_super
void iter_inform_super(struct module_qstate *qstate, int id, struct module_qstate *super)
Return priming query results to interested super querystates.
Definition iterator.c:4152
iter_clear
void iter_clear(struct module_qstate *qstate, int id)
iterator cleanup query state
Definition iterator.c:4483
iter_deinit
void iter_deinit(struct module_env *env, int id)
iterator deinit
Definition iterator.c:117
iter_operate
void iter_operate(struct module_qstate *qstate, enum module_ev event, int id, struct outbound_entry *outbound)
iterator operate on a query
Definition iterator.c:4437

The iterator function block.

Referenced by iter_get_funcblock().