iter_fwd.c (256281) | iter_fwd.c (269257) |
---|---|
1/* 2 * iterator/iter_fwd.c - iterative resolver module forward zones. 3 * 4 * Copyright (c) 2007, NLnet Labs. All rights reserved. 5 * 6 * This software is open source. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 7 unchanged lines hidden (view full) --- 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 19 * Neither the name of the NLNET LABS nor the names of its contributors may 20 * be used to endorse or promote products derived from this software without 21 * specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 1/* 2 * iterator/iter_fwd.c - iterative resolver module forward zones. 3 * 4 * Copyright (c) 2007, NLnet Labs. All rights reserved. 5 * 6 * This software is open source. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 7 unchanged lines hidden (view full) --- 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 19 * Neither the name of the NLNET LABS nor the names of its contributors may 20 * be used to endorse or promote products derived from this software without 21 * specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 * POSSIBILITY OF SUCH DAMAGE. | 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
34 */ 35 36/** 37 * \file 38 * 39 * This file contains functions to assist the iterator module. 40 * Keep track of forward zones and config settings. 41 */ 42#include "config.h" | 34 */ 35 36/** 37 * \file 38 * 39 * This file contains functions to assist the iterator module. 40 * Keep track of forward zones and config settings. 41 */ 42#include "config.h" |
43#include <ldns/rdata.h> 44#include <ldns/dname.h> 45#include <ldns/rr.h> | |
46#include "iterator/iter_fwd.h" 47#include "iterator/iter_delegpt.h" 48#include "util/log.h" 49#include "util/config_file.h" 50#include "util/net_help.h" 51#include "util/data/dname.h" | 43#include "iterator/iter_fwd.h" 44#include "iterator/iter_delegpt.h" 45#include "util/log.h" 46#include "util/config_file.h" 47#include "util/net_help.h" 48#include "util/data/dname.h" |
49#include "ldns/rrdef.h" 50#include "ldns/str2wire.h" |
|
52 53int 54fwd_cmp(const void* k1, const void* k2) 55{ 56 int m; 57 struct iter_forward_zone* n1 = (struct iter_forward_zone*)k1; 58 struct iter_forward_zone* n2 = (struct iter_forward_zone*)k2; 59 if(n1->dclass != n2->dclass) { --- 115 unchanged lines hidden (view full) --- 175 } 176} 177 178/** set zone name */ 179static struct delegpt* 180read_fwds_name(struct config_stub* s) 181{ 182 struct delegpt* dp; | 51 52int 53fwd_cmp(const void* k1, const void* k2) 54{ 55 int m; 56 struct iter_forward_zone* n1 = (struct iter_forward_zone*)k1; 57 struct iter_forward_zone* n2 = (struct iter_forward_zone*)k2; 58 if(n1->dclass != n2->dclass) { --- 115 unchanged lines hidden (view full) --- 174 } 175} 176 177/** set zone name */ 178static struct delegpt* 179read_fwds_name(struct config_stub* s) 180{ 181 struct delegpt* dp; |
183 ldns_rdf* rdf; | 182 uint8_t* dname; 183 size_t dname_len; |
184 if(!s->name) { 185 log_err("forward zone without a name (use name \".\" to forward everything)"); 186 return NULL; 187 } | 184 if(!s->name) { 185 log_err("forward zone without a name (use name \".\" to forward everything)"); 186 return NULL; 187 } |
188 rdf = ldns_dname_new_frm_str(s->name); 189 if(!rdf) { | 188 dname = sldns_str2wire_dname(s->name, &dname_len); 189 if(!dname) { |
190 log_err("cannot parse forward zone name %s", s->name); 191 return NULL; 192 } | 190 log_err("cannot parse forward zone name %s", s->name); 191 return NULL; 192 } |
193 if(!(dp=delegpt_create_mlc(ldns_rdf_data(rdf)))) { 194 ldns_rdf_deep_free(rdf); | 193 if(!(dp=delegpt_create_mlc(dname))) { 194 free(dname); |
195 log_err("out of memory"); 196 return NULL; 197 } | 195 log_err("out of memory"); 196 return NULL; 197 } |
198 ldns_rdf_deep_free(rdf); | 198 free(dname); |
199 return dp; 200} 201 202/** set fwd host names */ 203static int 204read_fwds_host(struct config_stub* s, struct delegpt* dp) 205{ 206 struct config_strlist* p; | 199 return dp; 200} 201 202/** set fwd host names */ 203static int 204read_fwds_host(struct config_stub* s, struct delegpt* dp) 205{ 206 struct config_strlist* p; |
207 ldns_rdf* rdf; | 207 uint8_t* dname; 208 size_t dname_len; |
208 for(p = s->hosts; p; p = p->next) { 209 log_assert(p->str); | 209 for(p = s->hosts; p; p = p->next) { 210 log_assert(p->str); |
210 rdf = ldns_dname_new_frm_str(p->str); 211 if(!rdf) { | 211 dname = sldns_str2wire_dname(p->str, &dname_len); 212 if(!dname) { |
212 log_err("cannot parse forward %s server name: '%s'", 213 s->name, p->str); 214 return 0; 215 } | 213 log_err("cannot parse forward %s server name: '%s'", 214 s->name, p->str); 215 return 0; 216 } |
216 if(!delegpt_add_ns_mlc(dp, ldns_rdf_data(rdf), 0)) { 217 ldns_rdf_deep_free(rdf); | 217 if(!delegpt_add_ns_mlc(dp, dname, 0)) { 218 free(dname); |
218 log_err("out of memory"); 219 return 0; 220 } | 219 log_err("out of memory"); 220 return 0; 221 } |
221 ldns_rdf_deep_free(rdf); | 222 free(dname); |
222 } 223 return 1; 224} 225 226/** set fwd server addresses */ 227static int 228read_fwds_addr(struct config_stub* s, struct delegpt* dp) 229{ --- 55 unchanged lines hidden (view full) --- 285 key.namelen, key.namelabs, NULL); 286} 287 288/** make NULL entries for stubs */ 289static int 290make_stub_holes(struct iter_forwards* fwd, struct config_file* cfg) 291{ 292 struct config_stub* s; | 223 } 224 return 1; 225} 226 227/** set fwd server addresses */ 228static int 229read_fwds_addr(struct config_stub* s, struct delegpt* dp) 230{ --- 55 unchanged lines hidden (view full) --- 286 key.namelen, key.namelabs, NULL); 287} 288 289/** make NULL entries for stubs */ 290static int 291make_stub_holes(struct iter_forwards* fwd, struct config_file* cfg) 292{ 293 struct config_stub* s; |
294 uint8_t* dname; 295 size_t dname_len; |
|
293 for(s = cfg->stubs; s; s = s->next) { | 296 for(s = cfg->stubs; s; s = s->next) { |
294 ldns_rdf* rdf = ldns_dname_new_frm_str(s->name); 295 if(!rdf) { | 297 dname = sldns_str2wire_dname(s->name, &dname_len); 298 if(!dname) { |
296 log_err("cannot parse stub name '%s'", s->name); 297 return 0; 298 } | 299 log_err("cannot parse stub name '%s'", s->name); 300 return 0; 301 } |
299 if(!fwd_add_stub_hole(fwd, LDNS_RR_CLASS_IN, 300 ldns_rdf_data(rdf))) { 301 ldns_rdf_deep_free(rdf); | 302 if(!fwd_add_stub_hole(fwd, LDNS_RR_CLASS_IN, dname)) { 303 free(dname); |
302 log_err("out of memory"); 303 return 0; 304 } | 304 log_err("out of memory"); 305 return 0; 306 } |
305 ldns_rdf_deep_free(rdf); | 307 free(dname); |
306 } 307 return 1; 308} 309 310int 311forwards_apply_cfg(struct iter_forwards* fwd, struct config_file* cfg) 312{ 313 fwd_del_tree(fwd); --- 6 unchanged lines hidden (view full) --- 320 return 0; 321 if(!make_stub_holes(fwd, cfg)) 322 return 0; 323 fwd_init_parents(fwd); 324 return 1; 325} 326 327struct delegpt* | 308 } 309 return 1; 310} 311 312int 313forwards_apply_cfg(struct iter_forwards* fwd, struct config_file* cfg) 314{ 315 fwd_del_tree(fwd); --- 6 unchanged lines hidden (view full) --- 322 return 0; 323 if(!make_stub_holes(fwd, cfg)) 324 return 0; 325 fwd_init_parents(fwd); 326 return 1; 327} 328 329struct delegpt* |
330forwards_find(struct iter_forwards* fwd, uint8_t* qname, uint16_t qclass) 331{ 332 rbnode_t* res = NULL; 333 struct iter_forward_zone key; 334 key.node.key = &key; 335 key.dclass = qclass; 336 key.name = qname; 337 key.namelabs = dname_count_size_labels(qname, &key.namelen); 338 res = rbtree_search(fwd->tree, &key); 339 if(res) return ((struct iter_forward_zone*)res)->dp; 340 return NULL; 341} 342 343struct delegpt* |
|
328forwards_lookup(struct iter_forwards* fwd, uint8_t* qname, uint16_t qclass) 329{ 330 /* lookup the forward zone in the tree */ 331 rbnode_t* res = NULL; 332 struct iter_forward_zone *result; 333 struct iter_forward_zone key; 334 key.node.key = &key; 335 key.dclass = qclass; --- 155 unchanged lines hidden --- | 344forwards_lookup(struct iter_forwards* fwd, uint8_t* qname, uint16_t qclass) 345{ 346 /* lookup the forward zone in the tree */ 347 rbnode_t* res = NULL; 348 struct iter_forward_zone *result; 349 struct iter_forward_zone key; 350 key.node.key = &key; 351 key.dclass = qclass; --- 155 unchanged lines hidden --- |