Kea  2.1.7-git
cfg_hosts.h
Go to the documentation of this file.
1 // Copyright (C) 2014-2020 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>
14 #include <dhcpsrv/host_container.h>
15 #include <dhcpsrv/subnet_id.h>
17 #include <boost/shared_ptr.hpp>
18 #include <vector>
19 
20 namespace isc {
21 namespace dhcp {
22 
39 public:
40 
42  virtual ~CfgHosts() { }
43 
57  virtual ConstHostCollection
58  getAll(const Host::IdentifierType& identifier_type,
59  const uint8_t* identifier_begin, const size_t identifier_len) const;
60 
73  virtual HostCollection
74  getAll(const Host::IdentifierType& identifier_type,
75  const uint8_t* identifier_begin,
76  const size_t identifier_len);
77 
86  virtual ConstHostCollection
87  getAll4(const SubnetID& subnet_id) const;
88 
97  virtual HostCollection
98  getAll4(const SubnetID& subnet_id);
99 
108  virtual ConstHostCollection
109  getAll6(const SubnetID& subnet_id) const;
110 
119  virtual HostCollection
120  getAll6(const SubnetID& subnet_id);
121 
130  virtual ConstHostCollection
131  getAllbyHostname(const std::string& hostname) const;
132 
141  virtual HostCollection
142  getAllbyHostname(const std::string& hostname);
143 
153  virtual ConstHostCollection
154  getAllbyHostname4(const std::string& hostname, const SubnetID& subnet_id) const;
155 
165  virtual HostCollection
166  getAllbyHostname4(const std::string& hostname, const SubnetID& subnet_id);
167 
177  virtual ConstHostCollection
178  getAllbyHostname6(const std::string& hostname, const SubnetID& subnet_id) const;
179 
189  virtual HostCollection
190  getAllbyHostname6(const std::string& hostname, const SubnetID& subnet_id);
191 
204  virtual ConstHostCollection
205  getPage4(const SubnetID& subnet_id,
206  size_t& source_index,
207  uint64_t lower_host_id,
208  const HostPageSize& page_size) const;
209 
222  virtual HostCollection
223  getPage4(const SubnetID& subnet_id,
224  size_t& source_index,
225  uint64_t lower_host_id,
226  const HostPageSize& page_size);
227 
240  virtual ConstHostCollection
241  getPage6(const SubnetID& subnet_id,
242  size_t& source_index,
243  uint64_t lower_host_id,
244  const HostPageSize& page_size) const;
245 
258  virtual HostCollection
259  getPage6(const SubnetID& subnet_id,
260  size_t& source_index,
261  uint64_t lower_host_id,
262  const HostPageSize& page_size);
263 
275  virtual ConstHostCollection
276  getPage4(size_t& source_index,
277  uint64_t lower_host_id,
278  const HostPageSize& page_size) const;
279 
291  virtual HostCollection
292  getPage4(size_t& source_index,
293  uint64_t lower_host_id,
294  const HostPageSize& page_size);
295 
307  virtual ConstHostCollection
308  getPage6(size_t& source_index,
309  uint64_t lower_host_id,
310  const HostPageSize& page_size) const;
311 
323  virtual HostCollection
324  getPage6(size_t& source_index,
325  uint64_t lower_host_id,
326  const HostPageSize& page_size);
327 
336  virtual ConstHostCollection
337  getAll4(const asiolink::IOAddress& address) const;
338 
347  virtual HostCollection
348  getAll4(const asiolink::IOAddress& address);
349 
358  virtual ConstHostCollection
359  getAll6(const asiolink::IOAddress& address) const;
360 
369  virtual HostCollection
370  getAll6(const asiolink::IOAddress& address);
371 
382  virtual ConstHostPtr
383  get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
384  const uint8_t* identifier_begin, const size_t identifier_len) const;
385 
396  virtual HostPtr
397  get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
398  const uint8_t* identifier_begin, const size_t identifier_len);
399 
407  virtual ConstHostPtr
408  get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
409 
433  virtual ConstHostCollection
434  getAll4(const SubnetID& subnet_id,
435  const asiolink::IOAddress& address) const;
436 
447  virtual ConstHostPtr
448  get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
449  const uint8_t* identifier_begin, const size_t identifier_len) const;
450 
461  virtual HostPtr
462  get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
463  const uint8_t* identifier_begin, const size_t identifier_len);
464 
471  virtual ConstHostPtr
472  get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const;
473 
481  virtual HostPtr
482  get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len);
483 
491  virtual ConstHostPtr
492  get6(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
493 
501  virtual HostPtr
502  get6(const SubnetID& subnet_id, const asiolink::IOAddress& address);
503 
527  virtual ConstHostCollection
528  getAll6(const SubnetID& subnet_id,
529  const asiolink::IOAddress& address) const;
530 
537  virtual void add(const HostPtr& host);
538 
546  virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr);
547 
553  virtual size_t delAll4(const SubnetID& subnet_id);
554 
566  virtual bool del4(const SubnetID& subnet_id,
567  const Host::IdentifierType& identifier_type,
568  const uint8_t* identifier_begin, const size_t identifier_len);
569 
575  virtual size_t delAll6(const SubnetID& subnet_id);
576 
588  virtual bool del6(const SubnetID& subnet_id,
589  const Host::IdentifierType& identifier_type,
590  const uint8_t* identifier_begin, const size_t identifier_len);
591 
597  virtual std::string getType() const {
598  return (std::string("configuration file"));
599  }
600 
616  virtual bool setIPReservationsUnique(const bool unique);
617 
635 
636 private:
637 
650  template<typename Storage>
651  void getAllInternal(const Host::IdentifierType& identifier_type,
652  const uint8_t* identifier,
653  const size_t identifier_len,
654  Storage& storage) const;
655 
666  template<typename Storage>
667  void getAllInternal4(const SubnetID& subnet_id,
668  Storage& storage) const;
669 
680  template<typename Storage>
681  void getAllInternal6(const SubnetID& subnet_id,
682  Storage& storage) const;
683 
694  template<typename Storage>
695  void getAllbyHostnameInternal(const std::string& hostname,
696  Storage& storage) const;
697 
709  template<typename Storage>
710  void getAllbyHostnameInternal4(const std::string& hostname,
711  const SubnetID& subnet_id,
712  Storage& storage) const;
713 
725  template<typename Storage>
726  void getAllbyHostnameInternal6(const std::string& hostname,
727  const SubnetID& subnet_id,
728  Storage& storage) const;
729 
743  template<typename Storage>
744  void getPageInternal4(const SubnetID& subnet_id,
745  uint64_t lower_host_id,
746  const HostPageSize& page_size,
747  Storage& storage) const;
748 
762  template<typename Storage>
763  void getPageInternal6(const SubnetID& subnet_id,
764  uint64_t lower_host_id,
765  const HostPageSize& page_size,
766  Storage& storage) const;
767 
780  template<typename Storage>
781  void getPageInternal(uint64_t lower_host_id,
782  const HostPageSize& page_size,
783  Storage& storage) const;
784 
796  template<typename Storage>
797  void getAllInternal4(const asiolink::IOAddress& address,
798  Storage& storage) const;
799 
811  template<typename Storage>
812  void getAllInternal6(const asiolink::IOAddress& address,
813  Storage& storage) const;
814 
815 
828  template<typename Storage>
829  void
830  getAllInternal6(const SubnetID& subnet_id,
831  const asiolink::IOAddress& address,
832  Storage& storage) const;
833 
850  HostPtr
851  getHostInternal(const SubnetID& subnet_id, const bool subnet6,
852  const Host::IdentifierType& identifier_type,
853  const uint8_t* identifier,
854  const size_t identifier_len) const;
855 
869  template<typename ReturnType, typename Storage>
870  ReturnType getHostInternal6(const SubnetID& subnet_id,
871  const asiolink::IOAddress& address) const;
872 
873  template<typename ReturnType>
874  ReturnType getHostInternal6(const asiolink::IOAddress& prefix,
875  const uint8_t prefix_len) const;
876 
888  virtual void add4(const HostPtr& host);
889 
901  virtual void add6(const HostPtr& host);
902 
904  uint64_t next_host_id_ = 0;
905 
914  HostContainer hosts_;
915 
921  HostContainer6 hosts6_;
922 
925  bool ip_reservations_unique_ = true;
926 
930  isc::data::ElementPtr toElement4() const;
931 
935  isc::data::ElementPtr toElement6() const;
936 };
937 
939 
940 typedef boost::shared_ptr<CfgHosts> CfgHostsPtr;
942 
944 typedef boost::shared_ptr<const CfgHosts> ConstCfgHostsPtr;
945 
947 
948 }
949 }
950 
951 #endif // CFG_HOSTS_H
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:124
Wraps value holding size of the page with host reservations.
virtual ConstHostCollection getAllbyHostname(const std::string &hostname) const
Return all hosts with a hostname.
Definition: cfg_hosts.cc:86
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:664
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:785
boost::shared_ptr< const CfgHosts > ConstCfgHostsPtr
Const pointer.
Definition: cfg_hosts.h:944
Interface for retrieving writable host reservations.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
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:730
std::vector< HostPtr > HostCollection
Collection of the Host objects.
Definition: host.h:794
virtual bool del(const SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete a hosts by address.
Definition: cfg_hosts.cc:1113
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:104
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition: host.h:791
virtual size_t delAll4(const SubnetID &subnet_id)
Attempts to delete all hosts for a given IPv4 subnet.
Definition: cfg_hosts.cc:1120
Abstract class for configuration Cfg_* classes.
virtual void add(const HostPtr &host)
Adds a new host to the collection.
Definition: cfg_hosts.cc:952
virtual bool setIPReservationsUnique(const bool unique)
Controls whether IP reservations are unique or non-unique.
Definition: cfg_hosts.cc:1170
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition: host.h:788
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: cfg_hosts.cc:1132
virtual std::string getType() const
Return backend type.
Definition: cfg_hosts.h:597
virtual size_t delAll6(const SubnetID &subnet_id)
Attempts to delete all hosts for a given IPv6 subnet.
Definition: cfg_hosts.cc:1142
Defines the logger used by the top-level component of kea-lfc.
isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: cfg_hosts.cc:1177
virtual ConstHostCollection getAll4(const SubnetID &subnet_id) const
Return all hosts in a DHCPv4 subnet.
Definition: cfg_hosts.cc:50
Base interface for the classes implementing simple data source for host reservations.
virtual ~CfgHosts()
Destructor.
Definition: cfg_hosts.h:42
Represents the host reservations specified in the configuration file.
Definition: cfg_hosts.h:37
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:174
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::getKey > >, 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::getKey > > >, boost::multi_index::ordered_non_unique< boost::multi_index::member< HostResrv6Tuple, const SubnetID, &HostResrv6Tuple::subnet_id_ > > >> HostContainer6
Multi-index container holding IPv6 reservations.
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:27
IdentifierType
Type of the host identifier.
Definition: host.h:307
virtual ConstHostCollection getAll6(const SubnetID &subnet_id) const
Return all hosts in a DHCPv6 subnet.
Definition: cfg_hosts.cc:68
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:144
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition: subnet_id.h:24
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: cfg_hosts.cc:1160
boost::shared_ptr< CfgHosts > CfgHostsPtr
Non-const pointer.
Definition: cfg_hosts.h:941