]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[master] Merge branch 'trac3977'
authorMarcin Siodelski <marcin@isc.org>
Tue, 27 Oct 2015 10:19:35 +0000 (11:19 +0100)
committerMarcin Siodelski <marcin@isc.org>
Tue, 27 Oct 2015 10:19:35 +0000 (11:19 +0100)
13 files changed:
1  2 
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp4/dhcp4_srv.h
src/bin/dhcp4/tests/dhcp4_test_utils.h
src/bin/dhcp6/dhcp6_messages.mes
src/bin/dhcp6/dhcp6_srv.cc
src/bin/dhcp6/dhcp6_srv.h
src/bin/dhcp6/tests/dhcp6_test_utils.h
src/bin/dhcp6/tests/fqdn_unittest.cc
src/lib/dhcp/tests/pkt6_unittest.cc
src/lib/dhcpsrv/alloc_engine.cc
src/lib/dhcpsrv/alloc_engine_messages.mes
src/lib/dhcpsrv/dhcpsrv_messages.mes
src/lib/dhcpsrv/tests/alloc_engine_expiration_unittest.cc

Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index 3d99674fc5f469dd5c36bd8279d891b8df3a9513,12d72856ce98004829d8007bafba719bd41fd34e..868e4a4f69ef0306cf059413910dee9cd3eab1b4
@@@ -1706,6 -1578,200 +1578,200 @@@ AllocEngine::reclaimExpiredLeases4(cons
      }
  }
  
 -    /// @todo: Maybe add support for DROP stauts?
