Skip to content

Commit 89a34ee

Browse files
committed
[#2022] Finished RADIUS v6 server code
1 parent 3b9cecf commit 89a34ee

8 files changed

+224
-171
lines changed

src/bin/dhcp6/dhcp6_srv.cc

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

494501
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+
}
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());

src/bin/dhcp6/dhcp6_srv.h

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,28 +175,47 @@ class Dhcpv6Srv : public process::Daemon {
175175

176176
/// @brief Process a single incoming DHCPv6 packet.
177177
///
178-
/// It verifies correctness of the passed packet, calls per-type processXXX
179-
/// methods, generates appropriate answer.
178+
/// It verifies correctness of the passed packet, localizes it,
179+
/// calls per-type processXXX methods, generates appropriate answer.
180180
///
181181
/// @param query A pointer to the packet to be processed.
182182
/// @return A pointer to the response.
183183
Pkt6Ptr processPacket(Pkt6Ptr query);
184184

185185
/// @brief Process a single incoming DHCPv6 query.
186186
///
187-
/// It calls per-type processXXX methods, generates appropriate answer.
187+
/// It localizes the query, calls per-type processXXX methods,
188+
/// generates appropriate answer.
188189
///
189190
/// @param query A pointer to the packet to be processed.
190191
/// @return A pointer to the response.
191192
Pkt6Ptr processDhcp6Query(Pkt6Ptr query);
192193

193194
/// @brief Process a single incoming DHCPv6 query.
194195
///
196+
/// It localizes the query, calls per-type processXXX methods,
197+
/// generates appropriate answer, sends the answer to the client.
198+
///
199+
/// @param query A pointer to the packet to be processed.
200+
void processDhcp6QueryAndSendResponse(Pkt6Ptr query);
201+
202+
/// @brief Process a localized incoming DHCPv6 query.
203+
///
204+
/// It calls per-type processXXX methods, generates appropriate answer.
205+
///
206+
/// @param ctx Pointer to The client context.
207+
/// @return A pointer to the response.
208+
Pkt6Ptr processLocalizedQuery6(AllocEngine::ClientContext6& ctx);
209+
210+
/// @brief Process a localized incoming DHCPv6 query.
211+
///
195212
/// It calls per-type processXXX methods, generates appropriate answer,
196213
/// sends the answer to the client.
197214
///
198215
/// @param query A pointer to the packet to be processed.
199-
void processDhcp6QueryAndSendResponse(Pkt6Ptr query);
216+
/// @param ctx Pointer to The client context.
217+
void processLocalizedQuery6AndSendResponse(Pkt6Ptr query,
218+
AllocEngine::ClientContext6& ctx);
200219

201220
/// @brief Instructs the server to shut down.
202221
void shutdown() override;
@@ -254,6 +273,13 @@ class Dhcpv6Srv : public process::Daemon {
254273
/// Called during reconfigure and shutdown.
255274
void discardPackets();
256275

276+
/// @brief Initialize client context (first part).
277+
///
278+
/// @param query The query message.
279+
/// @param ctx Reference to client context.
280+
void initContext0(const Pkt6Ptr& query,
281+
AllocEngine::ClientContext6& ctx);
282+
257283
/// @brief Initialize client context and perform early global
258284
/// reservations lookup.
259285
///
@@ -917,14 +943,9 @@ class Dhcpv6Srv : public process::Daemon {
917943
/// the Rapid Commit option was included and that the server respects
918944
/// it.
919945
///
920-
/// @param subnet Selected subnet.
921-
/// @param pkt pointer to a packet for which context will be created.
922946
/// @param [out] ctx reference to context object to be initialized.
923947
/// @param [out] drop if it is true the packet will be dropped.
924-
void initContext(const Subnet6Ptr& subnet,
925-
const Pkt6Ptr& pkt,
926-
AllocEngine::ClientContext6& ctx,
927-
bool& drop);
948+
void initContext(AllocEngine::ClientContext6& ctx, bool& drop);
928949

929950
/// @brief this is a prefix added to the content of vendor-class option
930951
///

0 commit comments

Comments
 (0)