]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2022] Checkpoint: added methods
authorFrancis Dupont <fdupont@isc.org>
Wed, 21 Feb 2024 16:13:55 +0000 (17:13 +0100)
committerFrancis Dupont <fdupont@isc.org>
Fri, 23 Feb 2024 09:54:45 +0000 (10:54 +0100)
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp4/dhcp4_srv.h

index 3087cbfdccbf18d617be397a711be97e6d6dfc3d..30c26bfb6b644bf37db01a28f2dbff73688d41af 100644 (file)
@@ -1372,7 +1372,6 @@ Dhcpv4Srv::processDhcp4Query(Pkt4Ptr query, bool allow_packet_park) {
         return (Pkt4Ptr());
     }
 
-    Pkt4Ptr rsp;
     try {
         sanityCheck(query);
         if ((query->getType() == DHCPDISCOVER) ||
@@ -1385,6 +1384,56 @@ Dhcpv4Srv::processDhcp4Query(Pkt4Ptr query, bool allow_packet_park) {
                 return (Pkt4Ptr());
             }
         }
+    } catch (const std::exception& e) {
+
+        // Catch-all exception (we used to call only isc::Exception, but
+        // std::exception could potentially be raised and if we don't catch
+        // it here, it would be caught in main() and the process would
+        // terminate).  Just log the problem and ignore the packet.
+        // (The problem is logged as a debug message because debug is
+        // disabled by default - it prevents a DDOS attack based on the
+        // sending of problem packets.)
+        LOG_DEBUG(bad_packet4_logger, DBGLVL_PKT_HANDLING, DHCP4_PACKET_DROP_0007)
+            .arg(query->getLabel())
+            .arg(e.what());
+
+        // Increase the statistic of dropped packets.
+        isc::stats::StatsMgr::instance().addValue("pkt4-receive-drop",
+                                                  static_cast<int64_t>(1));
+    }
+
+    return (processLocalizedQuery4(ctx, allow_packet_park));
+}
+
+void
+Dhcpv4Srv::processLocalizedQuery4AndSendResponse(Pkt4Ptr query,
+                                                 AllocEngine::ClientContext4Ptr& ctx) {
+    try {
+        Pkt4Ptr rsp = processLocalizedQuery4(ctx, true);
+        if (!rsp) {
+            return;
+        }
+
+        CalloutHandlePtr callout_handle = getCalloutHandle(query);
+
+        processPacketBufferSend(callout_handle, rsp);
+    } catch (const std::exception& e) {
+        LOG_ERROR(packet4_logger, DHCP4_PACKET_PROCESS_STD_EXCEPTION)
+            .arg(e.what());
+    } catch (...) {
+        LOG_ERROR(packet4_logger, DHCP4_PACKET_PROCESS_EXCEPTION);
+    }
+}
+
+Pkt4Ptr
+Dhcpv4Srv::processLocalizedQuery4(AllocEngine::ClientContext4Ptr& ctx,
+                                  bool allow_packet_park) {
+    if (!ctx) {
+        isc_throw(Unexpected, "null context");
+    }
+    Pkt4Ptr query = ctx->query_;
+    Pkt4Ptr rsp;
+    try {
         switch (query->getType()) {
         case DHCPDISCOVER:
             rsp = processDiscover(query, ctx);
index c7da359fdf711a269a78d0a587e35bbf9a9301e2..a38c1528664aa7f1a3c662fd77161256b2eb42a0 100644 (file)
@@ -375,7 +375,8 @@ public:
 
     /// @brief Process a single incoming DHCPv4 query.
     ///
-    /// It calls per-type processXXX methods, generates appropriate answer.
+    /// It localizes the query, calls per-type processXXX methods,
+    /// generates appropriate answer.
     ///
     /// @param query A pointer to the packet to be processed.
     /// @param allow_packet_park Indicates if parking a packet is allowed.
@@ -384,14 +385,35 @@ public:
 
     /// @brief Process a single incoming DHCPv4 query.
     ///
-    /// It calls per-type processXXX methods, generates appropriate answer,
-    /// sends the answer to the client.
+    /// It localizes the query, calls per-type processXXX methods,
+    /// generates appropriate answer, sends the answer to the client.
     ///
     /// @param query A pointer to the packet to be processed.
     /// @param allow_packet_park Indicates if parking a packet is allowed.
     void processDhcp4QueryAndSendResponse(Pkt4Ptr query,
                                           bool allow_packet_park);
 
+    /// @brief Process a localized incoming DHCPv4 query.
+    ///
+    /// It calls per-type processXXX methods, generates appropriate answer.
+    ///
+    /// @param ctx Pointer to The client context.
+    /// @param allow_packet_park Indicates if parking a packet is allowed.
+    /// @return A pointer to the response.
+    Pkt4Ptr processLocalizedQuery4(AllocEngine::ClientContext4Ptr& ctx,
+                                   bool allow_packet_park);
+
+    /// @brief Process a localized incoming DHCPv4 query.
+    ///
+    /// A variant of the precedent method used to resume processing
+    /// for packets parked in the subnet4_select callout.
+    ///
+    /// @param query A pointer to the unparked packet.
+    /// @param ctx Pointer to The client context.
+    /// @return A pointer to the response.
+    void processLocalizedQuery4AndSendResponse(Pkt4Ptr query,
+                                               AllocEngine::ClientContext4Ptr& ctx);
+
     /// @brief Instructs the server to shut down.
     void shutdown() override;