]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3262] Optimized getSubnet() (#3268 1st point)
authorFrancis Dupont <fdupont@isc.org>
Tue, 12 Mar 2024 15:24:10 +0000 (16:24 +0100)
committerAndrei Pavel <andrei@isc.org>
Mon, 18 Mar 2024 09:33:37 +0000 (11:33 +0200)
src/lib/dhcpsrv/cfg_subnets4.cc
src/lib/dhcpsrv/cfg_subnets4.h
src/lib/dhcpsrv/cfg_subnets6.cc
src/lib/dhcpsrv/cfg_subnets6.h

index 5b91f3c9164cf9392b678437ea4b8f978ed29a70..681f4c36f06283c607d46270bfe4d08cbff92eaf 100644 (file)
@@ -183,13 +183,6 @@ CfgSubnets4::merge(CfgOptionDefPtr cfg_def, CfgSharedNetworks4Ptr networks,
     }
 }
 
-ConstSubnet4Ptr
-CfgSubnets4::getBySubnetId(const SubnetID& subnet_id) const {
-    auto const& index = subnets_.get<SubnetSubnetIdIndexTag>();
-    auto subnet_it = index.find(subnet_id);
-    return ((subnet_it != index.cend()) ? (*subnet_it) : ConstSubnet4Ptr());
-}
-
 ConstSubnet4Ptr
 CfgSubnets4::getByPrefix(const std::string& subnet_text) const {
     auto const& index = subnets_.get<SubnetPrefixIndexTag>();
@@ -459,15 +452,10 @@ CfgSubnets4::selectSubnet(const std::string& iface,
 }
 
 Subnet4Ptr
-CfgSubnets4::getSubnet(const SubnetID id) const {
-    /// @todo: Once this code is migrated to multi-index container, use
-    /// an index rather than full scan.
-    for (auto const& subnet : subnets_) {
-        if (subnet->getID() == id) {
-            return (subnet);
-        }
-    }
-    return (Subnet4Ptr());
+CfgSubnets4::getSubnet(const SubnetID subnet_id) const {
+    auto const& index = subnets_.get<SubnetSubnetIdIndexTag>();
+    auto subnet_it = index.find(subnet_id);
+    return ((subnet_it != index.cend()) ? (*subnet_it) : Subnet4Ptr());
 }
 
 Subnet4Ptr
index 57b7e00e688f643f28addd4d5f6f40f9e5ef8a44..5d2519b9e60df04ac82f18ea764372a771430448 100644 (file)
@@ -135,7 +135,9 @@ public:
     ///
     /// @return Pointer to the @c Subnet4 object or null pointer if such
     /// subnet doesn't exist.
-    ConstSubnet4Ptr getBySubnetId(const SubnetID& subnet_id) const;
+    ConstSubnet4Ptr getBySubnetId(const SubnetID& subnet_id) const {
+        return (getSubnet(subnet_id));
+    }
 
     /// @brief Returns const pointer to a subnet which matches the specified
     /// prefix in the canonical form.
@@ -221,11 +223,9 @@ public:
 
     /// @brief Returns subnet with specified subnet-id value
     ///
-    /// Warning: this method uses full scan. Its use is not recommended for
-    /// packet processing.
     /// Please use @ref getBySubnetId instead when possible.
     ///
-    /// @return Subnet (or NULL)
+    /// @return Subnet (or null)
     Subnet4Ptr getSubnet(const SubnetID id) const;
 
     /// @brief Returns a pointer to a subnet if provided address is in its range.
index 0b77ef43f43401b651382a44a57849a2a1523d3c..704cd42cb92f7ba0e6f75f565d672fc0c3657739 100644 (file)
@@ -185,13 +185,6 @@ CfgSubnets6::merge(CfgOptionDefPtr cfg_def, CfgSharedNetworks6Ptr networks,
     }
 }
 
-ConstSubnet6Ptr
-CfgSubnets6::getBySubnetId(const SubnetID& subnet_id) const {
-    auto const& index = subnets_.get<SubnetSubnetIdIndexTag>();
-    auto subnet_it = index.find(subnet_id);
-    return ((subnet_it != index.cend()) ? (*subnet_it) : ConstSubnet6Ptr());
-}
-
 ConstSubnet6Ptr
 CfgSubnets6::getByPrefix(const std::string& subnet_text) const {
     auto const& index = subnets_.get<SubnetPrefixIndexTag>();
@@ -375,15 +368,10 @@ CfgSubnets6::selectSubnet(const OptionPtr& interface_id,
 }
 
 Subnet6Ptr
-CfgSubnets6::getSubnet(const SubnetID id) const {
-    /// @todo: Once this code is migrated to multi-index container, use
-    /// an index rather than full scan.
-    for (auto const& subnet : subnets_) {
-        if (subnet->getID() == id) {
-            return (subnet);
-        }
-    }
-    return (Subnet6Ptr());
+CfgSubnets6::getSubnet(const SubnetID subnet_id) const {
+    auto const& index = subnets_.get<SubnetSubnetIdIndexTag>();
+    auto subnet_it = index.find(subnet_id);
+    return ((subnet_it != index.cend()) ? (*subnet_it) : Subnet6Ptr());
 }
 
 SubnetIDSet
index ddf17d6499d6bd753bf8e506500c54aaac415a33..9e618b4422258b7e8e99f6437faff9481854a06d 100644 (file)
@@ -136,7 +136,9 @@ public:
     ///
     /// @return Pointer to the @c Subnet6 object or null pointer if such
     /// subnet doesn't exist.
-    ConstSubnet6Ptr getBySubnetId(const SubnetID& subnet_id) const;
+    ConstSubnet6Ptr getBySubnetId(const SubnetID& subnet_id) const {
+        return (getSubnet(subnet_id));
+    }
 
     /// @brief Returns const pointer to a subnet which matches the specified
     /// prefix in the canonical form.
@@ -203,11 +205,9 @@ public:
 
     /// @brief Returns subnet with specified subnet-id value
     ///
-    /// Warning: this method uses full scan. Its use is not recommended for
-    /// packet processing.
     /// Please use @ref getBySubnetId instead when possible.
     ///
-    /// @return Subnet (or NULL)
+    /// @return Subnet (or null)
     Subnet6Ptr getSubnet(const SubnetID id) const;
 
     /// @brief Selects the subnet using a specified address.