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

Controlled version of the DHCPv4 server. More...

#include <ctrl_dhcp4_srv.h>

+ Inheritance diagram for isc::dhcp::ControlledDhcpv4Srv:

Public Member Functions

 ControlledDhcpv4Srv (uint16_t server_port=DHCP4_SERVER_PORT, uint16_t client_port=0)
 Constructor. More...
 
virtual ~ControlledDhcpv4Srv ()
 Destructor. More...
 
isc::data::ConstElementPtr checkConfig (isc::data::ConstElementPtr new_config)
 Configuration checker. More...
 
void cleanup ()
 Performs cleanup, immediately before termination. More...
 
void init (const std::string &config_file)
 Initializes the server. More...
 
isc::data::ConstElementPtr loadConfigFile (const std::string &file_name)
 Configure DHCPv4 server using the configuration file specified. More...
 
void shutdownServer (int exit_value)
 Initiates shutdown procedure for the whole DHCPv4 server. More...
 
- Public Member Functions inherited from isc::dhcp::Dhcpv4Srv
 Dhcpv4Srv (uint16_t server_port=DHCP4_SERVER_PORT, uint16_t client_port=0, const bool use_bcast=true, const bool direct_response_desired=true)
 Default constructor. More...
 
virtual ~Dhcpv4Srv ()
 Destructor. Used during DHCPv4 service shutdown. More...
 
void classifyByVendor (const Pkt4Ptr &pkt)
 Assign class using vendor-class-identifier option. More...
 
virtual void d2ClientErrorHandler (const dhcp_ddns::NameChangeSender::Result result, dhcp_ddns::NameChangeRequestPtr &ncr)
 Implements the error handler for DHCP_DDNS IO errors. More...
 
void declineLease (const Lease4Ptr &lease, const Pkt4Ptr &decline, AllocEngine::ClientContext4Ptr &context)
 Marks lease as declined. More...
 
void discardPackets ()
 Discards parked packets Clears the packet parking lots of all packets. More...
 
bool earlyGHRLookup (const Pkt4Ptr &query, AllocEngine::ClientContext4Ptr ctx)
 Initialize client context and perform early global reservations lookup. More...
 
CBControlDHCPv4Ptr getCBControl () const
 Returns an object which controls access to the configuration backends. More...
 
asiolink::IOServicePtrgetIOService ()
 Returns pointer to the IO service used by the server. More...
 
NetworkStatePtrgetNetworkState ()
 Returns pointer to the network state used by the server. More...
 
bool getSendResponsesToSource () const
 Returns value of the test_send_responses_to_source_ flag. More...
 
bool inTestMode () const
 Checks if the server is running in unit test mode. More...
 
std::list< std::list< std::string > > jsonPathsToRedact () const final override
 Return a list of all paths that contain passwords or secrets for kea-dhcp4. More...
 
void processDhcp4Query (Pkt4Ptr &query, Pkt4Ptr &rsp, bool allow_packet_park)
 Process a single incoming DHCPv4 query. More...
 
void processDhcp4QueryAndSendResponse (Pkt4Ptr &query, Pkt4Ptr &rsp, bool allow_packet_park)
 Process a single incoming DHCPv4 query. More...
 
void processPacket (Pkt4Ptr &query, Pkt4Ptr &rsp, bool allow_packet_park=true)
 Process a single incoming DHCPv4 packet. More...
 
void processPacketAndSendResponse (Pkt4Ptr &query)
 Process a single incoming DHCPv4 packet and sends the response. More...
 
void processPacketAndSendResponseNoThrow (Pkt4Ptr &query)
 Process a single incoming DHCPv4 packet and sends the response. More...
 
int run ()
 Main server processing loop. More...
 
void run_one ()
 Main server processing step. More...
 
void sendResponseNoThrow (hooks::CalloutHandlePtr &callout_handle, Pkt4Ptr &query, Pkt4Ptr &rsp)
 Process an unparked DHCPv4 packet and sends the response. More...
 
