35 const char* KEA_LFC_EXECUTABLE_ENV_NAME =
"KEA_LFC_EXECUTABLE";
88 void setup(
const uint32_t lfc_interval,
89 const boost::shared_ptr<CSVLeaseFile4>& lease_file4,
90 const boost::shared_ptr<CSVLeaseFile6>& lease_file6,
91 bool run_once_now =
false);
99 bool isRunning()
const;
102 int getExitStatus()
const;
108 boost::scoped_ptr<ProcessSpawn> process_;
124 : process_(),
callback_(callback), pid_(0),
140 timer_mgr_->unregisterTimer(
"memfile-lfc");
142 }
catch (
const std::exception& ex) {
153 const boost::shared_ptr<CSVLeaseFile4>& lease_file4,
154 const boost::shared_ptr<CSVLeaseFile6>& lease_file6,
158 if (lfc_interval == 0 && !run_once_now) {
163 std::string executable;
164 char* c_executable = getenv(KEA_LFC_EXECUTABLE_ENV_NAME);
165 if (c_executable == NULL) {
166 executable = KEA_LFC_EXECUTABLE;
168 executable = c_executable;
172 std::string lease_file = lease_file4 ? lease_file4->getFilename() :
173 lease_file6->getFilename();
178 args.push_back(lease_file4 ?
"-4" :
"-6");
181 args.push_back(
"-x");
185 args.push_back(
"-i");
189 args.push_back(
"-o");
193 args.push_back(
"-f");
197 args.push_back(
"-p");
202 args.push_back(
"-c");
203 args.push_back(
"ignored-path");
214 if (lfc_interval > 0) {
221 timer_mgr_->registerTimer(
"memfile-lfc", callback_, lfc_interval * 1000,
223 timer_mgr_->setup(
"memfile-lfc");
231 .arg(process_->getCommandLine());
232 pid_ = process_->spawn();
241 return (process_ && process_->isRunning(pid_));
248 " the process is NULL");
250 return (process_->getExitStatus(pid_));
307 return (
rows_.size());
376 Lease4StorageSubnetIdIndex::const_iterator lower;
377 Lease4StorageSubnetIdIndex::const_iterator upper;
396 if (lower == upper) {
404 int64_t assigned = 0;
405 int64_t declined = 0;
406 for (Lease4StorageSubnetIdIndex::const_iterator lease = lower;
407 lease != upper; ++lease) {
410 if ((*lease)->subnet_id_ != cur_id) {
428 cur_id = (*lease)->subnet_id_;
518 Lease6StorageSubnetIdIndex::const_iterator lower;
519 Lease6StorageSubnetIdIndex::const_iterator upper;
538 if (lower == upper) {
546 int64_t assigned = 0;
547 int64_t declined = 0;
548 int64_t assigned_pds = 0;
549 for (Lease6StorageSubnetIdIndex::const_iterator lease = lower;
550 lease != upper; ++lease) {
553 if ((*lease)->subnet_id_ != cur_id) {
569 if (assigned_pds > 0) {
578 cur_id = (*lease)->subnet_id_;
583 switch((*lease)->type_) {
612 if (assigned_pds > 0) {
632 :
LeaseMgr(), lfc_setup_(), conn_(parameters), mutex_(new
std::mutex) {
633 bool conversion_needed =
false;
637 if (universe ==
"4") {
638 std::string file4 = initLeaseFilePath(
V4);
639 if (!file4.empty()) {
640 conversion_needed = loadLeasesFromFiles<
Lease4,
646 std::string file6 = initLeaseFilePath(
V6);
647 if (!file6.empty()) {
648 conversion_needed = loadLeasesFromFiles<
Lease6,
662 if (conversion_needed) {
666 lfcSetup(conversion_needed);
672 lease_file4_->close();
673 lease_file4_.reset();
676 lease_file6_->close();
677 lease_file6_.reset();
683 std::stringstream tmp;
690 Memfile_LeaseMgr::addLeaseInternal(
const Lease4Ptr& lease) {
691 if (getLease4Internal(lease->addr_)) {
700 lease_file4_->append(*lease);
703 storage4_.insert(lease);
707 lease->updateCurrentExpirationTime();
717 if (MultiThreadingMgr::instance().getMode()) {
718 std::lock_guard<std::mutex> lock(*mutex_);
719 return (addLeaseInternal(lease));
721 return (addLeaseInternal(lease));
726 Memfile_LeaseMgr::addLeaseInternal(
const Lease6Ptr& lease) {
727 if (getLease6Internal(lease->type_, lease->addr_)) {
736 lease_file6_->append(*lease);
739 storage6_.insert(lease);
743 lease->updateCurrentExpirationTime();
753 if (MultiThreadingMgr::instance().getMode()) {
754 std::lock_guard<std::mutex> lock(*mutex_);
755 return (addLeaseInternal(lease));
757 return (addLeaseInternal(lease));
764 Lease4StorageAddressIndex::iterator l = idx.find(addr);
765 if (l == idx.end()) {
777 if (MultiThreadingMgr::instance().getMode()) {
778 std::lock_guard<std::mutex> lock(*mutex_);
779 return (getLease4Internal(addr));
781 return (getLease4Internal(addr));
786 Memfile_LeaseMgr::getLease4Internal(
const HWAddr& hwaddr,
792 std::pair<Lease4StorageHWAddressSubnetIdIndex::const_iterator,
793 Lease4StorageHWAddressSubnetIdIndex::const_iterator> l
794 = idx.equal_range(boost::make_tuple(hwaddr.
hwaddr_));
796 for (
auto lease = l.first; lease != l.second; ++lease) {
807 if (MultiThreadingMgr::instance().getMode()) {
808 std::lock_guard<std::mutex> lock(*mutex_);
809 getLease4Internal(hwaddr, collection);
811 getLease4Internal(hwaddr, collection);
818 Memfile_LeaseMgr::getLease4Internal(
const HWAddr& hwaddr,
824 Lease4StorageHWAddressSubnetIdIndex::const_iterator lease =
825 idx.find(boost::make_tuple(hwaddr.
hwaddr_, subnet_id));
827 if (lease == idx.end()) {
842 if (MultiThreadingMgr::instance().getMode()) {
843 std::lock_guard<std::mutex> lock(*mutex_);
844 return (getLease4Internal(hwaddr, subnet_id));
846 return (getLease4Internal(hwaddr, subnet_id));
851 Memfile_LeaseMgr::getLease4Internal(
const ClientId& client_id,
857 std::pair<Lease4StorageClientIdSubnetIdIndex::const_iterator,
858 Lease4StorageClientIdSubnetIdIndex::const_iterator> l
859 = idx.equal_range(boost::make_tuple(client_id.
getClientId()));
861 for (
auto lease = l.first; lease != l.second; ++lease) {
872 if (MultiThreadingMgr::instance().getMode()) {
873 std::lock_guard<std::mutex> lock(*mutex_);
874 getLease4Internal(client_id, collection);
876 getLease4Internal(client_id, collection);
883 Memfile_LeaseMgr::getLease4Internal(
const ClientId& client_id,
889 Lease4StorageClientIdSubnetIdIndex::const_iterator lease =
890 idx.find(boost::make_tuple(client_id.
getClientId(), subnet_id));
892 if (lease == idx.end()) {
906 if (MultiThreadingMgr::instance().getMode()) {
907 std::lock_guard<std::mutex> lock(*mutex_);
908 return (getLease4Internal(client_id, subnet_id));
910 return (getLease4Internal(client_id, subnet_id));
915 Memfile_LeaseMgr::getLeases4Internal(
SubnetID subnet_id,
918 std::pair<Lease4StorageSubnetIdIndex::const_iterator,
919 Lease4StorageSubnetIdIndex::const_iterator> l =
920 idx.equal_range(subnet_id);
922 for (
auto lease = l.first; lease != l.second; ++lease) {
933 if (MultiThreadingMgr::instance().getMode()) {
934 std::lock_guard<std::mutex> lock(*mutex_);
935 getLeases4Internal(subnet_id, collection);
937 getLeases4Internal(subnet_id, collection);
944 Memfile_LeaseMgr::getLeases4Internal(
const std::string& hostname,
947 std::pair<Lease4StorageHostnameIndex::const_iterator,
948 Lease4StorageHostnameIndex::const_iterator> l =
949 idx.equal_range(hostname);
951 for (
auto lease = l.first; lease != l.second; ++lease) {
962 if (MultiThreadingMgr::instance().getMode()) {
963 std::lock_guard<std::mutex> lock(*mutex_);
964 getLeases4Internal(hostname, collection);
966 getLeases4Internal(hostname, collection);
974 for (
auto lease = storage4_.begin(); lease != storage4_.end(); ++lease) {
984 if (MultiThreadingMgr::instance().getMode()) {
985 std::lock_guard<std::mutex> lock(*mutex_);
986 getLeases4Internal(collection);
988 getLeases4Internal(collection);
999 Lease4StorageAddressIndex::const_iterator lb = idx.lower_bound(lower_bound_address);
1002 if ((lb != idx.end()) && ((*lb)->addr_ == lower_bound_address)) {
1007 for (
auto lease = lb;
1008 (lease != idx.end()) && (std::distance(lb, lease) < page_size.
page_size_);
1010 collection.push_back(
Lease4Ptr(
new Lease4(**lease)));
1018 if (!lower_bound_address.
isV4()) {
1020 "retrieving leases from the lease database, got "
1021 << lower_bound_address);
1026 .arg(lower_bound_address.
toText());
1029 if (MultiThreadingMgr::instance().getMode()) {
1030 std::lock_guard<std::mutex> lock(*mutex_);
1031 getLeases4Internal(lower_bound_address, page_size, collection);
1033 getLeases4Internal(lower_bound_address, page_size, collection);
1036 return (collection);
1040 Memfile_LeaseMgr::getLease6Internal(
Lease::Type type,
1042 Lease6Storage::iterator l = storage6_.find(addr);
1043 if (l == storage6_.end() || !(*l) || ((*l)->type_ != type)) {
1058 if (MultiThreadingMgr::instance().getMode()) {
1059 std::lock_guard<std::mutex> lock(*mutex_);
1060 return (getLease6Internal(type, addr));
1062 return (getLease6Internal(type, addr));
1067 Memfile_LeaseMgr::getLeases6Internal(
Lease::Type type,
1074 std::pair<Lease6StorageDuidIaidTypeIndex::const_iterator,
1075 Lease6StorageDuidIaidTypeIndex::const_iterator> l =
1076 idx.equal_range(boost::make_tuple(duid.
getDuid(), iaid, type));
1078 for (Lease6StorageDuidIaidTypeIndex::const_iterator lease =
1079 l.first; lease != l.second; ++lease) {
1087 uint32_t iaid)
const {
1095 if (MultiThreadingMgr::instance().getMode()) {
1096 std::lock_guard<std::mutex> lock(*mutex_);
1097 getLeases6Internal(type, duid, iaid, collection);
1099 getLeases6Internal(type, duid, iaid, collection);
1102 return (collection);
1106 Memfile_LeaseMgr::getLeases6Internal(
Lease::Type type,
1114 std::pair<Lease6StorageDuidIaidTypeIndex::const_iterator,
1115 Lease6StorageDuidIaidTypeIndex::const_iterator> l =
1116 idx.equal_range(boost::make_tuple(duid.
getDuid(), iaid, type));
1118 for (Lease6StorageDuidIaidTypeIndex::const_iterator lease =
1119 l.first; lease != l.second; ++lease) {
1121 if ((*lease)->subnet_id_ == subnet_id) {
1140 if (MultiThreadingMgr::instance().getMode()) {
1141 std::lock_guard<std::mutex> lock(*mutex_);
1142 getLeases6Internal(type, duid, iaid, subnet_id, collection);
1144 getLeases6Internal(type, duid, iaid, subnet_id, collection);
1147 return (collection);
1151 Memfile_LeaseMgr::getLeases6Internal(
SubnetID subnet_id,
1154 std::pair<Lease6StorageSubnetIdIndex::const_iterator,
1155 Lease6StorageSubnetIdIndex::const_iterator> l =
1156 idx.equal_range(subnet_id);
1158 for (
auto lease = l.first; lease != l.second; ++lease) {
1169 if (MultiThreadingMgr::instance().getMode()) {
1170 std::lock_guard<std::mutex> lock(*mutex_);
1171 getLeases6Internal(subnet_id, collection);
1173 getLeases6Internal(subnet_id, collection);
1176 return (collection);
1180 Memfile_LeaseMgr::getLeases6Internal(
const std::string& hostname,
1183 std::pair<Lease6StorageHostnameIndex::const_iterator,
1184 Lease6StorageHostnameIndex::const_iterator> l =
1185 idx.equal_range(hostname);
1187 for (
auto lease = l.first; lease != l.second; ++lease) {
1198 if (MultiThreadingMgr::instance().getMode()) {
1199 std::lock_guard<std::mutex> lock(*mutex_);
1200 getLeases6Internal(hostname, collection);
1202 getLeases6Internal(hostname, collection);
1205 return (collection);
1210 for (
auto lease = storage6_.begin(); lease != storage6_.end(); ++lease) {
1220 if (MultiThreadingMgr::instance().getMode()) {
1221 std::lock_guard<std::mutex> lock(*mutex_);
1222 getLeases6Internal(collection);
1224 getLeases6Internal(collection);
1227 return (collection);
1231 Memfile_LeaseMgr::getLeases6Internal(
const DUID& duid,
1234 std::pair<Lease6StorageDuidIndex::const_iterator,
1235 Lease6StorageDuidIndex::const_iterator> l =
1236 idx.equal_range(duid.
getDuid());
1238 for (
auto lease = l.first; lease != l.second; ++lease) {
1249 if (MultiThreadingMgr::instance().getMode()) {
1250 std::lock_guard<std::mutex> lock(*mutex_);
1251 getLeases6Internal(duid, collection);
1253 getLeases6Internal(duid, collection);
1256 return (collection);
1264 Lease6StorageAddressIndex::const_iterator lb = idx.lower_bound(lower_bound_address);
1267 if ((lb != idx.end()) && ((*lb)->addr_ == lower_bound_address)) {
1272 for (
auto lease = lb;
1273 (lease != idx.end()) && (std::distance(lb, lease) < page_size.
page_size_);
1275 collection.push_back(
Lease6Ptr(
new Lease6(**lease)));
1283 if (!lower_bound_address.
isV6()) {
1285 "retrieving leases from the lease database, got "
1286 << lower_bound_address);
1291 .arg(lower_bound_address.
toText());
1294 if (MultiThreadingMgr::instance().getMode()) {
1295 std::lock_guard<std::mutex> lock(*mutex_);
1296 getLeases6Internal(lower_bound_address, page_size, collection);
1298 getLeases6Internal(lower_bound_address, page_size, collection);
1301 return (collection);
1305 Memfile_LeaseMgr::getExpiredLeases4Internal(
Lease4Collection& expired_leases,
1306 const size_t max_leases)
const {
1314 Lease4StorageExpirationIndex::const_iterator ub =
1315 index.upper_bound(boost::make_tuple(
false, time(NULL)));
1318 for (Lease4StorageExpirationIndex::const_iterator lease = index.begin();
1319 (lease != ub) && ((max_leases == 0) || (std::distance(index.begin(), lease) <
1328 const size_t max_leases)
const {
1332 if (MultiThreadingMgr::instance().getMode()) {
1333 std::lock_guard<std::mutex> lock(*mutex_);
1334 getExpiredLeases4Internal(expired_leases, max_leases);
1336 getExpiredLeases4Internal(expired_leases, max_leases);
1341 Memfile_LeaseMgr::getExpiredLeases6Internal(
Lease6Collection& expired_leases,
1342 const size_t max_leases)
const {
1350 Lease6StorageExpirationIndex::const_iterator ub =
1351 index.upper_bound(boost::make_tuple(
false, time(NULL)));
1354 for (Lease6StorageExpirationIndex::const_iterator lease = index.begin();
1355 (lease != ub) && ((max_leases == 0) || (std::distance(index.begin(), lease) <
1364 const size_t max_leases)
const {
1368 if (MultiThreadingMgr::instance().getMode()) {
1369 std::lock_guard<std::mutex> lock(*mutex_);
1370 getExpiredLeases6Internal(expired_leases, max_leases);
1372 getExpiredLeases6Internal(expired_leases, max_leases);
1377 Memfile_LeaseMgr::updateLease4Internal(
const Lease4Ptr& lease) {
1384 Lease4StorageAddressIndex::const_iterator lease_it = index.find(lease->addr_);
1385 if (lease_it == index.end()) {
1387 << lease->addr_ <<
" - no such lease");
1388 }
else if ((!persist) && (((*lease_it)->cltt_ != lease->current_cltt_) ||
1389 ((*lease_it)->valid_lft_ != lease->current_valid_lft_))) {
1392 isc_throw(NoSuchLease,
"failed to update the lease with address "
1393 << lease->addr_ <<
" - lease has changed in database");
1400 lease_file4_->append(*lease);
1404 lease->updateCurrentExpirationTime();
1407 index.replace(lease_it,
Lease4Ptr(
new Lease4(*lease)));
1415 if (MultiThreadingMgr::instance().getMode()) {
1416 std::lock_guard<std::mutex> lock(*mutex_);
1417 updateLease4Internal(lease);
1419 updateLease4Internal(lease);
1424 Memfile_LeaseMgr::updateLease6Internal(
const Lease6Ptr& lease) {
1431 Lease6StorageAddressIndex::const_iterator lease_it = index.find(lease->addr_);
1432 if (lease_it == index.end()) {
1434 << lease->addr_ <<
" - no such lease");
1435 }
else if ((!persist) && (((*lease_it)->cltt_ != lease->current_cltt_) ||
1436 ((*lease_it)->valid_lft_ != lease->current_valid_lft_))) {
1439 isc_throw(NoSuchLease,
"failed to update the lease with address "
1440 << lease->addr_ <<
" - lease has changed in database");
1447 lease_file6_->append(*lease);
1451 lease->updateCurrentExpirationTime();
1454 index.replace(lease_it,
Lease6Ptr(
new Lease6(*lease)));
1462 if (MultiThreadingMgr::instance().getMode()) {
1463 std::lock_guard<std::mutex> lock(*mutex_);
1464 updateLease6Internal(lease);
1466 updateLease6Internal(lease);
1471 Memfile_LeaseMgr::deleteLeaseInternal(
const Lease4Ptr& lease) {
1473 Lease4Storage::iterator l = storage4_.find(addr);
1474 if (l == storage4_.end()) {
1481 Lease4 lease_copy = **l;
1484 lease_copy.valid_lft_ = 0;
1485 lease_file4_->append(lease_copy);
1489 if (((*l)->cltt_ != lease->current_cltt_) ||
1490 ((*l)->valid_lft_ != lease->current_valid_lft_)) {
1504 if (MultiThreadingMgr::instance().getMode()) {
1505 std::lock_guard<std::mutex> lock(*mutex_);
1506 return (deleteLeaseInternal(lease));
1508 return (deleteLeaseInternal(lease));
1513 Memfile_LeaseMgr::deleteLeaseInternal(
const Lease6Ptr& lease) {
1515 Lease6Storage::iterator l = storage6_.find(addr);
1516 if (l == storage6_.end()) {
1523 Lease6 lease_copy = **l;
1525 lease_copy.valid_lft_ = 0;
1526 lease_copy.preferred_lft_ = 0;
1527 lease_file6_->append(lease_copy);
1531 if (((*l)->cltt_ != lease->current_cltt_) ||
1532 ((*l)->valid_lft_ != lease->current_valid_lft_)) {
1546 if (MultiThreadingMgr::instance().getMode()) {
1547 std::lock_guard<std::mutex> lock(*mutex_);
1548 return (deleteLeaseInternal(lease));
1550 return (deleteLeaseInternal(lease));
1560 if (MultiThreadingMgr::instance().getMode()) {
1561 std::lock_guard<std::mutex> lock(*mutex_);
1562 return (deleteExpiredReclaimedLeases<
1564 >(secs,
V4, storage4_, lease_file4_));
1566 return (deleteExpiredReclaimedLeases<
1568 >(secs,
V4, storage4_, lease_file4_));
1578 if (MultiThreadingMgr::instance().getMode()) {
1579 std::lock_guard<std::mutex> lock(*mutex_);
1580 return (deleteExpiredReclaimedLeases<
1582 >(secs,
V6, storage6_, lease_file6_));
1584 return (deleteExpiredReclaimedLeases<
1586 >(secs,
V6, storage6_, lease_file6_));
1590 template<
typename IndexType,
typename LeaseType,
typename StorageType,
1591 typename LeaseFileType>
1593 Memfile_LeaseMgr::deleteExpiredReclaimedLeases(
const uint32_t secs,
1594 const Universe& universe,
1595 StorageType& storage,
1596 LeaseFileType& lease_file)
const {
1598 IndexType& index = storage.template get<ExpirationIndexTag>();
1609 typename IndexType::const_iterator upper_limit =
1610 index.upper_bound(boost::make_tuple(
true, time(NULL) - secs));
1619 typename IndexType::const_iterator lower_limit =
1620 index.upper_bound(boost::make_tuple(
true, std::numeric_limits<int64_t>::min()));
1623 uint64_t num_leases =
static_cast<uint64_t
>(std::distance(lower_limit, upper_limit));
1624 if (num_leases > 0) {
1634 for (
typename IndexType::const_iterator lease = lower_limit;
1635 lease != upper_limit; ++lease) {
1637 LeaseType lease_copy(**lease);
1640 lease_copy.valid_lft_ = 0;
1641 lease_file->append(lease_copy);
1646 index.erase(lower_limit, upper_limit);
1649 return (num_leases);
1655 return (std::string(
"In memory database with leases stored in a CSV file."));
1672 std::string name(file_name);
1673 switch (file_type) {
1684 name +=
".completed";
1699 std::ostringstream s;
1701 s << (u ==
V4 ?
"4" :
"6");
1709 return (lease_file4_ ? lease_file4_->getFilename() :
"");
1712 return (lease_file6_ ? lease_file6_->getFilename() :
"");
1720 if (u ==
V4 && lease_file4_) {
1724 return (u ==
V6 && lease_file6_);
1728 Memfile_LeaseMgr::initLeaseFilePath(Universe u) {
1729 std::string persist_val;
1735 persist_val =
"true";
1739 if (persist_val ==
"false") {
1742 }
else if (persist_val !=
"true") {
1744 << persist_val <<
"'");
1747 std::string lease_file;
1750 }
catch (
const Exception&) {
1753 return (lease_file);
1756 template<
typename LeaseObjectType,
typename LeaseFileType,
typename StorageType>
1758 Memfile_LeaseMgr::loadLeasesFromFiles(
const std::string& filename,
1759 boost::shared_ptr<LeaseFileType>& lease_file,
1760 StorageType& storage) {
1768 if (pid_file.check()) {
1770 "lease file cleanup is in progress");
1775 std::string max_row_errors_str =
"0";
1777 max_row_errors_str = conn_.
getParameter(
"max-row-errors");
1778 }
catch (
const std::exception&) {
1782 uint32_t max_row_errors = 0;
1784 max_row_errors = boost::lexical_cast<uint32_t>(max_row_errors_str);
1785 }
catch (
const boost::bad_lexical_cast&) {
1787 << max_row_errors_str <<
" specified");
1791 bool conversion_needed =
false;
1792 lease_file.reset(
new LeaseFileType(std::string(filename +
".completed")));
1793 if (lease_file->exists()) {
1794 LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
1796 conversion_needed = conversion_needed || lease_file->needsConversion();
1801 if (lease_file->exists()) {
1802 LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
1804 conversion_needed = conversion_needed || lease_file->needsConversion();
1808 if (lease_file->exists()) {
1809 LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
1811 conversion_needed = conversion_needed || lease_file->needsConversion();
1821 lease_file.reset(
new LeaseFileType(filename));
1822 LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
1823 max_row_errors,
false);
1824 conversion_needed = conversion_needed || lease_file->needsConversion();
1826 return (conversion_needed);
1832 return (lfc_setup_->isRunning());
1837 return (lfc_setup_->getExitStatus());
1847 lfcExecute(lease_file4_);
1848 }
else if (lease_file6_) {
1850 lfcExecute(lease_file6_);
1855 Memfile_LeaseMgr::lfcSetup(
bool conversion_needed) {
1856 std::string lfc_interval_str =
"3600";
1859 }
catch (
const std::exception&) {
1863 uint32_t lfc_interval = 0;
1865 lfc_interval = boost::lexical_cast<uint32_t>(lfc_interval_str);
1866 }
catch (
const boost::bad_lexical_cast&) {
1868 << lfc_interval_str <<
" specified");
1871 if (lfc_interval > 0 || conversion_needed) {
1873 lfc_setup_->setup(lfc_interval, lease_file4_, lease_file6_, conversion_needed);
1877 template<
typename LeaseFileType>
1879 Memfile_LeaseMgr::lfcExecute(boost::shared_ptr<LeaseFileType>& lease_file) {
1889 if (!lease_file_finish.exists() && !lease_file_copy.exists()) {
1891 lease_file->close();
1894 do_lfc = (rename(lease_file->getFilename().c_str(),
1895 lease_file_copy.getFilename().c_str()) == 0);
1899 .arg(lease_file->getFilename())
1900 .arg(lease_file_copy.getFilename())
1901 .arg(strerror(errno));
1910 lease_file->open(
true);
1923 .arg(lease_file->getFilename())
1934 lfc_setup_->execute();
1993 std::pair<Lease4StorageSubnetIdIndex::const_iterator,
1994 Lease4StorageSubnetIdIndex::const_iterator> l =
1995 idx.equal_range(subnet_id);
1999 for (
auto lease = l.first; lease != l.second; ++lease) {
2000 leases.push_back(*lease);
2003 size_t num = leases.size();
2004 for (
auto l = leases.begin(); l != leases.end(); ++l) {
2008 .arg(subnet_id).arg(num);
2022 std::pair<Lease6StorageSubnetIdIndex::const_iterator,
2023 Lease6StorageSubnetIdIndex::const_iterator> l =
2024 idx.equal_range(subnet_id);
2028 for (
auto lease = l.first; lease != l.second; ++lease) {
2029 leases.push_back(*lease);
2032 size_t num = leases.size();
2033 for (
auto l = leases.begin(); l != leases.end(); ++l) {
2037 .arg(subnet_id).arg(num);
RAII class creating a critical section.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery6(const SubnetID &subnet_id)
Creates and runs the IPv6 lease stats query for a single subnet.
const std::vector< uint8_t > & getDuid() const
Returns a const reference to the actual DUID value.
Represents a configuration for Lease File Cleanup.
virtual void rollback()
Rollback Transactions.
Tag for indexes by DUID, IAID, lease type tuple.
virtual ~MemfileLeaseStatsQuery4()
Destructor.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_HWADDR
boost::shared_ptr< TimerMgr > TimerMgrPtr
Type definition of the shared pointer to TimerMgr.
virtual ~Memfile_LeaseMgr()
Destructor (closes file)
MemfileLeaseStatsQuery(const SubnetID &subnet_id)
Constructor for single subnet query.
virtual std::string getDescription() const
Returns description of the backend.
boost::shared_ptr< LeaseStatsQuery > LeaseStatsQueryPtr
Defines a pointer to a LeaseStatsQuery.
std::string toText() const
Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
const isc::log::MessageID DHCPSRV_MEMFILE_UPDATE_ADDR6
Structure that holds a lease for IPv4 address.
SelectMode getSelectMode() const
Returns the selection criteria mode The value returned is based upon the constructor variant used and...
const isc::log::MessageID DHCPSRV_MEMFILE_WIPE_LEASES4
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.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
std::function< void()> callback_
The callback function.
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_START
std::vector< LeaseStatsRow >::iterator next_pos_
An iterator for accessing the next row within the result set.
static std::string typeToText(Type type)
returns text representation of a lease type
const isc::log::MessageID DHCPSRV_MEMFILE_WIPE_LEASES6
Memfile derivation of the IPv6 statistical lease data query.
virtual size_t wipeLeases6(const SubnetID &subnet_id)
Removed specified IPv6 leases.
const isc::log::MessageID DHCPSRV_MEMFILE_GET6_DUID
MemfileLeaseStatsQuery(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Constructor for subnet range query.
static CfgMgr & instance()
returns a single instance of Configuration Manager
Manages a pool of asynchronous interval timers.
Attempt to update lease that was not there.
std::vector< Lease4Ptr > Lease4Collection
A collection of IPv4 leases.
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery6(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Creates and runs the IPv6 lease stats query for a single subnet.
Lease4Storage::index< HostnameIndexTag >::type Lease4StorageHostnameIndex
DHCPv4 lease storage index by hostname.
Lease6Storage::index< DuidIaidTypeIndexTag >::type Lease6StorageDuidIaidTypeIndex
DHCPv6 lease storage index by DUID, IAID, lease type.
Universe
Specifies universe (V4, V6)
virtual void getExpiredLeases6(Lease6Collection &expired_leases, const size_t max_leases) const
Returns a collection of expired DHCPv6 leases.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
the lease contains IPv6 prefix (for prefix delegation)
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_EXPIRED_RECLAIMED4
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID_HWADDR
Tag for indexes by expiration time.
std::vector< uint8_t > hwaddr_
const isc::log::MessageID DHCPSRV_MEMFILE_CONVERTING_LEASE_FILES
virtual void getExpiredLeases4(Lease4Collection &expired_leases, const size_t max_leases) const
Returns a collection of expired DHCPv4 leases.
Lease4Storage::index< HWAddressSubnetIdIndexTag >::type Lease4StorageHWAddressSubnetIdIndex
DHCPv4 lease storage index by HW address and subnet identifier.
Base class for fulfilling a statistical lease data query.
static const int MAJOR_VERSION
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_SETUP
std::string toText(bool include_htype=true) const
Returns textual representation of a hardware address (e.g.
virtual bool deleteLease(const Lease4Ptr &lease)
Deletes an IPv4 lease.
void start()
Creates the IPv4 lease statistical data result set.
Class to help with processing PID files.
std::string getDefaultLeaseFilePath(Universe u) const
Returns default path to the lease file.
Memfile_LeaseMgr(const db::DatabaseConnection::ParameterMap ¶meters)
The sole lease manager constructor.
boost::multi_index_container< Lease4Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< AddressIndexTag >, boost::multi_index::member< Lease, isc::asiolink::IOAddress,&Lease::addr_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< HWAddressSubnetIdIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::const_mem_fun< Lease, const std::vector< uint8_t > &,&Lease::getHWAddrVector >, boost::multi_index::member< Lease, SubnetID,&Lease::subnet_id_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ClientIdSubnetIdIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::const_mem_fun< Lease4, const std::vector< uint8_t > &,&Lease4::getClientIdVector >, boost::multi_index::member< Lease, uint32_t,&Lease::subnet_id_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ExpirationIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::const_mem_fun< Lease, bool,&Lease::stateExpiredReclaimed >, boost::multi_index::const_mem_fun< Lease, int64_t,&Lease::getExpirationTime > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetIdIndexTag >, boost::multi_index::member< Lease, isc::dhcp::SubnetID,&Lease::subnet_id_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< HostnameIndexTag >, boost::multi_index::member< Lease, std::string,&Lease::hostname_ > > >> Lease4Storage
A multi index container holding DHCPv4 leases.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_IAID_SUBID_DUID
std::function< void()> Callback
const isc::log::MessageID DHCPSRV_MEMFILE_GET_PAGE6
static std::string getDBVersion()
Local version of getDBVersion() class method.
bool isV4() const
Convenience function to check for an IPv4 address.
LFCFileType
Types of the lease files used by the Lease File Cleanup.
Holds DUID (DHCPv6 Unique Identifier)
const isc::log::MessageID DHCPSRV_MEMFILE_UPDATE_ADDR4
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID4
Tag for index using hostname.
Exception thrown on failure to open database.
Provides methods to access CSV file with DHCPv4 leases.
static isc::asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service.
virtual LeaseStatsQueryPtr startSubnetLeaseStatsQuery4(const SubnetID &subnet_id)
Creates and runs the IPv4 lease stats query for a single subnet.
MemfileLeaseStatsQuery6(Lease6Storage &storage6, const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Constructor for a subnet range query.
const isc::log::MessageID DHCPSRV_MEMFILE_ADD_ADDR6
const isc::log::MessageID DHCPSRV_MEMFILE_GET6
Lease6Storage::index< AddressIndexTag >::type Lease6StorageAddressIndex
DHCPv6 lease storage index by address.
MemfileLeaseStatsQuery6(Lease6Storage &storage6, const SubnetID &subnet_id)
Constructor for a single subnet query.
virtual LeaseStatsQueryPtr startLeaseStatsQuery6()
Creates and runs the IPv6 lease stats query.
const isc::log::MessageID DHCPSRV_MEMFILE_ADD_ADDR4
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
const isc::log::MessageID DHCPSRV_MEMFILE_WIPE_LEASES6_FINISHED
virtual void lfcCallback()
A callback function triggering Lease File Cleanup (LFC).
Lease6Storage::index< DuidIndexTag >::type Lease6StorageDuidIndex
DHCPv6 lease storage index by DUID.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_CLIENTID
Lease4Storage::index< AddressIndexTag >::type Lease4StorageAddressIndex
DHCPv4 lease storage index by address.
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const
Returns existing IPv6 lease for a given IPv6 address.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_IAID_DUID
util::Optional< std::string > getDataDir() const
returns path do the data directory
virtual bool getNextRow(LeaseStatsRow &row)
Fetches the next row in the result set.
Lease4Storage::index< SubnetIdIndexTag >::type Lease4StorageSubnetIdIndex
DHCPv4 lease storage index subnet identifier.
const size_t page_size_
Holds page size.
boost::multi_index_container< Lease6Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< AddressIndexTag >, boost::multi_index::member< Lease, isc::asiolink::IOAddress,&Lease::addr_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< DuidIaidTypeIndexTag >, boost::multi_index::composite_key< Lease6, boost::multi_index::const_mem_fun< Lease6, const std::vector< uint8_t > &,&Lease6::getDuidVector >, boost::multi_index::member< Lease6, uint32_t,&Lease6::iaid_ >, boost::multi_index::member< Lease6, Lease::Type,&Lease6::type_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ExpirationIndexTag >, boost::multi_index::composite_key< Lease6, boost::multi_index::const_mem_fun< Lease, bool,&Lease::stateExpiredReclaimed >, boost::multi_index::const_mem_fun< Lease, int64_t,&Lease::getExpirationTime > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetIdIndexTag >, boost::multi_index::member< Lease, isc::dhcp::SubnetID,&Lease::subnet_id_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< DuidIndexTag >, boost::multi_index::const_mem_fun< Lease6, const std::vector< uint8_t > &,&Lease6::getDuidVector > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< HostnameIndexTag >, boost::multi_index::member< Lease, std::string,&Lease::hostname_ > > >> Lease6Storage
A multi index container holding DHCPv6 leases.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
const int DHCPSRV_DBG_TRACE_DETAIL
Additional information.
Lease4Storage::index< ExpirationIndexTag >::type Lease4StorageExpirationIndex
DHCPv4 lease storage index by expiration time.
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_EXECUTE
const std::vector< uint8_t > & getClientId() const
Returns reference to the client-id data.
const isc::log::MessageID DHCPSRV_MEMFILE_ROLLBACK
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs)
Deletes all expired-reclaimed DHCPv4 leases.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_ADDR4
virtual void commit()
Commit Transactions.
int getLFCExitStatus() const
Returns the status code returned by the last executed LFC process.
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_EXPIRED_RECLAIMED6
const isc::log::MessageID DHCPSRV_MEMFILE_GET_HOSTNAME4
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID6
const isc::log::MessageID DHCPSRV_MEMFILE_GET_HOSTNAME6
Structure that holds a lease for IPv6 address and/or prefix.
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_ADDR
Lease6Storage::index< HostnameIndexTag >::type Lease6StorageHostnameIndex
DHCPv6 lease storage index by hostname.
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_UNREGISTER_TIMER_FAILED
static const int MINOR_VERSION
Defines minor version of the memfile backend.
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
Tag for index using DUID.
MemfileLeaseStatsQuery()
Constructor for all subnets query.
std::string toText() const
Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
MemfileLeaseStatsQuery4(Lease4Storage &storage4, const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Constructor for a subnet range query.
bool isLFCRunning() const
Checks if the process performing lease file cleanup is running.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_EXPIRED6
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Tag for indexes by HW address, subnet identifier tuple.
virtual LeaseStatsQueryPtr startSubnetRangeLeaseStatsQuery4(const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Creates and runs the IPv4 lease stats query for a single subnet.
the lease contains non-temporary IPv6 address
virtual size_t wipeLeases4(const SubnetID &subnet_id)
Removes specified IPv4 leases.
Memfile derivation of the IPv4 statistical lease data query.
const isc::log::MessageID DHCPSRV_MEMFILE_GET4
virtual Lease6Collection getLeases6() const
Returns all IPv6 leases.
std::string getLeaseFilePath(Universe u) const
Returns an absolute path to the lease file.
Invalid address family used as input to Lease Manager.
virtual LeaseStatsQueryPtr startLeaseStatsQuery4()
Creates and runs the IPv4 lease stats query.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
virtual Lease4Collection getLeases4() const
Returns all IPv4 leases.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_ADDR6
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_LEASE_FILE_RENAME_FAIL
virtual void updateLease4(const Lease4Ptr &lease4)
Updates IPv4 lease.
std::string getParameter(const std::string &name) const
Returns value of a connection parameter.
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_EXPIRED_RECLAIMED_START
Tag for indexes by address.
const isc::log::MessageID DHCPSRV_MEMFILE_COMMIT
Exception thrown when error occurs during spawning a process.
virtual ~MemfileLeaseStatsQuery6()
Destructor.
Type
Type of lease or pool.
Lease6Storage::index< ExpirationIndexTag >::type Lease6StorageExpirationIndex
DHCPv6 lease storage index by expiration time.
Holds Client identifier or client IPv4 address.
bool isRunning() const
Checks if the lease file cleanup is in progress.
A generic exception that is thrown if a function is called in a prohibited way.
Provides input/output access to CSV files.
MemfileLeaseStatsQuery6(Lease6Storage &storage6)
Constructor.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
std::string toText() const
Convert the address to a string.
virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs)
Deletes all expired-reclaimed DHCPv6 leases.
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_SPAWN_FAIL
Hardware type that represents information from DHCPv4 packet.
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
int getRowCount() const
Returns the number of rows in the result set.
Base Memfile derivation of the statistical lease data query.
static const uint32_t STATE_DEFAULT
A lease in the default state.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_PAGE4
bool isV6() const
Convenience function to check for an IPv6 address.
SubnetID getFirstSubnetID() const
Returns the value of first subnet ID specified (or zero)
int getExitStatus() const
Returns exit code of the last completed cleanup.
const isc::log::MessageID DHCPSRV_MEMFILE_WIPE_LEASES4_FINISHED
Tag for indexes by client and subnet identifiers.
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
static const uint32_t STATE_DECLINED
Declined lease.
Contains a single row of lease statistical data.
std::vector< LeaseStatsRow > rows_
A vector containing the "result set".
void execute()
Spawns a new process.
std::vector< std::string > ProcessArgs
Type of the container holding arguments of the executable being run as a background process...
MemfileLeaseStatsQuery4(Lease4Storage &storage4, const SubnetID &subnet_id)
Constructor for a single subnet query.
Wraps value holding size of the page with leases.
const isc::log::MessageID DHCPSRV_MEMFILE_NO_STORAGE
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Tag for indexes by subnet-id.
SubnetID getLastSubnetID() const
Returns the value of last subnet ID specified (or zero)
virtual ~MemfileLeaseStatsQuery()
Destructor.
Lease4Storage::index< ClientIdSubnetIdIndexTag >::type Lease4StorageClientIdSubnetIdIndex
DHCPv4 lease storage index by client and subnet identifier.
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_LEASE_FILE_REOPEN_FAIL
The IOAddress class represents an IP addresses (version agnostic)
virtual void start()
Creates the IPv6 lease statistical data result set.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_EXPIRED4
virtual void updateLease6(const Lease6Ptr &lease6)
Updates IPv6 lease.
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Provides methods to access CSV file with DHCPv6 leases.
static std::string appendSuffix(const std::string &file_name, const LFCFileType &file_type)
Appends appropriate suffix to the file name.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID_CLIENTID
MemfileLeaseStatsQuery4(Lease4Storage &storage4)
Constructor for an all subnets query.
bool persistLeases(Universe u) const
Specifies whether or not leases are written to disk.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
Lease6Storage::index< SubnetIdIndexTag >::type Lease6StorageSubnetIdIndex
DHCPv6 lease storage index by Subnet-id.
virtual bool addLease(const Lease4Ptr &lease)
Adds an IPv4 lease.
virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress &addr) const
Returns existing IPv4 lease for specified IPv4 address.
Exception thrown when an error occurs during CSV file processing.
Utility class for spawning new processes.