35 const char* KEA_LFC_EXECUTABLE_ENV_NAME =
"KEA_LFC_EXECUTABLE";
90 void setup(
const uint32_t lfc_interval,
91 const boost::shared_ptr<CSVLeaseFile4>& lease_file4,
92 const boost::shared_ptr<CSVLeaseFile6>& lease_file6,
93 bool run_once_now =
false);
101 bool isRunning()
const;
104 int getExitStatus()
const;
110 boost::scoped_ptr<ProcessSpawn> process_;
126 : process_(), callback_(callback), pid_(0),
142 timer_mgr_->unregisterTimer(
"memfile-lfc");
144 }
catch (
const std::exception& ex) {
155 const boost::shared_ptr<CSVLeaseFile4>& lease_file4,
156 const boost::shared_ptr<CSVLeaseFile6>& lease_file6,
160 if (lfc_interval == 0 && !run_once_now) {
165 std::string executable;
166 char* c_executable = getenv(KEA_LFC_EXECUTABLE_ENV_NAME);
167 if (c_executable == NULL) {
168 executable = KEA_LFC_EXECUTABLE;
170 executable = c_executable;
174 std::string lease_file = lease_file4 ? lease_file4->getFilename() :
175 lease_file6->getFilename();
180 args.push_back(lease_file4 ?
"-4" :
"-6");
183 args.push_back(
"-x");
187 args.push_back(
"-i");
191 args.push_back(
"-o");
195 args.push_back(
"-f");
199 args.push_back(
"-p");
204 args.push_back(
"-c");
205 args.push_back(
"ignored-path");
216 if (lfc_interval > 0) {
223 timer_mgr_->registerTimer(
"memfile-lfc", callback_, lfc_interval * 1000,
225 timer_mgr_->setup(
"memfile-lfc");
233 .arg(process_->getCommandLine());
234 pid_ = process_->spawn();
243 return (process_ && process_->isRunning(pid_));
250 " the process is NULL");
252 return (process_->getExitStatus(pid_));
266 : rows_(0), next_pos_(rows_.end()) {
281 :
LeaseStatsQuery(first_subnet_id, last_subnet_id), rows_(0), next_pos_(rows_.end()) {
298 if (next_pos_ == rows_.end()) {
309 return (rows_.size());
378 Lease4StorageSubnetIdIndex::const_iterator lower;
379 Lease4StorageSubnetIdIndex::const_iterator upper;
380 switch (getSelectMode()) {
387 lower = idx.lower_bound(getFirstSubnetID());
388 upper = idx.upper_bound(getFirstSubnetID());
392 lower = idx.lower_bound(getFirstSubnetID());
393 upper = idx.upper_bound(getLastSubnetID());
398 if (lower == upper) {
406 int64_t assigned = 0;
407 int64_t declined = 0;
408 for (Lease4StorageSubnetIdIndex::const_iterator lease = lower;
409 lease != upper; ++lease) {
412 if ((*lease)->subnet_id_ != cur_id) {
430 cur_id = (*lease)->subnet_id_;
453 next_pos_ = rows_.begin();
520 Lease6StorageSubnetIdIndex::const_iterator lower;
521 Lease6StorageSubnetIdIndex::const_iterator upper;
522 switch (getSelectMode()) {
529 lower = idx.lower_bound(getFirstSubnetID());
530 upper = idx.upper_bound(getFirstSubnetID());
534 lower = idx.lower_bound(getFirstSubnetID());
535 upper = idx.upper_bound(getLastSubnetID());
540 if (lower == upper) {
548 int64_t assigned = 0;
549 int64_t declined = 0;
550 int64_t assigned_pds = 0;
551 for (Lease6StorageSubnetIdIndex::const_iterator lease = lower;
552 lease != upper; ++lease) {
555 if ((*lease)->subnet_id_ != cur_id) {
571 if (assigned_pds > 0) {
580 cur_id = (*lease)->subnet_id_;
585 switch((*lease)->type_) {
614 if (assigned_pds > 0) {
620 next_pos_ = rows_.begin();
636 :
LeaseMgr(), lfc_setup_(), conn_(parameters), mutex_(new
std::mutex) {
637 bool conversion_needed =
false;
641 if (universe ==
"4") {
642 std::string file4 = initLeaseFilePath(
V4);
643 if (!file4.empty()) {
644 conversion_needed = loadLeasesFromFiles<
Lease4,
650 std::string file6 = initLeaseFilePath(
V6);
651 if (!file6.empty()) {
652 conversion_needed = loadLeasesFromFiles<
Lease6,
666 if (conversion_needed) {
671 lfcSetup(conversion_needed);
677 lease_file4_->close();
678 lease_file4_.reset();
681 lease_file6_->close();
682 lease_file6_.reset();
688 std::stringstream tmp;
689 tmp <<
"Memfile backend ";
692 }
else if (u ==
V6) {
699 Memfile_LeaseMgr::addLeaseInternal(
const Lease4Ptr& lease) {
700 if (getLease4Internal(lease->addr_)) {
709 lease_file4_->append(*lease);
712 storage4_.insert(lease);
716 lease->updateCurrentExpirationTime();
726 if (MultiThreadingMgr::instance().getMode()) {
727 std::lock_guard<std::mutex> lock(*mutex_);
728 return (addLeaseInternal(lease));
730 return (addLeaseInternal(lease));
735 Memfile_LeaseMgr::addLeaseInternal(
const Lease6Ptr& lease) {
736 if (getLease6Internal(lease->type_, lease->addr_)) {
745 lease_file6_->append(*lease);
748 storage6_.insert(lease);
752 lease->updateCurrentExpirationTime();
762 if (MultiThreadingMgr::instance().getMode()) {
763 std::lock_guard<std::mutex> lock(*mutex_);
764 return (addLeaseInternal(lease));
766 return (addLeaseInternal(lease));
773 Lease4StorageAddressIndex::iterator l = idx.find(addr);
774 if (l == idx.end()) {
786 if (MultiThreadingMgr::instance().getMode()) {
787 std::lock_guard<std::mutex> lock(*mutex_);
788 return (getLease4Internal(addr));
790 return (getLease4Internal(addr));
795 Memfile_LeaseMgr::getLease4Internal(
const HWAddr& hwaddr,
801 std::pair<Lease4StorageHWAddressSubnetIdIndex::const_iterator,
802 Lease4StorageHWAddressSubnetIdIndex::const_iterator> l
803 = idx.equal_range(boost::make_tuple(hwaddr.
hwaddr_));
805 for (
auto lease = l.first; lease != l.second; ++lease) {
816 if (MultiThreadingMgr::instance().getMode()) {
817 std::lock_guard<std::mutex> lock(*mutex_);
818 getLease4Internal(hwaddr, collection);
820 getLease4Internal(hwaddr, collection);
827 Memfile_LeaseMgr::getLease4Internal(
const HWAddr& hwaddr,
833 Lease4StorageHWAddressSubnetIdIndex::const_iterator lease =
834 idx.find(boost::make_tuple(hwaddr.
hwaddr_, subnet_id));
836 if (lease == idx.end()) {
851 if (MultiThreadingMgr::instance().getMode()) {
852 std::lock_guard<std::mutex> lock(*mutex_);
853 return (getLease4Internal(hwaddr, subnet_id));
855 return (getLease4Internal(hwaddr, subnet_id));
860 Memfile_LeaseMgr::getLease4Internal(
const ClientId& client_id,
866 std::pair<Lease4StorageClientIdSubnetIdIndex::const_iterator,
867 Lease4StorageClientIdSubnetIdIndex::const_iterator> l
868 = idx.equal_range(boost::make_tuple(client_id.
getClientId()));
870 for (
auto lease = l.first; lease != l.second; ++lease) {
881 if (MultiThreadingMgr::instance().getMode()) {
882 std::lock_guard<std::mutex> lock(*mutex_);
883 getLease4Internal(client_id, collection);
885 getLease4Internal(client_id, collection);
892 Memfile_LeaseMgr::getLease4Internal(
const ClientId& client_id,
898 Lease4StorageClientIdSubnetIdIndex::const_iterator lease =
899 idx.find(boost::make_tuple(client_id.
getClientId(), subnet_id));
901 if (lease == idx.end()) {
915 if (MultiThreadingMgr::instance().getMode()) {
916 std::lock_guard<std::mutex> lock(*mutex_);
917 return (getLease4Internal(client_id, subnet_id));
919 return (getLease4Internal(client_id, subnet_id));
924 Memfile_LeaseMgr::getLeases4Internal(
SubnetID subnet_id,
927 std::pair<Lease4StorageSubnetIdIndex::const_iterator,
928 Lease4StorageSubnetIdIndex::const_iterator> l =
929 idx.equal_range(subnet_id);
931 for (
auto lease = l.first; lease != l.second; ++lease) {
942 if (MultiThreadingMgr::instance().getMode()) {
943 std::lock_guard<std::mutex> lock(*mutex_);
944 getLeases4Internal(subnet_id, collection);
946 getLeases4Internal(subnet_id, collection);
953 Memfile_LeaseMgr::getLeases4Internal(
const std::string& hostname,
956 std::pair<Lease4StorageHostnameIndex::const_iterator,
957 Lease4StorageHostnameIndex::const_iterator> l =
958 idx.equal_range(hostname);
960 for (
auto lease = l.first; lease != l.second; ++lease) {
971 if (MultiThreadingMgr::instance().getMode()) {
972 std::lock_guard<std::mutex> lock(*mutex_);
973 getLeases4Internal(hostname, collection);
975 getLeases4Internal(hostname, collection);
983 for (
auto lease = storage4_.begin(); lease != storage4_.end(); ++lease) {
993 if (MultiThreadingMgr::instance().getMode()) {
994 std::lock_guard<std::mutex> lock(*mutex_);
995 getLeases4Internal(collection);
997 getLeases4Internal(collection);
1000 return (collection);
1008 Lease4StorageAddressIndex::const_iterator lb = idx.lower_bound(lower_bound_address);
1011 if ((lb != idx.end()) && ((*lb)->addr_ == lower_bound_address)) {
1016 for (
auto lease = lb;
1017 (lease != idx.end()) && (std::distance(lb, lease) < page_size.
page_size_);
1027 if (!lower_bound_address.
isV4()) {
1029 "retrieving leases from the lease database, got " 1030 << lower_bound_address);
1035 .arg(lower_bound_address.
toText());
1038 if (MultiThreadingMgr::instance().getMode()) {
1039 std::lock_guard<std::mutex> lock(*mutex_);
1040 getLeases4Internal(lower_bound_address, page_size, collection);
1042 getLeases4Internal(lower_bound_address, page_size, collection);
1045 return (collection);
1049 Memfile_LeaseMgr::getLease6Internal(
Lease::Type type,
1051 Lease6Storage::iterator l = storage6_.find(addr);
1052 if (l == storage6_.end() || !(*l) || ((*l)->type_ != type)) {
1067 if (MultiThreadingMgr::instance().getMode()) {
1068 std::lock_guard<std::mutex> lock(*mutex_);
1069 return (getLease6Internal(type, addr));
1071 return (getLease6Internal(type, addr));
1076 Memfile_LeaseMgr::getLeases6Internal(
Lease::Type type,
1083 std::pair<Lease6StorageDuidIaidTypeIndex::const_iterator,
1084 Lease6StorageDuidIaidTypeIndex::const_iterator> l =
1085 idx.equal_range(boost::make_tuple(duid.
getDuid(), iaid, type));
1087 for (Lease6StorageDuidIaidTypeIndex::const_iterator lease =
1088 l.first; lease != l.second; ++lease) {
1096 uint32_t iaid)
const {
1104 if (MultiThreadingMgr::instance().getMode()) {
1105 std::lock_guard<std::mutex> lock(*mutex_);
1106 getLeases6Internal(type, duid, iaid, collection);
1108 getLeases6Internal(type, duid, iaid, collection);
1111 return (collection);
1115 Memfile_LeaseMgr::getLeases6Internal(
Lease::Type type,
1123 std::pair<Lease6StorageDuidIaidTypeIndex::const_iterator,
1124 Lease6StorageDuidIaidTypeIndex::const_iterator> l =
1125 idx.equal_range(boost::make_tuple(duid.
getDuid(), iaid, type));
1127 for (Lease6StorageDuidIaidTypeIndex::const_iterator lease =
1128 l.first; lease != l.second; ++lease) {
1130 if ((*lease)->subnet_id_ == subnet_id) {
1149 if (MultiThreadingMgr::instance().getMode()) {
1150 std::lock_guard<std::mutex> lock(*mutex_);
1151 getLeases6Internal(type, duid, iaid, subnet_id, collection);
1153 getLeases6Internal(type, duid, iaid, subnet_id, collection);
1156 return (collection);
1160 Memfile_LeaseMgr::getLeases6Internal(
SubnetID subnet_id,
1163 std::pair<Lease6StorageSubnetIdIndex::const_iterator,
1164 Lease6StorageSubnetIdIndex::const_iterator> l =
1165 idx.equal_range(subnet_id);
1167 for (
auto lease = l.first; lease != l.second; ++lease) {
1178 if (MultiThreadingMgr::instance().getMode()) {
1179 std::lock_guard<std::mutex> lock(*mutex_);
1180 getLeases6Internal(subnet_id, collection);
1182 getLeases6Internal(subnet_id, collection);
1185 return (collection);
1189 Memfile_LeaseMgr::getLeases6Internal(
const std::string& hostname,
1192 std::pair<Lease6StorageHostnameIndex::const_iterator,
1193 Lease6StorageHostnameIndex::const_iterator> l =
1194 idx.equal_range(hostname);
1196 for (
auto lease = l.first; lease != l.second; ++lease) {
1207 if (MultiThreadingMgr::instance().getMode()) {
1208 std::lock_guard<std::mutex> lock(*mutex_);
1209 getLeases6Internal(hostname, collection);
1211 getLeases6Internal(hostname, collection);
1214 return (collection);
1219 for (
auto lease = storage6_.begin(); lease != storage6_.end(); ++lease) {
1229 if (MultiThreadingMgr::instance().getMode()) {
1230 std::lock_guard<std::mutex> lock(*mutex_);
1231 getLeases6Internal(collection);
1233 getLeases6Internal(collection);
1236 return (collection);
1240 Memfile_LeaseMgr::getLeases6Internal(
const DUID& duid,
1243 std::pair<Lease6StorageDuidIndex::const_iterator,
1244 Lease6StorageDuidIndex::const_iterator> l =
1245 idx.equal_range(duid.
getDuid());
1247 for (
auto lease = l.first; lease != l.second; ++lease) {
1258 if (MultiThreadingMgr::instance().getMode()) {
1259 std::lock_guard<std::mutex> lock(*mutex_);
1260 getLeases6Internal(duid, collection);
1262 getLeases6Internal(duid, collection);
1265 return (collection);
1273 Lease6StorageAddressIndex::const_iterator lb = idx.lower_bound(lower_bound_address);
1276 if ((lb != idx.end()) && ((*lb)->addr_ == lower_bound_address)) {
1281 for (
auto lease = lb;
1282 (lease != idx.end()) && (std::distance(lb, lease) < page_size.
page_size_);
1292 if (!lower_bound_address.
isV6()) {
1294 "retrieving leases from the lease database, got " 1295 << lower_bound_address);
1300 .arg(lower_bound_address.
toText());
1303 if (MultiThreadingMgr::instance().getMode()) {
1304 std::lock_guard<std::mutex> lock(*mutex_);
1305 getLeases6Internal(lower_bound_address, page_size, collection);
1307 getLeases6Internal(lower_bound_address, page_size, collection);
1310 return (collection);
1314 Memfile_LeaseMgr::getExpiredLeases4Internal(
Lease4Collection& expired_leases,
1315 const size_t max_leases)
const {
1323 Lease4StorageExpirationIndex::const_iterator ub =
1324 index.upper_bound(boost::make_tuple(
false, time(NULL)));
1327 for (Lease4StorageExpirationIndex::const_iterator lease = index.begin();
1328 (lease != ub) && ((max_leases == 0) || (std::distance(index.begin(), lease) <
1337 const size_t max_leases)
const {
1341 if (MultiThreadingMgr::instance().getMode()) {
1342 std::lock_guard<std::mutex> lock(*mutex_);
1343 getExpiredLeases4Internal(expired_leases, max_leases);
1345 getExpiredLeases4Internal(expired_leases, max_leases);
1350 Memfile_LeaseMgr::getExpiredLeases6Internal(
Lease6Collection& expired_leases,
1351 const size_t max_leases)
const {
1359 Lease6StorageExpirationIndex::const_iterator ub =
1360 index.upper_bound(boost::make_tuple(
false, time(NULL)));
1363 for (Lease6StorageExpirationIndex::const_iterator lease = index.begin();
1364 (lease != ub) && ((max_leases == 0) || (std::distance(index.begin(), lease) <
1373 const size_t max_leases)
const {
1377 if (MultiThreadingMgr::instance().getMode()) {
1378 std::lock_guard<std::mutex> lock(*mutex_);
1379 getExpiredLeases6Internal(expired_leases, max_leases);
1381 getExpiredLeases6Internal(expired_leases, max_leases);
1386 Memfile_LeaseMgr::updateLease4Internal(
const Lease4Ptr& lease) {
1393 Lease4StorageAddressIndex::const_iterator lease_it = index.find(lease->addr_);
1394 if (lease_it == index.end()) {
1396 << lease->addr_ <<
" - no such lease");
1397 }
else if ((!persist) && (((*lease_it)->cltt_ != lease->current_cltt_) ||
1398 ((*lease_it)->valid_lft_ != lease->current_valid_lft_))) {
1402 << lease->addr_ <<
" - lease has changed in database");
1409 lease_file4_->append(*lease);
1413 lease->updateCurrentExpirationTime();
1424 if (MultiThreadingMgr::instance().getMode()) {
1425 std::lock_guard<std::mutex> lock(*mutex_);
1426 updateLease4Internal(lease);
1428 updateLease4Internal(lease);
1433 Memfile_LeaseMgr::updateLease6Internal(
const Lease6Ptr& lease) {
1440 Lease6StorageAddressIndex::const_iterator lease_it = index.find(lease->addr_);
1441 if (lease_it == index.end()) {
1443 << lease->addr_ <<
" - no such lease");
1444 }
else if ((!persist) && (((*lease_it)->cltt_ != lease->current_cltt_) ||
1445 ((*lease_it)->valid_lft_ != lease->current_valid_lft_))) {
1449 << lease->addr_ <<
" - lease has changed in database");
1456 lease_file6_->append(*lease);
1460 lease->updateCurrentExpirationTime();
1471 if (MultiThreadingMgr::instance().getMode()) {
1472 std::lock_guard<std::mutex> lock(*mutex_);
1473 updateLease6Internal(lease);
1475 updateLease6Internal(lease);
1480 Memfile_LeaseMgr::deleteLeaseInternal(
const Lease4Ptr& lease) {
1482 Lease4Storage::iterator l = storage4_.find(addr);
1483 if (l == storage4_.end()) {
1494 lease_file4_->append(lease_copy);
1498 if (((*l)->cltt_ != lease->current_cltt_) ||
1499 ((*l)->valid_lft_ != lease->current_valid_lft_)) {
1513 if (MultiThreadingMgr::instance().getMode()) {
1514 std::lock_guard<std::mutex> lock(*mutex_);
1515 return (deleteLeaseInternal(lease));
1517 return (deleteLeaseInternal(lease));
1522 Memfile_LeaseMgr::deleteLeaseInternal(
const Lease6Ptr& lease) {
1524 Lease6Storage::iterator l = storage6_.find(addr);
1525 if (l == storage6_.end()) {
1536 lease_file6_->append(lease_copy);
1540 if (((*l)->cltt_ != lease->current_cltt_) ||
1541 ((*l)->valid_lft_ != lease->current_valid_lft_)) {
1555 if (MultiThreadingMgr::instance().getMode()) {
1556 std::lock_guard<std::mutex> lock(*mutex_);
1557 return (deleteLeaseInternal(lease));
1559 return (deleteLeaseInternal(lease));
1569 if (MultiThreadingMgr::instance().getMode()) {
1570 std::lock_guard<std::mutex> lock(*mutex_);
1571 return (deleteExpiredReclaimedLeases<
1573 >(secs,
V4, storage4_, lease_file4_));
1575 return (deleteExpiredReclaimedLeases<
1577 >(secs,
V4, storage4_, lease_file4_));
1587 if (MultiThreadingMgr::instance().getMode()) {
1588 std::lock_guard<std::mutex> lock(*mutex_);
1589 return (deleteExpiredReclaimedLeases<
1591 >(secs,
V6, storage6_, lease_file6_));
1593 return (deleteExpiredReclaimedLeases<
1595 >(secs,
V6, storage6_, lease_file6_));
1599 template<
typename IndexType,
typename LeaseType,
typename StorageType,
1600 typename LeaseFileType>
1602 Memfile_LeaseMgr::deleteExpiredReclaimedLeases(
const uint32_t secs,
1604 StorageType& storage,
1605 LeaseFileType& lease_file)
const {
1607 IndexType& index = storage.template get<ExpirationIndexTag>();
1618 typename IndexType::const_iterator upper_limit =
1619 index.upper_bound(boost::make_tuple(
true, time(NULL) - secs));
1628 typename IndexType::const_iterator lower_limit =
1629 index.upper_bound(boost::make_tuple(
true, std::numeric_limits<int64_t>::min()));
1632 uint64_t num_leases =
static_cast<uint64_t
>(std::distance(lower_limit, upper_limit));
1633 if (num_leases > 0) {
1643 for (
typename IndexType::const_iterator lease = lower_limit;
1644 lease != upper_limit; ++lease) {
1646 LeaseType lease_copy(**lease);
1649 lease_copy.valid_lft_ = 0;
1650 lease_file->append(lease_copy);
1655 index.erase(lower_limit, upper_limit);
1658 return (num_leases);
1664 return (std::string(
"In memory database with leases stored in a CSV file."));
1667 std::pair<uint32_t, uint32_t>
1669 std::string
const& universe(conn_.
getParameter(
"universe"));
1670 if (universe ==
"4") {
1672 }
else if (universe ==
"6") {
1692 std::string name(file_name);
1693 switch (file_type) {
1704 name +=
".completed";
1719 std::ostringstream s;
1721 s << (u ==
V4 ?
"4" :
"6");
1729 return (lease_file4_ ? lease_file4_->getFilename() :
"");
1732 return (lease_file6_ ? lease_file6_->getFilename() :
"");
1740 if (u ==
V4 && lease_file4_) {
1744 return (u ==
V6 && lease_file6_);
1748 Memfile_LeaseMgr::initLeaseFilePath(
Universe u) {
1749 std::string persist_val;
1755 persist_val =
"true";
1759 if (persist_val ==
"false") {
1762 }
else if (persist_val !=
"true") {
1764 << persist_val <<
"'");
1767 std::string lease_file;
1773 return (lease_file);
1776 template<
typename LeaseObjectType,
typename LeaseFileType,
typename StorageType>
1778 Memfile_LeaseMgr::loadLeasesFromFiles(
const std::string& filename,
1779 boost::shared_ptr<LeaseFileType>& lease_file,
1780 StorageType& storage) {
1788 if (pid_file.
check()) {
1790 "lease file cleanup is in progress");
1795 std::string max_row_errors_str =
"0";
1797 max_row_errors_str = conn_.
getParameter(
"max-row-errors");
1798 }
catch (
const std::exception&) {
1802 uint32_t max_row_errors = 0;
1804 max_row_errors = boost::lexical_cast<uint32_t>(max_row_errors_str);
1805 }
catch (
const boost::bad_lexical_cast&) {
1807 << max_row_errors_str <<
" specified");
1811 bool conversion_needed =
false;
1812 lease_file.reset(
new LeaseFileType(std::string(filename +
".completed")));
1813 if (lease_file->exists()) {
1814 LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
1816 conversion_needed = conversion_needed || lease_file->needsConversion();
1821 if (lease_file->exists()) {
1822 LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
1824 conversion_needed = conversion_needed || lease_file->needsConversion();
1828 if (lease_file->exists()) {
1829 LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
1831 conversion_needed = conversion_needed || lease_file->needsConversion();
1841 lease_file.reset(
new LeaseFileType(filename));
1842 LeaseFileLoader::load<LeaseObjectType>(*lease_file, storage,
1843 max_row_errors,
false);
1844 conversion_needed = conversion_needed || lease_file->needsConversion();
1846 return (conversion_needed);
1852 return (lfc_setup_->isRunning());
1857 return (lfc_setup_->getExitStatus());
1867 lfcExecute(lease_file4_);
1868 }
else if (lease_file6_) {
1870 lfcExecute(lease_file6_);
1875 Memfile_LeaseMgr::lfcSetup(
bool conversion_needed) {
1876 std::string lfc_interval_str =
"3600";
1879 }
catch (
const std::exception&) {
1883 uint32_t lfc_interval = 0;
1885 lfc_interval = boost::lexical_cast<uint32_t>(lfc_interval_str);
1886 }
catch (
const boost::bad_lexical_cast&) {
1888 << lfc_interval_str <<
" specified");
1891 if (lfc_interval > 0 || conversion_needed) {
1893 lfc_setup_->setup(lfc_interval, lease_file4_, lease_file6_, conversion_needed);
1897 template<
typename LeaseFileType>
1899 Memfile_LeaseMgr::lfcExecute(boost::shared_ptr<LeaseFileType>& lease_file) {
1909 if (!lease_file_finish.
exists() && !lease_file_copy.
exists()) {
1911 lease_file->close();
1914 do_lfc = (rename(lease_file->getFilename().c_str(),
1919 .arg(lease_file->getFilename())
1921 .arg(strerror(errno));
1930 lease_file->open(
true);
1943 .arg(lease_file->getFilename())
1954 lfc_setup_->execute();
2013 std::pair<Lease4StorageSubnetIdIndex::const_iterator,
2014 Lease4StorageSubnetIdIndex::const_iterator> l =
2015 idx.equal_range(subnet_id);
2019 for (
auto lease = l.first; lease != l.second; ++lease) {
2020 leases.push_back(*lease);
2023 size_t num = leases.size();
2024 for (
auto l = leases.begin(); l != leases.end(); ++l) {
2028 .arg(subnet_id).arg(num);
2042 std::pair<Lease6StorageSubnetIdIndex::const_iterator,
2043 Lease6StorageSubnetIdIndex::const_iterator> l =
2044 idx.equal_range(subnet_id);
2048 for (
auto lease = l.first; lease != l.second; ++lease) {
2049 leases.push_back(*lease);
2052 size_t num = leases.size();
2053 for (
auto l = leases.begin(); l != leases.end(); ++l) {
2057 .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.
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
bool exists() const
Checks if the CSV file exists and can be opened for reading.
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.
boost::shared_ptr< LeaseStatsQuery > LeaseStatsQueryPtr
Defines a pointer to a LeaseStatsQuery.
util::Optional< std::string > getDataDir() const
returns path do the data directory
A generic exception that is thrown when a function is not implemented.
const isc::log::MessageID DHCPSRV_MEMFILE_UPDATE_ADDR6
const std::vector< uint8_t > & getClientId() const
Returns reference to the client-id data.
Structure that holds a lease for IPv4 address.
const isc::log::MessageID DHCPSRV_MEMFILE_WIPE_LEASES4
virtual std::string getDescription() const
Returns description of the backend.
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.
int getExitStatus() const
Returns exit code of the last completed cleanup.
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_START
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.
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
uint32_t preferred_lft_
Preferred lifetime.
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)
#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_
bool isRunning() const
Checks if the lease file cleanup is in progress.
const isc::log::MessageID DHCPSRV_MEMFILE_CONVERTING_LEASE_FILES
Lease4Storage::index< HWAddressSubnetIdIndexTag >::type Lease4StorageHWAddressSubnetIdIndex
DHCPv4 lease storage index by HW address and subnet identifier.
Base class for fulfilling a statistical lease data query.
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_SETUP
std::string getFilename() const
Returns the path to the CSV file.
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.
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
virtual Lease6Collection getLeases6() const
Returns all IPv6 leases.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
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.
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_ADD_ADDR6
virtual std::pair< uint32_t, uint32_t > getVersion() const
Returns backend version.
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.
static std::string getDBVersion()
Class method to return extended version info This class method must be redeclared and redefined in de...
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.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_IAID_DUID
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.
bool isLFCRunning() const
Checks if the process performing lease file cleanup is running.
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.
static const int MINOR_VERSION_V4
the minor version of the v4 memfile backend
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_EXECUTE
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.
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 void getExpiredLeases6(Lease6Collection &expired_leases, const size_t max_leases) const
Returns a collection of expired DHCPv6 leases.
boost::shared_ptr< const Element > ConstElementPtr
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.
int version()
returns Kea hooks version.
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
std::string getParameter(const std::string &name) const
Returns value of a connection parameter.
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
bool isJsonSupported() const override
Checks if JSON support is enabled in the database.
Tag for index using DUID.
bool isV6() const
Convenience function to check for an IPv6 address.
MemfileLeaseStatsQuery()
Constructor for all subnets query.
MemfileLeaseStatsQuery4(Lease4Storage &storage4, const SubnetID &first_subnet_id, const SubnetID &last_subnet_id)
Constructor for a subnet range query.
bool isV4() const
Convenience function to check for an IPv4 address.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_EXPIRED6
Tag for indexes by HW address, subnet identifier tuple.
const std::vector< uint8_t > & getDuid() const
Returns a const reference to the actual DUID value.
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
Invalid address family used as input to Lease Manager.
virtual LeaseStatsQueryPtr startLeaseStatsQuery4()
Creates and runs the IPv4 lease stats query.
std::string getLeaseFilePath(Universe u) const
Returns an absolute path to the lease file.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
bool persistLeases(Universe u) const
Specifies whether or not leases are written to disk.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_ADDR6
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_LEASE_FILE_RENAME_FAIL
std::string toText() const
Convert the address to a string.
virtual void updateLease4(const Lease4Ptr &lease4)
Updates IPv4 lease.
const isc::log::MessageID DHCPSRV_MEMFILE_DELETE_EXPIRED_RECLAIMED_START
virtual void getExpiredLeases4(Lease4Collection &expired_leases, const size_t max_leases) const
Returns a collection of expired DHCPv4 leases.
Tag for indexes by address.
const isc::log::MessageID DHCPSRV_MEMFILE_COMMIT
std::string getDefaultLeaseFilePath(Universe u) const
Returns default path to the lease file.
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.
static const int MAJOR_VERSION_V4
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.
virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs)
Deletes all expired-reclaimed DHCPv6 leases.
const isc::log::MessageID DHCPSRV_MEMFILE_LFC_SPAWN_FAIL
static const int MAJOR_VERSION_V6
Hardware type that represents information from DHCPv4 packet.
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
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
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::string toText() const
Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
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
uint32_t valid_lft_
Valid lifetime.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Tag for indexes by subnet-id.
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.
int getLFCExitStatus() const
Returns the status code returned by the last executed LFC process.
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.
static const int MINOR_VERSION_V6
the minor version of the v6 memfile backend
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.
virtual Lease4Collection getLeases4() const
Returns all IPv4 leases.
const isc::log::MessageID DHCPSRV_MEMFILE_GET_SUBID_CLIENTID
MemfileLeaseStatsQuery4(Lease4Storage &storage4)
Constructor for an all subnets query.
virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress &addr) const
Returns existing IPv4 lease for specified IPv4 address.
int getRowCount() const
Returns the number of rows in the result set.
std::string toText() const
Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
std::string toText(bool include_htype=true) const
Returns textual representation of a hardware address (e.g.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Lease6Storage::index< SubnetIdIndexTag >::type Lease6StorageSubnetIdIndex
DHCPv6 lease storage index by Subnet-id.
virtual bool addLease(const Lease4Ptr &lease)
Adds an IPv4 lease.
Exception thrown when an error occurs during CSV file processing.
Utility class for spawning new processes.
int check() const
Read the PID in from the file and check it.