published IP, resend packets every 500ms instead of single-shot, fix Docker iptables-legacy chains so miniupnpd port mapping fully works without warnings
4.8 KiB
UPnP IGD Protocol Testing
This directory contains a Docker-based test environment for the UPnP IGD (Internet Gateway Device) implementation.
Overview
UPnP IGD allows clients behind a NAT to:
- Discover the gateway via SSDP multicast (239.255.255.250:1900)
- Fetch the gateway's XML device description
- Use SOAP to query the external (public) IP address
- Use SOAP to request port mappings from the NAT gateway
This test uses miniupnpd as the UPnP daemon with NAT-PMP disabled, so the mwp-demo is forced to use the UPnP IGD path.
Network Topology
┌─────────────────────────────────────────────────────┐
│ Internal (10.100.0.0/24) │
│ │
│ ┌─────────┐ ┌─────────┐ ┌───────┐ │
│ │ peer-a │ │ peer-b │ │router │ │
│ │ .10 │ │ .11 │ │ .1 │ │
│ └─────────┘ └─────────┘ └───┬───┘ │
└─────────────────────────────────────────────┼──────┘
│
┌─────────────────────────────────────────────┼──────┐
│ External (10.200.0.0/24) │ │
│ ┌─────┴────┐ │
│ │ router │ │
│ │ .1 │ │
│ └──────────┘ │
└────────────────────────────────────────────────────┘
The router:
- Runs
miniupnpdwith UPnP IGD enabled, NAT-PMP disabled - Does NAT (iptables MASQUERADE) for internal clients
- Uses a public-looking "external" IP (93.184.216.34) added as alias on the external interface (miniupnpd rejects private IPs)
Quick Start
# Build Linux binary first (from project root)
zig build -Doptimize=ReleaseFast -Dtarget=aarch64-linux
# Run the test
cd docker-tests/upnp
./run-test.sh
What This Tests
| Component | What's Tested |
|---|---|
| SSDP discovery | M-SEARCH multicast finds the UPnP gateway |
| XML description | Fetching and parsing the gateway's device XML |
| GetExternalIPAddress | SOAP request to retrieve the public IP |
| AddPortMapping | SOAP request for port forwarding |
| MWP integration | Using UPnP-discovered address in MWP |
| NAT-PMP fallthrough | NAT-PMP fails (disabled), UPnP is tried next |
Expected Results
External Address Discovery: PASS
The UPnP implementation discovers the gateway via SSDP, fetches its XML description, and queries the external IP via SOAP.
UPnP: External address is 93.184.216.34
Using UPnP IGD: 93.184.216.34:18101
Port Mapping: PASS
miniupnpd creates DNAT and masquerade rules via libiptc (iptables-legacy).
info: UPnP: Mapped UDP port 18101 -> 93.184.216.34:18101 (lifetime: 3600s)
Connection: PASS
Full MWP hole punch completes. Both peers establish a verified connection through the NAT router using DNAT port forwarding and hairpin masquerade.
NAT-PMP: SKIPPED
NAT-PMP is disabled on the router (enable_natpmp=no), so the mwp-demo's NAT-PMP attempt fails silently and falls through to UPnP.
Files
| File | Purpose |
|---|---|
docker-compose.yml |
Network topology and service definitions |
Dockerfile.router |
Router image with miniupnpd (UPnP only) |
Dockerfile.peer |
Peer image with mwp-demo binary |
router-entrypoint.sh |
Router startup (NAT setup, miniupnpd config with NAT-PMP disabled) |
peer-test.sh |
Peer test script |
run-test.sh |
Main test orchestrator |
Troubleshooting
"miniupnpd not running"
Check router logs:
docker compose logs router
"UPnP: Gateway discovery failed"
SSDP multicast may not work on all Docker network configurations. Check that the internal bridge network allows multicast traffic.
"No UPnP messages"
The mwp-demo tries NAT-PMP first. If NAT-PMP somehow succeeds (shouldn't with enable_natpmp=no), UPnP will be skipped. Check for Using NAT-PMP: in logs.
See Also
- UPnP IGD Specification
- miniupnpd
src/network/upnp.zig- Implementationdocker-tests/nat-pmp/- NAT-PMP test (same topology, different protocol)