idnits 2.17.1 draft-ietf-tram-turnbis-02.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- == There are 4 instances of lines with private range IPv4 addresses in the document. If these are generic example addresses, they should be changed to use any of the ranges defined in RFC 6890 (or successor): 192.0.2.x, 198.51.100.x or 203.0.113.x. -- The document has examples using IPv4 documentation addresses according to RFC6890, but does not use any IPv6 documentation addresses. Maybe there should be IPv6 examples, too? Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (February 3, 2015) is 3369 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Missing Reference: '0x4001' is mentioned on line 654, but not defined ** Obsolete normative reference: RFC 5389 (Obsoleted by RFC 8489) ** Obsolete normative reference: RFC 6145 (Obsoleted by RFC 7915) ** Obsolete normative reference: RFC 3697 (Obsoleted by RFC 6437) -- Obsolete informational reference (is this intentional?): RFC 5245 (Obsoleted by RFC 8445, RFC 8839) -- Obsolete informational reference (is this intentional?): RFC 6156 (Obsoleted by RFC 8656) == Outdated reference: A later version (-12) exists of draft-ietf-tram-turn-server-discovery-01 -- Obsolete informational reference (is this intentional?): RFC 5766 (Obsoleted by RFC 8656) Summary: 3 errors (**), 0 flaws (~~), 4 warnings (==), 5 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 TRAM WG T. Reddy, Ed. 3 Internet-Draft Cisco Systems, Inc. 4 Intended status: Standards Track A. Johnston, Ed. 5 Expires: August 7, 2015 Avaya 6 P. Matthews 7 Alcatel-Lucent 8 J. Rosenberg 9 jdrosen.net 10 February 3, 2015 12 Traversal Using Relays around NAT (TURN): Relay Extensions to Session 13 Traversal Utilities for NAT (STUN) 14 draft-ietf-tram-turnbis-02 16 Abstract 18 If a host is located behind a NAT, then in certain situations it can 19 be impossible for that host to communicate directly with other hosts 20 (peers). In these situations, it is necessary for the host to use 21 the services of an intermediate node that acts as a communication 22 relay. This specification defines a protocol, called TURN (Traversal 23 Using Relays around NAT), that allows the host to control the 24 operation of the relay and to exchange packets with its peers using 25 the relay. TURN differs from some other relay control protocols in 26 that it allows a client to communicate with multiple peers using a 27 single relay address. 29 The TURN protocol was designed to be used as part of the ICE 30 (Interactive Connectivity Establishment) approach to NAT traversal, 31 though it also can be used without ICE. 33 Status of This Memo 35 This Internet-Draft is submitted in full conformance with the 36 provisions of BCP 78 and BCP 79. 38 Internet-Drafts are working documents of the Internet Engineering 39 Task Force (IETF). Note that other groups may also distribute 40 working documents as Internet-Drafts. The list of current Internet- 41 Drafts is at http://datatracker.ietf.org/drafts/current/. 43 Internet-Drafts are draft documents valid for a maximum of six months 44 and may be updated, replaced, or obsoleted by other documents at any 45 time. It is inappropriate to use Internet-Drafts as reference 46 material or to cite them other than as "work in progress." 48 This Internet-Draft will expire on August 7, 2015. 50 Copyright Notice 52 Copyright (c) 2015 IETF Trust and the persons identified as the 53 document authors. All rights reserved. 55 This document is subject to BCP 78 and the IETF Trust's Legal 56 Provisions Relating to IETF Documents 57 (http://trustee.ietf.org/license-info) in effect on the date of 58 publication of this document. Please review these documents 59 carefully, as they describe your rights and restrictions with respect 60 to this document. Code Components extracted from this document must 61 include Simplified BSD License text as described in Section 4.e of 62 the Trust Legal Provisions and are provided without warranty as 63 described in the Simplified BSD License. 65 Table of Contents 67 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 68 2. Overview of Operation . . . . . . . . . . . . . . . . . . . . 5 69 2.1. Transports . . . . . . . . . . . . . . . . . . . . . . . 8 70 2.2. Allocations . . . . . . . . . . . . . . . . . . . . . . . 9 71 2.3. Permissions . . . . . . . . . . . . . . . . . . . . . . . 11 72 2.4. Send Mechanism . . . . . . . . . . . . . . . . . . . . . 11 73 2.5. Channels . . . . . . . . . . . . . . . . . . . . . . . . 13 74 2.6. Unprivileged TURN Servers . . . . . . . . . . . . . . . . 15 75 2.7. Avoiding IP Fragmentation . . . . . . . . . . . . . . . . 16 76 2.8. RTP Support . . . . . . . . . . . . . . . . . . . . . . . 17 77 2.9. Discovery of Servers . . . . . . . . . . . . . . . . . . 17 78 3. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 17 79 4. General Behavior . . . . . . . . . . . . . . . . . . . . . . 19 80 5. Allocations . . . . . . . . . . . . . . . . . . . . . . . . . 22 81 6. Creating an Allocation . . . . . . . . . . . . . . . . . . . 23 82 6.1. Sending an Allocate Request . . . . . . . . . . . . . . . 23 83 6.2. Receiving an Allocate Request . . . . . . . . . . . . . . 25 84 6.3. Receiving an Allocate Success Response . . . . . . . . . 29 85 6.4. Receiving an Allocate Error Response . . . . . . . . . . 30 86 7. Refreshing an Allocation . . . . . . . . . . . . . . . . . . 32 87 7.1. Sending a Refresh Request . . . . . . . . . . . . . . . . 32 88 7.2. Receiving a Refresh Request . . . . . . . . . . . . . . . 33 89 7.3. Receiving a Refresh Response . . . . . . . . . . . . . . 34 90 8. Permissions . . . . . . . . . . . . . . . . . . . . . . . . . 34 91 9. CreatePermission . . . . . . . . . . . . . . . . . . . . . . 35 92 9.1. Forming a CreatePermission Request . . . . . . . . . . . 35 93 9.2. Receiving a CreatePermission Request . . . . . . . . . . 36 94 9.3. Receiving a CreatePermission Response . . . . . . . . . . 36 95 10. Send and Data Methods . . . . . . . . . . . . . . . . . . . . 37 96 10.1. Forming a Send Indication . . . . . . . . . . . . . . . 37 97 10.2. Receiving a Send Indication . . . . . . . . . . . . . . 37 98 10.3. Receiving a UDP Datagram . . . . . . . . . . . . . . . . 38 99 10.4. Receiving a Data Indication . . . . . . . . . . . . . . 38 100 11. Channels . . . . . . . . . . . . . . . . . . . . . . . . . . 39 101 11.1. Sending a ChannelBind Request . . . . . . . . . . . . . 41 102 11.2. Receiving a ChannelBind Request . . . . . . . . . . . . 41 103 11.3. Receiving a ChannelBind Response . . . . . . . . . . . . 43 104 11.4. The ChannelData Message . . . . . . . . . . . . . . . . 43 105 11.5. Sending a ChannelData Message . . . . . . . . . . . . . 43 106 11.6. Receiving a ChannelData Message . . . . . . . . . . . . 44 107 11.7. Relaying Data from the Peer . . . . . . . . . . . . . . 45 108 12. Packet Translations . . . . . . . . . . . . . . . . . . . . . 45 109 12.1. IPv4-to-IPv6 Translations . . . . . . . . . . . . . . . 45 110 12.2. IPv6-to-IPv6 Translations . . . . . . . . . . . . . . . 46 111 12.3. IPv6-to-IPv4 Translations . . . . . . . . . . . . . . . 48 112 13. IP Header Fields . . . . . . . . . . . . . . . . . . . . . . 48 113 14. New STUN Methods . . . . . . . . . . . . . . . . . . . . . . 50 114 15. New STUN Attributes . . . . . . . . . . . . . . . . . . . . . 50 115 15.1. CHANNEL-NUMBER . . . . . . . . . . . . . . . . . . . . . 51 116 15.2. LIFETIME . . . . . . . . . . . . . . . . . . . . . . . . 51 117 15.3. XOR-PEER-ADDRESS . . . . . . . . . . . . . . . . . . . . 51 118 15.4. DATA . . . . . . . . . . . . . . . . . . . . . . . . . . 51 119 15.5. XOR-RELAYED-ADDRESS . . . . . . . . . . . . . . . . . . 52 120 15.6. REQUESTED-ADDRESS-FAMILY . . . . . . . . . . . . . . . . 52 121 15.7. EVEN-PORT . . . . . . . . . . . . . . . . . . . . . . . 52 122 15.8. REQUESTED-TRANSPORT . . . . . . . . . . . . . . . . . . 53 123 15.9. DONT-FRAGMENT . . . . . . . . . . . . . . . . . . . . . 53 124 15.10. RESERVATION-TOKEN . . . . . . . . . . . . . . . . . . . 54 125 15.11. ADDITIONAL-ADDRESS-FAMILY . . . . . . . . . . . . . . . 54 126 15.12. ADDRESS-ERROR-CODE Attribute . . . . . . . . . . . . . . 55 127 16. New STUN Error Response Codes . . . . . . . . . . . . . . . . 55 128 17. Detailed Example . . . . . . . . . . . . . . . . . . . . . . 56 129 18. Security Considerations . . . . . . . . . . . . . . . . . . . 63 130 18.1. Outsider Attacks . . . . . . . . . . . . . . . . . . . . 63 131 18.1.1. Obtaining Unauthorized Allocations . . . . . . . . . 63 132 18.1.2. Offline Dictionary Attacks . . . . . . . . . . . . . 64 133 18.1.3. Faked Refreshes and Permissions . . . . . . . . . . 64 134 18.1.4. Fake Data . . . . . . . . . . . . . . . . . . . . . 64 135 18.1.5. Impersonating a Server . . . . . . . . . . . . . . . 65 136 18.1.6. Eavesdropping Traffic . . . . . . . . . . . . . . . 65 137 18.1.7. TURN Loop Attack . . . . . . . . . . . . . . . . . . 66 138 18.2. Firewall Considerations . . . . . . . . . . . . . . . . 67 139 18.2.1. Faked Permissions . . . . . . . . . . . . . . . . . 67 140 18.2.2. Blacklisted IP Addresses . . . . . . . . . . . . . . 68 141 18.2.3. Running Servers on Well-Known Ports . . . . . . . . 68 142 18.3. Insider Attacks . . . . . . . . . . . . . . . . . . . . 68 143 18.3.1. DoS against TURN Server . . . . . . . . . . . . . . 68 144 18.3.2. Anonymous Relaying of Malicious Traffic . . . . . . 69 145 18.3.3. Manipulating Other Allocations . . . . . . . . . . . 69 147 18.4. Tunnel Amplification Attack . . . . . . . . . . . . . . 69 148 18.5. Other Considerations . . . . . . . . . . . . . . . . . . 70 149 19. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 70 150 20. IAB Considerations . . . . . . . . . . . . . . . . . . . . . 71 151 21. Changes since RFC 5766 . . . . . . . . . . . . . . . . . . . 73 152 22. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 73 153 23. References . . . . . . . . . . . . . . . . . . . . . . . . . 73 154 23.1. Normative References . . . . . . . . . . . . . . . . . . 73 155 23.2. Informative References . . . . . . . . . . . . . . . . . 74 156 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 76 158 1. Introduction 160 A host behind a NAT may wish to exchange packets with other hosts, 161 some of which may also be behind NATs. To do this, the hosts 162 involved can use "hole punching" techniques (see [RFC5128]) in an 163 attempt discover a direct communication path; that is, a 164 communication path that goes from one host to another through 165 intervening NATs and routers, but does not traverse any relays. 167 As described in [RFC5128] and [RFC4787], hole punching techniques 168 will fail if both hosts are behind NATs that are not well behaved. 169 For example, if both hosts are behind NATs that have a mapping 170 behavior of "address-dependent mapping" or "address- and port- 171 dependent mapping", then hole punching techniques generally fail. 173 When a direct communication path cannot be found, it is necessary to 174 use the services of an intermediate host that acts as a relay for the 175 packets. This relay typically sits in the public Internet and relays 176 packets between two hosts that both sit behind NATs. 178 This specification defines a protocol, called TURN, that allows a 179 host behind a NAT (called the TURN client) to request that another 180 host (called the TURN server) act as a relay. The client can arrange 181 for the server to relay packets to and from certain other hosts 182 (called peers) and can control aspects of how the relaying is done. 183 The client does this by obtaining an IP address and port on the 184 server, called the relayed transport address. When a peer sends a 185 packet to the relayed transport address, the server relays the packet 186 to the client. When the client sends a data packet to the server, 187 the server relays it to the appropriate peer using the relayed 188 transport address as the source. 190 A client using TURN must have some way to communicate the relayed 191 transport address to its peers, and to learn each peer's IP address 192 and port (more precisely, each peer's server-reflexive transport 193 address, see Section 2). How this is done is out of the scope of the 194 TURN protocol. One way this might be done is for the client and 195 peers to exchange email messages. Another way is for the client and 196 its peers to use a special-purpose "introduction" or "rendezvous" 197 protocol (see [RFC5128] for more details). 199 If TURN is used with ICE [RFC5245], then the relayed transport 200 address and the IP addresses and ports of the peers are included in 201 the ICE candidate information that the rendezvous protocol must 202 carry. For example, if TURN and ICE are used as part of a multimedia 203 solution using SIP [RFC3261], then SIP serves the role of the 204 rendezvous protocol, carrying the ICE candidate information inside 205 the body of SIP messages. If TURN and ICE are used with some other 206 rendezvous protocol, then [I-D.rosenberg-mmusic-ice-nonsip] provides 207 guidance on the services the rendezvous protocol must perform. 209 Though the use of a TURN server to enable communication between two 210 hosts behind NATs is very likely to work, it comes at a high cost to 211 the provider of the TURN server, since the server typically needs a 212 high-bandwidth connection to the Internet . As a consequence, it is 213 best to use a TURN server only when a direct communication path 214 cannot be found. When the client and a peer use ICE to determine the 215 communication path, ICE will use hole punching techniques to search 216 for a direct path first and only use a TURN server when a direct path 217 cannot be found. 219 TURN was originally invented to support multimedia sessions signaled 220 using SIP. Since SIP supports forking, TURN supports multiple peers 221 per relayed transport address; a feature not supported by other 222 approaches (e.g., SOCKS [RFC1928]). However, care has been taken to 223 make sure that TURN is suitable for other types of applications. 225 TURN was designed as one piece in the larger ICE approach to NAT 226 traversal. Implementors of TURN are urged to investigate ICE and 227 seriously consider using it for their application. However, it is 228 possible to use TURN without ICE. 230 TURN is an extension to the STUN (Session Traversal Utilities for 231 NAT) protocol [RFC5389]. Most, though not all, TURN messages are 232 STUN-formatted messages. A reader of this document should be 233 familiar with STUN. 235 2. Overview of Operation 237 This section gives an overview of the operation of TURN. It is non- 238 normative. 240 In a typical configuration, a TURN client is connected to a private 241 network [RFC1918] and through one or more NATs to the public 242 Internet. On the public Internet is a TURN server. Elsewhere in the 243 Internet are one or more peers with which the TURN client wishes to 244 communicate. These peers may or may not be behind one or more NATs. 245 The client uses the server as a relay to send packets to these peers 246 and to receive packets from these peers. 248 Peer A 249 Server-Reflexive +---------+ 250 Transport Address | | 251 192.0.2.150:32102 | | 252 | /| | 253 TURN | / ^| Peer A | 254 Client's Server | / || | 255 Host Transport Transport | // || | 256 Address Address | // |+---------+ 257 10.1.1.2:49721 192.0.2.15:3478 |+-+ // Peer A 258 | | ||N| / Host Transport 259 | +-+ | ||A|/ Address 260 | | | | v|T| 192.168.100.2:49582 261 | | | | /+-+ 262 +---------+| | | |+---------+ / +---------+ 263 | || |N| || | // | | 264 | TURN |v | | v| TURN |/ | | 265 | Client |----|A|----------| Server |------------------| Peer B | 266 | | | |^ | |^ ^| | 267 | | |T|| | || || | 268 +---------+ | || +---------+| |+---------+ 269 | || | | 270 | || | | 271 +-+| | | 272 | | | 273 | | | 274 Client's | Peer B 275 Server-Reflexive Relayed Transport 276 Transport Address Transport Address Address 277 192.0.2.1:7000 192.0.2.15:50000 192.0.2.210:49191 279 Figure 1 281 Figure 1 shows a typical deployment. In this figure, the TURN client 282 and the TURN server are separated by a NAT, with the client on the 283 private side and the server on the public side of the NAT. This NAT 284 is assumed to be a "bad" NAT; for example, it might have a mapping 285 property of "address-and-port-dependent mapping" (see [RFC4787]). 287 The client talks to the server from a (IP address, port) combination 288 called the client's HOST TRANSPORT ADDRESS. (The combination of an 289 IP address and port is called a TRANSPORT ADDRESS.) 290 The client sends TURN messages from its host transport address to a 291 transport address on the TURN server that is known as the TURN SERVER 292 TRANSPORT ADDRESS. The client learns the TURN server transport 293 address through some unspecified means (e.g., configuration), and 294 this address is typically used by many clients simultaneously. 296 Since the client is behind a NAT, the server sees packets from the 297 client as coming from a transport address on the NAT itself. This 298 address is known as the client's SERVER-REFLEXIVE transport address; 299 packets sent by the server to the client's server-reflexive transport 300 address will be forwarded by the NAT to the client's host transport 301 address. 303 The client uses TURN commands to create and manipulate an ALLOCATION 304 on the server. An allocation is a data structure on the server. 305 This data structure contains, amongst other things, the RELAYED 306 TRANSPORT ADDRESS for the allocation. The relayed transport address 307 is the transport address on the server that peers can use to have the 308 server relay data to the client. An allocation is uniquely 309 identified by its relayed transport address. 311 Once an allocation is created, the client can send application data 312 to the server along with an indication of to which peer the data is 313 to be sent, and the server will relay this data to the appropriate 314 peer. The client sends the application data to the server inside a 315 TURN message; at the server, the data is extracted from the TURN 316 message and sent to the peer in a UDP datagram. In the reverse 317 direction, a peer can send application data in a UDP datagram to the 318 relayed transport address for the allocation; the server will then 319 encapsulate this data inside a TURN message and send it to the client 320 along with an indication of which peer sent the data. Since the TURN 321 message always contains an indication of which peer the client is 322 communicating with, the client can use a single allocation to 323 communicate with multiple peers. 325 When the peer is behind a NAT, then the client must identify the peer 326 using its server-reflexive transport address rather than its host 327 transport address. For example, to send application data to Peer A 328 in the example above, the client must specify 192.0.2.150:32102 (Peer 329 A's server-reflexive transport address) rather than 330 192.168.100.2:49582 (Peer A's host transport address). 332 Each allocation on the server belongs to a single client and has 333 exactly one relayed transport address that is used only by that 334 allocation. Thus, when a packet arrives at a relayed transport 335 address on the server, the server knows for which client the data is 336 intended. 338 The client may have multiple allocations on a server at the same 339 time. 341 2.1. Transports 343 TURN, as defined in this specification, always uses UDP between the 344 server and the peer. However, this specification allows the use of 345 any one of UDP, TCP, Transport Layer Security (TLS) over TCP or 346 Datagram Transport Layer Security (DTLS) over UDP to carry the TURN 347 messages between the client and the server. 349 +----------------------------+---------------------+ 350 | TURN client to TURN server | TURN server to peer | 351 +----------------------------+---------------------+ 352 | UDP | UDP | 353 | TCP | UDP | 354 | TLS-over-TCP | UDP | 355 | DTLS-over-UDP | UDP | 356 +----------------------------+---------------------+ 358 If TCP or TLS-over-TCP is used between the client and the server, 359 then the server will convert between these transports and UDP 360 transport when relaying data to/from the peer. 362 Since this version of TURN only supports UDP between the server and 363 the peer, it is expected that most clients will prefer to use UDP 364 between the client and the server as well. That being the case, some 365 readers may wonder: Why also support TCP and TLS-over-TCP? 367 TURN supports TCP transport between the client and the server because 368 some firewalls are configured to block UDP entirely. These firewalls 369 block UDP but not TCP, in part because TCP has properties that make 370 the intention of the nodes being protected by the firewall more 371 obvious to the firewall. For example, TCP has a three-way handshake 372 that makes in clearer that the protected node really wishes to have 373 that particular connection established, while for UDP the best the 374 firewall can do is guess which flows are desired by using filtering 375 rules. Also, TCP has explicit connection teardown; while for UDP, 376 the firewall has to use timers to guess when the flow is finished. 378 TURN supports TLS-over-TCP transport and DTLS-over-UDP transport 379 between the client and the server because (D)TLS provides additional 380 security properties not provided by TURN's default digest 381 authentication; properties that some clients may wish to take 382 advantage of. In particular, (D)TLS provides a way for the client to 383 ascertain that it is talking to the correct server, and provides for 384 confidentiality of TURN control messages. TURN does not require 385 (D)TLS because the overhead of using (D)TLS is higher than that of 386 digest authentication; for example, using (D)TLS likely means that 387 most application data will be doubly encrypted (once by (D)TLS and 388 once to ensure it is still encrypted in the UDP datagram). 390 There is an extension to TURN for TCP transport between the server 391 and the peers [RFC6062]. For this reason, allocations that use UDP 392 between the server and the peers are known as UDP allocations, while 393 allocations that use TCP between the server and the peers are known 394 as TCP allocations. This specification describes only UDP 395 allocations. 397 In some applications for TURN, the client may send and receive 398 packets other than TURN packets on the host transport address it uses 399 to communicate with the server. This can happen, for example, when 400 using TURN with ICE. In these cases, the client can distinguish TURN 401 packets from other packets by examining the source address of the 402 arriving packet: those arriving from the TURN server will be TURN 403 packets. 405 2.2. Allocations 407 To create an allocation on the server, the client uses an Allocate 408 transaction. The client sends an Allocate request to the server, and 409 the server replies with an Allocate success response containing the 410 allocated relayed transport address. The client can include 411 attributes in the Allocate request that describe the type of 412 allocation it desires (e.g., the lifetime of the allocation). Since 413 relaying data has security implications, the server requires that the 414 client authenticate itself, typically using STUN's long-term 415 credential mechanism, to show that it is authorized to use the 416 server. 418 Once a relayed transport address is allocated, a client must keep the 419 allocation alive. To do this, the client periodically sends a 420 Refresh request to the server. TURN deliberately uses a different 421 method (Refresh rather than Allocate) for refreshes to ensure that 422 the client is informed if the allocation vanishes for some reason. 424 The frequency of the Refresh transaction is determined by the 425 lifetime of the allocation. The default lifetime of an allocation is 426 10 minutes -- this value was chosen to be long enough so that 427 refreshing is not typically a burden on the client, while expiring 428 allocations where the client has unexpectedly quit in a timely 429 manner. However, the client can request a longer lifetime in the 430 Allocate request and may modify its request in a Refresh request, and 431 the server always indicates the actual lifetime in the response. The 432 client must issue a new Refresh transaction within "lifetime" seconds 433 of the previous Allocate or Refresh transaction. Once a client no 434 longer wishes to use an allocation, it should delete the allocation 435 using a Refresh request with a requested lifetime of 0. 437 Both the server and client keep track of a value known as the 438 5-TUPLE. At the client, the 5-tuple consists of the client's host 439 transport address, the server transport address, and the transport 440 protocol used by the client to communicate with the server. At the 441 server, the 5-tuple value is the same except that the client's host 442 transport address is replaced by the client's server-reflexive 443 address, since that is the client's address as seen by the server. 445 Both the client and the server remember the 5-tuple used in the 446 Allocate request. Subsequent messages between the client and the 447 server use the same 5-tuple. In this way, the client and server know 448 which allocation is being referred to. If the client wishes to 449 allocate a second relayed transport address, it must create a second 450 allocation using a different 5-tuple (e.g., by using a different 451 client host address or port). 453 NOTE: While the terminology used in this document refers to 454 5-tuples, the TURN server can store whatever identifier it likes 455 that yields identical results. Specifically, an implementation 456 may use a file-descriptor in place of a 5-tuple to represent a TCP 457 connection. 459 TURN TURN Peer Peer 460 client server A B 461 |-- Allocate request --------------->| | | 462 | | | | 463 |<--------------- Allocate failure --| | | 464 | (401 Unauthorized) | | | 465 | | | | 466 |-- Allocate request --------------->| | | 467 | | | | 468 |<---------- Allocate success resp --| | | 469 | (192.0.2.15:50000) | | | 470 // // // // 471 | | | | 472 |-- Refresh request ---------------->| | | 473 | | | | 474 |<----------- Refresh success resp --| | | 475 | | | | 477 Figure 2 479 In Figure 2, the client sends an Allocate request to the server 480 without credentials. Since the server requires that all requests be 481 authenticated using STUN's long-term credential mechanism, the server 482 rejects the request with a 401 (Unauthorized) error code. The client 483 then tries again, this time including credentials (not shown). This 484 time, the server accepts the Allocate request and returns an Allocate 485 success response containing (amongst other things) the relayed 486 transport address assigned to the allocation. Sometime later, the 487 client decides to refresh the allocation and thus sends a Refresh 488 request to the server. The refresh is accepted and the server 489 replies with a Refresh success response. 491 2.3. Permissions 493 To ease concerns amongst enterprise IT administrators that TURN could 494 be used to bypass corporate firewall security, TURN includes the 495 notion of permissions. TURN permissions mimic the address-restricted 496 filtering mechanism of NATs that comply with [RFC4787]. 498 An allocation can have zero or more permissions. Each permission 499 consists of an IP address and a lifetime. When the server receives a 500 UDP datagram on the allocation's relayed transport address, it first 501 checks the list of permissions. If the source IP address of the 502 datagram matches a permission, the application data is relayed to the 503 client, otherwise the UDP datagram is silently discarded. 505 A permission expires after 5 minutes if it is not refreshed, and 506 there is no way to explicitly delete a permission. This behavior was 507 selected to match the behavior of a NAT that complies with [RFC4787]. 509 The client can install or refresh a permission using either a 510 CreatePermission request or a ChannelBind request. Using the 511 CreatePermission request, multiple permissions can be installed or 512 refreshed with a single request -- this is important for applications 513 that use ICE. For security reasons, permissions can only be 514 installed or refreshed by transactions that can be authenticated; 515 thus, Send indications and ChannelData messages (which are used to 516 send data to peers) do not install or refresh any permissions. 518 Note that permissions are within the context of an allocation, so 519 adding or expiring a permission in one allocation does not affect 520 other allocations. 522 2.4. Send Mechanism 524 There are two mechanisms for the client and peers to exchange 525 application data using the TURN server. The first mechanism uses the 526 Send and Data methods, the second way uses channels. Common to both 527 ways is the ability of the client to communicate with multiple peers 528 using a single allocated relayed transport address; thus, both ways 529 include a means for the client to indicate to the server which peer 530 should receive the data, and for the server to indicate to the client 531 which peer sent the data. 533 The Send mechanism uses Send and Data indications. Send indications 534 are used to send application data from the client to the server, 535 while Data indications are used to send application data from the 536 server to the client. 538 When using the Send mechanism, the client sends a Send indication to 539 the TURN server containing (a) an XOR-PEER-ADDRESS attribute 540 specifying the (server-reflexive) transport address of the peer and 541 (b) a DATA attribute holding the application data. When the TURN 542 server receives the Send indication, it extracts the application data 543 from the DATA attribute and sends it in a UDP datagram to the peer, 544 using the allocated relay address as the source address. Note that 545 there is no need to specify the relayed transport address, since it 546 is implied by the 5-tuple used for the Send indication. 548 In the reverse direction, UDP datagrams arriving at the relayed 549 transport address on the TURN server are converted into Data 550 indications and sent to the client, with the server-reflexive 551 transport address of the peer included in an XOR-PEER-ADDRESS 552 attribute and the data itself in a DATA attribute. Since the relayed 553 transport address uniquely identified the allocation, the server 554 knows which client should receive the data. 556 Send and Data indications cannot be authenticated, since the long- 557 term credential mechanism of STUN does not support authenticating 558 indications. This is not as big an issue as it might first appear, 559 since the client-to-server leg is only half of the total path to the 560 peer. Applications that want proper security should encrypt the data 561 sent between the client and a peer. 563 Because Send indications are not authenticated, it is possible for an 564 attacker to send bogus Send indications to the server, which will 565 then relay these to a peer. To partly mitigate this attack, TURN 566 requires that the client install a permission towards a peer before 567 sending data to it using a Send indication. 569 TURN TURN Peer Peer 570 client server A B 571 | | | | 572 |-- CreatePermission req (Peer A) -->| | | 573 |<-- CreatePermission success resp --| | | 574 | | | | 575 |--- Send ind (Peer A)-------------->| | | 576 | |=== data ===>| | 577 | | | | 578 | |<== data ====| | 579 |<-------------- Data ind (Peer A) --| | | 580 | | | | 581 | | | | 582 |--- Send ind (Peer B)-------------->| | | 583 | | dropped | | 584 | | | | 585 | |<== data ==================| 586 | dropped | | | 587 | | | | 589 Figure 3 591 In Figure 3, the client has already created an allocation and now 592 wishes to send data to its peers. The client first creates a 593 permission by sending the server a CreatePermission request 594 specifying Peer A's (server-reflexive) IP address in the XOR-PEER- 595 ADDRESS attribute; if this was not done, the server would not relay 596 data between the client and the server. The client then sends data 597 to Peer A using a Send indication; at the server, the application 598 data is extracted and forwarded in a UDP datagram to Peer A, using 599 the relayed transport address as the source transport address. When 600 a UDP datagram from Peer A is received at the relayed transport 601 address, the contents are placed into a Data indication and forwarded 602 to the client. Later, the client attempts to exchange data with Peer 603 B; however, no permission has been installed for Peer B, so the Send 604 indication from the client and the UDP datagram from the peer are 605 both dropped by the server. 607 2.5. Channels 609 For some applications (e.g., Voice over IP), the 36 bytes of overhead 610 that a Send indication or Data indication adds to the application 611 data can substantially increase the bandwidth required between the 612 client and the server. To remedy this, TURN offers a second way for 613 the client and server to associate data with a specific peer. 615 This second way uses an alternate packet format known as the 616 ChannelData message. The ChannelData message does not use the STUN 617 header used by other TURN messages, but instead has a 4-byte header 618 that includes a number known as a channel number. Each channel 619 number in use is bound to a specific peer and thus serves as a 620 shorthand for the peer's host transport address. 622 To bind a channel to a peer, the client sends a ChannelBind request 623 to the server, and includes an unbound channel number and the 624 transport address of the peer. Once the channel is bound, the client 625 can use a ChannelData message to send the server data destined for 626 the peer. Similarly, the server can relay data from that peer 627 towards the client using a ChannelData message. 629 Channel bindings last for 10 minutes unless refreshed -- this 630 lifetime was chosen to be longer than the permission lifetime. 631 Channel bindings are refreshed by sending another ChannelBind request 632 rebinding the channel to the peer. Like permissions (but unlike 633 allocations), there is no way to explicitly delete a channel binding; 634 the client must simply wait for it to time out. 636 TURN TURN Peer Peer 637 client server A B 638 | | | | 639 |-- ChannelBind req ---------------->| | | 640 | (Peer A to 0x4001) | | | 641 | | | | 642 |<---------- ChannelBind succ resp --| | | 643 | | | | 644 |-- [0x4001] data ------------------>| | | 645 | |=== data ===>| | 646 | | | | 647 | |<== data ====| | 648 |<------------------ [0x4001] data --| | | 649 | | | | 650 |--- Send ind (Peer A)-------------->| | | 651 | |=== data ===>| | 652 | | | | 653 | |<== data ====| | 654 |<------------------ [0x4001] data --| | | 655 | | | | 657 Figure 4 659 Figure 4 shows the channel mechanism in use. The client has already 660 created an allocation and now wishes to bind a channel to Peer A. To 661 do this, the client sends a ChannelBind request to the server, 662 specifying the transport address of Peer A and a channel number 663 (0x4001). After that, the client can send application data 664 encapsulated inside ChannelData messages to Peer A: this is shown as 665 "[0x4001] data" where 0x4001 is the channel number. When the 666 ChannelData message arrives at the server, the server transfers the 667 data to a UDP datagram and sends it to Peer A (which is the peer 668 bound to channel number 0x4001). 670 In the reverse direction, when Peer A sends a UDP datagram to the 671 relayed transport address, this UDP datagram arrives at the server on 672 the relayed transport address assigned to the allocation. Since the 673 UDP datagram was received from Peer A, which has a channel number 674 assigned to it, the server encapsulates the data into a ChannelData 675 message when sending the data to the client. 677 Once a channel has been bound, the client is free to intermix 678 ChannelData messages and Send indications. In the figure, the client 679 later decides to use a Send indication rather than a ChannelData 680 message to send additional data to Peer A. The client might decide 681 to do this, for example, so it can use the DONT-FRAGMENT attribute 682 (see the next section). However, once a channel is bound, the server 683 will always use a ChannelData message, as shown in the call flow. 685 Note that ChannelData messages can only be used for peers to which 686 the client has bound a channel. In the example above, Peer A has 687 been bound to a channel, but Peer B has not, so application data to 688 and from Peer B would use the Send mechanism. 690 2.6. Unprivileged TURN Servers 692 This version of TURN is designed so that the server can be 693 implemented as an application that runs in user space under commonly 694 available operating systems without requiring special privileges. 695 This design decision was made to make it easy to deploy a TURN 696 server: for example, to allow a TURN server to be integrated into a 697 peer-to-peer application so that one peer can offer NAT traversal 698 services to another peer. 700 This design decision has the following implications for data relayed 701 by a TURN server: 703 o The value of the Diffserv field may not be preserved across the 704 server; 706 o The Time to Live (TTL) field may be reset, rather than 707 decremented, across the server; 709 o The Explicit Congestion Notification (ECN) field may be reset by 710 the server; 712 o ICMP messages are not relayed by the server; 713 o There is no end-to-end fragmentation, since the packet is re- 714 assembled at the server. 716 Future work may specify alternate TURN semantics that address these 717 limitations. 719 2.7. Avoiding IP Fragmentation 721 For reasons described in [Frag-Harmful], applications, especially 722 those sending large volumes of data, should try hard to avoid having 723 their packets fragmented. Applications using TCP can more or less 724 ignore this issue because fragmentation avoidance is now a standard 725 part of TCP, but applications using UDP (and thus any application 726 using this version of TURN) must handle fragmentation avoidance 727 themselves. 729 The application running on the client and the peer can take one of 730 two approaches to avoid IP fragmentation. 732 The first approach is to avoid sending large amounts of application 733 data in the TURN messages/UDP datagrams exchanged between the client 734 and the peer. This is the approach taken by most VoIP (Voice-over- 735 IP) applications. In this approach, the application exploits the 736 fact that the IP specification [RFC0791] specifies that IP packets up 737 to 576 bytes should never need to be fragmented. 739 The exact amount of application data that can be included while 740 avoiding fragmentation depends on the details of the TURN session 741 between the client and the server: whether UDP, TCP, or (D)TLS 742 transport is used, whether ChannelData messages or Send/Data 743 indications are used, and whether any additional attributes (such as 744 the DONT-FRAGMENT attribute) are included. Another factor, which is 745 hard to determine, is whether the MTU is reduced somewhere along the 746 path for other reasons, such as the use of IP-in-IP tunneling. 748 As a guideline, sending a maximum of 500 bytes of application data in 749 a single TURN message (by the client on the client-to-server leg) or 750 a UDP datagram (by the peer on the peer-to-server leg) will generally 751 avoid IP fragmentation. To further reduce the chance of 752 fragmentation, it is recommended that the client use ChannelData 753 messages when transferring significant volumes of data, since the 754 overhead of the ChannelData message is less than Send and Data 755 indications. 757 The second approach the client and peer can take to avoid 758 fragmentation is to use a path MTU discovery algorithm to determine 759 the maximum amount of application data that can be sent without 760 fragmentation. 762 Unfortunately, because servers implementing this version of TURN do 763 not relay ICMP messages, the classic path MTU discovery algorithm 764 defined in [RFC1191] is not able to discover the MTU of the 765 transmission path between the client and the peer. (Even if they did 766 relay ICMP messages, the algorithm would not always work since ICMP 767 messages are often filtered out by combined NAT/firewall devices). 769 So the client and server need to use a path MTU discovery algorithm 770 that does not require ICMP messages. The Packetized Path MTU 771 Discovery algorithm defined in [RFC4821] is one such algorithm. 773 The details of how to use the algorithm of [RFC4821] with TURN are 774 still under investigation. However, as a step towards this goal, 775 this version of TURN supports a DONT-FRAGMENT attribute. When the 776 client includes this attribute in a Send indication, this tells the 777 server to set the DF bit in the resulting UDP datagram that it sends 778 to the peer. Since some servers may be unable to set the DF bit, the 779 client should also include this attribute in the Allocate request -- 780 any server that does not support the DONT-FRAGMENT attribute will 781 indicate this by rejecting the Allocate request. 783 2.8. RTP Support 785 One of the envisioned uses of TURN is as a relay for clients and 786 peers wishing to exchange real-time data (e.g., voice or video) using 787 RTP. To facilitate the use of TURN for this purpose, TURN includes 788 some special support for older versions of RTP. 790 Old versions of RTP [RFC3550] required that the RTP stream be on an 791 even port number and the associated RTP Control Protocol (RTCP) 792 stream, if present, be on the next highest port. To allow clients to 793 work with peers that still require this, TURN allows the client to 794 request that the server allocate a relayed transport address with an 795 even port number, and to optionally request the server reserve the 796 next-highest port number for a subsequent allocation. 798 2.9. Discovery of Servers 800 Methods of TURN server discovery, including using anycast, are 801 described in [I-D.ietf-tram-turn-server-discovery]. 803 3. Terminology 805 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 806 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 807 document are to be interpreted as described in RFC 2119 [RFC2119]. 809 Readers are expected to be familiar with [RFC5389] and the terms 810 defined there. 812 The following terms are used in this document: 814 TURN: The protocol spoken between a TURN client and a TURN server. 815 It is an extension to the STUN protocol [RFC5389]. The protocol 816 allows a client to allocate and use a relayed transport address. 818 TURN client: A STUN client that implements this specification. 820 TURN server: A STUN server that implements this specification. It 821 relays data between a TURN client and its peer(s). 823 Peer: A host with which the TURN client wishes to communicate. The 824 TURN server relays traffic between the TURN client and its 825 peer(s). The peer does not interact with the TURN server using 826 the protocol defined in this document; rather, the peer receives 827 data sent by the TURN server and the peer sends data towards the 828 TURN server. 830 Transport Address: The combination of an IP address and a port. 832 Host Transport Address: A transport address on a client or a peer. 834 Server-Reflexive Transport Address: A transport address on the 835 "public side" of a NAT. This address is allocated by the NAT to 836 correspond to a specific host transport address. 838 Relayed Transport Address: A transport address on the TURN server 839 that is used for relaying packets between the client and a peer. 840 A peer sends to this address on the TURN server, and the packet is 841 then relayed to the client. 843 TURN Server Transport Address: A transport address on the TURN 844 server that is used for sending TURN messages to the server. This 845 is the transport address that the client uses to communicate with 846 the server. 848 Peer Transport Address: The transport address of the peer as seen by 849 the server. When the peer is behind a NAT, this is the peer's 850 server-reflexive transport address. 852 Allocation: The relayed transport address granted to a client 853 through an Allocate request, along with related state, such as 854 permissions and expiration timers. 856 5-tuple: The combination (client IP address and port, server IP 857 address and port, and transport protocol (currently one of UDP, 858 TCP, or (D)TLS)) used to communicate between the client and the 859 server. The 5-tuple uniquely identifies this communication 860 stream. The 5-tuple also uniquely identifies the Allocation on 861 the server. 863 Channel: A channel number and associated peer transport address. 864 Once a channel number is bound to a peer's transport address, the 865 client and server can use the more bandwidth-efficient ChannelData 866 message to exchange data. 868 Permission: The IP address and transport protocol (but not the port) 869 of a peer that is permitted to send traffic to the TURN server and 870 have that traffic relayed to the TURN client. The TURN server 871 will only forward traffic to its client from peers that match an 872 existing permission. 874 Realm: A string used to describe the server or a context within the 875 server. The realm tells the client which username and password 876 combination to use to authenticate requests. 878 Nonce: A string chosen at random by the server and included in the 879 message-digest. To prevent reply attacks, the server should 880 change the nonce regularly. 882 4. General Behavior 884 This section contains general TURN processing rules that apply to all 885 TURN messages. 887 TURN is an extension to STUN. All TURN messages, with the exception 888 of the ChannelData message, are STUN-formatted messages. All the 889 base processing rules described in [RFC5389] apply to STUN-formatted 890 messages. This means that all the message-forming and message- 891 processing descriptions in this document are implicitly prefixed with 892 the rules of [RFC5389]. 894 [RFC5389] specifies an authentication mechanism called the long-term 895 credential mechanism. TURN servers and clients MUST implement this 896 mechanism. The server MUST demand that all requests from the client 897 be authenticated using this mechanism, or that a equally strong or 898 stronger mechanism for client authentication is used. 900 Note that the long-term credential mechanism applies only to requests 901 and cannot be used to authenticate indications; thus, indications in 902 TURN are never authenticated. If the server requires requests to be 903 authenticated, then the server's administrator MUST choose a realm 904 value that will uniquely identify the username and password 905 combination that the client must use, even if the client uses 906 multiple servers under different administrations. The server's 907 administrator MAY choose to allocate a unique username to each 908 client, or MAY choose to allocate the same username to more than one 909 client (for example, to all clients from the same department or 910 company). For each allocation, the server SHOULD generate a new 911 random nonce when the allocation is first attempted following the 912 randomness recommendations in [RFC4086] and SHOULD expire the nonce 913 at least once every hour during the lifetime of the allocation. 915 All requests after the initial Allocate must use the same username as 916 that used to create the allocation, to prevent attackers from 917 hijacking the client's allocation. Specifically, if the server 918 requires the use of the long-term credential mechanism, and if a non- 919 Allocate request passes authentication under this mechanism, and if 920 the 5-tuple identifies an existing allocation, but the request does 921 not use the same username as used to create the allocation, then the 922 request MUST be rejected with a 441 (Wrong Credentials) error. 924 When a TURN message arrives at the server from the client, the server 925 uses the 5-tuple in the message to identify the associated 926 allocation. For all TURN messages (including ChannelData) EXCEPT an 927 Allocate request, if the 5-tuple does not identify an existing 928 allocation, then the message MUST either be rejected with a 437 929 Allocation Mismatch error (if it is a request) or silently ignored 930 (if it is an indication or a ChannelData message). A client 931 receiving a 437 error response to a request other than Allocate MUST 932 assume the allocation no longer exists. 934 [RFC5389] defines a number of attributes, including the SOFTWARE and 935 FINGERPRINT attributes. The client SHOULD include the SOFTWARE 936 attribute in all Allocate and Refresh requests and MAY include it in 937 any other requests or indications. The server SHOULD include the 938 SOFTWARE attribute in all Allocate and Refresh responses (either 939 success or failure) and MAY include it in other responses or 940 indications. The client and the server MAY include the FINGERPRINT 941 attribute in any STUN-formatted messages defined in this document. 943 TURN does not use the backwards-compatibility mechanism described in 944 [RFC5389]. 946 TURN, as defined in this specification, supports both IPv4 and IPv6. 947 IPv6 support in TURN includes IPv4-to-IPv6, IPv6-to-IPv6, and IPv6- 948 to-IPv4 relaying. The REQUESTED-ADDRESS-FAMILY attribute allows a 949 client to explicitly request the address type the TURN server will 950 allocate (e.g., an IPv4-only node may request the TURN server to 951 allocate an IPv6 address). The ADDITIONAL-ADDRESS-FAMILY attribute 952 allows a client to request the server to allocate one IPv4 and one 953 IPv6 relay address in a single Allocate request. This saves local 954 ports on the client and reduces the number of messages sent between 955 the client and the TURN server. 957 By default, TURN runs on the same ports as STUN: 3478 for TURN over 958 UDP and TCP, and 5349 for TURN over (D)TLS. However, TURN has its 959 own set of Service Record (SRV) names: "turn" for UDP and TCP, and 960 "turns" for (D)TLS. Either the SRV procedures or the ALTERNATE- 961 SERVER procedures, both described in Section 6, can be used to run 962 TURN on a different port. 964 To ensure interoperability, a TURN server MUST support the use of UDP 965 transport between the client and the server, and SHOULD support the 966 use of TCP and (D)TLS transport. 968 When UDP transport is used between the client and the server, the 969 client will retransmit a request if it does not receive a response 970 within a certain timeout period. Because of this, the server may 971 receive two (or more) requests with the same 5-tuple and same 972 transaction id. STUN requires that the server recognize this case 973 and treat the request as idempotent (see [RFC5389]). Some 974 implementations may choose to meet this requirement by remembering 975 all received requests and the corresponding responses for 40 seconds. 976 Other implementations may choose to reprocess the request and arrange 977 that such reprocessing returns essentially the same response. To aid 978 implementors who choose the latter approach (the so-called "stateless 979 stack approach"), this specification includes some implementation 980 notes on how this might be done. Implementations are free to choose 981 either approach or choose some other approach that gives the same 982 results. 984 When TCP transport is used between the client and the server, it is 985 possible that a bit error will cause a length field in a TURN packet 986 to become corrupted, causing the receiver to lose synchronization 987 with the incoming stream of TURN messages. A client or server that 988 detects a long sequence of invalid TURN messages over TCP transport 989 SHOULD close the corresponding TCP connection to help the other end 990 detect this situation more rapidly. 992 To mitigate either intentional or unintentional denial-of-service 993 attacks against the server by clients with valid usernames and 994 passwords, it is RECOMMENDED that the server impose limits on both 995 the number of allocations active at one time for a given username and 996 on the amount of bandwidth those allocations can use. The server 997 should reject new allocations that would exceed the limit on the 998 allowed number of allocations active at one time with a 486 999 (Allocation Quota Exceeded) (see Section 6.2), and should discard 1000 application data traffic that exceeds the bandwidth quota. 1002 5. Allocations 1004 All TURN operations revolve around allocations, and all TURN messages 1005 are associated with an allocation. An allocation conceptually 1006 consists of the following state data: 1008 o the relayed transport address; 1010 o the 5-tuple: (client's IP address, client's port, server IP 1011 address, server port, transport protocol); 1013 o the authentication information; 1015 o the time-to-expiry; 1017 o a list of permissions; 1019 o a list of channel to peer bindings. 1021 The relayed transport address is the transport address allocated by 1022 the server for communicating with peers, while the 5-tuple describes 1023 the communication path between the client and the server. On the 1024 client, the 5-tuple uses the client's host transport address; on the 1025 server, the 5-tuple uses the client's server-reflexive transport 1026 address. 1028 Both the relayed transport address and the 5-tuple MUST be unique 1029 across all allocations, so either one can be used to uniquely 1030 identify the allocation. 1032 The authentication information (e.g., username, password, realm, and 1033 nonce) is used to both verify subsequent requests and to compute the 1034 message integrity of responses. The username, realm, and nonce 1035 values are initially those used in the authenticated Allocate request 1036 that creates the allocation, though the server can change the nonce 1037 value during the lifetime of the allocation using a 438 (Stale Nonce) 1038 reply. Note that, rather than storing the password explicitly, for 1039 security reasons, it may be desirable for the server to store the key 1040 value, which is an MD5 hash over the username, realm, and password 1041 (see [RFC5389]). 1043 Editor's Note: Remove MD5 based on the changes in STUN bis draft. 1045 The time-to-expiry is the time in seconds left until the allocation 1046 expires. Each Allocate or Refresh transaction sets this timer, which 1047 then ticks down towards 0. By default, each Allocate or Refresh 1048 transaction resets this timer to the default lifetime value of 600 1049 seconds (10 minutes), but the client can request a different value in 1050 the Allocate and Refresh request. Allocations can only be refreshed 1051 using the Refresh request; sending data to a peer does not refresh an 1052 allocation. When an allocation expires, the state data associated 1053 with the allocation can be freed. 1055 The list of permissions is described in Section 8 and the list of 1056 channels is described in Section 11. 1058 6. Creating an Allocation 1060 An allocation on the server is created using an Allocate transaction. 1062 6.1. Sending an Allocate Request 1064 The client forms an Allocate request as follows. 1066 The client first picks a host transport address. It is RECOMMENDED 1067 that the client pick a currently unused transport address, typically 1068 by allowing the underlying OS to pick a currently unused port for a 1069 new socket. 1071 The client then picks a transport protocol to use between the client 1072 and the server. The transport protocol MUST be one of UDP, TCP, TLS- 1073 over-TCP or DTLS-over-UDP. Since this specification only allows UDP 1074 between the server and the peers, it is RECOMMENDED that the client 1075 pick UDP unless it has a reason to use a different transport. One 1076 reason to pick a different transport would be that the client 1077 believes, either through configuration or by experiment, that it is 1078 unable to contact any TURN server using UDP. See Section 2.1 for 1079 more discussion. 1081 The client also picks a server transport address, which SHOULD be 1082 done as follows. The client receives (perhaps through configuration) 1083 a domain name for a TURN server. The client then uses the DNS 1084 procedures described in [RFC5389], but using an SRV service name of 1085 "turn" (or "turns" for TURN over (D)TLS) instead of "stun" (or 1086 "stuns"). For example, to find servers in the example.com domain, 1087 the client performs a lookup for '_turn._udp.example.com', 1088 '_turn._tcp.example.com', and '_turns._tcp.example.com' if the client 1089 wants to communicate with the server using UDP, TCP, TLS-over-TCP, or 1090 DTLS-over-UDP, respectively. 1092 The client MUST include a REQUESTED-TRANSPORT attribute in the 1093 request. This attribute specifies the transport protocol between the 1094 server and the peers (note that this is NOT the transport protocol 1095 that appears in the 5-tuple). In this specification, the REQUESTED- 1096 TRANSPORT type is always UDP. This attribute is included to allow 1097 future extensions to specify other protocols. 1099 If the client wishes to obtain a relayed transport address of a 1100 specific address type then it includes a REQUESTED-ADDRESS-FAMILY 1101 attribute in the request. This attribute indicates the specific 1102 address type the client wishes the TURN server to allocate. Clients 1103 MUST NOT include more than one REQUESTED-ADDRESS-FAMILY attribute in 1104 an Allocate request. Clients MUST NOT include a REQUESTED-ADDRESS- 1105 FAMILY attribute in an Allocate request that contains a RESERVATION- 1106 TOKEN attribute, for the reasons outlined in [RFC6156]. 1108 If the client wishes to obtain one IPv6 and one IPv4 relayed 1109 transport addresses then it includes an ADDITIONAL-ADDRESS-FAMILY 1110 attribute in the request. This attribute specifies that the server 1111 must allocate both address types. The attribute value in the 1112 ADDITIONAL-ADDRESS-FAMILY MUST be set to 0x02 (IPv6 address family). 1113 Clients MUST NOT include REQUESTED-ADDRESS-FAMILY and ADDITIONAL- 1114 ADDRESS-FAMILY attributes in the same request. Clients MUST NOT 1115 include ADDITIONAL-ADDRESS-FAMILY attribute in a Allocate request 1116 that contains a RESERVATION-TOKEN attribute. Clients MUST NOT 1117 include ADDITIONAL-ADDRESS-FAMILY attribute in a Allocate request 1118 that contains a EVEN-PORT attribute with the R bit set to 1. 1120 If the client wishes the server to initialize the time-to-expiry 1121 field of the allocation to some value other than the default 1122 lifetime, then it MAY include a LIFETIME attribute specifying its 1123 desired value. This is just a hint, and the server may elect to use 1124 a different value. Note that the server will ignore requests to 1125 initialize the field to less than the default value. 1127 If the client wishes to later use the DONT-FRAGMENT attribute in one 1128 or more Send indications on this allocation, then the client SHOULD 1129 include the DONT-FRAGMENT attribute in the Allocate request. This 1130 allows the client to test whether this attribute is supported by the 1131 server. 1133 If the client requires the port number of the relayed transport 1134 address be even, the client includes the EVEN-PORT attribute. If 1135 this attribute is not included, then the port can be even or odd. By 1136 setting the R bit in the EVEN-PORT attribute to 1, the client can 1137 request that the server reserve the next highest port number (on the 1138 same IP address) for a subsequent allocation. If the R bit is 0, no 1139 such request is made. 1141 The client MAY also include a RESERVATION-TOKEN attribute in the 1142 request to ask the server to use a previously reserved port for the 1143 allocation. If the RESERVATION-TOKEN attribute is included, then the 1144 client MUST omit the EVEN-PORT attribute. 1146 Once constructed, the client sends the Allocate request on the 1147 5-tuple. 1149 6.2. Receiving an Allocate Request 1151 When the server receives an Allocate request, it performs the 1152 following checks: 1154 1. The server MUST require that the request be authenticated. This 1155 authentication MUST be done using the long-term credential 1156 mechanism of [RFC5389] unless the client and server agree to use 1157 another mechanism through some procedure outside the scope of 1158 this document. 1160 2. The server checks if the 5-tuple is currently in use by an 1161 existing allocation. If yes, the server rejects the request 1162 with a 437 (Allocation Mismatch) error. 1164 3. The server checks if the request contains a REQUESTED-TRANSPORT 1165 attribute. If the REQUESTED-TRANSPORT attribute is not included 1166 or is malformed, the server rejects the request with a 400 (Bad 1167 Request) error. Otherwise, if the attribute is included but 1168 specifies a protocol other that UDP, the server rejects the 1169 request with a 442 (Unsupported Transport Protocol) error. 1171 4. The request may contain a DONT-FRAGMENT attribute. If it does, 1172 but the server does not support sending UDP datagrams with the 1173 DF bit set to 1 (see Section 13), then the server treats the 1174 DONT-FRAGMENT attribute in the Allocate request as an unknown 1175 comprehension-required attribute. 1177 5. The server checks if the request contains a RESERVATION-TOKEN 1178 attribute. If yes, and the request also contains an EVEN-PORT 1179 or REQUESTED-ADDRESS-FAMILY or ADDITIONAL-ADDRESS-FAMILY 1180 attribute, the server rejects the request with a 400 (Bad 1181 Request) error. Otherwise, it checks to see if the token is 1182 valid (i.e., the token is in range and has not expired and the 1183 corresponding relayed transport address is still available). If 1184 the token is not valid for some reason, the server rejects the 1185 request with a 508 (Insufficient Capacity) error. 1187 6. The server checks if the request contains both REQUESTED- 1188 ADDRESS-FAMILY and ADDITIONAL-ADDRESS-FAMILY attributes, then 1189 the server rejects the request with a 400 (Bad Request) error. 1191 7. If the server does not support the address family requested by 1192 the client in REQUESTED-ADDRESS-FAMILY or is disabled by local 1193 policy, it MUST generate an Allocate error response, and it MUST 1194 include an ERROR-CODE attribute with the 440 (Address Family not 1195 Supported) response code. If the REQUESTED-ADDRESS-FAMILY 1196 attribute is absent, the server MUST allocate an IPv4 relayed 1197 transport address for the TURN client. 1199 8. The server checks if the request contains an EVEN-PORT attribute 1200 with the R bit set to 1. If yes, and the request also contains 1201 an ADDITIONAL- ADDRESS-FAMILY attribute, the server rejects the 1202 request with a 400 (Bad Request) error. Otherwise, the server 1203 checks if it can satisfy the request (i.e., can allocate a 1204 relayed transport address as described below). If the server 1205 cannot satisfy the request, then the server rejects the request 1206 with a 508 (Insufficient Capacity) error. 1208 9. The server checks if the request contains an ADDITIONAL-ADDRESS- 1209 FAMILY attribute. If yes, and the attribute value is 0x01 (IPv4 1210 address family), then the server rejects the request with a 400 1211 (Bad Request) error. Otherwise, and the server checks if it can 1212 allocate relayed transport addresses of both address types. If 1213 the server cannot satisfy the request, then the server rejects 1214 the request with a 508 (Insufficient Capacity) error. If the 1215 server can partially meet the request, i.e. if it can only 1216 allocate one relayed transport address of a specific address 1217 type, then it includes ADDRESS-ERROR-CODE attribute in the 1218 response to inform the client the reason for partial failure of 1219 the request. The error code value signaled in the ADDRESS- 1220 ERROR-CODE attribute could be 440 (Address Family not Supported) 1221 or 508 (Insufficient Capacity). 1223 10. At any point, the server MAY choose to reject the request with a 1224 486 (Allocation Quota Reached) error if it feels the client is 1225 trying to exceed some locally defined allocation quota. The 1226 server is free to define this allocation quota any way it 1227 wishes, but SHOULD define it based on the username used to 1228 authenticate the request, and not on the client's transport 1229 address. 1231 11. Also at any point, the server MAY choose to reject the request 1232 with a 300 (Try Alternate) error if it wishes to redirect the 1233 client to a different server. The use of this error code and 1234 attribute follow the specification in [RFC5389]. 1236 If all the checks pass, the server creates the allocation. The 1237 5-tuple is set to the 5-tuple from the Allocate request, while the 1238 list of permissions and the list of channels are initially empty. 1240 The server chooses a relayed transport address for the allocation as 1241 follows: 1243 o If the request contains a RESERVATION-TOKEN attribute, the server 1244 uses the previously reserved transport address corresponding to 1245 the included token (if it is still available). Note that the 1246 reservation is a server-wide reservation and is not specific to a 1247 particular allocation, since the Allocate request containing the 1248 RESERVATION-TOKEN uses a different 5-tuple than the Allocate 1249 request that made the reservation. The 5-tuple for the Allocate 1250 request containing the RESERVATION-TOKEN attribute can be any 1251 allowed 5-tuple; it can use a different client IP address and 1252 port, a different transport protocol, and even different server IP 1253 address and port (provided, of course, that the server IP address 1254 and port are ones on which the server is listening for TURN 1255 requests). 1257 o If the request contains an EVEN-PORT attribute with the R bit set 1258 to 0, then the server allocates a relayed transport address with 1259 an even port number. 1261 o If the request contains an EVEN-PORT attribute with the R bit set 1262 to 1, then the server looks for a pair of port numbers N and N+1 1263 on the same IP address, where N is even. Port N is used in the 1264 current allocation, while the relayed transport address with port 1265 N+1 is assigned a token and reserved for a future allocation. The 1266 server MUST hold this reservation for at least 30 seconds, and MAY 1267 choose to hold longer (e.g., until the allocation with port N 1268 expires). The server then includes the token in a RESERVATION- 1269 TOKEN attribute in the success response. 1271 o Otherwise, the server allocates any available relayed transport 1272 address. 1274 In all cases, the server SHOULD only allocate ports from the range 1275 49152 - 65535 (the Dynamic and/or Private Port range [Port-Numbers]), 1276 unless the TURN server application knows, through some means not 1277 specified here, that other applications running on the same host as 1278 the TURN server application will not be impacted by allocating ports 1279 outside this range. This condition can often be satisfied by running 1280 the TURN server application on a dedicated machine and/or by 1281 arranging that any other applications on the machine allocate ports 1282 before the TURN server application starts. In any case, the TURN 1283 server SHOULD NOT allocate ports in the range 0 - 1023 (the Well- 1284 Known Port range) to discourage clients from using TURN to run 1285 standard services. 1287 NOTE: The use of randomized port assignments to avoid certain 1288 types of attacks is described in [RFC6056]. It is RECOMMENDED 1289 that a TURN server implement a randomized port assignment 1290 algorithm from [RFC6056]. This is especially applicable to 1291 servers that choose to pre-allocate a number of ports from the 1292 underlying OS and then later assign them to allocations; for 1293 example, a server may choose this technique to implement the EVEN- 1294 PORT attribute. 1296 The server determines the initial value of the time-to-expiry field 1297 as follows. If the request contains a LIFETIME attribute, then the 1298 server computes the minimum of the client's proposed lifetime and the 1299 server's maximum allowed lifetime. If this computed value is greater 1300 than the default lifetime, then the server uses the computed lifetime 1301 as the initial value of the time-to-expiry field. Otherwise, the 1302 server uses the default lifetime. It is RECOMMENDED that the server 1303 use a maximum allowed lifetime value of no more than 3600 seconds (1 1304 hour). Servers that implement allocation quotas or charge users for 1305 allocations in some way may wish to use a smaller maximum allowed 1306 lifetime (perhaps as small as the default lifetime) to more quickly 1307 remove orphaned allocations (that is, allocations where the 1308 corresponding client has crashed or terminated or the client 1309 connection has been lost for some reason). Also, note that the time- 1310 to-expiry is recomputed with each successful Refresh request, and 1311 thus the value computed here applies only until the first refresh. 1313 Once the allocation is created, the server replies with a success 1314 response. The success response contains: 1316 o An XOR-RELAYED-ADDRESS attribute containing the relayed transport 1317 address. 1319 o A LIFETIME attribute containing the current value of the time-to- 1320 expiry timer. 1322 o A RESERVATION-TOKEN attribute (if a second relayed transport 1323 address was reserved). 1325 o An XOR-MAPPED-ADDRESS attribute containing the client's IP address 1326 and port (from the 5-tuple). 1328 NOTE: The XOR-MAPPED-ADDRESS attribute is included in the response 1329 as a convenience to the client. TURN itself does not make use of 1330 this value, but clients running ICE can often need this value and 1331 can thus avoid having to do an extra Binding transaction with some 1332 STUN server to learn it. 1334 The response (either success or error) is sent back to the client on 1335 the 5-tuple. 1337 NOTE: When the Allocate request is sent over UDP, section 7.3.1 of 1338 [RFC5389] requires that the server handle the possible 1339 retransmissions of the request so that retransmissions do not 1340 cause multiple allocations to be created. Implementations may 1341 achieve this using the so-called "stateless stack approach" as 1342 follows. To detect retransmissions when the original request was 1343 successful in creating an allocation, the server can store the 1344 transaction id that created the request with the allocation data 1345 and compare it with incoming Allocate requests on the same 1346 5-tuple. Once such a request is detected, the server can stop 1347 parsing the request and immediately generate a success response. 1348 When building this response, the value of the LIFETIME attribute 1349 can be taken from the time-to-expiry field in the allocate state 1350 data, even though this value may differ slightly from the LIFETIME 1351 value originally returned. In addition, the server may need to 1352 store an indication of any reservation token returned in the 1353 original response, so that this may be returned in any 1354 retransmitted responses. 1356 For the case where the original request was unsuccessful in 1357 creating an allocation, the server may choose to do nothing 1358 special. Note, however, that there is a rare case where the 1359 server rejects the original request but accepts the retransmitted 1360 request (because conditions have changed in the brief intervening 1361 time period). If the client receives the first failure response, 1362 it will ignore the second (success) response and believe that an 1363 allocation was not created. An allocation created in this matter 1364 will eventually timeout, since the client will not refresh it. 1365 Furthermore, if the client later retries with the same 5-tuple but 1366 different transaction id, it will receive a 437 (Allocation 1367 Mismatch), which will cause it to retry with a different 5-tuple. 1368 The server may use a smaller maximum lifetime value to minimize 1369 the lifetime of allocations "orphaned" in this manner. 1371 6.3. Receiving an Allocate Success Response 1373 If the client receives an Allocate success response, then it MUST 1374 check that the mapped address and the relayed transport address are 1375 part of an address family that the client understands and is prepared 1376 to handle. If these two addresses are not part of an address family 1377 which the client is prepared to handle, then the client MUST delete 1378 the allocation (Section 7) and MUST NOT attempt to create another 1379 allocation on that server until it believes the mismatch has been 1380 fixed. 1382 Otherwise, the client creates its own copy of the allocation data 1383 structure to track what is happening on the server. In particular, 1384 the client needs to remember the actual lifetime received back from 1385 the server, rather than the value sent to the server in the request. 1386 The client must also remember the 5-tuple used for the request and 1387 the username and password it used to authenticate the request to 1388 ensure that it reuses them for subsequent messages. The client also 1389 needs to track the channels and permissions it establishes on the 1390 server. 1392 The client will probably wish to send the relayed transport address 1393 to peers (using some method not specified here) so the peers can 1394 communicate with it. The client may also wish to use the server- 1395 reflexive address it receives in the XOR-MAPPED-ADDRESS attribute in 1396 its ICE processing. 1398 6.4. Receiving an Allocate Error Response 1400 If the client receives an Allocate error response, then the 1401 processing depends on the actual error code returned: 1403 o (Request timed out): There is either a problem with the server, or 1404 a problem reaching the server with the chosen transport. The 1405 client considers the current transaction as having failed but MAY 1406 choose to retry the Allocate request using a different transport 1407 (e.g., TCP instead of UDP). 1409 o 300 (Try Alternate): The server would like the client to use the 1410 server specified in the ALTERNATE-SERVER attribute instead. The 1411 client considers the current transaction as having failed, but 1412 SHOULD try the Allocate request with the alternate server before 1413 trying any other servers (e.g., other servers discovered using the 1414 SRV procedures). When trying the Allocate request with the 1415 alternate server, the client follows the ALTERNATE-SERVER 1416 procedures specified in [RFC5389]. 1418 o 400 (Bad Request): The server believes the client's request is 1419 malformed for some reason. The client considers the current 1420 transaction as having failed. The client MAY notify the user or 1421 operator and SHOULD NOT retry the request with this server until 1422 it believes the problem has been fixed. 1424 o 401 (Unauthorized): If the client has followed the procedures of 1425 the long-term credential mechanism and still gets this error, then 1426 the server is not accepting the client's credentials. In this 1427 case, the client considers the current transaction as having 1428 failed and SHOULD notify the user or operator. The client SHOULD 1429 NOT send any further requests to this server until it believes the 1430 problem has been fixed. 1432 o 403 (Forbidden): The request is valid, but the server is refusing 1433 to perform it, likely due to administrative restrictions. The 1434 client considers the current transaction as having failed. The 1435 client MAY notify the user or operator and SHOULD NOT retry the 1436 same request with this server until it believes the problem has 1437 been fixed. 1439 o 420 (Unknown Attribute): If the client included a DONT-FRAGMENT 1440 attribute in the request and the server rejected the request with 1441 a 420 error code and listed the DONT-FRAGMENT attribute in the 1442 UNKNOWN-ATTRIBUTES attribute in the error response, then the 1443 client now knows that the server does not support the DONT- 1444 FRAGMENT attribute. The client considers the current transaction 1445 as having failed but MAY choose to retry the Allocate request 1446 without the DONT-FRAGMENT attribute. 1448 o 437 (Allocation Mismatch): This indicates that the client has 1449 picked a 5-tuple that the server sees as already in use. One way 1450 this could happen is if an intervening NAT assigned a mapped 1451 transport address that was used by another client that recently 1452 crashed. The client considers the current transaction as having 1453 failed. The client SHOULD pick another client transport address 1454 and retry the Allocate request (using a different transaction id). 1455 The client SHOULD try three different client transport addresses 1456 before giving up on this server. Once the client gives up on the 1457 server, it SHOULD NOT try to create another allocation on the 1458 server for 2 minutes. 1460 o 438 (Stale Nonce): See the procedures for the long-term credential 1461 mechanism [RFC5389]. 1463 o 440 (Address Family not Supported): The server does not support 1464 the address family requested by the client. If the client 1465 receives an Allocate error response with the 440 (Unsupported 1466 Address Family) error code, the client MUST NOT retry the request. 1468 o 441 (Wrong Credentials): The client should not receive this error 1469 in response to a Allocate request. The client MAY notify the user 1470 or operator and SHOULD NOT retry the same request with this server 1471 until it believes the problem has been fixed. 1473 o 442 (Unsupported Transport Address): The client should not receive 1474 this error in response to a request for a UDP allocation. The 1475 client MAY notify the user or operator and SHOULD NOT reattempt 1476 the request with this server until it believes the problem has 1477 been fixed. 1479 o 486 (Allocation Quota Reached): The server is currently unable to 1480 create any more allocations with this username. The client 1481 considers the current transaction as having failed. The client 1482 SHOULD wait at least 1 minute before trying to create any more 1483 allocations on the server. 1485 o 508 (Insufficient Capacity): The server has no more relayed 1486 transport addresses available, or has none with the requested 1487 properties, or the one that was reserved is no longer available. 1488 The client considers the current operation as having failed. If 1489 the client is using either the EVEN-PORT or the RESERVATION-TOKEN 1490 attribute, then the client MAY choose to remove or modify this 1491 attribute and try again immediately. Otherwise, the client SHOULD 1492 wait at least 1 minute before trying to create any more 1493 allocations on this server. 1495 An unknown error response MUST be handled as described in [RFC5389]. 1497 7. Refreshing an Allocation 1499 A Refresh transaction can be used to either (a) refresh an existing 1500 allocation and update its time-to-expiry or (b) delete an existing 1501 allocation. 1503 If a client wishes to continue using an allocation, then the client 1504 MUST refresh it before it expires. It is suggested that the client 1505 refresh the allocation roughly 1 minute before it expires. If a 1506 client no longer wishes to use an allocation, then it SHOULD 1507 explicitly delete the allocation. A client MAY refresh an allocation 1508 at any time for other reasons. 1510 7.1. Sending a Refresh Request 1512 If the client wishes to immediately delete an existing allocation, it 1513 includes a LIFETIME attribute with a value of 0. All other forms of 1514 the request refresh the allocation. The client MUST NOT include any 1515 REQUESTED-ADDRESS-FAMILY attribute in its Refresh Request. 1517 When refreshing a dual allocation, the client includes ADDITIONAL- 1518 ADDRESS-FAMILY attribute indicating the address family type that 1519 should be refreshed. If no ADDITIONAL-ADDRESS-FAMILY is included 1520 then the request should be treated as applying to all current 1521 allocations. The client MUST only include family types it previously 1522 allocated and has not yet deleted. This process can also be used to 1523 delete an allocation of a specific address type, by setting the 1524 lifetime of that refresh request to 0. Deleting a single allocation 1525 destroys any permissions or channels associated with that particular 1526 allocation; it MUST NOT affect any permissions or channels associated 1527 with allocations for the other address family. 1529 The Refresh transaction updates the time-to-expiry timer of an 1530 allocation. If the client wishes the server to set the time-to- 1531 expiry timer to something other than the default lifetime, it 1532 includes a LIFETIME attribute with the requested value. The server 1533 then computes a new time-to-expiry value in the same way as it does 1534 for an Allocate transaction, with the exception that a requested 1535 lifetime of 0 causes the server to immediately delete the allocation. 1537 7.2. Receiving a Refresh Request 1539 When the server receives a Refresh request, it processes it as per 1540 Section 4 plus the specific rules mentioned here. 1542 If the server receives a Refresh Request with an ADDITIONAL-ADDRESS- 1543 FAMILY attribute and the attribute value does not match the address 1544 family of the allocation, the server MUST reply with a 443 (Peer 1545 Address Family Mismatch) Refresh error response. 1547 The server computes a value called the "desired lifetime" as follows: 1548 if the request contains a LIFETIME attribute and the attribute value 1549 is 0, then the "desired lifetime" is 0. Otherwise, if the request 1550 contains a LIFETIME attribute, then the server computes the minimum 1551 of the client's requested lifetime and the server's maximum allowed 1552 lifetime. If this computed value is greater than the default 1553 lifetime, then the "desired lifetime" is the computed value. 1554 Otherwise, the "desired lifetime" is the default lifetime. 1556 Subsequent processing depends on the "desired lifetime" value: 1558 o If the "desired lifetime" is 0, then the request succeeds and the 1559 allocation is deleted. 1561 o If the "desired lifetime" is non-zero, then the request succeeds 1562 and the allocation's time-to-expiry is set to the "desired 1563 lifetime". 1565 If the request succeeds, then the server sends a success response 1566 containing: 1568 o A LIFETIME attribute containing the current value of the time-to- 1569 expiry timer. 1571 NOTE: A server need not do anything special to implement 1572 idempotency of Refresh requests over UDP using the "stateless 1573 stack approach". Retransmitted Refresh requests with a non-zero 1574 "desired lifetime" will simply refresh the allocation. A 1575 retransmitted Refresh request with a zero "desired lifetime" will 1576 cause a 437 (Allocation Mismatch) response if the allocation has 1577 already been deleted, but the client will treat this as equivalent 1578 to a success response (see below). 1580 7.3. Receiving a Refresh Response 1582 If the client receives a success response to its Refresh request with 1583 a non-zero lifetime, it updates its copy of the allocation data 1584 structure with the time-to-expiry value contained in the response. 1586 If the client receives a 437 (Allocation Mismatch) error response to 1587 a request to delete the allocation, then the allocation no longer 1588 exists and it should consider its request as having effectively 1589 succeeded. 1591 8. Permissions 1593 For each allocation, the server keeps a list of zero or more 1594 permissions. Each permission consists of an IP address and an 1595 associated time-to-expiry. While a permission exists, all peers 1596 using the IP address in the permission are allowed to send data to 1597 the client. The time-to-expiry is the number of seconds until the 1598 permission expires. Within the context of an allocation, a 1599 permission is uniquely identified by its associated IP address. 1601 By sending either CreatePermission requests or ChannelBind requests, 1602 the client can cause the server to install or refresh a permission 1603 for a given IP address. This causes one of two things to happen: 1605 o If no permission for that IP address exists, then a permission is 1606 created with the given IP address and a time-to-expiry equal to 1607 Permission Lifetime. 1609 o If a permission for that IP address already exists, then the time- 1610 to-expiry for that permission is reset to Permission Lifetime. 1612 The Permission Lifetime MUST be 300 seconds (= 5 minutes). 1614 Each permission's time-to-expiry decreases down once per second until 1615 it reaches 0; at which point, the permission expires and is deleted. 1617 CreatePermission and ChannelBind requests may be freely intermixed on 1618 a permission. A given permission may be initially installed and/or 1619 refreshed with a CreatePermission request, and then later refreshed 1620 with a ChannelBind request, or vice versa. 1622 When a UDP datagram arrives at the relayed transport address for the 1623 allocation, the server extracts the source IP address from the IP 1624 header. The server then compares this address with the IP address 1625 associated with each permission in the list of permissions for the 1626 allocation. If no match is found, relaying is not permitted, and the 1627 server silently discards the UDP datagram. If an exact match is 1628 found, then the permission check is considered to have succeeded and 1629 the server continues to process the UDP datagram as specified 1630 elsewhere (Section 10.3). Note that only addresses are compared and 1631 port numbers are not considered. 1633 The permissions for one allocation are totally unrelated to the 1634 permissions for a different allocation. If an allocation expires, 1635 all its permissions expire with it. 1637 NOTE: Though TURN permissions expire after 5 minutes, many NATs 1638 deployed at the time of publication expire their UDP bindings 1639 considerably faster. Thus, an application using TURN will 1640 probably wish to send some sort of keep-alive traffic at a much 1641 faster rate. Applications using ICE should follow the keep-alive 1642 guidelines of ICE [RFC5245], and applications not using ICE are 1643 advised to do something similar. 1645 9. CreatePermission 1647 TURN supports two ways for the client to install or refresh 1648 permissions on the server. This section describes one way: the 1649 CreatePermission request. 1651 A CreatePermission request may be used in conjunction with either the 1652 Send mechanism in Section 10 or the Channel mechanism in Section 11. 1654 9.1. Forming a CreatePermission Request 1656 The client who wishes to install or refresh one or more permissions 1657 can send a CreatePermission request to the server. 1659 When forming a CreatePermission request, the client MUST include at 1660 least one XOR-PEER-ADDRESS attribute, and MAY include more than one 1661 such attribute. The IP address portion of each XOR-PEER-ADDRESS 1662 attribute contains the IP address for which a permission should be 1663 installed or refreshed. The port portion of each XOR-PEER-ADDRESS 1664 attribute will be ignored and can be any arbitrary value. The 1665 various XOR-PEER-ADDRESS attributes can appear in any order. The 1666 client MUST only include XOR-PEER-ADDRESS attributes with addresses 1667 of the same address family as that of the relayed transport address 1668 for the allocation. For dual allocations obtained using the 1669 ADDITIONAL-FAMILY-ADDRESS attribute, the client can include XOR-PEER- 1670 ADDRESS attributes with addresses of IPv4 and IPv6 address families. 1672 9.2. Receiving a CreatePermission Request 1674 When the server receives the CreatePermission request, it processes 1675 as per Section 4 plus the specific rules mentioned here. 1677 The message is checked for validity. The CreatePermission request 1678 MUST contain at least one XOR-PEER-ADDRESS attribute and MAY contain 1679 multiple such attributes. If no such attribute exists, or if any of 1680 these attributes are invalid, then a 400 (Bad Request) error is 1681 returned. If the request is valid, but the server is unable to 1682 satisfy the request due to some capacity limit or similar, then a 508 1683 (Insufficient Capacity) error is returned. 1685 If an XOR-PEER-ADDRESS attribute contains an address of an address 1686 family that is not the same as that of the relayed transport address 1687 for the allocation, the server MUST generate an error response with 1688 the 443 (Peer Address Family Mismatch) response code. 1690 The server MAY impose restrictions on the IP address allowed in the 1691 XOR-PEER-ADDRESS attribute -- if a value is not allowed, the server 1692 rejects the request with a 403 (Forbidden) error. 1694 If the message is valid and the server is capable of carrying out the 1695 request, then the server installs or refreshes a permission for the 1696 IP address contained in each XOR-PEER-ADDRESS attribute as described 1697 in Section 8. The port portion of each attribute is ignored and may 1698 be any arbitrary value. 1700 The server then responds with a CreatePermission success response. 1701 There are no mandatory attributes in the success response. 1703 NOTE: A server need not do anything special to implement 1704 idempotency of CreatePermission requests over UDP using the 1705 "stateless stack approach". Retransmitted CreatePermission 1706 requests will simply refresh the permissions. 1708 9.3. Receiving a CreatePermission Response 1710 If the client receives a valid CreatePermission success response, 1711 then the client updates its data structures to indicate that the 1712 permissions have been installed or refreshed. 1714 10. Send and Data Methods 1716 TURN supports two mechanisms for sending and receiving data from 1717 peers. This section describes the use of the Send and Data 1718 mechanisms, while Section 11 describes the use of the Channel 1719 mechanism. 1721 10.1. Forming a Send Indication 1723 The client can use a Send indication to pass data to the server for 1724 relaying to a peer. A client may use a Send indication even if a 1725 channel is bound to that peer. However, the client MUST ensure that 1726 there is a permission installed for the IP address of the peer to 1727 which the Send indication is being sent; this prevents a third party 1728 from using a TURN server to send data to arbitrary destinations. 1730 When forming a Send indication, the client MUST include an XOR-PEER- 1731 ADDRESS attribute and a DATA attribute. The XOR-PEER-ADDRESS 1732 attribute contains the transport address of the peer to which the 1733 data is to be sent, and the DATA attribute contains the actual 1734 application data to be sent to the peer. 1736 The client MAY include a DONT-FRAGMENT attribute in the Send 1737 indication if it wishes the server to set the DF bit on the UDP 1738 datagram sent to the peer. 1740 10.2. Receiving a Send Indication 1742 When the server receives a Send indication, it processes as per 1743 Section 4 plus the specific rules mentioned here. 1745 The message is first checked for validity. The Send indication MUST 1746 contain both an XOR-PEER-ADDRESS attribute and a DATA attribute. If 1747 one of these attributes is missing or invalid, then the message is 1748 discarded. Note that the DATA attribute is allowed to contain zero 1749 bytes of data. 1751 The Send indication may also contain the DONT-FRAGMENT attribute. If 1752 the server is unable to set the DF bit on outgoing UDP datagrams when 1753 this attribute is present, then the server acts as if the DONT- 1754 FRAGMENT attribute is an unknown comprehension-required attribute 1755 (and thus the Send indication is discarded). 1757 The server also checks that there is a permission installed for the 1758 IP address contained in the XOR-PEER-ADDRESS attribute. If no such 1759 permission exists, the message is discarded. Note that a Send 1760 indication never causes the server to refresh the permission. 1762 The server MAY impose restrictions on the IP address and port values 1763 allowed in the XOR-PEER-ADDRESS attribute -- if a value is not 1764 allowed, the server silently discards the Send indication. 1766 If everything is OK, then the server forms a UDP datagram as follows: 1768 o the source transport address is the relayed transport address of 1769 the allocation, where the allocation is determined by the 5-tuple 1770 on which the Send indication arrived; 1772 o the destination transport address is taken from the XOR-PEER- 1773 ADDRESS attribute; 1775 o the data following the UDP header is the contents of the value 1776 field of the DATA attribute. 1778 The handling of the DONT-FRAGMENT attribute (if present), is 1779 described in Section 13. 1781 The resulting UDP datagram is then sent to the peer. 1783 10.3. Receiving a UDP Datagram 1785 When the server receives a UDP datagram at a currently allocated 1786 relayed transport address, the server looks up the allocation 1787 associated with the relayed transport address. The server then 1788 checks to see whether the set of permissions for the allocation allow 1789 the relaying of the UDP datagram as described in Section 8. 1791 If relaying is permitted, then the server checks if there is a 1792 channel bound to the peer that sent the UDP datagram (see 1793 Section 11). If a channel is bound, then processing proceeds as 1794 described in Section 11.7. 1796 If relaying is permitted but no channel is bound to the peer, then 1797 the server forms and sends a Data indication. The Data indication 1798 MUST contain both an XOR-PEER-ADDRESS and a DATA attribute. The DATA 1799 attribute is set to the value of the 'data octets' field from the 1800 datagram, and the XOR-PEER-ADDRESS attribute is set to the source 1801 transport address of the received UDP datagram. The Data indication 1802 is then sent on the 5-tuple associated with the allocation. 1804 10.4. Receiving a Data Indication 1806 When the client receives a Data indication, it checks that the Data 1807 indication contains both an XOR-PEER-ADDRESS and a DATA attribute, 1808 and discards the indication if it does not. The client SHOULD also 1809 check that the XOR-PEER-ADDRESS attribute value contains an IP 1810 address with which the client believes there is an active permission, 1811 and discard the Data indication otherwise. Note that the DATA 1812 attribute is allowed to contain zero bytes of data. 1814 NOTE: The latter check protects the client against an attacker who 1815 somehow manages to trick the server into installing permissions 1816 not desired by the client. 1818 If the Data indication passes the above checks, the client delivers 1819 the data octets inside the DATA attribute to the application, along 1820 with an indication that they were received from the peer whose 1821 transport address is given by the XOR-PEER-ADDRESS attribute. 1823 11. Channels 1825 Channels provide a way for the client and server to send application 1826 data using ChannelData messages, which have less overhead than Send 1827 and Data indications. 1829 The ChannelData message (see Section 11.4) starts with a two-byte 1830 field that carries the channel number. The values of this field are 1831 allocated as follows: 1833 0x0000 through 0x3FFF: These values can never be used for channel 1834 numbers. 1836 0x4000 through 0x7FFF: These values are the allowed channel 1837 numbers (16,384 possible values). 1839 0x8000 through 0xFFFF: These values are reserved for future use. 1841 Because of this division, ChannelData messages can be distinguished 1842 from STUN-formatted messages (e.g., Allocate request, Send 1843 indication, etc.) by examining the first two bits of the message: 1845 0b00: STUN-formatted message (since the first two bits of a STUN- 1846 formatted message are always zero). 1848 0b01: ChannelData message (since the channel number is the first 1849 field in the ChannelData message and channel numbers fall in the 1850 range 0x4000 - 0x7FFF). 1852 0b10: Reserved 1854 0b11: Reserved 1856 The reserved values may be used in the future to extend the range of 1857 channel numbers. Thus, an implementation MUST NOT assume that a TURN 1858 message always starts with a 0 bit. 1860 Channel bindings are always initiated by the client. The client can 1861 bind a channel to a peer at any time during the lifetime of the 1862 allocation. The client may bind a channel to a peer before 1863 exchanging data with it, or after exchanging data with it (using Send 1864 and Data indications) for some time, or may choose never to bind a 1865 channel to it. The client can also bind channels to some peers while 1866 not binding channels to other peers. 1868 Channel bindings are specific to an allocation, so that the use of a 1869 channel number or peer transport address in a channel binding in one 1870 allocation has no impact on their use in a different allocation. If 1871 an allocation expires, all its channel bindings expire with it. 1873 A channel binding consists of: 1875 o a channel number; 1877 o a transport address (of the peer); and 1879 o A time-to-expiry timer. 1881 Within the context of an allocation, a channel binding is uniquely 1882 identified either by the channel number or by the peer's transport 1883 address. Thus, the same channel cannot be bound to two different 1884 transport addresses, nor can the same transport address be bound to 1885 two different channels. 1887 A channel binding lasts for 10 minutes unless refreshed. Refreshing 1888 the binding (by the server receiving a ChannelBind request rebinding 1889 the channel to the same peer) resets the time-to-expiry timer back to 1890 10 minutes. 1892 When the channel binding expires, the channel becomes unbound. Once 1893 unbound, the channel number can be bound to a different transport 1894 address, and the transport address can be bound to a different 1895 channel number. To prevent race conditions, the client MUST wait 5 1896 minutes after the channel binding expires before attempting to bind 1897 the channel number to a different transport address or the transport 1898 address to a different channel number. 1900 When binding a channel to a peer, the client SHOULD be prepared to 1901 receive ChannelData messages on the channel from the server as soon 1902 as it has sent the ChannelBind request. Over UDP, it is possible for 1903 the client to receive ChannelData messages from the server before it 1904 receives a ChannelBind success response. 1906 In the other direction, the client MAY elect to send ChannelData 1907 messages before receiving the ChannelBind success response. Doing 1908 so, however, runs the risk of having the ChannelData messages dropped 1909 by the server if the ChannelBind request does not succeed for some 1910 reason (e.g., packet lost if the request is sent over UDP, or the 1911 server being unable to fulfill the request). A client that wishes to 1912 be safe should either queue the data or use Send indications until 1913 the channel binding is confirmed. 1915 11.1. Sending a ChannelBind Request 1917 A channel binding is created or refreshed using a ChannelBind 1918 transaction. A ChannelBind transaction also creates or refreshes a 1919 permission towards the peer (see Section 8). 1921 To initiate the ChannelBind transaction, the client forms a 1922 ChannelBind request. The channel to be bound is specified in a 1923 CHANNEL-NUMBER attribute, and the peer's transport address is 1924 specified in an XOR-PEER-ADDRESS attribute. Section 11.2 describes 1925 the restrictions on these attributes. The client MUST only include 1926 an XOR-PEER-ADDRESS attribute with an address of the same address 1927 family as that of the relayed transport address for the allocation. 1928 For dual allocations obtained using the ADDITIONAL-FAMILY-ADDRESS 1929 attribute, the client can include XOR-PEER-ADDRESS attributes with 1930 addresses of IPv4 and IPv6 address families. When using dual 1931 allocation, the peer addresses of those channels may be of different 1932 families. Thus, a single 5-tuple session may create several IPv4 1933 channels and several IPv6 channels. 1935 Rebinding a channel to the same transport address that it is already 1936 bound to provides a way to refresh a channel binding and the 1937 corresponding permission without sending data to the peer. Note 1938 however, that permissions need to be refreshed more frequently than 1939 channels. 1941 11.2. Receiving a ChannelBind Request 1943 When the server receives a ChannelBind request, it processes as per 1944 Section 4 plus the specific rules mentioned here. 1946 The server checks the following: 1948 o The request contains both a CHANNEL-NUMBER and an XOR-PEER-ADDRESS 1949 attribute; 1951 o The channel number is in the range 0x4000 through 0x7FFE 1952 (inclusive); 1954 o The channel number is not currently bound to a different transport 1955 address (same transport address is OK); 1957 o The transport address is not currently bound to a different 1958 channel number. 1960 o If the XOR-PEER-ADDRESS attribute contains an address of an 1961 address family that is not the same as that of the relayed 1962 transport address for the allocation, the server MUST generate an 1963 error response with the 443 (Peer Address Family Mismatch) 1964 response code. 1966 If any of these tests fail, the server replies with a 400 (Bad 1967 Request) error. 1969 The server MAY impose restrictions on the IP address and port values 1970 allowed in the XOR-PEER-ADDRESS attribute -- if a value is not 1971 allowed, the server rejects the request with a 403 (Forbidden) error. 1973 If the request is valid, but the server is unable to fulfill the 1974 request due to some capacity limit or similar, the server replies 1975 with a 508 (Insufficient Capacity) error. 1977 Otherwise, the server replies with a ChannelBind success response. 1978 There are no required attributes in a successful ChannelBind 1979 response. 1981 If the server can satisfy the request, then the server creates or 1982 refreshes the channel binding using the channel number in the 1983 CHANNEL-NUMBER attribute and the transport address in the XOR-PEER- 1984 ADDRESS attribute. The server also installs or refreshes a 1985 permission for the IP address in the XOR-PEER-ADDRESS attribute as 1986 described in Section 8. 1988 NOTE: A server need not do anything special to implement 1989 idempotency of ChannelBind requests over UDP using the "stateless 1990 stack approach". Retransmitted ChannelBind requests will simply 1991 refresh the channel binding and the corresponding permission. 1992 Furthermore, the client must wait 5 minutes before binding a 1993 previously bound channel number or peer address to a different 1994 channel, eliminating the possibility that the transaction would 1995 initially fail but succeed on a retransmission. 1997 11.3. Receiving a ChannelBind Response 1999 When the client receives a ChannelBind success response, it updates 2000 its data structures to record that the channel binding is now active. 2001 It also updates its data structures to record that the corresponding 2002 permission has been installed or refreshed. 2004 If the client receives a ChannelBind failure response that indicates 2005 that the channel information is out-of-sync between the client and 2006 the server (e.g., an unexpected 400 "Bad Request" response), then it 2007 is RECOMMENDED that the client immediately delete the allocation and 2008 start afresh with a new allocation. 2010 11.4. The ChannelData Message 2012 The ChannelData message is used to carry application data between the 2013 client and the server. It has the following format: 2015 0 1 2 3 2016 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2017 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2018 | Channel Number | Length | 2019 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2020 | | 2021 / Application Data / 2022 / / 2023 | | 2024 | +-------------------------------+ 2025 | | 2026 +-------------------------------+ 2028 The Channel Number field specifies the number of the channel on which 2029 the data is traveling, and thus the address of the peer that is 2030 sending or is to receive the data. 2032 The Length field specifies the length in bytes of the application 2033 data field (i.e., it does not include the size of the ChannelData 2034 header). Note that 0 is a valid length. 2036 The Application Data field carries the data the client is trying to 2037 send to the peer, or that the peer is sending to the client. 2039 11.5. Sending a ChannelData Message 2041 Once a client has bound a channel to a peer, then when the client has 2042 data to send to that peer it may use either a ChannelData message or 2043 a Send indication; that is, the client is not obligated to use the 2044 channel when it exists and may freely intermix the two message types 2045 when sending data to the peer. The server, on the other hand, MUST 2046 use the ChannelData message if a channel has been bound to the peer. 2048 The fields of the ChannelData message are filled in as described in 2049 Section 11.4. 2051 Over TCP and TLS-over-TCP, the ChannelData message MUST be padded to 2052 a multiple of four bytes in order to ensure the alignment of 2053 subsequent messages. The padding is not reflected in the length 2054 field of the ChannelData message, so the actual size of a ChannelData 2055 message (including padding) is (4 + Length) rounded up to the nearest 2056 multiple of 4. Over UDP, the padding is not required but MAY be 2057 included. 2059 The ChannelData message is then sent on the 5-tuple associated with 2060 the allocation. 2062 11.6. Receiving a ChannelData Message 2064 The receiver of the ChannelData message uses the first two bits to 2065 distinguish it from STUN-formatted messages, as described above. If 2066 the message uses a value in the reserved range (0x8000 through 2067 0xFFFF), then the message is silently discarded. 2069 If the ChannelData message is received in a UDP datagram, and if the 2070 UDP datagram is too short to contain the claimed length of the 2071 ChannelData message (i.e., the UDP header length field value is less 2072 than the ChannelData header length field value + 4 + 8), then the 2073 message is silently discarded. 2075 If the ChannelData message is received over TCP or over TLS-over-TCP, 2076 then the actual length of the ChannelData message is as described in 2077 Section 11.5. 2079 If the ChannelData message is received on a channel that is not bound 2080 to any peer, then the message is silently discarded. 2082 On the client, it is RECOMMENDED that the client discard the 2083 ChannelData message if the client believes there is no active 2084 permission towards the peer. On the server, the receipt of a 2085 ChannelData message MUST NOT refresh either the channel binding or 2086 the permission towards the peer. 2088 On the server, if no errors are detected, the server relays the 2089 application data to the peer by forming a UDP datagram as follows: 2091 o the source transport address is the relayed transport address of 2092 the allocation, where the allocation is determined by the 5-tuple 2093 on which the ChannelData message arrived; 2095 o the destination transport address is the transport address to 2096 which the channel is bound; 2098 o the data following the UDP header is the contents of the data 2099 field of the ChannelData message. 2101 The resulting UDP datagram is then sent to the peer. Note that if 2102 the Length field in the ChannelData message is 0, then there will be 2103 no data in the UDP datagram, but the UDP datagram is still formed and 2104 sent. 2106 11.7. Relaying Data from the Peer 2108 When the server receives a UDP datagram on the relayed transport 2109 address associated with an allocation, the server processes it as 2110 described in Section 10.3. If that section indicates that a 2111 ChannelData message should be sent (because there is a channel bound 2112 to the peer that sent to the UDP datagram), then the server forms and 2113 sends a ChannelData message as described in Section 11.5. 2115 12. Packet Translations 2117 As discussed in Section 2.6, translations in TURN are designed so 2118 that a TURN server can be implemented as an application that runs in 2119 userland under commonly available operating systems and that does not 2120 require special privileges. The translations specified in the 2121 following sections follow this principle. 2123 The descriptions below have two parts: a preferred behavior and an 2124 alternate behavior. The server SHOULD implement the preferred 2125 behavior. Otherwise, the server MUST implement the alternate 2126 behavior and MUST NOT do anything else for the reasons detailed in 2127 [RFC6145]. 2129 12.1. IPv4-to-IPv6 Translations 2131 Traffic Class 2133 Preferred behavior: As specified in Section 4 of [RFC6145]. 2135 Alternate behavior: The relay sets the Traffic Class to the 2136 default value for outgoing packets. 2138 Flow Label 2139 Preferred behavior: The relay sets the Flow label to 0. The relay 2140 can choose to set the Flow label to a different value if it 2141 supports the IPv6 Flow Label field[RFC3697]. 2143 Alternate behavior: the relay sets the Flow label to the default 2144 value for outgoing packets. 2146 Hop Limit 2148 Preferred behavior: As specified in Section 4 of [RFC6145]. 2150 Alternate behavior: The relay sets the Hop Limit to the default 2151 value for outgoing packets. 2153 Fragmentation 2155 Preferred behavior: As specified in Section 4 of [RFC6145]. 2157 Alternate behavior: The relay assembles incoming fragments. The 2158 relay follows its default behavior to send outgoing packets. 2160 For both preferred and alternate behavior, the DONT-FRAGMENT 2161 attribute MUST be ignored by the server. 2163 Extension Headers 2165 Preferred behavior: The relay sends outgoing packet without any 2166 IPv6 extension headers, with the exception of the Fragmentation 2167 header as described above. 2169 Alternate behavior: Same as preferred. 2171 12.2. IPv6-to-IPv6 Translations 2173 Flow Label 2175 The relay should consider that it is handling two different IPv6 2176 flows. Therefore, the Flow label [RFC3697] SHOULD NOT be copied as 2177 part of the translation. 2179 Preferred behavior: The relay sets the Flow label to 0. The relay 2180 can choose to set the Flow label to a different value if it 2181 supports the IPv6 Flow Label field[RFC3697]. 2183 Alternate behavior: The relay sets the Flow label to the default 2184 value for outgoing packets. 2186 Hop Limit 2187 Preferred behavior: The relay acts as a regular router with 2188 respect to decrementing the Hop Limit and generating an ICMPv6 2189 error if it reaches zero. 2191 Alternate behavior: The relay sets the Hop Limit to the default 2192 value for outgoing packets. 2194 Fragmentation 2196 Preferred behavior: If the incoming packet did not include a 2197 Fragment header and the outgoing packet size does not exceed the 2198 outgoing link's MTU, the relay sends the outgoing packet without a 2199 Fragment header. 2201 If the incoming packet did not include a Fragment header and the 2202 outgoing packet size exceeds the outgoing link's MTU, the relay 2203 drops the outgoing packet and send an ICMP message of type 2 code 2204 0 ("Packet too big") to the sender of the incoming packet. If 2205 the packet is being sent to the peer, the relay reduces the MTU 2206 reported in the ICMP message by 48 bytes to allow room for the 2207 overhead of a Data indication. 2209 If the incoming packet included a Fragment header and the outgoing 2210 packet size (with a Fragment header included) does not exceed the 2211 outgoing link's MTU, the relay sends the outgoing packet with a 2212 Fragment header. The relay sets the fields of the Fragment header 2213 as appropriate for a packet originating from the server. 2215 If the incoming packet included a Fragment header and the outgoing 2216 packet size exceeds the outgoing link's MTU, the relay MUST 2217 fragment the outgoing packet into fragments of no more than 1280 2218 bytes. The relay sets the fields of the Fragment header as 2219 appropriate for a packet originating from the server. 2221 Alternate behavior: The relay assembles incoming fragments. The 2222 relay follows its default behavior to send outgoing packets. 2224 For both preferred and alternate behavior, the DONT-FRAGMENT 2225 attribute MUST be ignored by the server. 2227 Extension Headers 2229 Preferred behavior: The relay sends outgoing packet without any 2230 IPv6 extension headers, with the exception of the Fragmentation 2231 header as described above. 2233 Alternate behavior: Same as preferred. 2235 12.3. IPv6-to-IPv4 Translations 2237 Type of Service and Precedence 2239 Preferred behavior: As specified in Section 5 of [RFC6145]. 2241 Alternate behavior: The relay sets the Type of Service and 2242 Precedence to the default value for outgoing packets. 2244 Time to Live 2246 Preferred behavior: As specified in Section 5 of [RFC6145]. 2248 Alternate behavior: The relay sets the Time to Live to the default 2249 value for outgoing packets. 2251 Fragmentation 2253 Preferred behavior: As specified in Section 5 of [RFC6145]. 2254 Additionally, when the outgoing packet's size exceeds the 2255 outgoing link's MTU, the relay needs to generate an ICMP error 2256 (ICMPv6 Packet Too Big) reporting the MTU size. If the packet is 2257 being sent to the peer, the relay SHOULD reduce the MTU reported 2258 in the ICMP message by 48 bytes to allow room for the overhead of 2259 a Data indication. 2261 Alternate behavior: The relay assembles incoming fragments. The 2262 relay follows its default behavior to send outgoing packets. 2264 For both preferred and alternate behavior, the DONT-FRAGMENT 2265 attribute MUST be ignored by the server. 2267 13. IP Header Fields 2269 This section describes how the server sets various fields in the IP 2270 header when relaying between the client and the peer or vice versa. 2271 The descriptions in this section apply: (a) when the server sends a 2272 UDP datagram to the peer, or (b) when the server sends a Data 2273 indication or ChannelData message to the client over UDP transport. 2274 The descriptions in this section do not apply to TURN messages sent 2275 over TCP or TLS transport from the server to the client. 2277 The descriptions below have two parts: a preferred behavior and an 2278 alternate behavior. The server SHOULD implement the preferred 2279 behavior, but if that is not possible for a particular field, then it 2280 SHOULD implement the alternative behavior. 2282 Time to Live (TTL) field 2283 Preferred Behavior: If the incoming value is 0, then the drop the 2284 incoming packet. Otherwise, set the outgoing Time to Live/Hop 2285 Count to one less than the incoming value. 2287 Alternate Behavior: Set the outgoing value to the default for 2288 outgoing packets. 2290 Differentiated Services Code Point (DSCP) field [RFC2474] 2292 Preferred Behavior: Set the outgoing value to the incoming value, 2293 unless the server includes a differentiated services classifier 2294 and marker [RFC2474]. 2296 Alternate Behavior: Set the outgoing value to a fixed value, which 2297 by default is Best Effort unless configured otherwise. 2299 In both cases, if the server is immediately adjacent to a 2300 differentiated services classifier and marker, then DSCP MAY be 2301 set to any arbitrary value in the direction towards the 2302 classifier. 2304 Explicit Congestion Notification (ECN) field [RFC3168] 2306 Preferred Behavior: Set the outgoing value to the incoming value, 2307 UNLESS the server is doing Active Queue Management, the incoming 2308 ECN field is ECT(1) (=0b01) or ECT(0) (=0b10), and the server 2309 wishes to indicate that congestion has been experienced, in which 2310 case set the outgoing value to CE (=0b11). 2312 Alternate Behavior: Set the outgoing value to Not-ECT (=0b00). 2314 IPv4 Fragmentation fields 2316 Preferred Behavior: When the server sends a packet to a peer in 2317 response to a Send indication containing the DONT-FRAGMENT 2318 attribute, then set the DF bit in the outgoing IP header to 1. In 2319 all other cases when sending an outgoing packet containing 2320 application data (e.g., Data indication, ChannelData message, or 2321 DONT-FRAGMENT attribute not included in the Send indication), copy 2322 the DF bit from the DF bit of the incoming packet that contained 2323 the application data. 2325 Set the other fragmentation fields (Identification, More 2326 Fragments, Fragment Offset) as appropriate for a packet 2327 originating from the server. 2329 Alternate Behavior: As described in the Preferred Behavior, except 2330 always assume the incoming DF bit is 0. 2332 In both the Preferred and Alternate Behaviors, the resulting 2333 packet may be too large for the outgoing link. If this is the 2334 case, then the normal fragmentation rules apply [RFC1122]. 2336 IPv4 Options 2338 Preferred Behavior: The outgoing packet is sent without any IPv4 2339 options. 2341 Alternate Behavior: Same as preferred. 2343 14. New STUN Methods 2345 This section lists the codepoints for the new STUN methods defined in 2346 this specification. See elsewhere in this document for the semantics 2347 of these new methods. 2349 0x003 : Allocate (only request/response semantics defined) 2350 0x004 : Refresh (only request/response semantics defined) 2351 0x006 : Send (only indication semantics defined) 2352 0x007 : Data (only indication semantics defined) 2353 0x008 : CreatePermission (only request/response semantics defined 2354 0x009 : ChannelBind (only request/response semantics defined) 2356 15. New STUN Attributes 2358 This STUN extension defines the following new attributes: 2360 0x000C: CHANNEL-NUMBER 2361 0x000D: LIFETIME 2362 0x0010: Reserved (was BANDWIDTH) 2363 0x0012: XOR-PEER-ADDRESS 2364 0x0013: DATA 2365 0x0016: XOR-RELAYED-ADDRESS 2366 0x0017: REQUESTED-ADDRESS-FAMILY 2367 0x0018: EVEN-PORT 2368 0x0019: REQUESTED-TRANSPORT 2369 0x001A: DONT-FRAGMENT 2370 0x0021: Reserved (was TIMER-VAL) 2371 0x0022: RESERVATION-TOKEN 2372 TBD-CA: ADDITIONAL-ADDRESS-FAMILY 2373 TBD-CA: ADDRESS-ERROR-CODE 2375 Some of these attributes have lengths that are not multiples of 4. 2376 By the rules of STUN, any attribute whose length is not a multiple of 2377 4 bytes MUST be immediately followed by 1 to 3 padding bytes to 2378 ensure the next attribute (if any) would start on a 4-byte boundary 2379 (see [RFC5389]). 2381 15.1. CHANNEL-NUMBER 2383 The CHANNEL-NUMBER attribute contains the number of the channel. The 2384 value portion of this attribute is 4 bytes long and consists of a 2385 16-bit unsigned integer, followed by a two-octet RFFU (Reserved For 2386 Future Use) field, which MUST be set to 0 on transmission and MUST be 2387 ignored on reception. 2389 0 1 2 3 2390 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2391 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2392 | Channel Number | RFFU = 0 | 2393 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2395 15.2. LIFETIME 2397 The LIFETIME attribute represents the duration for which the server 2398 will maintain an allocation in the absence of a refresh. The value 2399 portion of this attribute is 4-bytes long and consists of a 32-bit 2400 unsigned integral value representing the number of seconds remaining 2401 until expiration. 2403 15.3. XOR-PEER-ADDRESS 2405 The XOR-PEER-ADDRESS specifies the address and port of the peer as 2406 seen from the TURN server. (For example, the peer's server-reflexive 2407 transport address if the peer is behind a NAT.) It is encoded in the 2408 same way as XOR-MAPPED-ADDRESS [RFC5389]. 2410 15.4. DATA 2412 The DATA attribute is present in all Send and Data indications. The 2413 value portion of this attribute is variable length and consists of 2414 the application data (that is, the data that would immediately follow 2415 the UDP header if the data was been sent directly between the client 2416 and the peer). If the length of this attribute is not a multiple of 2417 4, then padding must be added after this attribute. 2419 15.5. XOR-RELAYED-ADDRESS 2421 The XOR-RELAYED-ADDRESS is present in Allocate responses. It 2422 specifies the address and port that the server allocated to the 2423 client. It is encoded in the same way as XOR-MAPPED-ADDRESS 2424 [RFC5389]. 2426 15.6. REQUESTED-ADDRESS-FAMILY 2428 This attribute is used by clients to request the allocation of a 2429 specific address type from a server. The following is the format of 2430 the REQUESTED-ADDRESS-FAMILY attribute. Note that TURN attributes 2431 are TLV (Type-Length-Value) encoded, with a 16-bit type, a 16-bit 2432 length, and a variable-length value. 2434 0 1 2 3 2435 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2436 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2437 | Type | Length | 2438 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2439 | Family | Reserved | 2440 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2442 Type: the type of the REQUESTED-ADDRESS-FAMILY attribute is 0x0017. 2443 As specified in [RFC5389], attributes with values between 0x0000 2444 and 0x7FFF are comprehension-required, which means that the client 2445 or server cannot successfully process the message unless it 2446 understands the attribute. 2448 Length: this 16-bit field contains the length of the attribute in 2449 bytes. The length of this attribute is 4 bytes. 2451 Family: there are two values defined for this field and specified in 2452 [RFC5389], Section 15.1: 0x01 for IPv4 addresses and 0x02 for IPv6 2453 addresses. 2455 Reserved: at this point, the 24 bits in the Reserved field MUST be 2456 set to zero by the client and MUST be ignored by the server. 2458 The REQUEST-ADDRESS-TYPE attribute MAY only be present in Allocate 2459 requests. 2461 15.7. EVEN-PORT 2463 This attribute allows the client to request that the port in the 2464 relayed transport address be even, and (optionally) that the server 2465 reserve the next-higher port number. The value portion of this 2466 attribute is 1 byte long. Its format is: 2468 0 2469 0 1 2 3 4 5 6 7 2470 +-+-+-+-+-+-+-+-+ 2471 |R| RFFU | 2472 +-+-+-+-+-+-+-+-+ 2474 The value contains a single 1-bit flag: 2476 R: If 1, the server is requested to reserve the next-higher port 2477 number (on the same IP address) for a subsequent allocation. If 2478 0, no such reservation is requested. 2480 The other 7 bits of the attribute's value must be set to zero on 2481 transmission and ignored on reception. 2483 Since the length of this attribute is not a multiple of 4, padding 2484 must immediately follow this attribute. 2486 15.8. REQUESTED-TRANSPORT 2488 This attribute is used by the client to request a specific transport 2489 protocol for the allocated transport address. The value of this 2490 attribute is 4 bytes with the following format: 2492 0 1 2 3 2493 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2494 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2495 | Protocol | RFFU | 2496 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2498 The Protocol field specifies the desired protocol. The codepoints 2499 used in this field are taken from those allowed in the Protocol field 2500 in the IPv4 header and the NextHeader field in the IPv6 header 2501 [Protocol-Numbers]. This specification only allows the use of 2502 codepoint 17 (User Datagram Protocol). 2504 The RFFU field MUST be set to zero on transmission and MUST be 2505 ignored on reception. It is reserved for future uses. 2507 15.9. DONT-FRAGMENT 2509 This attribute is used by the client to request that the server set 2510 the DF (Don't Fragment) bit in the IP header when relaying the 2511 application data onward to the peer. This attribute has no value 2512 part and thus the attribute length field is 0. 2514 15.10. RESERVATION-TOKEN 2516 The RESERVATION-TOKEN attribute contains a token that uniquely 2517 identifies a relayed transport address being held in reserve by the 2518 server. The server includes this attribute in a success response to 2519 tell the client about the token, and the client includes this 2520 attribute in a subsequent Allocate request to request the server use 2521 that relayed transport address for the allocation. 2523 The attribute value is 8 bytes and contains the token value. 2525 15.11. ADDITIONAL-ADDRESS-FAMILY 2527 This attribute is used by clients to request the allocation of a IPv4 2528 and IPv6 address type from a server. The following is the format of 2529 the ADDITIONAL-ADDRESS-FAMILY attribute. 2531 0 1 2 3 2532 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2533 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2534 | Type | Length | 2535 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2536 | Family | Reserved | 2537 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2539 Type: the type of the ADDITIONAL-ADDRESS-FAMILY attribute is TBD-CA. 2540 As specified in [RFC5389], attributes with values between 0x8000 2541 and 0xFFFF are comprehension-optional, which means that the client 2542 or server can safely ignore the attribute if they don't understand 2543 it. 2545 Length: this 16-bit field contains the length of the attribute in 2546 bytes. The length of this attribute is 4 bytes. 2548 Family: there are two values defined for this field and specified in 2549 [RFC5389], Section 15.1: 0x01 for IPv4 addresses and 0x02 for IPv6 2550 addresses. 2552 Reserved: at this point, the 24 bits in the Reserved field MUST be 2553 set to zero by the client and MUST be ignored by the server. 2555 The ADDITIONAL-ADDRESS-FAMILY attribute MAY be present in Allocate or 2556 Refresh requests. The attribute value of 0x02 (IPv6 address) is the 2557 only valid value in Allocate request. 2559 15.12. ADDRESS-ERROR-CODE Attribute 2561 This attribute is used by servers to signal the reason for not 2562 allocating the requested address family. The following is the format 2563 of the ADDRESS-ERROR-CODE attribute. 2565 0 1 2 3 2566 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2567 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2568 | Type | Length | 2569 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2570 | Family | Error code | Reserved | 2571 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2573 Type: the type of the ADDRESS-ERROR-CODE attribute is TBD-CA. As 2574 specified in [RFC5389], attributes with values between 0x8000 and 2575 0xFFFF are comprehension-optional, which means that the client or 2576 server can safely ignore the attribute if they don't understand 2577 it. 2579 Length: this 16-bit field contains the length of the attribute in 2580 bytes. The length of this attribute is 4 bytes. 2582 Family: there are two values defined for this field and specified in 2583 [RFC5389], Section 15.1: 0x01 for IPv4 addresses and 0x02 for IPv6 2584 addresses. 2586 Error code: this 8-bit field contains the reason server cannot 2587 allocate one of the requested address types. The error code 2588 values could be either 440 (unsupported address family) or 508 2589 (insufficient capacity). 2591 Reserved: at this point, the 16 bits in the Reserved field MUST be 2592 set to zero by the client and MUST be ignored by the server. 2594 The ADDRESS-ERROR-CODE attribute MAY only be present in Allocate 2595 responses. 2597 16. New STUN Error Response Codes 2599 This document defines the following new error response codes: 2601 403 (Forbidden): The request was valid but cannot be performed due 2602 to administrative or similar restrictions. 2604 437 (Allocation Mismatch): A request was received by the server that 2605 requires an allocation to be in place, but no allocation exists, 2606 or a request was received that requires no allocation, but an 2607 allocation exists. 2609 440 (Address Family not Supported): The server does not support the 2610 address family requested by the client. 2612 441 (Wrong Credentials): The credentials in the (non-Allocate) 2613 request do not match those used to create the allocation. 2615 442 (Unsupported Transport Protocol): The Allocate request asked the 2616 server to use a transport protocol between the server and the peer 2617 that the server does not support. NOTE: This does NOT refer to 2618 the transport protocol used in the 5-tuple. 2620 443 (Peer Address Family Mismatch). A peer address is part of a 2621 different address family than that of the relayed transport 2622 address of the allocation. 2624 486 (Allocation Quota Reached): No more allocations using this 2625 username can be created at the present time. 2627 508 (Insufficient Capacity): The server is unable to carry out the 2628 request due to some capacity limit being reached. In an Allocate 2629 response, this could be due to the server having no more relayed 2630 transport addresses available at that time, having none with the 2631 requested properties, or the one that corresponds to the specified 2632 reservation token is not available. 2634 17. Detailed Example 2636 This section gives an example of the use of TURN, showing in detail 2637 the contents of the messages exchanged. The example uses the network 2638 diagram shown in the Overview (Figure 1). 2640 For each message, the attributes included in the message and their 2641 values are shown. For convenience, values are shown in a human- 2642 readable format rather than showing the actual octets; for example, 2643 "XOR-RELAYED-ADDRESS=192.0.2.15:9000" shows that the XOR-RELAYED- 2644 ADDRESS attribute is included with an address of 192.0.2.15 and a 2645 port of 9000, here the address and port are shown before the xor-ing 2646 is done. For attributes with string-like values (e.g., 2647 SOFTWARE="Example client, version 1.03" and 2648 NONCE="adl7W7PeDU4hKE72jdaQvbAMcr6h39sm"), the value of the attribute 2649 is shown in quotes for readability, but these quotes do not appear in 2650 the actual value. 2652 TURN TURN Peer Peer 2653 client server A B 2654 | | | | 2655 |--- Allocate request -------------->| | | 2656 | Transaction-Id=0xA56250D3F17ABE679422DE85 | | 2657 | SOFTWARE="Example client, version 1.03" | | 2658 | LIFETIME=3600 (1 hour) | | | 2659 | REQUESTED-TRANSPORT=17 (UDP) | | | 2660 | DONT-FRAGMENT | | | 2661 | | | | 2662 |<-- Allocate error response --------| | | 2663 | Transaction-Id=0xA56250D3F17ABE679422DE85 | | 2664 | SOFTWARE="Example server, version 1.17" | | 2665 | ERROR-CODE=401 (Unauthorized) | | | 2666 | REALM="example.com" | | | 2667 | NONCE="adl7W7PeDU4hKE72jdaQvbAMcr6h39sm" | | 2668 | | | | 2669 |--- Allocate request -------------->| | | 2670 | Transaction-Id=0xC271E932AD7446A32C234492 | | 2671 | SOFTWARE="Example client 1.03" | | | 2672 | LIFETIME=3600 (1 hour) | | | 2673 | REQUESTED-TRANSPORT=17 (UDP) | | | 2674 | DONT-FRAGMENT | | | 2675 | USERNAME="George" | | | 2676 | REALM="example.com" | | | 2677 | NONCE="adl7W7PeDU4hKE72jdaQvbAMcr6h39sm" | | 2678 | MESSAGE-INTEGRITY=... | | | 2679 | | | | 2680 |<-- Allocate success response ------| | | 2681 | Transaction-Id=0xC271E932AD7446A32C234492 | | 2682 | SOFTWARE="Example server, version 1.17" | | 2683 | LIFETIME=1200 (20 minutes) | | | 2684 | XOR-RELAYED-ADDRESS=192.0.2.15:50000 | | 2685 | XOR-MAPPED-ADDRESS=192.0.2.1:7000 | | 2686 | MESSAGE-INTEGRITY=... | | | 2688 The client begins by selecting a host transport address to use for 2689 the TURN session; in this example, the client has selected 2690 10.1.1.2:49721 as shown in Figure 1. The client then sends an 2691 Allocate request to the server at the server transport address. The 2692 client randomly selects a 96-bit transaction id of 2693 0xA56250D3F17ABE679422DE85 for this transaction; this is encoded in 2694 the transaction id field in the fixed header. The client includes a 2695 SOFTWARE attribute that gives information about the client's 2696 software; here the value is "Example client, version 1.03" to 2697 indicate that this is version 1.03 of something called the Example 2698 client. The client includes the LIFETIME attribute because it wishes 2699 the allocation to have a longer lifetime than the default of 10 2700 minutes; the value of this attribute is 3600 seconds, which 2701 corresponds to 1 hour. The client must always include a REQUESTED- 2702 TRANSPORT attribute in an Allocate request and the only value allowed 2703 by this specification is 17, which indicates UDP transport between 2704 the server and the peers. The client also includes the DONT-FRAGMENT 2705 attribute because it wishes to use the DONT-FRAGMENT attribute later 2706 in Send indications; this attribute consists of only an attribute 2707 header, there is no value part. We assume the client has not 2708 recently interacted with the server, thus the client does not include 2709 USERNAME, REALM, NONCE, or MESSAGE-INTEGRITY attribute. Finally, 2710 note that the order of attributes in a message is arbitrary (except 2711 for the MESSAGE-INTEGRITY and FINGERPRINT attributes) and the client 2712 could have used a different order. 2714 Servers require any request to be authenticated. Thus, when the 2715 server receives the initial Allocate request, it rejects the request 2716 because the request does not contain the authentication attributes. 2717 Following the procedures of the long-term credential mechanism of 2718 STUN [RFC5389], the server includes an ERROR-CODE attribute with a 2719 value of 401 (Unauthorized), a REALM attribute that specifies the 2720 authentication realm used by the server (in this case, the server's 2721 domain "example.com"), and a nonce value in a NONCE attribute. The 2722 server also includes a SOFTWARE attribute that gives information 2723 about the server's software. 2725 The client, upon receipt of the 401 error, re-attempts the Allocate 2726 request, this time including the authentication attributes. The 2727 client selects a new transaction id, and then populates the new 2728 Allocate request with the same attributes as before. The client 2729 includes a USERNAME attribute and uses the realm value received from 2730 the server to help it determine which value to use; here the client 2731 is configured to use the username "George" for the realm 2732 "example.com". The client also includes the REALM and NONCE 2733 attributes, which are just copied from the 401 error response. 2734 Finally, the client includes a MESSAGE-INTEGRITY attribute as the 2735 last attribute in the message, whose value is a Hashed Message 2736 Authentication Code - Secure Hash Algorithm 1 (HMAC-SHA1) hash over 2737 the contents of the message (shown as just "..." above); this HMAC- 2738 SHA1 computation includes a password value. Thus, an attacker cannot 2739 compute the message integrity value without somehow knowing the 2740 secret password. 2742 The server, upon receipt of the authenticated Allocate request, 2743 checks that everything is OK, then creates an allocation. The server 2744 replies with an Allocate success response. The server includes a 2745 LIFETIME attribute giving the lifetime of the allocation; here, the 2746 server has reduced the client's requested 1-hour lifetime to just 20 2747 minutes, because this particular server doesn't allow lifetimes 2748 longer than 20 minutes. The server includes an XOR-RELAYED-ADDRESS 2749 attribute whose value is the relayed transport address of the 2750 allocation. The server includes an XOR-MAPPED-ADDRESS attribute 2751 whose value is the server-reflexive address of the client; this value 2752 is not used otherwise in TURN but is returned as a convenience to the 2753 client. The server includes a MESSAGE-INTEGRITY attribute to 2754 authenticate the response and to ensure its integrity; note that the 2755 response does not contain the USERNAME, REALM, and NONCE attributes. 2756 The server also includes a SOFTWARE attribute. 2758 TURN TURN Peer Peer 2759 client server A B 2760 |--- CreatePermission request ------>| | | 2761 | Transaction-Id=0xE5913A8F460956CA277D3319 | | 2762 | XOR-PEER-ADDRESS=192.0.2.150:0 | | | 2763 | USERNAME="George" | | | 2764 | REALM="example.com" | | | 2765 | NONCE="adl7W7PeDU4hKE72jdaQvbAMcr6h39sm" | | 2766 | MESSAGE-INTEGRITY=... | | | 2767 | | | | 2768 |<-- CreatePermission success resp.--| | | 2769 | Transaction-Id=0xE5913A8F460956CA277D3319 | | 2770 | MESSAGE-INTEGRITY=... | | | 2772 The client then creates a permission towards Peer A in preparation 2773 for sending it some application data. This is done through a 2774 CreatePermission request. The XOR-PEER-ADDRESS attribute contains 2775 the IP address for which a permission is established (the IP address 2776 of peer A); note that the port number in the attribute is ignored 2777 when used in a CreatePermission request, and here it has been set to 2778 0; also, note how the client uses Peer A's server-reflexive IP 2779 address and not its (private) host address. The client uses the same 2780 username, realm, and nonce values as in the previous request on the 2781 allocation. Though it is allowed to do so, the client has chosen not 2782 to include a SOFTWARE attribute in this request. 2784 The server receives the CreatePermission request, creates the 2785 corresponding permission, and then replies with a CreatePermission 2786 success response. Like the client, the server chooses not to include 2787 the SOFTWARE attribute in its reply. Again, note how success 2788 responses contain a MESSAGE-INTEGRITY attribute (assuming the server 2789 uses the long-term credential mechanism), but no USERNAME, REALM, and 2790 NONCE attributes. 2792 TURN TURN Peer Peer 2793 client server A B 2794 |--- Send indication --------------->| | | 2795 | Transaction-Id=0x1278E9ACA2711637EF7D3328 | | 2796 | XOR-PEER-ADDRESS=192.0.2.150:32102 | | 2797 | DONT-FRAGMENT | | | 2798 | DATA=... | | | 2799 | |-- UDP dgm ->| | 2800 | | data=... | | 2801 | | | | 2802 | |<- UDP dgm --| | 2803 | | data=... | | 2804 |<-- Data indication ----------------| | | 2805 | Transaction-Id=0x8231AE8F9242DA9FF287FEFF | | 2806 | XOR-PEER-ADDRESS=192.0.2.150:32102 | | 2807 | DATA=... | | | 2809 The client now sends application data to Peer A using a Send 2810 indication. Peer A's server-reflexive transport address is specified 2811 in the XOR-PEER-ADDRESS attribute, and the application data (shown 2812 here as just "...") is specified in the DATA attribute. The client 2813 is doing a form of path MTU discovery at the application layer and 2814 thus specifies (by including the DONT-FRAGMENT attribute) that the 2815 server should set the DF bit in the UDP datagram to send to the peer. 2816 Indications cannot be authenticated using the long-term credential 2817 mechanism of STUN, so no MESSAGE-INTEGRITY attribute is included in 2818 the message. An application wishing to ensure that its data is not 2819 altered or forged must integrity-protect its data at the application 2820 level. 2822 Upon receipt of the Send indication, the server extracts the 2823 application data and sends it in a UDP datagram to Peer A, with the 2824 relayed transport address as the source transport address of the 2825 datagram, and with the DF bit set as requested. Note that, had the 2826 client not previously established a permission for Peer A's server- 2827 reflexive IP address, then the server would have silently discarded 2828 the Send indication instead. 2830 Peer A then replies with its own UDP datagram containing application 2831 data. The datagram is sent to the relayed transport address on the 2832 server. When this arrives, the server creates a Data indication 2833 containing the source of the UDP datagram in the XOR-PEER-ADDRESS 2834 attribute, and the data from the UDP datagram in the DATA attribute. 2835 The resulting Data indication is then sent to the client. 2837 TURN TURN Peer Peer 2838 client server A B 2839 |--- ChannelBind request ----------->| | | 2840 | Transaction-Id=0x6490D3BC175AFF3D84513212 | | 2841 | CHANNEL-NUMBER=0x4000 | | | 2842 | XOR-PEER-ADDRESS=192.0.2.210:49191 | | 2843 | USERNAME="George" | | | 2844 | REALM="example.com" | | | 2845 | NONCE="adl7W7PeDU4hKE72jdaQvbAMcr6h39sm" | | 2846 | MESSAGE-INTEGRITY=... | | | 2847 | | | | 2848 |<-- ChannelBind success response ---| | | 2849 | Transaction-Id=0x6490D3BC175AFF3D84513212 | | 2850 | MESSAGE-INTEGRITY=... | | | 2852 The client now binds a channel to Peer B, specifying a free channel 2853 number (0x4000) in the CHANNEL-NUMBER attribute, and Peer B's 2854 transport address in the XOR-PEER-ADDRESS attribute. As before, the 2855 client re-uses the username, realm, and nonce from its last request 2856 in the message. 2858 Upon receipt of the request, the server binds the channel number to 2859 the peer, installs a permission for Peer B's IP address, and then 2860 replies with ChannelBind success response. 2862 TURN TURN Peer Peer 2863 client server A B 2864 |--- ChannelData ------------------->| | | 2865 | Channel-number=0x4000 |--- UDP datagram --------->| 2866 | Data=... | Data=... | 2867 | | | | 2868 | |<-- UDP datagram ----------| 2869 | | Data=... | | 2870 |<-- ChannelData --------------------| | | 2871 | Channel-number=0x4000 | | | 2872 | Data=... | | | 2874 The client now sends a ChannelData message to the server with data 2875 destined for Peer B. The ChannelData message is not a STUN message, 2876 and thus has no transaction id. Instead, it has only three fields: a 2877 channel number, data, and data length; here the channel number field 2878 is 0x4000 (the channel the client just bound to Peer B). When the 2879 server receives the ChannelData message, it checks that the channel 2880 is currently bound (which it is) and then sends the data onward to 2881 Peer B in a UDP datagram, using the relayed transport address as the 2882 source transport address and 192.0.2.210:49191 (the value of the XOR- 2883 PEER-ADDRESS attribute in the ChannelBind request) as the destination 2884 transport address. 2886 Later, Peer B sends a UDP datagram back to the relayed transport 2887 address. This causes the server to send a ChannelData message to the 2888 client containing the data from the UDP datagram. The server knows 2889 to which client to send the ChannelData message because of the 2890 relayed transport address at which the UDP datagram arrived, and 2891 knows to use channel 0x4000 because this is the channel bound to 2892 192.0.2.210:49191. Note that if there had not been any channel 2893 number bound to that address, the server would have used a Data 2894 indication instead. 2896 TURN TURN Peer Peer 2897 client server A B 2898 |--- Refresh request --------------->| | | 2899 | Transaction-Id=0x0864B3C27ADE9354B4312414 | | 2900 | SOFTWARE="Example client 1.03" | | | 2901 | USERNAME="George" | | | 2902 | REALM="example.com" | | | 2903 | NONCE="adl7W7PeDU4hKE72jdaQvbAMcr6h39sm" | | 2904 | MESSAGE-INTEGRITY=... | | | 2905 | | | | 2906 |<-- Refresh error response ---------| | | 2907 | Transaction-Id=0x0864B3C27ADE9354B4312414 | | 2908 | SOFTWARE="Example server, version 1.17" | | 2909 | ERROR-CODE=438 (Stale Nonce) | | | 2910 | REALM="example.com" | | | 2911 | NONCE="npSw1Xw239bBwGYhjNWgz2yH47sxB2j" | | 2912 | | | | 2913 |--- Refresh request --------------->| | | 2914 | Transaction-Id=0x427BD3E625A85FC731DC4191 | | 2915 | SOFTWARE="Example client 1.03" | | | 2916 | USERNAME="George" | | | 2917 | REALM="example.com" | | | 2918 | NONCE="npSw1Xw239bBwGYhjNWgz2yH47sxB2j" | | 2919 | MESSAGE-INTEGRITY=... | | | 2920 | | | | 2921 |<-- Refresh success response -------| | | 2922 | Transaction-Id=0x427BD3E625A85FC731DC4191 | | 2923 | SOFTWARE="Example server, version 1.17" | | 2924 | LIFETIME=600 (10 minutes) | | | 2926 Sometime before the 20 minute lifetime is up, the client refreshes 2927 the allocation. This is done using a Refresh request. As before, 2928 the client includes the latest username, realm, and nonce values in 2929 the request. The client also includes the SOFTWARE attribute, 2930 following the recommended practice of always including this attribute 2931 in Allocate and Refresh messages. When the server receives the 2932 Refresh request, it notices that the nonce value has expired, and so 2933 replies with 438 (Stale Nonce) error given a new nonce value. The 2934 client then reattempts the request, this time with the new nonce 2935 value. This second attempt is accepted, and the server replies with 2936 a success response. Note that the client did not include a LIFETIME 2937 attribute in the request, so the server refreshes the allocation for 2938 the default lifetime of 10 minutes (as can be seen by the LIFETIME 2939 attribute in the success response). 2941 18. Security Considerations 2943 This section considers attacks that are possible in a TURN 2944 deployment, and discusses how they are mitigated by mechanisms in the 2945 protocol or recommended practices in the implementation. 2947 Most of the attacks on TURN are mitigated by the server requiring 2948 requests be authenticated. Thus, this specification requires the use 2949 of authentication. The mandatory-to-implement mechanism is the long- 2950 term credential mechanism of STUN. Other authentication mechanisms 2951 of equal or stronger security properties may be used. However, it is 2952 important to ensure that they can be invoked in an inter-operable 2953 way. 2955 18.1. Outsider Attacks 2957 Outsider attacks are ones where the attacker has no credentials in 2958 the system, and is attempting to disrupt the service seen by the 2959 client or the server. 2961 18.1.1. Obtaining Unauthorized Allocations 2963 An attacker might wish to obtain allocations on a TURN server for any 2964 number of nefarious purposes. A TURN server provides a mechanism for 2965 sending and receiving packets while cloaking the actual IP address of 2966 the client. This makes TURN servers an attractive target for 2967 attackers who wish to use it to mask their true identity. 2969 An attacker might also wish to simply utilize the services of a TURN 2970 server without paying for them. Since TURN services require 2971 resources from the provider, it is anticipated that their usage will 2972 come with a cost. 2974 These attacks are prevented using the long-term credential mechanism, 2975 which allows the TURN server to determine the identity of the 2976 requestor and whether the requestor is allowed to obtain the 2977 allocation. 2979 18.1.2. Offline Dictionary Attacks 2981 The long-term credential mechanism used by TURN is subject to offline 2982 dictionary attacks. An attacker that is capable of eavesdropping on 2983 a message exchange between a client and server can determine the 2984 password by trying a number of candidate passwords and seeing if one 2985 of them is correct. This attack works when the passwords are low 2986 entropy, such as a word from the dictionary. This attack can be 2987 mitigated by using strong passwords with large entropy. In 2988 situations where even stronger mitigation is required, (D)TLS 2989 transport between the client and the server can be used. 2991 18.1.3. Faked Refreshes and Permissions 2993 An attacker might wish to attack an active allocation by sending it a 2994 Refresh request with an immediate expiration, in order to delete it 2995 and disrupt service to the client. This is prevented by 2996 authentication of refreshes. Similarly, an attacker wishing to send 2997 CreatePermission requests to create permissions to undesirable 2998 destinations is prevented from doing so through authentication. The 2999 motivations for such an attack are described in Section 18.2. 3001 18.1.4. Fake Data 3003 An attacker might wish to send data to the client or the peer, as if 3004 they came from the peer or client, respectively. To do that, the 3005 attacker can send the client a faked Data Indication or ChannelData 3006 message, or send the TURN server a faked Send Indication or 3007 ChannelData message. 3009 Since indications and ChannelData messages are not authenticated, 3010 this attack is not prevented by TURN. However, this attack is 3011 generally present in IP-based communications and is not substantially 3012 worsened by TURN. Consider a normal, non-TURN IP session between 3013 hosts A and B. An attacker can send packets to B as if they came 3014 from A by sending packets towards A with a spoofed IP address of B. 3015 This attack requires the attacker to know the IP addresses of A and 3016 B. With TURN, an attacker wishing to send packets towards a client 3017 using a Data indication needs to know its IP address (and port), the 3018 IP address and port of the TURN server, and the IP address and port 3019 of the peer (for inclusion in the XOR-PEER-ADDRESS attribute). To 3020 send a fake ChannelData message to a client, an attacker needs to 3021 know the IP address and port of the client, the IP address and port 3022 of the TURN server, and the channel number. This particular 3023 combination is mildly more guessable than in the non-TURN case. 3025 These attacks are more properly mitigated by application-layer 3026 authentication techniques. In the case of real-time traffic, usage 3027 of SRTP [RFC3711] prevents these attacks. 3029 In some situations, the TURN server may be situated in the network 3030 such that it is able to send to hosts to which the client cannot 3031 directly send. This can happen, for example, if the server is 3032 located behind a firewall that allows packets from outside the 3033 firewall to be delivered to the server, but not to other hosts behind 3034 the firewall. In these situations, an attacker could send the server 3035 a Send indication with an XOR-PEER-ADDRESS attribute containing the 3036 transport address of one of the other hosts behind the firewall. If 3037 the server was to allow relaying of traffic to arbitrary peers, then 3038 this would provide a way for the attacker to attack arbitrary hosts 3039 behind the firewall. 3041 To mitigate this attack, TURN requires that the client establish a 3042 permission to a host before sending it data. Thus, an attacker can 3043 only attack hosts with which the client is already communicating, 3044 unless the attacker is able to create authenticated requests. 3045 Furthermore, the server administrator may configure the server to 3046 restrict the range of IP addresses and ports to which it will relay 3047 data. To provide even greater security, the server administrator can 3048 require that the client use (D)TLS for all communication between the 3049 client and the server. 3051 18.1.5. Impersonating a Server 3053 When a client learns a relayed address from a TURN server, it uses 3054 that relayed address in application protocols to receive traffic. 3055 Therefore, an attacker wishing to intercept or redirect that traffic 3056 might try to impersonate a TURN server and provide the client with a 3057 faked relayed address. 3059 This attack is prevented through the long-term credential mechanism, 3060 which provides message integrity for responses in addition to 3061 verifying that they came from the server. Furthermore, an attacker 3062 cannot replay old server responses as the transaction id in the STUN 3063 header prevents this. Replay attacks are further thwarted through 3064 frequent changes to the nonce value. 3066 18.1.6. Eavesdropping Traffic 3068 TURN concerns itself primarily with authentication and message 3069 integrity. Confidentiality is only a secondary concern, as TURN 3070 control messages do not include information that is particularly 3071 sensitive. The primary protocol content of the messages is the IP 3072 address of the peer. If it is important to prevent an eavesdropper 3073 on a TURN connection from learning this, TURN can be run over (D)TLS. 3075 Confidentiality for the application data relayed by TURN is best 3076 provided by the application protocol itself, since running TURN over 3077 (D)TLS does not protect application data between the server and the 3078 peer. If confidentiality of application data is important, then the 3079 application should encrypt or otherwise protect its data. For 3080 example, for real-time media, confidentiality can be provided by 3081 using SRTP. 3083 18.1.7. TURN Loop Attack 3085 An attacker might attempt to cause data packets to loop indefinitely 3086 between two TURN servers. The attack goes as follows. First, the 3087 attacker sends an Allocate request to server A, using the source 3088 address of server B. Server A will send its response to server B, 3089 and for the attack to succeed, the attacker must have the ability to 3090 either view or guess the contents of this response, so that the 3091 attacker can learn the allocated relayed transport address. The 3092 attacker then sends an Allocate request to server B, using the source 3093 address of server A. Again, the attacker must be able to view or 3094 guess the contents of the response, so it can send learn the 3095 allocated relayed transport address. Using the same spoofed source 3096 address technique, the attacker then binds a channel number on server 3097 A to the relayed transport address on server B, and similarly binds 3098 the same channel number on server B to the relayed transport address 3099 on server A. Finally, the attacker sends a ChannelData message to 3100 server A. 3102 The result is a data packet that loops from the relayed transport 3103 address on server A to the relayed transport address on server B, 3104 then from server B's transport address to server A's transport 3105 address, and then around the loop again. 3107 This attack is mitigated as follows. By requiring all requests to be 3108 authenticated and/or by randomizing the port number allocated for the 3109 relayed transport address, the server forces the attacker to either 3110 intercept or view responses sent to a third party (in this case, the 3111 other server) so that the attacker can authenticate the requests and 3112 learn the relayed transport address. Without one of these two 3113 measures, an attacker can guess the contents of the responses without 3114 needing to see them, which makes the attack much easier to perform. 3115 Furthermore, by requiring authenticated requests, the server forces 3116 the attacker to have credentials acceptable to the server, which 3117 turns this from an outsider attack into an insider attack and allows 3118 the attack to be traced back to the client initiating it. 3120 The attack can be further mitigated by imposing a per-username limit 3121 on the bandwidth used to relay data by allocations owned by that 3122 username, to limit the impact of this attack on other allocations. 3123 More mitigation can be achieved by decrementing the TTL when relaying 3124 data packets (if the underlying OS allows this). 3126 18.2. Firewall Considerations 3128 A key security consideration of TURN is that TURN should not weaken 3129 the protections afforded by firewalls deployed between a client and a 3130 TURN server. It is anticipated that TURN servers will often be 3131 present on the public Internet, and clients may often be inside 3132 enterprise networks with corporate firewalls. If TURN servers 3133 provide a 'backdoor' for reaching into the enterprise, TURN will be 3134 blocked by these firewalls. 3136 TURN servers therefore emulate the behavior of NAT devices that 3137 implement address-dependent filtering [RFC4787], a property common in 3138 many firewalls as well. When a NAT or firewall implements this 3139 behavior, packets from an outside IP address are only allowed to be 3140 sent to an internal IP address and port if the internal IP address 3141 and port had recently sent a packet to that outside IP address. TURN 3142 servers introduce the concept of permissions, which provide exactly 3143 this same behavior on the TURN server. An attacker cannot send a 3144 packet to a TURN server and expect it to be relayed towards the 3145 client, unless the client has tried to contact the attacker first. 3147 It is important to note that some firewalls have policies that are 3148 even more restrictive than address-dependent filtering. Firewalls 3149 can also be configured with address- and port-dependent filtering, or 3150 can be configured to disallow inbound traffic entirely. In these 3151 cases, if a client is allowed to connect the TURN server, 3152 communications to the client will be less restrictive than what the 3153 firewall would normally allow. 3155 18.2.1. Faked Permissions 3157 In firewalls and NAT devices, permissions are granted implicitly 3158 through the traversal of a packet from the inside of the network 3159 towards the outside peer. Thus, a permission cannot, by definition, 3160 be created by any entity except one inside the firewall or NAT. With 3161 TURN, this restriction no longer holds. Since the TURN server sits 3162 outside the firewall, at attacker outside the firewall can now send a 3163 message to the TURN server and try to create a permission for itself. 3165 This attack is prevented because all messages that create permissions 3166 (i.e., ChannelBind and CreatePermission) are authenticated. 3168 18.2.2. Blacklisted IP Addresses 3170 Many firewalls can be configured with blacklists that prevent a 3171 client behind the firewall from sending packets to, or receiving 3172 packets from, ranges of blacklisted IP addresses. This is 3173 accomplished by inspecting the source and destination addresses of 3174 packets entering and exiting the firewall, respectively. 3176 This feature is also present in TURN, since TURN servers are allowed 3177 to arbitrarily restrict the range of addresses of peers that they 3178 will relay to. 3180 18.2.3. Running Servers on Well-Known Ports 3182 A malicious client behind a firewall might try to connect to a TURN 3183 server and obtain an allocation which it then uses to run a server. 3184 For example, a client might try to run a DNS server or FTP server. 3186 This is not possible in TURN. A TURN server will never accept 3187 traffic from a peer for which the client has not installed a 3188 permission. Thus, peers cannot just connect to the allocated port in 3189 order to obtain the service. 3191 18.3. Insider Attacks 3193 In insider attacks, a client has legitimate credentials but defies 3194 the trust relationship that goes with those credentials. These 3195 attacks cannot be prevented by cryptographic means but need to be 3196 considered in the design of the protocol. 3198 18.3.1. DoS against TURN Server 3200 A client wishing to disrupt service to other clients might obtain an 3201 allocation and then flood it with traffic, in an attempt to swamp the 3202 server and prevent it from servicing other legitimate clients. This 3203 is mitigated by the recommendation that the server limit the amount 3204 of bandwidth it will relay for a given username. This won't prevent 3205 a client from sending a large amount of traffic, but it allows the 3206 server to immediately discard traffic in excess. 3208 Since each allocation uses a port number on the IP address of the 3209 TURN server, the number of allocations on a server is finite. An 3210 attacker might attempt to consume all of them by requesting a large 3211 number of allocations. This is prevented by the recommendation that 3212 the server impose a limit of the number of allocations active at a 3213 time for a given username. 3215 18.3.2. Anonymous Relaying of Malicious Traffic 3217 TURN servers provide a degree of anonymization. A client can send 3218 data to peers without revealing its own IP address. TURN servers may 3219 therefore become attractive vehicles for attackers to launch attacks 3220 against targets without fear of detection. Indeed, it is possible 3221 for a client to chain together multiple TURN servers, such that any 3222 number of relays can be used before a target receives a packet. 3224 Administrators who are worried about this attack can maintain logs 3225 that capture the actual source IP and port of the client, and perhaps 3226 even every permission that client installs. This will allow for 3227 forensic tracing to determine the original source, should it be 3228 discovered that an attack is being relayed through a TURN server. 3230 18.3.3. Manipulating Other Allocations 3232 An attacker might attempt to disrupt service to other users of the 3233 TURN server by sending Refresh requests or CreatePermission requests 3234 that (through source address spoofing) appear to be coming from 3235 another user of the TURN server. TURN prevents this by requiring 3236 that the credentials used in CreatePermission, Refresh, and 3237 ChannelBind messages match those used to create the initial 3238 allocation. Thus, the fake requests from the attacker will be 3239 rejected. 3241 18.4. Tunnel Amplification Attack 3243 An attacker might attempt to cause data packets to loop numerous 3244 times between a TURN server and a tunnel between IPv4 and IPv6. The 3245 attack goes as follows. 3247 Suppose an attacker knows that a tunnel endpoint will forward 3248 encapsulated packets from a given IPv6 address (this doesn't 3249 necessarily need to be the tunnel endpoint's address). Suppose he 3250 then spoofs two packets from this address: 3252 1. An Allocate request asking for a v4 address, and 3254 2. A ChannelBind request establishing a channel to the IPv4 address 3255 of the tunnel endpoint 3257 Then he has set up an amplification attack: 3259 o The TURN relay will re-encapsulate IPv6 UDP data in v4 and send it 3260 to the tunnel endpoint 3262 o The tunnel endpoint will de-encapsulate packets from the v4 3263 interface and send them to v6 3265 So if the attacker sends a packet of the following form... 3267 IPv6: src=2001:DB9::1 dst=2001:DB8::2 3268 UDP: 3269 TURN: 3270 IPv6: src=2001:DB9::1 dst=2001:DB8::2 3271 UDP: 3272 TURN: 3273 IPv6: src=2001:DB9::1 dst=2001:DB8::2 3274 UDP: 3275 TURN: 3276 ... 3278 Then the TURN relay and the tunnel endpoint will send it back and 3279 forth until the last TURN header is consumed, at which point the TURN 3280 relay will send an empty packet, which the tunnel endpoint will drop. 3282 The amplification potential here is limited by the MTU, so it's not 3283 huge: IPv6+UDP+TURN takes 334 bytes, so a four-to-one amplification 3284 out of a 1500-byte packet is possible. But the attacker could still 3285 increase traffic volume by sending multiple packets or by 3286 establishing multiple channels spoofed from different addresses 3287 behind the same tunnel endpoint. 3289 The attack is mitigated as follows. It is RECOMMENDED that TURN 3290 relays not accept allocation or channel binding requests from 3291 addresses known to be tunneled, and that they not forward data to 3292 such addresses. In particular, a TURN relay MUST NOT accept Teredo 3293 or 6to4 addresses in these requests. 3295 18.5. Other Considerations 3297 Any relay addresses learned through an Allocate request will not 3298 operate properly with IPsec Authentication Header (AH) [RFC4302] in 3299 transport or tunnel mode. However, tunnel-mode IPsec Encapsulating 3300 Security Payload (ESP) [RFC4303] should still operate. 3302 19. IANA Considerations 3304 Since TURN is an extension to STUN [RFC5389], the methods, 3305 attributes, and error codes defined in this specification are new 3306 methods, attributes, and error codes for STUN. IANA has added these 3307 new protocol elements to the IANA registry of STUN protocol elements. 3309 The codepoints for the new STUN methods defined in this specification 3310 are listed in Section 14. 3312 The codepoints for the new STUN attributes defined in this 3313 specification are listed in Section 15. 3315 The codepoints for the new STUN error codes defined in this 3316 specification are listed in Section 16. 3318 IANA has allocated the SRV service name of "turn" for TURN over UDP 3319 or TCP, and the service name of "turns" for TURN over (D)TLS. 3321 IANA has created a registry for TURN channel numbers, initially 3322 populated as follows: 3324 o 0x0000 through 0x3FFF: Reserved and not available for use, since 3325 they conflict with the STUN header. 3327 o 0x4000 through 0x7FFF: A TURN implementation is free to use 3328 channel numbers in this range. 3330 o 0x8000 through 0xFFFF: Unassigned. 3332 Any change to this registry must be made through an IETF Standards 3333 Action. 3335 [Paragraphs in braces should be removed by the RFC Editor upon 3336 publication] 3338 [The ADDITIONAL-ADDRESS-FAMILY, ADDRESS-ERROR-CODE attributes 3339 requires that IANA allocate a value in the "STUN attributes Registry" 3340 from the comprehension- optional range (0x8000-0xFFFF), to be 3341 replaced for TBD-CA throughout this document] 3343 20. IAB Considerations 3345 The IAB has studied the problem of "Unilateral Self Address Fixing" 3346 (UNSAF), which is the general process by which a client attempts to 3347 determine its address in another realm on the other side of a NAT 3348 through a collaborative protocol-reflection mechanism [RFC3424]. The 3349 TURN extension is an example of a protocol that performs this type of 3350 function. The IAB has mandated that any protocols developed for this 3351 purpose document a specific set of considerations. These 3352 considerations and the responses for TURN are documented in this 3353 section. 3355 Consideration 1: Precise definition of a specific, limited-scope 3356 problem that is to be solved with the UNSAF proposal. A short-term 3357 fix should not be generalized to solve other problems. Such 3358 generalizations lead to the prolonged dependence on and usage of the 3359 supposed short-term fix -- meaning that it is no longer accurate to 3360 call it "short-term". 3362 Response: TURN is a protocol for communication between a relay (= 3363 TURN server) and its client. The protocol allows a client that is 3364 behind a NAT to obtain and use a public IP address on the relay. As 3365 a convenience to the client, TURN also allows the client to determine 3366 its server-reflexive transport address. 3368 Consideration 2: Description of an exit strategy/transition plan. 3369 The better short-term fixes are the ones that will naturally see less 3370 and less use as the appropriate technology is deployed. 3372 Response: TURN will no longer be needed once there are no longer any 3373 NATs. Unfortunately, as of the date of publication of this document, 3374 it no longer seems very likely that NATs will go away any time soon. 3375 However, the need for TURN will also decrease as the number of NATs 3376 with the mapping property of Endpoint-Independent Mapping [RFC4787] 3377 increases. 3379 Consideration 3: Discussion of specific issues that may render 3380 systems more "brittle". For example, approaches that involve using 3381 data at multiple network layers create more dependencies, increase 3382 debugging challenges, and make it harder to transition. 3384 Response: TURN is "brittle" in that it requires the NAT bindings 3385 between the client and the server to be maintained unchanged for the 3386 lifetime of the allocation. This is typically done using keep- 3387 alives. If this is not done, then the client will lose its 3388 allocation and can no longer exchange data with its peers. 3390 Consideration 4: Identify requirements for longer-term, sound 3391 technical solutions; contribute to the process of finding the right 3392 longer-term solution. 3394 Response: The need for TURN will be reduced once NATs implement the 3395 recommendations for NAT UDP behavior documented in [RFC4787]. 3396 Applications are also strongly urged to use ICE [RFC5245] to 3397 communicate with peers; though ICE uses TURN, it does so only as a 3398 last resort, and uses it in a controlled manner. 3400 Consideration 5: Discussion of the impact of the noted practical 3401 issues with existing deployed NATs and experience reports. 3403 Response: Some NATs deployed today exhibit a mapping behavior other 3404 than Endpoint-Independent mapping. These NATs are difficult to work 3405 with, as they make it difficult or impossible for protocols like ICE 3406 to use server-reflexive transport addresses on those NATs. A client 3407 behind such a NAT is often forced to use a relay protocol like TURN 3408 because "UDP hole punching" techniques [RFC5128] do not work. 3410 21. Changes since RFC 5766 3412 This section lists the major changes in the TURN protocol from the 3413 original [RFC5766] specification. 3415 o IPv6 support. 3417 o REQUESTED-ADDRESS-FAMILY, ADDITIONAL-ADDRESS-FAMILY, AND ADDRESS- 3418 ERRR-CODE attributes. 3420 o 440 (Address Family not Supported) and 443 (Peer Address Family 3421 Mismatch) responses. 3423 o Description of the tunnel amplification attack. 3425 o DTLS support. 3427 o More detail on packet translations. 3429 22. Acknowledgements 3431 Most of the text in this note comes from the original TURN 3432 specification, [RFC5766]. The authors would like to thank Rohan Mahy 3433 co-author of orginal TURN specification and everyone who had 3434 contributed to that document. 3436 Thanks to Justin Uberti, Pal Martinsen, Oleg Moskalenko, Aijun Wang 3437 and Simon Perreault for their help on SSODA mechanism. 3439 23. References 3441 23.1. Normative References 3443 [RFC5389] Rosenberg, J., Mahy, R., Matthews, P., and D. Wing, 3444 "Session Traversal Utilities for NAT (STUN)", RFC 5389, 3445 October 2008. 3447 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 3448 Requirement Levels", BCP 14, RFC 2119, March 1997. 3450 [RFC2474] Nichols, K., Blake, S., Baker, F., and D. Black, 3451 "Definition of the Differentiated Services Field (DS 3452 Field) in the IPv4 and IPv6 Headers", RFC 2474, December 3453 1998. 3455 [RFC3168] Ramakrishnan, K., Floyd, S., and D. Black, "The Addition 3456 of Explicit Congestion Notification (ECN) to IP", RFC 3457 3168, September 2001. 3459 [RFC1122] Braden, R., "Requirements for Internet Hosts - 3460 Communication Layers", STD 3, RFC 1122, October 1989. 3462 [RFC6145] Li, X., Bao, C., and F. Baker, "IP/ICMP Translation 3463 Algorithm", RFC 6145, April 2011. 3465 [RFC3697] Rajahalme, J., Conta, A., Carpenter, B., and S. Deering, 3466 "IPv6 Flow Label Specification", RFC 3697, March 2004. 3468 23.2. Informative References 3470 [RFC1191] Mogul, J. and S. Deering, "Path MTU discovery", RFC 1191, 3471 November 1990. 3473 [RFC0791] Postel, J., "Internet Protocol", STD 5, RFC 791, September 3474 1981. 3476 [RFC1918] Rekhter, Y., Moskowitz, R., Karrenberg, D., Groot, G., and 3477 E. Lear, "Address Allocation for Private Internets", BCP 3478 5, RFC 1918, February 1996. 3480 [RFC3424] Daigle, L. and IAB, "IAB Considerations for UNilateral 3481 Self-Address Fixing (UNSAF) Across Network Address 3482 Translation", RFC 3424, November 2002. 3484 [RFC4787] Audet, F. and C. Jennings, "Network Address Translation 3485 (NAT) Behavioral Requirements for Unicast UDP", BCP 127, 3486 RFC 4787, January 2007. 3488 [RFC5245] Rosenberg, J., "Interactive Connectivity Establishment 3489 (ICE): A Protocol for Network Address Translator (NAT) 3490 Traversal for Offer/Answer Protocols", RFC 5245, April 3491 2010. 3493 [RFC6062] Perreault, S. and J. Rosenberg, "Traversal Using Relays 3494 around NAT (TURN) Extensions for TCP Allocations", RFC 3495 6062, November 2010. 3497 [RFC6156] Camarillo, G., Novo, O., and S. Perreault, "Traversal 3498 Using Relays around NAT (TURN) Extension for IPv6", RFC 3499 6156, April 2011. 3501 [RFC6056] Larsen, M. and F. Gont, "Recommendations for Transport- 3502 Protocol Port Randomization", BCP 156, RFC 6056, January 3503 2011. 3505 [RFC5128] Srisuresh, P., Ford, B., and D. Kegel, "State of Peer-to- 3506 Peer (P2P) Communication across Network Address 3507 Translators (NATs)", RFC 5128, March 2008. 3509 [RFC1928] Leech, M., Ganis, M., Lee, Y., Kuris, R., Koblas, D., and 3510 L. Jones, "SOCKS Protocol Version 5", RFC 1928, March 3511 1996. 3513 [RFC3550] Schulzrinne, H., Casner, S., Frederick, R., and V. 3514 Jacobson, "RTP: A Transport Protocol for Real-Time 3515 Applications", STD 64, RFC 3550, July 2003. 3517 [RFC3711] Baugher, M., McGrew, D., Naslund, M., Carrara, E., and K. 3518 Norrman, "The Secure Real-time Transport Protocol (SRTP)", 3519 RFC 3711, March 2004. 3521 [RFC4302] Kent, S., "IP Authentication Header", RFC 4302, December 3522 2005. 3524 [RFC4303] Kent, S., "IP Encapsulating Security Payload (ESP)", RFC 3525 4303, December 2005. 3527 [RFC4821] Mathis, M. and J. Heffner, "Packetization Layer Path MTU 3528 Discovery", RFC 4821, March 2007. 3530 [RFC3261] Rosenberg, J., Schulzrinne, H., Camarillo, G., Johnston, 3531 A., Peterson, J., Sparks, R., Handley, M., and E. 3532 Schooler, "SIP: Session Initiation Protocol", RFC 3261, 3533 June 2002. 3535 [I-D.rosenberg-mmusic-ice-nonsip] 3536 Rosenberg, J., "Guidelines for Usage of Interactive 3537 Connectivity Establishment (ICE) by non Session Initiation 3538 Protocol (SIP) Protocols", draft-rosenberg-mmusic-ice- 3539 nonsip-01 (work in progress), July 2008. 3541 [I-D.ietf-tram-turn-server-discovery] 3542 Patil, P., Reddy, T., and D. Wing, "TURN Server Auto 3543 Discovery", draft-ietf-tram-turn-server-discovery-01 (work 3544 in progress), January 2015. 3546 [RFC4086] Eastlake, D., Schiller, J., and S. Crocker, "Randomness 3547 Requirements for Security", BCP 106, RFC 4086, June 2005. 3549 [RFC5766] Mahy, R., Matthews, P., and J. Rosenberg, "Traversal Using 3550 Relays around NAT (TURN): Relay Extensions to Session 3551 Traversal Utilities for NAT (STUN)", RFC 5766, April 2010. 3553 [Port-Numbers] 3554 "IANA Port Numbers Registry", 2005, 3555 . 3557 [Frag-Harmful] 3558 "Fragmentation Considered Harmful", . 3561 [Protocol-Numbers] 3562 "IANA Protocol Numbers Registry", 2005, 3563 . 3565 Authors' Addresses 3567 Tirumaleswar Reddy (editor) 3568 Cisco Systems, Inc. 3569 Cessna Business Park, Varthur Hobl 3570 Sarjapur Marathalli Outer Ring Road 3571 Bangalore, Karnataka 560103 3572 India 3574 Email: tireddy@cisco.com 3576 Alan Johnston (editor) 3577 Avaya 3578 St. Louis, MO 3579 USA 3581 Email: alan.b.johnston@gmail.com 3583 Philip Matthews 3584 Alcatel-Lucent 3585 600 March Road 3586 Ottawa, Ontario 3587 Canada 3589 Email: philip_matthews@magma.ca 3590 Jonathan Rosenberg 3591 jdrosen.net 3592 Edison, NJ 3593 USA 3595 Email: jdrosen@jdrosen.net 3596 URI: http://www.jdrosen.net