]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[4271] Debug logging added.
authorTomek Mrugalski <tomasz@isc.org>
Tue, 9 Aug 2016 14:08:11 +0000 (16:08 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Tue, 9 Aug 2016 14:08:11 +0000 (16:08 +0200)
src/lib/eval/eval_messages.mes
src/lib/eval/token.cc
src/lib/eval/token.h

index 3ee2da130675dcda1bd95235c243fad1200e8bc1..10e7af5f605b0ee381706241b12d15ed864b3edd 100644 (file)
@@ -111,3 +111,50 @@ still pushed.  The strings are displayed in hex.
 This debug message indicates that the expression has been evaluated
 to said value. This message is mostly useful during debugging of the
 client classification expressions.
+
+% EVAL_DEBUG_VENDOR_NO_OPTION Vendor option (code %1) missing, pushing result %2
+This debug message indicates that the expression has been evaluated
+and vendor option was not found. This message is mostly useful during
+debugging of the client classification expressions.
+
+% EVAL_DEBUG_VENDOR_ENTERPRISE_ID_MISMATCH Vendor option was found, but does not have expected enterprise-id (was looking for %1, option had %2), pushing result %3
+This debug message indicates that the expression has been evaluated
+and vendor option was found, but has different enterprise-id than specified
+in the expression. This message is mostly useful during debugging of the
+client classification expressions.
+
+% EVAL_DEBUG_VENDOR_ENTERPRISE_ID Vendor option found, pushing enterprise-id %1 as result %2
+This debug message indicates that the expression has been evaluated and vendor
+option was found and its enterprise-id is being reported. This message is mostly
+useful during debugging of the client classification expressions.
+
+% EVAL_DEBUG_VENDOR_EXISTS Vendor option exists, pushing result %1
+This debug message indicates that the expression has been evaluated and vendor
+option was found. This message is mostly useful during debugging of the client
+classification expressions.
+
+% EVAL_DEBUG_VENDOR_CLASS_NO_OPTION Vendor class option (code %1) missing, pushing result %2
+This debug message indicates that the expression has been evaluated
+and vendor class option was not found. This message is mostly useful during
+debugging of the client classification expressions.
+
+% EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID_MISMATCH Vendor class option was found, but does not have expected enterprise-id (was looking for %1, option had %2), pushing result %3
+This debug message indicates that the expression has been evaluated
+and vendor class option was found, but has different enterprise-id than specified
+in the expression. This message is mostly useful during debugging of the
+client classification expressions.
+
+% EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID Vendor class option found, pushing enterprise-id %1 as result %2
+This debug message indicates that the expression has been evaluated and vendor
+class option was found and its enterprise-id is being reported. This message is mostly
+useful during debugging of the client classification expressions.
+
+% EVAL_DEBUG_VENDOR_CLASS_EXISTS Vendor class option exists, pushing result %1
+This debug message indicates that the expression has been evaluated and vendor
+class option was found. This message is mostly useful during debugging of the
+client classification expressions.
+
+% EVAL_DEBUG_VENDOR_CLASS_DATA Vendor class data %1 (out of %2 received) is pushed as %3
+This debug message indicates that vendor class option was found and passed
+enterprise-id checks and has sufficient number of data chunks. Total numer
+of chunks and value pushed are reported as debugging aid.
index f8df034e05450bea7702d00d0e02180438c3b6c4..a2b5cd8f60da12f5130952c75c90fd301c7dafb2 100644 (file)
@@ -140,13 +140,14 @@ TokenOption::evaluate(Pkt& pkt, ValueStack& values) {
     }
 }
 
-void
+std::string
 TokenOption::pushFailure(ValueStack& values) {
+    std::string txt;
     if (representation_type_ == EXISTS) {
-        values.push("false");
-    } else {
-        values.push("");
+        txt = "false";
     }
+    values.push(txt);
+    return (txt);
 }
 
 TokenRelay4Option::TokenRelay4Option(const uint16_t option_code,
@@ -654,14 +655,21 @@ void TokenVendor::evaluate(Pkt& pkt, ValueStack& values) {
     OptionVendorPtr vendor = boost::dynamic_pointer_cast<OptionVendor>(opt);
     if (!vendor) {
         // There's no vendor option, give up.
-        pushFailure(values);
+        std::string txt = pushFailure(values);
+        LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_VENDOR_NO_OPTION)
+            .arg(code)
+            .arg(txt);
         return;
     }
 
     if (vendor_id_ && (vendor_id_ != vendor->getVendorId())) {
         // There is vendor option, but it has other vendor-id value
         // than we're looking for. (0 means accept any vendor-id)
-        pushFailure(values);
+        std::string txt = pushFailure(values);
+        LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_VENDOR_ENTERPRISE_ID_MISMATCH)
+            .arg(vendor_id_)
+            .arg(vendor->getVendorId())
+            .arg(txt);
         return;
     }
 
