Skip to content

Commit

Permalink
[#3262] Optimized getSubnet() (#3268 1st point)
Browse files Browse the repository at this point in the history
  • Loading branch information
fxdupont authored and andrei-pavel committed Mar 18, 2024
1 parent 8491e56 commit 3c217d8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 40 deletions.
20 changes: 4 additions & 16 deletions src/lib/dhcpsrv/cfg_subnets4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/lib/dhcpsrv/cfg_subnets4.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ class CfgSubnets4 : public isc::data::CfgToElement {
///
/// @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.
Expand Down Expand Up @@ -221,11 +223,9 @@ class CfgSubnets4 : public isc::data::CfgToElement {

/// @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.
Expand Down
20 changes: 4 additions & 16 deletions src/lib/dhcpsrv/cfg_subnets6.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/lib/dhcpsrv/cfg_subnets6.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ class CfgSubnets6 : public isc::data::CfgToElement {
///
/// @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.
Expand Down Expand Up @@ -203,11 +205,9 @@ class CfgSubnets6 : public isc::data::CfgToElement {

/// @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.
Expand Down

0 comments on commit 3c217d8

Please sign in to comment.