Files
Jake Bailey 91d10d38ae net/portmapper: avoid leaking permanent UPnP mappings
MikroTik routers only support permanent UPnP leases. Previously, a
mapping attempt could proceed as follows:

  1. Add a temporary mapping.
  2. Retry with a permanent mapping after error 725.
  3. Successfully create the permanent mapping.
  4. Fail to query the external IP.
  5. Forget the mapping and retry with another random port.

Each retry left another permanent NAT rule behind.

To prevent this, query and validate the external IP before creating
the mapping. When service selection has already queried the address,
reuse that result. This leaves no fallible network request after
AddPortMapping succeeds.

I tested this on my own MikroTik router running RouterOS 7.23.2. A
successful mapping queried the external IP before creating the
permanent rule, and a forced external-IP failure created no rule.

Updates #10602

RELNOTE: Prevent UPnP rule accumulation on MikroTik routers.

Change-Id: Id925ed9cc3a3da6ecb06fc892f2a934addfac37b
Signed-off-by: Jake Bailey <jacob.b.bailey@gmail.com>
2026-09-01 20:07:27 -07:00
..