IfaceMgr::instance().send(packet);
}
-bool
-Dhcpv4Srv::earlyGHRLookup(const Pkt4Ptr& query,
- AllocEngine::ClientContext4Ptr ctx) {
+void
+Dhcpv4Srv::initContext0(const Pkt4Ptr& query,
+ AllocEngine::ClientContext4Ptr ctx) {
// Pointer to client's query.
ctx->query_ = query;
// Hardware address.
ctx->hwaddr_ = query->getHWAddr();
+}
+
+bool
+Dhcpv4Srv::earlyGHRLookup(const Pkt4Ptr& query,
+ AllocEngine::ClientContext4Ptr ctx) {
+
+ // First part of context initialization.
+ initContext0(query, ctx);
// Get the early-global-reservations-lookup flag value.
data::ConstElementPtr egrl = CfgMgr::instance().getCurrentCfg()->
}
void
-Dhcpv4Srv::processPacketAndSendResponseNoThrow(Pkt4Ptr& query) {
+Dhcpv4Srv::processPacketAndSendResponseNoThrow(Pkt4Ptr query) {
try {
processPacketAndSendResponse(query);
} catch (const std::exception& e) {
}
void
-Dhcpv4Srv::processPacketAndSendResponse(Pkt4Ptr& query) {
- Pkt4Ptr rsp;
- processPacket(query, rsp);
+Dhcpv4Srv::processPacketAndSendResponse(Pkt4Ptr query) {
+ Pkt4Ptr rsp = processPacket(query);
if (!rsp) {
return;
}
processPacketBufferSend(callout_handle, rsp);
}
-void
-Dhcpv4Srv::processPacket(Pkt4Ptr& query, Pkt4Ptr& rsp, bool allow_packet_park) {
+Pkt4Ptr
+Dhcpv4Srv::processPacket(Pkt4Ptr query, bool allow_packet_park) {
query->addPktEvent("process_started");
// All packets belong to ALL.
.arg(query->getRemoteAddr().toText())
.arg(query->getLocalAddr().toText())
.arg(query->getIface());
- return;
+ return (Pkt4Ptr());;
}
// Callouts decided to skip the next processing step. The next
static_cast<int64_t>(1));
isc::stats::StatsMgr::instance().addValue("pkt4-receive-drop",
static_cast<int64_t>(1));
- return;
+ return (Pkt4Ptr());
}
}
// Increase the statistic of dropped packets.
isc::stats::StatsMgr::instance().addValue("pkt4-receive-drop",
static_cast<int64_t>(1));
- return;
+ return (Pkt4Ptr());
}
// We have sanity checked (in accept() that the Message Type option
LOG_DEBUG(hooks_logger, DBG_DHCP4_HOOKS,
DHCP4_HOOK_PACKET_RCVD_SKIP)
.arg(query->getLabel());
- return;
+ return (Pkt4Ptr());
}
callout_handle->getArgument("query4", query);
.arg(query->toText());
isc::stats::StatsMgr::instance().addValue("pkt4-receive-drop",
static_cast<int64_t>(1));
- return;
+ return (Pkt4Ptr());
}
- processDhcp4Query(query, rsp, allow_packet_park);
+ return (processDhcp4Query(query, allow_packet_park));
}
void
-Dhcpv4Srv::processDhcp4QueryAndSendResponse(Pkt4Ptr& query, Pkt4Ptr& rsp,
+Dhcpv4Srv::processDhcp4QueryAndSendResponse(Pkt4Ptr query,
bool allow_packet_park) {
try {
- processDhcp4Query(query, rsp, allow_packet_park);
+ Pkt4Ptr rsp = processDhcp4Query(query, allow_packet_park);
if (!rsp) {
return;
}
}
}
-void
-Dhcpv4Srv::processDhcp4Query(Pkt4Ptr& query, Pkt4Ptr& rsp,
- bool allow_packet_park) {
+Pkt4Ptr
+Dhcpv4Srv::processDhcp4Query(Pkt4Ptr query, bool allow_packet_park) {
// Create a client race avoidance RAII handler.
ClientHandler client_handler;
(query->getType() == DHCPDECLINE))) {
ContinuationPtr cont =
makeContinuation(std::bind(&Dhcpv4Srv::processDhcp4QueryAndSendResponse,
- this, query, rsp, allow_packet_park));
+ this, query, allow_packet_park));
if (!client_handler.tryLock(query, cont)) {
- return;
+ return (Pkt4Ptr());
}
}
AllocEngine::ClientContext4Ptr ctx(new AllocEngine::ClientContext4());
if (!earlyGHRLookup(query, ctx)) {
- return;
+ return (Pkt4Ptr());
}
+ Pkt4Ptr rsp;
try {
+ sanityCheck(query);
+ if ((query->getType() == DHCPDISCOVER) ||
+ (query->getType() == DHCPREQUEST) ||
+ (query->getType() == DHCPINFORM)) {
+ bool drop = false;
+ ctx->subnet_ = selectSubnet(query, drop);
+ // Stop here if selectSubnet decided to drop the packet
+ if (drop) {
+ return (Pkt4Ptr());
+ }
+ }
switch (query->getType()) {
case DHCPDISCOVER:
rsp = processDiscover(query, ctx);
.arg(query->getLabel());
isc::stats::StatsMgr::instance().addValue("pkt4-receive-drop",
static_cast<int64_t>(1));
- rsp.reset();
- return;
+ return (Pkt4Ptr());
}
}
Subnet4Ptr subnet = (ctx ? ctx->subnet_ : Subnet4Ptr());
processPacketPktSend(callout_handle, query, rsp, subnet);
}
+ return (rsp);
}
void
Pkt4Ptr
Dhcpv4Srv::processDiscover(Pkt4Ptr& discover, AllocEngine::ClientContext4Ptr& context) {
- // server-id is forbidden.
- sanityCheck(discover, FORBIDDEN);
-
bool drop = false;
- Subnet4Ptr subnet = selectSubnet(discover, drop);
-
- // Stop here if selectSubnet decided to drop the packet
- if (drop) {
- return (Pkt4Ptr());
- }
-
- Dhcpv4Exchange ex(alloc_engine_, discover, context, subnet, drop);
+ Dhcpv4Exchange ex(alloc_engine_, discover, context, context->subnet_, drop);
// Stop here if Dhcpv4Exchange constructor decided to drop the packet
if (drop) {
Pkt4Ptr
Dhcpv4Srv::processRequest(Pkt4Ptr& request, AllocEngine::ClientContext4Ptr& context) {
- // Since we cannot distinguish between client states
- // we'll make server-id is optional for REQUESTs.
- sanityCheck(request, OPTIONAL);
-
bool drop = false;
- Subnet4Ptr subnet = selectSubnet(request, drop);
-
- // Stop here if selectSubnet decided to drop the packet
- if (drop) {
- return (Pkt4Ptr());
- }
-
- Dhcpv4Exchange ex(alloc_engine_, request, context, subnet, drop);
+ Dhcpv4Exchange ex(alloc_engine_, request, context, context->subnet_, drop);
// Stop here if Dhcpv4Exchange constructor decided to drop the packet
if (drop) {
void
Dhcpv4Srv::processRelease(Pkt4Ptr& release, AllocEngine::ClientContext4Ptr& context) {
- // Server-id is mandatory in DHCPRELEASE (see table 5, RFC2131)
- // but ISC DHCP does not enforce this, so we'll follow suit.
- sanityCheck(release, OPTIONAL);
-
// Try to find client-id. Note that for the DHCPRELEASE we don't check if the
// match-client-id configuration parameter is disabled because this parameter
// is configured for subnets and we don't select subnet for the DHCPRELEASE.
void
Dhcpv4Srv::processDecline(Pkt4Ptr& decline, AllocEngine::ClientContext4Ptr& context) {
- // Server-id is mandatory in DHCPDECLINE (see table 5, RFC2131)
- // but ISC DHCP does not enforce this, so we'll follow suit.
- sanityCheck(decline, OPTIONAL);
-
// Client is supposed to specify the address being declined in
// Requested IP address option, but must not set its ciaddr.
// (again, see table 5 in RFC2131).
Pkt4Ptr
Dhcpv4Srv::processInform(Pkt4Ptr& inform, AllocEngine::ClientContext4Ptr& context) {
- // server-id is supposed to be forbidden (as is requested address)
- // but ISC DHCP does not enforce either. So neither will we.
- sanityCheck(inform, OPTIONAL);
-
bool drop = false;
- Subnet4Ptr subnet = selectSubnet(inform, drop);
-
- // Stop here if selectSubnet decided to drop the packet
- if (drop) {
- return (Pkt4Ptr());
- }
-
- Dhcpv4Exchange ex(alloc_engine_, inform, context, subnet, drop);
+ Dhcpv4Exchange ex(alloc_engine_, inform, context, context->subnet_, drop);
// Stop here if Dhcpv4Exchange constructor decided to drop the packet
if (drop) {
return (opt_server_id && (opt_server_id->readAddress() == server_id));
}
+void
+Dhcpv4Srv::sanityCheck(const Pkt4Ptr& query) {
+ switch (query->getType()) {
+ case DHCPDISCOVER:
+ // server-id is forbidden.
+ sanityCheck(query, FORBIDDEN);
+ break;
+ case DHCPREQUEST:
+ // Since we cannot distinguish between client states
+ // we'll make server-id is optional for REQUESTs.
+ sanityCheck(query, OPTIONAL);
+ break;
+ case DHCPRELEASE:
+ // Server-id is mandatory in DHCPRELEASE (see table 5, RFC2131)
+ // but ISC DHCP does not enforce this, so we'll follow suit.
+ sanityCheck(query, OPTIONAL);
+ break;
+ case DHCPDECLINE:
+ // Server-id is mandatory in DHCPDECLINE (see table 5, RFC2131)
+ // but ISC DHCP does not enforce this, so we'll follow suit.
+ sanityCheck(query, OPTIONAL);
+ break;
+ case DHCPINFORM:
+ // server-id is supposed to be forbidden (as is requested address)
+ // but ISC DHCP does not enforce either. So neither will we.
+ sanityCheck(query, OPTIONAL);
+ break;
+ }
+}
+
void
Dhcpv4Srv::sanityCheck(const Pkt4Ptr& query, RequirementLevel serverid) {
OptionPtr server_id = query->getOption(DHO_DHCP_SERVER_IDENTIFIER);
-// Copyright (C) 2011-2023 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2024 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
/// methods, generates appropriate answer, sends the answer to the client.
///
/// @param query A pointer to the packet to be processed.
- void processPacketAndSendResponse(Pkt4Ptr& query);
+ void processPacketAndSendResponse(Pkt4Ptr query);
/// @brief Process a single incoming DHCPv4 packet and sends the response.
///
/// methods, generates appropriate answer, sends the answer to the client.
///
/// @param query A pointer to the packet to be processed.
- void processPacketAndSendResponseNoThrow(Pkt4Ptr& query);
+ void processPacketAndSendResponseNoThrow(Pkt4Ptr query);
/// @brief Process an unparked DHCPv4 packet and sends the response.
///
/// methods, generates appropriate answer.
///
/// @param query A pointer to the packet to be processed.
- /// @param rsp A pointer to the response.
/// @param allow_packet_park Indicates if parking a packet is allowed.
- void processPacket(Pkt4Ptr& query, Pkt4Ptr& rsp,
- bool allow_packet_park = true);
+ /// @return A pointer to the response.
+ Pkt4Ptr processPacket(Pkt4Ptr query, bool allow_packet_park = true);
/// @brief Process a single incoming DHCPv4 query.
///
/// It calls per-type processXXX methods, generates appropriate answer.
///
/// @param query A pointer to the packet to be processed.
- /// @param rsp A pointer to the response.
/// @param allow_packet_park Indicates if parking a packet is allowed.
- void processDhcp4Query(Pkt4Ptr& query, Pkt4Ptr& rsp,
- bool allow_packet_park);
+ /// @return A pointer to the response.
+ Pkt4Ptr processDhcp4Query(Pkt4Ptr query, bool allow_packet_park);
/// @brief Process a single incoming DHCPv4 query.
///
/// sends the answer to the client.
///
/// @param query A pointer to the packet to be processed.
- /// @param rsp A pointer to the response.
/// @param allow_packet_park Indicates if parking a packet is allowed.
- void processDhcp4QueryAndSendResponse(Pkt4Ptr& query, Pkt4Ptr& rsp,
+ void processDhcp4QueryAndSendResponse(Pkt4Ptr query,
bool allow_packet_park);
/// @brief Instructs the server to shut down.
return (test_send_responses_to_source_);
}
+ /// @brief Initialize client context (first part).
+ ///
+ /// @param query The query message.
+ /// @param ctx Pointer to client context.
+ void initContext0(const Pkt4Ptr& query,
+ AllocEngine::ClientContext4Ptr ctx);
+
/// @brief Initialize client context and perform early global
/// reservations lookup.
///
bool acceptServerId(const Pkt4Ptr& pkt) const;
//@}
+ /// @brief Verifies if specified packet meets RFC requirements
+ ///
+ /// Checks if mandatory option is really there, that forbidden option
+ /// is not there, and that client-id or server-id appears only once.
+ /// Calls the second method with the requirement level from the
+ /// message type.
+ ///
+ /// @param query Pointer to the client's message.
+ /// @throw RFCViolation if any issues are detected
+ static void sanityCheck(const Pkt4Ptr& query);
+
/// @brief Verifies if specified packet meets RFC requirements
///
/// Checks if mandatory option is really there, that forbidden option
-// Copyright (C) 2013-2023 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2024 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Pkt4Ptr processDiscover(Pkt4Ptr& discover) {
AllocEngine::ClientContext4Ptr context(new AllocEngine::ClientContext4());
earlyGHRLookup(discover, context);
+ sanityCheck(discover);
+ bool drop = false;
+ context->subnet_ = selectSubnet(discover, drop);
+ if (drop) {
+ return (Pkt4Ptr ());
+ }
return (processDiscover(discover, context));
}
Pkt4Ptr processRequest(Pkt4Ptr& request) {
AllocEngine::ClientContext4Ptr context(new AllocEngine::ClientContext4());
earlyGHRLookup(request, context);
+ sanityCheck(request);
+ bool drop = false;
+ context->subnet_ = selectSubnet(request, drop);
+ if (drop) {
+ return (Pkt4Ptr ());
+ }
return (processRequest(request, context));
}
void processRelease(Pkt4Ptr& release) {
AllocEngine::ClientContext4Ptr context(new AllocEngine::ClientContext4());
earlyGHRLookup(release, context);
+ sanityCheck(release);
processRelease(release, context);
}
void processDecline(Pkt4Ptr& decline) {
AllocEngine::ClientContext4Ptr context(new AllocEngine::ClientContext4());
earlyGHRLookup(decline, context);
+ sanityCheck(decline);
processDecline(decline, context);
}
Pkt4Ptr processInform(Pkt4Ptr& inform) {
AllocEngine::ClientContext4Ptr context(new AllocEngine::ClientContext4());
earlyGHRLookup(inform, context);
+ sanityCheck(inform);
+ bool drop = false;
+ context->subnet_ = selectSubnet(inform, drop);
+ if (drop) {
+ return (Pkt4Ptr ());
+ }
return (processInform(inform, context));
}