Commit c4ae16b2 authored by Michael Sawyer's avatar Michael Sawyer
Browse files

Change command line options for dig. In particular, +short option added,

so users can easily get (for example) SOA list from all authorative servers
with 'dig +short +nssearch isc.org soa' rather than stringing dozens of
options together.  (Rather these options remain or are removed in the
release version is still subject to discussion.)
parent 6d790901
......@@ -62,7 +62,7 @@ extern ISC_LIST(dig_lookup_t) lookup_list;
extern ISC_LIST(dig_server_t) server_list;
extern isc_boolean_t tcp_mode, have_ipv6, show_details,
usesearch;
usesearch, trace;
extern in_port_t port;
extern unsigned int timeout;
extern isc_mem_t *mctx;
......@@ -87,6 +87,7 @@ isc_boolean_t comments = ISC_TRUE, section_question = ISC_TRUE,
section_answer = ISC_TRUE, section_authority = ISC_TRUE,
section_additional = ISC_TRUE, recurse = ISC_TRUE;
static char *opcodetext[] = {
"QUERY",
"IQUERY",
......@@ -149,8 +150,6 @@ show_usage() {
" +[no]search (Set whether to use searchlist)\n"
" +[no]recursive (Recursive mode)\n"
" +[no]details (Show details of all requests)\n"
" +[no]nssearch (Search for info on all authorative\n"
" nameservers for the domain.)\n"
#ifdef TWIDDLE
" +twiddle (Intentionally form bad requests)\n"
#endif
......@@ -160,6 +159,13 @@ show_usage() {
" +[no]answer (Control display of answer)\n"
" +[no]authority (Control display of authority)\n"
" +[no]additional (Control display of additional)\n"
" +[no]short (Disable everything except short\n"
" form of answer)\n"
" Additional d-opts subject to removal before release:\n"
" +[no]nssearch (Search all authorative nameservers)\n"
" +[no]identify (ID responders in short answers)\n"
" Available but not yet completed:\n"
" +[no]trace (Trace delegation down from root)\n"
, stderr);
}
......@@ -231,6 +237,25 @@ trying(int frmsize, char *frm, dig_lookup_t *lookup) {
}
static void
say_message(dns_rdata_t *rdata, dig_query_t *query) {
isc_buffer_t *b=NULL;
isc_region_t r;
isc_result_t result;
result = isc_buffer_allocate(mctx, &b, BUFSIZE);
check_result (result, "isc_buffer_allocate");
result = dns_rdata_totext(rdata, NULL, b);
check_result(result, "dns_rdata_totext");
isc_buffer_usedregion(b, &r);
printf ( "%.*s", (int)r.length, (char *)r.base);
if (query->lookup->identify) {
printf (" on server %s", query->servname);
}
printf ("\n");
isc_buffer_free(&b);
}
static isc_result_t
printsection(dns_message_t *msg, dns_section_t sectionid, char *section_name,
isc_boolean_t headers, dig_query_t *query)
......@@ -238,12 +263,13 @@ printsection(dns_message_t *msg, dns_section_t sectionid, char *section_name,
dns_name_t *name, *print_name;
dns_rdataset_t *rdataset;
isc_buffer_t target;
isc_result_t result;
isc_result_t result, loopresult;
isc_region_t r;
dns_name_t empty_name;
char t[4096];
isc_boolean_t first;
isc_boolean_t no_rdata;
dns_rdata_t rdata;
if (sectionid == DNS_SECTION_QUESTION)
no_rdata = ISC_TRUE;
......@@ -272,19 +298,30 @@ printsection(dns_message_t *msg, dns_section_t sectionid, char *section_name,
for (rdataset = ISC_LIST_HEAD(name->list);
rdataset != NULL;
rdataset = ISC_LIST_NEXT(rdataset, link)) {
result = dns_rdataset_totext(rdataset,
print_name,
ISC_FALSE,
no_rdata,
&target);
if (result != ISC_R_SUCCESS)
return (result);
if (!short_form) {
result = dns_rdataset_totext(rdataset,
print_name,
ISC_FALSE,
no_rdata,
&target);
if (result != ISC_R_SUCCESS)
return (result);
#ifdef USEINITALWS
if (first) {
print_name = &empty_name;
first = ISC_FALSE;
}
if (first) {
print_name = &empty_name;
first = ISC_FALSE;
}
#endif
} else {
loopresult = dns_rdataset_first(rdataset);
while (loopresult == ISC_R_SUCCESS) {
dns_rdataset_current(rdataset, &rdata);
say_message(&rdata, query);
loopresult = dns_rdataset_next(
rdataset);
}
}
}
isc_buffer_usedregion(&target, &r);
if (no_rdata)
......@@ -484,7 +521,7 @@ reorder_args(int argc, char *argv[]) {
*/
void
parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
isc_boolean_t have_host = ISC_FALSE;
isc_boolean_t have_host = ISC_FALSE, identify = ISC_FALSE;
dig_server_t *srv = NULL;
dig_lookup_t *lookup = NULL;
char *batchname = NULL;
......@@ -550,12 +587,34 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
recurse = ISC_FALSE;
} else if (strncmp(argv[0], "+ns", 3) == 0) {
ns_search_only = ISC_TRUE;
recurse = ISC_FALSE;
identify = ISC_TRUE;
} else if (strncmp(argv[0], "+nons", 6) == 0) {
ns_search_only = ISC_FALSE;
} else if (strncmp(argv[0], "+tr", 3) == 0) {
trace = ISC_TRUE;
ns_search_only = ISC_TRUE;
recurse = ISC_FALSE;
} else if (strncmp(argv[0], "+notr", 6) == 0) {
trace = ISC_FALSE;
} else if (strncmp(argv[0], "+det", 4) == 0) {
show_details = ISC_TRUE;
short_form = ISC_FALSE;
} else if (strncmp(argv[0], "+nodet", 6) == 0) {
show_details = ISC_FALSE;
} else if (strncmp(argv[0], "+sho", 4) == 0) {
short_form = ISC_TRUE;
show_details = ISC_FALSE;
comments = ISC_FALSE;
section_additional = ISC_FALSE;
section_authority = ISC_FALSE;
section_question = ISC_FALSE;
} else if (strncmp(argv[0], "+nosho", 6) == 0) {
short_form = ISC_FALSE;
} else if (strncmp(argv[0], "+id", 3) == 0) {
identify = ISC_TRUE;
} else if (strncmp(argv[0], "+noid", 5) == 0) {
identify = ISC_FALSE;
} else if (strncmp(argv[0], "+com", 4) == 0) {
comments = ISC_TRUE;
} else if (strncmp(argv[0], "+nocom", 6) == 0) {
......@@ -650,10 +709,11 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
lookup->oname=NULL;
lookup->timer = NULL;
lookup->xfr_q = NULL;
lookup->origin = NULL;
lookup->use_my_server_list = ISC_FALSE;
lookup->ns_search_only = ns_search_only;
lookup->doing_xfr = ISC_FALSE;
lookup->identify = ISC_FALSE;
lookup->identify = identify;
lookup->recurse = recurse;
lookup->retries = tries;
lookup->comments = comments;
......@@ -671,14 +731,14 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
} else {
if (have_host) {
ENSURE(lookup != NULL);
if (isclass(argv[0])) {
strncpy(lookup->rctext, argv[0],
MXRD);
continue;
} else if (istype(argv[0])) {
if (istype(argv[0])) {
strncpy(lookup->rttext, argv[0], MXRD);
continue;
}
} else if (isclass(argv[0])) {
strncpy(lookup->rctext, argv[0],
MXRD);
continue;
}
}
lookup = isc_mem_allocate(mctx,
sizeof(struct dig_lookup));
......@@ -695,10 +755,11 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
lookup->oname=NULL;
lookup->timer = NULL;
lookup->xfr_q = NULL;
lookup->origin = NULL;
lookup->use_my_server_list = ISC_FALSE;
lookup->doing_xfr = ISC_FALSE;
lookup->ns_search_only = ns_search_only;
lookup->identify = ISC_FALSE;
lookup->identify = identify;
lookup->recurse = recurse;
lookup->retries = tries;
lookup->comments = comments;
......@@ -748,10 +809,11 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
lookup->oname=NULL;
lookup->timer = NULL;
lookup->xfr_q = NULL;
lookup->origin = NULL;
lookup->use_my_server_list = ISC_FALSE;
lookup->doing_xfr = ISC_FALSE;
lookup->ns_search_only = ns_search_only;
lookup->identify = ISC_FALSE;
lookup->identify = identify;
lookup->recurse = recurse;
lookup->retries = tries;
lookup->comments = comments;
......@@ -760,7 +822,6 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
lookup->section_authority = section_authority;
lookup->section_additional = section_additional;
ISC_LIST_INIT(lookup->q);
lookup->origin = NULL;
ISC_LIST_INIT(lookup->my_server_list);
strcpy(lookup->textname, ".");
strcpy(lookup->rttext, "NS");
......
......@@ -60,7 +60,8 @@ ISC_LIST(dig_server_t) server_list;
ISC_LIST(dig_searchlist_t) search_list;
isc_boolean_t tcp_mode = ISC_FALSE, have_ipv6 = ISC_FALSE,
free_now = ISC_FALSE, show_details = ISC_FALSE, usesearch=ISC_TRUE;
free_now = ISC_FALSE, show_details = ISC_FALSE, usesearch=ISC_TRUE,
trace = ISC_FALSE;
#ifdef TWIDDLE
isc_boolean_t twiddle = ISC_FALSE;
#endif
......@@ -479,6 +480,7 @@ followup_lookup(dns_message_t *msg, dig_query_t *query) {
lookup->oname=NULL;
lookup->timer = NULL;
lookup->xfr_q = NULL;
lookup->origin = NULL;
lookup->doing_xfr = ISC_FALSE;
lookup->identify = ISC_TRUE;
lookup->recurse = query->lookup->
......@@ -520,9 +522,9 @@ followup_lookup(dns_message_t *msg, dig_query_t *query) {
srv, link);
isc_buffer_free (&b);
}
debug ("Before insertion, init@%ld "
"-> %ld, new@%ld "
"-> %ld", (long int)query->lookup,
debug ("Before insertion, init@%lx "
"-> %lx, new@%lx "
"-> %lx", (long int)query->lookup,
(long int)query->lookup->link.next,
(long int)lookup, (long int)lookup->
link.next);
......@@ -530,8 +532,8 @@ followup_lookup(dns_message_t *msg, dig_query_t *query) {
lookup, lookup,
link);
debug ("After insertion, init -> "
"%ld, new = %ld, "
"new -> %ld", (long int)query->
"%lx, new = %lx, "
"new -> %lx", (long int)query->
lookup->link.next,
(long int)lookup, (long int)lookup->
link.next);
......@@ -639,7 +641,7 @@ setup_lookup(dig_lookup_t *lookup) {
char store[MXNAME];
debug("setup_lookup()");
debug("Setting up for looking up %s @%ld->%ld",
debug("Setting up for looking up %s @%lx->%lx",
lookup->textname, (long int)lookup,
(long int)lookup->link.next);
......@@ -657,6 +659,7 @@ setup_lookup(dig_lookup_t *lookup) {
if (count_dots(lookup->textname) >= ndots)
lookup->origin = NULL; /* Force root lookup */
debug ("lookup->origin = %lx", (long int)lookup->origin);
if (lookup->origin != NULL) {
debug ("Trying origin %s", lookup->origin->origin);
result = dns_message_gettempname(lookup->sendmsg,
......@@ -905,9 +908,10 @@ connect_timeout(isc_task_t *task, isc_event_t *event) {
if (q->lookup->retries > 1)
printf(";; Connection to server %.*s "
"for %s timed out. "
"Retrying.\n",
"Retrying %d.\n",
(int)r.length, r.base,
q->lookup->textname);
q->lookup->textname,
q->lookup->retries-1);
else
printf(";; Connection to server %.*s "
"for %s timed out. "
......@@ -1149,9 +1153,16 @@ recv_done(isc_task_t *task, isc_event_t *event) {
if (query->lookup->xfr_q == NULL)
query->lookup->xfr_q = query;
if (query->lookup->xfr_q == query) {
if (query->lookup->ns_search_only)
followup_lookup(msg, query);
else if ((msg->rcode != 0) &&
if (query->lookup->ns_search_only) {
if (show_details) {
printmessage(query, msg, ISC_TRUE);
}
if ((msg->rcode != 0) &&
(query->lookup->origin != NULL)) {
next_origin(msg, query);
} else
followup_lookup(msg, query);
} else if ((msg->rcode != 0) &&
(query->lookup->origin != NULL)) {
next_origin(msg, query);
if (show_details) {
......@@ -1405,7 +1416,6 @@ free_lists(void) {
o = ISC_LIST_NEXT(o, link);
isc_mem_free(mctx, ptr);
}
dns_name_invalidate(dns_rootname);
if (socketmgr != NULL)
isc_socketmgr_destroy(&socketmgr);
if (timermgr != NULL)
......
......@@ -61,7 +61,7 @@ extern ISC_LIST(dig_server_t) server_list;
extern ISC_LIST(dig_searchlist_t) search_list;
extern isc_boolean_t tcp_mode,
have_ipv6;
have_ipv6, show_details;
extern in_port_t port;
extern unsigned int timeout;
extern isc_mem_t *mctx;
......@@ -170,7 +170,7 @@ check_next_lookup (dig_lookup_t *lookup) {
dig_query_t *query;
isc_boolean_t still_working=ISC_FALSE;
debug("In check_next_lookup");
debug("check_next_lookup()");
for (query = ISC_LIST_HEAD(lookup->q);
query != NULL;
query = ISC_LIST_NEXT(query, link)) {
......@@ -244,10 +244,17 @@ show_usage() {
void
received(int bytes, int frmsize, char *frm, dig_query_t *query) {
UNUSED(query);
if (!short_form)
printf("Received %u bytes from %.*s\n",
bytes, frmsize, frm);
isc_time_t now;
isc_result_t result;
int diff;
if ((!short_form) || (show_details)) {
result = isc_time_now(&now);
check_result (result, "isc_time_now");
diff = isc_time_microdiff(&now, &query->time_sent);
printf("Received %u bytes from %.*s in %d ms\n",
bytes, frmsize, frm, diff/1000);
}
}
void
......@@ -416,12 +423,22 @@ printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
dns_rdataset_t *opt, *tsig = NULL;
dns_name_t *tsigname;
isc_result_t result = ISC_R_SUCCESS;
isc_buffer_t *b;
isc_region_t r;
UNUSED (headers);
if (msg->rcode != 0) {
printf ("Host not found: %d(%s)\n",
result = isc_buffer_allocate(mctx, &b, MXNAME);
check_result (result, "isc_buffer_allocate");
result = dns_name_totext(query->lookup->name, ISC_FALSE,
b);
check_result (result, "dns_name_totext");
isc_buffer_usedregion (b, &r);
printf ("Host %.*s not found: %d(%s)\n",
(int)r.length, (char *)r.base,
msg->rcode, rcodetext[msg->rcode]);
isc_buffer_free (&b);
return (ISC_R_SUCCESS);
}
if (!short_form) {
......@@ -585,6 +602,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
strcpy (queryclass, "in");
nsfind = ISC_TRUE;
showallsoa = ISC_TRUE;
show_details = ISC_TRUE;
break;
case 'N':
debug ("Setting NDOTS to %s",
......@@ -627,6 +645,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
lookup->oname=NULL;
lookup->timer = NULL;
lookup->xfr_q = NULL;
lookup->origin = NULL;
lookup->doing_xfr = ISC_FALSE;
lookup->identify = ISC_FALSE;
lookup->recurse = recursion;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment