<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
  <!ENTITY  rfc793 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.0793.xml'>
  <!ENTITY rfc1035 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.1035.xml'>
  <!ENTITY rfc1123 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.1123.xml'>
  <!ENTITY rfc2119 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml'>
  <!ENTITY rfc2131 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2131.xml'>
  <!ENTITY rfc2132 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2132.xml'>
  <!ENTITY rfc2671 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2671.xml'>
  <!ENTITY rfc2845 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2845.xml'>
  <!ENTITY rfc2930 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2930.xml'>
  <!ENTITY rfc3597 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3597.xml'>
  <!ENTITY rfc4035 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4035.xml'>
  <!ENTITY rfc5358 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5358.xml'>
  <!ENTITY forgery PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml3/reference.I-D.ietf-dnsext-forgery-resilience.xml'>
  ]>

<rfc category="bcp" ipr="full3978"
    docName="draft-bellis-dnsext-dnsproxy-00">
    <?rfc toc='yes' ?>
    <?rfc tocompact='no' ?>
    <?rfc compact='yes' ?>
    <?rfc subcompact='yes' ?>
    <?rfc sortrefs='yes' ?>
    <?rfc symrefs='yes' ?>
    <front>
        <title>DNS Proxy Implementation Guidelines</title>
        <author initials="R.P." surname="Bellis" fullname="Ray Bellis">
            <organization>Nominet UK</organization>
            <address>
            <postal>
                <street>Edmund Halley Road</street>
                <city>Oxford</city>
                <code>OX4 4DQ</code>
                <country>United Kingdom</country>
            </postal>
            <phone>+44 1865 332211</phone>
            <email>ray.bellis@nominet.org.uk</email>
            <uri>http://www.nominet.org.uk/</uri>
        </address>
        </author>

        <date year="2008"/>
        <area>Internet Area</area>
        <workgroup>DNSEXT</workgroup>
        <keyword>DNS</keyword>
        <keyword>Proxy</keyword>

        <abstract>
            <t> This document provides guidelines for the implementation of DNS proxies, as found in
                broadband routers and other similar network devices.</t>
        </abstract>
    </front>

    <middle>
        <section title="Introduction">

            <t> Recent research (<xref target="SAC035"/>, <xref target="DOTSE"/>) has shown that
                many commonly-used broadband routers (and similar devices) contain DNS proxies which
                are incompatible in various ways with current DNS standards. </t>

            <t> These proxies are usual simple DNS forwarders, but do not usually have any caching
                capabilities. The proxy serves as a convenient default DNS resolver for clients on
                the LAN, but relies on an upstream resolver (e.g. at an ISP) to perform recursive
                DNS lookups.</t>

            <t> This documents describes the incompatibilities that have been discovered and offers
                guidelines to implementors on how to provide maximum interoperability.</t>

        </section>
        <section title="Terminology">

            <t> The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
                "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
                interpreted as described in <xref target="RFC2119"/>.</t>

        </section>

        <section title="The Transparency Principle">

            <t> It is not considered practical for a simple DNS proxy to directly implement all
                current and future DNS features.</t>

            <t> There are several reasons why this is the case:</t>
            <t>
                <list style="symbols">
                    <t> broadband routers usually have limited hardware resources </t>
                    <t> firmware upgrade cycles are long, and many users do not routinely apply
                        upgrades when they become available</t>
                    <t> no-one knows what those future DNS features will be, nor how they might be
                        implemented</t>
                    <t> it would substantially complicate the configuration UI of the device</t>
                </list>
            </t>

            <t> Furthermore some modern DNS protocol extensions (see e.g. EDNS0, below) are intended
                to be used as "hop-by-hop" mechanisms. If the DNS proxy is considered to be such a
                "hop" in the resolution chain then for it to function correctly it would need to be
                fully compliant with all such mechanisms.</t>

            <t> Research has shown that the more actively a proxy participates in the DNS protocol
                then the more likely it is that it will somehow interfere with the flow of messages
                between the DNS client and the upstream recursive resolvers.</t>

            <t> The task of the proxy SHOULD therefore be no more and no less than to receive DNS
                requests from clients on the LAN side, forward those verbatim to one of the known
                upstream recursive resolvers on the WAN side, and ensure that the whole response is
                returned verbatim to the original client.</t>

            <t> It is RECOMMENDED that proxies should be as transparent as possible, such that any
                "hop-by-hop" mechanisms or newly introduced protocol extensions operate as if the
                proxy were not there.</t>

        </section>

        <section title="Protocol Conformance">

            <section title="Unexpected Flags and Data" anchor="flags">

                <t> The Transparency Principle above, when combined with <xref target="RFC0793"
                        >Postel's Robustness Principle</xref>, suggests that DNS proxies should not
                    arbitrarily reject or otherwise drop requests or responses based on perceived
                    non-compliance with standards.</t>

                <t> For example, some proxies have been observed to drop any packet containing
                    either the "Authentic Data" (AD) or "Checking Disabled" (CD) bits from <xref
                        target="RFC4035">DNSSEC</xref>. This may be because <xref target="RFC1035"/>
                    originally specified that these unused "Z" flag bits "MUST" be zero. However
                    these flag bits were always intended to be reserved for future use, so refusing
                    to proxy any packet containing these flags (now that uses for those flags have
                    indeed been defined) is not appropriate.</t>

                <t> Therefore it is RECOMMENDED that proxies SHOULD ignore any unknown DNS flags and
                    proxy those packets as usual.</t>

            </section>

            <section anchor="unknown" title="Unknown Resource Record Types">

                <t>
                    <xref target="RFC3597"/> requires that resolvers MUST handle Resource Records
                    (RRs) of unknown type transparently.</t>

                <t> All requests and responses MUST be proxied regardless of the values of the QTYPE
                    and QCLASS fields.</t>

                <t> Similarly all responses MUST be proxied regardless of the values of the TYPE and
                    CLASS fields of any Resource Record therein.</t>

            </section>

            <section title="Packet Size Limits">
                <t>
                    <xref target="RFC1035"/> specifies that the maximum size of the DNS payload in a
                    UDP packet is 512 octets. Where the required portions of a response would not
                    fit inside that limit the DNS server MUST set the "TrunCation" (TC) bit in the
                    DNS response header to indicate that truncation has occurred. There are however
                    two standard mechanisms (described below) for transporting responses larger than
                    512 octets.</t>

                <t> Many proxies have been observed to truncate all responses at 512 octets, and
                    others at a packet size related to the WAN MTU, in either case doing so without
                    setting the TC bit.</t>

                <t> Other proxies have been observed to remove the TC bit in server responses which
                    correctly had the TC bit set by the server.</t>

                <t> If a DNS response is truncated but the TC bit is not set then client failures
                    may result, in particular a naïve DNS client library might suffer crashes due to
                    reading beyond the end of the data actually received.</t>

                <t> Therefore if a proxy must unilaterally truncate a response then the proxy MUST
                    set the TC bit. Similarly, proxies MUST NOT remove the TC bit from responses.</t>

                <section title="TCP Transport">

                    <t> Should a UDP query fail because of truncation the standard fail-over
                        mechanism is to retry the query using TCP, as described in section 6.1.3.2
                        of <xref target="RFC1123"/> .</t>

                    <t> DNS proxies SHOULD therefore be prepared to receive and forward queries over
                        TCP.</t>

                    <t> Note that it is unlikely that a client would send a request over TCP unless
                        it had already received a truncated UDP response. Some "smart" proxies have
                        been observed to first forward a request received over TCP to an upstream
                        resolver over UDP, only for the response to be truncated, causing the proxy
                        to retry over TCP. Such behaviour increases network traffic and causes delay
                        in DNS resolution since the initial UDP request is doomed to fail.</t>

                    <t> Therefore whenever a proxy receives a request over TCP, the proxy SHOULD
                        forward the query over TCP and SHOULD NOT attempt the same query over UDP
                        first.</t>

                </section>

                <section title="Extension Mechanisms for DNS (EDNS0)">

                    <t> The <xref target="RFC2671">Extension Mechanism for DNS</xref> was introduced
                        to allow the transport of larger DNS packets over UDP and also to allow for
                        additional request and response flags.</t>

                    <t> A client may send an OPT Resource Record (OPT RR) in the Additional Section
                        of a request to indicate that it supports a specific receive buffer size.
                        The OPT RR also includes the "DNSSEC OK" (DO) flag used by DNSSEC to
                        indicate that DNSSEC-related RRs should be returned to the client.</t>

                    <t> However some proxies have been observed to either reject (with a FORMERR
                        response code) or black-hole any packet containing an OPT RR. As per <xref
                            target="flags"/> proxies SHOULD NOT refuse to proxy such packets. </t>

                </section>

                <section title="IP Fragmentation">
                    <t> Support for UDP packet sizes exceeding the WAN MTU depends on the router's
                        algorithm for handling fragmented IP packets. Several options are possible:</t>

                    <t>
                        <list style="numbers">
                            <t> fragments are dropped</t>
                            <t> fragments are forwarded individually as they're received </t>
                            <t> complete packets are reassembled on the router, and then
                                re-fragmented (if necessary) as they're forwarded to the client </t>
                        </list>
                    </t>

                    <t> Option 1 above will cause compatibility problems with EDNS0 unless the DNS
                        client is configured to advertise an EDNS0 buffer size limited to 28 octets
                        less than the MTU. Note that RFC 2671 does recommend that the path MTU
                        should be taken into account when using EDNS0.</t>

                    <t> Also, whilst the EDNS0 specification allows for a buffer size of up to 65536
                        octets, most common DNS server implementations do not support a buffer size
                        above 4096 octets.</t>

                    <t> Therefore it is RECOMMENDED (whichever of options 2 or 3 above is in use)
                        that routers SHOULD be capable of forwarding UDP packets up to a payload
                        size of at least 4096 octets.</t>

                </section>

            </section>

            <section title="Secret Key Transaction Authentication for DNS (TSIG)">
                <t>
                    <xref target="RFC2845"/> defines TSIG, which is a hop-by-hop mechanism for
                    authenticating DNS requests and responses at the packet level. </t>

                <t> Whilst it's not impossible for a simple DNS proxy to implement TSIG directly it
                    is not advised since parsing and validating received packets is a
                    computationally intensive task, best left to full-featured DNS clients.</t>

                <t> DNS proxies SHOULD be transparent to TSIG signed packets.</t>

                <t> Similarly, as per <xref target="unknown"/>, DNS proxies SHOULD be capable to
                    proxying packets containing <xref target="RFC2930">TKEY</xref> Resource Records</t>

            </section>

        </section>

        <section title="DHCP's Interaction with DNS">

            <t> Whilst this document is primarily about DNS proxies, most consumers rely on <xref
                    target="RFC2131">DHCP</xref> to obtain network configuration settings. Such
                settings include the client machine's IP address, subnet mask and default gateway,
                but also include DNS related settings.</t>

            <t> It is therefore appropriate to examine how DHCP affects client DNS configuration.</t>

            <section title="Domain Name Server (DHCP Option 6)">

                <t> Most routers default to supplying their own IP address in the DHCP "Domain Name
                    Server" <xref target="RFC2132">option</xref>. The net result is that without
                    explicit re-configuration many DNS clients will by default send queries to the
                    router's DNS proxy. This is understandable behaviour given that the correct
                    upstream settings are not usually known at boot time. </t>

                <t> Most routers learn their own DNS settings via values supplied by an ISP via DHCP
                    or PPP over the WAN interface. However whilst many routers do allow the end-user
                    to override those values, some routers only use those end-user supplied values
                    to affect the proxy's own forwarding function, and do not offer these values via
                    DHCP.</t>

                <t> When using such a device the only way to avoid using the DNS proxy is to
                    hard-code the required values in the client operating system. This may be
                    acceptable for a desktop system but it is inappropriate for mobile devices which
                    are regularly used on many different networks.</t>

                <t> It is therefore RECOMMENDED that routers SHOULD support end-user configuration
                    of values for the "Domain Name Server" DHCP option.</t>

            </section>

            <section title="Domain Name (DHCP Option 15)">

                <t> A significant amount of traffic to the DNS Root Name Servers is for invalid
                    top-level domain names, and some of that traffic can be attributed to particular
                    equipment vendors whose firmware defaults this DHCP option to specific values. </t>

                <t> Since no standard exists for a "local" scoped domain name suffix it is
                    RECOMMENDED that the default value for this option SHOULD be empty, and that
                    this option SHOULD NOT be sent to clients when no value is configured. </t>

                <!-- <t> Where an ISP is sending out pre-configured units to customers they MAY consider
                    configuring a suitable stub zone (e.g. ".local") on their recursive DNS servers
                    and using this zone as the configured default. This would mitigate any leakage
                    of end users' locally scoped queries to the wider internet.</t> -->

            </section>

            <section title="DHCP Leases">

                <t> It is noted that some DHCP servers in broadband gateways by default offer their
                    own IP address for the "Domain Name Server" option (as describe above) but then
                    automatically start offering the upstream settings once they've been learnt over
                    the WAN interface.</t>

                <t> In general this behaviour is desirable, but the effect for the end-user is that
                    the settings used depend on whether the DHCP lease was obtained before or after
                    the WAN link was established.</t>

                <t> If the DHCP lease is obtained whilst the WAN link is down then the DHCP client
                    (and hence the DNS client) will not receive the correct values until the DHCP
                    lease is renewed.</t>

                <t> Whilst no specific recommendations are given here, vendors may wish to give
                    consideration to the length of DHCP leases, and whether some mechanism for
                    forcing a DHCP lease renewal (i.e. by toggling the LAN port link state whenever
                    the WAN link state changes from DOWN to UP) might be appropriate.</t>

                <t> Another possibility is that the learnt upstream values might be persisted in
                    non-volatile memory such that on reboot the same values can be automatically
                    offered via DHCP. However this does run the risk that incorrect values are
                    initially offered if the device is moved or connected to another ISP.</t>

            </section>
        </section>

        <section anchor="security" title="Security Considerations">

            <t>This document introduces no new protocols. However there are some security related
                recommendations for vendors that are listed here.</t>

            <section title="Forgery Resilience">

                <t> Whilst DNS proxies are not usually full-feature resolvers they nevertheless
                    share some characteristics with them.</t>

                <t> Notwithstanding the recommendations above about transparency it is often
                    necessary for a DNS proxy to pick a new Query ID for outbound requests to ensure
                    that responses are directed to the correct client.</t>

                <t> It has been standard guidance for many years that each DNS query should use a
                    randomly generated Query ID. However many proxies have been observed picking
                    sequential Query IDs for successive requests.</t>

                <t> DNS proxies SHOULD follow the relevant recommendations in <xref
                        target="I-D.ietf-dnsext-forgery-resilience"/>, particularly those in Section
                    9.2 relating to randomisation of Query IDs and source ports.</t>

            </section>

            <section title="Interface Binding">

                <t> Some routers have been observed to have their DNS proxy listening on both
                    internal (LAN) and external (WAN) interfaces. In this configuration it is
                    possible for the proxy to be used to mount reflector attacks as described in
                        <xref target="RFC5358"/></t>

                <t> The DNS proxy in a router SHOULD NOT by default be accessible from the WAN
                    interfaces of the device.</t>

            </section>

            <section title="Packet Filtering">
                <t> The Transparency and Robustness Principles are not entirely compatible with the
                    Deep Packet Inspection features of security appliances such as firewalls which
                    are intended to protect systems on the inside of a network from rogue traffic.</t>

                <t> However a clear distinction may be made between traffic that is intrinsically
                    malformed and that which merely contains unexpected data.</t>

                <t> Examples of malformed packets which MAY be dropped include:</t>

                <t>
                    <list style="symbols">
                        <t> invalid compression pointers (i.e. those that run forward of the current
                            packet offset, or which don't point at the start of another label).</t>
                        <t> incorrect counts for the Question, Answer, Authority and Additional
                            Sections (although care should be taken where truncation is a
                            possibility).</t>
                    </list>
                </t>

                <t> Since dropped packets will cause the client to repeatedly retransmit the
                    original request, it is RECOMMENDED that proxies SHOULD instead return a
                    suitable DNS error response to the client (i.e. FORMERR) instead of dropping the
                    packet completely.</t>

            </section>

        </section>

        <section anchor="iana" title="IANA Considerations">

            <t>This document requests no IANA actions.</t>

        </section>

        <section title="Change Log">
            <t>draft-bellis-dnsproxy-00 <list>
                    <t>Initial draft</t>
                </list>
            </t>
        </section>

        <section title="Acknowledgements">
            <t>The author would particularly like to acknowledge the assistance of Lisa Phifer of
                Core Competence.</t>
        </section>

    </middle>

    <back>
        <references title="Normative References"> &rfc793; &rfc1035; &rfc1123;
            &rfc2119; &rfc4035; &rfc2131; &rfc2132; &rfc2671; &rfc2845;
            &rfc2930; &rfc3597; &rfc5358; &forgery; </references>
        <references title="Informative References">
            <reference anchor="SAC035" target="http://www.icann.org/committees/security/sac035.pdf">
                <front>
                    <title>Test Report: DNSSEC Impact on Broadband Routers and Firewalls</title>
                    <author fullname="Ray Bellis" initials="R" surname="Bellis">
                        <organization>Nominet UK</organization>
                    </author>
                    <author fullname="Lisa M. Phifer" initials="L.M." surname="Phifer">
                        <organization>Core Competence</organization>
                    </author>
                    <date day="16" month="September" year="2008"/>
                </front>
            </reference>
            <reference anchor="DOTSE" target="http://www.iis.se/docs/Routertester_en.pdf">
                <front>
                    <title>DNSSEC Tests of Consumer Broadband Routers</title>
                    <author fullname="Joakim Ahlund" surname="Ahlund">
                        <organization>.SE</organization>
                    </author>
                    <author fullname="Patrik Wallstrom" surname="Wallstrom">
                        <organization>.SE</organization>
                    </author>
                    <date day="26" month="February" year="2008"/>
                </front>
            </reference>
        </references>
    </back>
</rfc>
