<?xml version="1.0" encoding="US-ASCII"?>
<!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 RFC2119 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml">
<!ENTITY RFC6052 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6052.xml">
<!ENTITY RFC6146 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6146.xml">
<!ENTITY RFC6147 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6147.xml">
<!ENTITY RFC6535 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6535.xml">
<!ENTITY RFC6555 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6555.xml">
<!ENTITY RFC6724 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6724.xml">
<!ENTITY RFC6877 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6877.xml">
<!ENTITY RFC7050 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7050.xml">
<!ENTITY RFC7413 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7413.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 ipr="trust200902"
    updates=""
    obsoletes="6555"
    category="std"
    docName="draft-ietf-v6ops-rfc6555bis-01">

  <!-- category values: std, bcp, info, exp, and historic -->

  <!-- ***** 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="Happy Eyeballs v2">Happy Eyeballs Version 2: Better Connectivity Using Concurrency</title>

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


	<author fullname="David Schinazi" initials="D." surname="Schinazi">
		<organization>Apple Inc.</organization>

		<address>
			<postal>
				<street>1 Infinite Loop</street>
				<city>Cupertino</city>
				<region>California</region>
				<code>95014</code>
				<country>US</country>
			</postal>

			<phone></phone>
			<email>dschinazi@apple.com</email>
		</address>
	</author>

    <author fullname="Tommy Pauly" initials="T." surname="Pauly">
      <organization>Apple Inc.</organization>

      <address>
        <postal>
          <street>1 Infinite Loop</street>
          <city>Cupertino</city>
          <region>California</region>
          <code>95014</code>
          <country>US</country>
        </postal>

        <phone></phone>
        <email>tpauly@apple.com</email>
      </address>
    </author>

