+1607. [bug] tmark
+ Corrected an initialization issue which caused lease sanity
+ checking to be enabled inside the Lease File Cleanup (LFC)
+ process. The LFC cannot meaningfully perform sanity checking
+ as it does not have access to the full server configuration.
+ (Gitlab #686,!403 git TBD)
+
1606. [bug] tmark
Corrected an error with retrieving DHCPv6 leases, whose IAID
values are larger than int32_t max, from Postgresql lease
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
/// @brief Constructor
CfgConsistency()
- : lease_sanity_check_(LEASE_CHECK_WARN) {
+ : lease_sanity_check_(LEASE_CHECK_NONE) {
}
-// Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2019 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
#include <util/versioned_csv_file.h>
#include <dhcpsrv/sanity_checker.h>
+#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
namespace isc {
lease_file.close();
lease_file.open();
- SanityChecker lease_checker;
+ // Create lease sanity checker if checking is enabled.
+ boost::scoped_ptr<SanityChecker> lease_checker;
+ if (SanityChecker::leaseCheckingEnabled(false)) {
+ // Since lease file is loaded during the configuration,
+ // we have to use staging config, rather than current
+ // config for this (false = staging).
+ lease_checker.reset(new SanityChecker());
+ }
boost::shared_ptr<LeaseObjectType> lease;
// Track the number of corrupted leases.
DHCPSRV_MEMFILE_LEASE_LOAD)
.arg(lease->toText());
- // Now see if we need to sanitize this lease. As lease file is
- // loaded during the configuration, we have to use staging config,
- // rather than current config for this (false = staging).
- lease_checker.checkLease(lease, false);
- if (!lease) {
- continue;
+ if (lease_checker) {
+ // If the lease is insane the checker will rese the lease pointer.
+ // As lease file is loaded during the configuration, we have
+ // to use staging config, rather than current config for this
+ // (false = staging).
+ lease_checker->checkLease(lease, false);
+ if (!lease) {
+ continue;
+ }
}
// Check if this lease exists.
{ "re-detect", Element::boolean, "true" }
};
+/// @brief This table defines default values for dhcp-queue-control in DHCPv4.
+const SimpleDefaults SimpleParser4::DHCP_QUEUE_CONTROL4_DEFAULTS = {
+ { "enable-queue", Element::boolean, "false"},
+ { "queue-type", Element::string, "kea-ring4"},
+ { "capacity", Element::integer, "500"}
+};
+
+/// @brief This defines default values for sanity checking for DHCPv4.
+const SimpleDefaults SimpleParser4::SANITY_CHECKS4_DEFAULTS = {
+ { "lease-checks", Element::string, "warn" }
+};
+
/// @brief List of parameters that can be inherited to subnet4 scope.
///
/// Some parameters may be defined on both global (directly in Dhcp4) and
"t2-percent"
};
-/// @brief This table defines default values for dhcp-queue-control in DHCPv4.
-const SimpleDefaults SimpleParser4::DHCP_QUEUE_CONTROL4_DEFAULTS = {
- { "enable-queue", Element::boolean, "false"},
- { "queue-type", Element::string, "kea-ring4"},
- { "capacity", Element::integer, "500"}
-};
-
-
/// @}
/// ---------------------------------------------------------------------------
cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL4_DEFAULTS);
+ // Set the defaults for sanity-checks. If the element isn't
+ // there we'll add it.
+ ConstElementPtr sanity_checks = global->get("sanity-checks");
+ if (sanity_checks) {
+ mutable_cfg = boost::const_pointer_cast<Element>(sanity_checks);
+ } else {
+ mutable_cfg = Element::createMap();
+ global->set("sanity-checks", mutable_cfg);
+ }
+
+ cnt += setDefaults(mutable_cfg, SANITY_CHECKS4_DEFAULTS);
+
return (cnt);
}
static const isc::data::SimpleDefaults SHARED_NETWORK4_DEFAULTS;
static const isc::data::SimpleDefaults IFACE4_DEFAULTS;
static const isc::data::SimpleDefaults DHCP_QUEUE_CONTROL4_DEFAULTS;
+ static const isc::data::SimpleDefaults SANITY_CHECKS4_DEFAULTS;
static const isc::data::ParamsList INHERIT_TO_SUBNET4;
};
{ "re-detect", Element::boolean, "true" }
};
+/// @brief This table defines default values for dhcp-queue-control in DHCPv4.
+const SimpleDefaults SimpleParser6::DHCP_QUEUE_CONTROL6_DEFAULTS = {
+ { "enable-queue", Element::boolean, "false"},
+ { "queue-type", Element::string, "kea-ring6"},
+ { "capacity", Element::integer, "500"}
+};
+
+/// @brief This defines default values for sanity checking for DHCPv6.
+const SimpleDefaults SimpleParser6::SANITY_CHECKS6_DEFAULTS = {
+ { "lease-checks", Element::string, "warn" }
+};
+
/// @brief List of parameters that can be inherited from the global to subnet6 scope.
///
/// Some parameters may be defined on both global (directly in Dhcp6) and
"t2-percent"
};
-/// @brief This table defines default values for dhcp-queue-control in DHCPv4.
-const SimpleDefaults SimpleParser6::DHCP_QUEUE_CONTROL6_DEFAULTS = {
- { "enable-queue", Element::boolean, "false"},
- { "queue-type", Element::string, "kea-ring6"},
- { "capacity", Element::integer, "500"}
-};
-
-
/// @}
/// ---------------------------------------------------------------------------
cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL6_DEFAULTS);
+ // Set the defaults for sanity-checks. If the element isn't
+ // there we'll add it.
+ ConstElementPtr sanity_checks = global->get("sanity-checks");
+ if (sanity_checks) {
+ mutable_cfg = boost::const_pointer_cast<Element>(sanity_checks);
+ } else {
+ mutable_cfg = Element::createMap();
+ global->set("sanity-checks", mutable_cfg);
+ }
+
+ cnt += setDefaults(mutable_cfg, SANITY_CHECKS6_DEFAULTS);
+
return (cnt);
}
static const isc::data::SimpleDefaults SHARED_NETWORK6_DEFAULTS;
static const isc::data::SimpleDefaults IFACE6_DEFAULTS;
static const isc::data::SimpleDefaults DHCP_QUEUE_CONTROL6_DEFAULTS;
+ static const isc::data::SimpleDefaults SANITY_CHECKS6_DEFAULTS;
static const isc::data::ParamsList INHERIT_TO_SUBNET6;
};
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <dhcpsrv/sanity_checker.h>
#include <dhcpsrv/cfg_consistency.h>
-#include <dhcpsrv/cfg_subnets4.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/subnet_id.h>
#include <dhcpsrv/dhcpsrv_log.h>
namespace isc {
namespace dhcp {
+bool SanityChecker::leaseCheckingEnabled(bool current) {
+ SrvConfigPtr cfg;
+ if (current) {
+ cfg = CfgMgr::instance().getCurrentCfg();
+ } else {
+ cfg = CfgMgr::instance().getStagingCfg();
+ }
+
+ if (cfg) {
+ CfgConsistencyPtr sanity = cfg->getConsistency();
+ return (sanity && (sanity->getLeaseSanityCheck() != CfgConsistency::LEASE_CHECK_NONE));
+ }
+
+ return (false);
+}
+
void SanityChecker::checkLease(Lease4Ptr& lease, bool current) {
SrvConfigPtr cfg;
if (current) {
} else {
cfg = CfgMgr::instance().getStagingCfg();
}
+
CfgConsistencyPtr sanity = cfg->getConsistency();
+ if (sanity->getLeaseSanityCheck() == CfgConsistency::LEASE_CHECK_NONE) {
+ // No sense going farther.
+ return;
+ }
+
CfgSubnets4Ptr subnets = cfg->getCfgSubnets4();
checkLeaseInternal(lease, sanity, subnets);
}
cfg = CfgMgr::instance().getStagingCfg();
}
CfgConsistencyPtr sanity = cfg->getConsistency();
+ if (sanity->getLeaseSanityCheck() == CfgConsistency::LEASE_CHECK_NONE) {
+ // No sense going farther.
+ return;
+ }
+
CfgSubnets6Ptr subnets = cfg->getCfgSubnets6();
checkLeaseInternal(lease, sanity, subnets);
}
void SanityChecker::checkLeaseInternal(LeasePtrType& lease, const CfgConsistencyPtr& checks,
const SubnetsType& subnets) {
- if (checks->getLeaseSanityCheck() == CfgConsistency::LEASE_CHECK_NONE) {
- return;
- }
-
auto subnet = subnets->getBySubnetId(lease->subnet_id_);
-
if (subnet && subnet->inRange(lease->addr_)) {
// If the subnet is defined and the address is in range, we're good.
template<typename LeaseType, typename SubnetsType>
SubnetID SanityChecker::findSubnetId(const LeaseType& lease, const SubnetsType& subnets) {
- //CfgSubnets4Ptr subnets = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4();
-
auto subnet = subnets->selectSubnet(lease->addr_);
if (!subnet) {
return (0);
/// config
void checkLease(Lease6Ptr& lease, bool current = true);
+ /// @brief Indicates the specified configuration enables lease sanity checking.
+ ///
+ /// @param current specifies whether to use current (true) or staging(false)
+ /// server configuration
+ /// @return true if the sanity-checks/lease-checks parameter value (see
+ /// @ref CfgConsistency for details) is not CfgConsistency::LEASE_CHECK_NONE.
+ static bool leaseCheckingEnabled(bool current = true);
+
private:
/// @brief Internal implementation for checkLease command
SrvConfig cfg;
- // The default should be to warn about inconsistency.
+ // The default should be to none.
EXPECT_EQ(cfg.getConsistency()->getLeaseSanityCheck(),
- CfgConsistency::LEASE_CHECK_WARN);
+ CfgConsistency::LEASE_CHECK_NONE);
parserCheck(cfg, valid1, false, CfgConsistency::LEASE_CHECK_NONE);
parserCheck(cfg, valid2, false, CfgConsistency::LEASE_CHECK_WARN);
defaults += "\"lease-database\": { \"type\": \"memfile\" },\n";
defaults += "\"hooks-libraries\": [ ],\n";
defaults += "\"sanity-checks\": {\n";
- defaults += " \"lease-checks\": \"warn\"\n";
+ defaults += " \"lease-checks\": \"none\"\n";
defaults += " },\n";
defaults += "\"dhcp-ddns\": \n";