From: Tomek Mrugalski Date: Mon, 2 Jun 2014 17:44:33 +0000 (+0200) Subject: [master] Merge branch 'trac3399' [Kea4 reads config from JSON file] X-Git-Tag: trac3434_base~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=83816e00c53f869d19701db0ff047cf7f7d87c01;p=thirdparty%2Fkea.git [master] Merge branch 'trac3399' [Kea4 reads config from JSON file] Conflicts: ChangeLog src/bin/dhcp6/kea_controller.cc src/lib/dhcpsrv/daemon.h --- 83816e00c53f869d19701db0ff047cf7f7d87c01 diff --cc ChangeLog index d5d2168222,bb12ba4ff1..d2ee0fe725 --- a/ChangeLog +++ b/ChangeLog @@@ -1,27 -1,9 +1,34 @@@ -7XX. [func] tomek ++788. [func] tomek + DHCPv4 server: New parameter added to configure.ac: --with-kea-config. + It allows selecting configuration backend and accepts one of two + values: BUNDY, which uses Bundy (former BIND10) framework as Kea + 0.8 did, or JSON, which reads configuration from a JSON file. - (Trac #3399, git TBD) ++ (Trac #3399, git 6e4dd3ae58c091ba0fd64c87fa8d7c268210f99b) ++ +787. [func] marcin + DHCPv6 server: Implemented dynamic reconfiguration of the server, + triggered when the SIGHUP signal is received by the server's + process. Also, server performs a graceful shut down when SIGINT + or SIGTERM signal is received. + (Trac #3406, git 3be60fa6ac521aecae6ae92d26dc03792bc76903) + +786. [func] tmark + DHCP-DDNS now supports DDNS updates with TSIG. Please refer to the + Kea Guide for details. Prior to this TSIG keys could be defined but + were not used. + (Trac #3432, git 80fea12a53d1e832d4e7b710ca6ea613300f73ea) + +785. [bug] marcin + DHCPv6 server avoids collisions between prefixes that are allocated + as a result of receiving hints from the clients. Previously the + whole prefix (including bits beyond the prefix length) was used to + search existing leases in the lease database. If not found, the + new lease was crated for the prefix sent by the client. If another + client sent the same prefix but with different non-significant bits + the prefix was allocated. This led to prefix collisions. Currently, + server ignores bits beyond the prefix length when searching for + existing leases. + (Trac #3246, git 50de7df4195195e981ae9c8c6f1b4100047d5bb5) 784. [func] tmark DHCP_DDNS's configuration was changed. The unused parameter, "interface" diff --cc src/bin/dhcp6/kea_controller.cc index 3c8135c8a1,cd099009d6..33404cac58 --- a/src/bin/dhcp6/kea_controller.cc +++ b/src/bin/dhcp6/kea_controller.cc @@@ -21,43 -20,19 +20,28 @@@ #include #include #include - #include - #include - #include - #include - #include - #include - #include #include - #include - #include - #include +#include ++ #include - #include using namespace isc::asiolink; - using namespace isc::cc; - using namespace isc::config; - using namespace isc::data; using namespace isc::dhcp; - using namespace isc::log; - using namespace isc::util; using namespace std; -namespace isc { -namespace dhcp { - -void -ControlledDhcpv6Srv::init(const std::string& file_name) { +namespace { + +/// @brief Configure DHCPv6 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 DHCPv6 server's configuration from the 'Dhcp6' section of +/// the JSON configuration file. +/// +/// @param file_name Configuration file location. +void configure(const std::string& file_name) { // This is a configuration backend implementation that reads the // configuration from a JSON file. @@@ -122,52 -97,8 +106,52 @@@ reason = string(" (") + comment->stringValue() + string(")"); } LOG_ERROR(dhcp6_logger, DHCP6_CONFIG_LOAD_FAIL).arg(reason); - isc_throw(BadValue, "Failed to apply configuration:" << reason); + isc_throw(isc::BadValue, "Failed to apply configuration:" << reason); } +} + +/// @brief Signals handler for DHCPv6 server. +/// +/// This signal handler handles the following signals received by the DHCPv6 +/// server process: +/// - SIGHUP - triggers server's dynamic reconfiguration. +/// - SIGTERM - triggers server's shut down. +/// - SIGINT - triggers server's shut down. +/// +/// @param signo Signal number received. +void signalHandler(int signo) { + // SIGHUP signals a request to reconfigure the server. + if (signo == SIGHUP) { + // Get configuration file name. + std::string file = ControlledDhcpv6Srv::getInstance()->getConfigFile(); + try { + LOG_INFO(dhcp6_logger, DHCP6_DYNAMIC_RECONFIGURATION).arg(file); + configure(file); + } catch (const std::exception& ex) { + // Log the unsuccessful reconfiguration. The reason for failure + // should be already logged. Don't rethrow an exception so as + // the server keeps working. + LOG_ERROR(dhcp6_logger, DHCP6_DYNAMIC_RECONFIGURATION_FAIL) + .arg(file); + } + } else if ((signo == SIGTERM) || (signo == SIGINT)) { - ElementPtr params(new isc::data::MapElement()); ++ isc::data::ElementPtr params(new isc::data::MapElement()); + ControlledDhcpv6Srv::processCommand("shutdown", params); + } +} + +} + +namespace isc { +namespace dhcp { + +void +ControlledDhcpv6Srv::init(const std::string& file_name) { + // Call parent class's init to initialize file name. + Daemon::init(file_name); + + // Configure the server using JSON file. + configure(file_name); // We don't need to call openActiveSockets() or startD2() as these // methods are called in processConfig() which is called by diff --cc src/lib/dhcpsrv/daemon.h index 52623f0ff3,9bcbf7f80e..515b168b6f --- a/src/lib/dhcpsrv/daemon.h +++ b/src/lib/dhcpsrv/daemon.h @@@ -93,20 -83,14 +93,24 @@@ public /// virtual destructor as well. virtual ~Daemon(); - /// Initializez logger + /// @brief Returns config file name. + static std::string getConfigFile() { + return (config_file_); + } + + /// Initializes logger /// - /// This method initializes logger. - static void loggerInit(const char* log_name, bool verbose, bool stand_alone); + /// This method initializes logger. Currently its implementation is specific + /// to each configuration backend. + /// + /// @param log_name name used in logger initialization + /// @param verbose verbose mode (true usually enables DEBUG messages) + static void loggerInit(const char* log_name, bool verbose); + +private: + + /// @brief Config file name or empty if config file not used. + static std::string config_file_; }; }; // end of isc::dhcp namespace