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>
15#include <dhcpsrv/subnet_id.h>
17#include <boost/shared_ptr.hpp>
18#include <vector>
19
20namespace isc {
21namespace dhcp {
22
39public:
40
42 virtual ~CfgHosts() { }
43
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
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
315private:
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
482typedef boost::shared_ptr<CfgHosts> CfgHostsPtr;
483
485typedef boost::shared_ptr<const CfgHosts> ConstCfgHostsPtr;
486
488
489}
490}
491
492#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:38
virtual ~CfgHosts()
Destructor.
Definition: cfg_hosts.h:42
virtual size_t delAll4(const SubnetID &subnet_id)
Attempts to delete all hosts for a given IPv4 subnet.
Definition: cfg_hosts.cc:604
virtual void add(const HostPtr &host)
Adds a new host to the collection.
Definition: cfg_hosts.cc:439
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
virtual ConstHostCollection getAll6(const asiolink::IOAddress &address) const
Returns a collection of hosts using the specified IPv6 address.
Definition: cfg_hosts.cc:68
virtual bool del(const SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete a host by address.
Definition: cfg_hosts.cc:597
virtual ConstHostCollection getAll4(const asiolink::IOAddress &address) const
Returns a collection of hosts using the specified IPv4 address.
Definition: cfg_hosts.cc:50
virtual size_t delAll6(const SubnetID &subnet_id)
Attempts to delete all hosts for a given IPv6 subnet.
Definition: cfg_hosts.cc:626
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
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
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
virtual std::string getType() const
Return backend type.
Definition: cfg_hosts.h:293
isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: cfg_hosts.cc:654
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:252
Interface for retrieving writable host reservations.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:22
boost::shared_ptr< const CfgHosts > ConstCfgHostsPtr
Const pointer.
Definition: cfg_hosts.h:485
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition: host.h:725
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.
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition: host.h:731
std::vector< HostPtr > HostCollection
Collection of the Host objects.
Definition: host.h:734
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
Definition: lease.h:24
boost::shared_ptr< CfgHosts > CfgHostsPtr
Non-const pointer.
Definition: cfg_hosts.h:482
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition: host.h:728
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.
Defines the logger used by the top-level component of kea-dhcp-ddns.
Abstract class for configuration Cfg_* classes.