void shutdown () override
 Instructs the server to shut down. More...
 
void startD2 ()
 Starts DHCP_DDNS client IO if DDNS updates are enabled. More...
 
void stopD2 ()
 Stops DHCP_DDNS client IO if DDNS updates are enabled. More...
 
uint16_t getServerPort () const
 Get UDP port on which server should listen. More...
 
bool useBroadcast () const
 Return bool value indicating that broadcast flags should be set on sockets. More...
 
- Public Member Functions inherited from isc::process::Daemon
 Daemon ()
 Default constructor. More...
 
virtual ~Daemon ()
 Destructor. More...
 
void checkConfigFile () const
 Checks the configuration file name. More...
 
void createPIDFile (int pid=0)
 Creates the PID file. More...
 
std::string getConfigFile () const
 Returns config file name. More...
 
int getExitValue ()
 Fetches the exit value. More...
 
std::string getPIDFileDir () const
 Returns the directory used when forming default PID file name. More...
 
std::string getPIDFileName () const
 Returns the current PID file name. More...
 
isc::data::ConstElementPtr redactConfig (isc::data::ConstElementPtr const &config)
 Redact a configuration. More...
 
void setConfigFile (const std::string &config_file)
 Sets the configuration file name. More...
 
void setExitValue (int value)
 Sets the exit value. More...
 
void setPIDFileDir (const std::string &pid_file_dir)
 Sets the PID file directory. More...
 
void setPIDFileName (const std::string &pid_file_name)
 Sets PID file name. More...
 
virtual size_t writeConfigFile (const std::string &config_file, isc::data::ConstElementPtr cfg=isc::data::ConstElementPtr()) const
 Writes current configuration to specified file. More...
 

Static Public Member Functions

static ControlledDhcpv4SrvgetInstance ()
 Returns pointer to the sole instance of Dhcpv4Srv. More...
 
static isc::data::ConstElementPtr processCommand (const std::string &command, isc::data::ConstElementPtr args)
 Command processor. More...
 
static isc::data::ConstElementPtr processConfig (isc::data::ConstElementPtr new_config)
 Configuration processor. More...
 
- Static Public Member Functions inherited from isc::dhcp::Dhcpv4Srv
static int getHookIndexBuffer4Receive ()
 Returns the index for "buffer4_receive" hook point. More...
 
static int getHookIndexBuffer4Send ()
 Returns the index for "buffer4_send" hook point. More...
 
static int getHookIndexLease4Decline ()
 Returns the index for "lease4_decline" hook point. More...
 
static int getHookIndexLease4Release ()
 Returns the index for "lease4_release" hook point. More...
 
static int getHookIndexPkt4Receive ()
 Returns the index for "pkt4_receive" hook point. More...
 
static int getHookIndexPkt4Send ()
 Returns the index for "pkt4_send" hook point. More...
 
static int getHookIndexSubnet4Select ()
 Returns the index for "subnet4_select" hook point. More...
 
static std::string getVersion (bool extended)
 returns Kea version on stdout and exit. More...
 
static void processStatsReceived (const Pkt4Ptr &query)
 Class methods for DHCPv4-over-DHCPv6 handler. More...
 
static void processStatsSent (const Pkt4Ptr &response)
 Updates statistics for transmitted packets. More...
 
- Static Public Member Functions inherited from isc::process::Daemon
static void configureLogger (const isc::data::ConstElementPtr &log_config, const isc::process::ConfigPtr &storage)
 Configures logger. More...
 
static std::string getDefaultLoggerName ()
 Returns default logger name. More...
 
static std::string getProcName ()
 returns the process name This value is used as when forming the default PID file name More...
 
static bool getVerbose ()
 Returns if running in verbose mode. More...
 
static std::string getVersion (bool extended)
 returns Kea version on stdout and exits. More...
 
static void loggerInit (const char *log_name, bool verbose)
 Initializes logger. More...
 
static void setDefaultLoggerName (const std::string &logger)
 Sets the default logger name. More...
 
