extern const isc::log::MessageID DHCP4_RESPONSE_HOSTNAME_GENERATE = "DHCP4_RESPONSE_HOSTNAME_GENERATE";
extern const isc::log::MessageID DHCP4_SERVER_FAILED = "DHCP4_SERVER_FAILED";
extern const isc::log::MessageID DHCP4_SERVER_INITIATED_DECLINE = "DHCP4_SERVER_INITIATED_DECLINE";
+extern const isc::log::MessageID DHCP4_SERVER_INITIATED_DECLINE_ADD_FAILED = "DHCP4_SERVER_INITIATED_DECLINE_ADD_FAILED";
extern const isc::log::MessageID DHCP4_SERVER_INITIATED_DECLINE_FAILED = "DHCP4_SERVER_INITIATED_DECLINE_FAILED";
+extern const isc::log::MessageID DHCP4_SERVER_INITIATED_DECLINE_RESOURCE_BUSY = "DHCP4_SERVER_INITIATED_DECLINE_RESOURCE_BUSY";
+extern const isc::log::MessageID DHCP4_SERVER_INITIATED_DECLINE_UPDATE_FAILED = "DHCP4_SERVER_INITIATED_DECLINE_UPDATE_FAILED";
extern const isc::log::MessageID DHCP4_SHUTDOWN = "DHCP4_SHUTDOWN";
extern const isc::log::MessageID DHCP4_SHUTDOWN_REQUEST = "DHCP4_SHUTDOWN_REQUEST";
extern const isc::log::MessageID DHCP4_SRV_CONSTRUCT_ERROR = "DHCP4_SRV_CONSTRUCT_ERROR";
"DHCP4_RESPONSE_HOSTNAME_GENERATE", "%1: server has generated hostname %2 for the client",
"DHCP4_SERVER_FAILED", "server failed: %1",
"DHCP4_SERVER_INITIATED_DECLINE", "Lease for addr %1 has been found to be already in use. The lease will be unavailable for %2 seconds.",
+ "DHCP4_SERVER_INITIATED_DECLINE_ADD_FAILED", "%1: error adding a lease for address %2",
"DHCP4_SERVER_INITIATED_DECLINE_FAILED", "%1: error on server-initiated decline lease for address %2: %3",
+ "DHCP4_SERVER_INITIATED_DECLINE_RESOURCE_BUSY", "%1: error declining a lease for address %2",
+ "DHCP4_SERVER_INITIATED_DECLINE_UPDATE_FAILED", "%1: error updating lease for address %2",
"DHCP4_SHUTDOWN", "server shutdown",
"DHCP4_SHUTDOWN_REQUEST", "shutdown of server requested",
"DHCP4_SRV_CONSTRUCT_ERROR", "error creating Dhcpv4Srv object, reason: %1",
extern const isc::log::MessageID DHCP4_RESPONSE_HOSTNAME_GENERATE;
extern const isc::log::MessageID DHCP4_SERVER_FAILED;
extern const isc::log::MessageID DHCP4_SERVER_INITIATED_DECLINE;
+extern const isc::log::MessageID DHCP4_SERVER_INITIATED_DECLINE_ADD_FAILED;
extern const isc::log::MessageID DHCP4_SERVER_INITIATED_DECLINE_FAILED;
+extern const isc::log::MessageID DHCP4_SERVER_INITIATED_DECLINE_RESOURCE_BUSY;
+extern const isc::log::MessageID DHCP4_SERVER_INITIATED_DECLINE_UPDATE_FAILED;
extern const isc::log::MessageID DHCP4_SHUTDOWN;
extern const isc::log::MessageID DHCP4_SHUTDOWN_REQUEST;
extern const isc::log::MessageID DHCP4_SRV_CONSTRUCT_ERROR;
for which the decline was attempted. The last one contains the reason of
failure.
+% DHCP4_HOOK_LEASE4_OFFER_ARGUMENT_MISSING hook callouts did not set an argument as expected %1 for %2
+This error message is printed when none of the callouts installed on the
+lease4_offer hook point set an expected argument in the callout status.
+This is a programming error in the installed hook libraries. Details of
+the argument and the query in process at the time are provided log arguments.
+
% DHCP4_SERVER_INITIATED_DECLINE Lease for addr %1 has been found to be already in use. The lease will be unavailable for %2 seconds.
This informational message is printed when the server has detected via
ICMP ECHO (i.e. ping check) or other means that a lease which should be
the underlying problem of a misconfigured or rogue device is not solved, this
address may be declined again in the future.
-% DHCP4_HOOK_LEASE4_OFFER_ARGUMENT_MISSING hook callouts did not set an argument as expected %1 for %2
-This error message is printed when none of the callouts installed on the
-lease4_offer hook point set an expected argument in the callout status.
-This is a programming error in the installed hook libraries. Details of
-the argument and the query in process at the time are provided log arguments.
+% DHCP4_SERVER_INITIATED_DECLINE_UPDATE_FAILED %1: error updating lease for address %2
+This error message indicates that the server failed to update a lease in the
+lease store to the DECLINED state The first argument includes the client and
+the transaction identification information. The second argument holds the IPv4
+address for which the decline was attempted.
+
+% DHCP4_SERVER_INITIATED_DECLINE_ADD_FAILED %1: error adding a lease for address %2
+This error message indicates that the server failed to add a DECLINED lease to
+the lease store The first argument includes the client and the transaction
+identification information. The second argument holds the IPv4 address for which
+the decline was attempted.
+
+% DHCP4_SERVER_INITIATED_DECLINE_RESOURCE_BUSY %1: error declining a lease for address %2
+This error message indicates that the while one server thread was attempting
+to mark a lease as DECLINED, it was already locked by another thread.
+The first argument includes the client and the transaction identification
+information. The second argument holds the IPv4 address for which the decline
+was attempted.
#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>
#include <cryptolink/cryptolink.h>
#include <process/cfgrpt/config_report.h>
+
#ifdef HAVE_MYSQL
#include <dhcpsrv/mysql_lease_mgr.h>
#endif
}
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);
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 {
+ } 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
/// @param callout_handle pointer to the callout handle.
/// @param query A pointer to the packet to be processed.
/// @param rsp A pointer to the response.
- void sendResponseNoThrow(hooks::CalloutHandlePtr callout_handle,
- Pkt4Ptr query, Pkt4Ptr rsp);
+ void sendResponseNoThrow(hooks::CalloutHandlePtr& callout_handle,
+ Pkt4Ptr& query, Pkt4Ptr& rsp);
/// @brief Process a single incoming DHCPv4 packet.
///