22#include <boost/foreach.hpp>
39const char* KEA_LFC_EXECUTABLE_ENV_NAME =
"KEA_LFC_EXECUTABLE";
94 void setup(
const uint32_t lfc_interval,
95 const boost::shared_ptr<CSVLeaseFile4>& lease_file4,
96 const boost::shared_ptr<CSVLeaseFile6>& lease_file6,
97 bool run_once_now =
false);
114 boost::scoped_ptr<ProcessSpawn> process_;
130 : process_(), callback_(callback), pid_(0),
146 timer_mgr_->unregisterTimer(
"memfile-lfc");
148 }
catch (
const std::exception& ex) {
159 const boost::shared_ptr<CSVLeaseFile4>& lease_file4,
160 const boost::shared_ptr<CSVLeaseFile6>& lease_file6,
164 if (lfc_interval == 0 && !run_once_now) {
169 std::string executable;
170 char* c_executable = getenv(KEA_LFC_EXECUTABLE_ENV_NAME);
172 executable = KEA_LFC_EXECUTABLE;
174 executable = c_executable;
178 std::string lease_file = lease_file4 ? lease_file4->getFilename() :
179 lease_file6->getFilename();
184 args.push_back(lease_file4 ?
"-4" :
"-6");
187 args.push_back(
"-x");
191 args.push_back(
"-i");
195 args.push_back(
"-o");
199 args.push_back(
"-f");
203 args.push_back(
"-p");
208 args.push_back(
"-c");
209 args.push_back(
"ignored-path");
221 if (lfc_interval > 0) {
228 timer_mgr_->registerTimer(
"memfile-lfc", callback_, lfc_interval * 1000,
230 timer_mgr_->setup(
"memfile-lfc");
238 .arg(process_->getCommandLine());
239 pid_ = process_->spawn();
248 return (process_ && process_->isRunning(pid_));
255 " the process is null");
257 return (process_->getExitStatus(pid_));
316 return (
rows_.size());
412 void startSubnets() {
417 Lease4StorageSubnetIdIndex::const_iterator lower;
418 Lease4StorageSubnetIdIndex::const_iterator upper;
441 if (lower == upper) {
449 int64_t assigned = 0;
450 int64_t declined = 0;
451 for (Lease4StorageSubnetIdIndex::const_iterator lease = lower;
452 lease != upper; ++lease) {
455 if ((*lease)->subnet_id_ != cur_id) {
458 rows_.push_back(LeaseStatsRow(cur_id,
465 rows_.push_back(LeaseStatsRow(cur_id,
473 cur_id = (*lease)->subnet_id_;
513 void startSubnetPools() {
515 = storage4_.get<SubnetIdPoolIdIndexTag>();
518 Lease4StorageSubnetIdPoolIdIndex::const_iterator lower;
519 Lease4StorageSubnetIdPoolIdIndex::const_iterator upper;
531 if (lower == upper) {
539 uint32_t cur_pool_id = 0;
540 int64_t assigned = 0;
541 int64_t declined = 0;
542 for (Lease4StorageSubnetIdPoolIdIndex::const_iterator lease = lower;
543 lease != upper; ++lease) {
546 if ((*lease)->pool_id_ != cur_pool_id) {
548 rows_.push_back(LeaseStatsRow(cur_id,
550 assigned, cur_pool_id));
555 rows_.push_back(LeaseStatsRow(cur_id,
557 declined, cur_pool_id));
562 cur_pool_id = (*lease)->pool_id_;
567 if ((*lease)->subnet_id_ != cur_id) {
570 rows_.push_back(LeaseStatsRow(cur_id,
572 assigned, cur_pool_id));
577 rows_.push_back(LeaseStatsRow(cur_id,
579 declined, cur_pool_id));
585 cur_id = (*lease)->subnet_id_;
602 assigned, cur_pool_id));
607 declined, cur_pool_id));
704 virtual void startSubnets() {
709 Lease6StorageSubnetIdIndex::const_iterator lower;
710 Lease6StorageSubnetIdIndex::const_iterator upper;
732 if (lower == upper) {
740 int64_t assigned = 0;
741 int64_t declined = 0;
742 int64_t assigned_pds = 0;
743 for (Lease6StorageSubnetIdIndex::const_iterator lease = lower;
744 lease != upper; ++lease) {
747 if ((*lease)->subnet_id_ != cur_id) {
763 if (assigned_pds > 0) {
772 cur_id = (*lease)->subnet_id_;
777 switch((*lease)->type_) {
806 if (assigned_pds > 0) {
829 virtual void startSubnetPools() {
831 = storage6_.get<SubnetIdPoolIdIndexTag>();
834 Lease6StorageSubnetIdPoolIdIndex::const_iterator lower;
835 Lease6StorageSubnetIdPoolIdIndex::const_iterator upper;
847 if (lower == upper) {
855 uint32_t cur_pool_id = 0;
856 int64_t assigned = 0;
857 int64_t declined = 0;
858 int64_t assigned_pds = 0;
859 for (Lease6StorageSubnetIdPoolIdIndex::const_iterator lease = lower;
860 lease != upper; ++lease) {
863 if ((*lease)->pool_id_ != cur_pool_id) {
867 assigned, cur_pool_id));
874 declined, cur_pool_id));
878 if (assigned_pds > 0) {
881 assigned_pds, cur_pool_id));
886 cur_pool_id = (*lease)->pool_id_;
891 if ((*lease)->subnet_id_ != cur_id) {
896 assigned, cur_pool_id));
903 declined, cur_pool_id));
907 if (assigned_pds > 0) {
910 assigned_pds, cur_pool_id));
916 cur_id = (*lease)->subnet_id_;
924 switch((*lease)->type_) {
955 if (assigned_pds > 0) {
977 :
TrackingLeaseMgr(), lfc_setup_(), conn_(parameters), mutex_(new std::mutex) {
978 bool conversion_needed =
false;
985 if (universe ==
"4") {
986 std::string file4 = initLeaseFilePath(
V4);
987 if (!file4.empty()) {
988 conversion_needed = loadLeasesFromFiles<
Lease4,
995 std::string file6 = initLeaseFilePath(
V6);
996 if (!file6.empty()) {
997 conversion_needed = loadLeasesFromFiles<
Lease6,
1012 if (conversion_needed) {
1017 lfcSetup(conversion_needed);
1034 std::stringstream tmp;
1035 tmp <<
"Memfile backend ";
1038 }
else if (u ==
V6) {
1045Memfile_LeaseMgr::addLeaseInternal(
const Lease4Ptr& lease) {
1046 if (getLease4Internal(lease->addr_)) {
1058 storage4_.insert(lease);
1062 lease->updateCurrentExpirationTime();
1065 class_lease_counter_.
addLease(lease);
1081 std::lock_guard<std::mutex> lock(*mutex_);
1082 return (addLeaseInternal(lease));
1084 return (addLeaseInternal(lease));
1089Memfile_LeaseMgr::addLeaseInternal(
const Lease6Ptr& lease) {
1090 if (getLease6Internal(lease->type_, lease->addr_)) {
1103 storage6_.insert(lease);
1107 lease->updateCurrentExpirationTime();
1110 class_lease_counter_.
addLease(lease);
1130 std::lock_guard<std::mutex> lock(*mutex_);
1131 return (addLeaseInternal(lease));
1133 return (addLeaseInternal(lease));
1140 Lease4StorageAddressIndex::iterator l = idx.find(addr);
1141 if (l == idx.end()) {
1154 std::lock_guard<std::mutex> lock(*mutex_);
1155 return (getLease4Internal(addr));
1157 return (getLease4Internal(addr));
1162Memfile_LeaseMgr::getLease4Internal(
const HWAddr& hwaddr,
1168 std::pair<Lease4StorageHWAddressSubnetIdIndex::const_iterator,
1169 Lease4StorageHWAddressSubnetIdIndex::const_iterator> l
1170 = idx.equal_range(boost::make_tuple(hwaddr.
hwaddr_));
1172 BOOST_FOREACH(
auto const& lease, l) {
1184 std::lock_guard<std::mutex> lock(*mutex_);
1185 getLease4Internal(hwaddr, collection);
1187 getLease4Internal(hwaddr, collection);
1190 return (collection);
1194Memfile_LeaseMgr::getLease4Internal(
const HWAddr& hwaddr,
1200 Lease4StorageHWAddressSubnetIdIndex::const_iterator lease =
1201 idx.find(boost::make_tuple(hwaddr.
hwaddr_, subnet_id));
1203 if (lease == idx.end()) {
1208 return (
Lease4Ptr(
new Lease4(**lease)));
1219 std::lock_guard<std::mutex> lock(*mutex_);
1220 return (getLease4Internal(hwaddr, subnet_id));
1222 return (getLease4Internal(hwaddr, subnet_id));
1227Memfile_LeaseMgr::getLease4Internal(
const ClientId& client_id,
1233 std::pair<Lease4StorageClientIdSubnetIdIndex::const_iterator,
1234 Lease4StorageClientIdSubnetIdIndex::const_iterator> l
1235 = idx.equal_range(boost::make_tuple(client_id.
getClientId()));
1237 BOOST_FOREACH(
auto const& lease, l) {
1249 std::lock_guard<std::mutex> lock(*mutex_);
1250 getLease4Internal(client_id, collection);
1252 getLease4Internal(client_id, collection);
1255 return (collection);
1259Memfile_LeaseMgr::getLease4Internal(
const ClientId& client_id,
1265 Lease4StorageClientIdSubnetIdIndex::const_iterator lease =
1266 idx.find(boost::make_tuple(client_id.
getClientId(), subnet_id));
1268 if (lease == idx.end()) {
1272 return (
Lease4Ptr(
new Lease4(**lease)));
1280 .arg(client_id.
toText());
1283 std::lock_guard<std::mutex> lock(*mutex_);
1284 return (getLease4Internal(client_id, subnet_id));
1286 return (getLease4Internal(client_id, subnet_id));
1291Memfile_LeaseMgr::getLeases4Internal(
SubnetID subnet_id,
1294 std::pair<Lease4StorageSubnetIdIndex::const_iterator,
1295 Lease4StorageSubnetIdIndex::const_iterator> l =
1296 idx.equal_range(subnet_id);
1298 BOOST_FOREACH(
auto const& lease, l) {
1310 std::lock_guard<std::mutex> lock(*mutex_);
1311 getLeases4Internal(subnet_id, collection);
1313 getLeases4Internal(subnet_id, collection);
1316 return (collection);
1320Memfile_LeaseMgr::getLeases4Internal(
const std::string& hostname,
1323 std::pair<Lease4StorageHostnameIndex::const_iterator,
1324 Lease4StorageHostnameIndex::const_iterator> l =
1325 idx.equal_range(hostname);
1327 BOOST_FOREACH(
auto const& lease, l) {
1339 std::lock_guard<std::mutex> lock(*mutex_);
1340 getLeases4Internal(hostname, collection);
1342 getLeases4Internal(hostname, collection);
1345 return (collection);
1350 for (
auto const& lease : storage4_) {
1361 std::lock_guard<std::mutex> lock(*mutex_);
1362 getLeases4Internal(collection);
1364 getLeases4Internal(collection);
1367 return (collection);
1375 Lease4StorageAddressIndex::const_iterator lb = idx.lower_bound(lower_bound_address);
1378 if ((lb != idx.end()) && ((*lb)->addr_ == lower_bound_address)) {
1383 for (
auto lease = lb;
1384 (lease != idx.end()) && (std::distance(lb, lease) < page_size.page_size_);
1386 collection.push_back(
Lease4Ptr(
new Lease4(**lease)));
1394 if (!lower_bound_address.isV4()) {
1396 "retrieving leases from the lease database, got "
1397 << lower_bound_address);
1401 .arg(page_size.page_size_)
1402 .arg(lower_bound_address.toText());
1406 std::lock_guard<std::mutex> lock(*mutex_);
1407 getLeases4Internal(lower_bound_address, page_size, collection);
1409 getLeases4Internal(lower_bound_address, page_size, collection);
1412 return (collection);
1416Memfile_LeaseMgr::getLease6Internal(
Lease::Type type,
1418 Lease6Storage::iterator l = storage6_.find(addr);
1419 if (l == storage6_.end() || !(*l) || ((*l)->type_ != type)) {
1428 Lease6Storage::iterator l = storage6_.find(addr);
1429 if (l == storage6_.end() || !(*l)) {
1445 std::lock_guard<std::mutex> lock(*mutex_);
1446 return (getLease6Internal(type, addr));
1448 return (getLease6Internal(type, addr));
1453Memfile_LeaseMgr::getLeases6Internal(
Lease::Type type,
1460 std::pair<Lease6StorageDuidIaidTypeIndex::const_iterator,
1461 Lease6StorageDuidIaidTypeIndex::const_iterator> l =
1462 idx.equal_range(boost::make_tuple(duid.
getDuid(), iaid, type));
1464 for (Lease6StorageDuidIaidTypeIndex::const_iterator lease =
1465 l.first; lease != l.second; ++lease) {
1473 uint32_t iaid)
const {
1482 std::lock_guard<std::mutex> lock(*mutex_);
1483 getLeases6Internal(type, duid, iaid, collection);
1485 getLeases6Internal(type, duid, iaid, collection);
1488 return (collection);
1492Memfile_LeaseMgr::getLeases6Internal(
Lease::Type type,
1500 std::pair<Lease6StorageDuidIaidTypeIndex::const_iterator,
1501 Lease6StorageDuidIaidTypeIndex::const_iterator> l =
1502 idx.equal_range(boost::make_tuple(duid.
getDuid(), iaid, type));
1504 for (Lease6StorageDuidIaidTypeIndex::const_iterator lease =
1505 l.first; lease != l.second; ++lease) {
1507 if ((*lease)->subnet_id_ == subnet_id) {
1527 std::lock_guard<std::mutex> lock(*mutex_);
1528 getLeases6Internal(type, duid, iaid, subnet_id, collection);
1530 getLeases6Internal(type, duid, iaid, subnet_id, collection);
1533 return (collection);
1537Memfile_LeaseMgr::getLeases6Internal(
SubnetID subnet_id,
1540 std::pair<Lease6StorageSubnetIdIndex::const_iterator,
1541 Lease6StorageSubnetIdIndex::const_iterator> l =
1542 idx.equal_range(subnet_id);
1544 BOOST_FOREACH(
auto const& lease, l) {
1556 std::lock_guard<std::mutex> lock(*mutex_);
1557 getLeases6Internal(subnet_id, collection);
1559 getLeases6Internal(subnet_id, collection);
1562 return (collection);
1566Memfile_LeaseMgr::getLeases6Internal(
const std::string& hostname,
1569 std::pair<Lease6StorageHostnameIndex::const_iterator,
1570 Lease6StorageHostnameIndex::const_iterator> l =
1571 idx.equal_range(hostname);
1573 BOOST_FOREACH(
auto const& lease, l) {
1585 std::lock_guard<std::mutex> lock(*mutex_);
1586 getLeases6Internal(hostname, collection);
1588 getLeases6Internal(hostname, collection);
1591 return (collection);
1596 for (
auto const& lease : storage6_) {
1607 std::lock_guard<std::mutex> lock(*mutex_);
1608 getLeases6Internal(collection);
1610 getLeases6Internal(collection);
1613 return (collection);
1617Memfile_LeaseMgr::getLeases6Internal(
const DUID& duid,
1620 std::pair<Lease6StorageDuidIndex::const_iterator,
1621 Lease6StorageDuidIndex::const_iterator> l =
1622 idx.equal_range(duid.
getDuid());
1624 BOOST_FOREACH(
auto const& lease, l) {
1636 std::lock_guard<std::mutex> lock(*mutex_);
1637 getLeases6Internal(duid, collection);
1639 getLeases6Internal(duid, collection);
1642 return (collection);
1650 Lease6StorageAddressIndex::const_iterator lb = idx.lower_bound(lower_bound_address);
1653 if ((lb != idx.end()) && ((*lb)->addr_ == lower_bound_address)) {
1658 for (
auto lease = lb;
1659 (lease != idx.end()) && (std::distance(lb, lease) < page_size.page_size_);
1661 collection.push_back(
Lease6Ptr(
new Lease6(**lease)));
1669 if (!lower_bound_address.isV6()) {
1671 "retrieving leases from the lease database, got "
1672 << lower_bound_address);
1676 .arg(page_size.page_size_)
1677 .arg(lower_bound_address.toText());
1681 std::lock_guard<std::mutex> lock(*mutex_);
1682 getLeases6Internal(lower_bound_address, page_size, collection);
1684 getLeases6Internal(lower_bound_address, page_size, collection);
1687 return (collection);
1691Memfile_LeaseMgr::getLeases6Internal(
SubnetID subnet_id,
1696 Lease6StorageSubnetIdIndex::const_iterator lb =
1697 idx.lower_bound(boost::make_tuple(subnet_id, lower_bound_address));
1700 if ((lb != idx.end()) && ((*lb)->addr_ == lower_bound_address)) {
1705 for (
auto it = lb; it != idx.end(); ++it) {
1706 if ((*it)->subnet_id_ != subnet_id) {
1710 collection.push_back(
Lease6Ptr(
new Lease6(**it)));
1711 if (collection.size() >= page_size.page_size_) {
1715 return (collection);
1724 .arg(page_size.page_size_)
1725 .arg(lower_bound_address.toText())
1729 if (!lower_bound_address.isV6()) {
1731 "retrieving leases from the lease database, got "
1732 << lower_bound_address);
1736 std::lock_guard<std::mutex> lock(*mutex_);
1737 return (getLeases6Internal(subnet_id,
1738 lower_bound_address,
1741 return (getLeases6Internal(subnet_id,
1742 lower_bound_address,
1748Memfile_LeaseMgr::getExpiredLeases4Internal(
Lease4Collection& expired_leases,
1749 const size_t max_leases)
const {
1757 Lease4StorageExpirationIndex::const_iterator ub =
1758 index.upper_bound(boost::make_tuple(
false, time(0)));
1761 for (Lease4StorageExpirationIndex::const_iterator lease = index.begin();
1762 (lease != ub) && ((max_leases == 0) || (std::distance(index.begin(), lease) <
1771 const size_t max_leases)
const {
1776 std::lock_guard<std::mutex> lock(*mutex_);
1777 getExpiredLeases4Internal(expired_leases, max_leases);
1779 getExpiredLeases4Internal(expired_leases, max_leases);
1784Memfile_LeaseMgr::getExpiredLeases6Internal(
Lease6Collection& expired_leases,
1785 const size_t max_leases)
const {
1793 Lease6StorageExpirationIndex::const_iterator ub =
1794 index.upper_bound(boost::make_tuple(
false, time(0)));
1797 for (Lease6StorageExpirationIndex::const_iterator lease = index.begin();
1798 (lease != ub) && ((max_leases == 0) || (std::distance(index.begin(), lease) <
1807 const size_t max_leases)
const {
1812 std::lock_guard<std::mutex> lock(*mutex_);
1813 getExpiredLeases6Internal(expired_leases, max_leases);
1815 getExpiredLeases6Internal(expired_leases, max_leases);
1820Memfile_LeaseMgr::updateLease4Internal(
const Lease4Ptr& lease) {
1827 Lease4StorageAddressIndex::const_iterator lease_it = index.find(lease->addr_);
1828 if (lease_it == index.end()) {
1830 << lease->addr_ <<
" - no such lease");
1831 }
else if ((!persist) && (((*lease_it)->cltt_ != lease->current_cltt_) ||
1832 ((*lease_it)->valid_lft_ != lease->current_valid_lft_))) {
1835 isc_throw(NoSuchLease,
"failed to update the lease with address "
1836 << lease->addr_ <<
" - lease has changed in database");
1847 lease->updateCurrentExpirationTime();
1854 index.replace(lease_it,
Lease4Ptr(
new Lease4(*lease)));
1857 class_lease_counter_.
updateLease(lease, old_lease);
1871 std::lock_guard<std::mutex> lock(*mutex_);
1872 updateLease4Internal(lease);
1874 updateLease4Internal(lease);
1879Memfile_LeaseMgr::updateLease6Internal(
const Lease6Ptr& lease) {
1890 Lease6StorageAddressIndex::const_iterator lease_it = index.find(lease->addr_);
1891 if (lease_it == index.end()) {
1893 << lease->addr_ <<
" - no such lease");
1894 }
else if ((!persist) && (((*lease_it)->cltt_ != lease->current_cltt_) ||
1895 ((*lease_it)->valid_lft_ != lease->current_valid_lft_))) {
1898 isc_throw(NoSuchLease,
"failed to update the lease with address "
1899 << lease->addr_ <<
" - lease has changed in database");
1910 lease->updateCurrentExpirationTime();
1917 index.replace(lease_it,
Lease6Ptr(
new Lease6(*lease)));
1920 class_lease_counter_.
updateLease(lease, old_lease);
1924 switch (recorded_action) {
1951 std::lock_guard<std::mutex> lock(*mutex_);
1952 updateLease6Internal(lease);
1954 updateLease6Internal(lease);
1959Memfile_LeaseMgr::deleteLeaseInternal(
const Lease4Ptr& lease) {
1961 Lease4Storage::iterator l = storage4_.find(addr);
1962 if (l == storage4_.end()) {
1969 Lease4 lease_copy = **l;
1972 lease_copy.valid_lft_ = 0;
1977 if (((*l)->cltt_ != lease->current_cltt_) ||
1978 ((*l)->valid_lft_ != lease->current_valid_lft_)) {
2003 std::lock_guard<std::mutex> lock(*mutex_);
2004 return (deleteLeaseInternal(lease));
2006 return (deleteLeaseInternal(lease));
2011Memfile_LeaseMgr::deleteLeaseInternal(
const Lease6Ptr& lease) {
2015 Lease6Storage::iterator l = storage6_.find(addr);
2016 if (l == storage6_.end()) {
2023 Lease6 lease_copy = **l;
2025 lease_copy.valid_lft_ = 0;
2026 lease_copy.preferred_lft_ = 0;
2031 if (((*l)->cltt_ != lease->current_cltt_) ||
2032 ((*l)->valid_lft_ != lease->current_valid_lft_)) {
2062 std::lock_guard<std::mutex> lock(*mutex_);
2063 return (deleteLeaseInternal(lease));
2065 return (deleteLeaseInternal(lease));
2076 std::lock_guard<std::mutex> lock(*mutex_);
2077 return (deleteExpiredReclaimedLeases<
2081 return (deleteExpiredReclaimedLeases<
2094 std::lock_guard<std::mutex> lock(*mutex_);
2095 return (deleteExpiredReclaimedLeases<
2099 return (deleteExpiredReclaimedLeases<
2105template<
typename IndexType,
typename LeaseType,
typename StorageType,
2106 typename LeaseFileType>
2108Memfile_LeaseMgr::deleteExpiredReclaimedLeases(
const uint32_t secs,
2109 const Universe& universe,
2110 StorageType& storage,
2111 LeaseFileType& lease_file) {
2113 IndexType& index = storage.template get<ExpirationIndexTag>();
2124 typename IndexType::const_iterator upper_limit =
2125 index.upper_bound(boost::make_tuple(
true, time(0) - secs));
2134 typename IndexType::const_iterator lower_limit =
2135 index.upper_bound(boost::make_tuple(
true, std::numeric_limits<int64_t>::min()));
2138 uint64_t num_leases =
static_cast<uint64_t
>(std::distance(lower_limit, upper_limit));
2139 if (num_leases > 0) {
2149 for (
typename IndexType::const_iterator lease = lower_limit;
2150 lease != upper_limit; ++lease) {
2152 LeaseType lease_copy(**lease);
2155 lease_copy.valid_lft_ = 0;
2156 lease_file->append(lease_copy);
2161 index.erase(lower_limit, upper_limit);
2165 return (num_leases);
2170 return (std::string(
"In memory database with leases stored in a CSV file."));
2173std::pair<uint32_t, uint32_t>
2175 std::string
const& universe(conn_.
getParameter(
"universe"));
2176 if (universe ==
"4") {
2178 }
else if (universe ==
"6") {
2198 std::string name(file_name);
2199 switch (file_type) {
2210 name +=
".completed";
2225 std::ostringstream s;
2227 s << (u ==
V4 ?
"4" :
"6");
2254Memfile_LeaseMgr::initLeaseFilePath(Universe u) {
2255 std::string persist_val;
2261 persist_val =
"true";
2265 if (persist_val ==
"false") {
2268 }
else if (persist_val !=
"true") {
2270 << persist_val <<
"'");
2273 std::string lease_file;
2279 return (lease_file);
2282template<
typename LeaseObjectType,
typename LeaseFileType,
typename StorageType>
2284Memfile_LeaseMgr::loadLeasesFromFiles(
const std::string& filename,
2285 boost::shared_ptr<LeaseFileType>& lease_file,
2286 StorageType& storage) {
2294 if (pid_file.check()) {
2296 "lease file cleanup is in progress");
2301 std::string max_row_errors_str =
"0";
2303 max_row_errors_str = conn_.
getParameter(
"max-row-errors");
2304 }
catch (
const std::exception&) {
2308 int64_t max_row_errors64;
2310 max_row_errors64 = boost::lexical_cast<int64_t>(max_row_errors_str);
2311 }
catch (
const boost::bad_lexical_cast&) {
2313 << max_row_errors_str <<
" specified");
2315 if ((max_row_errors64 < 0) ||
2316 (max_row_errors64 > std::numeric_limits<uint32_t>::max())) {
2318 << max_row_errors_str <<
" specified");
2320 uint32_t max_row_errors =
static_cast<uint32_t
>(max_row_errors64);
2323 bool conversion_needed =
false;
2324 lease_file.reset(
new LeaseFileType(std::string(filename +
".completed")));
2325 if (lease_file->exists()) {
2326 LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
2328 conversion_needed = conversion_needed || lease_file->needsConversion();
2333 if (lease_file->exists()) {
2334 LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
2336 conversion_needed = conversion_needed || lease_file->needsConversion();
2340 if (lease_file->exists()) {
2341 LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
2343 conversion_needed = conversion_needed || lease_file->needsConversion();
2353 lease_file.reset(
new LeaseFileType(filename));
2354 LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
2355 max_row_errors,
false);
2356 conversion_needed = conversion_needed || lease_file->needsConversion();
2358 return (conversion_needed);
2364 return (lfc_setup_->isRunning());
2369 return (lfc_setup_->getExitStatus());
2387Memfile_LeaseMgr::lfcSetup(
bool conversion_needed) {
2388 std::string lfc_interval_str =
"3600";
2391 }
catch (
const std::exception&) {
2395 uint32_t lfc_interval = 0;
2397 lfc_interval = boost::lexical_cast<uint32_t>(lfc_interval_str);
2398 }
catch (
const boost::bad_lexical_cast&) {
2400 << lfc_interval_str <<
" specified");
2403 if (lfc_interval > 0 || conversion_needed) {
2409template<
typename LeaseFileType>
2411Memfile_LeaseMgr::lfcExecute(boost::shared_ptr<LeaseFileType>& lease_file) {
2421 if (!lease_file_finish.exists() && !lease_file_copy.exists()) {
2423 lease_file->close();
2426 do_lfc = (rename(lease_file->getFilename().c_str(),
2427 lease_file_copy.getFilename().c_str()) == 0);
2431 .arg(lease_file->getFilename())
2432 .arg(lease_file_copy.getFilename())
2433 .arg(strerror(errno));
2442 lease_file->open(
true);
2455 .arg(lease_file->getFilename())
2466 lfc_setup_->execute();
2474 std::lock_guard<std::mutex> lock(*mutex_);
2487 std::lock_guard<std::mutex> lock(*mutex_);
2500 std::lock_guard<std::mutex> lock(*mutex_);
2515 std::lock_guard<std::mutex> lock(*mutex_);
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_);
2587 std::pair<Lease4StorageSubnetIdIndex::const_iterator,
2588 Lease4StorageSubnetIdIndex::const_iterator> r =
2589 idx.equal_range(subnet_id);
2593 BOOST_FOREACH(
auto const& lease, r) {
2594 leases.push_back(lease);
2597 size_t num = leases.size();
2598 for (
auto const& l : leases) {
2602 .arg(subnet_id).arg(num);
2616 std::pair<Lease6StorageSubnetIdIndex::const_iterator,
2617 Lease6StorageSubnetIdIndex::const_iterator> r =
2618 idx.equal_range(subnet_id);
2622 BOOST_FOREACH(
auto const& lease, r) {
2623 leases.push_back(lease);
2626 size_t num = leases.size();
2627 for (
auto const& l : leases) {
2631 .arg(subnet_id).arg(num);
2638 class_lease_counter_.
clear();
2639 for (
auto const& lease : storage4_) {
2642 class_lease_counter_.
addLease(lease);
2649 class_lease_counter_.
clear();
2650 for (
auto const& lease : storage6_) {
2653 class_lease_counter_.
addLease(lease);
2662 std::lock_guard<std::mutex> lock(*mutex_);
2663 return(class_lease_counter_.
getClassCount(client_class, ltype));
2665 return(class_lease_counter_.
getClassCount(client_class, ltype));
2671 return(class_lease_counter_.
clear());
2676 if (!user_context) {
2689 for (
int i = 0; i < classes->size(); ++i) {
2698 std::string name = name_elem->stringValue();
2709 size_t lease_count = 0;
2715 if (lease_count >= limit) {
2716 std::ostringstream ss;
2717 ss <<
"address limit " << limit <<
" for client class \""
2718 << name <<
"\", current lease count " << lease_count;
2734 SubnetID subnet_id = id_elem->intValue();
2741 int64_t lease_count = 0;
2743 lease_count = getSubnetStat(subnet_id,
"assigned-addresses");
2747 if (lease_count >= limit) {
2748 std::ostringstream ss;
2749 ss <<
"address limit " << limit <<
" for subnet ID " << subnet_id
2750 <<
", current lease count " << lease_count;
2762 if (!user_context) {
2776 for (
int i = 0; i < classes->size(); ++i) {
2785 std::string name = name_elem->stringValue();
2790 if (!getLeaseLimit(class_elem, ltype, limit)) {
2792 if (!getLeaseLimit(class_elem, ltype, limit)) {
2800 size_t lease_count = 0;
2806 if (lease_count >= limit) {
2807 std::ostringstream ss;
2809 <<
" limit " << limit <<
" for client class \""
2810 << name <<
"\", current lease count " << lease_count;
2826 SubnetID subnet_id = id_elem->intValue();
2831 if (!getLeaseLimit(subnet_elem, ltype, limit)) {
2833 if (!getLeaseLimit(subnet_elem, ltype, limit)) {
2841 int64_t lease_count = 0;
2843 lease_count = getSubnetStat(subnet_id, (ltype ==
Lease::TYPE_NA ?
2844 "assigned-nas" :
"assigned-pds"));
2848 if (lease_count >= limit) {
2849 std::ostringstream ss;
2851 <<
" limit " << limit <<
" for subnet ID " << subnet_id
2852 <<
", current lease count " << lease_count;
2867Memfile_LeaseMgr::getSubnetStat(
const SubnetID& subnet_id,
const std::string& stat_label)
const {
2873 if (samples && samples->size()) {
2874 auto sample = samples->get(0);
2875 if (sample->size()) {
2876 auto count_elem = sample->get(0);
2877 return (count_elem->intValue());
2887 "prefix-limit" :
"address-limit");
2889 limit = limit_elem->intValue();
2900 std::stringstream tmp;
2903 for (
auto const& it : id) {
2907 tmp << std::setw(2) << std::setfill(
'0')
2908 <<
static_cast<unsigned int>(it);
2920 const time_t& qry_start_time ,
2921 const time_t& qry_end_time ) {
2924 .arg(page_size.page_size_)
2925 .arg(lower_bound_address.toText())
2926 .arg(idToText(relay_id))
2927 .arg(qry_start_time)
2931 if (!lower_bound_address.isV4()) {
2933 "retrieving leases from the lease database, got "
2934 << lower_bound_address);
2938 if ((qry_start_time < 0) || (qry_end_time < 0)) {
2943 if ((qry_start_time > 0) && (qry_end_time > 0) &&
2944 (qry_start_time > qry_end_time)) {
2949 std::lock_guard<std::mutex> lock(*mutex_);
2950 return (getLeases4ByRelayIdInternal(relay_id,
2951 lower_bound_address,
2956 return (getLeases4ByRelayIdInternal(relay_id,
2957 lower_bound_address,
2965Memfile_LeaseMgr::getLeases4ByRelayIdInternal(
const OptionBuffer& relay_id,
2968 const time_t& qry_start_time,
2969 const time_t& qry_end_time) {
2972 Lease4StorageRelayIdIndex::const_iterator lb =
2973 idx.lower_bound(boost::make_tuple(relay_id, lower_bound_address));
2975 IOAddress last_addr = lower_bound_address;
2976 for (; lb != idx.end(); ++lb) {
2977 if ((*lb)->addr_ == last_addr) {
2981 if ((*lb)->relay_id_ != relay_id) {
2985 last_addr = (*lb)->addr_;
2986 if ((qry_start_time > 0) && ((*lb)->cltt_ < qry_start_time)) {
2990 if ((qry_end_time > 0) && ((*lb)->cltt_ > qry_end_time)) {
2994 collection.push_back(
Lease4Ptr(
new Lease4(**lb)));
2995 if (collection.size() >= page_size.page_size_) {
2999 return (collection);
3006 const time_t& qry_start_time ,
3007 const time_t& qry_end_time ) {
3010 .arg(page_size.page_size_)
3011 .arg(lower_bound_address.toText())
3012 .arg(idToText(remote_id))
3013 .arg(qry_start_time)
3017 if (!lower_bound_address.isV4()) {
3019 "retrieving leases from the lease database, got "
3020 << lower_bound_address);
3024 if ((qry_start_time < 0) || (qry_end_time < 0)) {
3029 if ((qry_start_time > 0) && (qry_end_time > 0) &&
3030 (qry_start_time > qry_end_time)) {
3035 std::lock_guard<std::mutex> lock(*mutex_);
3036 return (getLeases4ByRemoteIdInternal(remote_id,
3037 lower_bound_address,
3042 return (getLeases4ByRemoteIdInternal(remote_id,
3043 lower_bound_address,
3051Memfile_LeaseMgr::getLeases4ByRemoteIdInternal(
const OptionBuffer& remote_id,
3054 const time_t& qry_start_time,
3055 const time_t& qry_end_time) {
3057 std::map<IOAddress, Lease4Ptr> sorted;
3061 BOOST_FOREACH(
auto const& it, er) {
3063 if (addr <= lower_bound_address) {
3067 if ((qry_start_time > 0) && (it->cltt_ < qry_start_time)) {
3071 if ((qry_end_time > 0) && (it->cltt_ > qry_end_time)) {
3079 for (
auto const& it : sorted) {
3080 collection.push_back(
Lease4Ptr(
new Lease4(*it.second)));
3081 if (collection.size() >= page_size.page_size_) {
3085 return (collection);
3091 std::lock_guard<std::mutex> lock(*mutex_);
3116 .arg(page_size.page_size_)
3117 .arg(lower_bound_address.toText())
3118 .arg(relay_id.toText());
3121 if (!lower_bound_address.isV6()) {
3123 "retrieving leases from the lease database, got "
3124 << lower_bound_address);
3128 std::lock_guard<std::mutex> lock(*mutex_);
3129 return (getLeases6ByRelayIdInternal(relay_id,
3130 lower_bound_address,
3133 return (getLeases6ByRelayIdInternal(relay_id,
3134 lower_bound_address,
3140Memfile_LeaseMgr::getLeases6ByRelayIdInternal(
const DUID& relay_id,
3143 const std::vector<uint8_t>& relay_id_data = relay_id.getDuid();
3146 RelayIdIndex::const_iterator lb =
3147 idx.lower_bound(boost::make_tuple(relay_id_data, lower_bound_address));
3150 IOAddress last_addr = lower_bound_address;
3151 for (; lb != idx.end(); ++lb) {
3152 if ((*lb)->lease_addr_ == last_addr) {
3156 if ((*lb)->id_ != relay_id_data) {
3160 last_addr = (*lb)->lease_addr_;
3161 Lease6Ptr lease = getAnyLease6Internal(last_addr);
3163 collection.push_back(lease);
3164 if (collection.size() >= page_size.page_size_) {
3169 return (collection);
3178 .arg(page_size.page_size_)
3179 .arg(lower_bound_address.toText())
3180 .arg(idToText(remote_id));
3183 if (!lower_bound_address.isV6()) {
3185 "retrieving leases from the lease database, got "
3186 << lower_bound_address);
3190 std::lock_guard<std::mutex> lock(*mutex_);
3191 return (getLeases6ByRemoteIdInternal(remote_id,
3192 lower_bound_address,
3195 return (getLeases6ByRemoteIdInternal(remote_id,
3196 lower_bound_address,
3202Memfile_LeaseMgr::getLeases6ByRemoteIdInternal(
const OptionBuffer& remote_id,
3206 std::set<IOAddress> sorted;
3210 BOOST_FOREACH(
auto const& it, er) {
3211 const IOAddress& addr = it->lease_addr_;
3212 if (addr <= lower_bound_address) {
3215 static_cast<void>(sorted.insert(addr));
3220 Lease6Ptr lease = getAnyLease6Internal(addr);
3222 collection.push_back(lease);
3223 if (collection.size() >= page_size.page_size_) {
3228 return (collection);
3241 <<
" consistency configuration is null");
3243 auto check = cfg->getExtendedInfoSanityCheck();
3248 .arg(update ?
" updating in file" :
"");
3251 size_t modified = 0;
3253 size_t processed = 0;
3255 auto lease_it = index.begin();
3256 auto next_it = index.end();
3258 for (; lease_it != index.end(); lease_it = next_it) {
3259 next_it = std::next(lease_it);
3274 if (!
copy->relay_id_.empty() || !
copy->remote_id_.empty()) {
3275 index.replace(lease_it,
copy);
3278 }
catch (
const std::exception& ex) {
3281 .arg(lease->addr_.toText())
3306 auto check = cfg->getExtendedInfoSanityCheck();
3312 .arg(enabled ?
"enabled" :
"disabled");
3321 size_t modified = 0;
3322 size_t processed = 0;
3324 for (
auto const& lease : storage6_) {
3333 }
catch (
const std::exception& ex) {
3336 .arg(lease->addr_.toText())
3356 static_cast<void>(relay_id_idx.erase(addr));
3359 static_cast<void>(remote_id_idx.erase(addr));
3364 const std::vector<uint8_t>& relay_id) {
3372 const std::vector<uint8_t>& remote_id) {
3381 std::lock_guard<std::mutex> lock(*mutex_);
3382 writeLeases4Internal(filename);
3384 writeLeases4Internal(filename);
3389Memfile_LeaseMgr::writeLeases4Internal(
const std::string& filename) {
3395 std::ostringstream old;
3396 old << filename <<
".bak" << getpid();
3397 ::rename(filename.c_str(), old.str().c_str());
3398 CSVLeaseFile4 backup(filename);
3400 for (
auto const& lease : storage4_) {
3401 backup.append(*lease);
3407 }
catch (
const std::exception&) {
3418 std::lock_guard<std::mutex> lock(*mutex_);
3419 writeLeases6Internal(filename);
3421 writeLeases6Internal(filename);
3426Memfile_LeaseMgr::writeLeases6Internal(
const std::string& filename) {
3432 std::ostringstream old;
3433 old << filename <<
".bak" << getpid();
3434 ::rename(filename.c_str(), old.str().c_str());
3435 CSVLeaseFile6 backup(filename);
3437 for (
auto const& lease : storage6_) {
3438 backup.append(*lease);
3444 }
catch (
const std::exception&) {
int version()
returns Kea hooks version.
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.
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.
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.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Exception thrown on failure to open database.
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.
static CfgMgr & instance()
returns a single instance of Configuration Manager
void addLease(LeasePtr lease)
Increment the counts for all of a lease's classes by one.
void clear()
Remove all entries.
void removeLease(LeasePtr lease)
Decrement the counts for all of a lease's classes by one.
void updateLease(LeasePtr new_lease, LeasePtr old_lease)
Adjust class lease counts given a new and old version of a lease.
size_t getClassCount(const ClientClass &client_class, const Lease::Type <ype=Lease::TYPE_V4) const
Fetches the lease count for the given class and lease type.
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.
Represents a configuration for Lease File Cleanup.
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.
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 std::string getDBVersion()
Class method to return extended version info This class method must be redeclared and redefined in de...
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.
Base class for fulfilling a statistical lease data query.
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.
Base Memfile derivation of the statistical lease data 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)
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.
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.
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.
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.
std::string getDefaultLeaseFilePath(Universe u) const
Returns default path to the lease file.
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.
Introduces callbacks into the LeaseMgr.
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.
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.
Exception thrown when an error occurs during CSV file processing.
Provides input/output access to CSV files.
RAII class creating a critical section.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
Class to help with processing PID files.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
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
#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
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_DELETE_ADDR
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
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.
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.
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.
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 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).