fix MWP hole punch for production use. bind to 0.0.0.0 instead of

published IP, resend packets every 500ms instead of single-shot, fix
Docker iptables-legacy chains so miniupnpd port mapping fully works
without warnings
This commit is contained in:
2026-02-10 11:26:57 -03:00
parent 33730fed8a
commit 2fe03cb855
12 changed files with 356 additions and 56 deletions

View File

@@ -34,7 +34,7 @@ This test uses `miniupnpd` as the NAT-PMP daemon running on a simulated router.
The router:
- Runs `miniupnpd` (NAT-PMP + UPnP IGD daemon)
- Does NAT (iptables MASQUERADE) for internal clients
- Reports a fake "external" IP (93.184.216.34) for testing
- Uses a public-looking "external" IP (93.184.216.34) added as alias on the external interface (miniupnpd rejects private IPs)
## Quick Start
@@ -66,19 +66,16 @@ info: NAT-PMP: External address is 93.184.216.34
Using NAT-PMP: 93.184.216.34:18201
```
### Port Mapping: PARTIAL
Port mapping requests are sent correctly, but miniupnpd returns "Network Failure" because:
- The fake external IP doesn't match the actual interface
- iptables rules can't be created for a non-local address
### Port Mapping: PASS
miniupnpd creates DNAT and masquerade rules via libiptc (iptables-legacy).
This is expected in the Docker test environment. On a real router with NAT-PMP support, port mapping would succeed.
```
info: NAT-PMP: Mapped UDP port 18101 -> 93.184.216.34:18101 (lifetime: 3600s)
```
### Connection: LIMITED
Full MWP connection can't complete because:
- The fake external IP can't be bound locally
- No actual internet routing exists
The test validates the protocol implementation, not end-to-end connectivity.
### Connection: PASS
Full MWP hole punch completes. Both peers establish a verified connection through
the NAT router using DNAT port forwarding and hairpin masquerade.
## Files
@@ -104,7 +101,9 @@ Common issues:
- Interface detection problems
### "NAT-PMP: Gateway returned error: Network Failure"
This is expected when port mapping fails. External address discovery should still work.
miniupnpd needs the `MINIUPNPD-POSTROUTING` chain in the nat table for masquerade
rules. If missing, the DNAT rule is created but miniupnpd reports failure. Ensure
`router-entrypoint.sh` creates all three chains: `MINIUPNPD` (nat), `MINIUPNPD-POSTROUTING` (nat), `MINIUPNPD` (filter).
### "Cannot determine gateway"
The NAT-PMP client probes common gateway IPs. Ensure the router is at 10.100.0.1.