@@ -421,9 +421,9 @@ Dhcpv6Srv::setHostIdentifiers(AllocEngine::ClientContext6& ctx) {
421421 }
422422}
423423
424- bool
425- Dhcpv6Srv::earlyGHRLookup (const Pkt6Ptr& query,
426- AllocEngine::ClientContext6& ctx) {
424+ void
425+ Dhcpv6Srv::initContext0 (const Pkt6Ptr& query,
426+ AllocEngine::ClientContext6& ctx) {
427427 // Pointer to client's query.
428428 ctx.query_ = query;
429429
@@ -432,6 +432,13 @@ Dhcpv6Srv::earlyGHRLookup(const Pkt6Ptr& query,
432432
433433 // Hardware address.
434434 ctx.hwaddr_ = getMAC (query);
435+ }
436+
437+ bool
438+ Dhcpv6Srv::earlyGHRLookup (const Pkt6Ptr& query,
439+ AllocEngine::ClientContext6& ctx) {
440+ // First part of context initialization.
441+ initContext0 (query, ctx);
435442
436443 // Get the early-global-reservations-lookup flag value.
437444 data::ConstElementPtr egrl = CfgMgr::instance ().getCurrentCfg ()->
@@ -492,15 +499,16 @@ Dhcpv6Srv::earlyGHRLookup(const Pkt6Ptr& query,
492499}
493500
494501void
495- Dhcpv6Srv::initContext (const Subnet6Ptr& subnet,
496- const Pkt6Ptr& pkt,
497- AllocEngine::ClientContext6& ctx,
498- bool & drop) {
499- ctx.subnet_ = subnet;
502+ Dhcpv6Srv::initContext (AllocEngine::ClientContext6& ctx, bool & drop) {
503+ // Sanity check.
504+ if (!ctx.query_ ) {
505+ drop = true ;
506+ return ;
507+ }
500508 ctx.fwd_dns_update_ = false ;
501509 ctx.rev_dns_update_ = false ;
502510 ctx.hostname_ = " " ;
503- ctx.callout_handle_ = getCalloutHandle (pkt );
511+ ctx.callout_handle_ = getCalloutHandle (ctx. query_ );
504512
505513 // Collect host identifiers if host reservations enabled. The identifiers
506514 // are stored in order of preference. The server will use them in that
@@ -545,37 +553,37 @@ Dhcpv6Srv::initContext(const Subnet6Ptr& subnet,
545553 // a result, the first_class set via the host reservation will
546554 // replace the second_class because the second_class will this
547555 // time evaluate to false as desired.
548- removeDependentEvaluatedClasses (pkt );
549- setReservedClientClasses (pkt , ctx);
550- evaluateClasses (pkt , false );
556+ removeDependentEvaluatedClasses (ctx. query_ );
557+ setReservedClientClasses (ctx. query_ , ctx);
558+ evaluateClasses (ctx. query_ , false );
551559 }
552560
553561 // Set KNOWN builtin class if something was found, UNKNOWN if not.
554562 if (!ctx.hosts_ .empty ()) {
555- pkt ->addClass (" KNOWN" );
563+ ctx. query_ ->addClass (" KNOWN" );
556564 LOG_DEBUG (dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLASS_ASSIGNED)
557- .arg (pkt ->getLabel ())
565+ .arg (ctx. query_ ->getLabel ())
558566 .arg (" KNOWN" );
559567 } else {
560- pkt ->addClass (" UNKNOWN" );
568+ ctx. query_ ->addClass (" UNKNOWN" );
561569 LOG_DEBUG (dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLASS_ASSIGNED)
562- .arg (pkt ->getLabel ())
570+ .arg (ctx. query_ ->getLabel ())
563571 .arg (" UNKNOWN" );
564572 }
565573
566574 // Perform second pass of classification.
567- evaluateClasses (pkt , true );
575+ evaluateClasses (ctx. query_ , true );
568576
569- const ClientClasses& classes = pkt ->getClasses ();
577+ const ClientClasses& classes = ctx. query_ ->getClasses ();
570578 LOG_DEBUG (dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLASSES_ASSIGNED_AFTER_SUBNET_SELECTION)
571- .arg (pkt ->getLabel ())
579+ .arg (ctx. query_ ->getLabel ())
572580 .arg (classes.toText ());
573581
574582 // Check the DROP special class.
575- if (pkt ->inClass (" DROP" )) {
583+ if (ctx. query_ ->inClass (" DROP" )) {
576584 LOG_DEBUG (packet6_logger, DBGLVL_PKT_HANDLING, DHCP6_PACKET_DROP_DROP_CLASS2)
577- .arg (pkt ->makeLabel (pkt ->getClientId (), nullptr ))
578- .arg (pkt ->toText ());
585+ .arg (ctx. query_ ->makeLabel (ctx. query_ ->getClientId (), 0 ))
586+ .arg (ctx. query_ ->toText ());
579587 StatsMgr::instance ().addValue (" pkt6-receive-drop" ,
580588 static_cast <int64_t >(1 ));
581589 drop = true ;
@@ -968,15 +976,39 @@ Dhcpv6Srv::processDhcp6Query(Pkt6Ptr query) {
968976
969977 // Complete the client context initialization.
970978 bool drop = false ;
971- Subnet6Ptr subnet = selectSubnet (query, drop);
979+ ctx. subnet_ = selectSubnet (query, drop);
972980 if (drop) {
973981 // Caller will immediately drop the packet so simply return now.
974982 return (Pkt6Ptr ());
975983 }
976984
977- // Park point here.
985+ return (processLocalizedQuery6 (ctx));
986+ }
987+
988+ void
989+ Dhcpv6Srv::processLocalizedQuery6AndSendResponse (Pkt6Ptr query,
990+ AllocEngine::ClientContext6& ctx) {
991+ try {
992+ Pkt6Ptr rsp = processLocalizedQuery6 (ctx);
993+ if (!rsp) {
994+ return ;
995+ }
996+
997+ CalloutHandlePtr callout_handle = getCalloutHandle (query);
998+ processPacketBufferSend (callout_handle, rsp);
999+ } catch (const std::exception& e) {
1000+ LOG_ERROR (packet6_logger, DHCP6_PACKET_PROCESS_STD_EXCEPTION)
1001+ .arg (e.what ());
1002+ } catch (...) {
1003+ LOG_ERROR (packet6_logger, DHCP6_PACKET_PROCESS_EXCEPTION);
1004+ }
1005+ }
9781006
979- initContext (subnet, query, ctx, drop);
1007+ Pkt6Ptr
1008+ Dhcpv6Srv::processLocalizedQuery6 (AllocEngine::ClientContext6& ctx) {
1009+ Pkt6Ptr query = ctx.query_ ;
1010+ bool drop = false ;
1011+ initContext (ctx, drop);
9801012 // Stop here if initContext decided to drop the packet.
9811013 if (drop) {
9821014 return (Pkt6Ptr ());
0 commit comments