Parcourir la source

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

Marcin Siodelski il y a 7 ans
Parent
commit
6094638e34

+ 8 - 14
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;

+ 0 - 8
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_;
 

+ 8 - 3
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);

+ 0 - 8
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_;