static void setProcName (const std::string &proc_name)
 Sets the process name. More...
 
static void setVerbose (const bool verbose)
 Sets or clears verbose mode. More...
 

Additional Inherited Members

- Public Types inherited from isc::dhcp::Dhcpv4Srv
enum  RequirementLevel { FORBIDDEN, MANDATORY, OPTIONAL }
 defines if certain option may, must or must not appear More...
 
- Static Public Attributes inherited from isc::dhcp::Dhcpv4Srv
static const std::string VENDOR_CLASS_PREFIX
 this is a prefix added to the content of vendor-class option More...
 
- Protected Member Functions inherited from isc::dhcp::Dhcpv4Srv
void adjustIfaceData (Dhcpv4Exchange &ex)
 Set IP/UDP and interface parameters for the DHCPv4 response. More...
 
void adjustRemoteAddr (Dhcpv4Exchange &ex)
 Sets remote addresses for outgoing packet. More...
 
void appendBasicOptions (Dhcpv4Exchange &ex)
 Append basic options if they are not present. More...
 
void appendRequestedOptions (Dhcpv4Exchange &ex)
 Appends options requested by client. More...
 
void appendRequestedVendorOptions (Dhcpv4Exchange &ex)
 Appends requested vendor options as requested by client. More...
 
void assignLease (Dhcpv4Exchange &ex)
 Assigns a lease and appends corresponding options. More...
 
void buildCfgOptionList (Dhcpv4Exchange &ex)
 Build the configured option list. More...
 
void classifyPacket (const Pkt4Ptr &pkt)
 Assigns incoming packet to zero or more classes. More...
 
void createNameChangeRequests (const Lease4Ptr &lease, const Lease4Ptr &old_lease, const DdnsParams &ddns_params)
 Creates NameChangeRequests which correspond to the lease which has been acquired. More...
 
void deferredUnpack (Pkt4Ptr &query)
 Perform deferred option unpacking. More...
 
void postAllocateNameUpdate (const AllocEngine::ClientContext4Ptr &ctx, const Lease4Ptr &lease, const Pkt4Ptr &query, const Pkt4Ptr &resp, bool client_name_changed)
 Update client name and DNS flags in the lease and response. More...
 
void processClientName (Dhcpv4Exchange &ex)
 Processes Client FQDN and Hostname Options sent by a client. More...
 
void processDecline (Pkt4Ptr &decline, AllocEngine::ClientContext4Ptr &context)
 Process incoming DHCPDECLINE messages. More...
 
Pkt4Ptr processDiscover (Pkt4Ptr &discover, AllocEngine::ClientContext4Ptr &context)
 Processes incoming DISCOVER and returns response. More...
 
Pkt4Ptr processInform (Pkt4Ptr &inform, AllocEngine::ClientContext4Ptr &context)
 Processes incoming DHCPINFORM messages. More...
 
void processPacketBufferSend (hooks::CalloutHandlePtr &callout_handle, Pkt4Ptr &rsp)
 Executes buffer4_send callout and sends the response. More...
 
void processPacketPktSend (hooks::CalloutHandlePtr &callout_handle, Pkt4Ptr &query, Pkt4Ptr &rsp)
 Executes pkt4_send callout. More...
 
void processRelease (Pkt4Ptr &release, AllocEngine::ClientContext4Ptr &context)
 Processes incoming DHCPRELEASE messages. More...
 
Pkt4Ptr processRequest (Pkt4Ptr &request, AllocEngine::ClientContext4Ptr &context)
 Processes incoming REQUEST and returns REPLY response. More...
 
virtual Pkt4Ptr receivePacket (int timeout)
 dummy wrapper around IfaceMgr::receive4 More...
 
void renewLease (const Pkt4Ptr &renew, Pkt4Ptr &reply)
 Attempts to renew received addresses. More...
 
void requiredClassify (Dhcpv4Exchange &ex)
 Assigns incoming packet to zero or more classes (required pass). More...
 
