Kea 3.1.1
isc::lease_query::LeaseQueryImpl4 Class Reference

Provides configuration and for processing DHCPv4 lease queries. More...

#include <lease_query_impl4.h>

+ Inheritance diagram for isc::lease_query::LeaseQueryImpl4:

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.
 
- Public Member Functions inherited from isc::lease_query::LeaseQueryImpl
 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 Public Attributes inherited from isc::lease_query::LeaseQueryImpl
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.
 

Detailed Description

Provides configuration and for processing DHCPv4 lease queries.

Definition at line 22 of file lease_query_impl4.h.

Constructor & Destructor Documentation

◆ LeaseQueryImpl4()

LeaseQueryImpl4::LeaseQueryImpl4 ( const data::ConstElementPtr config)

Constructor.

Parameters
configinput configuration

Definition at line 45 of file lease_query_impl4.cc.

References isc::lease_query::LeaseQueryImpl::LeaseQueryImpl().

+ Here is the call graph for this function:

◆ ~LeaseQueryImpl4()

virtual isc::lease_query::LeaseQueryImpl4::~LeaseQueryImpl4 ( )
inlinevirtual

Destructor.

Definition at line 30 of file lease_query_impl4.h.

Member Function Documentation

◆ acceptServerId()

bool LeaseQueryImpl4::acceptServerId ( const dhcp::Pkt4Ptr & query,
dhcp::OptionPtr & server_id_opt )
static

Validates dhcp-server-identifier option in the inbound query (if one)

Parameters
queryclient lease query which server identifier is to be checked.
[out]server_id_optcopy of the dhcp-server-identifier in the query
Returns
True if the query either contained no dhcp-server-identifier or it did and it matched a known server identifier; false otherwise.

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().

+ Here is the call graph for this function:

◆ addAssociatedLeases()

void LeaseQueryImpl4::addAssociatedLeases ( dhcp::Pkt4Ptr response,
const dhcp::Lease4Collection & leases )
static

Adds associated leases to a query response.

Parameters
responsequery response to which to add
leaseslist of active leases (if any)

Definition at line 293 of file lease_query_impl4.cc.

References isc::dhcp::DHO_ASSOCIATED_IP.

Referenced by buildResponse().

◆ addLeaseTimes()

void LeaseQueryImpl4::addLeaseTimes ( dhcp::Pkt4Ptr response,
const dhcp::Lease4Ptr & lease,
const dhcp::Subnet4Ptr & subnet )
static

Adds life time, T1, and T2 options to a query response.

Parameters
responsequery response to which to add
leasenewest active lease.
subnetlease'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().

◆ addOptions()

void LeaseQueryImpl4::addOptions ( const dhcp::Pkt4Ptr & query,
dhcp::Pkt4Ptr response,
const dhcp::Lease4Ptr & lease )
static

Adds options to a query response.

Adds the following options to the reponse (regardless of PRL):

  • DHO_DHCP_CLIENT_IDENTIFIER - if one
  • DHO_DHCP_LEASE_TIME
  • DHO_CLIENT_LAST_TRANSACTION_TIME
  • DHO_DHCP_REBINDING_TIME - if subnet configured to provide and value is sane
  • DHO_DHCP_RENEWAL_TIME - if subnet configured to provide and value is sane
  • DHO_DHCP_AGENT_OPTIONS - if one
Parameters
queryused to get associated client classes
responsequery response to which to add
leasenewest 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().

+ Here is the call graph for this function:

◆ addRelayAgentInfo()

void LeaseQueryImpl4::addRelayAgentInfo ( dhcp::Pkt4Ptr response,
const dhcp::Lease4Ptr & lease )
static

Adds relay-agent-info option to a query response.

Parameters
responsequery response to which to add
leasenewest 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().

+ Here is the call graph for this function:

◆ appendServerId()

void LeaseQueryImpl4::appendServerId ( dhcp::Pkt4Ptr & response,
dhcp::CfgOptionList & co_list )
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.

Parameters
responsepacket to which the option should be added
co_listList 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().

+ Here is the call graph for this function:

◆ buildCfgOptionList()

void LeaseQueryImpl4::buildCfgOptionList ( dhcp::CfgOptionList & co_list,
const dhcp::Pkt4Ptr & query,
const dhcp::Lease4Ptr & lease = dhcp::Lease4Ptr(),
const dhcp::Subnet4Ptr & subnet = dhcp::Subnet4Ptr() )
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:

  • Todo
    Reservation options (when/if implemented)
Note
This list built by this function could be used to support fulfilling PRL options for active leases. Currently we only use it for dhcp-server-identifier.
Parameters
[out]co_listlist to populate
leaselease to use for matching options
subnetto use for matching options
queryto get associated client classes
Exceptions
Unexpectedif lease is provided but subnet is not.
Todo
We don't support host options (yet). We Would have to look for reservations based on ip-address, mac, and or client-id. If we had class-list we skip HR lookup if for clients that are not KNOWN. host = find-host-somehow(); if (host && !host->getCfgOption4()->empty()) { co_list.push_back(host->getCfgOption4());

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().

