]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5374] Final cleanup
authorFrancis Dupont <fdupont@isc.org>
Mon, 27 Nov 2017 23:23:45 +0000 (00:23 +0100)
committerFrancis Dupont <fdupont@isc.org>
Mon, 27 Nov 2017 23:23:45 +0000 (00:23 +0100)
src/bin/dhcp4/dhcp4_messages.mes
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp6/dhcp6_messages.mes
src/bin/dhcp6/dhcp6_srv.cc
src/lib/dhcpsrv/client_class_def.cc
src/lib/dhcpsrv/client_class_def.h
src/lib/dhcpsrv/parsers/client_class_def_parser.cc
src/lib/dhcpsrv/parsers/client_class_def_parser.h

index 15b9e8272389e0a57c087b0d18bcdc68a5b1f71f..ca29b07ccca2b34baa29f3eb0a642396c880752e 100644 (file)
@@ -59,6 +59,14 @@ which cannot be found in the configuration. Either a hook written
 before the classification was added to Kea is used, or class naming is
 inconsistent.
 
+% DHCP4_CLASS_UNKNOWN on-demand class %1 has no definition
+This debug message informs that a class is listed for late evaluation but
+has no definition.
+
+% DHCP4_CLASS_UNTESTABLE on-demand class %1 has no test expression
+This debug message informs that a class was listed for late evaluation but
+its definition does not include a test expression to evaluate.
+
 % DHCP4_CLIENTID_IGNORED_FOR_LEASES %1: not using client identifier for lease allocation for subnet %2
 This debug message is issued when the server is processing the DHCPv4 message
 for which client identifier will not be used when allocating new lease or
