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_donotq; 50b7579f77SDag-Erling Smørgrav struct iter_prep_list; 51b7579f77SDag-Erling Smørgrav struct iter_priv; 523005e0a3SDag-Erling Smørgrav struct rbtree_type; 53b7579f77SDag-Erling Smørgrav 5452df462fSXin LI /** max number of targets spawned for a query and its subqueries */ 55b75612f8SDag-Erling Smørgrav #define MAX_TARGET_COUNT 64 5656850988SCy Schubert /** max number of upstream queries for a query and its subqueries, it is 5756850988SCy Schubert * never reset. */ 5846d2f618SCy Schubert extern int MAX_GLOBAL_QUOTA; 59091e9e46SCy Schubert /** max number of target lookups per qstate, per delegation point */ 60091e9e46SCy Schubert #define MAX_DP_TARGET_COUNT 16 61091e9e46SCy Schubert /** max number of nxdomains allowed for target lookups for a query and 62091e9e46SCy Schubert * its subqueries */ 63091e9e46SCy Schubert #define MAX_TARGET_NX 5 640a92a9fcSCy Schubert /** max number of nxdomains allowed for target lookups for a query and 650a92a9fcSCy Schubert * its subqueries when fallback has kicked in */ 660a92a9fcSCy Schubert #define MAX_TARGET_NX_FALLBACK (MAX_TARGET_NX*2) 67b7579f77SDag-Erling Smørgrav /** max number of referrals. Makes sure resolver does not run away */ 68b7579f77SDag-Erling Smørgrav #define MAX_REFERRAL_COUNT 130 69e2d15004SDag-Erling Smørgrav /** max number of queries for which to perform dnsseclameness detection, 708a384985SDag-Erling Smørgrav * (rrsigs missing detection) after that, just pick up that response */ 71e2d15004SDag-Erling Smørgrav #define DNSSEC_LAME_DETECT_COUNT 4 72e2d15004SDag-Erling Smørgrav /** 73e2d15004SDag-Erling Smørgrav * max number of QNAME minimisation iterations. Limits number of queries for 74e2d15004SDag-Erling Smørgrav * QNAMEs with a lot of labels. 75e2d15004SDag-Erling Smørgrav */ 76e2d15004SDag-Erling Smørgrav #define MAX_MINIMISE_COUNT 10 77b5663de9SDag-Erling Smørgrav /* max number of time-outs for minimised query. Prevents resolving failures 78b5663de9SDag-Erling Smørgrav * when the QNAME minimisation QTYPE is blocked. */ 79b5663de9SDag-Erling Smørgrav #define MAX_MINIMISE_TIMEOUT_COUNT 3 80e2d15004SDag-Erling Smørgrav /** 81e2d15004SDag-Erling Smørgrav * number of labels from QNAME that are always send individually when using 82e2d15004SDag-Erling Smørgrav * QNAME minimisation, even when the number of labels of the QNAME is bigger 839cf5bc93SCy Schubert * than MAX_MINIMISE_COUNT */ 84e2d15004SDag-Erling Smørgrav #define MINIMISE_ONE_LAB 4 85e2d15004SDag-Erling Smørgrav #define MINIMISE_MULTIPLE_LABS (MAX_MINIMISE_COUNT - MINIMISE_ONE_LAB) 86b7579f77SDag-Erling Smørgrav /** at what query-sent-count to stop target fetch policy */ 87b7579f77SDag-Erling Smørgrav #define TARGET_FETCH_STOP 3 88b7579f77SDag-Erling Smørgrav /** how nice is a server without further information, in msec 89b7579f77SDag-Erling Smørgrav * Equals rtt initial timeout value. 90b7579f77SDag-Erling Smørgrav */ 91e86b9096SDag-Erling Smørgrav extern int UNKNOWN_SERVER_NICENESS; 92b7579f77SDag-Erling Smørgrav /** maximum timeout before a host is deemed unsuitable, in msec. 93b7579f77SDag-Erling Smørgrav * After host_ttl this will be timed out and the host will be tried again. 94790c6b24SCy Schubert * Equals RTT_MAX_TIMEOUT, and thus when RTT_MAX_TIMEOUT is overwritten by 95790c6b24SCy Schubert * config infra_cache_max_rtt, it will be overwritten as well. */ 96790c6b24SCy Schubert extern int USEFUL_SERVER_TOP_TIMEOUT; 97790c6b24SCy Schubert /** penalty to validation failed blacklisted IPs 98790c6b24SCy Schubert * Equals USEFUL_SERVER_TOP_TIMEOUT*4, and thus when RTT_MAX_TIMEOUT is 99790c6b24SCy Schubert * overwritten by config infra_cache_max_rtt, it will be overwritten as well. */ 100790c6b24SCy Schubert extern int BLACKLIST_PENALTY; 101b7579f77SDag-Erling Smørgrav /** RTT band, within this amount from the best, servers are chosen randomly. 102b7579f77SDag-Erling Smørgrav * Chosen so that the UNKNOWN_SERVER_NICENESS falls within the band of a 103b7579f77SDag-Erling Smørgrav * fast server, this causes server exploration as a side benefit. msec. */ 104b7579f77SDag-Erling Smørgrav #define RTT_BAND 400 105103ba509SCy Schubert /** Number of retries for empty nodata packets before it is accepted. */ 106103ba509SCy Schubert #define EMPTY_NODATA_RETRY_COUNT 2 107b7579f77SDag-Erling Smørgrav 108b7579f77SDag-Erling Smørgrav /** 109*be771a7bSCy Schubert * Iterator global state for nat64. 110b7579f77SDag-Erling Smørgrav */ 111*be771a7bSCy Schubert struct iter_nat64 { 1128f76bb7dSCy Schubert /** A flag to locally apply NAT64 to make IPv4 addrs into IPv6 */ 1138f76bb7dSCy Schubert int use_nat64; 1148f76bb7dSCy Schubert 1158f76bb7dSCy Schubert /** NAT64 prefix address, cf. dns64_env->prefix_addr */ 1168f76bb7dSCy Schubert struct sockaddr_storage nat64_prefix_addr; 1178f76bb7dSCy Schubert 1188f76bb7dSCy Schubert /** sizeof(sockaddr_in6) */ 1198f76bb7dSCy Schubert socklen_t nat64_prefix_addrlen; 1208f76bb7dSCy Schubert 1218f76bb7dSCy Schubert /** CIDR mask length of NAT64 prefix */ 1228f76bb7dSCy Schubert int nat64_prefix_net; 123*be771a7bSCy Schubert }; 124*be771a7bSCy Schubert 125*be771a7bSCy Schubert /** 126*be771a7bSCy Schubert * Global state for the iterator. 127*be771a7bSCy Schubert */ 128*be771a7bSCy Schubert struct iter_env { 129*be771a7bSCy Schubert /** A flag to indicate whether or not we have an IPv6 route */ 130*be771a7bSCy Schubert int supports_ipv6; 131*be771a7bSCy Schubert 132*be771a7bSCy Schubert /** A flag to indicate whether or not we have an IPv4 route */ 133*be771a7bSCy Schubert int supports_ipv4; 134*be771a7bSCy Schubert 135*be771a7bSCy Schubert /** State for nat64 */ 136*be771a7bSCy Schubert struct iter_nat64 nat64; 1378f76bb7dSCy Schubert 138b7579f77SDag-Erling Smørgrav /** A set of inetaddrs that should never be queried. */ 139b7579f77SDag-Erling Smørgrav struct iter_donotq* donotq; 140b7579f77SDag-Erling Smørgrav 141b7579f77SDag-Erling Smørgrav /** private address space and private domains */ 142b7579f77SDag-Erling Smørgrav struct iter_priv* priv; 143b7579f77SDag-Erling Smørgrav 14409a3aaf3SDag-Erling Smørgrav /** whitelist for capsforid names */ 1453005e0a3SDag-Erling Smørgrav struct rbtree_type* caps_white; 14609a3aaf3SDag-Erling Smørgrav 147b7579f77SDag-Erling Smørgrav /** The maximum dependency depth that this resolver will pursue. */ 148b7579f77SDag-Erling Smørgrav int max_dependency_depth; 149b7579f77SDag-Erling Smørgrav 150b7579f77SDag-Erling Smørgrav /** 151b7579f77SDag-Erling Smørgrav * The target fetch policy for each dependency level. This is 152b7579f77SDag-Erling Smørgrav * described as a simple number (per dependency level): 153b7579f77SDag-Erling Smørgrav * negative numbers (usually just -1) mean fetch-all, 154b7579f77SDag-Erling Smørgrav * 0 means only fetch on demand, and 155b7579f77SDag-Erling Smørgrav * positive numbers mean to fetch at most that many targets. 156b7579f77SDag-Erling Smørgrav * array of max_dependency_depth+1 size. 157b7579f77SDag-Erling Smørgrav */ 158b7579f77SDag-Erling Smørgrav int* target_fetch_policy; 15905ab2901SDag-Erling Smørgrav 160971980c3SDag-Erling Smørgrav /** lock on ratelimit counter */ 161971980c3SDag-Erling Smørgrav lock_basic_type queries_ratelimit_lock; 162971980c3SDag-Erling Smørgrav /** number of queries that have been ratelimited */ 163971980c3SDag-Erling Smørgrav size_t num_queries_ratelimited; 16424e36522SCy Schubert 16524e36522SCy Schubert /** number of retries on outgoing queries */ 16624e36522SCy Schubert int outbound_msg_retry; 1671838dec3SCy Schubert 1681838dec3SCy Schubert /** number of queries_sent */ 1691838dec3SCy Schubert int max_sent_count; 1701838dec3SCy Schubert 1711838dec3SCy Schubert /** max number of query restarts to limit length of CNAME chain */ 1721838dec3SCy Schubert int max_query_restarts; 17305ab2901SDag-Erling Smørgrav }; 17405ab2901SDag-Erling Smørgrav 17505ab2901SDag-Erling Smørgrav /** 17605ab2901SDag-Erling Smørgrav * QNAME minimisation state 17705ab2901SDag-Erling Smørgrav */ 17805ab2901SDag-Erling Smørgrav enum minimisation_state { 17905ab2901SDag-Erling Smørgrav /** 18005ab2901SDag-Erling Smørgrav * (Re)start minimisation. Outgoing QNAME should be set to dp->name. 1818a384985SDag-Erling Smørgrav * State entered on new query or after following referral or CNAME. 18205ab2901SDag-Erling Smørgrav */ 18305ab2901SDag-Erling Smørgrav INIT_MINIMISE_STATE = 0, 18405ab2901SDag-Erling Smørgrav /** 1858a384985SDag-Erling Smørgrav * QNAME minimisation ongoing. Increase QNAME on every iteration. 18605ab2901SDag-Erling Smørgrav */ 18705ab2901SDag-Erling Smørgrav MINIMISE_STATE, 18805ab2901SDag-Erling Smørgrav /** 18905ab2901SDag-Erling Smørgrav * Don't increment QNAME this iteration 19005ab2901SDag-Erling Smørgrav */ 19105ab2901SDag-Erling Smørgrav SKIP_MINIMISE_STATE, 19205ab2901SDag-Erling Smørgrav /** 19305ab2901SDag-Erling Smørgrav * Send out full QNAME + original QTYPE 19405ab2901SDag-Erling Smørgrav */ 19505ab2901SDag-Erling Smørgrav DONOT_MINIMISE_STATE, 196b7579f77SDag-Erling Smørgrav }; 197b7579f77SDag-Erling Smørgrav 198b7579f77SDag-Erling Smørgrav /** 199b7579f77SDag-Erling Smørgrav * State of the iterator for a query. 200b7579f77SDag-Erling Smørgrav */ 201b7579f77SDag-Erling Smørgrav enum iter_state { 202b7579f77SDag-Erling Smørgrav /** 203b7579f77SDag-Erling Smørgrav * Externally generated queries start at this state. Query restarts are 204b7579f77SDag-Erling Smørgrav * reset to this state. 205b7579f77SDag-Erling Smørgrav */ 206b7579f77SDag-Erling Smørgrav INIT_REQUEST_STATE = 0, 207b7579f77SDag-Erling Smørgrav 208b7579f77SDag-Erling Smørgrav /** 209b7579f77SDag-Erling Smørgrav * Root priming events reactivate here, most other events pass 210b7579f77SDag-Erling Smørgrav * through this naturally as the 2nd part of the INIT_REQUEST_STATE. 211b7579f77SDag-Erling Smørgrav */ 212b7579f77SDag-Erling Smørgrav INIT_REQUEST_2_STATE, 213b7579f77SDag-Erling Smørgrav 214b7579f77SDag-Erling Smørgrav /** 215b7579f77SDag-Erling Smørgrav * Stub priming events reactivate here, most other events pass 216b7579f77SDag-Erling Smørgrav * through this naturally as the 3rd part of the INIT_REQUEST_STATE. 217b7579f77SDag-Erling Smørgrav */ 218b7579f77SDag-Erling Smørgrav INIT_REQUEST_3_STATE, 219b7579f77SDag-Erling Smørgrav 220b7579f77SDag-Erling Smørgrav /** 221b7579f77SDag-Erling Smørgrav * Each time a delegation point changes for a given query or a 222b7579f77SDag-Erling Smørgrav * query times out and/or wakes up, this state is (re)visited. 2238a384985SDag-Erling Smørgrav * This state is responsible for iterating through a list of 224b7579f77SDag-Erling Smørgrav * nameserver targets. 225b7579f77SDag-Erling Smørgrav */ 226b7579f77SDag-Erling Smørgrav QUERYTARGETS_STATE, 227b7579f77SDag-Erling Smørgrav 228b7579f77SDag-Erling Smørgrav /** 229b7579f77SDag-Erling Smørgrav * Responses to queries start at this state. This state handles 230b7579f77SDag-Erling Smørgrav * the decision tree associated with handling responses. 231b7579f77SDag-Erling Smørgrav */ 232b7579f77SDag-Erling Smørgrav QUERY_RESP_STATE, 233b7579f77SDag-Erling Smørgrav 234b7579f77SDag-Erling Smørgrav /** Responses to priming queries finish at this state. */ 235b7579f77SDag-Erling Smørgrav PRIME_RESP_STATE, 236b7579f77SDag-Erling Smørgrav 237b7579f77SDag-Erling Smørgrav /** Collecting query class information, for qclass=ANY, when 238b7579f77SDag-Erling Smørgrav * it spawns off queries for every class, it returns here. */ 239b7579f77SDag-Erling Smørgrav COLLECT_CLASS_STATE, 240b7579f77SDag-Erling Smørgrav 241b7579f77SDag-Erling Smørgrav /** Find NS record to resolve DS record from, walking to the right 242b7579f77SDag-Erling Smørgrav * NS spot until we find it */ 243b7579f77SDag-Erling Smørgrav DSNS_FIND_STATE, 244b7579f77SDag-Erling Smørgrav 245b7579f77SDag-Erling Smørgrav /** Responses that are to be returned upstream end at this state. 246b7579f77SDag-Erling Smørgrav * As well as responses to target queries. */ 247b7579f77SDag-Erling Smørgrav FINISHED_STATE 248b7579f77SDag-Erling Smørgrav }; 249b7579f77SDag-Erling Smørgrav 250b7579f77SDag-Erling Smørgrav /** 2510a92a9fcSCy Schubert * Shared counters for queries. 2520a92a9fcSCy Schubert */ 2530a92a9fcSCy Schubert enum target_count_variables { 2540a92a9fcSCy Schubert /** Reference count for the shared iter_qstate->target_count. */ 2550a92a9fcSCy Schubert TARGET_COUNT_REF = 0, 2560a92a9fcSCy Schubert /** Number of target queries spawned for the query and subqueries. */ 2570a92a9fcSCy Schubert TARGET_COUNT_QUERIES, 2580a92a9fcSCy Schubert /** Number of nxdomain responses encountered. */ 2590a92a9fcSCy Schubert TARGET_COUNT_NX, 26056850988SCy Schubert /** Global quota on number of queries to upstream servers per 26156850988SCy Schubert * client request, that is never reset. */ 26256850988SCy Schubert TARGET_COUNT_GLOBAL_QUOTA, 2630a92a9fcSCy Schubert 2640a92a9fcSCy Schubert /** This should stay last here, it is used for the allocation */ 2650a92a9fcSCy Schubert TARGET_COUNT_MAX, 2660a92a9fcSCy Schubert }; 2670a92a9fcSCy Schubert 2680a92a9fcSCy Schubert /** 269b7579f77SDag-Erling Smørgrav * Per query state for the iterator module. 270b7579f77SDag-Erling Smørgrav */ 271b7579f77SDag-Erling Smørgrav struct iter_qstate { 272b7579f77SDag-Erling Smørgrav /** 273b7579f77SDag-Erling Smørgrav * State of the iterator module. 274b7579f77SDag-Erling Smørgrav * This is the state that event is in or should sent to -- all 275b7579f77SDag-Erling Smørgrav * requests should start with the INIT_REQUEST_STATE. All 276b7579f77SDag-Erling Smørgrav * responses should start with QUERY_RESP_STATE. Subsequent 277b7579f77SDag-Erling Smørgrav * processing of the event will change this state. 278b7579f77SDag-Erling Smørgrav */ 279b7579f77SDag-Erling Smørgrav enum iter_state state; 280b7579f77SDag-Erling Smørgrav 281b7579f77SDag-Erling Smørgrav /** 282b7579f77SDag-Erling Smørgrav * Final state for the iterator module. 283b7579f77SDag-Erling Smørgrav * This is the state that responses should be routed to once the 284b7579f77SDag-Erling Smørgrav * response is final. For externally initiated queries, this 285b7579f77SDag-Erling Smørgrav * will be FINISHED_STATE, locally initiated queries will have 286b7579f77SDag-Erling Smørgrav * different final states. 287b7579f77SDag-Erling Smørgrav */ 288b7579f77SDag-Erling Smørgrav enum iter_state final_state; 289b7579f77SDag-Erling Smørgrav 290b7579f77SDag-Erling Smørgrav /** 291b7579f77SDag-Erling Smørgrav * The depth of this query, this means the depth of recursion. 292b7579f77SDag-Erling Smørgrav * This address is needed for another query, which is an address 293b7579f77SDag-Erling Smørgrav * needed for another query, etc. Original client query has depth 0. 294b7579f77SDag-Erling Smørgrav */ 295b7579f77SDag-Erling Smørgrav int depth; 296b7579f77SDag-Erling Smørgrav 297b7579f77SDag-Erling Smørgrav /** 298b7579f77SDag-Erling Smørgrav * The response 299b7579f77SDag-Erling Smørgrav */ 300b7579f77SDag-Erling Smørgrav struct dns_msg* response; 301b7579f77SDag-Erling Smørgrav 302b7579f77SDag-Erling Smørgrav /** 303b7579f77SDag-Erling Smørgrav * This is a list of RRsets that must be prepended to the 304b7579f77SDag-Erling Smørgrav * ANSWER section of a response before being sent upstream. 305b7579f77SDag-Erling Smørgrav */ 306b7579f77SDag-Erling Smørgrav struct iter_prep_list* an_prepend_list; 307b7579f77SDag-Erling Smørgrav /** Last element of the prepend list */ 308b7579f77SDag-Erling Smørgrav struct iter_prep_list* an_prepend_last; 309b7579f77SDag-Erling Smørgrav 310b7579f77SDag-Erling Smørgrav /** 311b7579f77SDag-Erling Smørgrav * This is the list of RRsets that must be prepended to the 312b7579f77SDag-Erling Smørgrav * AUTHORITY section of the response before being sent upstream. 313b7579f77SDag-Erling Smørgrav */ 314b7579f77SDag-Erling Smørgrav struct iter_prep_list* ns_prepend_list; 315b7579f77SDag-Erling Smørgrav /** Last element of the authority prepend list */ 316b7579f77SDag-Erling Smørgrav struct iter_prep_list* ns_prepend_last; 317b7579f77SDag-Erling Smørgrav 318b7579f77SDag-Erling Smørgrav /** query name used for chasing the results. Initially the same as 319b7579f77SDag-Erling Smørgrav * the state qinfo, but after CNAMEs this will be different. 320b7579f77SDag-Erling Smørgrav * The query info used to elicit the results needed. */ 321b7579f77SDag-Erling Smørgrav struct query_info qchase; 322b7579f77SDag-Erling Smørgrav /** query flags to use when chasing the answer (i.e. RD flag) */ 323b7579f77SDag-Erling Smørgrav uint16_t chase_flags; 324b7579f77SDag-Erling Smørgrav /** true if we set RD bit because of last resort recursion lame query*/ 325b7579f77SDag-Erling Smørgrav int chase_to_rd; 326b7579f77SDag-Erling Smørgrav 327b7579f77SDag-Erling Smørgrav /** 328b7579f77SDag-Erling Smørgrav * This is the current delegation point for an in-progress query. This 329b7579f77SDag-Erling Smørgrav * object retains state as to which delegation targets need to be 330b7579f77SDag-Erling Smørgrav * (sub)queried for vs which ones have already been visited. 331b7579f77SDag-Erling Smørgrav */ 332b7579f77SDag-Erling Smørgrav struct delegpt* dp; 333b7579f77SDag-Erling Smørgrav 334b7579f77SDag-Erling Smørgrav /** state for 0x20 fallback when capsfail happens, 0 not a fallback */ 335b7579f77SDag-Erling Smørgrav int caps_fallback; 336b7579f77SDag-Erling Smørgrav /** state for capsfail: current server number to try */ 337b7579f77SDag-Erling Smørgrav size_t caps_server; 338ff825849SDag-Erling Smørgrav /** state for capsfail: stored query for comparisons. Can be NULL if 339ff825849SDag-Erling Smørgrav * no response had been seen prior to starting the fallback. */ 340b7579f77SDag-Erling Smørgrav struct reply_info* caps_reply; 34109a3aaf3SDag-Erling Smørgrav struct dns_msg* caps_response; 342b7579f77SDag-Erling Smørgrav 343b7579f77SDag-Erling Smørgrav /** Current delegation message - returned for non-RD queries */ 344b7579f77SDag-Erling Smørgrav struct dns_msg* deleg_msg; 345b7579f77SDag-Erling Smørgrav 346b7579f77SDag-Erling Smørgrav /** number of outstanding target sub queries */ 347b7579f77SDag-Erling Smørgrav int num_target_queries; 348b7579f77SDag-Erling Smørgrav 349b7579f77SDag-Erling Smørgrav /** outstanding direct queries */ 350b7579f77SDag-Erling Smørgrav int num_current_queries; 351b7579f77SDag-Erling Smørgrav 352b7579f77SDag-Erling Smørgrav /** the number of times this query has been restarted. */ 353b7579f77SDag-Erling Smørgrav int query_restart_count; 354b7579f77SDag-Erling Smørgrav 355865f46b2SCy Schubert /** the number of times this query has followed a referral. */ 356b7579f77SDag-Erling Smørgrav int referral_count; 357b7579f77SDag-Erling Smørgrav 358b7579f77SDag-Erling Smørgrav /** number of queries fired off */ 359b7579f77SDag-Erling Smørgrav int sent_count; 360b7579f77SDag-Erling Smørgrav 3610a92a9fcSCy Schubert /** malloced-array shared with this query and its subqueries. It keeps 3620a92a9fcSCy Schubert * track of the defined enum target_count_variables counters. */ 36352df462fSXin LI int* target_count; 36452df462fSXin LI 365091e9e46SCy Schubert /** number of target lookups per delegation point. Reset to 0 after 366091e9e46SCy Schubert * receiving referral answer. Not shared with subqueries. */ 367091e9e46SCy Schubert int dp_target_count; 368091e9e46SCy Schubert 3690a92a9fcSCy Schubert /** Delegation point that triggered the NXNS fallback; shared with 3700a92a9fcSCy Schubert * this query and its subqueries, count-referenced by the reference 3710a92a9fcSCy Schubert * counter in target_count. 3720a92a9fcSCy Schubert * This also marks the fallback activation. */ 3730a92a9fcSCy Schubert uint8_t** nxns_dp; 3740a92a9fcSCy Schubert 37509a3aaf3SDag-Erling Smørgrav /** if true, already tested for ratelimiting and passed the test */ 37609a3aaf3SDag-Erling Smørgrav int ratelimit_ok; 37709a3aaf3SDag-Erling Smørgrav 378b7579f77SDag-Erling Smørgrav /** 379b7579f77SDag-Erling Smørgrav * The query must store NS records from referrals as parentside RRs 380b7579f77SDag-Erling Smørgrav * Enabled once it hits resolution problems, to throttle retries. 381b7579f77SDag-Erling Smørgrav * If enabled it is the pointer to the old delegation point with 382b7579f77SDag-Erling Smørgrav * the old retry counts for bad-nameserver-addresses. 383b7579f77SDag-Erling Smørgrav */ 384b7579f77SDag-Erling Smørgrav struct delegpt* store_parent_NS; 385b7579f77SDag-Erling Smørgrav 386b7579f77SDag-Erling Smørgrav /** 387b7579f77SDag-Erling Smørgrav * The query is for parent-side glue(A or AAAA) for a nameserver. 388b7579f77SDag-Erling Smørgrav * If the item is seen as glue in a referral, and pside_glue is NULL, 389b7579f77SDag-Erling Smørgrav * then it is stored in pside_glue for later. 390b7579f77SDag-Erling Smørgrav * If it was never seen, at the end, then a negative caching element 391b7579f77SDag-Erling Smørgrav * must be created. 392b7579f77SDag-Erling Smørgrav * The (data or negative) RR cache element then throttles retries. 393b7579f77SDag-Erling Smørgrav */ 394b7579f77SDag-Erling Smørgrav int query_for_pside_glue; 395b7579f77SDag-Erling Smørgrav /** the parent-side-glue element (NULL if none, its first match) */ 396b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key* pside_glue; 397b7579f77SDag-Erling Smørgrav 398b7579f77SDag-Erling Smørgrav /** If nonNULL we are walking upwards from DS query to find NS */ 399b7579f77SDag-Erling Smørgrav uint8_t* dsns_point; 400b7579f77SDag-Erling Smørgrav /** length of the dname in dsns_point */ 401b7579f77SDag-Erling Smørgrav size_t dsns_point_len; 402b7579f77SDag-Erling Smørgrav 403b7579f77SDag-Erling Smørgrav /** 404b7579f77SDag-Erling Smørgrav * expected dnssec information for this iteration step. 405b7579f77SDag-Erling Smørgrav * If dnssec rrsigs are expected and not given, the server is marked 406b7579f77SDag-Erling Smørgrav * lame (dnssec-lame). 407b7579f77SDag-Erling Smørgrav */ 408b7579f77SDag-Erling Smørgrav int dnssec_expected; 409b7579f77SDag-Erling Smørgrav 410b7579f77SDag-Erling Smørgrav /** 411b7579f77SDag-Erling Smørgrav * We are expecting dnssec information, but we also know the server 412b7579f77SDag-Erling Smørgrav * is DNSSEC lame. The response need not be marked dnssec-lame again. 413b7579f77SDag-Erling Smørgrav */ 414b7579f77SDag-Erling Smørgrav int dnssec_lame_query; 415b7579f77SDag-Erling Smørgrav 416b7579f77SDag-Erling Smørgrav /** 417b7579f77SDag-Erling Smørgrav * This is flag that, if true, means that this event is 418b7579f77SDag-Erling Smørgrav * waiting for a stub priming query. 419b7579f77SDag-Erling Smørgrav */ 420b7579f77SDag-Erling Smørgrav int wait_priming_stub; 421b7579f77SDag-Erling Smørgrav 422b7579f77SDag-Erling Smørgrav /** 423b7579f77SDag-Erling Smørgrav * This is a flag that, if true, means that this query is 424b7579f77SDag-Erling Smørgrav * for (re)fetching glue from a zone. Since the address should 425b7579f77SDag-Erling Smørgrav * have been glue, query again to the servers that should have 426b7579f77SDag-Erling Smørgrav * been returning it as glue. 427b7579f77SDag-Erling Smørgrav * The delegation point must be set to the one that should *not* 428b7579f77SDag-Erling Smørgrav * be used when creating the state. A higher one will be attempted. 429b7579f77SDag-Erling Smørgrav */ 430b7579f77SDag-Erling Smørgrav int refetch_glue; 431b7579f77SDag-Erling Smørgrav 432103ba509SCy Schubert /** 433103ba509SCy Schubert * This flag detects that a completely empty nodata was received, 434103ba509SCy Schubert * already so that it is accepted later. */ 435103ba509SCy Schubert int empty_nodata_found; 436103ba509SCy Schubert 437b7579f77SDag-Erling Smørgrav /** list of pending queries to authoritative servers. */ 438b7579f77SDag-Erling Smørgrav struct outbound_list outlist; 43905ab2901SDag-Erling Smørgrav 4409cf5bc93SCy Schubert /** QNAME minimisation state, RFC9156 */ 44105ab2901SDag-Erling Smørgrav enum minimisation_state minimisation_state; 44205ab2901SDag-Erling Smørgrav 4434c75e3aaSDag-Erling Smørgrav /** State for capsfail: QNAME minimisation state for comparisons. */ 4444c75e3aaSDag-Erling Smørgrav enum minimisation_state caps_minimisation_state; 4454c75e3aaSDag-Erling Smørgrav 44605ab2901SDag-Erling Smørgrav /** 44705ab2901SDag-Erling Smørgrav * The query info that is sent upstream. Will be a subset of qchase 44805ab2901SDag-Erling Smørgrav * when qname minimisation is enabled. 44905ab2901SDag-Erling Smørgrav */ 45005ab2901SDag-Erling Smørgrav struct query_info qinfo_out; 451e2d15004SDag-Erling Smørgrav 452e2d15004SDag-Erling Smørgrav /** 4538a384985SDag-Erling Smørgrav * Count number of QNAME minimisation iterations. Used to limit number of 454e2d15004SDag-Erling Smørgrav * outgoing queries when QNAME minimisation is enabled. 455e2d15004SDag-Erling Smørgrav */ 456e2d15004SDag-Erling Smørgrav int minimise_count; 457b5663de9SDag-Erling Smørgrav 458b5663de9SDag-Erling Smørgrav /** 459b5663de9SDag-Erling Smørgrav * Count number of time-outs. Used to prevent resolving failures when 46025039b37SCy Schubert * the QNAME minimisation QTYPE is blocked. Used to determine if 46125039b37SCy Schubert * capsforid fallback should be started.*/ 46225039b37SCy Schubert int timeout_count; 46357bddd21SDag-Erling Smørgrav 46457bddd21SDag-Erling Smørgrav /** True if the current response is from auth_zone */ 46557bddd21SDag-Erling Smørgrav int auth_zone_response; 46657bddd21SDag-Erling Smørgrav /** True if the auth_zones should not be consulted for the query */ 46757bddd21SDag-Erling Smørgrav int auth_zone_avoid; 4685469a995SCy Schubert /** true if there have been scrubbing failures of reply packets */ 4695469a995SCy Schubert int scrub_failures; 4705469a995SCy Schubert /** true if there have been parse failures of reply packets */ 4715469a995SCy Schubert int parse_failures; 4725469a995SCy Schubert /** a failure printout address for last received answer */ 4738f76bb7dSCy Schubert union { 4748f76bb7dSCy Schubert struct in_addr in; 4758f76bb7dSCy Schubert #ifdef AF_INET6 4768f76bb7dSCy Schubert struct in6_addr in6; 4778f76bb7dSCy Schubert #endif 4788f76bb7dSCy Schubert } fail_addr; 4798f76bb7dSCy Schubert /** which fail_addr, 0 is nothing, 4 or 6 */ 4808f76bb7dSCy Schubert int fail_addr_type; 481b7579f77SDag-Erling Smørgrav }; 482b7579f77SDag-Erling Smørgrav 483b7579f77SDag-Erling Smørgrav /** 484b7579f77SDag-Erling Smørgrav * List of prepend items 485b7579f77SDag-Erling Smørgrav */ 486b7579f77SDag-Erling Smørgrav struct iter_prep_list { 487b7579f77SDag-Erling Smørgrav /** next in list */ 488b7579f77SDag-Erling Smørgrav struct iter_prep_list* next; 489b7579f77SDag-Erling Smørgrav /** rrset */ 490b7579f77SDag-Erling Smørgrav struct ub_packed_rrset_key* rrset; 491b7579f77SDag-Erling Smørgrav }; 492b7579f77SDag-Erling Smørgrav 493b7579f77SDag-Erling Smørgrav /** 494b7579f77SDag-Erling Smørgrav * Get the iterator function block. 495b7579f77SDag-Erling Smørgrav * @return: function block with function pointers to iterator methods. 496b7579f77SDag-Erling Smørgrav */ 497b7579f77SDag-Erling Smørgrav struct module_func_block* iter_get_funcblock(void); 498b7579f77SDag-Erling Smørgrav 499b7579f77SDag-Erling Smørgrav /** 500b7579f77SDag-Erling Smørgrav * Get iterator state as a string 501b7579f77SDag-Erling Smørgrav * @param state: to convert 502b7579f77SDag-Erling Smørgrav * @return constant string that is printable. 503b7579f77SDag-Erling Smørgrav */ 504b7579f77SDag-Erling Smørgrav const char* iter_state_to_string(enum iter_state state); 505b7579f77SDag-Erling Smørgrav 506b7579f77SDag-Erling Smørgrav /** 507b7579f77SDag-Erling Smørgrav * See if iterator state is a response state 508b7579f77SDag-Erling Smørgrav * @param s: to inspect 509b7579f77SDag-Erling Smørgrav * @return true if response state. 510b7579f77SDag-Erling Smørgrav */ 511b7579f77SDag-Erling Smørgrav int iter_state_is_responsestate(enum iter_state s); 512b7579f77SDag-Erling Smørgrav 513b7579f77SDag-Erling Smørgrav /** iterator init */ 514b7579f77SDag-Erling Smørgrav int iter_init(struct module_env* env, int id); 515b7579f77SDag-Erling Smørgrav 516b7579f77SDag-Erling Smørgrav /** iterator deinit */ 517b7579f77SDag-Erling Smørgrav void iter_deinit(struct module_env* env, int id); 518b7579f77SDag-Erling Smørgrav 519b7579f77SDag-Erling Smørgrav /** iterator operate on a query */ 520b7579f77SDag-Erling Smørgrav void iter_operate(struct module_qstate* qstate, enum module_ev event, int id, 521b7579f77SDag-Erling Smørgrav struct outbound_entry* outbound); 522b7579f77SDag-Erling Smørgrav 523b7579f77SDag-Erling Smørgrav /** 5248a384985SDag-Erling Smørgrav * Return priming query results to interested super querystates. 525b7579f77SDag-Erling Smørgrav * 526b7579f77SDag-Erling Smørgrav * Sets the delegation point and delegation message (not nonRD queries). 527b7579f77SDag-Erling Smørgrav * This is a callback from walk_supers. 528b7579f77SDag-Erling Smørgrav * 529b7579f77SDag-Erling Smørgrav * @param qstate: query state that finished. 530b7579f77SDag-Erling Smørgrav * @param id: module id. 531b7579f77SDag-Erling Smørgrav * @param super: the qstate to inform. 532b7579f77SDag-Erling Smørgrav */ 533b7579f77SDag-Erling Smørgrav void iter_inform_super(struct module_qstate* qstate, int id, 534b7579f77SDag-Erling Smørgrav struct module_qstate* super); 535b7579f77SDag-Erling Smørgrav 536b7579f77SDag-Erling Smørgrav /** iterator cleanup query state */ 537b7579f77SDag-Erling Smørgrav void iter_clear(struct module_qstate* qstate, int id); 538b7579f77SDag-Erling Smørgrav 539b7579f77SDag-Erling Smørgrav /** iterator alloc size routine */ 540b7579f77SDag-Erling Smørgrav size_t iter_get_mem(struct module_env* env, int id); 541b7579f77SDag-Erling Smørgrav 542b7579f77SDag-Erling Smørgrav #endif /* ITERATOR_ITERATOR_H */ 543