Kea  2.1.7-git
host_mgr.h
Go to the documentation of this file.
1 // Copyright (C) 2014-2021 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 
10 #include <asiolink/io_service.h>
14 #include <dhcpsrv/host.h>
15 #include <dhcpsrv/subnet_id.h>
16 #include <boost/noncopyable.hpp>
17 #include <boost/scoped_ptr.hpp>
18 #include <string>
19 
20 namespace isc {
21 namespace dhcp {
22 
55 class HostMgr : public boost::noncopyable, public BaseHostDataSource {
56 public:
57 
64  static void create();
65 
75  static void addBackend(const std::string& access);
76 
81  static bool delBackend(const std::string& db_type);
82 
92  static bool delBackend(const std::string& db_type,
93  const std::string& access,
94  bool if_unusable = false);
95 
97  static void delAllBackends();
98 
106  static bool checkCacheBackend(bool logging = false);
107 
116  static HostMgr& instance();
117 
137  virtual ConstHostCollection
138  getAll(const Host::IdentifierType& identifier_type,
139  const uint8_t* identifier_begin,
140  const size_t identifier_len) const;
141 
157  virtual ConstHostCollection
158  getAll4(const SubnetID& subnet_id) const;
159 
175  virtual ConstHostCollection
176  getAll6(const SubnetID& subnet_id) const;
177 
186  virtual ConstHostCollection
187  getAllbyHostname(const std::string& hostname) const;
188 
198  virtual ConstHostCollection
199  getAllbyHostname4(const std::string& hostname, const SubnetID& subnet_id) const;
200 
210  virtual ConstHostCollection
211  getAllbyHostname6(const std::string& hostname, const SubnetID& subnet_id) const;
212 
237  virtual ConstHostCollection
238  getPage4(const SubnetID& subnet_id,
239  size_t& source_index,
240  uint64_t lower_host_id,
241  const HostPageSize& page_size) const;
242 
267  virtual ConstHostCollection
268  getPage6(const SubnetID& subnet_id,
269  size_t& source_index,
270  uint64_t lower_host_id,
271  const HostPageSize& page_size) const;
272 
295  virtual ConstHostCollection
296  getPage4(size_t& source_index,
297  uint64_t lower_host_id,
298  const HostPageSize& page_size) const;
299 
322  virtual ConstHostCollection
323  getPage6(size_t& source_index,
324  uint64_t lower_host_id,
325  const HostPageSize& page_size) const;
326 
340  virtual ConstHostCollection
341  getAll4(const asiolink::IOAddress& address) const;
342 
358  virtual ConstHostPtr
359  get4Any(const SubnetID& subnet_id,
360  const Host::IdentifierType& identifier_type,
361  const uint8_t* identifier_begin,
362  const size_t identifier_len) const;
363 
377  virtual ConstHostPtr
378  get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
379  const uint8_t* identifier_begin, const size_t identifier_len) const;
380 
392  virtual ConstHostPtr
393  get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
394 
418  virtual ConstHostCollection
419  getAll4(const SubnetID& subnet_id,
420  const asiolink::IOAddress& address) const;
421 
437  virtual ConstHostPtr
438  get6Any(const SubnetID& subnet_id,
439  const Host::IdentifierType& identifier_type,
440  const uint8_t* identifier_begin,
441  const size_t identifier_len) const;
442 
456  virtual ConstHostPtr
457  get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
458  const uint8_t* identifier_begin, const size_t identifier_len) const;
459 
469  virtual ConstHostPtr
470  get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const;
471 
478  virtual ConstHostPtr
479  get6(const SubnetID& subnet_id, const asiolink::IOAddress& addr) const;
480 
504  virtual ConstHostCollection
505  getAll6(const SubnetID& subnet_id,
506  const asiolink::IOAddress& address) const;
507 
514  virtual void add(const HostPtr& host);
515 
528  virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr);
529 
540  virtual bool
541  del4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
542  const uint8_t* identifier_begin, const size_t identifier_len);
543 
554  virtual bool
555  del6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
556  const uint8_t* identifier_begin, const size_t identifier_len);
557 
563  virtual std::string getType() const {
564  return (std::string("host_mgr"));
565  }
566 
571  return (alternate_sources_);
572  }
573 
579 
583  bool getNegativeCaching() const {
584  return (negative_caching_);
585  }
586 
589  void setNegativeCaching(bool negative_caching) {
590  negative_caching_ = negative_caching;
591  }
592 
596  bool getDisableSingleQuery() const {
597  return (disable_single_query_);
598  }
599 
602  void setDisableSingleQuery(bool disable_single_query) {
603  disable_single_query_ = disable_single_query;
604  }
605 
624  virtual bool setIPReservationsUnique(const bool unique);
625 
631  bool getIPReservationsUnique() const {
632  return (ip_reservations_unique_);
633  }
634 
638  static void setIOService(const isc::asiolink::IOServicePtr& io_service) {
639  io_service_ = io_service;
640  }
641 
644  return (io_service_);
645  }
646 
647 protected:
648 
655 
662 
666  virtual void cache(ConstHostPtr host) const;
667 
675  virtual void cacheNegative(const SubnetID& ipv4_subnet_id,
676  const SubnetID& ipv6_subnet_id,
677  const Host::IdentifierType& identifier_type,
678  const uint8_t* identifier_begin,
679  const size_t identifier_len) const;
680 
681 private:
682 
689  bool ip_reservations_unique_;
690 
692  HostMgr() : negative_caching_(false), disable_single_query_(false),
693  ip_reservations_unique_(true) { }
694 
696  HostDataSourceList alternate_sources_;
697 
699  CacheHostDataSourcePtr cache_ptr_;
700 
703  static boost::scoped_ptr<HostMgr>& getHostMgrPtr();
704 
706  static isc::asiolink::IOServicePtr io_service_;
707 };
708 
709 } // namespace dhcp
710 } // namespace isc
711 
712 #endif // HOST_MGR_H
bool getIPReservationsUnique() const
Returns the boolean flag indicating if the IP reservations must be unique or can be non-unique...
Definition: host_mgr.h:631
static HostMgr & instance()
Returns a sole instance of the HostMgr.
Definition: host_mgr.cc:105
Wraps value holding size of the page with host reservations.
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:451
static void setIOService(const isc::asiolink::IOServicePtr &io_service)
Sets IO service to be used by the Host Manager.
Definition: host_mgr.h:638
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition: host.h:785
virtual ConstHostCollection getAll6(const SubnetID &subnet_id) const
Return all hosts in a DHCPv6 subnet.
Definition: host_mgr.cc:140
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.
Definition: host_mgr.cc:186
bool getDisableSingleQuery() const
Returns the disable single query flag.
Definition: host_mgr.h:596
virtual ConstHostCollection getAllbyHostname4(const std::string &hostname, const SubnetID &subnet_id) const
Return all hosts with a hostname in a DHCPv4 subnet.
Definition: host_mgr.cc:160
void setNegativeCaching(bool negative_caching)
Sets the negative caching flag.
Definition: host_mgr.h:589
static isc::asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service.
Definition: host_mgr.h:643
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:114
virtual void cache(ConstHostPtr host) const
Cache an answer.
Definition: host_mgr.cc:621
boost::shared_ptr< BaseHostDataSource > HostDataSourcePtr
HostDataSource pointer.
virtual bool setIPReservationsUnique(const bool unique)
Controls whether IP reservations are unique or non-unique.
Definition: host_mgr.cc:652
bool getNegativeCaching() const
Returns the negative caching flag.
Definition: host_mgr.h:583
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.
Definition: host_mgr.cc:217
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:604
boost::shared_ptr< CacheHostDataSource > CacheHostDataSourcePtr
CacheHostDataSource pointer.
static bool delBackend(const std::string &db_type)
Delete an alternate host backend (aka host data source).
Definition: host_mgr.cc:53
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition: host.h:791
static void create()
Creates new instance of the HostMgr.
Definition: host_mgr.cc:43
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:634
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition: host.h:788
virtual ConstHostCollection getAllbyHostname6(const std::string &hostname, const SubnetID &subnet_id) const
Return all hosts with a hostname in a DHCPv6 subnet.
Definition: host_mgr.cc:173
Defines the logger used by the top-level component of kea-lfc.
Host Manager.
Definition: host_mgr.h:55
HostDataSourcePtr getHostDataSource() const
Returns the first host data source.
Definition: host_mgr.cc:75
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:368
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:498
void setDisableSingleQuery(bool disable_single_query)
Sets the disable single query flag.
Definition: host_mgr.h:602
virtual ConstHostCollection getAllbyHostname(const std::string &hostname) const
Return all hosts with a hostname.
Definition: host_mgr.cc:150
Base interface for the classes implementing simple data source for host reservations.
std::vector< HostDataSourcePtr > HostDataSourceList
HostDataSource list.
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:587
virtual ConstHostCollection getAll4(const SubnetID &subnet_id) const
Return all hosts in a DHCPv4 subnet.
Definition: host_mgr.cc:129
static void delAllBackends()
Delete all alternate backends.
Definition: host_mgr.cc:70
static void addBackend(const std::string &access)
Add an alternate host backend (aka host data source).
Definition: host_mgr.cc:48
bool negative_caching_
The negative caching flag.
Definition: host_mgr.h:654
static bool checkCacheBackend(bool logging=false)
Check for the cache host backend.
Definition: host_mgr.cc:83
virtual std::string getType() const
Return backend type.
Definition: host_mgr.h:563
IdentifierType
Type of the host identifier.
Definition: host.h:307
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:318
HostDataSourceList & getHostDataSourceList()
Returns the host data source list.
Definition: host_mgr.h:570
virtual void add(const HostPtr &host)
Adds a new host to the alternate data source.
Definition: host_mgr.cc:557
bool disable_single_query_
The disable single query flag.
Definition: host_mgr.h:661
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition: subnet_id.h:24
virtual bool del(const SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete hosts by address.
Definition: host_mgr.cc:572