From: Marcin Siodelski Date: Wed, 26 Jul 2017 11:56:49 +0000 (+0200) Subject: [5315] Check for subnet prefix duplicates when subnet is added. X-Git-Tag: trac5124a_base~5^2~6 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=6094638e34c853d09148dc26b6747a4869bdf558;p=thirdparty%2Fkea.git [5315] Check for subnet prefix duplicates when subnet is added. --- diff --git a/src/lib/dhcpsrv/cfg_subnets4.cc b/src/lib/dhcpsrv/cfg_subnets4.cc index f5fcd232c0..78ca8339c3 100644 --- a/src/lib/dhcpsrv/cfg_subnets4.cc +++ b/src/lib/dhcpsrv/cfg_subnets4.cc @@ -23,12 +23,17 @@ namespace dhcp { void CfgSubnets4::add(const Subnet4Ptr& subnet) { - /// @todo: Check that this new subnet does not cross boundaries of any - /// other already defined subnet. - if (isDuplicate(*subnet)) { + if (getBySubnetId(subnet->getID())) { isc_throw(isc::dhcp::DuplicateSubnetID, "ID of the new IPv4 subnet '" << subnet->getID() << "' is already in use"); + + } else if (getByPrefix(subnet->toText())) { + /// @todo: Check that this new subnet does not cross boundaries of any + /// other already defined subnet. + isc_throw(isc::dhcp::DuplicateSubnetID, "subnet with the prefix of '" + << subnet->toText() << "' already exists"); } + LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_ADD_SUBNET4) .arg(subnet->toText()); subnets_.push_back(subnet); @@ -246,17 +251,6 @@ CfgSubnets4::selectSubnet(const IOAddress& address, return (Subnet4Ptr()); } -bool -CfgSubnets4::isDuplicate(const Subnet4& subnet) const { - for (Subnet4Collection::const_iterator subnet_it = subnets_.begin(); - subnet_it != subnets_.end(); ++subnet_it) { - if ((*subnet_it)->getID() == subnet.getID()) { - return (true); - } - } - return (false); -} - void CfgSubnets4::removeStatistics() { using namespace isc::stats; diff --git a/src/lib/dhcpsrv/cfg_subnets4.h b/src/lib/dhcpsrv/cfg_subnets4.h index 215060e346..ac609e3b89 100644 --- a/src/lib/dhcpsrv/cfg_subnets4.h +++ b/src/lib/dhcpsrv/cfg_subnets4.h @@ -235,14 +235,6 @@ public: private: - /// @brief Checks that the IPv4 subnet with the given id already exists. - /// - /// @param subnet Subnet for which this function will check if the other - /// subnet with equal id already exists. - /// - /// @return true if the duplicate subnet exists. - bool isDuplicate(const Subnet4& subnet) const; - /// @brief A container for IPv4 subnets. Subnet4Collection subnets_; diff --git a/src/lib/dhcpsrv/cfg_subnets6.cc b/src/lib/dhcpsrv/cfg_subnets6.cc index 111fed0997..468b563503 100644 --- a/src/lib/dhcpsrv/cfg_subnets6.cc +++ b/src/lib/dhcpsrv/cfg_subnets6.cc @@ -22,12 +22,17 @@ namespace dhcp { void CfgSubnets6::add(const Subnet6Ptr& subnet) { - /// @todo: Check that this new subnet does not cross boundaries of any - /// other already defined subnet. - if (isDuplicate(*subnet)) { + if (getBySubnetId(subnet->getID())) { isc_throw(isc::dhcp::DuplicateSubnetID, "ID of the new IPv6 subnet '" << subnet->getID() << "' is already in use"); + + } else if (getByPrefix(subnet->toText())) { + /// @todo: Check that this new subnet does not cross boundaries of any + /// other already defined subnet. + isc_throw(isc::dhcp::DuplicateSubnetID, "subnet with the prefix of '" + << subnet->toText() << "' already exists"); } + LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_ADD_SUBNET6) .arg(subnet->toText()); subnets_.push_back(subnet); diff --git a/src/lib/dhcpsrv/cfg_subnets6.h b/src/lib/dhcpsrv/cfg_subnets6.h index 0c27928926..b8e70a9610 100644 --- a/src/lib/dhcpsrv/cfg_subnets6.h +++ b/src/lib/dhcpsrv/cfg_subnets6.h @@ -241,14 +241,6 @@ private: selectSubnet(const OptionPtr& interface_id, const ClientClasses& client_classes) const; - /// @brief Checks that the IPv6 subnet with the given id already exists. - /// - /// @param subnet Subnet for which this function will check if the other - /// subnet with equal id already exists. - /// - /// @return true if the duplicate subnet exists. - bool isDuplicate(const Subnet6& subnet) const; - /// @brief A container for IPv6 subnets. Subnet6Collection subnets_;