Kea  2.1.7-git
isc::dhcp::Dhcpv4Exchange Class Reference

DHCPv4 message exchange. More...

#include <dhcp4_srv.h>

Public Member Functions

 Dhcpv4Exchange (const AllocEnginePtr &alloc_engine, const Pkt4Ptr &query, AllocEngine::ClientContext4Ptr &context, const Subnet4Ptr &subnet, bool &drop)
 Constructor. More...
 
void conditionallySetReservedClientClasses ()
 Assigns classes retrieved from host reservation database if they haven't been yet set. More...
 
void deleteResponse ()
 Removes the response message by resetting the pointer to NULL. More...
 
CfgOptionListgetCfgOptionList ()
 Returns the configured option list (non-const version) More...
 
const CfgOptionListgetCfgOptionList () const
 Returns the configured option list (const version) More...
 
AllocEngine::ClientContext4Ptr getContext () const
 Returns the copy of the context for the Allocation engine. More...
 
Pkt4Ptr getQuery () const
 Returns the pointer to the query from the client. More...
 
Pkt4Ptr getResponse () const
 Returns the pointer to the server's response. More...
 
void initResponse ()
 Initializes the instance of the response message. More...
 
void initResponse4o6 ()
 Initializes the DHCPv6 part of the response message. More...
 
void setReservedMessageFields ()
 Sets reserved values of siaddr, sname and file in the server's response. More...
 

Static Public Member Functions

static void classifyByVendor (const Pkt4Ptr &pkt)
 Assign class using vendor-class-identifier option. More...
 
static void classifyPacket (const Pkt4Ptr &pkt)
 Assigns incoming packet to zero or more classes. More...
 
static void evaluateClasses (const Pkt4Ptr &pkt, bool depend_on_known)
 Evaluate classes. More...
 
static void removeDependentEvaluatedClasses (const Pkt4Ptr &query)
 Removed evaluated client classes. More...
 
static void setHostIdentifiers (AllocEngine::ClientContext4Ptr context)
 Set host identifiers within a context. More...
 
static void setReservedClientClasses (AllocEngine::ClientContext4Ptr context)
 Assigns classes retrieved from host reservation database. More...
 

Detailed Description

DHCPv4 message exchange.

This class represents the DHCPv4 message exchange. The message exchange consists of the single client message, server response to this message and the mechanisms to generate the server's response. The server creates the instance of the Dhcpv4Exchange for each inbound message that it accepts for processing.

The use of the Dhcpv4Exchange object as a central repository of information about the message exchange simplifies the API of the Dhcpv4Srv class.

Another benefit of using this class is that different methods of the Dhcpv4Srv may share information. For example, the constructor of this class selects the subnet and multiple methods of Dhcpv4Srv use this subnet, without the need to select it again.

Todo:
This is the initial version of this class. In the future a lot of code from the Dhcpv4Srv class will be migrated here.

Definition at line 62 of file dhcp4_srv.h.

Constructor & Destructor Documentation

◆ Dhcpv4Exchange()

isc::dhcp::Dhcpv4Exchange::Dhcpv4Exchange ( const AllocEnginePtr alloc_engine,
const Pkt4Ptr query,
AllocEngine::ClientContext4Ptr context,
const Subnet4Ptr subnet,
bool &  drop 
)

Constructor.

The constructor selects the subnet for the query and checks for the static host reservations for the client which has sent the message. The information about the reservations is stored in the AllocEngine::ClientContext4 object, which can be obtained by calling the getContext.

Parameters
alloc_enginePointer to the instance of the Allocation Engine used by the server.
queryPointer to the client message.
contextPointer to the client context.
subnetPointer to the subnet to which the client belongs.
dropif it is true the packet will be dropped.

Definition at line 151 of file dhcp4_srv.cc.

References isc::stats::StatsMgr::addValue(), isc::dhcp::DBG_DHCP4_BASIC, isc::log::DBGLVL_PKT_HANDLING, isc::dhcp::DHCP4_CLASS_ASSIGNED, isc::dhcp::dhcp4_logger, isc::dhcp::DHCP4_PACKET_DROP_0013, isc::dhcp::DHO_DHCP_CLIENT_IDENTIFIER, isc::dhcp::ClientClasses::empty(), evaluateClasses(), initResponse(), isc::stats::StatsMgr::instance(), isc_throw, LOG_DEBUG, isc::dhcp::packet4_logger, removeDependentEvaluatedClasses(), setHostIdentifiers(), setReservedClientClasses(), and isc::dhcp::ClientClasses::toText().

