16#include <boost/foreach.hpp>
27 int hook_index_cb4_updated_;
49 const boost::posix_time::ptime& lb_modification_time,
52 auto globals_fetched =
false;
53 auto reconfig = audit_entries.empty();
54 auto cb_update = !reconfig;
71 auto range = index.equal_range(boost::make_tuple(
"dhcp4_global_parameter",
72 AuditEntry::ModificationType::DELETE));
73 if (range.first != range.second) {
81 globals =
getMgr().getPool()->getAllGlobalParameters4(backend_selector, server_selector);
88 external_cfg->sanityChecksLifetime(
"valid-lifetime");
92 current_cfg->clearConfiguredGlobals();
94 globals_fetched =
true;
101 range = index.equal_range(boost::make_tuple(
"dhcp4_option_def",
102 AuditEntry::ModificationType::DELETE));
103 BOOST_FOREACH(
auto const& entry, range) {
104 current_cfg->getCfgOptionDef()->del(entry->getObjectId());
109 range = index.equal_range(boost::make_tuple(
"dhcp4_options",
110 AuditEntry::ModificationType::DELETE));
111 BOOST_FOREACH(
auto const& entry, range) {
112 current_cfg->getCfgOption()->del(entry->getObjectId());
115 range = index.equal_range(boost::make_tuple(
"dhcp4_client_class",
116 AuditEntry::ModificationType::DELETE));
117 BOOST_FOREACH(
auto const& entry, range) {
118 current_cfg->getClientClassDictionary()->removeClass(entry->getObjectId());
121 range = index.equal_range(boost::make_tuple(
"dhcp4_shared_network",
122 AuditEntry::ModificationType::DELETE));
123 BOOST_FOREACH(
auto const& entry, range) {
124 current_cfg->getCfgSharedNetworks4()->del(entry->getObjectId());
127 range = index.equal_range(boost::make_tuple(
"dhcp4_subnet",
128 AuditEntry::ModificationType::DELETE));
129 BOOST_FOREACH(
auto const& entry, range) {
133 auto subnet = current_cfg->getCfgSubnets4()->getBySubnetId(entry->getObjectId());
137 subnet->getSharedNetwork(network);
140 network->del(subnet->getID());
143 current_cfg->getCfgSubnets4()->del(entry->getObjectId());
160 if (!globals_fetched) {
164 if (reconfig || !updated_entries.empty()) {
166 globals =
getMgr().getPool()->getModifiedGlobalParameters4(backend_selector, server_selector,
167 lb_modification_time);
169 globals_fetched =
true;
177 if (reconfig || !updated_entries.empty()) {
179 getMgr().getPool()->getModifiedOptionDefs4(backend_selector, server_selector,
180 lb_modification_time);
181 for (
auto const& option_def : option_defs) {
182 if (!audit_entries.empty() && !
hasObjectId(updated_entries, option_def->getId())) {
185 external_cfg->getCfgOptionDef()->add(option_def);
193 if (reconfig || !updated_entries.empty()) {
196 lb_modification_time);
197 for (
auto const& option : options) {
198 if (!audit_entries.empty() && !
hasObjectId(updated_entries, option.getId())) {
201 external_cfg->getCfgOption()->add(option, option.space_name_);
209 if (reconfig || !updated_entries.empty()) {
214 client_classes.initMatchExpr(AF_INET);
217 client_classes.createOptions(external_cfg->getCfgOptionDef());
218 client_classes.encapsulateOptions();
220 external_cfg->setClientClassDictionary(boost::make_shared<ClientClassDictionary>(client_classes));
226 std::string global_allocator;
229 global_allocator = allocator->stringValue();
235 auto allocator_changed =
false;
241 allocator_changed = (global_allocator != allocator->stringValue());
250 if (allocator_changed || reconfig) {
253 networks =
getMgr().getPool()->getAllSharedNetworks4(backend_selector, server_selector);
255 }
else if (!updated_entries.empty()) {
258 networks =
getMgr().getPool()->getModifiedSharedNetworks4(backend_selector, server_selector,
259 lb_modification_time);
262 for (
auto const& network : networks) {
263 if (!allocator_changed && cb_update && !
hasObjectId(updated_entries, network->getId())) {
272 network->setDefaultAllocatorType(global_allocator);
273 external_cfg->getCfgSharedNetworks4()->add(network);
281 if (allocator_changed || reconfig) {
284 subnets =
getMgr().getPool()->getAllSubnets4(backend_selector, server_selector);
286 }
else if (!updated_entries.empty()) {
289 subnets =
getMgr().getPool()->getModifiedSubnets4(backend_selector,
291 lb_modification_time);
294 for (
auto const& subnet : subnets) {
295 if (!allocator_changed && cb_update && !
hasObjectId(updated_entries, subnet->getID())) {
304 subnet->setDefaultAllocatorType(global_allocator);
305 external_cfg->getCfgSubnets4()->add(subnet);
312 external_cfg->sanityChecksLifetime(*staging_cfg,
"valid-lifetime");
316 if (globals_fetched) {
319 bool ip_unique =
true;
320 auto ip_unique_param = external_cfg->getConfiguredGlobal(
"ip-reservations-unique");
322 ip_unique = ip_unique_param->boolValue();
330 external_cfg->addConfiguredGlobal(
"ip-reservations-unique",
Element::create(
true));
333 external_cfg->sanityChecksLifetime(*current_cfg,
"valid-lifetime");
335 CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->initAllocatorsAfterConfigure();
352 callout_handle->setArgument(
"audit_entries", ptr);
static ElementPtr create(const Position &pos=ZERO_POSITION())
Server selector for associating objects in a database with specific servers.
void translateAndAddGlobalsToConfig(SrvConfigPtr external_cfg, data::StampedValueCollection &cb_globals) const
It translates the top level map parameters from flat naming format (e.g.
virtual void databaseConfigApply(const db::BackendSelector &backend_selector, const db::ServerSelector &server_selector, const boost::posix_time::ptime &lb_modification_time, const db::AuditEntryCollection &audit_entries)
DHCPv4 server specific method to fetch and apply back end configuration into the local configuration.
static CfgMgr & instance()
returns a single instance of Configuration Manager
Maintains a list of ClientClassDef's.
static HostMgr & instance()
Returns a sole instance of the HostMgr.
static const isc::data::SimpleDefaults GLOBAL4_DEFAULTS
This table defines default global values for DHCPv4.
static int registerHook(const std::string &name)
Register Hook.
static bool calloutsPresent(int index)
Are callouts present?
static boost::shared_ptr< CalloutHandle > createCalloutHandle()
Return callout handle.
static void callCallouts(int index, CalloutHandle &handle)
Calls the callouts for a given hook.
Wrapper class around callout handle which automatically resets handle's state.
db::AuditEntryCollection fetchConfigElement(const db::AuditEntryCollection &audit_entries, const std::string &object_type) const
Returns audit entries for new or updated configuration elements of specific type to be fetched from t...
ConfigBackendMgrType & getMgr() const
Returns the instance of the Config Backend Manager used by this object.
Defines classes for storing client class definitions.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
boost::multi_index_container< StampedValuePtr, boost::multi_index::indexed_by< boost::multi_index::hashed_non_unique< boost::multi_index::tag< StampedValueNameIndexTag >, boost::multi_index::const_mem_fun< StampedValue, std::string, &StampedValue::getName > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< StampedValueModificationTimeIndexTag >, boost::multi_index::const_mem_fun< BaseStampedElement, boost::posix_time::ptime, &BaseStampedElement::getModificationTime > > > > StampedValueCollection
Multi index container for StampedValue.
boost::multi_index_container< AuditEntryPtr, boost::multi_index::indexed_by< boost::multi_index::ordered_non_unique< boost::multi_index::tag< AuditEntryObjectTypeTag >, boost::multi_index::composite_key< AuditEntry, boost::multi_index::const_mem_fun< AuditEntry, std::string, &AuditEntry::getObjectType >, boost::multi_index::const_mem_fun< AuditEntry, AuditEntry::ModificationType, &AuditEntry::getModificationType > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< AuditEntryModificationTimeIdTag >, boost::multi_index::composite_key< AuditEntry, boost::multi_index::const_mem_fun< AuditEntry, boost::posix_time::ptime, &AuditEntry::getModificationTime >, boost::multi_index::const_mem_fun< AuditEntry, uint64_t, &AuditEntry::getRevisionId > > >, boost::multi_index::hashed_non_unique< boost::multi_index::tag< AuditEntryObjectIdTag >, boost::multi_index::const_mem_fun< AuditEntry, uint64_t, &AuditEntry::getObjectId > > > > AuditEntryCollection
Multi index container holding AuditEntry instances.
boost::shared_ptr< AuditEntryCollection > AuditEntryCollectionPtr
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
boost::shared_ptr< const CfgGlobals > ConstCfgGlobalsPtr
Const shared pointer to a CfgGlobals instance.
const isc::log::MessageID DHCPSRV_CFGMGR_CONFIG4_MERGED
const isc::log::MessageID DHCPSRV_CFGMGR_IPV4_RESERVATIONS_NON_UNIQUE_IGNORED
boost::multi_index_container< Subnet4Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetSubnetIdIndexTag >, boost::multi_index::const_mem_fun< Subnet, SubnetID, &Subnet::getID > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetPrefixIndexTag >, boost::multi_index::const_mem_fun< Subnet, std::string, &Subnet::toText > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetServerIdIndexTag >, boost::multi_index::const_mem_fun< Network4, asiolink::IOAddress, &Network4::getServerId > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetModificationTimeIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::BaseStampedElement::getModificationTime > > > > Subnet4Collection
A collection of Subnet4 objects.
boost::multi_index_container< SharedNetwork4Ptr, boost::multi_index::indexed_by< boost::multi_index::random_access< boost::multi_index::tag< SharedNetworkRandomAccessIndexTag > >, boost::multi_index::hashed_non_unique< boost::multi_index::tag< SharedNetworkIdIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, uint64_t, &data::BaseStampedElement::getId > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SharedNetworkNameIndexTag >, boost::multi_index::const_mem_fun< SharedNetwork4, std::string, &SharedNetwork4::getName > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SharedNetworkServerIdIndexTag >, boost::multi_index::const_mem_fun< Network4, asiolink::IOAddress, &Network4::getServerId > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SharedNetworkModificationTimeIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::BaseStampedElement::getModificationTime > > > > SharedNetwork4Collection
Multi index container holding shared networks.
boost::multi_index_container< OptionDescriptor, boost::multi_index::indexed_by< boost::multi_index::sequenced<>, boost::multi_index::hashed_non_unique< KeyFromKeyExtractor< boost::multi_index::const_mem_fun< Option, uint16_t, &Option::getType >, boost::multi_index::member< OptionDescriptor, OptionPtr, &OptionDescriptor::option_ > > >, boost::multi_index::hashed_non_unique< boost::multi_index::member< OptionDescriptor, bool, &OptionDescriptor::persistent_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::BaseStampedElement::getModificationTime > >, boost::multi_index::hashed_non_unique< boost::multi_index::tag< OptionIdIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, uint64_t, &data::BaseStampedElement::getId > >, boost::multi_index::hashed_non_unique< boost::multi_index::member< OptionDescriptor, bool, &OptionDescriptor::cancelled_ > > > > OptionContainer
Multi index container for DHCP option descriptors.
boost::shared_ptr< SharedNetwork4 > SharedNetwork4Ptr
Pointer to SharedNetwork4 object.
boost::multi_index_container< OptionDefinitionPtr, boost::multi_index::indexed_by< boost::multi_index::sequenced<>, boost::multi_index::hashed_non_unique< boost::multi_index::const_mem_fun< OptionDefinition, uint16_t, &OptionDefinition::getCode > >, boost::multi_index::hashed_non_unique< boost::multi_index::const_mem_fun< OptionDefinition, std::string, &OptionDefinition::getName > >, boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::StampedElement::getModificationTime > >, boost::multi_index::hashed_non_unique< boost::multi_index::tag< OptionIdIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, uint64_t, &data::BaseStampedElement::getId > > > > OptionDefContainer
Multi index container for DHCP option definitions.
boost::shared_ptr< CalloutHandle > CalloutHandlePtr
A shared pointer to a CalloutHandle object.
bool hasObjectId(const db::AuditEntryCollection &audit_entries, const uint64_t &object_id)
Checks if an object is in a collection od audit entries.
Defines the logger used by the top-level component of kea-lfc.
Tag used to access index by object type.