From 45b5069775eb0e38457fb8f66c3935343eef069d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Wed, 6 Mar 2024 11:18:50 -0500
Subject: [PATCH] UPnP: workaround invalid action returned by some routers

Change-Id: I5db532611b48916b599d81515a37664a61830d20
---
 src/upnp/protocol/pupnp/pupnp.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/upnp/protocol/pupnp/pupnp.cpp b/src/upnp/protocol/pupnp/pupnp.cpp
index d07cc20..7003a49 100644
--- a/src/upnp/protocol/pupnp/pupnp.cpp
+++ b/src/upnp/protocol/pupnp/pupnp.cpp
@@ -1157,6 +1157,13 @@ PUPnP::actionIsIgdConnected(const UPnPIGD& igd)
                                   nullptr,
                                   action.get(),
                                   &response_container_ptr);
+    if (upnp_err == 401) {
+        // YET ANOTHER UPNP HACK: MiniUpnp on some routers seems to not recognize this action, sending a 401: Invalid Action.
+        // So even if mapping succeeds, the router was considered as not connected.
+        // Returning true here works around this issue.
+        // E.g. https://community.tp-link.com/us/home/forum/topic/577840
+        return true;
+    }
     if (not response_container_ptr or upnp_err != UPNP_E_SUCCESS) {
         if (logger_) logger_->warn("PUPnP: Failed to send GetStatusInfo action -> {}", UpnpGetErrorMessage(upnp_err));
         return false;
-- 
GitLab