]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[259-libyang-adapt-authoritative] Wrote methods to remove not hyet supported authorit... 259-libyang-adapt-authoritative
authorFrancis Dupont <fdupont@isc.org>
Thu, 8 Nov 2018 11:43:33 +0000 (12:43 +0100)
committerFrancis Dupont <fdupont@isc.org>
Thu, 8 Nov 2018 11:43:33 +0000 (12:43 +0100)
src/lib/yang/adaptor_config.cc
src/lib/yang/adaptor_config.h

index adca8e27b00eaa887ef16c78d002bd3290031c14..cca5b7c8be613bbed15874af0ed60dcc4fa722d4 100644 (file)
@@ -522,6 +522,52 @@ AdaptorConfig::sanitizeRelaySuppliedOptions(ConstElementPtr dhcp) {
     mutable_dhcp->remove("relay-supplied-options");
 }
 
+void
+AdaptorConfig::removeAuthoritativeSubnets(ConstElementPtr subnets) {
+    if (!subnets || subnets->empty()) {
+        // nothing to do here.
+        return;
+    }
+
+    for (size_t i = 0; i < subnets->size(); ++i) {
+        ElementPtr subnet = subnets->getNonConst(i);
+        ConstElementPtr auth = subnet->get("authoritative");
+        if (auth) {
+            subnet->remove("authoritative");
+        }
+    }
+}
+
+void
+AdaptorConfig::removeAuthoritativeSharedNetworks(ConstElementPtr networks) {
+    if (!networks || networks->empty()) {
+        // nothing to do here.
+        return;
+    }
+
+    for (size_t i = 0; i < networks->size(); ++i) {
+        ElementPtr network = networks->getNonConst(i);
+        ConstElementPtr auth = network->get("authoritative");
+        if (auth) {
+            network->remove("authoritative");
+        }
+        removeAuthoritativeSubnets(network->get("subnet4"));
+    }
+}
+
+void
+AdaptorConfig::removeAuthoritative(ConstElementPtr dhcp) {
+    removeAuthoritativeSubnets(dhcp->get("subnet4"));
+    removeAuthoritativeSharedNetworks(dhcp->get("shared-networks"));
+    ConstElementPtr auth = dhcp->get("authoritative");
+    if (!auth) {
+        // Done.
+        return;
+    }
+    ElementPtr mutable_dhcp = boost::const_pointer_cast<Element>(dhcp);
+    mutable_dhcp->remove("authoritative");
+}
+
 void
 AdaptorConfig::preProcess(ElementPtr dhcp, const string& subsel,
                           const string& space) {
@@ -608,7 +654,9 @@ AdaptorConfig::preProcess(ElementPtr dhcp, const string& subsel,
 
     sanitizeDatabase(dhcp);
 
-    if (space == DHCP6_SPACE) {
+    if (space == DHCP4_SPACE) {
+        removeAuthoritative(dhcp);
+    } else if (space == DHCP6_SPACE) {
         sanitizeRelaySuppliedOptions(dhcp);
     }
 }
index 22c23f15ad0673fe0fb7d2541845ed34ab06c836..85f5cff6352e0ba1eeb5a681b7fb82eff7715a88 100644 (file)
@@ -275,6 +275,26 @@ protected:
     /// @param dhcp The DHCPv6 server.
     static void sanitizeRelaySuppliedOptions(isc::data::ConstElementPtr dhcp);
 
+    /// @brief Remove authoritative flag from a subnet list.
+    ///
+    /// @param subnets The subnet list.
+    static void removeAuthoritativeSubnets(isc::data::ConstElementPtr subnets);
+
+    /// @brief Remove authoritative flag from a shared network list.
+    ///
+    /// Remove authoritative flag in each shared network and its
+    /// subnet4 children.
+    ///
+    /// @param networks The shared network list.
+    static void removeAuthoritativeSharedNetworks(isc::data::ConstElementPtr networks);
+
+    /// @brief Remove authoritative flags.
+    ///
+    /// Remove global, shared network and subnet4 authoritative flags.
+    ///
+    /// @param dhcp The DHCPv4 server.
+    static void removeAuthoritative(isc::data::ConstElementPtr dhcp);
+
     /// @brief Pre process a configuration.
     ///
     /// Assign subnet IDs, check and set default in options, etc.