36boost::scoped_ptr<HostMgr>&
37HostMgr::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()) {
92 boost::dynamic_pointer_cast<CacheHostDataSource>(sources[0]);
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()) {
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()) {
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 {
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;
The IOAddress class represents an IP addresses (version agnostic)
static const IOAddress & IPV4_ZERO_ADDRESS()
Returns an address set to all zeros.
std::string toText() const
Convert the address to a string.
static CfgMgr & instance()
returns a single instance of Configuration Manager
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.
virtual void add(const HostPtr &host)
Adds a new host to the alternate data source.
static void delAllBackends()
Delete all alternate backends.
static void create()
Creates new instance of the HostMgr.
bool negative_caching_
The negative caching flag.
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.
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.
virtual bool setIPReservationsUnique(const bool unique)
Controls whether IP reservations are unique or non-unique.
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...
virtual ConstHostCollection getAllbyHostname6(const std::string &hostname, const SubnetID &subnet_id) const
Return all hosts with a hostname in a DHCPv6 subnet.
virtual ConstHostCollection getAllbyHostname4(const std::string &hostname, const SubnetID &subnet_id) const
Return all hosts with a hostname in a DHCPv4 subnet.
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.
virtual void cache(ConstHostPtr host) const
Cache an answer.
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)
static bool delBackend(const std::string &db_type)
Delete an alternate host backend (aka host data source).
static void addBackend(const std::string &access)
Add an alternate host backend (aka host data source).
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 getAll6(const SubnetID &subnet_id) const
Return all hosts in a DHCPv6 subnet.
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 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.
HostDataSourcePtr getHostDataSource() const
Returns the first host data source.
static bool checkCacheBackend(bool logging=false)
Check for the cache host backend.
virtual bool del(const SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete hosts by address.
static HostMgr & instance()
Returns a sole instance of the HostMgr.
virtual ConstHostCollection getAll4(const SubnetID &subnet_id) const
Return all hosts in a DHCPv4 subnet.
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.
virtual ConstHostCollection getAllbyHostname(const std::string &hostname) const
Return all hosts with a hostname.
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)
Wraps value holding size of the page with host reservations.
Represents a device with IPv4 and/or IPv6 reservations.
IdentifierType
Type of the host identifier.
std::string getIdentifierAsText() const
Returns host identifier in a textual form.
No host data source instance exception.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#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.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
boost::shared_ptr< BaseHostDataSource > HostDataSourcePtr
HostDataSource pointer.
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_IDENTIFIER_NULL
isc::log::Logger hosts_logger("hosts")
Logger for the HostMgr and the code it calls.
boost::shared_ptr< const CfgHosts > ConstCfgHostsPtr
Const pointer.
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET6_PREFIX
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_ADDRESS6
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_IDENTIFIER_HOST
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_IDENTIFIER_HOST
std::vector< HostDataSourcePtr > HostDataSourceList
HostDataSource list.
const isc::log::MessageID HOSTS_CFG_CACHE_HOST_DATA_SOURCE
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_ADDRESS4
const int HOSTS_DBG_TRACE
Logging levels for the host reservations management.
boost::shared_ptr< CacheHostDataSource > CacheHostDataSourcePtr
CacheHostDataSource pointer.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
const isc::log::MessageID HOSTS_MGR_NON_UNIQUE_IP_UNSUPPORTED
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_IDENTIFIER
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET_ALL_SUBNET_ID_ADDRESS4
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET_ALL_SUBNET_ID_ADDRESS6
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_IDENTIFIER_NULL
const int HOSTS_DBG_RESULTS
Records the results of the lookups.
const isc::log::MessageID HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_IDENTIFIER
Defines the logger used by the top-level component of kea-lfc.