Kea 2.7.5
host_mgr.h
Go to the documentation of this file.
1// Copyright (C) 2014-2023 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#include <cstdint>
20
21namespace isc {
22namespace dhcp {
23
24// Enum flags to define a target of the host manager functions.
26 // The operation target not specified. Consider nothing.
28 // Consider only the CfgHosts instance.
29 PRIMARY_SOURCE = 1, // 1 << 1
30 // Consider only the alternate sources.
31 ALTERNATE_SOURCES = 2, // 1 << 2
32 // Consider both CfgInstance and alternate sources.
33 ALL_SOURCES = 3 // PRIMARY_SOURCE | ALTERNATE_SOURCES
34};
35
68class HostMgr : public boost::noncopyable, public BaseHostDataSource {
69public:
70
77 static void create();
78
88 static void addBackend(const std::string& access);
89
94 static bool delBackend(const std::string& db_type);
95
105 static bool delBackend(const std::string& db_type,
106 const std::string& access,
107 bool if_unusable = false);
108
110 static void delAllBackends();
111
119 static bool checkCacheBackend(bool logging = false);
120
129 static HostMgr& instance();
130
152 getAll(const Host::IdentifierType& identifier_type,
153 const uint8_t* identifier_begin,
154 const size_t identifier_len,
155 const HostMgrOperationTarget target) const;
156
159 virtual ConstHostCollection
160 getAll(const Host::IdentifierType& identifier_type,
161 const uint8_t* identifier_begin,
162 const size_t identifier_len) const;
163
181 getAll4(const SubnetID& subnet_id, const HostMgrOperationTarget target) const;
182
185 virtual ConstHostCollection
186 getAll4(const SubnetID& subnet_id) const;
187
205 getAll6(const SubnetID& subnet_id,
206 const HostMgrOperationTarget target) const;
207
210 virtual ConstHostCollection
211 getAll6(const SubnetID& subnet_id) const;
212
223 getAllbyHostname(const std::string& hostname,
224 const HostMgrOperationTarget target) const;
225
228 virtual ConstHostCollection
229 getAllbyHostname(const std::string& hostname) const;
230
242 getAllbyHostname4(const std::string& hostname, const SubnetID& subnet_id,
243 const HostMgrOperationTarget target) const;
244
247 virtual ConstHostCollection
248 getAllbyHostname4(const std::string& hostname, const SubnetID& subnet_id) const;
249
261 getAllbyHostname6(const std::string& hostname, const SubnetID& subnet_id,
262 const HostMgrOperationTarget target) const;
263
266 virtual ConstHostCollection
267 getAllbyHostname6(const std::string& hostname, const SubnetID& subnet_id) const;
268
293 virtual ConstHostCollection
294 getPage4(const SubnetID& subnet_id,
295 size_t& source_index,
296 uint64_t lower_host_id,
297 const HostPageSize& page_size) const;
298
323 virtual ConstHostCollection
324 getPage6(const SubnetID& subnet_id,
325 size_t& source_index,
326 uint64_t lower_host_id,
327 const HostPageSize& page_size) const;
328
351 virtual ConstHostCollection
352 getPage4(size_t& source_index,
353 uint64_t lower_host_id,
354 const HostPageSize& page_size) const;
355
378 virtual ConstHostCollection
379 getPage6(size_t& source_index,
380 uint64_t lower_host_id,
381 const HostPageSize& page_size) const;
382
398 getAll4(const asiolink::IOAddress& address,
399 const HostMgrOperationTarget target) const;
400
403 virtual ConstHostCollection
404 getAll4(const asiolink::IOAddress& address) const;
405
423 get4Any(const SubnetID& subnet_id,
424 const Host::IdentifierType& identifier_type,
425 const uint8_t* identifier_begin,
426 const size_t identifier_len,
427 const HostMgrOperationTarget target) const;
428
431 virtual ConstHostPtr
432 get4Any(const SubnetID& subnet_id,
433 const Host::IdentifierType& identifier_type,
434 const uint8_t* identifier_begin,
435 const size_t identifier_len) const;
436
452 get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
453 const uint8_t* identifier_begin, const size_t identifier_len,
454 const HostMgrOperationTarget target) const;
455
458 virtual ConstHostPtr
459 get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
460 const uint8_t* identifier_begin, const size_t identifier_len) const;
461
475 get4(const SubnetID& subnet_id, const asiolink::IOAddress& address,
476 const HostMgrOperationTarget target) const;
477
480 virtual ConstHostPtr
481 get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
482
508 getAll4(const SubnetID& subnet_id,
509 const asiolink::IOAddress& address,
510 const HostMgrOperationTarget target) const;
511
514 virtual ConstHostCollection
515 getAll4(const SubnetID& subnet_id,
516 const asiolink::IOAddress& address) const;
517
535 get6Any(const SubnetID& subnet_id,
536 const Host::IdentifierType& identifier_type,
537 const uint8_t* identifier_begin,
538 const size_t identifier_len,
539 const HostMgrOperationTarget target) const;
540
543 virtual ConstHostPtr
544 get6Any(const SubnetID& subnet_id,
545 const Host::IdentifierType& identifier_type,
546 const uint8_t* identifier_begin,
547 const size_t identifier_len) const;
548
564 get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
565 const uint8_t* identifier_begin, const size_t identifier_len,
566 const HostMgrOperationTarget target) const;
567
570 virtual ConstHostPtr
571 get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
572 const uint8_t* identifier_begin, const size_t identifier_len) const;
573
585 get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len,
586 const HostMgrOperationTarget target) const;
587
590 virtual ConstHostPtr
591 get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const;
592
601 get6(const SubnetID& subnet_id, const asiolink::IOAddress& addr,
602 const HostMgrOperationTarget target) const;
603
606 virtual ConstHostPtr
607 get6(const SubnetID& subnet_id, const asiolink::IOAddress& addr) const;
608
634 getAll6(const SubnetID& subnet_id,
635 const asiolink::IOAddress& address,
636 const HostMgrOperationTarget target) const;
637
640 virtual ConstHostCollection
641 getAll6(const SubnetID& subnet_id,
642 const asiolink::IOAddress& address) const;
643
646 virtual ConstHostCollection
647 getAll6(const asiolink::IOAddress& address) const;
648
664 getAll6(const asiolink::IOAddress& address,
665 const HostMgrOperationTarget target) const;
666
674 void add(const HostPtr& host, const HostMgrOperationTarget target);
675
678 virtual void add(const HostPtr& host);
679
693 bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr,
694 const HostMgrOperationTarget target);
695
698 virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr);
699
712 bool
713 del4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
714 const uint8_t* identifier_begin, const size_t identifier_len,
715 const HostMgrOperationTarget target);
716
719 virtual bool
720 del4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
721 const uint8_t* identifier_begin, const size_t identifier_len);
722
735 bool
736 del6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
737 const uint8_t* identifier_begin, const size_t identifier_len,
738 const HostMgrOperationTarget target);
739
742 virtual bool
743 del6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
744 const uint8_t* identifier_begin, const size_t identifier_len);
745
752 void update(HostPtr const& host, const HostMgrOperationTarget target);
753
756 void update(HostPtr const& host);
757
763 virtual std::string getType() const {
764 return (std::string("host_mgr"));
765 }
766
771 return (alternate_sources_);
772 }
773
779
783 bool getNegativeCaching() const {
784 return (negative_caching_);
785 }
786
789 void setNegativeCaching(bool negative_caching) {
790 negative_caching_ = negative_caching;
791 }
792
797 return (disable_single_query_);
798 }
799
802 void setDisableSingleQuery(bool disable_single_query) {
803 disable_single_query_ = disable_single_query;
804 }
805
824 virtual bool setIPReservationsUnique(const bool unique);
825
832 return (ip_reservations_unique_);
833 }
834
835protected:
836
843
850
854 virtual void cache(ConstHostPtr host) const;
855
863 virtual void cacheNegative(const SubnetID& ipv4_subnet_id,
864 const SubnetID& ipv6_subnet_id,
865 const Host::IdentifierType& identifier_type,
866 const uint8_t* identifier_begin,
867 const size_t identifier_len) const;
868
869private:
870
877 bool ip_reservations_unique_;
878
881 ip_reservations_unique_(true) { }
882
884 HostDataSourceList alternate_sources_;
885
887 CacheHostDataSourcePtr cache_ptr_;
888
891 static boost::scoped_ptr<HostMgr>& getHostMgrPtr();
892};
893
894} // namespace dhcp
895} // namespace isc
896
897#endif // HOST_MGR_H
Base interface for the classes implementing simple data source for host reservations.
Host Manager.
Definition host_mgr.h:68
ConstHostCollection getAll6(const SubnetID &subnet_id, const HostMgrOperationTarget target) const
Return all hosts in a DHCPv6 subnet.
Definition host_mgr.cc:171
ConstHostCollection getAll4(const SubnetID &subnet_id, const HostMgrOperationTarget target) const
Return all hosts in a DHCPv4 subnet.
Definition host_mgr.cc:151
static void delAllBackends()
Delete all alternate backends.
Definition host_mgr.cc:79
static void create()
Creates new instance of the HostMgr.
Definition host_mgr.cc:52
bool negative_caching_
The negative caching flag.
Definition host_mgr.h:842
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:940
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:290
bool getNegativeCaching() const
Returns the negative caching flag.
Definition host_mgr.h:783
virtual bool setIPReservationsUnique(const bool unique)
Controls whether IP reservations are unique or non-unique.
Definition host_mgr.cc:958
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.
Definition host_mgr.cc:590
void setDisableSingleQuery(bool disable_single_query)
Sets the disable single query flag.
Definition host_mgr.h:802
virtual std::string getType() const
Return backend type.
Definition host_mgr.h:763
ConstHostCollection getAllbyHostname4(const std::string &hostname, const SubnetID &subnet_id, const HostMgrOperationTarget target) const
Return all hosts with a hostname in a DHCPv4 subnet.
Definition host_mgr.cc:211
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)
Definition host_mgr.cc:824
virtual void cache(ConstHostPtr host) const
Cache an answer.
Definition host_mgr.cc:927
static bool delBackend(const std::string &db_type)
Delete an alternate host backend (aka host data source).
Definition host_mgr.cc:62
static void addBackend(const std::string &access)
Add an alternate host backend (aka host data source).
Definition host_mgr.cc:57
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...
Definition host_mgr.cc:123
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.
Definition host_mgr.cc:401
bool getDisableSingleQuery() const
Returns the disable single query flag.
Definition host_mgr.h:796
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)
Definition host_mgr.cc:861
void add(const HostPtr &host, const HostMgrOperationTarget target)
Adds a new host to the alternate data source.
Definition host_mgr.cc:764
bool del(const SubnetID &subnet_id, const asiolink::IOAddress &addr, const HostMgrOperationTarget target)
Attempts to delete hosts by address.
Definition host_mgr.cc:794
void setNegativeCaching(bool negative_caching)
Sets the negative caching flag.
Definition host_mgr.h:789
ConstHostCollection getAllbyHostname6(const std::string &hostname, const SubnetID &subnet_id, const HostMgrOperationTarget target) const
Return all hosts with a hostname in a DHCPv6 subnet.
Definition host_mgr.cc:235
bool disable_single_query_
The disable single query flag.
Definition host_mgr.h:849
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:259
HostDataSourcePtr getHostDataSource() const
Returns the first host data source.
Definition host_mgr.cc:84
static bool checkCacheBackend(bool logging=false)
Check for the cache host backend.
Definition host_mgr.cc:92
bool getIPReservationsUnique() const
Returns the boolean flag indicating if the IP reservations must be unique or can be non-unique.
Definition host_mgr.h:831
static HostMgr & instance()
Returns a sole instance of the HostMgr.
Definition host_mgr.cc:114
void update(HostPtr const &host, const HostMgrOperationTarget target)
Implements BaseHostDataSource::update() for alternate sources.
Definition host_mgr.cc:898
ConstHostCollection getAllbyHostname(const std::string &hostname, const HostMgrOperationTarget target) const
Return all hosts with a hostname.
Definition host_mgr.cc:191
HostDataSourceList & getHostDataSourceList()
Returns the host data source list.
Definition host_mgr.h:770
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.
Definition host_mgr.cc:465
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.
Definition host_mgr.cc:650
Wraps value holding size of the page with host reservations.
IdentifierType
Type of the host identifier.
Definition host.h:337
boost::shared_ptr< BaseHostDataSource > HostDataSourcePtr
HostDataSource pointer.
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition host.h:837
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition host.h:843
std::vector< HostDataSourcePtr > HostDataSourceList
HostDataSource list.
boost::shared_ptr< CacheHostDataSource > CacheHostDataSourcePtr
CacheHostDataSource pointer.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition host.h:840
HostMgrOperationTarget
Definition host_mgr.h:25
@ PRIMARY_SOURCE
Definition host_mgr.h:29
@ ALTERNATE_SOURCES
Definition host_mgr.h:31
@ UNSPECIFIED_SOURCE
Definition host_mgr.h:27
@ ALL_SOURCES
Definition host_mgr.h:33
Defines the logger used by the top-level component of kea-lfc.