2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-04 07:55:18 +00:00

[2524] Add logging to configuration manager

This commit is contained in:
Stephen Morris
2012-12-18 13:11:17 +00:00
parent 46cf8771c2
commit b075676335
6 changed files with 151 additions and 64 deletions

View File

@@ -14,6 +14,7 @@
#include <asiolink/io_address.h> #include <asiolink/io_address.h>
#include <dhcpsrv/cfgmgr.h> #include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/dhcpsrv_log.h>
using namespace isc::asiolink; using namespace isc::asiolink;
using namespace isc::util; using namespace isc::util;
@@ -21,9 +22,6 @@ using namespace isc::util;
namespace isc { namespace isc {
namespace dhcp { namespace dhcp {
CfgMgr& CfgMgr&
CfgMgr::instance() { CfgMgr::instance() {
static CfgMgr cfg_mgr; static CfgMgr cfg_mgr;
@@ -42,6 +40,9 @@ CfgMgr::getSubnet6(const isc::asiolink::IOAddress& hint) {
// The server does not need to have a global address (using just link-local // The server does not need to have a global address (using just link-local
// is ok for DHCPv6 server) from the pool it serves. // is ok for DHCPv6 server) from the pool it serves.
if ((subnets6_.size() == 1) && hint.getAddress().to_v6().is_link_local()) { if ((subnets6_.size() == 1) && hint.getAddress().to_v6().is_link_local()) {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
DHCPSRV_CFGMGR_ONLY_SUBNET6)
.arg(subnets6_[0]->toText()).arg(hint.toText());
return (subnets6_[0]); return (subnets6_[0]);
} }
@@ -49,11 +50,16 @@ CfgMgr::getSubnet6(const isc::asiolink::IOAddress& hint) {
for (Subnet6Collection::iterator subnet = subnets6_.begin(); for (Subnet6Collection::iterator subnet = subnets6_.begin();
subnet != subnets6_.end(); ++subnet) { subnet != subnets6_.end(); ++subnet) {
if ((*subnet)->inRange(hint)) { if ((*subnet)->inRange(hint)) {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
DHCPSRV_CFGMGR_SUBNET6)
.arg((*subnet)->toText()).arg(hint.toText());
return (*subnet); return (*subnet);
} }
} }
// sorry, we don't support that subnet // sorry, we don't support that subnet
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_NO_SUBNET6)
.arg(hint.toText());
return (Subnet6Ptr()); return (Subnet6Ptr());
} }
@@ -65,6 +71,8 @@ Subnet6Ptr CfgMgr::getSubnet6(OptionPtr /*interfaceId*/) {
void CfgMgr::addSubnet6(const Subnet6Ptr& subnet) { void CfgMgr::addSubnet6(const Subnet6Ptr& subnet) {
/// @todo: Check that this new subnet does not cross boundaries of any /// @todo: Check that this new subnet does not cross boundaries of any
/// other already defined subnet. /// other already defined subnet.
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_ADD_SUBNET6)
.arg(subnet->toText());
subnets6_.push_back(subnet); subnets6_.push_back(subnet);
} }
@@ -80,6 +88,9 @@ CfgMgr::getSubnet4(const isc::asiolink::IOAddress& hint) {
// The server does not need to have a global address (using just link-local // The server does not need to have a global address (using just link-local
// is ok for DHCPv6 server) from the pool it serves. // is ok for DHCPv6 server) from the pool it serves.
if (subnets4_.size() == 1) { if (subnets4_.size() == 1) {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
DHCPSRV_CFGMGR_ONLY_SUBNET4)
.arg(subnets4_[0]->toText()).arg(hint.toText());
return (subnets4_[0]); return (subnets4_[0]);
} }
@@ -87,25 +98,34 @@ CfgMgr::getSubnet4(const isc::asiolink::IOAddress& hint) {
for (Subnet4Collection::iterator subnet = subnets4_.begin(); for (Subnet4Collection::iterator subnet = subnets4_.begin();
subnet != subnets4_.end(); ++subnet) { subnet != subnets4_.end(); ++subnet) {
if ((*subnet)->inRange(hint)) { if ((*subnet)->inRange(hint)) {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
DHCPSRV_CFGMGR_SUBNET4)
.arg((*subnet)->toText()).arg(hint.toText());
return (*subnet); return (*subnet);
} }
} }
// sorry, we don't support that subnet // sorry, we don't support that subnet
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_NO_SUBNET4)
.arg(hint.toText());
return (Subnet4Ptr()); return (Subnet4Ptr());
} }
void CfgMgr::addSubnet4(const Subnet4Ptr& subnet) { void CfgMgr::addSubnet4(const Subnet4Ptr& subnet) {
/// @todo: Check that this new subnet does not cross boundaries of any /// @todo: Check that this new subnet does not cross boundaries of any
/// other already defined subnet. /// other already defined subnet.
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_ADD_SUBNET4)
.arg(subnet->toText());
subnets4_.push_back(subnet); subnets4_.push_back(subnet);
} }
void CfgMgr::deleteSubnets4() { void CfgMgr::deleteSubnets4() {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_DELETE_SUBNET4);
subnets4_.clear(); subnets4_.clear();
} }
void CfgMgr::deleteSubnets6() { void CfgMgr::deleteSubnets6() {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_DELETE_SUBNET6);
subnets6_.clear(); subnets6_.clear();
} }

