mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-03 23:45:27 +00:00
[#3084] More review comments
src/bin/dhcp4/dhcp4_messages.h b/src/bin/dhcp4/dhcp4_messages.* New messages DHCP4_SERVER_INITIATED_DECLINE_UPDATE_FAILED DHCP4_SERVER_INITIATED_DECLINE_ADD_FAILED DHCP4_SERVER_INITIATED_DECLINE_RESOURCE_BUSY src/bin/dhcp4/dhcp4_srv.* Dhcpv4Srv::sendResponseNoThrow() - restored argument passing by ref Dhcpv4Srv::serverDecline() - use ResourceHandle, try add if update fails
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#include <dhcpsrv/lease_mgr.h>
|
||||
#include <dhcpsrv/lease_mgr_factory.h>
|
||||
#include <dhcpsrv/ncr_generator.h>
|
||||
#include <dhcpsrv/resource_handler.h>
|
||||
#include <dhcpsrv/shared_network.h>
|
||||
#include <dhcpsrv/subnet.h>
|
||||
#include <dhcpsrv/subnet_selector.h>
|
||||
@@ -52,6 +53,7 @@
|
||||
#include <cryptolink/cryptolink.h>
|
||||
#include <process/cfgrpt/config_report.h>
|
||||
|
||||
|
||||
#ifdef HAVE_MYSQL
|
||||
#include <dhcpsrv/mysql_lease_mgr.h>
|
||||
#endif
|
||||
@@ -1599,8 +1601,8 @@ Dhcpv4Srv::processDhcp4Query(Pkt4Ptr& query, Pkt4Ptr& rsp,
|
||||
}
|
||||
|
||||
void
|
||||
Dhcpv4Srv::sendResponseNoThrow(hooks::CalloutHandlePtr callout_handle,
|
||||
Pkt4Ptr query, Pkt4Ptr rsp) {
|
||||
Dhcpv4Srv::sendResponseNoThrow(hooks::CalloutHandlePtr& callout_handle,
|
||||
Pkt4Ptr& query, Pkt4Ptr& rsp) {
|
||||
try {
|
||||
processPacketPktSend(callout_handle, query, rsp);
|
||||
processPacketBufferSend(callout_handle, rsp);
|
||||
@@ -3948,25 +3950,48 @@ Dhcpv4Srv::declineLease(const Lease4Ptr& lease, const Pkt4Ptr& decline,
|
||||
void
|
||||
Dhcpv4Srv::serverDecline(hooks::CalloutHandlePtr& /* callout_handle */, Pkt4Ptr& query,
|
||||
Lease4Ptr lease, bool lease_exists) {
|
||||
|
||||
// Check if the resource is busy i.e. can be modified by another thread
|
||||
// for another client. Highly unlikely.
|
||||
ResourceHandler4 resource_handler;
|
||||
if (MultiThreadingMgr::instance().getMode() && !resource_handler.tryLock4(lease->addr_)) {
|
||||
LOG_ERROR(lease4_logger, DHCP4_SERVER_INITIATED_DECLINE_RESOURCE_BUSY)
|
||||
.arg(query->getLabel())
|
||||
.arg(lease->addr_.toText());
|
||||
return;
|
||||
}
|
||||
|
||||
// We need to disassociate the lease from the client. Once we move a lease
|
||||
// to declined state, it is no longer associated with the client in any
|
||||
// way.
|
||||
lease->decline(CfgMgr::instance().getCurrentCfg()->getDeclinePeriod());
|
||||
|
||||
// Add or update the lease in the database.
|
||||
try {
|
||||
if (lease_exists) {
|
||||
// If the lease already exists, update it in the database.
|
||||
if (lease_exists) {
|
||||
try {
|
||||
LeaseMgrFactory::instance().updateLease4(lease);
|
||||
} else {
|
||||
LeaseMgrFactory::instance().addLease(lease);
|
||||
} catch (const NoSuchLease& ex) {
|
||||
// We expected the lease to exist but it doesn't so let's add
|
||||
// try to add it.
|
||||
lease_exists = false;
|
||||
} catch (const Exception& ex) {
|
||||
// Update failed.
|
||||
LOG_ERROR(lease4_logger, DHCP4_SERVER_INITIATED_DECLINE_UPDATE_FAILED)
|
||||
.arg(query->getLabel())
|
||||
.arg(lease->addr_.toText());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!lease_exists) {
|
||||
try {
|
||||
LeaseMgrFactory::instance().addLease(lease);
|
||||
} catch (const Exception& ex) {
|
||||
LOG_ERROR(lease4_logger, DHCP4_SERVER_INITIATED_DECLINE_ADD_FAILED)
|
||||
.arg(query->getLabel())
|
||||
.arg(lease->addr_.toText());
|
||||
return;
|
||||
}
|
||||
} catch (const Exception& ex) {
|
||||
// Update failed.
|
||||
LOG_ERROR(lease4_logger, DHCP4_SERVER_INITIATED_DECLINE_FAILED)
|
||||
.arg(query->getLabel())
|
||||
.arg(lease->addr_.toText())
|
||||
.arg(ex.what());
|
||||
return;
|
||||
}
|
||||
|
||||
// Bump up the statistics. If the lease does not exist (i.e. offer-lifetime == 0) we
|
||||
|
Reference in New Issue
Block a user