Kea  2.3.2-git
memfile_lease_storage.h
Go to the documentation of this file.
1 // Copyright (C) 2015-2022 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/ordered_index.hpp>
18 #include <boost/multi_index_container.hpp>
19 #include <boost/multi_index/composite_key.hpp>
20 
21 #include <vector>
22 
23 namespace isc {
24 namespace dhcp {
25 
27 struct AddressIndexTag { };
28 
31 
33 struct ExpirationIndexTag { };
34 
37 
40 
42 struct SubnetIdIndexTag { };
43 
45 struct DuidIndexTag { };
46 
48 struct HostnameIndexTag { };
49 
52 
53 
65 typedef boost::multi_index_container<
66  // It holds pointers to Lease6 objects.
67  Lease6Ptr,
68  boost::multi_index::indexed_by<
69  // Specification of the first index starts here.
70  // This index sorts leases by IPv6 addresses represented as
71  // IOAddress objects.
72  boost::multi_index::ordered_unique<
73  boost::multi_index::tag<AddressIndexTag>,
74  boost::multi_index::member<Lease, isc::asiolink::IOAddress, &Lease::addr_>
75  >,
76 
77  // Specification of the second index starts here.
78  boost::multi_index::ordered_non_unique<
79  boost::multi_index::tag<DuidIaidTypeIndexTag>,
80  // This is a composite index that will be used to search for
81  // the lease using three attributes: DUID, IAID and lease type.
82  boost::multi_index::composite_key<
83  Lease6,
84  // The DUID can be retrieved from the Lease6 object using
85  // a getDuidVector const function.
86  boost::multi_index::const_mem_fun<Lease6, const std::vector<uint8_t>&,
88  // The two other ingredients of this index are IAID and
89  // lease type.
90  boost::multi_index::member<Lease6, uint32_t, &Lease6::iaid_>,
91  boost::multi_index::member<Lease6, Lease::Type, &Lease6::type_>
92  >
93  >,
94 
95  // Specification of the third index starts here.
96  boost::multi_index::ordered_non_unique<
97  boost::multi_index::tag<ExpirationIndexTag>,
98  // This is a composite index that is used to search for
99  // the expired leases. Depending on the value of the first component
100  // of the search key, the reclaimed or not reclaimed leases can
101  // be searched.
102  boost::multi_index::composite_key<
103  Lease6,
104  // The boolean value specifying if lease is reclaimed or not.
105  boost::multi_index::const_mem_fun<Lease, bool,
107  // Lease expiration time.
108  boost::multi_index::const_mem_fun<Lease, int64_t,
110  >
111  >,
112 
113  // Specification of the fourth index starts here.
114  // This index sorts leases by SubnetID.
115  boost::multi_index::ordered_non_unique<
116  boost::multi_index::tag<SubnetIdIndexTag>,
117  boost::multi_index::member<Lease, isc::dhcp::SubnetID,
119  >,
120 
121  // Specification of the fifth index starts here
122  // This index is used to retrieve leases for matching duid.
123  boost::multi_index::ordered_non_unique<
124  boost::multi_index::tag<DuidIndexTag>,
125  boost::multi_index::const_mem_fun<Lease6,
126  const std::vector<uint8_t>&,
127  &Lease6::getDuidVector>
128  >,
129 
130  // Specification of the sixth index starts here
131  // This index is used to retrieve leases for matching hostname.
132  boost::multi_index::ordered_non_unique<
133  boost::multi_index::tag<HostnameIndexTag>,
134  boost::multi_index::member<Lease, std::string, &Lease::hostname_>
135  >
136  >
137 > Lease6Storage; // Specify the type name of this container.
138 
151 typedef boost::multi_index_container<
152  // It holds pointers to Lease4 objects.
153  Lease4Ptr,
154  // Specification of search indexes starts here.
155  boost::multi_index::indexed_by<
156  // Specification of the first index starts here.
157  // This index sorts leases by IPv4 addresses represented as
158  // IOAddress objects.
159  boost::multi_index::ordered_unique<
160  boost::multi_index::tag<AddressIndexTag>,
161  // The IPv4 address are held in addr_ members that belong to
162  // Lease class.
163  boost::multi_index::member<Lease, isc::asiolink::IOAddress, &Lease::addr_>
164  >,
165 
166  // Specification of the second index starts here.
167  boost::multi_index::ordered_non_unique<
168  boost::multi_index::tag<HWAddressSubnetIdIndexTag>,
169  // This is a composite index that combines two attributes of the
170  // Lease4 object: hardware address and subnet id.
171  boost::multi_index::composite_key<
172  Lease4,
173  // The hardware address is held in the hwaddr_ member of the
174  // Lease4 object, which is a HWAddr object. Boost does not
175  // provide a key extractor for getting a member of a member,
176  // so we need a simple method for that.
177  boost::multi_index::const_mem_fun<Lease, const std::vector<uint8_t>&,
179  // The subnet id is held in the subnet_id_ member of Lease4
180  // class. Note that the subnet_id_ is defined in the base
181  // class (Lease) so we have to point to this class rather
182  // than derived class: Lease4.
183  boost::multi_index::member<Lease, SubnetID, &Lease::subnet_id_>
184  >
185  >,
186 
187  // Specification of the third index starts here.
188  boost::multi_index::ordered_non_unique<
189  boost::multi_index::tag<ClientIdSubnetIdIndexTag>,
190  // This is a composite index that uses two values to search for a
191  // lease: client id and subnet id.
192  boost::multi_index::composite_key<
193  Lease4,
194  // The client id can be retrieved from the Lease4 object by
195  // calling getClientIdVector const function.
196  boost::multi_index::const_mem_fun<Lease4, const std::vector<uint8_t>&,
198  // The subnet id is accessed through the subnet_id_ member.
199  boost::multi_index::member<Lease, uint32_t, &Lease::subnet_id_>
200  >
201  >,
202 
203  // Specification of the fourth index starts here.
204  boost::multi_index::ordered_non_unique<
205  boost::multi_index::tag<ExpirationIndexTag>,
206  // This is a composite index that will be used to search for
207  // the expired leases. Depending on the value of the first component
208  // of the search key, the reclaimed or not reclaimed leases will can
209  // be searched.
210  boost::multi_index::composite_key<
211  Lease4,
212  // The boolean value specifying if lease is reclaimed or not.
213  boost::multi_index::const_mem_fun<Lease, bool,
214  &Lease::stateExpiredReclaimed>,
215  // Lease expiration time.
216  boost::multi_index::const_mem_fun<Lease, int64_t,
217  &Lease::getExpirationTime>
218  >
219  >,
220 
221  // Specification of the fifth index starts here.
222  // This index sorts leases by SubnetID.
223  boost::multi_index::ordered_non_unique<
224  boost::multi_index::tag<SubnetIdIndexTag>,
225  boost::multi_index::member<Lease, isc::dhcp::SubnetID, &Lease::subnet_id_>
226  >,
227 
228  // Specification of the seventh index starts here
229  // This index is used to retrieve leases for matching hostname.
230  boost::multi_index::ordered_non_unique<
231  boost::multi_index::tag<HostnameIndexTag>,
232  boost::multi_index::member<Lease, std::string, &Lease::hostname_>
233  >
234  >
235 > Lease4Storage; // Specify the type name for this container.
236 
238 
241 
242 
244 typedef Lease6Storage::index<AddressIndexTag>::type Lease6StorageAddressIndex;
245 
247 typedef Lease6Storage::index<DuidIaidTypeIndexTag>::type Lease6StorageDuidIaidTypeIndex;
248 
250 typedef Lease6Storage::index<ExpirationIndexTag>::type Lease6StorageExpirationIndex;
251 
253 typedef Lease6Storage::index<SubnetIdIndexTag>::type Lease6StorageSubnetIdIndex;
254 
256 typedef Lease6Storage::index<DuidIndexTag>::type Lease6StorageDuidIndex;
257 
259 typedef Lease6Storage::index<HostnameIndexTag>::type Lease6StorageHostnameIndex;
260 
262 typedef Lease4Storage::index<AddressIndexTag>::type Lease4StorageAddressIndex;
263 
265 typedef Lease4Storage::index<ExpirationIndexTag>::type Lease4StorageExpirationIndex;
266 
268 typedef Lease4Storage::index<HWAddressSubnetIdIndexTag>::type
270 
272 typedef Lease4Storage::index<ClientIdSubnetIdIndexTag>::type
274 
276 typedef Lease4Storage::index<SubnetIdIndexTag>::type Lease4StorageSubnetIdIndex;
277 
279 typedef Lease4Storage::index<HostnameIndexTag>::type Lease4StorageHostnameIndex;
280 
282 } // end of isc::dhcp namespace
283 } // end of isc namespace
284 
285 #endif // MEMFILE_LEASE_STORAGE_H
Tag for indexes by DUID, IAID, lease type tuple.
Structure that holds a lease for IPv4 address.
Definition: lease.h:295
const std::vector< uint8_t > & getHWAddrVector() const
Returns raw (as vector) hardware address.
Definition: lease.cc:355
Lease4Storage::index< HostnameIndexTag >::type Lease4StorageHostnameIndex
DHCPv4 lease storage index by hostname.
Lease6Storage::index< DuidIaidTypeIndexTag >::type Lease6StorageDuidIaidTypeIndex
DHCPv6 lease storage index by DUID, IAID, lease type.
Tag for indexes by expiration time.
Lease4Storage::index< HWAddressSubnetIdIndexTag >::type Lease4StorageHWAddressSubnetIdIndex
DHCPv4 lease storage index by HW address and subnet identifier.
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_ > > >> Lease4Storage
A multi index container holding DHCPv4 leases.
SubnetID subnet_id_
Subnet identifier.
Definition: lease.h:154
Tag for index using hostname.
Lease6Storage::index< AddressIndexTag >::type Lease6StorageAddressIndex
DHCPv6 lease storage index by address.
Lease6Storage::index< DuidIndexTag >::type Lease6StorageDuidIndex
DHCPv6 lease storage index by DUID.
Lease4Storage::index< AddressIndexTag >::type Lease4StorageAddressIndex
DHCPv4 lease storage index by address.
Lease4Storage::index< SubnetIdIndexTag >::type Lease4StorageSubnetIdIndex
DHCPv4 lease storage index subnet identifier.
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.
int64_t getExpirationTime() const
Returns lease expiration time.
Definition: lease.cc:123
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Definition: lease.h:284
Lease4Storage::index< ExpirationIndexTag >::type Lease4StorageExpirationIndex
DHCPv4 lease storage index by expiration time.
Structure that holds a lease for IPv6 address and/or prefix.
Definition: lease.h:514
Lease6Storage::index< HostnameIndexTag >::type Lease6StorageHostnameIndex
DHCPv6 lease storage index by hostname.
Tag for index using DUID.
Tag for indexes by HW address, subnet identifier tuple.
Defines the logger used by the top-level component of kea-lfc.
Tag for indexes by address.
const std::vector< uint8_t > & getDuidVector() const
Returns a reference to a vector representing a DUID.
Definition: lease.cc:533
bool stateExpiredReclaimed() const
Indicates if the lease is in the "expired-reclaimed" state.
Definition: lease.cc:113
a common structure for IPv4 and IPv6 leases
Definition: lease.h:31
Lease6Storage::index< ExpirationIndexTag >::type Lease6StorageExpirationIndex
DHCPv6 lease storage index by expiration time.
Tag for indexes by client and subnet identifiers.
Tag for indexes by subnet-id.
const std::vector< uint8_t > & getClientIdVector() const
Returns a client identifier.
Definition: lease.cc:345
Lease4Storage::index< ClientIdSubnetIdIndexTag >::type Lease4StorageClientIdSubnetIdIndex
DHCPv4 lease storage index by client and subnet identifier.
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition: lease.h:503
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition: subnet_id.h:24
Lease6Storage::index< SubnetIdIndexTag >::type Lease6StorageSubnetIdIndex
DHCPv6 lease storage index by Subnet-id.