+ Here is the call graph for this function:

Member Function Documentation

◆ classifyByVendor()

void isc::dhcp::Dhcpv4Exchange::classifyByVendor ( const Pkt4Ptr pkt)
static

Assign class using vendor-class-identifier option.

Note
This is the first part of classifyPacket
Parameters
pktpacket to be classified

Definition at line 553 of file dhcp4_srv.cc.

References isc::dhcp::DHO_VENDOR_CLASS_IDENTIFIER, and isc::dhcp::Dhcpv4Srv::VENDOR_CLASS_PREFIX.

Referenced by classifyPacket(), and getCfgOptionList().

◆ classifyPacket()

void isc::dhcp::Dhcpv4Exchange::classifyPacket ( const Pkt4Ptr pkt)
static

Assigns incoming packet to zero or more classes.

Note
This is done in two phases: first the content of the vendor-class-identifier option is used as a class, by calling classifyByVendor(). Second, the classification match expressions are evaluated. The resulting classes will be stored in the packet (see isc::dhcp::Pkt4::classes_ and isc::dhcp::Pkt4::inClass).
Parameters
pktpacket to be classified

Definition at line 565 of file dhcp4_srv.cc.

References classifyByVendor(), and evaluateClasses().

Referenced by isc::dhcp::Dhcpv4Srv::classifyPacket(), and getCfgOptionList().

+ Here is the call graph for this function:

◆ conditionallySetReservedClientClasses()

void isc::dhcp::Dhcpv4Exchange::conditionallySetReservedClientClasses ( )

Assigns classes retrieved from host reservation database if they haven't been yet set.

This function sets reserved client classes in case they haven't been set after fetching host reservations from the database. This is the case when the client has non-global host reservation and the selected subnet belongs to a shared network.

Definition at line 517 of file dhcp4_srv.cc.

References setReservedClientClasses().

Referenced by getCfgOptionList(), isc::dhcp::Dhcpv4Srv::processDiscover(), isc::dhcp::Dhcpv4Srv::processInform(), and isc::dhcp::Dhcpv4Srv::processRequest().

+ Here is the call graph for this function:

◆ deleteResponse()

void isc::dhcp::Dhcpv4Exchange::deleteResponse ( )
inline

Removes the response message by resetting the pointer to NULL.

Definition at line 108 of file dhcp4_srv.h.

Referenced by isc::dhcp::Dhcpv4Srv::assignLease().

◆ evaluateClasses()

void isc::dhcp::Dhcpv4Exchange::evaluateClasses ( const Pkt4Ptr pkt,
bool  depend_on_known 
)
static

Evaluate classes.

Note
Second part of the classification.

Evaluate expressions of client classes: if it returns true the class is added to the incoming packet.

Parameters
pktpacket to be classified.
depend_on_knownif false classes depending on the KNOWN or UNKNOWN classes are skipped, if true only these classes are evaluated.

Definition at line 576 of file dhcp4_srv.cc.

References isc::dhcp::DBG_DHCP4_DETAIL, isc::dhcp::EVAL_RESULT, isc::dhcp::evaluateBool(), isc::dhcp::CfgMgr::getCurrentCfg(), isc::dhcp::CfgMgr::instance(), LOG_DEBUG, LOG_ERROR, LOG_INFO, isc::dhcp::options4_logger, isc::dhcp::Dhcpv4Srv::VENDOR_CLASS_PREFIX, and isc::Exception::what().

Referenced by classifyPacket(), Dhcpv4Exchange(), isc::dhcp::Dhcpv4Srv::earlyGHRLookup(), and getCfgOptionList().

+ Here is the call graph for this function:

◆ getCfgOptionList() [1/2]

CfgOptionList& isc::dhcp::Dhcpv4Exchange::getCfgOptionList ( )
inline

◆ getCfgOptionList() [2/2]

const CfgOptionList& isc::dhcp::Dhcpv4Exchange::getCfgOptionList ( ) const
inline