+ template<typename LeasePtrType>
+ void
+ AllocEngine::reclaimExpiredLease(const LeasePtrType& lease, const bool remove_lease,
+                                  const CalloutHandlePtr& callout_handle) {
+     reclaimExpiredLease(lease, remove_lease ? DB_RECLAIM_REMOVE : DB_RECLAIM_UPDATE,
+                         callout_handle);
+ }
+ template<typename LeasePtrType>
+ void
+ AllocEngine::reclaimExpiredLease(const LeasePtrType& lease,
+                                  const CalloutHandlePtr& callout_handle) {
+     // This variant of the method is used by the code which allocates or
+     // renews leases. It may be the case that the lease has already been
+     // reclaimed, so there is nothing to do.
+     if (!lease->stateExpiredReclaimed()) {
+         reclaimExpiredLease(lease, DB_RECLAIM_LEAVE_UNCHANGED, callout_handle);
+     }
+ }
+ void
+ AllocEngine::reclaimExpiredLease(const Lease6Ptr& lease,
+                                  const DbReclaimMode& reclaim_mode,
+                                  const CalloutHandlePtr& callout_handle) {
+     LOG_DEBUG(alloc_engine_logger, ALLOC_ENGINE_DBG_TRACE,
+               ALLOC_ENGINE_V6_LEASE_RECLAIM)
+         .arg(Pkt6::makeLabel(lease->duid_, lease->hwaddr_))
+         .arg(lease->addr_.toText())
+         .arg(static_cast<int>(lease->prefixlen_));
+     // The skip flag indicates if the callouts have taken responsibility
+     // for reclaiming the lease. The callout will set this to true if
+     // it reclaims the lease itself. In this case the reclamation routine
+     // will not update DNS nor update the database.
+     bool skipped = false;
+     if (callout_handle) {
+         callout_handle->deleteAllArguments();
+         callout_handle->setArgument("lease6", lease);
+         callout_handle->setArgument("remove_lease", reclaim_mode == DB_RECLAIM_REMOVE);
+         HooksManager::callCallouts(Hooks.hook_index_lease6_expire_,
+                                    *callout_handle);
+         skipped = callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP;
+     }
 -    /// @todo: Maybe add support for DROP stauts?
++    /// @todo: Maybe add support for DROP status?
+     /// Not sure if we need to support every possible status everywhere.
+     if (!skipped) {
+         // Generate removal name change request for D2, if required.
+         // This will return immediatelly if the DNS wasn't updated
+         // when the lease was created.
+         queueNCR(CHG_REMOVE, lease);
+         // Let's check if the lease that just expired is in DECLINED state.
+         // If it is, we need to conduct couple extra steps and also force
+         // its removal.
+         bool remove_tmp = (reclaim_mode == DB_RECLAIM_REMOVE);
+         if (lease->state_ == Lease::STATE_DECLINED) {
+             // There's no point in keeping declined lease after its
+             // reclaimation. Declined lease doesn't have any client
+             // identifying information anymore.
+             if (reclaim_mode != DB_RECLAIM_LEAVE_UNCHANGED) {
+                 remove_tmp = true;
+             }
+             // Do extra steps required for declined lease reclaimation:
+             // - bump decline-related stats
+             // - log separate message
+             reclaimDeclined(lease);
+         }
+         if (reclaim_mode != DB_RECLAIM_LEAVE_UNCHANGED) {
+             // Reclaim the lease - depending on the configuration, set the
+             // expired-reclaimed state or simply remove it.
+             LeaseMgr& lease_mgr = LeaseMgrFactory::instance();
+             reclaimLeaseInDatabase<Lease6Ptr>(lease, remove_tmp,
+                                               boost::bind(&LeaseMgr::updateLease6,
+                                                           &lease_mgr, _1));
+         }
+     }
+     // Update statistics.
+     // Decrease number of assigned leases.
+     if (lease->type_ == Lease::TYPE_NA) {
+         // IA_NA
+         StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
+                                                              lease->subnet_id_,
+                                                              "assigned-nas"),
+                                       int64_t(-1));
+     } else if (lease->type_ == Lease::TYPE_PD) {
+         // IA_PD
+         StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
+                                                              lease->subnet_id_,
+                                                              "assigned-pds"),
+                                       int64_t(-1));
+     }
+     // Increase total number of reclaimed leases.
+     StatsMgr::instance().addValue("reclaimed-leases", int64_t(1));
+     // Increase number of reclaimed leases for a subnet.
+     StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
+                                                          lease->subnet_id_,
+                                                          "reclaimed-leases"),
+                                   int64_t(1));
+ }
+ void
+ AllocEngine::reclaimExpiredLease(const Lease4Ptr& lease,
+                                  const DbReclaimMode& reclaim_mode,
+                                  const CalloutHandlePtr& callout_handle) {
+     LOG_DEBUG(alloc_engine_logger, ALLOC_ENGINE_DBG_TRACE,
+               ALLOC_ENGINE_V4_LEASE_RECLAIM)
+         .arg(Pkt4::makeLabel(lease->hwaddr_, lease->client_id_))
+         .arg(lease->addr_.toText());
+     // The skip flag indicates if the callouts have taken responsibility
+     // for reclaiming the lease. The callout will set this to true if
+     // it reclaims the lease itself. In this case the reclamation routine
+     // will not update DNS nor update the database.
+     bool skipped = false;
+     if (callout_handle) {
+         callout_handle->deleteAllArguments();
+         callout_handle->setArgument("lease4", lease);
+         callout_handle->setArgument("remove_lease", reclaim_mode == DB_RECLAIM_REMOVE);
+         HooksManager::callCallouts(Hooks.hook_index_lease4_expire_,
+                                    *callout_handle);
+         skipped = callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP;
+     }
++    /// @todo: Maybe add support for DROP status?
+     /// Not sure if we need to support every possible status everywhere.
+     if (!skipped) {
+         // Generate removal name change request for D2, if required.
+         // This will return immediatelly if the DNS wasn't updated
+         // when the lease was created.
+         queueNCR(CHG_REMOVE, lease);
+         // Let's check if the lease that just expired is in DECLINED state.
+         // If it is, we need to conduct couple extra steps and also force
+         // its removal.
+         bool remove_tmp = (reclaim_mode == DB_RECLAIM_REMOVE);
+         if (lease->state_ == Lease::STATE_DECLINED) {
+             // There's no point in keeping declined lease after its
+             // reclaimation. Declined lease doesn't have any client
+             // identifying information anymore.
+             if (reclaim_mode != DB_RECLAIM_LEAVE_UNCHANGED) {
+                 remove_tmp = true;
+             }
+             // Do extra steps required for declined lease reclaimation:
+             // - bump decline-related stats
+             // - log separate message
+             reclaimDeclined(lease);
+         }
+         if (reclaim_mode != DB_RECLAIM_LEAVE_UNCHANGED) {
+             // Reclaim the lease - depending on the configuration, set the
+             // expired-reclaimed state or simply remove it.
+             LeaseMgr& lease_mgr = LeaseMgrFactory::instance();
+             reclaimLeaseInDatabase<Lease4Ptr>(lease, remove_tmp,
+                                               boost::bind(&LeaseMgr::updateLease4,
+                                                           &lease_mgr, _1));
+         }
+     }
+     // Decrease number of assigned addresses.
+     StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
+                                                          lease->subnet_id_,
+                                                          "assigned-addresses"),
+                                   int64_t(-1));
+     // Increase total number of reclaimed leases.
+     StatsMgr::instance().addValue("reclaimed-leases", int64_t(1));
+     // Increase number of reclaimed leases for a subnet.
+     StatsMgr::instance().addValue(StatsMgr::generateName("subnet",
+                                                          lease->subnet_id_,
+                                                          "reclaimed-leases"),
+                                   int64_t(1));
+ }
  void
  AllocEngine::deleteExpiredReclaimedLeases4(const uint32_t secs) {
      LOG_DEBUG(alloc_engine_logger, ALLOC_ENGINE_DBG_TRACE,
Simple merge