Browse Source

[1545] Minor tidy-up of DHCP4 server logging code

Stephen Morris 12 years ago
parent
commit
71555cfc1c

+ 7 - 5
src/bin/dhcp4/ctrl_dhcp4_srv.cc

@@ -13,20 +13,21 @@
 // PERFORMANCE OF THIS SOFTWARE.
 // PERFORMANCE OF THIS SOFTWARE.
 
 
 #include <config.h>
 #include <config.h>
+
 #include <cassert>
 #include <cassert>
 #include <iostream>
 #include <iostream>
 
 
-#include <cc/session.h>
+#include <asiolink/asiolink.h>
 #include <cc/data.h>
 #include <cc/data.h>
-#include <exceptions/exceptions.h>
+#include <cc/session.h>
 #include <cc/session.h>
 #include <cc/session.h>
 #include <config/ccsession.h>
 #include <config/ccsession.h>
-#include <util/buffer.h>
-#include <dhcp4/spec_config.h>
 #include <dhcp4/ctrl_dhcp4_srv.h>
 #include <dhcp4/ctrl_dhcp4_srv.h>
 #include <dhcp4/dhcp4_log.h>
 #include <dhcp4/dhcp4_log.h>
+#include <dhcp4/spec_config.h>
 #include <dhcp/iface_mgr.h>
 #include <dhcp/iface_mgr.h>
-#include <asiolink/asiolink.h>
+#include <exceptions/exceptions.h>
+#include <util/buffer.h>
 
 
 using namespace isc::asiolink;
 using namespace isc::asiolink;
 using namespace isc::cc;
 using namespace isc::cc;
@@ -55,6 +56,7 @@ ConstElementPtr
 ControlledDhcpv4Srv::dhcp4CommandHandler(const string& command, ConstElementPtr args) {
 ControlledDhcpv4Srv::dhcp4CommandHandler(const string& command, ConstElementPtr args) {
     LOG_DEBUG(dhcp4_logger, DBG_DHCP4_COMMAND, DHCP4_COMMAND_RECEIVED)
     LOG_DEBUG(dhcp4_logger, DBG_DHCP4_COMMAND, DHCP4_COMMAND_RECEIVED)
               .arg(command).arg(args->str());
               .arg(command).arg(args->str());
+
     if (command == "shutdown") {
     if (command == "shutdown") {
         if (ControlledDhcpv4Srv::server_) {
         if (ControlledDhcpv4Srv::server_) {
             ControlledDhcpv4Srv::server_->shutdown();
             ControlledDhcpv4Srv::server_->shutdown();

+ 3 - 13
src/bin/dhcp4/dhcp4_messages.mes

@@ -44,19 +44,9 @@ the packet is invalid is include in the message.
 
 
 % DHCP4_PACKET_RECEIVED %1 (type %2) packet received on interface %3
 % DHCP4_PACKET_RECEIVED %1 (type %2) packet received on interface %3
 A debug message noting that the server has received the specified type of packet
 A debug message noting that the server has received the specified type of packet
-on the specified interface.
+on the specified interface.  Note that a packet marked as UNKNOWN may well be
-
+a valid DHCP packet, just a type not expected by the server (e.g. it will
-% DHCP4_PACKET_RELEASE RELEASE packet received on interface %1
+report a received OFFER packet as UNKNOWN).
-The server has received a RELEASE packet on the specified interface.
-
-% DHCP4_PACKET_REQUEST REQUEST packet received on interface %1
-The server has received a REQUEST packet on the specified interface.
-
-% DHCP4_PACKET_UNKNOWN unknown packet type (%1) received on interface %2
-Debug message indicating that the server has received an unknown packet type
-on the specified interface.  The type code is given in the message.  Note that
-this message will also be output if the server receives packet which is valid,
-but which should not be sent to the server (e.g. an OFFER or ACK).
 
 
 % DHCP4_PACK_FAIL failed to assemble message to be returned correctly
 % DHCP4_PACK_FAIL failed to assemble message to be returned correctly
 This error is output if the server failed to assemble the data to be returned to the client into
 This error is output if the server failed to assemble the data to be returned to the client into

+ 5 - 3
src/bin/dhcp4/dhcp4_srv.cc

@@ -86,7 +86,7 @@ Dhcpv4Srv::run() {
                           DHCP4_PACKET_PARSE_FAIL).arg(e.what());
                           DHCP4_PACKET_PARSE_FAIL).arg(e.what());
                 continue;
                 continue;
             }
             }
-            LOG_DEBUG(dhcp4_logger, DBG_DHCP4_DETAIL, DHCP4_PACKET_UNKNOWN)
+            LOG_DEBUG(dhcp4_logger, DBG_DHCP4_DETAIL, DHCP4_PACKET_RECEIVED)
                       .arg(serverReceivedPacketName(query->getType()))
                       .arg(serverReceivedPacketName(query->getType()))
                       .arg(query->getType())
                       .arg(query->getType())
                       .arg(query->getIface());
                       .arg(query->getIface());
@@ -139,10 +139,12 @@ Dhcpv4Srv::run() {
                 LOG_DEBUG(dhcp4_logger, DBG_DHCP4_DETAIL_DATA,
                 LOG_DEBUG(dhcp4_logger, DBG_DHCP4_DETAIL_DATA,
                           DHCP4_RESPONSE_DATA)
                           DHCP4_RESPONSE_DATA)
                           .arg(rsp->getType()).arg(rsp->toText());
                           .arg(rsp->getType()).arg(rsp->toText());
-                if (!rsp->pack()) {
+
+                if (rsp->pack()) {
+                    IfaceMgr::instance().send(rsp);
+                } else {
                     LOG_ERROR(dhcp4_logger, DHCP4_PACK_FAIL);
                     LOG_ERROR(dhcp4_logger, DHCP4_PACK_FAIL);
                 }
                 }
-                IfaceMgr::instance().send(rsp);
             }
             }
         }
         }
 
 

