<?xml version="1.0" encoding="US-ASCII"?>
<!-- This template is for creating an Internet Draft using xml2rfc,
     which is available here: http://xml.resource.org. -->
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
<!-- One method to get references from the online citation libraries.
     There has to be one entity for each item to be referenced. 
     An alternate method (rfc include) is described in the references. -->

<!ENTITY RFC1035 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.1035.xml">
<!ENTITY RFC2119 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml">
<!ENTITY RFC2629 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2629.xml">
<!ENTITY RFC3552 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3552.xml">
<!ENTITY RFC5321 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5321.xml">
<!ENTITY RFC6724 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6724.xml">
<!ENTITY RFC6555 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6555.xml">
<!ENTITY RFC3974 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3974.xml">
]>
<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>
<!-- used by XSLT processors -->
<!-- For a complete list and description of processing instructions (PIs), 
     please see http://xml.resource.org/authoring/README.html. -->
<!-- Below are generally applicable Processing Instructions (PIs) that most I-Ds might want to use.
     (Here they are set differently than their defaults in xml2rfc v1.32) -->
<?rfc strict="yes" ?>
<!-- give errors regarding ID-nits and DTD validation -->
<!-- control the table of contents (ToC) -->
<?rfc toc="yes"?>
<!-- generate a ToC -->
<?rfc tocdepth="4"?>
<!-- the number of levels of subsections in ToC. default: 3 -->
<!-- control references -->
<?rfc symrefs="yes"?>
<!-- use symbolic references tags, i.e, [RFC2119] instead of [1] -->
<?rfc sortrefs="yes" ?>
<!-- sort the reference entries alphabetically -->
<!-- control vertical white space 
     (using these PIs as follows is recommended by the RFC Editor) -->
