From: Tomek Mrugalski Date: Thu, 23 Mar 2017 03:33:49 +0000 (-0700) Subject: [5132] host6_identifier hook point implemented X-Git-Tag: trac5196_base~12^2~19 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2e62414209604b636691ebd38bd3cddeb2d9af77;p=thirdparty%2Fkea.git [5132] host6_identifier hook point implemented --- diff --git a/src/bin/dhcp6/dhcp6_messages.mes b/src/bin/dhcp6/dhcp6_messages.mes index 748941b279..7cdc24e8ce 100644 --- a/src/bin/dhcp6/dhcp6_messages.mes +++ b/src/bin/dhcp6/dhcp6_messages.mes @@ -263,6 +263,12 @@ as a result of receiving SIGHUP signal. This is an error message logged when the dynamic reconfiguration of the DHCP server failed. +% DHCP6_FLEX_ID flexible identifier generated for incoming packet: %1 +This debug message is printed when host reservation type is set to flexible identifier +and the expression specified in its configuration generated (was evaluated to) +an indetifier for incoming packet. This debug message is mainly intended as a +debugging assistance for flexible identifier. + % DHCP6_HANDLE_SIGNAL_EXCEPTION An exception was thrown while handing signal: %1 This error message is printed when an exception was raised during signal processing. This likely indicates a coding error and should be reported to ISC. diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index 78bd55993a..290bfe4bc5 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -100,16 +100,18 @@ struct Dhcp6Hooks { int hook_index_pkt6_send_; ///< index for "pkt6_send" hook point int hook_index_buffer6_send_; ///< index for "buffer6_send" hook point int hook_index_lease6_decline_; ///< index for "lease6_decline" hook point + int hook_index_host6_identifier_;///< index for "host6_identifier" hook point /// Constructor that registers hook points for DHCPv6 engine Dhcp6Hooks() { - hook_index_buffer6_receive_= HooksManager::registerHook("buffer6_receive"); - hook_index_pkt6_receive_ = HooksManager::registerHook("pkt6_receive"); - hook_index_subnet6_select_ = HooksManager::registerHook("subnet6_select"); - hook_index_lease6_release_ = HooksManager::registerHook("lease6_release"); - hook_index_pkt6_send_ = HooksManager::registerHook("pkt6_send"); - hook_index_buffer6_send_ = HooksManager::registerHook("buffer6_send"); - hook_index_lease6_decline_ = HooksManager::registerHook("lease6_decline"); + hook_index_buffer6_receive_ = HooksManager::registerHook("buffer6_receive"); + hook_index_pkt6_receive_ = HooksManager::registerHook("pkt6_receive"); + hook_index_subnet6_select_ = HooksManager::registerHook("subnet6_select"); + hook_index_lease6_release_ = HooksManager::registerHook("lease6_release"); + hook_index_pkt6_send_ = HooksManager::registerHook("pkt6_send"); + hook_index_buffer6_send_ = HooksManager::registerHook("buffer6_send"); + hook_index_lease6_decline_ = HooksManager::registerHook("lease6_decline"); + hook_index_host6_identifier_= HooksManager::registerHook("host6_identifier"); } }; @@ -323,7 +325,40 @@ Dhcpv6Srv::initContext(const Pkt6Ptr& pkt, AllocEngine::ClientContext6& ctx) { ctx.addHostIdentifier(id_type, ctx.hwaddr_->hwaddr_); } break; + case Host::IDENT_FLEX: + // At this point the information in the packet has been unpacked into + // the various packet fields and option objects has been created. + // Execute callouts registered for packet6_receive. + if (HooksManager::calloutsPresent(Hooks.hook_index_host6_identifier_)) { + CalloutHandlePtr callout_handle = getCalloutHandle(pkt); + Host::IdentifierType type = Host::IDENT_FLEX; + std::vector id; + + // Delete previously set arguments + callout_handle->deleteAllArguments(); + + // Pass incoming packet as argument + callout_handle->setArgument("query6", pkt); + callout_handle->setArgument("id_type", type); + callout_handle->setArgument("id_value", id); + + // Call callouts + HooksManager::callCallouts(Hooks.hook_index_pkt6_receive_, *callout_handle); + + callout_handle->getArgument("id_type", type); + callout_handle->getArgument("id_value", id); + + if ((callout_handle->getStatus() == CalloutHandle::NEXT_STEP_CONTINUE) && + !id.empty()) { + + LOG_DEBUG(packet6_logger, DBGLVL_TRACE_BASIC, DHCP6_FLEX_ID) + .arg(Host::getIdentifierAsText(type, &id[0], id.size())); + + ctx.addHostIdentifier(type, id); + } + } + break; default: ; } diff --git a/src/lib/dhcpsrv/host.cc b/src/lib/dhcpsrv/host.cc index abd8113395..976719d330 100644 --- a/src/lib/dhcpsrv/host.cc +++ b/src/lib/dhcpsrv/host.cc @@ -204,6 +204,8 @@ Host::getIdentifierAsText(const IdentifierType& type, const uint8_t* value, case IDENT_CLIENT_ID: s << "client-id"; break; + case IDENT_FLEX: + s << "flex"; default: // This should never happen actually, unless we add new identifier // and forget to add a case for it above. diff --git a/src/lib/dhcpsrv/host.h b/src/lib/dhcpsrv/host.h index 201f528938..a89242a294 100644 --- a/src/lib/dhcpsrv/host.h +++ b/src/lib/dhcpsrv/host.h @@ -184,7 +184,8 @@ public: IDENT_HWADDR, IDENT_DUID, IDENT_CIRCUIT_ID, - IDENT_CLIENT_ID + IDENT_CLIENT_ID, + IDENT_FLEX, ///< Flexible host identifier. }; /// @brief Constant pointing to the last identifier of the