1b7579f77SDag-Erling Smørgrav /* 2b7579f77SDag-Erling Smørgrav * iterator/iterator.h - iterative resolver DNS query response module 3b7579f77SDag-Erling Smørgrav * 4b7579f77SDag-Erling Smørgrav * Copyright (c) 2007, NLnet Labs. All rights reserved. 5b7579f77SDag-Erling Smørgrav * 6b7579f77SDag-Erling Smørgrav * This software is open source. 7b7579f77SDag-Erling Smørgrav * 8b7579f77SDag-Erling Smørgrav * Redistribution and use in source and binary forms, with or without 9b7579f77SDag-Erling Smørgrav * modification, are permitted provided that the following conditions 10b7579f77SDag-Erling Smørgrav * are met: 11b7579f77SDag-Erling Smørgrav * 12b7579f77SDag-Erling Smørgrav * Redistributions of source code must retain the above copyright notice, 13b7579f77SDag-Erling Smørgrav * this list of conditions and the following disclaimer. 14b7579f77SDag-Erling Smørgrav * 15b7579f77SDag-Erling Smørgrav * Redistributions in binary form must reproduce the above copyright notice, 16b7579f77SDag-Erling Smørgrav * this list of conditions and the following disclaimer in the documentation 17b7579f77SDag-Erling Smørgrav * and/or other materials provided with the distribution. 18b7579f77SDag-Erling Smørgrav * 19b7579f77SDag-Erling Smørgrav * Neither the name of the NLNET LABS nor the names of its contributors may 20b7579f77SDag-Erling Smørgrav * be used to endorse or promote products derived from this software without 21b7579f77SDag-Erling Smørgrav * specific prior written permission. 22b7579f77SDag-Erling Smørgrav * 23b7579f77SDag-Erling Smørgrav * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2417d15b25SDag-Erling Smørgrav * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2517d15b25SDag-Erling Smørgrav * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2617d15b25SDag-Erling Smørgrav * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2717d15b25SDag-Erling Smørgrav * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2817d15b25SDag-Erling Smørgrav * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 2917d15b25SDag-Erling Smørgrav * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 3017d15b25SDag-Erling Smørgrav * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 3117d15b25SDag-Erling Smørgrav * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 3217d15b25SDag-Erling Smørgrav * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 3317d15b25SDag-Erling Smørgrav * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34b7579f77SDag-Erling Smørgrav */ 35b7579f77SDag-Erling Smørgrav 36b7579f77SDag-Erling Smørgrav /** 37b7579f77SDag-Erling Smørgrav * \file 38b7579f77SDag-Erling Smørgrav * 398a384985SDag-Erling Smørgrav * This file contains a module that performs recursive iterative DNS query 40b7579f77SDag-Erling Smørgrav * processing. 41b7579f77SDag-Erling Smørgrav */ 42b7579f77SDag-Erling Smørgrav 43b7579f77SDag-Erling Smørgrav #ifndef ITERATOR_ITERATOR_H 44b7579f77SDag-Erling Smørgrav #define ITERATOR_ITERATOR_H 45b7579f77SDag-Erling Smørgrav #include "services/outbound_list.h" 46b7579f77SDag-Erling Smørgrav #include "util/data/msgreply.h" 47b7579f77SDag-Erling Smørgrav #include "util/module.h" 48b7579f77SDag-Erling Smørgrav struct delegpt; 49b7579f77SDag-Erling Smørgrav struct iter_hints; 50b7579f77SDag-Erling Smørgrav struct iter_forwards; 51b7579f77SDag-Erling Smørgrav struct iter_donotq; 52b7579f77SDag-Erling Smørgrav struct iter_prep_list; 53b7579f77SDag-Erling Smørgrav struct iter_priv; 543005e0a3SDag-Erling Smørgrav struct rbtree_type; 55b7579f77SDag-Erling Smørgrav 5652df462fSXin LI /** max number of targets spawned for a query and its subqueries */ 57b75612f8SDag-Erling Smørgrav #define MAX_TARGET_COUNT 64 58091e9e46SCy Schubert /** max number of target lookups per qstate, per delegation point */ 59091e9e46SCy Schubert #define MAX_DP_TARGET_COUNT 16 60091e9e46SCy Schubert /** max number of nxdomains allowed for target lookups for a query and 61091e9e46SCy Schubert * its subqueries */ 62091e9e46SCy Schubert #define MAX_TARGET_NX 5 630a92a9fcSCy Schubert /** max number of nxdomains allowed for target lookups for a query and 640a92a9fcSCy Schubert * its subqueries when fallback has kicked in */ 650a92a9fcSCy Schubert #define MAX_TARGET_NX_FALLBACK (MAX_TARGET_NX*2) 66b7579f77SDag-Erling Smørgrav /** max number of query restarts. Determines max number of CNAME chain. */ 675469a995SCy Schubert #define MAX_RESTART_COUNT 11 68b7579f77SDag-Erling Smørgrav /** max number of referrals. Makes sure resolver does not run away */ 69b7579f77SDag-Erling Smørgrav #define MAX_REFERRAL_COUNT 130 70b7579f77SDag-Erling Smørgrav /** max number of queries-sent-out. Make sure large NS set does not loop */ 71ff825849SDag-Erling Smørgrav #define MAX_SENT_COUNT 32 72e2d15004SDag-Erling Smørgrav /** max number of queries for which to perform dnsseclameness detection, 738a384985SDag-Erling Smørgrav * (rrsigs missing detection) after that, just pick up that response */ 74e2d15004SDag-Erling Smørgrav #define DNSSEC_LAME_DETECT_COUNT 4 75e2d15004SDag-Erling Smørgrav /** 76e2d15004SDag-Erling Smørgrav * max number of QNAME minimisation iterations. Limits number of queries for 77e2d15004SDag-Erling Smørgrav * QNAMEs with a lot of labels. 78e2d15004SDag-Erling Smørgrav */ 79e2d15004SDag-Erling Smørgrav #define MAX_MINIMISE_COUNT 10 80b5663de9SDag-Erling Smørgrav /* max number of time-outs for minimised query. Prevents resolving failures 81b5663de9SDag-Erling Smørgrav * when the QNAME minimisation QTYPE is blocked. */ 82b5663de9SDag-Erling Smørgrav #define MAX_MINIMISE_TIMEOUT_COUNT 3 83e2d15004SDag-Erling Smørgrav /** 84e2d15004SDag-Erling Smørgrav * number of labels from QNAME that are always send individually when using 85e2d15004SDag-Erling Smørgrav * QNAME minimisation, even when the number of labels of the QNAME is bigger 869cf5bc93SCy Schubert * than MAX_MINIMISE_COUNT */ 87e2d15004SDag-Erling Smørgrav #define MINIMISE_ONE_LAB 4 88e2d15004SDag-Erling Smørgrav #define MINIMISE_MULTIPLE_LABS (MAX_MINIMISE_COUNT - MINIMISE_ONE_LAB) 89b7579f77SDag-Erling Smørgrav /** at what query-sent-count to stop target fetch policy */ 90b7579f77SDag-Erling Smørgrav #define TARGET_FETCH_STOP 3 91b7579f77SDag-Erling Smørgrav /** how nice is a server without further information, in msec 92b7579f77SDag-Erling Smørgrav * Equals rtt initial timeout value. 93b7579f77SDag-Erling Smørgrav */ 94e86b9096SDag-Erling Smørgrav extern int UNKNOWN_SERVER_NICENESS; 95b7579f77SDag-Erling Smørgrav /** maximum timeout before a host is deemed unsuitable, in msec. 96b7579f77SDag-Erling Smørgrav * After host_ttl this will be timed out and the host will be tried again. 97*790c6b24SCy Schubert * Equals RTT_MAX_TIMEOUT, and thus when RTT_MAX_TIMEOUT is overwritten by 98*790c6b24SCy Schubert * config infra_cache_max_rtt, it will be overwritten as well. */ 99*790c6b24SCy Schubert extern int USEFUL_SERVER_TOP_TIMEOUT; 100*790c6b24SCy Schubert /** penalty to validation failed blacklisted IPs 101*790c6b24SCy Schubert * Equals USEFUL_SERVER_TOP_TIMEOUT*4, and thus when RTT_MAX_TIMEOUT is 102*790c6b24SCy Schubert * overwritten by config infra_cache_max_rtt, it will be overwritten as well. */ 103*790c6b24SCy Schubert extern int BLACKLIST_PENALTY; 104b7579f77SDag-Erling Smørgrav /** RTT band, within this amount from the best, servers are chosen randomly. 105b7579f77SDag-Erling Smørgrav * Chosen so that the UNKNOWN_SERVER_NICENESS falls within the band of a 106b7579f77SDag-Erling Smørgrav * fast server, this causes server exploration as a side benefit. msec. */ 107b7579f77SDag-Erling Smørgrav #define RTT_BAND 400 108b7579f77SDag-Erling Smørgrav 109b7579f77SDag-Erling Smørgrav /** 110b7579f77SDag-Erling Smørgrav * Global state for the iterator. 111b7579f77SDag-Erling Smørgrav */ 112b7579f77SDag-Erling Smørgrav struct iter_env { 113b7579f77SDag-Erling Smørgrav /** A flag to indicate whether or not we have an IPv6 route */ 114b7579f77SDag-Erling Smørgrav int supports_ipv6; 115b7579f77SDag-Erling Smørgrav 116b7579f77SDag-Erling Smørgrav /** A flag to indicate whether or not we have an IPv4 route */ 117b7579f77SDag-Erling Smørgrav int supports_ipv4; 118b7579f77SDag-Erling Smørgrav 119b7579f77SDag-Erling Smørgrav /** A set of inetaddrs that should never be queried. */ 120b7579f77SDag-Erling Smørgrav struct iter_donotq* donotq; 121b7579f77SDag-Erling Smørgrav 122b7579f77SDag-Erling Smørgrav /** private address space and private domains */ 123b7579f77SDag-Erling Smørgrav struct iter_priv* priv; 124b7579f77SDag-Erling Smørgrav 12509a3aaf3SDag-Erling Smørgrav /** whitelist for capsforid names */ 1263005e0a3SDag-Erling Smørgrav struct rbtree_type* caps_white; 12709a3aaf3SDag-Erling Smørgrav 128b7579f77SDag-Erling Smørgrav /** The maximum dependency depth that this resolver will pursue. */ 129b7579f77SDag-Erling Smørgrav int max_dependency_depth; 130b7579f77SDag-Erling Smørgrav 131b7579f77SDag-Erling Smørgrav /** 132b7579f77SDag-Erling Smørgrav * The target fetch policy for each dependency level. This is 133b7579f77SDag-Erling Smørgrav * described as a simple number (per dependency level): 134b7579f77SDag-Erling Smørgrav * negative numbers (usually just -1) mean fetch-all, 135b7579f77SDag-Erling Smørgrav * 0 means only fetch on demand, and 136b7579f77SDag-Erling Smørgrav * positive numbers mean to fetch at most that many targets. 137b7579f77SDag-Erling Smørgrav * array of max_dependency_depth+1 size. 138b7579f77SDag-Erling Smørgrav */ 139b7579f77SDag-Erling Smørgrav int* target_fetch_policy; 14005ab2901SDag-Erling Smørgrav 141971980c3SDag-Erling Smørgrav /** lock on ratelimit counter */ 142971980c3SDag-Erling Smørgrav lock_basic_type queries_ratelimit_lock; 143971980c3SDag-Erling Smørgrav /** number of queries that have been ratelimited */ 144971980c3SDag-Erling Smørgrav size_t num_queries_ratelimited; 14524e36522SCy Schubert 14624e36522SCy Schubert /** number of retries on outgoing queries */ 14724e36522SCy Schubert int outbound_msg_retry; 14805ab2901SDag-Erling Smørgrav }; 14905ab2901SDag-Erling Smørgrav 15005ab2901SDag-Erling Smørgrav /** 15105ab2901SDag-Erling Smørgrav * QNAME minimisation state 15205ab2901SDag-Erling Smørgrav */ 15305ab2901SDag-Erling Smørgrav enum minimisation_state { 15405ab2901SDag-Erling Smørgrav /** 15505ab2901SDag-Erling Smørgrav * (Re)start minimisation. Outgoing QNAME should be set to dp->name. 1568a384985SDag-Erling Smørgrav * State entered on new query or after following referral or CNAME. 15705ab2901SDag-Erling Smørgrav */ 15805ab2901SDag-Erling Smørgrav INIT_MINIMISE_STATE = 0, 15905ab2901SDag-Erling Smørgrav /** 1608a384985SDag-Erling Smørgrav * QNAME minimisation ongoing. Increase QNAME on every iteration. 16105ab2901SDag-Erling Smørgrav */ 16205ab2901SDag-Erling Smørgrav MINIMISE_STATE, 16305ab2901SDag-Erling Smørgrav /** 16405ab2901SDag-Erling Smørgrav * Don't increment QNAME this iteration 16505ab2901SDag-Erling Smørgrav */ 16605ab2901SDag-Erling Smørgrav SKIP_MINIMISE_STATE, 16705ab2901SDag-Erling Smørgrav /** 16805ab2901SDag-Erling Smørgrav * Send out full QNAME + original QTYPE 16905ab2901SDag-Erling Smørgrav */ 17005ab2901SDag-Erling Smørgrav DONOT_MINIMISE_STATE, 171b7579f77SDag-Erling Smørgrav }; 172b7579f77SDag-Erling Smørgrav 173b7579f77SDag-Erling Smørgrav /** 174b7579f77SDag-Erling Smørgrav * State of the iterator for a query. 175b7579f77SDag-Erling Smørgrav */ 176b7579f77SDag-Erling Smørgrav enum iter_state { 177b7579f77SDag-Erling Smørgrav /** 178b7579f77SDag-Erling Smørgrav * Externally generated queries start at this state. Query restarts are 179b7579f77SDag-Erling Smørgrav * reset to this state. 180b7579f77SDag-Erling Smørgrav */ 181b7579f77SDag-Erling Smørgrav INIT_REQUEST_STATE = 0, 182b7579f77SDag-Erling Smørgrav 183b7579f77SDag-Erling Smørgrav /** 184b7579f77SDag-Erling Smørgrav * Root priming events reactivate here, most other events pass 185b7579f77SDag-Erling Smørgrav * through this naturally as the 2nd part of the INIT_REQUEST_STATE. 186b7579f77SDag-Erling Smørgrav */ 187b7579f77SDag-Erling Smørgrav INIT_REQUEST_2_STATE, 188b7579f77SDag-Erling Smørgrav 189b7579f77SDag-Erling Smørgrav /** 190b7579f77SDag-Erling Smørgrav * Stub priming events reactivate here, most other events pass 191b7579f77SDag-Erling Smørgrav * through this naturally as the 3rd part of the INIT_REQUEST_STATE. 192b7579f77SDag-Erling Smørgrav */ 193b7579f77SDag-Erling Smørgrav INIT_REQUEST_3_STATE, 194b7579f77SDag-Erling Smørgrav 195b7579f77SDag-Erling Smørgrav /** 196b7579f77SDag-Erling Smørgrav * Each time a delegation point changes for a given query or a 197b7579f77SDag-Erling Smørgrav * query times out and/or wakes up, this state is (re)visited. 1988a384985SDag-Erling Smørgrav * This state is responsible for iterating through a list of 199b7579f77SDag-Erling Smørgrav * nameserver targets. 200b7579f77SDag-Erling Smørgrav */ 201b7579f77SDag-Erling Smørgrav QUERYTARGETS_STATE, 202b7579f77SDag-Erling Smørgrav 203b7579f77SDag-Erling Smørgrav /** 204b7579f77SDag-Erling Smørgrav * Responses to queries start at this state. This state handles 205b7579f77SDag-Erling Smørgrav * the decision tree associated with handling responses. 206b7579f77SDag-Erling Smørgrav */ 207b7579f77SDag-Erling Smørgrav QUERY_RESP_STATE, 208b7579f77SDag-Erling Smørgrav 209b7579f77SDag-Erling Smørgrav /** Responses to priming queries finish at this state. */ 210b7579f77SDag-Erling Smørgrav PRIME_RESP_STATE, 211b7579f77SDag-Erling Smørgrav 212b7579f77SDag-Erling Smørgrav /** Collecting query class information, for qclass=ANY, when 213b7579f77SDag-Erling Smørgrav * it spawns off queries for every class, it returns here. */ 214b7579f77SDag-Erling Smørgrav COLLECT_CLASS_STATE, 215b7579f77SDag-Erling Smørgrav 216b7579f77SDag-Erling Smørgrav /** Find NS record to resolve DS record from, walking to the right 217b7579f77SDag-Erling Smørgrav * NS spot until we find it */ 218b7579f77SDag-Erling Smørgrav DSNS_FIND_STATE, 219b7579f77SDag-Erling Smørgrav 220b7579f77SDag-Erling Smørgrav /** Responses that are to be returned upstream end at this state. 221b7579f77SDag-Erling Smørgrav * As well as responses to target queries. */ 222b7579f77SDag-Erling Smørgrav FINISHED_STATE 223b7579f77SDag-Erling Smørgrav }; 224b7579f77SDag-Erling Smørgrav 225b7579f77SDag-Erling Smørgrav /** 2260a92a9fcSCy Schubert * Shared counters for queries. 2270a92a9fcSCy Schubert */ 2280a92a9fcSCy Schubert enum target_count_variables { 2290a92a9fcSCy Schubert /** Reference count for the shared iter_qstate->target_count. */ 2300a92a9fcSCy Schubert TARGET_COUNT_REF = 0, 2310a92a9fcSCy Schubert /** Number of target queries spawned for the query and subqueries. */ 2320a92a9fcSCy Schubert TARGET_COUNT_QUERIES, 2330a92a9fcSCy Schubert /** Number of nxdomain responses encountered. */ 2340a92a9fcSCy Schubert TARGET_COUNT_NX, 2350a92a9fcSCy Schubert 2360a92a9fcSCy Schubert /** This should stay last here, it is used for the allocation */ 2370a92a9fcSCy Schubert TARGET_COUNT_MAX, 2380a92a9fcSCy Schubert }; 2390a92a9fcSCy Schubert 2400a92a9fcSCy Schubert /** 241b7579f77SDag-Erling Smørgrav * Per query state for the iterator module. 242b7579f77SDag-Erling Smørgrav */ 243b7579f77SDag-Erling Smørgrav struct iter_qstate { 244b7579f77SDag-Erling Smørgrav /** 245b7579f77SDag-Erling Smørgrav * State of the iterator module. 246b7579f77SDag-Erling Smørgrav * This is the state that event is in or should sent to -- all 247b7579f77SDag-Erling Smørgrav * requests should start with the INIT_REQUEST_STATE. All 248b7579f77SDag-Erling Smørgrav * responses should start with QUERY_RESP_STATE. Subsequent 249b7579f77SDag-Erling Smørgrav * processing of the event will change this state. 250b7579f77SDag-Erling Smørgrav */ 251b7579f77SDag-Erling Smørgrav enum iter_state state; 252b7579f77SDag-Erling Smørgrav 253b7579f77SDag-Erling Smørgrav /** 254b7579f77SDag-Erling Smørgrav * Final state for the iterator module. 255b7579f77SDag-Erling Smørgrav * This is the state that responses should be routed to once the 256b7579f77SDag-Erling Smørgrav * response is final. For externally initiated queries, this 257b7579f77SDag-Erling Smørgrav * will be FINISHED_STATE, locally initiated queries will have 258b7579f77SDag-Erling Smørgrav * different final states. 259b7579f77SDag-Erling Smørgrav */ 260b7579f77SDag-Erling Smørgrav enum iter_state final_state; 261b7579f77SDag-Erling Smørgrav 262b7579f77SDag-Erling Smørgrav /** 263b7579f77SDag-Erling Smørgrav * The depth of this query, this means the depth of recursion. 264b7579f77SDag-Erling Smørgrav * This address is needed for another query, which is an address 265b7579f77SDag-Erling Smørgrav * needed for another query, etc. Original client query has depth 0. 266b7579f77SDag-Erling Smørgrav */ 267b7579f77SDag-Erling Smørgrav int depth; 268b7579f77SDag-Erling Smørgrav 269b7579f77SDag-Erling Smørgrav /** 270b7579f77SDag-Erling Smørgrav * The response 271b7579f77SDag-Erling Smørgrav */ 272b7579f77SDag-Erling Smørgrav struct dns_msg* response; 273b7579f77SDag-Erling Smørgrav 274b7579f77SDag-Erling Smørgrav /** 275b7579f77SDag-Erling Smørgrav * This is a list of RRsets that must be prepended to the 276b7579f77SDag-Erling Smørgrav * ANSWER section of a response before being sent upstream. 277b7579f77SDag-Erling Smørgrav */ 278b7579f77SDag-Erling Smørgrav struct iter_prep_list* an_prepend_list; 279b7579f77SDag-Erling Smørgrav /** Last element of the prepend list */ 280b7579f77SDag-Erling Smørgrav struct iter_prep_list* an_prepend_last; 281b7579f77SDag-Erling Smørgrav 282b7579f77SDag-Erling Smørgrav /** 283b7579f77SDag-Erling Smørgrav * This is the list of RRsets that must be prepended to the 284b7579f77SDag-Erling Smørgrav * AUTHORITY section of the response before being sent upstream. 285b7579f77SDag-Erling Smørgrav */ 286b7579f77SDag-Erling Smørgrav struct iter_prep_list* ns_prepend_list; 287b7579f77SDag-Erling Smørgrav /** Last element of the authority prepend list */ 288b7579f77SDag-Erling Smørgrav struct iter_prep_list* ns_prepend_last; 289b7579f77SDag-Erling Smørgrav 290b7579f77SDag-Erling Smørgrav /** query name used for chasing the results. Initially the same as 291b7579f77SDag-Erling Smørgrav * the state qinfo, but after CNAMEs this will be different. 292b7579f77SDag-Erling Smørgrav * The query info used to elicit the results needed. */ 293b7579f77SDag-Erling Smørgrav struct query_info qchase; 294b7579f77SDag-Erling Smørgrav /** query flags to use when chasing the answer (i.e. RD flag) */ 295b7579f77SDag-Erling Smørgrav uint16_t chase_flags; 296b7579f77SDag-Erling Smørgrav /** true if we set RD bit because of last resort recursion lame query*/ 297b7579f77SDag-Erling Smørgrav int chase_to_rd; 298b7579f77SDag-Erling Smørgrav 299b7579f77SDag-Erling Smørgrav /** 300b7579f77SDag-Erling Smørgrav * This is the current delegation point for an in-progress query. This 301b7579f77SDag-Erling Smørgrav * object retains state as to which delegation targets need to be 302b7579f77SDag-Erling Smørgrav * (sub)queried for vs which ones have already been visited. 303b7579f77SDag-Erling Smørgrav */ 304b7579f77SDag-Erling Smørgrav struct delegpt* dp; 305b7579f77SDag-Erling Smørgrav 306b7579f77SDag-Erling Smørgrav /** state for 0x20 fallback when capsfail happens, 0 not a fallback */ 307b7579f77SDag-Erling Smørgrav int caps_fallback; 308b7579f77SDag-Erling Smørgrav /** state for capsfail: current server number to try */ 309b7579f77SDag-Erling Smørgrav size_t caps_server; 310ff825849SDag-Erling Smørgrav /** state for capsfail: stored query for comparisons. Can be NULL if 311ff825849SDag-Erling Smørgrav * no response had been seen prior to starting the fallback. */ 312b7579f77SDag-Erling Smørgrav struct reply_info* caps_reply; 31309a3aaf3SDag-Erling Smørgrav struct dns_msg* caps_response; 314b7579f77SDag-Erling Smørgrav 315b7579f77SDag-Erling Smørgrav /** Current delegation message - returned for non-RD queries */ 316b7579f77SDag-Erling Smørgrav struct dns_msg* deleg_msg; 317b7579f77SDag-Erling Smørgrav 318b7579f77SDag-Erling Smørgrav /** number of outstanding target sub queries */ 319b7579f77SDag-Erling Smørgrav int num_target_queries; 320b7579f77SDag-Erling Smørgrav 321b7579f77SDag-Erling Smørgrav /** outstanding direct queries */ 322b7579f77SDag-Erling Smørgrav int num_current_queries; 323b7579f77SDag-Erling Smørgrav 324b7579f77SDag-Erling Smørgrav /** the number of times this query has been restarted. */ 325b7579f77SDag-Erling Smørgrav int query_restart_count; 326b7579f77SDag-Erling Smørgrav 327b7579f77SDag-Erling Smørgrav /** the number of times this query as followed a referral. */ 328b7579f77SDag-Erling Smørgrav int referral_count; 329b7579f77SDag-Erling Smørgrav 330b7579f77SDag-Erling Smørgrav /** number of queries fired off */ 331b7579f77SDag-Erling Smørgrav int sent_count; 332b7579f77SDag-Erling Smørgrav 3330a92a9fcSCy Schubert /** malloced-array shared with this query and its subqueries. It keeps 3340a92a9fcSCy Schubert * track of the defined enum target_count_variables counters. */ 33552df462fSXin LI int* target_count; 33652df462fSXin LI 337091e9e46SCy Schubert /** number of target lookups per delegation point. Reset to 0 after 338091e9e46SCy Schubert * receiving referral answer. Not shared with subqueries. */ 339091e9e46SCy Schubert int dp_target_count; 340091e9e46SCy Schubert 3410a92a9fcSCy Schubert /** Delegation point that triggered the NXNS fallback; shared with 3420a92a9fcSCy Schubert * this query and its subqueries, count-referenced by the reference 3430a92a9fcSCy Schubert * counter in target_count. 3440a92a9fcSCy Schubert * This also marks the fallback activation. */ 3450a92a9fcSCy Schubert uint8_t** nxns_dp; 3460a92a9fcSCy Schubert 34709a3aaf3SDag-Erling Smørgrav /** if true, already tested for ratelimiting and passed the test */ 34809a3aaf3SDag-Erling Smørgrav int ratelimit_ok; 34909a3aaf3SDag-Erling Smørgrav 350b7579f77SDag-Erling Smørgrav /** 351b7579f77SDag-Erling Smørgrav * The query must store NS records from referrals as parentside RRs 352b7579f77SDag-Erling Smørgrav * Enabled once it hits resolution problems, to throttle retries. 353b7579f77SDag-Erling Smørgrav * If enabled it is the pointer to the old delegation point with 354b7579f77SDag-Erling Smørgrav * the old retry counts for bad-nameserver-addresses. 355b7579f77SDag-Erling Smørgrav */ 356b7579f77SDag-Erling Smørgrav struct delegpt* store_parent_NS; 357b7579f77SDag-Erling Smørgrav 358b7579f77SDag-Erling Smørgrav /** 359b7579f77SDag-Erling Smørgrav * The query is for parent-side glue(A or AAAA) for a nameserver. 360b7579f77SDag-Erling Smørgrav * If the item is seen as glue in a referral, and pside_glue is NULL, 361b7579f77SDag-Erling Smørgrav * then it is stored in pside_glue for later. 362b7579f77SDag-Erling Smørgrav * If it was never seen, at the end, then a negative caching element 363b7579f77SDag-Erling Smørgrav * must be created. 364b7579f77SDag-Erling Smørgrav * The (data or negative) RR cache element then throttles retries. 365b7579f77SDag-Erling Smørgrav */ 366b7579f77SDag-Erling Smørgrav int query_for_pside_glue; 367b7579f77SDag-Erling Smørgrav /** the parent-side-glue element (NULL if none, its first match) */ 368b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key* pside_glue; 369b7579f77SDag-Erling Smørgrav 370b7579f77SDag-Erling Smørgrav /** If nonNULL we are walking upwards from DS query to find NS */ 371b7579f77SDag-Erling Smørgrav uint8_t* dsns_point; 372b7579f77SDag-Erling Smørgrav /** length of the dname in dsns_point */ 373b7579f77SDag-Erling Smørgrav size_t dsns_point_len; 374b7579f77SDag-Erling Smørgrav 375b7579f77SDag-Erling Smørgrav /** 376b7579f77SDag-Erling Smørgrav * expected dnssec information for this iteration step. 377b7579f77SDag-Erling Smørgrav * If dnssec rrsigs are expected and not given, the server is marked 378b7579f77SDag-Erling Smørgrav * lame (dnssec-lame). 379b7579f77SDag-Erling Smørgrav */ 380b7579f77SDag-Erling Smørgrav int dnssec_expected; 381b7579f77SDag-Erling Smørgrav 382b7579f77SDag-Erling Smørgrav /** 383b7579f77SDag-Erling Smørgrav * We are expecting dnssec information, but we also know the server 384b7579f77SDag-Erling Smørgrav * is DNSSEC lame. The response need not be marked dnssec-lame again. 385b7579f77SDag-Erling Smørgrav */ 386b7579f77SDag-Erling Smørgrav int dnssec_lame_query; 387b7579f77SDag-Erling Smørgrav 388b7579f77SDag-Erling Smørgrav /** 389b7579f77SDag-Erling Smørgrav * This is flag that, if true, means that this event is 390b7579f77SDag-Erling Smørgrav * waiting for a stub priming query. 391b7579f77SDag-Erling Smørgrav */ 392b7579f77SDag-Erling Smørgrav int wait_priming_stub; 393b7579f77SDag-Erling Smørgrav 394b7579f77SDag-Erling Smørgrav /** 395b7579f77SDag-Erling Smørgrav * This is a flag that, if true, means that this query is 396b7579f77SDag-Erling Smørgrav * for (re)fetching glue from a zone. Since the address should 397b7579f77SDag-Erling Smørgrav * have been glue, query again to the servers that should have 398b7579f77SDag-Erling Smørgrav * been returning it as glue. 399b7579f77SDag-Erling Smørgrav * The delegation point must be set to the one that should *not* 400b7579f77SDag-Erling Smørgrav * be used when creating the state. A higher one will be attempted. 401b7579f77SDag-Erling Smørgrav */ 402b7579f77SDag-Erling Smørgrav int refetch_glue; 403b7579f77SDag-Erling Smørgrav 404b7579f77SDag-Erling Smørgrav /** list of pending queries to authoritative servers. */ 405b7579f77SDag-Erling Smørgrav struct outbound_list outlist; 40605ab2901SDag-Erling Smørgrav 4079cf5bc93SCy Schubert /** QNAME minimisation state, RFC9156 */ 40805ab2901SDag-Erling Smørgrav enum minimisation_state minimisation_state; 40905ab2901SDag-Erling Smørgrav 4104c75e3aaSDag-Erling Smørgrav /** State for capsfail: QNAME minimisation state for comparisons. */ 4114c75e3aaSDag-Erling Smørgrav enum minimisation_state caps_minimisation_state; 4124c75e3aaSDag-Erling Smørgrav 41305ab2901SDag-Erling Smørgrav /** 41405ab2901SDag-Erling Smørgrav * The query info that is sent upstream. Will be a subset of qchase 41505ab2901SDag-Erling Smørgrav * when qname minimisation is enabled. 41605ab2901SDag-Erling Smørgrav */ 41705ab2901SDag-Erling Smørgrav struct query_info qinfo_out; 418e2d15004SDag-Erling Smørgrav 419e2d15004SDag-Erling Smørgrav /** 4208a384985SDag-Erling Smørgrav * Count number of QNAME minimisation iterations. Used to limit number of 421e2d15004SDag-Erling Smørgrav * outgoing queries when QNAME minimisation is enabled. 422e2d15004SDag-Erling Smørgrav */ 423e2d15004SDag-Erling Smørgrav int minimise_count; 424b5663de9SDag-Erling Smørgrav 425b5663de9SDag-Erling Smørgrav /** 426b5663de9SDag-Erling Smørgrav * Count number of time-outs. Used to prevent resolving failures when 42725039b37SCy Schubert * the QNAME minimisation QTYPE is blocked. Used to determine if 42825039b37SCy Schubert * capsforid fallback should be started.*/ 42925039b37SCy Schubert int timeout_count; 43057bddd21SDag-Erling Smørgrav 43157bddd21SDag-Erling Smørgrav /** True if the current response is from auth_zone */ 43257bddd21SDag-Erling Smørgrav int auth_zone_response; 43357bddd21SDag-Erling Smørgrav /** True if the auth_zones should not be consulted for the query */ 43457bddd21SDag-Erling Smørgrav int auth_zone_avoid; 4355469a995SCy Schubert /** true if there have been scrubbing failures of reply packets */ 4365469a995SCy Schubert int scrub_failures; 4375469a995SCy Schubert /** true if there have been parse failures of reply packets */ 4385469a995SCy Schubert int parse_failures; 4395469a995SCy Schubert /** a failure printout address for last received answer */ 4405469a995SCy Schubert struct comm_reply* fail_reply; 441b7579f77SDag-Erling Smørgrav }; 442b7579f77SDag-Erling Smørgrav 443b7579f77SDag-Erling Smørgrav /** 444b7579f77SDag-Erling Smørgrav * List of prepend items 445b7579f77SDag-Erling Smørgrav */ 446b7579f77SDag-Erling Smørgrav struct iter_prep_list { 447b7579f77SDag-Erling Smørgrav /** next in list */ 448b7579f77SDag-Erling Smørgrav struct iter_prep_list* next; 449b7579f77SDag-Erling Smørgrav /** rrset */ 450b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key* rrset; 451b7579f77SDag-Erling Smørgrav }; 452b7579f77SDag-Erling Smørgrav 453b7579f77SDag-Erling Smørgrav /** 454b7579f77SDag-Erling Smørgrav * Get the iterator function block. 455b7579f77SDag-Erling Smørgrav * @return: function block with function pointers to iterator methods. 456b7579f77SDag-Erling Smørgrav */ 457b7579f77SDag-Erling Smørgrav struct module_func_block* iter_get_funcblock(void); 458b7579f77SDag-Erling Smørgrav 459b7579f77SDag-Erling Smørgrav /** 460b7579f77SDag-Erling Smørgrav * Get iterator state as a string 461b7579f77SDag-Erling Smørgrav * @param state: to convert 462b7579f77SDag-Erling Smørgrav * @return constant string that is printable. 463b7579f77SDag-Erling Smørgrav */ 464b7579f77SDag-Erling Smørgrav const char* iter_state_to_string(enum iter_state state); 465b7579f77SDag-Erling Smørgrav 466b7579f77SDag-Erling Smørgrav /** 467b7579f77SDag-Erling Smørgrav * See if iterator state is a response state 468b7579f77SDag-Erling Smørgrav * @param s: to inspect 469b7579f77SDag-Erling Smørgrav * @return true if response state. 470b7579f77SDag-Erling Smørgrav */ 471b7579f77SDag-Erling Smørgrav int iter_state_is_responsestate(enum iter_state s); 472b7579f77SDag-Erling Smørgrav 473b7579f77SDag-Erling Smørgrav /** iterator init */ 474b7579f77SDag-Erling Smørgrav int iter_init(struct module_env* env, int id); 475b7579f77SDag-Erling Smørgrav 476b7579f77SDag-Erling Smørgrav /** iterator deinit */ 477b7579f77SDag-Erling Smørgrav void iter_deinit(struct module_env* env, int id); 478b7579f77SDag-Erling Smørgrav 479b7579f77SDag-Erling Smørgrav /** iterator operate on a query */ 480b7579f77SDag-Erling Smørgrav void iter_operate(struct module_qstate* qstate, enum module_ev event, int id, 481b7579f77SDag-Erling Smørgrav struct outbound_entry* outbound); 482b7579f77SDag-Erling Smørgrav 483b7579f77SDag-Erling Smørgrav /** 4848a384985SDag-Erling Smørgrav * Return priming query results to interested super querystates. 485b7579f77SDag-Erling Smørgrav * 486b7579f77SDag-Erling Smørgrav * Sets the delegation point and delegation message (not nonRD queries). 487b7579f77SDag-Erling Smørgrav * This is a callback from walk_supers. 488b7579f77SDag-Erling Smørgrav * 489b7579f77SDag-Erling Smørgrav * @param qstate: query state that finished. 490b7579f77SDag-Erling Smørgrav * @param id: module id. 491b7579f77SDag-Erling Smørgrav * @param super: the qstate to inform. 492b7579f77SDag-Erling Smørgrav */ 493b7579f77SDag-Erling Smørgrav void iter_inform_super(struct module_qstate* qstate, int id, 494b7579f77SDag-Erling Smørgrav struct module_qstate* super); 495b7579f77SDag-Erling Smørgrav 496b7579f77SDag-Erling Smørgrav /** iterator cleanup query state */ 497b7579f77SDag-Erling Smørgrav void iter_clear(struct module_qstate* qstate, int id); 498b7579f77SDag-Erling Smørgrav 499b7579f77SDag-Erling Smørgrav /** iterator alloc size routine */ 500b7579f77SDag-Erling Smørgrav size_t iter_get_mem(struct module_env* env, int id); 501b7579f77SDag-Erling Smørgrav 502b7579f77SDag-Erling Smørgrav #endif /* ITERATOR_ITERATOR_H */ 503