From 7be9aed9a6701bd43b4d15e2595cedeff4a4e681 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Tue, 1 Feb 2011 12:01:28 +0100 Subject: [PATCH] Log burnt IP only once --- src/service.cpp | 17 ++++++++++++++++- src/service.hpp | 1 + 2 files changed, 17 insertions(+), 1 deletions(-) diff --git a/src/service.cpp b/src/service.cpp index 3eebff0..f8279ae 100644 --- a/src/service.cpp +++ b/src/service.cpp @@ -24,6 +24,7 @@ Service::Service() : Login("NOT SERIALIZED") , Password("NOT SERIALIZED") , ActualIP("0.0.0.0") + , ActualIPIsBurnt(false) , UpdateInterval(15) , MaxUpdatesWithinInterval(3) , MaxEqualUpdatesInSuccession(2) @@ -209,6 +210,7 @@ bool Service::operator!= (const Service& other) const * Checks if update will exceed max update interval or if the IP address is burnt. * @param current_time Current time. * @param changed_to_online True if we just changed to online, false if we were already online + * @param ip_host The new ip to set for the hostname. * @return True if update is allowed, false if update would exceed max update interval. */ bool Service::update_allowed(const time_t current_time, bool changed_to_online, const std::string& ip_host) @@ -227,6 +229,18 @@ bool Service::update_allowed(const time_t current_time, bool changed_to_online, i++; } + if (ActualIPIsBurnt) + { + // Changed IP address removes the "burnt state" + if (ip_host != ActualIP) + ActualIPIsBurnt = false; + else + { + // IP is burnt and didn't change -> Update not allowed + return false; + } + } + // Check for burnt IP. // Only check for burnt IP address if there are at least max_equal_updates_in_succession entries in the last_updates map. if ( (MaxEqualUpdatesInSuccession != 0) && ((int)LastUpdates.size() >= MaxEqualUpdatesInSuccession) ) @@ -248,8 +262,9 @@ bool Service::update_allowed(const time_t current_time, bool changed_to_online, if ( ip_burnt ) { - // IP Address is burnt. Too many updates in succession with the same IP. + // IP Address is burnt. Too many updates in succession with the same IP. Log once. Log->print_ip_burnt(ip_host,get_service_name()); + ActualIPIsBurnt = true; return false; } } diff --git a/src/service.hpp b/src/service.hpp index 82b765b..09548f2 100644 --- a/src/service.hpp +++ b/src/service.hpp @@ -32,6 +32,7 @@ private: std::string Password; std::string ActualIP; + bool ActualIPIsBurnt; int UpdateInterval; int MaxUpdatesWithinInterval; -- 1.7.1