]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[65-libyang-simplify-update-models] Implemented authoritative
authorFrancis Dupont <fdupont@isc.org>
Mon, 19 Nov 2018 15:55:03 +0000 (16:55 +0100)
committerFrancis Dupont <fdupont@isc.org>
Thu, 22 Nov 2018 22:13:47 +0000 (17:13 -0500)
src/lib/yang/adaptor_config.cc
src/lib/yang/adaptor_config.h
src/lib/yang/models/kea-dhcp4-server.yang
src/lib/yang/translator_config.cc
src/lib/yang/translator_shared_network.cc
src/lib/yang/translator_subnet.cc

index cca5b7c8be613bbed15874af0ed60dcc4fa722d4..adca8e27b00eaa887ef16c78d002bd3290031c14 100644 (file)
@@ -522,52 +522,6 @@ 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) {
@@ -654,9 +608,7 @@ AdaptorConfig::preProcess(ElementPtr dhcp, const string& subsel,
 
     sanitizeDatabase(dhcp);
 
-    if (space == DHCP4_SPACE) {
-        removeAuthoritative(dhcp);
-    } else if (space == DHCP6_SPACE) {
+    if (space == DHCP6_SPACE) {
         sanitizeRelaySuppliedOptions(dhcp);
     }
 }
index 85f5cff6352e0ba1eeb5a681b7fb82eff7715a88..22c23f15ad0673fe0fb7d2541845ed34ab06c836 100644 (file)
@@ -275,26 +275,6 @@ 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.
index e997dfbede44d6344f1801fb419631e6f310aef1..3ae0a6f743973d4026d3d7ada42e1e3d792e39f9 100644 (file)
@@ -8,12 +8,15 @@ module kea-dhcp4-server {
   }
   import kea-types {
     prefix kea;
+    revision-date 2018-09-14;
   }
   import kea-dhcp-types {
     prefix dhcp;
+    revision-date 2018-09-14;
   }
   import kea-logging {
     prefix logging;
+    revision-date 2018-09-14;
   }
 
   organization "Internet Systems Consortium";
@@ -21,7 +24,7 @@ module kea-dhcp4-server {
   description "This model defines a YANG data model that can be
                used to configure and manage a Kea DHCPv4 server.";
 
-  revision 2018-09-14 {
+  revision 2018-11-11 {
     description "Initial revision";
     reference "";
   }
@@ -88,6 +91,15 @@ module kea-dhcp4-server {
     }
   }
 
+  grouping authoritative {
+    description "Authoritative grouping.";
+    leaf authoritative {
+      type boolean;
+      description "NAK requests for unknown clients. If set to false
+                   ignore them.";
+      }
+  }
+
   grouping relay {
     description "Relay grouping.";
     leaf-list ip-addresses {
@@ -201,6 +213,7 @@ module kea-dhcp4-server {
         type inet:ipv6-prefix;
         description "Subnet DHCPv4-over-DHCPv6 IPv6 prefix.";
       }
+      uses authoritative;
       uses dhcp:subnet-user-context;
     }
   }
@@ -312,6 +325,7 @@ module kea-dhcp4-server {
           description "Optional information about relay agent.";
           uses relay;
         }
+        uses authoritative;
         uses dhcp:network-reservation-mode;
         uses dhcp:network-client-class;
         uses dhcp:network-require-client-classes;
@@ -405,6 +419,7 @@ module kea-dhcp4-server {
         description "Global host reservations.";
       }
     }
+    uses authoritative;
   }
 
   container logging {
index 1f5c2207ef86f15185520e3d84345ff40776a375..a2798e377df2f56dc39714f4666ab50aa551286c 100644 (file)
@@ -299,6 +299,7 @@ TranslatorConfig::getServerKeaDhcp4() {
     getParam(result, xpath, "next-server");
     getParam(result, xpath, "server-hostname");
     getParam(result, xpath, "boot-file-name");
+    getParam(result, xpath, "authoritative");
     return (result);
 }
 
@@ -725,6 +726,10 @@ TranslatorConfig::setServerKeaDhcp4(ConstElementPtr elem) {
     if (boot) {
         setItem(xpath + "/boot-file-name", boot, SR_STRING_T);
     }
+    ConstElementPtr auth = elem->get("authoritative");
+    if (auth) {
+        setItem(xpath + "/authoritative", auth, SR_BOOL_T);
+    }
 }
 
 void
index 0774b8a9abf2b148cdfa5da6e52b4482066f9cbe..e9936f9ecc46efc443129d22a20e7517c2d68d9f 100644 (file)
@@ -128,6 +128,10 @@ TranslatorSharedNetwork::getSharedNetworkKea(const string& xpath,
         if (match) {
             result->set("match-client-id", match);
         }
+        ConstElementPtr auth = getItem(xpath + "/authoritative");
+        if (auth) {
+            result->set("authoritative", auth);
+        }
         ConstElementPtr next = getItem(xpath + "/next-server");
         if (next) {
             result->set("next-server", next);
@@ -244,6 +248,10 @@ TranslatorSharedNetwork::setSharedNetworkKea(const string& xpath,
         if (match) {
             setItem(xpath + "/match-client-id", match, SR_BOOL_T);
         }
+        ConstElementPtr auth = elem->get("authoritative");
+        if (auth) {
+            setItem(xpath + "/authoritative", auth, SR_BOOL_T);
+        }
         ConstElementPtr next = elem->get("next-server");
         if (next) {
             setItem(xpath + "/next-server", next, SR_STRING_T);
index c7849edf18bac322fbc97b983a9a93eb8308fe55..526f1410df9c23b5ef80b634e0f70b3506ab517c 100644 (file)
@@ -179,6 +179,10 @@ TranslatorSubnet::getSubnetKea(const string& xpath) {
         if (match) {
             result->set("match-client-id", match);
         }
+        ConstElementPtr auth = getItem(xpath + "/authoritative");
+        if (auth) {
+            result->set("authoritative", auth);
+        }
         ConstElementPtr next = getItem(xpath + "/next-server");
         if (next) {
             result->set("next-server", next);
@@ -349,6 +353,10 @@ TranslatorSubnet::setSubnetKea(const string& xpath, ConstElementPtr elem) {
         if (match) {
             setItem(xpath + "/match-client-id", match, SR_BOOL_T);
         }
+        ConstElementPtr auth = elem->get("authoritative");
+        if (auth) {
+            setItem(xpath + "/authoritative", auth, SR_BOOL_T);
+        }
         ConstElementPtr next = elem->get("next-server");
         if (next) {
             setItem(xpath + "/next-server", next, SR_STRING_T);