+ 4 - 4
src/bin/dhcp4/tests/dhcp4_test.py

@@ -27,7 +27,7 @@ import fcntl
 
 
 class TestDhcpv4Daemon(unittest.TestCase):
 class TestDhcpv4Daemon(unittest.TestCase):
     def setUp(self):
     def setUp(self):
-        # don't redirect stdout/stderr here as we want to print out things
+        # Don't redirect stdout/stderr here as we want to print out things
         # during the test
         # during the test
         #
         #
         # However, we do want to set the logging lock directory to somewhere
         # However, we do want to set the logging lock directory to somewhere
@@ -152,7 +152,7 @@ class TestDhcpv4Daemon(unittest.TestCase):
     def test_portnumber_missing(self):
     def test_portnumber_missing(self):
         print("Check that -p option requires a parameter.")
         print("Check that -p option requires a parameter.")
 
 
-        (returncode, output, error) = self.runCommand(['../b10-dhcp4', '-v', '-p'])
+        (returncode, output, error) = self.runCommand(['../b10-dhcp4', '-p'])
 
 
         # When invalid port number is specified, return code must not be success
         # When invalid port number is specified, return code must not be success
         self.assertTrue(returncode != 0)
         self.assertTrue(returncode != 0)
@@ -163,7 +163,7 @@ class TestDhcpv4Daemon(unittest.TestCase):
     def test_portnumber_invalid1(self):
     def test_portnumber_invalid1(self):
         print("Check that -p option is check against bogus port number (999999).")
         print("Check that -p option is check against bogus port number (999999).")
 
 
-        (returncode, output, error) = self.runCommand(['../b10-dhcp4', '-v', '-p','999999'])
+        (returncode, output, error) = self.runCommand(['../b10-dhcp4', '-p','999999'])
 
 
         # When invalid port number is specified, return code must not be success
         # When invalid port number is specified, return code must not be success
         self.assertTrue(returncode != 0)
         self.assertTrue(returncode != 0)
@@ -174,7 +174,7 @@ class TestDhcpv4Daemon(unittest.TestCase):
     def test_portnumber_invalid2(self):
     def test_portnumber_invalid2(self):
         print("Check that -p option is check against bogus port number (123garbage).")
         print("Check that -p option is check against bogus port number (123garbage).")
 
 
-        (returncode, output, error) = self.runCommand(['../b10-dhcp4', '-v', '-p','123garbage'])
+        (returncode, output, error) = self.runCommand(['../b10-dhcp4', '-p','123garbage'])
 
 
         # When invalid port number is specified, return code must not be success
         # When invalid port number is specified, return code must not be success
         self.assertTrue(returncode != 0)
         self.assertTrue(returncode != 0)