]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
support printing AAAA in expanded form
authorMark Andrews <marka@isc.org>
Thu, 6 Dec 2018 06:36:46 +0000 (17:36 +1100)
committerEvan Hunt <each@isc.org>
Tue, 7 May 2019 04:50:38 +0000 (21:50 -0700)
bin/dig/dig.c
bin/dig/dig.docbook
bin/dig/dighost.c
bin/dig/include/dig/dig.h
bin/tests/system/digdelv/tests.sh
lib/dns/include/dns/rdata.h
lib/dns/rdata/in_1/aaaa_28.c

index cede60d7985ecd4744ddcf8515678626e3135850..afaf3e76d3450b80a72d728ac12f3054621c513e 100644 (file)
@@ -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;
index 94547a2ae42be5f28096d9acdc5b38efd208fa4d..e4014427168e61eda848844009c9c088bc258fa7 100644 (file)
          </listitem>
        </varlistentry>
 
+       <varlistentry>
+         <term><option>+[no]expandaaaa</option></term>
+         <listitem>
+           <para>
+             When printing AAAA record print all zero nibbles rather
+             than the default RFC 5952 preferred presentation format.
+           </para>
+         </listitem>
+       </varlistentry>
+
        <varlistentry>
          <term><option>+[no]fail</option></term>
          <listitem>
index 4f9162419d4c94b7867466f6447806c66a523383..3e7cef312083297af5bdbf0348f365bc7cf3ed01 100644 (file)
@@ -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;
index 23ad8d686dc5f4d5bef1c9b37cc329767e6cc005..41cc31a3a4faa684ba6485eea5a1f31f788b51c9 100644 (file)
@@ -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];
index aecc104a6fa0961725d76d72876ff152a7a7bbe9..22f074940b3a735234062c942c897a966c9dac4c 100644 (file)
@@ -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
index 81ecce2bfc65cef2238ecbc888e6664eb602dd63..0801cd0608815bb2b22ce2240346bb8c779112ab 100644 (file)
@@ -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
index 655c5edd2ea27de67236cb6b7c9ed5187258b2d3..75e5d2169af5fc3065d8f16b97ead810e9173ca0 100644 (file)
@@ -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, &region);
        return (inet_totext(AF_INET6, &region, target));
 }