From 58c103e09c83c77cb80d0bca20c8e32a3b26e1ac Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Wed, 18 Apr 2018 09:18:41 +1000 Subject: [PATCH] dig: add the ability to set RA and TC in queries --- CHANGES | 3 +++ bin/dig/dig.c | 24 ++++++++++++++++++++---- bin/dig/dig.docbook | 22 ++++++++++++++++++++++ bin/dig/dighost.c | 14 ++++++++++++++ bin/dig/include/dig/dig.h | 2 ++ bin/tests/system/digdelv/tests.sh | 19 +++++++++++++++++++ 6 files changed, 80 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 615a84f0b0..053657cf3a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +4929. [func] Add the ability to set RA and TC in queries made by + dig (+[no]raflag, +[no]tcflag). [GL #213] + 4928. [func] The "dnskey-sig-validity" option allows "sig-validity-interval" to be overriden for signatures covering DNSKEY RRsets. [GL #145] diff --git a/bin/dig/dig.c b/bin/dig/dig.c index 5c41a8e114..6a0ed33cdd 100644 --- a/bin/dig/dig.c +++ b/bin/dig/dig.c @@ -205,6 +205,7 @@ help(void) { " +padding=### (Set padding block size [0])\n" " +[no]qr (Print question before sending)\n" " +[no]question (Control display of question section)\n" +" +[no]raflag (Set RA flag in query (+[no]raflag))\n" " +[no]rdflag (Recursive mode (+[no]recurse))\n" " +[no]recurse (Recursive mode (+[no]rdflag))\n" " +retry=### (Set number of UDP retries) [2]\n" @@ -217,6 +218,7 @@ help(void) { " +[no]split=## (Split hex/base64 fields into chunks)\n" " +[no]stats (Control display of statistics)\n" " +subnet=addr (Set edns-client-subnet option)\n" +" +[no]tcflag (Set TC flag in query (+[no]tcflag))\n" " +[no]tcp (TCP mode (+[no]vc))\n" " +timeout=### (Set query timeout) [5]\n" " +[no]trace (Trace delegation down from root [+dnssec])\n" @@ -1240,6 +1242,10 @@ plus_option(char *option, isc_boolean_t is_batchfile, break; case 'r': switch (cmd[1]) { + case 'a': /* raflag */ + FULLCHECK("raflag"); + lookup->raflag = state; + break; case 'd': /* rdflag */ FULLCHECK("rdflag"); lookup->recurse = state; @@ -1383,10 +1389,20 @@ plus_option(char *option, isc_boolean_t is_batchfile, case 't': switch (cmd[1]) { case 'c': /* tcp */ - FULLCHECK("tcp"); - if (!is_batchfile) { - lookup->tcp_mode = state; - lookup->tcp_mode_set = ISC_TRUE; + switch (cmd[2]) { + case 'f': + FULLCHECK("tcflag"); + lookup->tcflag = state; + break; + case 'p': + FULLCHECK("tcp"); + if (!is_batchfile) { + lookup->tcp_mode = state; + lookup->tcp_mode_set = ISC_TRUE; + } + break; + default: + goto invalid_option; } break; case 'i': /* timeout */ diff --git a/bin/dig/dig.docbook b/bin/dig/dig.docbook index 453f4221b3..03c9fb66a3 100644 --- a/bin/dig/dig.docbook +++ b/bin/dig/dig.docbook @@ -953,6 +953,17 @@ + + + + + Set [do not set] the RA (Recursion Available) bit in + the query. The default is +noraflag. This bit should + be ignored by the server for QUERY. + + + + @@ -1096,6 +1107,17 @@ + + + + + Set [do not set] the TC (TrunCation) bit in the query. + The default is +notcflag. This bit should be ignored + by the server for QUERY. + + + + diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 172b94bf13..37b27dde11 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -655,6 +655,8 @@ make_empty_lookup(void) { looknew->aaonly = ISC_FALSE; looknew->adflag = ISC_FALSE; looknew->cdflag = ISC_FALSE; + looknew->raflag = ISC_FALSE; + looknew->tcflag = ISC_FALSE; looknew->print_unknown_format = ISC_FALSE; looknew->zflag = ISC_FALSE; looknew->ns_search_only = ISC_FALSE; @@ -797,6 +799,8 @@ clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers) { looknew->aaonly = lookold->aaonly; looknew->adflag = lookold->adflag; looknew->cdflag = lookold->cdflag; + looknew->raflag = lookold->raflag; + looknew->tcflag = lookold->tcflag; looknew->print_unknown_format = lookold->print_unknown_format; looknew->zflag = lookold->zflag; looknew->ns_search_only = lookold->ns_search_only; @@ -2235,6 +2239,16 @@ setup_lookup(dig_lookup_t *lookup) { lookup->sendmsg->flags |= DNS_MESSAGEFLAG_CD; } + if (lookup->raflag) { + debug("RA query"); + lookup->sendmsg->flags |= DNS_MESSAGEFLAG_RA; + } + + if (lookup->tcflag) { + debug("TC query"); + lookup->sendmsg->flags |= DNS_MESSAGEFLAG_TC; + } + if (lookup->zflag) { debug("Z query"); lookup->sendmsg->flags |= 0x0040U; diff --git a/bin/dig/include/dig/dig.h b/bin/dig/include/dig/dig.h index 0b6fc460d0..ed97b07577 100644 --- a/bin/dig/include/dig/dig.h +++ b/bin/dig/include/dig/dig.h @@ -94,6 +94,8 @@ struct dig_lookup { aaonly, adflag, cdflag, + raflag, + tcflag, zflag, trace, /*% dig +trace */ trace_root, /*% initial query for either +trace or +nssearch */ diff --git a/bin/tests/system/digdelv/tests.sh b/bin/tests/system/digdelv/tests.sh index 0a7bc3166e..080d38e037 100644 --- a/bin/tests/system/digdelv/tests.sh +++ b/bin/tests/system/digdelv/tests.sh @@ -140,6 +140,7 @@ if [ -x ${DIG} ] ; then if [ $ret != 0 ]; then echo_i "failed"; fi status=`expr $status + $ret` + n=`expr $n + 1` echo_i "checking dig +header-only works ($n)" ret=0 $DIG $DIGOPTS +tcp @10.53.0.3 +header-only example > dig.out.test$n || ret=1 @@ -148,6 +149,24 @@ if [ -x ${DIG} ] ; then if [ $ret != 0 ]; then echo_i "failed"; fi status=`expr $status + $ret` + n=`expr $n + 1` + echo_i "checking dig +raflag works ($n)" + ret=0 + $DIG $DIGOPTS +tcp @10.53.0.3 +raflag +qr example > dig.out.test$n || ret=1 + grep "^;; flags: rd ra ad; QUERY: 1, ANSWER: 0," < dig.out.test$n > /dev/null || ret=1 + grep "^;; flags: qr rd ra; QUERY: 1, ANSWER: 0," < dig.out.test$n > /dev/null || ret=1 + if [ $ret != 0 ]; then echo_i "failed"; fi + status=`expr $status + $ret` + + n=`expr $n + 1` + echo_i "checking dig +tcflag works ($n)" + ret=0 + $DIG $DIGOPTS +tcp @10.53.0.3 +tcflag +qr example > dig.out.test$n || ret=1 + grep "^;; flags: tc rd ad; QUERY: 1, ANSWER: 0" < dig.out.test$n > /dev/null || ret=1 + grep "^;; flags: qr rd ra; QUERY: 1, ANSWER: 0," < dig.out.test$n > /dev/null || ret=1 + if [ $ret != 0 ]; then echo_i "failed"; fi + status=`expr $status + $ret` + n=`expr $n + 1` echo_i "checking dig +header-only works (with class and type set) ($n)" ret=0