From 7454d2d002c73e72a1e446dd1d54d71b8229d443 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Thu, 8 Nov 2018 12:43:33 +0100 Subject: [PATCH] [259-libyang-adapt-authoritative] Wrote methods to remove not hyet supported authoritative flags --- src/lib/yang/adaptor_config.cc | 50 +++++++++++++++++++++++++++++++++- src/lib/yang/adaptor_config.h | 20 ++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/lib/yang/adaptor_config.cc b/src/lib/yang/adaptor_config.cc index adca8e27b0..cca5b7c8be 100644 --- a/src/lib/yang/adaptor_config.cc +++ b/src/lib/yang/adaptor_config.cc @@ -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(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); } } diff --git a/src/lib/yang/adaptor_config.h b/src/lib/yang/adaptor_config.h index 22c23f15ad..85f5cff635 100644 --- a/src/lib/yang/adaptor_config.h +++ b/src/lib/yang/adaptor_config.h @@ -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. -- GitLab