]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
dig +bufsize=0 failed to disable EDNS as a side effect.
authorMark Andrews <marka@isc.org>
Wed, 29 Jul 2020 02:34:54 +0000 (12:34 +1000)
committerMark Andrews <marka@isc.org>
Wed, 2 Sep 2020 09:07:55 +0000 (09:07 +0000)
CHANGES
bin/dig/dig.c
bin/dig/dig.rst
bin/dig/dighost.c
bin/dig/include/dig/dig.h
bin/dig/nslookup.c
bin/tests/system/digdelv/tests.sh

diff --git a/CHANGES b/CHANGES
index c71813ddc11ca42368e485c0655354c5be928156..7651aead09756745d5411066aedbdc52b79fb61d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+5497.  [bug]           dig +bufsize=0 failed to disable EDNS as a side
+                       effect. [GL #2054]
+
 5496.  [bug]           The rate limiter needs to hold a reference to its task.
                        [GL #2081]
 
index e400edf8c46d86efa91b241fa5cfe331cce8e468..34a42c8b64d83a5e3fc2b1ab845e56423ebf605d 100644 (file)
@@ -179,7 +179,7 @@ help(void) {
              "responses)\n"
              "                 +[no]besteffort     (Try to parse even illegal "
              "messages)\n"
-             "                 +bufsize=###        (Set EDNS0 Max UDP packet "
+             "                 +bufsize[=###]      (Set EDNS0 Max UDP packet "
              "size)\n"
              "                 +[no]cdflag         (Set checking disabled "
              "flag in query)\n"
@@ -1037,12 +1037,13 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup) {
                        break;
                case 'u': /* bufsize */
                        FULLCHECK("bufsize");
-                       if (value == NULL) {
-                               goto need_value;
-                       }
                        if (!state) {
                                goto invalid_option;
                        }
+                       if (value == NULL) {
+                               lookup->udpsize = DEFAULT_EDNS_BUFSIZE;
+                               break;
+                       }
                        result = parse_uint(&num, value, COMMSIZE,
                                            "buffer size");
                        if (result != ISC_R_SUCCESS) {
@@ -1050,6 +1051,9 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup) {
                                goto exit_or_usage;
                        }
                        lookup->udpsize = num;
+                       if (lookup->udpsize == 0) {
+                               lookup->edns = -1;
+                       }
                        break;
                default:
                        goto invalid_option;
@@ -1089,7 +1093,7 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup) {
                        case 'o': /* cookie */
                                FULLCHECK("cookie");
                                if (state && lookup->edns == -1) {
-                                       lookup->edns = 0;
+                                       lookup->edns = DEFAULT_EDNS_VERSION;
                                }
                                lookup->sendcookie = state;
                                if (value != NULL) {
@@ -1128,7 +1132,7 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup) {
                        FULLCHECK("dnssec");
                dnssec:
                        if (state && lookup->edns == -1) {
-                               lookup->edns = 0;
+                               lookup->edns = DEFAULT_EDNS_VERSION;
                        }
                        lookup->dnssec = state;
                        break;
@@ -1180,7 +1184,8 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup) {
                                                        break;
                                                }
                                                if (value == NULL) {
-                                                       lookup->edns = 0;
+                                                       lookup->edns =
+                                                               DEFAULT_EDNS_VERSION;
                                                        break;
                                                }
                                                result = parse_uint(&num, value,
@@ -1395,7 +1400,7 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup) {
                        case 'i': /* nsid */
                                FULLCHECK("nsid");
                                if (state && lookup->edns == -1) {
-                                       lookup->edns = 0;
+                                       lookup->edns = DEFAULT_EDNS_VERSION;
                                }
                                lookup->nsid = state;
                                break;
@@ -1465,7 +1470,7 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup) {
        case 'p':
                FULLCHECK("padding");
                if (state && lookup->edns == -1) {
-                       lookup->edns = 0;
+                       lookup->edns = DEFAULT_EDNS_VERSION;
                }
                if (value == NULL) {
                        goto need_value;
@@ -1633,7 +1638,7 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup) {
                                break;
                        }
                        if (lookup->edns == -1) {
-                               lookup->edns = 0;
+                               lookup->edns = DEFAULT_EDNS_VERSION;
                        }
                        if (lookup->ecs_addr != NULL) {
                                isc_mem_free(mctx, lookup->ecs_addr);
@@ -2248,7 +2253,7 @@ parse_args(bool is_batchfile, bool config_only, int argc, char **argv) {
                debug("making new lookup");
                default_lookup = make_empty_lookup();
                default_lookup->adflag = true;
-               default_lookup->edns = 0;
+               default_lookup->edns = DEFAULT_EDNS_VERSION;
                default_lookup->sendcookie = true;
 
 #ifndef NOPOSIX
index f1d57430e497bccc3a79a47e1815fab3b50e4cb5..2707a7504190589ba583ba3cd5e30ceac5494466 100644 (file)
@@ -251,12 +251,12 @@ abbreviation is unambiguous; for example, ``+cd`` is equivalent to
    Attempt to display the contents of messages which are malformed. The
    default is to not display malformed answers.
 
-``+bufsize=B``
-   Set the UDP message buffer size advertised using EDNS0 to ``B``
-   bytes. The maximum and minimum sizes of this buffer are 65535 and 0
-   respectively. Values outside this range are rounded up or down
-   appropriately. Values other than zero will cause a EDNS query to be
-   sent.
+``+bufsize[=B]``
+   This option sets the UDP message buffer size advertised using EDNS0
+   to ``B`` bytes.  The maximum and minimum sizes of this buffer are
+   65535 and 0, respectively.  ``+bufsize=0`` disables EDNS (use
+   ``+bufsize=0 +edns`` to send a EDNS messages with a advertised size
+   of 0 bytes). ``+bufsize`` restores the default buffer size.
 
 ``+[no]cdflag``
    Set [do not set] the CD (checking disabled) bit in the query. This
index 9a7aa2d1ccfd9f20b236cdb5593e070e72ebd754..34a22242475776de84e6cbd0017241b1b7576e47 100644 (file)
@@ -667,7 +667,7 @@ make_empty_lookup(void) {
        looknew->idnin = false;
        looknew->idnout = false;
 #endif /* HAVE_LIBIDN2 */
-       looknew->udpsize = 0;
+       looknew->udpsize = -1;
        looknew->edns = -1;
        looknew->recurse = true;
        looknew->aaonly = false;
@@ -2366,11 +2366,11 @@ setup_lookup(dig_lookup_t *lookup) {
                 * and DNS_EDNSOPTIONS set by other arguments
                 * (+nsid, +cookie, etc).
                 */
-               if (lookup->udpsize == 0) {
-                       lookup->udpsize = 4096;
+               if (lookup->udpsize < 0) {
+                       lookup->udpsize = DEFAULT_EDNS_BUFSIZE;
                }
                if (lookup->edns < 0) {
-                       lookup->edns = 0;
+                       lookup->edns = DEFAULT_EDNS_VERSION;
                }
 
                if (lookup->nsid) {
index 6460dd13c087c1c542ca03c9122406b83421a95e..f02210b132dd7b5349985d22717f4e7be5f8a646 100644 (file)
 #define SERVER_TIMEOUT 1
 
 #define LOOKUP_LIMIT 64
+
+#define DEFAULT_EDNS_VERSION 0
+#define DEFAULT_EDNS_BUFSIZE 4096
+
 /*%
  * Lookup_limit is just a limiter, keeping too many lookups from being
  * created.  It's job is mainly to prevent the program from running away
@@ -137,7 +141,7 @@ struct dig_lookup {
        dig_query_t *     xfr_q;
        uint32_t          retries;
        int               nsfound;
-       uint16_t          udpsize;
+       int16_t           udpsize;
        int16_t           edns;
        int16_t           padding;
        uint32_t          ixfr_serial;
index beb8efd7dbbc7f4656e815f694ab623630730b15..54868d423f8772204978b3990e90d412e59960da 100644 (file)
@@ -791,7 +791,6 @@ addlookup(char *opt) {
        lookup->recurse = recurse;
        lookup->aaonly = aaonly;
        lookup->retries = tries;
-       lookup->udpsize = 0;
        lookup->comments = comments;
        if (lookup->rdtype == dns_rdatatype_any && !tcpmode_set) {
                lookup->tcp_mode = true;
index 77b9600a02c77cce4b93bbe667dbc3bbb3477f97..37503e0ac5948b31f7a69fd42577b2afbda5ced6 100644 (file)
@@ -944,6 +944,31 @@ if [ -x "$DIG" ] ; then
   if [ $ret -ne 0 ]; then echo_i "failed"; fi
   status=$((status+ret))
 
+  n=$((n+1))
+  echo_i "check that dig +bufsize=0 disables EDNS ($n)"
+  ret=0
+  dig_with_opts @10.53.0.3 a.example +bufsize=0 +qr > dig.out.test$n 2>&1 || ret=1
+  grep "EDNS:" 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 +bufsize=0 +edns sends EDNS with bufsize of 0 ($n)"
+  ret=0
+  dig_with_opts @10.53.0.3 a.example +bufsize=0 +edns +qr > dig.out.test$n 2>&1 || ret=1
+  grep -E 'EDNS:.* udp: 0\r{0,1}$' 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 +bufsize restores default bufsize ($n)"
+  ret=0
+  dig_with_opts @10.53.0.3 a.example +bufsize=0 +bufsize +qr > dig.out.test$n 2>&1 || ret=1
+  lines=`grep "EDNS:.* udp: 4096" dig.out.test$n | wc -l`
+  test $lines -eq 2 || 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