<?rfc compact="yes" ?>
<!-- do not start each main section on a new page -->
<?rfc subcompact="no" ?>
<!-- keep one blank line between list items -->
<!-- end of list of popular I-D processing instructions -->
<rfc category="std" docName="draft-martin-smtp-target-host-selection-ipv4-ipv6-01" ipr="trust200902" updates="5321">
  <!-- category values: std, bcp, info, exp, and historic
     ipr values: full3667, noModification3667, noDerivatives3667
     you can add the attributes updates="NNNN" and obsoletes="NNNN" 
     they will automatically be output with "(if approved)" -->

  <!-- ***** FRONT MATTER ***** -->

  <front>
    <!-- The abbreviated title is used in the page header - it is only necessary if the 
         full title is longer than 39 characters -->

    <title abbrev="SMTP host selection with IPv4/v6">SMTP target host selection in Mixed IPv4/IPv6 environments</title>

    <!-- add 'role="editor"' below for the editors if appropriate -->

    <!-- Another author who claims to be an editor -->

    <author fullname="Franck Martin" initials="F.M." role="editor"
            surname="Martin">
      <organization>LinkedIn</organization>

      <address>
        <postal>
          <street></street>

          <!-- Reorder these if your country does things differently -->

          <city>Mountain View</city>

          <region>CA</region>

          <code></code>

          <country>US</country>
        </postal>

        <phone></phone>

        <email>fmartin@linkedin.com</email>

        <!-- uri and facsimile elements may also be added -->
      </address>
    </author>

    <author fullname="Alec Peterson" initials="A.P." role="editor"
            surname="Peterson">
      <organization>Message Systems</organization>

      <address>
        <postal>
          <street></street>

          <!-- Reorder these if your country does things differently -->

          <city>Columbia</city>

          <region>MD</region>

          <code></code>

          <country>US</country>
        </postal>

        <phone></phone>

        <email>alec@messagesystems.com</email>

        <!-- uri and facsimile elements may also be added -->
      </address>
    </author>

    <date month="December" year="2013" />

    <!-- If the month and year are both specified and are the current ones, xml2rfc will fill 
         in the current day for you. If only the current year is specified, xml2rfc will fill 
	 in the current day and month for you. If the year is not the current one, it is 
	 necessary to specify at least a month (xml2rfc assumes day="1" if not specified for the 
	 purpose of calculating the expiry date).  With drafts it is normally sufficient to 
	 specify just the year. -->

    <!-- Meta-data Declarations -->

    <area>apparea</area>

    <workgroup>Network Working Group</workgroup>

    <!-- WG name at the upperleft corner of the doc,
         IETF is fine for individual submissions.  
	 If this element is not present, the default is "Network Working Group",
         which is used by the RFC Editor as a nod to the history of the IETF. -->

    <keyword>SMTP</keyword>
    <keyword>IPv4</keyword>
    <keyword>IPv6</keyword>
    <keyword>MX</keyword>

    <!-- Keywords will be incorporated into HTML output
         files in a meta tag but they have no effect on text or nroff
         output. If you submit your draft to the RFC Editor, the
         keywords will be used for the search engine. -->

    <abstract>
      <t>The Simple Mail Transfer Protocol (SMTP) is defined in <xref target="RFC5321"></xref>. Section 5 of that document describes the process of host selection. While locating the target host in IPv4 is well defined, this process is unclear for sytems in IPv4 and IPv6 environemts. This specification extends <xref target="RFC5321"></xref> to provide a standard way of selecting the target host in mixed environements.</t>
    </abstract>
  </front>

  <middle>
    <section title="Introduction">
      <t>Target host selection is discussed in <xref target="RFC5321"></xref> section 5 and some operational experience is described in <xref target="RFC3974"></xref>. However the process is unclear when selecting the target host in a mixed environment. Several widely deployed open source MTA do not make this selection the same and sometimes do not find all the hosts. This specification addresses the issue of host selection in mixed environments.</t>

      <section title="Requirements Language">
        <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">RFC 2119</xref>.</t>
      </section>

      <section title="Rationale">
        <t><xref target="RFC5321"></xref> section 5.2 specifically discusses SMTP implementations taking into account 'local circumstances' when deciding which network addresses to use.  However, neither it nor [RFC3974] explore what 'local circumstances' should be evaluated or how they should be evaluated.  The result has thus far been an inconsistent set of SMTP client implementations.  Providing a guideline for how SMTP client implementations should handle various dual-stack situations will improve the stability of the network while we operate in a dual- stack mode (which will likely be for an extended period of time).</t>
      </section>
    </section>

    <section title="Locating the target host">
      <t>This part applies if one or more <xref target="RFC1035">MX Resource Records (RR)</xref> are found for a given name and if the sender-SMTP server is IPV4 and/or IPv6 capable.</t>

      <t>When a domain name associated with an MX RR is looked up and the associated data field obtained, the data field of that response MUST contain a domain name.  That domain name is queried for A RR if the sender-SMTP is IPv4 capable and is queried for AAAA RR if the sender-SMTP is IPv6 capable. A list of IPv4 and IPv6 addresses of the SMTP servers to which the message should be directed is therefore built.</t>

      <t>When there are more than one MX RR associated to the given domain, the above process is done for each MX RR. An ordered list of IPv4 and IPv6 addresses is then established using the MX RR preference. Lower numbers are more preferred than higher ones.</t>

      <t>For the same MX RR preference, when there is more than one IP address (IPv4/IPv6) to be tried, the sender-SMTP SHOULD sort this list either following the application configuration, recognition of an easily reached or well performing address, or the operating system's address selection <xref target="RFC6724"/> or when there is no clear reason to favor one, then the sender-SMTP MUST randomize them to spread the load across multiple mail exchangers for a specific domain name.</t>

      <t>Most sender-SMTP limit the number of IP addresses that will be tried for each MX record.  For the same MX RR preference, the sender-SMTP SHOULD ensure that at least two IP addresses of the other address family are tried before that limit.</t>

      <t>If the sender-SMTP orders the IP list for the same MX RR preference based on some reacheability criteria, it will not prefer IP addresses for instance it cannot connect to, or IP addresses with more rejection or latency. In some ways, this strategy is similar to the <xref target="RFC6555">Happy Eveballs</xref> strategy where web browsers initiate parralel connections to web servers using IPv4 and IPv6 and select the better connection. It is however not similar, because the sender-SMTP MUST NOT try to establish a connection to all the MX RR in parralel but remembers for a period of time which connection, for IP addresses with same MX RR preference, had better response.</t>

      <t>Network paths and servers are constantly breaking and being repaired. Thus, implementations MUST occasionally age out their IPv6 or IPv4 preferences.  It is RECOMMENDED that this information be aged out several times before the maximum retry time of a message while also following the DNS TTL <xref target="RFC1035"/> of the MX RR.</t>

    </section>

    <section anchor="Acknowledgements" title="Acknowledgements">
      <t>Thanks to Murray Kucheraway for guidance in getting this draft out.</t>

    </section>

    <!-- Possibly a 'Contributors' section ... -->

    <section anchor="IANA" title="IANA Considerations">
      <t>This section has no action requested of IANA.</t>

      <t>[RFC Editor: Please remove this section before publication.] </t>

    </section>

    <section anchor="Security" title="Security Considerations">
      <t>Rogue sender-SMTP do not follow MX RR preferences, this existed over IPv4 and common defense can be used over IPv6</t>
    </section>
  </middle>

  <!--  *****BACK MATTER ***** -->

  <back>
    <!-- References split into informative and normative -->

    <!-- There are 2 ways to insert reference entries from the citation libraries:
     1. define an ENTITY at the top, and use "ampersand character"RFC2629; here (as shown)
     2. simply use a PI "less than character"?rfc include="reference.RFC.2119.xml"?> here
        (for I-Ds: include="reference.I-D.narten-iana-considerations-rfc2434bis.xml")

     Both are cited textually in the same manner: by using xref elements.
     If you use the PI option, xml2rfc will, by default, try to find included files in the same
     directory as the including file. You can also define the XML_LIBRARY environment variable
     with a value containing a set of directories to search.  These can be either in the local
     filing system or remote ones accessed by http (http://domain/dir/... ).-->

    <references title="Normative References">
      <!--?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml"?-->
      &RFC1035;

      &RFC2119;

      &RFC3552;

      &RFC5321;

      &RFC6555;

      &RFC6724;      

    </references>

    <references title="Informative References">
      <!-- Here we use entities that we defined at the beginning. -->

      &RFC3974;

    </references>

    <section anchor="app-additional" title="Examples">
      <section title="Target list">
        <section title="Example 1: dual stacked servers">
          <figure>
            <preamble>For example, a site with dual stacked servers may have the following DNS definitions:</preamble>
            <artwork><![CDATA[
      example.org.            IN MX   1  mx1.example.org.
                              IN MX   10 mx10.example.org.
      mx1.example.org.        IN AAAA 2001:db8:ffff::1
                              IN A    192.0.2.1
      mx10.example.org.       IN AAAA 2001:db8:ffff::2
                              IN A    192.0.2.2      
            ]]></artwork>
          </figure>
          <figure>
            <preamble>The ordered preference list will look initially:</preamble>
            <artwork><![CDATA[
      1  2001:db8:ffff::1
      1  192.0.2.1
      10 2001:db8:ffff::2
      10 192.0.2.2  
      ]]></artwork>
          </figure>
        </section>
        <section title="Example 2: single stacked servers">
          <figure>
            <preamble>For example, a site with single stacked servers may have the following DNS definitions:</preamble>
            <artwork><![CDATA[
      example.org.            IN MX   1  mx1-6.example.org.
                              IN MX   1  mx1.example.org
                              IN MX   10 mx10-6.example.org.
                              IN MX   10 mx10.example.org
      mx1-6.example.org.      IN AAAA 2001:db8:ffff::1
      mx1.example.org.        IN A    192.0.2.1
      mx10-6.example.org.     IN AAAA 2001:db8:ffff::2
      mx10.example.org        IN A    192.0.2.2      
            ]]></artwork>
          </figure>
          <figure>
            <preamble>The ordered preference list will look initially:</preamble>
            <artwork><![CDATA[
      1  2001:db8:ffff::1
      1  192.0.2.1
      10 2001:db8:ffff::2
      10 192.0.2.2  
      ]]></artwork>
          </figure>
        </section>

        <section title="Example 3: single and dual stacked servers">
          <figure>
            <preamble>For example, a site with a mix of single and dual stacked servers may have the following DNS definitions:</preamble>
            <artwork><![CDATA[
      example.org.            IN MX   1  mx1.example.org.
                              IN MX   1  mx1-6.example.org
                              IN MX   1  mx2.example.org
                              IN MX   10 mx10.example.org.
      mx1.example.org.        IN A    192.0.2.1
      mx1-6.example.org.      IN AAAA 2001:db8:ffff::1
      mx2.example.org.        IN A    192.0.2.2
      mx10.example.org.       IN AAAA 2001:db8:ffff::2
      mx10.example.org        IN A    192.0.2.3      
            ]]></artwork>
          </figure>
          <figure>
            <preamble>The ordered preference list will look initially:</preamble>
            <artwork><![CDATA[
      1  192.0.2.1
      1  2001:db8:ffff::1
      1  192.0.2.2
      10 2001:db8:ffff::2
      10 192.0.2.3  
      ]]></artwork>
          </figure>
        </section>

        <section title="Example 4: SMTP-Sender limiting the number of IP tried per MX">
          <figure>
            <preamble>For example, a SMTP-server that prefers IPv6 over IPv4 as per <xref target="RFC6724"/> default address preference is trying to send a message to example.org with the following configuration:</preamble>
            <artwork><![CDATA[
      example.org.       IN      MX     10  mail1.example.org.
      example.org.       IN      MX     20  mail2.example.org.
      mail1.example.org. IN      A     192.0.2.1
      mail1.example.org. IN      A     192.0.2.2
      mail1.example.org. IN      A     192.0.2.3
      mail1.example.org. IN      A     192.0.2.4
      mail1.example.org. IN      A     192.0.2.5
      mail1.example.org. IN      A     192.0.2.6
      mail1.example.org. IN      AAAA  2001:db8::1
      mail1.example.org. IN      AAAA  2001:db8::2
      mail1.example.org. IN      AAAA  2001:db8::3
      mail1.example.org. IN      AAAA  2001:db8::4
      mail1.example.org. IN      AAAA  2001:db8::5
      mail1.example.org. IN      AAAA  2001:db8::6
      mail2.example.org. IN      A     192.0.2.100
      mail2.example.org. IN      AAAA  2001:db8::100
            ]]></artwork>
          </figure>
          <figure>
            <preamble>The sender-SMTP would prefer mail1 (preference 10) and then mail2 (preference 20). An SMTP-server implementation that does not implement this specification and has a 6 address limit per MX record and <xref target="RFC6724"/> default address preference, would attempt to connect to the 6 IPv6 addresses belonging to mail1.  If the IPv6 path is broken, these connection attempts would all fail (after a timeout), as would the connection attempt to mail2's IPv6 address.  Finally, after those connection timeouts, the IPv4 address for mail2 would succeed. In contrast, an SMTP-server which is following the normative procedure above would succeed in connecting to mail1 if the IPv4 path is working but the IPv6 path is broken. This SMTP-server implementation would attempt to connect to the four IPv6 addresses belonging to mail1 and then to the IPv4 addresses belonging to mail2 -- resulting in mail delivery to mail1 (which is preferable for the receiving domain) and faster mail delivery.  Following the procedure above with a 6 address limit per MX record and <xref target="RFC6724"/> default address preference, the connections attempted would be:</preamble>
            <artwork><![CDATA[
      2001:db8::1   ; mail1, connection attempt 1
      2001:db8::2   ; mail1, connection attempt 2
      2001:db8::3   ; mail1, connection attempt 3
      2001:db8::4   ; mail1, connection attempt 4
      192.0.2.1     ; mail1, connection attempt 5 (IPv4)
      192.0.2.2     ; mail1, connection attempt 6 (IPv4)
      ; the other addresses for mail1 are not used by this particular
      ; sender-SMTP because of its 6 address limit per MX record.
      2001:db8::100 ; mail2, connection attempt 1 (IPv6)
      192.0.2.100   ; mail2, connection attempt 2 (IPv4)
      ]]></artwork>
          </figure>
        </section>

      </section>
    </section>

  </back>
</rfc>