<date/>

    <!-- 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>General</area>

    <workgroup>Network</workgroup>

    <!-- TODO
    -->

    <abstract>
      <t>Many communication protocols operated over the modern Internet use host names. These often resolve to multiple IP addresses, each of which may have different performance and connectivity characteristics. Since specific addresses or address families (IPv4 or IPv6) may be blocked, broken, or sub-optimal on a network, clients that attempt multiple connections in parallel have a higher chance of establishing a connection sooner. This document specifies requirements for algorithms that reduce this user-visible delay and provides an example algorithm.</t>
    </abstract>
  </front>

  <middle>
    <?rfc needLines="16"?>
    <section title="Introduction">
        <t>Many communication protocols operated over the modern Internet use host names. These often correspond to multiple IP addresses, whose performance can vary. Since specific addresses or address families (IPv4 or IPv6) may be blocked, broken, or sub-optimal on a network, clients that attempt multiple connections in parallel have a higher chance of establishing a connection sooner. This document specifies requirements for algorithms that reduce this user-visible delay and provides an algorithm.</t>
		<t>This documents expands on "Happy Eyeballs" <xref target="RFC6555"/>, a technique of reducing user-visible delays on dual-stack hosts. Now that this approach has been deployed at scale and measured for several years, the algorithm specification can be refined to improve its reliability and generalization. This document recommends an algorithm of racing resolved addresses that has several stages of ordering and racing to avoid delays to the user whenever possible, while preferring the use of IPv6. Specifically, it discusses how to handle DNS queries when starting a connection on a dual-stack client, how to create an ordered list of addresses to which to attempt connections, and how to race the connection attempts.</t>
      <section title="Requirements Language">
        <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in "Key words for use in RFCs to Indicate Requirement Levels" <xref target="RFC2119"/>.</t>
      </section>
    </section>

	<section title="Overview">
		<t>This document defines a method of connection establishment, named "Happy Eyeballs Connection Setup". This approach has several distinct phases:</t>
		<t><list style="numbers">
			<t>Initiation of asynchronous DNS queries [<xref target="dns"/>]</t>
			<t>Sorting of resolved addresses [<xref target="sorting"/>]</t>
			<t>Initiation of asynchronous connection attempts [<xref target="attempts"/>]</t>
			<t>Establishment of one connection, which cancels all other attempts</t>
		</list></t>
        <t>Note that this document assumes that the host address preference policy favors IPv6 over IPv4. If the host is configured differently, the recommendations in this document can be easily adapted.</t>
	</section>

    <section title="Hostname Resolution Query Handling" anchor="dns">
		<t>When a client has both IPv4 and IPv6 connectivity, and is trying to establish a connection with a named host, it needs to send out both AAAA and A DNS queries. Both queries SHOULD be made as soon after one another as possible, with the AAAA query made first, immediately followed by the A query.</t>
		<t>Implementations MUST NOT wait for both families of answers to return before attempting connection establishment. If one query fails to return, or takes significantly longer to return, waiting for the second address family can significantly delay the connection establishment of the first one. Therefore, the client MUST treat DNS resolution as asynchronous. Note that if the platform does not offer an asynchronous DNS API, this behavior can be simulated by making two separate synchronous queries on different threads, one per address family. If the AAAA query returns first, the first IPv6 connection attempt MUST be immediately started. If the A query returns first, the client SHOULD wait for a short time for the AAAA response. This delay will be referred to as the "Resolution Delay". The RECOMMENDED value for the Resolution Delay is 50 milliseconds. If the AAAA response is received within the Resolution Delay period, the client MUST immediately start the IPv6 connection attempt. If, at the end of the Resolution Delay period, the AAAA response has not been received but the A response has been received, the client SHOULD proceed to Sorting Addresses [<xref target="sorting"/>] and staggered connection attempts [<xref target="attempts"/>] using only the IPv4 addresses returned so far. If the AAAA response arrives while these connection attempts are in progress, but before any connection has been established, then the newly received IPv6 addresses are incorporated into the list of available candidate addresses [<xref target="changes"/>] and the process of connection attempts will continue with the IPv6 addresses added, until one connection is established.</t>
		<section title="Handling Multiple DNS Server Addresses">
			<t>If multiple DNS server addresses are configured for the current network, the client may have the option of sending its DNS queries over IPv4 or IPv6. In keeping with the Happy Eyeballs approach, queries SHOULD be sent over IPv6 first (note that this is not referring to the sending of AAAA or A queries, but rather the address of the DNS server itself). If DNS queries sent to the IPv6 address do not receive responses, that address may be marked as penalized, and queries can be sent to other DNS server addresses.</t>
            <?rfc needLines="5"?>
			<t>As native IPv6 deployments become more prevalent, and IPv4 addresses are exhausted, it is expected that IPv6 connectivity will have preferential treatment within networks. If a DNS server is configured to be accessible over IPv6, IPv6 should be assumed to be the preferred address family.</t>
            <t>Client systems SHOULD NOT have an explicit limit to the number of DNS servers that can be configured, either manually or by the network. If such a limit is required by hardware limitations, it is RECOMMENDED to use at least one address from each address family from the available list.</t>
		</section>
    </section>

	<section title="Sorting Addresses" anchor="sorting">
		<t>Before attempting to connect to any of the resolved addresses, the client should define the order in which to start the attempts. Once the order has been defined, the client can use a simple algorithm for racing each option after a short delay [<xref target="attempts"/>]. It is important that the ordered list involves all addresses from both families, as this allows the client to get the racing effect of Happy Eyeballs for the entire list, not just the first IPv4 and first IPv6 addresses.</t>
		<t>First, the client MUST sort the addresses using Destination Address Selection (<xref target="RFC6724"/>, Section 6).</t>
        <t>If the client is stateful and has history of expected round-trip times (RTT) for the routes to access each address, it SHOULD add a Destination Address Selection rule between rules 8 and 9 that prefers addresses with lower RTTs. If the client keeps track of which addresses it has used in the past, it SHOULD add another destination address selection rule between the RTT rule and rule 9, which prefers used addresses over unused ones. This helps servers that use the client's IP address during authentication, as is the case for TCP Fast Open (<xref target="RFC7413"/>) and some HTTP cookies. This historical data MUST NOT be used across networks, and SHOULD be flushed on network changes.</t>
        <?rfc needLines="11"?>
        <t>Next, the client SHOULD modify the ordered list to interleave address families. Whichever address family is first in the list should be followed by an address of the other address family; that is, if the first address in the sorted list is IPv6, then the first IPv4 address should be moved up in the list to be second in the list. An implementation MAY want to favor one address family more by allowing multiple addresses of that family to be attempted before trying the other family. The number of contiguous addresses of the first address family will be referred to as the "First Address Family Count", and can be a configurable value. This is performed to avoid waiting through a long list of addresses from a given address family if connectivity over that address family is impaired.</t>
	</section>
	<section title="Connection Attempts" anchor="attempts">
		<t>Once the list of addresses has been constructed, the client will attempt to make connections. In order to avoid unreasonable network load, connection attempts SHOULD NOT be made simultaneously. Instead, one connection attempt to a single address is started first, followed by the others in the list, one at a time. Starting a new connection attempt does not affect previous attempts, as multiple connection attempts may occur in parallel. Once one of the connection attempts succeeds (generally when the TCP handshake completes), all other connections attempts that have not yet succeeded SHOULD be cancelled. Any address that was not yet attempted as a connection SHOULD be ignored.</t>
		<t>A simple implementation can have a fixed delay for how long to wait before starting the next connection attempt. This delay is referred to as the "Connection Attempt Delay". One recommended value for this delay is 250 milliseconds. If the client has historical RTT data, it can also use the expected RTT to choose a more nuanced delay value. The recommended formula for calculating the delay after starting a connection attempt is: MAX( 1.25 * RTT_MEAN + 4 * RTT_VARIANCE, 2 * RTT_MEAN ), where the RTT values are based on the statistics for previous address used. If the TCP implementation leverages historical RTT data to compute SYN timeout, these algorithms should match so that a new attempt will be started at the same time as the previous is sending its second TCP SYN. While TCP implementations often leverage an exponential backoff when they detect packet loss, the "Connection Attempt Delay" SHOULD NOT such an aggressive backoff, as it would harm user experience.</t>
        <?rfc needLines="8"?>
        <t>The Connection Attempt Delay MUST have a lower bound, especially if it is computed using historical data. More specifically, a subsequent connection MUST NOT be started within 10 milliseconds of the previous attempt. The recommended minimum value is 100 milliseconds, which is referred to as the "Minimum Connection Attempt Delay". This minimum value is required to avoid congestion collapse in the presence of high packet loss rates. The Connection Attempt Delay SHOULD have an upper bound, referred to as the "Maximum Connection Attempt Delay". The current recommended value is 2 seconds.</t>
	</section>

	<section title="DNS Answer Changes during Happy Eyeballs Connection Setup" anchor="changes">
		<t>If, during the course of connection establishment, the DNS answers change either by adding resolved addresses (for example, due to DNS push notifications <xref target="DNS-PUSH"/>), or removing previously resolved addresses (for example, due to expiry of the TTL on that DNS record), the client should react based on its current progress.</t>
		<t>If an address is removed from the list that already had a connection attempt started, the connection attempt SHOULD NOT be cancelled, but rather be allowed to continue. If the removed address had not yet had a connection attempt started, it SHOULD be removed from the list of addresses to try.</t>
		<t>If an address is added to the list, it should be sorted into the list of addresses not yet attempted according to the rules above (<xref target="sorting"/>).</t>
	</section>

    <section title="Supporting IPv6-only Networks with NAT64 and DNS64" anchor="nat64">
        <t>While many IPv6 transition protocols have been standardized and deployed, most are transparent to client devices. The combined use of NAT64 <xref target="RFC6146"/> and DNS64 <xref target="RFC6147"/> is a popular solution that is being deployed and requires changes in client devices. One possible way to handle these networks is for the client device networking stack to implement 464XLAT <xref target="RFC6877"/>. 464XLAT has the advantage of not requiring changes to user space software, however it requires per-packet translation and does not encourage client application software to support native IPv6. On platforms that do not support 464XLAT, the Happy Eyeballs engine SHOULD follow the recommendations in this section to properly support IPv6-only networks with NAT64 and DNS64.</t>
        <t>The features described in this section SHOULD only be enabled when the host detects one of these networks. A simple heuristic to achieve that is to check if the networks offers routable IPv6 addressing, does not offer routable IPv4 addressing, and offers a DNS resolver address.</t>
        <section title="IPv4 Address Literals" anchor="nat64_v4_literals">
            <t>If client applications or users wish to connect to IPv4 address literals, the Happy Eyeballs engine will need to perform NAT64 address synthesis for them. The solution is similar to "Bump-in-the-Host" <xref target="RFC6535"/> but is implemented inside the Happy Eyeballs library.</t>
            <t>When an IPv4 address is passed in to the library instead of a host name, the device queries the network for the NAT64 prefix using "Discovery of the IPv6 Prefix Used for IPv6 Address Synthesis" <xref target="RFC7050"/> then synthesizes an appropriate IPv6 address (or several) using the encoding described in "IPv6 Addressing of IPv4/IPv6 Translators" <xref target="RFC6052"/>. The synthesized addresses are then inserted into the list of addresses as if they were results from DNS queries; connection attempts follow the algorithm described above (<xref target="attempts"/>).</t>
        </section>
        <section title="Host Names with Broken AAAA Records" anchor="nat64_broken_AAAA">
            <t>At the time of writing, there exist a small but non negligible number of host names that resolve to valid A records and broken AAAA records, which we define as AAAA records that contain seemingly valid IPv6 addresses but those addresses never reply when contacted on the usual ports. These can be for example caused by:
                <list style="symbols">
                    <t>Mistyping of the IPv6 address in the DNS zone configuration</t>
                    <t>Routing black holes</t>
                    <t>Service outages</t>
                </list>
            </t>
            <t>While an algorithm complying with the other sections of this document would correctly handle such host names on a dual-stack network, they will not necessarily function correctly on IPv6-only networks with NAT64 and DNS64. Since DNS64 recursive resolvers rely on the authoritative name servers sending negative ("no error no answer") responses for AAAA records in order to synthesize, they will not synthesize records for these particular host names, and will instead pass through the broken AAAA record.</t>
            <?rfc needLines="11"?>
            <t>In order to support these scenarios, the client device needs to query the DNS for the A record then perform local synthesis. Since these types of host names are rare, and in order to minimize load on DNS servers, this A query should only be performed when the client has given up on the AAAA records it initially received. This can be achieved by using a longer timeout, referred to as the "Last Resort Local Synthesis Delay" and RECOMMENDED at 2 seconds. The timer is started when the last connection attempt is fired. If no connection attempt has succeeded when this timer fires, the device queries the DNS for the IPv4 address and on reception of a valid A record, treats it as if it were provided by the application (<xref target="nat64_v4_literals"/>).</t>
        </section>
        <section title="Virtual Private Networks" anchor="nat64_vpn">
            <t>Some Virtual Private Networks (VPN) may be configured to handle DNS queries from the device. The configuration could encompass all queries, or a subset such as "*.internal.example.com". These VPNs can also be configured to only route part of the IPv4 address space, such as 192.0.2.0/24. However, if an internal hostname resolves to an external IPv4 address, these can cause issues if the underlying network is IPv6-only. As an example, let's assume that "www.internal.example.com" has exactly one A record, 198.51.100.42, and no AAAA records. The client will send the DNS query to the company's recursive resolver and that resolver will reply with these records. The device now only has an IPv4 address to connect to, and no route to that address. Since the company's resolver does not know the NAT64 prefix of the underlying network, it cannot synthesize the address. Similarly, the underlying network's DNS64 recursive resolver does not know the company's internal addresses, so it cannot resolve the hostname. Because of this, the client device needs to resolve the A record using the company's resolver then locally synthesize an IPv6 address, as if the resolved IPv4 address were provided by the application (<xref target="nat64_v4_literals"/>).</t>
            <?rfc needLines="20"?>
        </section>
    </section>

	<section title="Summary of Configurable Values">
		<t>The values that may be configured as defaults on a client for use in Happy Eyeballs are as follows:</t>
		<t><list style="symbols">
			<t>Resolution Delay (<xref target="dns"/>): The time to wait for a AAAA response after receiving an A response. RECOMMENDED at 50 milliseconds.</t>
			<t>First Address Family Count (<xref target="sorting"/>): The number of addresses belonging to the first address family (such as IPv6) that should be attempted before attempting another address family. RECOMMENDED as 1, or 2 to more aggressively favor one address family.</t>
			<t>Connection Attempt Delay (<xref target="attempts"/>): The time to wait between connection attempts in the absence of RTT data. RECOMMENDED at 250 milliseconds.</t>
            <t>Minimum Connection Attempt Delay (<xref target="attempts"/>): The minimum time to wait between connection attempts. RECOMMENDED at 100 milliseconds. MUST NOT be less than 10 milliseconds.</t>
            <t>Maximum Connection Attempt Delay (<xref target="attempts"/>): The maximum time to wait between connection attempts. RECOMMENDED at 2 seconds.</t>
            <t>Last Resort Local Synthesis Delay (<xref target="nat64_broken_AAAA"/>): The time to wait after starting the last IPv6 attempt and before sending the A query. RECOMMENDED at 2 seconds.</t>
		</list></t>
        <t>As time advances, it is expected that the properties of networks will evolve. For that reason, it is expected that these values will change over time. Implementors should feel welcome to use different values without changing this specification. In particular, IPv6 issues are expected to be less common, therefore the Resolution Delay SHOULD be increased with time as client software is updated.</t>
	</section>

    <section title="Limitations">
        <t>Happy Eyeballs will handle initial connection failures at the TCP/IP layer, however other failures or performance issues may still affect the chosen connection.</t>
        <section title="Path Maximum Transmission Unit Discovery">
            <t>Since Happy Eyeballs is only active during the initial handshake and TCP does not pass the initial handshake, issues related to MTU can be masked and go unnoticed during Happy Eyeballs. Solving this issue is out of scope of this document.</t>
        </section>
        <section title="Application Layer">
            <t>If the DNS returns multiple addresses for different application servers, the application itself may not be operational and functional on all of them. Common examples include Transport Layer Security (TLS) and the Hypertext Transport Protocol (HTTP).</t>
        </section>
        <section title="Hiding Operational Issues">
            <t>It has been observed in practice that Happy Eyeballs can hide issues in networks. For example, if a misconfiguration causes IPv6 to consistently fail on a given network while IPv4 is still functional, Happy Eyeballs may impair the operator's ability to notice the issue. It is recommended that network operators deploy external means of monitoring to ensure functionality of all address families.</t>
        </section>
    </section>

	<section anchor="Security" title="Security Considerations">
		<t>This memo has no direct security considerations.</t>
	</section>

    <section anchor="IANA" title="IANA Considerations">
      <t>This memo includes no request to IANA.</t>
    </section>

