From f9018208f3a86e17ee1a3dbe41e7669d7a340735 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Thu, 3 Apr 2025 14:22:08 +0200 Subject: [PATCH] p2p/nat: do not use UPnP delete workaround by default Signed-off-by: Csaba Kiraly --- p2p/nat/natupnp.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/p2p/nat/natupnp.go b/p2p/nat/natupnp.go index 053eec17f5..92afd77c84 100644 --- a/p2p/nat/natupnp.go +++ b/p2p/nat/natupnp.go @@ -37,6 +37,13 @@ const ( rateLimit = 200 * time.Millisecond retryCount = 3 // number of retries after a failed AddPortMapping randomCount = 3 // number of random ports to try + + // According to the UPnP spec delete before add is not needed if the + // private IP remained the same. However, we have seen this workaround + // being used in practice. It could also create problems, so we keep it + // disabled by default. If the private IP changed, an external port change + // should be OK. + deleteBeforeAdd = false ) type upnp struct { @@ -93,7 +100,7 @@ func (n *upnp) AddMapping(protocol string, extport, intport int, desc string, li if extport == 0 { extport = intport - } else { + } else if deleteBeforeAdd { // Only delete port mapping if the external port was already used by geth. err := n.DeleteMapping(protocol, extport, intport) log.Trace("Deleting port mapping", "protocol", protocol, "extport", extport, "intport", intport, "err", err)