Log burnt IP only once
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Tue, 1 Feb 2011 11:01:28 +0000 (12:01 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Tue, 1 Feb 2011 11:01:28 +0000 (12:01 +0100)
src/service.cpp
src/service.hpp

index 3eebff0..f8279ae 100644 (file)
@@ -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;
         }
     }
index 82b765b..09548f2 100644 (file)
@@ -32,6 +32,7 @@ private:
     std::string Password;
 
     std::string ActualIP;
+    bool ActualIPIsBurnt;
 
     int UpdateInterval;
     int MaxUpdatesWithinInterval;