aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2020-12-22 02:11:52 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2020-12-22 02:12:41 +0000
commit56748e1d746e3aad68eaa9f6a98b4823aa512fd4 (patch)
treef3b9b8d096340821d5874707b878ac2b042d5df6 /src
parentMerge pull request #7151 (diff)
downloadmonero-56748e1d746e3aad68eaa9f6a98b4823aa512fd4.tar.xz
ban lists may now include subnets
Diffstat (limited to 'src')
-rw-r--r--src/daemon/command_parser_executor.cpp12
-rw-r--r--src/p2p/net_node.inl12
2 files changed, 18 insertions, 6 deletions
diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp
index 767ce7bc6..5a7560874 100644
--- a/src/daemon/command_parser_executor.cpp
+++ b/src/daemon/command_parser_executor.cpp
@@ -694,13 +694,19 @@ bool t_command_parser_executor::ban(const std::vector<std::string>& args)
std::ifstream ifs(ban_list_path.string());
for (std::string line; std::getline(ifs, line); )
{
+ auto subnet = net::get_ipv4_subnet_address(line);
+ if (subnet)
+ {
+ ret &= m_executor.ban(subnet->str(), seconds);
+ continue;
+ }
const expect<epee::net_utils::network_address> parsed_addr = net::get_network_address(line, 0);
- if (!parsed_addr)
+ if (parsed_addr)
{
- std::cout << "Invalid IP address: " << line << " - " << parsed_addr.error() << std::endl;
+ ret &= m_executor.ban(parsed_addr->host_str(), seconds);
continue;
}
- ret &= m_executor.ban(parsed_addr->host_str(), seconds);
+ std::cout << "Invalid IP address or IPv4 subnet: " << line << std::endl;
}
return ret;
}
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index ab098b7d4..f1638325c 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -481,13 +481,19 @@ namespace nodetool
std::istringstream iss(banned_ips);
for (std::string line; std::getline(iss, line); )
{
+ auto subnet = net::get_ipv4_subnet_address(line);
+ if (subnet)
+ {
+ block_subnet(*subnet, std::numeric_limits<time_t>::max());
+ continue;
+ }
const expect<epee::net_utils::network_address> parsed_addr = net::get_network_address(line, 0);
- if (!parsed_addr)
+ if (parsed_addr)
{
- MERROR("Invalid IP address: " << line << " - " << parsed_addr.error());
+ block_host(*parsed_addr, std::numeric_limits<time_t>::max());
continue;
}
- block_host(*parsed_addr, std::numeric_limits<time_t>::max());
+ MERROR("Invalid IP address or IPv4 subnet: " << line);
}
}