mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-04 06:12:07 +01:00
Merge #15993: net: Drop support of the insecure miniUPnPc versions
59cb722fd0Update configure to reject unsafe miniUPnPc API ver (Hennadii Stepanov)ab2190557edoc: Add release notes for 15993 (Hennadii Stepanov)02709e9560Align formatting with clang-format (Hennadii Stepanov)91a1b85083Use PACKAGE_NAME in UPnP description (Hennadii Stepanov)9f76e45b9dDrop support of insecure miniUPnPc versions (Hennadii Stepanov) Pull request description: 1. Minimum supported miniUPnPc API version is set to 10: - https://packages.ubuntu.com/xenial/libminiupnpc-dev - https://packages.debian.org/jessie/libminiupnpc-dev Refs: - #6583 - #6789 - #10414 2. The hardcoded "Bitcoin" replaced with `PACKAGE_NAME`:  3. Also style-only commit applied. Pardon: could not reopen my previous PR #15966. ACKs for top commit: ryanofsky: utACK59cb722fd0. Changes since last review: adding a new commit which updates configure script to fall back to disabling upnp if version is too old, adding a requested comment explaining static_assert condition, and fixing a spelling (jessy/jessie) Tree-SHA512: 42ed11bc2fb2ec83d5dd58e2383da5444a24fd572707f6cf10b622cb8943e28adfcca4750d06801024c4472625b5ea9279516fbd9d2ccebc9bbaafe1d148e80d
This commit is contained in:
48
src/net.cpp
48
src/net.cpp
@@ -37,6 +37,9 @@
|
||||
#include <miniupnpc/miniwget.h>
|
||||
#include <miniupnpc/upnpcommands.h>
|
||||
#include <miniupnpc/upnperrors.h>
|
||||
// The minimum supported miniUPnPc API version is set to 10. This keeps compatibility
|
||||
// with Ubuntu 16.04 LTS and Debian 8 libminiupnpc-dev packages.
|
||||
static_assert(MINIUPNPC_API_VERSION >= 10, "miniUPnPc API version >= 10 assumed");
|
||||
#endif
|
||||
|
||||
#include <unordered_map>
|
||||
@@ -1404,16 +1407,10 @@ static void ThreadMapPort()
|
||||
struct UPNPDev * devlist = nullptr;
|
||||
char lanaddr[64];
|
||||
|
||||
#ifndef UPNPDISCOVER_SUCCESS
|
||||
/* miniupnpc 1.5 */
|
||||
devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0);
|
||||
#elif MINIUPNPC_API_VERSION < 14
|
||||
/* miniupnpc 1.6 */
|
||||
int error = 0;
|
||||
#if MINIUPNPC_API_VERSION < 14
|
||||
devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, &error);
|
||||
#else
|
||||
/* miniupnpc 1.9.20150730 */
|
||||
int error = 0;
|
||||
devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, 2, &error);
|
||||
#endif
|
||||
|
||||
@@ -1427,43 +1424,32 @@ static void ThreadMapPort()
|
||||
if (fDiscover) {
|
||||
char externalIPAddress[40];
|
||||
r = UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIPAddress);
|
||||
if(r != UPNPCOMMAND_SUCCESS)
|
||||
if (r != UPNPCOMMAND_SUCCESS) {
|
||||
LogPrintf("UPnP: GetExternalIPAddress() returned %d\n", r);
|
||||
else
|
||||
{
|
||||
if(externalIPAddress[0])
|
||||
{
|
||||
} else {
|
||||
if (externalIPAddress[0]) {
|
||||
CNetAddr resolved;
|
||||
if(LookupHost(externalIPAddress, resolved, false)) {
|
||||
if (LookupHost(externalIPAddress, resolved, false)) {
|
||||
LogPrintf("UPnP: ExternalIPAddress = %s\n", resolved.ToString().c_str());
|
||||
AddLocal(resolved, LOCAL_UPNP);
|
||||
}
|
||||
}
|
||||
else
|
||||
} else {
|
||||
LogPrintf("UPnP: GetExternalIPAddress failed.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string strDesc = "Bitcoin " + FormatFullVersion();
|
||||
std::string strDesc = PACKAGE_NAME " " + FormatFullVersion();
|
||||
|
||||
do {
|
||||
#ifndef UPNPDISCOVER_SUCCESS
|
||||
/* miniupnpc 1.5 */
|
||||
r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
|
||||
port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0);
|
||||
#else
|
||||
/* miniupnpc 1.6 */
|
||||
r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
|
||||
port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0, "0");
|
||||
#endif
|
||||
r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0, "0");
|
||||
|
||||
if(r!=UPNPCOMMAND_SUCCESS)
|
||||
LogPrintf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n",
|
||||
port, port, lanaddr, r, strupnperror(r));
|
||||
else
|
||||
if (r != UPNPCOMMAND_SUCCESS) {
|
||||
LogPrintf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n", port, port, lanaddr, r, strupnperror(r));
|
||||
} else {
|
||||
LogPrintf("UPnP Port Mapping successful.\n");
|
||||
}
|
||||
while(g_upnp_interrupt.sleep_for(std::chrono::minutes(20)));
|
||||
}
|
||||
} while (g_upnp_interrupt.sleep_for(std::chrono::minutes(20)));
|
||||
|
||||
r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(), "TCP", 0);
|
||||
LogPrintf("UPNP_DeletePortMapping() returned: %d\n", r);
|
||||
|
||||
Reference in New Issue
Block a user