Skip to content

Commit 9482cb7

Browse files
committed
netbase: possibly change the result of LookupSubNet() to CJDNS
All callers of `LookupSubNet()` need the result to be of CJDNS type if `-cjdnsreachable` is set and the address begins with `fc`: * `NetWhitelistPermissions::TryParse()`: otherwise `-whitelist=` fails to white list CJDNS addresses: when a CJDNS peer connects to us, it will be matched against IPv6 `fc...` subnet and the match will never succeed. * `BanMapFromJson()`: CJDNS bans are stored as just IPv6 addresses in `banlist.json`. Upon reading from disk they have to be converted back to CJDNS, otherwise, after restart, a ban entry like (`fc00::1`, IPv6) would not match a peer (`fc00::1`, CJDNS). * `setban()` (in `rpc/net.cpp`): otherwise `setban fc.../mask add` would add an IPv6 entry to BanMan. Subnetting does not make sense for CJDNS addresses, thus treat `fc.../mask` as invalid `CSubNet`. The result of `LookupHost()` has to be converted for the case of banning a single host. * `InitHTTPAllowList()`: not necessary since before this change `-rpcallowip=fc...` would match IPv6 subnets against IPv6 peers even if they started with `fc`. But because it is necessary for the above, `HTTPRequest::GetPeer()` also has to be adjusted to return CJDNS peer, so that now CJDNS peers are matched against CJDNS subnets.
1 parent 53afa68 commit 9482cb7

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/httpserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ CService HTTPRequest::GetPeer() const
682682
evhttp_connection_get_peer(con, (char**)&address, &port);
683683
#endif // HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR
684684

685-
peer = LookupNumeric(address, port);
685+
peer = MaybeFlipIPv6toCJDNS(LookupNumeric(address, port));
686686
}
687687
return peer;
688688
}

src/netbase.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,10 @@ bool LookupSubNet(const std::string& subnet_str, CSubNet& subnet_out)
653653

654654
const size_t slash_pos{subnet_str.find_last_of('/')};
655655
const std::string str_addr{subnet_str.substr(0, slash_pos)};
656-
const std::optional<CNetAddr> addr{LookupHost(str_addr, /*fAllowLookup=*/false)};
656+
std::optional<CNetAddr> addr{LookupHost(str_addr, /*fAllowLookup=*/false)};
657657

658658
if (addr.has_value()) {
659+
addr = static_cast<CNetAddr>(MaybeFlipIPv6toCJDNS(CService{addr.value(), /*port=*/0}));
659660
if (slash_pos != subnet_str.npos) {
660661
const std::string netmask_str{subnet_str.substr(slash_pos + 1)};
661662
uint8_t netmask;

src/rpc/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ static RPCHelpMan setban()
730730
if (!isSubnet) {
731731
const std::optional<CNetAddr> addr{LookupHost(request.params[0].get_str(), false)};
732732
if (addr.has_value()) {
733-
netAddr = addr.value();
733+
netAddr = static_cast<CNetAddr>(MaybeFlipIPv6toCJDNS(CService{addr.value(), /*port=*/0}));
734734
}
735735
}
736736
else

0 commit comments

Comments
 (0)