diff options
author | Francis Dupont <fdupont@isc.org> | 2019-06-21 16:29:41 +0200 |
---|---|---|
committer | Francis Dupont <fdupont@isc.org> | 2019-06-26 14:51:04 +0200 |
commit | 5367cd1196662739bbff5e99072ab6a55cfb0489 (patch) | |
tree | 7f60c53876b7e893fa9007a64aafffc5b4dd219f | |
parent | [694-add-valid-lifetime-to-dhcp4_lease_alloc-and-dhcp6_lease_alloc-logging] A... (diff) | |
download | kea-5367cd1196662739bbff5e99072ab6a55cfb0489.tar.xz kea-5367cd1196662739bbff5e99072ab6a55cfb0489.zip |
[685-log-the-expected-subnet-id-as-well-as-the-actual-subnet-id-when-the-sanity-checker-identifies-a-problem] Improved SanityChecker logs
-rw-r--r-- | src/lib/dhcpsrv/dhcpsrv_messages.cc | 6 | ||||
-rw-r--r-- | src/lib/dhcpsrv/dhcpsrv_messages.h | 2 | ||||
-rw-r--r-- | src/lib/dhcpsrv/dhcpsrv_messages.mes | 4 | ||||
-rw-r--r-- | src/lib/dhcpsrv/sanity_checker.cc | 33 |
4 files changed, 33 insertions, 12 deletions
diff --git a/src/lib/dhcpsrv/dhcpsrv_messages.cc b/src/lib/dhcpsrv/dhcpsrv_messages.cc index 0fc54f8595..c877d365b0 100644 --- a/src/lib/dhcpsrv/dhcpsrv_messages.cc +++ b/src/lib/dhcpsrv/dhcpsrv_messages.cc @@ -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", diff --git a/src/lib/dhcpsrv/dhcpsrv_messages.h b/src/lib/dhcpsrv/dhcpsrv_messages.h index 854de0155c..effc486d09 100644 --- a/src/lib/dhcpsrv/dhcpsrv_messages.h +++ b/src/lib/dhcpsrv/dhcpsrv_messages.h @@ -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 diff --git a/src/lib/dhcpsrv/dhcpsrv_messages.mes b/src/lib/dhcpsrv/dhcpsrv_messages.mes index 6ad1ef292a..fa451ab7df 100644 --- a/src/lib/dhcpsrv/dhcpsrv_messages.mes +++ b/src/lib/dhcpsrv/dhcpsrv_messages.mes @@ -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 diff --git a/src/lib/dhcpsrv/sanity_checker.cc b/src/lib/dhcpsrv/sanity_checker.cc index 6e512d09ed..1ce6959fa6 100644 --- a/src/lib/dhcpsrv/sanity_checker.cc +++ b/src/lib/dhcpsrv/sanity_checker.cc @@ -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; |