Kea  2.3.7
memfile_lease_storage.h
Go to the documentation of this file.
1 // Copyright (C) 2015-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 MEMFILE_LEASE_STORAGE_H
8 #define MEMFILE_LEASE_STORAGE_H
9 
10 #include <asiolink/io_address.h>
11 #include <dhcpsrv/lease.h>
12 #include <dhcpsrv/subnet_id.h>
13 
14 #include <boost/multi_index/indexed_by.hpp>
15 #include <boost/multi_index/member.hpp>
16 #include <boost/multi_index/mem_fun.hpp>
17 #include <boost/multi_index/hashed_index.hpp>
18 #include <boost/multi_index/ordered_index.hpp>
19 #include <boost/multi_index_container.hpp>
20 #include <boost/multi_index/composite_key.hpp>
21 
22 #include <functional>
23 #include <vector>
24 
25 namespace isc {
26 namespace dhcp {
27 
29 struct AddressIndexTag { };
30 
33 
35 struct ExpirationIndexTag { };
36 
39 
42 
44 struct SubnetIdIndexTag { };
45 
47 struct DuidIndexTag { };
48 
50 struct HostnameIndexTag { };
51 
53 struct RemoteIdIndexTag { };
54 
56 struct RelayIdIndexTag { };
57 
60 
61 
75 typedef boost::multi_index_container<
76  // It holds pointers to Lease6 objects.
77  Lease6Ptr,
78  boost::multi_index::indexed_by<
79  // Specification of the first index starts here.
80  // This index sorts leases by IPv6 addresses represented as
81  // IOAddress objects.
82  boost::multi_index::ordered_unique<
83  boost::multi_index::tag<AddressIndexTag>,
84  boost::multi_index::member<Lease, isc::asiolink::IOAddress, &Lease::addr_>
85  >,
86 
87  // Specification of the second index starts here.
88  boost::multi_index::ordered_non_unique<
89  boost::multi_index::tag<DuidIaidTypeIndexTag>,
90  // This is a composite index that will be used to search for
91  // the lease using three attributes: DUID, IAID and lease type.
92  boost::multi_index::composite_key<
93  Lease6,
94  // The DUID can be retrieved from the Lease6 object using
95  // a getDuidVector const function.
96  boost::multi_index::const_mem_fun<Lease6, const std::vector<uint8_t>&,
98  // The two other ingredients of this index are IAID and
99  // lease type.
100  boost::multi_index::member<Lease6, uint32_t, &Lease6::iaid_>,
101  boost::multi_index::member<Lease6, Lease::Type, &Lease6::type_>
102  >
103  >,
104 
105  // Specification of the third index starts here.
106  boost::multi_index::ordered_non_unique<
107  boost::multi_index::tag<ExpirationIndexTag>,
108  // This is a composite index that is used to search for
109  // the expired leases. Depending on the value of the first component
110  // of the search key, the reclaimed or not reclaimed leases can
111  // be searched.
112  boost::multi_index::composite_key<
113  Lease6,
114  // The boolean value specifying if lease is reclaimed or not.
115  boost::multi_index::const_mem_fun<Lease, bool,
117  // Lease expiration time.
118  boost::multi_index::const_mem_fun<Lease, int64_t,
120  >
121  >,
122 
123  // Specification of the fourth index starts here.
124  // This index sorts leases by SubnetID.
125  boost::multi_index::ordered_non_unique<
126  boost::multi_index::tag<SubnetIdIndexTag>,
127  boost::multi_index::member<Lease, isc::dhcp::SubnetID,
129  >,
130 
131  // Specification of the fifth index starts here
132  // This index is used to retrieve leases for matching duid.
133  boost::multi_index::ordered_non_unique<
134  boost::multi_index::tag<DuidIndexTag>,
135  boost::multi_index::const_mem_fun<Lease6,
136  const std::vector<uint8_t>&,
138  >,
139 
140  // Specification of the sixth index starts here
141  // This index is used to retrieve leases for matching hostname.
142  boost::multi_index::ordered_non_unique<
143  boost::multi_index::tag<HostnameIndexTag>,
144  boost::multi_index::member<Lease, std::string, &Lease::hostname_>
145  >
146  >
147 > Lease6Storage; // Specify the type name of this container.
148 
165 typedef boost::multi_index_container<
166  // It holds pointers to Lease4 objects.
167  Lease4Ptr,
168  // Specification of search indexes starts here.
169  boost::multi_index::indexed_by<
170  // Specification of the first index starts here.
171  // This index sorts leases by IPv4 addresses represented as
172  // IOAddress objects.
173  boost::multi_index::ordered_unique<
174  boost::multi_index::tag<AddressIndexTag>,
175  // The IPv4 address are held in addr_ members that belong to
176  // Lease class.
177  boost::multi_index::member<Lease, isc::asiolink::IOAddress, &Lease::addr_>
178  >,
179 
180  // Specification of the second index starts here.
181  boost::multi_index::ordered_non_unique<
182  boost::multi_index::tag<HWAddressSubnetIdIndexTag>,
183  // This is a composite index that combines two attributes of the
184  // Lease4 object: hardware address and subnet id.
185  boost::multi_index::composite_key<
186  Lease4,
187  // The hardware address is held in the hwaddr_ member of the
188  // Lease4 object, which is a HWAddr object. Boost does not
189  // provide a key extractor for getting a member of a member,
190  // so we need a simple method for that.
191  boost::multi_index::const_mem_fun<Lease, const std::vector<uint8_t>&,
193  // The subnet id is held in the subnet_id_ member of Lease4
194  // class. Note that the subnet_id_ is defined in the base
195  // class (Lease) so we have to point to this class rather
196  // than derived class: Lease4.
197  boost::multi_index::member<Lease, SubnetID, &Lease::subnet_id_>
198  >
199  >,
200 
201  // Specification of the third index starts here.
202  boost::multi_index::ordered_non_unique<
203  boost::multi_index::tag<ClientIdSubnetIdIndexTag>,
204  // This is a composite index that uses two values to search for a
205  // lease: client id and subnet id.
206  boost::multi_index::composite_key<
207  Lease4,
208  // The client id can be retrieved from the Lease4 object by
209  // calling getClientIdVector const function.
210  boost::multi_index::const_mem_fun<Lease4, const std::vector<uint8_t>&,
212  // The subnet id is accessed through the subnet_id_ member.
213  boost::multi_index::member<Lease, uint32_t, &Lease::subnet_id_>
214  >
215  >,
216 
217  // Specification of the fourth index starts here.
218  boost::multi_index::ordered_non_unique<
219  boost::multi_index::tag<ExpirationIndexTag>,
220  // This is a composite index that will be used to search for
221  // the expired leases. Depending on the value of the first component
222  // of the search key, the reclaimed or not reclaimed leases will can
223  // be searched.
224  boost::multi_index::composite_key<
225  Lease4,
226  // The boolean value specifying if lease is reclaimed or not.
227  boost::multi_index::const_mem_fun<Lease, bool,
229  // Lease expiration time.
230  boost::multi_index::const_mem_fun<Lease, int64_t,
232  >
233  >,
234 
235  // Specification of the fifth index starts here.
236  // This index sorts leases by SubnetID.
237  boost::multi_index::ordered_non_unique<
238  boost::multi_index::tag<SubnetIdIndexTag>,
239  boost::multi_index::member<Lease, isc::dhcp::SubnetID, &Lease::subnet_id_>
240  >,
241 
242  // Specification of the sixth index starts here.
243  // This index is used to retrieve leases for matching hostname.
244  boost::multi_index::ordered_non_unique<
245  boost::multi_index::tag<HostnameIndexTag>,
246  boost::multi_index::member<Lease, std::string, &Lease::hostname_>
247  >,
248 
249  // Specification of the seventh index starts here.
250  // This index is used to retrieve leases for matching remote id
251  // for Bulk Lease Query.
252  boost::multi_index::hashed_non_unique<
253  boost::multi_index::tag<RemoteIdIndexTag>,
254  boost::multi_index::member<Lease4,
255  std::vector<uint8_t>,
257  >,
258 
259  // Specification of the eighth index starts here.
260  // This index is used to retrieve leases for matching relay id
261  // for Bulk Lease Query.
262  boost::multi_index::ordered_non_unique<
263  boost::multi_index::tag<RelayIdIndexTag>,
264  boost::multi_index::composite_key<
265  Lease4,
266  // Relay id.
267  boost::multi_index::member<Lease4,
268  std::vector<uint8_t>,
270  // Address.
271  boost::multi_index::member<Lease,
273  &Lease::addr_>
274  >
275  >
276  >
277 > Lease4Storage; // Specify the type name for this container.
278 
280 
283 
284 
286 typedef Lease6Storage::index<AddressIndexTag>::type Lease6StorageAddressIndex;
287 
289 typedef Lease6Storage::index<DuidIaidTypeIndexTag>::type Lease6StorageDuidIaidTypeIndex;
290 
292 typedef Lease6Storage::index<ExpirationIndexTag>::type Lease6StorageExpirationIndex;
293 
295 typedef Lease6Storage::index<SubnetIdIndexTag>::type Lease6StorageSubnetIdIndex;
296 
298 typedef Lease6Storage::index<DuidIndexTag>::type Lease6StorageDuidIndex;
299 
301 typedef Lease6Storage::index<HostnameIndexTag>::type Lease6StorageHostnameIndex;
302 
304 typedef Lease4Storage::index<AddressIndexTag>::type Lease4StorageAddressIndex;
305 
307 typedef Lease4Storage::index<ExpirationIndexTag>::type Lease4StorageExpirationIndex;
308 
310 typedef Lease4Storage::index<HWAddressSubnetIdIndexTag>::type
312 
314 typedef Lease4Storage::index<ClientIdSubnetIdIndexTag>::type
316 
318 typedef Lease4Storage::index<SubnetIdIndexTag>::type Lease4StorageSubnetIdIndex;
319 
321 typedef Lease4Storage::index<HostnameIndexTag>::type Lease4StorageHostnameIndex;
322 
324 typedef Lease4Storage::index<RemoteIdIndexTag>::type Lease4StorageRemoteIdIndex;
325 
327 typedef std::pair<Lease4StorageRemoteIdIndex::const_iterator,
328  Lease4StorageRemoteIdIndex::const_iterator> Lease4StorageRemoteIdRange;
329 
331 typedef Lease4Storage::index<RelayIdIndexTag>::type Lease4StorageRelayIdIndex;
332 
334 
337 
338 
341 public:
347  const std::vector<uint8_t>& id)
348  : lease_addr_(lease_addr), id_(id) {
349  }
350 
353 
355  std::vector<uint8_t> id_;
356 };
357 
359 typedef boost::shared_ptr<Lease6ExtendedInfo> Lease6ExtendedInfoPtr;
360 
363 
376 typedef boost::multi_index_container<
377  // It holds pointers to lease6 extended info.
379  boost::multi_index::indexed_by<
380  // First index is by relay id and lease address.
381  boost::multi_index::ordered_non_unique<
382  boost::multi_index::tag<RelayIdIndexTag>,
383  boost::multi_index::composite_key<
385  boost::multi_index::member<Lease6ExtendedInfo,
386  std::vector<uint8_t>,
388  boost::multi_index::member<Lease6ExtendedInfo,
391  >
392  >,
393 
394  // Last index is by lease address.
395  boost::multi_index::hashed_non_unique<
396  boost::multi_index::tag<LeaseAddressIndexTag>,
397  boost::multi_index::member<Lease6ExtendedInfo,
400  >
401  >
403 
417 typedef boost::multi_index_container<
418  // It holds pointers to lease6 extended info.
420  boost::multi_index::indexed_by<
421  // First index is by remote id.
422  boost::multi_index::hashed_non_unique<
423  boost::multi_index::tag<RemoteIdIndexTag>,
424  boost::multi_index::member<Lease6ExtendedInfo,
425  std::vector<uint8_t>,
427  >,
428 
429  // Last index is by lease address.
430  boost::multi_index::hashed_non_unique<
431  boost::multi_index::tag<LeaseAddressIndexTag>,
432  boost::multi_index::member<Lease6ExtendedInfo,
435  >
436  >
438 
440 typedef Lease6ExtendedInfoRelayIdTable::index<RelayIdIndexTag>::type
442 
444 typedef Lease6ExtendedInfoRelayIdTable::index<LeaseAddressIndexTag>::type
446 
448 typedef Lease6ExtendedInfoRemoteIdTable::index<RemoteIdIndexTag>::type
450 
452 typedef std::pair<RemoteIdIndex::const_iterator, RemoteIdIndex::const_iterator>
454 
456 typedef Lease6ExtendedInfoRemoteIdTable::index<LeaseAddressIndexTag>::type
458 
460 
461 } // end of isc::dhcp namespace
462 } // end of isc namespace
463 
464 #endif // MEMFILE_LEASE_STORAGE_H
Lease6 extended informations for Bulk Lease Query.
Lease6ExtendedInfo(const isc::asiolink::IOAddress &lease_addr, const std::vector< uint8_t > &id)
Constructor.
std::vector< uint8_t > id_
Remote or relay opaque identifier.
isc::asiolink::IOAddress lease_addr_
Lease address.
boost::multi_index_container< Lease6ExtendedInfoPtr, boost::multi_index::indexed_by< boost::multi_index::hashed_non_unique< boost::multi_index::tag< RemoteIdIndexTag >, boost::multi_index::member< Lease6ExtendedInfo, std::vector< uint8_t >, &Lease6ExtendedInfo::id_ > >, boost::multi_index::hashed_non_unique< boost::multi_index::tag< LeaseAddressIndexTag >, boost::multi_index::member< Lease6ExtendedInfo, isc::asiolink::IOAddress, &Lease6ExtendedInfo::lease_addr_ > > >> Lease6ExtendedInfoRemoteIdTable
A multi index container holding lease6 extended info for by remote id.
Lease6Storage::index< ExpirationIndexTag >::type Lease6StorageExpirationIndex
DHCPv6 lease storage index by expiration time.
Lease6Storage::index< DuidIndexTag >::type Lease6StorageDuidIndex
DHCPv6 lease storage index by DUID.
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition: lease.h:509
Lease6Storage::index< DuidIaidTypeIndexTag >::type Lease6StorageDuidIaidTypeIndex
DHCPv6 lease storage index by DUID, IAID, lease type.
boost::multi_index_container< Lease4Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< AddressIndexTag >, boost::multi_index::member< Lease, isc::asiolink::IOAddress, &Lease::addr_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< HWAddressSubnetIdIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::const_mem_fun< Lease, const std::vector< uint8_t > &, &Lease::getHWAddrVector >, boost::multi_index::member< Lease, SubnetID, &Lease::subnet_id_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ClientIdSubnetIdIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::const_mem_fun< Lease4, const std::vector< uint8_t > &, &Lease4::getClientIdVector >, boost::multi_index::member< Lease, uint32_t, &Lease::subnet_id_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ExpirationIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::const_mem_fun< Lease, bool, &Lease::stateExpiredReclaimed >, boost::multi_index::const_mem_fun< Lease, int64_t, &Lease::getExpirationTime > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetIdIndexTag >, boost::multi_index::member< Lease, isc::dhcp::SubnetID, &Lease::subnet_id_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< HostnameIndexTag >, boost::multi_index::member< Lease, std::string, &Lease::hostname_ > >, boost::multi_index::hashed_non_unique< boost::multi_index::tag< RemoteIdIndexTag >, boost::multi_index::member< Lease4, std::vector< uint8_t >, &Lease4::remote_id_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< RelayIdIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::member< Lease4, std::vector< uint8_t >, &Lease4::relay_id_ >, boost::multi_index::member< Lease, isc::asiolink::IOAddress, &Lease::addr_ > > > >> Lease4Storage
A multi index container holding DHCPv4 leases.
Lease4Storage::index< ExpirationIndexTag >::type Lease4StorageExpirationIndex
DHCPv4 lease storage index by expiration time.
Lease6Storage::index< AddressIndexTag >::type Lease6StorageAddressIndex
DHCPv6 lease storage index by address.
Lease4Storage::index< HostnameIndexTag >::type Lease4StorageHostnameIndex
DHCPv4 lease storage index by hostname.
std::pair< Lease4StorageRemoteIdIndex::const_iterator, Lease4StorageRemoteIdIndex::const_iterator > Lease4StorageRemoteIdRange
DHCPv4 lease storage range by remote identifier.
Lease6Storage::index< HostnameIndexTag >::type Lease6StorageHostnameIndex
DHCPv6 lease storage index by hostname.
Lease4Storage::index< ClientIdSubnetIdIndexTag >::type Lease4StorageClientIdSubnetIdIndex
DHCPv4 lease storage index by client and subnet identifier.
Lease4Storage::index< HWAddressSubnetIdIndexTag >::type Lease4StorageHWAddressSubnetIdIndex
DHCPv4 lease storage index by HW address and subnet identifier.
Lease6ExtendedInfoRelayIdTable::index< LeaseAddressIndexTag >::type LeaseAddressRelayIdIndex
Lease6 extended information by lease address index of by relay id table.
Lease6ExtendedInfoRelayIdTable::index< RelayIdIndexTag >::type RelayIdIndex
Lease6 extended information by relay id index.
Lease4Storage::index< RemoteIdIndexTag >::type Lease4StorageRemoteIdIndex
DHCPv4 lease storage index by remote identifier.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition: subnet_id.h:25
boost::multi_index_container< Lease6Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< AddressIndexTag >, boost::multi_index::member< Lease, isc::asiolink::IOAddress, &Lease::addr_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< DuidIaidTypeIndexTag >, boost::multi_index::composite_key< Lease6, boost::multi_index::const_mem_fun< Lease6, const std::vector< uint8_t > &, &Lease6::getDuidVector >, boost::multi_index::member< Lease6, uint32_t, &Lease6::iaid_ >, boost::multi_index::member< Lease6, Lease::Type, &Lease6::type_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ExpirationIndexTag >, boost::multi_index::composite_key< Lease6, boost::multi_index::const_mem_fun< Lease, bool, &Lease::stateExpiredReclaimed >, boost::multi_index::const_mem_fun< Lease, int64_t, &Lease::getExpirationTime > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetIdIndexTag >, boost::multi_index::member< Lease, isc::dhcp::SubnetID, &Lease::subnet_id_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< DuidIndexTag >, boost::multi_index::const_mem_fun< Lease6, const std::vector< uint8_t > &, &Lease6::getDuidVector > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< HostnameIndexTag >, boost::multi_index::member< Lease, std::string, &Lease::hostname_ > > >> Lease6Storage
A multi index container holding DHCPv6 leases.
std::pair< RemoteIdIndex::const_iterator, RemoteIdIndex::const_iterator > RemoteIdIndexRange
Lease6 extended information by remote id range.
Lease4Storage::index< SubnetIdIndexTag >::type Lease4StorageSubnetIdIndex
DHCPv4 lease storage index subnet identifier.
Lease4Storage::index< AddressIndexTag >::type Lease4StorageAddressIndex
DHCPv4 lease storage index by address.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Definition: lease.h:284
Lease6ExtendedInfoRemoteIdTable::index< LeaseAddressIndexTag >::type LeaseAddressRemoteIdIndex
Lease6 extended information by lease address index of by remote id table.
Lease6Storage::index< SubnetIdIndexTag >::type Lease6StorageSubnetIdIndex
DHCPv6 lease storage index by Subnet-id.
boost::multi_index_container< Lease6ExtendedInfoPtr, boost::multi_index::indexed_by< boost::multi_index::ordered_non_unique< boost::multi_index::tag< RelayIdIndexTag >, boost::multi_index::composite_key< Lease6ExtendedInfo, boost::multi_index::member< Lease6ExtendedInfo, std::vector< uint8_t >, &Lease6ExtendedInfo::id_ >, boost::multi_index::member< Lease6ExtendedInfo, isc::asiolink::IOAddress, &Lease6ExtendedInfo::lease_addr_ > > >, boost::multi_index::hashed_non_unique< boost::multi_index::tag< LeaseAddressIndexTag >, boost::multi_index::member< Lease6ExtendedInfo, isc::asiolink::IOAddress, &Lease6ExtendedInfo::lease_addr_ > > >> Lease6ExtendedInfoRelayIdTable
A multi index container holding lease6 extended info for by relay id.
boost::shared_ptr< Lease6ExtendedInfo > Lease6ExtendedInfoPtr
Pointer to a Lease6ExtendedInfo object.
Lease6ExtendedInfoRemoteIdTable::index< RemoteIdIndexTag >::type RemoteIdIndex
Lease6 extended information by remote id index.
Lease4Storage::index< RelayIdIndexTag >::type Lease4StorageRelayIdIndex
DHCPv4 lease storage index by relay identifier.
Defines the logger used by the top-level component of kea-lfc.
Tag for indexes by address.
Tag for indexes by client and subnet identifiers.
Tag for indexes by DUID, IAID, lease type tuple.
Tag for index using DUID.
Tag for indexes by expiration time.
Tag for indexes by HW address, subnet identifier tuple.
Tag for index using hostname.
Structure that holds a lease for IPv4 address.
Definition: lease.h:295
std::vector< uint8_t > remote_id_
Remote identifier for Bulk Lease Query.
Definition: lease.h:497
std::vector< uint8_t > relay_id_
Relay identifier for Bulk Lease Query.
Definition: lease.h:500
const std::vector< uint8_t > & getClientIdVector() const
Returns a client identifier.
Definition: lease.cc:348
Structure that holds a lease for IPv6 address and/or prefix.
Definition: lease.h:520
const std::vector< uint8_t > & getDuidVector() const
Returns a reference to a vector representing a DUID.
Definition: lease.cc:542
Tag for indexes by lease address.
a common structure for IPv4 and IPv6 leases
Definition: lease.h:31
bool stateExpiredReclaimed() const
Indicates if the lease is in the "expired-reclaimed" state.
Definition: lease.cc:114
SubnetID subnet_id_
Subnet identifier.
Definition: lease.h:154
const std::vector< uint8_t > & getHWAddrVector() const
Returns raw (as vector) hardware address.
Definition: lease.cc:358
int64_t getExpirationTime() const
Returns lease expiration time.
Definition: lease.cc:124
isc::asiolink::IOAddress addr_
IPv4 ot IPv6 address.
Definition: lease.h:120
Tag for index using relay-id.
Tag for index using remote-id.
Tag for indexes by subnet-id.