2007-05-23 09:34:01 +00:00
|
|
|
/*
|
|
|
|
* iterator/iter_utils.h - iterative resolver module utility functions.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007, NLnet Labs. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software is open source.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* Neither the name of the NLNET LABS nor the names of its contributors may
|
|
|
|
* be used to endorse or promote products derived from this software without
|
|
|
|
* specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
*
|
|
|
|
* This file contains functions to assist the iterator module.
|
|
|
|
* Configuration options. Forward zones.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ITERATOR_ITER_UTILS_H
|
|
|
|
#define ITERATOR_ITER_UTILS_H
|
|
|
|
struct iter_env;
|
|
|
|
struct config_file;
|
2007-05-31 12:51:36 +00:00
|
|
|
struct module_env;
|
|
|
|
struct delegpt_addr;
|
|
|
|
struct delegpt;
|
2007-06-01 12:05:48 +00:00
|
|
|
struct region;
|
|
|
|
struct msg_parse;
|
2007-07-19 09:25:55 +00:00
|
|
|
struct ub_randstate;
|
2007-07-19 15:16:39 +00:00
|
|
|
struct query_info;
|
|
|
|
struct reply_info;
|
2007-05-23 09:34:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Process config options and set iterator module state.
|
|
|
|
* Sets default values if no config is found.
|
|
|
|
* @param iter_env: iterator module state.
|
|
|
|
* @param cfg: config options.
|
|
|
|
* @return 0 on error.
|
|
|
|
*/
|
|
|
|
int iter_apply_cfg(struct iter_env* iter_env, struct config_file* cfg);
|
|
|
|
|
2007-05-31 12:51:36 +00:00
|
|
|
/**
|
|
|
|
* Select a valid, nice target to send query to.
|
|
|
|
* Sorting and removing unsuitable targets is combined.
|
|
|
|
*
|
|
|
|
* @param iter_env: iterator module global state, with ip6 enabled and
|
|
|
|
* do-not-query-addresses.
|
|
|
|
* @param env: environment with infra cache (lameness, rtt info).
|
|
|
|
* @param dp: delegation point with result list.
|
|
|
|
* @param name: zone name (for lameness check).
|
|
|
|
* @param namelen: length of name.
|
|
|
|
* @return best target or NULL if no target.
|
|
|
|
* if not null, that target is removed from the result list in the dp.
|
|
|
|
*/
|
|
|
|
struct delegpt_addr* iter_server_selection(struct iter_env* iter_env,
|
|
|
|
struct module_env* env, struct delegpt* dp, uint8_t* name,
|
|
|
|
size_t namelen);
|
|
|
|
|
2007-06-01 12:05:48 +00:00
|
|
|
/**
|
|
|
|
* Allocate dns_msg from parsed msg, in region.
|
2007-06-01 12:52:07 +00:00
|
|
|
* @param pkt: packet.
|
2007-06-01 12:05:48 +00:00
|
|
|
* @param msg: parsed message (cleaned and ready for region allocation).
|
|
|
|
* @param region: region to use for allocation.
|
|
|
|
* @return newly allocated dns_msg, or NULL on memory error.
|
|
|
|
*/
|
2007-06-01 12:52:07 +00:00
|
|
|
struct dns_msg* dns_alloc_msg(ldns_buffer* pkt, struct msg_parse* msg,
|
|
|
|
struct region* region);
|
2007-06-01 12:05:48 +00:00
|
|
|
|
2007-06-04 12:22:38 +00:00
|
|
|
/**
|
|
|
|
* Copy a dns_msg to this region.
|
|
|
|
* @param from: dns message, also in region.
|
|
|
|
* @param region: region to use for allocation.
|
|
|
|
* @return newly allocated dns_msg, or NULL on memory error.
|
|
|
|
*/
|
|
|
|
struct dns_msg* dns_copy_msg(struct dns_msg* from, struct region* region);
|
|
|
|
|
2007-06-01 20:24:33 +00:00
|
|
|
/**
|
|
|
|
* Allocate a dns_msg with malloc/alloc structure and store in dns cache.
|
|
|
|
* @param env: environment, with alloc structure and dns cache.
|
2007-07-19 15:16:39 +00:00
|
|
|
* @param qinf: query info, the query for which answer is stored.
|
|
|
|
* @param rep: reply in dns_msg from dns_alloc_msg for example.
|
2007-06-01 20:24:33 +00:00
|
|
|
* @param is_referral: If true, then the given message to be stored is a
|
|
|
|
* referral. The cache implementation may use this as a hint.
|
|
|
|
* @return 0 on alloc error (out of memory).
|
|
|
|
*/
|
2007-07-19 15:16:39 +00:00
|
|
|
int iter_dns_store(struct module_env* env, struct query_info* qinf,
|
|
|
|
struct reply_info* rep, int is_referral);
|
2007-06-01 20:24:33 +00:00
|
|
|
|
2007-07-19 09:25:55 +00:00
|
|
|
/**
|
|
|
|
* Select randomly with n/m probability.
|
|
|
|
* For shuffle NS records for address fetching.
|
|
|
|
* @param rnd: random table
|
|
|
|
* @param n: probability.
|
|
|
|
* @param m: divisor for probability.
|
|
|
|
* @return true with n/m probability.
|
|
|
|
*/
|
|
|
|
int iter_ns_probability(struct ub_randstate* rnd, int n, int m);
|
|
|
|
|
2007-05-23 09:34:01 +00:00
|
|
|
#endif /* ITERATOR_ITER_UTILS_H */
|