Deleted Added
sdiff udiff text old ( 256281 ) new ( 269257 )
full compact
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
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"
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"
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;
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 }
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 }
193 if(!(dp=delegpt_create_mlc(dname))) {
194 free(dname);
195 log_err("out of memory");
196 return NULL;
197 }
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;
207 uint8_t* dname;
208 size_t dname_len;
209 for(p = s->hosts; p; p = p->next) {
210 log_assert(p->str);
211 dname = sldns_str2wire_dname(p->str, &dname_len);
212 if(!dname) {
213 log_err("cannot parse forward %s server name: '%s'",
214 s->name, p->str);
215 return 0;
216 }
217 if(!delegpt_add_ns_mlc(dp, dname, 0)) {
218 free(dname);
219 log_err("out of memory");
220 return 0;
221 }
222 free(dname);
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;
296 for(s = cfg->stubs; s; s = s->next) {
297 dname = sldns_str2wire_dname(s->name, &dname_len);
298 if(!dname) {
299 log_err("cannot parse stub name '%s'", s->name);
300 return 0;
301 }
302 if(!fwd_add_stub_hole(fwd, LDNS_RR_CLASS_IN, dname)) {
303 free(dname);
304 log_err("out of memory");
305 return 0;
306 }
307 free(dname);
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*
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 ---