]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3743] More review clean up, use ClientId for client info output
authorThomas Markwalder <tmark@isc.org>
Mon, 20 Apr 2015 18:12:44 +0000 (14:12 -0400)
committerThomas Markwalder <tmark@isc.org>
Mon, 20 Apr 2015 18:12:44 +0000 (14:12 -0400)
src/bin/dhcp4/dhcp4_srv.cc
src/lib/dhcp/pkt.h
src/lib/dhcp/pkt4.cc
src/lib/dhcp/pkt4.h
src/lib/dhcp/tests/pkt4_unittest.cc

index 026ba00adf5515a0e44bee6d56076a5a6a9c9780..aad3ebae05a0deb97cedb68aa3a034801e10fa58 100644 (file)
@@ -404,7 +404,8 @@ Dhcpv4Srv::run() {
                 // Failed to parse the packet.
                 LOG_DEBUG(bad_packet_logger, DBG_DHCP4_DETAIL,
                           DHCP4_PACKET_DROP_0001)
-                    .arg(query->getLabel()).arg(e.what());
+                    .arg(query->getLabel())
+                    .arg(e.what());
                 continue;
             }
         }
index e0f98447113ccc4680507abda135a39199078604..5f0c5afebf628015ea7e0a652ea9a55d000b4d5b 100755 (executable)
@@ -148,7 +148,7 @@ public:
     /// there own implementation.
     ///
     /// @return string with text representation
-    virtual std::string getLabel() {
+    virtual std::string getLabel() const {
         isc_throw(NotImplemented, "Pkt::getLabel()");
     }
 
index a0d4b98c8635608e0cd468299b9540a3454fd0fa..50d1b5f6a722655c830e32e95220c682fb0b8fd3 100644 (file)
@@ -282,20 +282,29 @@ void Pkt4::setType(uint8_t dhcp_type) {
 }
 
 std::string
-Pkt4::getLabel() {
-    return makeLabel(hwaddr_, getOption(DHO_DHCP_CLIENT_IDENTIFIER), transid_);
-}
+Pkt4::getLabel() const {
+
+    /// @TODO If and when client id is extracted into Pkt4, this method should
+    /// the instance member rather than fetch it every time.
+    ClientIdPtr client_id;
+    OptionPtr client_opt = getOption(DHO_DHCP_CLIENT_IDENTIFIER);
+    if (client_opt ) {
+        client_id = ClientIdPtr(new ClientId(client_opt->getData()));
+    }
 
-std::string
-Pkt4::makeLabel(HWAddrPtr hwaddr, OptionPtr client_id, uint32_t transid)
-{
-    stringstream tmp;
+    return makeLabel(hwaddr_, client_id, transid_);
 
-    tmp << "hwaddr=[" << (hwaddr ? hwaddr->toText() : "no info")
-        << "], client-id=[" << (client_id ? client_id->toText() : "no info")
-        << "], transid=0x" << hex << transid << dec;
+}
 
-    return tmp.str();
+std::string
+Pkt4::makeLabel(const HWAddrPtr hwaddr, const ClientIdPtr client_id,
+                const uint32_t transid) {
+    stringstream label;
+    label << "hwaddr=[" << (hwaddr ? hwaddr->toText() : "no info")
+          << "], client-id=[" << (client_id ? client_id->toText() : "no info")
+          << "], transid=0x" << hex << transid << dec;
+
+    return label.str();
 }
 
 
index a622e3179fe5e40ee013e2b3be85e28735507a03..73898e2846d93038c08c6e079233a4afd355cf68 100755 (executable)
@@ -17,6 +17,7 @@
 
 #include <asiolink/io_address.h>
 #include <dhcp/option.h>
+#include <dhcp/duid.h>
 #include <util/buffer.h>
 #include <dhcp/option.h>
 #include <dhcp/classify.h>
@@ -108,26 +109,28 @@ public:
     /// Method will throw exception if anomaly is found.
     void check();
 
-    /// @brief Returns text representation primary packet identifiers
+    /// @brief Returns text representation of the primary packet identifiers
     ///
     /// This method is intended to be used to provide a consistent way to
     /// identify packets within log statements.  It is an instance-level
-    /// wrapper around static makeLabel()(). See this method for string
+    /// wrapper around static makeLabel(). See this method for string
     /// content.
     ///
     /// @return string with text representation
-    std::string getLabel();
+    std::string getLabel() const;
 
     /// @brief Returns text representation of the given packet identifiers
     ///
-    /// @param hwaddr - hardware address to include in the string
-    /// @param client_id - DHO_DHCP_CLIENT_ID_OPTION containing the client id
+    /// @param hwaddr - hardware address to include in the string, it may be
+    /// NULL.
+    /// @param client_id - client id to include in the string, it may be NULL.
     /// to include in the string
     /// @param transid - numeric transaction id to include in the string
     ///
     /// @return string with text representation
-    static std::string makeLabel(HWAddrPtr hwaddr, OptionPtr client_id,
-                                 uint32_t transid);
+    static std::string makeLabel(const HWAddrPtr hwaddr,
+                                 const ClientIdPtr client_id,
+                                 const uint32_t transid);
 
     /// @brief Returns text representation of the packet.
     ///
index 7fa3fe5e4cd7a19095006e6ffba1dcb8cf2d1b3f..8d2f4cf0d473b0189562b2e871ee7fb78357258e 100644 (file)
@@ -885,7 +885,7 @@ TEST_F(Pkt4Test, getLabel) {
 
     // Verify makeLabel() handles empty values
     EXPECT_EQ ("hwaddr=[no info], client-id=[no info], transid=0x0",
-               Pkt4::makeLabel(HWAddrPtr(), OptionPtr(), 0));
+               Pkt4::makeLabel(HWAddrPtr(), ClientIdPtr(), 0));
 
     // Verify an "empty" packet label is as we expect
     EXPECT_EQ ("hwaddr=[hwtype=1 ], client-id=[no info], transid=0x4d2",
@@ -911,7 +911,7 @@ TEST_F(Pkt4Test, getLabel) {
     pkt.addOption(opt);
 
     EXPECT_EQ ("hwaddr=[hwtype=123 02:04:06:08:0a:0c],"
-               " client-id=[type=61, len=4: 64:65:66:67], transid=0x4d2",
+               " client-id=[64:65:66:67], transid=0x4d2",
                pkt.getLabel());
 
 }