View File

@@ -39,10 +39,16 @@ const int DHCPSRV_DBG_TRACE = DBGLVL_TRACE_BASIC;
/// just record the summary results. /// just record the summary results.
const int DHCPSRV_DBG_RESULTS = DBGLVL_TRACE_BASIC_DATA; const int DHCPSRV_DBG_RESULTS = DBGLVL_TRACE_BASIC_DATA;
/// @brief Additional information
///
/// Record detailed tracing. This is generally reserved for tracing access to
/// the lease database.
const int DHCPSRV_DBG_TRACE_DETAIL = DBGLVL_TRACE_DETAIL;
/// @brief Additional information /// @brief Additional information
/// ///
/// Record detailed (and verbose) data on the server. /// Record detailed (and verbose) data on the server.
const int DHCPSRV_DBG_RTT = DBGLVL_TRACE_DETAIL_DATA; const int DHCPSRV_DBG_TRACE_DETAIL_DATA = DBGLVL_TRACE_DETAIL_DATA;
///@} ///@}

View File

@@ -14,6 +14,52 @@
$NAMESPACE isc::dhcp $NAMESPACE isc::dhcp
% DHCPSRV_CFGMGR_ADD_SUBNET4 adding subnet %1
A debug message reported when the DHCP configuration manager is adding the
specified IPv4 subnet to its database.
% DHCPSRV_CFGMGR_ADD_SUBNET6 adding subnet %1
A debug message reported when the DHCP configuration manager is adding the
specified IPv6 subnet to its database.
% DHCPSRV_CFGMGR_DELETE_SUBNET4 deleting all IPv4 subnets
A debug message noting that the DHCP configuration manager has deleted all IPv4
subnets in its database.
% DHCPSRV_CFGMGR_DELETE_SUBNET6 deleting all IPv6 subnets
A debug message noting that the DHCP configuration manager has deleted all IPv6
subnets in its database.
% DHCPSRV_CFGMGR_NO_SUBNET4 no suitable subnet is defined for address hint %1
This debug message is output when the DHCP configuration manager has received
a request for an IPv4 subnet for the specified address, but no such
subnet exists.
% DHCPSRV_CFGMGR_NO_SUBNET6 no suitable subnet is defined for address hint %1
This debug message is output when the DHCP configuration manager has received
a request for an IPv6 subnet for the specified address, but no such
subnet exists.
% DHCPSRV_CFGMGR_ONLY_SUBNET4 retrieved subnet %1 for address hint %2
This is a debug message reporting that the DHCP configuration manager has
returned the specified IPv4 subnet when given the address hint specified
because it is the only subnet defined.
% DHCPSRV_CFGMGR_ONLY_SUBNET6 retrieved subnet %1 for address hint %2
This is a debug message reporting that the DHCP configuration manager has
returned the specified IPv6 subnet when given the address hint specified
because it is the only subnet defined.
% DHCPSRV_CFGMGR_SUBNET4 retrieved subnet %1 for address hint %2
This is a debug message reporting that the DHCP configuration manager has
returned the specified IPv4 subnet when given the address hint specified
as the address is within the subnet.
% DHCPSRV_CFGMGR_SUBNET6 retrieved subnet %1 for address hint %2
This is a debug message reporting that the DHCP configuration manager has
returned the specified IPv6 subnet when given the address hint specified
as the address is within the subnet.
% DHCPSRV_INVALID_ACCESS invalid database access string: %1 % DHCPSRV_INVALID_ACCESS invalid database access string: %1
This is logged when an attempt has been made to parse a database access string This is logged when an attempt has been made to parse a database access string
and the attempt ended in error. The access string in question - which and the attempt ended in error. The access string in question - which

