From a6d9072f5c6ae29f7d77adef8bfcc70d3974de7f Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Sun, 31 Aug 2025 06:55:36 +0200 Subject: [PATCH] Allow (only) dn42 IPs --- nano/node/transport/transport.cpp | 100 ++++-------------------------- 1 file changed, 12 insertions(+), 88 deletions(-) diff --git a/nano/node/transport/transport.cpp b/nano/node/transport/transport.cpp index d3ec24be..7f3e5668 100644 --- a/nano/node/transport/transport.cpp +++ b/nano/node/transport/transport.cpp @@ -71,98 +71,22 @@ bool nano::transport::reserved_address (nano::endpoint const & endpoint_a, bool { debug_assert (endpoint_a.address ().is_v6 ()); auto bytes (endpoint_a.address ().to_v6 ()); - auto result (false); - static auto const rfc1700_min (mapped_from_v4_bytes (0x00000000ul)); - static auto const rfc1700_max (mapped_from_v4_bytes (0x00fffffful)); - static auto const rfc1918_1_min (mapped_from_v4_bytes (0x0a000000ul)); - static auto const rfc1918_1_max (mapped_from_v4_bytes (0x0afffffful)); - static auto const rfc1918_2_min (mapped_from_v4_bytes (0xac100000ul)); - static auto const rfc1918_2_max (mapped_from_v4_bytes (0xac1ffffful)); - static auto const rfc1918_3_min (mapped_from_v4_bytes (0xc0a80000ul)); - static auto const rfc1918_3_max (mapped_from_v4_bytes (0xc0a8fffful)); - static auto const rfc6598_min (mapped_from_v4_bytes (0x64400000ul)); - static auto const rfc6598_max (mapped_from_v4_bytes (0x647ffffful)); - static auto const rfc5737_1_min (mapped_from_v4_bytes (0xc0000200ul)); - static auto const rfc5737_1_max (mapped_from_v4_bytes (0xc00002fful)); - static auto const rfc5737_2_min (mapped_from_v4_bytes (0xc6336400ul)); - static auto const rfc5737_2_max (mapped_from_v4_bytes (0xc63364fful)); - static auto const rfc5737_3_min (mapped_from_v4_bytes (0xcb007100ul)); - static auto const rfc5737_3_max (mapped_from_v4_bytes (0xcb0071fful)); - static auto const ipv4_multicast_min (mapped_from_v4_bytes (0xe0000000ul)); - static auto const ipv4_multicast_max (mapped_from_v4_bytes (0xeffffffful)); - static auto const rfc6890_min (mapped_from_v4_bytes (0xf0000000ul)); - static auto const rfc6890_max (mapped_from_v4_bytes (0xfffffffful)); - static auto const rfc6666_min (boost::asio::ip::make_address_v6 ("100::")); - static auto const rfc6666_max (boost::asio::ip::make_address_v6 ("100::ffff:ffff:ffff:ffff")); - static auto const rfc3849_min (boost::asio::ip::make_address_v6 ("2001:db8::")); - static auto const rfc3849_max (boost::asio::ip::make_address_v6 ("2001:db8:ffff:ffff:ffff:ffff:ffff:ffff")); - static auto const rfc4193_min (boost::asio::ip::make_address_v6 ("fc00::")); - static auto const rfc4193_max (boost::asio::ip::make_address_v6 ("fd00:ffff:ffff:ffff:ffff:ffff:ffff:ffff")); - static auto const ipv6_multicast_min (boost::asio::ip::make_address_v6 ("ff00::")); - static auto const ipv6_multicast_max (boost::asio::ip::make_address_v6 ("ff00:ffff:ffff:ffff:ffff:ffff:ffff:ffff")); - if (endpoint_a.port () == 0) + auto result (true); + + static auto const dn42_ipv4_min (mapped_from_v4_bytes (0xac140000ul)); + static auto const dn42_ipv4_max (mapped_from_v4_bytes (0xac14fffful)); + static auto const dn42_ipv6_min (boost::asio::ip::make_address_v6 ("fd00::")); + static auto const dn42_ipv6_max (boost::asio::ip::make_address_v6 ("fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")); + + if (bytes >= dn42_ipv4_min && bytes <= dn42_ipv4_max) { - result = true; + result = false; } - else if (bytes >= rfc1700_min && bytes <= rfc1700_max) + else if (bytes >= dn42_ipv6_min && bytes <= dn42_ipv6_max) { - result = true; - } - else if (bytes >= rfc5737_1_min && bytes <= rfc5737_1_max) - { - result = true; - } - else if (bytes >= rfc5737_2_min && bytes <= rfc5737_2_max) - { - result = true; - } - else if (bytes >= rfc5737_3_min && bytes <= rfc5737_3_max) - { - result = true; - } - else if (bytes >= ipv4_multicast_min && bytes <= ipv4_multicast_max) - { - result = true; - } - else if (bytes >= rfc6890_min && bytes <= rfc6890_max) - { - result = true; - } - else if (bytes >= rfc6666_min && bytes <= rfc6666_max) - { - result = true; - } - else if (bytes >= rfc3849_min && bytes <= rfc3849_max) - { - result = true; - } - else if (bytes >= ipv6_multicast_min && bytes <= ipv6_multicast_max) - { - result = true; - } - else if (!allow_local_peers) - { - if (bytes >= rfc1918_1_min && bytes <= rfc1918_1_max) - { - result = true; - } - else if (bytes >= rfc1918_2_min && bytes <= rfc1918_2_max) - { - result = true; - } - else if (bytes >= rfc1918_3_min && bytes <= rfc1918_3_max) - { - result = true; - } - else if (bytes >= rfc6598_min && bytes <= rfc6598_max) - { - result = true; - } - else if (bytes >= rfc4193_min && bytes <= rfc4193_max) - { - result = true; - } + result = false; } + return result; }