@@ -673,6 +681,10 @@ void TokenVendor::evaluate(Pkt& pkt, ValueStack& values) {
         uint32_t value = htonl(vendor->getVendorId());
         memcpy(&txt[0], &value, sizeof(uint32_t));
         values.push(txt);
+        LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_VENDOR_ENTERPRISE_ID)
+            .arg(vendor_id_)
+            .arg(util::encode::encodeHex(std::vector<uint8_t>(txt.begin(),
+                                                              txt.end())));
         return;
     }
     case SUBOPTION:
@@ -683,6 +695,8 @@ void TokenVendor::evaluate(Pkt& pkt, ValueStack& values) {
     case EXISTS:
         // We already passed all the checks: the option is there and has specified
         // enterprise-id.
+        LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_VENDOR_EXISTS)
+            .arg("true");
         values.push("true");
         return;
     case DATA:
@@ -746,15 +760,22 @@ void TokenVendorClass::evaluate(Pkt& pkt, ValueStack& values) {
     OptionPtr opt = pkt.getOption(code);
     OptionVendorClassPtr vendor = boost::dynamic_pointer_cast<OptionVendorClass>(opt);
     if (!vendor) {
-        // There's no vendor option, give up.
-        pushFailure(values);
+        // There's no vendor class option, give up.
+        std::string txt = pushFailure(values);
+        LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_VENDOR_CLASS_NO_OPTION)
+            .arg(code)
+            .arg(txt);
         return;
     }
 
     if (vendor_id_ && (vendor_id_ != vendor->getVendorId())) {
         // There is vendor option, but it has other vendor-id value
         // than we're looking for. (0 means accept any vendor-id)
-        pushFailure(values);
+        std::string txt = pushFailure(values);
+        LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID_MISMATCH)
+            .arg(vendor_id_)
+            .arg(vendor->getVendorId())
+            .arg(txt);
         return;
     }
 
@@ -766,6 +787,10 @@ void TokenVendorClass::evaluate(Pkt& pkt, ValueStack& values) {
         uint32_t value = htonl(vendor->getVendorId());
         memcpy(&txt[0], &value, sizeof(uint32_t));
         values.push(txt);
+        LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID)
+            .arg(vendor_id_)
+            .arg(util::encode::encodeHex(std::vector<uint8_t>(txt.begin(),
+                                                              txt.end())));
         return;
     }
     case SUBOPTION:
@@ -775,6 +800,8 @@ void TokenVendorClass::evaluate(Pkt& pkt, ValueStack& values) {
     case EXISTS:
         // We already passed all the checks: the option is there and has specified
         // enterprise-id.
+        LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_VENDOR_CLASS_EXISTS)
+            .arg("true");
         values.push("true");
         return;
     case DATA:
@@ -790,6 +817,12 @@ void TokenVendorClass::evaluate(Pkt& pkt, ValueStack& values) {
         OpaqueDataTuple tuple = vendor->getTuple(index_);
         OpaqueDataTuple::Buffer buf = tuple.getData();
         string txt(buf.begin(), buf.end());
+
+        LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_VENDOR_CLASS_DATA)
+            .arg(index_)
+            .arg(max)
+            .arg(util::encode::encodeHex(buf));
+
         values.push(txt);
         return;
     }
index fcc123df5713a2dc182a4981062710e611afacea..28c444c617f9a79df4ac8a9ddb4736e9f9542918 100644 (file)
@@ -261,7 +261,8 @@ protected:
     /// Depending on the representation type, this is either "" or "false".
     ///
     /// @param values a string representing failure will be pushed here.
-    virtual void pushFailure(ValueStack& values);
+    /// @return value pushed
+    virtual std::string pushFailure(ValueStack& values);
 
     uint16_t option_code_; ///< Code of the option to be extracted
     RepresentationType representation_type_; ///< Representation type.