306-ipv6-happy-eyeballs.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. Filename: 306-ipv6-happy-eyeballs.txt
  2. Title: A Tor Implementation of IPv6 Happy Eyeballs
  3. Author: Neel Chauhan
  4. Created: 25-Jun-2019
  5. Supercedes: 299
  6. Status: Open
  7. Ticket: https://trac.torproject.org/projects/tor/ticket/29801
  8. 1. Introduction
  9. As IPv4 address space becomes scarce, ISPs and organizations will deploy
  10. IPv6 in their networks. Right now, Tor clients connect to guards using
  11. IPv4 connectivity by default.
  12. When networks first transition to IPv6, both IPv4 and IPv6 will be enabled
  13. on most networks in a so-called "dual-stack" configuration. This is to not
  14. break existing IPv4-only applications while enabling IPv6 connectivity.
  15. However, IPv6 connectivity may be unreliable and clients should be able
  16. to connect to the guard using the most reliable technology, whether IPv4
  17. or IPv6.
  18. In ticket #27490, we introduced the option ClientAutoIPv6ORPort which
  19. lets a client randomly choose between IPv4 or IPv6. However, this
  20. random decision does not take into account unreliable connectivity
  21. or falling back to the competing IP version should one be unreliable
  22. or unavailable.
  23. One way to select between IPv4 and IPv6 on a dual-stack network is a
  24. so-called "Happy Eyeballs" algorithm as per RFC 8305. In one, a client
  25. attempts the preferred IP family, whether IPv4 or IPv6. Should it work,
  26. the client sticks with the preferred IP family. Otherwise, the client
  27. attempts the alternate version. This means if a dual-stack client has
  28. both IPv4 and IPv6, and IPv6 is unreliable, preferred or not, the
  29. client uses IPv4, and vice versa. However, if IPv4 and IPv6 are both
  30. equally reliable, and IPv6 is preferred, we use IPv6.
  31. In Proposal 299, we have attempted a IP fallback mechanism using failure
  32. counters and preferring IPv4 and IPv6 based on the state of the counters.
  33. However, Prop299 was not standard Happy Eyeballs and an alternative,
  34. standards-compliant proposal was requested in [P299-TRAC] to avoid issues
  35. from complexity caused by randomness.
  36. This proposal describes a Tor implementation of Happy Eyeballs and is
  37. intended as a successor to Proposal 299.
  38. 2. Address/Relay Selection
  39. This section describes the necessary changes for address selection to
  40. implement Prop306.
  41. 2.1. Extend Info Structure Changes
  42. To be able to handle Happy Eyeballs in Tor, we will need to modify the
  43. data structures used for connections to guards, namely the extend info
  44. structure.
  45. The extend info structure should contain both an IPv4 and an IPv6 address.
  46. This will allow us to try IPv4 and the IPv6 addresses should both be
  47. available on a relay and the client is dual-stack.
  48. When parsing relay descriptors and filling in the extend info data
  49. structure, we need to fill in both the IPv4 and IPv6 address if they both
  50. are available. If only one family is available for a relay (IPv4 or IPv6),
  51. we should fill in the address for preferred family and leave the alternate
  52. family null.
  53. 2.2. Relay Selection Changes
  54. In Proposal 283, we have allowed microdescriptor consensus documents to
  55. contain IPv6 addresses. As clients download microdescriptors, Prop283
  56. makes it possible to implement Prop306.
  57. When we select candidates for the entry guard, we should select at least
  58. one relay with an IPv6 address. This makes it possible for an IPv6-only
  59. client to bootstrap. Otherwise we would have failures if all the selected
  60. guard candidates only have IPv4 addresses.
  61. 3. Relay Connections
  62. If there is an existing authenticated connection, we should use it
  63. similar to how we used it pre-Prop306.
  64. If there is no existing authenticated connection for an extend info,
  65. we should attempt to connect using the first available, allowed, and
  66. preferred address.
  67. We should also allow falling back to the alternate address. For this,
  68. three alternate designs will be given.
  69. 3.1. Proposed Designs
  70. This subsection will have three proposed designs for connecting to relays
  71. via IPv4 and IPv6 in a Tor implementation of Happy Eyeballs.
  72. These proposed designs will have some tradeoffs, including:
  73. * Launching multiple TCP connections places up to 2x extra socket load on
  74. dual-stack relays and authorities, because both connections may succeed.
  75. * Launching multiple TLS connections places up to 2x the CPU load on
  76. dual-stack relays and authorities, because both connections may succeed.
  77. * Increasing the delay between connections mitigates the above issues,
  78. but reduces perceived performance, particularly at bootstrap time
  79. (pre-emptive circuits hide these delays after bootstrap).
  80. The proposed designs are as listed as follows:
  81. * Section 3.1.1: First Successful Authentication
  82. * Section 3.1.2: TCP Connection to Preferred Address On First Authenticated
  83. Connection
  84. * Section 3.1.3: TCP Connection to Preferred Address On First TCP Success
  85. 3.1.1. First Successful Authentication
  86. In this design, Tor will first connect to the preferred address and
  87. attempt to authenticate. After a 1.5 second delay (based on Onionperf
  88. data), Tor will connect to the alternate address and try to authenticate.
  89. On the first successful authenticated connection, we close the other
  90. connection.
  91. This design places the least connection load on the network, but might
  92. add extra TLS load.
  93. 3.1.2. TCP Connection to Preferred Address On First Authenticated Connection
  94. This design attempts a TCP connection to a preferred address. On a failure
  95. or a 1.5 second delay, we try the alternative address.
  96. On the first successful TCP connection Tor attempts to authenticate
  97. immediately. On the first authentication success, Tor closes the other
  98. connection.
  99. This design is the most reliable for clients, but increases the connection
  100. load on dual-stack guards and authorities. For instance, this can be used
  101. to amplify a DoS attack on the Tor network.
  102. 3.1.3. TCP Connection to Preferred Address On First TCP Success
  103. In this design, we will connect via TCP to the first preferred address. On
  104. a failure or after a 1.5 second delay, we attempt to connect via TCP to the
  105. alternate address. On a success, Tor attempts to authenticate and closes
  106. the other connection.
  107. This design is the closest to RFC 8305 and is similar to how Happy Eyeballs
  108. is implemented in a web browser.
  109. 3.2. Recommendations for Implementation of Section 3.1 Proposals
  110. We should start with implementing and testing the implementation as
  111. described in Section 3.1.1 (First Successful Authentication), and then
  112. doing the same for the implementations described in 3.1.2 and 3.1.3 if
  113. desired or required.
  114. 3.3. Handling Connection Successes And Failures
  115. Should a connection to a guard succeed and is authenticated via TLS, we
  116. can then use the connection. In this case, we should cancel all other
  117. connection timers and in-progress connections. Cancelling the timers is
  118. necessary so we don't attempt new unnecessary connections when our
  119. existing connection is successful, preventing denial-of-service risks.
  120. However, if we fail all available and allowed connections, we should tell
  121. the rest of Tor that the connection has failed. This is so we can attempt
  122. another guard relay.
  123. 3.4. Connection Attempt Delays
  124. As mentioned in [TEOR-P306-REP], initially, clients should prefer IPv4
  125. by default. The Connection Attempt Delay, or delay between IPv4 and IPv6
  126. connections should be 1.5 seconds. This is to avoid the overhead from
  127. tunneled IPv6 connections.
  128. The Minimum Connection Attempt Delay should not be dynamically adjusted
  129. as it adds privacy risks. This value should be fixed at 10 ms as per
  130. RFC 8305 and could be adjusted using a proposed consensus parameter called
  131. ConnectionAttemptDelay. ConnectionAttemptDelay should be in milliseconds.
  132. The Maximum Connection Attempt Delay should also not be dynamically adjusted
  133. for privacy reasons, but the maximum should be higher than the RFC 8305
  134. recommendation of 2 seconds. For Tor, we should make this timeout value 30
  135. seconds to match Tor's existing timeout.
  136. We should also make it possible for users to set the Maximum Connection
  137. Attempt value higher for slower and higher-latency networks such as dial-up
  138. and satellite.
  139. 4. Option Changes
  140. As we enable IPv6-enabled clients to connect out of the box, we should
  141. adjust the default options to enable IPv6 while not breaking IPv4-only
  142. clients.
  143. 4.1. New Default Options for Prop306
  144. The new default options should be:
  145. * ClientUseIPv4 as 1 (to enable IPv4)
  146. * ClientUseIPv6 as 1 (to enable IPv6)
  147. * ClientPreferIPv6ORPort as 0 (for load-balancing reasons so we don't
  148. overload IPv6-only guards)
  149. One thing to note is that clients should be able to connect with the above
  150. options on IPv4-only, dual-stack, and IPv6-only networks, and they should
  151. also work if ClientPreferIPv6ORPort is 1. This means we shouldn't expect
  152. IPv4 or IPv6 to work if ClientUseIPv4 or ClientUseIPv6 is set.
  153. When the majority of clients are IPv6-capable, we could set the default
  154. value of ClientPreferIPv6ORPort to 1 in order to take advantage of IPv6.
  155. 4.2. Prop306 Consensus Parameters
  156. We could have the following consensus parameters:
  157. * ClientUseIPv6
  158. * ClientPreferIPv6ORPort (when most of the guards have IPv6 and it is fast)
  159. Should we have the consenus parameters, the values for these options should
  160. be set to the values of the similarly-named options as described in Section
  161. 4.1 including the consideration for ClientPreferIPv6ORPort.
  162. 5. Statistics
  163. 5.1. Relay Statistics
  164. Relays could measure the number of successful IPv4 and IPv6 connections.
  165. We could also send this information to directory authorities.
  166. However, should we implement Section 5.1, we should consider the privacy
  167. implications of these statistics, and whether they should be public or not.
  168. 5.2. Client Heartbeat Messages
  169. In a Tor session, we should count the number of IPv4 and IPv6 connections
  170. to ORPorts, and distinguish between authenticated (relay, authority
  171. reachability) and unauthenticated (client, bridge) connections. These
  172. statistics should be included in the Heartbeat logs.
  173. 6. Deploying Prop306
  174. This section describes the information necessary for deployment of Prop306
  175. on Tor clients and in Tor Browser.
  176. 6.1. Initial Feasibility Testing
  177. We should test this proposal with the following scenarios:
  178. * Different combinations of values for the options ClientUseIPv4,
  179. ClientUseIPv6, and ClientPreferIPv6ORPort on IPv4-only, IPv6-only,
  180. and dual-stack connections
  181. * Dual-stack connections of different technologies, including high-bandwidth
  182. and low-latency (e.g. fiber), moderate-bandwidth and moderate-latency
  183. (e.g. DSL, LTE), and high-latency and low-bandwidth (e.g. satellite,
  184. dial-up) to see if Prop306 is reliable and feasible
  185. 6.2. Minimum Viable Prop306 Product
  186. The mimumum viable product for Prop306 must include the following:
  187. * Implementation of one of the algorithms in Section 3.1 along with the
  188. changes described in Sections 2.1 and 2.2
  189. * The Connection Success/Failure mechanism in Section 3.3 and Connection
  190. Delay mechanism in Section 3.4 (the consensus parameter is optional)
  191. * A default setup capable of both IPv4 and IPv6 connections with the
  192. options described in Section 4.1
  193. 6.3. Optional Features
  194. Some features which are optional include:
  195. * Consensus Parameter ConnectionAttemptDelay (Section 3.4) - We will need
  196. this if the Minimum Connection Attempt Delay needs to be dynamically
  197. adjusted
  198. * Consensus Parameters ClientUseIPv6 (Section 4.2), and
  199. ClientPreferIPv6ORPort (Section 4.2) - We will need this if we desire
  200. the ability for clients to prefer IPv6 when the majority of clients
  201. and relays are IPv6-capable without changing the configuration
  202. * Prop306 Statistics (Section 5) - While optional, this may be useful for
  203. debugging and reliability testing, and metrics on IPv4 vs. IPv6
  204. 7. Acknowledgments
  205. Thank you so much to teor for the discussion of the happy eyeballs proposal.
  206. I wouldn't have been able to do this has it not been for your help.
  207. 8. Refrences
  208. [P299-TRAC]: https://trac.torproject.org/projects/tor/ticket/29801
  209. [TEOR-P306-REP]: https://lists.torproject.org/pipermail/tor-dev/2019-July/013919.html