]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[master] Merge branch 'trac3987' (lease6_decline hook)
authorTomek Mrugalski <tomasz@isc.org>
Thu, 15 Oct 2015 07:29:55 +0000 (09:29 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Thu, 15 Oct 2015 07:29:55 +0000 (09:29 +0200)
1  2 
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
src/bin/dhcp6/dhcp6_srv.cc
src/bin/dhcp6/dhcp6_srv.h

Simple merge
index ade56a632f7f7a3def81088b00aeee052d99f764,2f4f1ce767097ef1a3de7352c5bd39fcf66e4bf7..38ea30402614a5c9df9ca80103b27b043fe702f6
@@@ -52,9 -56,9 +52,8 @@@ using namespace isc
  using namespace isc::dhcp;
  using namespace isc::data;
  using namespace isc::asiolink;
 -using namespace isc::hooks;
  using namespace isc::config;
  using namespace isc::dhcp::test;
- using namespace isc::test;
  
  namespace {
  
index 029a60e724d8fc1c23c6891f2aec13a5ad45ded6,d5d3d9e24aad2bc8dd04f54547cd0941e20001dd..8eb09c4d1606da402d6f9635fac315c2353b373b
@@@ -2755,18 -2776,47 +2776,55 @@@ Dhcpv6Srv::setStatusCode(boost::shared_
      container->addOption(status);
  }
  
- void
+ bool
  Dhcpv6Srv::declineLease(const Pkt6Ptr& decline, const Lease6Ptr lease,
                          boost::shared_ptr<Option6IA> ia_rsp) {
 +    // We do not want to decrease the assigned-nas at this time. While
 +    // technically a declined address is no longer allocated, the primary usage
 +    // of the assigned-addresses statistic is to monitor pool utilization. Most
 +    // people would forget to include declined-addresses in the calculation,
 +    // and simply do assigned-addresses/total-addresses. This would have a bias
 +    // towards under-representing pool utilization, if we decreased allocated
 +    // immediately after receiving DHCPDECLINE, rather than later when we recover
 +    // the address.
  
+     // Let's call lease6_decline hooks if necessary.
+     if (HooksManager::calloutsPresent(Hooks.hook_index_lease6_decline_)) {
+         CalloutHandlePtr callout_handle = getCalloutHandle(decline);
+         // Delete previously set arguments
+         callout_handle->deleteAllArguments();
+         // Pass incoming packet as argument
+         callout_handle->setArgument("query6", decline);
+         callout_handle->setArgument("lease6", lease);
+         // Call callouts
+         HooksManager::callCallouts(Hooks.hook_index_lease6_decline_,
+                                    *callout_handle);
+         // Callouts decided to SKIP the next processing step. The next
+         // processing step would to actually decline the lease, so we'll
+         // keep the lease as is.
+         if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
+             LOG_DEBUG(hooks_logger, DBG_DHCP6_DETAIL, DHCP6_HOOK_DECLINE_SKIP)
+                 .arg(decline->getLabel())
+                 .arg(decline->getIface())
+                 .arg(lease->addr_.toText());
+             return (true);
+         }
+         // Callouts decided to DROP the packet. Let's simply log it and
+         // return false, so callers will act accordingly.
+         if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_DROP) {
+             LOG_DEBUG(hooks_logger, DBG_DHCP6_DETAIL, DHCP6_HOOK_DECLINE_DROP)
+                 .arg(decline->getLabel())
+                 .arg(decline->getIface())
+                 .arg(lease->addr_.toText());
+             return (false);
+         }
+     }
      // Check if a lease has flags indicating that the FQDN update has
      // been performed. If so, create NameChangeRequest which removes
      // the entries. This method does all necessary checks.
Simple merge