<?xml version='1.0' encoding='UTF-8'?>

<!-- draft submitted in xml v3 -->

<!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">
]>

<rfc xmlns:xi="http://www.w3.org/2001/XInclude" ipr="trust200902" docName="draft-ietf-dnsop-qdcount-is-one-04" number="9619" category="std" consensus="true" submissionType="IETF" updates="1035" obsoletes="" tocInclude="true" sortRefs="true" symRefs="true" version="3" xml:lang="en">

  <front>
    <title abbrev="In the DNS, QDCOUNT Is (Usually) One">In the DNS, QDCOUNT Is (Usually) One</title>
    <seriesInfo name="RFC" value="9619"/>
    <author initials="R." surname="Bellis" fullname="Ray Bellis">
      <organization abbrev="ISC">Internet Systems Consortium, Inc.</organization>
      <address>
        <postal>
          <street>PO Box 360</street>
          <city>Newmarket</city>
	  <region>NH</region>
          <code>03857</code>
          <country>United States of America</country>
        </postal>
        <phone>+1 650 423 1300</phone>
        <email>ray@isc.org</email>
      </address>
    </author>
    <author initials="J." surname="Abley" fullname="Joe Abley">
      <organization>Cloudflare</organization>
      <address>
        <postal>
          <city>Amsterdam</city>
          <country>Netherlands</country>
        </postal>
        <phone>+31 6 45 56 36 34</phone>
        <email>jabley@cloudflare.com</email>
      </address>
    </author>
    <date year="2024" month="July"/>
    <area>OPS</area>
    <workgroup>dnsop</workgroup>
    <abstract>
<t>This document updates RFC 1035 by constraining the allowed value of the
QDCOUNT parameter in DNS messages with OPCODE = 0 (QUERY) to a maximum
of one, and it specifies the required behavior when values that are not
allowed are encountered.</t>
    </abstract>
  </front>
  <middle>


<section anchor="introduction">
      <name>Introduction</name>
      <t>The DNS protocol <xref target="RFC1034"/> <xref target="RFC1035"/> includes a parameter
QDCOUNT in the DNS message header whose value is specified to mean
the number of questions in the Question section of a DNS message.</t>
      <t>In a general sense, it seems perfectly plausible for the QDCOUNT
parameter, an unsigned 16-bit value, to take a considerable range
of values. However, in the specific case of messages that encode
DNS queries and responses (messages with OPCODE = 0), there are other
limitations inherent in the protocol that constrain values of QDCOUNT
to be either 0 or 1. In particular, several parameters specified
for DNS response messages such as AA and RCODE have no defined
meaning when the message contains multiple queries as there is
no way to signal which question those parameters relate to.</t>
      <t>In this document, we briefly survey the existing written DNS
specification; provide a description of the semantic and practical
requirements for DNS queries that naturally constrain the allowable
values of QDCOUNT; and update the DNS base specification to
clarify the allowable values of the QDCODE parameter in the specific
case of DNS messages with OPCODE = 0.</t>
    </section>
    <section anchor="terminology-used-in-this-document">
      <name>Terminology Used in This Document</name>
              <t>
    The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>",
    "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL NOT</bcp14>",
    "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>",
    "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>",
    "<bcp14>MAY</bcp14>", and "<bcp14>OPTIONAL</bcp14>" in this document are to be
    interpreted as described in BCP&nbsp;14 <xref target="RFC2119"/> <xref
    target="RFC8174"/> when, and only when, they appear in all capitals, as
    shown here.
              </t>

    </section>
    <section anchor="qdcount-is-usually-one">
      <name>QDCOUNT Is (Usually) One</name>     
      <t>A brief summary of the guidance provided in the existing DNS
specification (<xref target="RFC1035" format="default"/> and many other documents) for the use of QDCOUNT can be found in <xref target="Survey"/>.
While the specification is clear in many cases, there is some ambiguity in the specific case of OPCODE = 0, which this
document aims to eliminate.</t>
    </section>
    <section anchor="updates-to-rfc-1035">
      <name>Updates to RFC 1035</name>
      <t>A DNS message with OPCODE = 0 <bcp14>MUST NOT</bcp14> include a QDCOUNT