View File

@@ -30,14 +30,14 @@ Memfile_LeaseMgr::~Memfile_LeaseMgr() {
} }
bool Memfile_LeaseMgr::addLease(const Lease4Ptr& lease) { bool Memfile_LeaseMgr::addLease(const Lease4Ptr& lease) {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MEMFILE_ADD_ADDR4) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(lease->addr_.toText()); DHCPSRV_MEMFILE_ADD_ADDR4).arg(lease->addr_.toText());
return (false); return (false);
} }
bool Memfile_LeaseMgr::addLease(const Lease6Ptr& lease) { bool Memfile_LeaseMgr::addLease(const Lease6Ptr& lease) {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MEMFILE_ADD_ADDR6) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(lease->addr_.toText()); DHCPSRV_MEMFILE_ADD_ADDR6).arg(lease->addr_.toText());
if (getLease6(lease->addr_)) { if (getLease6(lease->addr_)) {
// there is a lease with specified address already // there is a lease with specified address already
@@ -49,43 +49,45 @@ bool Memfile_LeaseMgr::addLease(const Lease6Ptr& lease) {
Lease4Ptr Memfile_LeaseMgr::getLease4( Lease4Ptr Memfile_LeaseMgr::getLease4(
const isc::asiolink::IOAddress& addr) const { const isc::asiolink::IOAddress& addr) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MEMFILE_GET_ADDR4) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(addr.toText()); DHCPSRV_MEMFILE_GET_ADDR4).arg(addr.toText());
return (Lease4Ptr()); return (Lease4Ptr());
} }
Lease4Collection Memfile_LeaseMgr::getLease4(const HWAddr& hwaddr) const { Lease4Collection Memfile_LeaseMgr::getLease4(const HWAddr& hwaddr) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MEMFILE_GET_HWADDR) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(hardwareAddressString(hwaddr)); DHCPSRV_MEMFILE_GET_HWADDR).arg(hardwareAddressString(hwaddr));
return (Lease4Collection()); return (Lease4Collection());
} }
Lease4Ptr Memfile_LeaseMgr::getLease4(const HWAddr& hwaddr, Lease4Ptr Memfile_LeaseMgr::getLease4(const HWAddr& hwaddr,
SubnetID subnet_id) const { SubnetID subnet_id) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MEMFILE_GET_SUBID_HWADDR) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(subnet_id).arg(hardwareAddressString(hwaddr)); DHCPSRV_MEMFILE_GET_SUBID_HWADDR).arg(subnet_id)
.arg(hardwareAddressString(hwaddr));
return (Lease4Ptr()); return (Lease4Ptr());
} }
Lease4Collection Memfile_LeaseMgr::getLease4(const ClientId& clientid) const { Lease4Collection Memfile_LeaseMgr::getLease4(const ClientId& clientid) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MEMFILE_GET_CLIENTID) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(clientid.toText()); DHCPSRV_MEMFILE_GET_CLIENTID).arg(clientid.toText());
return (Lease4Collection()); return (Lease4Collection());
} }
Lease4Ptr Memfile_LeaseMgr::getLease4(const ClientId& clientid, Lease4Ptr Memfile_LeaseMgr::getLease4(const ClientId& clientid,
SubnetID subnet_id) const { SubnetID subnet_id) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MEMFILE_GET_SUBID_CLIENTID) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(subnet_id).arg(clientid.toText()); DHCPSRV_MEMFILE_GET_SUBID_CLIENTID).arg(subnet_id)
.arg(clientid.toText());
return (Lease4Ptr()); return (Lease4Ptr());
} }
Lease6Ptr Memfile_LeaseMgr::getLease6( Lease6Ptr Memfile_LeaseMgr::getLease6(
const isc::asiolink::IOAddress& addr) const { const isc::asiolink::IOAddress& addr) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MEMFILE_GET_ADDR6) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(addr.toText()); DHCPSRV_MEMFILE_GET_ADDR6).arg(addr.toText());
Lease6Storage::iterator l = storage6_.find(addr); Lease6Storage::iterator l = storage6_.find(addr);
if (l == storage6_.end()) { if (l == storage6_.end()) {
@@ -97,15 +99,15 @@ Lease6Ptr Memfile_LeaseMgr::getLease6(
Lease6Collection Memfile_LeaseMgr::getLease6(const DUID& duid, Lease6Collection Memfile_LeaseMgr::getLease6(const DUID& duid,
uint32_t iaid) const { uint32_t iaid) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MEMFILE_GET_IAID_DUID) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(iaid).arg(duid.toText()); DHCPSRV_MEMFILE_GET_IAID_DUID).arg(iaid).arg(duid.toText());
return (Lease6Collection()); return (Lease6Collection());
} }
Lease6Ptr Memfile_LeaseMgr::getLease6(const DUID& duid, uint32_t iaid, Lease6Ptr Memfile_LeaseMgr::getLease6(const DUID& duid, uint32_t iaid,
SubnetID subnet_id) const { SubnetID subnet_id) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
DHCPSRV_MEMFILE_GET_IAID_SUBID_DUID) DHCPSRV_MEMFILE_GET_IAID_SUBID_DUID)
.arg(iaid).arg(subnet_id).arg(duid.toText()); .arg(iaid).arg(subnet_id).arg(duid.toText());
@@ -121,21 +123,21 @@ Lease6Ptr Memfile_LeaseMgr::getLease6(const DUID& duid, uint32_t iaid,
} }
void Memfile_LeaseMgr::updateLease4(const Lease4Ptr& lease) { void Memfile_LeaseMgr::updateLease4(const Lease4Ptr& lease) {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MEMFILE_UPDATE_ADDR4) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(lease->addr_.toText()); DHCPSRV_MEMFILE_UPDATE_ADDR4).arg(lease->addr_.toText());
} }
void Memfile_LeaseMgr::updateLease6(const Lease6Ptr& lease) { void Memfile_LeaseMgr::updateLease6(const Lease6Ptr& lease) {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MEMFILE_UPDATE_ADDR6) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(lease->addr_.toText()); DHCPSRV_MEMFILE_UPDATE_ADDR6).arg(lease->addr_.toText());
} }
bool Memfile_LeaseMgr::deleteLease(const isc::asiolink::IOAddress& addr) { bool Memfile_LeaseMgr::deleteLease(const isc::asiolink::IOAddress& addr) {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MEMFILE_DELETE_ADDR) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(addr.toText()); DHCPSRV_MEMFILE_DELETE_ADDR).arg(addr.toText());
if (addr.isV4()) { if (addr.isV4()) {
// V4 not implemented yet // V4 not implemented yet
return (false); return (false);
@@ -161,10 +163,11 @@ std::string Memfile_LeaseMgr::getDescription() const {
void void
Memfile_LeaseMgr::commit() { Memfile_LeaseMgr::commit() {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MEMFILE_COMMIT); LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_COMMIT);
} }
void void
Memfile_LeaseMgr::rollback() { Memfile_LeaseMgr::rollback() {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MEMFILE_ROLLBACK); LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
DHCPSRV_MEMFILE_ROLLBACK);
} }

