From: Tomek Mrugalski Date: Thu, 15 Oct 2015 07:29:55 +0000 (+0200) Subject: [master] Merge branch 'trac3987' (lease6_decline hook) X-Git-Tag: trac3874_base~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b6e3f1bbe3595aeba769d627d571e2eeee38a397;p=thirdparty%2Fkea.git [master] Merge branch 'trac3987' (lease6_decline hook) --- b6e3f1bbe3595aeba769d627d571e2eeee38a397 diff --cc src/bin/dhcp4/tests/dhcp4_srv_unittest.cc index ade56a632f,2f4f1ce767..38ea304026 --- a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc @@@ -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 { diff --cc src/bin/dhcp6/dhcp6_srv.cc index 029a60e724,d5d3d9e24a..8eb09c4d16 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@@ -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 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.