From: Francis Dupont Date: Mon, 27 Nov 2017 23:23:45 +0000 (+0100) Subject: [5374] Final cleanup X-Git-Tag: trac5458a_base~14^2~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f848c18c0a58674cf61019b752b10a5c48caffb2;p=thirdparty%2Fkea.git [5374] Final cleanup --- diff --git a/src/bin/dhcp4/dhcp4_messages.mes b/src/bin/dhcp4/dhcp4_messages.mes index 15b9e82723..ca29b07ccc 100644 --- a/src/bin/dhcp4/dhcp4_messages.mes +++ b/src/bin/dhcp4/dhcp4_messages.mes @@ -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 diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index 36e6cf6b1a..2e3f72bafa 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -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), diff --git a/src/bin/dhcp6/dhcp6_messages.mes b/src/bin/dhcp6/dhcp6_messages.mes index 4c8c115454..aececc9b71 100644 --- a/src/bin/dhcp6/dhcp6_messages.mes +++ b/src/bin/dhcp6/dhcp6_messages.mes @@ -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. diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index 18cbcb03fe..cfdd446195 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -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), diff --git a/src/lib/dhcpsrv/client_class_def.cc b/src/lib/dhcpsrv/client_class_def.cc index 9b5b153704..0b85639bf2 100644 --- a/src/lib/dhcpsrv/client_class_def.cc +++ b/src/lib/dhcpsrv/client_class_def.cc @@ -292,5 +292,44 @@ ClientClassDictionary::toElement() const { return (result); } +std::list +builtinPrefixes = { + "VENDOR_CLASS_", "AFTER_", "EXTERNAL_" +}; + +bool +isClientClassBuiltIn(const ClientClass& client_class) { + for (std::list::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 diff --git a/src/lib/dhcpsrv/client_class_def.h b/src/lib/dhcpsrv/client_class_def.h index d12d2b6f80..b38263aba2 100644 --- a/src/lib/dhcpsrv/client_class_def.h +++ b/src/lib/dhcpsrv/client_class_def.h @@ -340,6 +340,26 @@ private: /// @brief Defines a pointer to a ClientClassDictionary typedef boost::shared_ptr ClientClassDictionaryPtr; +/// @brief List of built-in client class prefixes +/// i.e. VENDOR_CLASS_, AFTER_ and EXTERNAL_. +extern std::list 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 diff --git a/src/lib/dhcpsrv/parsers/client_class_def_parser.cc b/src/lib/dhcpsrv/parsers/client_class_def_parser.cc index e0d11ec957..cf4b231bbe 100644 --- a/src/lib/dhcpsrv/parsers/client_class_def_parser.cc +++ b/src/lib/dhcpsrv/parsers/client_class_def_parser.cc @@ -201,36 +201,6 @@ ClientClassDefParser::parse(ClientClassDictionaryPtr& class_dictionary, } } -std::list -ClientClassDefParser::builtinPrefixes = { - "VENDOR_CLASS_", "AFTER_", "EXTERNAL_" -}; - -bool -ClientClassDefParser::isClientClassKnown(ClientClassDictionaryPtr& class_dictionary, - const ClientClass& client_class) { - // First check built-in prefixes - for (std::list::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 diff --git a/src/lib/dhcpsrv/parsers/client_class_def_parser.h b/src/lib/dhcpsrv/parsers/client_class_def_parser.h index 95a0a592c6..4723f480f4 100644 --- a/src/lib/dhcpsrv/parsers/client_class_def_parser.h +++ b/src/lib/dhcpsrv/parsers/client_class_def_parser.h @@ -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 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