]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[685-log-the-expected-subnet-id-as-well-as-the-actual-subnet-id-when-the-sanity-check...
authorFrancis Dupont <fdupont@isc.org>
Fri, 21 Jun 2019 14:29:41 +0000 (16:29 +0200)
committerFrancis Dupont <fdupont@isc.org>
Wed, 26 Jun 2019 12:51:04 +0000 (14:51 +0200)
src/lib/dhcpsrv/dhcpsrv_messages.cc
src/lib/dhcpsrv/dhcpsrv_messages.h
src/lib/dhcpsrv/dhcpsrv_messages.mes
src/lib/dhcpsrv/sanity_checker.cc

index 0fc54f85954fb9c6bf5dc5cd73f7826baaab86d2..c877d365b0c829d5f78dcce3f46ab5d7ab88f4af 100644 (file)
@@ -1,4 +1,4 @@
-// File created from ../../../src/lib/dhcpsrv/dhcpsrv_messages.mes on Tue Apr 16 2019 17:21
+// File created from ../../../src/lib/dhcpsrv/dhcpsrv_messages.mes on Fri Jun 21 2019 16:14
 
 #include <cstddef>
 #include <log/message_types.h>
@@ -329,8 +329,8 @@ const char* values[] = {
     "DHCPSRV_HOOK_LEASE6_RECOVER_SKIP", "DHCPv6 lease %1 was not recovered from declined state because a callout set the skip status.",
     "DHCPSRV_HOOK_LEASE6_SELECT_SKIP", "Lease6 (non-temporary) creation was skipped, because of callout skip flag.",
     "DHCPSRV_INVALID_ACCESS", "invalid database access string: %1",
-    "DHCPSRV_LEASE_SANITY_FAIL", "The lease %1 with subnet-id %2 failed subnet-id checks.",
-    "DHCPSRV_LEASE_SANITY_FAIL_DISCARD", "The lease %1 with subnet-id %2 failed subnet-id checks and was dropped.",
+    "DHCPSRV_LEASE_SANITY_FAIL", "The lease %1 with subnet-id %2 failed subnet-id checks (%3).",
+    "DHCPSRV_LEASE_SANITY_FAIL_DISCARD", "The lease %1 with subnet-id %2 failed subnet-id checks (%3) and was dropped.",
     "DHCPSRV_LEASE_SANITY_FIXED", "The lease %1 with subnet-id %2 failed subnet-id checks, but was corrected to subnet-id %3.",
     "DHCPSRV_MEMFILE_ADD_ADDR4", "adding IPv4 lease with address %1",
     "DHCPSRV_MEMFILE_ADD_ADDR6", "adding IPv6 lease with address %1",
index 854de0155c6bf5391e717f41cc701eb4673f36a9..effc486d098e8cd9713eccdcbff59ba55941620d 100644 (file)
@@ -1,4 +1,4 @@
-// File created from ../../../src/lib/dhcpsrv/dhcpsrv_messages.mes on Tue Apr 16 2019 17:21
+// File created from ../../../src/lib/dhcpsrv/dhcpsrv_messages.mes on Fri Jun 21 2019 16:14
 
 #ifndef DHCPSRV_MESSAGES_H
 #define DHCPSRV_MESSAGES_H
index 6ad1ef292a517292fab62dab51c786c447da046e..fa451ab7df09205fdab57d655381888dbbdb42b3 100644 (file)
@@ -450,13 +450,13 @@ and the attempt ended in error.  The access string in question - which
 should be of the form 'keyword=value keyword=value...' is included in
 the message.
 
-% DHCPSRV_LEASE_SANITY_FAIL The lease %1 with subnet-id %2 failed subnet-id checks.
+% DHCPSRV_LEASE_SANITY_FAIL The lease %1 with subnet-id %2 failed subnet-id checks (%3).
 This warning message is printed when the lease being loaded does not match the
 configuration. Due to lease-checks value, the lease will be loaded, but
 it will most likely be unused by Kea, as there is no subnet that matches
 the IP address associated with the lease.
 
-% DHCPSRV_LEASE_SANITY_FAIL_DISCARD The lease %1 with subnet-id %2 failed subnet-id checks and was dropped.
+% DHCPSRV_LEASE_SANITY_FAIL_DISCARD The lease %1 with subnet-id %2 failed subnet-id checks (%3) and was dropped.
 This warning message is printed when a lease was loaded, but Kea was told
 (by setting lease-checks parameter) to discard leases with inconsistent
 data. The lease was discarded, because either there is no subnet configured
index 6e512d09ed5ca8cdef60d72e941b9695176a6e99..1ce6959fa6199fcb7689698628993a2e84db0fe2 100644 (file)
@@ -9,6 +9,7 @@
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/subnet_id.h>
 #include <dhcpsrv/dhcpsrv_log.h>
+#include <sstream>
 
 namespace isc {
 namespace dhcp {
@@ -63,6 +64,14 @@ void SanityChecker::checkLeaseInternal(LeasePtrType& lease, const CfgConsistency
     // of found it, but it wasn't the right subnet.
     SubnetID id = findSubnetId(lease, subnets);
 
+    // Prepare a message in the case the check fails.
+    std::ostringstream msg;
+    if (id != 0) {
+        msg << "the lease should have subnet-id " << id;
+    } else {
+        msg << "the lease IP address did not belong to a configured subnet";
+    }
+
     switch (checks->getLeaseSanityCheck()) {
     case CfgConsistency::LEASE_CHECK_NONE:
         // No checks whatsoever, just return the lease as-is.
@@ -71,7 +80,9 @@ void SanityChecker::checkLeaseInternal(LeasePtrType& lease, const CfgConsistency
         if (lease->subnet_id_ != id) {
             // Print a warning, but return the lease as is.
             LOG_WARN(dhcpsrv_logger, DHCPSRV_LEASE_SANITY_FAIL)
-                .arg(lease->addr_.toText()).arg(lease->subnet_id_);
+                .arg(lease->addr_.toText())
+                .arg(lease->subnet_id_)
+                .arg(msg.str());
         }
         break;
 
@@ -81,12 +92,16 @@ void SanityChecker::checkLeaseInternal(LeasePtrType& lease, const CfgConsistency
             // If there is a better subnet, use it.
             if (id != 0) {
                 LOG_INFO(dhcpsrv_logger, DHCPSRV_LEASE_SANITY_FIXED)
-                    .arg(lease->addr_.toText()).arg(lease->subnet_id_).arg(id);
+                    .arg(lease->addr_.toText())
+                    .arg(lease->subnet_id_)
+                    .arg(id);
                 lease->subnet_id_ = id;
             } else {
                 // If not, return the lease as is.
                 LOG_WARN(dhcpsrv_logger, DHCPSRV_LEASE_SANITY_FAIL)
-                    .arg(lease->addr_.toText()).arg(lease->subnet_id_);
+                    .arg(lease->addr_.toText())
+                    .arg(lease->subnet_id_)
+                    .arg(msg.str());
             }
         }
         break;
@@ -97,13 +112,17 @@ void SanityChecker::checkLeaseInternal(LeasePtrType& lease, const CfgConsistency
             // If there is a better subnet, use it.
             if (id != 0) {
                 LOG_INFO(dhcpsrv_logger, DHCPSRV_LEASE_SANITY_FIXED)
-                    .arg(lease->addr_.toText()).arg(lease->subnet_id_).arg(id);
+                    .arg(lease->addr_.toText())
+                    .arg(lease->subnet_id_)
+                    .arg(id);
                 lease->subnet_id_ = id;
                 break;
             } else {
                 // If not, delete the lease.
                 LOG_INFO(dhcpsrv_logger, DHCPSRV_LEASE_SANITY_FAIL_DISCARD)
-                    .arg(lease->addr_.toText()).arg(lease->subnet_id_);
+                    .arg(lease->addr_.toText())
+                    .arg(lease->subnet_id_)
+                    .arg(msg.str());
                 lease.reset();
             }
 
@@ -112,7 +131,9 @@ void SanityChecker::checkLeaseInternal(LeasePtrType& lease, const CfgConsistency
     case CfgConsistency::LEASE_CHECK_DEL:
         if (lease->subnet_id_ != id) {
             LOG_INFO(dhcpsrv_logger, DHCPSRV_LEASE_SANITY_FAIL_DISCARD)
-                .arg(lease->addr_.toText()).arg(lease->subnet_id_);
+                .arg(lease->addr_.toText())
+                .arg(lease->subnet_id_)
+                .arg(msg.str());
             lease.reset();
         }
         break;