2 * daemon/cachedump.c - dump the cache to text format.
4 * Copyright (c) 2008, NLnet Labs. All rights reserved.
6 * This software is open source.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
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.
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.
39 * This file contains functions to read and write the cache(s)
43 #include <ldns/ldns.h>
44 #include "daemon/cachedump.h"
45 #include "daemon/remote.h"
46 #include "daemon/worker.h"
47 #include "services/cache/rrset.h"
48 #include "services/cache/dns.h"
49 #include "services/cache/infra.h"
50 #include "util/data/msgreply.h"
51 #include "util/regional.h"
52 #include "util/net_help.h"
53 #include "util/data/dname.h"
54 #include "iterator/iterator.h"
55 #include "iterator/iter_delegpt.h"
56 #include "iterator/iter_utils.h"
57 #include "iterator/iter_fwd.h"
58 #include "iterator/iter_hints.h"
60 /** convert to ldns rr */
62 to_rr(struct ub_packed_rrset_key* k, struct packed_rrset_data* d,
63 time_t now, size_t i, uint16_t type)
65 ldns_rr* rr = ldns_rr_new();
69 log_assert(i < d->count + d->rrsig_count);
73 ldns_rr_set_type(rr, type);
74 ldns_rr_set_class(rr, ntohs(k->rk.rrset_class));
75 if(d->rr_ttl[i] < now)
76 ldns_rr_set_ttl(rr, 0);
77 else ldns_rr_set_ttl(rr, d->rr_ttl[i] - now);
79 status = ldns_wire2dname(&rdf, k->rk.dname, k->rk.dname_len, &pos);
80 if(status != LDNS_STATUS_OK) {
81 /* we drop detailed error in status */
85 ldns_rr_set_owner(rr, rdf);
87 status = ldns_wire2rdf(rr, d->rr_data[i], d->rr_len[i], &pos);
88 if(status != LDNS_STATUS_OK) {
89 /* we drop detailed error in status */
96 /** dump one rrset zonefile line */
98 dump_rrset_line(SSL* ssl, struct ub_packed_rrset_key* k,
99 struct packed_rrset_data* d, time_t now, size_t i, uint16_t type)
102 ldns_rr* rr = to_rr(k, d, now, i, type);
104 return ssl_printf(ssl, "BADRR\n");
109 return ssl_printf(ssl, "BADRR\n");
111 if(!ssl_printf(ssl, "%s", s)) {
119 /** dump rrset key and data info */
121 dump_rrset(SSL* ssl, struct ub_packed_rrset_key* k,
122 struct packed_rrset_data* d, time_t now)
125 /* rd lock held by caller */
126 if(!k || !d) return 1;
127 if(d->ttl < now) return 1; /* expired */
130 if(!ssl_printf(ssl, ";rrset%s %lld %u %u %d %d\n",
131 (k->rk.flags & PACKED_RRSET_NSEC_AT_APEX)?" nsec_apex":"",
132 (long long)(d->ttl - now),
133 (unsigned)d->count, (unsigned)d->rrsig_count,
134 (int)d->trust, (int)d->security
137 for(i=0; i<d->count; i++) {
138 if(!dump_rrset_line(ssl, k, d, now, i, ntohs(k->rk.type)))
141 for(i=0; i<d->rrsig_count; i++) {
142 if(!dump_rrset_line(ssl, k, d, now, i+d->count,
150 /** dump lruhash rrset cache */
152 dump_rrset_lruhash(SSL* ssl, struct lruhash* h, time_t now)
154 struct lruhash_entry* e;
155 /* lruhash already locked by caller */
156 /* walk in order of lru; best first */
157 for(e=h->lru_start; e; e = e->lru_next) {
158 lock_rw_rdlock(&e->lock);
159 if(!dump_rrset(ssl, (struct ub_packed_rrset_key*)e->key,
160 (struct packed_rrset_data*)e->data, now)) {
161 lock_rw_unlock(&e->lock);
164 lock_rw_unlock(&e->lock);
169 /** dump rrset cache */
171 dump_rrset_cache(SSL* ssl, struct worker* worker)
173 struct rrset_cache* r = worker->env.rrset_cache;
175 if(!ssl_printf(ssl, "START_RRSET_CACHE\n")) return 0;
176 for(slab=0; slab<r->table.size; slab++) {
177 lock_quick_lock(&r->table.array[slab]->lock);
178 if(!dump_rrset_lruhash(ssl, r->table.array[slab],
180 lock_quick_unlock(&r->table.array[slab]->lock);
183 lock_quick_unlock(&r->table.array[slab]->lock);
185 return ssl_printf(ssl, "END_RRSET_CACHE\n");
188 /** dump message to rrset reference */
190 dump_msg_ref(SSL* ssl, struct ub_packed_rrset_key* k)
198 status = ldns_wire2dname(&rdf, k->rk.dname, k->rk.dname_len, &pos);
199 if(status != LDNS_STATUS_OK) {
200 return ssl_printf(ssl, "BADREF\n");
202 nm = ldns_rdf2str(rdf);
203 ldns_rdf_deep_free(rdf);
204 tp = ldns_rr_type2str(ntohs(k->rk.type));
205 cl = ldns_rr_class2str(ntohs(k->rk.rrset_class));
206 if(!nm || !cl || !tp) {
210 return ssl_printf(ssl, "BADREF\n");
212 if(!ssl_printf(ssl, "%s %s %s %d\n", nm, cl, tp, (int)k->rk.flags)) {
225 /** dump message entry */
227 dump_msg(SSL* ssl, struct query_info* k, struct reply_info* d,
235 if(!k || !d) return 1;
236 if(d->ttl < now) return 1; /* expired */
239 status = ldns_wire2dname(&rdf, k->qname, k->qname_len, &pos);
240 if(status != LDNS_STATUS_OK) {
241 return 1; /* skip this entry */
243 nm = ldns_rdf2str(rdf);
244 ldns_rdf_deep_free(rdf);
245 tp = ldns_rr_type2str(k->qtype);
246 cl = ldns_rr_class2str(k->qclass);
247 if(!nm || !tp || !cl) {
251 return 1; /* skip this entry */
253 if(!rrset_array_lock(d->ref, d->rrset_count, now)) {
254 /* rrsets have timed out or do not exist */
258 return 1; /* skip this entry */
262 if(!ssl_printf(ssl, "msg %s %s %s %d %d %lld %d %u %u %u\n",
264 (int)d->flags, (int)d->qdcount,
265 (long long)(d->ttl-now), (int)d->security,
266 (unsigned)d->an_numrrsets,
267 (unsigned)d->ns_numrrsets,
268 (unsigned)d->ar_numrrsets)) {
272 rrset_array_unlock(d->ref, d->rrset_count);
279 for(i=0; i<d->rrset_count; i++) {
280 if(!dump_msg_ref(ssl, d->rrsets[i])) {
281 rrset_array_unlock(d->ref, d->rrset_count);
285 rrset_array_unlock(d->ref, d->rrset_count);
290 /** copy msg to worker pad */
292 copy_msg(struct regional* region, struct lruhash_entry* e,
293 struct query_info** k, struct reply_info** d)
295 struct reply_info* rep = (struct reply_info*)e->data;
296 *d = (struct reply_info*)regional_alloc_init(region, e->data,
297 sizeof(struct reply_info) +
298 sizeof(struct rrset_ref) * (rep->rrset_count-1) +
299 sizeof(struct ub_packed_rrset_key*) * rep->rrset_count);
302 (*d)->rrsets = (struct ub_packed_rrset_key**)(
303 (uint8_t*)(&((*d)->ref[0])) +
304 sizeof(struct rrset_ref) * rep->rrset_count);
305 *k = (struct query_info*)regional_alloc_init(region,
306 e->key, sizeof(struct query_info));
309 (*k)->qname = regional_alloc_init(region,
310 (*k)->qname, (*k)->qname_len);
311 return (*k)->qname != NULL;
314 /** dump lruhash msg cache */
316 dump_msg_lruhash(SSL* ssl, struct worker* worker, struct lruhash* h)
318 struct lruhash_entry* e;
319 struct query_info* k;
320 struct reply_info* d;
322 /* lruhash already locked by caller */
323 /* walk in order of lru; best first */
324 for(e=h->lru_start; e; e = e->lru_next) {
325 regional_free_all(worker->scratchpad);
326 lock_rw_rdlock(&e->lock);
327 /* make copy of rrset in worker buffer */
328 if(!copy_msg(worker->scratchpad, e, &k, &d)) {
329 lock_rw_unlock(&e->lock);
332 lock_rw_unlock(&e->lock);
333 /* release lock so we can lookup the rrset references
334 * in the rrset cache */
335 if(!dump_msg(ssl, k, d, *worker->env.now)) {
342 /** dump msg cache */
344 dump_msg_cache(SSL* ssl, struct worker* worker)
346 struct slabhash* sh = worker->env.msg_cache;
348 if(!ssl_printf(ssl, "START_MSG_CACHE\n")) return 0;
349 for(slab=0; slab<sh->size; slab++) {
350 lock_quick_lock(&sh->array[slab]->lock);
351 if(!dump_msg_lruhash(ssl, worker, sh->array[slab])) {
352 lock_quick_unlock(&sh->array[slab]->lock);
355 lock_quick_unlock(&sh->array[slab]->lock);
357 return ssl_printf(ssl, "END_MSG_CACHE\n");
361 dump_cache(SSL* ssl, struct worker* worker)
363 if(!dump_rrset_cache(ssl, worker))
365 if(!dump_msg_cache(ssl, worker))
367 return ssl_printf(ssl, "EOF\n");
370 /** read a line from ssl into buffer */
372 ssl_read_buf(SSL* ssl, ldns_buffer* buf)
374 return ssl_read_line(ssl, (char*)ldns_buffer_begin(buf),
375 ldns_buffer_capacity(buf));
378 /** check fixed text on line */
380 read_fixed(SSL* ssl, ldns_buffer* buf, const char* str)
382 if(!ssl_read_buf(ssl, buf)) return 0;
383 return (strcmp((char*)ldns_buffer_begin(buf), str) == 0);
386 /** load an RR into rrset */
388 load_rr(SSL* ssl, ldns_buffer* buf, struct regional* region,
389 struct ub_packed_rrset_key* rk, struct packed_rrset_data* d,
390 unsigned int i, int is_rrsig, int* go_on, time_t now)
396 if(!ssl_read_buf(ssl, buf))
398 if(strncmp((char*)ldns_buffer_begin(buf), "BADRR\n", 6) == 0) {
402 status = ldns_rr_new_frm_str(&rr, (char*)ldns_buffer_begin(buf),
403 LDNS_DEFAULT_TTL, NULL, NULL);
404 if(status != LDNS_STATUS_OK) {
405 log_warn("error cannot parse rr: %s: %s",
406 ldns_get_errorstr_by_id(status),
407 (char*)ldns_buffer_begin(buf));
410 if(is_rrsig && ldns_rr_get_type(rr) != LDNS_RR_TYPE_RRSIG) {
411 log_warn("error expected rrsig but got %s",
412 (char*)ldns_buffer_begin(buf));
416 /* convert ldns rr into packed_rr */
417 d->rr_ttl[i] = ldns_rr_ttl(rr) + now;
418 ldns_buffer_clear(buf);
419 ldns_buffer_skip(buf, 2);
420 status = ldns_rr_rdata2buffer_wire(buf, rr);
421 if(status != LDNS_STATUS_OK) {
422 log_warn("error cannot rr2wire: %s",
423 ldns_get_errorstr_by_id(status));
427 ldns_buffer_flip(buf);
428 ldns_buffer_write_u16_at(buf, 0, ldns_buffer_limit(buf) - 2);
430 d->rr_len[i] = ldns_buffer_limit(buf);
431 d->rr_data[i] = (uint8_t*)regional_alloc_init(region,
432 ldns_buffer_begin(buf), ldns_buffer_limit(buf));
435 log_warn("error out of memory");
439 /* if first entry, fill the key structure */
441 rk->rk.type = htons(ldns_rr_get_type(rr));
442 rk->rk.rrset_class = htons(ldns_rr_get_class(rr));
443 ldns_buffer_clear(buf);
444 status = ldns_dname2buffer_wire(buf, ldns_rr_owner(rr));
445 if(status != LDNS_STATUS_OK) {
446 log_warn("error cannot dname2buffer: %s",
447 ldns_get_errorstr_by_id(status));
451 ldns_buffer_flip(buf);
452 rk->rk.dname_len = ldns_buffer_limit(buf);
453 rk->rk.dname = regional_alloc_init(region,
454 ldns_buffer_begin(buf), ldns_buffer_limit(buf));
456 log_warn("error out of memory");
466 /** move entry into cache */
468 move_into_cache(struct ub_packed_rrset_key* k,
469 struct packed_rrset_data* d, struct worker* worker)
471 struct ub_packed_rrset_key* ak;
472 struct packed_rrset_data* ad;
473 size_t s, i, num = d->count + d->rrsig_count;
474 struct rrset_ref ref;
477 ak = alloc_special_obtain(&worker->alloc);
479 log_warn("error out of memory");
482 ak->entry.data = NULL;
484 ak->entry.hash = rrset_key_hash(&k->rk);
485 ak->rk.dname = (uint8_t*)memdup(k->rk.dname, k->rk.dname_len);
487 log_warn("error out of memory");
488 ub_packed_rrset_parsedelete(ak, &worker->alloc);
491 s = sizeof(*ad) + (sizeof(size_t) + sizeof(uint8_t*) +
492 sizeof(time_t))* num;
495 ad = (struct packed_rrset_data*)malloc(s);
497 log_warn("error out of memory");
498 ub_packed_rrset_parsedelete(ak, &worker->alloc);
502 memmove(p, d, sizeof(*ad));
504 memmove(p, &d->rr_len[0], sizeof(size_t)*num);
505 p += sizeof(size_t)*num;
506 memmove(p, &d->rr_data[0], sizeof(uint8_t*)*num);
507 p += sizeof(uint8_t*)*num;
508 memmove(p, &d->rr_ttl[0], sizeof(time_t)*num);
509 p += sizeof(time_t)*num;
510 for(i=0; i<num; i++) {
511 memmove(p, d->rr_data[i], d->rr_len[i]);
514 packed_rrset_ptr_fixup(ad);
520 (void)rrset_cache_update(worker->env.rrset_cache, &ref,
521 &worker->alloc, *worker->env.now);
525 /** load an rrset entry */
527 load_rrset(SSL* ssl, ldns_buffer* buf, struct worker* worker)
529 char* s = (char*)ldns_buffer_begin(buf);
530 struct regional* region = worker->scratchpad;
531 struct ub_packed_rrset_key* rk;
532 struct packed_rrset_data* d;
533 unsigned int rr_count, rrsig_count, trust, security;
537 regional_free_all(region);
539 rk = (struct ub_packed_rrset_key*)regional_alloc_zero(region,
541 d = (struct packed_rrset_data*)regional_alloc_zero(region, sizeof(*d));
543 log_warn("error out of memory");
547 if(strncmp(s, ";rrset", 6) != 0) {
548 log_warn("error expected ';rrset' but got %s", s);
552 if(strncmp(s, " nsec_apex", 10) == 0) {
554 rk->rk.flags |= PACKED_RRSET_NSEC_AT_APEX;
556 if(sscanf(s, " %lld %u %u %u %u", &ttl, &rr_count, &rrsig_count,
557 &trust, &security) != 5) {
558 log_warn("error bad rrset spec %s", s);
561 if(rr_count == 0 && rrsig_count == 0) {
562 log_warn("bad rrset without contents");
565 d->count = (size_t)rr_count;
566 d->rrsig_count = (size_t)rrsig_count;
567 d->security = (enum sec_status)security;
568 d->trust = (enum rrset_trust)trust;
569 d->ttl = (time_t)ttl + *worker->env.now;
571 d->rr_len = regional_alloc_zero(region,
572 sizeof(size_t)*(d->count+d->rrsig_count));
573 d->rr_ttl = regional_alloc_zero(region,
574 sizeof(time_t)*(d->count+d->rrsig_count));
575 d->rr_data = regional_alloc_zero(region,
576 sizeof(uint8_t*)*(d->count+d->rrsig_count));
577 if(!d->rr_len || !d->rr_ttl || !d->rr_data) {
578 log_warn("error out of memory");
582 /* read the rr's themselves */
583 for(i=0; i<rr_count; i++) {
584 if(!load_rr(ssl, buf, region, rk, d, i, 0,
585 &go_on, *worker->env.now)) {
586 log_warn("could not read rr %u", i);
590 for(i=0; i<rrsig_count; i++) {
591 if(!load_rr(ssl, buf, region, rk, d, i+rr_count, 1,
592 &go_on, *worker->env.now)) {
593 log_warn("could not read rrsig %u", i);
598 /* skip this entry */
602 return move_into_cache(rk, d, worker);
605 /** load rrset cache */
607 load_rrset_cache(SSL* ssl, struct worker* worker)
609 ldns_buffer* buf = worker->env.scratch_buffer;
610 if(!read_fixed(ssl, buf, "START_RRSET_CACHE")) return 0;
611 while(ssl_read_buf(ssl, buf) &&
612 strcmp((char*)ldns_buffer_begin(buf), "END_RRSET_CACHE")!=0) {
613 if(!load_rrset(ssl, buf, worker))
619 /** read qinfo from next three words */
621 load_qinfo(char* str, struct query_info* qinfo, ldns_buffer* buf,
622 struct regional* region)
624 /* s is part of the buf */
629 /* skip three words */
630 s = strchr(str, ' ');
631 if(s) s = strchr(s+1, ' ');
632 if(s) s = strchr(s+1, ' ');
634 log_warn("error line too short, %s", str);
641 status = ldns_rr_new_question_frm_str(&rr, str, NULL, NULL);
642 if(status != LDNS_STATUS_OK) {
643 log_warn("error cannot parse: %s %s",
644 ldns_get_errorstr_by_id(status), str);
647 qinfo->qtype = ldns_rr_get_type(rr);
648 qinfo->qclass = ldns_rr_get_class(rr);
649 ldns_buffer_clear(buf);
650 status = ldns_dname2buffer_wire(buf, ldns_rr_owner(rr));
652 if(status != LDNS_STATUS_OK) {
653 log_warn("error cannot dname2wire: %s",
654 ldns_get_errorstr_by_id(status));
657 ldns_buffer_flip(buf);
658 qinfo->qname_len = ldns_buffer_limit(buf);
659 qinfo->qname = (uint8_t*)regional_alloc_init(region,
660 ldns_buffer_begin(buf), ldns_buffer_limit(buf));
662 log_warn("error out of memory");
669 /** load a msg rrset reference */
671 load_ref(SSL* ssl, ldns_buffer* buf, struct worker* worker,
672 struct regional *region, struct ub_packed_rrset_key** rrset,
675 char* s = (char*)ldns_buffer_begin(buf);
676 struct query_info qinfo;
678 struct ub_packed_rrset_key* k;
681 if(!ssl_read_buf(ssl, buf))
683 if(strncmp(s, "BADREF", 6) == 0) {
684 *go_on = 0; /* its bad, skip it and skip message */
688 s = load_qinfo(s, &qinfo, buf, region);
692 if(sscanf(s, " %u", &flags) != 1) {
693 log_warn("error cannot parse flags: %s", s);
697 /* lookup in cache */
698 k = rrset_cache_lookup(worker->env.rrset_cache, qinfo.qname,
699 qinfo.qname_len, qinfo.qtype, qinfo.qclass,
700 (uint32_t)flags, *worker->env.now, 0);
702 /* not found or expired */
707 /* store in result */
708 *rrset = packed_rrset_copy_region(k, region, *worker->env.now);
709 lock_rw_unlock(&k->entry.lock);
711 return (*rrset != NULL);
714 /** load a msg entry */
716 load_msg(SSL* ssl, ldns_buffer* buf, struct worker* worker)
718 struct regional* region = worker->scratchpad;
719 struct query_info qinf;
720 struct reply_info rep;
721 char* s = (char*)ldns_buffer_begin(buf);
722 unsigned int flags, qdcount, security, an, ns, ar;
727 regional_free_all(region);
729 if(strncmp(s, "msg ", 4) != 0) {
730 log_warn("error expected msg but got %s", s);
734 s = load_qinfo(s, &qinf, buf, region);
739 /* read remainder of line */
740 if(sscanf(s, " %u %u %lld %u %u %u %u", &flags, &qdcount, &ttl,
741 &security, &an, &ns, &ar) != 7) {
742 log_warn("error cannot parse numbers: %s", s);
745 rep.flags = (uint16_t)flags;
746 rep.qdcount = (uint16_t)qdcount;
747 rep.ttl = (time_t)ttl;
748 rep.prefetch_ttl = PREFETCH_TTL_CALC(rep.ttl);
749 rep.security = (enum sec_status)security;
750 rep.an_numrrsets = (size_t)an;
751 rep.ns_numrrsets = (size_t)ns;
752 rep.ar_numrrsets = (size_t)ar;
753 rep.rrset_count = (size_t)an+(size_t)ns+(size_t)ar;
754 rep.rrsets = (struct ub_packed_rrset_key**)regional_alloc_zero(
755 region, sizeof(struct ub_packed_rrset_key*)*rep.rrset_count);
757 /* fill repinfo with references */
758 for(i=0; i<rep.rrset_count; i++) {
759 if(!load_ref(ssl, buf, worker, region, &rep.rrsets[i],
766 return 1; /* skip this one, not all references satisfied */
768 if(!dns_cache_store(&worker->env, &qinf, &rep, 0, 0, 0, NULL)) {
769 log_warn("error out of memory");
775 /** load msg cache */
777 load_msg_cache(SSL* ssl, struct worker* worker)
779 ldns_buffer* buf = worker->env.scratch_buffer;
780 if(!read_fixed(ssl, buf, "START_MSG_CACHE")) return 0;
781 while(ssl_read_buf(ssl, buf) &&
782 strcmp((char*)ldns_buffer_begin(buf), "END_MSG_CACHE")!=0) {
783 if(!load_msg(ssl, buf, worker))
790 load_cache(SSL* ssl, struct worker* worker)
792 if(!load_rrset_cache(ssl, worker))
794 if(!load_msg_cache(ssl, worker))
796 return read_fixed(ssl, worker->env.scratch_buffer, "EOF");
799 /** print details on a delegation point */
801 print_dp_details(SSL* ssl, struct worker* worker, struct delegpt* dp)
804 struct delegpt_addr* a;
805 int lame, dlame, rlame, rto, edns_vs, to, delay,
806 tA = 0, tAAAA = 0, tother = 0;
809 uint8_t edns_lame_known;
810 for(a = dp->target_list; a; a = a->next_target) {
811 addr_to_str(&a->addr, a->addrlen, buf, sizeof(buf));
812 if(!ssl_printf(ssl, "%-16s\t", buf))
815 if(!ssl_printf(ssl, "Address is BOGUS. "))
818 /* lookup in infra cache */
820 entry_ttl = infra_get_host_rto(worker->env.infra_cache,
821 &a->addr, a->addrlen, dp->name, dp->namelen,
822 &ri, &delay, *worker->env.now, &tA, &tAAAA, &tother);
823 if(entry_ttl == -2 && ri.rto >= USEFUL_SERVER_TOP_TIMEOUT) {
824 if(!ssl_printf(ssl, "expired, rto %d msec, tA %d "
825 "tAAAA %d tother %d.\n", ri.rto, tA, tAAAA,
830 if(entry_ttl == -1 || entry_ttl == -2) {
831 if(!ssl_printf(ssl, "not in infra cache.\n"))
833 continue; /* skip stuff not in infra cache */
836 /* uses type_A because most often looked up, but other
837 * lameness won't be reported then */
838 if(!infra_get_lame_rtt(worker->env.infra_cache,
839 &a->addr, a->addrlen, dp->name, dp->namelen,
840 LDNS_RR_TYPE_A, &lame, &dlame, &rlame, &rto,
842 if(!ssl_printf(ssl, "not in infra cache.\n"))
844 continue; /* skip stuff not in infra cache */
846 if(!ssl_printf(ssl, "%s%s%s%srto %d msec, ttl %lld, ping %d "
847 "var %d rtt %d, tA %d, tAAAA %d, tother %d",
848 lame?"LAME ":"", dlame?"NoDNSSEC ":"",
849 a->lame?"AddrWasParentSide ":"",
850 rlame?"NoAuthButRecursive ":"", rto, entry_ttl,
851 ri.srtt, ri.rttvar, rtt_notimeout(&ri),
855 if(!ssl_printf(ssl, ", probedelay %d", delay))
857 if(infra_host(worker->env.infra_cache, &a->addr, a->addrlen,
858 dp->name, dp->namelen, *worker->env.now, &edns_vs,
859 &edns_lame_known, &to)) {
861 if(!ssl_printf(ssl, ", noEDNS%s.",
862 edns_lame_known?" probed":" assumed"))
865 if(!ssl_printf(ssl, ", EDNS %d%s.", edns_vs,
866 edns_lame_known?" probed":" assumed"))
870 if(!ssl_printf(ssl, "\n"))
875 /** print main dp info */
877 print_dp_main(SSL* ssl, struct delegpt* dp, struct dns_msg* msg)
879 size_t i, n_ns, n_miss, n_addr, n_res, n_avail;
883 for(i=0; i<msg->rep->rrset_count; i++) {
884 struct ub_packed_rrset_key* k = msg->rep->rrsets[i];
885 struct packed_rrset_data* d =
886 (struct packed_rrset_data*)k->entry.data;
887 if(d->security == sec_status_bogus) {
888 if(!ssl_printf(ssl, "Address is BOGUS:\n"))
891 if(!dump_rrset(ssl, k, d, 0))
894 delegpt_count_ns(dp, &n_ns, &n_miss);
895 delegpt_count_addr(dp, &n_addr, &n_res, &n_avail);
896 /* since dp has not been used by iterator, all are available*/
897 if(!ssl_printf(ssl, "Delegation with %d names, of which %d "
898 "can be examined to query further addresses.\n"
899 "%sIt provides %d IP addresses.\n",
900 (int)n_ns, (int)n_miss, (dp->bogus?"It is BOGUS. ":""),
905 int print_deleg_lookup(SSL* ssl, struct worker* worker, uint8_t* nm,
906 size_t nmlen, int ATTR_UNUSED(nmlabs))
908 /* deep links into the iterator module */
911 struct regional* region = worker->scratchpad;
913 struct query_info qinfo;
914 struct iter_hints_stub* stub;
915 regional_free_all(region);
917 qinfo.qname_len = nmlen;
918 qinfo.qtype = LDNS_RR_TYPE_A;
919 qinfo.qclass = LDNS_RR_CLASS_IN;
922 if(!ssl_printf(ssl, "The following name servers are used for lookup "
926 dp = forwards_lookup(worker->env.fwds, nm, qinfo.qclass);
928 if(!ssl_printf(ssl, "forwarding request:\n"))
930 print_dp_main(ssl, dp, NULL);
931 print_dp_details(ssl, worker, dp);
936 dp = dns_cache_find_delegation(&worker->env, nm, nmlen,
937 qinfo.qtype, qinfo.qclass, region, &msg,
940 return ssl_printf(ssl, "no delegation from "
941 "cache; goes to configured roots\n");
944 if(iter_dp_is_useless(&qinfo, BIT_RD, dp)) {
945 print_dp_main(ssl, dp, msg);
946 print_dp_details(ssl, worker, dp);
947 if(!ssl_printf(ssl, "cache delegation was "
948 "useless (no IP addresses)\n"))
950 if(dname_is_root(nm)) {
951 /* goes to root config */
952 return ssl_printf(ssl, "no delegation from "
953 "cache; goes to configured roots\n");
955 /* useless, goes up */
958 dname_remove_label(&nm, &nmlen);
960 if(!ssl_printf(ssl, "going up, lookup %s\n", b))
965 stub = hints_lookup_stub(worker->env.hints, nm, qinfo.qclass,
969 if(!ssl_printf(ssl, "The noprime stub servers "
973 if(!ssl_printf(ssl, "The stub is primed "
977 print_dp_main(ssl, stub->dp, NULL);
978 print_dp_details(ssl, worker, stub->dp);
980 print_dp_main(ssl, dp, msg);
981 print_dp_details(ssl, worker, dp);