Kea  1.5.0
host_mgr.h
Go to the documentation of this file.
1 // Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef HOST_MGR_H
8 #define HOST_MGR_H
9 
13 #include <dhcpsrv/host.h>
14 #include <dhcpsrv/subnet_id.h>
15 #include <boost/noncopyable.hpp>
16 #include <boost/scoped_ptr.hpp>
17 #include <string>
18 
19 namespace isc {
20 namespace dhcp {
21 
54 class HostMgr : public boost::noncopyable, public BaseHostDataSource {
55 public:
56 
63  static void create();
64 
73  static void addBackend(const std::string& access);
74 
79  static bool delBackend(const std::string& db_type);
80 
82  static void delAllBackends();
83 
91  static bool checkCacheBackend(bool logging = false);
92 
101  static HostMgr& instance();
102 
122  virtual ConstHostCollection
123  getAll(const Host::IdentifierType& identifier_type,
124  const uint8_t* identifier_begin,
125  const size_t identifier_len) const;
126 
140  virtual ConstHostCollection
141  getAll4(const asiolink::IOAddress& address) const;
142 
158  virtual ConstHostPtr
159  get4Any(const SubnetID& subnet_id,
160  const Host::IdentifierType& identifier_type,
161  const uint8_t* identifier_begin,
162  const size_t identifier_len) const;
163 
177  virtual ConstHostPtr
178  get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
179  const uint8_t* identifier_begin, const size_t identifier_len) const;
180 
192  virtual ConstHostPtr
193  get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
194 
210  virtual ConstHostPtr
211  get6Any(const SubnetID& subnet_id,
212  const Host::IdentifierType& identifier_type,
213  const uint8_t* identifier_begin,
214  const size_t identifier_len) const;
215 
229  virtual ConstHostPtr
230  get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
231  const uint8_t* identifier_begin, const size_t identifier_len) const;
232 
242  virtual ConstHostPtr
243  get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const;
244 
251  virtual ConstHostPtr
252  get6(const SubnetID& subnet_id, const asiolink::IOAddress& addr) const;
253 
260  virtual void add(const HostPtr& host);
261 
269  virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr);
270 
281  virtual bool
282  del4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
283  const uint8_t* identifier_begin, const size_t identifier_len);
284 
295  virtual bool
296  del6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
297  const uint8_t* identifier_begin, const size_t identifier_len);
298 
304  virtual std::string getType() const {
305  return (std::string("host_mgr"));
306  }
307 
312  return (alternate_sources_);
313  }
314 
320 
324  bool getNegativeCaching() const {
325  return (negative_caching_);
326  }
327 
330  void setNegativeCaching(bool negative_caching) {
331  negative_caching_ = negative_caching;
332  }
333 
334 protected:
341 
345  virtual void cache(ConstHostPtr host) const;
346 
354  virtual void cacheNegative(const SubnetID& ipv4_subnet_id,
355  const SubnetID& ipv6_subnet_id,
356  const Host::IdentifierType& identifier_type,
357  const uint8_t* identifier_begin,
358  const size_t identifier_len) const;
359 
360 private:
361 
363  HostMgr() : negative_caching_(false) { }
364 
366  HostDataSourceList alternate_sources_;
367 
369  CacheHostDataSourcePtr cache_ptr_;
370 
373  static boost::scoped_ptr<HostMgr>& getHostMgrPtr();
374 
375 };
376 }
377 }
378 
379 #endif // HOST_MGR_H
host.h
isc::dhcp::Host::IdentifierType
IdentifierType
Type of the host identifier.
Definition: host.h:252
isc::dhcp::HostMgr::get4
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.
Definition: host_mgr.cc:175
isc::dhcp::HostMgr::checkCacheBackend
static bool checkCacheBackend(bool logging=false)
Check for the cache host backend.
Definition: host_mgr.cc:68
isc::dhcp::HostMgr::negative_caching_
bool negative_caching_
The negative caching flag.
Definition: host_mgr.h:340
isc::dhcp::HostMgr::addBackend
static void addBackend(const std::string &access)
Add an alternate host backend (aka host data source).
Definition: host_mgr.cc:45
isc::dhcp::HostMgr::get4Any
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.
Definition: host_mgr.cc:125
isc::dhcp::HostMgr::create
static void create()
Creates new instance of the HostMgr.
Definition: host_mgr.cc:40
isc::dhcp::HostPtr
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition: host.h:725
isc::dhcp::HostMgr::getType
virtual std::string getType() const
Return backend type.
Definition: host_mgr.h:304
isc::dhcp::HostMgr::get6
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.
Definition: host_mgr.cc:289
isc::dhcp::HostMgr::getAll
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...
Definition: host_mgr.cc:99
cache_host_data_source.h
isc::dhcp::HostMgr::del4
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)
Definition: host_mgr.cc:361
isc::dhcp::HostMgr::getHostDataSource
HostDataSourcePtr getHostDataSource() const
Returns the first host data source.
Definition: host_mgr.cc:60
isc::dhcp::HostMgr::add
virtual void add(const HostPtr &host)
Adds a new host to the alternate data source.
Definition: host_mgr.cc:331
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::dhcp::HostMgr::getHostDataSourceList
HostDataSourceList & getHostDataSourceList()
Returns the host data source list.
Definition: host_mgr.h:311
base_host_data_source.h
isc::dhcp::HostMgr::get6Any
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.
Definition: host_mgr.cc:242
isc::dhcp::HostDataSourceList
std::vector< HostDataSourcePtr > HostDataSourceList
HostDataSource list.
Definition: base_host_data_source.h:254
isc::dhcp::HostMgr::del
virtual bool del(const SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete a host by address.
Definition: host_mgr.cc:346
isc::dhcp::BaseHostDataSource
Base interface for the classes implementing simple data source for host reservations.
Definition: base_host_data_source.h:57
isc::dhcp::HostMgr::del6
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)
Definition: host_mgr.cc:378
isc::dhcp::HostMgr::delBackend
static bool delBackend(const std::string &db_type)
Delete an alternate host backend (aka host data source).
Definition: host_mgr.cc:50
database_connection.h
isc::dhcp::CacheHostDataSourcePtr
boost::shared_ptr< CacheHostDataSource > CacheHostDataSourcePtr
CacheHostDataSource pointer.
Definition: cache_host_data_source.h:62
isc::dhcp::HostMgr::instance
static HostMgr & instance()
Returns a sole instance of the HostMgr.
Definition: host_mgr.cc:90
isc::dhcp::HostDataSourcePtr
boost::shared_ptr< BaseHostDataSource > HostDataSourcePtr
HostDataSource pointer.
Definition: base_host_data_source.h:251
isc::dhcp::ConstHostCollection
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition: host.h:731
isc::dhcp::HostMgr::cacheNegative
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.
Definition: host_mgr.cc:408
isc::dhcp::ConstHostPtr
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition: host.h:728
subnet_id.h
isc::dhcp::HostMgr::cache
virtual void cache(ConstHostPtr host) const
Cache an answer.
Definition: host_mgr.cc:395
isc::dhcp::SubnetID
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
Definition: lease.h:24
isc::dhcp::HostMgr::getAll4
virtual ConstHostCollection getAll4(const asiolink::IOAddress &address) const
Returns a collection of hosts using the specified IPv4 address.
Definition: host_mgr.cc:115
isc::dhcp::HostMgr::setNegativeCaching
void setNegativeCaching(bool negative_caching)
Sets the negative caching flag.
Definition: host_mgr.h:330
isc::dhcp::HostMgr
Host Manager.
Definition: host_mgr.h:54
isc::dhcp::HostMgr::getNegativeCaching
bool getNegativeCaching() const
Returns the negative caching flag.
Definition: host_mgr.h:324
isc::dhcp::HostMgr::delAllBackends
static void delAllBackends()
Delete all alternate backends.
Definition: host_mgr.cc:55