2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-01 06:55:30 +00:00

4481. [func] dig: make +class, +crypto, +multiline, +rrcomments,

+onesoa, +qr, +ttlid, +ttlunits and -u per lookup
                        rather than global. [RT #42450]
This commit is contained in:
Mark Andrews
2016-10-10 11:55:59 +11:00
parent ef59039b04
commit 3b6aba8dcb
7 changed files with 114 additions and 27 deletions

View File

@@ -1,3 +1,7 @@
4481. [func] dig: make +class, +crypto, +multiline, +rrcomments,
+onesoa, +qr, +ttlid, +ttlunits and -u per lookup
rather than global. [RT #42450]
4480. [placeholder] 4480. [placeholder]
4479. [placeholder] 4479. [placeholder]

View File

@@ -59,14 +59,17 @@ static char hexcookie[81];
static isc_boolean_t short_form = ISC_FALSE, printcmd = ISC_TRUE, static isc_boolean_t short_form = ISC_FALSE, printcmd = ISC_TRUE,
ip6_int = ISC_FALSE, plusquest = ISC_FALSE, pluscomm = ISC_FALSE, ip6_int = ISC_FALSE, plusquest = ISC_FALSE, pluscomm = ISC_FALSE,
#ifdef DIG_SIGCHASE
multiline = ISC_FALSE, nottl = ISC_FALSE, noclass = ISC_FALSE, multiline = ISC_FALSE, nottl = ISC_FALSE, noclass = ISC_FALSE,
onesoa = ISC_FALSE, use_usec = ISC_FALSE,
nocrypto = ISC_FALSE, ttlunits = ISC_FALSE, nocrypto = ISC_FALSE, ttlunits = ISC_FALSE,
#endif
ipv4only = ISC_FALSE, ipv6only = ISC_FALSE; ipv4only = ISC_FALSE, ipv6only = ISC_FALSE;
static isc_uint32_t splitwidth = 0xffffffff; static isc_uint32_t splitwidth = 0xffffffff;
/*% rrcomments are neither explicitly enabled nor disabled by default */ /*% rrcomments are neither explicitly enabled nor disabled by default */
#ifdef DIG_SIGCHASE
static int rrcomments = 0; static int rrcomments = 0;
#endif
/*% opcode text */ /*% opcode text */
static const char * const opcodetext[] = { static const char * const opcodetext[] = {
@@ -249,7 +252,7 @@ received(int bytes, isc_sockaddr_t *from, dig_query_t *query) {
if (query->lookup->stats && !short_form) { if (query->lookup->stats && !short_form) {
diff = isc_time_microdiff(&query->time_recv, &query->time_sent); diff = isc_time_microdiff(&query->time_recv, &query->time_sent);
if (use_usec) if (query->lookup->use_usec)
printf(";; Query time: %ld usec\n", (long) diff); printf(";; Query time: %ld usec\n", (long) diff);
else else
printf(";; Query time: %ld msec\n", (long) diff / 1000); printf(";; Query time: %ld msec\n", (long) diff / 1000);
@@ -278,7 +281,7 @@ received(int bytes, isc_sockaddr_t *from, dig_query_t *query) {
puts(""); puts("");
} else if (query->lookup->identify && !short_form) { } else if (query->lookup->identify && !short_form) {
diff = isc_time_microdiff(&query->time_recv, &query->time_sent); diff = isc_time_microdiff(&query->time_recv, &query->time_sent);
if (use_usec) if (query->lookup->use_usec)
printf(";; Received %" ISC_PRINT_QUADFORMAT "u bytes " printf(";; Received %" ISC_PRINT_QUADFORMAT "u bytes "
"from %s(%s) in %ld us\n\n", "from %s(%s) in %ld us\n\n",
query->lookup->doing_xfr query->lookup->doing_xfr
@@ -324,9 +327,9 @@ say_message(dns_rdata_t *rdata, dig_query_t *query, isc_buffer_t *buf) {
} }
/* Turn on rrcomments if explicitly enabled */ /* Turn on rrcomments if explicitly enabled */
if (rrcomments > 0) if (query->lookup->rrcomments > 0)
styleflags |= DNS_STYLEFLAG_RRCOMMENT; styleflags |= DNS_STYLEFLAG_RRCOMMENT;
if (nocrypto) if (query->lookup->nocrypto)
styleflags |= DNS_STYLEFLAG_NOCRYPTO; styleflags |= DNS_STYLEFLAG_NOCRYPTO;
if (query->lookup->print_unknown_format) if (query->lookup->print_unknown_format)
styleflags |= DNS_STYLEFLAG_UNKNOWNFORMAT; styleflags |= DNS_STYLEFLAG_UNKNOWNFORMAT;
@@ -339,7 +342,7 @@ say_message(dns_rdata_t *rdata, dig_query_t *query, isc_buffer_t *buf) {
diff = isc_time_microdiff(&query->time_recv, &query->time_sent); diff = isc_time_microdiff(&query->time_recv, &query->time_sent);
ADD_STRING(buf, " from server "); ADD_STRING(buf, " from server ");
ADD_STRING(buf, query->servname); ADD_STRING(buf, query->servname);
if (use_usec) if (query->lookup->use_usec)
snprintf(store, 19, " in %ld us.", (long) diff); snprintf(store, 19, " in %ld us.", (long) diff);
else else
snprintf(store, 19, " in %ld ms.", (long) diff / 1000); snprintf(store, 19, " in %ld ms.", (long) diff / 1000);
@@ -477,17 +480,17 @@ printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
if (query->lookup->print_unknown_format) if (query->lookup->print_unknown_format)
styleflags |= DNS_STYLEFLAG_UNKNOWNFORMAT; styleflags |= DNS_STYLEFLAG_UNKNOWNFORMAT;
/* Turn on rrcomments if explicitly enabled */ /* Turn on rrcomments if explicitly enabled */
if (rrcomments > 0) if (query->lookup->rrcomments > 0)
styleflags |= DNS_STYLEFLAG_RRCOMMENT; styleflags |= DNS_STYLEFLAG_RRCOMMENT;
if (ttlunits) if (query->lookup->ttlunits)
styleflags |= DNS_STYLEFLAG_TTL_UNITS; styleflags |= DNS_STYLEFLAG_TTL_UNITS;
if (nottl) if (query->lookup->nottl)
styleflags |= DNS_STYLEFLAG_NO_TTL; styleflags |= DNS_STYLEFLAG_NO_TTL;
if (noclass) if (query->lookup->noclass)
styleflags |= DNS_STYLEFLAG_NO_CLASS; styleflags |= DNS_STYLEFLAG_NO_CLASS;
if (nocrypto) if (query->lookup->nocrypto)
styleflags |= DNS_STYLEFLAG_NOCRYPTO; styleflags |= DNS_STYLEFLAG_NOCRYPTO;
if (multiline) { if (query->lookup->multiline) {
styleflags |= DNS_STYLEFLAG_OMIT_OWNER; styleflags |= DNS_STYLEFLAG_OMIT_OWNER;
styleflags |= DNS_STYLEFLAG_OMIT_CLASS; styleflags |= DNS_STYLEFLAG_OMIT_CLASS;
styleflags |= DNS_STYLEFLAG_REL_DATA; styleflags |= DNS_STYLEFLAG_REL_DATA;
@@ -495,14 +498,15 @@ printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
styleflags |= DNS_STYLEFLAG_TTL; styleflags |= DNS_STYLEFLAG_TTL;
styleflags |= DNS_STYLEFLAG_MULTILINE; styleflags |= DNS_STYLEFLAG_MULTILINE;
/* Turn on rrcomments unless explicitly disabled */ /* Turn on rrcomments unless explicitly disabled */
if (rrcomments >= 0) if (query->lookup->rrcomments >= 0)
styleflags |= DNS_STYLEFLAG_RRCOMMENT; styleflags |= DNS_STYLEFLAG_RRCOMMENT;
} }
if (multiline || (nottl && noclass)) if (query->lookup->multiline ||
(query->lookup->nottl && query->lookup->noclass))
result = dns_master_stylecreate2(&style, styleflags, result = dns_master_stylecreate2(&style, styleflags,
24, 24, 24, 32, 80, 8, 24, 24, 24, 32, 80, 8,
splitwidth, mctx); splitwidth, mctx);
else if (nottl || noclass) else if (query->lookup->nottl || query->lookup->noclass)
result = dns_master_stylecreate2(&style, styleflags, result = dns_master_stylecreate2(&style, styleflags,
24, 24, 32, 40, 80, 8, 24, 24, 32, 40, 80, 8,
splitwidth, mctx); splitwidth, mctx);
@@ -526,7 +530,8 @@ printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
flags |= DNS_MESSAGETEXTFLAG_NOHEADERS; flags |= DNS_MESSAGETEXTFLAG_NOHEADERS;
flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS; flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
} }
if (onesoa && query->lookup->rdtype == dns_rdatatype_axfr) if (query->lookup->onesoa &&
query->lookup->rdtype == dns_rdatatype_axfr)
flags |= (query->msg_count == 0) ? DNS_MESSAGETEXTFLAG_ONESOA : flags |= (query->msg_count == 0) ? DNS_MESSAGETEXTFLAG_ONESOA :
DNS_MESSAGETEXTFLAG_OMITSOA; DNS_MESSAGETEXTFLAG_OMITSOA;
if (!query->lookup->comments) if (!query->lookup->comments)
@@ -872,7 +877,10 @@ plus_option(const char *option, isc_boolean_t is_batchfile,
case 'l': /* class */ case 'l': /* class */
/* keep +cl for backwards compatibility */ /* keep +cl for backwards compatibility */
FULLCHECK2("cl", "class"); FULLCHECK2("cl", "class");
lookup->noclass = ISC_TF(!state);
#ifdef DIG_SIGCHASE
noclass = ISC_TF(!state); noclass = ISC_TF(!state);
#endif
break; break;
case 'm': /* cmd */ case 'm': /* cmd */
FULLCHECK("cmd"); FULLCHECK("cmd");
@@ -906,7 +914,10 @@ plus_option(const char *option, isc_boolean_t is_batchfile,
break; break;
case 'r': case 'r':
FULLCHECK("crypto"); FULLCHECK("crypto");
lookup->nocrypto = ISC_TF(!state);
#ifdef DIG_SIGCHASE
nocrypto = ISC_TF(!state); nocrypto = ISC_TF(!state);
#endif
break; break;
default: default:
goto invalid_option; goto invalid_option;
@@ -1069,7 +1080,10 @@ plus_option(const char *option, isc_boolean_t is_batchfile,
break; break;
case 'u': case 'u':
FULLCHECK("multiline"); FULLCHECK("multiline");
lookup->multiline = state;
#ifdef DIG_SIGCHASE
multiline = state; multiline = state;
#endif
break; break;
default: default:
goto invalid_option; goto invalid_option;
@@ -1111,7 +1125,10 @@ plus_option(const char *option, isc_boolean_t is_batchfile,
lookup->rdtype = dns_rdatatype_ns; lookup->rdtype = dns_rdatatype_ns;
lookup->rdtypeset = ISC_TRUE; lookup->rdtypeset = ISC_TRUE;
short_form = ISC_TRUE; short_form = ISC_TRUE;
lookup->rrcomments = 0;
#ifdef DIG_SIGCHASE
rrcomments = 0; rrcomments = 0;
#endif
} }
break; break;
default: default:
@@ -1126,7 +1143,7 @@ plus_option(const char *option, isc_boolean_t is_batchfile,
switch (cmd[1]) { switch (cmd[1]) {
case 'n': case 'n':
FULLCHECK("onesoa"); FULLCHECK("onesoa");
onesoa = state; lookup->onesoa = state;
break; break;
case 'p': case 'p':
FULLCHECK("opcode"); FULLCHECK("opcode");
@@ -1159,7 +1176,7 @@ plus_option(const char *option, isc_boolean_t is_batchfile,
switch (cmd[1]) { switch (cmd[1]) {
case 'r': /* qr */ case 'r': /* qr */
FULLCHECK("qr"); FULLCHECK("qr");
qr = state; lookup->qr = state;
break; break;
case 'u': /* question */ case 'u': /* question */
FULLCHECK("question"); FULLCHECK("question");
@@ -1201,7 +1218,10 @@ plus_option(const char *option, isc_boolean_t is_batchfile,
break; break;
case 'r': /* rrcomments */ case 'r': /* rrcomments */
FULLCHECK("rrcomments"); FULLCHECK("rrcomments");
lookup->rrcomments = state ? 1 : -1;
#ifdef DIG_SIGCHASE
rrcomments = state ? 1 : -1; rrcomments = state ? 1 : -1;
#endif
break; break;
default: default:
goto invalid_option; goto invalid_option;
@@ -1230,7 +1250,10 @@ plus_option(const char *option, isc_boolean_t is_batchfile,
lookup->section_question = ISC_FALSE; lookup->section_question = ISC_FALSE;
lookup->comments = ISC_FALSE; lookup->comments = ISC_FALSE;
lookup->stats = ISC_FALSE; lookup->stats = ISC_FALSE;
lookup->rrcomments = -1;
#ifdef DIG_SIGCHASE
rrcomments = -1; rrcomments = -1;
#endif
} }
break; break;
case 'w': /* showsearch */ case 'w': /* showsearch */
@@ -1346,7 +1369,10 @@ plus_option(const char *option, isc_boolean_t is_batchfile,
lookup->recurse = ISC_FALSE; lookup->recurse = ISC_FALSE;
lookup->identify = ISC_TRUE; lookup->identify = ISC_TRUE;
lookup->comments = ISC_FALSE; lookup->comments = ISC_FALSE;
lookup->rrcomments = 0;
#ifdef DIG_SIGCHASE
rrcomments = 0; rrcomments = 0;
#endif
lookup->stats = ISC_FALSE; lookup->stats = ISC_FALSE;
lookup->section_additional = ISC_FALSE; lookup->section_additional = ISC_FALSE;
lookup->section_authority = ISC_TRUE; lookup->section_authority = ISC_TRUE;
@@ -1393,12 +1419,19 @@ plus_option(const char *option, isc_boolean_t is_batchfile,
case 0: case 0:
case 'i': /* ttlid */ case 'i': /* ttlid */
FULLCHECK2("ttl", "ttlid"); FULLCHECK2("ttl", "ttlid");
lookup->nottl = ISC_TF(!state);
#ifdef DIG_SIGCHASE
nottl = ISC_TF(!state); nottl = ISC_TF(!state);
#endif
break; break;
case 'u': /* ttlunits */ case 'u': /* ttlunits */
FULLCHECK("ttlunits"); FULLCHECK("ttlunits");
lookup->nottl = ISC_FALSE;
lookup->ttlunits = ISC_TF(state);
#ifdef DIG_SIGCHASE
nottl = ISC_FALSE; nottl = ISC_FALSE;
ttlunits = ISC_TF(state); ttlunits = ISC_TF(state);
#endif
break; break;
default: default:
goto invalid_option; goto invalid_option;
@@ -1513,7 +1546,7 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
/* deprecated */ /* deprecated */
break; break;
case 'u': case 'u':
use_usec = ISC_TRUE; (*lookup)->use_usec = ISC_TRUE;
break; break;
case 'v': case 'v':
version(); version();

View File

@@ -1205,8 +1205,9 @@
can also be supplied. These global query options must precede the can also be supplied. These global query options must precede the
first tuple of name, class, type, options, flags, and query options first tuple of name, class, type, options, flags, and query options
supplied on the command line. Any global query options (except supplied on the command line. Any global query options (except
the <option>+[no]cmd</option> option) can be <option>+[no]cmd</option> and <option>+[no]short</option> options)
overridden by a query-specific set of query options. For example: can be overridden by a query-specific set of query options.
For example:
<programlisting> <programlisting>
dig +qr www.isc.org any -x 127.0.0.1 isc.org ns +noqr dig +qr www.isc.org any -x 127.0.0.1 isc.org ns +noqr
</programlisting> </programlisting>

View File

@@ -121,7 +121,6 @@ isc_boolean_t
cancel_now = ISC_FALSE, cancel_now = ISC_FALSE,
usesearch = ISC_FALSE, usesearch = ISC_FALSE,
showsearch = ISC_FALSE, showsearch = ISC_FALSE,
qr = ISC_FALSE,
is_dst_up = ISC_FALSE, is_dst_up = ISC_FALSE,
keep_open = ISC_FALSE, keep_open = ISC_FALSE,
verbose = ISC_FALSE; verbose = ISC_FALSE;
@@ -781,6 +780,15 @@ make_empty_lookup(void) {
looknew->sendcookie = ISC_FALSE; looknew->sendcookie = ISC_FALSE;
looknew->seenbadcookie = ISC_FALSE; looknew->seenbadcookie = ISC_FALSE;
looknew->badcookie = ISC_TRUE; looknew->badcookie = ISC_TRUE;
looknew->multiline = ISC_FALSE;
looknew->nottl = ISC_FALSE;
looknew->noclass = ISC_FALSE;
looknew->onesoa = ISC_FALSE;
looknew->use_usec = ISC_FALSE;
looknew->nocrypto = ISC_FALSE;
looknew->ttlunits = ISC_FALSE;
looknew->ttlunits = ISC_FALSE;
looknew->qr = ISC_FALSE;
#ifdef DIG_SIGCHASE #ifdef DIG_SIGCHASE
looknew->sigchase = ISC_FALSE; looknew->sigchase = ISC_FALSE;
#if DIG_SIGCHASE_TD #if DIG_SIGCHASE_TD
@@ -826,6 +834,7 @@ make_empty_lookup(void) {
looknew->ednsneg = ISC_TRUE; looknew->ednsneg = ISC_TRUE;
looknew->mapped = ISC_TRUE; looknew->mapped = ISC_TRUE;
looknew->dscp = -1; looknew->dscp = -1;
looknew->rrcomments = 0;
dns_fixedname_init(&looknew->fdomain); dns_fixedname_init(&looknew->fdomain);
ISC_LINK_INIT(looknew, link); ISC_LINK_INIT(looknew, link);
ISC_LIST_INIT(looknew->q); ISC_LIST_INIT(looknew->q);
@@ -885,6 +894,14 @@ clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
looknew->ednsoptscnt = lookold->ednsoptscnt; looknew->ednsoptscnt = lookold->ednsoptscnt;
looknew->ednsneg = lookold->ednsneg; looknew->ednsneg = lookold->ednsneg;
looknew->mapped = lookold->mapped; looknew->mapped = lookold->mapped;
looknew->multiline = lookold->multiline;
looknew->nottl = lookold->nottl;
looknew->noclass = lookold->noclass;
looknew->onesoa = lookold->onesoa;
looknew->use_usec = lookold->use_usec;
looknew->nocrypto = lookold->nocrypto;
looknew->ttlunits = lookold->ttlunits;
looknew->qr = lookold->qr;
#ifdef DIG_SIGCHASE #ifdef DIG_SIGCHASE
looknew->sigchase = lookold->sigchase; looknew->sigchase = lookold->sigchase;
#if DIG_SIGCHASE_TD #if DIG_SIGCHASE_TD
@@ -919,6 +936,7 @@ clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
looknew->need_search = lookold->need_search; looknew->need_search = lookold->need_search;
looknew->done_as_is = lookold->done_as_is; looknew->done_as_is = lookold->done_as_is;
looknew->dscp = lookold->dscp; looknew->dscp = lookold->dscp;
looknew->rrcomments = lookold->rrcomments;
if (lookold->ecs_addr != NULL) { if (lookold->ecs_addr != NULL) {
size_t len = sizeof(isc_sockaddr_t); size_t len = sizeof(isc_sockaddr_t);
@@ -2702,7 +2720,7 @@ setup_lookup(dig_lookup_t *lookup) {
} }
/* XXX qrflag, print_query, etc... */ /* XXX qrflag, print_query, etc... */
if (!ISC_LIST_EMPTY(lookup->q) && qr) { if (!ISC_LIST_EMPTY(lookup->q) && lookup->qr) {
extrabytes = 0; extrabytes = 0;
printmessage(ISC_LIST_HEAD(lookup->q), lookup->sendmsg, printmessage(ISC_LIST_HEAD(lookup->q), lookup->sendmsg,
ISC_TRUE); ISC_TRUE);

View File

@@ -129,7 +129,15 @@ struct dig_lookup {
header_only, header_only,
ednsneg, ednsneg,
mapped, mapped,
print_unknown_format; print_unknown_format,
multiline,
nottl,
noclass,
onesoa,
use_usec,
nocrypto,
ttlunits,
qr;
#ifdef DIG_SIGCHASE #ifdef DIG_SIGCHASE
isc_boolean_t sigchase; isc_boolean_t sigchase;
#if DIG_SIGCHASE_TD #if DIG_SIGCHASE_TD
@@ -190,6 +198,7 @@ isc_boolean_t sigchase;
isc_dscp_t dscp; isc_dscp_t dscp;
unsigned int ednsflags; unsigned int ednsflags;
dns_opcode_t opcode; dns_opcode_t opcode;
int rrcomments;
}; };
/*% The dig_query structure */ /*% The dig_query structure */
@@ -260,7 +269,7 @@ extern dig_searchlistlist_t search_list;
extern unsigned int extrabytes; extern unsigned int extrabytes;
extern isc_boolean_t check_ra, have_ipv4, have_ipv6, specified_source, extern isc_boolean_t check_ra, have_ipv4, have_ipv6, specified_source,
usesearch, showsearch, qr; usesearch, showsearch;
extern in_port_t port; extern in_port_t port;
extern unsigned int timeout; extern unsigned int timeout;
extern isc_mem_t *mctx; extern isc_mem_t *mctx;

View File

@@ -6,8 +6,12 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
rm -f dig.out.*test*
rm -f delv.out.test*
rm -f */named.memstats rm -f */named.memstats
rm -f */named.run rm -f */named.run
rm -f delv.out.test*
rm -f dig.out.*test*
rm -f dig.out.mm.*
rm -f dig.out.mn.*
rm -f dig.out.nm.*
rm -f dig.out.nn.*
rm -f ns*/named.lock rm -f ns*/named.lock

View File

@@ -102,6 +102,24 @@ if [ -x ${DIG} ] ; then
if [ $ret != 0 ]; then echo "I:failed"; fi if [ $ret != 0 ]; then echo "I:failed"; fi
status=`expr $status + $ret` status=`expr $status + $ret`
n=`expr $n + 1`
echo "I:checking dig multi flag is local($n)"
ret=0
$DIG $DIGOPTS +tcp @10.53.0.3 -t DNSKEY dnskey.example +nomulti dnskey.example +nomulti > dig.out.nn.$n || ret=1
$DIG $DIGOPTS +tcp @10.53.0.3 -t DNSKEY dnskey.example +multi dnskey.example +nomulti > dig.out.mn.$n || ret=1
$DIG $DIGOPTS +tcp @10.53.0.3 -t DNSKEY dnskey.example +nomulti dnskey.example +multi > dig.out.nm.$n || ret=1
$DIG $DIGOPTS +tcp @10.53.0.3 -t DNSKEY dnskey.example +multi dnskey.example +multi > dig.out.mm.$n || ret=1
lcnn=`wc -l < dig.out.nn.$n`
lcmn=`wc -l < dig.out.mn.$n`
lcnm=`wc -l < dig.out.nm.$n`
lcmm=`wc -l < dig.out.mm.$n`
test $lcmm -ge $lcnm || ret=1
test $lcmm -ge $lcmn || ret=1
test $lcnm -ge $lcnn || ret=1
test $lcmn -ge $lcnn || ret=1
if [ $ret != 0 ]; then echo "I:failed"; fi
status=`expr $status + $ret`
n=`expr $n + 1` n=`expr $n + 1`
echo "I:checking dig +noheader-only works ($n)" echo "I:checking dig +noheader-only works ($n)"
ret=0 ret=0