]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[465-add-subnet4-update-and-subnet6-update-commands-to-subnet-cmds-hook] Added cfg_su...
authorFrancis Dupont <fdupont@isc.org>
Fri, 8 Mar 2019 04:12:59 +0000 (05:12 +0100)
committerTomek Mrugalski <tomek@isc.org>
Fri, 19 Apr 2019 10:39:47 +0000 (06:39 -0400)
src/lib/dhcpsrv/cfg_subnets4.cc
src/lib/dhcpsrv/cfg_subnets4.h
src/lib/dhcpsrv/cfg_subnets6.cc
src/lib/dhcpsrv/cfg_subnets6.h
src/lib/dhcpsrv/dhcpsrv_messages.mes

index f7a96efb1f0be87d1a5ff6683f21c64b0db39c6e..244b39f29045a55148de4ef18e24c85eb6094edc 100644 (file)
@@ -41,6 +41,27 @@ CfgSubnets4::add(const Subnet4Ptr& subnet) {
     subnets_.push_back(subnet);
 }
 
+Subnet4Ptr
+CfgSubnets4::replace(const Subnet4Ptr& subnet) {
+    // Get the subnet with the same ID.
+    const SubnetID& subnet_id = subnet->getID();
+    auto& index = subnets_.template get<SubnetSubnetIdIndexTag>();
+    auto subnet_it = index.find(subnet_id);
+    if (subnet_it == index.end()) {
+        isc_throw(BadValue, "ID of the IPv4 subnet '" << subnet_id
+                  << "' is not in use");
+    }
+    bool ret = index.replace(subnet_it, subnet);
+
+    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_UPDATE_SUBNET4)
+        .arg(subnet_id).arg(ret);
+    if (ret) {
+        return (*subnet_it);
+    } else {
+        return (Subnet4Ptr());
+    }
+}
+
 void
 CfgSubnets4::del(const ConstSubnet4Ptr& subnet) {
     del(subnet->getID());
index aab236e97b255deb30012f514ad9cb23b2e4dace..31a5a1bc8751fab4ff1d80673e2ad2df362109a5 100644 (file)
@@ -41,6 +41,16 @@ public:
     /// duplicates id of an existing subnet.
     void add(const Subnet4Ptr& subnet);
 
+    /// @brief Replaces subnet in the configuration.
+    ///
+    /// This method replaces a subnet by another subnet with the same ID.
+    /// The prefix should be the same too.
+    ///
+    /// @param subnet Pointer to the subnet being updated.
+    /// @throw BadValue if the subnet to update does not exit.
+    /// @return Pointer to the replaced subnet or NULL if it failed.
+    Subnet4Ptr replace(const Subnet4Ptr& subnet);
+
     /// @brief Removes subnet from the configuration.
     ///
     /// @param subnet Pointer to the subnet to be removed.
index 3167e3b7b459be4d2a9fd31ab4c1010289b51f46..210ad8a9b6e50fdd2f8fa4d03a76b35ece25c93e 100644 (file)
@@ -41,6 +41,27 @@ CfgSubnets6::add(const Subnet6Ptr& subnet) {
     subnets_.push_back(subnet);
 }
 
+Subnet6Ptr
+CfgSubnets6::replace(const Subnet6Ptr& subnet) {
+    // Get the subnet with the same ID.
+    const SubnetID& subnet_id = subnet->getID();
+    auto& index = subnets_.template get<SubnetSubnetIdIndexTag>();
+    auto subnet_it = index.find(subnet_id);
+    if (subnet_it == index.end()) {
+        isc_throw(BadValue, "ID of the IPv6 subnet '" << subnet_id
+                  << "' is not in use");
+    }
+    bool ret = index.replace(subnet_it, subnet);
+
+    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, DHCPSRV_CFGMGR_UPDATE_SUBNET6)
+        .arg(subnet_id).arg(ret);
+    if (ret) {
+        return (*subnet_it);
+    } else {
+        return (Subnet6Ptr());
+    }
+}
+
 void
 CfgSubnets6::del(const ConstSubnet6Ptr& subnet) {
     del(subnet->getID());
index caf98e4ac30ee9a0abe69d987f8bb3ddf84fd2c8..1abfc24c78ac83aa7e77fa0bca2551d8871a774a 100644 (file)
@@ -42,6 +42,16 @@ public:
     /// duplicates id of an existing subnet.
     void add(const Subnet6Ptr& subnet);
 
+    /// @brief Replaces subnet in the configuration.
+    ///
+    /// This method replaces a subnet by another subnet with the same ID.
+    /// The prefix should be the same too.
+    ///
+    /// @param subnet Pointer to the subnet being updated.
+    /// @throw BadValue if the subnet to update does not exit.
+    /// @return Pointer to the replaced subnet or NULL if it failed.
+    Subnet6Ptr replace(const Subnet6Ptr& subnet);
+
     /// @brief Removes subnet from the configuration.
     ///
     /// @param subnet Pointer to the subnet to be removed.
index 810d695f217b2d58ea55c28dc57d092645bca2e5..0dbe55b0ce11f9ecdbe98e3f0de4e05f89a77717 100644 (file)
@@ -100,6 +100,16 @@ contains "ip-address" rather than its replacement, "ip-addresses".
 The server will still honor the value but users are encouraged to
 move to the new list parameter.
 
+% DHCPSRV_CFGMGR_UPDATE_SUBNET4 updating subnet %1 (result %2)
+A debug message reported when the DHCP configuration manager is updating the
+specified IPv4 subnet to its database. Subnet ID and result (expected to
+be true) are displayed.
+
+% DHCPSRV_CFGMGR_UPDATE_SUBNET6 updating subnet %1 (result %2)
+A debug message reported when the DHCP configuration manager is replacing the
+specified IPv6 subnet to its database.  Subnet ID and result (expected to
+be true) are displayed.
+
 % DHCPSRV_CFGMGR_SOCKET_RAW_UNSUPPORTED use of raw sockets is unsupported on this OS, UDP sockets will be used
 This warning message is logged when the user specified that the
 DHCPv4 server should use the raw sockets to receive the DHCP