36 boost::scoped_ptr<HostMgr>&
37 HostMgr::getHostMgrPtr() {
38 static boost::scoped_ptr<HostMgr> host_mgr_ptr;
39 return (host_mgr_ptr);
44 getHostMgrPtr().reset(
new HostMgr());
54 if (getHostMgrPtr()->cache_ptr_ &&
55 getHostMgrPtr()->cache_ptr_->getType() == db_type) {
56 getHostMgrPtr()->cache_ptr_.reset();
66 db_type, access, if_unusable));
71 getHostMgrPtr()->alternate_sources_.clear();
76 if (alternate_sources_.empty()) {
79 return (alternate_sources_[0]);
84 if (getHostMgrPtr()->cache_ptr_) {
88 if (sources.empty()) {
94 getHostMgrPtr()->cache_ptr_ = cache_ptr;
97 .arg(cache_ptr->getType());
106 boost::scoped_ptr<HostMgr>& host_mgr_ptr = getHostMgrPtr();
110 return (*host_mgr_ptr);
115 const uint8_t* identifier_begin,
116 const size_t identifier_len)
const {
120 for (
auto source : alternate_sources_) {
122 source->getAll(identifier_type, identifier_begin, identifier_len);
123 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
131 for (
auto source : alternate_sources_) {
133 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
142 for (
auto source : alternate_sources_) {
144 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
152 for (
auto source : alternate_sources_) {
154 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
164 for (
auto source : alternate_sources_) {
167 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
177 for (
auto source : alternate_sources_) {
180 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
187 size_t& source_index,
188 uint64_t lower_host_id,
191 if (source_index > alternate_sources_.size()) {
197 if (source_index == 0) {
198 hosts = getCfgHosts()->
199 getPage4(subnet_id, source_index, lower_host_id, page_size);
201 hosts = alternate_sources_[source_index - 1]->
202 getPage4(subnet_id, source_index, lower_host_id, page_size);
206 if (!hosts.empty()) {
213 return (getPage4(subnet_id, source_index, 0UL, page_size));
218 size_t& source_index,
219 uint64_t lower_host_id,
222 if (source_index > alternate_sources_.size()) {
228 if (source_index == 0) {
229 hosts = getCfgHosts()->
230 getPage6(subnet_id, source_index, lower_host_id, page_size);
232 hosts = alternate_sources_[source_index - 1]->
233 getPage6(subnet_id, source_index, lower_host_id, page_size);
237 if (!hosts.empty()) {
244 return (getPage6(subnet_id, source_index, 0UL, page_size));
249 uint64_t lower_host_id,
252 if (source_index > alternate_sources_.size()) {
258 if (source_index == 0) {
259 hosts = getCfgHosts()->
260 getPage4(source_index, lower_host_id, page_size);
262 hosts = alternate_sources_[source_index - 1]->
263 getPage4(source_index, lower_host_id, page_size);
267 if (!hosts.empty()) {
274 return (getPage4(source_index, 0UL, page_size));
279 uint64_t lower_host_id,
282 if (source_index > alternate_sources_.size()) {
288 if (source_index == 0) {
289 hosts = getCfgHosts()->
290 getPage6(source_index, lower_host_id, page_size);
292 hosts = alternate_sources_[source_index - 1]->
293 getPage6(source_index, lower_host_id, page_size);
297 if (!hosts.empty()) {
304 return (getPage6(source_index, 0UL, page_size));
310 for (
auto source : alternate_sources_) {
312 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
320 const uint8_t* identifier_begin,
321 const size_t identifier_len)
const {
322 ConstHostPtr host = getCfgHosts()->get4(subnet_id, identifier_type,
323 identifier_begin, identifier_len);
327 if (host || alternate_sources_.empty()) {
339 for (
auto source : alternate_sources_) {
340 host = source->get4(subnet_id, identifier_type,
341 identifier_begin, identifier_len);
350 .arg(source->getType())
351 .arg(host->toText());
353 if (source != cache_ptr_) {
370 const uint8_t* identifier_begin,
371 const size_t identifier_len)
const {
373 identifier_begin, identifier_len);
374 if (host && host->getNegative()) {
376 }
else if (!host && negative_caching_) {
377 cacheNegative(subnet_id,
SubnetID(SUBNET_ID_UNUSED),
378 identifier_type, identifier_begin, identifier_len);
386 ConstHostPtr host = getCfgHosts()->get4(subnet_id, address);
387 if (host || alternate_sources_.empty()) {
394 for (
auto source : alternate_sources_) {
395 host = source->get4(subnet_id, address);
396 if (host && host->getNegative()) {
399 if (host && source != cache_ptr_) {
412 auto hosts = getCfgHosts()->getAll4(subnet_id, address);
419 for (
auto source : alternate_sources_) {
420 auto hosts_plus = source->getAll4(subnet_id, address);
421 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
428 ConstHostPtr host = getCfgHosts()->get6(prefix, prefix_len);
429 if (host || alternate_sources_.empty()) {
434 .arg(static_cast<int>(prefix_len));
435 for (
auto source : alternate_sources_) {
436 host = source->get6(prefix, prefix_len);
437 if (host && host->getNegative()) {
440 if (host && source != cache_ptr_) {
453 const uint8_t* identifier_begin,
454 const size_t identifier_len)
const {
455 ConstHostPtr host = getCfgHosts()->get6(subnet_id, identifier_type,
456 identifier_begin, identifier_len);
457 if (host || alternate_sources_.empty()) {
467 for (
auto source : alternate_sources_) {
468 host = source->get6(subnet_id, identifier_type,
469 identifier_begin, identifier_len);
478 .arg(source->getType())
479 .arg(host->toText());
481 if (source != cache_ptr_) {
500 const uint8_t* identifier_begin,
501 const size_t identifier_len)
const {
503 identifier_begin, identifier_len);
504 if (host && host->getNegative()) {
506 }
else if (!host && negative_caching_) {
507 cacheNegative(
SubnetID(SUBNET_ID_UNUSED), subnet_id,
508 identifier_type, identifier_begin, identifier_len);
516 ConstHostPtr host = getCfgHosts()->get6(subnet_id, addr);
517 if (host || alternate_sources_.empty()) {
524 for (
auto source : alternate_sources_) {
525 host = source->get6(subnet_id, addr);
526 if (host && host->getNegative()) {
529 if (host && source != cache_ptr_) {
542 auto hosts = getCfgHosts()->getAll6(subnet_id, address);
549 for (
auto source : alternate_sources_) {
550 auto hosts_plus = source->getAll6(subnet_id, address);
551 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
558 if (alternate_sources_.empty()) {
560 "no hosts-database configured.");
562 for (
auto source : alternate_sources_) {
573 if (alternate_sources_.empty()) {
575 "no hosts-database configured.");
578 for (
auto source : alternate_sources_) {
579 if (source->del(subnet_id, addr)) {
588 const uint8_t* identifier_begin,
const size_t identifier_len) {
589 if (alternate_sources_.empty()) {
591 "no hosts-database configured.");
594 for (
auto source : alternate_sources_) {
595 if (source->del4(subnet_id, identifier_type,
596 identifier_begin, identifier_len)) {
605 const uint8_t* identifier_begin,
const size_t identifier_len) {
606 if (alternate_sources_.empty()) {
608 "no alternate host data source present");
611 for (
auto source : alternate_sources_) {
612 if (source->del6(subnet_id, identifier_type,
613 identifier_begin, identifier_len)) {
624 if (!host || host->getNegative()) {
629 cache_ptr_->insert(host,
true);
637 const uint8_t* identifier_begin,
638 const size_t identifier_len)
const {
639 if (cache_ptr_ && negative_caching_) {
640 HostPtr host(
new Host(identifier_begin, identifier_len,
642 ipv4_subnet_id, ipv6_subnet_id,
644 host->setNegative(
true);
647 cache_ptr_->insert(host,
false);
655 for (
auto source : alternate_sources_) {
656 if (!source->setIPReservationsUnique(unique)) {
660 ip_reservations_unique_ =
true;
662 .arg(source->getType());
663 for (
auto source : alternate_sources_) {
664 source->setIPReservationsUnique(
true);
672 ip_reservations_unique_ = unique;
std::string getIdentifierAsText() const
Returns host identifier in a textual form.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
static HostMgr & instance()
Returns a sole instance of the HostMgr.
virtual ConstHostCollection getAllbyHostname(const std::string &hostname) const
Return all hosts with a hostname.
const isc::log::MessageID HOSTS_CFG_CACHE_HOST_DATA_SOURCE
virtual ConstHostPtr get6Any(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
Returns any host connected to the IPv6 subnet.
Wraps value holding size of the page with host reservations.
virtual ConstHostCollection getAllbyHostname6(const std::string &hostname, const SubnetID &subnet_id) const
Return all hosts with a hostname in a DHCPv6 subnet.
virtual ConstHostCollection getAll4(const SubnetID &subnet_id) const
Return all hosts in a DHCPv4 subnet.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
const isc::log::MessageID HOSTS_MGR_NON_UNIQUE_IP_UNSUPPORTED
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET_ALL_SUBNET_ID_ADDRESS4
const int HOSTS_DBG_RESULTS
Records the results of the lookups.
static CfgMgr & instance()
returns a single instance of Configuration Manager
virtual ConstHostCollection getPage6(const SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const HostPageSize &page_size) const
Returns range of hosts in a DHCPv6 subnet.
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_IDENTIFIER
boost::shared_ptr< const CfgHosts > ConstCfgHostsPtr
Const pointer.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
boost::shared_ptr< BaseHostDataSource > HostDataSourcePtr
HostDataSource pointer.
virtual void cache(ConstHostPtr host) const
Cache an answer.
virtual bool setIPReservationsUnique(const bool unique)
Controls whether IP reservations are unique or non-unique.
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_ADDRESS6
virtual ConstHostCollection getAll6(const SubnetID &subnet_id) const
Return all hosts in a DHCPv6 subnet.
virtual ConstHostCollection getAll(const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
Return all hosts connected to any subnet for which reservations have been made using a specified iden...
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_IDENTIFIER
virtual bool del6(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)
Attempts to delete a host by (subnet6-id, identifier, identifier-type)
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_IDENTIFIER_HOST
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_IDENTIFIER_NULL
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
virtual ConstHostPtr get4Any(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
Returns any host connected to the IPv4 subnet.
boost::shared_ptr< CacheHostDataSource > CacheHostDataSourcePtr
CacheHostDataSource pointer.
static bool delBackend(const std::string &db_type)
Delete an alternate host backend (aka host data source).
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_IDENTIFIER_NULL
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
static void create()
Creates new instance of the HostMgr.
isc::log::Logger hosts_logger("hosts")
Logger for the HostMgr and the code it calls.
const int HOSTS_DBG_TRACE
Logging levels for the host reservations management.
static const IOAddress & IPV4_ZERO_ADDRESS()
Returns an address set to all zeros.
virtual ConstHostPtr get6(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
Returns a host connected to the IPv6 subnet.
virtual ConstHostCollection getAllbyHostname4(const std::string &hostname, const SubnetID &subnet_id) const
Return all hosts with a hostname in a DHCPv4 subnet.
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Represents a device with IPv4 and/or IPv6 reservations.
HostDataSourcePtr getHostDataSource() const
Returns the first host data source.
Defines the logger used by the top-level component of kea-dhcp-ddns.
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET6_PREFIX
static void add(HostDataSourceList &sources, const std::string &dbaccess)
Create and add an instance of a host data source.
static bool del(HostDataSourceList &sources, const std::string &db_type)
Delete a host data source.
std::vector< HostDataSourcePtr > HostDataSourceList
HostDataSource list.
No host data source instance exception.
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_ADDRESS4
virtual bool del4(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)
Attempts to delete a host by (subnet4-id, identifier, identifier-type)
static void delAllBackends()
Delete all alternate backends.
static void addBackend(const std::string &access)
Add an alternate host backend (aka host data source).
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET_ALL_SUBNET_ID_ADDRESS6
std::string toText() const
Convert the address to a string.
static bool checkCacheBackend(bool logging=false)
Check for the cache host backend.
virtual ConstHostPtr get4(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
Returns a host connected to the IPv4 subnet.
virtual void cacheNegative(const SubnetID &ipv4_subnet_id, const SubnetID &ipv6_subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
Cache a negative answer.
Abstract interface extending base simple data source for host reservations to host cache...
IdentifierType
Type of the host identifier.
The IOAddress class represents an IP addresses (version agnostic)
virtual ConstHostCollection getPage4(const SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const HostPageSize &page_size) const
Returns range of hosts in a DHCPv4 subnet.
virtual void add(const HostPtr &host)
Adds a new host to the alternate data source.
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_IDENTIFIER_HOST
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
virtual bool del(const SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete hosts by address.