]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1518] addressed review comments
authorRazvan Becheriu <razvan@isc.org>
Thu, 19 Jan 2023 14:06:31 +0000 (16:06 +0200)
committerRazvan Becheriu <razvan@isc.org>
Fri, 20 Jan 2023 15:36:06 +0000 (17:36 +0200)
src/lib/dhcp/libdhcp++.cc

index c6dd3de7ef3d80faacd89c8e949c883d53fa3d06..2006c267787de084f4e665057bf88a70df809262 100644 (file)
@@ -62,10 +62,10 @@ const OptionDefParamsEncapsulation OPTION_DEF_PARAMS[] = {
 }  // namespace isc
 
 // static array with factories for options
-std::map<unsigned short, Option::Factory*> LibDHCP::v4factories_;
+map<unsigned short, Option::Factory*> LibDHCP::v4factories_;
 
 // static array with factories for options
-std::map<unsigned short, Option::Factory*> LibDHCP::v6factories_;
+map<unsigned short, Option::Factory*> LibDHCP::v6factories_;
 
 // Static container with option definitions grouped by option space.
 OptionDefContainers LibDHCP::option_defs_;
@@ -93,7 +93,7 @@ void initOptionSpace(OptionDefContainerPtr& defs,
 bool LibDHCP::initialized_ = LibDHCP::initOptionDefs();
 
 const OptionDefContainerPtr
-LibDHCP::getOptionDefs(const std::string& space) {
+LibDHCP::getOptionDefs(const string& space) {
     auto const& container = option_defs_.find(space);
     if (container != option_defs_.end()) {
         return (container->second);
@@ -120,7 +120,7 @@ LibDHCP::getVendorOptionDefs(const Option::Universe u, const uint32_t vendor_id)
 }
 
 OptionDefinitionPtr
-LibDHCP::getOptionDef(const std::string& space, const uint16_t code) {
+LibDHCP::getOptionDef(const string& space, const uint16_t code) {
     const OptionDefContainerPtr& defs = getOptionDefs(space);
     const OptionDefContainerTypeIndex& idx = defs->get<1>();
     const OptionDefContainerTypeRange& range = idx.equal_range(code);
@@ -132,7 +132,7 @@ LibDHCP::getOptionDef(const std::string& space, const uint16_t code) {
 }
 
 OptionDefinitionPtr
-LibDHCP::getOptionDef(const std::string& space, const std::string& name) {
+LibDHCP::getOptionDef(const string& space, const string& name) {
     const OptionDefContainerPtr& defs = getOptionDefs(space);
     const OptionDefContainerNameIndex& idx = defs->get<2>();
     const OptionDefContainerNameRange& range = idx.equal_range(name);
@@ -145,7 +145,7 @@ LibDHCP::getOptionDef(const std::string& space, const std::string& name) {
 
 OptionDefinitionPtr
 LibDHCP::getVendorOptionDef(const Option::Universe u, const uint32_t vendor_id,
-                            const std::string& name) {
+                            const string& name) {
     const OptionDefContainerPtr& defs = getVendorOptionDefs(u, vendor_id);
 
     if (!defs) {
@@ -183,7 +183,7 @@ LibDHCP::getVendorOptionDef(const Option::Universe u, const uint32_t vendor_id,
 }
 
 OptionDefinitionPtr
-LibDHCP::getRuntimeOptionDef(const std::string& space, const uint16_t code) {
+LibDHCP::getRuntimeOptionDef(const string& space, const uint16_t code) {
     OptionDefContainerPtr container = runtime_option_defs_.getValue().getItems(space);
     const OptionDefContainerTypeIndex& index = container->get<1>();
     const OptionDefContainerTypeRange& range = index.equal_range(code);
@@ -195,7 +195,7 @@ LibDHCP::getRuntimeOptionDef(const std::string& space, const uint16_t code) {
 }
 
 OptionDefinitionPtr
-LibDHCP::getRuntimeOptionDef(const std::string& space, const std::string& name) {
+LibDHCP::getRuntimeOptionDef(const string& space, const string& name) {
     OptionDefContainerPtr container = runtime_option_defs_.getValue().getItems(space);
     const OptionDefContainerNameIndex& index = container->get<2>();
     const OptionDefContainerNameRange& range = index.equal_range(name);
@@ -207,14 +207,14 @@ LibDHCP::getRuntimeOptionDef(const std::string& space, const std::string& name)
 }
 
 OptionDefContainerPtr
-LibDHCP::getRuntimeOptionDefs(const std::string& space) {
+LibDHCP::getRuntimeOptionDefs(const string& space) {
     return (runtime_option_defs_.getValue().getItems(space));
 }
 
 void
 LibDHCP::setRuntimeOptionDefs(const OptionDefSpaceContainer& defs) {
     OptionDefSpaceContainer defs_copy;
-    std::list<std::string> option_space_names = defs.getOptionSpaceNames();
+    list<string> option_space_names = defs.getOptionSpaceNames();
     for (auto const& name : option_space_names) {
         OptionDefContainerPtr container = defs.getItems(name);
         for (auto const& def : *container) {
@@ -241,7 +241,7 @@ LibDHCP::commitRuntimeOptionDefs() {
 }
 
 OptionDefinitionPtr
-LibDHCP::getLastResortOptionDef(const std::string& space, const uint16_t code) {
+LibDHCP::getLastResortOptionDef(const string& space, const uint16_t code) {
     OptionDefContainerPtr container = getLastResortOptionDefs(space);
     const OptionDefContainerTypeIndex& index = container->get<1>();
     const OptionDefContainerTypeRange& range = index.equal_range(code);
@@ -253,7 +253,7 @@ LibDHCP::getLastResortOptionDef(const std::string& space, const uint16_t code) {
 }
 
 OptionDefinitionPtr
-LibDHCP::getLastResortOptionDef(const std::string& space, const std::string& name) {
+LibDHCP::getLastResortOptionDef(const string& space, const string& name) {
     OptionDefContainerPtr container = getLastResortOptionDefs(space);
     const OptionDefContainerNameIndex& index = container->get<2>();
     const OptionDefContainerNameRange& range = index.equal_range(name);
@@ -265,7 +265,7 @@ LibDHCP::getLastResortOptionDef(const std::string& space, const std::string& nam
 }
 
 OptionDefContainerPtr
-LibDHCP::getLastResortOptionDefs(const std::string& space) {
+LibDHCP::getLastResortOptionDefs(const string& space) {
     if (space == DHCP4_OPTION_SPACE) {
         return getOptionDefs(LAST_RESORT_V4_OPTION_SPACE);
     }
@@ -274,7 +274,7 @@ LibDHCP::getLastResortOptionDefs(const std::string& space) {
 }
 
 bool
-LibDHCP::shouldDeferOptionUnpack(const std::string& space, const uint16_t code) {
+LibDHCP::shouldDeferOptionUnpack(const string& space, const uint16_t code) {
     return ((space == DHCP4_OPTION_SPACE) &&
             ((code == DHO_VENDOR_ENCAPSULATED_OPTIONS) ||
              ((code >= 224) && (code <= 254))));
@@ -305,9 +305,8 @@ LibDHCP::optionFactory(Option::Universe u,
 }
 
 size_t
-LibDHCP::unpackOptions6(const OptionBuffer& buf,
-                        const std::string& option_space,
-                        isc::dhcp::OptionCollection& options,
+LibDHCP::unpackOptions6(const OptionBuffer& buf, const string& option_space,
+                        OptionCollection& options,
                         size_t* relay_msg_offset /* = 0 */,
                         size_t* relay_msg_len /* = 0 */) {
     size_t offset = 0;
@@ -342,10 +341,10 @@ LibDHCP::unpackOptions6(const OptionBuffer& buf,
         }
 
         // Parse the option header
-        uint16_t opt_type = isc::util::readUint16(&buf[offset], 2);
+        uint16_t opt_type = readUint16(&buf[offset], 2);
         offset += 2;
 
-        uint16_t opt_len = isc::util::readUint16(&buf[offset], 2);
+        uint16_t opt_len = readUint16(&buf[offset], 2);
         offset += 2;
 
         if (offset + opt_len > length) {
@@ -454,10 +453,8 @@ LibDHCP::unpackOptions6(const OptionBuffer& buf,
 }
 
 size_t
-LibDHCP::unpackOptions4(const OptionBuffer& buf,
-                        const std::string& option_space,
-                        isc::dhcp::OptionCollection& options,
-                        std::list<uint16_t>& deferred,
+LibDHCP::unpackOptions4(const OptionBuffer& buf, const string& option_space,
+                        OptionCollection& options, list<uint16_t>& deferred,
                         bool check) {
     size_t offset = 0;
     size_t last_offset = 0;
@@ -686,7 +683,7 @@ LibDHCP::fuseOptions4(OptionCollection& options) {
 }
 
 void
-LibDHCP::extendVendorOptions4(isc::dhcp::OptionCollection& options) {
+LibDHCP::extendVendorOptions4(OptionCollection& options) {
     map<uint32_t, OptionCollection> vendors_data;
     auto const& it = options.find(DHO_VIVSO_SUBOPTIONS);
     // After calling fuseOptions4 there should be at most one option of
@@ -703,11 +700,12 @@ LibDHCP::extendVendorOptions4(isc::dhcp::OptionCollection& options) {
                           "Truncated vendor-specific information option"
                           << ", length=" << size);
             }
-            uint32_t vendor_id = isc::util::readUint32(&(*begin) + offset, data.size());
+            uint32_t vendor_id = readUint32(&data[offset], data.size());
             offset += 4;
             const OptionBuffer vendor_buffer(begin + offset, data.end());
             try {
-                offset += LibDHCP::unpackVendorOptions4(vendor_id, vendor_buffer, vendors_data[vendor_id]);
+                offset += LibDHCP::unpackVendorOptions4(vendor_id, vendor_buffer,
+                                                        vendors_data[vendor_id]);
             } catch (const SkipThisOptionError&) {
                 // Ignore this kind of error and continue.
             } catch (const Exception&) {
@@ -731,9 +729,8 @@ LibDHCP::extendVendorOptions4(isc::dhcp::OptionCollection& options) {
 }
 
 size_t
-LibDHCP::unpackVendorOptions6(const uint32_t vendor_id,
-                              const OptionBuffer& buf,
-                              isc::dhcp::OptionCollection& options) {
+LibDHCP::unpackVendorOptions6(const uint32_t vendor_id, const OptionBuffer& buf,
+                              OptionCollection& options) {
     size_t offset = 0;
     size_t length = buf.size();
 
@@ -757,10 +754,10 @@ LibDHCP::unpackVendorOptions6(const uint32_t vendor_id,
                       "Vendor option parse failed: truncated header");
         }
 
-        uint16_t opt_type = isc::util::readUint16(&buf[offset], 2);
+        uint16_t opt_type = readUint16(&buf[offset], 2);
         offset += 2;
 
-        uint16_t opt_len = isc::util::readUint16(&buf[offset], 2);
+        uint16_t opt_len = readUint16(&buf[offset], 2);
         offset += 2;
 
         if (offset + opt_len > length) {
@@ -829,7 +826,7 @@ LibDHCP::unpackVendorOptions6(const uint32_t vendor_id,
 
 size_t
 LibDHCP::unpackVendorOptions4(const uint32_t vendor_id, const OptionBuffer& buf,
-                              isc::dhcp::OptionCollection& options) {
+                              OptionCollection& options) {
     size_t offset = 0;
 
     // Get the list of standard option definitions.
@@ -934,8 +931,7 @@ LibDHCP::unpackVendorOptions4(const uint32_t vendor_id, const OptionBuffer& buf,
 }
 
 void
-LibDHCP::packOptions4(isc::util::OutputBuffer& buf,
-                      const OptionCollection& options,
+LibDHCP::packOptions4(OutputBuffer& buf, const OptionCollection& options,
                       bool top, bool check) {
     OptionCollection agent;
     OptionPtr end;
@@ -1115,16 +1111,14 @@ LibDHCP::splitOptions4(OptionCollection& options,
 }
 
 void
-LibDHCP::packOptions6(isc::util::OutputBuffer& buf,
-                      const OptionCollection& options) {
+LibDHCP::packOptions6(OutputBuffer& buf, const OptionCollection& options) {
     for (auto const& option : options) {
         option.second->pack(buf);
     }
 }
 
 void
-LibDHCP::OptionFactoryRegister(Option::Universe u,
-                               uint16_t opt_type,
+LibDHCP::OptionFactoryRegister(Option::Universe u, uint16_t opt_type,
                                Option::Factory* factory) {
     switch (u) {
     case Option::V6:
@@ -1166,7 +1160,7 @@ LibDHCP::OptionFactoryRegister(Option::Universe u,
 bool
 LibDHCP::initOptionDefs() {
     for (uint32_t i = 0; OPTION_DEF_PARAMS[i].optionDefParams; ++i) {
-        std::string space = OPTION_DEF_PARAMS[i].space;
+        string space = OPTION_DEF_PARAMS[i].space;
         option_defs_[space] = OptionDefContainerPtr(new OptionDefContainer);
         initOptionSpace(option_defs_[space],
                         OPTION_DEF_PARAMS[i].optionDefParams,
@@ -1177,7 +1171,7 @@ LibDHCP::initOptionDefs() {
 }
 
 uint32_t
-LibDHCP::optionSpaceToVendorId(const std::string& option_space) {
+LibDHCP::optionSpaceToVendorId(const string& option_space) {
     // 8 is a minimal length of "vendor-X" format
     if ((option_space.size() < 8) || (option_space.substr(0,7) != "vendor-")) {
         return (0);
@@ -1186,7 +1180,7 @@ LibDHCP::optionSpaceToVendorId(const std::string& option_space) {
     int64_t check;
     try {
         // text after "vendor-", supposedly numbers only
-        std::string x = option_space.substr(7);
+        string x = option_space.substr(7);
 
         check = boost::lexical_cast<int64_t>(x);
     } catch (const boost::bad_lexical_cast &) {
@@ -1202,8 +1196,7 @@ LibDHCP::optionSpaceToVendorId(const std::string& option_space) {
 }
 
 void
-initOptionSpace(OptionDefContainerPtr& defs,
-                const OptionDefParams* params,
+initOptionSpace(OptionDefContainerPtr& defs, const OptionDefParams* params,
                 size_t params_size) {
     // Container holding vendor options is typically not initialized, as it
     // is held in map of null pointers. We need to initialize here in this
@@ -1215,7 +1208,7 @@ initOptionSpace(OptionDefContainerPtr& defs,
     }
 
     for (size_t i = 0; i < params_size; ++i) {
-        std::string encapsulates(params[i].encapsulates);
+        string encapsulates(params[i].encapsulates);
         if (!encapsulates.empty() && params[i].array) {
             isc_throw(isc::BadValue, "invalid standard option definition: "
                       << "option with code '" << params[i].code