Don't ban localhost

pull/166/head
SChernykh 2 years ago
parent 6b4640c413
commit 8f27d940e3

@ -309,6 +309,14 @@ struct raw_ip
}
FORCEINLINE bool operator!=(const raw_ip& other) const { return !operator==(other); }
FORCEINLINE bool is_localhost() const
{
static constexpr raw_ip localhost_ipv4 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x01 };
static constexpr raw_ip localhost_ipv6 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
return (*this == localhost_ipv4) || (*this == localhost_ipv6);
}
};
static_assert(sizeof(raw_ip) == 16, "struct raw_ip has invalid size");

@ -322,6 +322,10 @@ void TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::on_connect_failed(bool, const raw
template<size_t READ_BUF_SIZE, size_t WRITE_BUF_SIZE>
bool TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::is_banned(const raw_ip& ip)
{
if (ip.is_localhost()) {
return false;
}
const auto cur_time = std::chrono::steady_clock::now();
MutexLock lock(m_bansLock);
@ -495,6 +499,10 @@ void TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::print_status()
template<size_t READ_BUF_SIZE, size_t WRITE_BUF_SIZE>
void TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::ban(const raw_ip& ip, uint64_t seconds)
{
if (ip.is_localhost()) {
return;
}
const auto ban_time = std::chrono::steady_clock::now() + std::chrono::seconds(seconds);
MutexLock lock(m_bansLock);

Loading…
Cancel
Save