Commit 6094638e authored by Marcin Siodelski's avatar Marcin Siodelski Committed by Tomek Mrugalski

[5315] Check for subnet prefix duplicates when subnet is added.

parent 5e0bc0d7
......@@ -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;
......
......@@ -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_;
......
......@@ -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);
......
......@@ -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_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment