Kea 2.7.5
|
Controlled version of the DHCPv4 server. More...
#include <ctrl_dhcp4_srv.h>
Public Member Functions | |
ControlledDhcpv4Srv (uint16_t server_port=DHCP4_SERVER_PORT, uint16_t client_port=0) | |
Constructor. | |
virtual | ~ControlledDhcpv4Srv () |
Destructor. | |
void | cleanup () |
Performs cleanup, immediately before termination. | |
void | init (const std::string &config_file) |
Initializes the server. | |
isc::data::ConstElementPtr | loadConfigFile (const std::string &file_name) |
Configure DHCPv4 server using the configuration file specified. | |
virtual void | shutdownServer (int exit_value) |
Initiates shutdown procedure for the whole DHCPv4 server. | |
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. | |
virtual | ~Dhcpv4Srv () |
Destructor. Used during DHCPv4 service shutdown. | |
CBControlDHCPv4Ptr | getCBControl () const |
Returns an object which controls access to the configuration backends. | |
asiolink::IOServicePtr & | getIOService () |
Returns pointer to the IO service used by the server. | |
NetworkStatePtr & | getNetworkState () |
Returns pointer to the network state used by the server. | |
bool | inTestMode () const |
Checks if the server is running in unit test mode. | |
Pkt4Ptr | processDhcp4Query (Pkt4Ptr query, bool allow_answer_park) |
Process a single incoming DHCPv4 query. | |
void | processDhcp4QueryAndSendResponse (Pkt4Ptr query, bool allow_answer_park) |
Process a single incoming DHCPv4 query. | |
Pkt4Ptr | processLocalizedQuery4 (AllocEngine::ClientContext4Ptr &ctx, bool allow_answer_park) |
Process a localized incoming DHCPv4 query. | |
void | processLocalizedQuery4AndSendResponse (Pkt4Ptr query, AllocEngine::ClientContext4Ptr &ctx, bool allow_answer_park) |
Process a localized incoming DHCPv4 query. | |
void | processLocalizedQuery4AndSendResponse (Pkt4Ptr query, bool allow_answer_park) |
Process a localized incoming DHCPv4 query. | |
Pkt4Ptr | processPacket (Pkt4Ptr query, bool allow_answer_park=true) |
Process a single incoming DHCPv4 packet. | |
void | processPacketAndSendResponse (Pkt4Ptr query) |
Process a single incoming DHCPv4 packet and sends the response. | |
void | processPacketAndSendResponseNoThrow (Pkt4Ptr query) |
Process a single incoming DHCPv4 packet and sends the response. | |
int | run () |
Main server processing loop. | |
void | runOne () |
Main server processing step. | |
void | sendResponseNoThrow (hooks::CalloutHandlePtr &callout_handle, Pkt4Ptr &query, Pkt4Ptr &rsp, ConstSubnet4Ptr &subnet) |
Process an unparked DHCPv4 packet and sends the response. | |
void | shutdown () override |
Instructs the server to shut down. | |
uint16_t | getServerPort () const |
Get UDP port on which server should listen. | |
bool | useBroadcast () const |
Return bool value indicating that broadcast flags should be set on sockets. | |
void | startD2 () |
Starts DHCP_DDNS client IO if DDNS updates are enabled. | |
void | stopD2 () |
Stops DHCP_DDNS client IO if DDNS updates are enabled. | |
virtual void | d2ClientErrorHandler (const dhcp_ddns::NameChangeSender::Result result, dhcp_ddns::NameChangeRequestPtr &ncr) |
Implements the error handler for DHCP_DDNS IO errors. | |
void | discardPackets () |
Discards parked packets Clears the packet parking lots of all packets. | |
bool | getSendResponsesToSource () const |
Returns value of the test_send_responses_to_source_ flag. | |
void | initContext0 (const Pkt4Ptr &query, AllocEngine::ClientContext4Ptr ctx) |
Initialize client context (first part). | |
bool | earlyGHRLookup (const Pkt4Ptr &query, AllocEngine::ClientContext4Ptr ctx) |
Initialize client context and perform early global reservations lookup. | |
void | declineLease (const Lease4Ptr &lease, const Pkt4Ptr &decline, AllocEngine::ClientContext4Ptr &context) |
Marks lease as declined. | |
std::list< std::list< std::string > > | jsonPathsToRedact () const final override |
Return a list of all paths that contain passwords or secrets for kea-dhcp4. | |
Public Member Functions inherited from isc::process::Daemon | |
Daemon () | |
Default constructor. | |
virtual | ~Daemon () |
Destructor. | |
void | checkConfigFile () const |
Checks the configuration file name. | |
void | createPIDFile (int pid=0) |
Creates the PID file. | |
std::string | getConfigFile () const |
Returns config file name. | |
int | getExitValue () |
Fetches the exit value. | |
std::string | getPIDFileDir () const |
Returns the directory used when forming default PID file name. | |
std::string | getPIDFileName () const |
Returns the current PID file name. | |
isc::data::ConstElementPtr | redactConfig (isc::data::ConstElementPtr const &config) |
Redact a configuration. | |
void | setConfigFile (const std::string &config_file) |
Sets the configuration file name. | |
void | setExitValue (int value) |
Sets the exit value. | |
void | setPIDFileDir (const std::string &pid_file_dir) |
Sets the PID file directory. | |
void | setPIDFileName (const std::string &pid_file_name) |
Sets PID file name. | |
virtual size_t | writeConfigFile (const std::string &config_file, isc::data::ConstElementPtr cfg=isc::data::ConstElementPtr()) const |
Writes current configuration to specified file. | |
Static Public Member Functions | |
static isc::data::ConstElementPtr | checkConfig (isc::data::ConstElementPtr config) |
Configuration checker. | |
static isc::data::ConstElementPtr | finishConfigHookLibraries (isc::data::ConstElementPtr config) |
Configuration checker for hook libraries. | |
static ControlledDhcpv4Srv * | getInstance () |
Returns pointer to the sole instance of Dhcpv4Srv. | |
static isc::data::ConstElementPtr | processConfig (isc::data::ConstElementPtr config) |
Configuration processor. | |
Static Public Member Functions inherited from isc::dhcp::Dhcpv4Srv | |
static std::string | getVersion (bool extended) |
returns Kea version on stdout and exit. | |
static void | processStatsReceived (const Pkt4Ptr &query) |
Class methods for DHCPv4-over-DHCPv6 handler. | |
static void | processStatsSent (const Pkt4Ptr &response) |
Updates statistics for transmitted packets. | |
static int | getHookIndexBuffer4Receive () |
Returns the index for "buffer4_receive" hook point. | |
static int | getHookIndexPkt4Receive () |
Returns the index for "pkt4_receive" hook point. | |
static int | getHookIndexSubnet4Select () |
Returns the index for "subnet4_select" hook point. | |
static int | getHookIndexLease4Release () |
Returns the index for "lease4_release" hook point. | |
static int | getHookIndexPkt4Send () |
Returns the index for "pkt4_send" hook point. | |
static int | getHookIndexBuffer4Send () |
Returns the index for "buffer4_send" hook point. | |
static int | getHookIndexLease4Decline () |
Returns the index for "lease4_decline" hook point. | |
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. | |
static std::string | getDefaultLoggerName () |
Returns default logger name. | |
static std::string | getProcName () |
returns the process name This value is used as when forming the default PID file name | |
static bool | getVerbose () |
Returns if running in verbose mode. | |
static std::string | getVersion (bool extended) |
returns Kea version on stdout and exits. | |
static void | loggerInit (const char *log_name, bool verbose) |
Initializes logger. | |
static void | setDefaultLoggerName (const std::string &logger) |
Sets the default logger name. | |
static void | setProcName (const std::string &proc_name) |
Sets the process name. | |
static void | setVerbose (const bool verbose) |
Sets or clears verbose mode. | |
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 | |
Protected Member Functions inherited from isc::dhcp::Dhcpv4Srv | |
bool | accept (const Pkt4Ptr &query) |
Checks whether received message should be processed or discarded. | |
bool | acceptDirectRequest (const Pkt4Ptr &query) |
Check if a message sent by directly connected client should be accepted or discarded. | |
bool | acceptMessageType (const Pkt4Ptr &query) const |
Check if received message type is valid for the server to process. | |
bool | acceptServerId (const Pkt4Ptr &pkt) const |
Verifies if the server id belongs to our server. | |
Pkt4Ptr | processDiscover (Pkt4Ptr &discover, AllocEngine::ClientContext4Ptr &context) |
Processes incoming DISCOVER and returns response. | |
Pkt4Ptr | processRequest (Pkt4Ptr &request, AllocEngine::ClientContext4Ptr &context) |
Processes incoming REQUEST and returns REPLY response. | |
void | processRelease (Pkt4Ptr &release, AllocEngine::ClientContext4Ptr &context) |
Processes incoming DHCPRELEASE messages. | |
void | processDecline (Pkt4Ptr &decline, AllocEngine::ClientContext4Ptr &context) |
Process incoming DHCPDECLINE messages. | |
Pkt4Ptr | processInform (Pkt4Ptr &inform, AllocEngine::ClientContext4Ptr &context) |
Processes incoming DHCPINFORM messages. | |
void | buildCfgOptionList (Dhcpv4Exchange &ex) |
Build the configured option list. | |
void | appendRequestedOptions (Dhcpv4Exchange &ex) |
Appends options requested by client. | |
void | appendRequestedVendorOptions (Dhcpv4Exchange &ex) |
Appends requested vendor options as requested by client. | |
bool | assignZero (ConstSubnet4Ptr &subnet, const ClientClasses &client_classes) |
Assign the 0.0.0.0 address to an IPv6-Only client. | |
void | assignLease (Dhcpv4Exchange &ex) |
Assigns a lease and appends corresponding options. | |
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. | |
void | setTeeTimes (const Lease4Ptr &lease, const ConstSubnet4Ptr &subnet, Pkt4Ptr resp) |
Adds the T1 and T2 timers to the outbound response as appropriate. | |
void | appendBasicOptions (Dhcpv4Exchange &ex) |
Append basic options if they are not present. | |
void | setFixedFields (Dhcpv4Exchange &ex) |
Sets fixed fields of the outgoing packet. | |
void | processClientName (Dhcpv4Exchange &ex) |
Processes Client FQDN and Hostname Options sent by a client. | |
void | setPacketStatisticsDefaults () |
This function sets statistics related to DHCPv4 packets processing to their initial values. | |
void | setSendResponsesToSource (bool value) |
Sets value of the test_send_responses_to_source_ flag. | |
void | serverDecline (hooks::CalloutHandlePtr &callout_handle, Pkt4Ptr &query, Lease4Ptr lease, bool lease_exists) |
Renders a lease declined after the server has detected, via ping-check or other means, that its address is already in-use. | |
void | serverDeclineNoThrow (hooks::CalloutHandlePtr &callout_handle, Pkt4Ptr &query, Lease4Ptr lease, bool lease_exists) |
Exception safe wrapper around serverDecline() | |
void | createNameChangeRequests (const Lease4Ptr &lease, const Lease4Ptr &old_lease, const DdnsParams &ddns_params) |
Creates NameChangeRequests which correspond to the lease which has been acquired. | |
void | renewLease (const Pkt4Ptr &renew, Pkt4Ptr &reply) |
Attempts to renew received addresses. | |
void | adjustIfaceData (Dhcpv4Exchange &ex) |
Set IP/UDP and interface parameters for the DHCPv4 response. | |
void | adjustRemoteAddr (Dhcpv4Exchange &ex) |
Sets remote addresses for outgoing packet. | |
isc::dhcp::ConstSubnet4Ptr | selectSubnet (const Pkt4Ptr &query, bool &drop, bool sanity_only=false, bool allow_answer_park=true) |
Selects a subnet for a given client's packet. | |
isc::dhcp::ConstSubnet4Ptr | selectSubnet4o6 (const Pkt4Ptr &query, bool &drop, bool sanity_only=false, bool allow_answer_park=true) |
Selects a subnet for a given client's DHCP4o6 packet. | |
virtual Pkt4Ptr | receivePacket (int timeout) |
dummy wrapper around IfaceMgr::receive4 | |
virtual void | sendPacket (const Pkt4Ptr &pkt) |
dummy wrapper around IfaceMgr::send() | |
void | classifyPacket (const Pkt4Ptr &pkt) |
Assigns incoming packet to zero or more classes. | |
void | recoverStashedAgentOption (const Pkt4Ptr &query) |
Recover stashed agent options from client address lease. | |
void | evaluateAdditionalClasses (Dhcpv4Exchange &ex) |
Evaluates classes in the additional classes lists. | |
void | deferredUnpack (Pkt4Ptr &query) |
Perform deferred option unpacking. | |
void | processPacketPktSend (hooks::CalloutHandlePtr &callout_handle, Pkt4Ptr &query, Pkt4Ptr &rsp, ConstSubnet4Ptr &subnet) |
Executes pkt4_send callout. | |
void | processPacketBufferSend (hooks::CalloutHandlePtr &callout_handle, Pkt4Ptr &rsp) |
Executes buffer4_send callout and sends the response. | |
Protected Member Functions inherited from isc::process::Daemon | |
std::string | makePIDFileName () const |
Manufacture the pid file name. | |
Static Protected Member Functions inherited from isc::dhcp::Dhcpv4Srv | |
static void | sanityCheck (const Pkt4Ptr &query) |
Verifies if specified packet meets RFC requirements. | |
static void | sanityCheck (const Pkt4Ptr &query, RequirementLevel serverid) |
Verifies if specified packet meets RFC requirements. | |
static void | appendServerID (Dhcpv4Exchange &ex) |
Adds server identifier option to the server's response. | |
static uint16_t | checkRelayPort (const Dhcpv4Exchange &ex) |
Check if the relay port RAI sub-option was set in the query. | |
static std::string | srvidToString (const OptionPtr &opt) |
converts server-id to text Converts content of server-id option to a text representation, e.g. | |
Protected Attributes inherited from isc::dhcp::Dhcpv4Srv | |
uint16_t | server_port_ |
UDP port number on which server listens. | |
uint16_t | client_port_ |
UDP port number to which server sends all responses. | |
volatile bool | shutdown_ |
Indicates if shutdown is in progress. | |
boost::shared_ptr< AllocEngine > | alloc_engine_ |
Allocation Engine. | |
bool | use_bcast_ |
Should broadcast be enabled on sockets (if true). | |
NetworkStatePtr | network_state_ |
Holds information about disabled DHCP service and/or disabled subnet/network scopes. | |
CBControlDHCPv4Ptr | cb_control_ |
Controls access to the configuration backends. | |
Protected Attributes inherited from isc::process::Daemon | |
isc::asiolink::IOSignalSetPtr | signal_set_ |
A pointer to the object installing custom signal handlers. | |
boost::posix_time::ptime | start_ |
Timestamp of the start of the daemon. | |
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.
isc::dhcp::ControlledDhcpv4Srv::ControlledDhcpv4Srv | ( | uint16_t | server_port = DHCP4_SERVER_PORT, |
uint16_t | client_port = 0 ) |
Constructor.
server_port | UDP port to be opened for DHCP traffic |
client_port | UDP port where all responses are sent to. |
Definition at line 1431 of file ctrl_dhcp4_srv.cc.
References isc::config::HttpCommandConfig::DEFAULT_AUTHENTICATION_REALM, getInstance(), isc::dhcp::Dhcpv4Srv::getIOService(), isc::config::CommandMgr::instance(), isc::config::HttpCommandMgr::instance(), isc::config::UnixCommandMgr::instance(), isc::dhcp::TimerMgr::instance(), isc_throw, isc::db::DatabaseConnection::setIOService(), isc::asiolink::ProcessSpawn::setIOService(), isc::stats::StatsMgr::statisticGetAllHandler(), isc::stats::StatsMgr::statisticGetHandler(), isc::stats::StatsMgr::statisticRemoveAllHandler(), isc::stats::StatsMgr::statisticRemoveHandler(), isc::stats::StatsMgr::statisticResetAllHandler(), isc::stats::StatsMgr::statisticResetHandler(), isc::stats::StatsMgr::statisticSetMaxSampleAgeHandler(), and isc::stats::StatsMgr::statisticSetMaxSampleCountHandler().
|
virtual |
Destructor.
Definition at line 1547 of file ctrl_dhcp4_srv.cc.
References cleanup(), isc::dhcp::HostMgr::create(), isc::db::DatabaseConnection::db_failed_callback_, isc::db::DatabaseConnection::db_lost_callback_, isc::db::DatabaseConnection::db_recovered_callback_, isc::dhcp::LeaseMgrFactory::destroy(), isc::config::CommandMgr::instance(), isc::config::HttpCommandMgr::instance(), isc::config::UnixCommandMgr::instance(), isc::util::MultiThreadingMgr::instance(), and isc::db::DatabaseConnection::setIOService().
|
static |
Configuration checker.
This is a method for checking incoming configuration.
config | JSON representation of the new configuration |
Definition at line 1416 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_RECEIVED, isc::dhcp::dhcp4_logger, getInstance(), and LOG_DEBUG.
|
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.
References isc::dhcp::Dhcpv4Srv::getIOService(), and isc::process::Daemon::signal_set_.
Referenced by ~ControlledDhcpv4Srv().
|
static |
Configuration checker for hook libraries.
This is a method for checking incoming configuration in the hooks libraries. It calls dhcp4_srv_configured hook point for all hooks.
config | JSON representation of the new configuration |
Definition at line 1382 of file ctrl_dhcp4_srv.cc.
References isc::hooks::HooksManager::callCallouts(), isc::hooks::HooksManager::calloutsPresent(), isc::config::CONTROL_RESULT_ERROR, isc::config::createAnswer(), isc::hooks::HooksManager::createCalloutHandle(), isc::db::error, getInstance(), Hooks, isc::dhcp::CfgMgr::instance(), and isc::hooks::CalloutHandle::NEXT_STEP_DROP.
Referenced by isc::dhcp::configureDhcp4Server(), and processConfig().
|
inlinestatic |
Returns pointer to the sole instance of Dhcpv4Srv.
Definition at line 114 of file ctrl_dhcp4_srv.h.
Referenced by ControlledDhcpv4Srv(), checkConfig(), finishConfigHookLibraries(), isc::dhcp::Dhcp4to6Ipc::handler(), and processConfig().
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 96 of file ctrl_dhcp4_srv.cc.
References isc::config::CONTROL_RESULT_SUCCESS, isc::dhcp::Dhcpv4Srv::getIOService(), isc_throw, loadConfigFile(), isc::config::parseAnswer(), isc::process::Daemon::signal_set_, and isc::process::Daemon::start_.
ConstElementPtr isc::dhcp::ControlledDhcpv4Srv::loadConfigFile | ( | const std::string & | file_name | ) |
Configure DHCPv4 server using the configuration file specified.
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.
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 (apply it as current configuration).
file_name | name of the file to be loaded |
Definition at line 127 of file ctrl_dhcp4_srv.cc.
References isc::config::CONTROL_RESULT_SUCCESS, isc::config::createCommand(), isc::dhcp::DHCP4_CONFIG_LOAD_FAIL, isc::dhcp::dhcp4_logger, isc::dhcp::DHCP4_MULTI_THREADING_INFO, isc::config::CommandMgr::instance(), isc::dhcp::CfgMgr::instance(), isc::util::MultiThreadingMgr::instance(), isc_throw, LOG_ERROR, LOG_WARN, isc::data::Element::map, isc::config::parseAnswer(), isc::dhcp::Parser4Context::parseFile(), isc::dhcp::Parser4Context::PARSER_DHCP4, and isc::Exception::what().
Referenced by init().
|
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.
config | textual representation of the new configuration |
Definition at line 1191 of file ctrl_dhcp4_srv.cc.
References isc::dhcp::CfgMultiThreading::apply(), isc::dhcp::LibDHCP::commitRuntimeOptionDefs(), isc::dhcp::configureDhcp4Server(), isc::config::CONTROL_RESULT_ERROR, isc::dhcp::HostMgr::create(), isc::config::createAnswer(), isc::db::DatabaseConnection::db_failed_callback_, isc::db::DatabaseConnection::db_lost_callback_, isc::db::DatabaseConnection::db_recovered_callback_, isc::dhcp::DBG_DHCP4_COMMAND, isc::dhcp::LeaseMgrFactory::destroy(), isc::dhcp::DHCP4_CONFIG_PACKET_QUEUE, isc::dhcp::DHCP4_CONFIG_RECEIVED, isc::dhcp::dhcp4_logger, finishConfigHookLibraries(), getInstance(), isc::dhcp::Dhcp4to6Ipc::instance(), isc::dhcp::IfaceMgr::instance(), isc::dhcp::CfgMgr::instance(), isc::dhcp::TimerMgr::instance(), LOG_DEBUG, LOG_INFO, isc::asiolink::IntervalTimer::ONE_SHOT, isc::dhcp::CfgIface::open_sockets_failed_callback_, isc::config::parseAnswer(), and isc::dhcp::Dhcpv4Srv::useBroadcast().
|
virtual |
Initiates shutdown procedure for the whole DHCPv4 server.
exit_value | integer value to the process should exit with. |
Definition at line 1541 of file ctrl_dhcp4_srv.cc.
References isc::dhcp::Dhcpv4Srv::getIOService(), isc::process::Daemon::setExitValue(), and isc::dhcp::Dhcpv4Srv::shutdown().