@@ -421,9 +421,9 @@ Dhcpv6Srv::setHostIdentifiers(AllocEngine::ClientContext6& ctx) {
421
421
}
422
422
}
423
423
424
- bool
425
- Dhcpv6Srv::earlyGHRLookup (const Pkt6Ptr& query,
426
- AllocEngine::ClientContext6& ctx) {
424
+ void
425
+ Dhcpv6Srv::initContext0 (const Pkt6Ptr& query,
426
+ AllocEngine::ClientContext6& ctx) {
427
427
// Pointer to client's query.
428
428
ctx.query_ = query;
429
429
@@ -432,6 +432,13 @@ Dhcpv6Srv::earlyGHRLookup(const Pkt6Ptr& query,
432
432
433
433
// Hardware address.
434
434
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);
435
442
436
443
// Get the early-global-reservations-lookup flag value.
437
444
data::ConstElementPtr egrl = CfgMgr::instance ().getCurrentCfg ()->
@@ -492,15 +499,16 @@ Dhcpv6Srv::earlyGHRLookup(const Pkt6Ptr& query,
492
499
}
493
500
494
501
void
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
+ }
500
508
ctx.fwd_dns_update_ = false ;
501
509
ctx.rev_dns_update_ = false ;
502
510
ctx.hostname_ = " " ;
503
- ctx.callout_handle_ = getCalloutHandle (pkt );
511
+ ctx.callout_handle_ = getCalloutHandle (ctx. query_ );
504
512
505
513
// Collect host identifiers if host reservations enabled. The identifiers
506
514
// are stored in order of preference. The server will use them in that
@@ -545,37 +553,37 @@ Dhcpv6Srv::initContext(const Subnet6Ptr& subnet,
545
553
// a result, the first_class set via the host reservation will
546
554
// replace the second_class because the second_class will this
547
555
// 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 );
551
559
}
552
560
553
561
// Set KNOWN builtin class if something was found, UNKNOWN if not.
554
562
if (!ctx.hosts_ .empty ()) {
555
- pkt ->addClass (" KNOWN" );
563
+ ctx. query_ ->addClass (" KNOWN" );
556
564
LOG_DEBUG (dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLASS_ASSIGNED)
557
- .arg (pkt ->getLabel ())
565
+ .arg (ctx. query_ ->getLabel ())
558
566
.arg (" KNOWN" );
559
567
} else {
560
- pkt ->addClass (" UNKNOWN" );
568
+ ctx. query_ ->addClass (" UNKNOWN" );
561
569
LOG_DEBUG (dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLASS_ASSIGNED)
562
- .arg (pkt ->getLabel ())
570
+ .arg (ctx. query_ ->getLabel ())
563
571
.arg (" UNKNOWN" );
564
572
}
565
573
566
574
// Perform second pass of classification.
567
- evaluateClasses (pkt , true );
575
+ evaluateClasses (ctx. query_ , true );
568
576
569
- const ClientClasses& classes = pkt ->getClasses ();
577
+ const ClientClasses& classes = ctx. query_ ->getClasses ();
570
578
LOG_DEBUG (dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLASSES_ASSIGNED_AFTER_SUBNET_SELECTION)
571
- .arg (pkt ->getLabel ())
579
+ .arg (ctx. query_ ->getLabel ())
572
580
.arg (classes.toText ());
573
581
574
582
// Check the DROP special class.
575
- if (pkt ->inClass (" DROP" )) {
583
+ if (ctx. query_ ->inClass (" DROP" )) {
576
584
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 ());
579
587
StatsMgr::instance ().addValue (" pkt6-receive-drop" ,
580
588
static_cast <int64_t >(1 ));
581
589
drop = true ;
@@ -968,15 +976,39 @@ Dhcpv6Srv::processDhcp6Query(Pkt6Ptr query) {
968
976
969
977
// Complete the client context initialization.
970
978
bool drop = false ;
971
- Subnet6Ptr subnet = selectSubnet (query, drop);
979
+ ctx. subnet_ = selectSubnet (query, drop);
972
980
if (drop) {
973
981
// Caller will immediately drop the packet so simply return now.
974
982
return (Pkt6Ptr ());
975
983
}
976
984
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
+ }
978
1006
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);
980
1012
// Stop here if initContext decided to drop the packet.
981
1013
if (drop) {
982
1014
return (Pkt6Ptr ());
0 commit comments