From c47014887af5ba7747b001f01cf75f8fa12f2675 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 7 Nov 2018 21:13:27 -0800 Subject: [PATCH] Avoid making duplicate NAT-PMP requests to a UPnP gateway that was disconnected --- miss/miss.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/miss/miss.cpp b/miss/miss.cpp index 4a4b627..c1e9194 100644 --- a/miss/miss.cpp +++ b/miss/miss.cpp @@ -606,6 +606,14 @@ void UpdatePortMappingsForTarget(bool enable, char* targetAddressIP4, char* inte tryNatPmp = false; } + // Don't try with NAT-PMP if the UPnP attempt for the same gateway failed due to being + // disconnected or some other error. This will avoid overwriting UPnP rules on a disconnected IGD + // with duplicate NAT-PMP rules. We want to allow deletion of NAT-PMP rules in any case though. + if (tryNatPmp && enable && !strcmp(upstreamAddrNatPmp, upstreamAddrNatPmp)) { + printf("Not attempting to use NAT-PMP to talk to the same UPnP gateway\n"); + tryNatPmp = false; + } + if (tryNatPmp) { bool success = true; for (int i = 0; i < ARRAYSIZE(k_Ports); i++) {