34#include <boost/scoped_ptr.hpp>
35#include <boost/algorithm/string.hpp>
95 if (txt ==
"address") {
97 }
else if (txt ==
"hw-address") {
99 }
else if (txt ==
"duid") {
101 }
else if (txt ==
"client-id") {
105 << txt <<
", the only supported values are: "
106 "address, hw-address, duid");
392 const int control_result,
393 const std::string& error_message)
const;
406 short family = AF_INET)
const;
468 if (!user_context || (user_context->getType() !=
Element::map)) {
475 return (
isc->get(
"relay-info"));
525 if (!lease->stateExpiredReclaimed()) {
530 "assigned-addresses"),
531 static_cast<int64_t
>(1));
541 "assigned-addresses")),
542 static_cast<int64_t
>(1));
546 if (lease->stateDeclined()) {
551 "declined-addresses"),
552 static_cast<int64_t
>(1));
558 "declined-addresses")),
559 static_cast<int64_t
>(1));
567 if (lease->stateRegistered()) {
570 static_cast<int64_t
>(1));
571 }
else if (!lease->stateExpiredReclaimed()) {
573 "assigned-nas" :
"assigned-pds",
574 static_cast<int64_t
>(1));
579 "assigned-nas" :
"assigned-pds"),
580 static_cast<int64_t
>(1));
585 pool = subnet->getPool(lease->type_, lease->addr_,
false);
590 "pool" :
"pd-pool", pool->getID(),
592 "assigned-nas" :
"assigned-pds")),
593 static_cast<int64_t
>(1));
597 if (lease->stateDeclined()) {
602 "declined-addresses"),
603 static_cast<int64_t
>(1));
609 "declined-addresses")),
610 static_cast<int64_t
>(1));
619 if (!existing->stateExpiredReclaimed()) {
624 if (existing->subnet_id_ != lease->subnet_id_) {
627 "assigned-addresses"),
628 static_cast<int64_t
>(-1));
637 "assigned-addresses")),
638 static_cast<int64_t
>(-1));
643 if (existing->stateDeclined()) {
649 "declined-addresses"),
650 static_cast<int64_t
>(-1));
656 "declined-addresses")),
657 static_cast<int64_t
>(-1));
663 if (!lease->stateExpiredReclaimed()) {
665 if (existing->subnet_id_ != lease->subnet_id_) {
668 "assigned-addresses"),
669 static_cast<int64_t
>(1));
678 "assigned-addresses")),
679 static_cast<int64_t
>(1));
684 if (lease->stateDeclined()) {
690 "declined-addresses"),
691 static_cast<int64_t
>(1));
697 "declined-addresses")),
698 static_cast<int64_t
>(1));
704 if (!lease->stateExpiredReclaimed()) {
710 "assigned-addresses"),
711 static_cast<int64_t
>(1));
721 "assigned-addresses")),
722 static_cast<int64_t
>(1));
726 if (lease->stateDeclined()) {
732 "declined-addresses"),
733 static_cast<int64_t
>(1));
739 "declined-addresses")),
740 static_cast<int64_t
>(1));
751 if (existing->stateRegistered()) {
752 if (existing->subnet_id_ != lease->subnet_id_) {
756 static_cast<int64_t
>(-1));
760 static_cast<int64_t
>(1));
762 }
else if (!existing->stateExpiredReclaimed()) {
767 if (existing->subnet_id_ != lease->subnet_id_) {
771 "assigned-nas" :
"assigned-pds"),
772 static_cast<int64_t
>(-1));
776 pool = subnet->getPool(existing->type_, existing->addr_,
false);
781 "pool" :
"pd-pool", pool->getID(),
783 "assigned-nas" :
"assigned-pds")),
784 static_cast<int64_t
>(-1));
789 if (existing->stateDeclined()) {
795 "declined-addresses"),
796 static_cast<int64_t
>(-1));
802 "declined-addresses")),
803 static_cast<int64_t
>(-1));
809 if (!lease->stateExpiredReclaimed()) {
811 if (existing->subnet_id_ != lease->subnet_id_) {
815 "assigned-nas" :
"assigned-pds"),
816 static_cast<int64_t
>(1));
820 pool = subnet->getPool(lease->type_, lease->addr_,
false);
825 "pool" :
"pd-pool", pool->getID(),
827 "assigned-nas" :
"assigned-pds")),
828 static_cast<int64_t
>(1));
833 if (lease->stateDeclined()) {
839 "declined-addresses"),
840 static_cast<int64_t
>(1));
846 "declined-addresses")),
847 static_cast<int64_t
>(1));
853 if (!lease->stateExpiredReclaimed()) {
856 "assigned-nas" :
"assigned-pds",
857 static_cast<int64_t
>(1));
862 "assigned-nas" :
"assigned-pds"),
863 static_cast<int64_t
>(1));
868 pool = subnet->getPool(lease->type_, lease->addr_,
false);
873 "pool" :
"pd-pool", pool->getID(),
875 "assigned-nas" :
"assigned-pds")),
876 static_cast<int64_t
>(1));
880 if (lease->stateDeclined()) {
886 "declined-addresses"),
887 static_cast<int64_t
>(1));
893 "declined-addresses")),
894 static_cast<int64_t
>(1));
903 if (!lease->stateExpiredReclaimed()) {
908 "assigned-addresses"),
909 static_cast<int64_t
>(-1));
919 "assigned-addresses")),
920 static_cast<int64_t
>(-1));
924 if (lease->stateDeclined()) {
929 "declined-addresses"),
930 static_cast<int64_t
>(-1));
936 "declined-addresses")),
937 static_cast<int64_t
>(-1));
945 if (lease->stateRegistered()) {
949 static_cast<int64_t
>(-1));
950 }
else if (!lease->stateExpiredReclaimed()) {
952 "assigned-nas" :
"assigned-pds",
953 static_cast<int64_t
>(-1));
958 "assigned-nas" :
"assigned-pds"),
959 static_cast<int64_t
>(-1));
964 pool = subnet->getPool(lease->type_, lease->addr_,
false);
969 "pool" :
"pd-pool", pool->getID(),
971 "assigned-nas" :
"assigned-pds")),
972 static_cast<int64_t
>(-1));
976 if (lease->stateDeclined()) {
981 "declined-addresses"),
982 static_cast<int64_t
>(-1));
988 "declined-addresses")),
989 static_cast<int64_t
>(-1));
998 if (force_create && !existing) {
1002 "lost race between calls to get and add");
1017 << lease->addr_ <<
" either because the lease has been "
1018 "deleted or it has changed in the database, in both cases a "
1019 "retry might succeed");
1030 if (force_create && !existing) {
1034 "lost race between calls to get and add");
1041 if (existing->stateRegistered() && !lease->stateRegistered()) {
1044 }
else if (!existing->stateRegistered() && lease->stateRegistered()) {
1046 <<
" can't be registered");
1057 if ((!old_extended_info && !extended_info) ||
1058 (old_extended_info && extended_info &&
1059 (*old_extended_info == *extended_info))) {
1069 << lease->addr_ <<
" either because the lease has been "
1070 "deleted or it has changed in the database, in both cases a "
1071 "retry might succeed");
1084 string lease_address =
"unknown";
1095 bool force_create =
false;
1102 lease_address = lease4->addr_.toText();
1110 if (resource_handler.
tryLock4(lease4->addr_)) {
1114 "ResourceBusy: IP address:" << lease4->addr_
1115 <<
" could not be added.");
1124 resp <<
"Lease for address " << lease4->addr_.toText()
1125 <<
", subnet-id " << lease4->subnet_id_ <<
" added.";
1131 lease_address = lease6->addr_.toText();
1139 if (resource_handler.
tryLock(lease6->type_, lease6->addr_)) {
1143 "ResourceBusy: IP address:" << lease6->addr_
1144 <<
" could not be added.");
1154 resp <<
"Lease for address " << lease6->addr_.toText()
1155 <<
", subnet-id " << lease6->subnet_id_ <<
" added.";
1157 resp <<
"Lease for prefix " << lease6->addr_.toText()
1158 <<
"/" <<
static_cast<int>(lease6->prefixlen_)
1159 <<
", subnet-id " << lease6->subnet_id_ <<
" added.";
1170 }
catch (
const std::exception& ex) {
1180 .arg(lease_address);
1193 if (params->contains(
"update-ddns")) {
1206 if (params->contains(
"type")) {
1207 string t = params->get(
"type")->stringValue();
1208 if (t ==
"IA_NA" || t ==
"0") {
1210 }
else if (t ==
"IA_TA" || t ==
"1") {
1212 }
else if (t ==
"IA_PD" || t ==
"2") {
1214 }
else if (t ==
"V4" || t ==
"3") {
1218 << t <<
", only supported values are: IA_NA, IA_TA,"
1219 <<
" IA_PD and V4");
1233 txt <<
"Invalid " << (v6 ?
"IPv6" :
"IPv4")
1234 <<
" address specified: " << tmp->stringValue();
1242 tmp = params->get(
"subnet-id");
1251 if (params->contains(
"iaid")) {
1252 x.
iaid = params->get(
"iaid")->intValue();
1263 " and 'identifier-type' is either missing or not a string.");
1267 " and 'identifier' is either missing or not a string.");
1296 " is not supported.");
1327 "requires hwaddr to be specified");
1340 "requires duid to be specified");
1354 "requires client-id to be specified");
1368 }
catch (
const std::exception& ex) {
1378 lease_json = lease4->toElement();
1380 "IPv4 lease found.", lease_json);
1382 }
else if (!v4 && lease6) {
1383 lease_json = lease6->toElement();
1385 "IPv6 lease found.", lease_json);
1415 const std::vector<ElementPtr>& subnet_ids = subnets->listValue();
1416 for (
auto const& subnet_id : subnet_ids) {
1424 for (
auto const& lease : leases) {
1426 leases_json->add(lease_json);
1431 for (
auto const& lease : leases) {
1433 leases_json->add(lease_json);
1442 for (
auto const& lease : leases) {
1444 leases_json->add(lease_json);
1448 for (
auto const& lease : leases) {
1450 leases_json->add(lease_json);
1455 std::ostringstream s;
1456 s << leases_json->size()
1457 <<
" IPv" << (v4 ?
"4" :
"6")
1458 <<
" lease(s) found.";
1460 args->set(
"leases", leases_json);
1468 }
catch (
const std::exception& ex) {
1502 boost::scoped_ptr<IOAddress> from_address;
1504 if (from->stringValue() ==
"start") {
1505 from_address.reset(
new IOAddress(v4 ?
"0.0.0.0" :
"::"));
1509 from_address.reset(
new IOAddress(from->stringValue()));
1514 "a valid IPv" << (v4 ?
"4" :
"6") <<
" address");
1519 if (v4 && (!from_address->isV4())) {
1521 <<
" is not an IPv4 address");
1523 }
else if (!v4 && from_address->isV4()) {
1525 <<
" is not an IPv6 address");
1540 size_t page_limit_value =
static_cast<size_t>(page_limit->intValue());
1551 for (
auto const& lease : leases) {
1553 leases_json->add(lease_json);
1562 for (
auto const& lease : leases) {
1564 leases_json->add(lease_json);
1569 std::ostringstream s;
1570 s << leases_json->size()
1571 <<
" IPv" << (v4 ?
"4" :
"6")
1572 <<
" lease(s) found.";
1576 args->set(
"leases", leases_json);
1577 args->set(
"count",
Element::create(
static_cast<int64_t
>(leases_json->size())));
1587 }
catch (
const std::exception& ex) {
1600 v4 = (
cmd_name_ ==
"lease4-get-by-hw-address");
1618 if (hw_address->stringValue().empty()) {
1629 for (
auto const& lease : leases) {
1631 leases_json->add(lease_json);
1636 for (
auto const& lease : leases) {
1638 leases_json->add(lease_json);
1642 std::ostringstream s;
1643 s << leases_json->size()
1644 <<
" IPv" << (v4 ?
"4" :
"6")
1645 <<
" lease(s) found.";
1647 args->set(
"leases", leases_json);
1655 }
catch (
const std::exception& ex) {
1689 for (
auto const& lease : leases) {
1691 leases_json->add(lease_json);
1694 std::ostringstream s;
1695 s << leases_json->size() <<
" IPv4 lease(s) found.";
1697 args->set(
"leases", leases_json);
1705 }
catch (
const std::exception& ex) {
1739 for (
auto const& lease : leases) {
1741 leases_json->add(lease_json);
1744 std::ostringstream s;
1745 s << leases_json->size() <<
" IPv6 lease(s) found.";
1747 args->set(
"leases", leases_json);
1755 }
catch (
const std::exception& ex) {
1768 v4 = (
cmd_name_ ==
"lease4-get-by-hostname");
1786 std::string hostname_ = hostname->stringValue();
1788 if (hostname_.empty()) {
1791 boost::algorithm::to_lower(hostname_);
1798 for (
auto const& lease : leases) {
1800 leases_json->add(lease_json);
1806 for (
auto const& lease : leases) {
1808 leases_json->add(lease_json);
1812 std::ostringstream s;
1813 s << leases_json->size()
1814 <<
" IPv" << (v4 ?
"4" :
"6")
1815 <<
" lease(s) found.";
1817 args->set(
"leases", leases_json);
1825 }
catch (
const std::exception& ex) {
1853 "requires hwaddr to be specified");
1867 "requires client-id to be specified");
1900 }
catch (
const std::exception& ex) {
1908 .arg(lease4->addr_.toText());
1923 auto deleted_leases =
cmd_args_->get(
"deleted-leases");
1926 if (!deleted_leases && !leases) {
1932 if (deleted_leases && (deleted_leases->getType() !=
Element::list)) {
1944 std::list<std::pair<Parameters, Lease6Ptr> > parsed_deleted_list;
1945 if (deleted_leases) {
1946 auto leases_list = deleted_leases->listValue();
1949 for (
auto const& lease_params : leases_list) {
1954 parsed_deleted_list.push_back(std::make_pair(p, lease));
1960 std::list<Lease6Ptr> parsed_leases_list;
1965 auto leases_list = leases->listValue();
1966 for (
auto const& lease_params : leases_list) {
1974 parsed_leases_list.push_back(lease6);
1979 size_t success_count = 0;
1982 if (!parsed_deleted_list.empty()) {
1985 for (
auto const& lease_params_pair : parsed_deleted_list) {
1990 auto lease = lease_params_pair.second;
2003 if (!failed_deleted_list) {
2014 "lease not found"));
2018 }
catch (
const std::exception& ex) {
2020 if (!failed_deleted_list) {
2033 if (!parsed_leases_list.empty()) {
2037 for (
auto const& lease : parsed_leases_list) {
2040 std::ostringstream text;
2048 if (resource_handler.
tryLock(lease->type_, lease->addr_)) {
2052 "ResourceBusy: IP address:" << lease->addr_
2053 <<
" could not be updated.");
2062 }
catch (
const std::exception& ex) {
2069 if (!failed_leases_list) {
2084 if (failed_deleted_list || failed_leases_list) {
2089 if (failed_deleted_list) {
2090 args->set(
"failed-deleted-leases", failed_deleted_list);
2094 if (failed_leases_list) {
2095 args->set(
"failed-leases", failed_leases_list);
2100 std::ostringstream resp_text;
2101 resp_text <<
"Bulk apply of " << success_count <<
" IPv6 leases completed.";
2108 .arg(success_count);
2110 }
catch (
const std::exception& ex) {
2150 "requires duid to be specified");
2180 }
catch (
const std::exception& ex) {
2189 .arg(lease6->addr_.toText());
2207 bool force_create =
false;
2219 if (resource_handler.
tryLock4(lease4->addr_)) {
2223 "ResourceBusy: IP address:" << lease4->addr_
2224 <<
" could not be updated.");
2235 .arg(lease4->addr_.toText());
2244 }
catch (
const std::exception& ex) {
2269 bool force_create =
false;
2281 if (resource_handler.
tryLock(lease6->type_, lease6->addr_)) {
2285 "ResourceBusy: IP address:" << lease6->addr_
2286 <<
" could not be updated.");
2297 .arg(lease6->addr_.toText());
2306 }
catch (
const std::exception& ex) {
2341 int64_t previous_assigned = 0;
2343 if (assigned_observation) {
2344 previous_assigned = assigned_observation->getInteger().first;
2350 int64_t previous_declined = 0;
2352 if (declined_observation) {
2353 previous_declined = declined_observation->getInteger().first;
2358 static_cast<int64_t
>(0));
2362 static_cast<int64_t
>(0));
2369 "assigned-addresses")));
2376 "declined-addresses")));
2393 for (
auto const& sub : *subs) {
2395 ids <<
" " << sub->getID();
2398 static_cast<int64_t
>(0));
2402 static_cast<int64_t
>(0));
2407 "assigned-addresses")));
2414 "declined-addresses")));
2427 tmp <<
"Deleted " << num <<
" IPv4 lease(s) from subnet(s)" << ids.str();
2431 }
catch (
const std::exception& ex) {
2473 int64_t previous_assigned_na = 0;
2475 if (assigned_na_observation) {
2476 previous_assigned_na = assigned_na_observation->getInteger().first;
2482 int64_t previous_assigned_pd = 0;
2484 if (assigned_pd_observation) {
2485 previous_assigned_pd = assigned_pd_observation->getInteger().first;
2491 int64_t previous_declined = 0;
2493 if (declined_observation) {
2494 previous_declined = declined_observation->getInteger().first;
2499 static_cast<int64_t
>(0));
2503 static_cast<int64_t
>(0));
2507 static_cast<int64_t
>(0));
2511 static_cast<int64_t
>(0));
2525 "declined-addresses")));
2553 for (
auto const& sub : *subs) {
2555 ids <<
" " << sub->getID();
2558 static_cast<int64_t
>(0));
2562 static_cast<int64_t
>(0));
2566 static_cast<int64_t
>(0));
2570 static_cast<int64_t
>(0));
2582 "declined-addresses")));
2606 tmp <<
"Deleted " << num <<
" IPv6 lease(s) from subnet(s)" << ids.str();
2610 }
catch (
const std::exception& ex) {
2635 lease6.reset(
new Lease6());
2636 lease6->addr_ = parameters.
addr;
2645 if (!parameters.
duid) {
2647 "requires duid to be specified");
2667 short family)
const {
2680 }
catch (
const std::exception& ex) {
2682 <<
"' is not a valid IP address.");
2687 << (family == AF_INET6 ?
"IPv6" :
"IPv4")
2688 <<
" address specified: " << param->stringValue());
2696 std::stringstream ss;
2706 ss <<
"DDNS updating is not enabled";
2712 ss <<
"No lease found for: " << addr.
toText();
2714 }
else if (lease->hostname_.empty()) {
2715 ss <<
"Lease for: " << addr.
toText()
2716 <<
", has no hostname, nothing to update";
2718 }
else if (!lease->fqdn_fwd_ && !lease->fqdn_rev_) {
2719 ss <<
"Neither forward nor reverse updates enabled for lease for: "
2726 ss <<
"NCR generated for: " << addr.
toText()
2727 <<
", hostname: " << lease->hostname_;
2733 }
catch (
const std::exception& ex) {
2744 std::stringstream ss;
2754 ss <<
"DDNS updating is not enabled";
2760 ss <<
"No lease found for: " << addr.
toText();
2762 }
else if (lease->hostname_.empty()) {
2763 ss <<
"Lease for: " << addr.
toText()
2764 <<
", has no hostname, nothing to update";
2766 }
else if (!lease->fqdn_fwd_ && !lease->fqdn_rev_) {
2767 ss <<
"Neither forward nor reverse updates enabled for lease for: "
2774 ss <<
"NCR generated for: " << addr.
toText()
2775 <<
", hostname: " << lease->hostname_;
2781 }
catch (
const std::exception& ex) {
2794 const int control_result,
2795 const std::string& error_message)
const {
2808 failed_lease_map->set(
"error-message",
Element::create(error_message));
2810 return (failed_lease_map);
2832 std::string filename;
2838 filename =
file->stringValue();
2839 }
catch (
const std::exception& ex) {
2850 s << (v4 ?
"IPv4" :
"IPv6")
2851 <<
" lease database into '"
2852 << filename <<
"'.";
2855 }
catch (
const std::exception& ex) {
2866 uint32_t offer_lifetime;
2867 callout_handle.
getArgument(
"offer_lifetime", offer_lifetime);
2868 if (!offer_lifetime) {
2879 callout_handle.
getArgument(
"response4", response);
2882 if (!leases || leases->empty() || !((*leases)[0])) {
2888 if (mgr->evaluateVariables(query, response, lease)) {
2893 " the lease with address " << lease->addr_ <<
2894 " either because the lease has been"
2895 " deleted or it has changed in the database");
2896 }
catch (
const std::exception& ex) {
2898 << query->getLabel() <<
", :" << ex.what());
2911 callout_handle.
getArgument(
"response4", response);
2920 if (leases->empty() || !response || (response->getType() !=
DHCPACK)) {
2930 if (mgr->evaluateVariables(query, response, lease)) {
2935 " the lease with address " << lease->addr_ <<
2936 " either because the lease has been"
2937 " deleted or it has changed in the database");
2938 }
catch (
const std::exception& ex) {
2940 << query->getLabel() <<
", :" << ex.what());
2953 callout_handle.
getArgument(
"response6", response);
2961 if (leases->empty() || !response) {
2967 for (
auto lease : *leases) {
2979 if (lease->valid_lft_) {
2981 if (mgr->evaluateVariables(query, response, lease)) {
2988 .arg(lease->addr_.toText())
2989 .arg(query->getLabel());
2990 }
catch (
const std::exception& ex) {
2993 .arg(query->getLabel())
2994 .arg(lease->addr_.toText())
3001 <<
" leases failed to update for "
3002 << query->getLabel());
3008 return (impl_->leaseAddHandler(handle));
3013 return (impl_->lease6BulkApplyHandler(handle));
3018 return (impl_->leaseGetHandler(handle));
3023 return (impl_->leaseGetAllHandler(handle));
3028 return (impl_->leaseGetPageHandler(handle));
3033 return (impl_->leaseGetByHwAddressHandler(handle));
3038 return (impl_->leaseGetByClientIdHandler(handle));
3043 return (impl_->leaseGetByDuidHandler(handle));
3048 return (impl_->leaseGetByHostnameHandler(handle));
3053 return (impl_->lease4DelHandler(handle));
3058 return (impl_->lease6DelHandler(handle));
3063 return (impl_->lease4UpdateHandler(handle));
3068 return (impl_->lease6UpdateHandler(handle));
3074 return (impl_->lease4WipeHandler(handle));
3080 return (impl_->lease6WipeHandler(handle));
3085 return (impl_->lease4ResendDdnsHandler(handle));
3090 return (impl_->lease6ResendDdnsHandler(handle));
3095 return (impl_->leaseWriteHandler(handle));
3105 impl_->lease4Offer(callout_handle, mgr);
3111 impl_->leases4Committed(callout_handle, mgr);
3117 impl_->leases6Committed(callout_handle, mgr);
static DUID fromText(const std::string &text)
Create DUID from the textual format.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Exception thrown when a command failed due to a conflict.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown if a function is called in a prohibited way.
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
std::string toText() const
Convert the address to a string.
bool isV6() const
Convenience function to check for an IPv6 address.
bool isV4() const
Convenience function to check for an IPv4 address.
bool isV6Zero() const
Convenience function to check if it is an IPv4 zero address.
short getFamily() const
Returns the address family.
static const IOAddress & IPV6_ZERO_ADDRESS()
Returns an IPv6 zero address.
Base class that command handler implementers may use for common tasks.
std::string cmd_name_
Stores the command name extracted by a call to extractCommand.
void setErrorResponse(hooks::CalloutHandle &handle, const std::string &text, int status=CONTROL_RESULT_ERROR)
Set the callout argument "response" to indicate an error.
data::ConstElementPtr cmd_args_
Stores the command arguments extracted by a call to extractCommand.
void extractCommand(hooks::CalloutHandle &handle)
Extracts the command name and arguments from a Callout handle.
void setSuccessResponse(hooks::CalloutHandle &handle, const std::string &text)
Set the callout argument "response" to indicate success.
void setResponse(hooks::CalloutHandle &handle, data::ConstElementPtr &response)
Set the callout argument "response" to the given response.
uint32_t getUint32(isc::data::ConstElementPtr scope, const std::string &name)
Returns a value converted to uint32_t.
std::string validatePath(const std::string data_path) const
Validates a file path against the supported directory for DHDP data.
static CfgMgr & instance()
returns a single instance of Configuration Manager
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
static ClientIdPtr fromText(const std::string &text)
Create client identifier from the textual format.
Holds DUID (DHCPv6 Unique Identifier)
static TrackingLeaseMgr & instance()
Return current lease manager.
virtual Lease6Collection getLeases6(Lease::Type type, const DUID &duid, uint32_t iaid) const =0
Returns existing IPv6 leases for a given DUID+IA combination.
virtual size_t wipeLeases6(const SubnetID &subnet_id)=0
Virtual method which removes specified leases.
virtual Lease4Collection getLeases4(SubnetID subnet_id) const =0
Returns all IPv4 leases for the particular subnet identifier.
virtual void writeLeases6(const std::string &filename)=0
Write V6 leases to a file.
virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress &addr) const =0
Returns an IPv4 lease for specified IPv4 address.
virtual bool addLease(const Lease4Ptr &lease)=0
Adds an IPv4 lease.
virtual size_t wipeLeases4(const SubnetID &subnet_id)=0
Virtual method which removes specified leases.
virtual void updateLease4(const Lease4Ptr &lease4)=0
Updates IPv4 lease.
virtual void writeLeases4(const std::string &filename)=0
Write V4 leases to a file.
virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress &addr) const =0
Returns existing IPv6 lease for a given IPv6 address.
virtual void updateLease6(const Lease6Ptr &lease6)=0
Updates IPv6 lease.
Wraps value holding size of the page with leases.
Attempt to update lease that was not there.
Resource race avoidance RAII handler for DHCPv4.
bool tryLock4(const asiolink::IOAddress &addr)
Tries to acquires a resource.
Resource race avoidance RAII handler.
bool tryLock(Lease::Type type, const asiolink::IOAddress &addr)
Tries to acquires a resource.
Per-packet callout handle.
void getArgument(const std::string &name, T &value) const
Get argument.
Parser for Lease4 structure.
virtual isc::dhcp::Lease4Ptr parse(isc::dhcp::ConstSrvConfigPtr &cfg, const isc::data::ConstElementPtr &lease_info, bool &force_create)
Parses Element tree and tries to convert to Lease4.
Parser for Lease6 structure.
virtual isc::dhcp::Lease6Ptr parse(isc::dhcp::ConstSrvConfigPtr &cfg, const isc::data::ConstElementPtr &lease_info, bool &force_create)
Parses Element tree and tries to convert to Lease4.
Parameters specified for lease commands.
uint32_t iaid
IAID identifier used for v6 leases.
HWAddrPtr hwaddr
Specifies hardware address (used when query_type is TYPE_HWADDR)
Lease::Type lease_type
Lease type (NA,TA or PD) used for v6 leases.
Type query_type
specifies parameter types
Type
specifies type of query (by IP addr, by hwaddr, by DUID)
@ TYPE_DUID
query by DUID (v6 only)
@ TYPE_CLIENT_ID
query by client identifier (v4 only).
@ TYPE_HWADDR
query by hardware address (v4 only)
@ TYPE_ADDR
query by IP address (either v4 or v6)
isc::dhcp::ClientIdPtr client_id
Specifies identifier value (used when query_type is TYPE_CLIENT_ID)
static Type txtToType(const std::string &txt)
Attempts to covert text to one of specified types.
Parameters()
Default constructor.
bool updateDDNS
Indicates whether or not DNS should be updated.
IOAddress addr
Specifies IPv4/v6 address (used when query_type is TYPE_ADDR)
SubnetID subnet_id
Specifies subnet-id (always used)
isc::dhcp::DuidPtr duid
Specifies identifier value (used when query_type is TYPE_DUID)
Wrapper class around reservation command handlers.
int lease4DelHandler(CalloutHandle &handle)
lease4-del command handler
IOAddress getAddressParam(ConstElementPtr params, const std::string name, short family=AF_INET) const
static void lease4Offer(CalloutHandle &callout_handle, BindingVariableMgrPtr mgr)
lease4_offer hookpoint handler.
static void updateStatsOnUpdate(const Lease4Ptr &existing, const Lease4Ptr &lease)
Update stats when updating lease.
ElementPtr createFailedLeaseMap(const Lease::Type &lease_type, const IOAddress &lease_address, const DuidPtr &duid, const int control_result, const std::string &error_message) const
Returns a map holding brief information about a lease which failed to be deleted, updated or added.
static bool addOrUpdate6(Lease6Ptr lease, bool force_create)
Add or update lease.
int lease6BulkApplyHandler(CalloutHandle &handle)
lease6-bulk-apply command handler
int leaseGetByDuidHandler(hooks::CalloutHandle &handle)
lease6-get-by-duid command handler
int lease6UpdateHandler(CalloutHandle &handle)
lease6-update handler
int leaseGetPageHandler(hooks::CalloutHandle &handle)
lease4-get-page, lease6-get-page commands handler
Lease6Ptr getIPv6LeaseForDelete(const Parameters ¶meters) const
Convenience function fetching IPv6 address to be used to delete a lease.
int leaseGetByHostnameHandler(hooks::CalloutHandle &handle)
lease4-get-by-hostname and lease6-get-by-hostname commands handler
int lease6DelHandler(CalloutHandle &handle)
lease6-del command handler
int leaseGetByHwAddressHandler(hooks::CalloutHandle &handle)
lease4-get-by-hw-address, lease6-get-by-hw-address command handler
static ConstElementPtr getExtendedInfo6(const Lease6Ptr &lease)
Get DHCPv6 extended info.
int leaseGetHandler(CalloutHandle &handle)
lease4-get, lease6-get command handler
static bool addOrUpdate4(Lease4Ptr lease, bool force_create)
Add or update lease.
static void leases4Committed(CalloutHandle &callout_handle, BindingVariableMgrPtr mgr)
leases4_committed hookpoint handler.
int lease6WipeHandler(CalloutHandle &handle)
lease6-wipe handler
int leaseGetByClientIdHandler(hooks::CalloutHandle &handle)
lease4-get-by-client-id command handler
int lease6ResendDdnsHandler(CalloutHandle &handle)
lease6-resend-ddns handler
int leaseAddHandler(CalloutHandle &handle)
lease4-add, lease6-add command handler
int lease4ResendDdnsHandler(CalloutHandle &handle)
lease4-resend-ddns handler
static void updateStatsOnAdd(const Lease4Ptr &lease)
Update stats when adding lease.
Parameters getParameters(bool v6, const ConstElementPtr &args)
Extracts parameters required for reservation-get and reservation-del.
static void leases6Committed(CalloutHandle &callout_handle, BindingVariableMgrPtr mgr)
leases6_committed hookpoint handler.
int lease4UpdateHandler(CalloutHandle &handle)
lease4-update handler
int lease4WipeHandler(CalloutHandle &handle)
lease4-wipe handler
int leaseGetAllHandler(CalloutHandle &handle)
lease4-get-all, lease6-get-all commands handler
int leaseWriteHandler(CalloutHandle &handle)
lease4-write handler, lease6-write handler
static void updateStatsOnDelete(const Lease4Ptr &lease)
Update stats when deleting lease.
int lease4ResendDdnsHandler(hooks::CalloutHandle &handle)
lease4-resend-ddns command handler
int lease6WipeHandler(hooks::CalloutHandle &handle)
lease6-wipe handler
int leaseGetPageHandler(hooks::CalloutHandle &handle)
lease4-get-page, lease6-get-page commands handler
int lease6DelHandler(hooks::CalloutHandle &handle)
lease6-del command handler
int leaseGetAllHandler(hooks::CalloutHandle &handle)
lease4-get-all, lease6-get-all commands handler
int leaseGetByHostnameHandler(hooks::CalloutHandle &handle)
lease4-get-by-hostname and lease6-get-by-hostname commands handler
void leases4Committed(hooks::CalloutHandle &callout_handle, BindingVariableMgrPtr mgr)
leases4_committed hookpoint handler.
int lease4DelHandler(hooks::CalloutHandle &handle)
lease4-del command handler
int leaseWriteHandler(hooks::CalloutHandle &handle)
lease4-write handler, lease6-write handler
int leaseAddHandler(hooks::CalloutHandle &handle)
lease4-add, lease6-add command handler
int leaseGetByClientIdHandler(hooks::CalloutHandle &handle)
lease4-get-by-client-id command handler
void lease4Offer(hooks::CalloutHandle &callout_handle, BindingVariableMgrPtr mgr)
lease4_offer hookpoint handler.
int lease4UpdateHandler(hooks::CalloutHandle &handle)
lease4-update handler
int leaseGetHandler(hooks::CalloutHandle &handle)
lease4-get, lease6-get command handler
int leaseGetByHwAddressHandler(hooks::CalloutHandle &handle)
lease4-get-by-hw-address, lease6-get-by-hw-address command handler
int lease6UpdateHandler(hooks::CalloutHandle &handle)
lease6-update handler
void leases6Committed(hooks::CalloutHandle &callout_handle, BindingVariableMgrPtr mgr)
leases6_committed hookpoint handler.
int leaseGetByDuidHandler(hooks::CalloutHandle &handle)
lease6-get-by-duid command handler
int lease6BulkApplyHandler(hooks::CalloutHandle &handle)
lease6-bulk-apply command handler
int lease4WipeHandler(hooks::CalloutHandle &handle)
lease4-wipe handler
int lease6ResendDdnsHandler(hooks::CalloutHandle &handle)
lease6-resend-ddns command handler
ObservationPtr getObservation(const std::string &name) const
Returns an observation.
static StatsMgr & instance()
Statistics Manager accessor method.
static std::string generateName(const std::string &context, Type index, const std::string &stat_name)
Generates statistic name in a given context.
RAII class creating a critical section.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
A generic exception that is thrown if a parameter given violates security check but enforcement is la...
This file contains several functions and constants that are used for handling commands and responses ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
void setValue(const std::string &name, const int64_t value)
Records absolute integer observation.
void addValue(const std::string &name, const int64_t value)
Records incremental integer observation.
const isc::log::MessageID LEASE_CMDS_DEL4
const isc::log::MessageID LEASE_CMDS_WIPE4_FAILED
const isc::log::MessageID LEASE_CMDS_UPDATE6_FAILED
const isc::log::MessageID LEASE_CMDS_UPDATE4_FAILED
const isc::log::MessageID LEASE_CMDS_WIPE6_FAILED
const isc::log::MessageID LEASE_CMDS_UPDATE6_CONFLICT
const isc::log::MessageID LEASE_CMDS_UPDATE4_CONFLICT
const isc::log::MessageID LEASE_CMDS_RESEND_DDNS4_FAILED
const isc::log::MessageID LEASE_CMDS_DEL6
const isc::log::MessageID LEASE_CMDS_ADD4_FAILED
const isc::log::MessageID LEASE_CMDS_LEASES6_COMMITTED_LEASE_ERROR
const isc::log::MessageID LEASE_CMDS_PATH_SECURITY_WARNING
const isc::log::MessageID LEASE_CMDS_ADD6
const isc::log::MessageID LEASE_CMDS_ADD4
const isc::log::MessageID LEASE_CMDS_WIPE6
const isc::log::MessageID LEASE_CMDS_ADD6_CONFLICT
const isc::log::MessageID LEASE_CMDS_BULK_APPLY6_FAILED
const isc::log::MessageID LEASE_CMDS_UPDATE6
const isc::log::MessageID LEASE_CMDS_RESEND_DDNS4
const isc::log::MessageID LEASE_CMDS_GET6_FAILED
const isc::log::MessageID LEASE_CMDS_WIPE4
const isc::log::MessageID LEASE_CMDS_BULK_APPLY6
const isc::log::MessageID LEASE_CMDS_RESEND_DDNS6_FAILED
const isc::log::MessageID LEASE_CMDS_RESEND_DDNS6
const isc::log::MessageID LEASE_CMDS_GET4_FAILED
const isc::log::MessageID LEASE_CMDS_ADD4_CONFLICT
const isc::log::MessageID LEASE_CMDS_LEASES6_COMMITTED_CONFLICT
const isc::log::MessageID LEASE_CMDS_DEL4_FAILED
const isc::log::MessageID LEASE_CMDS_ADD6_FAILED
const isc::log::MessageID LEASE_CMDS_UPDATE4
const isc::log::MessageID LEASE_CMDS_DEL6_FAILED
An abstract API for lease database.
#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.
const int CONTROL_RESULT_EMPTY
Status code indicating that the specified command was completed correctly, but failed to produce any ...
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
const int CONTROL_RESULT_CONFLICT
Status code indicating that the command was unsuccessful due to a conflict between the command argume...
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< Lease4Collection > Lease4CollectionPtr
A shared pointer to the collection of IPv4 leases.
boost::shared_ptr< const SrvConfig > ConstSrvConfigPtr
Const pointer to the SrvConfig.
void queueNCR(const NameChangeType &chg_type, const Lease4Ptr &lease)
Creates name change request from the DHCPv4 lease.
boost::shared_ptr< const Subnet6 > ConstSubnet6Ptr
A const pointer to a Subnet6 object.
boost::shared_ptr< const Subnet4 > ConstSubnet4Ptr
A const pointer to a Subnet4 object.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
boost::shared_ptr< DUID > DuidPtr
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
boost::multi_index_container< Subnet6Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetSubnetIdIndexTag >, boost::multi_index::const_mem_fun< Subnet, SubnetID, &Subnet::getID > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetPrefixIndexTag >, boost::multi_index::const_mem_fun< Subnet, std::string, &Subnet::toText > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetModificationTimeIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::BaseStampedElement::getModificationTime > > > > Subnet6Collection
A collection of Subnet6 objects.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
boost::multi_index_container< Subnet4Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetSubnetIdIndexTag >, boost::multi_index::const_mem_fun< Subnet, SubnetID, &Subnet::getID > >, boost::multi_index::ordered_unique< boost::multi_index::tag< SubnetPrefixIndexTag >, boost::multi_index::const_mem_fun< Subnet, std::string, &Subnet::toText > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetServerIdIndexTag >, boost::multi_index::const_mem_fun< Network4, asiolink::IOAddress, &Network4::getServerId > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetModificationTimeIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::BaseStampedElement::getModificationTime > > > > Subnet4Collection
A collection of Subnet4 objects.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
boost::shared_ptr< const CfgSubnets4 > ConstCfgSubnets4Ptr
Const pointer.
boost::shared_ptr< const CfgSubnets6 > ConstCfgSubnets6Ptr
Const pointer.
boost::shared_ptr< Lease6Collection > Lease6CollectionPtr
A shared pointer to the collection of IPv6 leases.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
std::vector< Lease4Ptr > Lease4Collection
A collection of IPv4 leases.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
const int LEASE_CMDS_DBG_COMMAND_DATA
Logging level used to log successful commands.
isc::log::Logger lease_cmds_logger("lease-cmds-hooks")
boost::shared_ptr< BindingVariableMgr > BindingVariableMgrPtr
Defines a shared pointer to a BindingVariableMgr.
Defines the logger used by the top-level component of kea-lfc.
Hardware type that represents information from DHCPv4 packet.
static HWAddr fromText(const std::string &text, const uint16_t htype=HTYPE_ETHER)
Creates instance of the hardware address from textual format.
Structure that holds a lease for IPv6 address and/or prefix.
@ ACTION_UPDATE
update extended info tables.
a common structure for IPv4 and IPv6 leases
Type
Type of lease or pool.
@ TYPE_TA
the lease contains temporary IPv6 address
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
@ TYPE_NA
the lease contains non-temporary IPv6 address
static void syncCurrentExpirationTime(const Lease &from, Lease &to)
Sync lease current expiration time with new value from another lease, so that additional operations c...
static std::string typeToText(Type type)
returns text representation of a lease type