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 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.
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"
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;
183 ldns_rdf* rdf;
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) {
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);
195 log_err("out of memory");
196 return NULL;
197 }
198 ldns_rdf_deep_free(rdf);
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;
208 for(p = s->hosts; p; p = p->next) {
209 log_assert(p->str);
210 rdf = ldns_dname_new_frm_str(p->str);
211 if(!rdf) {
212 log_err("cannot parse forward %s server name: '%s'",
213 s->name, p->str);
214 return 0;
215 }
216 if(!delegpt_add_ns_mlc(dp, ldns_rdf_data(rdf), 0)) {
217 ldns_rdf_deep_free(rdf);
218 log_err("out of memory");
219 return 0;
220 }
221 ldns_rdf_deep_free(rdf);
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;
293 for(s = cfg->stubs; s; s = s->next) {
294 ldns_rdf* rdf = ldns_dname_new_frm_str(s->name);
295 if(!rdf) {
296 log_err("cannot parse stub name '%s'", s->name);
297 return 0;
298 }
299 if(!fwd_add_stub_hole(fwd, LDNS_RR_CLASS_IN,
300 ldns_rdf_data(rdf))) {
301 ldns_rdf_deep_free(rdf);
302 log_err("out of memory");
303 return 0;
304 }
305 ldns_rdf_deep_free(rdf);
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*
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 ---