Parcourir la source

[3694] Added warning message when there is an address conflict.

Marcin Siodelski il y a 10 ans
Parent
commit
2ae3435279

+ 43 - 29
src/lib/dhcpsrv/alloc_engine.cc

@@ -63,35 +63,6 @@ AllocEngineHooks Hooks;
 namespace isc {
 namespace dhcp {
 
-AllocEngine::ClientContext4::ClientContext4()
-    : subnet_(), clientid_(), hwaddr_(),
-      requested_address_(IOAddress::IPV4_ZERO_ADDRESS()),
-      fwd_dns_update_(false), rev_dns_update_(false),
-      hostname_(""), callout_handle_(), fake_allocation_(false),
-      old_lease_(), host_() {
-}
-
-bool
-AllocEngine::ClientContext4::myLease(const Lease4& lease) const {
-    if ((!hwaddr_ && lease.hwaddr_) || (hwaddr_ && !lease.hwaddr_)) {
-        return (false);
-    }
-
-    if ((hwaddr_ && lease.hwaddr_) && (hwaddr_->hwaddr_ != lease.hwaddr_->hwaddr_)) {
-        return (false);
-    }
-
-    if ((!clientid_ && lease.client_id_) || (clientid_ && !lease.client_id_)) {
-        return (false);
-    }
-
-    if ((clientid_ && lease.client_id_) && (*clientid_ != *lease.client_id_)) {
-        return (false);
-    }
-
-    return (true);
-}
-
 AllocEngine::IterativeAllocator::IterativeAllocator(Lease::Type lease_type)
     :Allocator(lease_type) {
 }
@@ -1218,6 +1189,35 @@ addressReserved(const IOAddress& address, const AllocEngine::ClientContext4& ctx
 namespace isc {
 namespace dhcp {
 
+AllocEngine::ClientContext4::ClientContext4()
+    : subnet_(), clientid_(), hwaddr_(),
+      requested_address_(IOAddress::IPV4_ZERO_ADDRESS()),
+      fwd_dns_update_(false), rev_dns_update_(false),
+      hostname_(""), callout_handle_(), fake_allocation_(false),
+      old_lease_(), host_(), conflicting_lease_() {
+}
+
+bool
+AllocEngine::ClientContext4::myLease(const Lease4& lease) const {
+    if ((!hwaddr_ && lease.hwaddr_) || (hwaddr_ && !lease.hwaddr_)) {
+        return (false);
+    }
+
+    if ((hwaddr_ && lease.hwaddr_) && (hwaddr_->hwaddr_ != lease.hwaddr_->hwaddr_)) {
+        return (false);
+    }
+
+    if ((!clientid_ && lease.client_id_) || (clientid_ && !lease.client_id_)) {
+        return (false);
+    }
+
+    if ((clientid_ && lease.client_id_) && (*clientid_ != *lease.client_id_)) {
+        return (false);
+    }
+
+    return (true);
+}
+
 Lease4Ptr
 AllocEngine::allocateLease4(const SubnetPtr& subnet, const ClientIdPtr& clientid,
                             const HWAddrPtr& hwaddr, const IOAddress& hint,
@@ -1317,6 +1317,12 @@ AllocEngine::discoverLease4(AllocEngine::ClientContext4& ctx) {
             // because this is not a real allocation, we just offer what we can
             // allocate in the DHCPREQUEST time.
             new_lease = allocateOrReuseLease4(ctx.host_->getIPv4Reservation(), ctx);
+            if (!new_lease) {
+                LOG_WARN(dhcpsrv_logger, DHCPSRV_DISCOVER_ADDRESS_CONFLICT)
+                    .arg(ctx.host_->getIPv4Reservation().toText())
+                    .arg(ctx.conflicting_lease_ ? ctx.conflicting_lease_->toText() :
+                         "(no lease info)");
+            }
 
         } else {
             new_lease = renewLease4(client_lease, ctx);
@@ -1720,11 +1726,19 @@ AllocEngine::reuseExpiredLease4(Lease4Ptr& expired,
 
 Lease4Ptr
 AllocEngine::allocateOrReuseLease4(const IOAddress& candidate, ClientContext4& ctx) {
+    ctx.conflicting_lease_.reset();
+
     Lease4Ptr exist_lease = LeaseMgrFactory::instance().getLease4(candidate);
     if (exist_lease) {
         if (exist_lease->expired()) {
             ctx.old_lease_ = Lease4Ptr(new Lease4(*exist_lease));
             return (reuseExpiredLease4(exist_lease, ctx));
+
+        } else {
+            // If there is a lease and it is not expired, pass this lease back
+            // to the caller in the context. The caller may need to know
+            // which lease we're conflicting with.
+            ctx.conflicting_lease_ = exist_lease;
         }
 
     } else {

+ 7 - 0
src/lib/dhcpsrv/alloc_engine.h

@@ -777,6 +777,13 @@ public:
         /// @brief A pointer to the object identifying host reservations.
         ConstHostPtr host_;
 
+        /// @brief A pointer to the object representing a lease in conflict.
+        ///
+        /// This pointer is set by some of the allocation methods when
+        /// the lease can't be allocated because there is another lease
+        /// which is in conflict with this allocation.
+        Lease4Ptr conflicting_lease_;
+
         /// @brief Default constructor.
         ClientContext4();
 

+ 7 - 0
src/lib/dhcpsrv/dhcpsrv_messages.mes

@@ -179,6 +179,13 @@ the database access parameters are changed: in the latter case, the
 server closes the currently open database, and opens a database using
 the new parameters.
 
+% DHCPSRV_DISCOVER_ADDRESS_CONFLICT conflicting reservation for address %1 with existing lease %2
+This warning message is issued when the DHCP server finds that the
+address reserved for the client can't be offered because this address
+is currently allocated to another client. The server will try to allocate
+a different (temporary) address to the client to use until the conflict
+is resolved.
+
 % DHCPSRV_DHCP_DDNS_ERROR_EXCEPTION error handler for DHCP_DDNS IO generated an expected exception: %1
 This is an error message that occurs when an attempt to send a request to
 kea-dhcp-ddns fails there registered error handler threw an uncaught exception.