Kea 2.7.1
cfg_hosts.h
Go to the documentation of this file.
1// Copyright (C) 2014-2024 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 CFG_HOSTS_H
8#define CFG_HOSTS_H
9
10#include <asiolink/io_address.h>
11#include <cc/cfg_to_element.h>
13#include <dhcpsrv/host.h>
15#include <dhcpsrv/subnet_id.h>
17#include <boost/scoped_ptr.hpp>
18#include <boost/shared_ptr.hpp>
19#include <set>
20#include <mutex>
21#include <vector>
22
23namespace isc {
24namespace dhcp {
25
42public:
43
45 CfgHosts();
46
48 virtual ~CfgHosts() { }
49
64 getAll(const Host::IdentifierType& identifier_type,
65 const uint8_t* identifier_begin, const size_t identifier_len) const;
66
79 virtual HostCollection
80 getAll(const Host::IdentifierType& identifier_type,
81 const uint8_t* identifier_begin,
82 const size_t identifier_len);
83
93 getAll4(const SubnetID& subnet_id) const;
94
103 virtual HostCollection
104 getAll4(const SubnetID& subnet_id);
105
114 virtual ConstHostCollection
115 getAll6(const SubnetID& subnet_id) const;
116
125 virtual HostCollection
126 getAll6(const SubnetID& subnet_id);
127
136 virtual ConstHostCollection
137 getAllbyHostname(const std::string& hostname) const;
138
147 virtual HostCollection
148 getAllbyHostname(const std::string& hostname);
149
159 virtual ConstHostCollection
160 getAllbyHostname4(const std::string& hostname, const SubnetID& subnet_id) const;
161
171 virtual HostCollection
172 getAllbyHostname4(const std::string& hostname, const SubnetID& subnet_id);
173
183 virtual ConstHostCollection
184 getAllbyHostname6(const std::string& hostname, const SubnetID& subnet_id) const;
185
195 virtual HostCollection
196 getAllbyHostname6(const std::string& hostname, const SubnetID& subnet_id);
197
210 virtual ConstHostCollection
211 getPage4(const SubnetID& subnet_id,
212 size_t& source_index,
213 uint64_t lower_host_id,
214 const HostPageSize& page_size) const;
215
228 virtual HostCollection
229 getPage4(const SubnetID& subnet_id,
230 size_t& source_index,
231 uint64_t lower_host_id,
232 const HostPageSize& page_size);
233
246 virtual ConstHostCollection
247 getPage6(const SubnetID& subnet_id,
248 size_t& source_index,
249 uint64_t lower_host_id,
250 const HostPageSize& page_size) const;
251
264 virtual HostCollection
265 getPage6(const SubnetID& subnet_id,
266 size_t& source_index,
267 uint64_t lower_host_id,
268 const HostPageSize& page_size);
269
281 virtual ConstHostCollection
282 getPage4(size_t& source_index,
283 uint64_t lower_host_id,
284 const HostPageSize& page_size) const;
285
297 virtual HostCollection
298 getPage4(size_t& source_index,
299 uint64_t lower_host_id,
300 const HostPageSize& page_size);
301
313 virtual ConstHostCollection
314 getPage6(size_t& source_index,
315 uint64_t lower_host_id,
316 const HostPageSize& page_size) const;
317
329 virtual HostCollection
330 getPage6(size_t& source_index,
331 uint64_t lower_host_id,
332 const HostPageSize& page_size);
333
342 virtual ConstHostCollection
343 getAll4(const asiolink::IOAddress& address) const;
344
353 virtual HostCollection
354 getAll4(const asiolink::IOAddress& address);
355
364 virtual ConstHostCollection
365 getAll6(const asiolink::IOAddress& address) const;
366
375 virtual HostCollection
376 getAll6(const asiolink::IOAddress& address);
377
388 virtual ConstHostPtr
389 get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
390 const uint8_t* identifier_begin, const size_t identifier_len) const;
391
402 virtual HostPtr
403 get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
404 const uint8_t* identifier_begin, const size_t identifier_len);
405
413 virtual ConstHostPtr
414 get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
415
439 virtual ConstHostCollection
440 getAll4(const SubnetID& subnet_id,
441 const asiolink::IOAddress& address) const;
442
453 virtual ConstHostPtr
454 get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
455 const uint8_t* identifier_begin, const size_t identifier_len) const;
456
467 virtual HostPtr
468 get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
469 const uint8_t* identifier_begin, const size_t identifier_len);
470
477 virtual ConstHostPtr
478 get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const;
479
487 virtual HostPtr
488 get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len);
489
497 virtual ConstHostPtr
498 get6(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
499
507 virtual HostPtr
508 get6(const SubnetID& subnet_id, const asiolink::IOAddress& address);
509
533 virtual ConstHostCollection
534 getAll6(const SubnetID& subnet_id,
535 const asiolink::IOAddress& address) const;
536
543 virtual void add(const HostPtr& host);
544
552 virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr);
553
559 virtual size_t delAll4(const SubnetID& subnet_id);
560
571 virtual bool del4(const SubnetID& subnet_id,
572 const Host::IdentifierType& identifier_type,
573 const uint8_t* identifier_begin, const size_t identifier_len);
574
580 virtual size_t delAll6(const SubnetID& subnet_id);
581
592 virtual bool del6(const SubnetID& subnet_id,
593 const Host::IdentifierType& identifier_type,
594 const uint8_t* identifier_begin, const size_t identifier_len);
595
603 virtual void update(HostPtr const& host);
604
610 virtual std::string getType() const {
611 return (std::string("configuration file"));
612 }
613
629 virtual bool setIPReservationsUnique(const bool unique);
630
648
649private:
650
653
666 template<typename Storage>
667 void getAllInternal(const Host::IdentifierType& identifier_type,
668 const uint8_t* identifier,
669 const size_t identifier_len,
670 Storage& storage) const;
671
682 template<typename Storage>
683 void getAllInternal4(const SubnetID& subnet_id,
684 Storage& storage) const;
685
696 template<typename Storage>
697 void getAllInternal6(const SubnetID& subnet_id,
698 Storage& storage) const;
699
710 template<typename Storage>
711 void getAllbyHostnameInternal(const std::string& hostname,
712 Storage& storage) const;
713
725 template<typename Storage>
726 void getAllbyHostnameInternal4(const std::string& hostname,
727 const SubnetID& subnet_id,
728 Storage& storage) const;
729
741 template<typename Storage>
742 void getAllbyHostnameInternal6(const std::string& hostname,
743 const SubnetID& subnet_id,
744 Storage& storage) const;
745
759 template<typename Storage>
760 void getPageInternal4(const SubnetID& subnet_id,
761 uint64_t lower_host_id,
762 const HostPageSize& page_size,
763 Storage& storage) const;
764
778 template<typename Storage>
779 void getPageInternal6(const SubnetID& subnet_id,
780 uint64_t lower_host_id,
781 const HostPageSize& page_size,
782 Storage& storage) const;
783
796 template<typename Storage>
797 void getPageInternal(uint64_t lower_host_id,
798 const HostPageSize& page_size,
799 Storage& storage) const;
800
812 template<typename Storage>
813 void getAllInternal4(const asiolink::IOAddress& address,
814 Storage& storage) const;
815
827 template<typename Storage>
828 void getAllInternal6(const asiolink::IOAddress& address,
829 Storage& storage) const;
830
842 getAllInternal4(const SubnetID& subnet_id,
843 const asiolink::IOAddress& address) const;
844
857 template<typename Storage>
858 void
859 getAllInternal6(const SubnetID& subnet_id,
860 const asiolink::IOAddress& address,
861 Storage& storage) const;
862
879 HostPtr
880 getHostInternal(const SubnetID& subnet_id, const bool subnet6,
881 const Host::IdentifierType& identifier_type,
882 const uint8_t* identifier,
883 const size_t identifier_len) const;
884
898 template<typename ReturnType, typename Storage>
899 ReturnType getHostInternal6(const SubnetID& subnet_id,
900 const asiolink::IOAddress& address) const;
901
902 template<typename ReturnType>
903 ReturnType getHostInternal6(const asiolink::IOAddress& prefix,
904 const uint8_t prefix_len) const;
905
917 virtual void add4(const HostPtr& host);
918
930 virtual void add6(const HostPtr& host);
931
933 uint64_t next_host_id_ = 0;
934
943 HostContainer hosts_;
944
950 HostContainer6 hosts6_;
951
954 bool ip_reservations_unique_ = true;
955
957 const boost::scoped_ptr<std::mutex> mutex_;
958
962 isc::data::ElementPtr toElement4() const;
963
967 isc::data::ElementPtr toElement6() const;
968};
969
971
972
973typedef boost::shared_ptr<CfgHosts> CfgHostsPtr;
974
976typedef boost::shared_ptr<const CfgHosts> ConstCfgHostsPtr;
977
979
980}
981}
982
983#endif // CFG_HOSTS_H
Base interface for the classes implementing simple data source for host reservations.
Represents the host reservations specified in the configuration file.
Definition cfg_hosts.h:41
virtual ~CfgHosts()
Destructor.
Definition cfg_hosts.h:48
virtual void update(HostPtr const &host)
Attempts to update an existing host entry.
CfgHosts()
Constructor.
Definition cfg_hosts.cc:30
virtual size_t delAll4(const SubnetID &subnet_id)
Attempts to delete all hosts for a given IPv4 subnet.
virtual void add(const HostPtr &host)
Adds a new host to the collection.
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 cfg_hosts.cc:195
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)
virtual bool del(const SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete hosts by address.
virtual bool setIPReservationsUnique(const bool unique)
Controls whether IP reservations are unique or non-unique.
virtual size_t delAll6(const SubnetID &subnet_id)
Attempts to delete all hosts for a given IPv6 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.
Definition cfg_hosts.cc:779
virtual ConstHostCollection getAllbyHostname(const std::string &hostname) const
Return all hosts with a hostname.
Definition cfg_hosts.cc:99
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)
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 cfg_hosts.cc:163
virtual ConstHostCollection getAll4(const SubnetID &subnet_id) const
Return all hosts in a DHCPv4 subnet.
Definition cfg_hosts.cc:59
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 cfg_hosts.cc:729
virtual ConstHostCollection getAll6(const SubnetID &subnet_id) const
Return all hosts in a DHCPv6 subnet.
Definition cfg_hosts.cc:79
virtual ConstHostCollection getAllbyHostname6(const std::string &hostname, const SubnetID &subnet_id) const
Return all hosts with a hostname in a DHCPv6 subnet.
Definition cfg_hosts.cc:141
virtual std::string getType() const
Return backend type.
Definition cfg_hosts.h:610
isc::data::ElementPtr toElement() const
Unparse a configuration object.
virtual ConstHostCollection getAllbyHostname4(const std::string &hostname, const SubnetID &subnet_id) const
Return all hosts with a hostname in a DHCPv4 subnet.
Definition cfg_hosts.cc:119
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 cfg_hosts.cc:34
Wraps value holding size of the page with host reservations.
IdentifierType
Type of the host identifier.
Definition host.h:307
Interface for retrieving writable host reservations.
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
boost::shared_ptr< const CfgHosts > ConstCfgHostsPtr
Const pointer.
Definition cfg_hosts.h:976
boost::multi_index_container< HostPtr, boost::multi_index::indexed_by< boost::multi_index::ordered_non_unique< boost::multi_index::composite_key< Host, boost::multi_index::const_mem_fun< Host, const std::vector< uint8_t > &, &Host::getIdentifier >, boost::multi_index::const_mem_fun< Host, Host::IdentifierType, &Host::getIdentifierType > > >, boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< Host, const asiolink::IOAddress &, &Host::getIPv4Reservation > >, boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< Host, SubnetID, &Host::getIPv4SubnetID > >, boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< Host, SubnetID, &Host::getIPv6SubnetID > >, boost::multi_index::ordered_unique< boost::multi_index::const_mem_fun< Host, uint64_t, &Host::getHostId > >, boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< Host, std::string, &Host::getLowerHostname > > > > HostContainer
Multi-index container holding host reservations.
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition host.h:807
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition host.h:813
boost::multi_index_container< HostResrv6Tuple, boost::multi_index::indexed_by< boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< HostResrv6Tuple, const asiolink::IOAddress &, &HostResrv6Tuple::getPrefix > >, boost::multi_index::ordered_non_unique< boost::multi_index::composite_key< HostResrv6Tuple, boost::multi_index::member< HostResrv6Tuple, const SubnetID, &HostResrv6Tuple::subnet_id_ >, boost::multi_index::const_mem_fun< HostResrv6Tuple, const asiolink::IOAddress &, &HostResrv6Tuple::getPrefix > > >, boost::multi_index::ordered_non_unique< boost::multi_index::member< HostResrv6Tuple, const SubnetID, &HostResrv6Tuple::subnet_id_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< HostResrv6Tuple, uint64_t, &HostResrv6Tuple::getHostId > >, boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< HostResrv6Tuple, const asiolink::IOAddress &, &HostResrv6Tuple::getPrefix > > > > HostContainer6
Multi-index container holding IPv6 reservations.
std::vector< HostPtr > HostCollection
Collection of the Host objects.
Definition host.h:816
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
boost::shared_ptr< CfgHosts > CfgHostsPtr
Non-const pointer.
Definition cfg_hosts.h:973
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition host.h:810
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.