Browse Source

[4108] extract packet processing of Dhcpv4Srv::run() into a new method.

the new one is named processPacket().  this is a trivial refactoring,
intentionally not making any other editorial cleanups (such as indentation
fixup).
JINMEI Tatuya 9 years ago
parent
commit
7e04df6e4b
2 changed files with 30 additions and 22 deletions
  1. 28 22
      src/bin/dhcp4/dhcp4_srv.cc
  2. 2 0
      src/bin/dhcp4/dhcp4_srv.h

+ 28 - 22
src/bin/dhcp4/dhcp4_srv.cc

@@ -417,7 +417,6 @@ Dhcpv4Srv::run() {
     while (!shutdown_) {
         // client's message and server's response
         Pkt4Ptr query;
-        Pkt4Ptr rsp;
 
         try {
 
@@ -484,6 +483,29 @@ Dhcpv4Srv::run() {
             continue;
         }
 
+        processPacket(query);
+
+        } catch (const std::exception& e) {
+            // General catch-all exception that are not caught by more specific
+            // catches. This one is for exceptions derived from std::exception.
+            LOG_ERROR(packet4_logger, DHCP4_PACKET_PROCESS_EXCEPTION)
+                .arg(e.what());
+        } catch (...) {
+            // General catch-all exception that are not caught by more specific
+            // catches. This one is for other exceptions, not derived from
+            // std::exception.
+            LOG_ERROR(packet4_logger, DHCP4_PACKET_PROCESS_EXCEPTION)
+                .arg("an unknown exception not derived from std::exception");
+        }
+    }
+
+    return (true);
+}
+
+void
+Dhcpv4Srv::processPacket(Pkt4Ptr& query) {
+        Pkt4Ptr rsp;
+
         // Log reception of the packet. We need to increase it early, as any
         // failures in unpacking will cause the packet to be dropped. We
         // will increase type specific packets further down the road.
@@ -557,7 +579,7 @@ Dhcpv4Srv::run() {
                                                           static_cast<int64_t>(1));
                 isc::stats::StatsMgr::instance().addValue("pkt4-receive-drop",
                                                           static_cast<int64_t>(1));
-                continue;
+                return;
             }
         }
 
@@ -575,7 +597,7 @@ Dhcpv4Srv::run() {
             // Increase the statistic of dropped packets.
             isc::stats::StatsMgr::instance().addValue("pkt4-receive-drop",
                                                       static_cast<int64_t>(1));
-            continue;
+            return;
         }
 
         // We have sanity checked (in accept() that the Message Type option
@@ -612,7 +634,7 @@ Dhcpv4Srv::run() {
             if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
                 LOG_DEBUG(hooks_logger, DBG_DHCP4_HOOKS, DHCP4_HOOK_PACKET_RCVD_SKIP)
                     .arg(query->getLabel());
-                continue;
+                return;
             }
 
             /// @todo: Add support for DROP status
@@ -671,7 +693,7 @@ Dhcpv4Srv::run() {
         }
 
         if (!rsp) {
-            continue;
+            return;
         }
 
 
@@ -747,7 +769,7 @@ Dhcpv4Srv::run() {
                     LOG_DEBUG(hooks_logger, DBG_DHCP4_HOOKS,
                               DHCP4_HOOK_BUFFER_SEND_SKIP)
                         .arg(rsp->getLabel());
-                    continue;
+                    return;
                 }
 
                 /// @todo: Add support for DROP status.
@@ -781,22 +803,6 @@ Dhcpv4Srv::run() {
                 .arg(rsp->getLabel())
                 .arg(e.what());
         }
-
-        } catch (const std::exception& e) {
-            // General catch-all exception that are not caught by more specific
-            // catches. This one is for exceptions derived from std::exception.
-            LOG_ERROR(packet4_logger, DHCP4_PACKET_PROCESS_EXCEPTION)
-                .arg(e.what());
-        } catch (...) {
-            // General catch-all exception that are not caught by more specific
-            // catches. This one is for other exceptions, not derived from
-            // std::exception.
-            LOG_ERROR(packet4_logger, DHCP4_PACKET_PROCESS_EXCEPTION)
-                .arg("an unknown exception not derived from std::exception");
-        }
-    }
-
-    return (true);
 }
 
 string

+ 2 - 0
src/bin/dhcp4/dhcp4_srv.h

@@ -216,6 +216,8 @@ public:
     ///         critical error.
     bool run();
 
+    void processPacket(Pkt4Ptr& packet);
+
     /// @brief Instructs the server to shut down.
     void shutdown();