+ Here is the call graph for this function:

◆ buildResponse()

Pkt4Ptr LeaseQueryImpl4::buildResponse ( dhcp::DHCPMessageType response_type,
const dhcp::Pkt4Ptr & query,
const dhcp::Lease4Collection & leases )
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.

Parameters
response_typeMessage type of the response
queryclient lease query to which we are responding.
leaseslist of active leases (if any).
Returns
pointer the populated response

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().

+ Here is the call graph for this function:

◆ initResponse()

Pkt4Ptr LeaseQueryImpl4::initResponse ( dhcp::DHCPMessageType response_type,
const dhcp::Pkt4Ptr & query )
static

Creates the initial query response.

Creates the response packet and populating basic response values based on query attributes.

Parameters
response_typeMessage type of the response
queryclient lease query to which we are responding
Returns
pointer to the newly constructed response packet

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().

+ Here is the call graph for this function:

◆ leaseQueryLabel()

std::string LeaseQueryImpl4::leaseQueryLabel ( const dhcp::Pkt4Ptr & packet)
static

Convenience method for generating per packet logging info.

Parameters
packetDHCPv4 lease query packet (query or response)
Returns
the query label.

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().

+ Here is the call graph for this function:

◆ processQuery()

void LeaseQueryImpl4::processQuery ( dhcp::PktPtr base_query) const
virtual

Processes a single DHCPv4 client Lease Query.

  • Validates query content
  • Determines is the query is permitted
  • Queries matching lease(s)
  • Constructs the reply
  • Sends the reply
Parameters
base_queryDHCPv4 lease query to process.
  • Validates query content

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().

+ Here is the call graph for this function:

◆ queryByClientId()

DHCPMessageType LeaseQueryImpl4::queryByClientId ( const dhcp::ClientIdPtr & client_id,
dhcp::Lease4Collection & leases )
static

Queries LeaseMgr for active leases matching a client.

Parameters
client_idclient id for which to search
[out]leasesa collection of leases containing the matching leases (if one). The newest (by CLTT) will be the first lease in the collection.
Returns
returns the message response type based on the query results:
  • DHCPLEASEACTIVE - if there are one or more active leases for the client id.
  • DHCPUNKNOWN - if there are no active leases for the client id

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().

+ Here is the call graph for this function:

◆ queryByHWAddr()

DHCPMessageType LeaseQueryImpl4::queryByHWAddr ( const dhcp::HWAddrPtr & hwaddr,
dhcp::Lease4Collection & leases )
static

Queries LeaseMgr for active leases matching a HW address.

Parameters
hwaddrHardware address for which to search
[out]leasesa collection of leases containing the matching leases (if one). The newest (by CLTT) will be the first lease in the collection.
Returns
returns the message response type based on the query results:
  • DHCPLEASEACTIVE - if there are one or more active leases for the hardware address
  • DHCPUNKNOWN - if there are no active leases for the hardware address

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().

+ Here is the call graph for this function:

◆ queryByIpAddress()

DHCPMessageType LeaseQueryImpl4::queryByIpAddress ( const asiolink::IOAddress & ciaddr,
dhcp::Lease4Collection & leases )
static

Queries for an active lease matching an ip address.

Parameters
ciaddrip address for which to search
[out]leasesa collection of leases containing the matching lease (if one)
Returns
returns the message response type based on the query results:
  • DHCPLEASEACTIVE - if there is an active lease for the ip address
  • DHCPLEASEUNASSIGNED - if ip address is one the server knows about but for which there is no currently active lease
  • DHCPUNKNOWN - it the ip address is not one the server knows about

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().

+ Here is the call graph for this function:

◆ sendResponse()

void LeaseQueryImpl4::sendResponse ( const dhcp::Pkt4Ptr & response)
static

◆ upgradeHandler()

int LeaseQueryImpl4::upgradeHandler ( hooks::CalloutHandle & handle)
static

Upgrade extended information.

Sanitize the extended information and fills relay and remoted IDs SQL new columns. Does nothing for the memfile backend.

Parameters
handleCallout 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().

+ Here is the call graph for this function:

◆ winnowLeases()

Lease4Collection LeaseQueryImpl4::winnowLeases ( const dhcp::Lease4Collection & leases)
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.

Parameters
leasesinput list of leases.
Returns
Cleaned list of leases.

Definition at line 172 of file lease_query_impl4.cc.

References isc::dhcp::Lease::STATE_DEFAULT.

Referenced by queryByClientId(), and queryByHWAddr().


The documentation for this class was generated from the following files: