From 5589241b2467b520a2eb2366d14ea3f12aeff96b Mon Sep 17 00:00:00 2001 From: Patrick Lodder Date: Wed, 12 Mar 2025 11:55:45 -0400 Subject: [PATCH] net: fix compatibility with miniupnp API version 18 - Fix breaking change on UPNP_GetValidIGD by macro condition on MINIUPNPC_API_VERSION > 18 - Verbosely log what was returned by UPNP_GetValidIGD - because we can detect whether a valid outbound connection was found to and unroutable external IP. This helps troubleshooting situations where for example an ISP uses CGNAT. See miniupnp commit c0a50ce33e3b99ce8a96fd43049bb5b53ffac62f for the full change. Co-authored-by: Daniel Morante --- src/net.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/net.cpp b/src/net.cpp index 70f303a0d..356c613cb 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1488,7 +1488,16 @@ void ThreadMapPort() struct IGDdatas data; int r; + // since API version 18 / release 2.2.8 + // both signature and return values of UPNP_GetValidIGD have been changed + // see miniupnp commit c0a50ce33e3b99ce8a96fd43049bb5b53ffac62f +#if MINIUPNPC_API_VERSION < 18 r = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr)); + // r: 1 = success, 2 = not connected, 3 = unrecognized IGD +#else + r = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr), nullptr, 0); + // r: 1 = success, 2 = success but not routable (i.e. CGNAT), 3 = not connected, 4 = unrecognized IGD +#endif // MINIUPNPC_API_VERSION < 18 if (r == 1) { if (fDiscover) { @@ -1543,7 +1552,7 @@ void ThreadMapPort() throw; } } else { - LogPrintf("No valid UPnP IGDs found\n"); + LogPrintf("No valid UPnP IGDs found: %d\n", r); freeUPNPDevlist(devlist); devlist = 0; if (r != 0) FreeUPNPUrls(&urls);