index 36e6cf6b1ac2dd13fb9780fdd3d9d5b7360afc65..2e3f72bafadc3150a67f0bcac8a453aefb058390 100644 (file)
@@ -1218,10 +1218,8 @@ Dhcpv4Srv::buildCfgOptionList(Dhcpv4Exchange& ex) {
         const ClientClassDefPtr& ccdef = CfgMgr::instance().getCurrentCfg()->
             getClientClassDictionary()->findClass(*cclass);
         if (!ccdef) {
-            // Not found: the class is not configured
-            if (((*cclass).size() <= VENDOR_CLASS_PREFIX.size()) ||
-                ((*cclass).compare(0, VENDOR_CLASS_PREFIX.size(), VENDOR_CLASS_PREFIX) != 0)) {
-                // Not a VENDOR_CLASS_* so should be configured
+            // Not found: the class is built-in or not configured
+            if (!isClientClassBuiltIn(*cclass)) {
                 LOG_DEBUG(dhcp4_logger, DBG_DHCP4_BASIC, DHCP4_CLASS_UNCONFIGURED)
                     .arg(ex.getQuery()->getLabel())
                     .arg(*cclass);
@@ -3071,13 +3069,16 @@ void Dhcpv4Srv::lateClassify(Dhcpv4Exchange& ex) {
     for (ClientClasses::const_iterator cclass = classes.cbegin();
          cclass != classes.cend(); ++cclass) {
         const ClientClassDefPtr class_def = dict->findClass(*cclass);
-        // Todo: log unknown classes
         if (!class_def) {
+            LOG_DEBUG(dhcp4_logger, DBG_DHCP4_BASIC, DHCP4_CLASS_UNKNOWN)
+                .arg(*cclass);
             continue;
         }
         const ExpressionPtr& expr_ptr = class_def->getMatchExpr();
         // Nothing to do without an expression to evaluate
         if (!expr_ptr) {
+            LOG_DEBUG(dhcp4_logger, DBG_DHCP4_BASIC, DHCP4_CLASS_UNTESTABLE)
+                .arg(*cclass);
             continue;
         }
         // Evaluate the expression which can return false (no match),
index 4c8c1154546a618766d696c61157d142c564ffae..aececc9b71be72311e68b79a4d78d48802b8ca1e 100644 (file)
@@ -66,6 +66,14 @@ which cannot be found in the configuration. Either a hook written
 before the classification was added to Kea is used, or class naming is
 inconsistent.
 
+% DHCP6_CLASS_UNKNOWN on-demand class %1 has no definition
+This debug message informs that a class is listed for late evaluation but
+has no definition.
+
+% DHCP6_CLASS_UNTESTABLE on-demand class %1 has no test expression
+This debug message informs that a class was listed for late evaluation but
+its definition does not include a test expression to evaluate.
+
 % DHCP6_COMMAND_RECEIVED received command %1, arguments: %2
 A debug message listing the command (and possible arguments) received
 from the Kea control system by the IPv6 DHCP server.
index 18cbcb03febb4c04718fad8dc55b098284875f0d..cfdd44619566511e60e9b31ec003c2dcffdaf746 100644 (file)
@@ -902,10 +902,8 @@ Dhcpv6Srv::buildCfgOptionList(const Pkt6Ptr& question,
         const ClientClassDefPtr& ccdef = CfgMgr::instance().getCurrentCfg()->
             getClientClassDictionary()->findClass(*cclass);
         if (!ccdef) {
-            // Not found: the class is not configured
-            if (((*cclass).size() <= VENDOR_CLASS_PREFIX.size()) ||
-                ((*cclass).compare(0, VENDOR_CLASS_PREFIX.size(), VENDOR_CLASS_PREFIX) != 0)) {
-                // Not a VENDOR_CLASS_* so should be configured
+            // Not found: the class is built-in or not configured
+            if (!isClientClassBuiltIn(*cclass)) {
                 LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLASS_UNCONFIGURED)
                     .arg(question->getLabel())
                     .arg(*cclass);
@@ -3207,13 +3205,16 @@ Dhcpv6Srv::lateClassify(const Pkt6Ptr& pkt, AllocEngine::ClientContext6& ctx) {
     for (ClientClasses::const_iterator cclass = classes.cbegin();
          cclass != classes.cend(); ++cclass) {
         const ClientClassDefPtr class_def = dict->findClass(*cclass);
-        // Todo: log unknown classes
         if (!class_def) {
+            LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLASS_UNKNOWN)
+                .arg(*cclass);
             continue;
         }
         const ExpressionPtr& expr_ptr = class_def->getMatchExpr();
         // Nothing to do without an expression to evaluate
         if (!expr_ptr) {
+            LOG_DEBUG(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLASS_UNTESTABLE)
+                .arg(*cclass);
             continue;
         }
         // Evaluate the expression which can return false (no match),
index 9b5b1537042c8f5075d8ac67d00b90f52906aa46..0b85639bf2adb65692c62202d7aebf98a2107fb6 100644 (file)
@@ -292,5 +292,44 @@ ClientClassDictionary::toElement() const {
     return (result);
 }
 
+std::list<std::string>
+builtinPrefixes = {
+    "VENDOR_CLASS_", "AFTER_", "EXTERNAL_"
+};
+
+bool
+isClientClassBuiltIn(const ClientClass& client_class) {
+    for (std::list<std::string>::const_iterator bt = builtinPrefixes.cbegin();
+         bt != builtinPrefixes.cend(); ++bt) {
+        if (client_class.size() <= bt->size()) {
+            continue;
+        }
+        auto mis = std::mismatch(bt->cbegin(), bt->cend(), client_class.cbegin());
+        if (mis.first == bt->cend()) {
+            return true;
+        }
+    }
+
+    return false;
+}
+
+bool
+isClientClassKnown(ClientClassDictionaryPtr& class_dictionary,
+                   const ClientClass& client_class) {
+    // First check built-in prefixes
+    if (isClientClassBuiltIn(client_class)) {
+        return (true);
+    }
+
+    // Second check already defined, i.e. in the dictionary
+    ClientClassDefPtr def = class_dictionary->findClass(client_class);
+    if (def) {
+        return (true);
+    }
+
+    // Unknown...
+    return (false);
+}
+
 } // namespace isc::dhcp
 } // namespace isc
index d12d2b6f80127490495d84ad799424e79d6b8b4d..b38263aba22c945fa83079b92f3366a14648134e 100644 (file)
@@ -340,6 +340,26 @@ private:
 /// @brief Defines a pointer to a ClientClassDictionary
 typedef boost::shared_ptr<ClientClassDictionary> ClientClassDictionaryPtr;
 
+/// @brief List of built-in client class prefixes
+/// i.e. VENDOR_CLASS_, AFTER_ and EXTERNAL_.
+extern std::list<std::string> builtinPrefixes;
+
+/// @brief Check if a client class name is builtin.
+///
+/// @param client_class A client class name to look for.
+/// @return true if built-in, false if not.
+bool isClientClassBuiltIn(const ClientClass& client_class);
+
+
+/// @brief Check if a client class name is already known,
+/// i.e. beginning by a built-in prefix or in the dictionary,
+///
+/// @param class_dictionary A class dictionary where to look for.
+/// @param client_class A client class name to look for.
+/// @return true if known or built-in, false if not.
+bool isClientClassKnown(ClientClassDictionaryPtr& class_dictionary,
+                        const ClientClass& client_class);
+
 } // namespace isc::dhcp
 } // namespace isc
 
index e0d11ec9573d7584446d628260f862f6326ca260..cf4b231bbe706326628a6742be4e6c7edc7cd395 100644 (file)
@@ -201,36 +201,6 @@ ClientClassDefParser::parse(ClientClassDictionaryPtr& class_dictionary,
     }
 }
 
-std::list<std::string>
-ClientClassDefParser::builtinPrefixes = {
-    "VENDOR_CLASS_", "AFTER_", "EXTERNAL_"
-};
-
-bool
-ClientClassDefParser::isClientClassKnown(ClientClassDictionaryPtr& class_dictionary,
-                                         const ClientClass& client_class) {
-    // First check built-in prefixes
-    for (std::list<std::string>::const_iterator bt = builtinPrefixes.cbegin();
-         bt != builtinPrefixes.cend(); ++bt) {
-        if (client_class.size() <= bt->size()) {
-            continue;
-        }
-        auto mis = std::mismatch(bt->cbegin(), bt->cend(), client_class.cbegin());
-        if (mis.first == bt->cend()) {
-            return true;
-        }
-    }
-
-    // Second check already defined, i.e. in the dictionary
-    ClientClassDefPtr def = class_dictionary->findClass(client_class);
-    if (def) {
-        return (true);
-    }
-
-    // Unknown...
-    return (false);
-}
-
 // ****************** ClientClassDefListParser ************************
 
 ClientClassDictionaryPtr
index 95a0a592c6a2b50bc2fb3be0dcde50552bb66099..4723f480f416b24f86703336081ad501a4fb76c6 100644 (file)
@@ -94,20 +94,6 @@ public:
     /// @throw DhcpConfigError if parsing was unsuccessful.
     void parse(ClientClassDictionaryPtr& class_dictionary,
                isc::data::ConstElementPtr client_class_def, uint16_t family);
-
-    /// @brief List of built-in client class prefixes
-    /// i.e. VENDOR_CLASS_, AFTER_ and EXTERNAL_.
-    static std::list<std::string> builtinPrefixes;
-
-    /// @brief Check if a client class name is already known,
-    /// i.e. beginning by a built-in prefix or in the dictionary,
-    ///
-    /// @param class_dictionary A class dictionary where to look for.
-    /// @param client_class A client class name to look for.
-    /// @return true if known or built-in, false if not.
-    static bool
-    isClientClassKnown(ClientClassDictionaryPtr& class_dictionary,
-                       const ClientClass& client_class);
 };
 
 /// @brief Defines a pointer to a ClientClassDefParser