23#include <boost/foreach.hpp>
40const char* KEA_LFC_EXECUTABLE_ENV_NAME =
"KEA_LFC_EXECUTABLE";
96 void setup(
const uint32_t lfc_interval,
97 const boost::shared_ptr<CSVLeaseFile4>& lease_file4,
98 const boost::shared_ptr<CSVLeaseFile6>& lease_file6,
99 bool run_once_now =
false);
116 boost::scoped_ptr<ProcessSpawn> process_;
132 : process_(), callback_(callback), pid_(0),
148 timer_mgr_->unregisterTimer(
"memfile-lfc");
150 }
catch (
const std::exception& ex) {
161 const boost::shared_ptr<CSVLeaseFile4>& lease_file4,
162 const boost::shared_ptr<CSVLeaseFile6>& lease_file6,
166 if (lfc_interval == 0 && !run_once_now) {
171 std::string executable;
172 char* c_executable = getenv(KEA_LFC_EXECUTABLE_ENV_NAME);
174 executable = KEA_LFC_EXECUTABLE;
176 executable = c_executable;
180 std::string lease_file = lease_file4 ? lease_file4->getFilename() :
181 lease_file6->getFilename();
186 args.push_back(lease_file4 ?
"-4" :
"-6");
189 args.push_back(
"-x");
193 args.push_back(
"-i");
197 args.push_back(
"-o");
201 args.push_back(
"-f");
205 args.push_back(
"-p");
210 args.push_back(
"-c");
211 args.push_back(
"ignored-path");
223 if (lfc_interval > 0) {
230 timer_mgr_->registerTimer(
"memfile-lfc", callback_, lfc_interval * 1000,
232 timer_mgr_->setup(
"memfile-lfc");
240 .arg(process_->getCommandLine());
241 pid_ = process_->spawn();
250 return (process_ && process_->isRunning(pid_));
257 " the process is null");
259 return (process_->getExitStatus(pid_));
318 return (
rows_.size());
414 void startSubnets() {
419 Lease4StorageSubnetIdIndex::const_iterator lower;
420 Lease4StorageSubnetIdIndex::const_iterator upper;
443 if (lower == upper) {
451 int64_t assigned = 0;
452 int64_t declined = 0;
453 for (Lease4StorageSubnetIdIndex::const_iterator lease = lower;
454 lease != upper; ++lease) {
457 if ((*lease)->subnet_id_ != cur_id) {
460 rows_.push_back(LeaseStatsRow(cur_id,
467 rows_.push_back(LeaseStatsRow(cur_id,
475 cur_id = (*lease)->subnet_id_;
515 void startSubnetPools() {
517 = storage4_.get<SubnetIdPoolIdIndexTag>();
520 Lease4StorageSubnetIdPoolIdIndex::const_iterator lower;
521 Lease4StorageSubnetIdPoolIdIndex::const_iterator upper;
533 if (lower == upper) {
541 uint32_t cur_pool_id = 0;
542 int64_t assigned = 0;
543 int64_t declined = 0;
544 for (Lease4StorageSubnetIdPoolIdIndex::const_iterator lease = lower;
545 lease != upper; ++lease) {
548 if ((*lease)->pool_id_ != cur_pool_id) {
550 rows_.push_back(LeaseStatsRow(cur_id,
552 assigned, cur_pool_id));
557 rows_.push_back(LeaseStatsRow(cur_id,
559 declined, cur_pool_id));
564 cur_pool_id = (*lease)->pool_id_;
569 if ((*lease)->subnet_id_ != cur_id) {
572 rows_.push_back(LeaseStatsRow(cur_id,
574 assigned, cur_pool_id));
579 rows_.push_back(LeaseStatsRow(cur_id,
581 declined, cur_pool_id));
587 cur_id = (*lease)->subnet_id_;
604 assigned, cur_pool_id));
609 declined, cur_pool_id));
708 virtual void startSubnets() {
713 Lease6StorageSubnetIdIndex::const_iterator lower;
714 Lease6StorageSubnetIdIndex::const_iterator upper;
736 if (lower == upper) {
744 int64_t assigned = 0;
745 int64_t declined = 0;
746 int64_t assigned_pds = 0;
747 int64_t registered = 0;
748 for (Lease6StorageSubnetIdIndex::const_iterator lease = lower;
749 lease != upper; ++lease) {
752 if ((*lease)->subnet_id_ != cur_id) {
768 if (assigned_pds > 0) {
775 if (registered > 0) {
784 cur_id = (*lease)->subnet_id_;
789 switch((*lease)->type_) {
823 if (assigned_pds > 0) {
828 if (registered > 0) {
851 virtual void startSubnetPools() {
853 = storage6_.get<SubnetIdPoolIdIndexTag>();
856 Lease6StorageSubnetIdPoolIdIndex::const_iterator lower;
857 Lease6StorageSubnetIdPoolIdIndex::const_iterator upper;
869 if (lower == upper) {
877 uint32_t cur_pool_id = 0;
878 int64_t assigned = 0;
879 int64_t declined = 0;
880 int64_t assigned_pds = 0;
881 for (Lease6StorageSubnetIdPoolIdIndex::const_iterator lease = lower;
882 lease != upper; ++lease) {
885 if ((*lease)->pool_id_ != cur_pool_id) {
889 assigned, cur_pool_id));
896 declined, cur_pool_id));
900 if (assigned_pds > 0) {
903 assigned_pds, cur_pool_id));
908 cur_pool_id = (*lease)->pool_id_;
913 if ((*lease)->subnet_id_ != cur_id) {
918 assigned, cur_pool_id));
925 declined, cur_pool_id));
929 if (assigned_pds > 0) {
932 assigned_pds, cur_pool_id));
938 cur_id = (*lease)->subnet_id_;
946 switch((*lease)->type_) {
977 if (assigned_pds > 0) {
999 :
TrackingLeaseMgr(), lfc_setup_(), conn_(parameters), mutex_(new std::mutex) {
1000 bool conversion_needed =
false;
1006 std::string universe = conn_.getParameter(
"universe");
1007 if (universe ==
"4") {
1008 std::string file4 = initLeaseFilePath(
V4);
1009 if (!file4.empty()) {
1010 conversion_needed = loadLeasesFromFiles<
Lease4,
1017 std::string file6 = initLeaseFilePath(
V6);
1018 if (!file6.empty()) {
1019 conversion_needed = loadLeasesFromFiles<
Lease6,
1034 if (conversion_needed) {
1039 lfcSetup(conversion_needed);
1056 std::stringstream tmp;
1057 tmp <<
"Memfile backend ";
1060 }
else if (u ==
V6) {
1069 if (family == AF_INET6) {
1077Memfile_LeaseMgr::addLeaseInternal(
const Lease4Ptr& lease) {
1078 if (getLease4Internal(lease->addr_)) {
1090 storage4_.insert(lease);
1094 lease->updateCurrentExpirationTime();
1097 class_lease_counter_.
addLease(lease);
1113 std::lock_guard<std::mutex> lock(*mutex_);
1114 return (addLeaseInternal(lease));
1116 return (addLeaseInternal(lease));
1121Memfile_LeaseMgr::addLeaseInternal(
const Lease6Ptr& lease) {
1122 if (getLease6Internal(lease->type_, lease->addr_)) {
1135 storage6_.insert(lease);
1139 lease->updateCurrentExpirationTime();
1142 class_lease_counter_.
addLease(lease);
1162 std::lock_guard<std::mutex> lock(*mutex_);
1163 return (addLeaseInternal(lease));
1165 return (addLeaseInternal(lease));
1172 Lease4StorageAddressIndex::iterator l = idx.find(addr);
1173 if (l == idx.end()) {
1186 std::lock_guard<std::mutex> lock(*mutex_);
1187 return (getLease4Internal(addr));
1189 return (getLease4Internal(addr));
1194Memfile_LeaseMgr::getLease4Internal(
const HWAddr& hwaddr,
1200 std::pair<Lease4StorageHWAddressSubnetIdIndex::const_iterator,
1201 Lease4StorageHWAddressSubnetIdIndex::const_iterator> l
1202 = idx.equal_range(boost::make_tuple(hwaddr.
hwaddr_));
1204 BOOST_FOREACH(
auto const& lease, l) {
1216 std::lock_guard<std::mutex> lock(*mutex_);
1217 getLease4Internal(hwaddr, collection);
1219 getLease4Internal(hwaddr, collection);
1222 return (collection);
1226Memfile_LeaseMgr::getLease4Internal(
const HWAddr& hwaddr,
1232 Lease4StorageHWAddressSubnetIdIndex::const_iterator lease =
1233 idx.find(boost::make_tuple(hwaddr.
hwaddr_, subnet_id));
1235 if (lease == idx.end()) {
1240 return (
Lease4Ptr(
new Lease4(**lease)));
1251 std::lock_guard<std::mutex> lock(*mutex_);
1252 return (getLease4Internal(hwaddr, subnet_id));
1254 return (getLease4Internal(hwaddr, subnet_id));
1259Memfile_LeaseMgr::getLease4Internal(
const ClientId& client_id,
1265 std::pair<Lease4StorageClientIdSubnetIdIndex::const_iterator,
1266 Lease4StorageClientIdSubnetIdIndex::const_iterator> l
1267 = idx.equal_range(boost::make_tuple(client_id.
getClientId()));
1269 BOOST_FOREACH(
auto const& lease, l) {
1281 std::lock_guard<std::mutex> lock(*mutex_);
1282 getLease4Internal(client_id, collection);
1284 getLease4Internal(client_id, collection);
1287 return (collection);
1291Memfile_LeaseMgr::getLease4Internal(
const ClientId& client_id,
1297 Lease4StorageClientIdSubnetIdIndex::const_iterator lease =
1298 idx.find(boost::make_tuple(client_id.
getClientId(), subnet_id));
1300 if (lease == idx.end()) {
1304 return (
Lease4Ptr(
new Lease4(**lease)));
1312 .arg(client_id.
toText());
1315 std::lock_guard<std::mutex> lock(*mutex_);
1316 return (getLease4Internal(client_id, subnet_id));
1318 return (getLease4Internal(client_id, subnet_id));
1323Memfile_LeaseMgr::getLeases4Internal(
SubnetID subnet_id,
1326 std::pair<Lease4StorageSubnetIdIndex::const_iterator,
1327 Lease4StorageSubnetIdIndex::const_iterator> l =
1328 idx.equal_range(subnet_id);
1330 BOOST_FOREACH(
auto const& lease, l) {
1342 std::lock_guard<std::mutex> lock(*mutex_);
1343 getLeases4Internal(subnet_id, collection);
1345 getLeases4Internal(subnet_id, collection);
1348 return (collection);
1352Memfile_LeaseMgr::getLeases4Internal(
const std::string& hostname,
1355 std::pair<Lease4StorageHostnameIndex::const_iterator,
1356 Lease4StorageHostnameIndex::const_iterator> l =
1357 idx.equal_range(hostname);
1359 BOOST_FOREACH(
auto const& lease, l) {
1371 std::lock_guard<std::mutex> lock(*mutex_);
1372 getLeases4Internal(hostname, collection);
1374 getLeases4Internal(hostname, collection);
1377 return (collection);
1382 for (
auto const& lease : storage4_) {
1393 std::lock_guard<std::mutex> lock(*mutex_);
1394 getLeases4Internal(collection);
1396 getLeases4Internal(collection);
1399 return (collection);
1407 Lease4StorageAddressIndex::const_iterator lb = idx.lower_bound(lower_bound_address);
1410 if ((lb != idx.end()) && ((*lb)->addr_ == lower_bound_address)) {
1415 for (
auto lease = lb;
1416 (lease != idx.end()) &&
1417 (
static_cast<size_t>(std::distance(lb, lease)) < page_size.
page_size_);
1419 collection.push_back(
Lease4Ptr(
new Lease4(**lease)));
1427 if (!lower_bound_address.
isV4()) {
1429 "retrieving leases from the lease database, got "
1430 << lower_bound_address);
1435 .arg(lower_bound_address.
toText());
1439 std::lock_guard<std::mutex> lock(*mutex_);
1440 getLeases4Internal(lower_bound_address, page_size, collection);
1442 getLeases4Internal(lower_bound_address, page_size, collection);
1445 return (collection);
1449Memfile_LeaseMgr::getLease6Internal(
Lease::Type type,
1451 Lease6Storage::iterator l = storage6_.find(addr);
1452 if (l == storage6_.end() || !(*l) || ((*l)->type_ != type)) {
1460Memfile_LeaseMgr::getAnyLease6Internal(
const isc::asiolink::IOAddress& addr)
const {
1461 Lease6Storage::iterator l = storage6_.find(addr);
1462 if (l == storage6_.end() || !(*l)) {
1478 std::lock_guard<std::mutex> lock(*mutex_);
1479 return (getLease6Internal(type, addr));
1481 return (getLease6Internal(type, addr));
1486Memfile_LeaseMgr::getLeases6Internal(
Lease::Type type,
1493 std::pair<Lease6StorageDuidIaidTypeIndex::const_iterator,
1494 Lease6StorageDuidIaidTypeIndex::const_iterator> l =
1495 idx.equal_range(boost::make_tuple(duid.
getDuid(), iaid, type));
1497 for (Lease6StorageDuidIaidTypeIndex::const_iterator lease =
1498 l.first; lease != l.second; ++lease) {
1506 uint32_t iaid)
const {
1515 std::lock_guard<std::mutex> lock(*mutex_);
1516 getLeases6Internal(type, duid, iaid, collection);
1518 getLeases6Internal(type, duid, iaid, collection);
1521 return (collection);
1525Memfile_LeaseMgr::getLeases6Internal(
Lease::Type type,
1533 std::pair<Lease6StorageDuidIaidTypeIndex::const_iterator,
1534 Lease6StorageDuidIaidTypeIndex::const_iterator> l =
1535 idx.equal_range(boost::make_tuple(duid.
getDuid(), iaid, type));
1537 for (Lease6StorageDuidIaidTypeIndex::const_iterator lease =
1538 l.first; lease != l.second; ++lease) {
1540 if ((*lease)->subnet_id_ == subnet_id) {
1560 std::lock_guard<std::mutex> lock(*mutex_);
1561 getLeases6Internal(type, duid, iaid, subnet_id, collection);
1563 getLeases6Internal(type, duid, iaid, subnet_id, collection);
1566 return (collection);
1570Memfile_LeaseMgr::getLeases6Internal(
SubnetID subnet_id,
1573 std::pair<Lease6StorageSubnetIdIndex::const_iterator,
1574 Lease6StorageSubnetIdIndex::const_iterator> l =
1575 idx.equal_range(subnet_id);
1577 BOOST_FOREACH(
auto const& lease, l) {
1589 std::lock_guard<std::mutex> lock(*mutex_);
1590 getLeases6Internal(subnet_id, collection);
1592 getLeases6Internal(subnet_id, collection);
1595 return (collection);
1599Memfile_LeaseMgr::getLeases6Internal(
const std::string& hostname,
1602 std::pair<Lease6StorageHostnameIndex::const_iterator,
1603 Lease6StorageHostnameIndex::const_iterator> l =
1604 idx.equal_range(hostname);
1606 BOOST_FOREACH(
auto const& lease, l) {
1618 std::lock_guard<std::mutex> lock(*mutex_);
1619 getLeases6Internal(hostname, collection);
1621 getLeases6Internal(hostname, collection);
1624 return (collection);
1629 for (
auto const& lease : storage6_) {
1640 std::lock_guard<std::mutex> lock(*mutex_);
1641 getLeases6Internal(collection);
1643 getLeases6Internal(collection);
1646 return (collection);
1650Memfile_LeaseMgr::getLeases6Internal(
const DUID& duid,
1653 std::pair<Lease6StorageDuidIndex::const_iterator,
1654 Lease6StorageDuidIndex::const_iterator> l =
1655 idx.equal_range(duid.
getDuid());
1657 BOOST_FOREACH(
auto const& lease, l) {
1669 std::lock_guard<std::mutex> lock(*mutex_);
1670 getLeases6Internal(duid, collection);
1672 getLeases6Internal(duid, collection);
1675 return (collection);
1683 Lease6StorageAddressIndex::const_iterator lb = idx.lower_bound(lower_bound_address);
1686 if ((lb != idx.end()) && ((*lb)->addr_ == lower_bound_address)) {
1691 for (
auto lease = lb;
1692 (lease != idx.end()) &&
1693 (
static_cast<size_t>(std::distance(lb, lease)) < page_size.
page_size_);
1695 collection.push_back(
Lease6Ptr(
new Lease6(**lease)));
1703 if (!lower_bound_address.
isV6()) {
1705 "retrieving leases from the lease database, got "
1706 << lower_bound_address);
1711 .arg(lower_bound_address.
toText());
1715 std::lock_guard<std::mutex> lock(*mutex_);
1716 getLeases6Internal(lower_bound_address, page_size, collection);
1718 getLeases6Internal(lower_bound_address, page_size, collection);
1721 return (collection);
1725Memfile_LeaseMgr::getLeases6Internal(
SubnetID subnet_id,
1730 Lease6StorageSubnetIdIndex::const_iterator lb =
1731 idx.lower_bound(boost::make_tuple(subnet_id, lower_bound_address));
1734 if ((lb != idx.end()) && ((*lb)->addr_ == lower_bound_address)) {
1739 for (
auto it = lb; it != idx.end(); ++it) {
1740 if ((*it)->subnet_id_ != subnet_id) {
1744 collection.push_back(
Lease6Ptr(
new Lease6(**it)));
1745 if (collection.size() >= page_size.
page_size_) {
1749 return (collection);
1759 .arg(lower_bound_address.
toText())
1763 if (!lower_bound_address.
isV6()) {
1765 "retrieving leases from the lease database, got "
1766 << lower_bound_address);
1770 std::lock_guard<std::mutex> lock(*mutex_);
1771 return (getLeases6Internal(subnet_id,
1772 lower_bound_address,
1775 return (getLeases6Internal(subnet_id,
1776 lower_bound_address,
1782Memfile_LeaseMgr::getExpiredLeases4Internal(
Lease4Collection& expired_leases,
1783 const size_t max_leases)
const {
1791 Lease4StorageExpirationIndex::const_iterator ub =
1792 index.upper_bound(boost::make_tuple(
false, time(0)));
1795 for (Lease4StorageExpirationIndex::const_iterator lease = index.begin();
1797 ((max_leases == 0) ||
1798 (
static_cast<size_t>(std::distance(index.begin(), lease)) < max_leases));
1806 const size_t max_leases)
const {
1811 std::lock_guard<std::mutex> lock(*mutex_);
1812 getExpiredLeases4Internal(expired_leases, max_leases);
1814 getExpiredLeases4Internal(expired_leases, max_leases);
1819Memfile_LeaseMgr::getExpiredLeases6Internal(
Lease6Collection& expired_leases,
1820 const size_t max_leases)
const {
1828 Lease6StorageExpirationIndex::const_iterator ub =
1829 index.upper_bound(boost::make_tuple(
false, time(0)));
1832 for (Lease6StorageExpirationIndex::const_iterator lease = index.begin();
1834 ((max_leases == 0) ||
1835 (
static_cast<size_t>(std::distance(index.begin(), lease)) < max_leases));
1843 const size_t max_leases)
const {
1848 std::lock_guard<std::mutex> lock(*mutex_);
1849 getExpiredLeases6Internal(expired_leases, max_leases);
1851 getExpiredLeases6Internal(expired_leases, max_leases);
1856Memfile_LeaseMgr::updateLease4Internal(
const Lease4Ptr& lease) {
1863 Lease4StorageAddressIndex::const_iterator lease_it = index.find(lease->addr_);
1864 if (lease_it == index.end()) {
1866 << lease->addr_ <<
" - no such lease");
1867 }
else if ((!persist) && (((*lease_it)->cltt_ != lease->current_cltt_) ||
1868 ((*lease_it)->valid_lft_ != lease->current_valid_lft_))) {
1871 isc_throw(NoSuchLease,
"unable to update lease for address " <<
1872 lease->addr_.toText() <<
" either because the lease does not exist, "
1873 "it has been deleted or it has changed in the database.");
1884 lease->updateCurrentExpirationTime();
1891 index.replace(lease_it,
Lease4Ptr(
new Lease4(*lease)));
1894 class_lease_counter_.updateLease(lease, old_lease);
1908 std::lock_guard<std::mutex> lock(*mutex_);
1909 updateLease4Internal(lease);
1911 updateLease4Internal(lease);
1916Memfile_LeaseMgr::updateLease6Internal(
const Lease6Ptr& lease) {
1927 Lease6StorageAddressIndex::const_iterator lease_it = index.find(lease->addr_);
1928 if (lease_it == index.end()) {
1930 << lease->addr_ <<
" - no such lease");
1931 }
else if ((!persist) && (((*lease_it)->cltt_ != lease->current_cltt_) ||
1932 ((*lease_it)->valid_lft_ != lease->current_valid_lft_))) {
1935 isc_throw(NoSuchLease,
"unable to update lease for address " <<
1936 lease->addr_.toText() <<
" either because the lease does not exist, "
1937 "it has been deleted or it has changed in the database.");
1948 lease->updateCurrentExpirationTime();
1955 index.replace(lease_it,
Lease6Ptr(
new Lease6(*lease)));
1958 class_lease_counter_.updateLease(lease, old_lease);
1962 switch (recorded_action) {
1989 std::lock_guard<std::mutex> lock(*mutex_);
1990 updateLease6Internal(lease);
1992 updateLease6Internal(lease);
1997Memfile_LeaseMgr::deleteLeaseInternal(
const Lease4Ptr& lease) {
1999 Lease4Storage::iterator l = storage4_.find(addr);
2000 if (l == storage4_.end()) {
2007 Lease4 lease_copy = **l;
2010 lease_copy.valid_lft_ = 0;
2015 if (((*l)->cltt_ != lease->current_cltt_) ||
2016 ((*l)->valid_lft_ != lease->current_valid_lft_)) {
2024 class_lease_counter_.removeLease(lease);
2041 std::lock_guard<std::mutex> lock(*mutex_);
2042 return (deleteLeaseInternal(lease));
2044 return (deleteLeaseInternal(lease));
2049Memfile_LeaseMgr::deleteLeaseInternal(
const Lease6Ptr& lease) {
2053 Lease6Storage::iterator l = storage6_.find(addr);
2054 if (l == storage6_.end()) {
2061 Lease6 lease_copy = **l;
2063 lease_copy.valid_lft_ = 0;
2064 lease_copy.preferred_lft_ = 0;
2069 if (((*l)->cltt_ != lease->current_cltt_) ||
2070 ((*l)->valid_lft_ != lease->current_valid_lft_)) {
2078 class_lease_counter_.removeLease(lease);
2100 std::lock_guard<std::mutex> lock(*mutex_);
2101 return (deleteLeaseInternal(lease));
2103 return (deleteLeaseInternal(lease));
2114 std::lock_guard<std::mutex> lock(*mutex_);
2115 return (deleteExpiredReclaimedLeases<
2119 return (deleteExpiredReclaimedLeases<
2132 std::lock_guard<std::mutex> lock(*mutex_);
2133 return (deleteExpiredReclaimedLeases<
2137 return (deleteExpiredReclaimedLeases<
2143template<
typename IndexType,
typename LeaseType,
typename StorageType,
2144 typename LeaseFileType>
2146Memfile_LeaseMgr::deleteExpiredReclaimedLeases(
const uint32_t secs,
2147 const Universe& universe,
2148 StorageType& storage,
2149 LeaseFileType& lease_file) {
2162 typename IndexType::const_iterator upper_limit =
2163 index.upper_bound(boost::make_tuple(
true, time(0) - secs));
2172 typename IndexType::const_iterator lower_limit =
2173 index.upper_bound(boost::make_tuple(
true, std::numeric_limits<int64_t>::min()));
2176 uint64_t num_leases =
static_cast<uint64_t
>(std::distance(lower_limit, upper_limit));
2177 if (num_leases > 0) {
2187 for (
typename IndexType::const_iterator lease = lower_limit;
2188 lease != upper_limit; ++lease) {
2190 LeaseType lease_copy(**lease);
2193 lease_copy.valid_lft_ = 0;
2194 lease_file->append(lease_copy);
2199 index.erase(lower_limit, upper_limit);
2203 return (num_leases);
2208 return (std::string(
"In memory database with leases stored in a CSV file."));
2211std::pair<uint32_t, uint32_t>
2213 std::string
const& universe(conn_.getParameter(
"universe"));
2214 if (universe ==
"4") {
2216 }
else if (universe ==
"6") {
2236 std::string name(file_name);
2237 switch (file_type) {
2248 name +=
".completed";
2263 std::string filename )
const {
2264 std::ostringstream s;;
2266 if (filename.empty()) {
2268 s << (u ==
V4 ?
"4" :
"6");
2271 s <<
"/" << filename;
2299Memfile_LeaseMgr::initLeaseFilePath(Universe u) {
2300 std::string persist_val;
2306 persist_val =
"true";
2310 if (persist_val ==
"false") {
2313 }
else if (persist_val !=
"true") {
2314 isc_throw(isc::BadValue,
"invalid value 'persist="
2315 << persist_val <<
"'");
2318 std::string lease_file;
2320 lease_file = conn_.getParameter(
"name");
2321 }
catch (
const Exception&) {
2328 }
catch (
const SecurityWarn& ex) {
2333 return (lease_file);
2336template<
typename LeaseObjectType,
typename LeaseFileType,
typename StorageType>
2338Memfile_LeaseMgr::loadLeasesFromFiles(
const std::string& filename,
2339 boost::shared_ptr<LeaseFileType>& lease_file,
2340 StorageType& storage) {
2348 if (pid_file.check()) {
2349 isc_throw(DbOpenError,
"unable to load leases from files while the "
2350 "lease file cleanup is in progress");
2355 std::string max_row_errors_str =
"0";
2357 max_row_errors_str = conn_.getParameter(
"max-row-errors");
2358 }
catch (
const std::exception&) {
2362 int64_t max_row_errors64;
2364 max_row_errors64 = boost::lexical_cast<int64_t>(max_row_errors_str);
2365 }
catch (
const boost::bad_lexical_cast&) {
2366 isc_throw(isc::BadValue,
"invalid value of the max-row-errors "
2367 << max_row_errors_str <<
" specified");
2369 if ((max_row_errors64 < 0) ||
2370 (max_row_errors64 > std::numeric_limits<uint32_t>::max())) {
2371 isc_throw(isc::BadValue,
"invalid value of the max-row-errors "
2372 << max_row_errors_str <<
" specified");
2374 uint32_t max_row_errors =
static_cast<uint32_t
>(max_row_errors64);
2377 bool conversion_needed =
false;
2378 lease_file.reset(
new LeaseFileType(std::string(filename +
".completed")));
2379 if (lease_file->exists()) {
2382 conversion_needed = conversion_needed || lease_file->needsConversion();
2387 if (lease_file->exists()) {
2390 conversion_needed = conversion_needed || lease_file->needsConversion();
2394 if (lease_file->exists()) {
2397 conversion_needed = conversion_needed || lease_file->needsConversion();
2407 lease_file.reset(
new LeaseFileType(filename));
2409 max_row_errors,
false);
2410 conversion_needed = conversion_needed || lease_file->needsConversion();
2412 return (conversion_needed);
2418 return (lfc_setup_->isRunning());
2423 return (lfc_setup_->getExitStatus());
2441Memfile_LeaseMgr::lfcSetup(
bool conversion_needed) {
2442 std::string lfc_interval_str =
"3600";
2445 }
catch (
const std::exception&) {
2449 uint32_t lfc_interval = 0;
2451 lfc_interval = boost::lexical_cast<uint32_t>(lfc_interval_str);
2452 }
catch (
const boost::bad_lexical_cast&) {
2453 isc_throw(isc::BadValue,
"invalid value of the lfc-interval "
2454 << lfc_interval_str <<
" specified");
2457 if (lfc_interval > 0 || conversion_needed) {
2463template<
typename LeaseFileType>
2465Memfile_LeaseMgr::lfcExecute(boost::shared_ptr<LeaseFileType>& lease_file) {
2475 if (!lease_file_finish.exists() && !lease_file_copy.exists()) {
2477 lease_file->close();
2480 do_lfc = (rename(lease_file->getFilename().c_str(),
2481 lease_file_copy.getFilename().c_str()) == 0);
2485 .arg(lease_file->getFilename())
2486 .arg(lease_file_copy.getFilename())
2487 .arg(strerror(errno));
2496 lease_file->open(
true);
2498 }
catch (
const CSVFileError& ex) {
2509 .arg(lease_file->getFilename())
2520 lfc_setup_->execute();
2528 std::lock_guard<std::mutex> lock(*mutex_);
2541 std::lock_guard<std::mutex> lock(*mutex_);
2554 std::lock_guard<std::mutex> lock(*mutex_);
2569 std::lock_guard<std::mutex> lock(*mutex_);
2582 std::lock_guard<std::mutex> lock(*mutex_);
2595 std::lock_guard<std::mutex> lock(*mutex_);
2608 std::lock_guard<std::mutex> lock(*mutex_);
2623 std::lock_guard<std::mutex> lock(*mutex_);
2641 std::pair<Lease4StorageSubnetIdIndex::const_iterator,
2642 Lease4StorageSubnetIdIndex::const_iterator> r =
2643 idx.equal_range(subnet_id);
2647 BOOST_FOREACH(
auto const& lease, r) {
2648 leases.push_back(lease);
2651 size_t num = leases.size();
2652 for (
auto const& l : leases) {
2656 .arg(subnet_id).arg(num);
2670 std::pair<Lease6StorageSubnetIdIndex::const_iterator,
2671 Lease6StorageSubnetIdIndex::const_iterator> r =
2672 idx.equal_range(subnet_id);
2676 BOOST_FOREACH(
auto const& lease, r) {
2677 leases.push_back(lease);
2680 size_t num = leases.size();
2681 for (
auto const& l : leases) {
2685 .arg(subnet_id).arg(num);
2692 class_lease_counter_.clear();
2693 for (
auto const& lease : storage4_) {
2696 class_lease_counter_.addLease(lease);
2703 class_lease_counter_.clear();
2704 for (
auto const& lease : storage6_) {
2707 class_lease_counter_.addLease(lease);
2716 std::lock_guard<std::mutex> lock(*mutex_);
2717 return(class_lease_counter_.getClassCount(client_class, ltype));
2719 return(class_lease_counter_.getClassCount(client_class, ltype));
2725 return(class_lease_counter_.clear());
2730 if (!user_context) {
2743 for (
unsigned i = 0; i < classes->size(); ++i) {
2752 std::string name = name_elem->stringValue();
2763 size_t lease_count = 0;
2769 if (lease_count >= limit) {
2770 std::ostringstream ss;
2771 ss <<
"address limit " << limit <<
" for client class \""
2772 << name <<
"\", current lease count " << lease_count;
2788 SubnetID subnet_id = id_elem->intValue();
2795 int64_t lease_count = 0;
2797 lease_count = getSubnetStat(subnet_id,
"assigned-addresses");
2801 if (
static_cast<uint64_t
>(lease_count) >= limit) {
2802 std::ostringstream ss;
2803 ss <<
"address limit " << limit <<
" for subnet ID " << subnet_id
2804 <<
", current lease count " << lease_count;
2816 if (!user_context) {
2830 for (
unsigned i = 0; i < classes->size(); ++i) {
2839 std::string name = name_elem->stringValue();
2844 if (!getLeaseLimit(class_elem, ltype, limit)) {
2846 if (!getLeaseLimit(class_elem, ltype, limit)) {
2854 size_t lease_count = 0;
2860 if (lease_count >= limit) {
2861 std::ostringstream ss;
2863 <<
" limit " << limit <<
" for client class \""
2864 << name <<
"\", current lease count " << lease_count;
2880 SubnetID subnet_id = id_elem->intValue();
2885 if (!getLeaseLimit(subnet_elem, ltype, limit)) {
2887 if (!getLeaseLimit(subnet_elem, ltype, limit)) {
2895 int64_t lease_count = 0;
2897 lease_count = getSubnetStat(subnet_id, (ltype ==
Lease::TYPE_NA ?
2898 "assigned-nas" :
"assigned-pds"));
2902 if (
static_cast<uint64_t
>(lease_count) >= limit) {
2903 std::ostringstream ss;
2905 <<
" limit " << limit <<
" for subnet ID " << subnet_id
2906 <<
", current lease count " << lease_count;
2921Memfile_LeaseMgr::getSubnetStat(
const SubnetID& subnet_id,
const std::string& stat_label)
const {
2927 if (samples && samples->size()) {
2928 auto sample = samples->get(0);
2929 if (sample->size()) {
2930 auto count_elem = sample->get(0);
2931 return (count_elem->intValue());
2941 "prefix-limit" :
"address-limit");
2943 limit = limit_elem->intValue();
2954 std::stringstream tmp;
2957 for (
auto const& it :
id) {
2961 tmp << std::setw(2) << std::setfill(
'0')
2962 <<
static_cast<unsigned int>(it);
2974 const time_t& qry_start_time ,
2975 const time_t& qry_end_time ) {
2979 .arg(lower_bound_address.
toText())
2980 .arg(idToText(relay_id))
2981 .arg(qry_start_time)
2985 if (!lower_bound_address.
isV4()) {
2987 "retrieving leases from the lease database, got "
2988 << lower_bound_address);
2992 if ((qry_start_time < 0) || (qry_end_time < 0)) {
2997 if ((qry_start_time > 0) && (qry_end_time > 0) &&
2998 (qry_start_time > qry_end_time)) {
3003 std::lock_guard<std::mutex> lock(*mutex_);
3004 return (getLeases4ByRelayIdInternal(relay_id,
3005 lower_bound_address,
3010 return (getLeases4ByRelayIdInternal(relay_id,
3011 lower_bound_address,
3019Memfile_LeaseMgr::getLeases4ByRelayIdInternal(
const OptionBuffer& relay_id,
3022 const time_t& qry_start_time,
3023 const time_t& qry_end_time) {
3026 Lease4StorageRelayIdIndex::const_iterator lb =
3027 idx.lower_bound(boost::make_tuple(relay_id, lower_bound_address));
3029 IOAddress last_addr = lower_bound_address;
3030 for (; lb != idx.end(); ++lb) {
3031 if ((*lb)->addr_ == last_addr) {
3035 if ((*lb)->relay_id_ != relay_id) {
3039 last_addr = (*lb)->addr_;
3040 if ((qry_start_time > 0) && ((*lb)->cltt_ < qry_start_time)) {
3044 if ((qry_end_time > 0) && ((*lb)->cltt_ > qry_end_time)) {
3048 collection.push_back(
Lease4Ptr(
new Lease4(**lb)));
3049 if (collection.size() >= page_size.
page_size_) {
3053 return (collection);
3060 const time_t& qry_start_time ,
3061 const time_t& qry_end_time ) {
3065 .arg(lower_bound_address.
toText())
3066 .arg(idToText(remote_id))
3067 .arg(qry_start_time)
3071 if (!lower_bound_address.
isV4()) {
3073 "retrieving leases from the lease database, got "
3074 << lower_bound_address);
3078 if ((qry_start_time < 0) || (qry_end_time < 0)) {
3083 if ((qry_start_time > 0) && (qry_end_time > 0) &&
3084 (qry_start_time > qry_end_time)) {
3089 std::lock_guard<std::mutex> lock(*mutex_);
3090 return (getLeases4ByRemoteIdInternal(remote_id,
3091 lower_bound_address,
3096 return (getLeases4ByRemoteIdInternal(remote_id,
3097 lower_bound_address,
3105Memfile_LeaseMgr::getLeases4ByRemoteIdInternal(
const OptionBuffer& remote_id,
3108 const time_t& qry_start_time,
3109 const time_t& qry_end_time) {
3111 std::map<IOAddress, Lease4Ptr> sorted;
3115 BOOST_FOREACH(
auto const& it, er) {
3117 if (addr <= lower_bound_address) {
3121 if ((qry_start_time > 0) && (it->cltt_ < qry_start_time)) {
3125 if ((qry_end_time > 0) && (it->cltt_ > qry_end_time)) {
3133 for (
auto const& it : sorted) {
3134 collection.push_back(
Lease4Ptr(
new Lease4(*it.second)));
3135 if (collection.size() >= page_size.
page_size_) {
3139 return (collection);
3145 std::lock_guard<std::mutex> lock(*mutex_);
3171 .arg(lower_bound_address.
toText())
3175 if (!lower_bound_address.
isV6()) {
3177 "retrieving leases from the lease database, got "
3178 << lower_bound_address);
3182 std::lock_guard<std::mutex> lock(*mutex_);
3183 return (getLeases6ByRelayIdInternal(relay_id,
3184 lower_bound_address,
3187 return (getLeases6ByRelayIdInternal(relay_id,
3188 lower_bound_address,
3194Memfile_LeaseMgr::getLeases6ByRelayIdInternal(
const DUID& relay_id,
3197 const std::vector<uint8_t>& relay_id_data = relay_id.
getDuid();
3200 RelayIdIndex::const_iterator lb =
3201 idx.lower_bound(boost::make_tuple(relay_id_data, lower_bound_address));
3204 IOAddress last_addr = lower_bound_address;
3205 for (; lb != idx.end(); ++lb) {
3206 if ((*lb)->lease_addr_ == last_addr) {
3210 if ((*lb)->id_ != relay_id_data) {
3214 last_addr = (*lb)->lease_addr_;
3215 Lease6Ptr lease = getAnyLease6Internal(last_addr);
3217 collection.push_back(lease);
3218 if (collection.size() >= page_size.
page_size_) {
3223 return (collection);
3233 .arg(lower_bound_address.
toText())
3234 .arg(idToText(remote_id));
3237 if (!lower_bound_address.
isV6()) {
3239 "retrieving leases from the lease database, got "
3240 << lower_bound_address);
3244 std::lock_guard<std::mutex> lock(*mutex_);
3245 return (getLeases6ByRemoteIdInternal(remote_id,
3246 lower_bound_address,
3249 return (getLeases6ByRemoteIdInternal(remote_id,
3250 lower_bound_address,
3256Memfile_LeaseMgr::getLeases6ByRemoteIdInternal(
const OptionBuffer& remote_id,
3260 std::set<IOAddress> sorted;
3264 BOOST_FOREACH(
auto const& it, er) {
3265 const IOAddress& addr = it->lease_addr_;
3266 if (addr <= lower_bound_address) {
3269 static_cast<void>(sorted.insert(addr));
3274 Lease6Ptr lease = getAnyLease6Internal(addr);
3276 collection.push_back(lease);
3277 if (collection.size() >= page_size.
page_size_) {
3282 return (collection);
3295 <<
" consistency configuration is null");
3297 auto check = cfg->getExtendedInfoSanityCheck();
3302 .arg(update ?
" updating in file" :
"");
3305 size_t modified = 0;
3307 size_t processed = 0;
3309 auto lease_it = index.begin();
3310 auto next_it = index.end();
3312 for (; lease_it != index.end(); lease_it = next_it) {
3313 next_it = std::next(lease_it);
3328 if (!
copy->relay_id_.empty() || !
copy->remote_id_.empty()) {
3329 index.replace(lease_it,
copy);
3332 }
catch (
const std::exception& ex) {
3335 .arg(lease->addr_.toText())
3360 auto check = cfg->getExtendedInfoSanityCheck();
3366 .arg(enabled ?
"enabled" :
"disabled");
3375 size_t modified = 0;
3376 size_t processed = 0;
3378 for (
auto const& lease : storage6_) {
3387 }
catch (
const std::exception& ex) {
3390 .arg(lease->addr_.toText())
3410 static_cast<void>(relay_id_idx.erase(addr));
3413 static_cast<void>(remote_id_idx.erase(addr));
3418 const std::vector<uint8_t>& relay_id) {
3426 const std::vector<uint8_t>& remote_id) {
3435 std::lock_guard<std::mutex> lock(*mutex_);
3436 writeLeases4Internal(filename);
3438 writeLeases4Internal(filename);
3443Memfile_LeaseMgr::writeLeases4Internal(
const std::string& filename) {
3449 std::ostringstream old;
3450 old << filename <<
".bak" << getpid();
3451 ::rename(filename.c_str(), old.str().c_str());
3452 CSVLeaseFile4 backup(filename);
3454 for (
auto const& lease : storage4_) {
3455 backup.append(*lease);
3461 }
catch (
const std::exception&) {
3472 std::lock_guard<std::mutex> lock(*mutex_);
3473 writeLeases6Internal(filename);
3475 writeLeases6Internal(filename);
3480Memfile_LeaseMgr::writeLeases6Internal(
const std::string& filename) {
3486 std::ostringstream old;
3487 old << filename <<
".bak" << getpid();
3488 ::rename(filename.c_str(), old.str().c_str());
3489 CSVLeaseFile6 backup(filename);
3491 for (
auto const& lease : storage6_) {
3492 backup.append(*lease);
3498 }
catch (
const std::exception&) {
3512 }
catch (
const std::exception& ex) {
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown if a function is called in a prohibited way.
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
std::string toText() const
Convert the address to a string.
bool isV6() const
Convenience function to check for an IPv6 address.
bool isV4() const
Convenience function to check for an IPv4 address.
std::function< void()> Callback
Exception thrown when error occurs during spawning a process.
Utility class for spawning new processes.
std::string getParameter(const std::string &name) const
Returns value of a connection parameter.
static std::string redactedAccessString(const ParameterMap ¶meters)
Redact database access string.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Invalid address family used as input to Lease Manager.
Provides methods to access CSV file with DHCPv4 leases.
Provides methods to access CSV file with DHCPv6 leases.
static std::string sanityCheckToText(LeaseSanity check_type)
Converts lease sanity check value to printable text.
uint16_t getFamily() const
Returns address family.
std::string validatePath(const std::string data_path) const
Validates a file path against the supported directory for DHDP data.
static CfgMgr & instance()
returns a single instance of Configuration Manager
SrvConfigPtr getStagingCfg()
Returns a pointer to the staging configuration.
std::string getDataDir(bool reset=false, const std::string explicit_path="")
Fetches the supported DHCP data directory.
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
void addLease(LeasePtr lease)
Increment the counts for all of a lease's classes by one.
Holds Client identifier or client IPv4 address.
const std::vector< uint8_t > & getClientId() const
Returns reference to the client-id data.
Holds DUID (DHCPv6 Unique Identifier)
const std::vector< uint8_t > & getDuid() const
Returns a const reference to the actual DUID value.
std::string toText() const
Returns textual representation of the identifier (e.g.
void execute()
Spawns a new process.
int getExitStatus() const
Returns exit code of the last completed cleanup.
bool isRunning() const
Checks if the lease file cleanup is in progress.
LFCSetup(asiolink::IntervalTimer::Callback callback)
Constructor.
void setup(const uint32_t lfc_interval, const boost::shared_ptr< CSVLeaseFile4 > &lease_file4, const boost::shared_ptr< CSVLeaseFile6 > &lease_file6, bool run_once_now=false)
Sets the new configuration for the Lease File Cleanup.
Lease6 extended informations for Bulk Lease Query.
static void load(LeaseFileType &lease_file, StorageType &storage, const uint32_t max_errors=0, const bool close_file_on_exit=true)
Load leases from the lease file into the specified storage.
void setExtendedInfoTablesEnabled(const bool enabled)
Modifies the setting whether the lease6 extended info tables are enabled.
static bool upgradeLease6ExtendedInfo(const Lease6Ptr &lease, CfgConsistency::ExtendedInfoSanity check=CfgConsistency::EXTENDED_INFO_CHECK_FIX)
Upgrade a V6 lease user context to the new extended info entry.
bool getExtendedInfoTablesEnabled() const
Returns the setting indicating if lease6 extended info tables are enabled.
static void extractLease4ExtendedInfo(const Lease4Ptr &lease, bool ignore_errors=true)
Extract relay and remote identifiers from the extended info.
static bool upgradeLease4ExtendedInfo(const Lease4Ptr &lease, CfgConsistency::ExtendedInfoSanity check=CfgConsistency::EXTENDED_INFO_CHECK_FIX)
The following queries are used to fulfill Bulk Lease Query queries.
virtual bool addExtendedInfo6(const Lease6Ptr &lease)
Extract extended info from a lease6 and add it into tables.
Wraps value holding size of the page with leases.
const size_t page_size_
Holds page size.
LeaseStatsQuery(const SelectMode &select_mode=ALL_SUBNETS)
Constructor to query statistics for all subnets.
SubnetID getLastSubnetID() const
Returns the value of last subnet ID specified (or zero)
SubnetID getFirstSubnetID() const
Returns the value of first subnet ID specified (or zero)
SelectMode getSelectMode() const
Returns the selection criteria mode The value returned is based upon the constructor variant used and...
SelectMode
Defines the types of selection criteria supported.
Memfile derivation of the IPv4 statistical lease data query.
MemfileLeaseStatsQuery4(Lease4Storage &storage4, const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Constructor for a subnet range query.
MemfileLeaseStatsQuery4(Lease4Storage &storage4, const SelectMode &select_mode=ALL_SUBNETS)
Constructor for an all subnets query.
virtual ~MemfileLeaseStatsQuery4()
Destructor.
void start()
Creates the IPv4 lease statistical data result set.
MemfileLeaseStatsQuery4(Lease4Storage &storage4, const SubnetID &subnet_id)
Constructor for a single subnet query.
Memfile derivation of the IPv6 statistical lease data query.
void start()
Creates the IPv6 lease statistical data result set.
virtual ~MemfileLeaseStatsQuery6()
Destructor.
MemfileLeaseStatsQuery6(Lease6Storage &storage6, const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Constructor for a subnet range query.
MemfileLeaseStatsQuery6(Lease6Storage &storage6, const SelectMode &select_mode=ALL_SUBNETS)
Constructor.
MemfileLeaseStatsQuery6(Lease6Storage &storage6, const SubnetID &subnet_id)
Constructor for a single subnet query.
std::vector< LeaseStatsRow >::iterator next_pos_
An iterator for accessing the next row within the result set.
MemfileLeaseStatsQuery(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Constructor for subnet range query.
virtual bool getNextRow(LeaseStatsRow &row)
Fetches the next row in the result set.
std::vector< LeaseStatsRow > rows_
A vector containing the "result set".
MemfileLeaseStatsQuery(const SelectMode &select_mode=ALL_SUBNETS)
Constructor for all subnets query.
virtual ~MemfileLeaseStatsQuery()
Destructor.
int getRowCount() const
Returns the number of rows in the result set.
MemfileLeaseStatsQuery(const SubnetID &subnet_id)
Constructor for single subnet query.
Lease6ExtendedInfoRemoteIdTable remote_id6_
stores IPv6 by-remote-id cross-reference table
virtual void rollback() override
Rollback Transactions.
size_t extractExtendedInfo4(bool update, bool current)
Extract extended info for v4 leases.
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery6(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id) override
Creates and runs the IPv6 lease stats query for a single subnet.
virtual void clearClassLeaseCounts() override
Clears the class-lease count map.
virtual size_t byRelayId6size() const override
Return the by-relay-id table size.
virtual Lease4Collection getLeases4ByRelayId(const OptionBuffer &relay_id, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size, const time_t &qry_start_time=0, const time_t &qry_end_time=0) override
The following queries are used to fulfill Bulk Lease Query queries.
Memfile_LeaseMgr(const db::DatabaseConnection::ParameterMap ¶meters)
The sole lease manager constructor.
bool isLFCRunning() const
Checks if the process performing lease file cleanup is running.
virtual void writeLeases4(const std::string &filename) override
Write V4 leases to a file.
virtual void updateLease4(const Lease4Ptr &lease4) override
Updates IPv4 lease.
virtual size_t wipeLeases4(const SubnetID &subnet_id) override
Removes specified IPv4 leases.
virtual void deleteExtendedInfo6(const isc::asiolink::IOAddress &addr) override
Delete lease6 extended info from tables.
virtual bool isJsonSupported() const override
Checks if JSON support is enabled in the database.
Universe
Specifies universe (V4, V6)
static TrackingLeaseMgrPtr factory(const isc::db::DatabaseConnection::ParameterMap ¶meters)
Factory class method.
LFCFileType
Types of the lease files used by the Lease File Cleanup.
@ FILE_PREVIOUS
Previous Lease File.
@ FILE_FINISH
LFC Finish File.
@ FILE_OUTPUT
LFC Output File.
@ FILE_INPUT
Lease File Copy
virtual bool deleteLease(const Lease4Ptr &lease) override
Deletes an IPv4 lease.
virtual void commit() override
Commit Transactions.
virtual size_t wipeLeases6(const SubnetID &subnet_id) override
Removed specified IPv6 leases.
virtual std::pair< uint32_t, uint32_t > getVersion(const std::string &timer_name=std::string()) const override
Returns backend version.
int getLFCExitStatus() const
Returns the status code returned by the last executed LFC process.
virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery6() override
Creates and runs the IPv6 lease stats query for all subnets and pools.
bool persistLeases(Universe u) const
Specifies whether or not leases are written to disk.
virtual void addRemoteId6(const isc::asiolink::IOAddress &lease_addr, const std::vector< uint8_t > &remote_id) override
Add lease6 extended info into by-remote-id table.
static std::string getDBVersion()
Return extended version info.
virtual Lease4Collection getLeases4() const override
Returns all IPv4 leases.
virtual size_t getClassLeaseCount(const ClientClass &client_class, const Lease::Type <ype=Lease::TYPE_V4) const override
Returns the class lease count for a given class and lease type.
virtual void getExpiredLeases6(Lease6Collection &expired_leases, const size_t max_leases) const override
Returns a collection of expired DHCPv6 leases.
void buildExtendedInfoTables6()
Extended information / Bulk Lease Query shared interface.
virtual bool addLease(const Lease4Ptr &lease) override
Adds an IPv4 lease.
virtual size_t byRemoteId6size() const override
Return the by-remote-id table size.
std::string getDefaultLeaseFilePath(Universe u, const std::string filename="") const
Returns default path to the lease file.
virtual void writeLeases6(const std::string &filename) override
Write V6 leases to a file.
Lease6ExtendedInfoRelayIdTable relay_id6_
stores IPv6 by-relay-id cross-reference table
virtual void recountClassLeases6() override
Recount the leases per class for V6 leases.
virtual Lease4Collection getLeases4ByRemoteId(const OptionBuffer &remote_id, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size, const time_t &qry_start_time=0, const time_t &qry_end_time=0) override
Returns existing IPv4 leases with a given remote-id.
virtual void wipeExtendedInfoTables6() override
Wipe extended info table (v6).
boost::shared_ptr< CSVLeaseFile4 > lease_file4_
Holds the pointer to the DHCPv4 lease file IO.
std::string getLeaseFilePath(Universe u) const
Returns an absolute path to the lease file.
virtual Lease6Collection getLeases6ByRemoteId(const OptionBuffer &remote_id, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size) override
Returns existing IPv6 leases with a given remote-id.
virtual Lease6Collection getLeases6() const override
Returns all IPv6 leases.
virtual void lfcCallback()
A callback function triggering Lease File Cleanup (LFC).
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID &subnet_id) override
Creates and runs the IPv4 lease stats query for a single subnet.
virtual Lease6Collection getLeases6ByRelayId(const DUID &relay_id, const asiolink::IOAddress &lower_bound_address, const LeasePageSize &page_size) override
Returns existing IPv6 leases with a given relay-id.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID &subnet_id) override
Creates and runs the IPv6 lease stats query for a single subnet.
virtual std::string getDescription() const override
Returns description of the backend.
static std::string appendSuffix(const std::string &file_name, const LFCFileType &file_type)
Appends appropriate suffix to the file name.
virtual void addRelayId6(const isc::asiolink::IOAddress &lease_addr, const std::vector< uint8_t > &relay_id) override
Add lease6 extended info into by-relay-id table.
virtual size_t upgradeExtendedInfo6(const LeasePageSize &page_size) override
Upgrade extended info (v6).
virtual LeaseStatsQueryPtr startLeaseStatsQuery4() override
Creates and runs the IPv4 lease stats query.
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const override
Returns existing IPv6 lease for a given IPv6 address.
virtual void recountClassLeases4() override
Recount the leases per class for V4 leases.
virtual void updateLease6(const Lease6Ptr &lease6) override
Updates IPv6 lease.
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery4(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id) override
Creates and runs the IPv4 lease stats query for a single subnet.
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs) override
Deletes all expired-reclaimed DHCPv4 leases.
static std::string getDBVersionInternal(Universe const &u)
Local version of getDBVersion() class method.
virtual LeaseStatsQueryPtr startPoolLeaseStatsQuery4() override
Creates and runs the IPv4 lease stats query for all subnets and pools.
virtual std::string checkLimits6(isc::data::ConstElementPtr const &user_context) const override
Checks if the IPv6 lease limits set in the given user context are exceeded.
virtual LeaseStatsQueryPtr startLeaseStatsQuery6() override
Creates and runs the IPv6 lease stats query.
virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress &addr) const override
Returns existing IPv4 lease for specified IPv4 address.
virtual ~Memfile_LeaseMgr()
Destructor (closes file)
virtual std::string checkLimits4(isc::data::ConstElementPtr const &user_context) const override
Checks if the IPv4 lease limits set in the given user context are exceeded.
boost::shared_ptr< CSVLeaseFile6 > lease_file6_
Holds the pointer to the DHCPv6 lease file IO.
virtual size_t upgradeExtendedInfo4(const LeasePageSize &page_size) override
Upgrade extended info (v4).
virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs) override
Deletes all expired-reclaimed DHCPv6 leases.
virtual void getExpiredLeases4(Lease4Collection &expired_leases, const size_t max_leases) const override
Returns a collection of expired DHCPv4 leases.
Attempt to update lease that was not there.
Manages a pool of asynchronous interval timers.
void trackAddLease(const LeasePtr &lease)
Invokes the callbacks when a new lease is added.
void trackUpdateLease(const LeasePtr &lease)
Invokes the callbacks when a lease is updated.
void trackDeleteLease(const LeasePtr &lease)
Invokes the callbacks when a lease is deleted.
TrackingLeaseMgr()
Constructor.
bool hasCallbacks() const
Checks if any callbacks have been registered.
static StatsMgr & instance()
Statistics Manager accessor method.
static std::string generateName(const std::string &context, Type index, const std::string &stat_name)
Generates statistic name in a given context.
RAII class creating a critical section.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
int version()
returns Kea hooks version.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
isc::data::ConstElementPtr get(const std::string &name) const
Returns a single statistic as a JSON structure.
static const int MAJOR_VERSION_V4
static const int MINOR_VERSION_V4
the minor version of the v4 memfile backend
static const int MAJOR_VERSION_V6
static const int MINOR_VERSION_V6
the minor version of the v6 memfile backend
int get(CalloutHandle &handle)
The gss-tsig-get command.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
std::vector< std::string > ProcessArgs
Type of the container holding arguments of the executable being run as a background process.
std::vector< std::string > ProcessEnvVars
Type of the container holding environment variables of the executable being run as a background proce...
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
void prettyPrint(ConstElementPtr element, std::ostream &out, unsigned indent, unsigned step)
Pretty prints the data into stream.
boost::shared_ptr< const Element > ConstElementPtr
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_START
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID_CLIENTID
const isc::log::MessageID DHCPSRV_MEMFILE_EXTRACT_EXTENDED_INFO4
std::string ClientClass
Defines a single class name.
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_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetIdPoolIdIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::member< Lease, SubnetID, &Lease::subnet_id_ >, boost::multi_index::member< Lease, uint32_t, &Lease::pool_id_ > > > > > Lease4Storage
A multi index container holding DHCPv4 leases.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID_HWADDR
const isc::log::MessageID DHCPSRV_MEMFILE_WIPE_LEASES6
const isc::log::MessageID DHCPSRV_MEMFILE_GET4
const isc::log::MessageID DHCPSRV_MEMFILE_BUILD_EXTENDED_INFO_TABLES6_ERROR
const isc::log::MessageID DHCPSRV_MEMFILE_GET_REMOTEID6
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID_PAGE6
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_UNREGISTER_TIMER_FAILED
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_SPAWN_FAIL
const isc::log::MessageID DHCPSRV_MEMFILE_PATH_SECURITY_WARNING
const isc::log::MessageID DHCPSRV_MEMFILE_DB
Lease6Storage::index< ExpirationIndexTag >::type Lease6StorageExpirationIndex
DHCPv6 lease storage index by expiration time.
const isc::log::MessageID DHCPSRV_MEMFILE_CONVERTING_LEASE_FILES
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_SETUP
const isc::log::MessageID DHCPSRV_MEMFILE_WIPE_LEASES6_FINISHED
Lease6Storage::index< DuidIndexTag >::type Lease6StorageDuidIndex
DHCPv6 lease storage index by DUID.
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
boost::shared_ptr< LeaseStatsQuery > LeaseStatsQueryPtr
Defines a pointer to a LeaseStatsQuery.
const isc::log::MessageID DHCPSRV_MEMFILE_WIPE_LEASES4
Lease6Storage::index< SubnetIdPoolIdIndexTag >::type Lease6StorageSubnetIdPoolIdIndex
DHCPv6 lease storage index subnet-id and pool-id.
Lease6Storage::index< DuidIaidTypeIndexTag >::type Lease6StorageDuidIaidTypeIndex
DHCPv6 lease storage index by DUID, IAID, lease type.
boost::shared_ptr< TimerMgr > TimerMgrPtr
Type definition of the shared pointer to TimerMgr.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_RELAYID4
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_EXPIRED_RECLAIMED_START
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_LEASE_FILE_RENAME_FAIL
const isc::log::MessageID DHCPSRV_MEMFILE_UPDATE_ADDR4
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID6
Lease4Storage::index< ExpirationIndexTag >::type Lease4StorageExpirationIndex
DHCPv4 lease storage index by expiration time.
Lease6Storage::index< AddressIndexTag >::type Lease6StorageAddressIndex
DHCPv6 lease storage index by address.
const int DHCPSRV_DBG_TRACE_DETAIL
Additional information.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_ADDR4
const isc::log::MessageID DHCPSRV_MEMFILE_ROLLBACK
const isc::log::MessageID DHCPSRV_MEMFILE_UPDATE_ADDR6
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-id.
Lease6Storage::index< HostnameIndexTag >::type Lease6StorageHostnameIndex
DHCPv6 lease storage index by hostname.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_EXPIRED4
const isc::log::MessageID DHCPSRV_MEMFILE_GET_EXPIRED6
const isc::log::MessageID DHCPSRV_MEMFILE_GET_HOSTNAME4
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_unique< boost::multi_index::tag< SubnetIdIndexTag >, boost::multi_index::composite_key< Lease6, boost::multi_index::member< Lease, isc::dhcp::SubnetID, &Lease::subnet_id_ >, boost::multi_index::member< Lease, isc::asiolink::IOAddress, &Lease::addr_ > > >, 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_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetIdPoolIdIndexTag >, boost::multi_index::composite_key< Lease6, boost::multi_index::member< Lease, SubnetID, &Lease::subnet_id_ >, boost::multi_index::member< Lease, uint32_t, &Lease::pool_id_ > > > > > Lease6Storage
A multi index container holding DHCPv6 leases.
Lease4Storage::index< ClientIdSubnetIdIndexTag >::type Lease4StorageClientIdSubnetIdIndex
DHCPv4 lease storage index by client-id and subnet-id.
Lease4Storage::index< HWAddressSubnetIdIndexTag >::type Lease4StorageHWAddressSubnetIdIndex
DHCPv4 lease storage index by HW address and subnet-id.
const isc::log::MessageID DHCPSRV_MEMFILE_EXTRACT_EXTENDED_INFO4_ERROR
const isc::log::MessageID DHCPSRV_MEMFILE_ADD_ADDR6
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-id.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
const isc::log::MessageID DHCPSRV_MEMFILE_BEGIN_EXTRACT_EXTENDED_INFO4
const isc::log::MessageID DHCPSRV_MEMFILE_WIPE_LEASES4_FINISHED
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID4
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_LEASE_FILE_REOPEN_FAIL
const isc::log::MessageID DHCPSRV_MEMFILE_COMMIT
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_EXPIRED_RECLAIMED4
boost::shared_ptr< CfgConsistency > CfgConsistencyPtr
Type used to for pointing to CfgConsistency structure.
const isc::log::MessageID DHCPSRV_MEMFILE_BEGIN_BUILD_EXTENDED_INFO_TABLES6
const isc::log::MessageID DHCPSRV_MEMFILE_GET_HOSTNAME6
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_EXPIRED_RECLAIMED6
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_EXECUTE
std::pair< RemoteIdIndex::const_iterator, RemoteIdIndex::const_iterator > RemoteIdIndexRange
Lease6 extended information by remote id range.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_RELAYID6
const isc::log::MessageID DHCPSRV_MEMFILE_NO_STORAGE
const isc::log::MessageID DHCPSRV_MEMFILE_BUILD_EXTENDED_INFO_TABLES6
std::unique_ptr< TrackingLeaseMgr > TrackingLeaseMgrPtr
TrackingLeaseMgr pointer.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_PAGE4
const isc::log::MessageID DHCPSRV_MEMFILE_GET_HWADDR
const isc::log::MessageID DHCPSRV_MEMFILE_GET6_DUID
Lease4Storage::index< SubnetIdIndexTag >::type Lease4StorageSubnetIdIndex
DHCPv4 lease storage index subnet-id.
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_ADDR4
std::vector< Lease4Ptr > Lease4Collection
A collection of IPv4 leases.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_ADDR6
const isc::log::MessageID DHCPSRV_MEMFILE_ADD_ADDR4
const isc::log::MessageID DHCPSRV_MEMFILE_GET_CLIENTID
Lease4Storage::index< AddressIndexTag >::type Lease4StorageAddressIndex
DHCPv4 lease storage index by address.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_IAID_DUID
const isc::log::MessageID DHCPSRV_MEMFILE_GET6
const isc::log::MessageID DHCPSRV_MEMFILE_GET_REMOTEID4
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Lease6ExtendedInfoRemoteIdTable::index< LeaseAddressIndexTag >::type LeaseAddressRemoteIdIndex
Lease6 extended information by lease address index of by remote id table.
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
const isc::log::MessageID DHCPSRV_MEMFILE_FAILED_TO_OPEN
Lease6Storage::index< SubnetIdIndexTag >::type Lease6StorageSubnetIdIndex
DHCPv6 lease storage index by subnet-id.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_IAID_SUBID_DUID
boost::shared_ptr< Lease6ExtendedInfo > Lease6ExtendedInfoPtr
Pointer to a Lease6ExtendedInfo object.
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_ADDR6
Lease6ExtendedInfoRemoteIdTable::index< RemoteIdIndexTag >::type RemoteIdIndex
Lease6 extended information by remote id index.
Lease4Storage::index< SubnetIdPoolIdIndexTag >::type Lease4StorageSubnetIdPoolIdIndex
DHCPv4 lease storage index subnet-id and pool-id.
Lease4Storage::index< RelayIdIndexTag >::type Lease4StorageRelayIdIndex
DHCPv4 lease storage index by relay-id.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_PAGE6
Defines the logger used by the top-level component of kea-lfc.
Tag for indexes by address.
Tag for indexes by client-id, subnet-id tuple.
Tag for indexes by DUID, IAID, lease type tuple.
Tag for index using DUID.
Tag for indexes by expiration time.
Hardware type that represents information from DHCPv4 packet.
std::vector< uint8_t > hwaddr_
std::string toText(bool include_htype=true) const
Returns textual representation of a hardware address (e.g.
Tag for indexes by HW address, subnet-id tuple.
Tag for index using hostname.
Structure that holds a lease for IPv4 address.
Structure that holds a lease for IPv6 address and/or prefix.
ExtendedInfoAction
Action on extended info tables.
@ ACTION_UPDATE
update extended info tables.
@ ACTION_DELETE
delete reference to the lease
@ ACTION_IGNORE
ignore extended info,
Tag for indexes by lease address.
Contains a single row of lease statistical data.
static const uint32_t STATE_DEFAULT
A lease in the default state.
static const uint32_t STATE_DECLINED
Declined lease.
Type
Type of lease or pool.
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
@ TYPE_NA
the lease contains non-temporary IPv6 address
static const uint32_t STATE_REGISTERED
Registered self-generated lease.
static std::string typeToText(Type type)
returns text representation of a lease type
Tag for index using relay-id.
Tag for index using remote-id.
Tag for indexes by subnet-id (and address for v6).