2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 05:55:28 +00:00

[#402,!224] kea-dhcp4 now merges global values from config backend

src/bin/dhcp4/json_config_parser.*
    Moved global merge logic into SrvConfig

src/lib/dhcpsrv/srv_config.*
    SrvConfig::merge(const ConfigBase& other) - now calls protocol
    specific merge methods

    SrvConfig::merge4() - new method for v4 merges
    SrvConfig::mergeGlobals4() - new method for merging v4 globals

src/lib/dhcpsrv/tests/srv_config_unittest.cc
    TEST_F(SrvConfigTest, mergeGlobals4) - new test
This commit is contained in:
Thomas Markwalder
2019-02-20 11:22:49 -05:00
parent 6b57b6b5d6
commit 16d2eaa574
6 changed files with 204 additions and 127 deletions

View File

@@ -740,50 +740,17 @@ bool databaseConfigConnect(const SrvConfigPtr& srv_cfg) {
void addGlobalsToConfig(SrvConfigPtr external_cfg, data::StampedValueCollection& cb_globals) {
const auto& index = cb_globals.get<StampedValueNameIndexTag>();
for (auto cb_global = index.begin(); cb_global != index.end(); ++cb_global) {
if ((*cb_global)->amNull()) {
continue;
}
// If the global is an explicit member of SrvConfig handle it that way.
if (handleExplicitGlobal(external_cfg, (*cb_global))) {
continue;
} else {
// Otherwise it must be added to the implicitly configured globals
handleImplicitGlobal(external_cfg, (*cb_global));
}
external_cfg->addConfiguredGlobal((*cb_global)->getName(),
(*cb_global)->getElementValue());
}
}
bool handleExplicitGlobal(SrvConfigPtr external_cfg, const data::StampedValuePtr& cb_global) {
bool was_handled = true;
try {
const std::string& name = cb_global->getName();
if (name == "decline-probation-period") {
external_cfg->setDeclinePeriod(cb_global->getIntegerValue());
}
else if (name == "echo-client-id") {
external_cfg->setEchoClientId(cb_global->getValue() == "true" ? true : false);
} else {
was_handled = false;
}
} catch(const std::exception& ex) {
isc_throw (BadValue, "Invalid value:" << cb_global->getValue()
<< " explict global:" << cb_global->getName());
}
return (was_handled);
}
void handleImplicitGlobal(SrvConfigPtr external_cfg, const data::StampedValuePtr& cb_global) {
external_cfg->addConfiguredGlobal(cb_global->getName(), cb_global->getElementValue());
}
}; // end of isc::dhcp namespace
}; // end of isc namespace