Expand description
NAT-assisted candidates (RFC 6544 section 5.3, RFC 8445 section 5.1.1.2): an opt-in client of
the Port Control Protocol (PCP, RFC 6887) with a fallback to NAT-PMP (RFC 6886), asking the
gateway for a port mapping. Nothing here runs unless the application calls it, and it
adds no dependency: one UDP socket of the driver’s Runtime.
The engine needs nothing new: the mapped address is a candidate the application adds
itself, a server-reflexive one whose related address is the base (RFC 6544 section 5.3
calls it NAT-assisted; candidate_line writes it with the type preference 105 RFC 6544
section 4.2 recommends). Finding the gateway is the application’s: this module does not
read routing tables (that would need a platform dependency); the default gateway’s address
is passed in.
map_port sends a PCP MAP request (RFC 6887 section 11) to gateway:5351, retransmitted
as section 8.1.1 says (3 s first, doubling, here up to MappingConfig::attempts times);
a gateway that answers with UNSUPP_VERSION, or with a NAT-PMP response, is asked again with
NAT-PMP (RFC 6886 section 3.3, retransmitted from 250 ms doubling, at most nine times,
section 3.1). Mappings expire: renew them with map_port again before half their
lifetime has passed, and delete one with a lifetime of 0.
Structs§
- Mapping
- A mapping the gateway granted.
- Mapping
Config - How
map_portasks.
Enums§
- Mapping
Protocol - Which protocol answered.
- NatPmp
Answer - A NAT-PMP answer.
- PcpAnswer
- What a PCP response says.
- Protocol
- The transport a mapping is for.
Constants§
- SERVER_
PORT - The port PCP and NAT-PMP servers listen on (RFC 6887 section 19.1, RFC 6886 section 3).
Functions§
- candidate_
line - The NAT-assisted candidate of
mappingfor the localbase(RFC 6544 sections 4.2 and 5.3): a server-reflexive candidate with the type preference 105, for the application to add withadd_local_candidate. Over TCPtcp_typenames its direction (RFC 6544 section 4.2: for NAT-assisted candidates simultaneous-open 6, active 4, passive 2; an active one is signalled on port 9). - map_
port - Asks the gateway at
gatewayfor a mapping ofinternal_portonlocal_ip(the interface the gateway is reached from): PCP first, NAT-PMP when the gateway does not speak PCP.Ok(None)when no gateway answered; an error when it refused. - nat_
pmp_ address_ request - A NAT-PMP external address request (RFC 6886 section 3.2).
- nat_
pmp_ map_ request - A NAT-PMP mapping request (RFC 6886 section 3.3).
- parse_
nat_ pmp_ response - Parses a NAT-PMP response to
opcode(RFC 6886 sections 3.2, 3.3, 3.5). - parse_
pcp_ map_ response - Parses a PCP MAP response to the request with
nonce(RFC 6887 sections 7.2 and 11.1).Nonefor anything else (not PCP, not a MAP response, another nonce). - pcp_
map_ request - A PCP MAP request (RFC 6887 sections 7.1 and 11.1): 24-byte header, 36-byte MAP opcode.