|
@@ -16,14 +16,15 @@
|
|
|
|
|
|
#include <asiolink/io_address.h>
|
|
|
#include <dhcp/duid.h>
|
|
|
+#include <dhcpsrv/dhcpsrv_log.h>
|
|
|
#include <dhcpsrv/mysql_lease_mgr.h>
|
|
|
|
|
|
#include <boost/static_assert.hpp>
|
|
|
#include <mysql/mysqld_error.h>
|
|
|
|
|
|
-#include <algorithm>
|
|
|
#include <iostream>
|
|
|
#include <iomanip>
|
|
|
+#include <sstream>
|
|
|
#include <string>
|
|
|
#include <time.h>
|
|
|
|
|
@@ -191,8 +192,38 @@ TaggedStatement tagged_statements[] = {
|
|
|
{MySqlLeaseMgr::NUM_STATEMENTS, NULL}
|
|
|
};
|
|
|
|
|
|
+/// @brief Produce string representation of hardware address
|
|
|
+///
|
|
|
+/// Returns a string containing the hardware address. This is only used for
|
|
|
+/// logging.
|
|
|
+///
|
|
|
+/// @note Six characters is an arbitrary length, chosen to provide a
|
|
|
+/// suitably wide string.
|
|
|
+///
|
|
|
+/// @todo Create a "hardware address" class of which this will be a member.
|
|
|
+///
|
|
|
+/// @param hwaddr Hardware address to convert to string form
|
|
|
+///
|
|
|
+/// @return String form of the hardware address.
|
|
|
+std::string
|
|
|
+hardwareAddressString(const LeaseMgr::HWAddr& hwaddr) {
|
|
|
+ std::ostringstream stream;
|
|
|
+
|
|
|
+ for (size_t i = 0; i < hwaddr.size(); ++i) {
|
|
|
+ if (i > 0) {
|
|
|
+ stream << ":";
|
|
|
+ }
|
|
|
+ stream << std::setw(2) << std::setfill('0')
|
|
|
+ << static_cast<unsigned int>(hwaddr[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ return (stream.str());
|
|
|
+}
|
|
|
+
|
|
|
}; // Anonymous namespace
|
|
|
|
|
|
+
|
|
|
+
|
|
|
namespace isc {
|
|
|
namespace dhcp {
|
|
|
|
|
@@ -1112,6 +1143,9 @@ MySqlLeaseMgr::addLeaseCommon(StatementIndex stindex,
|
|
|
|
|
|
bool
|
|
|
MySqlLeaseMgr::addLease(const Lease4Ptr& lease) {
|
|
|
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_ADD_ADDR4)
|
|
|
+ .arg(lease->addr_.toText());
|
|
|
+
|
|
|
// Create the MYSQL_BIND array for the lease
|
|
|
std::vector<MYSQL_BIND> bind = exchange4_->createBindForSend(lease);
|
|
|
|
|
@@ -1121,6 +1155,9 @@ MySqlLeaseMgr::addLease(const Lease4Ptr& lease) {
|
|
|
|
|
|
bool
|
|
|
MySqlLeaseMgr::addLease(const Lease6Ptr& lease) {
|
|
|
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_ADD_ADDR6)
|
|
|
+ .arg(lease->addr_.toText());
|
|
|
+
|
|
|
// Create the MYSQL_BIND array for the lease
|
|
|
std::vector<MYSQL_BIND> bind = exchange6_->createBindForSend(lease);
|
|
|
|
|
@@ -1257,6 +1294,9 @@ void MySqlLeaseMgr::getLease(StatementIndex stindex, MYSQL_BIND* bind,
|
|
|
|
|
|
Lease4Ptr
|
|
|
MySqlLeaseMgr::getLease4(const isc::asiolink::IOAddress& addr) const {
|
|
|
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_GET_ADDR4)
|
|
|
+ .arg(addr.toText());
|
|
|
+
|
|
|
// Set up the WHERE clause value
|
|
|
MYSQL_BIND inbind[1];
|
|
|
memset(inbind, 0, sizeof(inbind));
|
|
@@ -1276,6 +1316,9 @@ MySqlLeaseMgr::getLease4(const isc::asiolink::IOAddress& addr) const {
|
|
|
|
|
|
Lease4Collection
|
|
|
MySqlLeaseMgr::getLease4(const HWAddr& hwaddr) const {
|
|
|
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_GET_HWADDR)
|
|
|
+ .arg(hardwareAddressString(hwaddr));
|
|
|
+
|
|
|
// Set up the WHERE clause value
|
|
|
MYSQL_BIND inbind[1];
|
|
|
memset(inbind, 0, sizeof(inbind));
|
|
@@ -1303,6 +1346,9 @@ MySqlLeaseMgr::getLease4(const HWAddr& hwaddr) const {
|
|
|
|
|
|
Lease4Ptr
|
|
|
MySqlLeaseMgr::getLease4(const HWAddr& hwaddr, SubnetID subnet_id) const {
|
|
|
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_GET_SUBID_HWADDR)
|
|
|
+ .arg(subnet_id).arg(hardwareAddressString(hwaddr));
|
|
|
+
|
|
|
// Set up the WHERE clause value
|
|
|
MYSQL_BIND inbind[2];
|
|
|
memset(inbind, 0, sizeof(inbind));
|
|
@@ -1334,6 +1380,9 @@ MySqlLeaseMgr::getLease4(const HWAddr& hwaddr, SubnetID subnet_id) const {
|
|
|
|
|
|
Lease4Collection
|
|
|
MySqlLeaseMgr::getLease4(const ClientId& clientid) const {
|
|
|
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_GET_CLIENTID)
|
|
|
+ .arg(clientid.toText());
|
|
|
+
|
|
|
// Set up the WHERE clause value
|
|
|
MYSQL_BIND inbind[1];
|
|
|
memset(inbind, 0, sizeof(inbind));
|
|
@@ -1355,6 +1404,9 @@ MySqlLeaseMgr::getLease4(const ClientId& clientid) const {
|
|
|
|
|
|
Lease4Ptr
|
|
|
MySqlLeaseMgr::getLease4(const ClientId& clientid, SubnetID subnet_id) const {
|
|
|
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_GET_SUBID_CLIENTID)
|
|
|
+ .arg(subnet_id).arg(clientid.toText());
|
|
|
+
|
|
|
// Set up the WHERE clause value
|
|
|
MYSQL_BIND inbind[2];
|
|
|
memset(inbind, 0, sizeof(inbind));
|
|
@@ -1380,6 +1432,9 @@ MySqlLeaseMgr::getLease4(const ClientId& clientid, SubnetID subnet_id) const {
|
|
|
|
|
|
Lease6Ptr
|
|
|
MySqlLeaseMgr::getLease6(const isc::asiolink::IOAddress& addr) const {
|
|
|
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_GET_ADDR6)
|
|
|
+ .arg(addr.toText());
|
|
|
+
|
|
|
// Set up the WHERE clause value
|
|
|
MYSQL_BIND inbind[1];
|
|
|
memset(inbind, 0, sizeof(inbind));
|
|
@@ -1403,6 +1458,8 @@ MySqlLeaseMgr::getLease6(const isc::asiolink::IOAddress& addr) const {
|
|
|
|
|
|
Lease6Collection
|
|
|
MySqlLeaseMgr::getLease6(const DUID& duid, uint32_t iaid) const {
|
|
|
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_GET_IAID_DUID)
|
|
|
+ .arg(iaid).arg(duid.toText());
|
|
|
|
|
|
// Set up the WHERE clause value
|
|
|
MYSQL_BIND inbind[2];
|
|
@@ -1444,6 +1501,8 @@ MySqlLeaseMgr::getLease6(const DUID& duid, uint32_t iaid) const {
|
|
|
Lease6Ptr
|
|
|
MySqlLeaseMgr::getLease6(const DUID& duid, uint32_t iaid,
|
|
|
SubnetID subnet_id) const {
|
|
|
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_GET_IAID_SUBID_DUID)
|
|
|
+ .arg(iaid).arg(subnet_id).arg(duid.toText());
|
|
|
|
|
|
// Set up the WHERE clause value
|
|
|
MYSQL_BIND inbind[3];
|
|
@@ -1511,6 +1570,9 @@ void
|
|
|
MySqlLeaseMgr::updateLease4(const Lease4Ptr& lease) {
|
|
|
const StatementIndex stindex = UPDATE_LEASE4;
|
|
|
|
|
|
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_UPDATE_ADDR4)
|
|
|
+ .arg(lease->addr_.toText());
|
|
|
+
|
|
|
// Create the MYSQL_BIND array for the data being updated
|
|
|
std::vector<MYSQL_BIND> bind = exchange4_->createBindForSend(lease);
|
|
|
|
|
@@ -1533,6 +1595,9 @@ void
|
|
|
MySqlLeaseMgr::updateLease6(const Lease6Ptr& lease) {
|
|
|
const StatementIndex stindex = UPDATE_LEASE6;
|
|
|
|
|
|
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_UPDATE_ADDR6)
|
|
|
+ .arg(lease->addr_.toText());
|
|
|
+
|
|
|
// Create the MYSQL_BIND array for the data being updated
|
|
|
std::vector<MYSQL_BIND> bind = exchange6_->createBindForSend(lease);
|
|
|
|
|
@@ -1579,6 +1644,8 @@ MySqlLeaseMgr::deleteLeaseCommon(StatementIndex stindex, MYSQL_BIND* bind) {
|
|
|
|
|
|
bool
|
|
|
MySqlLeaseMgr::deleteLease(const isc::asiolink::IOAddress& addr) {
|
|
|
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_DELETE_ADDR)
|
|
|
+ .arg(addr.toText());
|
|
|
|
|
|
// Set up the WHERE clause value
|
|
|
MYSQL_BIND inbind[1];
|
|
@@ -1632,6 +1699,8 @@ std::pair<uint32_t, uint32_t>
|
|
|
MySqlLeaseMgr::getVersion() const {
|
|
|
const StatementIndex stindex = GET_VERSION;
|
|
|
|
|
|
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_MYSQL_GET_VERSION);
|
|
|
+
|
|
|
uint32_t major; // Major version number
|
|
|
uint32_t minor; // Minor version number
|
|
|
|