for (ConstElementPtr network : networks->listValue()) {
ConstElementPtr subnets = network->get(subsel);
- if (subnets && (subnets->size() > 0)) {
- for (size_t i = 0; i < subnets->size(); ++i) {
- ElementPtr subnet = subnets->getNonConst(i);
- assignID(subnet, set, next);
- }
+ if (!subnets || subnets->empty()) {
+ continue;
+ }
+
+ for (size_t i = 0; i < subnets->size(); ++i) {
+ ElementPtr subnet = subnets->getNonConst(i);
+ assignID(subnet, set, next);
}
}
}
}
void
-AdaptorConfig::optionDefList(ConstElementPtr defs,
- const string& space,
- OptionCodes& codes) {
+AdaptorConfig::sanitizeOptionDefList(ConstElementPtr defs,
+ const string& space,
+ OptionCodes& codes) {
if (!defs || defs->empty()) {
// nothing to do here.
return;
}
void
-AdaptorConfig::optionDataList(ConstElementPtr options,const string& space,
- const OptionCodes& codes) {
+AdaptorConfig::sanitizeOptionDataList(ConstElementPtr options,
+ const string& space,
+ const OptionCodes& codes) {
if (!options || options->empty()) {
// nothing to do here.
return;
}
void
-AdaptorConfig::optionClasses(ConstElementPtr classes, const string& space,
- OptionCodes& codes) {
+AdaptorConfig::sanitizeOptionClasses(ConstElementPtr classes,
+ const string& space,
+ OptionCodes& codes) {
if (!classes || classes->empty()) {
// nothing to do here.
return;
}
+ // For every client class defined...
for (size_t i = 0; i < classes->size(); ++i) {
ElementPtr cclass = classes->getNonConst(i);
+
if (space == DHCP4_SPACE) {
ConstElementPtr options = cclass->get("option-def");
if (options) {
- if (options->size() > 0) {
- optionDefList(options, space, codes);
+ if (!options->empty()) {
+ // If present, sanitize it.
+ sanitizeOptionDefList(options, space, codes);
} else {
+ // If empty, remove it.
cclass->remove("option-def");
}
}
}
+
+ // also sanitize option data.
ConstElementPtr options = cclass->get("option-data");
if (options) {
- if (options->size() > 0) {
- optionDataList(options, space, codes);
+ if (!options->empty()) {
+ // If present, sanitize it.
+ sanitizeOptionDataList(options, space, codes);
} else {
+ // If empty, remove it.
cclass->remove("option-data");
}
}
}
void
-AdaptorConfig::optionPools(ConstElementPtr pools, const string& space,
- const OptionCodes& codes) {
+AdaptorConfig::sanitizeOptionPools(ConstElementPtr pools, const string& space,
+ const OptionCodes& codes) {
if (!pools || pools->empty()) {
// nothing to do here.
return;
ElementPtr pool = pools->getNonConst(i);
ConstElementPtr options = pool->get("option-data");
if (options) {
- if (options->size() > 0) {
- optionDataList(options, space, codes);
+ if (!options->empty()) {
+ sanitizeOptionDataList(options, space, codes);
} else {
pool->remove("option-data");
}
}
void
-AdaptorConfig::optionHosts(ConstElementPtr hosts, const string& space,
- const OptionCodes& codes) {
+AdaptorConfig::sanitizeOptionHosts(ConstElementPtr hosts, const string& space,
+ const OptionCodes& codes) {
if (!hosts || hosts->empty()) {
// nothing to do here.
return;
ElementPtr host = hosts->getNonConst(i);
ConstElementPtr options = host->get("option-data");
if (options) {
- if (options->size() > 0) {
- optionDataList(options, space, codes);
+ if (!options->empty()) {
+ sanitizeOptionDataList(options, space, codes);
} else {
host->remove("option-data");
}
}
void
-AdaptorConfig::optionSubnets(ConstElementPtr subnets, const string& space,
- const OptionCodes& codes) {
+AdaptorConfig::sanitizeOptionSubnets(ConstElementPtr subnets,
+ const string& space,
+ const OptionCodes& codes) {
if (!subnets || subnets->empty()) {
// nothing to do here.
return;
// Let's try to sanitize option-data first.
ConstElementPtr options = subnet->get("option-data");
if (options) {
- if (options->size() > 0) {
- optionDataList(options, space, codes);
+ if (!options->empty()) {
+ sanitizeOptionDataList(options, space, codes);
} else {
subnet->remove("option-data");
}
// Then try to sanitize pools.
ConstElementPtr pools = subnet->get("pools");
if (pools) {
- if (pools->size() > 0) {
- optionPools(pools, space, codes);
+ if (!pools->empty()) {
+ sanitizeOptionPools(pools, space, codes);
} else {
subnet->remove("pools");
}
if (space == DHCP6_SPACE) {
ConstElementPtr pools = subnet->get("pd-pools");
if (pools) {
- if (pools->size() > 0) {
- optionPools(pools, space, codes);
+ if (!pools->empty()) {
+ sanitizeOptionPools(pools, space, codes);
} else {
subnet->remove("pd-pools");
}
// Finally, sanitize host reservations.
ConstElementPtr hosts = subnet->get("reservations");
if (hosts) {
- if (hosts->size() > 0) {
- optionHosts(hosts, space, codes);
+ if (!hosts->empty()) {
+ sanitizeOptionHosts(hosts, space, codes);
} else {
subnet->remove("reservations");
}
}
void
-AdaptorConfig::optionSharedNetworks(ConstElementPtr networks,
- const string& space,
- const OptionCodes& codes) {
+AdaptorConfig::sanitizeOptionSharedNetworks(ConstElementPtr networks,
+ const string& space,
+ const OptionCodes& codes) {
if (!networks || networks->empty()) {
// nothing to do here.
return;
// try to sanitize shared network options first.
ConstElementPtr options = network->get("option-data");
if (options) {
- if (options->size() > 0) {
- optionDataList(options, space, codes);
+ if (!options->empty()) {
+ sanitizeOptionDataList(options, space, codes);
} else {
network->remove("option-data");
}
// Now try to sanitize subnets.
ConstElementPtr subnets = network->get(subnet);
if (subnets) {
- if (subnets->size() > 0) {
- optionSubnets(subnets, space, codes);
+ if (!subnets->empty()) {
+ sanitizeOptionSubnets(subnets, space, codes);
} else {
network->remove(subnet);
}
}
void
-AdaptorConfig::requireClassesPools(ConstElementPtr pools) {
+AdaptorConfig::sanitizeRequireClassesPools(ConstElementPtr pools) {
if (!pools || pools->empty()) {
// nothing to do here.
return;
}
void
-AdaptorConfig::requireClassesSubnets(ConstElementPtr subnets) {
+AdaptorConfig::sanitizeRequireClassesSubnets(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);
- requireClassesPools(subnet->get("pools"));
- requireClassesPools(subnet->get("pd-pools"));
+ sanitizeRequireClassesPools(subnet->get("pools"));
+ sanitizeRequireClassesPools(subnet->get("pd-pools"));
ConstElementPtr requires = subnet->get("require-client-classes");
- if (requires && (requires->size() == 0)) {
+ if (requires && requires->empty()) {
subnet->remove("require-client-classes");
}
}
for (size_t i = 0; i < networks->size(); ++i) {
ElementPtr network = networks->getNonConst(i);
- requireClassesSubnets(network->get(subsel));
+ sanitizeRequireClassesSubnets(network->get(subsel));
ConstElementPtr requires = network->get("require-client-classes");
- if (requires && (requires->size() == 0)) {
+ if (requires && requires->empty()) {
network->remove("require-client-classes");
}
}
}
void
-AdaptorConfig::hostList(ConstElementPtr hosts) {
+AdaptorConfig::sanitizeHostList(ConstElementPtr hosts) {
if (!hosts || hosts->empty()) {
// nothing to do here.
}
void
-AdaptorConfig::hostSubnets(ConstElementPtr subnets) {
+AdaptorConfig::sanitizeHostSubnets(ConstElementPtr subnets) {
if (!subnets || subnets->empty()) {
// nothing to do here.
}
for (ConstElementPtr subnet : subnets->listValue()) {
- hostList(subnet->get("reservations"));
+ sanitizeHostList(subnet->get("reservations"));
}
}
void
-AdaptorConfig::hostSharedNetworks(ConstElementPtr networks,
+AdaptorConfig::SanitizeHostsInSharedNetworks(ConstElementPtr networks,
const string& space) {
if (!networks || networks->empty()) {
// nothing to do here.
for (ConstElementPtr network : networks->listValue()) {
if (space == DHCP4_SPACE) {
- hostSubnets(network->get("subnet4"));
+ sanitizeHostSubnets(network->get("subnet4"));
} else {
- hostSubnets(network->get("subnet6"));
+ sanitizeHostSubnets(network->get("subnet6"));
}
}
}
void
-AdaptorConfig::relaySubnets(ConstElementPtr subnets) {
+AdaptorConfig::sanitizeRelaySubnets(ConstElementPtr subnets) {
if (!subnets || subnets->empty()) {
// nothing to do here.
return;
}
void
-AdaptorConfig::relaySharedNetworks(ConstElementPtr networks,
+AdaptorConfig::sanitizeRelayInSharedNetworks(ConstElementPtr networks,
const string& subsel) {
if (!networks || networks->empty()) {
// nothing to do here.
for (size_t i = 0; i < networks->size(); ++i) {
ElementPtr network = networks->getNonConst(i);
updateRelay(network);
- relaySubnets(network->get(subsel));
+ sanitizeRelaySubnets(network->get(subsel));
}
}
void
-AdaptorConfig::updateDatabase(ConstElementPtr dhcp) {
+AdaptorConfig::sanitizeDatabase(ConstElementPtr dhcp) {
ConstElementPtr database = dhcp->get("hosts-database");
if (!database) {
return;
}
void
-AdaptorConfig::relaySuppliedOptions(ConstElementPtr dhcp) {
+AdaptorConfig::sanitizeRelaySuppliedOptions(ConstElementPtr dhcp) {
ConstElementPtr options = dhcp->get("relay-supplied-options");
if (!options || options->empty()) {
return;
SubnetIDSet set;
ConstElementPtr subnets = dhcp->get(subsel);
if (subnets) {
- if (subnets->size() > 0) {
+ if (!subnets->empty()) {
if (!subnetsCollectID(subnets, set)) {
have_ids = false;
}
}
ConstElementPtr networks = dhcp->get("shared-networks");
if (networks) {
- if (networks->size() > 0) {
+ if (!networks->empty()) {
if (!sharedNetworksCollectID(networks, set, subsel)) {
have_ids = false;
}
initCodes(codes, space);;
ConstElementPtr defs = dhcp->get("option-def");
if (defs) {
- if (defs->size() > 0) {
- optionDefList(defs, space, codes);
+ if (!defs->empty()) {
+ sanitizeOptionDefList(defs, space, codes);
} else {
dhcp->remove("option-def");
}
}
ConstElementPtr options = dhcp->get("option-data");
if (options) {
- if (options->size() > 0) {
- optionDataList(options, space, codes);
+ if (!options->empty()) {
+ sanitizeOptionDataList(options, space, codes);
} else {
dhcp->remove("option-data");
}
}
ConstElementPtr classes = dhcp->get("client-classes");
if (classes) {
- if (classes->size() > 0) {
- optionClasses(classes, space, codes);
+ if (!classes->empty()) {
+ sanitizeOptionClasses(classes, space, codes);
} else {
dhcp->remove("client-classes");
}
}
ConstElementPtr hosts = dhcp->get("reservations");
if (hosts) {
- if (hosts->size() > 0) {
- optionHosts(hosts, space, codes);
+ if (!hosts->empty()) {
+ sanitizeOptionHosts(hosts, space, codes);
} else {
dhcp->remove("reservations");
}
}
- optionSubnets(subnets, space, codes);
- optionSharedNetworks(networks, space, codes);
+ sanitizeOptionSubnets(subnets, space, codes);
+ sanitizeOptionSharedNetworks(networks, space, codes);
sanitizePoolsInSubnets(subnets);
sanitizePoolsInSharedNetworks(networks, subsel);
- hostSubnets(subnets);
- hostSharedNetworks(networks, space);
+ sanitizeHostSubnets(subnets);
+ SanitizeHostsInSharedNetworks(networks, space);
- relaySubnets(subnets);
- relaySharedNetworks(networks, subsel);
+ sanitizeRelaySubnets(subnets);
+ sanitizeRelayInSharedNetworks(networks, subsel);
- requireClassesSubnets(subnets);
+ sanitizeRequireClassesSubnets(subnets);
requireClassesSharedNetworks(networks, subsel);
- updateDatabase(dhcp);
+ sanitizeDatabase(dhcp);
if (space == DHCP6_SPACE) {
- relaySuppliedOptions(dhcp);
+ sanitizeRelaySuppliedOptions(dhcp);
}
}
/// @brief Collect option definitions from an option definition list.
///
+ /// Collects options definitions, but also sets missing option space
+ /// with default.
+ ///
/// @param defs The option definition list.
- /// @param space The default space name.
+ /// @param space The default space name (missing will be filled with this)
/// @param codes Option definitions.
- static void optionDefList(isc::data::ConstElementPtr defs,
- const std::string& space,
- OptionCodes& codes);
+ static void sanitizeOptionDefList(isc::data::ConstElementPtr defs,
+ const std::string& space,
+ OptionCodes& codes);
/// @brief Set missing option codes to an option data list.
///
/// @param options The option data list.
/// @param space The default space name.
/// @param codes Option definitions.
- static void optionDataList(isc::data::ConstElementPtr options,
- const std::string& space,
- const OptionCodes& codes);
+ static void sanitizeOptionDataList(isc::data::ConstElementPtr options,
+ const std::string& space,
+ const OptionCodes& codes);
/// @brief Collect option definitions from a client class list
/// and set missing option codes.
/// @param classes The client class list.
/// @param space The default space name.
/// @param codes Option definitions.
- static void optionClasses(isc::data::ConstElementPtr classes,
- const std::string& space,
- OptionCodes& codes);
+ static void sanitizeOptionClasses(isc::data::ConstElementPtr classes,
+ const std::string& space,
+ OptionCodes& codes);
/// @brief Set missing option codes to a pool list.
///
/// @param pools The pool list.
/// @param space The default space name.
/// @param codes Option definitions.
- static void optionPools(isc::data::ConstElementPtr pools,
- const std::string& space,
- const OptionCodes& codes);
+ static void sanitizeOptionPools(isc::data::ConstElementPtr pools,
+ const std::string& space,
+ const OptionCodes& codes);
/// @brief Set missing option codes to a host reservation list.
///
/// @param hosts The host reservation list.
/// @param space The default space name.
/// @param codes Option definitions.
- static void optionHosts(isc::data::ConstElementPtr hosts,
- const std::string& space,
- const OptionCodes& codes);
+ static void sanitizeOptionHosts(isc::data::ConstElementPtr hosts,
+ const std::string& space,
+ const OptionCodes& codes);
/// @brief Set missing option codes to a subnet list.
///
/// @param subnets The subnet list.
/// @param space The default space name.
/// @param codes Option definitions.
- static void optionSubnets(isc::data::ConstElementPtr subnets,
- const std::string& space,
- const OptionCodes& codes);
+ static void sanitizeOptionSubnets(isc::data::ConstElementPtr subnets,
+ const std::string& space,
+ const OptionCodes& codes);
/// @brief Set missing option codes to a shared network list.
///
/// @param networks The shared network list.
/// @param space The default space name.
/// @param codes Option definitions.
- static void optionSharedNetworks(isc::data::ConstElementPtr networks,
- const std::string& space,
- const OptionCodes& codes);
+ static void sanitizeOptionSharedNetworks(isc::data::ConstElementPtr networks,
+ const std::string& space,
+ const OptionCodes& codes);
/// @brief Process require client classes in a pool list.
///
/// Remove empty require client class list.
///
/// @param pools The pool list.
- static void requireClassesPools(isc::data::ConstElementPtr pools);
+ static void sanitizeRequireClassesPools(isc::data::ConstElementPtr pools);
/// @brief Process require client classes in a subnet list.
///
/// Remove empty require client class lists.
///
/// @param subnets The subnet list.
- static void requireClassesSubnets(isc::data::ConstElementPtr subnets);
+ static void sanitizeRequireClassesSubnets(isc::data::ConstElementPtr subnets);
/// @brief Process require client classes in a shared network list.
///
/// Quote when needed flex-id identifiers.
///
/// @param hosts The host reservation list.
- static void hostList(isc::data::ConstElementPtr hosts);
+ static void sanitizeHostList(isc::data::ConstElementPtr hosts);
/// @brief Process host reservations in a subnet list.
///
/// Quote when needed flex-id identifiers.
///
/// @param subnets The subnet list.
- static void hostSubnets(isc::data::ConstElementPtr subnets);
+ static void sanitizeHostSubnets(isc::data::ConstElementPtr subnets);
/// @brief Process host reservations in a shared network list.
///
///
/// @param networks The shared network list.
/// @param space The default space name.
- static void hostSharedNetworks(isc::data::ConstElementPtr networks,
- const std::string& space);
+ static void SanitizeHostsInSharedNetworks(isc::data::ConstElementPtr networks,
+ const std::string& space);
- /// @brief updateRelay in a subnet list.
+ /// @brief Sanitizes relay information in subnets in a subnet list.
///
/// Force the use of ip-addresses when it finds an ip-address entry.
///
/// @param subnets The subnet list.
- static void relaySubnets(isc::data::ConstElementPtr subnets);
+ static void sanitizeRelaySubnets(isc::data::ConstElementPtr subnets);
- /// @brief updateRelay in a shared network list.
+ /// @brief Sanitizes relay information in a shared network list.
///
/// Force the use of ip-addresses when it finds an ip-address entry.
///
/// @param networks The shared network list.
/// @param subsel The subnet list name.
- static void relaySharedNetworks(isc::data::ConstElementPtr networks,
- const std::string& subsel);
+ static void sanitizeRelayInSharedNetworks(isc::data::ConstElementPtr networks,
+ const std::string& subsel);
/// @brief Update (hosts) database.
///
/// Force the use of hosts-databases vs. hosts-database.
///
/// @param dhcp The DHCP server.
- static void updateDatabase(isc::data::ConstElementPtr dhcp);
+ static void sanitizeDatabase(isc::data::ConstElementPtr dhcp);
/// @brief Update relay supplied options.
///
/// Remove empty relay supplied option list.
///
/// @param dhcp The DHCPv6 server.
- static void relaySuppliedOptions(isc::data::ConstElementPtr dhcp);
+ static void sanitizeRelaySuppliedOptions(isc::data::ConstElementPtr dhcp);
/// @brief Pre process a configuration.
///