diff options
author | Vasil Dimov <vd@FreeBSD.org> | 2020-10-19 15:32:54 +0200 |
---|---|---|
committer | Vasil Dimov <vd@FreeBSD.org> | 2022-03-02 15:42:40 +0100 |
commit | 7d64ea4a01920bb55bc6de0de6766712ec792a11 (patch) | |
tree | 75722477417ad2a8c3600dd8634d57befcdce58a /src | |
parent | 0cfc0cd32239d3c08d2121e028b297022450b320 (diff) |
net: only assume all local addresses if listening on any
If `-bind=` is provided then we would bind only to a particular address
and should not add all the other addresses of the machine to the list of
local addresses.
Fixes https://github.com/bitcoin/bitcoin/issues/20184 (case 4.)
Diffstat (limited to 'src')
-rw-r--r-- | src/init.cpp | 8 | ||||
-rw-r--r-- | src/net.h | 8 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/init.cpp b/src/init.cpp index 05a8437043..a3d53c3fae 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1668,8 +1668,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) LogPrintf("nBestHeight = %d\n", chain_active_height); if (node.peerman) node.peerman->SetBestHeight(chain_active_height); - Discover(); - // Map ports with UPnP or NAT-PMP. StartMapPort(args.GetBoolArg("-upnp", DEFAULT_UPNP), gArgs.GetBoolArg("-natpmp", DEFAULT_NATPMP)); @@ -1762,6 +1760,12 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) StartTorControl(onion_service_target); } + if (connOptions.bind_on_any) { + // Only add all IP addresses of the machine if we would be listening on + // any address - 0.0.0.0 (IPv4) and :: (IPv6). + Discover(); + } + for (const auto& net : args.GetArgs("-whitelist")) { NetWhitelistPermissions subnet; bilingual_str error; @@ -183,7 +183,15 @@ enum class ConnectionType { /** Convert ConnectionType enum to a string value */ std::string ConnectionTypeAsString(ConnectionType conn_type); + +/** + * Look up IP addresses from all interfaces on the machine and add them to the + * list of local addresses to self-advertise. + * The loopback interface is skipped and only the first address from each + * interface is used. + */ void Discover(); + uint16_t GetListenPort(); enum |