]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3699] Added more traces to the CfgHosts class.
authorMarcin Siodelski <marcin@isc.org>
Thu, 16 Apr 2015 10:14:15 +0000 (12:14 +0200)
committerMarcin Siodelski <marcin@isc.org>
Thu, 16 Apr 2015 10:14:15 +0000 (12:14 +0200)
src/lib/dhcpsrv/cfg_hosts.cc
src/lib/dhcpsrv/host.cc
src/lib/dhcpsrv/hosts_messages.mes

index 988efac4ecf2f652bdf9db2a412938c192ae65c6..7f76e347689dac70425ec7f6ec2909eba7f399d3 100644 (file)
@@ -81,7 +81,34 @@ void
 CfgHosts::getAllInternal(const std::vector<uint8_t>& identifier,
                          const Host::IdentifierType& identifier_type,
                          Storage& storage) const {
-    // HOST_RESRV_GET_ALL_IDENTIFIER
+    // We will need to transform the identifier into the textual format.
+    // Until we do it, we mark it as invalid.
+    std::string identifier_text = "(invalid)";
+    if (!identifier.empty()) {
+        try {
+            // Use Host object to find the textual form of the identifier.
+            // This may throw exception if the identifier is invalid.
+            Host host(&identifier[0], identifier.size(), identifier_type,
+                      SubnetID(0), SubnetID(0), IOAddress::IPV4_ZERO_ADDRESS());
+            identifier_text = host.getIdentifierAsText();
+
+        } catch (...) {
+            // Suppress exception and keep using (invalid) as an
+            // identifier. We will log that the identifier is
+            // invalid and return.
+        }
+
+    }
+    // This will log that we're invoking this function with the specified
+    // identifier. The identifier may also be marked as (invalid) if it
+    // had 0 length or its type is unsupported.
+    LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE, HOSTS_CFG_GET_ALL_IDENTIFIER)
+        .arg(identifier_text);
+
+    // Do nothing if the identifier specified is invalid.
+    if (identifier_text == "(invalid)") {
+        return;
+    }
 
     // Use the identifier and identifier type as a composite key.
     const HostContainerIndex0& idx = hosts_.get<0>();
index d2b20db412ea2b8c84f3f43350c24fd89660dea8..3b94e3c708c4a62610ec222d268be7d863ce881f 100644 (file)
@@ -138,6 +138,24 @@ Host::getIdentifierType() const {
     return (IDENT_DUID);
 }
 
+std::string
+Host::getIdentifierAsText() const {
+    std::string txt;
+    if (hw_address_) {
+        txt = "hwaddr=" + hw_address_->toText(false);
+    } else {
+        txt = "duid=";
+        if (duid_) {
+            txt += duid_->toText();
+        } else {
+            txt += "(none)";
+        }
+    }
+
+    return (txt);
+
+}
+
 void
 Host::setIdentifier(const uint8_t* identifier, const size_t len,
                     const IdentifierType& type) {
@@ -251,23 +269,6 @@ Host::addClientClassInternal(ClientClasses& classes,
     }
 }
 
-std::string
-Host::getIdentifierAsText() const {
-    std::string txt;
-    if (hw_address_) {
-        txt = "hwaddr=" + hw_address_->toText(false);
-    } else {
-        txt = "duid=";
-        if (duid_) {
-            txt += duid_->toText();
-        } else {
-            txt += "(none)";
-        }
-    }
-
-    return (txt);
-}
-
 std::string
 Host::toText() const {
     std::ostringstream s;
index 2e56f0ffd169b9c404028ba5012042ccbed21bb2..c41ec26a8c1c0e55c6fb60d4b303c285601e14bc 100644 (file)
@@ -34,6 +34,11 @@ This debug message is issued when retrieving reservations for all hosts
 using specific HW address or DUID. The arguments specify the HW address and
 DUID respectively. The argument specify the HW address and DUID respectively.
 
+% HOSTS_CFG_GET_ALL_IDENTIFIER get all hosts with reservations using identifier: %1
+This debug message is issued when retrieving reservations for all hosts
+identified by HW address or DUID. The argument holds both the identifier
+type and the value.
+
 % HOSTS_CFG_GET_ALL_SUBNET_ID_ADDRESS6 get all hosts with reservations for subnet id %1 and IPv6 address %2
 This debug message is issued when retrieving all hosts connected to
 the specific subnet and having the specific IPv6 address reserved.