Expand description
Router port mapping — PCP (RFC 6887), NAT-PMP (RFC 6886), UPnP-IGD.
An installed mapping beats an inferred one: it also covers port-restricted and many symmetric NATs, and it does not expire the way a hole-punched mapping does. Carrier-grade NAT refuses all three quickly and definitively, which is itself useful — it tells the pilot to stop hoping.
All three are implemented directly (no miniupnpc, no reqwest): the UPnP side needs only SSDP, one HTTP GET and two SOAP POSTs on the LAN.
Structs§
- Port
Mapping - An external
ip:portthe router agreed to forward to us.
Enums§
Functions§
- default_
gateway - Best-effort IPv4 default gateway, for the UDP-to-gateway protocols.
- encode_
natpmp_ map - NAT-PMP map-UDP request (opcode 1): version, opcode, reserved, internal, suggested external, lifetime.
- encode_
pcp_ map - PCP MAP request: version 2, opcode MAP, lifetime, client address as IPv4-mapped IPv6, 12-byte nonce, protocol UDP, internal + suggested port, any external address.
- find_
control_ url - Locate a WAN connection service in the device description:
(controlURL, serviceType). - map_
port - Ask the router to forward
internal_port/UDPto us, trying PCP, NAT-PMP and UPnP in that order.Nonewhen nothing succeeds (no gateway, CGNAT, UPnP disabled, double NAT). Never panics. - parse_
natpmp_ address - Parse a NAT-PMP external-address response (opcode 128).
- parse_
natpmp_ map - Parse a NAT-PMP map response:
(external_port, lifetime). - parse_
pcp_ map - Parse a PCP MAP response:
(lifetime, external_port, external_ip). - renew
- Re-request the same mapping before its lease expires. Returns the refreshed
mapping, or
Noneif the router declined this time (the caller should then re-run discovery and re-announce).