Returns the configured option list (const version)

Definition at line 123 of file dhcp4_srv.h.

References classifyByVendor(), classifyPacket(), conditionallySetReservedClientClasses(), evaluateClasses(), removeDependentEvaluatedClasses(), setHostIdentifiers(), setReservedClientClasses(), and setReservedMessageFields().

+ Here is the call graph for this function:

◆ getContext()

◆ getQuery()

◆ getResponse()

◆ initResponse()

void isc::dhcp::Dhcpv4Exchange::initResponse ( )

Initializes the instance of the response message.

The type of the response depends on the type of the query message. For the DHCPDISCOVER the DHCPOFFER is created. For the DHCPREQUEST and DHCPINFORM the DHCPACK is created. For the DHCPRELEASE the response is not initialized.

Definition at line 270 of file dhcp4_srv.cc.

References isc::dhcp::DHCPACK, isc::dhcp::DHCPDISCOVER, isc::dhcp::DHCPINFORM, isc::dhcp::DHCPOFFER, isc::dhcp::DHCPREQUEST, getQuery(), and initResponse4o6().

Referenced by Dhcpv4Exchange().

+ Here is the call graph for this function:

◆ initResponse4o6()

void isc::dhcp::Dhcpv4Exchange::initResponse4o6 ( )

◆ removeDependentEvaluatedClasses()

void isc::dhcp::Dhcpv4Exchange::removeDependentEvaluatedClasses ( const Pkt4Ptr query)
static

Removed evaluated client classes.

Todo:
: keep the list of dependent evaluated classes so remove only them.
Parameters
querythe query message.

Definition at line 491 of file dhcp4_srv.cc.

References isc::dhcp::CfgMgr::getCurrentCfg(), and isc::dhcp::CfgMgr::instance().

Referenced by Dhcpv4Exchange(), isc::dhcp::Dhcpv4Srv::earlyGHRLookup(), and getCfgOptionList().

+ Here is the call graph for this function:

◆ setHostIdentifiers()

void isc::dhcp::Dhcpv4Exchange::setHostIdentifiers ( AllocEngine::ClientContext4Ptr  context)
static

Set host identifiers within a context.

This method sets an ordered list of host identifier types and values which the server should use to find host reservations. The order of the set is determined by the configuration parameter, host-reservation-identifiers

Parameters
contextpointer to the context.

Definition at line 390 of file dhcp4_srv.cc.

References isc::log::DBGLVL_TRACE_BASIC, isc::dhcp::DHCP4_FLEX_ID, isc::dhcp::DHO_DHCP_AGENT_OPTIONS, isc::dhcp::getCalloutHandle(), isc::dhcp::CfgMgr::getCurrentCfg(), isc::dhcp::Host::getIdentifierAsText(), isc::dhcp::Host::IDENT_CIRCUIT_ID, isc::dhcp::Host::IDENT_CLIENT_ID, isc::dhcp::Host::IDENT_DUID, isc::dhcp::Host::IDENT_FLEX, isc::dhcp::Host::IDENT_HWADDR, isc::dhcp::CfgMgr::instance(), LOG_DEBUG, and isc::dhcp::packet4_logger.

Referenced by Dhcpv4Exchange(), isc::dhcp::Dhcpv4Srv::earlyGHRLookup(), and getCfgOptionList().

+ Here is the call graph for this function:

◆ setReservedClientClasses()

void isc::dhcp::Dhcpv4Exchange::setReservedClientClasses ( AllocEngine::ClientContext4Ptr  context)
static

Assigns classes retrieved from host reservation database.

Parameters
contextpointer to the context.

Definition at line 506 of file dhcp4_srv.cc.

References isc::dhcp::ClientClasses::cbegin(), and isc::dhcp::ClientClasses::cend().

Referenced by conditionallySetReservedClientClasses(), Dhcpv4Exchange(), and getCfgOptionList().

+ Here is the call graph for this function:

◆ setReservedMessageFields()

void isc::dhcp::Dhcpv4Exchange::setReservedMessageFields ( )

Sets reserved values of siaddr, sname and file in the server's response.

Definition at line 531 of file dhcp4_srv.cc.

Referenced by getCfgOptionList(), and isc::dhcp::Dhcpv4Srv::setFixedFields().


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