]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5315] Check for subnet prefix duplicates when subnet is added.
authorMarcin Siodelski <marcin@isc.org>
Wed, 26 Jul 2017 11:56:49 +0000 (13:56 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Tue, 15 Aug 2017 12:00:56 +0000 (14:00 +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 f5fcd232c0c4149fabaa48f69e17c7aca763e111..78ca8339c35732f9e0424fc86f342a7f67799427 100644 (file)
@@ -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;
index 215060e346719ab2a9ce109ac57a8ff4bc6bf528..ac609e3b89b67a07e3ffb81e1a53e57546e1d537 100644 (file)
@@ -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_;
 
index 111fed0997523bda5b6e859908509314bd488533..468b563503d82c2237e2d1eeb58754437552a45d 100644 (file)
@@ -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);
index 0c279289264f4a1e86b258e1990f8beb9790c910..b8e70a961004887141e303aaedf78e6bef1ad507 100644 (file)
@@ -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_;