ldns documentation

- Main Page
- Related Pages
- Data Structures
- Files

- File List
- Globals

resolver.c
Go to the documentation of this file.
1 /*
2 * resolver.c
3 *
4 * resolver implementation
5 *
6 * a Net::DNS like library for C
7 *
8 * (c) NLnet Labs, 2004-2006
9 *
10 * See the file LICENSE for the license
11 */
12
13 #include <ldns/config.h>
14
15 #include <ldns/ldns.h>
16 #include <strings.h>
17
18 /* Access function for reading
19 * and setting the different Resolver
20 * options */
21
22 /* read */
23 uint16_t
24 ldns_resolver_port(const ldns_resolver *r)
25 {
26 return r->_port;
27 }
28
29 ldns_rdf *
30 ldns_resolver_source(const ldns_resolver *r)
31 {
32 return r->_source;
33 }
34
35 uint16_t
36 ldns_resolver_edns_udp_size(const ldns_resolver *r)
37 {
38 return r->_edns_udp_size;
39 }
40
41 uint8_t
42 ldns_resolver_retry(const ldns_resolver *r)
43 {
44 return r->_retry;
45 }
46
47 uint8_t
48 ldns_resolver_retrans(const ldns_resolver *r)
49 {
50 return r->_retrans;
51 }
52
53 bool
54 ldns_resolver_fallback(const ldns_resolver *r)
55 {
56 return r->_fallback;
57 }
58
59 uint8_t
60 ldns_resolver_ip6(const ldns_resolver *r)
61 {
62 return r->_ip6;
63 }
64
65 bool
66 ldns_resolver_recursive(const ldns_resolver *r)
67 {
68 return r->_recursive;
69 }
70
71 bool
72 ldns_resolver_debug(const ldns_resolver *r)
73 {
74 return r->_debug;
75 }
76
77 bool
78 ldns_resolver_dnsrch(const ldns_resolver *r)
79 {
80 return r->_dnsrch;
81 }
82
83 bool
84 ldns_resolver_fail(const ldns_resolver *r)
85 {
86 return r->_fail;
87 }
88
89 bool
90 ldns_resolver_defnames(const ldns_resolver *r)
91 {
92 return r->_defnames;
93 }
94
95 ldns_rdf *
96 ldns_resolver_domain(const ldns_resolver *r)
97 {
98 return r->_domain;
99 }
100
101 ldns_rdf **
102 ldns_resolver_searchlist(const ldns_resolver *r)
103 {
104 return r->_searchlist;
105 }
106
107 ldns_rdf **
108 ldns_resolver_nameservers(const ldns_resolver *r)
109 {
110 return r->_nameservers;
111 }
112
113 size_t
114 ldns_resolver_nameserver_count(const ldns_resolver *r)
115 {
116 return r->_nameserver_count;
117 }
118
119 bool
120 ldns_resolver_dnssec(const ldns_resolver *r)
121 {
122 return r->_dnssec;
123 }
124
125 bool
126 ldns_resolver_dnssec_cd(const ldns_resolver *r)
127 {
128 return r->_dnssec_cd;
129 }
130
131 ldns_rr_list *
132 ldns_resolver_dnssec_anchors(const ldns_resolver *r)
133 {
134 return r->_dnssec_anchors;
135 }
136
137 bool
138 ldns_resolver_trusted_key(const ldns_resolver *r, ldns_rr_list * keys, ldns_rr_list * trusted_keys)
139 {
140 size_t i;
141 bool result = false;
142
143 ldns_rr_list * trust_anchors;
144 ldns_rr * cur_rr;
145
146 if (!r || !keys) { return false; }
147
148 trust_anchors = ldns_resolver_dnssec_anchors(r);
149
150 if (!trust_anchors) { return false; }
151
152 for (i = 0; i < ldns_rr_list_rr_count(keys); i++) {
153
154 cur_rr = ldns_rr_list_rr(keys, i);
155 if (ldns_rr_list_contains_rr(trust_anchors, cur_rr)) {
156 if (trusted_keys) { ldns_rr_list_push_rr(trusted_keys, cur_rr); }
157 result = true;
158 }
159 }
160
161 return result;
162 }
163
164 bool
165 ldns_resolver_igntc(const ldns_resolver *r)
166 {
167 return r->_igntc;
168 }
169
170 bool
171 ldns_resolver_usevc(const ldns_resolver *r)
172 {
173 return r->_usevc;
174 }
175
176 size_t *
177 ldns_resolver_rtt(const ldns_resolver *r)
178 {
179 return r->_rtt;
180 }
181
182 size_t
183 ldns_resolver_nameserver_rtt(const ldns_resolver *r, size_t pos)
184 {
185 size_t *rtt;
186
187 assert(r != NULL);
188
189 rtt = ldns_resolver_rtt(r);
190
191 if (pos >= ldns_resolver_nameserver_count(r)) {
192 /* error ?*/
193 return 0;
194 } else {
195 return rtt[pos];
196 }
197
198 }
199
200 struct timeval
201 ldns_resolver_timeout(const ldns_resolver *r)
202 {
203 return r->_timeout;
204 }
205
206 char *
207 ldns_resolver_tsig_keyname(const ldns_resolver *r)
208 {
209 return r->_tsig_keyname;
210 }
211
212 char *
213 ldns_resolver_tsig_algorithm(const ldns_resolver *r)
214 {
215 return r->_tsig_algorithm;
216 }
217
218 char *
219 ldns_resolver_tsig_keydata(const ldns_resolver *r)
220 {
221 return r->_tsig_keydata;
222 }
223
224 bool
225 ldns_resolver_random(const ldns_resolver *r)
226 {
227 return r->_random;
228 }
229
230 size_t
231 ldns_resolver_searchlist_count(const ldns_resolver *r)
232 {
233 return r->_searchlist_count;
234 }
235
236 /* write */
237 void
238 ldns_resolver_set_port(ldns_resolver *r, uint16_t p)
239 {
240 r->_port = p;
241 }
242
243 void
244 ldns_resolver_set_source(ldns_resolver *r, ldns_rdf *s)
245 {
246 r->_source = s;
247 }
248
249 ldns_rdf *
250 ldns_resolver_pop_nameserver(ldns_resolver *r)
251 {
252 ldns_rdf **nameservers;
253 ldns_rdf *pop;
254 size_t ns_count;
255 size_t *rtt;
256
257 assert(r != NULL);
258
259 ns_count = ldns_resolver_nameserver_count(r);
260 nameservers = ldns_resolver_nameservers(r);
261 rtt = ldns_resolver_rtt(r);
262 if (ns_count == 0 || !nameservers) {
263 return NULL;
264 }
265
266 pop = nameservers[ns_count - 1];
267
268 if (ns_count == 1) {
269 LDNS_FREE(nameservers);
270 LDNS_FREE(rtt);
271
272 ldns_resolver_set_nameservers(r, NULL);
273 ldns_resolver_set_rtt(r, NULL);
274 } else {
275 nameservers = LDNS_XREALLOC(nameservers, ldns_rdf *,
276 (ns_count - 1));
277 rtt = LDNS_XREALLOC(rtt, size_t, (ns_count - 1));
278
279 ldns_resolver_set_nameservers(r, nameservers);
280 ldns_resolver_set_rtt(r, rtt);
281 }
282 /* decr the count */
283 ldns_resolver_dec_nameserver_count(r);
284 return pop;
285 }
286
287 ldns_status
288 ldns_resolver_push_nameserver(ldns_resolver *r, ldns_rdf *n)
289 {
290 ldns_rdf **nameservers;
291 size_t ns_count;
292 size_t *rtt;
293
294 if (ldns_rdf_get_type(n) != LDNS_RDF_TYPE_A &&
295 ldns_rdf_get_type(n) != LDNS_RDF_TYPE_AAAA) {
296 return LDNS_STATUS_ERR;
297 }
298
299 ns_count = ldns_resolver_nameserver_count(r);
300 nameservers = ldns_resolver_nameservers(r);
301 rtt = ldns_resolver_rtt(r);
302
303 /* make room for the next one */
304 if (ns_count == 0) {
305 nameservers = LDNS_XMALLOC(ldns_rdf *, 1);
306 } else {
307 nameservers = LDNS_XREALLOC(nameservers, ldns_rdf *, (ns_count + 1));
308 }
309 if(!nameservers)
310 return LDNS_STATUS_MEM_ERR;
311
312 /* set the new value in the resolver */
313 ldns_resolver_set_nameservers(r, nameservers);
314
315 /* don't forget the rtt */
316 if (ns_count == 0) {
317 rtt = LDNS_XMALLOC(size_t, 1);
318 } else {
319 rtt = LDNS_XREALLOC(rtt, size_t, (ns_count + 1));
320 }
321 if(!rtt)
322 return LDNS_STATUS_MEM_ERR;
323
324 /* slide n in its slot. */
325 /* we clone it here, because then we can free the original
326 * rr's where it stood */
327 nameservers[ns_count] = ldns_rdf_clone(n);
328 rtt[ns_count] = LDNS_RESOLV_RTT_MIN;
329 ldns_resolver_incr_nameserver_count(r);
330 ldns_resolver_set_rtt(r, rtt);
331 return LDNS_STATUS_OK;
332 }
333
334 ldns_status
335 ldns_resolver_push_nameserver_rr(ldns_resolver *r, ldns_rr *rr)
336 {
337 ldns_rdf *address;
338 if ((!rr) || (ldns_rr_get_type(rr) != LDNS_RR_TYPE_A &&
339 ldns_rr_get_type(rr) != LDNS_RR_TYPE_AAAA)) {
340 return LDNS_STATUS_ERR;
341 }
342 address = ldns_rr_rdf(rr, 0); /* extract the ip number */
343 if (address) {
344 return ldns_resolver_push_nameserver(r, address);
345 } else {
346 return LDNS_STATUS_ERR;
347 }
348 }
349
350 ldns_status
351 ldns_resolver_push_nameserver_rr_list(ldns_resolver *r, ldns_rr_list *rrlist)
352 {
353 ldns_rr *rr;
354 ldns_status stat;
355 size_t i;
356
357 stat = LDNS_STATUS_OK;
358 if (rrlist) {
359 for(i = 0; i < ldns_rr_list_rr_count(rrlist); i++) {
360 rr = ldns_rr_list_rr(rrlist, i);
361 if (ldns_resolver_push_nameserver_rr(r, rr) != LDNS_STATUS_OK) {
362 stat = LDNS_STATUS_ERR;
363 break;
364 }
365 }
366 return stat;
367 } else {
368 return LDNS_STATUS_ERR;
369 }
370 }
371
372 void
373 ldns_resolver_set_edns_udp_size(ldns_resolver *r, uint16_t s)
374 {
375 r->_edns_udp_size = s;
376 }
377
378 void
379 ldns_resolver_set_recursive(ldns_resolver *r, bool re)
380 {
381 r->_recursive = re;
382 }
383
384 void
385 ldns_resolver_set_dnssec(ldns_resolver *r, bool d)
386 {
387 r->_dnssec = d;
388 }
389
390 void
391 ldns_resolver_set_dnssec_cd(ldns_resolver *r, bool d)
392 {
393 r->_dnssec_cd = d;
394 }
395
396 void
397 ldns_resolver_set_dnssec_anchors(ldns_resolver *r, ldns_rr_list * l)
398 {
399 r->_dnssec_anchors = l;
400 }
401
402 ldns_status
403 ldns_resolver_push_dnssec_anchor(ldns_resolver *r, ldns_rr *rr)
404 {
405 ldns_rr_list * trust_anchors;
406
407 if ((!rr) || (ldns_rr_get_type(rr) != LDNS_RR_TYPE_DNSKEY &&
408 ldns_rr_get_type(rr) != LDNS_RR_TYPE_DS)) {
409
410 return LDNS_STATUS_ERR;
411 }
412
413 if (!(trust_anchors = ldns_resolver_dnssec_anchors(r))) { /* Initialize */
414 trust_anchors = ldns_rr_list_new();
415 ldns_resolver_set_dnssec_anchors(r, trust_anchors);
416 }
417
418 return (ldns_rr_list_push_rr(trust_anchors, ldns_rr_clone(rr))) ? LDNS_STATUS_OK : LDNS_STATUS_ERR;
419 }
420
421 void
422 ldns_resolver_set_igntc(ldns_resolver *r, bool i)
423 {
424 r->_igntc = i;
425 }
426
427 void
428 ldns_resolver_set_usevc(ldns_resolver *r, bool vc)
429 {
430 r->_usevc = vc;
431 }
432
433 void
434 ldns_resolver_set_debug(ldns_resolver *r, bool d)
435 {
436 r->_debug = d;
437 }
438
439 void
440 ldns_resolver_set_ip6(ldns_resolver *r, uint8_t ip6)
441 {
442 r->_ip6 = ip6;
443 }
444
445 void
446 ldns_resolver_set_fail(ldns_resolver *r, bool f)
447 {
448 r->_fail =f;
449 }
450
451 static void
452 ldns_resolver_set_searchlist_count(ldns_resolver *r, size_t c)
453 {
454 r->_searchlist_count = c;
455 }
456
457 void
458 ldns_resolver_set_nameserver_count(ldns_resolver *r, size_t c)
459 {
460 r->_nameserver_count = c;
461 }
462
463 void
464 ldns_resolver_set_dnsrch(ldns_resolver *r, bool d)
465 {
466 r->_dnsrch = d;
467 }
468
469 void
470 ldns_resolver_set_retry(ldns_resolver *r, uint8_t retry)
471 {
472 r->_retry = retry;
473 }
474
475 void
476 ldns_resolver_set_retrans(ldns_resolver *r, uint8_t retrans)
477 {
478 r->_retrans = retrans;
479 }
480
481 void
482 ldns_resolver_set_fallback(ldns_resolver *r, bool fallback)
483 {
484 r->_fallback = fallback;
485 }
486
487 void
488 ldns_resolver_set_nameservers(ldns_resolver *r, ldns_rdf **n)
489 {
490 r->_nameservers = n;
491 }
492
493 void
494 ldns_resolver_set_defnames(ldns_resolver *r, bool d)
495 {
496 r->_defnames = d;
497 }
498
499 void
500 ldns_resolver_set_rtt(ldns_resolver *r, size_t *rtt)
501 {
502 r->_rtt = rtt;
503 }
504
505 void
506 ldns_resolver_set_nameserver_rtt(ldns_resolver *r, size_t pos, size_t value)
507 {
508 size_t *rtt;
509
510 assert(r != NULL);
511
512 rtt = ldns_resolver_rtt(r);
513
514 if (pos >= ldns_resolver_nameserver_count(r)) {
515 /* error ?*/
516 } else {
517 rtt[pos] = value;
518 }
519
520 }
521
522 void
523 ldns_resolver_incr_nameserver_count(ldns_resolver *r)
524 {
525 size_t c;
526
527 c = ldns_resolver_nameserver_count(r);
528 ldns_resolver_set_nameserver_count(r, ++c);
529 }
530
531 void
532 ldns_resolver_dec_nameserver_count(ldns_resolver *r)
533 {
534 size_t c;
535
536 c = ldns_resolver_nameserver_count(r);
537 if (c == 0) {
538 return;
539 } else {
540 ldns_resolver_set_nameserver_count(r, --c);
541 }
542 }
543
544 void
545 ldns_resolver_set_domain(ldns_resolver *r, ldns_rdf *d)
546 {
547 r->_domain = d;
548 }
549
550 void
551 ldns_resolver_set_timeout(ldns_resolver *r, struct timeval timeout)
552 {
553 r->_timeout.tv_sec = timeout.tv_sec;
554 r->_timeout.tv_usec = timeout.tv_usec;
555 }
556
557 void
558 ldns_resolver_push_searchlist(ldns_resolver *r, ldns_rdf *d)
559 {
560 ldns_rdf **searchlist;
561 size_t list_count;
562
563 if (ldns_rdf_get_type(d) != LDNS_RDF_TYPE_DNAME) {
564 return;
565 }
566
567 list_count = ldns_resolver_searchlist_count(r);
568 searchlist = ldns_resolver_searchlist(r);
569
570 searchlist = LDNS_XREALLOC(searchlist, ldns_rdf *, (list_count + 1));
571 if (searchlist) {
572 r->_searchlist = searchlist;
573
574 searchlist[list_count] = ldns_rdf_clone(d);
575 ldns_resolver_set_searchlist_count(r, list_count + 1);
576 } /* no way to report mem err */
577 }
578
579 void
580 ldns_resolver_set_tsig_keyname(ldns_resolver *r, char *tsig_keyname)
581 {
582 LDNS_FREE(r->_tsig_keyname);
583 r->_tsig_keyname = strdup(tsig_keyname);
584 }
585
586 void
587 ldns_resolver_set_tsig_algorithm(ldns_resolver *r, char *tsig_algorithm)
588 {
589 LDNS_FREE(r->_tsig_algorithm);
590 r->_tsig_algorithm = strdup(tsig_algorithm);
591 }
592
593 void
594 ldns_resolver_set_tsig_keydata(ldns_resolver *r, char *tsig_keydata)
595 {
596 LDNS_FREE(r->_tsig_keydata);
597 r->_tsig_keydata = strdup(tsig_keydata);
598 }
599
600 void
601 ldns_resolver_set_random(ldns_resolver *r, bool b)
602 {
603 r->_random = b;
604 }
605
606 /* more sophisticated functions */
607 ldns_resolver *
608 ldns_resolver_new(void)
609 {
610 ldns_resolver *r;
611
612 r = LDNS_MALLOC(ldns_resolver);
613 if (!r) {
614 return NULL;
615 }
616
617 r->_searchlist = NULL;
618 r->_nameservers = NULL;
619 r->_rtt = NULL;
620
621 /* defaults are filled out */
622 ldns_resolver_set_searchlist_count(r, 0);
623 ldns_resolver_set_nameserver_count(r, 0);
624 ldns_resolver_set_usevc(r, 0);
625 ldns_resolver_set_port(r, LDNS_PORT);
626 ldns_resolver_set_domain(r, NULL);
627 ldns_resolver_set_defnames(r, false);
628 ldns_resolver_set_retry(r, 3);
629 ldns_resolver_set_retrans(r, 2);
630 ldns_resolver_set_fallback(r, true);
631 ldns_resolver_set_fail(r, false);
632 ldns_resolver_set_edns_udp_size(r, 0);
633 ldns_resolver_set_dnssec(r, false);
634 ldns_resolver_set_dnssec_cd(r, false);
635 ldns_resolver_set_dnssec_anchors(r, NULL);
636 ldns_resolver_set_ip6(r, LDNS_RESOLV_INETANY);
637 ldns_resolver_set_igntc(r, false);
638 ldns_resolver_set_recursive(r, false);
639 ldns_resolver_set_dnsrch(r, true);
640 ldns_resolver_set_source(r, NULL);
641
642 /* randomize the nameserver to be queried
643 * when there are multiple
644 */
645 ldns_resolver_set_random(r, true);
646
647 ldns_resolver_set_debug(r, 0);
648
649 r->_timeout.tv_sec = LDNS_DEFAULT_TIMEOUT_SEC;
650 r->_timeout.tv_usec = LDNS_DEFAULT_TIMEOUT_USEC;
651
652 /* TODO: fd=0 is actually a valid socket (stdin),
653 replace with -1 */
654 r->_socket = 0;
655 r->_axfr_soa_count = 0;
656 r->_axfr_i = 0;
657 r->_cur_axfr_pkt = NULL;
658
659 r->_tsig_keyname = NULL;
660 r->_tsig_keydata = NULL;
661 r->_tsig_algorithm = NULL;
662 return r;
663 }
664
665 ldns_status
666 ldns_resolver_new_frm_fp(ldns_resolver **res, FILE *fp)
667 {
668 return ldns_resolver_new_frm_fp_l(res, fp, NULL);
669 }
670
671 ldns_status
672 ldns_resolver_new_frm_fp_l(ldns_resolver **res, FILE *fp, int *line_nr)
673 {
674 ldns_resolver *r;
675 const char *keyword[LDNS_RESOLV_KEYWORDS];
676 char word[LDNS_MAX_LINELEN + 1];
677 int8_t expect;
678 uint8_t i;
679 ldns_rdf *tmp;
680 #ifdef HAVE_SSL
681 ldns_rr *tmp_rr;
682 #endif
683 ssize_t gtr, bgtr;
684 ldns_buffer *b;
685 int lnr = 0, oldline;
686 FILE* myfp = fp;
687 if(!line_nr) line_nr = &lnr;
688
689 if(!fp) {
690 myfp = fopen("/etc/resolv.conf", "r");
691 if(!myfp)
692 return LDNS_STATUS_FILE_ERR;
693 }
694
695 /* do this better
696 * expect =
697 * 0: keyword
698 * 1: default domain dname
699 * 2: NS aaaa or a record
700 */
701
702 /* recognized keywords */
703 keyword[LDNS_RESOLV_NAMESERVER] = "nameserver";
704 keyword[LDNS_RESOLV_DEFDOMAIN] = "domain";
705 keyword[LDNS_RESOLV_SEARCH] = "search";
706 /* these two are read but not used atm TODO */
707 keyword[LDNS_RESOLV_SORTLIST] = "sortlist";
708 keyword[LDNS_RESOLV_OPTIONS] = "options";
709 keyword[LDNS_RESOLV_ANCHOR] = "anchor";
710 expect = LDNS_RESOLV_KEYWORD;
711
712 r = ldns_resolver_new();
713 if (!r) {
714 if(!fp) fclose(myfp);
715 return LDNS_STATUS_MEM_ERR;
716 }
717
718 gtr = 1;
719 word[0] = 0;
720 oldline = *line_nr;
721 expect = LDNS_RESOLV_KEYWORD;
722 while (gtr > 0) {
723 /* check comments */
724 if (word[0] == '#') {
725 word[0]='x';
726 if(oldline == *line_nr) {
727 /* skip until end of line */
728 int c;
729 do {
730 c = fgetc(myfp);
731 } while(c != EOF && c != '\n');
732 if(c=='\n') (*line_nr)++;
733 }
734 /* and read next to prepare for further parsing */
735 oldline = *line_nr;
736 continue;
737 }
738 oldline = *line_nr;
739 switch(expect) {
740 case LDNS_RESOLV_KEYWORD:
741 /* keyword */
742 gtr = ldns_fget_token_l(myfp, word, LDNS_PARSE_NORMAL, 0, line_nr);
743 if (gtr != 0) {
744 if(word[0] == '#') continue;
745 for(i = 0; i < LDNS_RESOLV_KEYWORDS; i++) {
746 if (strcasecmp(keyword[i], word) == 0) {
747 /* chosen the keyword and
748 * expect values carefully
749 */
750 expect = i;
751 break;
752 }
753 }
754 /* no keyword recognized */
755 if (expect == LDNS_RESOLV_KEYWORD) {
756 /* skip line */
757 /*
758 ldns_resolver_deep_free(r);
759 if(!fp) fclose(myfp);
760 return LDNS_STATUS_SYNTAX_KEYWORD_ERR;
761 */
762 }
763 }
764 break;
765 case LDNS_RESOLV_DEFDOMAIN:
766 /* default domain dname */
767 gtr = ldns_fget_token_l(myfp, word, LDNS_PARSE_NORMAL, 0, line_nr);
768 if (gtr == 0) {
769 if(!fp) fclose(myfp);
770 return LDNS_STATUS_SYNTAX_MISSING_VALUE_ERR;
771 }
772 if(word[0] == '#') {
773 expect = LDNS_RESOLV_KEYWORD;
774 continue;
775 }
776 tmp = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, word);
777 if (!tmp) {
778 ldns_resolver_deep_free(r);
779 if(!fp) fclose(myfp);
780 return LDNS_STATUS_SYNTAX_DNAME_ERR;
781 }
782
783 /* DOn't free, because we copy the pointer */
784 ldns_resolver_set_domain(r, tmp);
785 expect = LDNS_RESOLV_KEYWORD;
786 break;
787 case LDNS_RESOLV_NAMESERVER:
788 /* NS aaaa or a record */
789 gtr = ldns_fget_token_l(myfp, word, LDNS_PARSE_NORMAL, 0, line_nr);
790 if (gtr == 0) {
791 if(!fp) fclose(myfp);
792 return LDNS_STATUS_SYNTAX_MISSING_VALUE_ERR;
793 }
794 if(word[0] == '#') {
795 expect = LDNS_RESOLV_KEYWORD;
796 continue;
797 }
798 if(strchr(word, '%')) {
799 /* snip off interface labels,
800 * fe80::222:19ff:fe31:4222%eth0 */
801 strchr(word, '%')[0]=0;
802 }
803 tmp = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_AAAA, word);
804 if (!tmp) {
805 /* try ip4 */
806 tmp = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_A, word);
807 }
808 /* could not parse it, exit */
809 if (!tmp) {
810 ldns_resolver_deep_free(r);
811 if(!fp) fclose(myfp);
812 return LDNS_STATUS_SYNTAX_ERR;
813 }
814 (void)ldns_resolver_push_nameserver(r, tmp);
815 ldns_rdf_deep_free(tmp);
816 expect = LDNS_RESOLV_KEYWORD;
817 break;
818 case LDNS_RESOLV_SEARCH:
819 /* search list domain dname */
820 gtr = ldns_fget_token_l(myfp, word, LDNS_PARSE_SKIP_SPACE, 0, line_nr);
821 b = LDNS_MALLOC(ldns_buffer);
822 if(!b) {
823 ldns_resolver_deep_free(r);
824 if(!fp) fclose(myfp);
825 return LDNS_STATUS_MEM_ERR;
826 }
827
828 ldns_buffer_new_frm_data(b, word, (size_t) gtr);
829 if(ldns_buffer_status(b) != LDNS_STATUS_OK) {
830 LDNS_FREE(b);
831 ldns_resolver_deep_free(r);
832 if(!fp) fclose(myfp);
833 return LDNS_STATUS_MEM_ERR;
834 }
835 bgtr = ldns_bget_token(b, word, LDNS_PARSE_NORMAL, (size_t) gtr + 1);
836 while (bgtr > 0) {
837 gtr -= bgtr;
838 if(word[0] == '#') {
839 expect = LDNS_RESOLV_KEYWORD;
840 break;
841 }
842 tmp = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, word);
843 if (!tmp) {
844 ldns_resolver_deep_free(r);
845 ldns_buffer_free(b);
846 if(!fp) fclose(myfp);
847 return LDNS_STATUS_SYNTAX_DNAME_ERR;
848 }
849
850 ldns_resolver_push_searchlist(r, tmp);
851
852 ldns_rdf_deep_free(tmp);
853 bgtr = ldns_bget_token(b, word, LDNS_PARSE_NORMAL,
854 (size_t) gtr + 1);
855 }
856 ldns_buffer_free(b);
857 if (expect != LDNS_RESOLV_KEYWORD) {
858 gtr = 1;
859 expect = LDNS_RESOLV_KEYWORD;
860 }
861 break;
862 case LDNS_RESOLV_SORTLIST:
863 gtr = ldns_fget_token_l(myfp, word, LDNS_PARSE_SKIP_SPACE, 0, line_nr);
864 /* sortlist not implemented atm */
865 expect = LDNS_RESOLV_KEYWORD;
866 break;
867 case LDNS_RESOLV_OPTIONS:
868 gtr = ldns_fget_token_l(myfp, word, LDNS_PARSE_SKIP_SPACE, 0, line_nr);
869 /* options not implemented atm */
870 expect = LDNS_RESOLV_KEYWORD;
871 break;
872 case LDNS_RESOLV_ANCHOR:
873 /* a file containing a DNSSEC trust anchor */
874 gtr = ldns_fget_token_l(myfp, word, LDNS_PARSE_NORMAL, 0, line_nr);
875 if (gtr == 0) {
876 ldns_resolver_deep_free(r);
877 if(!fp) fclose(myfp);
878 return LDNS_STATUS_SYNTAX_MISSING_VALUE_ERR;
879 }
880 if(word[0] == '#') {
881 expect = LDNS_RESOLV_KEYWORD;
882 continue;
883 }
884
885 #ifdef HAVE_SSL
886 tmp_rr = ldns_read_anchor_file(word);
887 (void) ldns_resolver_push_dnssec_anchor(r, tmp_rr);
888 ldns_rr_free(tmp_rr);
889 #endif
890 expect = LDNS_RESOLV_KEYWORD;
891 break;
892 }
893 }
894
895 if(!fp)
896 fclose(myfp);
897
898 if (res) {
899 *res = r;
900 return LDNS_STATUS_OK;
901 } else {
902 ldns_resolver_deep_free(r);
903 return LDNS_STATUS_NULL;
904 }
905 }
906
907 ldns_status
908 ldns_resolver_new_frm_file(ldns_resolver **res, const char *filename)
909 {
910 ldns_resolver *r;
911 FILE *fp;
912 ldns_status s;
913
914 if (!filename) {
915 fp = fopen(LDNS_RESOLV_CONF, "r");
916
917 } else {
918 fp = fopen(filename, "r");
919 }
920 if (!fp) {
921 return LDNS_STATUS_FILE_ERR;
922 }
923
924 s = ldns_resolver_new_frm_fp(&r, fp);
925 fclose(fp);
926 if (s == LDNS_STATUS_OK) {
927 if (res) {
928 *res = r;
929 return LDNS_STATUS_OK;
930 } else {
931 ldns_resolver_free(r);
932 return LDNS_STATUS_NULL;
933 }
934 }
935 return s;
936 }
937
938 void
939 ldns_resolver_free(ldns_resolver *res)
940 {
941 LDNS_FREE(res);
942 }
943
944 void
945 ldns_resolver_deep_free(ldns_resolver *res)
946 {
947 size_t i;
948
949 if (res) {
950 if (res->_searchlist) {
951 for (i = 0; i < ldns_resolver_searchlist_count(res); i++) {
952 ldns_rdf_deep_free(res->_searchlist[i]);
953 }
954 LDNS_FREE(res->_searchlist);
955 }
956 if (res->_nameservers) {
957 for (i = 0; i < res->_nameserver_count; i++) {
958 ldns_rdf_deep_free(res->_nameservers[i]);
959 }
960 LDNS_FREE(res->_nameservers);
961 }
962 if (ldns_resolver_domain(res)) {
963 ldns_rdf_deep_free(ldns_resolver_domain(res));
964 }
965 if (res->_tsig_keyname) {
966 LDNS_FREE(res->_tsig_keyname);
967 }
968 if (res->_tsig_keydata) {
969 LDNS_FREE(res->_tsig_keydata);
970 }
971 if (res->_tsig_algorithm) {
972 LDNS_FREE(res->_tsig_algorithm);
973 }
974
975 if (res->_cur_axfr_pkt) {
976 ldns_pkt_free(res->_cur_axfr_pkt);
977 }
978
979 if (res->_rtt) {
980 LDNS_FREE(res->_rtt);
981 }
982 if (res->_dnssec_anchors) {
983 ldns_rr_list_deep_free(res->_dnssec_anchors);
984 }
985 LDNS_FREE(res);
986 }
987 }
988
989 ldns_status
990 ldns_resolver_search_status(ldns_pkt** pkt,
991 ldns_resolver *r, const ldns_rdf *name,
992 ldns_rr_type t, ldns_rr_class c, uint16_t flags)
993 {
994 ldns_rdf *new_name;
995 ldns_rdf **search_list;
996 size_t i;
997 ldns_status s = LDNS_STATUS_OK;
998
999 if (ldns_dname_absolute(name)) {
1000 /* query as-is */
1001 return ldns_resolver_query_status(pkt, r, name, t, c, flags);
1002 } else if (ldns_resolver_dnsrch(r)) {
1003 search_list = ldns_resolver_searchlist(r);
1004 for (i = 0; i < ldns_resolver_searchlist_count(r); i++) {
1005 new_name = ldns_dname_cat_clone(name, search_list[i]);
1006
1007 s = ldns_resolver_query_status(pkt, r,
1008 new_name, t, c, flags);
1009 ldns_rdf_free(new_name);
1010 if (pkt) {
1011 if (s == LDNS_STATUS_OK && *pkt &&
1012 ldns_pkt_get_rcode(*pkt) ==
1013 LDNS_RCODE_NOERROR) {
1014 return LDNS_STATUS_OK;
1015 }
1016 ldns_pkt_free(*pkt);
1017 }
1018 }
1019 }
1020 return s;
1021 }
1022
1023 ldns_pkt *
1024 ldns_resolver_search(const ldns_resolver *r,const ldns_rdf *name,
1025 ldns_rr_type t, ldns_rr_class c, uint16_t flags)
1026 {
1027 ldns_pkt* pkt = NULL;
1028 if (ldns_resolver_search_status(&pkt, (ldns_resolver *)r,
1029 name, t, c, flags) != LDNS_STATUS_OK) {
1030 ldns_pkt_free(pkt);
1031 }
1032 return pkt;
1033 }
1034
1035 ldns_status
1036 ldns_resolver_query_status(ldns_pkt** pkt,
1037 ldns_resolver *r, const ldns_rdf *name,
1038 ldns_rr_type t, ldns_rr_class c, uint16_t flags)
1039 {
1040 ldns_rdf *newname;
1041 ldns_status status;
1042
1043 if (!ldns_resolver_defnames(r) || !ldns_resolver_domain(r)) {
1044 return ldns_resolver_send(pkt, r, name, t, c, flags);
1045 }
1046
1047 newname = ldns_dname_cat_clone(name, ldns_resolver_domain(r));
1048 if (!newname) {
1049 return LDNS_STATUS_MEM_ERR;
1050 }
1051 status = ldns_resolver_send(pkt, r, newname, t, c, flags);
1052 ldns_rdf_free(newname);
1053 return status;
1054 }
1055
1056 ldns_pkt *
1057 ldns_resolver_query(const ldns_resolver *r, const ldns_rdf *name,
1058 ldns_rr_type t, ldns_rr_class c, uint16_t flags)
1059 {
1060 ldns_pkt* pkt = NULL;
1061 if (ldns_resolver_query_status(&pkt, (ldns_resolver *)r,
1062 name, t, c, flags) != LDNS_STATUS_OK) {
1063 ldns_pkt_free(pkt);
1064 }
1065 return pkt;
1066 }
1067
1068 static size_t *
1069 ldns_resolver_backup_rtt(ldns_resolver *r)
1070 {
1071 size_t *new_rtt;
1072 size_t *old_rtt = ldns_resolver_rtt(r);
1073
1074 if (old_rtt && ldns_resolver_nameserver_count(r)) {
1075 new_rtt = LDNS_XMALLOC(size_t
1076 , ldns_resolver_nameserver_count(r));
1077 memcpy(new_rtt, old_rtt, sizeof(size_t)
1078 * ldns_resolver_nameserver_count(r));
1079 ldns_resolver_set_rtt(r, new_rtt);
1080 return old_rtt;
1081 }
1082 return NULL;
1083 }
1084
1085 static void
1086 ldns_resolver_restore_rtt(ldns_resolver *r, size_t *old_rtt)
1087 {
1088 size_t *cur_rtt = ldns_resolver_rtt(r);
1089
1090 if (cur_rtt) {
1091 LDNS_FREE(cur_rtt);
1092 }
1093 ldns_resolver_set_rtt(r, old_rtt);
1094 }
1095
1096 ldns_status
1097 ldns_resolver_send_pkt(ldns_pkt **answer, ldns_resolver *r,
1098 ldns_pkt *query_pkt)
1099 {
1100 ldns_pkt *answer_pkt = NULL;
1101 ldns_status stat = LDNS_STATUS_OK;
1102 size_t *rtt;
1103
1104 stat = ldns_send(&answer_pkt, (ldns_resolver *)r, query_pkt);
1105 if (stat != LDNS_STATUS_OK) {
1106 if(answer_pkt) {
1107 ldns_pkt_free(answer_pkt);
1108 answer_pkt = NULL;
1109 }
1110 } else {
1111 /* if tc=1 fall back to EDNS and/or TCP */
1112 /* check for tcp first (otherwise we don't care about tc=1) */
1113 if (!ldns_resolver_usevc(r) && ldns_resolver_fallback(r)) {
1114 if (ldns_pkt_tc(answer_pkt)) {
1115 /* was EDNS0 set? */
1116 if (ldns_pkt_edns_udp_size(query_pkt) == 0) {
1117 ldns_pkt_set_edns_udp_size(query_pkt
1118 , 4096);
1119 ldns_pkt_free(answer_pkt);
1120 /* Nameservers should not become
1121 * unreachable because fragments are
1122 * dropped (network error). We might
1123 * still have success with TCP.
1124 * Therefore maintain reachability
1125 * statuses of the nameservers by
1126 * backup and restore the rtt list.
1127 */
1128 rtt = ldns_resolver_backup_rtt(r);
1129 stat = ldns_send(&answer_pkt, r
1130 , query_pkt);
1131 ldns_resolver_restore_rtt(r, rtt);
1132 }
1133 /* either way, if it is still truncated, use TCP */
1134 if (stat != LDNS_STATUS_OK ||
1135 ldns_pkt_tc(answer_pkt)) {
1136 ldns_resolver_set_usevc(r, true);
1137 ldns_pkt_free(answer_pkt);
1138 stat = ldns_send(&answer_pkt, r, query_pkt);
1139 ldns_resolver_set_usevc(r, false);
1140 }
1141 }
1142 }
1143 }
1144
1145 if (answer) {
1146 *answer = answer_pkt;
1147 }
1148
1149 return stat;
1150 }
1151
1152 ldns_status
1153 ldns_resolver_prepare_query_pkt(ldns_pkt **query_pkt, ldns_resolver *r,
1154 const ldns_rdf *name, ldns_rr_type t,
1155 ldns_rr_class c, uint16_t flags)
1156 {
1157 struct timeval now;
1158
1159 /* prepare a question pkt from the parameters
1160 * and then send this */
1161 if (t == LDNS_RR_TYPE_IXFR) {
1162 *query_pkt = ldns_pkt_ixfr_request_new(ldns_rdf_clone(name),
1163 c, flags, NULL);
1164 } else {
1165 *query_pkt = ldns_pkt_query_new(ldns_rdf_clone(name), t, c, flags);
1166 }
1167 if (!*query_pkt) {
1168 return LDNS_STATUS_ERR;
1169 }
1170
1171 /* set DO bit if necessary */
1172 if (ldns_resolver_dnssec(r)) {
1173 if (ldns_resolver_edns_udp_size(r) == 0) {
1174 ldns_resolver_set_edns_udp_size(r, 4096);
1175 }
1176 ldns_pkt_set_edns_do(*query_pkt, true);
1177 if (ldns_resolver_dnssec_cd(r) || (flags & LDNS_CD)) {
1178 ldns_pkt_set_cd(*query_pkt, true);
1179 }
1180 }
1181
1182 /* transfer the udp_edns_size from the resolver to the packet */
1183 if (ldns_resolver_edns_udp_size(r) != 0) {
1184 ldns_pkt_set_edns_udp_size(*query_pkt, ldns_resolver_edns_udp_size(r));
1185 }
1186
1187 /* set the timestamp */
1188 now.tv_sec = time(NULL);
1189 now.tv_usec = 0;
1190 ldns_pkt_set_timestamp(*query_pkt, now);
1191
1192
1193 if (ldns_resolver_debug(r)) {
1194 ldns_pkt_print(stdout, *query_pkt);
1195 }
1196
1197 /* only set the id if it is not set yet */
1198 if (ldns_pkt_id(*query_pkt) == 0) {
1199 ldns_pkt_set_random_id(*query_pkt);
1200 }
1201
1202 return LDNS_STATUS_OK;
1203 }
1204
1205
1206 ldns_status
1207 ldns_resolver_send(ldns_pkt **answer, ldns_resolver *r, const ldns_rdf *name,
1208 ldns_rr_type t, ldns_rr_class c, uint16_t flags)
1209 {
1210 ldns_pkt *query_pkt;
1211 ldns_pkt *answer_pkt;
1212 ldns_status status;
1213
1214 assert(r != NULL);
1215 assert(name != NULL);
1216
1217 answer_pkt = NULL;
1218
1219 /* do all the preprocessing here, then fire of an query to
1220 * the network */
1221
1222 if (0 == t) {
1223 t= LDNS_RR_TYPE_A;
1224 }
1225 if (0 == c) {
1226 c= LDNS_RR_CLASS_IN;
1227 }
1228 if (0 == ldns_resolver_nameserver_count(r)) {
1229 return LDNS_STATUS_RES_NO_NS;
1230 }
1231 if (ldns_rdf_get_type(name) != LDNS_RDF_TYPE_DNAME) {
1232 return LDNS_STATUS_RES_QUERY;
1233 }
1234
1235 status = ldns_resolver_prepare_query_pkt(&query_pkt, r, name,
1236 t, c, flags);
1237 if (status != LDNS_STATUS_OK) {
1238 return status;
1239 }
1240
1241 /* if tsig values are set, tsign it */
1242 /* TODO: make last 3 arguments optional too? maybe make complete
1243 rr instead of separate values in resolver (and packet)
1244 Jelte
1245 should this go in pkt_prepare?
1246 */
1247 if (ldns_resolver_tsig_keyname(r) && ldns_resolver_tsig_keydata(r)) {
1248 #ifdef HAVE_SSL
1249 status = ldns_pkt_tsig_sign(query_pkt,
1250 ldns_resolver_tsig_keyname(r),
1251 ldns_resolver_tsig_keydata(r),
1252 300, ldns_resolver_tsig_algorithm(r), NULL);
1253 if (status != LDNS_STATUS_OK) {
1254 ldns_pkt_free(query_pkt);
1255 return LDNS_STATUS_CRYPTO_TSIG_ERR;
1256 }
1257 #else
1258 ldns_pkt_free(query_pkt);
1259 return LDNS_STATUS_CRYPTO_TSIG_ERR;
1260 #endif /* HAVE_SSL */
1261 }
1262
1263 status = ldns_resolver_send_pkt(&answer_pkt, r, query_pkt);
1264 ldns_pkt_free(query_pkt);
1265
1266 /* allows answer to be NULL when not interested in return value */
1267 if (answer) {
1268 *answer = answer_pkt;
1269 }
1270 return status;
1271 }
1272
1273 ldns_rr *
1274 ldns_axfr_next(ldns_resolver *resolver)
1275 {
1276 ldns_rr *cur_rr;
1277 uint8_t *packet_wire;
1278 size_t packet_wire_size;
1279 ldns_lookup_table *rcode;
1280 ldns_status status;
1281
1282 /* check if start() has been called */
1283 if (!resolver || resolver->_socket == 0) {
1284 return NULL;
1285 }
1286
1287 if (resolver->_cur_axfr_pkt) {
1288 if (resolver->_axfr_i == ldns_pkt_ancount(resolver->_cur_axfr_pkt)) {
1289 ldns_pkt_free(resolver->_cur_axfr_pkt);
1290 resolver->_cur_axfr_pkt = NULL;
1291 return ldns_axfr_next(resolver);
1292 }
1293 cur_rr = ldns_rr_clone(ldns_rr_list_rr(
1294 ldns_pkt_answer(resolver->_cur_axfr_pkt),
1295 resolver->_axfr_i));
1296 resolver->_axfr_i++;
1297 if (ldns_rr_get_type(cur_rr) == LDNS_RR_TYPE_SOA) {
1298 resolver->_axfr_soa_count++;
1299 if (resolver->_axfr_soa_count >= 2) {
1300 #ifndef USE_WINSOCK
1301 close(resolver->_socket);
1302 #else
1303 closesocket(resolver->_socket);
1304 #endif
1305 resolver->_socket = 0;
1306 ldns_pkt_free(resolver->_cur_axfr_pkt);
1307 resolver->_cur_axfr_pkt = NULL;
1308 }
1309 }
1310 return cur_rr;
1311 } else {
1312 packet_wire = ldns_tcp_read_wire(resolver->_socket, &packet_wire_size);
1313 if(!packet_wire)
1314 return NULL;
1315
1316 status = ldns_wire2pkt(&resolver->_cur_axfr_pkt, packet_wire,
1317 packet_wire_size);
1318 LDNS_FREE(packet_wire);
1319
1320 resolver->_axfr_i = 0;
1321 if (status != LDNS_STATUS_OK) {
1322 /* TODO: make status return type of this function (...api change) */
1323 #ifdef STDERR_MSGS
1324 fprintf(stderr, "Error parsing rr during AXFR: %s\n", ldns_get_errorstr_by_id(status));
1325 #endif
1326
1327 /* we must now also close the socket, otherwise subsequent uses of the
1328 same resolver structure will fail because the link is still open or
1329 in an undefined state */
1330 #ifndef USE_WINSOCK
1331 close(resolver->_socket);
1332 #else
1333 closesocket(resolver->_socket);
1334 #endif
1335 resolver->_socket = 0;
1336
1337 return NULL;
1338 } else if (ldns_pkt_get_rcode(resolver->_cur_axfr_pkt) != 0) {
1339 rcode = ldns_lookup_by_id(ldns_rcodes, (int) ldns_pkt_get_rcode(resolver->_cur_axfr_pkt));
1340 #ifdef STDERR_MSGS
1341 if (rcode) {
1342 fprintf(stderr, "Error in AXFR: %s\n",
1343 rcode->name);
1344 } else {
1345 fprintf(stderr, "Error in AXFR: %d\n",
1346 (int) ldns_pkt_get_rcode(
1347 resolver->_cur_axfr_pkt));
1348 }
1349 #endif
1350
1351 /* we must now also close the socket, otherwise subsequent uses of the
1352 same resolver structure will fail because the link is still open or
1353 in an undefined state */
1354 #ifndef USE_WINSOCK
1355 close(resolver->_socket);
1356 #else
1357 closesocket(resolver->_socket);
1358 #endif
1359 resolver->_socket = 0;
1360
1361 return NULL;
1362 } else {
1363 return ldns_axfr_next(resolver);
1364 }
1365
1366 }
1367
1368 }
1369
1370 /* this function is needed to abort a transfer that is in progress;
1371 * without it an aborted transfer will lead to the AXFR code in the
1372 * library staying in an indetermined state because the socket for the
1373 * AXFR is never closed
1374 */
1375 void
1376 ldns_axfr_abort(ldns_resolver *resolver)
1377 {
1378 /* Only abort if an actual AXFR is in progress */
1379 if (resolver->_socket != 0)
1380 {
1381 #ifndef USE_WINSOCK
1382 close(resolver->_socket);
1383 #else
1384 closesocket(resolver->_socket);
1385 #endif
1386 resolver->_socket = 0;
1387 }
1388 }
1389
1390 bool
1391 ldns_axfr_complete(const ldns_resolver *res)
1392 {
1393 /* complete when soa count is 2? */
1394 return res->_axfr_soa_count == 2;
1395 }
1396
1397 ldns_pkt *
1398 ldns_axfr_last_pkt(const ldns_resolver *res)
1399 {
1400 return res->_cur_axfr_pkt;
1401 }
1402
1403 /* random isn't really that good */
1404 void
1405 ldns_resolver_nameservers_randomize(ldns_resolver *r)
1406 {
1407 uint16_t i, j;
1408 ldns_rdf **ns, *tmpns;
1409 size_t *rtt, tmprtt;
1410
1411 /* should I check for ldns_resolver_random?? */
1412 assert(r != NULL);
1413
1414 ns = ldns_resolver_nameservers(r);
1415 rtt = ldns_resolver_rtt(r);
1416 for (i = 0; i < ldns_resolver_nameserver_count(r); i++) {
1417 j = ldns_get_random() % ldns_resolver_nameserver_count(r);
1418 tmpns = ns[i];
1419 ns[i] = ns[j];
1420 ns[j] = tmpns;
1421 tmprtt = rtt[i];
1422 rtt[i] = rtt[j];
1423 rtt[j] = tmprtt;
1424 }
1425 ldns_resolver_set_nameservers(r, ns);
1426 }
1427
ldns_rr_rdf
ldns_rdf * ldns_rr_rdf(const ldns_rr *rr, size_t nr)
returns the rdata field member counter.
Definition: rr.c:873
ldns_resolver_ip6
uint8_t ldns_resolver_ip6(const ldns_resolver *r)
Does the resolver use ip6 or ip4.
Definition: resolver.c:60
ldns_struct_buffer
implementation of buffers to ease operations
Definition: buffer.h:50
ldns_resolver_free
void ldns_resolver_free(ldns_resolver *res)
Frees the allocated space for this resolver.
Definition: resolver.c:939
ldns_resolver_set_domain
void ldns_resolver_set_domain(ldns_resolver *r, ldns_rdf *d)
Set the resolver&#39;s default domain.
Definition: resolver.c:545
ldns_resolver_set_source
void ldns_resolver_set_source(ldns_resolver *r, ldns_rdf *s)
Set the source rdf (address) the resolver should use.
Definition: resolver.c:244
LDNS_PARSE_NORMAL
#define LDNS_PARSE_NORMAL
Definition: parse.h:21
ldns_resolver_dnsrch
bool ldns_resolver_dnsrch(const ldns_resolver *r)
Does the resolver apply search list.
Definition: resolver.c:78
LDNS_STATUS_NULL
Definition: error.h:51
ldns_rr_clone
ldns_rr * ldns_rr_clone(const ldns_rr *rr)
clones a rr and all its data
Definition: rr.c:1363
ldns_resolver_tsig_algorithm
char * ldns_resolver_tsig_algorithm(const ldns_resolver *r)
Return the tsig algorithm as used by the nameserver.
Definition: resolver.c:213
ldns_resolver_retry
uint8_t ldns_resolver_retry(const ldns_resolver *r)
Get the number of retries.
Definition: resolver.c:42
ldns_rdf_deep_free
void ldns_rdf_deep_free(ldns_rdf *rd)
frees a rdf structure and frees the data.
Definition: rdata.c:230
LDNS_RR_TYPE_A
a host address
Definition: rr.h:83
ldns_resolver_search_status
ldns_status ldns_resolver_search_status(ldns_pkt **pkt, ldns_resolver *r, const ldns_rdf *name, ldns_rr_type t, ldns_rr_class c, uint16_t flags)
Send the query for using the resolver and take the search list into account The search algorithm is a...
Definition: resolver.c:990
ldns_resolver_prepare_query_pkt
ldns_status ldns_resolver_prepare_query_pkt(ldns_pkt **query_pkt, ldns_resolver *r, const ldns_rdf *name, ldns_rr_type t, ldns_rr_class c, uint16_t flags)
Form a query packet from a resolver and name/type/class combo.
Definition: resolver.c:1153
ldns_struct_resolver::_dnssec_anchors
ldns_rr_list * _dnssec_anchors
Optional trust anchors for complete DNSSEC validation.
Definition: resolver.h:99
ldns_struct_resolver
DNS stub resolver structure.
Definition: resolver.h:59
ldns_struct_resolver::_fail
signed char _fail
Only try the first nameserver, and return with an error directly if it fails.
Definition: resolver.h:113
ldns_struct_resolver::_port
uint16_t _port
Port to send queries to.
Definition: resolver.h:62
ldns_rr_class
enum ldns_enum_rr_class ldns_rr_class
Definition: rr.h:64
ldns_rr_list_push_rr
bool ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr)
pushes an rr to an rrlist.
Definition: rr.c:1096
ldns_resolver_query
ldns_pkt * ldns_resolver_query(const ldns_resolver *r, const ldns_rdf *name, ldns_rr_type t, ldns_rr_class c, uint16_t flags)
Send a query to a nameserver.
Definition: resolver.c:1057
ldns_resolver_searchlist_count
size_t ldns_resolver_searchlist_count(const ldns_resolver *r)
Return the resolver&#39;s searchlist count.
Definition: resolver.c:231
ldns_rr_list_contains_rr
bool ldns_rr_list_contains_rr(const ldns_rr_list *rr_list, ldns_rr *rr)
returns true if the given rr is one of the rrs in the list, or if it is equal to one ...
Definition: rr.c:1203
ldns_struct_rr_list
List or Set of Resource Records.
Definition: rr.h:327
ldns_resolver_set_rtt
void ldns_resolver_set_rtt(ldns_resolver *r, size_t *rtt)
Set round trip time for all nameservers.
Definition: resolver.c:500
ldns_struct_resolver::_searchlist_count
size_t _searchlist_count
Number of entries in the searchlist array.
Definition: resolver.h:85
ldns_pkt_tc
bool ldns_pkt_tc(const ldns_pkt *packet)
Read the packet&#39;s tc bit.
Definition: packet.c:57
ldns_pkt_get_rcode
ldns_pkt_rcode ldns_pkt_get_rcode(const ldns_pkt *packet)
Return the packet&#39;s respons code.
Definition: packet.c:93
ldns_struct_resolver::_retrans
uint8_t _retrans
Time to wait before retrying.
Definition: resolver.h:90
ldns_resolver_deep_free
void ldns_resolver_deep_free(ldns_resolver *res)
Frees the allocated space for this resolver and all it&#39;s data.
Definition: resolver.c:945
LDNS_STATUS_OK
Definition: error.h:26
ldns_struct_resolver::_dnssec
signed char _dnssec
Whether to do DNSSEC.
Definition: resolver.h:95
LDNS_RESOLV_DEFDOMAIN
#define LDNS_RESOLV_DEFDOMAIN
Definition: resolver.h:41
ldns_resolver_dnssec
bool ldns_resolver_dnssec(const ldns_resolver *r)
Does the resolver do DNSSEC.
Definition: resolver.c:120
LDNS_RESOLV_SEARCH
#define LDNS_RESOLV_SEARCH
Definition: resolver.h:43
ldns_resolver_push_nameserver_rr_list
ldns_status ldns_resolver_push_nameserver_rr_list(ldns_resolver *r, ldns_rr_list *rrlist)
Push a new nameserver rr_list to the resolver.
Definition: resolver.c:351
ldns_resolver_set_nameserver_rtt
void ldns_resolver_set_nameserver_rtt(ldns_resolver *r, size_t pos, size_t value)
Set round trip time for a specific nameserver.
Definition: resolver.c:506
ldns_pkt_id
uint16_t ldns_pkt_id(const ldns_pkt *packet)
Read the packet id.
Definition: packet.c:39
ldns_resolver_set_tsig_keyname
void ldns_resolver_set_tsig_keyname(ldns_resolver *r, char *tsig_keyname)
Set the tsig key name.
Definition: resolver.c:580
LDNS_XMALLOC
#define LDNS_XMALLOC(type, count)
Definition: util.h:51
ldns_resolver_set_nameservers
void ldns_resolver_set_nameservers(ldns_resolver *r, ldns_rdf **n)
Set the resolver&#39;s nameserver count directly by using an rdf list.
Definition: resolver.c:488
ldns_resolver_push_searchlist
void ldns_resolver_push_searchlist(ldns_resolver *r, ldns_rdf *d)
Push a new rd to the resolver&#39;s searchlist.
Definition: resolver.c:558
LDNS_RESOLV_KEYWORDS
#define LDNS_RESOLV_KEYWORDS
Definition: resolver.h:47
ldns_rcodes
ldns_lookup_table ldns_rcodes[]
Response codes.
Definition: host2str.c:92
LDNS_RESOLV_ANCHOR
#define LDNS_RESOLV_ANCHOR
Definition: resolver.h:46
ldns_rr_list_deep_free
void ldns_rr_list_deep_free(ldns_rr_list *rr_list)
frees an rr_list structure and all rrs contained therein.
Definition: rr.c:984
ldns_buffer_free
void ldns_buffer_free(ldns_buffer *buffer)
frees the buffer.
Definition: buffer.c:137
LDNS_RESOLV_NAMESERVER
#define LDNS_RESOLV_NAMESERVER
Definition: resolver.h:42
LDNS_STATUS_RES_QUERY
Definition: error.h:71
ldns_rdf_clone
ldns_rdf * ldns_rdf_clone(const ldns_rdf *rd)
clones a rdf structure.
Definition: rdata.c:222
ldns_struct_resolver::_edns_udp_size
uint16_t _edns_udp_size
Definition: resolver.h:130
LDNS_CD
#define LDNS_CD
Definition: packet.h:31
ldns_resolver_set_tsig_algorithm
void ldns_resolver_set_tsig_algorithm(ldns_resolver *r, char *tsig_algorithm)
Set the tsig algorithm.
Definition: resolver.c:587
ldns_struct_resolver::_rtt
size_t * _rtt
Round trip time; 0 -> infinity.
Definition: resolver.h:70
ldns_rr_free
void ldns_rr_free(ldns_rr *rr)
frees an RR structure
Definition: rr.c:75
ldns_resolver_set_timeout
void ldns_resolver_set_timeout(ldns_resolver *r, struct timeval timeout)
Set the resolver&#39;s socket time out when talking to remote hosts.
Definition: resolver.c:551
ldns_bget_token
ssize_t ldns_bget_token(ldns_buffer *b, char *token, const char *delim, size_t limit)
returns a token/char from the buffer b.
Definition: parse.c:217
ldns_resolver_port
uint16_t ldns_resolver_port(const ldns_resolver *r)
Get the port the resolver should use.
Definition: resolver.c:24
ldns_resolver_searchlist
ldns_rdf ** ldns_resolver_searchlist(const ldns_resolver *r)
What is the searchlist as used by the resolver.
Definition: resolver.c:102
ldns_resolver_push_dnssec_anchor
ldns_status ldns_resolver_push_dnssec_anchor(ldns_resolver *r, ldns_rr *rr)
Push a new trust anchor to the resolver.
Definition: resolver.c:403
ldns_resolver_dnssec_anchors
ldns_rr_list * ldns_resolver_dnssec_anchors(const ldns_resolver *r)
Get the resolver&#39;s DNSSEC anchors.
Definition: resolver.c:132
ldns_pkt_set_edns_udp_size
void ldns_pkt_set_edns_udp_size(ldns_pkt *packet, uint16_t s)
Set the packet&#39;s edns udp size.
Definition: packet.c:591
ldns_pkt_query_new
ldns_pkt * ldns_pkt_query_new(ldns_rdf *rr_name, ldns_rr_type rr_type, ldns_rr_class rr_class, uint16_t flags)
creates a packet with a query in it for the given name, type and class.
Definition: packet.c:1034
ldns_resolver_dnssec_cd
bool ldns_resolver_dnssec_cd(const ldns_resolver *r)
Does the resolver set the CD bit.
Definition: resolver.c:126
LDNS_RR_TYPE_DNSKEY
Definition: rr.h:175
ldns_axfr_last_pkt
ldns_pkt * ldns_axfr_last_pkt(const ldns_resolver *res)
Returns a pointer to the last ldns_pkt that was sent by the server in the AXFR transfer uasable for i...
Definition: resolver.c:1398
LDNS_XREALLOC
#define LDNS_XREALLOC(ptr, type, count)
Definition: util.h:57
ldns_resolver_igntc
bool ldns_resolver_igntc(const ldns_resolver *r)
Does the resolver ignore the TC bit (truncated)
Definition: resolver.c:165
ldns_resolver_set_igntc
void ldns_resolver_set_igntc(ldns_resolver *r, bool i)
Definition: resolver.c:422
ldns_struct_resolver::_usevc
signed char _usevc
Whether to use tcp or udp (tcp if the value is true)
Definition: resolver.h:101
ldns_axfr_complete
bool ldns_axfr_complete(const ldns_resolver *res)
Returns true if the axfr transfer has completed (i.e.
Definition: resolver.c:1391
ldns_resolver_nameserver_rtt
size_t ldns_resolver_nameserver_rtt(const ldns_resolver *r, size_t pos)
Return the used round trip time for a specific nameserver.
Definition: resolver.c:183
LDNS_RESOLV_RTT_MIN
#define LDNS_RESOLV_RTT_MIN
Definition: resolver.h:54
ldns_struct_rr
Resource Record.
Definition: rr.h:299
ldns_rdf_free
void ldns_rdf_free(ldns_rdf *rd)
frees a rdf structure, leaving the data pointer intact.
Definition: rdata.c:241
ldns_struct_resolver::_tsig_algorithm
char * _tsig_algorithm
TSIG signing algorithm.
Definition: resolver.h:140
ldns_send
ldns_status ldns_send(ldns_pkt **result_packet, ldns_resolver *r, const ldns_pkt *query_pkt)
Sends ptk to the nameserver at the resolver object.
Definition: net.c:35
ldns_resolver_set_dnssec
void ldns_resolver_set_dnssec(ldns_resolver *r, bool d)
Definition: resolver.c:385
ldns_resolver_defnames
bool ldns_resolver_defnames(const ldns_resolver *r)
Does the resolver apply default domain name.
Definition: resolver.c:90
ldns.h
Including this file will include all ldns files, and define some lookup tables.
LDNS_RR_TYPE_AAAA
ipv6 address
Definition: rr.h:137
ldns_resolver_fallback
bool ldns_resolver_fallback(const ldns_resolver *r)
Get the truncation fallback status.
Definition: resolver.c:54
LDNS_RR_TYPE_SOA
marks the start of a zone of authority
Definition: rr.h:93
LDNS_STATUS_SYNTAX_MISSING_VALUE_ERR
Definition: error.h:93
ldns_struct_resolver::_nameserver_count
size_t _nameserver_count
Number of nameservers in _nameservers.
Definition: resolver.h:67
ldns_get_random
uint16_t ldns_get_random(void)
Get random number.
Definition: util.c:400
ldns_struct_resolver::_retry
uint8_t _retry
Number of times to retry before giving up.
Definition: resolver.h:88
ldns_resolver_set_recursive
void ldns_resolver_set_recursive(ldns_resolver *r, bool re)
Definition: resolver.c:379
ldns_struct_resolver::_debug
signed char _debug
Print debug information.
Definition: resolver.h:76
ldns_rr_list_rr
ldns_rr * ldns_rr_list_rr(const ldns_rr_list *rr_list, size_t nr)
returns a specific rr of an rrlist.
Definition: rr.c:954
ldns_resolver_set_defnames
void ldns_resolver_set_defnames(ldns_resolver *r, bool d)
Definition: resolver.c:494
LDNS_RESOLV_CONF
#define LDNS_RESOLV_CONF
Default location of the resolv.conf file.
Definition: resolver.h:36
ldns_axfr_next
ldns_rr * ldns_axfr_next(ldns_resolver *resolver)
Get the next stream of RRs in a AXFR.
Definition: resolver.c:1274
ldns_resolver_trusted_key
bool ldns_resolver_trusted_key(const ldns_resolver *r, ldns_rr_list *keys, ldns_rr_list *trusted_keys)
Returns true if at least one of the provided keys is a trust anchor.
Definition: resolver.c:138
ldns_read_anchor_file
ldns_rr * ldns_read_anchor_file(const char *filename)
Instantiates a DNSKEY or DS RR from file.
Definition: keys.c:1605
ldns_wire2pkt
ldns_status ldns_wire2pkt(ldns_pkt **packet_p, const uint8_t *wire, size_t max)
converts the data on the uint8_t bytearray (in wire format) to a DNS packet.
Definition: wire2host.c:401
ldns_resolver_query_status
ldns_status ldns_resolver_query_status(ldns_pkt **pkt, ldns_resolver *r, const ldns_rdf *name, ldns_rr_type t, ldns_rr_class c, uint16_t flags)
Send a query to a nameserver.
Definition: resolver.c:1036
ldns_resolver_nameservers_randomize
void ldns_resolver_nameservers_randomize(ldns_resolver *r)
Randomize the nameserver list in the resolver.
Definition: resolver.c:1405
ldns_resolver_set_nameserver_count
void ldns_resolver_set_nameserver_count(ldns_resolver *r, size_t c)
Set the resolver&#39;s nameserver count directly.
Definition: resolver.c:458
ldns_resolver_set_fallback
void ldns_resolver_set_fallback(ldns_resolver *r, bool fallback)
Definition: resolver.c:482
ldns_pkt_ancount
uint16_t ldns_pkt_ancount(const ldns_pkt *packet)
Return the packet&#39;s an count.
Definition: packet.c:105
ldns_resolver_usevc
bool ldns_resolver_usevc(const ldns_resolver *r)
Does the resolver use tcp or udp.
Definition: resolver.c:171
ldns_resolver_search
ldns_pkt * ldns_resolver_search(const ldns_resolver *r, const ldns_rdf *name, ldns_rr_type t, ldns_rr_class c, uint16_t flags)
Send the query for using the resolver and take the search list into account The search algorithm is a...
Definition: resolver.c:1024
ldns_resolver_nameserver_count
size_t ldns_resolver_nameserver_count(const ldns_resolver *r)
How many nameserver are configured in the resolver.
Definition: resolver.c:114
ldns_resolver_send
ldns_status ldns_resolver_send(ldns_pkt **answer, ldns_resolver *r, const ldns_rdf *name, ldns_rr_type t, ldns_rr_class c, uint16_t flags)
Send the query for name as-is.
Definition: resolver.c:1207
ldns_struct_resolver::_axfr_soa_count
int _axfr_soa_count
Count the number of LDNS_RR_TYPE_SOA RRs we have seen so far (the second one signifies the end of the...
Definition: resolver.h:121
LDNS_RDF_TYPE_A
A record.
Definition: rdata.h:58
ldns_rr_list_new
ldns_rr_list * ldns_rr_list_new(void)
creates a new rr_list structure.
Definition: rr.c:964
ldns_resolver_edns_udp_size
uint16_t ldns_resolver_edns_udp_size(const ldns_resolver *r)
Get the resolver&#39;s udp size.
Definition: resolver.c:36
ldns_resolver_incr_nameserver_count
void ldns_resolver_incr_nameserver_count(ldns_resolver *r)
Incremental the resolver&#39;s nameserver count.
Definition: resolver.c:523
ldns_resolver_set_random
void ldns_resolver_set_random(ldns_resolver *r, bool b)
Definition: resolver.c:601
LDNS_DEFAULT_TIMEOUT_SEC
#define LDNS_DEFAULT_TIMEOUT_SEC
Definition: net.h:23
ldns_lookup_by_id
ldns_lookup_table * ldns_lookup_by_id(ldns_lookup_table *table, int id)
Definition: util.c:41
LDNS_RESOLV_SORTLIST
#define LDNS_RESOLV_SORTLIST
Definition: resolver.h:44
ldns_struct_resolver::_cur_axfr_pkt
ldns_pkt * _cur_axfr_pkt
Packet currently handled when doing part of an AXFR.
Definition: resolver.h:126
LDNS_RR_CLASS_IN
the Internet
Definition: rr.h:50
LDNS_RDF_TYPE_AAAA
AAAA record.
Definition: rdata.h:60
ldns_struct_resolver::_timeout
struct timeval _timeout
Timeout for socket connections.
Definition: resolver.h:111
LDNS_STATUS_SYNTAX_DNAME_ERR
Definition: error.h:84
ldns_struct_resolver::_nameservers
ldns_rdf ** _nameservers
Array of nameservers to query (IP addresses or dnames)
Definition: resolver.h:65
LDNS_RESOLV_KEYWORD
#define LDNS_RESOLV_KEYWORD
Definition: resolver.h:40
ldns_rdf_new_frm_str
ldns_rdf * ldns_rdf_new_frm_str(ldns_rdf_type type, const char *str)
creates a new rdf from a string.
Definition: rdata.c:249
ldns_dname_cat_clone
ldns_rdf * ldns_dname_cat_clone(const ldns_rdf *rd1, const ldns_rdf *rd2)
concatenates two dnames together
Definition: dname.c:52
ldns_resolver_set_fail
void ldns_resolver_set_fail(ldns_resolver *r, bool f)
Definition: resolver.c:446
LDNS_RR_TYPE_DS
RFC4034, RFC3658.
Definition: rr.h:167
ldns_struct_resolver::_axfr_i
uint16_t _axfr_i
Counter for within the AXFR packets.
Definition: resolver.h:128
ldns_resolver_new
ldns_resolver * ldns_resolver_new(void)
Create a new resolver structure.
Definition: resolver.c:608
ldns_resolver_debug
bool ldns_resolver_debug(const ldns_resolver *r)
Get the debug status of the resolver.
Definition: resolver.c:72
ldns_struct_resolver::_recursive
signed char _recursive
Wether or not to be recursive.
Definition: resolver.h:73
LDNS_STATUS_RES_NO_NS
Definition: error.h:70
LDNS_STATUS_FILE_ERR
Definition: error.h:48
ldns_struct_resolver::_defnames
signed char _defnames
If true append the default domain.
Definition: resolver.h:107
ldns_fget_token_l
ssize_t ldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *line_nr)
returns a token/char from the stream F.
Definition: parse.c:31
LDNS_PORT
#define LDNS_PORT
Definition: ldns.h:133
ldns_resolver_push_nameserver_rr
ldns_status ldns_resolver_push_nameserver_rr(ldns_resolver *r, ldns_rr *rr)
Push a new nameserver to the resolver.
Definition: resolver.c:335
ldns_rdf_get_type
ldns_rdf_type ldns_rdf_get_type(const ldns_rdf *rd)
returns the type of the rdf.
Definition: rdata.c:31
ldns_struct_pkt
DNS packet.
Definition: packet.h:233
ldns_pkt_ixfr_request_new
ldns_pkt * ldns_pkt_ixfr_request_new(ldns_rdf *rr_name, ldns_rr_class rr_class, uint16_t flags, ldns_rr *soa)
creates an IXFR request packet for the given name, type and class.
Definition: packet.c:1042
ldns_resolver_set_port
void ldns_resolver_set_port(ldns_resolver *r, uint16_t p)
Set the port the resolver should use.
Definition: resolver.c:238
ldns_pkt_set_edns_do
void ldns_pkt_set_edns_do(ldns_pkt *packet, bool value)
Definition: packet.c:236
ldns_struct_resolver::_tsig_keyname
char * _tsig_keyname
Name of the key to use with TSIG, if _tsig_keyname and _tsig_keydata both contain values...
Definition: resolver.h:136
ldns_resolver_tsig_keydata
char * ldns_resolver_tsig_keydata(const ldns_resolver *r)
Return the tsig keydata as used by the nameserver.
Definition: resolver.c:219
ldns_rr_get_type
ldns_rr_type ldns_rr_get_type(const ldns_rr *rr)
returns the type of the rr.
Definition: rr.c:907
ldns_tcp_read_wire
uint8_t * ldns_tcp_read_wire(int sockfd, size_t *size)
This routine may block.
Definition: net.c:780
ldns_resolver_random
bool ldns_resolver_random(const ldns_resolver *r)
Does the resolver randomize the nameserver before usage.
Definition: resolver.c:225
ldns_struct_resolver::_domain
ldns_rdf * _domain
Default domain to add to non fully qualified domain names.
Definition: resolver.h:79
LDNS_STATUS_MEM_ERR
Definition: error.h:34
ldns_struct_lookup_table::name
const char * name
Definition: util.h:158
ldns_status
enum ldns_enum_status ldns_status
Definition: error.h:131
ldns_resolver_new_frm_file
ldns_status ldns_resolver_new_frm_file(ldns_resolver **res, const char *filename)
Configure a resolver by means of a resolv.conf file The file may be NULL in which case there will be ...
Definition: resolver.c:908
ldns_pkt_set_cd
void ldns_pkt_set_cd(ldns_pkt *packet, bool cd)
Definition: packet.c:512
LDNS_MALLOC
#define LDNS_MALLOC(type)
Memory management macros.
Definition: util.h:49
ldns_resolver_new_frm_fp_l
ldns_status ldns_resolver_new_frm_fp_l(ldns_resolver **res, FILE *fp, int *line_nr)
Create a resolver structure from a file like /etc/resolv.conf.
Definition: resolver.c:672
ldns_struct_lookup_table
A general purpose lookup table.
Definition: util.h:156
ldns_resolver_retrans
uint8_t ldns_resolver_retrans(const ldns_resolver *r)
Get the retransmit interval.
Definition: resolver.c:48
ldns_struct_resolver::_igntc
signed char _igntc
Whether to ignore the tc bit.
Definition: resolver.h:103
ldns_pkt_tsig_sign
ldns_status ldns_pkt_tsig_sign(ldns_pkt *pkt, const char *key_name, const char *key_data, uint16_t fudge, const char *algorithm_name, ldns_rdf *query_mac)
creates a tsig rr for the given packet and key.
Definition: tsig.c:352
LDNS_PARSE_SKIP_SPACE
#define LDNS_PARSE_SKIP_SPACE
Definition: parse.h:20
ldns_resolver_pop_nameserver
ldns_rdf * ldns_resolver_pop_nameserver(ldns_resolver *r)
pop the last nameserver from the resolver.
Definition: resolver.c:250
ldns_resolver_set_debug
void ldns_resolver_set_debug(ldns_resolver *r, bool d)
Definition: resolver.c:434
LDNS_STATUS_SYNTAX_ERR
Definition: error.h:97
ldns_resolver_rtt
size_t * ldns_resolver_rtt(const ldns_resolver *r)
Return the used round trip times for the nameservers.
Definition: resolver.c:177
ldns_pkt_edns_udp_size
uint16_t ldns_pkt_edns_udp_size(const ldns_pkt *packet)
return the packet&#39;s edns udp size
Definition: packet.c:206
ldns_resolver_set_usevc
void ldns_resolver_set_usevc(ldns_resolver *r, bool vc)
Definition: resolver.c:428
ldns_resolver_fail
bool ldns_resolver_fail(const ldns_resolver *r)
Does the resolver only try the first nameserver.
Definition: resolver.c:84
ldns_resolver_source
ldns_rdf * ldns_resolver_source(const ldns_resolver *r)
Get the source address the resolver should use.
Definition: resolver.c:30
ldns_struct_resolver::_searchlist
ldns_rdf ** _searchlist
Searchlist array, add the names in this array if a query cannot be found.
Definition: resolver.h:82
LDNS_RESOLV_OPTIONS
#define LDNS_RESOLV_OPTIONS
Definition: resolver.h:45
LDNS_STATUS_CRYPTO_TSIG_ERR
Definition: error.h:65
ldns_resolver_set_edns_udp_size
void ldns_resolver_set_edns_udp_size(ldns_resolver *r, uint16_t s)
Set maximum udp size.
Definition: resolver.c:373
ldns_struct_resolver::_dnssec_cd
signed char _dnssec_cd
Whether to set the CD bit on DNSSEC requests.
Definition: resolver.h:97
ldns_struct_resolver::_random
signed char _random
Randomly choose a nameserver.
Definition: resolver.h:115
ldns_struct_resolver::_source
ldns_rdf * _source
Source address to query from.
Definition: resolver.h:143
ldns_pkt_print
void ldns_pkt_print(FILE *output, const ldns_pkt *pkt)
Prints the data in the DNS packet to the given file stream (in presentation format) ...
Definition: host2str.c:2533
ldns_resolver_push_nameserver
ldns_status ldns_resolver_push_nameserver(ldns_resolver *r, ldns_rdf *n)
Push a new nameserver to the resolver.
Definition: resolver.c:288
ldns_resolver_nameservers
ldns_rdf ** ldns_resolver_nameservers(const ldns_resolver *r)
Return the configured nameserver ip address.
Definition: resolver.c:108
ldns_resolver_send_pkt
ldns_status ldns_resolver_send_pkt(ldns_pkt **answer, ldns_resolver *r, ldns_pkt *query_pkt)
Send the given packet to a nameserver.
Definition: resolver.c:1097
ldns_resolver_tsig_keyname
char * ldns_resolver_tsig_keyname(const ldns_resolver *r)
Return the tsig keyname as used by the nameserver.
Definition: resolver.c:207
LDNS_MAX_LINELEN
#define LDNS_MAX_LINELEN
Definition: parse.h:23
ldns_struct_rdf
Resource record data field.
Definition: rdata.h:166
ldns_struct_resolver::_ip6
uint8_t _ip6
Whether to use ip6, 0->does not matter, 1 is IPv4, 2 is IPv6.
Definition: resolver.h:105
LDNS_RCODE_NOERROR
Definition: packet.h:56
ldns_resolver_set_retry
void ldns_resolver_set_retry(ldns_resolver *r, uint8_t retry)
Set the number of times a resolver should retry a nameserver before the next one is tried...
Definition: resolver.c:470
LDNS_RESOLV_INETANY
#define LDNS_RESOLV_INETANY
Definition: resolver.h:49
ldns_rr_list_rr_count
size_t ldns_rr_list_rr_count(const ldns_rr_list *rr_list)
returns the number of rr&#39;s in an rr_list.
Definition: rr.c:921
ldns_resolver_set_dnssec_anchors
void ldns_resolver_set_dnssec_anchors(ldns_resolver *r, ldns_rr_list *l)
Set the resolver&#39;s DNSSEC anchor list directly.
Definition: resolver.c:397
ldns_rr_type
enum ldns_enum_rr_type ldns_rr_type
Definition: rr.h:236
ldns_resolver_set_retrans
void ldns_resolver_set_retrans(ldns_resolver *r, uint8_t retrans)
Set the resolver retrans timeout (in seconds)
Definition: resolver.c:476
LDNS_FREE
#define LDNS_FREE(ptr)
Definition: util.h:60
ldns_struct_resolver::_dnsrch
signed char _dnsrch
If true apply the search list.
Definition: resolver.h:109
ldns_resolver_recursive
bool ldns_resolver_recursive(const ldns_resolver *r)
Is the resolver set to recurse.
Definition: resolver.c:66
ldns_pkt_set_random_id
void ldns_pkt_set_random_id(ldns_pkt *packet)
Set the packet&#39;s id to a random value.
Definition: packet.c:456
ldns_resolver_set_ip6
void ldns_resolver_set_ip6(ldns_resolver *r, uint8_t ip6)
Whether the resolver uses ip6.
Definition: resolver.c:440
ldns_dname_absolute
bool ldns_dname_absolute(const ldns_rdf *rdf)
Checks whether the given dname is absolute (i.e.
Definition: dname.c:544
ldns_resolver_set_dnssec_cd
void ldns_resolver_set_dnssec_cd(ldns_resolver *r, bool d)
Definition: resolver.c:391
ldns_get_errorstr_by_id
const char * ldns_get_errorstr_by_id(ldns_status err)
look up a descriptive text by each error.
Definition: error.c:150
ldns_resolver_new_frm_fp
ldns_status ldns_resolver_new_frm_fp(ldns_resolver **res, FILE *fp)
Create a resolver structure from a file like /etc/resolv.conf.
Definition: resolver.c:666
ldns_struct_resolver::_socket
int _socket
Keep some things to make AXFR possible.
Definition: resolver.h:117
LDNS_RDF_TYPE_DNAME
domain name
Definition: rdata.h:50
ldns_axfr_abort
void ldns_axfr_abort(ldns_resolver *resolver)
Definition: resolver.c:1376
ldns_resolver_set_dnsrch
void ldns_resolver_set_dnsrch(ldns_resolver *r, bool d)
Definition: resolver.c:464
ldns_buffer_new_frm_data
void ldns_buffer_new_frm_data(ldns_buffer *buffer, void *data, size_t size)
creates a buffer with the specified data.
Definition: buffer.c:41
ldns_pkt_answer
ldns_rr_list * ldns_pkt_answer(const ldns_pkt *packet)
Return the packet&#39;s answer section.
Definition: packet.c:129
ldns_resolver_set_tsig_keydata
void ldns_resolver_set_tsig_keydata(ldns_resolver *r, char *tsig_keydata)
Set the tsig key data.
Definition: resolver.c:594
LDNS_RR_TYPE_IXFR
Definition: rr.h:212
ldns_struct_resolver::_tsig_keydata
char * _tsig_keydata
Secret key data to use with TSIG, if _tsig_keyname and _tsig_keydata both contain values...
Definition: resolver.h:138
ldns_pkt_free
void ldns_pkt_free(ldns_pkt *packet)
frees the packet structure and all data that it contains.
Definition: packet.c:784
LDNS_DEFAULT_TIMEOUT_USEC
#define LDNS_DEFAULT_TIMEOUT_USEC
Definition: net.h:24
LDNS_STATUS_ERR
Definition: error.h:37
config.h
ldns_resolver_dec_nameserver_count
void ldns_resolver_dec_nameserver_count(ldns_resolver *r)
Decrement the resolver&#39;s nameserver count.
Definition: resolver.c:532
ldns_resolver_domain
ldns_rdf * ldns_resolver_domain(const ldns_resolver *r)
What is the default dname to add to relative queries.
Definition: resolver.c:96
ldns_resolver_timeout
struct timeval ldns_resolver_timeout(const ldns_resolver *r)
What is the timeout on socket connections.
Definition: resolver.c:201
ldns_struct_resolver::_fallback
signed char _fallback
Use new fallback mechanism (try EDNS, then do TCP)
Definition: resolver.h:92
ldns_pkt_set_timestamp
void ldns_pkt_set_timestamp(ldns_pkt *packet, struct timeval timeval)
Set the packet&#39;s timestamp.
Definition: packet.c:578