iter_donotq.h revision 238106
1164190Sjkoshy/* 2164190Sjkoshy * iterator/iter_donotq.h - iterative resolver donotqueryaddresses storage. 3164190Sjkoshy * 4164190Sjkoshy * Copyright (c) 2007, NLnet Labs. All rights reserved. 5164190Sjkoshy * 6164190Sjkoshy * This software is open source. 7164190Sjkoshy * 8164190Sjkoshy * Redistribution and use in source and binary forms, with or without 9164190Sjkoshy * modification, are permitted provided that the following conditions 10164190Sjkoshy * are met: 11164190Sjkoshy * 12164190Sjkoshy * Redistributions of source code must retain the above copyright notice, 13164190Sjkoshy * this list of conditions and the following disclaimer. 14164190Sjkoshy * 15164190Sjkoshy * Redistributions in binary form must reproduce the above copyright notice, 16164190Sjkoshy * this list of conditions and the following disclaimer in the documentation 17164190Sjkoshy * and/or other materials provided with the distribution. 18164190Sjkoshy * 19164190Sjkoshy * Neither the name of the NLNET LABS nor the names of its contributors may 20164190Sjkoshy * be used to endorse or promote products derived from this software without 21164190Sjkoshy * specific prior written permission. 22164190Sjkoshy * 23164190Sjkoshy * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24164190Sjkoshy * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 25164190Sjkoshy * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26164190Sjkoshy * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 27165317Sjkoshy * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28164190Sjkoshy * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29164190Sjkoshy * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30164190Sjkoshy * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31165317Sjkoshy * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32165317Sjkoshy * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33165317Sjkoshy * POSSIBILITY OF SUCH DAMAGE. 34164190Sjkoshy */ 35164190Sjkoshy 36164190Sjkoshy/** 37164190Sjkoshy * \file 38164190Sjkoshy * 39165317Sjkoshy * This file contains functions to assist the iterator module. 40164190Sjkoshy * Keep track of the donotquery addresses and lookup fast. 41164190Sjkoshy */ 42164190Sjkoshy 43164190Sjkoshy#ifndef ITERATOR_ITER_DONOTQ_H 44164190Sjkoshy#define ITERATOR_ITER_DONOTQ_H 45164190Sjkoshy#include "util/storage/dnstree.h" 46164190Sjkoshystruct iter_env; 47164190Sjkoshystruct config_file; 48164190Sjkoshystruct regional; 49164190Sjkoshy 50164190Sjkoshy/** 51164225Sjkoshy * Iterator donotqueryaddresses structure 52164225Sjkoshy */ 53164190Sjkoshystruct iter_donotq { 54164190Sjkoshy /** regional for allocation */ 55164577Sru struct regional* region; 56164577Sru /** 57164225Sjkoshy * Tree of the address spans that are blocked. 58164190Sjkoshy * contents of type addr_tree_node. Each node is an address span 59164190Sjkoshy * that must not be used to send queries to. 60164190Sjkoshy */ 61164190Sjkoshy rbtree_t tree; 62164190Sjkoshy}; 63164190Sjkoshy 64164190Sjkoshy/** 65164190Sjkoshy * Create donotqueryaddresses structure 66164190Sjkoshy * @return new structure or NULL on error. 67164190Sjkoshy */ 68164190Sjkoshystruct iter_donotq* donotq_create(void); 69164190Sjkoshy 70164190Sjkoshy/** 71164190Sjkoshy * Delete donotqueryaddresses structure. 72164190Sjkoshy * @param donotq: to delete. 73164190Sjkoshy */ 74164190Sjkoshyvoid donotq_delete(struct iter_donotq* donotq); 75164190Sjkoshy 76164190Sjkoshy/** 77164190Sjkoshy * Process donotqueryaddresses config. 78164190Sjkoshy * @param donotq: where to store. 79164190Sjkoshy * @param cfg: config options. 80164190Sjkoshy * @return 0 on error. 81164190Sjkoshy */ 82164190Sjkoshyint donotq_apply_cfg(struct iter_donotq* donotq, struct config_file* cfg); 83164190Sjkoshy 84164190Sjkoshy/** 85164190Sjkoshy * See if an address is blocked. 86164190Sjkoshy * @param donotq: structure for address storage. 87164190Sjkoshy * @param addr: address to check 88164190Sjkoshy * @param addrlen: length of addr. 89164190Sjkoshy * @return: true if the address must not be queried. false if unlisted. 90164190Sjkoshy */ 91164190Sjkoshyint donotq_lookup(struct iter_donotq* donotq, struct sockaddr_storage* addr, 92164190Sjkoshy socklen_t addrlen); 93164190Sjkoshy 94164190Sjkoshy/** 95164190Sjkoshy * Get memory used by donotqueryaddresses structure. 96164190Sjkoshy * @param donotq: structure for address storage. 97164190Sjkoshy * @return bytes in use. 98164190Sjkoshy */ 99164190Sjkoshysize_t donotq_get_mem(struct iter_donotq* donotq); 100164190Sjkoshy 101164190Sjkoshy#endif /* ITERATOR_ITER_DONOTQ_H */ 102164190Sjkoshy