Commit 5367cd11 authored by Francis Dupont's avatar Francis Dupont
Browse files

[685-log-the-expected-subnet-id-as-well-as-the-actual-subnet-id-when-the-sanit...

[685-log-the-expected-subnet-id-as-well-as-the-actual-subnet-id-when-the-sanity-checker-identifies-a-problem] Improved SanityChecker logs
parent e5c3a800
// 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",
......
// 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
......
......@@ -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
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment