Kea  1.5.0
cfg_hosts.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 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 asiolink::IOAddress& address) const;
88 
97  virtual HostCollection
98  getAll4(const asiolink::IOAddress& address);
99 
108  virtual ConstHostCollection
109  getAll6(const asiolink::IOAddress& address) const;
110 
119  virtual HostCollection
120  getAll6(const asiolink::IOAddress& address);
121 
132  virtual ConstHostPtr
133  get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
134  const uint8_t* identifier_begin, const size_t identifier_len) const;
135 
146  virtual HostPtr
147  get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
148  const uint8_t* identifier_begin, const size_t identifier_len);
149 
157  virtual ConstHostPtr
158  get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
159 
170  virtual ConstHostPtr
171  get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
172  const uint8_t* identifier_begin, const size_t identifier_len) const;
173 
184  virtual HostPtr
185  get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
186  const uint8_t* identifier_begin, const size_t identifier_len);
187 
194  virtual ConstHostPtr
195  get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const;
196 
204  virtual HostPtr
205  get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len);
206 
214  virtual ConstHostPtr
215  get6(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
216 
224  virtual HostPtr
225  get6(const SubnetID& subnet_id, const asiolink::IOAddress& address);
226 
233  virtual void add(const HostPtr& host);
234 
242  virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr);
243 
249  virtual size_t delAll4(const SubnetID& subnet_id);
250 
262  virtual bool del4(const SubnetID& subnet_id,
263  const Host::IdentifierType& identifier_type,
264  const uint8_t* identifier_begin, const size_t identifier_len);
265 
271  virtual size_t delAll6(const SubnetID& subnet_id);
272 
284  virtual bool del6(const SubnetID& subnet_id,
285  const Host::IdentifierType& identifier_type,
286  const uint8_t* identifier_begin, const size_t identifier_len);
287 
293  virtual std::string getType() const {
294  return (std::string("configuration file"));
295  }
296 
314 
315 private:
316 
329  template<typename Storage>
330  void getAllInternal(const Host::IdentifierType& identifier_type,
331  const uint8_t* identifier,
332  const size_t identifier_len,
333  Storage& storage) const;
334 
346  template<typename Storage>
347  void getAllInternal4(const asiolink::IOAddress& address,
348  Storage& storage) const;
349 
361  template<typename Storage>
362  void getAllInternal6(const asiolink::IOAddress& address,
363  Storage& storage) const;
364 
365 
378  template<typename Storage>
379  void
380  getAllInternal6(const SubnetID& subnet_id,
381  const asiolink::IOAddress& address,
382  Storage& storage) const;
383 
400  HostPtr
401  getHostInternal(const SubnetID& subnet_id, const bool subnet6,
402  const Host::IdentifierType& identifier_type,
403  const uint8_t* identifier,
404  const size_t identifier_len) const;
405 
419  template<typename ReturnType, typename Storage>
420  ReturnType getHostInternal6(const SubnetID& subnet_id,
421  const asiolink::IOAddress& address) const;
422 
423  template<typename ReturnType>
424  ReturnType getHostInternal6(const asiolink::IOAddress& prefix,
425  const uint8_t prefix_len) const;
426 
438  virtual void add4(const HostPtr& host);
439 
451  virtual void add6(const HostPtr& host);
452 
459  HostContainer hosts_;
460 
466  HostContainer6 hosts6_;
467 
471  isc::data::ElementPtr toElement4() const;
472 
476  isc::data::ElementPtr toElement6() const;
477 };
478 
480 
481 typedef boost::shared_ptr<CfgHosts> CfgHostsPtr;
483 
485 typedef boost::shared_ptr<const CfgHosts> ConstCfgHostsPtr;
486 
488 
489 }
490 }
491 
492 #endif // CFG_HOSTS_H
host.h
isc::dhcp::Host::IdentifierType
IdentifierType
Type of the host identifier.
Definition: host.h:252
isc::dhcp::CfgHosts::delAll4
virtual size_t delAll4(const SubnetID &subnet_id)
Attempts to delete all hosts for a given IPv4 subnet.
Definition: cfg_hosts.cc:604
isc::dhcp::CfgHosts
Represents the host reservations specified in the configuration file.
Definition: cfg_hosts.h:38
io_address.h
isc::data::CfgToElement
Abstract class for configuration Cfg_* classes.
Definition: cfg_to_element.h:29
isc::dhcp::HostPtr
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition: host.h:725
isc::dhcp::CfgHosts::add
virtual void add(const HostPtr &host)
Adds a new host to the collection.
Definition: cfg_hosts.cc:439
isc::dhcp::CfgHosts::getType
virtual std::string getType() const
Return backend type.
Definition: cfg_hosts.h:293
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::dhcp::CfgHosts::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: cfg_hosts.cc:644
base_host_data_source.h
isc::dhcp::CfgHosts::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: cfg_hosts.cc:27
isc::dhcp::BaseHostDataSource
Base interface for the classes implementing simple data source for host reservations.
Definition: base_host_data_source.h:57
isc::dhcp::CfgHosts::toElement
isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: cfg_hosts.cc:654
isc::dhcp::CfgHosts::delAll6
virtual size_t delAll6(const SubnetID &subnet_id)
Attempts to delete all hosts for a given IPv6 subnet.
Definition: cfg_hosts.cc:626
isc::dhcp::WritableHostDataSource
Interface for retrieving writable host reservations.
Definition: writable_host_data_source.h:21
isc::dhcp::CfgHosts::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: cfg_hosts.cc:183
cfg_to_element.h
isc::dhcp::CfgHosts::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: cfg_hosts.cc:616
isc::dhcp::HostContainer
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 > > >> HostContainer
Multi-index container holding host reservations.
Definition: host_container.h:86
isc::dhcp::ConstHostCollection
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition: host.h:731
writable_host_data_source.h
isc::dhcp::ConstHostPtr
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition: host.h:728
isc::dhcp::CfgHosts::~CfgHosts
virtual ~CfgHosts()
Destructor.
Definition: cfg_hosts.h:42
subnet_id.h
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
isc::dhcp::HostContainer6
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_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.
Definition: host_container.h:213
isc::dhcp::SubnetID
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
Definition: lease.h:24
isc::dhcp::CfgHostsPtr
boost::shared_ptr< CfgHosts > CfgHostsPtr
Non-const pointer.
Definition: cfg_hosts.h:482
host_container.h
isc::dhcp::CfgHosts::del
virtual bool del(const SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete a host by address.
Definition: cfg_hosts.cc:597
isc::dhcp::CfgHosts::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: cfg_hosts.cc:225
isc::dhcp::ConstCfgHostsPtr
boost::shared_ptr< const CfgHosts > ConstCfgHostsPtr
Const pointer.
Definition: cfg_hosts.h:485
isc::dhcp::CfgHosts::getAll6
virtual ConstHostCollection getAll6(const asiolink::IOAddress &address) const
Returns a collection of hosts using the specified IPv6 address.
Definition: cfg_hosts.cc:68
isc::dhcp::CfgHosts::getAll4
virtual ConstHostCollection getAll4(const asiolink::IOAddress &address) const
Returns a collection of hosts using the specified IPv4 address.
Definition: cfg_hosts.cc:50
isc::dhcp::HostCollection
std::vector< HostPtr > HostCollection
Collection of the Host objects.
Definition: host.h:734