34 return (getCfgHostsForEdit());
47 boost::scoped_ptr<HostMgr>&
48 HostMgr::getHostMgrPtr() {
49 static boost::scoped_ptr<HostMgr> host_mgr_ptr;
50 return (host_mgr_ptr);
55 getHostMgrPtr().reset(
new HostMgr());
65 if (getHostMgrPtr()->cache_ptr_ &&
66 getHostMgrPtr()->cache_ptr_->getType() == db_type) {
67 getHostMgrPtr()->cache_ptr_.reset();
77 db_type, access, if_unusable));
82 getHostMgrPtr()->alternate_sources_.clear();
87 if (alternate_sources_.empty()) {
90 return (alternate_sources_[0]);
95 if (getHostMgrPtr()->cache_ptr_) {
99 if (sources.empty()) {
103 boost::dynamic_pointer_cast<CacheHostDataSource>(sources[0]);
105 getHostMgrPtr()->cache_ptr_ = cache_ptr;
108 .arg(cache_ptr->getType());
117 boost::scoped_ptr<HostMgr>& host_mgr_ptr = getHostMgrPtr();
121 return (*host_mgr_ptr);
126 const uint8_t* identifier_begin,
127 const size_t identifier_len,
131 hosts = getCfgHosts()->getAll(identifier_type, identifier_begin,
135 for (
auto source : alternate_sources_) {
137 source->getAll(identifier_type, identifier_begin, identifier_len);
138 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
146 const uint8_t* identifier_begin,
147 const size_t identifier_len)
const {
148 return getAll(identifier_type, identifier_begin, identifier_len,
156 hosts = getCfgHosts()->getAll4(subnet_id);
159 for (
auto source : alternate_sources_) {
161 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
176 hosts = getCfgHosts()->getAll6(subnet_id);
179 for (
auto source : alternate_sources_) {
181 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
196 hosts = getCfgHosts()->getAllbyHostname(hostname);
199 for (
auto source : alternate_sources_) {
201 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
218 hosts = getCfgHosts()->getAllbyHostname4(hostname, subnet_id);
221 for (
auto source : alternate_sources_) {
224 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
242 hosts = getCfgHosts()->getAllbyHostname6(hostname, subnet_id);
245 for (
auto source : alternate_sources_) {
248 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
262 size_t& source_index,
263 uint64_t lower_host_id,
266 if (source_index > alternate_sources_.size()) {
272 if (source_index == 0) {
273 hosts = getCfgHosts()->
274 getPage4(subnet_id, source_index, lower_host_id, page_size);
276 hosts = alternate_sources_[source_index - 1]->
277 getPage4(subnet_id, source_index, lower_host_id, page_size);
281 if (!hosts.empty()) {
288 return (getPage4(subnet_id, source_index, 0UL, page_size));
293 size_t& source_index,
294 uint64_t lower_host_id,
297 if (source_index > alternate_sources_.size()) {
303 if (source_index == 0) {
304 hosts = getCfgHosts()->
305 getPage6(subnet_id, source_index, lower_host_id, page_size);
307 hosts = alternate_sources_[source_index - 1]->
308 getPage6(subnet_id, source_index, lower_host_id, page_size);
312 if (!hosts.empty()) {
319 return (getPage6(subnet_id, source_index, 0UL, page_size));
324 uint64_t lower_host_id,
327 if (source_index > alternate_sources_.size()) {
333 if (source_index == 0) {
334 hosts = getCfgHosts()->
335 getPage4(source_index, lower_host_id, page_size);
337 hosts = alternate_sources_[source_index - 1]->
338 getPage4(source_index, lower_host_id, page_size);
342 if (!hosts.empty()) {
349 return (getPage4(source_index, 0UL, page_size));
354 uint64_t lower_host_id,
357 if (source_index > alternate_sources_.size()) {
363 if (source_index == 0) {
364 hosts = getCfgHosts()->
365 getPage6(source_index, lower_host_id, page_size);
367 hosts = alternate_sources_[source_index - 1]->
368 getPage6(source_index, lower_host_id, page_size);
372 if (!hosts.empty()) {
379 return (
getPage6(source_index, 0UL, page_size));
386 hosts = getCfgHosts()->getAll4(address);
389 for (
auto source : alternate_sources_) {
391 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
405 const uint8_t* identifier_begin,
406 const size_t identifier_len,
410 host = getCfgHosts()->get4(subnet_id, identifier_type,
411 identifier_begin, identifier_len);
429 for (
auto source : alternate_sources_) {
430 host = source->get4(subnet_id, identifier_type,
431 identifier_begin, identifier_len);
440 .arg(source->getType())
441 .arg(host->toText());
443 if (source != cache_ptr_) {
460 const uint8_t* identifier_begin,
461 const size_t identifier_len)
const {
462 return get4Any(subnet_id, identifier_type, identifier_begin, identifier_len,
469 const uint8_t* identifier_begin,
470 const size_t identifier_len,
473 identifier_begin, identifier_len, target);
474 if (host && host->getNegative()) {
476 }
else if (!host && negative_caching_) {
477 cacheNegative(subnet_id,
SubnetID(SUBNET_ID_UNUSED),
478 identifier_type, identifier_begin, identifier_len);
486 const uint8_t* identifier_begin,
487 const size_t identifier_len)
const {
488 return get4(subnet_id, identifier_type, identifier_begin, identifier_len,
498 host = getCfgHosts()->get4(subnet_id, address);
508 for (
auto source : alternate_sources_) {
509 host = source->get4(subnet_id, address);
510 if (host && host->getNegative()) {
513 if (host && source != cache_ptr_) {
535 hosts = getCfgHosts()->getAll4(subnet_id, address);
544 for (
auto source : alternate_sources_) {
545 auto hosts_plus = source->getAll4(subnet_id, address);
546 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
563 host = getCfgHosts()->get6(prefix, prefix_len);
570 .arg(
static_cast<int>(prefix_len));
571 for (
auto source : alternate_sources_) {
572 host = source->get6(prefix, prefix_len);
573 if (host && host->getNegative()) {
576 if (host && source != cache_ptr_) {
594 const uint8_t* identifier_begin,
595 const size_t identifier_len,
599 host = getCfgHosts()->get6(subnet_id, identifier_type,
600 identifier_begin, identifier_len);
612 for (
auto source : alternate_sources_) {
613 host = source->get6(subnet_id, identifier_type,
614 identifier_begin, identifier_len);
623 .arg(source->getType())
624 .arg(host->toText());
626 if (source != cache_ptr_) {
645 const uint8_t* identifier_begin,
646 const size_t identifier_len)
const {
647 return get6Any(subnet_id, identifier_type, identifier_begin, identifier_len,
654 const uint8_t* identifier_begin,
655 const size_t identifier_len,
658 identifier_begin, identifier_len, target);
659 if (host && host->getNegative()) {
661 }
else if (!host && negative_caching_) {
662 cacheNegative(
SubnetID(SUBNET_ID_UNUSED), subnet_id,
663 identifier_type, identifier_begin, identifier_len);
671 const uint8_t* identifier_begin,
672 const size_t identifier_len)
const {
673 return get6(subnet_id, identifier_type, identifier_begin, identifier_len,
683 host = getCfgHosts()->get6(subnet_id, addr);
692 for (
auto source : alternate_sources_) {
693 host = source->get6(subnet_id, addr);
694 if (host && host->getNegative()) {
697 if (host && source != cache_ptr_) {
720 hosts = getCfgHosts()->getAll6(subnet_id, address);
729 for (
auto source : alternate_sources_) {
730 auto hosts_plus = source->getAll6(subnet_id, address);
731 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
752 hosts = getCfgHosts()->getAll6(address);
756 for (
auto source : alternate_sources_) {
758 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
768 getCfgHostsForEdit()->add(host);
775 "no hosts-database configured.");
779 for (
auto source : alternate_sources_) {
798 size_t erased =
false;
801 erased = getCfgHostsForEdit()->del(subnet_id, addr);
808 "no hosts-database configured.");
811 for (
auto source : alternate_sources_) {
812 bool alternate_erased = source->del(subnet_id, addr);
813 erased = alternate_erased || erased;
827 const uint8_t* identifier_begin,
const size_t identifier_len,
829 bool success =
false;
832 if (getCfgHostsForEdit()->del4(subnet_id, identifier_type,
833 identifier_begin, identifier_len)) {
842 "no hosts-database configured.");
845 for (
auto source : alternate_sources_) {
846 if (source->del4(subnet_id, identifier_type,
847 identifier_begin, identifier_len)) {
857 const uint8_t* identifier_begin,
const size_t identifier_len) {
858 return del4(subnet_id, identifier_type, identifier_begin, identifier_len,
864 const uint8_t* identifier_begin,
const size_t identifier_len,
866 bool success =
false;
869 if (getCfgHostsForEdit()->del6(subnet_id, identifier_type,
870 identifier_begin, identifier_len)) {
879 "no hosts-database configured.");
882 for (
auto source : alternate_sources_) {
883 if (source->del6(subnet_id, identifier_type,
884 identifier_begin, identifier_len)) {
894 const uint8_t* identifier_begin,
const size_t identifier_len) {
895 return del6(subnet_id, identifier_type, identifier_begin, identifier_len,
902 getCfgHostsForEdit()->update(host);
909 "Unable to update existing host because there is no hosts-database configured.");
913 source->update(host);
932 if (!host || host->getNegative()) {
937 cache_ptr_->insert(host,
true);
945 const uint8_t* identifier_begin,
946 const size_t identifier_len)
const {
947 if (cache_ptr_ && negative_caching_) {
948 HostPtr host(
new Host(identifier_begin, identifier_len,
950 ipv4_subnet_id, ipv6_subnet_id,
952 host->setNegative(
true);
955 cache_ptr_->insert(host,
false);
963 for (
auto source : alternate_sources_) {
964 if (!source->setIPReservationsUnique(unique)) {
968 ip_reservations_unique_ =
true;
970 .arg(source->getType());
971 for (
auto source : alternate_sources_) {
972 source->setIPReservationsUnique(
true);
980 ip_reservations_unique_ = unique;
The IOAddress class represents an IP addresses (version agnostic)
std::string toText() const
Convert the address to a string.
static const IOAddress & IPV4_ZERO_ADDRESS()
Returns an address set to all zeros.
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.
ConstHostCollection getAll6(const SubnetID &subnet_id, const HostMgrOperationTarget target) const
Return all hosts in a DHCPv6 subnet.
ConstHostCollection getAll4(const SubnetID &subnet_id, const HostMgrOperationTarget target) const
Return all hosts in a DHCPv4 subnet.
static void delAllBackends()
Delete all alternate backends.
static void create()
Creates new instance of the HostMgr.
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.
ConstHostPtr get6Any(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target) const
Returns any host connected to the IPv6 subnet.
ConstHostCollection getAllbyHostname4(const std::string &hostname, const SubnetID &subnet_id, const HostMgrOperationTarget target) const
Return all hosts with a hostname in a DHCPv4 subnet.
bool del4(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target)
Attempts to delete a host by (subnet4-id, identifier, identifier-type, operation-target)
virtual void cache(ConstHostPtr host) const
Cache an answer.
virtual ConstHostCollection getPage6(size_t &source_index, uint64_t lower_host_id, const HostPageSize &page_size) const
Returns range of hosts.
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).
ConstHostCollection getAll(const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target) const
Return all hosts connected to any subnet for which reservations have been made using a specified iden...
ConstHostPtr get4Any(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target) const
Returns any host connected to the IPv4 subnet.
bool del6(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target)
Attempts to delete a host by (subnet6-id, identifier, identifier-type, operation-target)
void add(const HostPtr &host, const HostMgrOperationTarget target)
Adds a new host to the alternate data source.
bool del(const SubnetID &subnet_id, const asiolink::IOAddress &addr, const HostMgrOperationTarget target)
Attempts to delete hosts by address.
ConstHostCollection getAllbyHostname6(const std::string &hostname, const SubnetID &subnet_id, const HostMgrOperationTarget target) const
Return all hosts with a hostname 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.
HostDataSourcePtr getHostDataSource() const
Returns the first host data source.
static bool checkCacheBackend(bool logging=false)
Check for the cache host backend.
static HostMgr & instance()
Returns a sole instance of the HostMgr.
void update(HostPtr const &host, const HostMgrOperationTarget target)
Implements BaseHostDataSource::update() for alternate sources.
ConstHostCollection getAllbyHostname(const std::string &hostname, const HostMgrOperationTarget target) const
Return all hosts with a hostname.
ConstHostPtr get4(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target) const
Returns a host connected to the IPv4 subnet.
ConstHostPtr get6(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target) const
Returns a host connected to the IPv6 subnet.
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< CfgHosts > CfgHostsPtr
Non-const pointer.
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.