From 4ed60a5711b055d8c3b9492e1f8a1f65ad3c4571 Mon Sep 17 00:00:00 2001 From: Max Audron Date: Mon, 8 Nov 2021 22:48:07 +0100 Subject: [PATCH] upnp: expose interface configuration on UpnpInit2() Adds the Interface Name as an argument to the *Init functions to make it possible to select which interface is used by upnp to detect servers. Currently "nullptr" is passed in to let the upnp library select an interface, as before. --- src/db/plugins/upnp/UpnpDatabasePlugin.cxx | 2 +- src/lib/upnp/ClientInit.cxx | 4 ++-- src/lib/upnp/ClientInit.hxx | 2 +- src/lib/upnp/Init.cxx | 11 ++++++----- src/lib/upnp/Init.hxx | 2 +- src/neighbor/plugins/UpnpNeighborPlugin.cxx | 2 +- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/db/plugins/upnp/UpnpDatabasePlugin.cxx b/src/db/plugins/upnp/UpnpDatabasePlugin.cxx index f5bd48a62..86d3fe99a 100644 --- a/src/db/plugins/upnp/UpnpDatabasePlugin.cxx +++ b/src/db/plugins/upnp/UpnpDatabasePlugin.cxx @@ -155,7 +155,7 @@ UpnpDatabase::Create(EventLoop &, EventLoop &io_event_loop, void UpnpDatabase::Open() { - handle = UpnpClientGlobalInit(); + handle = UpnpClientGlobalInit(nullptr); discovery = new UPnPDeviceDirectory(event_loop, handle); try { diff --git a/src/lib/upnp/ClientInit.cxx b/src/lib/upnp/ClientInit.cxx index 1bf1dc146..f6796d219 100644 --- a/src/lib/upnp/ClientInit.cxx +++ b/src/lib/upnp/ClientInit.cxx @@ -57,9 +57,9 @@ DoInit() } UpnpClient_Handle -UpnpClientGlobalInit() +UpnpClientGlobalInit(const char* iface) { - UpnpGlobalInit(); + UpnpGlobalInit(iface); try { const std::lock_guard protect(upnp_client_init_mutex); diff --git a/src/lib/upnp/ClientInit.hxx b/src/lib/upnp/ClientInit.hxx index ac4729df5..6b2e2be16 100644 --- a/src/lib/upnp/ClientInit.hxx +++ b/src/lib/upnp/ClientInit.hxx @@ -23,7 +23,7 @@ #include "Compat.hxx" UpnpClient_Handle -UpnpClientGlobalInit(); +UpnpClientGlobalInit(const char* iface); void UpnpClientGlobalFinish() noexcept; diff --git a/src/lib/upnp/Init.cxx b/src/lib/upnp/Init.cxx index f9f0c8515..29bbe2c98 100644 --- a/src/lib/upnp/Init.cxx +++ b/src/lib/upnp/Init.cxx @@ -33,12 +33,13 @@ static Mutex upnp_init_mutex; static unsigned upnp_ref; static void -DoInit() +DoInit(const char* iface) { + #ifdef UPNP_ENABLE_IPV6 - auto code = UpnpInit2(nullptr, 0); + auto code = UpnpInit2(iface, 0); #else - auto code = UpnpInit(nullptr, 0); + auto code = UpnpInit(iface, 0); #endif if (code != UPNP_E_SUCCESS) throw FormatRuntimeError("UpnpInit() failed: %s", @@ -53,12 +54,12 @@ DoInit() } void -UpnpGlobalInit() +UpnpGlobalInit(const char* iface) { const std::lock_guard protect(upnp_init_mutex); if (upnp_ref == 0) - DoInit(); + DoInit(iface); ++upnp_ref; } diff --git a/src/lib/upnp/Init.hxx b/src/lib/upnp/Init.hxx index 356fa00d5..fdacd06ba 100644 --- a/src/lib/upnp/Init.hxx +++ b/src/lib/upnp/Init.hxx @@ -21,7 +21,7 @@ #define MPD_UPNP_INIT_HXX void -UpnpGlobalInit(); +UpnpGlobalInit(const char* iface); void UpnpGlobalFinish() noexcept; diff --git a/src/neighbor/plugins/UpnpNeighborPlugin.cxx b/src/neighbor/plugins/UpnpNeighborPlugin.cxx index e0bcbf615..54a7fb251 100644 --- a/src/neighbor/plugins/UpnpNeighborPlugin.cxx +++ b/src/neighbor/plugins/UpnpNeighborPlugin.cxx @@ -74,7 +74,7 @@ private: void UpnpNeighborExplorer::Open() { - auto handle = UpnpClientGlobalInit(); + auto handle = UpnpClientGlobalInit(nullptr); discovery = new UPnPDeviceDirectory(event_loop, handle, this);