diff --git a/ChangeLog b/ChangeLog index ff6d1ba066..a0032c3d6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +818. [func] tomek + DHCPv4,DHCPv6 and DDNS components now report their versions. + (Trac #3508, git 3f46c74ffa0ea1197e1fa62cb2f6580931be35f3) + 817. [bug] marcin DHCPv4 and DHCPv6 servers will log an error during an attempt to open socket on the interface which is down or not configured. diff --git a/configure.ac b/configure.ac index 81728c202a..b5570cf32e 100644 --- a/configure.ac +++ b/configure.ac @@ -29,6 +29,19 @@ AC_CONFIG_MACRO_DIR([m4macros]) # Checks for programs. AC_PROG_CXX +# Check for exact Kea version. +AC_MSG_CHECKING(whether this is a tarball or git source) +if test -d "${srcdir}/.git"; then + KEA_SRCID="git `(cd "${top_srcdir}";git rev-parse HEAD)`" + AC_MSG_RESULT("git") +else + KEA_SRCID="tarball" + AC_MSG_RESULT("tarball") +fi +# Export EXTENDED_VERSION to config.h +# This will be either "tarball" or "git abcd". +AC_DEFINE_UNQUOTED([EXTENDED_VERSION], ["${KEA_SRCID}"], [Extended Kea version]) + # Enable low-performing debugging facilities? This option optionally # enables some debugging aids that perform slowly and hence aren't built # by default. @@ -1481,6 +1494,11 @@ AC_OUTPUT dnl Print the results dnl +EXTENDED_VERSION=${PACKAGE_VERSION} +if test "$KEA_SRCID" != ""; then + EXTENDED_VERSION="${EXTENDED_VERSION} ($KEA_SRCID)" +fi + cat > config.report << END Kea source configure results: @@ -1489,6 +1507,7 @@ cat > config.report << END Package: Name: ${PACKAGE_NAME} Version: ${PACKAGE_VERSION} + Extended version:${EXTENDED_VERSION} OS Family: ${OS_TYPE} Using GNU sed: ${GNU_SED} diff --git a/doc/examples/kea6/simple.json b/doc/examples/kea6/simple.json index ff3c6c1ed2..e266d0ba10 100644 --- a/doc/examples/kea6/simple.json +++ b/doc/examples/kea6/simple.json @@ -31,7 +31,7 @@ # least subnet and pool entries. "subnet6": [ { - "pool": [ "2001:db8:1::/80" ], + "pools": [ { "pool": "2001:db8:1::/80" } ], "subnet": "2001:db8:1::/64", "interface": "eth0" } diff --git a/doc/guide/ddns.xml b/doc/guide/ddns.xml index 67bf2c6767..d88257ea25 100644 --- a/doc/guide/ddns.xml +++ b/doc/guide/ddns.xml @@ -58,9 +58,41 @@ Kea, is a separate binary that can be run on its own or through keactl (see ). In normal operation, controlling kea-dhcp-ddns - with keactl is recommended. + with keactl is recommended. However, it is also + possible to run the DHCP-DDNS server directly. It accepts the + following command-line switches: + + + + -c file - + specifies the configuration file. This is the only mandatory + switch. + + + + -d - specifies whether the server + logging should be switched to debug/verbose mode. In verbose mode, + the logging severity and debuglevel specified in a configuration + file are ignored and "debug" severity and the maximum debuglevel + (99) are assumed. The flag is convenient, for temporarily + switching the server into maximum verbosity, e.g. when + debugging. + + + + -v - prints out Kea version and exits. + + + + + -V - prints out Kea extended version with + additional parameters and exits. + + + + Upon start up the module will load its configuration and begin listening for NCRs based on that configuration. diff --git a/doc/guide/dhcp4-srv.xml b/doc/guide/dhcp4-srv.xml index 5e792e5fb2..3263aa73b6 100644 --- a/doc/guide/dhcp4-srv.xml +++ b/doc/guide/dhcp4-srv.xml @@ -28,8 +28,8 @@ - -v - specifies whether the server - logging should be switched to verbose mode. In verbose mode, + -d - specifies whether the server + logging should be switched to debug/verbose mode. In verbose mode, the logging severity and debuglevel specified in a configuration file are ignored and "debug" severity and the maximum debuglevel (99) are assumed. The flag is convenient, for temporarily @@ -44,6 +44,17 @@ ports other than default DHCPv4 ports will not be able to handle regular DHCPv4 queries. + + + -v - prints out Kea version and exits. + + + + + -V - prints out Kea extended version with + additional parameters and exits. + + diff --git a/doc/guide/dhcp6-srv.xml b/doc/guide/dhcp6-srv.xml index bd4443c7f7..361b8f4181 100644 --- a/doc/guide/dhcp6-srv.xml +++ b/doc/guide/dhcp6-srv.xml @@ -42,6 +42,17 @@ ports other than default DHCPv6 ports will not be able to handle regular DHCPv6 queries. + + + -v - prints out Kea version and exits. + + + + + -V - prints out Kea extended version with + additional parameters and exits. + + diff --git a/src/bin/d2/d2_messages.mes b/src/bin/d2/d2_messages.mes index ababcac075..870c5e9311 100644 --- a/src/bin/d2/d2_messages.mes +++ b/src/bin/d2/d2_messages.mes @@ -457,9 +457,9 @@ error after receiving a signal. This is a programmatic error and should be reported. While The application will likely continue to operating, it may be unable to respond correctly to signals. -% DHCP_DDNS_STARTING DHCP-DDNS starting, pid: %1 +% DHCP_DDNS_STARTING DHCP-DDNS starting, pid: %1, version: %2 This is an informational message issued when controller for the -service first starts. +service first starts. Version is also reported. % DHCP_DDNS_STARTING_TRANSACTION Transaction Key: %1 This is a debug message issued when DHCP-DDNS has begun a transaction for diff --git a/src/bin/d2/d_controller.cc b/src/bin/d2/d_controller.cc index 9c094ee48c..29e3e288df 100644 --- a/src/bin/d2/d_controller.cc +++ b/src/bin/d2/d_controller.cc @@ -12,7 +12,7 @@ // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. - +#include #include #include #include @@ -21,6 +21,7 @@ #include #include +#include namespace isc { namespace d2 { @@ -68,7 +69,7 @@ DControllerBase::launch(int argc, char* argv[], const bool test_mode) { // Log the starting of the service. Although this is the controller // module, use a "DHCP_DDNS_" prefix to the module (to conform to the // principle of least astonishment). - LOG_INFO(dctl_logger, DHCP_DDNS_STARTING).arg(getpid()); + LOG_INFO(dctl_logger, DHCP_DDNS_STARTING).arg(getpid()).arg(VERSION); try { // Step 2 is to create and initialize the application process object. initProcess(); @@ -132,14 +133,24 @@ DControllerBase::parseArgs(int argc, char* argv[]) int ch; opterr = 0; optind = 1; - std::string opts("vc:" + getCustomOpts()); + std::string opts("dvVc:" + getCustomOpts()); while ((ch = getopt(argc, argv, opts.c_str())) != -1) { switch (ch) { - case 'v': + case 'd': // Enables verbose logging. verbose_ = true; break; + case 'v': + // Print just Kea version and exit + std::cout << getVersion(false) << std::endl; + exit(EXIT_SUCCESS); + + case 'V': + // Print extended Kea version and exit + std::cout << getVersion(true) << std::endl; + exit(EXIT_SUCCESS); + case 'c': // config file name if (optarg == NULL) { @@ -399,7 +410,10 @@ DControllerBase::usage(const std::string & text) std::cerr << "Usage: " << bin_name_ << std::endl << " -c : mandatory," << " specifies name of configuration file " << std::endl - << " -v: optional, verbose output " << std::endl; + << " -d: optional, verbose output " << std::endl + << " -v: print version number and exit" << std::endl + << " -V: print extended version information and exit" + << std::endl; // add any derivation specific usage std::cerr << getUsageText() << std::endl; @@ -422,3 +436,19 @@ dhcp::Daemon::loggerInit(const char* log_name, bool verbose) { } }; // namespace isc + +std::string +isc::dhcp::Daemon::getVersion(bool extended) { + std::stringstream tmp; + + tmp << VERSION; + if (extended) { + tmp << std::endl << EXTENDED_VERSION; + + // @todo print more details (is it Botan or OpenSSL build, + // with or without MySQL/Postgres? What compilation options were + // used? etc) + } + + return (tmp.str()); +} diff --git a/src/bin/d2/tests/d2_process_tests.sh.in b/src/bin/d2/tests/d2_process_tests.sh.in index 659caca8b4..a9c19dad11 100755 --- a/src/bin/d2/tests/d2_process_tests.sh.in +++ b/src/bin/d2/tests/d2_process_tests.sh.in @@ -16,6 +16,8 @@ CFG_FILE=@abs_top_builddir@/src/bin/d2/tests/test_config.json # Path to the D2 log file. LOG_FILE=@abs_top_builddir@/src/bin/d2/tests/test.log +# Expected version +EXPECTED_VERSION="@PACKAGE_VERSION@" # D2 configuration to be stored in the configuration file. CONFIG="{ \"DhcpDdns\": @@ -236,3 +238,4 @@ shutdown_test() { dynamic_reconfiguration_test shutdown_test "dhcp-ddns.sigterm_test" 15 shutdown_test "dhcp-ddns.sigint_test" 2 +version_test "dhcp-ddns.version" diff --git a/src/bin/dhcp4/dhcp4_messages.mes b/src/bin/dhcp4/dhcp4_messages.mes index 10d2dabf60..08bfc07fa8 100644 --- a/src/bin/dhcp4/dhcp4_messages.mes +++ b/src/bin/dhcp4/dhcp4_messages.mes @@ -351,9 +351,10 @@ core component within the DHCPv4 server (the Dhcpv4 server object) has failed. As a result, the server will exit. The reason for the failure is given within the message. -% DHCP4_STARTING server starting +% DHCP4_STARTING Kea DHCPv4 server version %1 starting This informational message indicates that the DHCPv4 server has -processed any command-line switches and is starting. +processed any command-line switches and is starting. The version +is also printed. % DHCP4_START_INFO pid: %1, port: %2, verbose: %3 This is a debug message issued during the DHCPv4 server startup. diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index 6267da929e..ff07ec56d5 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -2036,5 +2036,21 @@ Dhcpv4Srv::d2ClientErrorHandler(const CfgMgr::instance().getD2ClientMgr().suspendUpdates(); } +std::string +Daemon::getVersion(bool extended) { + std::stringstream tmp; + + tmp << VERSION; + if (extended) { + tmp << endl << EXTENDED_VERSION; + + // @todo print more details (is it Botan or OpenSSL build, + // with or without MySQL/Postgres? What compilation options were + // used? etc) + } + + return (tmp.str()); +} + } // namespace dhcp } // namespace isc diff --git a/src/bin/dhcp4/main.cc b/src/bin/dhcp4/main.cc index 96b553ed43..56d9c1c7d5 100644 --- a/src/bin/dhcp4/main.cc +++ b/src/bin/dhcp4/main.cc @@ -41,13 +41,21 @@ const char* const DHCP4_NAME = "kea-dhcp4"; const char* const DHCP4_LOGGER_NAME = "kea-dhcp4"; +/// @brief Prints Kea Usage and exits +/// +/// Note: This function never returns. It terminates the process. void usage() { - cerr << "Usage: " << DHCP4_NAME << " [-v] [-p number] [-c file]" << endl; - cerr << " -v: verbose output" << endl; + cerr << "Kea DHCPv4 server, version " << VERSION << endl; + cerr << endl; + cerr << "Usage: " << DHCP4_NAME + << " [-v] [-V] [-d] [-p number] [-c file]" << endl; + cerr << " -c file: specify configuration file" << endl; + cerr << " -d: debug mode with extra verbosity (former -v)" << endl; cerr << " -p number: specify non-standard port number 1-65535 " << "(useful for testing only)" << endl; - cerr << " -c file: specify configuration file" << endl; + cerr << " -v: print version number and exit" << endl; + cerr << " -V: print extended version and exit" << endl; exit(EXIT_FAILURE); } } // end of anonymous namespace @@ -62,12 +70,20 @@ main(int argc, char* argv[]) { // The standard config file std::string config_file(""); - while ((ch = getopt(argc, argv, "vp:c:")) != -1) { + while ((ch = getopt(argc, argv, "dvVp:c:")) != -1) { switch (ch) { - case 'v': + case 'd': verbose_mode = true; break; + case 'v': + cout << Daemon::getVersion(false) << endl; + return (EXIT_SUCCESS); + + case 'V': + cout << Daemon::getVersion(false) << endl; + return (EXIT_SUCCESS); + case 'p': try { port_number = boost::lexical_cast(optarg); @@ -111,7 +127,7 @@ main(int argc, char* argv[]) { LOG_DEBUG(dhcp4_logger, DBG_DHCP4_START, DHCP4_START_INFO) .arg(getpid()).arg(port_number).arg(verbose_mode ? "yes" : "no"); - LOG_INFO(dhcp4_logger, DHCP4_STARTING); + LOG_INFO(dhcp4_logger, DHCP4_STARTING).arg(VERSION); // Create the server instance. ControlledDhcpv4Srv server(port_number); diff --git a/src/bin/dhcp4/tests/dhcp4_process_tests.sh.in b/src/bin/dhcp4/tests/dhcp4_process_tests.sh.in index 40967bf7ff..af5f5f0943 100755 --- a/src/bin/dhcp4/tests/dhcp4_process_tests.sh.in +++ b/src/bin/dhcp4/tests/dhcp4_process_tests.sh.in @@ -16,6 +16,8 @@ CFG_FILE=@abs_top_builddir@/src/bin/dhcp4/tests/test_config.json # Path to the Kea log file. LOG_FILE=@abs_top_builddir@/src/bin/dhcp4/tests/test.log +# Expected version +EXPECTED_VERSION="@PACKAGE_VERSION@" # Kea configuration to be stored in the configuration file. CONFIG="{ \"Dhcp4\": @@ -256,3 +258,4 @@ shutdown_test() { dynamic_reconfiguration_test shutdown_test "dhcpv4.sigterm_test" 15 shutdown_test "dhcpv4.sigint_test" 2 +version_test "dhcpv4.version" diff --git a/src/bin/dhcp6/dhcp6_messages.mes b/src/bin/dhcp6/dhcp6_messages.mes index 5ad2010700..381dad1387 100644 --- a/src/bin/dhcp6/dhcp6_messages.mes +++ b/src/bin/dhcp6/dhcp6_messages.mes @@ -540,9 +540,10 @@ standalone mode, not connected to the message queue. Standalone mode is only useful during program development, and should not be used in a production environment. -% DHCP6_STARTING server starting +% DHCP6_STARTING Kea DHCPv6 server version %1 starting This informational message indicates that the IPv6 DHCP server has -processed any command-line switches and is starting. +processed any command-line switches and is starting. The version +is also printed. % DHCP6_START_INFO pid: %1, port: %2, verbose: %3 This is a debug message issued during the IPv6 DHCP server startup. diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index ffea95a81a..5c4db35c08 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -2697,5 +2697,21 @@ Dhcpv6Srv::d2ClientErrorHandler(const CfgMgr::instance().getD2ClientMgr().suspendUpdates(); } +std::string +Daemon::getVersion(bool extended) { + std::stringstream tmp; + + tmp << VERSION; + if (extended) { + tmp << endl << EXTENDED_VERSION; + + // @todo print more details (is it Botan or OpenSSL build, + // with or without MySQL/Postgres? What compilation options were + // used? etc) + } + + return (tmp.str()); +} + }; }; diff --git a/src/bin/dhcp6/main.cc b/src/bin/dhcp6/main.cc index 983f169c34..ca86f6812e 100644 --- a/src/bin/dhcp6/main.cc +++ b/src/bin/dhcp6/main.cc @@ -41,13 +41,21 @@ const char* const DHCP6_NAME = "kea-dhcp6"; const char* const DHCP6_LOGGER_NAME = "kea-dhcp6"; +/// @brief Prints Kea Usage and exits +/// +/// Note: This function never returns. It terminates the process. void usage() { - cerr << "Usage: " << DHCP6_NAME << " [-v] [-p port_number] [-c cfgfile]" << endl; - cerr << " -v: verbose output" << endl; + cerr << "Kea DHCPv6 server, version " << VERSION << endl; + cerr << endl; + cerr << "Usage: " << DHCP6_NAME + << " [-c cfgfile] [-v] [-V] [-d] [-p port_number]" << endl; + cerr << " -c file: specify configuration file" << endl; + cerr << " -v: print version number and exit." << endl; + cerr << " -V: print extended version and exit" << endl; + cerr << " -d: debug mode with extra verbosity (former -v)" << endl; cerr << " -p number: specify non-standard port number 1-65535 " << "(useful for testing only)" << endl; - cerr << " -c file: specify configuration file" << endl; exit(EXIT_FAILURE); } } // end of anonymous namespace @@ -62,12 +70,20 @@ main(int argc, char* argv[]) { // The standard config file std::string config_file(""); - while ((ch = getopt(argc, argv, "vp:c:")) != -1) { + while ((ch = getopt(argc, argv, "dvVp:c:")) != -1) { switch (ch) { - case 'v': + case 'd': verbose_mode = true; break; + case 'v': + cout << Daemon::getVersion(false) << endl; + return (EXIT_SUCCESS); + + case 'V': + cout << Daemon::getVersion(true) << endl; + return (EXIT_SUCCESS); + case 'p': // port number try { port_number = boost::lexical_cast(optarg); @@ -112,7 +128,7 @@ main(int argc, char* argv[]) { LOG_DEBUG(dhcp6_logger, DBG_DHCP6_START, DHCP6_START_INFO) .arg(getpid()).arg(port_number).arg(verbose_mode ? "yes" : "no"); - LOG_INFO(dhcp6_logger, DHCP6_STARTING); + LOG_INFO(dhcp6_logger, DHCP6_STARTING).arg(VERSION); // Create the server instance. ControlledDhcpv6Srv server(port_number); diff --git a/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in b/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in index 54ee7e709a..b972774352 100755 --- a/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in +++ b/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in @@ -16,6 +16,8 @@ CFG_FILE=@abs_top_builddir@/src/bin/dhcp6/tests/test_config.json # Path to the Kea log file. LOG_FILE=@abs_top_builddir@/src/bin/dhcp6/tests/test.log +# Expected version +EXPECTED_VERSION="@PACKAGE_VERSION@" # Kea configuration to be stored in the configuration file. CONFIG="{ \"Dhcp6\": @@ -257,5 +259,6 @@ shutdown_test() { } dynamic_reconfiguration_test -shutdown_test "dhcpv4.sigterm_test" 15 -shutdown_test "dhcpv4.sigint_test" 2 +shutdown_test "dhcpv6.sigterm_test" 15 +shutdown_test "dhcpv6.sigint_test" 2 +version_test "dhcpv6.version" diff --git a/src/bin/keactrl/keactrl.in b/src/bin/keactrl/keactrl.in index a0b6f0e2ff..ca10b503f6 100644 --- a/src/bin/keactrl/keactrl.in +++ b/src/bin/keactrl/keactrl.in @@ -284,7 +284,7 @@ case ${command} in args="-c ${kea_config_file}" if [ "${kea_verbose}" = "yes" ]; then - args="${args} -v" + args="${args} -d" fi # Run servers if they are on the list of servers from the command line diff --git a/src/lib/dhcpsrv/daemon.h b/src/lib/dhcpsrv/daemon.h index af518b5a44..c9939a77b2 100644 --- a/src/lib/dhcpsrv/daemon.h +++ b/src/lib/dhcpsrv/daemon.h @@ -151,6 +151,17 @@ public: return (verbose_); } + /// @brief returns Kea version on stdout and exits. + /// + /// With extended == false, this method returns a simple string + /// containing version number. With extended == true, it returns + /// also additional information about sources. It is expected to + /// return extra information about dependencies and used DB backends. + /// + /// @param extended print additional information? + /// @return text string + static std::string getVersion(bool extended); + protected: /// @brief Invokes handler for the next received signal. diff --git a/src/lib/dhcpsrv/tests/daemon_unittest.cc b/src/lib/dhcpsrv/tests/daemon_unittest.cc index 7e805e5b7a..572812d3f1 100644 --- a/src/lib/dhcpsrv/tests/daemon_unittest.cc +++ b/src/lib/dhcpsrv/tests/daemon_unittest.cc @@ -23,8 +23,17 @@ using namespace isc; using namespace isc::dhcp; using namespace isc::data; +std::string isc::dhcp::Daemon::getVersion(bool extended) { + if (extended) { + return (std::string("EXTENDED")); + } else { + return (std::string("BASIC")); + } +} + namespace { + // Very simple test. Checks whether Daemon can be instantiated and its // default parameters are sane TEST(DaemonTest, constructor) { diff --git a/src/lib/testutils/dhcp_test_lib.sh.in b/src/lib/testutils/dhcp_test_lib.sh.in index f8f3bb9844..b63f7d48b5 100644 --- a/src/lib/testutils/dhcp_test_lib.sh.in +++ b/src/lib/testutils/dhcp_test_lib.sh.in @@ -401,3 +401,23 @@ must be a number" # Actually send a signal. kill -${sig} ${_GET_PIDS} } + +# This test verifies that the binary is reporting its version properly. +version_test() { + test_name=${1} # Test name + + # Log the start of the test and print test name. + test_start ${test_name} + + # Remove dangling Kea instances and remove log files. + cleanup + + REPORTED_VERSION="`${bin_path}/${bin} -v`" + + if test "${REPORTED_VERSION}" == "${EXPECTED_VERSION}"; then + test_finish 0 + else + printf "ERROR: Expected version ${EXPECTED_VERSION}, got ${REPORTED_VERSION}\n" + test_finish 1 + fi +}