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 referrals. Makes sure resolver does not run away */ 67b7579f77SDag-Erling Smørgrav #define MAX_REFERRAL_COUNT 130 68e2d15004SDag-Erling Smørgrav /** max number of queries for which to perform dnsseclameness detection, 698a384985SDag-Erling Smørgrav * (rrsigs missing detection) after that, just pick up that response */ 70e2d15004SDag-Erling Smørgrav #define DNSSEC_LAME_DETECT_COUNT 4 71e2d15004SDag-Erling Smørgrav /** 72e2d15004SDag-Erling Smørgrav * max number of QNAME minimisation iterations. Limits number of queries for 73e2d15004SDag-Erling Smørgrav * QNAMEs with a lot of labels. 74e2d15004SDag-Erling Smørgrav */ 75e2d15004SDag-Erling Smørgrav #define MAX_MINIMISE_COUNT 10 76b5663de9SDag-Erling Smørgrav /* max number of time-outs for minimised query. Prevents resolving failures 77b5663de9SDag-Erling Smørgrav * when the QNAME minimisation QTYPE is blocked. */ 78b5663de9SDag-Erling Smørgrav #define MAX_MINIMISE_TIMEOUT_COUNT 3 79e2d15004SDag-Erling Smørgrav /** 80e2d15004SDag-Erling Smørgrav * number of labels from QNAME that are always send individually when using 81e2d15004SDag-Erling Smørgrav * QNAME minimisation, even when the number of labels of the QNAME is bigger 829cf5bc93SCy Schubert * than MAX_MINIMISE_COUNT */ 83e2d15004SDag-Erling Smørgrav #define MINIMISE_ONE_LAB 4 84e2d15004SDag-Erling Smørgrav #define MINIMISE_MULTIPLE_LABS (MAX_MINIMISE_COUNT - MINIMISE_ONE_LAB) 85b7579f77SDag-Erling Smørgrav /** at what query-sent-count to stop target fetch policy */ 86b7579f77SDag-Erling Smørgrav #define TARGET_FETCH_STOP 3 87b7579f77SDag-Erling Smørgrav /** how nice is a server without further information, in msec 88b7579f77SDag-Erling Smørgrav * Equals rtt initial timeout value. 89b7579f77SDag-Erling Smørgrav */ 90e86b9096SDag-Erling Smørgrav extern int UNKNOWN_SERVER_NICENESS; 91b7579f77SDag-Erling Smørgrav /** maximum timeout before a host is deemed unsuitable, in msec. 92b7579f77SDag-Erling Smørgrav * After host_ttl this will be timed out and the host will be tried again. 93790c6b24SCy Schubert * Equals RTT_MAX_TIMEOUT, and thus when RTT_MAX_TIMEOUT is overwritten by 94790c6b24SCy Schubert * config infra_cache_max_rtt, it will be overwritten as well. */ 95790c6b24SCy Schubert extern int USEFUL_SERVER_TOP_TIMEOUT; 96790c6b24SCy Schubert /** penalty to validation failed blacklisted IPs 97790c6b24SCy Schubert * Equals USEFUL_SERVER_TOP_TIMEOUT*4, and thus when RTT_MAX_TIMEOUT is 98790c6b24SCy Schubert * overwritten by config infra_cache_max_rtt, it will be overwritten as well. */ 99790c6b24SCy Schubert extern int BLACKLIST_PENALTY; 100b7579f77SDag-Erling Smørgrav /** RTT band, within this amount from the best, servers are chosen randomly. 101b7579f77SDag-Erling Smørgrav * Chosen so that the UNKNOWN_SERVER_NICENESS falls within the band of a 102b7579f77SDag-Erling Smørgrav * fast server, this causes server exploration as a side benefit. msec. */ 103b7579f77SDag-Erling Smørgrav #define RTT_BAND 400 104*103ba509SCy Schubert /** Number of retries for empty nodata packets before it is accepted. */ 105*103ba509SCy Schubert #define EMPTY_NODATA_RETRY_COUNT 2 106b7579f77SDag-Erling Smørgrav 107b7579f77SDag-Erling Smørgrav /** 108b7579f77SDag-Erling Smørgrav * Global state for the iterator. 109b7579f77SDag-Erling Smørgrav */ 110b7579f77SDag-Erling Smørgrav struct iter_env { 111b7579f77SDag-Erling Smørgrav /** A flag to indicate whether or not we have an IPv6 route */ 112b7579f77SDag-Erling Smørgrav int supports_ipv6; 113b7579f77SDag-Erling Smørgrav 114b7579f77SDag-Erling Smørgrav /** A flag to indicate whether or not we have an IPv4 route */ 115b7579f77SDag-Erling Smørgrav int supports_ipv4; 116b7579f77SDag-Erling Smørgrav 1178f76bb7dSCy Schubert /** A flag to locally apply NAT64 to make IPv4 addrs into IPv6 */ 1188f76bb7dSCy Schubert int use_nat64; 1198f76bb7dSCy Schubert 1208f76bb7dSCy Schubert /** NAT64 prefix address, cf. dns64_env->prefix_addr */ 1218f76bb7dSCy Schubert struct sockaddr_storage nat64_prefix_addr; 1228f76bb7dSCy Schubert 1238f76bb7dSCy Schubert /** sizeof(sockaddr_in6) */ 1248f76bb7dSCy Schubert socklen_t nat64_prefix_addrlen; 1258f76bb7dSCy Schubert 1268f76bb7dSCy Schubert /** CIDR mask length of NAT64 prefix */ 1278f76bb7dSCy Schubert int nat64_prefix_net; 1288f76bb7dSCy Schubert 129b7579f77SDag-Erling Smørgrav /** A set of inetaddrs that should never be queried. */ 130b7579f77SDag-Erling Smørgrav struct iter_donotq* donotq; 131b7579f77SDag-Erling Smørgrav 132b7579f77SDag-Erling Smørgrav /** private address space and private domains */ 133b7579f77SDag-Erling Smørgrav struct iter_priv* priv; 134b7579f77SDag-Erling Smørgrav 13509a3aaf3SDag-Erling Smørgrav /** whitelist for capsforid names */ 1363005e0a3SDag-Erling Smørgrav struct rbtree_type* caps_white; 13709a3aaf3SDag-Erling Smørgrav 138b7579f77SDag-Erling Smørgrav /** The maximum dependency depth that this resolver will pursue. */ 139b7579f77SDag-Erling Smørgrav int max_dependency_depth; 140b7579f77SDag-Erling Smørgrav 141b7579f77SDag-Erling Smørgrav /** 142b7579f77SDag-Erling Smørgrav * The target fetch policy for each dependency level. This is 143b7579f77SDag-Erling Smørgrav * described as a simple number (per dependency level): 144b7579f77SDag-Erling Smørgrav * negative numbers (usually just -1) mean fetch-all, 145b7579f77SDag-Erling Smørgrav * 0 means only fetch on demand, and 146b7579f77SDag-Erling Smørgrav * positive numbers mean to fetch at most that many targets. 147b7579f77SDag-Erling Smørgrav * array of max_dependency_depth+1 size. 148b7579f77SDag-Erling Smørgrav */ 149b7579f77SDag-Erling Smørgrav int* target_fetch_policy; 15005ab2901SDag-Erling Smørgrav 151971980c3SDag-Erling Smørgrav /** lock on ratelimit counter */ 152971980c3SDag-Erling Smørgrav lock_basic_type queries_ratelimit_lock; 153971980c3SDag-Erling Smørgrav /** number of queries that have been ratelimited */ 154971980c3SDag-Erling Smørgrav size_t num_queries_ratelimited; 15524e36522SCy Schubert 15624e36522SCy Schubert /** number of retries on outgoing queries */ 15724e36522SCy Schubert int outbound_msg_retry; 1581838dec3SCy Schubert 1591838dec3SCy Schubert /** number of queries_sent */ 1601838dec3SCy Schubert int max_sent_count; 1611838dec3SCy Schubert 1621838dec3SCy Schubert /** max number of query restarts to limit length of CNAME chain */ 1631838dec3SCy Schubert int max_query_restarts; 16405ab2901SDag-Erling Smørgrav }; 16505ab2901SDag-Erling Smørgrav 16605ab2901SDag-Erling Smørgrav /** 16705ab2901SDag-Erling Smørgrav * QNAME minimisation state 16805ab2901SDag-Erling Smørgrav */ 16905ab2901SDag-Erling Smørgrav enum minimisation_state { 17005ab2901SDag-Erling Smørgrav /** 17105ab2901SDag-Erling Smørgrav * (Re)start minimisation. Outgoing QNAME should be set to dp->name. 1728a384985SDag-Erling Smørgrav * State entered on new query or after following referral or CNAME. 17305ab2901SDag-Erling Smørgrav */ 17405ab2901SDag-Erling Smørgrav INIT_MINIMISE_STATE = 0, 17505ab2901SDag-Erling Smørgrav /** 1768a384985SDag-Erling Smørgrav * QNAME minimisation ongoing. Increase QNAME on every iteration. 17705ab2901SDag-Erling Smørgrav */ 17805ab2901SDag-Erling Smørgrav MINIMISE_STATE, 17905ab2901SDag-Erling Smørgrav /** 18005ab2901SDag-Erling Smørgrav * Don't increment QNAME this iteration 18105ab2901SDag-Erling Smørgrav */ 18205ab2901SDag-Erling Smørgrav SKIP_MINIMISE_STATE, 18305ab2901SDag-Erling Smørgrav /** 18405ab2901SDag-Erling Smørgrav * Send out full QNAME + original QTYPE 18505ab2901SDag-Erling Smørgrav */ 18605ab2901SDag-Erling Smørgrav DONOT_MINIMISE_STATE, 187b7579f77SDag-Erling Smørgrav }; 188b7579f77SDag-Erling Smørgrav 189b7579f77SDag-Erling Smørgrav /** 190b7579f77SDag-Erling Smørgrav * State of the iterator for a query. 191b7579f77SDag-Erling Smørgrav */ 192b7579f77SDag-Erling Smørgrav enum iter_state { 193b7579f77SDag-Erling Smørgrav /** 194b7579f77SDag-Erling Smørgrav * Externally generated queries start at this state. Query restarts are 195b7579f77SDag-Erling Smørgrav * reset to this state. 196b7579f77SDag-Erling Smørgrav */ 197b7579f77SDag-Erling Smørgrav INIT_REQUEST_STATE = 0, 198b7579f77SDag-Erling Smørgrav 199b7579f77SDag-Erling Smørgrav /** 200b7579f77SDag-Erling Smørgrav * Root priming events reactivate here, most other events pass 201b7579f77SDag-Erling Smørgrav * through this naturally as the 2nd part of the INIT_REQUEST_STATE. 202b7579f77SDag-Erling Smørgrav */ 203b7579f77SDag-Erling Smørgrav INIT_REQUEST_2_STATE, 204b7579f77SDag-Erling Smørgrav 205b7579f77SDag-Erling Smørgrav /** 206b7579f77SDag-Erling Smørgrav * Stub priming events reactivate here, most other events pass 207b7579f77SDag-Erling Smørgrav * through this naturally as the 3rd part of the INIT_REQUEST_STATE. 208b7579f77SDag-Erling Smørgrav */ 209b7579f77SDag-Erling Smørgrav INIT_REQUEST_3_STATE, 210b7579f77SDag-Erling Smørgrav 211b7579f77SDag-Erling Smørgrav /** 212b7579f77SDag-Erling Smørgrav * Each time a delegation point changes for a given query or a 213b7579f77SDag-Erling Smørgrav * query times out and/or wakes up, this state is (re)visited. 2148a384985SDag-Erling Smørgrav * This state is responsible for iterating through a list of 215b7579f77SDag-Erling Smørgrav * nameserver targets. 216b7579f77SDag-Erling Smørgrav */ 217b7579f77SDag-Erling Smørgrav QUERYTARGETS_STATE, 218b7579f77SDag-Erling Smørgrav 219b7579f77SDag-Erling Smørgrav /** 220b7579f77SDag-Erling Smørgrav * Responses to queries start at this state. This state handles 221b7579f77SDag-Erling Smørgrav * the decision tree associated with handling responses. 222b7579f77SDag-Erling Smørgrav */ 223b7579f77SDag-Erling Smørgrav QUERY_RESP_STATE, 224b7579f77SDag-Erling Smørgrav 225b7579f77SDag-Erling Smørgrav /** Responses to priming queries finish at this state. */ 226b7579f77SDag-Erling Smørgrav PRIME_RESP_STATE, 227b7579f77SDag-Erling Smørgrav 228b7579f77SDag-Erling Smørgrav /** Collecting query class information, for qclass=ANY, when 229b7579f77SDag-Erling Smørgrav * it spawns off queries for every class, it returns here. */ 230b7579f77SDag-Erling Smørgrav COLLECT_CLASS_STATE, 231b7579f77SDag-Erling Smørgrav 232b7579f77SDag-Erling Smørgrav /** Find NS record to resolve DS record from, walking to the right 233b7579f77SDag-Erling Smørgrav * NS spot until we find it */ 234b7579f77SDag-Erling Smørgrav DSNS_FIND_STATE, 235b7579f77SDag-Erling Smørgrav 236b7579f77SDag-Erling Smørgrav /** Responses that are to be returned upstream end at this state. 237b7579f77SDag-Erling Smørgrav * As well as responses to target queries. */ 238b7579f77SDag-Erling Smørgrav FINISHED_STATE 239b7579f77SDag-Erling Smørgrav }; 240b7579f77SDag-Erling Smørgrav 241b7579f77SDag-Erling Smørgrav /** 2420a92a9fcSCy Schubert * Shared counters for queries. 2430a92a9fcSCy Schubert */ 2440a92a9fcSCy Schubert enum target_count_variables { 2450a92a9fcSCy Schubert /** Reference count for the shared iter_qstate->target_count. */ 2460a92a9fcSCy Schubert TARGET_COUNT_REF = 0, 2470a92a9fcSCy Schubert /** Number of target queries spawned for the query and subqueries. */ 2480a92a9fcSCy Schubert TARGET_COUNT_QUERIES, 2490a92a9fcSCy Schubert /** Number of nxdomain responses encountered. */ 2500a92a9fcSCy Schubert TARGET_COUNT_NX, 2510a92a9fcSCy Schubert 2520a92a9fcSCy Schubert /** This should stay last here, it is used for the allocation */ 2530a92a9fcSCy Schubert TARGET_COUNT_MAX, 2540a92a9fcSCy Schubert }; 2550a92a9fcSCy Schubert 2560a92a9fcSCy Schubert /** 257b7579f77SDag-Erling Smørgrav * Per query state for the iterator module. 258b7579f77SDag-Erling Smørgrav */ 259b7579f77SDag-Erling Smørgrav struct iter_qstate { 260b7579f77SDag-Erling Smørgrav /** 261b7579f77SDag-Erling Smørgrav * State of the iterator module. 262b7579f77SDag-Erling Smørgrav * This is the state that event is in or should sent to -- all 263b7579f77SDag-Erling Smørgrav * requests should start with the INIT_REQUEST_STATE. All 264b7579f77SDag-Erling Smørgrav * responses should start with QUERY_RESP_STATE. Subsequent 265b7579f77SDag-Erling Smørgrav * processing of the event will change this state. 266b7579f77SDag-Erling Smørgrav */ 267b7579f77SDag-Erling Smørgrav enum iter_state state; 268b7579f77SDag-Erling Smørgrav 269b7579f77SDag-Erling Smørgrav /** 270b7579f77SDag-Erling Smørgrav * Final state for the iterator module. 271b7579f77SDag-Erling Smørgrav * This is the state that responses should be routed to once the 272b7579f77SDag-Erling Smørgrav * response is final. For externally initiated queries, this 273b7579f77SDag-Erling Smørgrav * will be FINISHED_STATE, locally initiated queries will have 274b7579f77SDag-Erling Smørgrav * different final states. 275b7579f77SDag-Erling Smørgrav */ 276b7579f77SDag-Erling Smørgrav enum iter_state final_state; 277b7579f77SDag-Erling Smørgrav 278b7579f77SDag-Erling Smørgrav /** 279b7579f77SDag-Erling Smørgrav * The depth of this query, this means the depth of recursion. 280b7579f77SDag-Erling Smørgrav * This address is needed for another query, which is an address 281b7579f77SDag-Erling Smørgrav * needed for another query, etc. Original client query has depth 0. 282b7579f77SDag-Erling Smørgrav */ 283b7579f77SDag-Erling Smørgrav int depth; 284b7579f77SDag-Erling Smørgrav 285b7579f77SDag-Erling Smørgrav /** 286b7579f77SDag-Erling Smørgrav * The response 287b7579f77SDag-Erling Smørgrav */ 288b7579f77SDag-Erling Smørgrav struct dns_msg* response; 289b7579f77SDag-Erling Smørgrav 290b7579f77SDag-Erling Smørgrav /** 291b7579f77SDag-Erling Smørgrav * This is a list of RRsets that must be prepended to the 292b7579f77SDag-Erling Smørgrav * ANSWER section of a response before being sent upstream. 293b7579f77SDag-Erling Smørgrav */ 294b7579f77SDag-Erling Smørgrav struct iter_prep_list* an_prepend_list; 295b7579f77SDag-Erling Smørgrav /** Last element of the prepend list */ 296b7579f77SDag-Erling Smørgrav struct iter_prep_list* an_prepend_last; 297b7579f77SDag-Erling Smørgrav 298b7579f77SDag-Erling Smørgrav /** 299b7579f77SDag-Erling Smørgrav * This is the list of RRsets that must be prepended to the 300b7579f77SDag-Erling Smørgrav * AUTHORITY section of the response before being sent upstream. 301b7579f77SDag-Erling Smørgrav */ 302b7579f77SDag-Erling Smørgrav struct iter_prep_list* ns_prepend_list; 303b7579f77SDag-Erling Smørgrav /** Last element of the authority prepend list */ 304b7579f77SDag-Erling Smørgrav struct iter_prep_list* ns_prepend_last; 305b7579f77SDag-Erling Smørgrav 306b7579f77SDag-Erling Smørgrav /** query name used for chasing the results. Initially the same as 307b7579f77SDag-Erling Smørgrav * the state qinfo, but after CNAMEs this will be different. 308b7579f77SDag-Erling Smørgrav * The query info used to elicit the results needed. */ 309b7579f77SDag-Erling Smørgrav struct query_info qchase; 310b7579f77SDag-Erling Smørgrav /** query flags to use when chasing the answer (i.e. RD flag) */ 311b7579f77SDag-Erling Smørgrav uint16_t chase_flags; 312b7579f77SDag-Erling Smørgrav /** true if we set RD bit because of last resort recursion lame query*/ 313b7579f77SDag-Erling Smørgrav int chase_to_rd; 314b7579f77SDag-Erling Smørgrav 315b7579f77SDag-Erling Smørgrav /** 316b7579f77SDag-Erling Smørgrav * This is the current delegation point for an in-progress query. This 317b7579f77SDag-Erling Smørgrav * object retains state as to which delegation targets need to be 318b7579f77SDag-Erling Smørgrav * (sub)queried for vs which ones have already been visited. 319b7579f77SDag-Erling Smørgrav */ 320b7579f77SDag-Erling Smørgrav struct delegpt* dp; 321b7579f77SDag-Erling Smørgrav 322b7579f77SDag-Erling Smørgrav /** state for 0x20 fallback when capsfail happens, 0 not a fallback */ 323b7579f77SDag-Erling Smørgrav int caps_fallback; 324b7579f77SDag-Erling Smørgrav /** state for capsfail: current server number to try */ 325b7579f77SDag-Erling Smørgrav size_t caps_server; 326ff825849SDag-Erling Smørgrav /** state for capsfail: stored query for comparisons. Can be NULL if 327ff825849SDag-Erling Smørgrav * no response had been seen prior to starting the fallback. */ 328b7579f77SDag-Erling Smørgrav struct reply_info* caps_reply; 32909a3aaf3SDag-Erling Smørgrav struct dns_msg* caps_response; 330b7579f77SDag-Erling Smørgrav 331b7579f77SDag-Erling Smørgrav /** Current delegation message - returned for non-RD queries */ 332b7579f77SDag-Erling Smørgrav struct dns_msg* deleg_msg; 333b7579f77SDag-Erling Smørgrav 334b7579f77SDag-Erling Smørgrav /** number of outstanding target sub queries */ 335b7579f77SDag-Erling Smørgrav int num_target_queries; 336b7579f77SDag-Erling Smørgrav 337b7579f77SDag-Erling Smørgrav /** outstanding direct queries */ 338b7579f77SDag-Erling Smørgrav int num_current_queries; 339b7579f77SDag-Erling Smørgrav 340b7579f77SDag-Erling Smørgrav /** the number of times this query has been restarted. */ 341b7579f77SDag-Erling Smørgrav int query_restart_count; 342b7579f77SDag-Erling Smørgrav 343865f46b2SCy Schubert /** the number of times this query has followed a referral. */ 344b7579f77SDag-Erling Smørgrav int referral_count; 345b7579f77SDag-Erling Smørgrav 346b7579f77SDag-Erling Smørgrav /** number of queries fired off */ 347b7579f77SDag-Erling Smørgrav int sent_count; 348b7579f77SDag-Erling Smørgrav 3490a92a9fcSCy Schubert /** malloced-array shared with this query and its subqueries. It keeps 3500a92a9fcSCy Schubert * track of the defined enum target_count_variables counters. */ 35152df462fSXin LI int* target_count; 35252df462fSXin LI 353091e9e46SCy Schubert /** number of target lookups per delegation point. Reset to 0 after 354091e9e46SCy Schubert * receiving referral answer. Not shared with subqueries. */ 355091e9e46SCy Schubert int dp_target_count; 356091e9e46SCy Schubert 3570a92a9fcSCy Schubert /** Delegation point that triggered the NXNS fallback; shared with 3580a92a9fcSCy Schubert * this query and its subqueries, count-referenced by the reference 3590a92a9fcSCy Schubert * counter in target_count. 3600a92a9fcSCy Schubert * This also marks the fallback activation. */ 3610a92a9fcSCy Schubert uint8_t** nxns_dp; 3620a92a9fcSCy Schubert 36309a3aaf3SDag-Erling Smørgrav /** if true, already tested for ratelimiting and passed the test */ 36409a3aaf3SDag-Erling Smørgrav int ratelimit_ok; 36509a3aaf3SDag-Erling Smørgrav 366b7579f77SDag-Erling Smørgrav /** 367b7579f77SDag-Erling Smørgrav * The query must store NS records from referrals as parentside RRs 368b7579f77SDag-Erling Smørgrav * Enabled once it hits resolution problems, to throttle retries. 369b7579f77SDag-Erling Smørgrav * If enabled it is the pointer to the old delegation point with 370b7579f77SDag-Erling Smørgrav * the old retry counts for bad-nameserver-addresses. 371b7579f77SDag-Erling Smørgrav */ 372b7579f77SDag-Erling Smørgrav struct delegpt* store_parent_NS; 373b7579f77SDag-Erling Smørgrav 374b7579f77SDag-Erling Smørgrav /** 375b7579f77SDag-Erling Smørgrav * The query is for parent-side glue(A or AAAA) for a nameserver. 376b7579f77SDag-Erling Smørgrav * If the item is seen as glue in a referral, and pside_glue is NULL, 377b7579f77SDag-Erling Smørgrav * then it is stored in pside_glue for later. 378b7579f77SDag-Erling Smørgrav * If it was never seen, at the end, then a negative caching element 379b7579f77SDag-Erling Smørgrav * must be created. 380b7579f77SDag-Erling Smørgrav * The (data or negative) RR cache element then throttles retries. 381b7579f77SDag-Erling Smørgrav */ 382b7579f77SDag-Erling Smørgrav int query_for_pside_glue; 383b7579f77SDag-Erling Smørgrav /** the parent-side-glue element (NULL if none, its first match) */ 384b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key* pside_glue; 385b7579f77SDag-Erling Smørgrav 386b7579f77SDag-Erling Smørgrav /** If nonNULL we are walking upwards from DS query to find NS */ 387b7579f77SDag-Erling Smørgrav uint8_t* dsns_point; 388b7579f77SDag-Erling Smørgrav /** length of the dname in dsns_point */ 389b7579f77SDag-Erling Smørgrav size_t dsns_point_len; 390b7579f77SDag-Erling Smørgrav 391b7579f77SDag-Erling Smørgrav /** 392b7579f77SDag-Erling Smørgrav * expected dnssec information for this iteration step. 393b7579f77SDag-Erling Smørgrav * If dnssec rrsigs are expected and not given, the server is marked 394b7579f77SDag-Erling Smørgrav * lame (dnssec-lame). 395b7579f77SDag-Erling Smørgrav */ 396b7579f77SDag-Erling Smørgrav int dnssec_expected; 397b7579f77SDag-Erling Smørgrav 398b7579f77SDag-Erling Smørgrav /** 399b7579f77SDag-Erling Smørgrav * We are expecting dnssec information, but we also know the server 400b7579f77SDag-Erling Smørgrav * is DNSSEC lame. The response need not be marked dnssec-lame again. 401b7579f77SDag-Erling Smørgrav */ 402b7579f77SDag-Erling Smørgrav int dnssec_lame_query; 403b7579f77SDag-Erling Smørgrav 404b7579f77SDag-Erling Smørgrav /** 405b7579f77SDag-Erling Smørgrav * This is flag that, if true, means that this event is 406b7579f77SDag-Erling Smørgrav * waiting for a stub priming query. 407b7579f77SDag-Erling Smørgrav */ 408b7579f77SDag-Erling Smørgrav int wait_priming_stub; 409b7579f77SDag-Erling Smørgrav 410b7579f77SDag-Erling Smørgrav /** 411b7579f77SDag-Erling Smørgrav * This is a flag that, if true, means that this query is 412b7579f77SDag-Erling Smørgrav * for (re)fetching glue from a zone. Since the address should 413b7579f77SDag-Erling Smørgrav * have been glue, query again to the servers that should have 414b7579f77SDag-Erling Smørgrav * been returning it as glue. 415b7579f77SDag-Erling Smørgrav * The delegation point must be set to the one that should *not* 416b7579f77SDag-Erling Smørgrav * be used when creating the state. A higher one will be attempted. 417b7579f77SDag-Erling Smørgrav */ 418b7579f77SDag-Erling Smørgrav int refetch_glue; 419b7579f77SDag-Erling Smørgrav 420*103ba509SCy Schubert /** 421*103ba509SCy Schubert * This flag detects that a completely empty nodata was received, 422*103ba509SCy Schubert * already so that it is accepted later. */ 423*103ba509SCy Schubert int empty_nodata_found; 424*103ba509SCy Schubert 425b7579f77SDag-Erling Smørgrav /** list of pending queries to authoritative servers. */ 426b7579f77SDag-Erling Smørgrav struct outbound_list outlist; 42705ab2901SDag-Erling Smørgrav 4289cf5bc93SCy Schubert /** QNAME minimisation state, RFC9156 */ 42905ab2901SDag-Erling Smørgrav enum minimisation_state minimisation_state; 43005ab2901SDag-Erling Smørgrav 4314c75e3aaSDag-Erling Smørgrav /** State for capsfail: QNAME minimisation state for comparisons. */ 4324c75e3aaSDag-Erling Smørgrav enum minimisation_state caps_minimisation_state; 4334c75e3aaSDag-Erling Smørgrav 43405ab2901SDag-Erling Smørgrav /** 43505ab2901SDag-Erling Smørgrav * The query info that is sent upstream. Will be a subset of qchase 43605ab2901SDag-Erling Smørgrav * when qname minimisation is enabled. 43705ab2901SDag-Erling Smørgrav */ 43805ab2901SDag-Erling Smørgrav struct query_info qinfo_out; 439e2d15004SDag-Erling Smørgrav 440e2d15004SDag-Erling Smørgrav /** 4418a384985SDag-Erling Smørgrav * Count number of QNAME minimisation iterations. Used to limit number of 442e2d15004SDag-Erling Smørgrav * outgoing queries when QNAME minimisation is enabled. 443e2d15004SDag-Erling Smørgrav */ 444e2d15004SDag-Erling Smørgrav int minimise_count; 445b5663de9SDag-Erling Smørgrav 446b5663de9SDag-Erling Smørgrav /** 447b5663de9SDag-Erling Smørgrav * Count number of time-outs. Used to prevent resolving failures when 44825039b37SCy Schubert * the QNAME minimisation QTYPE is blocked. Used to determine if 44925039b37SCy Schubert * capsforid fallback should be started.*/ 45025039b37SCy Schubert int timeout_count; 45157bddd21SDag-Erling Smørgrav 45257bddd21SDag-Erling Smørgrav /** True if the current response is from auth_zone */ 45357bddd21SDag-Erling Smørgrav int auth_zone_response; 45457bddd21SDag-Erling Smørgrav /** True if the auth_zones should not be consulted for the query */ 45557bddd21SDag-Erling Smørgrav int auth_zone_avoid; 4565469a995SCy Schubert /** true if there have been scrubbing failures of reply packets */ 4575469a995SCy Schubert int scrub_failures; 4585469a995SCy Schubert /** true if there have been parse failures of reply packets */ 4595469a995SCy Schubert int parse_failures; 4605469a995SCy Schubert /** a failure printout address for last received answer */ 4618f76bb7dSCy Schubert union { 4628f76bb7dSCy Schubert struct in_addr in; 4638f76bb7dSCy Schubert #ifdef AF_INET6 4648f76bb7dSCy Schubert struct in6_addr in6; 4658f76bb7dSCy Schubert #endif 4668f76bb7dSCy Schubert } fail_addr; 4678f76bb7dSCy Schubert /** which fail_addr, 0 is nothing, 4 or 6 */ 4688f76bb7dSCy Schubert int fail_addr_type; 469b7579f77SDag-Erling Smørgrav }; 470b7579f77SDag-Erling Smørgrav 471b7579f77SDag-Erling Smørgrav /** 472b7579f77SDag-Erling Smørgrav * List of prepend items 473b7579f77SDag-Erling Smørgrav */ 474b7579f77SDag-Erling Smørgrav struct iter_prep_list { 475b7579f77SDag-Erling Smørgrav /** next in list */ 476b7579f77SDag-Erling Smørgrav struct iter_prep_list* next; 477b7579f77SDag-Erling Smørgrav /** rrset */ 478b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key* rrset; 479b7579f77SDag-Erling Smørgrav }; 480b7579f77SDag-Erling Smørgrav 481b7579f77SDag-Erling Smørgrav /** 482b7579f77SDag-Erling Smørgrav * Get the iterator function block. 483b7579f77SDag-Erling Smørgrav * @return: function block with function pointers to iterator methods. 484b7579f77SDag-Erling Smørgrav */ 485b7579f77SDag-Erling Smørgrav struct module_func_block* iter_get_funcblock(void); 486b7579f77SDag-Erling Smørgrav 487b7579f77SDag-Erling Smørgrav /** 488b7579f77SDag-Erling Smørgrav * Get iterator state as a string 489b7579f77SDag-Erling Smørgrav * @param state: to convert 490b7579f77SDag-Erling Smørgrav * @return constant string that is printable. 491b7579f77SDag-Erling Smørgrav */ 492b7579f77SDag-Erling Smørgrav const char* iter_state_to_string(enum iter_state state); 493b7579f77SDag-Erling Smørgrav 494b7579f77SDag-Erling Smørgrav /** 495b7579f77SDag-Erling Smørgrav * See if iterator state is a response state 496b7579f77SDag-Erling Smørgrav * @param s: to inspect 497b7579f77SDag-Erling Smørgrav * @return true if response state. 498b7579f77SDag-Erling Smørgrav */ 499b7579f77SDag-Erling Smørgrav int iter_state_is_responsestate(enum iter_state s); 500b7579f77SDag-Erling Smørgrav 501b7579f77SDag-Erling Smørgrav /** iterator init */ 502b7579f77SDag-Erling Smørgrav int iter_init(struct module_env* env, int id); 503b7579f77SDag-Erling Smørgrav 504b7579f77SDag-Erling Smørgrav /** iterator deinit */ 505b7579f77SDag-Erling Smørgrav void iter_deinit(struct module_env* env, int id); 506b7579f77SDag-Erling Smørgrav 507b7579f77SDag-Erling Smørgrav /** iterator operate on a query */ 508b7579f77SDag-Erling Smørgrav void iter_operate(struct module_qstate* qstate, enum module_ev event, int id, 509b7579f77SDag-Erling Smørgrav struct outbound_entry* outbound); 510b7579f77SDag-Erling Smørgrav 511b7579f77SDag-Erling Smørgrav /** 5128a384985SDag-Erling Smørgrav * Return priming query results to interested super querystates. 513b7579f77SDag-Erling Smørgrav * 514b7579f77SDag-Erling Smørgrav * Sets the delegation point and delegation message (not nonRD queries). 515b7579f77SDag-Erling Smørgrav * This is a callback from walk_supers. 516b7579f77SDag-Erling Smørgrav * 517b7579f77SDag-Erling Smørgrav * @param qstate: query state that finished. 518b7579f77SDag-Erling Smørgrav * @param id: module id. 519b7579f77SDag-Erling Smørgrav * @param super: the qstate to inform. 520b7579f77SDag-Erling Smørgrav */ 521b7579f77SDag-Erling Smørgrav void iter_inform_super(struct module_qstate* qstate, int id, 522b7579f77SDag-Erling Smørgrav struct module_qstate* super); 523b7579f77SDag-Erling Smørgrav 524b7579f77SDag-Erling Smørgrav /** iterator cleanup query state */ 525b7579f77SDag-Erling Smørgrav void iter_clear(struct module_qstate* qstate, int id); 526b7579f77SDag-Erling Smørgrav 527b7579f77SDag-Erling Smørgrav /** iterator alloc size routine */ 528b7579f77SDag-Erling Smørgrav size_t iter_get_mem(struct module_env* env, int id); 529b7579f77SDag-Erling Smørgrav 530b7579f77SDag-Erling Smørgrav #endif /* ITERATOR_ITERATOR_H */ 531