Skip to content

Commit b92b12e

Browse files
committed
Merge bitcoin/bitcoin#25735: net: remove useless call to IsReachable() from CConnman::Bind()
9cbfe40 net: remove useless call to IsReachable() from CConnman::Bind() (Vasil Dimov) Pull request description: `CConnman::Bind()` is called without `BF_EXPLICIT` only when passed either `0.0.0.0` or `::`. For those addresses `IsReachable()` is always true (regardless of the `-onlynet=` setting!), meaning that the `if` condition never evaluates to true. `IsReachable()` is always true for the "any" IPv4 and IPv6 addresses because `CNetAddr::GetNetwork()` returns `NET_UNROUTABLE` instead of `NET_IPV4` or `NET_IPV6` and the network `NET_UNROUTABLE` is always considered reachable. It follows that `BF_EXPLICIT` is unnecessary, remove it too. ACKs for top commit: naumenkogs: ACK 9cbfe40 aureleoules: ACK 9cbfe40 mzumsande: ACK 9cbfe40 Tree-SHA512: 4e53ee8a73ddd133fd4ff25635135b65e5c19d1fc56fe5c30337406560664616c0adff414dca47602948919f34c81073aae6bfc2871509f3912663d86750928e
2 parents 3baa0f5 + 9cbfe40 commit b92b12e

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/net.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,12 @@ static constexpr auto FEELER_SLEEP_WINDOW{1s};
9191
/** Used to pass flags to the Bind() function */
9292
enum BindFlags {
9393
BF_NONE = 0,
94-
BF_EXPLICIT = (1U << 0),
95-
BF_REPORT_ERROR = (1U << 1),
94+
BF_REPORT_ERROR = (1U << 0),
9695
/**
9796
* Do not call AddLocal() for our special addresses, e.g., for incoming
9897
* Tor connections, to prevent gossiping them over the network.
9998
*/
100-
BF_DONT_ADVERTISE = (1U << 2),
99+
BF_DONT_ADVERTISE = (1U << 1),
101100
};
102101

103102
// The set of sockets cannot be modified while waiting
@@ -2231,9 +2230,6 @@ bool CConnman::Bind(const CService& addr_, unsigned int flags, NetPermissionFlag
22312230
{
22322231
const CService addr{MaybeFlipIPv6toCJDNS(addr_)};
22332232

2234-
if (!(flags & BF_EXPLICIT) && !IsReachable(addr)) {
2235-
return false;
2236-
}
22372233
bilingual_str strError;
22382234
if (!BindListenPort(addr, strError, permissions)) {
22392235
if ((flags & BF_REPORT_ERROR) && m_client_interface) {
@@ -2253,13 +2249,13 @@ bool CConnman::InitBinds(const Options& options)
22532249
{
22542250
bool fBound = false;
22552251
for (const auto& addrBind : options.vBinds) {
2256-
fBound |= Bind(addrBind, (BF_EXPLICIT | BF_REPORT_ERROR), NetPermissionFlags::None);
2252+
fBound |= Bind(addrBind, BF_REPORT_ERROR, NetPermissionFlags::None);
22572253
}
22582254
for (const auto& addrBind : options.vWhiteBinds) {
2259-
fBound |= Bind(addrBind.m_service, (BF_EXPLICIT | BF_REPORT_ERROR), addrBind.m_flags);
2255+
fBound |= Bind(addrBind.m_service, BF_REPORT_ERROR, addrBind.m_flags);
22602256
}
22612257
for (const auto& addr_bind : options.onion_binds) {
2262-
fBound |= Bind(addr_bind, BF_EXPLICIT | BF_DONT_ADVERTISE, NetPermissionFlags::None);
2258+
fBound |= Bind(addr_bind, BF_DONT_ADVERTISE, NetPermissionFlags::None);
22632259
}
22642260
if (options.bind_on_any) {
22652261
struct in_addr inaddr_any;

0 commit comments

Comments
 (0)