From: Razvan Becheriu Date: Wed, 10 Apr 2019 10:26:37 +0000 (+0300) Subject: make LibDHCP thread safe X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f25bddb07af5265356be3afa78e6331168b95f2;p=thirdparty%2Fkea.git make LibDHCP thread safe --- diff --git a/src/lib/dhcp/libdhcp++.cc b/src/lib/dhcp/libdhcp++.cc index 38649497e8..90a43dfc8d 100644 --- a/src/lib/dhcp/libdhcp++.cc +++ b/src/lib/dhcp/libdhcp++.cc @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include @@ -27,6 +27,7 @@ #include #include +#include using namespace std; using namespace isc::dhcp; @@ -88,6 +89,8 @@ void initOptionSpace(OptionDefContainerPtr& defs, const OptionDefContainerPtr& LibDHCP::getOptionDefs(const std::string& space) { + static mutex local_mutex; + isc::util::thread::LockGuard lock(&local_mutex); // If any of the containers is not initialized, it means that we haven't // initialized option definitions at all. if (option_defs_.end() == option_defs_.find(space)) { @@ -837,11 +840,10 @@ void LibDHCP::OptionFactoryRegister(Option::Universe u, isc_throw(BadValue, "There is already DHCPv6 factory registered " << "for option type " << opt_type); } - v6factories_[opt_type]=factory; + v6factories_[opt_type] = factory; return; } - case Option::V4: - { + case Option::V4: { // Option 0 is special (a one octet-long, equal 0) PAD option. It is never // instantiated as an Option object, but rather consumed during packet parsing. if (opt_type == 0) { @@ -853,11 +855,11 @@ void LibDHCP::OptionFactoryRegister(Option::Universe u, if (opt_type > 254) { isc_throw(BadValue, "Too big option type for DHCPv4, only 0-254 allowed."); } - if (v4factories_.find(opt_type)!=v4factories_.end()) { + if (v4factories_.find(opt_type) != v4factories_.end()) { isc_throw(BadValue, "There is already DHCPv4 factory registered " << "for option type " << opt_type); } - v4factories_[opt_type]=factory; + v4factories_[opt_type] = factory; return; } default: @@ -892,7 +894,6 @@ LibDHCP::optionSpaceToVendorId(const std::string& option_space) { std::string x = option_space.substr(7); check = boost::lexical_cast(x); - } catch (const boost::bad_lexical_cast &) { return (0); } @@ -913,7 +914,6 @@ void initOptionSpace(OptionDefContainerPtr& defs, // case. if (!defs) { defs.reset(new OptionDefContainer()); - } else { defs->clear(); } diff --git a/src/lib/dhcp/libdhcp++.h b/src/lib/dhcp/libdhcp++.h index 12866a9bde..5182115ba0 100644 --- a/src/lib/dhcp/libdhcp++.h +++ b/src/lib/dhcp/libdhcp++.h @@ -27,7 +27,7 @@ class LibDHCP { public: /// Map of factory functions. - typedef std::map FactoryMap; + typedef std::map FactoryMap; /// @brief Returns collection of option definitions. /// @@ -366,7 +366,6 @@ public: static uint32_t optionSpaceToVendorId(const std::string& option_space); private: - /// Initialize DHCP option definitions. /// /// The method creates option definitions for all DHCP options.