View File

@@ -1115,8 +1115,8 @@ MySqlLeaseMgr::addLeaseCommon(StatementIndex stindex,
bool bool
MySqlLeaseMgr::addLease(const Lease4Ptr& lease) { MySqlLeaseMgr::addLease(const Lease4Ptr& lease) {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_ADD_ADDR4) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(lease->addr_.toText()); DHCPSRV_MYSQL_ADD_ADDR4).arg(lease->addr_.toText());
// Create the MYSQL_BIND array for the lease // Create the MYSQL_BIND array for the lease
std::vector<MYSQL_BIND> bind = exchange4_->createBindForSend(lease); std::vector<MYSQL_BIND> bind = exchange4_->createBindForSend(lease);
@@ -1127,8 +1127,8 @@ MySqlLeaseMgr::addLease(const Lease4Ptr& lease) {
bool bool
MySqlLeaseMgr::addLease(const Lease6Ptr& lease) { MySqlLeaseMgr::addLease(const Lease6Ptr& lease) {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_ADD_ADDR6) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(lease->addr_.toText()); DHCPSRV_MYSQL_ADD_ADDR6).arg(lease->addr_.toText());
// Create the MYSQL_BIND array for the lease // Create the MYSQL_BIND array for the lease
std::vector<MYSQL_BIND> bind = exchange6_->createBindForSend(lease); std::vector<MYSQL_BIND> bind = exchange6_->createBindForSend(lease);
@@ -1266,8 +1266,8 @@ void MySqlLeaseMgr::getLease(StatementIndex stindex, MYSQL_BIND* bind,
Lease4Ptr Lease4Ptr
MySqlLeaseMgr::getLease4(const isc::asiolink::IOAddress& addr) const { MySqlLeaseMgr::getLease4(const isc::asiolink::IOAddress& addr) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_GET_ADDR4) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(addr.toText()); DHCPSRV_MYSQL_GET_ADDR4).arg(addr.toText());
// Set up the WHERE clause value // Set up the WHERE clause value
MYSQL_BIND inbind[1]; MYSQL_BIND inbind[1];
@@ -1288,8 +1288,8 @@ MySqlLeaseMgr::getLease4(const isc::asiolink::IOAddress& addr) const {
Lease4Collection Lease4Collection
MySqlLeaseMgr::getLease4(const HWAddr& hwaddr) const { MySqlLeaseMgr::getLease4(const HWAddr& hwaddr) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_GET_HWADDR) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(hardwareAddressString(hwaddr)); DHCPSRV_MYSQL_GET_HWADDR).arg(hardwareAddressString(hwaddr));
// Set up the WHERE clause value // Set up the WHERE clause value
MYSQL_BIND inbind[1]; MYSQL_BIND inbind[1];
@@ -1318,8 +1318,9 @@ MySqlLeaseMgr::getLease4(const HWAddr& hwaddr) const {
Lease4Ptr Lease4Ptr
MySqlLeaseMgr::getLease4(const HWAddr& hwaddr, SubnetID subnet_id) const { MySqlLeaseMgr::getLease4(const HWAddr& hwaddr, SubnetID subnet_id) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_GET_SUBID_HWADDR) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(subnet_id).arg(hardwareAddressString(hwaddr)); DHCPSRV_MYSQL_GET_SUBID_HWADDR)
.arg(subnet_id).arg(hardwareAddressString(hwaddr));
// Set up the WHERE clause value // Set up the WHERE clause value
MYSQL_BIND inbind[2]; MYSQL_BIND inbind[2];
@@ -1352,8 +1353,8 @@ MySqlLeaseMgr::getLease4(const HWAddr& hwaddr, SubnetID subnet_id) const {
Lease4Collection Lease4Collection
MySqlLeaseMgr::getLease4(const ClientId& clientid) const { MySqlLeaseMgr::getLease4(const ClientId& clientid) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_GET_CLIENTID) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(clientid.toText()); DHCPSRV_MYSQL_GET_CLIENTID).arg(clientid.toText());
// Set up the WHERE clause value // Set up the WHERE clause value
MYSQL_BIND inbind[1]; MYSQL_BIND inbind[1];
@@ -1376,8 +1377,9 @@ MySqlLeaseMgr::getLease4(const ClientId& clientid) const {
Lease4Ptr Lease4Ptr
MySqlLeaseMgr::getLease4(const ClientId& clientid, SubnetID subnet_id) const { MySqlLeaseMgr::getLease4(const ClientId& clientid, SubnetID subnet_id) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_GET_SUBID_CLIENTID) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(subnet_id).arg(clientid.toText()); DHCPSRV_MYSQL_GET_SUBID_CLIENTID)
.arg(subnet_id).arg(clientid.toText());
// Set up the WHERE clause value // Set up the WHERE clause value
MYSQL_BIND inbind[2]; MYSQL_BIND inbind[2];
@@ -1404,8 +1406,8 @@ MySqlLeaseMgr::getLease4(const ClientId& clientid, SubnetID subnet_id) const {
Lease6Ptr Lease6Ptr
MySqlLeaseMgr::getLease6(const isc::asiolink::IOAddress& addr) const { MySqlLeaseMgr::getLease6(const isc::asiolink::IOAddress& addr) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_GET_ADDR6) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(addr.toText()); DHCPSRV_MYSQL_GET_ADDR6).arg(addr.toText());
// Set up the WHERE clause value // Set up the WHERE clause value
MYSQL_BIND inbind[1]; MYSQL_BIND inbind[1];
@@ -1430,8 +1432,8 @@ MySqlLeaseMgr::getLease6(const isc::asiolink::IOAddress& addr) const {
Lease6Collection Lease6Collection
MySqlLeaseMgr::getLease6(const DUID& duid, uint32_t iaid) const { MySqlLeaseMgr::getLease6(const DUID& duid, uint32_t iaid) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_GET_IAID_DUID) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(iaid).arg(duid.toText()); DHCPSRV_MYSQL_GET_IAID_DUID).arg(iaid).arg(duid.toText());
// Set up the WHERE clause value // Set up the WHERE clause value
MYSQL_BIND inbind[2]; MYSQL_BIND inbind[2];
@@ -1473,8 +1475,9 @@ MySqlLeaseMgr::getLease6(const DUID& duid, uint32_t iaid) const {
Lease6Ptr Lease6Ptr
MySqlLeaseMgr::getLease6(const DUID& duid, uint32_t iaid, MySqlLeaseMgr::getLease6(const DUID& duid, uint32_t iaid,
SubnetID subnet_id) const { SubnetID subnet_id) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_GET_IAID_SUBID_DUID) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(iaid).arg(subnet_id).arg(duid.toText()); DHCPSRV_MYSQL_GET_IAID_SUBID_DUID)
.arg(iaid).arg(subnet_id).arg(duid.toText());
// Set up the WHERE clause value // Set up the WHERE clause value
MYSQL_BIND inbind[3]; MYSQL_BIND inbind[3];
@@ -1542,8 +1545,8 @@ void
MySqlLeaseMgr::updateLease4(const Lease4Ptr& lease) { MySqlLeaseMgr::updateLease4(const Lease4Ptr& lease) {
const StatementIndex stindex = UPDATE_LEASE4; const StatementIndex stindex = UPDATE_LEASE4;
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_UPDATE_ADDR4) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(lease->addr_.toText()); DHCPSRV_MYSQL_UPDATE_ADDR4).arg(lease->addr_.toText());
// Create the MYSQL_BIND array for the data being updated // Create the MYSQL_BIND array for the data being updated
std::vector<MYSQL_BIND> bind = exchange4_->createBindForSend(lease); std::vector<MYSQL_BIND> bind = exchange4_->createBindForSend(lease);
@@ -1567,8 +1570,8 @@ void
MySqlLeaseMgr::updateLease6(const Lease6Ptr& lease) { MySqlLeaseMgr::updateLease6(const Lease6Ptr& lease) {
const StatementIndex stindex = UPDATE_LEASE6; const StatementIndex stindex = UPDATE_LEASE6;
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_UPDATE_ADDR6) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(lease->addr_.toText()); DHCPSRV_MYSQL_UPDATE_ADDR6).arg(lease->addr_.toText());
// Create the MYSQL_BIND array for the data being updated // Create the MYSQL_BIND array for the data being updated
std::vector<MYSQL_BIND> bind = exchange6_->createBindForSend(lease); std::vector<MYSQL_BIND> bind = exchange6_->createBindForSend(lease);
@@ -1616,8 +1619,8 @@ MySqlLeaseMgr::deleteLeaseCommon(StatementIndex stindex, MYSQL_BIND* bind) {
bool bool
MySqlLeaseMgr::deleteLease(const isc::asiolink::IOAddress& addr) { MySqlLeaseMgr::deleteLease(const isc::asiolink::IOAddress& addr) {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_DELETE_ADDR) LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(addr.toText()); DHCPSRV_MYSQL_DELETE_ADDR).arg(addr.toText());
// Set up the WHERE clause value // Set up the WHERE clause value
MYSQL_BIND inbind[1]; MYSQL_BIND inbind[1];
@@ -1671,7 +1674,8 @@ std::pair<uint32_t, uint32_t>
MySqlLeaseMgr::getVersion() const { MySqlLeaseMgr::getVersion() const {
const StatementIndex stindex = GET_VERSION; const StatementIndex stindex = GET_VERSION;
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_GET_VERSION); LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
DHCPSRV_MYSQL_GET_VERSION);
uint32_t major; // Major version number uint32_t major; // Major version number
uint32_t minor; // Minor version number uint32_t minor; // Minor version number
@@ -1719,7 +1723,7 @@ MySqlLeaseMgr::getVersion() const {
void void
MySqlLeaseMgr::commit() { MySqlLeaseMgr::commit() {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_COMMIT); LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MYSQL_COMMIT);
if (mysql_commit(mysql_) != 0) { if (mysql_commit(mysql_) != 0) {
isc_throw(DbOperationError, "commit failed: " << mysql_error(mysql_)); isc_throw(DbOperationError, "commit failed: " << mysql_error(mysql_));
} }
@@ -1728,7 +1732,7 @@ MySqlLeaseMgr::commit() {
void void
MySqlLeaseMgr::rollback() { MySqlLeaseMgr::rollback() {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_ROLLBACK); LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MYSQL_ROLLBACK);
if (mysql_rollback(mysql_) != 0) { if (mysql_rollback(mysql_) != 0) {
isc_throw(DbOperationError, "rollback failed: " << mysql_error(mysql_)); isc_throw(DbOperationError, "rollback failed: " << mysql_error(mysql_));
} }

View File

@@ -42,6 +42,7 @@ public:
} }
~CfgMgrTest() { ~CfgMgrTest() {
CfgMgr::instance().deleteSubnets4();
CfgMgr::instance().deleteSubnets6(); CfgMgr::instance().deleteSubnets6();
} }
}; };
@@ -56,8 +57,8 @@ TEST_F(CfgMgrTest, subnet4) {
Subnet4Ptr subnet2(new Subnet4(IOAddress("192.0.2.64"), 26, 1, 2, 3)); Subnet4Ptr subnet2(new Subnet4(IOAddress("192.0.2.64"), 26, 1, 2, 3));
Subnet4Ptr subnet3(new Subnet4(IOAddress("192.0.2.128"), 26, 1, 2, 3)); Subnet4Ptr subnet3(new Subnet4(IOAddress("192.0.2.128"), 26, 1, 2, 3));
// there shouldn't be any subnet configured at this stage // There shouldn't be any subnet configured at this stage
EXPECT_EQ( Subnet4Ptr(), cfg_mgr.getSubnet4(IOAddress("192.0.2.0"))); EXPECT_EQ(Subnet4Ptr(), cfg_mgr.getSubnet4(IOAddress("192.0.2.0")));
cfg_mgr.addSubnet4(subnet1); cfg_mgr.addSubnet4(subnet1);
@@ -75,6 +76,12 @@ TEST_F(CfgMgrTest, subnet4) {
// Try to find an address that does not belong to any subnet // Try to find an address that does not belong to any subnet
EXPECT_EQ(Subnet4Ptr(), cfg_mgr.getSubnet4(IOAddress("192.0.2.192"))); EXPECT_EQ(Subnet4Ptr(), cfg_mgr.getSubnet4(IOAddress("192.0.2.192")));
// Check that deletion of the subnets works.
cfg_mgr.deleteSubnets4();
EXPECT_EQ(Subnet4Ptr(), cfg_mgr.getSubnet4(IOAddress("192.0.2.191")));
EXPECT_EQ(Subnet4Ptr(), cfg_mgr.getSubnet4(IOAddress("192.0.2.15")));
EXPECT_EQ(Subnet4Ptr(), cfg_mgr.getSubnet4(IOAddress("192.0.2.85")));
} }
// This test verifies if the configuration manager is able to hold and return // This test verifies if the configuration manager is able to hold and return
@@ -87,8 +94,8 @@ TEST_F(CfgMgrTest, subnet6) {
Subnet6Ptr subnet2(new Subnet6(IOAddress("3000::"), 48, 1, 2, 3, 4)); Subnet6Ptr subnet2(new Subnet6(IOAddress("3000::"), 48, 1, 2, 3, 4));
Subnet6Ptr subnet3(new Subnet6(IOAddress("4000::"), 48, 1, 2, 3, 4)); Subnet6Ptr subnet3(new Subnet6(IOAddress("4000::"), 48, 1, 2, 3, 4));
// there shouldn't be any subnet configured at this stage // There shouldn't be any subnet configured at this stage
EXPECT_EQ( Subnet6Ptr(), cfg_mgr.getSubnet6(IOAddress("2000::1"))); EXPECT_EQ(Subnet6Ptr(), cfg_mgr.getSubnet6(IOAddress("2000::1")));
cfg_mgr.addSubnet6(subnet1); cfg_mgr.addSubnet6(subnet1);
@@ -106,6 +113,7 @@ TEST_F(CfgMgrTest, subnet6) {
EXPECT_EQ(subnet2, cfg_mgr.getSubnet6(IOAddress("3000::dead:beef"))); EXPECT_EQ(subnet2, cfg_mgr.getSubnet6(IOAddress("3000::dead:beef")));
EXPECT_EQ(Subnet6Ptr(), cfg_mgr.getSubnet6(IOAddress("5000::1"))); EXPECT_EQ(Subnet6Ptr(), cfg_mgr.getSubnet6(IOAddress("5000::1")));
// Check that deletion of the subnets works.
cfg_mgr.deleteSubnets6(); cfg_mgr.deleteSubnets6();
EXPECT_EQ(Subnet6Ptr(), cfg_mgr.getSubnet6(IOAddress("200::123"))); EXPECT_EQ(Subnet6Ptr(), cfg_mgr.getSubnet6(IOAddress("200::123")));
EXPECT_EQ(Subnet6Ptr(), cfg_mgr.getSubnet6(IOAddress("3000::123"))); EXPECT_EQ(Subnet6Ptr(), cfg_mgr.getSubnet6(IOAddress("3000::123")));