Skip to main content

Module portmap

Module portmap 

Source
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§

PortMapping
An external ip:port the router agreed to forward to us.

Enums§

MapProtocol

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/UDP to us, trying PCP, NAT-PMP and UPnP in that order. None when 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 None if the router declined this time (the caller should then re-run discovery and re-announce).