From d8798098e8fc83b418ae5df8406b5e5c3da1349a Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Thu, 6 Dec 2018 17:36:46 +1100 Subject: [PATCH] support printing AAAA in expanded form --- bin/dig/dig.c | 23 +++++++++++++++++++++-- bin/dig/dig.docbook | 10 ++++++++++ bin/dig/dighost.c | 2 ++ bin/dig/include/dig/dig.h | 1 + bin/tests/system/digdelv/tests.sh | 24 ++++++++++++++++++++++++ lib/dns/include/dns/rdata.h | 3 +++ lib/dns/rdata/in_1/aaaa_28.c | 21 +++++++++++++++++++-- 7 files changed, 80 insertions(+), 4 deletions(-) diff --git a/bin/dig/dig.c b/bin/dig/dig.c index cede60d798..afaf3e76d3 100644 --- a/bin/dig/dig.c +++ b/bin/dig/dig.c @@ -187,6 +187,7 @@ help(void) { " +[no]ednsnegotiation (Set EDNS version negotiation)\n" " +ednsopt=###[:value] (Send specified EDNS option)\n" " +noednsopt (Clear list of +ednsopt options)\n" +" +[no]expandaaaa (Expand AAAA records)\n" " +[no]expire (Request time to expire)\n" " +[no]fail (Don't try next server on SERVFAIL)\n" " +[no]header-only (Send query without a question section)\n" @@ -473,6 +474,8 @@ printmessage(dig_query_t *query, dns_message_t *msg, bool headers) { styleflags |= DNS_STYLEFLAG_NO_CLASS; if (query->lookup->nocrypto) styleflags |= DNS_STYLEFLAG_NOCRYPTO; + if (query->lookup->expandaaaa) + styleflags |= DNS_STYLEFLAG_EXPANDAAAA; if (query->lookup->multiline) { styleflags |= DNS_STYLEFLAG_OMIT_OWNER; styleflags |= DNS_STYLEFLAG_OMIT_CLASS; @@ -1034,8 +1037,24 @@ plus_option(char *option, bool is_batchfile, } break; case 'x': - FULLCHECK("expire"); - lookup->expire = state; + switch (cmd[2]) { + case 'p': + switch(cmd[3]) { + case 'a': + FULLCHECK("expandaaaa"); + lookup->expandaaaa = state; + break; + case 'i': + FULLCHECK("expire"); + lookup->expire = state; + break; + default: + goto invalid_option; + } + break; + default: + goto invalid_option; + } break; default: goto invalid_option; diff --git a/bin/dig/dig.docbook b/bin/dig/dig.docbook index 94547a2ae4..e401442716 100644 --- a/bin/dig/dig.docbook +++ b/bin/dig/dig.docbook @@ -747,6 +747,16 @@ + + + + + When printing AAAA record print all zero nibbles rather + than the default RFC 5952 preferred presentation format. + + + + diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 4f9162419d..3e7cef3120 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -621,6 +621,7 @@ make_empty_lookup(void) { looknew->nocrypto = false; looknew->ttlunits = false; looknew->ttlunits = false; + looknew->expandaaaa = false; looknew->qr = false; #ifdef HAVE_LIBIDN2 looknew->idnin = isatty(1)?(getenv("IDN_DISABLE") == NULL):false; @@ -769,6 +770,7 @@ clone_lookup(dig_lookup_t *lookold, bool servers) { looknew->use_usec = lookold->use_usec; looknew->nocrypto = lookold->nocrypto; looknew->ttlunits = lookold->ttlunits; + looknew->expandaaaa = lookold->expandaaaa; looknew->qr = lookold->qr; looknew->idnin = lookold->idnin; looknew->idnout = lookold->idnout; diff --git a/bin/dig/include/dig/dig.h b/bin/dig/include/dig/dig.h index 23ad8d686d..41cc31a3a4 100644 --- a/bin/dig/include/dig/dig.h +++ b/bin/dig/include/dig/dig.h @@ -140,6 +140,7 @@ struct dig_lookup { ttlunits, idnin, idnout, + expandaaaa, qr; char textname[MXNAME]; /*% Name we're going to be looking up */ char cmdline[MXNAME]; diff --git a/bin/tests/system/digdelv/tests.sh b/bin/tests/system/digdelv/tests.sh index aecc104a6f..22f074940b 100644 --- a/bin/tests/system/digdelv/tests.sh +++ b/bin/tests/system/digdelv/tests.sh @@ -636,6 +636,30 @@ if [ -x "$DIG" ] ; then [ `grep "communications error.*end of file" dig.out.test$n | wc -l` -eq 1 ] || ret=1 if [ $ret -ne 0 ]; then echo_i "failed"; fi status=$((status+ret)) + + n=$((n+1)) + echo_i "check that dig +expandaaaa works ($n)" + ret=0 + dig_with_opts @10.53.0.3 +expandaaaa AAAA ns2.example > dig.out.test$n 2>&1 || ret=1 + grep "ns2.example.*fd92:7065:0b8e:ffff:0000:0000:0000:0002" dig.out.test$n > /dev/null || ret=1 + if [ $ret -ne 0 ]; then echo_i "failed"; fi + status=$((status+ret)) + + n=$((n+1)) + echo_i "check that dig +noexpandaaaa works ($n)" + ret=0 + dig_with_opts @10.53.0.3 +noexpandaaaa AAAA ns2.example > dig.out.test$n 2>&1 || ret=1 + grep "ns2.example.*fd92:7065:b8e:ffff::2" dig.out.test$n > /dev/null || ret=1 + if [ $ret -ne 0 ]; then echo_i "failed"; fi + status=$((status+ret)) + + n=$((n+1)) + echo_i "check that dig default for +[no]expandaaa (+noexpandaaaa) works ($n)" + ret=0 + dig_with_opts @10.53.0.3 AAAA ns2.example > dig.out.test$n 2>&1 || ret=1 + grep "ns2.example.*fd92:7065:b8e:ffff::2" dig.out.test$n > /dev/null || ret=1 + if [ $ret -ne 0 ]; then echo_i "failed"; fi + status=$((status+ret)) else echo_i "$DIG is needed, so skipping these dig tests" fi diff --git a/lib/dns/include/dns/rdata.h b/lib/dns/include/dns/rdata.h index 81ecce2bfc..0801cd0608 100644 --- a/lib/dns/include/dns/rdata.h +++ b/lib/dns/include/dns/rdata.h @@ -172,6 +172,9 @@ struct dns_rdata { /*% Output textual RR type and RDATA in RFC 3597 unknown format */ #define DNS_STYLEFLAG_UNKNOWNFORMAT 0x00000010ULL +/*% Print AAAA record fully expanded */ +#define DNS_STYLEFLAG_EXPANDAAAA 0x00000020ULL + #define DNS_RDATA_DOWNCASE DNS_NAME_DOWNCASE #define DNS_RDATA_CHECKNAMES DNS_NAME_CHECKNAMES #define DNS_RDATA_CHECKNAMESFAIL DNS_NAME_CHECKNAMESFAIL diff --git a/lib/dns/rdata/in_1/aaaa_28.c b/lib/dns/rdata/in_1/aaaa_28.c index 655c5edd2e..75e5d2169a 100644 --- a/lib/dns/rdata/in_1/aaaa_28.c +++ b/lib/dns/rdata/in_1/aaaa_28.c @@ -50,12 +50,29 @@ static inline isc_result_t totext_in_aaaa(ARGS_TOTEXT) { isc_region_t region; - UNUSED(tctx); - REQUIRE(rdata->type == dns_rdatatype_aaaa); REQUIRE(rdata->rdclass == dns_rdataclass_in); REQUIRE(rdata->length == 16); + if ((tctx->flags & DNS_STYLEFLAG_EXPANDAAAA) != 0) { + char buf[5*8]; + const char *sep = ""; + int i, n; + unsigned int len = 0; + + for (i = 0; i < 16; i += 2) { + INSIST(len < sizeof(buf)); + n = snprintf(buf + len, sizeof(buf) - len, + "%s%02x%02x", sep, + rdata->data[i], rdata->data[i + 1]); + if (n < 0) { + return (ISC_R_FAILURE); + } + len += n; + sep = ":"; + } + return (str_totext(buf, target)); + } dns_rdata_toregion(rdata, ®ion); return (inet_totext(AF_INET6, ®ion, target)); }