| 1 |
<pre>Independent Submission S. Cheshire |
| 2 |
Request for Comments: 6886 M. Krochmal |
| 3 |
Category: Informational Apple Inc. |
| 4 |
ISSN: 2070-1721 April 2013 |
| 5 |
|
| 6 |
<span class="h1">NAT Port Mapping Protocol (NAT-PMP)</span> |
| 7 |
|
| 8 |
Abstract |
| 9 |
|
| 10 |
This document describes a protocol for automating the process of |
| 11 |
creating Network Address Translation (NAT) port mappings. Included |
| 12 |
in the protocol is a method for retrieving the external IPv4 address |
| 13 |
of a NAT gateway, thus allowing a client to make its external IPv4 |
| 14 |
address and port known to peers that may wish to communicate with it. |
| 15 |
From 2005 onwards, this protocol was implemented in Apple products |
| 16 |
including Mac OS X, Bonjour for Windows, and AirPort wireless base |
| 17 |
stations. In 2013, NAT Port Mapping Protocol (NAT-PMP) was |
| 18 |
superseded by the IETF Standards Track RFC "Port Control Protocol |
| 19 |
(PCP)", which builds on NAT-PMP and uses a compatible packet format, |
| 20 |
but adds a number of significant enhancements. |
| 21 |
|
| 22 |
Status of This Memo |
| 23 |
|
| 24 |
This document is not an Internet Standards Track specification; it is |
| 25 |
published for informational purposes. |
| 26 |
|
| 27 |
This is a contribution to the RFC Series, independently of any other |
| 28 |
RFC stream. The RFC Editor has chosen to publish this document at |
| 29 |
its discretion and makes no statement about its value for |
| 30 |
implementation or deployment. Documents approved for publication by |
| 31 |
the RFC Editor are not a candidate for any level of Internet |
| 32 |
Standard; see <a href="./rfc5741#section-2">Section 2 of RFC 5741</a>. |
| 33 |
|
| 34 |
Information about the current status of this document, any errata, |
| 35 |
and how to provide feedback on it may be obtained at |
| 36 |
<a href="http://www.rfc-editor.org/info/rfc6886">http://www.rfc-editor.org/info/rfc6886</a>. |
| 37 |
|
| 38 |
Copyright Notice |
| 39 |
|
| 40 |
Copyright (c) 2013 IETF Trust and the persons identified as the |
| 41 |
document authors. All rights reserved. |
| 42 |
|
| 43 |
This document is subject to <a href="https://www.rfc-editor.org/bcp/bcp78">BCP 78</a> and the IETF Trust's Legal |
| 44 |
Provisions Relating to IETF Documents |
| 45 |
(<a href="http://trustee.ietf.org/license-info">http://trustee.ietf.org/license-info</a>) in effect on the date of |
| 46 |
publication of this document. Please review these documents |
| 47 |
carefully, as they describe your rights and restrictions with respect |
| 48 |
to this document. |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
<span class="grey">Cheshire & Krochmal Informational [Page 1]</span></pre> |
| 53 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-2" ></span> |
| 54 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 55 |
|
| 56 |
|
| 57 |
Table of Contents |
| 58 |
|
| 59 |
<a href="#section-1">1</a>. Introduction ....................................................<a href="#page-3">3</a> |
| 60 |
<a href="#section-1.1">1.1</a>. Transition to Port Control Protocol ........................<a href="#page-4">4</a> |
| 61 |
<a href="#section-2">2</a>. Conventions and Terminology Used in This Document ...............<a href="#page-5">5</a> |
| 62 |
<a href="#section-3">3</a>. Protocol and Packet Format ......................................<a href="#page-5">5</a> |
| 63 |
<a href="#section-3.1">3.1</a>. Requests and Responses .....................................<a href="#page-6">6</a> |
| 64 |
<a href="#section-3.2">3.2</a>. Determining the External Address ...........................<a href="#page-7">7</a> |
| 65 |
<a href="#section-3.3">3.3</a>. Requesting a Mapping ......................................<a href="#page-10">10</a> |
| 66 |
<a href="#section-3.4">3.4</a>. Destroying a Mapping ......................................<a href="#page-13">13</a> |
| 67 |
<a href="#section-3.5">3.5</a>. Result Codes ..............................................<a href="#page-14">14</a> |
| 68 |
<a href="#section-3.6">3.6</a>. Seconds Since Start of Epoch ..............................<a href="#page-16">16</a> |
| 69 |
<a href="#section-3.7">3.7</a>. Recreating Mappings on NAT Gateway Reboot .................<a href="#page-16">16</a> |
| 70 |
<a href="#section-3.8">3.8</a>. NAT Gateways with NAT Function Disabled ...................<a href="#page-18">18</a> |
| 71 |
<a href="#section-3.9">3.9</a>. All Mappings Are Bidirectional ............................<a href="#page-19">19</a> |
| 72 |
<a href="#section-4">4</a>. UNSAF Considerations ...........................................<a href="#page-20">20</a> |
| 73 |
<a href="#section-4.1">4.1</a>. Scope .....................................................<a href="#page-20">20</a> |
| 74 |
<a href="#section-4.2">4.2</a>. Transition Plan ...........................................<a href="#page-20">20</a> |
| 75 |
<a href="#section-4.3">4.3</a>. Failure Cases .............................................<a href="#page-21">21</a> |
| 76 |
<a href="#section-4.4">4.4</a>. Long-Term Solution ........................................<a href="#page-23">23</a> |
| 77 |
<a href="#section-4.5">4.5</a>. Existing Deployed NATs ....................................<a href="#page-23">23</a> |
| 78 |
<a href="#section-5">5</a>. Security Considerations ........................................<a href="#page-23">23</a> |
| 79 |
<a href="#section-6">6</a>. IANA Considerations ............................................<a href="#page-24">24</a> |
| 80 |
<a href="#section-7">7</a>. Acknowledgments ................................................<a href="#page-24">24</a> |
| 81 |
<a href="#section-8">8</a>. Deployment History .............................................<a href="#page-25">25</a> |
| 82 |
<a href="#section-9">9</a>. Noteworthy Features of NAT Port Mapping Protocol and PCP .......<a href="#page-26">26</a> |
| 83 |
<a href="#section-9.1">9.1</a>. Simplicity ................................................<a href="#page-27">27</a> |
| 84 |
<a href="#section-9.2">9.2</a>. Focused Scope .............................................<a href="#page-27">27</a> |
| 85 |
<a href="#section-9.3">9.3</a>. Efficiency ................................................<a href="#page-27">27</a> |
| 86 |
<a href="#section-9.4">9.4</a>. Atomic Allocation Operations ..............................<a href="#page-29">29</a> |
| 87 |
<a href="#section-9.5">9.5</a>. Garbage Collection ........................................<a href="#page-29">29</a> |
| 88 |
<a href="#section-9.6">9.6</a>. State Change Announcements ................................<a href="#page-30">30</a> |
| 89 |
<a href="#section-9.7">9.7</a>. Soft State Recovery .......................................<a href="#page-31">31</a> |
| 90 |
<a href="#section-9.8">9.8</a>. On-Path NAT Discovery .....................................<a href="#page-31">31</a> |
| 91 |
<a href="#section-10">10</a>. References ....................................................<a href="#page-32">32</a> |
| 92 |
<a href="#section-10.1">10.1</a>. Normative References .....................................<a href="#page-32">32</a> |
| 93 |
<a href="#section-10.2">10.2</a>. Informative References ...................................<a href="#page-32">32</a> |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
<span class="grey">Cheshire & Krochmal Informational [Page 2]</span></pre> |
| 109 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-3" ></span> |
| 110 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 111 |
|
| 112 |
|
| 113 |
<span class="h2"><a class="selflink" id="section-1" href="#section-1">1</a>. Introduction</span> |
| 114 |
|
| 115 |
Network Address Translation (NAT) is a method of sharing one public |
| 116 |
Internet address with a number of devices. This document is focused |
| 117 |
on devices that are formally classified as "NAPTs" (Network |
| 118 |
Address/Port Translators) [<a href="./rfc2663" title=""IP Network Address Translator (NAT) Terminology and Considerations"">RFC2663</a>]. A full description of NAT is |
| 119 |
beyond the scope of this document. The following brief overview will |
| 120 |
cover the aspects relevant to this port mapping protocol. For more |
| 121 |
information on NAT, see "Traditional IP Network Address Translator |
| 122 |
(Traditional NAT)" [<a href="./rfc3022" title=""Traditional IP Network Address Translator (Traditional NAT)"">RFC3022</a>]. |
| 123 |
|
| 124 |
NATs have one or more external IP addresses. A private network is |
| 125 |
set up behind the NAT. Client devices on that private network behind |
| 126 |
the NAT are assigned private addresses, and those client devices use |
| 127 |
the private address of the NAT device as their default gateway. |
| 128 |
|
| 129 |
When a packet from any device behind the NAT is sent to an address on |
| 130 |
the public Internet, the packet first passes through the NAT box. |
| 131 |
The NAT box looks at the source port and address. In some cases, a |
| 132 |
NAT will also keep track of the destination port and address. The |
| 133 |
NAT then creates a mapping from the internal address and internal |
| 134 |
port to an external address and external port if a mapping does not |
| 135 |
already exist. |
| 136 |
|
| 137 |
The NAT box replaces the internal address and port in the packet with |
| 138 |
the external entries from the mapping and sends the packet on to the |
| 139 |
next gateway. |
| 140 |
|
| 141 |
When a packet from any address on the Internet is received on the |
| 142 |
NAT's external side, the NAT will look up the destination address and |
| 143 |
port (external address and port) in the list of mappings. If an |
| 144 |
entry is found, it will contain the internal address and port to |
| 145 |
which the packet should be sent. The NAT gateway will then rewrite |
| 146 |
the destination address and port with those from the mapping. The |
| 147 |
packet will then be forwarded to the new destination addresses. If |
| 148 |
the packet did not match any mapping, the packet will most likely be |
| 149 |
dropped. Various NATs implement different strategies to handle this. |
| 150 |
The important thing to note is that if there is no mapping, the NAT |
| 151 |
does not know to which internal address the packet should be sent. |
| 152 |
|
| 153 |
Mappings are usually created automatically as a result of observing |
| 154 |
outbound packets. There are a few exceptions. Some NATs may allow |
| 155 |
manually created permanent mappings that map an external port to a |
| 156 |
specific internal IP address and port. Such a mapping allows |
| 157 |
incoming connections to the device with that internal address. Some |
| 158 |
NATs also implement a default mapping where any inbound packet that |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
<span class="grey">Cheshire & Krochmal Informational [Page 3]</span></pre> |
| 165 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-4" ></span> |
| 166 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 167 |
|
| 168 |
|
| 169 |
does not match any other more specific mapping will be forwarded to a |
| 170 |
specified internal address. Both types of mappings are usually set |
| 171 |
up manually through some configuration tool. Such manual |
| 172 |
configuration of port mappings is unreasonably onerous for most |
| 173 |
residential NAT users. |
| 174 |
|
| 175 |
Without these manually created inbound port mappings, clients behind |
| 176 |
the NAT would be unable to receive inbound connections, which |
| 177 |
represents a loss of connectivity when compared to the original |
| 178 |
Internet architecture [<a href="#ref-ETEAISD" title=""End-to-end arguments in system design"">ETEAISD</a>]. For those who view this loss of |
| 179 |
connectivity as a bad thing, NAT-PMP allows clients to operate more |
| 180 |
like a host directly connected to the unrestricted public Internet, |
| 181 |
with an unrestricted public IPv4 address. NAT-PMP allows client |
| 182 |
hosts to communicate with the NAT gateway to request the creation of |
| 183 |
inbound mappings on demand. Having created a NAT mapping to allow |
| 184 |
inbound connections, the client can then record its external IPv4 |
| 185 |
address and external port in a public registry (e.g., the worldwide |
| 186 |
Domain Name System) or otherwise make it accessible to peers that |
| 187 |
wish to communicate with it. |
| 188 |
|
| 189 |
<span class="h3"><a class="selflink" id="section-1.1" href="#section-1.1">1.1</a>. Transition to Port Control Protocol</span> |
| 190 |
|
| 191 |
NAT-PMP enjoyed almost a decade of useful service, and operational |
| 192 |
experience with NAT-PMP informed the design of its IETF Standards |
| 193 |
Track successor, Port Control Protocol (PCP) [<a href="./rfc6887" title=""Port Control Protocol (PCP)"">RFC6887</a>]. PCP builds |
| 194 |
on NAT-PMP, using the same UDP ports 5350 and 5351, and a compatible |
| 195 |
packet format. PCP also adds significant enhancements, including |
| 196 |
IPv6 support, management of outbound mappings, management of firewall |
| 197 |
rules, full compatibility with large-scale NATs with a pool of |
| 198 |
external addresses, error lifetimes, and an extension mechanism to |
| 199 |
enable future enhancements. |
| 200 |
|
| 201 |
Because of the significant enhancements in PCP, all existing NAT-PMP |
| 202 |
implementations are encouraged to migrate to PCP. The version number |
| 203 |
in the packet header is 0 for NAT-PMP and 2 for PCP, so the packets |
| 204 |
are easily distinguished. (Version number 1 was used by a vendor |
| 205 |
that shipped products that use a protocol that is incompatible with |
| 206 |
the IETF Standard. PCP implementations MUST NOT use version |
| 207 |
number 1.) |
| 208 |
|
| 209 |
For NAT-PMP servers, adding PCP support is simple. When packets are |
| 210 |
received, if the version number is 2, then the packet is interpreted |
| 211 |
as a PCP request, the request is handled, and replies and updates |
| 212 |
pertaining to that mapping are sent using PCP format. If the version |
| 213 |
number is 0, then the existing code handles the request exactly as it |
| 214 |
already does, and replies and updates pertaining to that mapping are |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
<span class="grey">Cheshire & Krochmal Informational [Page 4]</span></pre> |
| 221 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-5" ></span> |
| 222 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 223 |
|
| 224 |
|
| 225 |
sent using NAT-PMP format. If the version number is 1 or any other |
| 226 |
unsupported version, then result code 1 (Unsupported Version) is |
| 227 |
returned. |
| 228 |
|
| 229 |
NAT-PMP clients should add PCP support, and should default to sending |
| 230 |
requests using PCP format, which will cause clients to prefer the |
| 231 |
newer format when possible. If a PCP request is sent to an old |
| 232 |
NAT-PMP server that doesn't understand the new PCP format, then it |
| 233 |
will return result code 1 (Unsupported Version), and the client |
| 234 |
should then immediately retry the same request using NAT-PMP format. |
| 235 |
The presence of the Unsupported Version reply allows fast fail-over |
| 236 |
to NAT-PMP format, without waiting for timeouts, retransmissions, or |
| 237 |
other arbitrary delays. It is recommended that clients always try |
| 238 |
PCP first for every new request, retransmission, and renewal, and |
| 239 |
only try NAT-PMP in response to an "Unsupported Version" error. |
| 240 |
Clients SHOULD NOT record that a given server only speaks NAT-PMP and |
| 241 |
subsequently default to NAT-PMP for that server, since NAT firmware |
| 242 |
gets updated, and even a NAT gateway that speaks only NAT-PMP today, |
| 243 |
may be updated to speak PCP tomorrow. |
| 244 |
|
| 245 |
<span class="h2"><a class="selflink" id="section-2" href="#section-2">2</a>. Conventions and Terminology Used in This Document</span> |
| 246 |
|
| 247 |
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", |
| 248 |
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this |
| 249 |
document are to be interpreted as described in "Key words for use in |
| 250 |
RFCs to Indicate Requirement Levels" [<a href="./rfc2119" title=""Key words for use in RFCs to Indicate Requirement Levels"">RFC2119</a>]. |
| 251 |
|
| 252 |
<span class="h2"><a class="selflink" id="section-3" href="#section-3">3</a>. Protocol and Packet Format</span> |
| 253 |
|
| 254 |
The NAT Port Mapping Protocol runs over UDP. Every packet starts |
| 255 |
with an 8-bit version followed by an 8-bit operation code. |
| 256 |
|
| 257 |
All numeric quantities in NAT-PMP larger than a single byte (e.g., |
| 258 |
error values, Seconds Since Start of Epoch, and mapping lifetime) are |
| 259 |
transmitted in the traditional IETF network byte order (i.e., most |
| 260 |
significant byte first). |
| 261 |
|
| 262 |
Non-numeric quantities in NAT-PMP larger than a single byte (e.g., |
| 263 |
the NAT gateway's external IP address) are transmitted in the natural |
| 264 |
byte order, with no byte swapping. |
| 265 |
|
| 266 |
This document specifies version 0 of the protocol. Any NAT-PMP |
| 267 |
gateway implementing this version of the protocol, receiving a |
| 268 |
request with a version number other than 0, MUST return result code 1 |
| 269 |
(Unsupported Version), indicating the highest version number it does |
| 270 |
support (i.e., 0) in the version field of the response. |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
<span class="grey">Cheshire & Krochmal Informational [Page 5]</span></pre> |
| 277 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-6" ></span> |
| 278 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 279 |
|
| 280 |
|
| 281 |
Opcodes between 0 and 127 are client requests. Opcodes from 128 to |
| 282 |
255 are corresponding server responses. Responses always contain a |
| 283 |
16-bit result code in network byte order. A result code of zero |
| 284 |
indicates success. Responses also contain a 32-bit unsigned integer |
| 285 |
corresponding to the number of seconds since the NAT gateway was |
| 286 |
rebooted or since its port mapping state was otherwise reset. |
| 287 |
|
| 288 |
This protocol SHOULD only be used when the client determines that its |
| 289 |
primary IPv4 address is in one of the private IPv4 address ranges |
| 290 |
defined in "Address Allocation for Private Internets" [<a href="./rfc1918" title=""Address Allocation for Private Internets"">RFC1918</a>]. |
| 291 |
This includes the address ranges 10/8, 172.16/12, and 192.168/16. |
| 292 |
|
| 293 |
Clients always send their NAT-PMP requests to their default gateway, |
| 294 |
as learned via DHCP [<a href="./rfc2131" title=""Dynamic Host Configuration Protocol"">RFC2131</a>], or similar means. This protocol is |
| 295 |
designed for small home networks, with a single logical link (subnet) |
| 296 |
where the client's default gateway is also the NAT for that network. |
| 297 |
For more complicated networks where the NAT is some device other than |
| 298 |
the client's default gateway, this protocol is not appropriate. |
| 299 |
|
| 300 |
<span class="h3"><a class="selflink" id="section-3.1" href="#section-3.1">3.1</a>. Requests and Responses</span> |
| 301 |
|
| 302 |
NAT gateways are often low-cost devices, with limited memory and CPU |
| 303 |
speed. For this reason, to avoid making excessive demands on the NAT |
| 304 |
gateway, clients SHOULD NOT issue multiple concurrent requests. If a |
| 305 |
client needs to perform multiple requests (e.g., on boot, wake from |
| 306 |
sleep, network connection, etc.), it SHOULD queue them and issue them |
| 307 |
serially, one at a time. Once the NAT gateway responds to one |
| 308 |
request the client machine may issue the next. In the case of a fast |
| 309 |
NAT gateway, the client may be able to complete requests at a rate of |
| 310 |
hundreds per second. In the case of a slow NAT gateway that takes |
| 311 |
perhaps half a second to respond to a NAT-PMP request, the client |
| 312 |
SHOULD respect this and allow the NAT gateway to operate at the pace |
| 313 |
it can manage, and not overload it by issuing requests faster than |
| 314 |
the rate it's answering them. |
| 315 |
|
| 316 |
To determine the external IPv4 address, or to request a port mapping, |
| 317 |
a NAT-PMP client sends its request packet to port 5351 of its |
| 318 |
configured gateway address, and waits 250 ms for a response. If no |
| 319 |
NAT-PMP response is received from the gateway after 250 ms, the |
| 320 |
client retransmits its request and waits 500 ms. The client SHOULD |
| 321 |
repeat this process with the interval between attempts doubling each |
| 322 |
time. If, after sending its ninth attempt (and then waiting for 64 |
| 323 |
seconds), the client has still received no response, then it SHOULD |
| 324 |
conclude that this gateway does not support NAT Port Mapping Protocol |
| 325 |
and MAY log an error message indicating this fact. In addition, if |
| 326 |
the NAT-PMP client receives an "ICMP Port Unreachable" message from |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
<span class="grey">Cheshire & Krochmal Informational [Page 6]</span></pre> |
| 333 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-7" ></span> |
| 334 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 335 |
|
| 336 |
|
| 337 |
the gateway for port 5351, then it can skip any remaining |
| 338 |
retransmissions and conclude immediately that the gateway does not |
| 339 |
support NAT-PMP. |
| 340 |
|
| 341 |
As a performance optimization the client MAY record this information |
| 342 |
and use it to suppress further attempts to use NAT-PMP, but the |
| 343 |
client should not retain this information for too long. In |
| 344 |
particular, any event that may indicate a potential change of gateway |
| 345 |
or a change in gateway configuration (hardware link change |
| 346 |
indication, change of gateway MAC address, acquisition of new DHCP |
| 347 |
lease, receipt of NAT-PMP announcement packet from gateway, etc.) |
| 348 |
should cause the client to discard its previous information regarding |
| 349 |
the gateway's lack of NAT-PMP support, and send its next NAT-PMP |
| 350 |
request packet normally. |
| 351 |
|
| 352 |
When deleting a port mapping, the client uses the same initial 250 ms |
| 353 |
timeout, doubling on each successive interval, except that clients |
| 354 |
may choose not to try the full nine times before giving up. This is |
| 355 |
because mapping deletion requests are in some sense advisory. They |
| 356 |
are useful for efficiency, but not required for correctness; it is |
| 357 |
always possible for client software to crash, or for power to fail, |
| 358 |
or for a client device to be physically unplugged from the network |
| 359 |
before it gets a chance to send its mapping deletion request(s), so |
| 360 |
NAT gateways already need to cope with this case. Because of this, |
| 361 |
it may be acceptable for a client to retry only once or twice before |
| 362 |
giving up on deleting its port mapping(s), but a client SHOULD always |
| 363 |
send at least one deletion request whenever possible, to reduce the |
| 364 |
amount of stale state that accumulates on NAT gateways. |
| 365 |
|
| 366 |
A client need not continue trying to delete a port mapping after the |
| 367 |
time when that mapping would naturally have expired anyway. |
| 368 |
|
| 369 |
<span class="h3"><a class="selflink" id="section-3.2" href="#section-3.2">3.2</a>. Determining the External Address</span> |
| 370 |
|
| 371 |
To determine the external address, the client behind the NAT sends |
| 372 |
the following UDP payload to port 5351 of the configured gateway |
| 373 |
address: |
| 374 |
|
| 375 |
0 1 |
| 376 |
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 |
| 377 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 378 |
| Vers = 0 | OP = 0 | |
| 379 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
<span class="grey">Cheshire & Krochmal Informational [Page 7]</span></pre> |
| 389 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-8" ></span> |
| 390 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 391 |
|
| 392 |
|
| 393 |
A compatible NAT gateway MUST generate a response with the following |
| 394 |
format: |
| 395 |
|
| 396 |
0 1 2 3 |
| 397 |
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 |
| 398 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 399 |
| Vers = 0 | OP = 128 + 0 | Result Code (net byte order) | |
| 400 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 401 |
| Seconds Since Start of Epoch (in network byte order) | |
| 402 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 403 |
| External IPv4 Address (a.b.c.d) | |
| 404 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 405 |
|
| 406 |
This response indicates that the NAT gateway implements this version |
| 407 |
of the protocol, and returns the external IPv4 address of the NAT |
| 408 |
gateway. If the result code is non-zero, the value of the External |
| 409 |
IPv4 Address field is undefined (MUST be set to zero on transmission, |
| 410 |
and MUST be ignored on reception). |
| 411 |
|
| 412 |
The NAT gateway MUST fill in the Seconds Since Start of Epoch field |
| 413 |
with the time elapsed since its port mapping table was initialized on |
| 414 |
startup, or reset for any other reason (see <a href="#section-3.6">Section 3.6</a>, "Seconds |
| 415 |
Since Start of Epoch"). |
| 416 |
|
| 417 |
Upon receiving a response packet, the client MUST check the source IP |
| 418 |
address, and silently discard the packet if the address is not the |
| 419 |
address of the gateway to which the request was sent. |
| 420 |
|
| 421 |
<span class="h4"><a class="selflink" id="section-3.2.1" href="#section-3.2.1">3.2.1</a>. Announcing Address Changes</span> |
| 422 |
|
| 423 |
Upon boot, acquisition of an external IPv4 address, subsequent change |
| 424 |
of the external IPv4 address, reboot, or any other event that may |
| 425 |
indicate possible loss or change of NAT mapping state, the NAT |
| 426 |
gateway MUST send a gratuitous response to the link-local multicast |
| 427 |
address 224.0.0.1, port 5350, with the packet format above, to notify |
| 428 |
clients of the external IPv4 address and Seconds Since Start of |
| 429 |
Epoch. |
| 430 |
|
| 431 |
To accommodate packet loss, the NAT gateway SHOULD multicast 10 |
| 432 |
address notifications. The interval between the first two |
| 433 |
notifications SHOULD be 250 ms, and the interval between each |
| 434 |
subsequent notification SHOULD double. The Seconds Since Start of |
| 435 |
Epoch field in each transmission MUST be updated appropriately to |
| 436 |
reflect the passage of time, so as not to trigger unnecessary |
| 437 |
additional mapping renewals (see <a href="#section-3.7">Section 3.7</a>, "Recreating Mappings on |
| 438 |
NAT Gateway Reboot"). |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
<span class="grey">Cheshire & Krochmal Informational [Page 8]</span></pre> |
| 445 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-9" ></span> |
| 446 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 447 |
|
| 448 |
|
| 449 |
Upon receiving a gratuitous address announcement packet, the client |
| 450 |
MUST check the source IP address, and silently discard the packet if |
| 451 |
the address is not the address of the client's current configured |
| 452 |
gateway. This is to guard against inadvertent misconfigurations |
| 453 |
where there may be more than one NAT gateway active on the network. |
| 454 |
|
| 455 |
If the source IP address is correct, then the Seconds Since Start of |
| 456 |
Epoch field is checked as described in <a href="#section-3.6">Section 3.6</a>, and if the value |
| 457 |
is outside the expected plausible range, indicating that a NAT |
| 458 |
gateway state loss has occurred, then the NAT-PMP client promptly |
| 459 |
recreates all its active port mapping leases, as described in <a href="#section-3.7">Section</a> |
| 460 |
<a href="#section-3.7">3.7</a>, "Recreating Mappings on NAT Gateway Reboot". |
| 461 |
|
| 462 |
IMPLEMENTATION NOTE: Earlier implementations of NAT-PMP used UDP port |
| 463 |
5351 as the destination both for client requests (address and port |
| 464 |
mapping) and for address announcements. NAT-PMP servers would listen |
| 465 |
on UDP 5351 for client requests, and NAT-PMP clients would listen on |
| 466 |
UDP 5351 for server announcements. However, implementers encountered |
| 467 |
difficulties when a single device is acting in both roles, for |
| 468 |
example, a home computer with Internet Sharing enabled. This |
| 469 |
computer is acting in the role of NAT-PMP server to its DHCP clients, |
| 470 |
yet, at the same time, it has to act in the role of NAT-PMP client in |
| 471 |
order to determine whether it is, itself, behind another NAT gateway. |
| 472 |
While in principle it might be possible on some operating systems for |
| 473 |
two processes to coordinate sharing of a single UDP port, on many |
| 474 |
platforms this is difficult or even impossible, so, for pragmatic |
| 475 |
engineering reasons, it is convenient to have clients listen on UDP |
| 476 |
5350 and servers listen on UDP 5351. |
| 477 |
|
| 478 |
IMPLEMENTATION NOTE: A given host may have more than one independent |
| 479 |
NAT-PMP client running at the same time, and address announcements |
| 480 |
need to be available to all of them. Clients should therefore set |
| 481 |
the SO_REUSEPORT option or equivalent in order to allow other |
| 482 |
processes to also listen on port 5350. Additionally, implementers |
| 483 |
have encountered issues when one or more processes on the same device |
| 484 |
listen to port 5350 on *all* addresses. Clients should therefore |
| 485 |
bind specifically to 224.0.0.1:5350, not to 0.0.0.0:5350. |
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
<span class="grey">Cheshire & Krochmal Informational [Page 9]</span></pre> |
| 501 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-10" ></span> |
| 502 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 503 |
|
| 504 |
|
| 505 |
<span class="h3"><a class="selflink" id="section-3.3" href="#section-3.3">3.3</a>. Requesting a Mapping</span> |
| 506 |
|
| 507 |
To create a mapping, the client sends a UDP packet to port 5351 of |
| 508 |
the gateway's internal IP address with the following format: |
| 509 |
|
| 510 |
0 1 2 3 |
| 511 |
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 |
| 512 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 513 |
| Vers = 0 | OP = x | Reserved | |
| 514 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 515 |
| Internal Port | Suggested External Port | |
| 516 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 517 |
| Requested Port Mapping Lifetime in Seconds | |
| 518 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 519 |
|
| 520 |
Opcodes supported: |
| 521 |
1 - Map UDP |
| 522 |
2 - Map TCP |
| 523 |
|
| 524 |
The Reserved field MUST be set to zero on transmission and MUST be |
| 525 |
ignored on reception. |
| 526 |
|
| 527 |
The Ports and Lifetime are transmitted in the traditional network |
| 528 |
byte order (i.e., most significant byte first). |
| 529 |
|
| 530 |
The Internal Port is set to the local port on which the client is |
| 531 |
listening. |
| 532 |
|
| 533 |
If the client would prefer to have a high-numbered "anonymous" |
| 534 |
external port assigned, then it should set the Suggested External |
| 535 |
Port to zero, which indicates to the gateway that it should allocate |
| 536 |
a high-numbered port of its choosing. If the client would prefer |
| 537 |
instead to have the mapped external port be the same as its local |
| 538 |
internal port if possible (e.g., a web server listening on port 80 |
| 539 |
that would ideally like to have external port 80), then it should set |
| 540 |
the Suggested External Port to the desired value. However, the |
| 541 |
gateway is not obliged to assign the port suggested, and may choose |
| 542 |
not to, either for policy reasons (e.g., port 80 is reserved and |
| 543 |
clients may not request it) or because that port has already been |
| 544 |
assigned to some other client. Because of this, some product |
| 545 |
developers have questioned the value of having the Suggested External |
| 546 |
Port field at all. The reason is for failure recovery. Most low- |
| 547 |
cost home NAT gateways do not record temporary port mappings in |
| 548 |
persistent storage, so if the gateway crashes or is rebooted, all the |
| 549 |
mappings are lost. A renewal packet is formatted identically to an |
| 550 |
initial mapping request packet, except that for renewals the client |
| 551 |
sets the Suggested External Port field to the port the gateway |
| 552 |
actually assigned, rather than the port the client originally wanted. |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
<span class="grey">Cheshire & Krochmal Informational [Page 10]</span></pre> |
| 557 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-11" ></span> |
| 558 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 559 |
|
| 560 |
|
| 561 |
When a freshly rebooted NAT gateway receives a renewal packet from a |
| 562 |
client, it appears to the gateway just like an ordinary initial |
| 563 |
request for a port mapping, except that in this case the Suggested |
| 564 |
External Port is likely to be one that the NAT gateway *is* willing |
| 565 |
to allocate (it allocated it to this client right before the reboot, |
| 566 |
so it should presumably be willing to allocate it again). This |
| 567 |
improves the stability of external ports across NAT gateway restarts. |
| 568 |
|
| 569 |
The RECOMMENDED Port Mapping Lifetime is 7200 seconds (two hours). |
| 570 |
|
| 571 |
After sending the port mapping request, the client then waits for the |
| 572 |
NAT gateway to respond. If after 250 ms the client hasn't received a |
| 573 |
response from the gateway, the client SHOULD reissue its request as |
| 574 |
described above in <a href="#section-3.1">Section 3.1</a>, "Requests and Responses". |
| 575 |
|
| 576 |
The NAT gateway responds with the following packet format: |
| 577 |
|
| 578 |
0 1 2 3 |
| 579 |
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 |
| 580 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 581 |
| Vers = 0 | OP = 128 + x | Result Code | |
| 582 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 583 |
| Seconds Since Start of Epoch | |
| 584 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 585 |
| Internal Port | Mapped External Port | |
| 586 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 587 |
| Port Mapping Lifetime in Seconds | |
| 588 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 589 |
|
| 590 |
The epoch time, ports, and lifetime are transmitted in the |
| 591 |
traditional network byte order (i.e., most significant byte first). |
| 592 |
|
| 593 |
The 'x' in the OP field MUST match what the client requested. Some |
| 594 |
NAT gateways are incapable of creating a UDP port mapping without |
| 595 |
also creating a corresponding TCP port mapping, and vice versa, and |
| 596 |
these gateways MUST NOT implement NAT Port Mapping Protocol until |
| 597 |
this deficiency is fixed. A NAT gateway that implements this |
| 598 |
protocol MUST be able to create TCP-only and UDP-only port mappings. |
| 599 |
If a NAT gateway silently creates a pair of mappings for a client |
| 600 |
that only requested one mapping, then it may expose that client to |
| 601 |
receiving inbound UDP packets or inbound TCP connection requests that |
| 602 |
it did not ask for and does not want. |
| 603 |
|
| 604 |
While a NAT gateway MUST NOT automatically create mappings for TCP |
| 605 |
when the client requests UDP, and vice versa, the NAT gateway MUST |
| 606 |
reserve the companion port so the same client can choose to map it in |
| 607 |
the future. For example, if a client requests to map TCP port 80, |
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
<span class="grey">Cheshire & Krochmal Informational [Page 11]</span></pre> |
| 613 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-12" ></span> |
| 614 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 615 |
|
| 616 |
|
| 617 |
as long as the client maintains the lease for that TCP port mapping, |
| 618 |
another client with a different internal IP address MUST NOT be able |
| 619 |
to successfully acquire the mapping for UDP port 80. |
| 620 |
|
| 621 |
The client normally requests the external port matching the internal |
| 622 |
port. If that external port is not available, the NAT gateway MUST |
| 623 |
return an available external port if possible, or return an error |
| 624 |
code if no external ports are available. |
| 625 |
|
| 626 |
The source address of the packet MUST be used for the internal |
| 627 |
address in the mapping. This protocol is not intended to facilitate |
| 628 |
one device behind a NAT creating mappings for other devices. If |
| 629 |
there are legacy devices that require inbound mappings, permanent |
| 630 |
mappings can be created manually by the user through an |
| 631 |
administrative interface, just as they are today. |
| 632 |
|
| 633 |
If a mapping already exists for a given internal address and port |
| 634 |
(whether that mapping was created explicitly using NAT-PMP, |
| 635 |
implicitly as a result of an outgoing TCP SYN packet, or manually by |
| 636 |
a human administrator) and that client requests another mapping for |
| 637 |
the same internal port (possibly requesting a different external |
| 638 |
port), then the mapping request should succeed, returning the |
| 639 |
already-assigned external port. This is necessary to handle the case |
| 640 |
where a client requests a mapping with suggested external port X, and |
| 641 |
is granted a mapping with actual external port Y, but the |
| 642 |
acknowledgment packet gets lost. When the client retransmits its |
| 643 |
mapping request, it should get back the same positive acknowledgment |
| 644 |
as was sent (and lost) the first time. |
| 645 |
|
| 646 |
The NAT gateway MUST NOT accept mapping requests destined to the NAT |
| 647 |
gateway's external IP address or received on its external network |
| 648 |
interface. Only packets received on the internal interface(s) with a |
| 649 |
destination address matching the internal address(es) of the NAT |
| 650 |
gateway should be allowed. |
| 651 |
|
| 652 |
The NAT gateway MUST fill in the Seconds Since Start of Epoch field |
| 653 |
with the time elapsed since its port mapping table was initialized on |
| 654 |
startup or reset for any other reason (see <a href="#section-3.6">Section 3.6</a>, "Seconds |
| 655 |
Since Start of Epoch"). |
| 656 |
|
| 657 |
The Port Mapping Lifetime is an unsigned integer in seconds. The NAT |
| 658 |
gateway MAY reduce the lifetime from what the client requested. The |
| 659 |
NAT gateway SHOULD NOT offer a lease lifetime greater than that |
| 660 |
requested by the client. |
| 661 |
|
| 662 |
Upon receiving the response packet, the client MUST check the source |
| 663 |
IP address, and silently discard the packet if the address is not the |
| 664 |
address of the gateway to which the request was sent. |
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
<span class="grey">Cheshire & Krochmal Informational [Page 12]</span></pre> |
| 669 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-13" ></span> |
| 670 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 671 |
|
| 672 |
|
| 673 |
The client SHOULD begin trying to renew the mapping halfway to expiry |
| 674 |
time, like DHCP. The renewal packet should look exactly the same as |
| 675 |
a request packet, except that the client SHOULD set the Suggested |
| 676 |
External Port to what the NAT gateway previously mapped, not what the |
| 677 |
client originally suggested. As described above, this enables the |
| 678 |
gateway to automatically recover its mapping state after a crash or |
| 679 |
reboot. |
| 680 |
|
| 681 |
<span class="h3"><a class="selflink" id="section-3.4" href="#section-3.4">3.4</a>. Destroying a Mapping</span> |
| 682 |
|
| 683 |
A mapping may be destroyed in a variety of ways. If a client fails |
| 684 |
to renew a mapping, then at the time its lifetime expires, the |
| 685 |
mapping MUST be automatically deleted. In the common case where the |
| 686 |
gateway device is a combined DHCP server and NAT gateway, when a |
| 687 |
client's DHCP address lease expires, the gateway device MAY |
| 688 |
automatically delete any mappings belonging to that client. |
| 689 |
Otherwise, a new client being assigned the same IP address could |
| 690 |
receive unexpected inbound UDP packets or inbound TCP connection |
| 691 |
requests that it did not ask for and does not want. |
| 692 |
|
| 693 |
A client MAY also send an explicit packet to request deletion of a |
| 694 |
mapping that is no longer needed. A client requests explicit |
| 695 |
deletion of a mapping by sending a message to the NAT gateway |
| 696 |
requesting the mapping, with the Requested Lifetime in Seconds set to |
| 697 |
zero. The Suggested External Port MUST be set to zero by the client |
| 698 |
on sending, and MUST be ignored by the gateway on reception. |
| 699 |
|
| 700 |
When a mapping is destroyed successfully as a result of the client |
| 701 |
explicitly requesting the deletion, the NAT gateway MUST send a |
| 702 |
response packet that is formatted as defined in <a href="#section-3.3">Section 3.3</a>, |
| 703 |
"Requesting a Mapping". The response MUST contain a result code of |
| 704 |
0, the internal port as indicated in the deletion request, an |
| 705 |
external port of 0, and a lifetime of 0. The NAT gateway MUST |
| 706 |
respond to a request to destroy a mapping that does not exist as if |
| 707 |
the request were successful. This is because of the case where the |
| 708 |
acknowledgment is lost, and the client retransmits its request to |
| 709 |
delete the mapping. In this case, the second request to delete the |
| 710 |
mapping MUST return the same response packet as the first request. |
| 711 |
|
| 712 |
If the deletion request was unsuccessful, the response MUST contain a |
| 713 |
non-zero result code and the requested mapping; the lifetime is |
| 714 |
undefined (MUST be set to zero on transmission, and MUST be ignored |
| 715 |
on reception). If the client attempts to delete a port mapping that |
| 716 |
was manually assigned by some kind of configuration tool, the NAT |
| 717 |
gateway MUST respond with a "Not Authorized" error, result code 2. |
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
<span class="grey">Cheshire & Krochmal Informational [Page 13]</span></pre> |
| 725 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-14" ></span> |
| 726 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 727 |
|
| 728 |
|
| 729 |
When a mapping is destroyed as a result of its lifetime expiring or |
| 730 |
for any other reason, if the NAT gateway's internal state indicates |
| 731 |
that there are still active TCP connections traversing that now- |
| 732 |
defunct mapping, then the NAT gateway SHOULD send appropriately |
| 733 |
constructed TCP RST (reset) packets both to the local client and to |
| 734 |
the remote peer on the Internet to terminate that TCP connection. |
| 735 |
|
| 736 |
A client can request the explicit deletion of all its UDP or TCP |
| 737 |
mappings by sending the same deletion request to the NAT gateway with |
| 738 |
the external port, internal port, and lifetime set to zero. A client |
| 739 |
MAY choose to do this when it first acquires a new IP address in |
| 740 |
order to protect itself from port mappings that were performed by a |
| 741 |
previous owner of the IP address. After receiving such a deletion |
| 742 |
request, the gateway MUST delete all its UDP or TCP port mappings |
| 743 |
(depending on the opcode). The gateway responds to such a deletion |
| 744 |
request with a response as described above, with the internal port |
| 745 |
set to zero. If the gateway is unable to delete a port mapping, for |
| 746 |
example, because the mapping was manually configured by the |
| 747 |
administrator, the gateway MUST still delete as many port mappings as |
| 748 |
possible, but respond with a non-zero result code. The exact result |
| 749 |
code to return depends on the cause of the failure. If the gateway |
| 750 |
is able to successfully delete all port mappings as requested, it |
| 751 |
MUST respond with a result code of zero. |
| 752 |
|
| 753 |
<span class="h3"><a class="selflink" id="section-3.5" href="#section-3.5">3.5</a>. Result Codes</span> |
| 754 |
|
| 755 |
Currently defined result codes: |
| 756 |
|
| 757 |
0 - Success |
| 758 |
1 - Unsupported Version |
| 759 |
2 - Not Authorized/Refused |
| 760 |
(e.g., box supports mapping, but user has turned feature off) |
| 761 |
3 - Network Failure |
| 762 |
(e.g., NAT box itself has not obtained a DHCP lease) |
| 763 |
4 - Out of resources |
| 764 |
(NAT box cannot create any more mappings at this time) |
| 765 |
5 - Unsupported opcode |
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
<span class="grey">Cheshire & Krochmal Informational [Page 14]</span></pre> |
| 781 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-15" ></span> |
| 782 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 783 |
|
| 784 |
|
| 785 |
If the version in the request is not zero, then the NAT-PMP server |
| 786 |
MUST return the following "Unsupported Version" error response to the |
| 787 |
client: |
| 788 |
|
| 789 |
0 1 2 3 |
| 790 |
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 |
| 791 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 792 |
| Vers = 0 | OP = 0 | Result Code = 1 | |
| 793 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 794 |
| Seconds Since Start of Epoch (in network byte order) | |
| 795 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 796 |
|
| 797 |
If the opcode in the request is 128 or greater, then this is not a |
| 798 |
request; it's a response, and the NAT-PMP server MUST silently ignore |
| 799 |
it. Otherwise, if the opcode in the request is less than 128, but is |
| 800 |
not a supported opcode (currently 0, 1, or 2), then the entire |
| 801 |
request MUST be returned to the sender, with the top bit of the |
| 802 |
opcode set (to indicate that this is a response) and the result code |
| 803 |
set to 5 (Unsupported opcode). |
| 804 |
|
| 805 |
For version 0 and a supported opcode (0, 1, or 2), if the operation |
| 806 |
fails for some reason (Not Authorized, Network Failure, or Out of |
| 807 |
resources), then a valid response MUST be sent to the client, with |
| 808 |
the top bit of the opcode set (to indicate that this is a response) |
| 809 |
and the result code set appropriately. Other fields in the response |
| 810 |
MUST be set appropriately. Specifically: |
| 811 |
|
| 812 |
o Seconds Since Start of Epoch MUST be set correctly |
| 813 |
|
| 814 |
o The External IPv4 Address should be set to the correct address, or |
| 815 |
to 0.0.0.0, as appropriate. |
| 816 |
|
| 817 |
o The Internal Port MUST be set to the client's requested Internal |
| 818 |
Port. This is particularly important, because the client needs |
| 819 |
this information to identify which request suffered the failure. |
| 820 |
|
| 821 |
o The Mapped External Port and Port Mapping Lifetime MUST be set |
| 822 |
appropriately -- i.e., zero if no successful port mapping was |
| 823 |
created. |
| 824 |
|
| 825 |
Should future NAT-PMP opcodes be defined, their error responses MUST |
| 826 |
similarly be specified to include sufficient information to identify |
| 827 |
which request suffered the failure. By design, NAT-PMP messages do |
| 828 |
not contain any transaction identifiers. All NAT-PMP messages are |
| 829 |
idempotent and self-describing; therefore, the specifications of |
| 830 |
future NAT-PMP messages need to include enough information for their |
| 831 |
responses to be self-describing. |
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
<span class="grey">Cheshire & Krochmal Informational [Page 15]</span></pre> |
| 837 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-16" ></span> |
| 838 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 839 |
|
| 840 |
|
| 841 |
Clients MUST be able to properly handle result codes not defined in |
| 842 |
this document. Undefined results codes MUST be treated as fatal |
| 843 |
errors of the request. |
| 844 |
|
| 845 |
<span class="h3"><a class="selflink" id="section-3.6" href="#section-3.6">3.6</a>. Seconds Since Start of Epoch</span> |
| 846 |
|
| 847 |
Every packet sent by the NAT gateway includes a Seconds Since Start |
| 848 |
of Epoch (SSSoE) field. If the NAT gateway resets or loses the state |
| 849 |
of its port mapping table, due to reboot, power failure, or any other |
| 850 |
reason, it MUST reset its epoch time and begin counting SSSoE from |
| 851 |
zero again. Whenever a client receives any packet from the NAT |
| 852 |
gateway, either unsolicited or in response to a client request, the |
| 853 |
client computes its own conservative estimate of the expected SSSoE |
| 854 |
value by taking the SSSoE value in the last packet it received from |
| 855 |
the gateway and adding 7/8 (87.5%) of the time elapsed according to |
| 856 |
the client's local clock since that packet was received. If the |
| 857 |
SSSoE in the newly received packet is less than the client's |
| 858 |
conservative estimate by more than 2 seconds, then the client |
| 859 |
concludes that the NAT gateway has undergone a reboot or other loss |
| 860 |
of port mapping state, and the client MUST immediately renew all its |
| 861 |
active port mapping leases as described in <a href="#section-3.7">Section 3.7</a>, "Recreating |
| 862 |
Mappings on NAT Gateway Reboot". |
| 863 |
|
| 864 |
<span class="h3"><a class="selflink" id="section-3.7" href="#section-3.7">3.7</a>. Recreating Mappings on NAT Gateway Reboot</span> |
| 865 |
|
| 866 |
The NAT gateway MAY store mappings in persistent storage so that, |
| 867 |
when it is powered off or rebooted, it remembers the port mapping |
| 868 |
state of the network. |
| 869 |
|
| 870 |
However, maintaining this state is not essential for correct |
| 871 |
operation. When the NAT gateway powers on or clears its port mapping |
| 872 |
state as the result of a configuration change, it MUST reset the |
| 873 |
epoch time and re-announce its IPv4 address as described in <a href="#section-3.2.1">Section</a> |
| 874 |
<a href="#section-3.2.1">3.2.1</a>, "Announcing Address Changes". Reception of this packet where |
| 875 |
time has apparently gone backwards serves as a hint to clients on the |
| 876 |
network that they SHOULD immediately send renewal packets (to |
| 877 |
immediately recreate their mappings) instead of waiting until the |
| 878 |
originally scheduled time for those renewals. Clients who miss |
| 879 |
receiving those gateway announcement packets for any reason will |
| 880 |
still renew their mappings at the originally scheduled time and cause |
| 881 |
their mappings to be recreated; it will just take a little longer for |
| 882 |
these clients. |
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
<span class="grey">Cheshire & Krochmal Informational [Page 16]</span></pre> |
| 893 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-17" ></span> |
| 894 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 895 |
|
| 896 |
|
| 897 |
A mapping renewal packet is formatted identically to an original |
| 898 |
mapping request; from the point of view of the client, it is a |
| 899 |
renewal of an existing mapping, but from the point of view of the |
| 900 |
freshly rebooted NAT gateway, it appears as a new mapping request. |
| 901 |
|
| 902 |
This self-healing property of the protocol is very important. |
| 903 |
|
| 904 |
The remarkable reliability of the Internet as a whole derives in |
| 905 |
large part from the fact that important state is held in the |
| 906 |
endpoints, not in the network itself [<a href="#ref-ETEAISD" title=""End-to-end arguments in system design"">ETEAISD</a>]. Power-cycling an |
| 907 |
Ethernet switch results only in a brief interruption in the flow of |
| 908 |
packets; established TCP connections through that switch are not |
| 909 |
broken, merely delayed for a few seconds. Indeed, a failing Ethernet |
| 910 |
switch can even be replaced with a new one, and as long as the cables |
| 911 |
are transferred over reasonably quickly, after the upgrade all the |
| 912 |
TCP connections that were previously going through the old switch |
| 913 |
will be unbroken and now going through the new one. The same is true |
| 914 |
of IP routers, wireless base stations, etc. The one exception is NAT |
| 915 |
gateways. Because the port mapping state is required for the NAT |
| 916 |
gateway to know where to forward inbound packets, loss of that state |
| 917 |
breaks connectivity through the NAT gateway. By allowing clients to |
| 918 |
detect when this loss of NAT gateway state has occurred, and recreate |
| 919 |
it on demand, we turn hard state in the network into soft state, and |
| 920 |
allow it to be recovered automatically when needed. |
| 921 |
|
| 922 |
Without this automatic recreation of soft state in the NAT gateway, |
| 923 |
reliable long-term networking would not be achieved. As mentioned |
| 924 |
above, the reliability of the Internet does not come from trying to |
| 925 |
build a perfect network in which errors never happen, but from |
| 926 |
accepting that in any sufficiently large system there will always be |
| 927 |
some component somewhere that's failing, and designing mechanisms |
| 928 |
that can handle those failures and recover. To illustrate this point |
| 929 |
with an example, consider the following scenario: Imagine a network |
| 930 |
security camera that has a web interface and accepts incoming |
| 931 |
connections from web browser clients. Imagine this network security |
| 932 |
camera uses NAT-PMP or a similar protocol to set up an inbound port |
| 933 |
mapping in the NAT gateway so that it can receive incoming |
| 934 |
connections from clients on the other side of the NAT gateway. Now, |
| 935 |
this camera may well operate for weeks, months, or even years. |
| 936 |
During that time, it's possible that the NAT gateway could experience |
| 937 |
a power failure or be rebooted. The user could upgrade the NAT |
| 938 |
gateway's firmware, or even replace the entire NAT gateway device |
| 939 |
with a newer model. The general point is that if the camera operates |
| 940 |
for a long enough period of time, some kind of disruption to the NAT |
| 941 |
gateway becomes inevitable. The question is not whether the NAT |
| 942 |
gateway will lose its port mappings, but when, and how often. If the |
| 943 |
network camera and devices like it on the network can detect when the |
| 944 |
NAT gateway has lost its port mappings, and recreate them |
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
<span class="grey">Cheshire & Krochmal Informational [Page 17]</span></pre> |
| 949 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-18" ></span> |
| 950 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 951 |
|
| 952 |
|
| 953 |
automatically, then these disruptions are self-correcting and largely |
| 954 |
invisible to the end user. If, on the other hand, the disruptions |
| 955 |
are not self-correcting, and after a NAT gateway reboot the user has |
| 956 |
to manually reset or reboot all the other devices on the network too, |
| 957 |
then these disruptions are *very* visible to the end user. This |
| 958 |
aspect of the design is part of what makes the difference between a |
| 959 |
protocol that keeps on working indefinitely over a time scale of |
| 960 |
months or years, and a protocol that works in brief testing, but in |
| 961 |
the real world is continually failing and requiring manual |
| 962 |
intervention to get it going again. |
| 963 |
|
| 964 |
When a client renews its port mappings as the result of receiving a |
| 965 |
packet where the Seconds Since Start of Epoch (SSSoE) field indicates |
| 966 |
that a reboot or similar loss of state has occurred, the client MUST |
| 967 |
first delay by a random amount of time selected with uniform random |
| 968 |
distribution in the range 0 to 5 seconds, and then send its first |
| 969 |
port mapping request. After that request is acknowledged by the |
| 970 |
gateway, the client may then send its second request, and so on, as |
| 971 |
rapidly as the gateway allows. The requests SHOULD be issued |
| 972 |
serially, one at a time; the client SHOULD NOT issue multiple |
| 973 |
concurrent requests. |
| 974 |
|
| 975 |
The discussion in this section focuses on recreating inbound port |
| 976 |
mappings after loss of NAT gateway state, because that is the more |
| 977 |
serious problem. Losing port mappings for outgoing connections |
| 978 |
destroys those currently active connections, but does not prevent |
| 979 |
clients from establishing new outgoing connections. In contrast, |
| 980 |
losing inbound port mappings not only destroys all existing inbound |
| 981 |
connections, but also prevents the reception of any new inbound |
| 982 |
connections until the port mapping is recreated. Accordingly, we |
| 983 |
consider recovery of inbound port mappings more important. However, |
| 984 |
clients that want outgoing connections to survive a NAT gateway |
| 985 |
reboot can also achieve that using NAT-PMP, in the common case of a |
| 986 |
residential NAT gateway with a single, relatively stable, external IP |
| 987 |
address. After initiating an outbound TCP connection (which will |
| 988 |
cause the NAT gateway to establish an implicit port mapping), the |
| 989 |
client should send the NAT gateway a port mapping request for the |
| 990 |
source port of its TCP connection, which will cause the NAT gateway |
| 991 |
to send a response giving the external port it allocated for that |
| 992 |
mapping. The client can then store this information, and use it |
| 993 |
later to recreate the mapping if it determines that the NAT gateway |
| 994 |
has lost its mapping state. |
| 995 |
|
| 996 |
<span class="h3"><a class="selflink" id="section-3.8" href="#section-3.8">3.8</a>. NAT Gateways with NAT Function Disabled</span> |
| 997 |
|
| 998 |
Note that only devices that are *currently* acting in the role of NAT |
| 999 |
gateway should participate in NAT-PMP protocol exchanges with |
| 1000 |
clients. A network device that is capable of NAT (and NAT-PMP) but |
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
<span class="grey">Cheshire & Krochmal Informational [Page 18]</span></pre> |
| 1005 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-19" ></span> |
| 1006 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 1007 |
|
| 1008 |
|
| 1009 |
is currently configured not to perform that function (e.g., it is |
| 1010 |
acting as a traditional IP router, forwarding packets without |
| 1011 |
modifying them) MUST NOT respond to NAT-PMP requests from clients nor |
| 1012 |
send spontaneous NAT-PMP address-change announcements. |
| 1013 |
|
| 1014 |
In particular, a network device not currently acting in the role of |
| 1015 |
NAT gateway should not even respond to NAT-PMP requests by returning |
| 1016 |
an error code such as 2, "Not Authorized/Refused", since to do so is |
| 1017 |
misleading to clients -- it suggests that NAT port mapping is |
| 1018 |
necessary on this network for the client to successfully receive |
| 1019 |
inbound connections, but is not available because the administrator |
| 1020 |
has chosen to disable that functionality. |
| 1021 |
|
| 1022 |
Clients should also be careful to avoid making unfounded assumptions, |
| 1023 |
such as the assumption that if the client has an IPv4 address in one |
| 1024 |
of the private IPv4 address ranges [<a href="./rfc1918" title=""Address Allocation for Private Internets"">RFC1918</a>], then that means NAT |
| 1025 |
necessarily must be in use. Net 10/8 has enough addresses to build a |
| 1026 |
private network with millions of hosts and thousands of |
| 1027 |
interconnected subnets, all without any use of NAT. Many |
| 1028 |
organizations have built such private networks that benefit from |
| 1029 |
using standard TCP/IP technology, but by choice do not connect to the |
| 1030 |
public Internet. The purpose of NAT-PMP is to mitigate some of the |
| 1031 |
damage caused by NAT. It would be an ironic and unwanted side effect |
| 1032 |
of this protocol if it were to lead well-meaning but misguided |
| 1033 |
developers to create products that refuse to work on a private |
| 1034 |
network *unless* they can find a NAT gateway to talk to. |
| 1035 |
Consequently, a client finding that NAT-PMP is not available on its |
| 1036 |
network should not give up, but should proceed on the assumption that |
| 1037 |
the network may be a traditional routed IP network, with no address |
| 1038 |
translation being used. This assumption may not always be true, but |
| 1039 |
it is better than the alternative of falsely assuming the worst and |
| 1040 |
not even trying to use normal (non-NAT) IP networking. |
| 1041 |
|
| 1042 |
If a network device not currently acting in the role of NAT gateway |
| 1043 |
receives UDP packets addressed to port 5351, it SHOULD respond |
| 1044 |
immediately with an "ICMP Port Unreachable" message to tell the |
| 1045 |
client that it needn't continue with timeouts and retransmissions, |
| 1046 |
and it should assume that NAT-PMP is not available and not needed on |
| 1047 |
this network. Typically, this behavior can be achieved merely by not |
| 1048 |
having an open socket listening on UDP port 5351. |
| 1049 |
|
| 1050 |
<span class="h3"><a class="selflink" id="section-3.9" href="#section-3.9">3.9</a>. All Mappings Are Bidirectional</span> |
| 1051 |
|
| 1052 |
All NAT mappings, whether created implicitly by an outbound packet, |
| 1053 |
created explicitly using NAT-PMP, or configured statically, are |
| 1054 |
bidirectional. This means that when an outbound packet from a |
| 1055 |
particular internal address and port is translated to an external |
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
<span class="grey">Cheshire & Krochmal Informational [Page 19]</span></pre> |
| 1061 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-20" ></span> |
| 1062 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 1063 |
|
| 1064 |
|
| 1065 |
address and port, replies addressed to that external address and port |
| 1066 |
need to be translated back to the corresponding internal address and |
| 1067 |
port. |
| 1068 |
|
| 1069 |
The converse is also true. When an inbound packet is received that |
| 1070 |
is addressed to an external address and port that matches an existing |
| 1071 |
mapping (implicit, explicit, or static), it is translated to the |
| 1072 |
corresponding internal address and port and forwarded. Outbound |
| 1073 |
replies from that internal address and port need to be translated to |
| 1074 |
the correct external address and port so that they are correctly |
| 1075 |
recognized by the remote peer. |
| 1076 |
|
| 1077 |
In particular, if an outbound UDP reply that matches an existing |
| 1078 |
explicit or static mapping is instead treated like a "new" outbound |
| 1079 |
UDP packet, and a new dynamic mapping is created (with a different |
| 1080 |
external address and port), then at the time that packet arrives at |
| 1081 |
the remote peer it will not be recognized as a valid reply. For TCP |
| 1082 |
this bug is quickly spotted because all TCP implementations will |
| 1083 |
ignore replies with the wrong apparent source address and port. For |
| 1084 |
UDP this bug can more easily go unnoticed because some UDP clients |
| 1085 |
neglect to check the source address and port of replies; thus, they |
| 1086 |
will appear to work some of the time with NAT gateways that put the |
| 1087 |
wrong source address and port in outbound packets. All NAT gateways |
| 1088 |
MUST ensure that mappings, however created, are bidirectional. |
| 1089 |
|
| 1090 |
<span class="h2"><a class="selflink" id="section-4" href="#section-4">4</a>. UNSAF Considerations</span> |
| 1091 |
|
| 1092 |
The document "IAB Considerations for UNilateral Self-Address Fixing |
| 1093 |
(UNSAF) Across Network Address Translation (NAT)" [<a href="./rfc3424" title=""IAB Considerations for UNilateral Self-Address Fixing (UNSAF) Across Network Address Translation"">RFC3424</a>] covers a |
| 1094 |
number of issues when working with NATs. It outlines some |
| 1095 |
requirements for any document that attempts to work around problems |
| 1096 |
associated with NATs. This section addresses those requirements. |
| 1097 |
|
| 1098 |
<span class="h3"><a class="selflink" id="section-4.1" href="#section-4.1">4.1</a>. Scope</span> |
| 1099 |
|
| 1100 |
This protocol addresses the needs of TCP and UDP transport peers that |
| 1101 |
are separated from the public Internet by exactly one IPv4 NAT. Such |
| 1102 |
peers must have access to some form of directory server for |
| 1103 |
registering the public IPv4 address and port at which they can be |
| 1104 |
reached. |
| 1105 |
|
| 1106 |
<span class="h3"><a class="selflink" id="section-4.2" href="#section-4.2">4.2</a>. Transition Plan</span> |
| 1107 |
|
| 1108 |
Any client making use of this protocol SHOULD implement IPv6 support. |
| 1109 |
If a client supports IPv6 and is running on a device with a global |
| 1110 |
IPv6 address, that IPv6 address SHOULD be preferred to the IPv4 |
| 1111 |
external address learned via this NAT mapping protocol. In case |
| 1112 |
other clients do not have IPv6 connectivity, both the IPv4 and IPv6 |
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
<span class="grey">Cheshire & Krochmal Informational [Page 20]</span></pre> |
| 1117 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-21" ></span> |
| 1118 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 1119 |
|
| 1120 |
|
| 1121 |
addresses SHOULD be registered with whatever form of directory server |
| 1122 |
is used. Preference SHOULD be given to IPv6 addresses when |
| 1123 |
available. By implementing support for IPv6 and using this protocol |
| 1124 |
for IPv4, vendors can ship products today that will work under both |
| 1125 |
scenarios. As IPv6 becomes more widely deployed, clients of this |
| 1126 |
protocol following these recommendations will transparently make use |
| 1127 |
of IPv6. |
| 1128 |
|
| 1129 |
<span class="h3"><a class="selflink" id="section-4.3" href="#section-4.3">4.3</a>. Failure Cases</span> |
| 1130 |
|
| 1131 |
Aside from NATs that do not implement this protocol, there are a |
| 1132 |
number of situations where this protocol may not work. |
| 1133 |
|
| 1134 |
<span class="h4"><a class="selflink" id="section-4.3.1" href="#section-4.3.1">4.3.1</a>. NAT behind NAT</span> |
| 1135 |
|
| 1136 |
Some people's primary IPv4 address, assigned by their ISP, may itself |
| 1137 |
be a NAT address. In addition, some people may have an external IPv4 |
| 1138 |
address, but may then double NAT themselves, perhaps by choice or |
| 1139 |
perhaps by accident. Although it might be possible in principle for |
| 1140 |
one NAT gateway to recursively request a mapping from the next one, |
| 1141 |
this document does not advocate that and does not try to prescribe |
| 1142 |
how it would be done. |
| 1143 |
|
| 1144 |
It would be a lot of work to implement nested NAT port mapping |
| 1145 |
correctly, and there are a number of reasons why the end result might |
| 1146 |
not be as useful as we might hope. Consider the case of an ISP that |
| 1147 |
offers each of its customers only a single NAT address. This ISP |
| 1148 |
could instead have chosen to provide each customer with a single |
| 1149 |
public IPv4 address, or, if the ISP insists on running NAT, it could |
| 1150 |
have chosen to allow each customer a reasonable number of addresses, |
| 1151 |
enough for each customer device to have its own NAT address directly |
| 1152 |
from the ISP. If, instead, this ISP chooses to allow each customer |
| 1153 |
just one and only one NAT address, forcing said customer to run |
| 1154 |
nested NAT in order to use more than one device, it seems unlikely |
| 1155 |
that such an ISP would be so obliging as to provide a NAT service |
| 1156 |
that supports NAT-PMP. Supposing that such an ISP did wish to offer |
| 1157 |
its customers NAT service with NAT-PMP so as to give them the ability |
| 1158 |
to receive inbound connections, this ISP could easily choose to allow |
| 1159 |
each client to request a reasonable number of DHCP addresses from |
| 1160 |
that gateway. Remember that Net 10/8 [<a href="./rfc1918" title=""Address Allocation for Private Internets"">RFC1918</a>] allows for over 16 |
| 1161 |
million addresses, so NAT addresses are not in any way in short |
| 1162 |
supply. A single NAT gateway with 16 million available addresses is |
| 1163 |
likely to run out of packet forwarding capacity before it runs out of |
| 1164 |
internal addresses to hand out. In this way, the ISP could offer |
| 1165 |
single-level NAT with NAT-PMP, obviating the need to support nested |
| 1166 |
NAT-PMP. In addition, an ISP that is motivated to provide their |
| 1167 |
customers with unhindered access to the Internet by allowing incoming |
| 1168 |
as well as outgoing connections has better ways to offer this |
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
<span class="grey">Cheshire & Krochmal Informational [Page 21]</span></pre> |
| 1173 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-22" ></span> |
| 1174 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 1175 |
|
| 1176 |
|
| 1177 |
service. Such an ISP could offer its customers real public IPv4 |
| 1178 |
addresses instead of NAT addresses, or could choose to offer its |
| 1179 |
customers full IPv6 connectivity, where no mapping or translation is |
| 1180 |
required at all. |
| 1181 |
|
| 1182 |
Note: In the nine years since NAT-PMP was designed, the pool of |
| 1183 |
available IPv4 addresses has been exhausted, and many ISPs now offer |
| 1184 |
translated IPv4 addresses out of necessity. Such ISPs have indicated |
| 1185 |
a willingness to offer PCP service to their customers. |
| 1186 |
|
| 1187 |
<span class="h4"><a class="selflink" id="section-4.3.2" href="#section-4.3.2">4.3.2</a>. NATs with Multiple External IPv4 Addresses</span> |
| 1188 |
|
| 1189 |
If a NAT maps internal addresses to multiple external addresses, then |
| 1190 |
it SHOULD pick one of those external addresses as the one it will |
| 1191 |
support for inbound connections, and for the purposes of this |
| 1192 |
protocol it SHOULD act as if that address were its only address. |
| 1193 |
|
| 1194 |
<span class="h4"><a class="selflink" id="section-4.3.3" href="#section-4.3.3">4.3.3</a>. NATs and Routed Private Networks</span> |
| 1195 |
|
| 1196 |
In some cases, a large network may be subnetted. Some sites may |
| 1197 |
install a NAT gateway and subnet the private network. Such |
| 1198 |
subnetting breaks this protocol because the router address is not |
| 1199 |
necessarily the address of the device performing NAT. |
| 1200 |
|
| 1201 |
Addressing this problem is not a high priority. Any site with the |
| 1202 |
resources to set up such a configuration should have the resources to |
| 1203 |
add manual mappings or attain a range of globally unique addresses. |
| 1204 |
|
| 1205 |
Not all NATs will support this protocol. In the case where a client |
| 1206 |
is run behind a NAT that does not support this protocol, the software |
| 1207 |
relying on the functionality of this protocol may be unusable. |
| 1208 |
|
| 1209 |
<span class="h4"><a class="selflink" id="section-4.3.4" href="#section-4.3.4">4.3.4</a>. Communication between Hosts behind the Same NAT</span> |
| 1210 |
|
| 1211 |
NAT gateways supporting NAT-PMP should also implement "hairpin |
| 1212 |
translation". Hairpin translation means supporting communication |
| 1213 |
between two local clients being served by the same NAT gateway. |
| 1214 |
|
| 1215 |
Suppose device A is listening on internal address and port |
| 1216 |
10.0.0.2:80 for incoming connections. Using NAT-PMP, device A has |
| 1217 |
obtained a mapping to external address and port x.x.x.x:80, and has |
| 1218 |
recorded this external address and port in a public directory of some |
| 1219 |
kind. For example, it could have created a DNS SRV record containing |
| 1220 |
this information, and recorded it, using DNS Dynamic Update |
| 1221 |
[<a href="./rfc3007" title=""Secure Domain Name System (DNS) Dynamic Update"">RFC3007</a>], in a publicly accessible DNS server. Suppose then that |
| 1222 |
device B, behind the same NAT gateway as device A, but unknowing or |
| 1223 |
uncaring of this fact, retrieves device A's DNS SRV record and |
| 1224 |
attempts to open a TCP connection to x.x.x.x:80. The outgoing |
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
<span class="grey">Cheshire & Krochmal Informational [Page 22]</span></pre> |
| 1229 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-23" ></span> |
| 1230 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 1231 |
|
| 1232 |
|
| 1233 |
packets addressed to this public Internet address will be sent to the |
| 1234 |
NAT gateway for translation and forwarding. Having translated the |
| 1235 |
source address and port number on the outgoing packet, the NAT |
| 1236 |
gateway needs to be smart enough to recognize that the destination |
| 1237 |
address is in fact itself, and then feed this packet back into its |
| 1238 |
packet reception engine, to perform the destination port mapping |
| 1239 |
lookup to translate and forward this packet to device A at address |
| 1240 |
and port 10.0.0.2:80. |
| 1241 |
|
| 1242 |
<span class="h4"><a class="selflink" id="section-4.3.5" href="#section-4.3.5">4.3.5</a>. Non-UDP/TCP Transport Traffic</span> |
| 1243 |
|
| 1244 |
Any communication over transport protocols other than TCP and UDP |
| 1245 |
will not be served by this protocol. Examples are Generic Routing |
| 1246 |
Encapsulation (GRE), Authentication Header (AH), and Encapsulating |
| 1247 |
Security Payload (ESP). |
| 1248 |
|
| 1249 |
<span class="h3"><a class="selflink" id="section-4.4" href="#section-4.4">4.4</a>. Long-Term Solution</span> |
| 1250 |
|
| 1251 |
As IPv6 is deployed, clients of this protocol supporting IPv6 will be |
| 1252 |
able to bypass this protocol and the NAT when communicating with |
| 1253 |
other IPv6 devices. In order to ensure this transition, any client |
| 1254 |
implementing this protocol SHOULD also implement IPv6 and use this |
| 1255 |
solution only when IPv6 is not available to both peers. |
| 1256 |
|
| 1257 |
<span class="h3"><a class="selflink" id="section-4.5" href="#section-4.5">4.5</a>. Existing Deployed NATs</span> |
| 1258 |
|
| 1259 |
Existing deployed NATs will not support this protocol. This protocol |
| 1260 |
will only work with NATs that are upgraded to support it. |
| 1261 |
|
| 1262 |
<span class="h2"><a class="selflink" id="section-5" href="#section-5">5</a>. Security Considerations</span> |
| 1263 |
|
| 1264 |
As discussed in <a href="#section-3.2">Section 3.2</a>, "Determining the External Address", only |
| 1265 |
a client on the internal side of the NAT may create port mappings, |
| 1266 |
and it may do so only on its own behalf. By using IP address |
| 1267 |
spoofing, it's possible for one client to delete the port mappings of |
| 1268 |
another client. It's also possible for one client to create port |
| 1269 |
mappings on behalf of another client. In cases where this is a |
| 1270 |
concern, it can be dealt with using IPsec [<a href="./rfc4301" title=""Security Architecture for the Internet Protocol"">RFC4301</a>]. |
| 1271 |
|
| 1272 |
The multicast announcements described in <a href="#section-3.2.1">Section 3.2.1</a>, "Announcing |
| 1273 |
Address Changes", could be spoofed, facilitating a denial-of-service |
| 1274 |
attack. This makes NAT-PMP unsuitable for use on LANs with large |
| 1275 |
numbers of hosts where one or more of the hosts may be untrustworthy. |
| 1276 |
|
| 1277 |
Another concern is that rogue software running on a local host could |
| 1278 |
create port mappings for unsuspecting hosts, thereby rendering them |
| 1279 |
vulnerable to external attack. However, it's not clear how realistic |
| 1280 |
this threat model is, since rogue software on a local host could |
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
<span class="grey">Cheshire & Krochmal Informational [Page 23]</span></pre> |
| 1285 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-24" ></span> |
| 1286 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 1287 |
|
| 1288 |
|
| 1289 |
attack such unsuspecting hosts directly itself, without resorting to |
| 1290 |
such a convoluted indirect technique. This concern is also a little |
| 1291 |
misguided because it is based on the assumption that a NAT gateway |
| 1292 |
and a firewall are the same thing, which they are not. |
| 1293 |
|
| 1294 |
Some people view the property of NATs blocking inbound connections as |
| 1295 |
a security benefit that is undermined by this protocol. The authors |
| 1296 |
of this document have a different point of view. In the days before |
| 1297 |
NAT became prevalent, all hosts had unique public IP addresses, and |
| 1298 |
had unhindered ability to communicate with any other host on the |
| 1299 |
Internet (a configuration that is still surprisingly common). Using |
| 1300 |
NAT breaks this unhindered connectivity, relegating hosts to second- |
| 1301 |
class status, unable to receive inbound connections. This protocol |
| 1302 |
goes some way to partially reverse that damage. The purpose of a NAT |
| 1303 |
gateway should be to allow several hosts to share a single address, |
| 1304 |
not to simultaneously impede those host's ability to communicate |
| 1305 |
freely. Security is most properly provided by end-to-end |
| 1306 |
cryptographic security, and/or by explicit firewall functionality, as |
| 1307 |
appropriate. Blocking of certain connections should occur only as a |
| 1308 |
result of explicit and intentional firewall policy, not as an |
| 1309 |
accidental side effect of some other technology. |
| 1310 |
|
| 1311 |
However, since many users do have an expectation that their NAT |
| 1312 |
gateways can function as a kind of firewall, any NAT gateway |
| 1313 |
implementing this protocol SHOULD have an administrative mechanism to |
| 1314 |
disable it, thereby restoring the pre-NAT-PMP behavior. |
| 1315 |
|
| 1316 |
<span class="h2"><a class="selflink" id="section-6" href="#section-6">6</a>. IANA Considerations</span> |
| 1317 |
|
| 1318 |
UDP ports 5350 and 5351 have been assigned for use by NAT-PMP, and |
| 1319 |
subsequently by its successor, Port Control Protocol [<a href="./rfc6887" title=""Port Control Protocol (PCP)"">RFC6887</a>]. |
| 1320 |
|
| 1321 |
No further IANA services are required by this document. |
| 1322 |
|
| 1323 |
<span class="h2"><a class="selflink" id="section-7" href="#section-7">7</a>. Acknowledgments</span> |
| 1324 |
|
| 1325 |
The concepts described in this document have been explored, |
| 1326 |
developed, and implemented with help from Mark Baugher, Bob Bradley, |
| 1327 |
Josh Graessley, Rory McGuire, Rob Newberry, Roger Pantos, John |
| 1328 |
Saxton, Kiren Sekar, Jessica Vazquez, and James Woodyatt. |
| 1329 |
|
| 1330 |
Special credit goes to Mike Bell, the Apple Vice President who |
| 1331 |
recognized the need for a clean, elegant, reliable Port Mapping |
| 1332 |
Protocol, and made the decision early on that Apple's AirPort base |
| 1333 |
stations would support NAT-PMP. |
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
<span class="grey">Cheshire & Krochmal Informational [Page 24]</span></pre> |
| 1341 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-25" ></span> |
| 1342 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 1343 |
|
| 1344 |
|
| 1345 |
<span class="h2"><a class="selflink" id="section-8" href="#section-8">8</a>. Deployment History</span> |
| 1346 |
|
| 1347 |
In August 2004, NAT-PMP client software first became available to the |
| 1348 |
public through Apple's Darwin Open Source code. In April 2005, |
| 1349 |
NAT-PMP implementations began shipping to end users with the launch |
| 1350 |
of Mac OS X 10.4 Tiger and Bonjour for Windows 1.0, and in June 2005 |
| 1351 |
the protocol was first publicly documented in the original draft |
| 1352 |
version of this document. |
| 1353 |
|
| 1354 |
The NAT-PMP client in Mac OS X 10.4 Tiger and Bonjour for Windows |
| 1355 |
exists as part of the mDNSResponder/mdnsd system service. When a |
| 1356 |
client advertises a service using Wide Area Bonjour [<a href="./rfc6763" title=""DNS-Based Service Discovery"">RFC6763</a>], and |
| 1357 |
the machine is behind a NAT-PMP-capable NAT gateway, and the machine |
| 1358 |
is so configured, the mDNSResponder system service automatically uses |
| 1359 |
NAT-PMP to set up an inbound port mapping, and then records the |
| 1360 |
external IPv4 address and port in the global DNS. Existing client |
| 1361 |
software using the Bonjour programming APIs [<a href="#ref-Bonjour" title=""Bonjour"">Bonjour</a>] got this new |
| 1362 |
NAT traversal functionality automatically. The logic behind this |
| 1363 |
decision was that if client software publishes its information into |
| 1364 |
the global DNS via Wide Area Bonjour service advertising, then it's |
| 1365 |
reasonable to infer an expectation that this information should |
| 1366 |
actually be usable by the peers retrieving it. Generally speaking, |
| 1367 |
recording a private IPv4 address like 10.0.0.2 in the public DNS is |
| 1368 |
likely to be pointless because that address is not reachable from |
| 1369 |
clients on the other side of the NAT gateway. In the case of a home |
| 1370 |
user with a single computer directly connected to their Cable or DSL |
| 1371 |
modem, with a single global IPv4 address and no NAT gateway (a common |
| 1372 |
configuration at that time), publishing the machine's global IPv4 |
| 1373 |
address into the global DNS is useful, because that IPv4 address is |
| 1374 |
globally reachable. In contrast, a home user using a NAT gateway to |
| 1375 |
share a single global IPv4 address between several computers loses |
| 1376 |
this ability to receive inbound connections. This breaks many peer- |
| 1377 |
to-peer collaborative applications, like the multi-user text editor |
| 1378 |
SubEthaEdit [<a href="#ref-SEE">SEE</a>]. For many users, moving from one computer with a |
| 1379 |
global IPv4 address, to two computers using NAT to share a single |
| 1380 |
global IPv4 address, loss of inbound reachability was an unwanted |
| 1381 |
side effect of using NAT for address sharing. Automatically creating |
| 1382 |
the necessary inbound port mappings helped remedy this unwanted side |
| 1383 |
effect of NAT. |
| 1384 |
|
| 1385 |
The server side of the NAT-PMP protocol is implemented in Apple's |
| 1386 |
AirPort Extreme, AirPort Express, and Time Capsule wireless base |
| 1387 |
stations, and in the Internet Sharing feature of Mac OS X 10.4 and |
| 1388 |
later. Some third-party NAT vendors, such as Peplink, also offer |
| 1389 |
NAT-PMP in their products. |
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
<span class="grey">Cheshire & Krochmal Informational [Page 25]</span></pre> |
| 1397 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-26" ></span> |
| 1398 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 1399 |
|
| 1400 |
|
| 1401 |
In Mac OS X 10.4 Tiger, the NAT-PMP client was invoked automatically |
| 1402 |
as a side effect of clients requesting Wide Area Bonjour service |
| 1403 |
registrations. Using NAT-PMP without an associated Wide Area Bonjour |
| 1404 |
service registration required use of a third-party client library. |
| 1405 |
|
| 1406 |
In October 2007, Mac OS X 10.5 Leopard added the "DNSServiceNATPort- |
| 1407 |
MappingCreate" API, which made NAT-PMP client functionality directly |
| 1408 |
available, so software could use it with other directory and |
| 1409 |
rendezvous mechanisms in addition to Wide Area Bonjour DNS Updates. |
| 1410 |
|
| 1411 |
In 2013, NAT-PMP was superseded by the IETF Standards Track Port |
| 1412 |
Control Protocol [<a href="./rfc6887" title=""Port Control Protocol (PCP)"">RFC6887</a>]. PCP builds on NAT-PMP and uses a |
| 1413 |
compatible packet format, and adds a number of significant |
| 1414 |
enhancements, including IPv6 support, management of outbound |
| 1415 |
mappings, management of firewall rules, full compatibility with |
| 1416 |
large-scale NATs with a pool of external addresses, error lifetimes, |
| 1417 |
and an extension mechanism to enable future enhancements. |
| 1418 |
|
| 1419 |
<span class="h2"><a class="selflink" id="section-9" href="#section-9">9</a>. Noteworthy Features of NAT Port Mapping Protocol and PCP</span> |
| 1420 |
|
| 1421 |
Some readers have asked how NAT-PMP and PCP compare to other similar |
| 1422 |
solutions, particularly the UPnP Forum's Internet Gateway Device |
| 1423 |
(IGD) Device Control Protocol [<a href="#ref-IGD" title=""Internet Gateway Device (IGD) Standardized Device Control Protocol V 1.0"">IGD</a>]. |
| 1424 |
|
| 1425 |
The answer is that although the Universal Plug and Play (UPnP) IGD |
| 1426 |
protocol is often used as a way for client devices to create port |
| 1427 |
mappings programmatically, it's not ideal for that task. Whereas |
| 1428 |
NAT-PMP was explicitly designed to be used primarily by software |
| 1429 |
entities managing their own port mappings, UPnP IGD is more tailored |
| 1430 |
towards being used by humans configuring all the settings of their |
| 1431 |
gateway using some GUI tool. This difference in emphasis leads to |
| 1432 |
protocol differences. For example, while it is reasonable and |
| 1433 |
sensible to require software entities to renew their mappings |
| 1434 |
periodically to prove that they are still there (like a device |
| 1435 |
renewing its DHCP address lease), it would be unreasonable to require |
| 1436 |
the same thing of a human user. When a human user configures their |
| 1437 |
gateway, they expect it to stay configured that way until they decide |
| 1438 |
to change it. If they configure a port mapping, they expect it to |
| 1439 |
stay configured until they decide to delete it. |
| 1440 |
|
| 1441 |
Because of this focus on being a general administration protocol for |
| 1442 |
all aspects of home gateway configuration, UPnP IGD is a large and |
| 1443 |
complicated collection of protocols (360 pages of specification |
| 1444 |
spread over 13 separate documents, not counting supporting protocol |
| 1445 |
specifications like Simple Service Discovery Protocol (SSDP) and |
| 1446 |
Extensible Markup Language (XML)). While it may be a fine way for |
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
<span class="grey">Cheshire & Krochmal Informational [Page 26]</span></pre> |
| 1453 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-27" ></span> |
| 1454 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 1455 |
|
| 1456 |
|
| 1457 |
human users to configure their home gateways, it is not especially |
| 1458 |
suited to the task of programmatically creating dynamic port |
| 1459 |
mappings. |
| 1460 |
|
| 1461 |
The requirements for a good port mapping protocol, requirements that |
| 1462 |
are met by NAT-PMP, are outlined below. |
| 1463 |
|
| 1464 |
<span class="h3"><a class="selflink" id="section-9.1" href="#section-9.1">9.1</a>. Simplicity</span> |
| 1465 |
|
| 1466 |
Many home gateways, and many of the devices that connect to them, are |
| 1467 |
small, low-cost devices, with limited RAM, flash memory, and CPU |
| 1468 |
resources. Protocols they use should be considerate of this, |
| 1469 |
supporting a small number of simple operations that can be |
| 1470 |
implemented easily with a small amount of code. A quick comparison, |
| 1471 |
based on page count of the respective documents alone, suggests that |
| 1472 |
NAT-PMP is at least ten times simpler than UPnP IGD. |
| 1473 |
|
| 1474 |
<span class="h3"><a class="selflink" id="section-9.2" href="#section-9.2">9.2</a>. Focused Scope</span> |
| 1475 |
|
| 1476 |
The more things a protocol can do, the more chance there is that |
| 1477 |
something it does could be exploited for malicious purposes. NAT-PMP |
| 1478 |
is tightly focused on the specific task of creating port mappings. |
| 1479 |
Were the protocol to be misused in some way, this helps limit the |
| 1480 |
scope of what mischief could be performed using the protocol. |
| 1481 |
|
| 1482 |
Because UPnP IGD allows control over all home gateway configuration |
| 1483 |
settings, the potential for mischief is far greater. For example, a |
| 1484 |
UPnP IGD home gateway allows messages that tell it to change the DNS |
| 1485 |
server addresses that it sends to clients in its DHCP packets. Using |
| 1486 |
this mechanism, a single item of malicious web content (e.g., a rogue |
| 1487 |
Flash banner advert on a web page) can make a persistent change to |
| 1488 |
the home gateway's configuration without the user's knowledge, such |
| 1489 |
that all future DNS requests by all local clients will be sent to a |
| 1490 |
rogue DNS server. This allows criminals to perform a variety of |
| 1491 |
mischief, such as hijacking connections to bank web sites and |
| 1492 |
redirecting them to the criminals' web servers instead [<a href="#ref-VU347812">VU347812</a>]. |
| 1493 |
|
| 1494 |
<span class="h3"><a class="selflink" id="section-9.3" href="#section-9.3">9.3</a>. Efficiency</span> |
| 1495 |
|
| 1496 |
In addition to low-cost home gateways, many of the clients will also |
| 1497 |
be similarly constrained low-cost devices with limited RAM resources. |
| 1498 |
|
| 1499 |
When implementing a NAT-PMP client on a constrained device, it's |
| 1500 |
beneficial to have well-defined bounds on RAM requirements that are |
| 1501 |
fixed and known in advance. For example, when requesting the |
| 1502 |
gateway's external IPv4 address, a NAT-PMP client on Ethernet knows |
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
<span class="grey">Cheshire & Krochmal Informational [Page 27]</span></pre> |
| 1509 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-28" ></span> |
| 1510 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 1511 |
|
| 1512 |
|
| 1513 |
that to receive the reply it will require 14 bytes for the Ethernet |
| 1514 |
header, 20 bytes for the IPv4 header, 8 bytes for the UDP header, and |
| 1515 |
12 bytes for the NAT-PMP payload, making a total of 54 bytes. |
| 1516 |
|
| 1517 |
In contrast, UPnP IGD uses an XML reply of unbounded size. It is not |
| 1518 |
uncommon for a UPnP IGD device to return an XML document 4000 to 8000 |
| 1519 |
bytes in size to communicate its 4-byte external IPv4 address, and |
| 1520 |
the protocol specification places no upper bound on how large the XML |
| 1521 |
response may be, so there's nothing to stop the reply being even |
| 1522 |
larger. This means that developers of UPnP client devices can only |
| 1523 |
guess at how much memory they may need to receive the XML reply. |
| 1524 |
Operational experience suggests that 10,000 bytes is usually enough |
| 1525 |
for most UPnP IGD home gateways today, but that's no guarantee that |
| 1526 |
some future UPnP IGD home gateway might not return a perfectly legal |
| 1527 |
XML reply much larger than that. |
| 1528 |
|
| 1529 |
In addition, because the XML reply is too large to fit in a single |
| 1530 |
UDP packet, UPnP IGD has to use a TCP connection, thereby adding the |
| 1531 |
overhead of TCP connection setup and teardown. |
| 1532 |
|
| 1533 |
The process of discovering a UPnP IGD home gateway's external IPv4 |
| 1534 |
address consists of: |
| 1535 |
|
| 1536 |
o SSDP transaction to discover the TCP port to use, and the "URL" of |
| 1537 |
the XML document to fetch from the gateway. Following the SSDP |
| 1538 |
specification, this is 3 multicast requests, eliciting 9 unicast |
| 1539 |
responses. |
| 1540 |
|
| 1541 |
o HTTP "GET" request to get the device description. Typically, 16 |
| 1542 |
packets: 3 for TCP connection setup, 9 packets of data exchange, |
| 1543 |
and a 4-packet FIN-ACK-FIN-ACK sequence to close the connection. |
| 1544 |
|
| 1545 |
o HTTP "POST" to request the external IPv4 address. Typically, 14 |
| 1546 |
packets: 3 for TCP connection setup, 7 packets of data exchange, |
| 1547 |
and a 4-packet FIN-ACK-FIN-ACK sequence to close the connection. |
| 1548 |
|
| 1549 |
To retrieve the external IPv4 address NAT-PMP takes a 2-packet UDP |
| 1550 |
exchange (44-byte request, 54-byte response); the same thing using |
| 1551 |
UPnP IGD takes 42 packets and thousands of bytes. |
| 1552 |
|
| 1553 |
Similarly, UPnP IGD's HTTP "POST" request for a port mapping is |
| 1554 |
typically a 14-packet exchange, compared with NAT-PMP's 2-packet UDP |
| 1555 |
exchange. |
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
<span class="grey">Cheshire & Krochmal Informational [Page 28]</span></pre> |
| 1565 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-29" ></span> |
| 1566 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 1567 |
|
| 1568 |
|
| 1569 |
<span class="h3"><a class="selflink" id="section-9.4" href="#section-9.4">9.4</a>. Atomic Allocation Operations</span> |
| 1570 |
|
| 1571 |
Some of the useful properties of NAT-PMP were inspired by DHCP, a |
| 1572 |
reliable and successful protocol. For example, DHCP allows a client |
| 1573 |
to request a desired IP address, but if that address is already in |
| 1574 |
use the DHCP server will instead assign some other available address. |
| 1575 |
|
| 1576 |
Correspondingly, NAT-PMP allows a client to request a desired |
| 1577 |
external port, and if that external port is already in use by some |
| 1578 |
other client, the NAT-PMP server will instead assign some other |
| 1579 |
available external port. |
| 1580 |
|
| 1581 |
UPnP IGD does not do this. If a UPnP IGD client requests an external |
| 1582 |
port that has already been allocated, then one of two things happens. |
| 1583 |
|
| 1584 |
Some UPnP IGD home gateways just silently overwrite the old mapping |
| 1585 |
with the new one, causing the previous client to lose connectivity. |
| 1586 |
If the previous client renews its port mapping, then it in turn |
| 1587 |
overwrites the new mapping, and the two clients fight over the same |
| 1588 |
external port indefinitely, neither achieving reliable connectivity. |
| 1589 |
|
| 1590 |
Other IGD home gateways return a "Conflict" error if the port is |
| 1591 |
already in use, which does at least tell the client what happened, |
| 1592 |
but doesn't tell the client what to do. Instead of the NAT gateway |
| 1593 |
(which does know which ports are available) assigning one to the |
| 1594 |
client, the NAT gateway makes the client (which doesn't know) keep |
| 1595 |
guessing until it gets lucky. This problem remains mild as long as |
| 1596 |
not many clients are using UPnP IGD, but gets progressively worse as |
| 1597 |
the number of clients on the network requesting port mappings goes |
| 1598 |
up. In addition, UPnP IGD works particularly badly in conjunction |
| 1599 |
with the emerging policy of allocating pre-assigned port ranges to |
| 1600 |
each client. If a client is assigned TCP port range 63488-64511, and |
| 1601 |
the UPnP IGD client requests TCP port 80, trying successive |
| 1602 |
incrementing ports until it succeeds, then the UPnP IGD client will |
| 1603 |
have to issue 63,409 requests before it succeeds. |
| 1604 |
|
| 1605 |
<span class="h3"><a class="selflink" id="section-9.5" href="#section-9.5">9.5</a>. Garbage Collection</span> |
| 1606 |
|
| 1607 |
In any system that operates for a long period of time (as a home |
| 1608 |
gateway should), it is important that garbage data does not |
| 1609 |
accumulate indefinitely until the system runs out of memory and |
| 1610 |
fails. |
| 1611 |
|
| 1612 |
Similar to how DHCP leases an IP address to a client for a finite |
| 1613 |
length of time, NAT-PMP leases an external port to a client for a |
| 1614 |
finite length of time. The NAT-PMP client must renew the port |
| 1615 |
mapping before it expires, or, like an unrenewed DHCP address, it |
| 1616 |
will be reclaimed. If a laptop computer is abruptly disconnected |
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
<span class="grey">Cheshire & Krochmal Informational [Page 29]</span></pre> |
| 1621 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-30" ></span> |
| 1622 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 1623 |
|
| 1624 |
|
| 1625 |
from the network without the opportunity to delete its port mappings, |
| 1626 |
the NAT gateway will reclaim those mappings when they are not |
| 1627 |
renewed. |
| 1628 |
|
| 1629 |
In principle, UPnP IGD should allow clients to specify a lifetime on |
| 1630 |
port mappings. However, a Google search for "UPnP NewLeaseDuration" |
| 1631 |
shows that in practice pretty much every client uses |
| 1632 |
"<NewLeaseDuration>0</NewLeaseDuration>" to request an infinite |
| 1633 |
lease, and the protocol has no way for the NAT gateway to decline |
| 1634 |
that infinite lease request and require the client to renew it at |
| 1635 |
reasonable intervals. Furthermore, anecdotal evidence is that if the |
| 1636 |
client requests a lease other than zero, there are IGD home gateways |
| 1637 |
that will ignore the request, fail in other ways, or even crash |
| 1638 |
completely. As a client implementer then, you would be well advised |
| 1639 |
not to attempt to request a lease other than zero, unless you want to |
| 1640 |
suffer the support costs and bad publicity of lots of people |
| 1641 |
complaining that your device brought down their entire network. |
| 1642 |
|
| 1643 |
Because none of the early UPnP IGD clients requested port mapping |
| 1644 |
leases, many UPnP IGD home gateway vendors never tested that |
| 1645 |
functionality, and got away with shipping home gateways where that |
| 1646 |
functionality was buggy or nonexistent. Because there are so many |
| 1647 |
buggy UPnP IGD home gateways already deployed, client writers wisely |
| 1648 |
stick to the well-trodden path of only requesting infinite leases. |
| 1649 |
Because there are now few (if any) clients attempting to request non- |
| 1650 |
zero leases, home gateway vendors have little incentive to expend |
| 1651 |
resources implementing a feature no one uses. |
| 1652 |
|
| 1653 |
This unfortunate consequence of the way UPnP IGD was developed and |
| 1654 |
deployed means that in practice it has no usable port mapping lease |
| 1655 |
facility today, and therefore when run for a long period of time UPnP |
| 1656 |
IGD home gateways have no good way to avoid accumulating an unbounded |
| 1657 |
number of stale port mappings. |
| 1658 |
|
| 1659 |
<span class="h3"><a class="selflink" id="section-9.6" href="#section-9.6">9.6</a>. State Change Announcements</span> |
| 1660 |
|
| 1661 |
When using DHCP on the external interface, as is the norm for home |
| 1662 |
gateways, there is no guarantee that a UPnP IGD home gateway's |
| 1663 |
external IPv4 address will remain unchanged. Indeed, some ISPs |
| 1664 |
change their customer's IPv4 address every 24 hours (possibly in an |
| 1665 |
effort to make it harder for their customers to "run a server" at |
| 1666 |
home). What this means is that if the home gateway's external IPv4 |
| 1667 |
address changes, it needs to inform its clients, so that they can |
| 1668 |
make any necessary updates to global directory information (e.g., |
| 1669 |
performing a Dynamic DNS update to update their address record). |
| 1670 |
|
| 1671 |
When a NAT-PMP gateway's external IPv4 address changes, it broadcasts |
| 1672 |
announcement packets to inform clients of this. UPnP IGD does not. |
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
<span class="grey">Cheshire & Krochmal Informational [Page 30]</span></pre> |
| 1677 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-31" ></span> |
| 1678 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 1679 |
|
| 1680 |
|
| 1681 |
<span class="h3"><a class="selflink" id="section-9.7" href="#section-9.7">9.7</a>. Soft State Recovery</span> |
| 1682 |
|
| 1683 |
When run for a long enough period of time, any network will have |
| 1684 |
devices that fail, get rebooted, suffer power outages, or lose state |
| 1685 |
for other reasons. A home gateway that runs for long enough is |
| 1686 |
likely to suffer some such incident eventually. After losing state, |
| 1687 |
it has no record of the port mappings it created, and clients suffer |
| 1688 |
a consequent loss of connectivity. |
| 1689 |
|
| 1690 |
To handle this case, NAT-PMP has the "Seconds Since Start of Epoch" |
| 1691 |
mechanism. After a reboot or other loss of state, a NAT-PMP gateway |
| 1692 |
broadcasts announcement packets giving its external IPv4 address, |
| 1693 |
with the Seconds Since Start of Epoch field reset to begin counting |
| 1694 |
from zero again. When a NAT-PMP client observes packets from its |
| 1695 |
NAT-PMP gateway where the gateway's notion of time has apparently |
| 1696 |
gone backwards compared to the client's, the client knows the gateway |
| 1697 |
has probably lost state, and immediately recreates its mappings to |
| 1698 |
restore connectivity. |
| 1699 |
|
| 1700 |
UPnP IGD has no equivalent mechanism. |
| 1701 |
|
| 1702 |
<span class="h3"><a class="selflink" id="section-9.8" href="#section-9.8">9.8</a>. On-Path NAT Discovery</span> |
| 1703 |
|
| 1704 |
For any given host, it is only useful to request NAT port mappings in |
| 1705 |
the NAT gateway through which that host's packets are flowing. A NAT |
| 1706 |
port mapping is a request for packets to be translated in a certain |
| 1707 |
way; the NAT gateway can only perform that translation if it's |
| 1708 |
actually forwarding inbound and outbound packets for that host. |
| 1709 |
|
| 1710 |
This is why NAT-PMP sends its requests to the host's default router, |
| 1711 |
since this is the device that is forwarding (and possibly |
| 1712 |
translating) inbound and outbound packets for that host. (In a |
| 1713 |
larger network with multiple hops between a host and its NAT gateway, |
| 1714 |
some other mechanism would need to be used to discover the correct |
| 1715 |
on-path NAT for a host; this is possible, but outside the scope of |
| 1716 |
this document.) |
| 1717 |
|
| 1718 |
In contrast, UPnP IGD does not limit itself to using only on-path |
| 1719 |
NATs. UPnP IGD uses a multicast SSDP query, and uses any device it |
| 1720 |
finds on the local network claiming UPnP IGD capability, regardless |
| 1721 |
of whether any inbound or outbound traffic is actually flowing |
| 1722 |
through that device. Over the past few years this led to many bug |
| 1723 |
reports being sent to Apple with the general form: "Port Mapping |
| 1724 |
doesn't work on my Mac and that's a bug because everything else on my |
| 1725 |
network says UPnP IGD is working fine." Upon investigation it always |
| 1726 |
turned out that: (i) these people had NAT gateways that either didn't |
| 1727 |
support port mapping requests, or had that capability disabled, and |
| 1728 |
(ii) for some reason they also had some other old NAT device still |
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
<span class="grey">Cheshire & Krochmal Informational [Page 31]</span></pre> |
| 1733 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-32" ></span> |
| 1734 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 1735 |
|
| 1736 |
|
| 1737 |
connected to their network, and those other NAT devices were |
| 1738 |
advertising UPnP IGD capability, even though they were not the active |
| 1739 |
NAT gateway for the network. This led to UPnP IGD clients falsely |
| 1740 |
reporting that they were "working fine", and only the Mac correctly |
| 1741 |
reporting that it was unable to make any useful port mappings. In |
| 1742 |
many cases the people reporting this "bug" had devices like game |
| 1743 |
consoles on their home network that for many years had been reporting |
| 1744 |
that UPnP IGD was "working fine", yet during those years they had |
| 1745 |
never once successfully received any inbound network packet or |
| 1746 |
connection. The irony is that, for these people who were reporting |
| 1747 |
bugs to Apple, UPnP IGD "working fine" had been indistinguishable |
| 1748 |
from UPnP IGD doing nothing useful at all. It was only when Back to |
| 1749 |
My Mac [<a href="./rfc6281" title=""Understanding Apple's Back to My Mac (BTMM) Service"">RFC6281</a>] started reporting that it was unable to make any |
| 1750 |
functional port mappings that these people discovered they'd never |
| 1751 |
had any working port mappings on their NAT gateway. |
| 1752 |
|
| 1753 |
<span class="h2"><a class="selflink" id="section-10" href="#section-10">10</a>. References</span> |
| 1754 |
|
| 1755 |
<span class="h3"><a class="selflink" id="section-10.1" href="#section-10.1">10.1</a>. Normative References</span> |
| 1756 |
|
| 1757 |
[<a id="ref-RFC1918">RFC1918</a>] Rekhter, Y., Moskowitz, B., Karrenberg, D., de Groot, G., |
| 1758 |
and E. Lear, "Address Allocation for Private Internets", |
| 1759 |
<a href="https://www.rfc-editor.org/bcp/bcp5">BCP 5</a>, <a href="./rfc1918">RFC 1918</a>, February 1996. |
| 1760 |
|
| 1761 |
[<a id="ref-RFC2119">RFC2119</a>] Bradner, S., "Key words for use in RFCs to Indicate |
| 1762 |
Requirement Levels", <a href="https://www.rfc-editor.org/bcp/bcp14">BCP 14</a>, <a href="./rfc2119">RFC 2119</a>, March 1997. |
| 1763 |
|
| 1764 |
<span class="h3"><a class="selflink" id="section-10.2" href="#section-10.2">10.2</a>. Informative References</span> |
| 1765 |
|
| 1766 |
[<a id="ref-Bonjour">Bonjour</a>] Apple "Bonjour" <<a href="http://developer.apple.com/bonjour/">http://developer.apple.com/bonjour/</a>>. |
| 1767 |
|
| 1768 |
[<a id="ref-ETEAISD">ETEAISD</a>] J. Saltzer, D. Reed and D. Clark: "End-to-end arguments in |
| 1769 |
system design", ACM Trans. Comp. Sys., 2(4):277-88, |
| 1770 |
November 1984. |
| 1771 |
|
| 1772 |
[<a id="ref-IGD">IGD</a>] UPnP Standards "Internet Gateway Device (IGD) Standardized |
| 1773 |
Device Control Protocol V 1.0", November 2001, |
| 1774 |
<<a href="http://www.upnp.org/standardizeddcps/igd.asp">http://www.upnp.org/standardizeddcps/igd.asp</a>>. |
| 1775 |
|
| 1776 |
[<a id="ref-RFC2131">RFC2131</a>] Droms, R., "Dynamic Host Configuration Protocol", <a href="./rfc2131">RFC</a> |
| 1777 |
<a href="./rfc2131">2131</a>, March 1997. |
| 1778 |
|
| 1779 |
[<a id="ref-RFC2663">RFC2663</a>] Srisuresh, P. and M. Holdrege, "IP Network Address |
| 1780 |
Translator (NAT) Terminology and Considerations", <a href="./rfc2663">RFC</a> |
| 1781 |
<a href="./rfc2663">2663</a>, August 1999. |
| 1782 |
|
| 1783 |
[<a id="ref-RFC3007">RFC3007</a>] Wellington, B., "Secure Domain Name System (DNS) Dynamic |
| 1784 |
Update", <a href="./rfc3007">RFC 3007</a>, November 2000. |
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
<span class="grey">Cheshire & Krochmal Informational [Page 32]</span></pre> |
| 1789 |
<hr class='noprint'/><!--NewPage--><pre class='newpage'><span id="page-33" ></span> |
| 1790 |
<span class="grey"><a href="./rfc6886">RFC 6886</a> NAT-PMP April 2013</span> |
| 1791 |
|
| 1792 |
|
| 1793 |
[<a id="ref-RFC3022">RFC3022</a>] Srisuresh, P. and K. Egevang, "Traditional IP Network |
| 1794 |
Address Translator (Traditional NAT)", <a href="./rfc3022">RFC 3022</a>, January |
| 1795 |
2001. |
| 1796 |
|
| 1797 |
[<a id="ref-RFC3424">RFC3424</a>] Daigle, L., Ed., and IAB, "IAB Considerations for |
| 1798 |
UNilateral Self-Address Fixing (UNSAF) Across Network |
| 1799 |
Address Translation", <a href="./rfc3424">RFC 3424</a>, November 2002. |
| 1800 |
|
| 1801 |
[<a id="ref-RFC4301">RFC4301</a>] Kent, S. and K. Seo, "Security Architecture for the |
| 1802 |
Internet Protocol", <a href="./rfc4301">RFC 4301</a>, December 2005. |
| 1803 |
|
| 1804 |
[<a id="ref-RFC6281">RFC6281</a>] Cheshire, S., Zhu, Z., Wakikawa, R., and L. Zhang, |
| 1805 |
"Understanding Apple's Back to My Mac (BTMM) Service", <a href="./rfc6281">RFC</a> |
| 1806 |
<a href="./rfc6281">6281</a>, June 2011. |
| 1807 |
|
| 1808 |
[<a id="ref-RFC6763">RFC6763</a>] Cheshire, S. and M. Krochmal, "DNS-Based Service |
| 1809 |
Discovery", <a href="./rfc6763">RFC 6763</a>, February 2013. |
| 1810 |
|
| 1811 |
[<a id="ref-RFC6887">RFC6887</a>] Wing, D., Ed., Cheshire, S., Boucadair, M., Penno, R., and |
| 1812 |
P. Selkirk, "Port Control Protocol (PCP)", <a href="./rfc6887">RFC 6887</a>, April |
| 1813 |
2013. |
| 1814 |
|
| 1815 |
[<a id="ref-SEE">SEE</a>] SubEthaEdit, <<a href="http://www.codingmonkeys.de/subethaedit/">http://www.codingmonkeys.de/subethaedit/</a>>. |
| 1816 |
|
| 1817 |
[<a id="ref-VU347812">VU347812</a>] United States Computer Emergency Readiness Team |
| 1818 |
Vulnerability Note VU#347812, |
| 1819 |
<<a href="http://www.kb.cert.org/vuls/id/347812">http://www.kb.cert.org/vuls/id/347812</a>>. |
| 1820 |
|
| 1821 |
Authors' Addresses |
| 1822 |
|
| 1823 |
Stuart Cheshire |
| 1824 |
Apple Inc. |
| 1825 |
1 Infinite Loop |
| 1826 |
Cupertino, CA 95014 |
| 1827 |
USA |
| 1828 |
|
| 1829 |
EMail: [email protected] |
| 1830 |
|
| 1831 |
Marc Krochmal |
| 1832 |
Apple Inc. |
| 1833 |
1 Infinite Loop |
| 1834 |
Cupertino, CA 95014 |
| 1835 |
USA |
| 1836 |
|
| 1837 |
EMail: [email protected] |
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
Cheshire & Krochmal Informational [Page 33] |
| 1845 |
</pre> |