Skip to content

Commit 3b9cecf

Browse files
committed
[#2022] Reorganized v6 code
1 parent 6626e68 commit 3b9cecf

8 files changed

+298
-121
lines changed

src/bin/dhcp6/dhcp6_srv.cc

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -492,20 +492,16 @@ Dhcpv6Srv::earlyGHRLookup(const Pkt6Ptr& query,
492492
}
493493

494494
void
495-
Dhcpv6Srv::initContext(const Pkt6Ptr& pkt,
495+
Dhcpv6Srv::initContext(const Subnet6Ptr& subnet,
496+
const Pkt6Ptr& pkt,
496497
AllocEngine::ClientContext6& ctx,
497498
bool& drop) {
498-
ctx.subnet_ = selectSubnet(pkt, drop);
499+
ctx.subnet_ = subnet;
499500
ctx.fwd_dns_update_ = false;
500501
ctx.rev_dns_update_ = false;
501502
ctx.hostname_ = "";
502503
ctx.callout_handle_ = getCalloutHandle(pkt);
503504

504-
if (drop) {
505-
// Caller will immediately drop the packet so simply return now.
506-
return;
507-
}
508-
509505
// Collect host identifiers if host reservations enabled. The identifiers
510506
// are stored in order of preference. The server will use them in that
511507
// order to search for host reservations.
@@ -703,7 +699,7 @@ Dhcpv6Srv::runOne() {
703699
}
704700

705701
void
706-
Dhcpv6Srv::processPacketAndSendResponseNoThrow(Pkt6Ptr& query) {
702+
Dhcpv6Srv::processPacketAndSendResponseNoThrow(Pkt6Ptr query) {
707703
try {
708704
processPacketAndSendResponse(query);
709705
} catch (const std::exception& e) {
@@ -715,9 +711,8 @@ Dhcpv6Srv::processPacketAndSendResponseNoThrow(Pkt6Ptr& query) {
715711
}
716712

717713
void
718-
Dhcpv6Srv::processPacketAndSendResponse(Pkt6Ptr& query) {
719-
Pkt6Ptr rsp;
720-
processPacket(query, rsp);
714+
Dhcpv6Srv::processPacketAndSendResponse(Pkt6Ptr query) {
715+
Pkt6Ptr rsp = processPacket(query);
721716
if (!rsp) {
722717
return;
723718
}
@@ -726,8 +721,8 @@ Dhcpv6Srv::processPacketAndSendResponse(Pkt6Ptr& query) {
726721
processPacketBufferSend(callout_handle, rsp);
727722
}
728723

729-
void
730-
Dhcpv6Srv::processPacket(Pkt6Ptr& query, Pkt6Ptr& rsp) {
724+
Pkt6Ptr
725+
Dhcpv6Srv::processPacket(Pkt6Ptr query) {
731726
// All packets belong to ALL.
732727
query->addClass("ALL");
733728

@@ -777,10 +772,14 @@ Dhcpv6Srv::processPacket(Pkt6Ptr& query, Pkt6Ptr& rsp) {
777772
// Increase the statistic of dropped packets.
778773
StatsMgr::instance().addValue("pkt6-receive-drop",
779774
static_cast<int64_t>(1));
780-
return;
775+
return (Pkt6Ptr());
781776
}
782777

783778
callout_handle->getArgument("query6", query);
779+
if (!query) {
780+
// Please use the status instead of resetting query!
781+
return (Pkt6Ptr());
782+
}
784783
}
785784

786785
// Unpack the packet information unless the buffer6_receive callouts
@@ -812,7 +811,7 @@ Dhcpv6Srv::processPacket(Pkt6Ptr& query, Pkt6Ptr& rsp) {
812811
static_cast<int64_t>(1));
813812
StatsMgr::instance().addValue("pkt6-receive-drop",
814813
static_cast<int64_t>(1));
815-
return;
814+
return (Pkt6Ptr());
816815
}
817816
}
818817

@@ -829,7 +828,7 @@ Dhcpv6Srv::processPacket(Pkt6Ptr& query, Pkt6Ptr& rsp) {
829828

830829
// Increase the statistic of dropped packets.
831830
StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
832-
return;
831+
return (Pkt6Ptr());
833832
}
834833

835834
// Check if the received query has been sent to unicast or multicast.
@@ -839,7 +838,7 @@ Dhcpv6Srv::processPacket(Pkt6Ptr& query, Pkt6Ptr& rsp) {
839838

840839
// Increase the statistic of dropped packets.
841840
StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
842-
return;
841+
return (Pkt6Ptr());
843842
}
844843

845844
// Assign this packet to a class, if possible
@@ -887,15 +886,19 @@ Dhcpv6Srv::processPacket(Pkt6Ptr& query, Pkt6Ptr& rsp) {
887886
// Increase the statistic of dropped packets.
888887
StatsMgr::instance().addValue("pkt6-receive-drop",
889888
static_cast<int64_t>(1));
890-
return;
889+
return (Pkt6Ptr());
891890
}
892891

893892
callout_handle->getArgument("query6", query);
893+
if (!query) {
894+
// Please use the status instead of resetting query!
895+
return (Pkt6Ptr());
896+
}
894897
}
895898

896899
// Reject the message if it doesn't pass the sanity check.
897900
if (!sanityCheck(query)) {
898-
return;
901+
return (Pkt6Ptr());
899902
}
900903

901904
// Check the DROP special class.
@@ -905,16 +908,16 @@ Dhcpv6Srv::processPacket(Pkt6Ptr& query, Pkt6Ptr& rsp) {
905908
.arg(query->toText());
906909
StatsMgr::instance().addValue("pkt6-receive-drop",
907910
static_cast<int64_t>(1));
908-
return;
911+
return (Pkt6Ptr());
909912
}
910913

911-
processDhcp6Query(query, rsp);
914+
return (processDhcp6Query(query));
912915
}
913916

914917
void
915-
Dhcpv6Srv::processDhcp6QueryAndSendResponse(Pkt6Ptr& query, Pkt6Ptr& rsp) {
918+
Dhcpv6Srv::processDhcp6QueryAndSendResponse(Pkt6Ptr query) {
916919
try {
917-
processDhcp6Query(query, rsp);
920+
Pkt6Ptr rsp = processDhcp6Query(query);
918921
if (!rsp) {
919922
return;
920923
}
@@ -929,8 +932,8 @@ Dhcpv6Srv::processDhcp6QueryAndSendResponse(Pkt6Ptr& query, Pkt6Ptr& rsp) {
929932
}
930933
}
931934

932-
void
933-
Dhcpv6Srv::processDhcp6Query(Pkt6Ptr& query, Pkt6Ptr& rsp) {
935+
Pkt6Ptr
936+
Dhcpv6Srv::processDhcp6Query(Pkt6Ptr query) {
934937
// Create a client race avoidance RAII handler.
935938
ClientHandler client_handler;
936939

@@ -944,36 +947,42 @@ Dhcpv6Srv::processDhcp6Query(Pkt6Ptr& query, Pkt6Ptr& rsp) {
944947
(query->getType() == DHCPV6_DECLINE))) {
945948
ContinuationPtr cont =
946949
makeContinuation(std::bind(&Dhcpv6Srv::processDhcp6QueryAndSendResponse,
947-
this, query, rsp));
950+
this, query));
948951
if (!client_handler.tryLock(query, cont)) {
949-
return;
952+
return (Pkt6Ptr());
950953
}
951954
}
952955

953956
// Let's create a simplified client context here.
954957
AllocEngine::ClientContext6 ctx;
955958
if (!earlyGHRLookup(query, ctx)) {
956-
return;
959+
return (Pkt6Ptr());
957960
}
958961

959962
if (query->getType() == DHCPV6_DHCPV4_QUERY) {
960963
// This call never throws. Should this change, this section must be
961964
// enclosed in try-catch.
962965
processDhcp4Query(query);
963-
return;
966+
return (Pkt6Ptr());
964967
}
965968

966969
// Complete the client context initialization.
967970
bool drop = false;
968-
initContext(query, ctx, drop);
969-
970-
// Stop here if initContext decided to drop the packet.
971+
Subnet6Ptr subnet = selectSubnet(query, drop);
971972
if (drop) {
972-
return;
973+
// Caller will immediately drop the packet so simply return now.
974+
return (Pkt6Ptr());
973975
}
974976

975977
// Park point here.
976978

979+
initContext(subnet, query, ctx, drop);
980+
// Stop here if initContext decided to drop the packet.
981+
if (drop) {
982+
return (Pkt6Ptr());
983+
}
984+
985+
Pkt6Ptr rsp;
977986
try {
978987
switch (query->getType()) {
979988
case DHCPV6_SOLICIT:
@@ -1009,7 +1018,7 @@ Dhcpv6Srv::processDhcp6Query(Pkt6Ptr& query, Pkt6Ptr& rsp) {
10091018
break;
10101019

10111020
default:
1012-
return;
1021+
return (rsp);
10131022
}
10141023

10151024
} catch (const std::exception& e) {
@@ -1031,7 +1040,7 @@ Dhcpv6Srv::processDhcp6Query(Pkt6Ptr& query, Pkt6Ptr& rsp) {
10311040
}
10321041

10331042
if (!rsp) {
1034-
return;
1043+
return (rsp);
10351044
}
10361045

10371046
// Process relay-supplied options. It is important to call this very
@@ -1162,7 +1171,7 @@ Dhcpv6Srv::processDhcp6Query(Pkt6Ptr& query, Pkt6Ptr& rsp) {
11621171
isc::stats::StatsMgr::instance().addValue("pkt6-receive-drop",
11631172
static_cast<int64_t>(1));
11641173
rsp.reset();
1165-
return;
1174+
return (rsp);
11661175
}
11671176
}
11681177

@@ -1219,11 +1228,13 @@ Dhcpv6Srv::processDhcp6Query(Pkt6Ptr& query, Pkt6Ptr& rsp) {
12191228
if (rsp) {
12201229
processPacketPktSend(callout_handle, query, rsp);
12211230
}
1231+
1232+
return (rsp);
12221233
}
12231234

12241235
void
12251236
Dhcpv6Srv::sendResponseNoThrow(hooks::CalloutHandlePtr& callout_handle,
1226-
Pkt6Ptr& query, Pkt6Ptr& rsp) {
1237+
Pkt6Ptr query, Pkt6Ptr& rsp) {
12271238
try {
12281239
processPacketPktSend(callout_handle, query, rsp);
12291240
processPacketBufferSend(callout_handle, rsp);

src/bin/dhcp6/dhcp6_srv.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2011-2022 Internet Systems Consortium, Inc. ("ISC")
1+
// Copyright (C) 2011-2023 Internet Systems Consortium, Inc. ("ISC")
22
//
33
// This Source Code Form is subject to the terms of the Mozilla Public
44
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -155,49 +155,48 @@ class Dhcpv6Srv : public process::Daemon {
155155
/// methods, generates appropriate answer, sends the answer to the client.
156156
///
157157
/// @param query A pointer to the packet to be processed.
158-
void processPacketAndSendResponse(Pkt6Ptr& query);
158+
void processPacketAndSendResponse(Pkt6Ptr query);
159159

160160
/// @brief Process a single incoming DHCPv6 packet and sends the response.
161161
///
162162
/// It verifies correctness of the passed packet, calls per-type processXXX
163163
/// methods, generates appropriate answer, sends the answer to the client.
164164
///
165165
/// @param query A pointer to the packet to be processed.
166-
void processPacketAndSendResponseNoThrow(Pkt6Ptr& query);
166+
void processPacketAndSendResponseNoThrow(Pkt6Ptr query);
167167

168168
/// @brief Process an unparked DHCPv6 packet and sends the response.
169169
///
170170
/// @param callout_handle pointer to the callout handle.
171171
/// @param query A pointer to the packet to be processed.
172172
/// @param rsp A pointer to the response.
173173
void sendResponseNoThrow(hooks::CalloutHandlePtr& callout_handle,
174-
Pkt6Ptr& query, Pkt6Ptr& rsp);
174+
Pkt6Ptr query, Pkt6Ptr& rsp);
175175

176176
/// @brief Process a single incoming DHCPv6 packet.
177177
///
178178
/// It verifies correctness of the passed packet, calls per-type processXXX
179179
/// methods, generates appropriate answer.
180180
///
181181
/// @param query A pointer to the packet to be processed.
182-
/// @param rsp A pointer to the response.
183-
void processPacket(Pkt6Ptr& query, Pkt6Ptr& rsp);
182+
/// @return A pointer to the response.
183+
Pkt6Ptr processPacket(Pkt6Ptr query);
184184

185185
/// @brief Process a single incoming DHCPv6 query.
186186
///
187187
/// It calls per-type processXXX methods, generates appropriate answer.
188188
///
189189
/// @param query A pointer to the packet to be processed.
190-
/// @param rsp A pointer to the response.
191-
void processDhcp6Query(Pkt6Ptr& query, Pkt6Ptr& rsp);
190+
/// @return A pointer to the response.
191+
Pkt6Ptr processDhcp6Query(Pkt6Ptr query);
192192

193193
/// @brief Process a single incoming DHCPv6 query.
194194
///
195195
/// It calls per-type processXXX methods, generates appropriate answer,
196196
/// sends the answer to the client.
197197
///
198198
/// @param query A pointer to the packet to be processed.
199-
/// @param rsp A pointer to the response.
200-
void processDhcp6QueryAndSendResponse(Pkt6Ptr& query, Pkt6Ptr& rsp);
199+
void processDhcp6QueryAndSendResponse(Pkt6Ptr query);
201200

202201
/// @brief Instructs the server to shut down.
203202
void shutdown() override;
@@ -905,7 +904,6 @@ class Dhcpv6Srv : public process::Daemon {
905904
/// @brief Initializes client context for specified packet
906905
///
907906
/// This method:
908-
/// - Performs the subnet selection and stores the result in context
909907
/// - Extracts the duid from the packet and saves it to the context
910908
/// - Extracts the hardware address from the packet and saves it to
911909
/// the context
@@ -919,10 +917,12 @@ class Dhcpv6Srv : public process::Daemon {
919917
/// the Rapid Commit option was included and that the server respects
920918
/// it.
921919
///
920+
/// @param subnet Selected subnet.
922921
/// @param pkt pointer to a packet for which context will be created.
923922
/// @param [out] ctx reference to context object to be initialized.
924923
/// @param [out] drop if it is true the packet will be dropped.
925-
void initContext(const Pkt6Ptr& pkt,
924+
void initContext(const Subnet6Ptr& subnet,
925+
const Pkt6Ptr& pkt,
926926
AllocEngine::ClientContext6& ctx,
927927
bool& drop);
928928

0 commit comments

Comments
 (0)