1238106Sdes/* 2238106Sdes * iterator/iter_hints.h - iterative resolver module stub and root hints. 3238106Sdes * 4238106Sdes * Copyright (c) 2007, NLnet Labs. All rights reserved. 5238106Sdes * 6238106Sdes * This software is open source. 7238106Sdes * 8238106Sdes * Redistribution and use in source and binary forms, with or without 9238106Sdes * modification, are permitted provided that the following conditions 10238106Sdes * are met: 11238106Sdes * 12238106Sdes * Redistributions of source code must retain the above copyright notice, 13238106Sdes * this list of conditions and the following disclaimer. 14238106Sdes * 15238106Sdes * Redistributions in binary form must reproduce the above copyright notice, 16238106Sdes * this list of conditions and the following disclaimer in the documentation 17238106Sdes * and/or other materials provided with the distribution. 18238106Sdes * 19238106Sdes * Neither the name of the NLNET LABS nor the names of its contributors may 20238106Sdes * be used to endorse or promote products derived from this software without 21238106Sdes * specific prior written permission. 22238106Sdes * 23238106Sdes * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24266114Sdes * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25266114Sdes * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26266114Sdes * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27266114Sdes * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28266114Sdes * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 29266114Sdes * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30266114Sdes * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31266114Sdes * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32266114Sdes * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33266114Sdes * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34238106Sdes */ 35238106Sdes 36238106Sdes/** 37238106Sdes * \file 38238106Sdes * 39238106Sdes * This file contains functions to assist the iterator module. 40238106Sdes * Keep track of stub and root hints, and read those from config. 41238106Sdes */ 42238106Sdes 43238106Sdes#ifndef ITERATOR_ITER_HINTS_H 44238106Sdes#define ITERATOR_ITER_HINTS_H 45238106Sdes#include "util/storage/dnstree.h" 46238106Sdesstruct iter_env; 47238106Sdesstruct config_file; 48238106Sdesstruct delegpt; 49238106Sdes 50238106Sdes/** 51238106Sdes * Iterator hints structure 52238106Sdes */ 53238106Sdesstruct iter_hints { 54238106Sdes /** 55238106Sdes * Hints are stored in this tree. Sort order is specially chosen. 56238106Sdes * first sorted on qclass. Then on dname in nsec-like order, so that 57238106Sdes * a lookup on class, name will return an exact match or the closest 58238106Sdes * match which gives the ancestor needed. 59238106Sdes * contents of type iter_hints_stub. The class IN root is in here. 60238106Sdes * uses name_tree_node from dnstree.h. 61238106Sdes */ 62356345Scy rbtree_type tree; 63238106Sdes}; 64238106Sdes 65238106Sdes/** 66238106Sdes * Iterator hints for a particular stub. 67238106Sdes */ 68238106Sdesstruct iter_hints_stub { 69238106Sdes /** tree sorted by name, class */ 70238106Sdes struct name_tree_node node; 71238106Sdes /** delegation point with hint information for this stub. malloced. */ 72238106Sdes struct delegpt* dp; 73238106Sdes /** does the stub need to forego priming (like on other ports) */ 74238106Sdes uint8_t noprime; 75238106Sdes}; 76238106Sdes 77238106Sdes/** 78238106Sdes * Create hints 79238106Sdes * @return new hints or NULL on error. 80238106Sdes */ 81238106Sdesstruct iter_hints* hints_create(void); 82238106Sdes 83238106Sdes/** 84238106Sdes * Delete hints. 85238106Sdes * @param hints: to delete. 86238106Sdes */ 87238106Sdesvoid hints_delete(struct iter_hints* hints); 88238106Sdes 89238106Sdes/** 90238106Sdes * Process hints config. Sets default values for root hints if no config. 91238106Sdes * @param hints: where to store. 92238106Sdes * @param cfg: config options. 93238106Sdes * @return 0 on error. 94238106Sdes */ 95238106Sdesint hints_apply_cfg(struct iter_hints* hints, struct config_file* cfg); 96238106Sdes 97238106Sdes/** 98238106Sdes * Find root hints for the given class. 99238106Sdes * @param hints: hint storage. 100238106Sdes * @param qclass: class for which root hints are requested. host order. 101238106Sdes * @return: NULL if no hints, or a ptr to stored hints. 102238106Sdes */ 103238106Sdesstruct delegpt* hints_lookup_root(struct iter_hints* hints, uint16_t qclass); 104238106Sdes 105238106Sdes/** 106238106Sdes * Find next root hints (to cycle through all root hints). 107238106Sdes * @param hints: hint storage 108238106Sdes * @param qclass: class for which root hints are sought. 109238106Sdes * 0 means give the first available root hints class. 110238106Sdes * x means, give class x or a higher class if any. 111238106Sdes * returns the found class in this variable. 112238106Sdes * @return true if a root hint class is found. 113238106Sdes * false if not root hint class is found (qclass may have been changed). 114238106Sdes */ 115238106Sdesint hints_next_root(struct iter_hints* hints, uint16_t* qclass); 116238106Sdes 117238106Sdes/** 118238106Sdes * Given a qname/qclass combination, and the delegation point from the cache 119238106Sdes * for this qname/qclass, determine if this combination indicates that a 120238106Sdes * stub hint exists and must be primed. 121238106Sdes * 122238106Sdes * @param hints: hint storage. 123238106Sdes * @param qname: The qname that generated the delegation point. 124238106Sdes * @param qclass: The qclass that generated the delegation point. 125238106Sdes * @param dp: The cache generated delegation point. 126238106Sdes * @return: A priming delegation point if there is a stub hint that must 127238106Sdes * be primed, otherwise null. 128238106Sdes */ 129238106Sdesstruct iter_hints_stub* hints_lookup_stub(struct iter_hints* hints, 130238106Sdes uint8_t* qname, uint16_t qclass, struct delegpt* dp); 131238106Sdes 132238106Sdes/** 133238106Sdes * Get memory in use by hints 134238106Sdes * @param hints: hint storage. 135238106Sdes * @return bytes in use 136238106Sdes */ 137238106Sdessize_t hints_get_mem(struct iter_hints* hints); 138238106Sdes 139238106Sdes/** 140238106Sdes * Add stub to hints structure. For external use since it recalcs 141238106Sdes * the tree parents. 142238106Sdes * @param hints: the hints data structure 143238106Sdes * @param c: class of zone 144238106Sdes * @param dp: delegation point with name and target nameservers for new 145238106Sdes * hints stub. malloced. 146238106Sdes * @param noprime: set noprime option to true or false on new hint stub. 147238106Sdes * @return false on failure (out of memory); 148238106Sdes */ 149238106Sdesint hints_add_stub(struct iter_hints* hints, uint16_t c, struct delegpt* dp, 150238106Sdes int noprime); 151238106Sdes 152238106Sdes/** 153238106Sdes * Remove stub from hints structure. For external use since it 154238106Sdes * recalcs the tree parents. 155238106Sdes * @param hints: the hints data structure 156238106Sdes * @param c: class of stub zone 157238106Sdes * @param nm: name of stub zone (in uncompressed wireformat). 158238106Sdes */ 159238106Sdesvoid hints_delete_stub(struct iter_hints* hints, uint16_t c, uint8_t* nm); 160238106Sdes 161238106Sdes#endif /* ITERATOR_ITER_HINTS_H */ 162