diff --git a/src/common.h b/src/common.h index ee20286..75c3495 100644 --- a/src/common.h +++ b/src/common.h @@ -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"); diff --git a/src/tcp_server.inl b/src/tcp_server.inl index 7c69c28..f73b334 100644 --- a/src/tcp_server.inl +++ b/src/tcp_server.inl @@ -322,6 +322,10 @@ void TCPServer::on_connect_failed(bool, const raw template bool TCPServer::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::print_status() template void TCPServer::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);