isc::dhcp::Subnet4Ptr selectSubnet (const Pkt4Ptr &query, bool &drop, bool sanity_only=false) const
 Selects a subnet for a given client's packet. More...
 
isc::dhcp::Subnet4Ptr selectSubnet4o6 (const Pkt4Ptr &query, bool &drop, bool sanity_only=false) const
 Selects a subnet for a given client's DHCP4o6 packet. More...
 
virtual void sendPacket (const Pkt4Ptr &pkt)
 dummy wrapper around IfaceMgr::send() More...
 
void setFixedFields (Dhcpv4Exchange &ex)
 Sets fixed fields of the outgoing packet. More...
 
void setPacketStatisticsDefaults ()
 This function sets statistics related to DHCPv4 packets processing to their initial values. More...
 
void setSendResponsesToSource (bool value)
 Sets value of the test_send_responses_to_source_ flag. More...
 
void setTeeTimes (const Lease4Ptr &lease, const Subnet4Ptr &subnet, Pkt4Ptr resp)
 Adds the T1 and T2 timers to the outbound response as appropriate. More...
 
bool accept (const Pkt4Ptr &query) const
 Checks whether received message should be processed or discarded. More...
 
bool acceptDirectRequest (const Pkt4Ptr &query) const
 Check if a message sent by directly connected client should be accepted or discarded. More...
 
bool acceptMessageType (const Pkt4Ptr &query) const
 Check if received message type is valid for the server to process. More...
 
bool acceptServerId (const Pkt4Ptr &pkt) const
 Verifies if the server id belongs to our server. More...
 
- Protected Member Functions inherited from isc::process::Daemon
std::string makePIDFileName () const
 Manufacture the pid file name. More...
 
- Static Protected Member Functions inherited from isc::dhcp::Dhcpv4Srv
static void appendServerID (Dhcpv4Exchange &ex)
 Adds server identifier option to the server's response. More...
 
static uint16_t checkRelayPort (const Dhcpv4Exchange &ex)
 Check if the relay port RAI sub-option was set in the query. More...
 
static void sanityCheck (const Pkt4Ptr &query, RequirementLevel serverid)
 Verifies if specified packet meets RFC requirements. More...
 
static std::string srvidToString (const OptionPtr &opt)
 converts server-id to text Converts content of server-id option to a text representation, e.g. More...
 
- Protected Attributes inherited from isc::dhcp::Dhcpv4Srv
boost::shared_ptr< AllocEnginealloc_engine_
 Allocation Engine. More...
 
CBControlDHCPv4Ptr cb_control_
 Controls access to the configuration backends. More...
 
uint16_t client_port_
 UDP port number to which server sends all responses. More...
 
NetworkStatePtr network_state_
 Holds information about disabled DHCP service and/or disabled subnet/network scopes. More...
 
uint16_t server_port_
 UDP port number on which server listens. More...
 
volatile bool shutdown_
 Indicates if shutdown is in progress. More...
 
bool use_bcast_
 Should broadcast be enabled on sockets (if true). More...
 
- Protected Attributes inherited from isc::process::Daemon
isc::asiolink::IOSignalSetPtr signal_set_
 A pointer to the object installing custom signal handlers. More...
 
boost::posix_time::ptime start_
 Timestamp of the start of the daemon. More...
 

Detailed Description

Controlled version of the DHCPv4 server.

This is a class that is responsible for DHCPv4 server being controllable, by reading configuration file from disk.

Definition at line 25 of file ctrl_dhcp4_srv.h.

Constructor & Destructor Documentation

◆ ControlledDhcpv4Srv()

isc::dhcp::ControlledDhcpv4Srv::ControlledDhcpv4Srv ( uint16_t  server_port = DHCP4_SERVER_PORT,
uint16_t  client_port = 0 
)

Constructor.

Parameters
server_portUDP port to be opened for DHCP traffic
client_portUDP port where all responses are sent to.

