Skip to content

Commit 9cbfe40

Browse files
committed
net: remove useless call to IsReachable() from CConnman::Bind()
`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.
1 parent 62c8646 commit 9cbfe40

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
@@ -2204,9 +2203,6 @@ bool CConnman::Bind(const CService& addr_, unsigned int flags, NetPermissionFlag
22042203
{
22052204
const CService addr{MaybeFlipIPv6toCJDNS(addr_)};
22062205

2207-
if (!(flags & BF_EXPLICIT) && !IsReachable(addr)) {
2208-
return false;
2209-
}
22102206
bilingual_str strError;
22112207
if (!BindListenPort(addr, strError, permissions)) {
22122208
if ((flags & BF_REPORT_ERROR) && m_client_interface) {
@@ -2226,13 +2222,13 @@ bool CConnman::InitBinds(const Options& options)
22262222
{
22272223
bool fBound = false;
22282224
for (const auto& addrBind : options.vBinds) {
2229-
fBound |= Bind(addrBind, (BF_EXPLICIT | BF_REPORT_ERROR), NetPermissionFlags::None);
2225+
fBound |= Bind(addrBind, BF_REPORT_ERROR, NetPermissionFlags::None);
22302226
}
22312227
for (const auto& addrBind : options.vWhiteBinds) {
2232-
fBound |= Bind(addrBind.m_service, (BF_EXPLICIT | BF_REPORT_ERROR), addrBind.m_flags);
2228+
fBound |= Bind(addrBind.m_service, BF_REPORT_ERROR, addrBind.m_flags);
22332229
}
22342230
for (const auto& addr_bind : options.onion_binds) {
2235-
fBound |= Bind(addr_bind, BF_EXPLICIT | BF_DONT_ADVERTISE, NetPermissionFlags::None);
2231+
fBound |= Bind(addr_bind, BF_DONT_ADVERTISE, NetPermissionFlags::None);
22362232
}
22372233
if (options.bind_on_any) {
22382234
struct in_addr inaddr_any;

0 commit comments

Comments
 (0)