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()) {
528 "assigned-addresses"),
529 static_cast<int64_t
>(1));
539 "assigned-addresses")),
540 static_cast<int64_t
>(1));
544 if (lease->stateDeclined()) {
549 "declined-addresses"),
550 static_cast<int64_t
>(1));
556 "declined-addresses")),
557 static_cast<int64_t
>(1));
565 if (lease->stateRegistered()) {
568 static_cast<int64_t
>(1));
569 }
else if (!lease->stateExpiredReclaimed()) {
573 "assigned-nas" :
"assigned-pds"),
574 static_cast<int64_t
>(1));
579 pool = subnet->getPool(lease->type_, lease->addr_,
false);
584 "pool" :
"pd-pool", pool->getID(),
586 "assigned-nas" :
"assigned-pds")),
587 static_cast<int64_t
>(1));
591 if (lease->stateDeclined()) {
596 "declined-addresses"),
597 static_cast<int64_t
>(1));
603 "declined-addresses")),
604 static_cast<int64_t
>(1));
613 if (!existing->stateExpiredReclaimed()) {
618 if (existing->subnet_id_ != lease->subnet_id_) {
621 "assigned-addresses"),
622 static_cast<int64_t
>(-1));
631 "assigned-addresses")),
632 static_cast<int64_t
>(-1));
637 if (existing->stateDeclined()) {
643 "declined-addresses"),
644 static_cast<int64_t
>(-1));
650 "declined-addresses")),
651 static_cast<int64_t
>(-1));
657 if (!lease->stateExpiredReclaimed()) {
659 if (existing->subnet_id_ != lease->subnet_id_) {
662 "assigned-addresses"),
663 static_cast<int64_t
>(1));
672 "assigned-addresses")),
673 static_cast<int64_t
>(1));
678 if (lease->stateDeclined()) {
684 "declined-addresses"),
685 static_cast<int64_t
>(1));
691 "declined-addresses")),
692 static_cast<int64_t
>(1));
698 if (!lease->stateExpiredReclaimed()) {
702 "assigned-addresses"),
703 static_cast<int64_t
>(1));
713 "assigned-addresses")),
714 static_cast<int64_t
>(1));
718 if (lease->stateDeclined()) {
724 "declined-addresses"),
725 static_cast<int64_t
>(1));
731 "declined-addresses")),
732 static_cast<int64_t
>(1));
743 if (existing->stateRegistered()) {
744 if (existing->subnet_id_ != lease->subnet_id_) {
748 static_cast<int64_t
>(-1));
752 static_cast<int64_t
>(1));
754 }
else if (!existing->stateExpiredReclaimed()) {
759 if (existing->subnet_id_ != lease->subnet_id_) {
763 "assigned-nas" :
"assigned-pds"),
764 static_cast<int64_t
>(-1));
768 pool = subnet->getPool(existing->type_, existing->addr_,
false);
773 "pool" :
"pd-pool", pool->getID(),
775 "assigned-nas" :
"assigned-pds")),
776 static_cast<int64_t
>(-1));
781 if (existing->stateDeclined()) {
787 "declined-addresses"),
788 static_cast<int64_t
>(-1));
794 "declined-addresses")),
795 static_cast<int64_t
>(-1));
801 if (!lease->stateExpiredReclaimed()) {
803 if (existing->subnet_id_ != lease->subnet_id_) {
807 "assigned-nas" :
"assigned-pds"),
808 static_cast<int64_t
>(1));
812 pool = subnet->getPool(lease->type_, lease->addr_,
false);
817 "pool" :
"pd-pool", pool->getID(),
819 "assigned-nas" :
"assigned-pds")),
820 static_cast<int64_t
>(1));
825 if (lease->stateDeclined()) {
831 "declined-addresses"),
832 static_cast<int64_t
>(1));
838 "declined-addresses")),
839 static_cast<int64_t
>(1));
845 if (!lease->stateExpiredReclaimed()) {
850 "assigned-nas" :
"assigned-pds"),
851 static_cast<int64_t
>(1));
856 pool = subnet->getPool(lease->type_, lease->addr_,
false);
861 "pool" :
"pd-pool", pool->getID(),
863 "assigned-nas" :
"assigned-pds")),
864 static_cast<int64_t
>(1));
868 if (lease->stateDeclined()) {
874 "declined-addresses"),
875 static_cast<int64_t
>(1));
881 "declined-addresses")),
882 static_cast<int64_t
>(1));
891 if (!lease->stateExpiredReclaimed()) {
894 "assigned-addresses"),
895 static_cast<int64_t
>(-1));
905 "assigned-addresses")),
906 static_cast<int64_t
>(-1));
910 if (lease->stateDeclined()) {
915 "declined-addresses"),
916 static_cast<int64_t
>(-1));
922 "declined-addresses")),
923 static_cast<int64_t
>(-1));
931 if (lease->stateRegistered()) {
935 static_cast<int64_t
>(-1));
936 }
else if (!lease->stateExpiredReclaimed()) {
940 "assigned-nas" :
"assigned-pds"),
941 static_cast<int64_t
>(-1));
946 pool = subnet->getPool(lease->type_, lease->addr_,
false);
951 "pool" :
"pd-pool", pool->getID(),
953 "assigned-nas" :
"assigned-pds")),
954 static_cast<int64_t
>(-1));
958 if (lease->stateDeclined()) {
963 "declined-addresses"),
964 static_cast<int64_t
>(-1));
970 "declined-addresses")),
971 static_cast<int64_t
>(-1));
980 if (force_create && !existing) {
984 "lost race between calls to get and add");
999 << lease->addr_ <<
" either because the lease has been "
1000 "deleted or it has changed in the database, in both cases a "
1001 "retry might succeed");
1012 if (force_create && !existing) {
1016 "lost race between calls to get and add");
1023 if (existing->stateRegistered() && !lease->stateRegistered()) {
1026 }
else if (!existing->stateRegistered() && lease->stateRegistered()) {
1028 <<
" can't be registered");
1039 if ((!old_extended_info && !extended_info) ||
1040 (old_extended_info && extended_info &&
1041 (*old_extended_info == *extended_info))) {
1051 << lease->addr_ <<
" either because the lease has been "
1052 "deleted or it has changed in the database, in both cases a "
1053 "retry might succeed");
1066 string lease_address =
"unknown";
1077 bool force_create =
false;
1084 lease_address = lease4->addr_.toText();
1092 if (resource_handler.
tryLock4(lease4->addr_)) {
1096 "ResourceBusy: IP address:" << lease4->addr_
1097 <<
" could not be added.");
1106 resp <<
"Lease for address " << lease4->addr_.toText()
1107 <<
", subnet-id " << lease4->subnet_id_ <<
" added.";
1113 lease_address = lease6->addr_.toText();
1121 if (resource_handler.
tryLock(lease6->type_, lease6->addr_)) {
1125 "ResourceBusy: IP address:" << lease6->addr_
1126 <<
" could not be added.");
1136 resp <<
"Lease for address " << lease6->addr_.toText()
1137 <<
", subnet-id " << lease6->subnet_id_ <<
" added.";
1139 resp <<
"Lease for prefix " << lease6->addr_.toText()
1140 <<
"/" <<
static_cast<int>(lease6->prefixlen_)
1141 <<
", subnet-id " << lease6->subnet_id_ <<
" added.";
1152 }
catch (
const std::exception& ex) {
1162 .arg(lease_address);
1175 if (params->contains(
"update-ddns")) {
1188 if (params->contains(
"type")) {
1189 string t = params->get(
"type")->stringValue();
1190 if (t ==
"IA_NA" || t ==
"0") {
1192 }
else if (t ==
"IA_TA" || t ==
"1") {
1194 }
else if (t ==
"IA_PD" || t ==
"2") {
1196 }
else if (t ==
"V4" || t ==
"3") {
1200 << t <<
", only supported values are: IA_NA, IA_TA,"
1201 <<
" IA_PD and V4");
1215 txt <<
"Invalid " << (v6 ?
"IPv6" :
"IPv4")
1216 <<
" address specified: " << tmp->stringValue();
1224 tmp = params->get(
"subnet-id");
1233 if (params->contains(
"iaid")) {
1234 x.
iaid = params->get(
"iaid")->intValue();
1245 " and 'identifier-type' is either missing or not a string.");
1249 " and 'identifier' is either missing or not a string.");
1278 " is not supported.");
1309 "requires hwaddr to be specified");
1322 "requires duid to be specified");
1336 "requires client-id to be specified");
1350 }
catch (
const std::exception& ex) {
1360 lease_json = lease4->toElement();
1362 "IPv4 lease found.", lease_json);
1364 }
else if (!v4 && lease6) {
1365 lease_json = lease6->toElement();
1367 "IPv6 lease found.", lease_json);
1397 const std::vector<ElementPtr>& subnet_ids = subnets->listValue();
1398 for (
auto const& subnet_id : subnet_ids) {
1406 for (
auto const& lease : leases) {
1408 leases_json->add(lease_json);
1413 for (
auto const& lease : leases) {
1415 leases_json->add(lease_json);
1424 for (
auto const& lease : leases) {
1426 leases_json->add(lease_json);
1430 for (
auto const& lease : leases) {
1432 leases_json->add(lease_json);
1437 std::ostringstream s;
1438 s << leases_json->size()
1439 <<
" IPv" << (v4 ?
"4" :
"6")
1440 <<
" lease(s) found.";
1442 args->set(
"leases", leases_json);
1450 }
catch (
const std::exception& ex) {
1484 boost::scoped_ptr<IOAddress> from_address;
1486 if (from->stringValue() ==
"start") {
1487 from_address.reset(
new IOAddress(v4 ?
"0.0.0.0" :
"::"));
1491 from_address.reset(
new IOAddress(from->stringValue()));
1496 "a valid IPv" << (v4 ?
"4" :
"6") <<
" address");
1501 if (v4 && (!from_address->isV4())) {
1503 <<
" is not an IPv4 address");
1505 }
else if (!v4 && from_address->isV4()) {
1507 <<
" is not an IPv6 address");
1522 size_t page_limit_value =
static_cast<size_t>(page_limit->intValue());
1533 for (
auto const& lease : leases) {
1535 leases_json->add(lease_json);
1544 for (
auto const& lease : leases) {
1546 leases_json->add(lease_json);
1551 std::ostringstream s;
1552 s << leases_json->size()
1553 <<
" IPv" << (v4 ?
"4" :
"6")
1554 <<
" lease(s) found.";
1558 args->set(
"leases", leases_json);
1559 args->set(
"count",
Element::create(
static_cast<int64_t
>(leases_json->size())));
1569 }
catch (
const std::exception& ex) {
1582 v4 = (
cmd_name_ ==
"lease4-get-by-hw-address");
1600 if (hw_address->stringValue().empty()) {
1611 for (
auto const& lease : leases) {
1613 leases_json->add(lease_json);
1618 for (
auto const& lease : leases) {
1620 leases_json->add(lease_json);
1624 std::ostringstream s;
1625 s << leases_json->size()
1626 <<
" IPv" << (v4 ?
"4" :
"6")
1627 <<
" lease(s) found.";
1629 args->set(
"leases", leases_json);
1637 }
catch (
const std::exception& ex) {
1671 for (
auto const& lease : leases) {
1673 leases_json->add(lease_json);
1676 std::ostringstream s;
1677 s << leases_json->size() <<
" IPv4 lease(s) found.";
1679 args->set(
"leases", leases_json);
1687 }
catch (
const std::exception& ex) {
1721 for (
auto const& lease : leases) {
1723 leases_json->add(lease_json);
1726 std::ostringstream s;
1727 s << leases_json->size() <<
" IPv6 lease(s) found.";
1729 args->set(
"leases", leases_json);
1737 }
catch (
const std::exception& ex) {
1750 v4 = (
cmd_name_ ==
"lease4-get-by-hostname");
1768 std::string hostname_ = hostname->stringValue();
1770 if (hostname_.empty()) {
1773 boost::algorithm::to_lower(hostname_);
1780 for (
auto const& lease : leases) {
1782 leases_json->add(lease_json);
1788 for (
auto const& lease : leases) {
1790 leases_json->add(lease_json);
1794 std::ostringstream s;
1795 s << leases_json->size()
1796 <<
" IPv" << (v4 ?
"4" :
"6")
1797 <<
" lease(s) found.";
1799 args->set(
"leases", leases_json);
1807 }
catch (
const std::exception& ex) {
1835 "requires hwaddr to be specified");
1849 "requires client-id to be specified");
1882 }
catch (
const std::exception& ex) {
1890 .arg(lease4->addr_.toText());
1905 auto deleted_leases =
cmd_args_->get(
"deleted-leases");
1908 if (!deleted_leases && !leases) {
1914 if (deleted_leases && (deleted_leases->getType() !=
Element::list)) {
1926 std::list<std::pair<Parameters, Lease6Ptr> > parsed_deleted_list;
1927 if (deleted_leases) {
1928 auto leases_list = deleted_leases->listValue();
1931 for (
auto const& lease_params : leases_list) {
1936 parsed_deleted_list.push_back(std::make_pair(p, lease));
1942 std::list<Lease6Ptr> parsed_leases_list;
1947 auto leases_list = leases->listValue();
1948 for (
auto const& lease_params : leases_list) {
1956 parsed_leases_list.push_back(lease6);
1961 size_t success_count = 0;
1964 if (!parsed_deleted_list.empty()) {
1967 for (
auto const& lease_params_pair : parsed_deleted_list) {
1972 auto lease = lease_params_pair.second;
1985 if (!failed_deleted_list) {
1996 "lease not found"));
2000 }
catch (
const std::exception& ex) {
2002 if (!failed_deleted_list) {
2015 if (!parsed_leases_list.empty()) {
2019 for (
auto const& lease : parsed_leases_list) {
2022 std::ostringstream text;
2030 if (resource_handler.
tryLock(lease->type_, lease->addr_)) {
2034 "ResourceBusy: IP address:" << lease->addr_
2035 <<
" could not be updated.");
2044 }
catch (
const std::exception& ex) {
2051 if (!failed_leases_list) {
2066 if (failed_deleted_list || failed_leases_list) {
2071 if (failed_deleted_list) {
2072 args->set(
"failed-deleted-leases", failed_deleted_list);
2076 if (failed_leases_list) {
2077 args->set(
"failed-leases", failed_leases_list);
2082 std::ostringstream resp_text;
2083 resp_text <<
"Bulk apply of " << success_count <<
" IPv6 leases completed.";
2090 .arg(success_count);
2092 }
catch (
const std::exception& ex) {
2132 "requires duid to be specified");
2162 }
catch (
const std::exception& ex) {
2171 .arg(lease6->addr_.toText());
2189 bool force_create =
false;
2201 if (resource_handler.
tryLock4(lease4->addr_)) {
2205 "ResourceBusy: IP address:" << lease4->addr_
2206 <<
" could not be updated.");
2217 .arg(lease4->addr_.toText());
2226 }
catch (
const std::exception& ex) {
2251 bool force_create =
false;
2263 if (resource_handler.
tryLock(lease6->type_, lease6->addr_)) {
2267 "ResourceBusy: IP address:" << lease6->addr_
2268 <<
" could not be updated.");
2279 .arg(lease6->addr_.toText());
2288 }
catch (
const std::exception& ex) {
2323 int64_t previous_declined = 0;
2326 previous_declined = observation->getInteger().first;
2331 static_cast<int64_t
>(0));
2335 static_cast<int64_t
>(0));
2342 "assigned-addresses")));
2349 "declined-addresses")));
2364 for (
auto const& sub : *subs) {
2366 ids <<
" " << sub->getID();
2369 static_cast<int64_t
>(0));
2373 static_cast<int64_t
>(0));
2378 "assigned-addresses")));
2385 "declined-addresses")));
2396 tmp <<
"Deleted " << num <<
" IPv4 lease(s) from subnet(s)" << ids.str();
2400 }
catch (
const std::exception& ex) {
2442 int64_t previous_declined = 0;
2445 previous_declined = observation->getInteger().first;
2450 static_cast<int64_t
>(0));
2454 static_cast<int64_t
>(0));
2458 static_cast<int64_t
>(0));
2462 static_cast<int64_t
>(0));
2476 "declined-addresses")));
2500 for (
auto const& sub : *subs) {
2502 ids <<
" " << sub->getID();
2505 static_cast<int64_t
>(0));
2509 static_cast<int64_t
>(0));
2513 static_cast<int64_t
>(0));
2517 static_cast<int64_t
>(0));
2529 "declined-addresses")));
2549 tmp <<
"Deleted " << num <<
" IPv6 lease(s) from subnet(s)" << ids.str();
2553 }
catch (
const std::exception& ex) {
2578 lease6.reset(
new Lease6());
2579 lease6->addr_ = parameters.
addr;
2588 if (!parameters.
duid) {
2590 "requires duid to be specified");
2610 short family)
const {
2623 }
catch (
const std::exception& ex) {
2625 <<
"' is not a valid IP address.");
2630 << (family == AF_INET6 ?
"IPv6" :
"IPv4")
2631 <<
" address specified: " << param->stringValue());
2639 std::stringstream ss;
2649 ss <<
"DDNS updating is not enabled";
2655 ss <<
"No lease found for: " << addr.
toText();
2657 }
else if (lease->hostname_.empty()) {
2658 ss <<
"Lease for: " << addr.
toText()
2659 <<
", has no hostname, nothing to update";
2661 }
else if (!lease->fqdn_fwd_ && !lease->fqdn_rev_) {
2662 ss <<
"Neither forward nor reverse updates enabled for lease for: "
2669 ss <<
"NCR generated for: " << addr.
toText()
2670 <<
", hostname: " << lease->hostname_;
2676 }
catch (
const std::exception& ex) {
2687 std::stringstream ss;
2697 ss <<
"DDNS updating is not enabled";
2703 ss <<
"No lease found for: " << addr.
toText();
2705 }
else if (lease->hostname_.empty()) {
2706 ss <<
"Lease for: " << addr.
toText()
2707 <<
", has no hostname, nothing to update";
2709 }
else if (!lease->fqdn_fwd_ && !lease->fqdn_rev_) {
2710 ss <<
"Neither forward nor reverse updates enabled for lease for: "
2717 ss <<
"NCR generated for: " << addr.
toText()
2718 <<
", hostname: " << lease->hostname_;
2724 }
catch (
const std::exception& ex) {
2737 const int control_result,
2738 const std::string& error_message)
const {
2751 failed_lease_map->set(
"error-message",
Element::create(error_message));
2753 return (failed_lease_map);
2775 std::string filename;
2781 filename =
file->stringValue();
2782 }
catch (
const std::exception& ex) {
2793 s << (v4 ?
"IPv4" :
"IPv6")
2794 <<
" lease database into '"
2795 << filename <<
"'.";
2798 }
catch (
const std::exception& ex) {
2809 uint32_t offer_lifetime;
2810 callout_handle.
getArgument(
"offer_lifetime", offer_lifetime);
2811 if (!offer_lifetime) {
2822 callout_handle.
getArgument(
"response4", response);
2825 if (!leases || leases->empty() || !((*leases)[0])) {
2831 if (mgr->evaluateVariables(query, response, lease)) {
2836 " the lease with address " << lease->addr_ <<
2837 " either because the lease has been"
2838 " deleted or it has changed in the database");
2839 }
catch (
const std::exception& ex) {
2841 << query->getLabel() <<
", :" << ex.what());
2854 callout_handle.
getArgument(
"response4", response);
2863 if (leases->empty() || !response || (response->getType() !=
DHCPACK)) {
2873 if (mgr->evaluateVariables(query, response, lease)) {
2878 " the lease with address " << lease->addr_ <<
2879 " either because the lease has been"
2880 " deleted or it has changed in the database");
2881 }
catch (
const std::exception& ex) {
2883 << query->getLabel() <<
", :" << ex.what());
2896 callout_handle.
getArgument(
"response6", response);
2904 if (leases->empty() || !response) {
2910 for (
auto lease : *leases) {
2922 if (lease->valid_lft_) {
2924 if (mgr->evaluateVariables(query, response, lease)) {
2931 .arg(lease->addr_.toText())
2932 .arg(query->getLabel());
2933 }
catch (
const std::exception& ex) {
2936 .arg(query->getLabel())
2937 .arg(lease->addr_.toText())
2944 <<
" leases failed to update for "
2945 << query->getLabel());
2951 return (impl_->leaseAddHandler(handle));
2956 return (impl_->lease6BulkApplyHandler(handle));
2961 return (impl_->leaseGetHandler(handle));
2966 return (impl_->leaseGetAllHandler(handle));
2971 return (impl_->leaseGetPageHandler(handle));
2976 return (impl_->leaseGetByHwAddressHandler(handle));
2981 return (impl_->leaseGetByClientIdHandler(handle));
2986 return (impl_->leaseGetByDuidHandler(handle));
2991 return (impl_->leaseGetByHostnameHandler(handle));
2996 return (impl_->lease4DelHandler(handle));
3001 return (impl_->lease6DelHandler(handle));
3006 return (impl_->lease4UpdateHandler(handle));
3011 return (impl_->lease6UpdateHandler(handle));
3017 return (impl_->lease4WipeHandler(handle));
3023 return (impl_->lease6WipeHandler(handle));
3028 return (impl_->lease4ResendDdnsHandler(handle));
3033 return (impl_->lease6ResendDdnsHandler(handle));
3038 return (impl_->leaseWriteHandler(handle));
3048 impl_->lease4Offer(callout_handle, mgr);
3054 impl_->leases4Committed(callout_handle, mgr);
3060 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