<section anchor="acknowledgments" title="Acknowledgments">
	<t>The authors thank Dan Wing, Andrew Yourtchenko, and everyone else who worked on the original Happy Eyeballs design (<xref target="RFC6555"/>), Josh Graessley, Stuart Cheshire, and the rest of team at Apple that helped implement and instrument this algorithm, and Jason Fesler and Paul Saab who helped measure and refine this algorithm. The authors would also like to thank Fred Baker, Nick Chettle, Lorenzo Colitti, Igor Gashinsky, Geoff Huston, Jen Linkova, Paul Hoffman, Philip Homburg, Erik Nygren, Jordi Palet Martinez, Rui Paulo, Jinmei Tatuya, Dave Thaler, Joe Touch and James Woodyatt for their input and contributions.</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"?-->
      &RFC2119;
      &RFC6052;
      &RFC6146;
      &RFC6147;
	  &RFC6535;
	  &RFC6555;
	  &RFC6724;
      &RFC7050;

    </references>

    <references title="Informative References">

        &RFC6877;
        &RFC7413;

        <reference anchor='DNS-PUSH'>
            <front>
                <title>DNS Push Notifications</title>
                <author initials='T' surname='Pusateri' fullname='Tom Pusateri'>
                    <organization />
                </author>
                <author initials='S' surname='Cheshire' fullname='Stuart Cheshire'>
                    <organization>Apple Inc.</organization>
                </author>
                <date month='March' year='2017' />
            </front>
            <seriesInfo name='Work in Progress,' value='draft-ietf-dnssd-push' />
            <format type='TXT' target='https://tools.ietf.org/id/draft-ietf-dnssd-push.txt' />
        </reference>

    </references>

    <section title="Differences from RFC6555">
        <t>"Happy Eyeballs: Success with Dual-Stack Hosts" <xref target="RFC6555"/> mostly concentrates on how to stagger connections to a hostname that has an AAAA and an A record. This document additionally discusses:
    <list style="symbols">
          <t>how to perform DNS queries to obtain these addresses</t>
          <t>how to handle multiple addresses from each address family</t>
          <t>how to handle DNS updates while connections are being raced</t>
          <t>how to leverage historical information</t>
          <t>how to support IPv6-only networks with NAT64 and DNS64</t>
        </list> </t>
    </section>
  </back>
</rfc>
