From 0dabedcca5db7933cae1cb8a4a87b14042f64d96 Mon Sep 17 00:00:00 2001 From: Michael Sawyer Date: Mon, 25 Sep 2000 23:10:00 +0000 Subject: [PATCH] Add +fail option to try next server after a SERVFAIL Fix some minor problems in some of the new option processing code. Slight change in mem debugging TODO changes --- bin/dig/dig.c | 17 +++++++++++------ bin/dig/dighost.c | 34 +++++++++++++++++++++++++++++++++- bin/dig/include/dig/dig.h | 3 ++- doc/todo/mws/todo | 6 +++++- 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/bin/dig/dig.c b/bin/dig/dig.c index bb1de72244..fd41c000d3 100644 --- a/bin/dig/dig.c +++ b/bin/dig/dig.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dig.c,v 1.101 2000/09/25 16:14:20 mws Exp $ */ +/* $Id: dig.c,v 1.102 2000/09/25 23:09:56 mws Exp $ */ #include #include @@ -160,6 +160,7 @@ show_usage(void) { " +[no]recursive (Recursive mode)\n" " +[no]ignore (Don't revert to TCP for TC responses.)" "\n" +" +[no]fail (Try next server on SERVFAIL reply)\n" " +[no]aaonly (Set AA flag in query)\n" " +[no]adflag (Set AD flag in query)\n" " +[no]cdflag (Set CD flag in query)\n" @@ -596,7 +597,7 @@ plus_option(char *option, isc_boolean_t is_batchfile, lookup->section_additional = state; break; case 'f': /* adflag */ - lookup->adflag = ISC_FALSE; + lookup->adflag = state; break; default: goto invalid_option; @@ -670,6 +671,9 @@ plus_option(char *option, isc_boolean_t is_batchfile, goto invalid_option; } break; + case 'f': /* fail */ + lookup->next_on_fail = state; + break; case 'i': switch (tolower(cmd[1])) { case 'd': /* identify */ @@ -799,9 +803,6 @@ plus_option(char *option, isc_boolean_t is_batchfile, show_details = ISC_TRUE; } break; - case 'e': /* recurse */ - lookup->recurse = ISC_TRUE; - break; case 'i': /* tries */ if (value == NULL) goto need_value; @@ -814,9 +815,11 @@ plus_option(char *option, isc_boolean_t is_batchfile, default: goto invalid_option; } + break; default: goto invalid_option; } + break; case 'v': /* vc */ if (!is_batchfile) lookup->tcp_mode = state; @@ -867,7 +870,7 @@ dash_option(char *option, char *next, dig_lookup_t **lookup) exit(0); break; case 'm': - isc_mem_debugging = ISC_MEM_DEBUGTRACE; + isc_mem_debugging = ISC_MEM_DEBUGTRACE | ISC_MEM_DEBUGRECORD; return (ISC_FALSE); break; case 'n': @@ -1270,6 +1273,8 @@ main(int argc, char **argv) { (dig_server_t *)s2, link); isc_mem_free(mctx, s2); } + if (isc_mem_debugging != 0) + isc_mem_stats(mctx, stderr); isc_mem_free(mctx, default_lookup); if (batchname != NULL) { if (batchfp != stdin) diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index dc7408972c..153987a9ac 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dighost.c,v 1.133 2000/09/22 23:21:32 mws Exp $ */ +/* $Id: dighost.c,v 1.134 2000/09/25 23:09:57 mws Exp $ */ /* * Notice to programmers: Do not use this code as an example of how to @@ -296,6 +296,7 @@ make_empty_lookup(void) { looknew->trace_root = ISC_FALSE; looknew->identify = ISC_FALSE; looknew->ignore = ISC_FALSE; + looknew->next_on_fail = ISC_FALSE; looknew->udpsize = 0; looknew->recurse = ISC_TRUE; looknew->aaonly = ISC_FALSE; @@ -347,6 +348,7 @@ clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers) { looknew->trace_root = lookold->trace_root; looknew->identify = lookold->identify; looknew->ignore = lookold->ignore; + looknew->next_on_fail = lookold->next_on_fail; looknew->udpsize = lookold->udpsize; looknew->recurse = lookold->recurse; looknew->aaonly = lookold->aaonly; @@ -2175,6 +2177,36 @@ recv_done(isc_task_t *task, isc_event_t *event) { UNLOCK_LOOKUP; return; } + if ((msg->rcode == dns_rcode_servfail) && + l->next_on_fail) { + dig_query_t *next = ISC_LIST_NEXT(query, link); + if (l->current_query == query) + l->current_query = NULL; + if (next != NULL) { + debug("sending query %lx\n", next); + if (l->tcp_mode) + send_tcp_connect(next); + else + send_udp(next); + } + /* + * If our query is at the head of the list and there + * is no next, we're the only one left, so fall + * through to print the message. + */ + if ((ISC_LIST_HEAD(l->q) != query) || + (ISC_LIST_NEXT(query, link) != NULL)) { + printf(";; Got SERVFAIL reply from %s, " + "trying next server\n", + query->servname); + clear_query(query); + check_next_lookup(l); + dns_message_destroy(&msg); + isc_event_free(&event); + UNLOCK_LOOKUP; + return; + } + } if (key != NULL) { result = dns_tsig_verify(&query->recvbuf, msg, diff --git a/bin/dig/include/dig/dig.h b/bin/dig/include/dig/dig.h index a011ecb9d7..cb9ed082e9 100644 --- a/bin/dig/include/dig/dig.h +++ b/bin/dig/include/dig/dig.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dig.h,v 1.48 2000/09/21 23:47:41 marka Exp $ */ +/* $Id: dig.h,v 1.49 2000/09/25 23:09:59 mws Exp $ */ #ifndef DIG_H #define DIG_H @@ -94,6 +94,7 @@ struct dig_lookup { section_answer, section_authority, section_additional, + next_on_fail, new_search; char textname[MXNAME]; /* Name we're going to be looking up */ dns_rdatatype_t rdtype; diff --git a/doc/todo/mws/todo b/doc/todo/mws/todo index dcb191e9bf..5dc934c01e 100644 --- a/doc/todo/mws/todo +++ b/doc/todo/mws/todo @@ -8,6 +8,10 @@ Examine dig8's behavior when one of the servers it talks to servfail's back, and, if necessary, reproduce behavior in dig9. (RT351) Remove or fix port number display in places where it is not correctly -reported (nslookup, in particular). (RT352) +reported (nslookup, in particular). (RT352) [COMPLETED] + +Check text strings for host and nslookup output ov various types. + +Check functionality of +search option