Definition at line 1054 of file ctrl_dhcp4_srv.cc.

References getInstance(), isc::dhcp::Dhcpv4Srv::getIOService(), isc::dhcp::TimerMgr::instance(), isc_throw, isc::dhcp::HostMgr::setIOService(), and isc::dhcp::LeaseMgr::setIOService().

+ Here is the call graph for this function:

◆ ~ControlledDhcpv4Srv()

Member Function Documentation

◆ checkConfig()

isc::data::ConstElementPtr isc::dhcp::ControlledDhcpv4Srv::checkConfig ( isc::data::ConstElementPtr  new_config)

Configuration checker.

This is a method for checking incoming configuration.

Parameters
new_configJSON representation of the new configuration
Returns
status of the config check

Definition at line 1036 of file ctrl_dhcp4_srv.cc.

References isc::dhcp::configureDhcp4Server(), isc::config::createAnswer(), isc::dhcp::DBG_DHCP4_COMMAND, isc::dhcp::DHCP4_CONFIG_RECEIVED, isc::dhcp::dhcp4_logger, LOG_DEBUG, and isc::process::redactConfig().

+ Here is the call graph for this function:

◆ cleanup()

void isc::dhcp::ControlledDhcpv4Srv::cleanup ( )
virtual

Performs cleanup, immediately before termination.

This method performs final clean up, just before the Dhcpv4Srv object is destroyed. Currently it is a no-op.

Reimplemented from isc::process::Daemon.

Definition at line 121 of file ctrl_dhcp4_srv.cc.

Referenced by ~ControlledDhcpv4Srv().

◆ getInstance()

static ControlledDhcpv4Srv* isc::dhcp::ControlledDhcpv4Srv::getInstance ( )
inlinestatic

Returns pointer to the sole instance of Dhcpv4Srv.

Returns
server instance (may return NULL, if called before server is spawned)

Definition at line 127 of file ctrl_dhcp4_srv.h.

Referenced by ControlledDhcpv4Srv(), and isc::dhcp::Dhcp4to6Ipc::handler().

◆ init()

void isc::dhcp::ControlledDhcpv4Srv::init ( const std::string &  config_file)

Initializes the server.

It reads the JSON file from disk or may perform any other setup operation. In particular, it also install signal handlers.

This method may throw if initialization fails.

Definition at line 92 of file ctrl_dhcp4_srv.cc.

References isc::config::CONTROL_RESULT_SUCCESS, isc_throw, and isc::config::parseAnswer().

+ Here is the call graph for this function:

◆ loadConfigFile()

ConstElementPtr isc::dhcp::ControlledDhcpv4Srv::loadConfigFile ( const std::string &  file_name)

Configure DHCPv4 server using the configuration file specified.

This utility method is called whenever we know a filename of the config and need to load it. It calls config-set command once the content of the file has been loaded and verified to be a sane JSON configuration. config-set handler will process the config file (load it as current configuration).

This function is used to both configure the DHCP server on its startup and dynamically reconfigure the server when SIGHUP signal is received.

It fetches DHCPv4 server's configuration from the 'Dhcp4' section of the JSON configuration file.

Parameters
file_namename of the file to be loaded
Returns
status of the file loading and outcome of config-set

Definition at line 126 of file ctrl_dhcp4_srv.cc.

