mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-18 13:17:55 +02:00
net: allow CSubNet of non-IP networks
Allow creation of valid `CSubNet` objects of non-IP networks and only match the single address they were created from (like /32 for IPv4 or /128 for IPv6). This fixes a deficiency in `CConnman::DisconnectNode(const CNetAddr& addr)` and in `BanMan` which assume that creating a subnet from any address using the `CSubNet(CNetAddr)` constructor would later match that address only. Before this change a non-IP subnet would be invalid and would not match any address. Github-Pull: #20852 Rebased-From:94d335da7f(cherry picked from commitc33fbab25c)
This commit is contained in:
parent
81ea0ed4a6
commit
0682f35ee4
3 changed files with 107 additions and 19 deletions
|
|
@ -224,8 +224,22 @@ BOOST_AUTO_TEST_CASE(subnet_test)
|
|||
// IPv4 address with IPv6 netmask or the other way around.
|
||||
BOOST_CHECK(!CSubNet(ResolveIP("1.1.1.1"), ResolveIP("ffff::")).IsValid());
|
||||
BOOST_CHECK(!CSubNet(ResolveIP("::1"), ResolveIP("255.0.0.0")).IsValid());
|
||||
// Can't subnet TOR (or any other non-IPv4 and non-IPv6 network).
|
||||
BOOST_CHECK(!CSubNet(ResolveIP("5wyqrzbvrdsumnok.onion"), ResolveIP("255.0.0.0")).IsValid());
|
||||
|
||||
// Create Non-IP subnets.
|
||||
|
||||
const CNetAddr tor_addr{
|
||||
ResolveIP("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion")};
|
||||
|
||||
subnet = CSubNet(tor_addr);
|
||||
BOOST_CHECK(subnet.IsValid());
|
||||
BOOST_CHECK_EQUAL(subnet.ToString(), tor_addr.ToString());
|
||||
BOOST_CHECK(subnet.Match(tor_addr));
|
||||
BOOST_CHECK(
|
||||
!subnet.Match(ResolveIP("kpgvmscirrdqpekbqjsvw5teanhatztpp2gl6eee4zkowvwfxwenqaid.onion")));
|
||||
BOOST_CHECK(!subnet.Match(ResolveIP("1.2.3.4")));
|
||||
|
||||
BOOST_CHECK(!CSubNet(tor_addr, 200).IsValid());
|
||||
BOOST_CHECK(!CSubNet(tor_addr, ResolveIP("255.0.0.0")).IsValid());
|
||||
|
||||
subnet = ResolveSubNet("1.2.3.4/255.255.255.255");
|
||||
BOOST_CHECK_EQUAL(subnet.ToString(), "1.2.3.4/32");
|
||||
|
|
@ -440,8 +454,7 @@ BOOST_AUTO_TEST_CASE(netbase_dont_resolve_strings_with_embedded_nul_characters)
|
|||
BOOST_CHECK(!LookupSubNet(std::string("1.2.3.0/24\0", 11), ret));
|
||||
BOOST_CHECK(!LookupSubNet(std::string("1.2.3.0/24\0example.com", 22), ret));
|
||||
BOOST_CHECK(!LookupSubNet(std::string("1.2.3.0/24\0example.com\0", 23), ret));
|
||||
// We only do subnetting for IPv4 and IPv6
|
||||
BOOST_CHECK(!LookupSubNet(std::string("5wyqrzbvrdsumnok.onion", 22), ret));
|
||||
BOOST_CHECK(LookupSubNet(std::string("5wyqrzbvrdsumnok.onion", 22), ret));
|
||||
BOOST_CHECK(!LookupSubNet(std::string("5wyqrzbvrdsumnok.onion\0", 23), ret));
|
||||
BOOST_CHECK(!LookupSubNet(std::string("5wyqrzbvrdsumnok.onion\0example.com", 34), ret));
|
||||
BOOST_CHECK(!LookupSubNet(std::string("5wyqrzbvrdsumnok.onion\0example.com\0", 35), ret));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue