diff --git a/CHANGES b/CHANGES index d332035634..e85280eda5 100644 --- a/CHANGES +++ b/CHANGES @@ -64,7 +64,8 @@ 1716. [doc] named.conf(5) was being installed in the wrong location. [RT# 12441] -1715. [placeholder] rt11681 +1715. [func] 'dig +trace' now randomly selects the next servers + to try. Report if there is a bad delegation. 1714. [bug] dig/host/nslookup were only trying the first address when a nameserver was specified by name. diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index a77a5a732b..8b3fe08407 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dighost.c,v 1.269 2004/10/05 03:01:47 marka Exp $ */ +/* $Id: dighost.c,v 1.270 2004/10/07 02:21:48 marka Exp $ */ /* * Notice to programmers: Do not use this code as an example of how to @@ -1405,6 +1405,7 @@ followup_lookup(dns_message_t *msg, dig_query_t *query, dns_section_t section) isc_result_t result; isc_boolean_t success = ISC_FALSE; int numLookups = 0; + dns_name_t *domain; INSIST(!free_now); @@ -1431,6 +1432,20 @@ followup_lookup(dns_message_t *msg, dig_query_t *query, dns_section_t section) debug("found NS set"); + if (query->lookup->trace && !query->lookup->trace_root) { + dns_namereln_t namereln; + unsigned int nlabels; + int order; + + domain = dns_fixedname_name(&query->lookup->fdomain); + namereln = dns_name_fullcompare(name, domain, + &order, &nlabels); + if (namereln == dns_namereln_equal) + printf(";; BAD (HORIZONTAL) REFERRAL\n"); + else if (namereln != dns_namereln_subdomain) + printf(";; BAD REFERRAL\n"); + } + for (result = dns_rdataset_first(rdataset); result == ISC_R_SUCCESS; result = dns_rdataset_next(rdataset)) { @@ -1466,6 +1481,9 @@ followup_lookup(dns_message_t *msg, dig_query_t *query, dns_section_t section) lookup->ns_search_only = query->lookup->ns_search_only; lookup->trace_root = ISC_FALSE; + dns_fixedname_init(&lookup->fdomain); + domain = dns_fixedname_name(&lookup->fdomain); + dns_name_copy(name, domain, NULL); } srv = make_server(namestr, namestr); debug("adding server %s", srv->servername); @@ -1479,7 +1497,29 @@ followup_lookup(dns_message_t *msg, dig_query_t *query, dns_section_t section) (query->lookup->trace || query->lookup->ns_search_only)) return (followup_lookup(msg, query, DNS_SECTION_AUTHORITY)); - return numLookups; + /* + * Randomize the order the nameserver will be tried. + */ + if (numLookups > 1) { + isc_uint32_t i, j; + dig_serverlist_t my_server_list; + + ISC_LIST_INIT(my_server_list); + + for (i = numLookups; i > 0; i--) { + isc_random_get(&j); + j %= i; + srv = ISC_LIST_HEAD(lookup->my_server_list); + while (j-- > 0) + srv = ISC_LIST_NEXT(srv, link); + ISC_LIST_DEQUEUE(lookup->my_server_list, srv, link); + ISC_LIST_APPEND(my_server_list, srv, link); + } + ISC_LIST_APPENDLIST(lookup->my_server_list, + my_server_list, link); + } + + return (numLookups); } /* diff --git a/bin/dig/include/dig/dig.h b/bin/dig/include/dig/dig.h index 555206c56a..b6b4a39452 100644 --- a/bin/dig/include/dig/dig.h +++ b/bin/dig/include/dig/dig.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dig.h,v 1.86 2004/09/06 01:24:44 marka Exp $ */ +/* $Id: dig.h,v 1.87 2004/10/07 02:21:48 marka Exp $ */ #ifndef DIG_H #define DIG_H @@ -176,6 +176,7 @@ isc_boolean_t sigchase; dst_context_t *tsigctx; isc_buffer_t *querysig; isc_uint32_t msgcounter; + dns_fixedname_t fdomain; }; struct dig_query {