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);
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;
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_;
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);
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_;