![]() |
Kea 3.1.1
|
Provides configuration and for processing DHCPv4 lease queries. More...
#include <lease_query_impl4.h>
Public Member Functions | |
LeaseQueryImpl4 (const data::ConstElementPtr config) | |
Constructor. | |
virtual | ~LeaseQueryImpl4 () |
Destructor. | |
virtual void | processQuery (dhcp::PktPtr base_query) const |
Processes a single DHCPv4 client Lease Query. | |
![]() | |
LeaseQueryImpl (uint16_t family, const isc::data::ConstElementPtr config) | |
Constructor. | |
virtual | ~LeaseQueryImpl () |
Destructor. | |
uint16_t | getFamily () |
Returns the protocol family of the impl. | |
isc::asiolink::IOServicePtr | getIOService () |
Get the hook I/O service. | |
size_t | getNumRequesters () const |
Returns the number of valid requester. | |
bool | isRequester (const isc::asiolink::IOAddress &address) const |
Checks if the given address belongs to a valid requester. | |
void | setIOService (isc::asiolink::IOServicePtr io_service) |
Set the hook I/O service. | |
Static Public Member Functions | |
static bool | acceptServerId (const dhcp::Pkt4Ptr &query, dhcp::OptionPtr &server_id_opt) |
Validates dhcp-server-identifier option in the inbound query (if one) | |
static void | addAssociatedLeases (dhcp::Pkt4Ptr response, const dhcp::Lease4Collection &leases) |
Adds associated leases to a query response. | |
static void | addLeaseTimes (dhcp::Pkt4Ptr response, const dhcp::Lease4Ptr &lease, const dhcp::Subnet4Ptr &subnet) |
Adds life time, T1, and T2 options to a query response. | |
static void | addOptions (const dhcp::Pkt4Ptr &query, dhcp::Pkt4Ptr response, const dhcp::Lease4Ptr &lease) |
Adds options to a query response. | |
static void | addRelayAgentInfo (dhcp::Pkt4Ptr response, const dhcp::Lease4Ptr &lease) |
Adds relay-agent-info option to a query response. | |
static void | appendServerId (dhcp::Pkt4Ptr &response, dhcp::CfgOptionList &co_list) |
Adds dhcp-server-identifier option (54) to the response. | |
static void | buildCfgOptionList (dhcp::CfgOptionList &co_list, const dhcp::Pkt4Ptr &query, const dhcp::Lease4Ptr &lease=dhcp::Lease4Ptr(), const dhcp::Subnet4Ptr &subnet=dhcp::Subnet4Ptr()) |
Constructs a list of configured option sets for a given lease and it's subnet. | |
static dhcp::Pkt4Ptr | buildResponse (dhcp::DHCPMessageType response_type, const dhcp::Pkt4Ptr &query, const dhcp::Lease4Collection &leases) |
Creates a lease query response packet. | |
static dhcp::Pkt4Ptr | initResponse (dhcp::DHCPMessageType response_type, const dhcp::Pkt4Ptr &query) |
Creates the initial query response. | |
static std::string | leaseQueryLabel (const dhcp::Pkt4Ptr &packet) |
Convenience method for generating per packet logging info. | |
static dhcp::DHCPMessageType | queryByClientId (const dhcp::ClientIdPtr &client_id, dhcp::Lease4Collection &leases) |
Queries LeaseMgr for active leases matching a client. | |
static dhcp::DHCPMessageType | queryByHWAddr (const dhcp::HWAddrPtr &hwaddr, dhcp::Lease4Collection &leases) |
Queries LeaseMgr for active leases matching a HW address. | |
static dhcp::DHCPMessageType | queryByIpAddress (const asiolink::IOAddress &ciaddr, dhcp::Lease4Collection &leases) |
Queries for an active lease matching an ip address. | |
static void | sendResponse (const dhcp::Pkt4Ptr &response) |
Packs and sends a query response. | |
static int | upgradeHandler (hooks::CalloutHandle &handle) |
Upgrade extended information. | |
static dhcp::Lease4Collection | winnowLeases (const dhcp::Lease4Collection &leases) |
Creates a list of active leases from a list of leases. | |
Additional Inherited Members | |
![]() | |
static const isc::data::SimpleKeywords | LEASE_QUERY_KEYWORDS |
Keywords for Lease Query configuration. | |
static size_t | PageSize = 100 |
Page size to commands. | |
static bool | terminated_ = false |
Terminated flag. | |
Provides configuration and for processing DHCPv4 lease queries.
Definition at line 22 of file lease_query_impl4.h.
LeaseQueryImpl4::LeaseQueryImpl4 | ( | const data::ConstElementPtr | config | ) |
Constructor.
config | input configuration |
Definition at line 45 of file lease_query_impl4.cc.
References isc::lease_query::LeaseQueryImpl::LeaseQueryImpl().
|
inlinevirtual |
Destructor.
Definition at line 30 of file lease_query_impl4.h.
|
static |
Validates dhcp-server-identifier option in the inbound query (if one)
query | client lease query which server identifier is to be checked. | |
[out] | server_id_opt | copy of the dhcp-server-identifier in the query |
Definition at line 544 of file lease_query_impl4.cc.
References DHCP4_OPTION_SPACE, isc::dhcp::DHO_DHCP_SERVER_IDENTIFIER, isc::dhcp::CfgMgr::getCurrentCfg(), isc::dhcp::CfgMgr::instance(), isc::dhcp::IfaceMgr::instance(), isc::asiolink::IOAddress::IPV4_ZERO_ADDRESS(), and isc::asiolink::IOAddress::isV4().
Referenced by processQuery().
|
static |
Adds associated leases to a query response.
response | query response to which to add |
leases | list of active leases (if any) |
Definition at line 293 of file lease_query_impl4.cc.
References isc::dhcp::DHO_ASSOCIATED_IP.
Referenced by buildResponse().
|
static |
Adds life time, T1, and T2 options to a query response.
response | query response to which to add |
lease | newest active lease. |
subnet | lease's subnet |
Definition at line 342 of file lease_query_impl4.cc.
References isc::dhcp::DHO_CLIENT_LAST_TRANSACTION_TIME, isc::dhcp::DHO_DHCP_LEASE_TIME, isc::dhcp::DHO_DHCP_REBINDING_TIME, isc::dhcp::DHO_DHCP_RENEWAL_TIME, isc::dhcp::Lease::INFINITY_LFT, and isc::dhcp::Option::V4.
Referenced by addOptions(), and isc::lease_query::BulkLeaseQuery4::sendActive().
|
static |
Adds options to a query response.
Adds the following options to the reponse (regardless of PRL):
query | used to get associated client classes |
response | query response to which to add |
lease | newest active lease. |
Definition at line 309 of file lease_query_impl4.cc.
References addLeaseTimes(), addRelayAgentInfo(), appendServerId(), buildCfgOptionList(), isc::dhcp::DHO_DHCP_CLIENT_IDENTIFIER, isc::dhcp::CfgMgr::getCurrentCfg(), isc::dhcp::CfgMgr::instance(), isc_throw, and isc::dhcp::Option::V4.
Referenced by buildResponse().
|
static |
Adds relay-agent-info option to a query response.
response | query response to which to add |
lease | newest active lease |
Definition at line 422 of file lease_query_impl4.cc.
References isc::util::str::decodeFormattedHexString(), isc::dhcp::DHO_DHCP_AGENT_OPTIONS, isc_throw, Element::map, isc::data::UserContext::toElement(), and isc::dhcp::Option::V4.
Referenced by addOptions(), and isc::lease_query::BulkLeaseQuery4::sendActive().
|
static |
Adds dhcp-server-identifier option (54) to the response.
If the response packet does not already contain the option it, will be added either from a configured value in co_list (if one) or constructed from the response's local address.
response | packet to which the option should be added |
co_list | List of configured option sets in which to search for the option. The sets should be in the list in the order of precedence. |
Definition at line 626 of file lease_query_impl4.cc.
References DHCP4_OPTION_SPACE, isc::dhcp::DHO_DHCP_SERVER_IDENTIFIER, isc::dhcp::LibDHCP::DHO_DHCP_SERVER_IDENTIFIER_DEF(), isc::dhcp::OptionDescriptor::option_, and isc::dhcp::Option::V4.
Referenced by addOptions(), and buildResponse().
|
static |
Constructs a list of configured option sets for a given lease and it's subnet.
When lease and subnet are not provided the list will only contain the set of globally configured options. When they are provided the list will contain option sets in the following order:
[out] | co_list | list to populate |
lease | lease to use for matching options | |
subnet | to use for matching options | |
query | to get associated client classes |
Unexpected | if lease is provided but subnet is not. |
Definition at line 650 of file lease_query_impl4.cc.
References isc::dhcp::CfgMgr::getCurrentCfg(), isc::dhcp::CfgMgr::instance(), isc_throw, and isc::dhcp::Lease::TYPE_V4.
Referenced by addOptions(), and buildResponse().
|
static |
Creates a lease query response packet.
Orchestrates the construction of a response to lease query based on the response_type and list of active leases.
response_type | Message type of the response |
query | client lease query to which we are responding. |
leases | list of active leases (if any). |
Definition at line 190 of file lease_query_impl4.cc.
References addAssociatedLeases(), addOptions(), appendServerId(), buildCfgOptionList(), isc::dhcp::DHCPLEASEACTIVE, isc::dhcp::DHCPLEASEUNASSIGNED, isc::dhcp::DHCPLEASEUNKNOWN, isc::dhcp::DHO_DHCP_CLIENT_IDENTIFIER, initResponse(), and isc_throw.
Referenced by processQuery().
|
static |
Creates the initial query response.
Creates the response packet and populating basic response values based on query attributes.
response_type | Message type of the response |
query | client lease query to which we are responding |
Definition at line 251 of file lease_query_impl4.cc.
References isc::dhcp::DHO_DHCP_SERVER_IDENTIFIER, isc::dhcp::IfaceMgr::getSocket(), isc::dhcp::IfaceMgr::instance(), and isc::asiolink::IOAddress::isV4Bcast().
Referenced by buildResponse().
|
static |
Convenience method for generating per packet logging info.
packet | DHCPv4 lease query packet (query or response) |
Definition at line 465 of file lease_query_impl4.cc.
References isc::dhcp::DHO_DHCP_CLIENT_IDENTIFIER, and isc::dhcp::IdentifierType< min_size, max_size >::toText().
Referenced by buffer4_receive(), isc::lease_query::BulkLeaseQuery4::leaseQueryLabel(), and sendResponse().
|
virtual |
Processes a single DHCPv4 client Lease Query.
base_query | DHCPv4 lease query to process. |
Send the response if we have one
Implements isc::lease_query::LeaseQueryImpl.
Definition at line 50 of file lease_query_impl4.cc.
References acceptServerId(), buildResponse(), isc::dhcp::DHO_DHCP_CLIENT_IDENTIFIER, isc_throw, isc::lease_query::LeaseQueryImpl::isRequester(), isc::asiolink::IOAddress::isV4Zero(), queryByClientId(), queryByHWAddr(), queryByIpAddress(), sendResponse(), and isc::asiolink::IOAddress::toText().
|
static |
Queries LeaseMgr for active leases matching a client.
client_id | client id for which to search | |
[out] | leases | a collection of leases containing the matching leases (if one). The newest (by CLTT) will be the first lease in the collection. |
Definition at line 158 of file lease_query_impl4.cc.
References isc::dhcp::DHCPLEASEACTIVE, isc::dhcp::DHCPLEASEUNKNOWN, isc::dhcp::LeaseMgrFactory::instance(), and winnowLeases().
Referenced by processQuery().
|
static |
Queries LeaseMgr for active leases matching a HW address.
hwaddr | Hardware address for which to search | |
[out] | leases | a collection of leases containing the matching leases (if one). The newest (by CLTT) will be the first lease in the collection. |
Definition at line 165 of file lease_query_impl4.cc.
References isc::dhcp::DHCPLEASEACTIVE, isc::dhcp::DHCPLEASEUNKNOWN, isc::dhcp::LeaseMgrFactory::instance(), and winnowLeases().
Referenced by processQuery().
|
static |
Queries for an active lease matching an ip address.
ciaddr | ip address for which to search | |
[out] | leases | a collection of leases containing the matching lease (if one) |
Definition at line 126 of file lease_query_impl4.cc.
References isc::dhcp::DHCPLEASEACTIVE, isc::dhcp::DHCPLEASEUNASSIGNED, isc::dhcp::DHCPLEASEUNKNOWN, isc::dhcp::CfgMgr::getCurrentCfg(), isc::dhcp::LeaseMgr::getLease4(), isc::dhcp::CfgMgr::instance(), isc::dhcp::LeaseMgrFactory::instance(), isc::dhcp::Lease::STATE_DEFAULT, and isc::dhcp::Lease::TYPE_V4.
Referenced by processQuery().
|
static |
Packs and sends a query response.
response | query response to send |
Definition at line 497 of file lease_query_impl4.cc.
References isc::stats::StatsMgr::addValue(), isc::log::DBGLVL_TRACE_BASIC, isc::lease_query::DHCP4_LEASE_QUERY_PACKET_PACK_FAILED, isc::lease_query::DHCP4_LEASE_QUERY_RESPONSE_SENT, isc::lease_query::DHCP4_LEASE_QUERY_SEND_FAILED, isc::dhcp::DHCPLEASEACTIVE, isc::dhcp::DHCPLEASEUNASSIGNED, isc::dhcp::DHCPLEASEUNKNOWN, isc::dhcp::IfaceMgr::instance(), isc::stats::StatsMgr::instance(), isc::lease_query::lease_query_logger, leaseQueryLabel(), LOG_DEBUG, LOG_ERROR, and isc::dhcp::IfaceMgr::send().
Referenced by processQuery().
|
static |
Upgrade extended information.
Sanitize the extended information and fills relay and remoted IDs SQL new columns. Does nothing for the memfile backend.
handle | Callout handle used to retrieve a command and provide a response. |
Definition at line 711 of file lease_query_impl4.cc.
References isc::config::CONTROL_RESULT_ERROR, isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), isc::dhcp::LeaseMgrFactory::instance(), isc::lease_query::LeaseQueryImpl::PageSize, and isc::hooks::CalloutHandle::setArgument().
|
static |
Creates a list of active leases from a list of leases.
The new list will contain active leases ordered from newest to oldest by CLTT.
leases | input list of leases. |
Definition at line 172 of file lease_query_impl4.cc.
References isc::dhcp::Lease::STATE_DEFAULT.
Referenced by queryByClientId(), and queryByHWAddr().