parameter whose value is greater than 1. It follows that the Question
section of a DNS message with OPCODE = 0 <bcp14>MUST NOT</bcp14> contain more than
one question.</t>
      <t>A DNS message with OPCODE = 0 and QDCOUNT &gt; 1 <bcp14>MUST</bcp14> be treated
as an incorrectly formatted message.  The value of the RCODE parameter
in the response message <bcp14>MUST</bcp14> be set to 1 (FORMERR).</t>
      <t>Middleboxes (e.g., firewalls) that process DNS messages in order to eliminate unwanted
traffic <bcp14>SHOULD</bcp14> treat messages with OPCODE = 0 and QDCOUNT &gt; 1 as
malformed traffic and return a FORMERR response as described above.
Such firewalls <bcp14>MUST NOT</bcp14> treat messages with OPCODE = 0 and QDCOUNT = 0
as malformed.  See <xref target="RFC8906" sectionFormat="of" section="4"/> for further guidance.</t>
    </section>
    <section anchor="security-considerations">
      <name>Security Considerations</name>
      <t>This document clarifies the DNS specification <xref target="RFC1035"/> and aims to improve
interoperability between different DNS implementations. In general, the elimination of ambiguity seems well-aligned with security
hygiene.</t>
    </section>
    <section anchor="iana-considerations">
      <name>IANA Considerations</name>
      <t>This document has no IANA actions.</t>
    </section>
  </middle>
  <back>
    <references>
      <name>References</name>
      <references anchor="sec-normative-references">
        <name>Normative References</name>
    
	<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.1034.xml"/>
	<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.1035.xml"/>
	<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
	<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>
	<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.3425.xml"/>
      </references>
      <references anchor="sec-informative-references">
        <name>Informative References</name>
	
	<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.8906.xml"/>
	<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.7873.xml"/>
	<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.5936.xml"/>
	<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.1996.xml"/>
	<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.2136.xml"/>
	<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.8490.xml"/>
      </references>
    </references>

<section anchor="Survey">
      <name>Guidance for the Use of QDCOUNT in the DNS Specification</name>
      <t>The DNS specification <xref target="RFC1035"/> provides some guidance about the values of
QDCOUNT that are appropriate in various situations. A brief summary
of this guidance is collated below.</t>
      <section anchor="opcode-0-query-and-1-iquery">
        <name>OPCODE = 0 (QUERY) and 1 (IQUERY)</name>
        <t><xref target="RFC1035"/> significantly predates the use of the normative requirement
key words specified in BCP 14 <xref target="RFC2119" format="default"/> <xref target="RFC8174" format="default"/>, and parts of it are consequently somewhat open to interpretation.</t>
        <t>Section <xref target="RFC1035" sectionFormat="bare" section="4.1.2">"Question section format"</xref> of <xref target="RFC1035"/> states the following about QDCOUNT:</t>
        <ul empty="true">
          <li>
            <t>"The section contains QDCOUNT (usually 1) entries"</t>
          </li>
        </ul>
        <t>The only documented exceptions within <xref target="RFC1035"/> relate to the IQuery
OpCode, where the request has "an empty question section" (QDCOUNT = 0),
and the response has "zero, one, or multiple domain names for the
specified resource as QNAMEs in the question section". The IQuery OpCode
was obsoleted by <xref target="RFC3425"/>.</t>
<t>In the absence of clearly expressed normative requirements, we rely on other text in <xref target="RFC1035"/> that makes use of the definite article or that implies a singular question and, by implication, QDCOUNT = 1.</t>
        <t>For example, <xref target="RFC1035" sectionFormat="of" section="4.1"/> states the following:</t>
        <ul empty="true">
          <li>
            <t>"the question for the name server"</t>
          </li>
        </ul>
        <t>and</t>
        <ul empty="true">
          <li>
            <t>"The question section contains fields that describe a question to a