References isc::config::CONTROL_RESULT_EMPTY, isc::config::CONTROL_RESULT_ERROR, isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), isc::dhcp::DHCP4_CB_ON_DEMAND_FETCH_UPDATES_FAIL, isc::dhcp::DHCP4_CONFIG_LOAD_FAIL, isc::dhcp::DHCP4_CONFIG_UNRECOVERABLE_ERROR, isc::dhcp::DHCP4_CONFIG_UNSUPPORTED_OBJECT, isc::dhcp::DHCP4_DYNAMIC_RECONFIGURATION, isc::dhcp::DHCP4_DYNAMIC_RECONFIGURATION_FAIL, isc::dhcp::DHCP4_DYNAMIC_RECONFIGURATION_SUCCESS, isc::dhcp::DHCP4_HOOKS_LIBS_RELOAD_FAIL, isc::dhcp::dhcp4_logger, isc::dhcp::DHCP4_MULTI_THREADING_INFO, isc::dhcp::DHCP4_NOT_RUNNING, isc::detail::getConfigReport(), isc::stats::StatsMgr::getMaxSampleAgeDefault(), isc::stats::StatsMgr::getMaxSampleCountDefault(), isc_throw, LOG_ERROR, LOG_FATAL, LOG_INFO, LOG_WARN, isc::data::Element::map, isc::config::parseAnswer(), isc::dhcp::Parser4Context::parseFile(), isc::stats::StatsMgr::statisticSetMaxSampleAgeAllHandler(), isc::stats::StatsMgr::statisticSetMaxSampleCountAllHandler(), isc::stats::toSeconds(), and isc::Exception::what().

+ Here is the call graph for this function:

◆ processCommand()

ConstElementPtr isc::dhcp::ControlledDhcpv4Srv::processCommand ( const std::string &  command,
isc::data::ConstElementPtr  args 
)
static

Command processor.

This method is uniform for all config backends. It processes received command (as a string + JSON arguments). Internally, it's just a wrapper that calls process*Command() methods and catches exceptions in them.

Currently supported commands are:

  • config-reload
  • config-test
  • shutdown
  • libreload
  • leases-reclaim ...
Note
It never throws.
Parameters
commandText representation of the command (e.g. "shutdown")
argsOptional parameters
Returns
status of the command

Definition at line 780 of file ctrl_dhcp4_srv.cc.

References isc::config::createAnswer(), isc::dhcp::DBG_DHCP4_COMMAND, isc::dhcp::DHCP4_COMMAND_RECEIVED, isc::dhcp::dhcp4_logger, LOG_DEBUG, and isc::Exception::what().

+ Here is the call graph for this function:

◆ processConfig()

isc::data::ConstElementPtr isc::dhcp::ControlledDhcpv4Srv::processConfig ( isc::data::ConstElementPtr  new_config)
static

Configuration processor.

This is a method for handling incoming configuration updates. This method should be called by all configuration backends when the server is starting up or when configuration has changed.

As pointer to this method is used a callback in ASIO used in ModuleCCSession, it has to be static.

Parameters
new_configtextual representation of the new configuration
Returns
status of the config update

Definition at line 854 of file ctrl_dhcp4_srv.cc.

References isc::dhcp::configureDhcp4Server(), isc::config::CONTROL_RESULT_ERROR, isc::config::createAnswer(), isc::dhcp::DBG_DHCP4_COMMAND, isc::dhcp::DHCP4_CONFIG_PACKET_QUEUE, isc::dhcp::DHCP4_CONFIG_RECEIVED, isc::dhcp::dhcp4_logger, isc::dhcp::Dhcpv4Srv::getIOService(), isc::dhcp::Dhcpv4Srv::getNetworkState(), isc::dhcp::Dhcpv4Srv::getServerPort(), LOG_DEBUG, LOG_INFO, isc::asiolink::IntervalTimer::ONE_SHOT, isc::config::parseAnswer(), isc::process::Daemon::redactConfig(), and isc::dhcp::Dhcpv4Srv::startD2().

+ Here is the call graph for this function:

◆ shutdownServer()

void isc::dhcp::ControlledDhcpv4Srv::shutdownServer ( int  exit_value)

Initiates shutdown procedure for the whole DHCPv4 server.

Parameters
exit_valueinteger value to the process should exit with.

Definition at line 1154 of file ctrl_dhcp4_srv.cc.

References isc::dhcp::Dhcpv4Srv::getIOService(), isc::process::Daemon::setExitValue(), and isc::dhcp::Dhcpv4Srv::shutdown().

Referenced by ~ControlledDhcpv4Srv().

+ Here is the call graph for this function:

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