27#include <boost/bind.hpp>
28#include <boost/scoped_ptr.hpp>
81 if (txt ==
"address") {
83 }
else if (txt ==
"hw-address") {
85 }
else if (txt ==
"duid") {
87 }
else if (txt ==
"client-id") {
91 << txt <<
", the only supported values are: "
92 "address, hw-address, duid");
242 string txt =
"malformed command";
249 txt =
"(missing parameters)";
261 bool force_create =
false;
268 resp <<
"Lease for address " << lease4->addr_.toText()
269 <<
", subnet-id " << lease4->subnet_id_ <<
" added.";
279 resp <<
"Lease for address " << lease6->addr_.toText()
280 <<
", subnet-id " << lease6->subnet_id_ <<
" added.";
282 resp <<
"Lease for prefix " << lease6->addr_.toText()
283 <<
"/" <<
static_cast<int>(lease6->prefixlen_)
284 <<
", subnet-id " << lease6->subnet_id_ <<
" added.";
289 }
catch (
const std::exception& ex) {
298 v4 ? LEASE_CMDS_ADD4 : LEASE_CMDS_ADD6).arg(txt);
315 if (params->contains(
"type")) {
316 string t = params->get(
"type")->stringValue();
317 if (t ==
"IA_NA" || t ==
"0") {
319 }
else if (t ==
"IA_TA" || t ==
"1") {
321 }
else if (t ==
"IA_PD" || t ==
"2") {
323 }
else if (t ==
"V4" || t ==
"3") {
327 << t <<
", only supported values are: IA_NA, IA_TA,"
342 txt <<
"Invalid " << (v6 ?
"IPv6" :
"IPv4")
343 <<
" address specified: " << tmp->stringValue();
351 tmp = params->get(
"subnet-id");
360 if (params->contains(
"iaid")) {
361 x.
iaid = params->get(
"iaid")->intValue();
372 " and 'identifier-type' is either missing or not a string.");
376 " and 'identifier' is either missing or not a string.");
405 " is not supported.");
436 "requires hwaddr to be specified");
449 "requires duid to be specified");
463 "requires client-id to be specified");
477 }
catch (
const std::exception& ex) {
484 lease_json = lease4->toElement();
486 "IPv4 lease found.", lease_json);
488 }
else if (!v4 && lease6) {
489 lease_json = lease6->toElement();
491 "IPv6 lease found.", lease_json);
521 const std::vector<ElementPtr>& subnet_ids = subnets->listValue();
522 for (
auto subnet_id = subnet_ids.begin();
523 subnet_id != subnet_ids.end();
532 for (
auto lease : leases) {
534 leases_json->add(lease_json);
539 for (
auto lease : leases) {
541 leases_json->add(lease_json);
550 for (
auto lease : leases) {
552 leases_json->add(lease_json);
556 for (
auto lease : leases) {
558 leases_json->add(lease_json);
563 std::ostringstream s;
564 s << leases_json->size()
565 <<
" IPv" << (v4 ?
"4" :
"6")
566 <<
" lease(s) found.";
568 args->set(
"leases", leases_json);
576 }
catch (
const std::exception& ex) {
610 boost::scoped_ptr<IOAddress> from_address;
612 if (from->stringValue() ==
"start") {
613 from_address.reset(
new IOAddress(v4 ?
"0.0.0.0" :
"::"));
617 from_address.reset(
new IOAddress(from->stringValue()));
622 "a valid IPv" << (v4 ?
"4" :
"6") <<
" address");
627 if (v4 && (!from_address->isV4())) {
629 <<
" is not an IPv4 address");
631 }
else if (!v4 && from_address->isV4()) {
633 <<
" is not an IPv6 address");
648 size_t page_limit_value =
static_cast<size_t>(page_limit->intValue());
659 for (
auto lease : leases) {
661 leases_json->add(lease_json);
670 for (
auto lease : leases) {
672 leases_json->add(lease_json);
677 std::ostringstream s;
678 s << leases_json->size()
679 <<
" IPv" << (v4 ?
"4" :
"6")
680 <<
" lease(s) found.";
684 args->set(
"leases", leases_json);
685 args->set(
"count",
Element::create(
static_cast<int64_t
>(leases_json->size())));
695 }
catch (std::exception& ex) {
722 "requires hwaddr to be specified");
733 addr = lease4->addr_;
739 "requires client-id to be specified");
750 addr = lease4->addr_;
768 }
catch (
const std::exception& ex) {
799 "requires duid to be specified");
811 addr = lease6->addr_;
825 }
catch (
const std::exception& ex) {
847 bool force_create =
false;
860 }
catch (
const std::exception& ex) {
882 bool force_create =
false;
895 }
catch (
const std::exception& ex) {
930 for (
auto sub : *subs) {
932 ids <<
" " << sub->getID();
937 tmp <<
"Deleted " << num <<
" IPv4 lease(s) from subnet(s)" << ids.str();
941 }
catch (
const std::exception& ex) {
982 for (
auto sub : *subs) {
984 ids <<
" " << sub->getID();
989 tmp <<
"Deleted " << num <<
" IPv6 lease(s) from subnet(s)" << ids.str();
993 }
catch (
const std::exception& ex) {
1003 return(impl_->leaseAddHandler(handle));
1008 return(impl_->leaseGetHandler(handle));
1013 return (impl_->leaseGetAllHandler(handle));
1018 return (impl_->leaseGetPageHandler(handle));
1023 return(impl_->lease4DelHandler(handle));
1028 return(impl_->lease6DelHandler(handle));
1033 return(impl_->lease4UpdateHandler(handle));
1038 return(impl_->lease6UpdateHandler(handle));
1043 return(impl_->lease4WipeHandler(handle));
1048 return(impl_->lease6WipeHandler(handle));
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
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...
The IOAddress class represents an IP addresses (version agnostic)
static const IOAddress & IPV4_ZERO_ADDRESS()
Returns an address set to all zeros.
bool isV6() const
Convenience function to check for an IPv6 address.
bool isV4() const
Convenience function to check for an IPv4 address.
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.
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.
uint32_t getUint32(isc::data::ConstElementPtr scope, const std::string &name)
Returns a value converted to uint32_t.
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 DUID fromText(const std::string &text)
Create DUID from the textual format.
static LeaseMgr & 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 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 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.
Per-packet callout handle.
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 (true = query by address, false = query by identifier-type,...
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.
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
int lease6UpdateHandler(CalloutHandle &handle)
lease6-update handler
int leaseGetPageHandler(hooks::CalloutHandle &handle)
lease4-get-page, lease6-get-page commands handler
int lease6DelHandler(CalloutHandle &handle)
lease6-del command handler
int leaseGetHandler(CalloutHandle &handle)
lease4-get, lease6-get command handler
int lease6WipeHandler(CalloutHandle &handle)
lease6-wipe handler
int leaseAddHandler(CalloutHandle &handle)
lease4-add, lease6-add command handler
Parameters getParameters(bool v6, const ConstElementPtr &args)
Extracts parameters required for reservation-get and reservation-del.
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 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 lease4DelHandler(hooks::CalloutHandle &handle)
lease4-del command handler
int leaseAddHandler(hooks::CalloutHandle &handle)
lease4-add, lease6-add command handler
int lease4UpdateHandler(hooks::CalloutHandle &handle)
lease4-update handler
int leaseGetHandler(hooks::CalloutHandle &handle)
lease4-get, lease6-get command handler
int lease6UpdateHandler(hooks::CalloutHandle &handle)
lease6-update handler
int lease4WipeHandler(hooks::CalloutHandle &handle)
lease4-wipe handler
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.
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.
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_SUCCESS
Status code indicating a successful operation.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
boost::multi_index_container< Subnet6Ptr, boost::multi_index::indexed_by< boost::multi_index::random_access< boost::multi_index::tag< SubnetRandomAccessIndexTag > >, 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 > > > > Subnet6Collection
A collection of Subnet6 objects.
boost::shared_ptr< const SrvConfig > ConstSrvConfigPtr
Const pointer to the SrvConfig.
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::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
boost::multi_index_container< Subnet4Ptr, boost::multi_index::indexed_by< boost::multi_index::random_access< boost::multi_index::tag< SubnetRandomAccessIndexTag > >, 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 > > > > Subnet4Collection
A collection of Subnet4 objects.
boost::shared_ptr< const CfgSubnets4 > ConstCfgSubnets4Ptr
Const pointer.
boost::shared_ptr< const CfgSubnets6 > ConstCfgSubnets6Ptr
Const pointer.
std::vector< Lease4Ptr > Lease4Collection
A collection of IPv4 leases.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
isc::log::Logger lease_cmds_logger("lease-cmds-hooks")
Defines the logger used by the top-level component of kea-dhcp-ddns.
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.
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