net: add an add_even_if_unreachable argument to AddLocal
What changed, and why it matters
This commit is a small, non-functional code cleanup. It adds a new optional parameter to an internal networking function so that a future change can allow user-specified local addresses to bypass a network-reachability check. The new parameter defaults to false, so existing behavior is unchanged. There is no security bug or fix here.
No action required. This is a benign refactoring commit with no security relevance on its own. Review the follow-up commit that actually consumes `add_even_if_unreachable` for security implications.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change introduces a bool argument add_even_if_unreachable to both overloads of AddLocal() in src/net.h and src/net.cpp, defaulting to false. The argument is passed through from the CNetAddr overload to the CService overload, but is not yet used in any logic. The commit message explicitly states this is preparatory refactoring for a later behavior change and avoids tying behavior to the LOCAL_MANUAL score. No call sites pass true, and no control flow is altered.
Changed components
src/net.cppsrc/net.hInspect captured patch +5 / −5
diff --git a/src/net.cpp b/src/net.cpp
index d046c2a2..c903afc6 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -274,7 +274,7 @@ void ClearLocal()
}
// learn a new local address
-bool AddLocal(const CService& addr_, int nScore)
+bool AddLocal(const CService& addr_, int nScore, bool add_even_if_unreachable)
{
CService addr{MaybeFlipIPv6toCJDNS(addr_)};
@@ -304,9 +304,9 @@ bool AddLocal(const CService& addr_, int nScore)
return true;
}
-bool AddLocal(const CNetAddr &addr, int nScore)
+bool AddLocal(const CNetAddr& addr, int nScore, bool add_even_if_unreachable)
{
- return AddLocal(CService(addr, GetListenPort()), nScore);
+ return AddLocal(CService(addr, GetListenPort()), nScore, add_even_if_unreachable);
}
void RemoveLocal(const CService& addr)
diff --git a/src/net.h b/src/net.h
index 928d518e..62e97b48 100644
--- a/src/net.h
+++ b/src/net.h
@@ -164,8 +164,8 @@ enum
std::optional<CService> GetLocalAddrForPeer(CNode& node);
void ClearLocal();
-bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
-bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
+bool AddLocal(const CService& addr, int nScore = LOCAL_NONE, bool add_even_if_unreachable = false);
+bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE, bool add_even_if_unreachable = false);
void RemoveLocal(const CService& addr);
bool SeenLocal(const CService& addr);
bool IsLocal(const CService& addr);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.