Skip to content

Commit

Permalink
[#2022] Checkpoint: last version of parking code
Browse files Browse the repository at this point in the history
  • Loading branch information
fxdupont authored and andrei-pavel committed Feb 19, 2024
1 parent a1f225f commit 96fcd7b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
52 changes: 42 additions & 10 deletions src/bin/dhcp6/dhcp6_srv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,23 @@ Dhcpv6Srv::processLocalizedQuery6AndSendResponse(Pkt6Ptr query,
}
}

void
Dhcpv6Srv::processLocalizedQuery6AndSendResponse(Pkt6Ptr query) {
// Initialize context.
AllocEngine::ClientContext6 ctx;
initContext0(query, ctx);

// Subnet is cached in the callout context associated to the query.
try {
CalloutHandlePtr callout_handle = getCalloutHandle(query);
callout_handle->getContext("subnet6", ctx.subnet_);
} catch (const Exception&) {
// No subnet, leave it to null...
}

processLocalizedQuery6AndSendResponse(query, ctx);
}

Pkt6Ptr
Dhcpv6Srv::processLocalizedQuery6(AllocEngine::ClientContext6& ctx) {
Pkt6Ptr query = ctx.query_;
Expand Down Expand Up @@ -1991,8 +2008,32 @@ Dhcpv6Srv::selectSubnet(const Pkt6Ptr& question, bool& drop) {
CfgMgr::instance().getCurrentCfg()->
getCfgSubnets6()->getAll());

// We proactively park the packet.
HooksManager::park("subnet6_select", question,
[this, question] () {
processLocalizedQuery6AndSendResponse(question);
});

// Call user (and server-side) callouts
HooksManager::callCallouts(Hooks.hook_index_subnet6_select_, *callout_handle);
try {
HooksManager::callCallouts(Hooks.hook_index_subnet6_select_,
*callout_handle);
} catch (...) {
// Make sure we don't orphan a parked packet.
HooksManager::drop("subnet6_select", question);
throw;
}

// Callouts parked the packet. Same as drop but callouts will resume
// processing or drop the packet later.
if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_PARK) {
LOG_DEBUG(hooks_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_SUBNET6_SELECT_PARK)
.arg(question->getLabel());
drop = true;
return (Subnet6Ptr());
} else {
HooksManager::drop("subnet6_select", question);
}

// Callouts decided to skip this step. This means that no
// subnet will be selected. Packet processing will continue,
Expand All @@ -2013,15 +2054,6 @@ Dhcpv6Srv::selectSubnet(const Pkt6Ptr& question, bool& drop) {
return (Subnet6Ptr());
}

// Callouts parked the packet. Same as drop but callouts will resume
// processing or drop the packet later.
if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_PARK) {
LOG_DEBUG(hooks_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_SUBNET6_SELECT_PARK)
.arg(question->getLabel());
drop = true;
return (Subnet6Ptr());
}

// Use whatever subnet was specified by the callout
callout_handle->getArgument("subnet6", subnet);
}
Expand Down
8 changes: 8 additions & 0 deletions src/bin/dhcp6/dhcp6_srv.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ class Dhcpv6Srv : public process::Daemon {
void processLocalizedQuery6AndSendResponse(Pkt6Ptr query,
AllocEngine::ClientContext6& ctx);

/// @brief Process a localized incoming DHCPv6 query.
///
/// A variant of the precedent method used to resume processing
/// for packets parked in the subnet6_select callout.
///
/// @param query A pointer to the unparked packet.
void processLocalizedQuery6AndSendResponse(Pkt6Ptr query);

/// @brief Instructs the server to shut down.
void shutdown() override;

Expand Down

0 comments on commit 96fcd7b

Please sign in to comment.