name server."</t>
          </li>
        </ul>
        <t>And per Section <xref target="RFC1035" sectionFormat="bare" section="4.1.1">"Header section format"</xref> of <xref target="RFC1035"/>:</t>
        <ul empty="true">
          <li>
            <t>"AA:  Authoritative Answer - this bit is valid in responses,
   and specifies that the responding name server is an
   authority for the domain name in question section."</t>
          </li>
        </ul>
        <t>DNS Cookies (<xref target="RFC7873" sectionFormat="of" section="5.4"/>) allow a client to receive a valid Server Cookie without sending a specific question by sending
a request (QR = 0) with OPCODE = 0 and QDCOUNT = 0, with the resulting
	response also containing no question.</t>

        <t>The DNS Zone Transfer Protocol (<xref target="RFC5936" sectionFormat="of" section="2.2"/>) allows an authoritative server to optionally send a response message
(QR = 1) to a standard Authoritative Transfer (AXFR) query (OPCODE = 0, QTYPE=252) with
QDCOUNT = 0 in the second or subsequent message of a multi-message
response.</t>
      </section>
      <section anchor="opcode-4-notify">
        <name>OPCODE = 4 (NOTIFY)</name>
        <t>DNS Notify <xref target="RFC1996"/> also lacks a clearly defined range of values
	for QDCOUNT.  Section <xref target="RFC1996" sectionFormat="bare" section="3.7"/> states that:</t>
	
        <ul empty="true">
          <li>
            <t>"A NOTIFY request has QDCOUNT&gt;0"</t>
          </li>
        </ul>
        <t>However, all other text in the RFC discusses the &lt;QNAME, QCLASS, QTYPE&gt;
tuple in the singular form.</t>
      </section>
      <section anchor="opcode-5-update">
        <name>OPCODE = 5 (UPDATE)</name>
        <t>DNS Update <xref target="RFC2136"/> renames the QDCOUNT field to ZOCOUNT, but
the value is constrained to be one by Section <xref target="RFC2136" sectionFormat="bare" section="2.3">"Zone Section"</xref>:</t>
        <ul empty="true">
          <li>
            <t>"All records to be updated must be in the same zone, and therefore the
Zone Section is allowed to contain exactly one record."</t>
          </li>
        </ul>
      </section>
      <section anchor="opcode-6-dns-stateful-operations-dso">
        <name>OPCODE = 6 (DNS Stateful Operations, DSO)</name>
	
        <t>DNS Stateful Operations (DSO) (OpCode 6) <xref target="RFC8490"/>
preserves compatibility with the standard DNS 12-octet header by requiring all four of the section count values to be set to zero.</t>
      </section>
      <section anchor="conclusion">
        <name>Conclusion</name>
        <t>There is no text in <xref target="RFC1035"/> that describes how other parameters
in the DNS message, such as AA and RCODE, should be interpreted in the
case where a message includes more than one question. An originator
of a query with QDCOUNT &gt; 1 can have no expectations of how it will
be processed, and the receiver of a response with QDCOUNT &gt; 1 has
	no guidance for how it should be interpreted.</t>
	
        <t>The allowable values of QDCOUNT seem to be clearly specified for
OPCODE = 4 (NOTIFY), OPCODE = 5 (UPDATE), and OPCODE = 6 (DNS Stateful
Operations, DSO). OPCODE = 1 (IQUERY) is obsolete and OPCODE = 2
(STATUS) is not specified. OPCODE = 3 is reserved.</t>
        <t>However, the allowable values of QDCOUNT for OPCODE = 0 (QUERY) are
specified in <xref target="RFC1035"/> without the clarity of normative language,
and this looseness of language results in some ambiguity.</t>
      </section>
    </section>
       <section anchor="acknowledgements" numbered="false">
      <name>Acknowledgements</name>
      <t>The clarifications in this document were prompted by questions posed
by <contact fullname="Ted Lemon"/>, which reminded the authors of earlier, similar questions
and motivated them to pick up their pens. <contact fullname="Ondrej Sury"/>, <contact fullname="Warren Kumari"/>, <contact fullname="Peter Thomassen"/>, <contact fullname="Mark Andrews"/>, <contact fullname="Lars-Johan Liman"/>, <contact fullname="Jim Reid"/>, and <contact fullname="Niall O'Reilly"/> provided useful feedback.</t>
    </section>
  </back>
</rfc>
