33 boost::scoped_ptr<HostMgr>&
34 HostMgr::getHostMgrPtr() {
35 static boost::scoped_ptr<HostMgr> host_mgr_ptr;
36 return (host_mgr_ptr);
41 getHostMgrPtr().reset(
new HostMgr());
56 getHostMgrPtr()->alternate_sources_.clear();
61 if (alternate_sources_.empty()) {
64 return (alternate_sources_[0]);
69 if (getHostMgrPtr()->cache_ptr_) {
73 if (sources.empty()) {
77 boost::dynamic_pointer_cast<CacheHostDataSource>(sources[0]);
79 getHostMgrPtr()->cache_ptr_ = cache_ptr;
82 .arg(cache_ptr->getType());
91 boost::scoped_ptr<HostMgr>& host_mgr_ptr = getHostMgrPtr();
95 return (*host_mgr_ptr);
100 const uint8_t* identifier_begin,
101 const size_t identifier_len)
const {
105 for (
auto source : alternate_sources_) {
107 source->getAll(identifier_type, identifier_begin, identifier_len);
108 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
117 for (
auto source : alternate_sources_) {
119 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
127 const uint8_t* identifier_begin,
128 const size_t identifier_len)
const {
129 ConstHostPtr host = getCfgHosts()->get4(subnet_id, identifier_type,
130 identifier_begin, identifier_len);
134 if (host || alternate_sources_.empty()) {
139 HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_IDENTIFIER)
146 for (
auto source : alternate_sources_) {
147 host = source->get4(subnet_id, identifier_type,
148 identifier_begin, identifier_len);
152 HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_IDENTIFIER_HOST)
157 .arg(source->getType())
158 .arg(host->toText());
160 if (source != cache_ptr_) {
167 HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_IDENTIFIER_NULL)
177 const uint8_t* identifier_begin,
178 const size_t identifier_len)
const {
180 identifier_begin, identifier_len);
181 if (host && host->getNegative()) {
183 }
else if (!host && negative_caching_) {
184 cacheNegative(subnet_id,
SubnetID(SUBNET_ID_UNUSED),
185 identifier_type, identifier_begin, identifier_len);
193 ConstHostPtr host = getCfgHosts()->get4(subnet_id, address);
194 if (host || alternate_sources_.empty()) {
198 HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_ADDRESS4)
201 for (
auto source : alternate_sources_) {
202 host = source->get4(subnet_id, address);
203 if (host && host->getNegative()) {
206 if (host && source != cache_ptr_) {
219 ConstHostPtr host = getCfgHosts()->get6(prefix, prefix_len);
220 if (host || alternate_sources_.empty()) {
225 .arg(static_cast<int>(prefix_len));
226 for (
auto source : alternate_sources_) {
227 host = source->get6(prefix, prefix_len);
228 if (host && host->getNegative()) {
231 if (host && source != cache_ptr_) {
244 const uint8_t* identifier_begin,
245 const size_t identifier_len)
const {
246 ConstHostPtr host = getCfgHosts()->get6(subnet_id, identifier_type,
247 identifier_begin, identifier_len);
248 if (host || alternate_sources_.empty()) {
253 HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_IDENTIFIER)
258 for (
auto source : alternate_sources_) {
259 host = source->get6(subnet_id, identifier_type,
260 identifier_begin, identifier_len);
264 HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_IDENTIFIER_HOST)
269 .arg(source->getType())
270 .arg(host->toText());
272 if (source != cache_ptr_) {
280 HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_IDENTIFIER_NULL)
291 const uint8_t* identifier_begin,
292 const size_t identifier_len)
const {
294 identifier_begin, identifier_len);
295 if (host && host->getNegative()) {
297 }
else if (!host && negative_caching_) {
298 cacheNegative(
SubnetID(SUBNET_ID_UNUSED), subnet_id,
299 identifier_type, identifier_begin, identifier_len);
307 ConstHostPtr host = getCfgHosts()->get6(subnet_id, addr);
308 if (host || alternate_sources_.empty()) {
312 HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_ADDRESS6)
315 for (
auto source : alternate_sources_) {
316 host = source->get6(subnet_id, addr);
317 if (host && host->getNegative()) {
320 if (host && source != cache_ptr_) {
332 if (alternate_sources_.empty()) {
334 "no hosts-database configured.");
336 for (
auto source : alternate_sources_) {
347 if (alternate_sources_.empty()) {
349 "no hosts-database configured.");
352 for (
auto source : alternate_sources_) {
353 if (source->del(subnet_id, addr)) {
362 const uint8_t* identifier_begin,
const size_t identifier_len) {
363 if (alternate_sources_.empty()) {
365 "no hosts-database configured.");
368 for (
auto source : alternate_sources_) {
369 if (source->del4(subnet_id, identifier_type,
370 identifier_begin, identifier_len)) {
379 const uint8_t* identifier_begin,
const size_t identifier_len) {
380 if (alternate_sources_.empty()) {
382 "no alternate host data source present");
385 for (
auto source : alternate_sources_) {
386 if (source->del6(subnet_id, identifier_type,
387 identifier_begin, identifier_len)) {
398 if (!host || host->getNegative()) {
403 cache_ptr_->insert(host,
true);
411 const uint8_t* identifier_begin,
412 const size_t identifier_len)
const {
413 if (cache_ptr_ && negative_caching_) {
414 HostPtr host(
new Host(identifier_begin, identifier_len,
416 ipv4_subnet_id, ipv6_subnet_id,
418 host->setNegative(
true);
421 cache_ptr_->insert(host,
false);
static HostMgr & instance()
Returns a sole instance of the HostMgr.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
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.
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
const int HOSTS_DBG_RESULTS
Records the results of the lookups.
static CfgMgr & instance()
returns a single instance of Configuration Manager
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 void cache(ConstHostPtr host) const
Cache an answer.
boost::shared_ptr< const CfgHosts > ConstCfgHostsPtr
Const pointer.
boost::shared_ptr< BaseHostDataSource > HostDataSourcePtr
HostDataSource pointer.
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)
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< CacheHostDataSource > CacheHostDataSourcePtr
CacheHostDataSource pointer.
static bool delBackend(const std::string &db_type)
Delete an alternate host backend (aka host data source).
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
std::string getIdentifierAsText() const
Returns host identifier in a textual form.
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 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.
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Represents a device with IPv4 and/or IPv6 reservations.
Defines the logger used by the top-level component of kea-dhcp-ddns.
std::string toText() const
Convert the address to a string.
HostDataSourcePtr getHostDataSource() const
Returns the first host data source.
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 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.
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.
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.
static bool checkCacheBackend(bool logging=false)
Check for the cache host backend.
IdentifierType
Type of the host identifier.
The IOAddress class represents an IP addresses (version agnostic)
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 add(const HostPtr &host)
Adds a new host to the alternate data source.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
virtual ConstHostCollection getAll4(const asiolink::IOAddress &address) const
Returns a collection of hosts using the specified IPv4 address.
virtual bool del(const SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete a host by address.