]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3536] added hook callouts
authorRazvan Becheriu <razvan@isc.org>
Mon, 16 Sep 2024 18:25:33 +0000 (21:25 +0300)
committerRazvan Becheriu <razvan@isc.org>
Thu, 3 Oct 2024 18:04:36 +0000 (21:04 +0300)
65 files changed:
src/hooks/dhcp/mysql_cb/mysql_cb_log.h
src/hooks/dhcp/mysql_cb/mysql_cb_messages.cc
src/hooks/dhcp/mysql_cb/mysql_cb_messages.mes
src/hooks/dhcp/mysql_hb/.gitattributes [new file with mode: 0644]
src/hooks/dhcp/mysql_hb/Makefile.am
src/hooks/dhcp/mysql_hb/libloadtests/.gitignore [new file with mode: 0644]
src/hooks/dhcp/mysql_hb/libloadtests/Makefile.am
src/hooks/dhcp/mysql_hb/libloadtests/load_unload_unittests.cc [new file with mode: 0644]
src/hooks/dhcp/mysql_hb/libloadtests/run_unittests.cc [new file with mode: 0644]
src/hooks/dhcp/mysql_hb/mysql_hb_callouts.cc [new file with mode: 0644]
src/hooks/dhcp/mysql_hb/mysql_hb_log.cc [new file with mode: 0644]
src/hooks/dhcp/mysql_hb/mysql_hb_log.h [new file with mode: 0644]
src/hooks/dhcp/mysql_hb/mysql_hb_messages.cc [new file with mode: 0644]
src/hooks/dhcp/mysql_hb/mysql_hb_messages.h [new file with mode: 0644]
src/hooks/dhcp/mysql_hb/mysql_hb_messages.mes
src/hooks/dhcp/mysql_hb/mysql_host_data_source.h
src/hooks/dhcp/mysql_hb/version.cc [new file with mode: 0644]
src/hooks/dhcp/mysql_lb/.gitattributes [new file with mode: 0644]
src/hooks/dhcp/mysql_lb/Makefile.am
src/hooks/dhcp/mysql_lb/libloadtests/.gitignore [new file with mode: 0644]
src/hooks/dhcp/mysql_lb/libloadtests/Makefile.am
src/hooks/dhcp/mysql_lb/libloadtests/load_unload_unittests.cc [new file with mode: 0644]
src/hooks/dhcp/mysql_lb/libloadtests/run_unittests.cc [new file with mode: 0644]
src/hooks/dhcp/mysql_lb/mysql_lb_callouts.cc [new file with mode: 0644]
src/hooks/dhcp/mysql_lb/mysql_lb_log.cc [new file with mode: 0644]
src/hooks/dhcp/mysql_lb/mysql_lb_log.h [new file with mode: 0644]
src/hooks/dhcp/mysql_lb/mysql_lb_messages.cc [new file with mode: 0644]
src/hooks/dhcp/mysql_lb/mysql_lb_messages.h [new file with mode: 0644]
src/hooks/dhcp/mysql_lb/mysql_lb_messages.mes
src/hooks/dhcp/mysql_lb/mysql_lease_mgr.h
src/hooks/dhcp/mysql_lb/version.cc [new file with mode: 0644]
src/hooks/dhcp/pgsql_cb/pgsql_cb_log.h
src/hooks/dhcp/pgsql_cb/pgsql_cb_messages.cc
src/hooks/dhcp/pgsql_cb/pgsql_cb_messages.mes
src/hooks/dhcp/pgsql_hb/.gitattributes [new file with mode: 0644]
src/hooks/dhcp/pgsql_hb/Makefile.am
src/hooks/dhcp/pgsql_hb/libloadtests/.gitignore [new file with mode: 0644]
src/hooks/dhcp/pgsql_hb/libloadtests/Makefile.am
src/hooks/dhcp/pgsql_hb/libloadtests/load_unload_unittests.cc [new file with mode: 0644]
src/hooks/dhcp/pgsql_hb/libloadtests/run_unittests.cc [new file with mode: 0644]
src/hooks/dhcp/pgsql_hb/pgsql_hb_callouts.cc [new file with mode: 0644]
src/hooks/dhcp/pgsql_hb/pgsql_hb_log.cc [new file with mode: 0644]
src/hooks/dhcp/pgsql_hb/pgsql_hb_log.h [new file with mode: 0644]
src/hooks/dhcp/pgsql_hb/pgsql_hb_messages.cc [new file with mode: 0644]
src/hooks/dhcp/pgsql_hb/pgsql_hb_messages.h [new file with mode: 0644]
src/hooks/dhcp/pgsql_hb/pgsql_hb_messages.mes
src/hooks/dhcp/pgsql_hb/pgsql_host_data_source.h
src/hooks/dhcp/pgsql_hb/version.cc [new file with mode: 0644]
src/hooks/dhcp/pgsql_lb/.gitattributes [new file with mode: 0644]
src/hooks/dhcp/pgsql_lb/Makefile.am
src/hooks/dhcp/pgsql_lb/libloadtests/.gitignore [new file with mode: 0644]
src/hooks/dhcp/pgsql_lb/libloadtests/Makefile.am
src/hooks/dhcp/pgsql_lb/libloadtests/load_unload_unittests.cc [new file with mode: 0644]
src/hooks/dhcp/pgsql_lb/libloadtests/run_unittests.cc [new file with mode: 0644]
src/hooks/dhcp/pgsql_lb/pgsql_lb_callouts.cc [new file with mode: 0644]
src/hooks/dhcp/pgsql_lb/pgsql_lb_log.cc [new file with mode: 0644]
src/hooks/dhcp/pgsql_lb/pgsql_lb_log.h [new file with mode: 0644]
src/hooks/dhcp/pgsql_lb/pgsql_lb_messages.cc [new file with mode: 0644]
src/hooks/dhcp/pgsql_lb/pgsql_lb_messages.h [new file with mode: 0644]
src/hooks/dhcp/pgsql_lb/pgsql_lb_messages.mes
src/hooks/dhcp/pgsql_lb/pgsql_lease_mgr.h
src/hooks/dhcp/pgsql_lb/version.cc [new file with mode: 0644]
src/lib/dhcpsrv/dhcpsrv_messages.cc
src/lib/dhcpsrv/dhcpsrv_messages.h
src/lib/dhcpsrv/dhcpsrv_messages.mes

index dc563301305cea9a439f855e70315382ac8fc250..024f30d0b9534fcfe70c8b28097a47dadd4080cb 100644 (file)
@@ -4,8 +4,8 @@
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-#ifndef LEASE_CMD_LOG_H
-#define LEASE_CMD_LOG_H
+#ifndef MYSQL_CB_LOG_H
+#define MYSQL_CB_LOG_H
 
 #include <log/logger_support.h>
 #include <log/macros.h>
index 00a8dde822b8b86e9ebceee46ac8bf4091733bd4..2a2d91db12e9d397503ecd4ee5062ad87a1d455a 100644 (file)
@@ -226,7 +226,7 @@ const char* values[] = {
     "MYSQL_CB_CREATE_UPDATE_SHARED_NETWORK_OPTION6", "create or update shared network: %1 option",
     "MYSQL_CB_CREATE_UPDATE_SUBNET4", "create or update subnet: %1",
     "MYSQL_CB_CREATE_UPDATE_SUBNET6", "create or update subnet: %1",
-    "MYSQL_CB_DEINIT_OK", "unloading MYSQL CB hooks library successful",
+    "MYSQL_CB_DEINIT_OK", "unloading MySQL CB hooks library successful",
     "MYSQL_CB_DELETE_ALL_CLIENT_CLASSES4", "delete all client classes",
     "MYSQL_CB_DELETE_ALL_CLIENT_CLASSES4_RESULT", "deleted: %1 entries",
     "MYSQL_CB_DELETE_ALL_CLIENT_CLASSES6", "delete all client classes",
@@ -383,7 +383,7 @@ const char* values[] = {
     "MYSQL_CB_GET_SUBNET6_BY_SUBNET_ID", "retrieving subnet by subnet id: %1",
     "MYSQL_CB_GET_TYPE4", "get type",
     "MYSQL_CB_GET_TYPE6", "get type",
-    "MYSQL_CB_INIT_OK", "loading MYSQL CB hooks library successful",
+    "MYSQL_CB_INIT_OK", "loading MySQL CB hooks library successful",
     "MYSQL_CB_NO_TLS", "TLS was required but is not used",
     "MYSQL_CB_RECONNECT_ATTEMPT_FAILED4", "database reconnect failed: %1",
     "MYSQL_CB_RECONNECT_ATTEMPT_FAILED6", "database reconnect failed: %1",
index 1d25f9b839f7ce10236a24ec6348acdb0b9792d6..15686c02b87450c06a630cfcb3921cd03009091c 100644 (file)
@@ -88,7 +88,7 @@ Debug message issued when triggered an action to create or update subnet
 Logged at debug log level 40.
 Debug message issued when triggered an action to create or update subnet
 
-% MYSQL_CB_DEINIT_OK unloading MYSQL CB hooks library successful
+% MYSQL_CB_DEINIT_OK unloading MySQL CB hooks library successful
 This informational message indicates that the MySQL Configuration Backend hooks
 library has been unloaded successfully.
 
@@ -720,7 +720,7 @@ Debug message issued when triggered an action to retrieve type
 Logged at debug log level 40.
 Debug message issued when triggered an action to retrieve type
 
-% MYSQL_CB_INIT_OK loading MYSQL CB hooks library successful
+% MYSQL_CB_INIT_OK loading MySQL CB hooks library successful
 This informational message indicates that the MySQL Configuration Backend hooks
 library has been loaded successfully. Enjoy!
 
diff --git a/src/hooks/dhcp/mysql_hb/.gitattributes b/src/hooks/dhcp/mysql_hb/.gitattributes
new file mode 100644 (file)
index 0000000..2545371
--- /dev/null
@@ -0,0 +1,2 @@
+/mysql_hb_messages.cc            -diff merge=ours
+/mysql_hb_messages.h             -diff merge=ours
index 24bc109fa0bb78ebf35cd1e2008689eb834d7101..09b789de648437cd992ca9b15263766e4cd33a65 100644 (file)
@@ -14,7 +14,11 @@ CLEANFILES = *.gcno *.gcda
 # convenience archive
 
 noinst_LTLIBRARIES = libmysqlhb.la
-libmysqlhb_la_SOURCES = mysql_host_data_source.cc mysql_host_data_source.h
+libmysqlhb_la_SOURCES  = mysql_hb_callouts.cc
+libmysqlhb_la_SOURCES += mysql_hb_log.cc mysql_hb_log.h
+libmysqlhb_la_SOURCES += mysql_hb_messages.cc mysql_hb_messages.h
+libmysqlhb_la_SOURCES += mysql_host_data_source.cc mysql_host_data_source.h
+libmysqlhb_la_SOURCES += version.cc
 
 libmysqlhb_la_CXXFLAGS = $(AM_CXXFLAGS)
 libmysqlhb_la_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/src/hooks/dhcp/mysql_hb/libloadtests/.gitignore b/src/hooks/dhcp/mysql_hb/libloadtests/.gitignore
new file mode 100644 (file)
index 0000000..ada6ed5
--- /dev/null
@@ -0,0 +1 @@
+hook_load_unittests
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..cefa663542a03a7325b5f1608e3a0eed6bc16f1f 100644 (file)
@@ -0,0 +1,56 @@
+SUBDIRS = .
+
+AM_CPPFLAGS  = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+AM_CPPFLAGS += -I$(top_builddir)/src/hooks/dhcp/mysql_hb -I$(top_srcdir)/src/hooks/dhcp/mysql_hb
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+AM_CPPFLAGS += -DLIBDHCP_MYSQL_HB_SO=\"$(abs_top_builddir)/src/hooks/dhcp/mysql_hb/.libs/libdhcp_mysql_hb.so\"
+AM_CXXFLAGS = $(KEA_CXXFLAGS)
+
+if USE_STATIC_LINK
+AM_LDFLAGS = -static
+endif
+
+EXTRA_DIST =
+
+CLEANFILES = *.gcno *.gcda
+
+TESTS_ENVIRONMENT = \
+       $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
+
+if HAVE_GTEST
+
+TESTS = hook_load_unittests
+
+hook_load_unittests_SOURCES  =
+hook_load_unittests_SOURCES += load_unload_unittests.cc
+hook_load_unittests_SOURCES += run_unittests.cc
+hook_load_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(LOG4CPLUS_INCLUDES)
+hook_load_unittests_CXXFLAGS = $(AM_CXXFLAGS)
+hook_load_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
+
+hook_load_unittests_LDADD  = $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/process/libkea-process.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/eval/libkea-eval.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/http/libkea-http.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/mysql/libkea-mysql.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/database/libkea-database.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/cryptolink/libkea-cryptolink.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
+hook_load_unittests_LDADD += $(LOG4CPLUS_LIBS)
+hook_load_unittests_LDADD += $(CRYPTO_LIBS)
+hook_load_unittests_LDADD += $(BOOST_LIBS)
+hook_load_unittests_LDADD += $(GTEST_LDADD)
+
+noinst_PROGRAMS = $(TESTS)
+
+endif
diff --git a/src/hooks/dhcp/mysql_hb/libloadtests/load_unload_unittests.cc b/src/hooks/dhcp/mysql_hb/libloadtests/load_unload_unittests.cc
new file mode 100644 (file)
index 0000000..b3c736b
--- /dev/null
@@ -0,0 +1,60 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+/// @file This file contains tests which exercise the load and unload
+/// functions in the ddns tuning hook library. In order to test the load
+/// function, one must be able to pass it hook library parameters. The
+/// the only way to populate these parameters is by actually loading the
+/// library via HooksManager::loadLibraries().
+
+#include <config.h>
+
+#include <dhcpsrv/testutils/lib_load_test_fixture.h>
+#include <testutils/gtest_utils.h>
+
+#include <gtest/gtest.h>
+#include <errno.h>
+
+using namespace std;
+using namespace isc;
+using namespace isc::hooks;
+using namespace isc::data;
+using namespace isc::dhcp;
+using namespace isc::process;
+
+namespace {
+
+/// @brief Test fixture for testing loading and unloading the MySQL hb library
+class MySqlHbLibLoadTest : public isc::test::LibLoadTest {
+public:
+    /// @brief Constructor
+    MySqlHbLibLoadTest() : LibLoadTest(LIBDHCP_MYSQL_HB_SO) {
+    }
+
+    /// @brief Destructor
+    virtual ~MySqlHbLibLoadTest() {
+        unloadLibraries();
+    }
+};
+
+// Simple V4 test that checks the library can be loaded and unloaded several times.
+TEST_F(MySqlHbLibLoadTest, validLoad4) {
+    validDaemonTest("kea-dhcp4");
+}
+
+// Simple V6 test that checks the library can be loaded and unloaded several times.
+TEST_F(MySqlHbLibLoadTest, validLoad6) {
+    validDaemonTest("kea-dhcp6", AF_INET6);
+}
+
+// Simple test that checks the library cannot by loaded by invalid daemons.
+TEST_F(MySqlHbLibLoadTest, invalidDaemonLoad) {
+    invalidDaemonTest("kea-ctrl-agent");
+    invalidDaemonTest("kea-dhcp-ddns");
+    invalidDaemonTest("bogus");
+}
+
+} // end of anonymous namespace
diff --git a/src/hooks/dhcp/mysql_hb/libloadtests/run_unittests.cc b/src/hooks/dhcp/mysql_hb/libloadtests/run_unittests.cc
new file mode 100644 (file)
index 0000000..755b9e4
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <log/logger_support.h>
+#include <gtest/gtest.h>
+
+int
+main(int argc, char* argv[]) {
+    ::testing::InitGoogleTest(&argc, argv);
+    isc::log::initLogger();
+    int result = RUN_ALL_TESTS();
+
+    return (result);
+}
diff --git a/src/hooks/dhcp/mysql_hb/mysql_hb_callouts.cc b/src/hooks/dhcp/mysql_hb/mysql_hb_callouts.cc
new file mode 100644 (file)
index 0000000..0d0394f
--- /dev/null
@@ -0,0 +1,82 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+// Functions accessed by the hooks framework use C linkage to avoid the name
+// mangling that accompanies use of the C++ compiler as well as to avoid
+// issues related to namespaces.
+
+#include <config.h>
+
+#include <asiolink/io_service_mgr.h>
+#include <dhcpsrv/base_host_data_source.h>
+#include <dhcpsrv/cfgmgr.h>
+#include <hooks/hooks.h>
+#include <process/daemon.h>
+#include <mysql_hb_log.h>
+#include <mysql_host_data_source.h>
+
+#include <sstream>
+#include <string>
+
+using namespace isc::asiolink;
+using namespace isc::dhcp;
+using namespace isc::hooks;
+using namespace isc::log;
+using namespace isc::process;
+using namespace std;
+
+extern "C" {
+
+/// @brief This function is called when the library is loaded.
+///
+/// @param handle library handle
+/// @return 0 when initialization is successful, 1 otherwise
+
+int load(LibraryHandle& /* handle */) {
+    // Make the hook library not loadable by d2 or ca.
+    uint16_t family = CfgMgr::instance().getFamily();
+    const std::string& proc_name = Daemon::getProcName();
+    if (family == AF_INET) {
+        if (proc_name != "kea-dhcp4") {
+            isc_throw(isc::Unexpected, "Bad process name: " << proc_name
+                      << ", expected kea-dhcp4");
+        }
+    } else {
+        if (proc_name != "kea-dhcp6") {
+            isc_throw(isc::Unexpected, "Bad process name: " << proc_name
+                      << ", expected kea-dhcp6");
+        }
+    }
+
+    // Register MySQL HB factories with Host Managers
+    isc::dhcp::HostDataSourceFactory::registerFactory("mysql", MySqlHostDataSource::factory, true);
+
+    LOG_INFO(mysql_hb_logger, MYSQL_HB_INIT_OK);
+    return (0);
+}
+
+/// @brief This function is called when the library is unloaded.
+///
+/// @return 0 if deregistration was successful, 1 otherwise
+int unload() {
+    // Unregister the factories and remove MySQL backends
+    isc::dhcp::HostDataSourceFactory::deregisterFactory("mysql", true);
+
+    LOG_INFO(mysql_hb_logger, MYSQL_HB_DEINIT_OK);
+    return (0);
+}
+
+/// @brief This function is called to retrieve the multi-threading compatibility.
+///
+/// @note: the compatibility is based on the assumption this hook library
+/// is always called from the main thread.
+///
+/// @return 1 which means compatible with multi-threading.
+int multi_threading_compatible() {
+    return (1);
+}
+
+} // end extern "C"
diff --git a/src/hooks/dhcp/mysql_hb/mysql_hb_log.cc b/src/hooks/dhcp/mysql_hb/mysql_hb_log.cc
new file mode 100644 (file)
index 0000000..b10bf3d
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright (C) 2019-2022 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <mysql_hb_log.h>
+
+namespace isc {
+namespace dhcp {
+
+isc::log::Logger mysql_hb_logger("mysql-hb-hooks");
+
+}  // namespace dhcp
+}  // namespace isc
diff --git a/src/hooks/dhcp/mysql_hb/mysql_hb_log.h b/src/hooks/dhcp/mysql_hb/mysql_hb_log.h
new file mode 100644 (file)
index 0000000..904d5fe
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright (C) 2019-2022 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef MYSQL_HB_LOG_H
+#define MYSQL_HB_LOG_H
+
+#include <log/logger_support.h>
+#include <log/macros.h>
+#include <mysql_hb_messages.h>
+
+namespace isc {
+namespace dhcp {
+
+extern isc::log::Logger mysql_hb_logger;
+
+}  // namespace dhcp
+}  // namespace isc
+
+#endif
diff --git a/src/hooks/dhcp/mysql_hb/mysql_hb_messages.cc b/src/hooks/dhcp/mysql_hb/mysql_hb_messages.cc
new file mode 100644 (file)
index 0000000..6acee77
--- /dev/null
@@ -0,0 +1,23 @@
+// File created from ../../../../src/hooks/dhcp/mysql_hb/mysql_hb_messages.mes
+
+#include <cstddef>
+#include <log/message_types.h>
+#include <log/message_initializer.h>
+
+extern const isc::log::MessageID MYSQL_HB_DB = "MYSQL_HB_DB";
+extern const isc::log::MessageID MYSQL_HB_DEINIT_OK = "MYSQL_HB_DEINIT_OK";
+extern const isc::log::MessageID MYSQL_HB_INIT_OK = "MYSQL_HB_INIT_OK";
+
+namespace {
+
+const char* values[] = {
+    "MYSQL_HB_DB", "opening MySQL hosts database: %1",
+    "MYSQL_HB_DEINIT_OK", "unloading MySQL HB hooks library successful",
+    "MYSQL_HB_INIT_OK", "loading MySQL HB hooks library successful",
+    NULL
+};
+
+const isc::log::MessageInitializer initializer(values);
+
+} // Anonymous namespace
+
diff --git a/src/hooks/dhcp/mysql_hb/mysql_hb_messages.h b/src/hooks/dhcp/mysql_hb/mysql_hb_messages.h
new file mode 100644 (file)
index 0000000..2b3d978
--- /dev/null
@@ -0,0 +1,12 @@
+// File created from ../../../../src/hooks/dhcp/mysql_hb/mysql_hb_messages.mes
+
+#ifndef MYSQL_HB_MESSAGES_H
+#define MYSQL_HB_MESSAGES_H
+
+#include <log/message_types.h>
+
+extern const isc::log::MessageID MYSQL_HB_DB;
+extern const isc::log::MessageID MYSQL_HB_DEINIT_OK;
+extern const isc::log::MessageID MYSQL_HB_INIT_OK;
+
+#endif // MYSQL_HB_MESSAGES_H
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..aab194a06a8d6cb430eaf5f527afcfe5fe92f299 100644 (file)
@@ -0,0 +1,14 @@
+% MYSQL_HB_DB opening MySQL hosts database: %1
+Logged at debug log level 50.
+This informational message is logged when a DHCP server (either V4 or
+V6) is about to open a MySQL hosts database. The parameters of the
+connection including database name and username needed to access it
+(but not the password if any) are logged.
+
+% MYSQL_HB_DEINIT_OK unloading MySQL HB hooks library successful
+This informational message indicates that the MySQL Host Backend hooks
+library has been unloaded successfully.
+
+% MYSQL_HB_INIT_OK loading MySQL HB hooks library successful
+This informational message indicates that the MySQL Host Backend hooks
+library has been loaded successfully. Enjoy!
index e77be063aa9aa9f2cfdd8b38846d46771900d493..e215c1f6c40a56bf3aad1cb98fe55a58244f93c1 100644 (file)
@@ -11,6 +11,7 @@
 #include <database/db_exceptions.h>
 #include <dhcpsrv/base_host_data_source.h>
 #include <dhcpsrv/host_data_source_factory.h>
+#include <mysql_hb_log.h>
 #include <mysql/mysql_connection.h>
 
 #include <stdint.h>
@@ -530,27 +531,32 @@ public:
 private:
     /// @brief Pointer to the implementation of the @ref MySqlHostDataSource.
     MySqlHostDataSourceImplPtr impl_;
+
+public:
+    /// @brief Factory class method.
+    ///
+    /// @param parameters A data structure relating keywords and values
+    ///        concerned with the database.
+    ///
+    /// @return The MySQL Host Manager.
+    static HostDataSourcePtr
+    factory(const isc::db::DatabaseConnection::ParameterMap& parameters) {
+        LOG_INFO(mysql_hb_logger, MYSQL_HB_DB)
+            .arg(isc::db::DatabaseConnection::redactedAccessString(parameters));
+        return (HostDataSourcePtr(new MySqlHostDataSource(parameters)));
+    }
 };
 
 struct MySqlHostDataSourceInit {
     // Constructor registers
     MySqlHostDataSourceInit() {
-        isc::dhcp::HostDataSourceFactory::registerFactory("mysql", factory, true);
+        isc::dhcp::HostDataSourceFactory::registerFactory("mysql", MySqlHostDataSource::factory, true);
     }
 
     // Destructor deregisters
     ~MySqlHostDataSourceInit() {
         isc::dhcp::HostDataSourceFactory::deregisterFactory("mysql", true);
     }
-
-    // Factory class method
-    static HostDataSourcePtr
-    factory(const isc::db::DatabaseConnection::ParameterMap& parameters) {
-        // TODO - fix messages
-        //LOG_INFO(hosts_logger, DHCPSRV_MYSQL_HOST_DB)
-        //    .arg(DatabaseConnection::redactedAccessString(parameters));
-        return (HostDataSourcePtr(new MySqlHostDataSource(parameters)));
-    }
 };
 
 }
diff --git a/src/hooks/dhcp/mysql_hb/version.cc b/src/hooks/dhcp/mysql_hb/version.cc
new file mode 100644 (file)
index 0000000..d64404b
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <hooks/hooks.h>
+
+extern "C" {
+
+/// @brief returns Kea hooks version.
+int version() {
+    return (KEA_HOOKS_VERSION);
+}
+
+}
diff --git a/src/hooks/dhcp/mysql_lb/.gitattributes b/src/hooks/dhcp/mysql_lb/.gitattributes
new file mode 100644 (file)
index 0000000..16c190a
--- /dev/null
@@ -0,0 +1,2 @@
+/mysql_lb_messages.cc            -diff merge=ours
+/mysql_lb_messages.h             -diff merge=ours
index 1d4c50dd3032aeea721f9772ae90d2ae3ac77624..57034e20f2117703d755176ff287b0941da4e711 100644 (file)
@@ -14,7 +14,11 @@ CLEANFILES = *.gcno *.gcda
 # convenience archive
 
 noinst_LTLIBRARIES = libmysqllb.la
-libmysqllb_la_SOURCES = mysql_lease_mgr.cc mysql_lease_mgr.h
+libmysqllb_la_SOURCES  = mysql_lb_callouts.cc
+libmysqllb_la_SOURCES += mysql_lb_log.cc mysql_lb_log.h
+libmysqllb_la_SOURCES += mysql_lb_messages.cc mysql_lb_messages.h
+libmysqllb_la_SOURCES += mysql_lease_mgr.cc mysql_lease_mgr.h
+libmysqllb_la_SOURCES += version.cc
 
 libmysqllb_la_CXXFLAGS = $(AM_CXXFLAGS)
 libmysqllb_la_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/src/hooks/dhcp/mysql_lb/libloadtests/.gitignore b/src/hooks/dhcp/mysql_lb/libloadtests/.gitignore
new file mode 100644 (file)
index 0000000..ada6ed5
--- /dev/null
@@ -0,0 +1 @@
+hook_load_unittests
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..f423defdd78939ded8df2425a8934fbffd0150a7 100644 (file)
@@ -0,0 +1,56 @@
+SUBDIRS = .
+
+AM_CPPFLAGS  = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+AM_CPPFLAGS += -I$(top_builddir)/src/hooks/dhcp/mysql_lb -I$(top_srcdir)/src/hooks/dhcp/mysql_lb
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+AM_CPPFLAGS += -DLIBDHCP_MYSQL_LB_SO=\"$(abs_top_builddir)/src/hooks/dhcp/mysql_lb/.libs/libdhcp_mysql_lb.so\"
+AM_CXXFLAGS = $(KEA_CXXFLAGS)
+
+if USE_STATIC_LINK
+AM_LDFLAGS = -static
+endif
+
+EXTRA_DIST =
+
+CLEANFILES = *.gcno *.gcda
+
+TESTS_ENVIRONMENT = \
+       $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
+
+if HAVE_GTEST
+
+TESTS = hook_load_unittests
+
+hook_load_unittests_SOURCES  =
+hook_load_unittests_SOURCES += load_unload_unittests.cc
+hook_load_unittests_SOURCES += run_unittests.cc
+hook_load_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(LOG4CPLUS_INCLUDES)
+hook_load_unittests_CXXFLAGS = $(AM_CXXFLAGS)
+hook_load_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
+
+hook_load_unittests_LDADD  = $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/process/libkea-process.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/eval/libkea-eval.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/http/libkea-http.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/mysql/libkea-mysql.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/database/libkea-database.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/cryptolink/libkea-cryptolink.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
+hook_load_unittests_LDADD += $(LOG4CPLUS_LIBS)
+hook_load_unittests_LDADD += $(CRYPTO_LIBS)
+hook_load_unittests_LDADD += $(BOOST_LIBS)
+hook_load_unittests_LDADD += $(GTEST_LDADD)
+
+noinst_PROGRAMS = $(TESTS)
+
+endif
diff --git a/src/hooks/dhcp/mysql_lb/libloadtests/load_unload_unittests.cc b/src/hooks/dhcp/mysql_lb/libloadtests/load_unload_unittests.cc
new file mode 100644 (file)
index 0000000..339c60f
--- /dev/null
@@ -0,0 +1,60 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+/// @file This file contains tests which exercise the load and unload
+/// functions in the ddns tuning hook library. In order to test the load
+/// function, one must be able to pass it hook library parameters. The
+/// the only way to populate these parameters is by actually loading the
+/// library via HooksManager::loadLibraries().
+
+#include <config.h>
+
+#include <dhcpsrv/testutils/lib_load_test_fixture.h>
+#include <testutils/gtest_utils.h>
+
+#include <gtest/gtest.h>
+#include <errno.h>
+
+using namespace std;
+using namespace isc;
+using namespace isc::hooks;
+using namespace isc::data;
+using namespace isc::dhcp;
+using namespace isc::process;
+
+namespace {
+
+/// @brief Test fixture for testing loading and unloading the MySQL lb library
+class MySqlLbLibLoadTest : public isc::test::LibLoadTest {
+public:
+    /// @brief Constructor
+    MySqlLbLibLoadTest() : LibLoadTest(LIBDHCP_MYSQL_LB_SO) {
+    }
+
+    /// @brief Destructor
+    virtual ~MySqlLbLibLoadTest() {
+        unloadLibraries();
+    }
+};
+
+// Simple V4 test that checks the library can be loaded and unloaded several times.
+TEST_F(MySqlLbLibLoadTest, validLoad4) {
+    validDaemonTest("kea-dhcp4");
+}
+
+// Simple V6 test that checks the library can be loaded and unloaded several times.
+TEST_F(MySqlLbLibLoadTest, validLoad6) {
+    validDaemonTest("kea-dhcp6", AF_INET6);
+}
+
+// Simple test that checks the library cannot by loaded by invalid daemons.
+TEST_F(MySqlLbLibLoadTest, invalidDaemonLoad) {
+    invalidDaemonTest("kea-ctrl-agent");
+    invalidDaemonTest("kea-dhcp-ddns");
+    invalidDaemonTest("bogus");
+}
+
+} // end of anonymous namespace
diff --git a/src/hooks/dhcp/mysql_lb/libloadtests/run_unittests.cc b/src/hooks/dhcp/mysql_lb/libloadtests/run_unittests.cc
new file mode 100644 (file)
index 0000000..755b9e4
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <log/logger_support.h>
+#include <gtest/gtest.h>
+
+int
+main(int argc, char* argv[]) {
+    ::testing::InitGoogleTest(&argc, argv);
+    isc::log::initLogger();
+    int result = RUN_ALL_TESTS();
+
+    return (result);
+}
diff --git a/src/hooks/dhcp/mysql_lb/mysql_lb_callouts.cc b/src/hooks/dhcp/mysql_lb/mysql_lb_callouts.cc
new file mode 100644 (file)
index 0000000..0d74d99
--- /dev/null
@@ -0,0 +1,82 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+// Functions accessed by the hooks framework use C linkage to avoid the name
+// mangling that accompanies use of the C++ compiler as well as to avoid
+// issues related to namespaces.
+
+#include <config.h>
+
+#include <asiolink/io_service_mgr.h>
+#include <dhcpsrv/cfgmgr.h>
+#include <hooks/hooks.h>
+#include <process/daemon.h>
+#include <mysql_lb_log.h>
+#include <mysql_lease_mgr.h>
+#include <dhcpsrv/lease_mgr_factory.h>
+
+#include <sstream>
+#include <string>
+
+using namespace isc::asiolink;
+using namespace isc::dhcp;
+using namespace isc::hooks;
+using namespace isc::log;
+using namespace isc::process;
+using namespace std;
+
+extern "C" {
+
+/// @brief This function is called when the library is loaded.
+///
+/// @param handle library handle
+/// @return 0 when initialization is successful, 1 otherwise
+
+int load(LibraryHandle& /* handle */) {
+    // Make the hook library not loadable by d2 or ca.
+    uint16_t family = CfgMgr::instance().getFamily();
+    const std::string& proc_name = Daemon::getProcName();
+    if (family == AF_INET) {
+        if (proc_name != "kea-dhcp4") {
+            isc_throw(isc::Unexpected, "Bad process name: " << proc_name
+                      << ", expected kea-dhcp4");
+        }
+    } else {
+        if (proc_name != "kea-dhcp6") {
+            isc_throw(isc::Unexpected, "Bad process name: " << proc_name
+                      << ", expected kea-dhcp6");
+        }
+    }
+
+    // Register MySQL LB factories with Lease Managers
+    LeaseMgrFactory::registerFactory("mysql", MySqlLeaseMgr::factory, true);
+
+    LOG_INFO(mysql_lb_logger, MYSQL_LB_INIT_OK);
+    return (0);
+}
+
+/// @brief This function is called when the library is unloaded.
+///
+/// @return 0 if deregistration was successful, 1 otherwise
+int unload() {
+    // Unregister the factories and remove MySQL backends
+    LeaseMgrFactory::deregisterFactory("mysql", true);
+
+    LOG_INFO(mysql_lb_logger, MYSQL_LB_DEINIT_OK);
+    return (0);
+}
+
+/// @brief This function is called to retrieve the multi-threading compatibility.
+///
+/// @note: the compatibility is based on the assumption this hook library
+/// is always called from the main thread.
+///
+/// @return 1 which means compatible with multi-threading.
+int multi_threading_compatible() {
+    return (1);
+}
+
+} // end extern "C"
diff --git a/src/hooks/dhcp/mysql_lb/mysql_lb_log.cc b/src/hooks/dhcp/mysql_lb/mysql_lb_log.cc
new file mode 100644 (file)
index 0000000..2064ae5
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright (C) 2019-2022 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <mysql_lb_log.h>
+
+namespace isc {
+namespace dhcp {
+
+isc::log::Logger mysql_lb_logger("mysql-lb-hooks");
+
+}  // namespace dhcp
+}  // namespace isc
diff --git a/src/hooks/dhcp/mysql_lb/mysql_lb_log.h b/src/hooks/dhcp/mysql_lb/mysql_lb_log.h
new file mode 100644 (file)
index 0000000..444dc95
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright (C) 2019-2022 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef MYSQL_LB_LOG_H
+#define MYSQL_LB_LOG_H
+
+#include <log/logger_support.h>
+#include <log/macros.h>
+#include <mysql_lb_messages.h>
+
+namespace isc {
+namespace dhcp {
+
+extern isc::log::Logger mysql_lb_logger;
+
+}  // namespace dhcp
+}  // namespace isc
+
+#endif
diff --git a/src/hooks/dhcp/mysql_lb/mysql_lb_messages.cc b/src/hooks/dhcp/mysql_lb/mysql_lb_messages.cc
new file mode 100644 (file)
index 0000000..81d6f1e
--- /dev/null
@@ -0,0 +1,23 @@
+// File created from ../../../../src/hooks/dhcp/mysql_lb/mysql_lb_messages.mes
+
+#include <cstddef>
+#include <log/message_types.h>
+#include <log/message_initializer.h>
+
+extern const isc::log::MessageID MYSQL_LB_DB = "MYSQL_LB_DB";
+extern const isc::log::MessageID MYSQL_LB_DEINIT_OK = "MYSQL_LB_DEINIT_OK";
+extern const isc::log::MessageID MYSQL_LB_INIT_OK = "MYSQL_LB_INIT_OK";
+
+namespace {
+
+const char* values[] = {
+    "MYSQL_LB_DB", "opening MySQL lease database: %1",
+    "MYSQL_LB_DEINIT_OK", "unloading MySQL LB hooks library successful",
+    "MYSQL_LB_INIT_OK", "loading MySQL LB hooks library successful",
+    NULL
+};
+
+const isc::log::MessageInitializer initializer(values);
+
+} // Anonymous namespace
+
diff --git a/src/hooks/dhcp/mysql_lb/mysql_lb_messages.h b/src/hooks/dhcp/mysql_lb/mysql_lb_messages.h
new file mode 100644 (file)
index 0000000..6de5744
--- /dev/null
@@ -0,0 +1,12 @@
+// File created from ../../../../src/hooks/dhcp/mysql_lb/mysql_lb_messages.mes
+
+#ifndef MYSQL_LB_MESSAGES_H
+#define MYSQL_LB_MESSAGES_H
+
+#include <log/message_types.h>
+
+extern const isc::log::MessageID MYSQL_LB_DB;
+extern const isc::log::MessageID MYSQL_LB_DEINIT_OK;
+extern const isc::log::MessageID MYSQL_LB_INIT_OK;
+
+#endif // MYSQL_LB_MESSAGES_H
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..b037442c5107bf0da602a04e6c9e93a69ebf4f8d 100644 (file)
@@ -0,0 +1,13 @@
+% MYSQL_LB_DB opening MySQL lease database: %1
+This informational message is logged when a DHCP server (either V4 or
+V6) is about to open a MySQL lease database. The parameters of the
+connection including database name and username needed to access it
+(but not the password if any) are logged.
+
+% MYSQL_LB_DEINIT_OK unloading MySQL LB hooks library successful
+This informational message indicates that the MySQL Lease Backend hooks
+library has been unloaded successfully.
+
+% MYSQL_LB_INIT_OK loading MySQL LB hooks library successful
+This informational message indicates that the MySQL Lease Backend hooks
+library has been loaded successfully. Enjoy!
index cde5f21198c948a46d2ff7de2c36c0f862b69ca9..acb49565ac05bb44b1cd3f3e155289a19a2d07c7 100644 (file)
@@ -8,9 +8,12 @@
 #define MYSQL_LEASE_MGR_H
 
 #include <asiolink/io_service.h>
+#include <database/database_connection.h>
 #include <dhcp/hwaddr.h>
 #include <dhcpsrv/dhcpsrv_exceptions.h>
+#include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcpsrv/tracking_lease_mgr.h>
+#include <mysql_lb_log.h>
 #include <mysql/mysql_connection.h>
 
 #include <boost/scoped_ptr.hpp>
@@ -1295,27 +1298,32 @@ private:
 
     /// @brief Timer name used to register database reconnect timer.
     std::string timer_name_;
+
+public:
+    /// @brief Factory class method.
+    ///
+    /// @param parameters A data structure relating keywords and values
+    ///        concerned with the database.
+    ///
+    /// @return The MySQL Lease Manager.
+    static TrackingLeaseMgrPtr
+    factory(const isc::db::DatabaseConnection::ParameterMap& parameters) {
+        LOG_INFO(mysql_lb_logger, MYSQL_LB_DB)
+            .arg(isc::db::DatabaseConnection::redactedAccessString(parameters));
+        return (TrackingLeaseMgrPtr(new MySqlLeaseMgr(parameters)));
+    }
 };
 
 struct MySqlLeaseMgrInit {
     // Constructor registers
     MySqlLeaseMgrInit() {
-        LeaseMgrFactory::registerFactory("mysql", factory, true);
+        LeaseMgrFactory::registerFactory("mysql", MySqlLeaseMgr::factory, true);
     }
 
     // Destructor deregisters
     ~MySqlLeaseMgrInit() {
         LeaseMgrFactory::deregisterFactory("mysql", true);
     }
-
-    // Factory class method
-    static TrackingLeaseMgrPtr
-    factory(const isc::db::DatabaseConnection::ParameterMap& parameters) {
-        // TODO - fix messages
-        //LOG_INFO(dhcpsrv_logger, DHCPSRV_MYSQL_DB)
-        //    .arg(DatabaseConnection::redactedAccessString(parameters));
-        return (TrackingLeaseMgrPtr(new MySqlLeaseMgr(parameters)));
-    }
 };
 
 }  // namespace dhcp
diff --git a/src/hooks/dhcp/mysql_lb/version.cc b/src/hooks/dhcp/mysql_lb/version.cc
new file mode 100644 (file)
index 0000000..d64404b
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <hooks/hooks.h>
+
+extern "C" {
+
+/// @brief returns Kea hooks version.
+int version() {
+    return (KEA_HOOKS_VERSION);
+}
+
+}
index 63311778f150a66db81a56718fed3641df8f117a..c2db08535e502fc677b72b5c2ad2a450e2b50cf7 100644 (file)
@@ -4,8 +4,8 @@
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-#ifndef LEASE_CMD_LOG_H
-#define LEASE_CMD_LOG_H
+#ifndef PGSQL_CB_LOG_H
+#define PGSQL_CB_LOG_H
 
 #include <log/logger_support.h>
 #include <log/macros.h>
index 2baed5c5e5077e1f98ec404d1a350c99b9206abc..ea9550beae8cbd3fb68b5c2eafe1a0b4d4eb7a89 100644 (file)
@@ -226,7 +226,7 @@ const char* values[] = {
     "PGSQL_CB_CREATE_UPDATE_SHARED_NETWORK_OPTION6", "create or update shared network: %1 option",
     "PGSQL_CB_CREATE_UPDATE_SUBNET4", "create or update subnet: %1",
     "PGSQL_CB_CREATE_UPDATE_SUBNET6", "create or update subnet: %1",
-    "PGSQL_CB_DEINIT_OK", "unloading Postgres CB hooks library successful",
+    "PGSQL_CB_DEINIT_OK", "unloading PostgreSQL CB hooks library successful",
     "PGSQL_CB_DELETE_ALL_CLIENT_CLASSES4", "delete all client classes",
     "PGSQL_CB_DELETE_ALL_CLIENT_CLASSES4_RESULT", "deleted: %1 entries",
     "PGSQL_CB_DELETE_ALL_CLIENT_CLASSES6", "delete all client classes",
@@ -383,7 +383,7 @@ const char* values[] = {
     "PGSQL_CB_GET_SUBNET6_BY_SUBNET_ID", "retrieving subnet by subnet id: %1",
     "PGSQL_CB_GET_TYPE4", "get type",
     "PGSQL_CB_GET_TYPE6", "get type",
-    "PGSQL_CB_INIT_OK", "loading Postgres CB hooks library successful",
+    "PGSQL_CB_INIT_OK", "loading PostgreSQL CB hooks library successful",
     "PGSQL_CB_NO_TLS_SUPPORT", "Attempt to configure TLS (unsupported for PostgreSQL): %1",
     "PGSQL_CB_RECONNECT_ATTEMPT_FAILED4", "database reconnect failed: %1",
     "PGSQL_CB_RECONNECT_ATTEMPT_FAILED6", "database reconnect failed: %1",
index 5c076b50a20e9dd743f2a102994aefffecf488ca..4072a03623c4ae8b86b4dadcd7177bef5ce8278a 100644 (file)
@@ -88,8 +88,8 @@ Debug message issued when triggered an action to create or update subnet
 Logged at debug log level 40.
 Debug message issued when triggered an action to create or update subnet
 
-% PGSQL_CB_DEINIT_OK unloading Postgres CB hooks library successful
-This informational message indicates that the Postgres Configuration Backend hooks
+% PGSQL_CB_DEINIT_OK unloading PostgreSQL CB hooks library successful
+This informational message indicates that the PostgreSQL Configuration Backend hooks
 library has been unloaded successfully.
 
 % PGSQL_CB_DELETE_ALL_CLIENT_CLASSES4 delete all client classes
@@ -720,8 +720,8 @@ Debug message issued when triggered an action to retrieve type
 Logged at debug log level 40.
 Debug message issued when triggered an action to retrieve type
 
-% PGSQL_CB_INIT_OK loading Postgres CB hooks library successful
-This informational message indicates that the Postgres Configuration Backend hooks
+% PGSQL_CB_INIT_OK loading PostgreSQL CB hooks library successful
+This informational message indicates that the PostgreSQL Configuration Backend hooks
 library has been loaded successfully. Enjoy!
 
 % PGSQL_CB_NO_TLS_SUPPORT Attempt to configure TLS (unsupported for PostgreSQL): %1
diff --git a/src/hooks/dhcp/pgsql_hb/.gitattributes b/src/hooks/dhcp/pgsql_hb/.gitattributes
new file mode 100644 (file)
index 0000000..9a63b22
--- /dev/null
@@ -0,0 +1,2 @@
+/pgsql_hb_messages.cc            -diff merge=ours
+/pgsql_hb_messages.h             -diff merge=ours
index 3a146b4673b2c09c9267185118442d13facd70ec..a2ee882632f3aca54b0373bad6f2be81083e4b22 100644 (file)
@@ -14,7 +14,11 @@ CLEANFILES = *.gcno *.gcda
 # convenience archive
 
 noinst_LTLIBRARIES = libpgsqlhb.la
-libpgsqlhb_la_SOURCES = pgsql_host_data_source.cc pgsql_host_data_source.h
+libpgsqlhb_la_SOURCES  = pgsql_hb_callouts.cc
+libpgsqlhb_la_SOURCES += pgsql_hb_log.cc pgsql_hb_log.h
+libpgsqlhb_la_SOURCES += pgsql_hb_messages.cc pgsql_hb_messages.h
+libpgsqlhb_la_SOURCES += pgsql_host_data_source.cc pgsql_host_data_source.h
+libpgsqlhb_la_SOURCES += version.cc
 
 libpgsqlhb_la_CXXFLAGS = $(AM_CXXFLAGS)
 libpgsqlhb_la_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/src/hooks/dhcp/pgsql_hb/libloadtests/.gitignore b/src/hooks/dhcp/pgsql_hb/libloadtests/.gitignore
new file mode 100644 (file)
index 0000000..ada6ed5
--- /dev/null
@@ -0,0 +1 @@
+hook_load_unittests
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..552e49a5508f6831e33bd74faeb172476320097d 100644 (file)
@@ -0,0 +1,56 @@
+SUBDIRS = .
+
+AM_CPPFLAGS  = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+AM_CPPFLAGS += -I$(top_builddir)/src/hooks/dhcp/pgsql_hb -I$(top_srcdir)/src/hooks/dhcp/pgsql_hb
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+AM_CPPFLAGS += -DLIBDHCP_PGSQL_HB_SO=\"$(abs_top_builddir)/src/hooks/dhcp/pgsql_hb/.libs/libdhcp_pgsql_hb.so\"
+AM_CXXFLAGS = $(KEA_CXXFLAGS)
+
+if USE_STATIC_LINK
+AM_LDFLAGS = -static
+endif
+
+EXTRA_DIST =
+
+CLEANFILES = *.gcno *.gcda
+
+TESTS_ENVIRONMENT = \
+       $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
+
+if HAVE_GTEST
+
+TESTS = hook_load_unittests
+
+hook_load_unittests_SOURCES  =
+hook_load_unittests_SOURCES += load_unload_unittests.cc
+hook_load_unittests_SOURCES += run_unittests.cc
+hook_load_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(LOG4CPLUS_INCLUDES)
+hook_load_unittests_CXXFLAGS = $(AM_CXXFLAGS)
+hook_load_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
+
+hook_load_unittests_LDADD  = $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/process/libkea-process.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/eval/libkea-eval.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/http/libkea-http.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/pgsql/libkea-pgsql.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/database/libkea-database.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/cryptolink/libkea-cryptolink.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
+hook_load_unittests_LDADD += $(LOG4CPLUS_LIBS)
+hook_load_unittests_LDADD += $(CRYPTO_LIBS)
+hook_load_unittests_LDADD += $(BOOST_LIBS)
+hook_load_unittests_LDADD += $(GTEST_LDADD)
+
+noinst_PROGRAMS = $(TESTS)
+
+endif
diff --git a/src/hooks/dhcp/pgsql_hb/libloadtests/load_unload_unittests.cc b/src/hooks/dhcp/pgsql_hb/libloadtests/load_unload_unittests.cc
new file mode 100644 (file)
index 0000000..5de4cd2
--- /dev/null
@@ -0,0 +1,60 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+/// @file This file contains tests which exercise the load and unload
+/// functions in the ddns tuning hook library. In order to test the load
+/// function, one must be able to pass it hook library parameters. The
+/// the only way to populate these parameters is by actually loading the
+/// library via HooksManager::loadLibraries().
+
+#include <config.h>
+
+#include <dhcpsrv/testutils/lib_load_test_fixture.h>
+#include <testutils/gtest_utils.h>
+
+#include <gtest/gtest.h>
+#include <errno.h>
+
+using namespace std;
+using namespace isc;
+using namespace isc::hooks;
+using namespace isc::data;
+using namespace isc::dhcp;
+using namespace isc::process;
+
+namespace {
+
+/// @brief Test fixture for testing loading and unloading the PgSQL hb library
+class PgSqlHbLibLoadTest : public isc::test::LibLoadTest {
+public:
+    /// @brief Constructor
+    PgSqlHbLibLoadTest() : LibLoadTest(LIBDHCP_PGSQL_HB_SO) {
+    }
+
+    /// @brief Destructor
+    virtual ~PgSqlHbLibLoadTest() {
+        unloadLibraries();
+    }
+};
+
+// Simple V4 test that checks the library can be loaded and unloaded several times.
+TEST_F(PgSqlHbLibLoadTest, validLoad4) {
+    validDaemonTest("kea-dhcp4");
+}
+
+// Simple V6 test that checks the library can be loaded and unloaded several times.
+TEST_F(PgSqlHbLibLoadTest, validLoad6) {
+    validDaemonTest("kea-dhcp6", AF_INET6);
+}
+
+// Simple test that checks the library cannot by loaded by invalid daemons.
+TEST_F(PgSqlHbLibLoadTest, invalidDaemonLoad) {
+    invalidDaemonTest("kea-ctrl-agent");
+    invalidDaemonTest("kea-dhcp-ddns");
+    invalidDaemonTest("bogus");
+}
+
+} // end of anonymous namespace
diff --git a/src/hooks/dhcp/pgsql_hb/libloadtests/run_unittests.cc b/src/hooks/dhcp/pgsql_hb/libloadtests/run_unittests.cc
new file mode 100644 (file)
index 0000000..755b9e4
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <log/logger_support.h>
+#include <gtest/gtest.h>
+
+int
+main(int argc, char* argv[]) {
+    ::testing::InitGoogleTest(&argc, argv);
+    isc::log::initLogger();
+    int result = RUN_ALL_TESTS();
+
+    return (result);
+}
diff --git a/src/hooks/dhcp/pgsql_hb/pgsql_hb_callouts.cc b/src/hooks/dhcp/pgsql_hb/pgsql_hb_callouts.cc
new file mode 100644 (file)
index 0000000..02158af
--- /dev/null
@@ -0,0 +1,82 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+// Functions accessed by the hooks framework use C linkage to avoid the name
+// mangling that accompanies use of the C++ compiler as well as to avoid
+// issues related to namespaces.
+
+#include <config.h>
+
+#include <asiolink/io_service_mgr.h>
+#include <dhcpsrv/base_host_data_source.h>
+#include <dhcpsrv/cfgmgr.h>
+#include <hooks/hooks.h>
+#include <process/daemon.h>
+#include <pgsql_hb_log.h>
+#include <pgsql_host_data_source.h>
+
+#include <sstream>
+#include <string>
+
+using namespace isc::asiolink;
+using namespace isc::dhcp;
+using namespace isc::hooks;
+using namespace isc::log;
+using namespace isc::process;
+using namespace std;
+
+extern "C" {
+
+/// @brief This function is called when the library is loaded.
+///
+/// @param handle library handle
+/// @return 0 when initialization is successful, 1 otherwise
+
+int load(LibraryHandle& /* handle */) {
+    // Make the hook library not loadable by d2 or ca.
+    uint16_t family = CfgMgr::instance().getFamily();
+    const std::string& proc_name = Daemon::getProcName();
+    if (family == AF_INET) {
+        if (proc_name != "kea-dhcp4") {
+            isc_throw(isc::Unexpected, "Bad process name: " << proc_name
+                      << ", expected kea-dhcp4");
+        }
+    } else {
+        if (proc_name != "kea-dhcp6") {
+            isc_throw(isc::Unexpected, "Bad process name: " << proc_name
+                      << ", expected kea-dhcp6");
+        }
+    }
+
+    // Register PgSQL HB factories with Host Managers
+    isc::dhcp::HostDataSourceFactory::registerFactory("postgresql", PgSqlHostDataSource::factory, true);
+
+    LOG_INFO(pgsql_hb_logger, PGSQL_HB_INIT_OK);
+    return (0);
+}
+
+/// @brief This function is called when the library is unloaded.
+///
+/// @return 0 if deregistration was successful, 1 otherwise
+int unload() {
+    // Unregister the factories and remove PgSQL backends
+    isc::dhcp::HostDataSourceFactory::deregisterFactory("postgresql", true);
+
+    LOG_INFO(pgsql_hb_logger, PGSQL_HB_DEINIT_OK);
+    return (0);
+}
+
+/// @brief This function is called to retrieve the multi-threading compatibility.
+///
+/// @note: the compatibility is based on the assumption this hook library
+/// is always called from the main thread.
+///
+/// @return 1 which means compatible with multi-threading.
+int multi_threading_compatible() {
+    return (1);
+}
+
+} // end extern "C"
diff --git a/src/hooks/dhcp/pgsql_hb/pgsql_hb_log.cc b/src/hooks/dhcp/pgsql_hb/pgsql_hb_log.cc
new file mode 100644 (file)
index 0000000..144c6ea
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright (C) 2019-2022 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <pgsql_hb_log.h>
+
+namespace isc {
+namespace dhcp {
+
+isc::log::Logger pgsql_hb_logger("pgsql-hb-hooks");
+
+}  // namespace dhcp
+}  // namespace isc
diff --git a/src/hooks/dhcp/pgsql_hb/pgsql_hb_log.h b/src/hooks/dhcp/pgsql_hb/pgsql_hb_log.h
new file mode 100644 (file)
index 0000000..b4f314b
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright (C) 2019-2022 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef PGSQL_HB_LOG_H
+#define PGSQL_HB_LOG_H
+
+#include <log/logger_support.h>
+#include <log/macros.h>
+#include <pgsql_hb_messages.h>
+
+namespace isc {
+namespace dhcp {
+
+extern isc::log::Logger pgsql_hb_logger;
+
+}  // namespace dhcp
+}  // namespace isc
+
+#endif
diff --git a/src/hooks/dhcp/pgsql_hb/pgsql_hb_messages.cc b/src/hooks/dhcp/pgsql_hb/pgsql_hb_messages.cc
new file mode 100644 (file)
index 0000000..63ca000
--- /dev/null
@@ -0,0 +1,23 @@
+// File created from ../../../../src/hooks/dhcp/pgsql_hb/pgsql_hb_messages.mes
+
+#include <cstddef>
+#include <log/message_types.h>
+#include <log/message_initializer.h>
+
+extern const isc::log::MessageID PGSQL_HB_DB = "PGSQL_HB_DB";
+extern const isc::log::MessageID PGSQL_HB_DEINIT_OK = "PGSQL_HB_DEINIT_OK";
+extern const isc::log::MessageID PGSQL_HB_INIT_OK = "PGSQL_HB_INIT_OK";
+
+namespace {
+
+const char* values[] = {
+    "PGSQL_HB_DB", "opening PostgreSQL hosts database: %1",
+    "PGSQL_HB_DEINIT_OK", "unloading PostgreSQL HB hooks library successful",
+    "PGSQL_HB_INIT_OK", "loading PostgreSQL HB hooks library successful",
+    NULL
+};
+
+const isc::log::MessageInitializer initializer(values);
+
+} // Anonymous namespace
+
diff --git a/src/hooks/dhcp/pgsql_hb/pgsql_hb_messages.h b/src/hooks/dhcp/pgsql_hb/pgsql_hb_messages.h
new file mode 100644 (file)
index 0000000..f001c18
--- /dev/null
@@ -0,0 +1,12 @@
+// File created from ../../../../src/hooks/dhcp/pgsql_hb/pgsql_hb_messages.mes
+
+#ifndef PGSQL_HB_MESSAGES_H
+#define PGSQL_HB_MESSAGES_H
+
+#include <log/message_types.h>
+
+extern const isc::log::MessageID PGSQL_HB_DB;
+extern const isc::log::MessageID PGSQL_HB_DEINIT_OK;
+extern const isc::log::MessageID PGSQL_HB_INIT_OK;
+
+#endif // PGSQL_HB_MESSAGES_H
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..e0b533608072949d970926d95cb8f1e31b693232 100644 (file)
@@ -0,0 +1,14 @@
+% PGSQL_HB_DB opening PostgreSQL hosts database: %1
+Logged at debug log level 50.
+This informational message is logged when a DHCP server (either V4 or
+V6) is about to open a PostgreSQL hosts database. The parameters of the
+connection including database name and username needed to access it
+(but not the password if any) are logged.
+
+% PGSQL_HB_DEINIT_OK unloading PostgreSQL HB hooks library successful
+This informational message indicates that the PostgreSQL Host Backend hooks
+library has been unloaded successfully.
+
+% PGSQL_HB_INIT_OK loading PostgreSQL HB hooks library successful
+This informational message indicates that the PostgreSQL Host Backend hooks
+library has been loaded successfully. Enjoy!
index 6fe55fdc1b21f454a4c3dcfeec0fb3f5334516bf..e4d371a8f0a2afbc6e5b33649121af0ebc4e95f5 100644 (file)
@@ -10,6 +10,7 @@
 #include <database/database_connection.h>
 #include <dhcpsrv/base_host_data_source.h>
 #include <dhcpsrv/host_data_source_factory.h>
+#include <pgsql_hb_log.h>
 #include <pgsql/pgsql_connection.h>
 #include <pgsql/pgsql_exchange.h>
 
@@ -582,27 +583,32 @@ public:
 private:
     /// @brief Pointer to the implementation of the @ref PgSqlHostDataSource.
     PgSqlHostDataSourceImplPtr impl_;
+
+public:
+    /// @brief Factory class method.
+    ///
+    /// @param parameters A data structure relating keywords and values
+    ///        concerned with the database.
+    ///
+    /// @return The PostgreSQL Host Manager.
+    static HostDataSourcePtr
+    factory(const isc::db::DatabaseConnection::ParameterMap& parameters) {
+        LOG_INFO(pgsql_hb_logger, PGSQL_HB_DB)
+            .arg(isc::db::DatabaseConnection::redactedAccessString(parameters));
+        return (HostDataSourcePtr(new PgSqlHostDataSource(parameters)));
+    }
 };
 
 struct PgSqlHostDataSourceInit {
     // Constructor registers
     PgSqlHostDataSourceInit() {
-        isc::dhcp::HostDataSourceFactory::registerFactory("postgresql", factory, true);
+        isc::dhcp::HostDataSourceFactory::registerFactory("postgresql", PgSqlHostDataSource::factory, true);
     }
 
     // Destructor deregisters
     ~PgSqlHostDataSourceInit() {
         isc::dhcp::HostDataSourceFactory::deregisterFactory("postgresql", true);
     }
-
-    // Factory class method
-    static HostDataSourcePtr
-    factory(const isc::db::DatabaseConnection::ParameterMap& parameters) {
-        // TODO - fix messages
-        //LOG_INFO(hosts_logger, DHCPSRV_PGSQL_HOST_DB)
-        //    .arg(DatabaseConnection::redactedAccessString(parameters));
-        return (HostDataSourcePtr(new PgSqlHostDataSource(parameters)));
-    }
 };
 
 }  // namespace dhcp
diff --git a/src/hooks/dhcp/pgsql_hb/version.cc b/src/hooks/dhcp/pgsql_hb/version.cc
new file mode 100644 (file)
index 0000000..d64404b
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <hooks/hooks.h>
+
+extern "C" {
+
+/// @brief returns Kea hooks version.
+int version() {
+    return (KEA_HOOKS_VERSION);
+}
+
+}
diff --git a/src/hooks/dhcp/pgsql_lb/.gitattributes b/src/hooks/dhcp/pgsql_lb/.gitattributes
new file mode 100644 (file)
index 0000000..2b7068e
--- /dev/null
@@ -0,0 +1,2 @@
+/pgsql_lb_messages.cc            -diff merge=ours
+/pgsql_lb_messages.h             -diff merge=ours
index b8f2b17405ade00b351321543c405eee58d1862b..00eb7a3fdcedb746b9467acf90489eab9f21dd15 100644 (file)
@@ -14,7 +14,11 @@ CLEANFILES = *.gcno *.gcda
 # convenience archive
 
 noinst_LTLIBRARIES = libpgsqllb.la
-libpgsqllb_la_SOURCES = pgsql_lease_mgr.cc pgsql_lease_mgr.h
+libpgsqllb_la_SOURCES  = pgsql_lb_callouts.cc
+libpgsqllb_la_SOURCES += pgsql_lb_log.cc pgsql_lb_log.h
+libpgsqllb_la_SOURCES += pgsql_lb_messages.cc pgsql_lb_messages.h
+libpgsqllb_la_SOURCES += pgsql_lease_mgr.cc pgsql_lease_mgr.h
+libpgsqllb_la_SOURCES += version.cc
 
 libpgsqllb_la_CXXFLAGS = $(AM_CXXFLAGS)
 libpgsqllb_la_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/src/hooks/dhcp/pgsql_lb/libloadtests/.gitignore b/src/hooks/dhcp/pgsql_lb/libloadtests/.gitignore
new file mode 100644 (file)
index 0000000..ada6ed5
--- /dev/null
@@ -0,0 +1 @@
+hook_load_unittests
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..c436c60ea11287c102110b78e32b1b7556c56b5f 100644 (file)
@@ -0,0 +1,56 @@
+SUBDIRS = .
+
+AM_CPPFLAGS  = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+AM_CPPFLAGS += -I$(top_builddir)/src/hooks/dhcp/pgsql_lb -I$(top_srcdir)/src/hooks/dhcp/pgsql_lb
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+AM_CPPFLAGS += -DLIBDHCP_PGSQL_LB_SO=\"$(abs_top_builddir)/src/hooks/dhcp/pgsql_lb/.libs/libdhcp_pgsql_lb.so\"
+AM_CXXFLAGS = $(KEA_CXXFLAGS)
+
+if USE_STATIC_LINK
+AM_LDFLAGS = -static
+endif
+
+EXTRA_DIST =
+
+CLEANFILES = *.gcno *.gcda
+
+TESTS_ENVIRONMENT = \
+       $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
+
+if HAVE_GTEST
+
+TESTS = hook_load_unittests
+
+hook_load_unittests_SOURCES  =
+hook_load_unittests_SOURCES += load_unload_unittests.cc
+hook_load_unittests_SOURCES += run_unittests.cc
+hook_load_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(LOG4CPLUS_INCLUDES)
+hook_load_unittests_CXXFLAGS = $(AM_CXXFLAGS)
+hook_load_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
+
+hook_load_unittests_LDADD  = $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/process/libkea-process.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/eval/libkea-eval.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/http/libkea-http.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/pgsql/libkea-pgsql.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/database/libkea-database.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/cryptolink/libkea-cryptolink.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
+hook_load_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
+hook_load_unittests_LDADD += $(LOG4CPLUS_LIBS)
+hook_load_unittests_LDADD += $(CRYPTO_LIBS)
+hook_load_unittests_LDADD += $(BOOST_LIBS)
+hook_load_unittests_LDADD += $(GTEST_LDADD)
+
+noinst_PROGRAMS = $(TESTS)
+
+endif
diff --git a/src/hooks/dhcp/pgsql_lb/libloadtests/load_unload_unittests.cc b/src/hooks/dhcp/pgsql_lb/libloadtests/load_unload_unittests.cc
new file mode 100644 (file)
index 0000000..dc975d3
--- /dev/null
@@ -0,0 +1,60 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+/// @file This file contains tests which exercise the load and unload
+/// functions in the ddns tuning hook library. In order to test the load
+/// function, one must be able to pass it hook library parameters. The
+/// the only way to populate these parameters is by actually loading the
+/// library via HooksManager::loadLibraries().
+
+#include <config.h>
+
+#include <dhcpsrv/testutils/lib_load_test_fixture.h>
+#include <testutils/gtest_utils.h>
+
+#include <gtest/gtest.h>
+#include <errno.h>
+
+using namespace std;
+using namespace isc;
+using namespace isc::hooks;
+using namespace isc::data;
+using namespace isc::dhcp;
+using namespace isc::process;
+
+namespace {
+
+/// @brief Test fixture for testing loading and unloading the PgSQL lb library
+class PgSqlLbLibLoadTest : public isc::test::LibLoadTest {
+public:
+    /// @brief Constructor
+    PgSqlLbLibLoadTest() : LibLoadTest(LIBDHCP_PGSQL_LB_SO) {
+    }
+
+    /// @brief Destructor
+    virtual ~PgSqlLbLibLoadTest() {
+        unloadLibraries();
+    }
+};
+
+// Simple V4 test that checks the library can be loaded and unloaded several times.
+TEST_F(PgSqlLbLibLoadTest, validLoad4) {
+    validDaemonTest("kea-dhcp4");
+}
+
+// Simple V6 test that checks the library can be loaded and unloaded several times.
+TEST_F(PgSqlLbLibLoadTest, validLoad6) {
+    validDaemonTest("kea-dhcp6", AF_INET6);
+}
+
+// Simple test that checks the library cannot by loaded by invalid daemons.
+TEST_F(PgSqlLbLibLoadTest, invalidDaemonLoad) {
+    invalidDaemonTest("kea-ctrl-agent");
+    invalidDaemonTest("kea-dhcp-ddns");
+    invalidDaemonTest("bogus");
+}
+
+} // end of anonymous namespace
diff --git a/src/hooks/dhcp/pgsql_lb/libloadtests/run_unittests.cc b/src/hooks/dhcp/pgsql_lb/libloadtests/run_unittests.cc
new file mode 100644 (file)
index 0000000..755b9e4
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <log/logger_support.h>
+#include <gtest/gtest.h>
+
+int
+main(int argc, char* argv[]) {
+    ::testing::InitGoogleTest(&argc, argv);
+    isc::log::initLogger();
+    int result = RUN_ALL_TESTS();
+
+    return (result);
+}
diff --git a/src/hooks/dhcp/pgsql_lb/pgsql_lb_callouts.cc b/src/hooks/dhcp/pgsql_lb/pgsql_lb_callouts.cc
new file mode 100644 (file)
index 0000000..f1c3d2c
--- /dev/null
@@ -0,0 +1,82 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+// Functions accessed by the hooks framework use C linkage to avoid the name
+// mangling that accompanies use of the C++ compiler as well as to avoid
+// issues related to namespaces.
+
+#include <config.h>
+
+#include <asiolink/io_service_mgr.h>
+#include <dhcpsrv/cfgmgr.h>
+#include <hooks/hooks.h>
+#include <process/daemon.h>
+#include <pgsql_lb_log.h>
+#include <pgsql_lease_mgr.h>
+#include <dhcpsrv/lease_mgr_factory.h>
+
+#include <sstream>
+#include <string>
+
+using namespace isc::asiolink;
+using namespace isc::dhcp;
+using namespace isc::hooks;
+using namespace isc::log;
+using namespace isc::process;
+using namespace std;
+
+extern "C" {
+
+/// @brief This function is called when the library is loaded.
+///
+/// @param handle library handle
+/// @return 0 when initialization is successful, 1 otherwise
+
+int load(LibraryHandle& /* handle */) {
+    // Make the hook library not loadable by d2 or ca.
+    uint16_t family = CfgMgr::instance().getFamily();
+    const std::string& proc_name = Daemon::getProcName();
+    if (family == AF_INET) {
+        if (proc_name != "kea-dhcp4") {
+            isc_throw(isc::Unexpected, "Bad process name: " << proc_name
+                      << ", expected kea-dhcp4");
+        }
+    } else {
+        if (proc_name != "kea-dhcp6") {
+            isc_throw(isc::Unexpected, "Bad process name: " << proc_name
+                      << ", expected kea-dhcp6");
+        }
+    }
+
+    // Register PgSQL LB factories with Lease Managers
+    LeaseMgrFactory::registerFactory("postgresql", PgSqlLeaseMgr::factory, true);
+
+    LOG_INFO(pgsql_lb_logger, PGSQL_LB_INIT_OK);
+    return (0);
+}
+
+/// @brief This function is called when the library is unloaded.
+///
+/// @return 0 if deregistration was successful, 1 otherwise
+int unload() {
+    // Unregister the factories and remove PgSQL backends
+    LeaseMgrFactory::deregisterFactory("postgresql", true);
+
+    LOG_INFO(pgsql_lb_logger, PGSQL_LB_DEINIT_OK);
+    return (0);
+}
+
+/// @brief This function is called to retrieve the multi-threading compatibility.
+///
+/// @note: the compatibility is based on the assumption this hook library
+/// is always called from the main thread.
+///
+/// @return 1 which means compatible with multi-threading.
+int multi_threading_compatible() {
+    return (1);
+}
+
+} // end extern "C"
diff --git a/src/hooks/dhcp/pgsql_lb/pgsql_lb_log.cc b/src/hooks/dhcp/pgsql_lb/pgsql_lb_log.cc
new file mode 100644 (file)
index 0000000..00d3319
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright (C) 2019-2022 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <pgsql_lb_log.h>
+
+namespace isc {
+namespace dhcp {
+
+isc::log::Logger pgsql_lb_logger("pgsql-lb-hooks");
+
+}  // namespace dhcp
+}  // namespace isc
diff --git a/src/hooks/dhcp/pgsql_lb/pgsql_lb_log.h b/src/hooks/dhcp/pgsql_lb/pgsql_lb_log.h
new file mode 100644 (file)
index 0000000..7cff0c4
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright (C) 2019-2022 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef PGSQL_LB_LOG_H
+#define PGSQL_LB_LOG_H
+
+#include <log/logger_support.h>
+#include <log/macros.h>
+#include <pgsql_lb_messages.h>
+
+namespace isc {
+namespace dhcp {
+
+extern isc::log::Logger pgsql_lb_logger;
+
+}  // namespace dhcp
+}  // namespace isc
+
+#endif
diff --git a/src/hooks/dhcp/pgsql_lb/pgsql_lb_messages.cc b/src/hooks/dhcp/pgsql_lb/pgsql_lb_messages.cc
new file mode 100644 (file)
index 0000000..de5b41f
--- /dev/null
@@ -0,0 +1,23 @@
+// File created from ../../../../src/hooks/dhcp/pgsql_lb/pgsql_lb_messages.mes
+
+#include <cstddef>
+#include <log/message_types.h>
+#include <log/message_initializer.h>
+
+extern const isc::log::MessageID PGSQL_LB_DB = "PGSQL_LB_DB";
+extern const isc::log::MessageID PGSQL_LB_DEINIT_OK = "PGSQL_LB_DEINIT_OK";
+extern const isc::log::MessageID PGSQL_LB_INIT_OK = "PGSQL_LB_INIT_OK";
+
+namespace {
+
+const char* values[] = {
+    "PGSQL_LB_DB", "opening PostgreSQL lease database: %1",
+    "PGSQL_LB_DEINIT_OK", "unloading PostgreSQL LB hooks library successful",
+    "PGSQL_LB_INIT_OK", "loading PostgreSQL LB hooks library successful",
+    NULL
+};
+
+const isc::log::MessageInitializer initializer(values);
+
+} // Anonymous namespace
+
diff --git a/src/hooks/dhcp/pgsql_lb/pgsql_lb_messages.h b/src/hooks/dhcp/pgsql_lb/pgsql_lb_messages.h
new file mode 100644 (file)
index 0000000..570da65
--- /dev/null
@@ -0,0 +1,12 @@
+// File created from ../../../../src/hooks/dhcp/pgsql_lb/pgsql_lb_messages.mes
+
+#ifndef PGSQL_LB_MESSAGES_H
+#define PGSQL_LB_MESSAGES_H
+
+#include <log/message_types.h>
+
+extern const isc::log::MessageID PGSQL_LB_DB;
+extern const isc::log::MessageID PGSQL_LB_DEINIT_OK;
+extern const isc::log::MessageID PGSQL_LB_INIT_OK;
+
+#endif // PGSQL_LB_MESSAGES_H
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..519681263943b96e412c351448dff581d5c33693 100644 (file)
@@ -0,0 +1,13 @@
+% PGSQL_LB_DB opening PostgreSQL lease database: %1
+This informational message is logged when a DHCP server (either V4 or
+V6) is about to open a PostgreSQL lease database. The parameters of the
+connection including database name and username needed to access it
+(but not the password if any) are logged.
+
+% PGSQL_LB_DEINIT_OK unloading PostgreSQL LB hooks library successful
+This informational message indicates that the PostgreSLQ Lease Backend hooks
+library has been unloaded successfully.
+
+% PGSQL_LB_INIT_OK loading PostgreSQL LB hooks library successful
+This informational message indicates that the PostgreSQL Lease Backend hooks
+library has been loaded successfully. Enjoy!
index b6fd5353f95d943268bee2a189b88c1bf6f92664..12588f23a3c46a98747732a7e5e1e9a06e207a89 100644 (file)
@@ -8,10 +8,12 @@
 #define PGSQL_LEASE_MGR_H
 
 #include <asiolink/io_service.h>
+#include <database/database_connection.h>
 #include <dhcp/hwaddr.h>
 #include <dhcpsrv/dhcpsrv_exceptions.h>
-#include <dhcpsrv/lease_mgr.h>
+#include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcpsrv/tracking_lease_mgr.h>
+#include <pgsql_lb_log.h>
 #include <pgsql/pgsql_connection.h>
 #include <pgsql/pgsql_exchange.h>
 
@@ -1255,27 +1257,32 @@ private:
 
     /// @brief Timer name used to register database reconnect timer.
     std::string timer_name_;
+
+public:
+    /// @brief Factory class method.
+    ///
+    /// @param parameters A data structure relating keywords and values
+    ///        concerned with the database.
+    ///
+    /// @return The PostgreSQL Lease Manager.
+    static TrackingLeaseMgrPtr
+    factory(const isc::db::DatabaseConnection::ParameterMap& parameters) {
+        LOG_INFO(pgsql_lb_logger, PGSQL_LB_DB)
+            .arg(isc::db::DatabaseConnection::redactedAccessString(parameters));
+        return (TrackingLeaseMgrPtr(new PgSqlLeaseMgr(parameters)));
+    }
 };
 
 struct PgSqlLeaseMgrInit {
     // Constructor registers
     PgSqlLeaseMgrInit() {
-        LeaseMgrFactory::registerFactory("postgresql", factory, true);
+        LeaseMgrFactory::registerFactory("postgresql", PgSqlLeaseMgr::factory, true);
     }
 
     // Destructor deregisters
     ~PgSqlLeaseMgrInit() {
         LeaseMgrFactory::deregisterFactory("postgresql", true);
     }
-
-    // Factory class method
-    static TrackingLeaseMgrPtr
-    factory(const isc::db::DatabaseConnection::ParameterMap& parameters) {
-        // TODO - fix messages
-        //LOG_INFO(dhcpsrv_logger, DHCPSRV_PGSQL_DB)
-        //    .arg(DatabaseConnection::redactedAccessString(parameters));
-        return (TrackingLeaseMgrPtr(new PgSqlLeaseMgr(parameters)));
-    }
 };
 
 }  // namespace dhcp
diff --git a/src/hooks/dhcp/pgsql_lb/version.cc b/src/hooks/dhcp/pgsql_lb/version.cc
new file mode 100644 (file)
index 0000000..d64404b
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <hooks/hooks.h>
+
+extern "C" {
+
+/// @brief returns Kea hooks version.
+int version() {
+    return (KEA_HOOKS_VERSION);
+}
+
+}
index 471bef7f8f52ec27ffe7ddb9ef94685c43afe8b7..ff6e78fe854145132ccd6df59319f7cdae295aee 100644 (file)
@@ -143,7 +143,6 @@ extern const isc::log::MessageID DHCPSRV_MULTIPLE_RAW_SOCKETS_PER_IFACE = "DHCPS
 extern const isc::log::MessageID DHCPSRV_MYSQL_ADD_ADDR4 = "DHCPSRV_MYSQL_ADD_ADDR4";
 extern const isc::log::MessageID DHCPSRV_MYSQL_ADD_ADDR6 = "DHCPSRV_MYSQL_ADD_ADDR6";
 extern const isc::log::MessageID DHCPSRV_MYSQL_COMMIT = "DHCPSRV_MYSQL_COMMIT";
-extern const isc::log::MessageID DHCPSRV_MYSQL_DB = "DHCPSRV_MYSQL_DB";
 extern const isc::log::MessageID DHCPSRV_MYSQL_DELETED_EXPIRED_RECLAIMED = "DHCPSRV_MYSQL_DELETED_EXPIRED_RECLAIMED";
 extern const isc::log::MessageID DHCPSRV_MYSQL_DELETE_ADDR = "DHCPSRV_MYSQL_DELETE_ADDR";
 extern const isc::log::MessageID DHCPSRV_MYSQL_DELETE_EXPIRED_RECLAIMED4 = "DHCPSRV_MYSQL_DELETE_EXPIRED_RECLAIMED4";
@@ -173,7 +172,6 @@ extern const isc::log::MessageID DHCPSRV_MYSQL_GET_SUBID_CLIENTID = "DHCPSRV_MYS
 extern const isc::log::MessageID DHCPSRV_MYSQL_GET_SUBID_HWADDR = "DHCPSRV_MYSQL_GET_SUBID_HWADDR";
 extern const isc::log::MessageID DHCPSRV_MYSQL_GET_SUBID_PAGE6 = "DHCPSRV_MYSQL_GET_SUBID_PAGE6";
 extern const isc::log::MessageID DHCPSRV_MYSQL_GET_VERSION = "DHCPSRV_MYSQL_GET_VERSION";
-extern const isc::log::MessageID DHCPSRV_MYSQL_HOST_DB = "DHCPSRV_MYSQL_HOST_DB";
 extern const isc::log::MessageID DHCPSRV_MYSQL_HOST_DB_GET_VERSION = "DHCPSRV_MYSQL_HOST_DB_GET_VERSION";
 extern const isc::log::MessageID DHCPSRV_MYSQL_HOST_DB_READONLY = "DHCPSRV_MYSQL_HOST_DB_READONLY";
 extern const isc::log::MessageID DHCPSRV_MYSQL_HOST_DB_RECONNECT_ATTEMPT_FAILED = "DHCPSRV_MYSQL_HOST_DB_RECONNECT_ATTEMPT_FAILED";
@@ -200,7 +198,6 @@ extern const isc::log::MessageID DHCPSRV_OPEN_SOCKET_FAIL = "DHCPSRV_OPEN_SOCKET
 extern const isc::log::MessageID DHCPSRV_PGSQL_ADD_ADDR4 = "DHCPSRV_PGSQL_ADD_ADDR4";
 extern const isc::log::MessageID DHCPSRV_PGSQL_ADD_ADDR6 = "DHCPSRV_PGSQL_ADD_ADDR6";
 extern const isc::log::MessageID DHCPSRV_PGSQL_COMMIT = "DHCPSRV_PGSQL_COMMIT";
-extern const isc::log::MessageID DHCPSRV_PGSQL_DB = "DHCPSRV_PGSQL_DB";
 extern const isc::log::MessageID DHCPSRV_PGSQL_DELETE_ADDR = "DHCPSRV_PGSQL_DELETE_ADDR";
 extern const isc::log::MessageID DHCPSRV_PGSQL_DELETE_EXPIRED_RECLAIMED4 = "DHCPSRV_PGSQL_DELETE_EXPIRED_RECLAIMED4";
 extern const isc::log::MessageID DHCPSRV_PGSQL_DELETE_EXPIRED_RECLAIMED6 = "DHCPSRV_PGSQL_DELETE_EXPIRED_RECLAIMED6";
@@ -229,7 +226,6 @@ extern const isc::log::MessageID DHCPSRV_PGSQL_GET_SUBID_CLIENTID = "DHCPSRV_PGS
 extern const isc::log::MessageID DHCPSRV_PGSQL_GET_SUBID_HWADDR = "DHCPSRV_PGSQL_GET_SUBID_HWADDR";
 extern const isc::log::MessageID DHCPSRV_PGSQL_GET_SUBID_PAGE6 = "DHCPSRV_PGSQL_GET_SUBID_PAGE6";
 extern const isc::log::MessageID DHCPSRV_PGSQL_GET_VERSION = "DHCPSRV_PGSQL_GET_VERSION";
-extern const isc::log::MessageID DHCPSRV_PGSQL_HOST_DB = "DHCPSRV_PGSQL_HOST_DB";
 extern const isc::log::MessageID DHCPSRV_PGSQL_HOST_DB_GET_VERSION = "DHCPSRV_PGSQL_HOST_DB_GET_VERSION";
 extern const isc::log::MessageID DHCPSRV_PGSQL_HOST_DB_READONLY = "DHCPSRV_PGSQL_HOST_DB_READONLY";
 extern const isc::log::MessageID DHCPSRV_PGSQL_HOST_DB_RECONNECT_ATTEMPT_FAILED = "DHCPSRV_PGSQL_HOST_DB_RECONNECT_ATTEMPT_FAILED";
@@ -416,7 +412,6 @@ const char* values[] = {
     "DHCPSRV_MYSQL_ADD_ADDR4", "adding IPv4 lease with address %1",
     "DHCPSRV_MYSQL_ADD_ADDR6", "adding IPv6 lease with address %1, lease type %2",
     "DHCPSRV_MYSQL_COMMIT", "committing to MySQL database",
-    "DHCPSRV_MYSQL_DB", "opening MySQL lease database: %1",
     "DHCPSRV_MYSQL_DELETED_EXPIRED_RECLAIMED", "deleted %1 reclaimed leases from the database",
     "DHCPSRV_MYSQL_DELETE_ADDR", "deleting lease for address %1",
     "DHCPSRV_MYSQL_DELETE_EXPIRED_RECLAIMED4", "deleting reclaimed IPv4 leases that expired more than %1 seconds ago",
@@ -446,7 +441,6 @@ const char* values[] = {
     "DHCPSRV_MYSQL_GET_SUBID_HWADDR", "obtaining IPv4 lease for subnet ID %1 and hardware address %2",
     "DHCPSRV_MYSQL_GET_SUBID_PAGE6", "obtaining at most %1 IPv6 leases starting from address %2 for subnet ID %3",
     "DHCPSRV_MYSQL_GET_VERSION", "obtaining schema version information",
-    "DHCPSRV_MYSQL_HOST_DB", "opening MySQL hosts database: %1",
     "DHCPSRV_MYSQL_HOST_DB_GET_VERSION", "obtaining schema version information for the MySQL hosts database",
     "DHCPSRV_MYSQL_HOST_DB_READONLY", "MySQL host database opened for read access only",
     "DHCPSRV_MYSQL_HOST_DB_RECONNECT_ATTEMPT_FAILED", "database reconnect failed: %1",
@@ -473,7 +467,6 @@ const char* values[] = {
     "DHCPSRV_PGSQL_ADD_ADDR4", "adding IPv4 lease with address %1",
     "DHCPSRV_PGSQL_ADD_ADDR6", "adding IPv6 lease with address %1, lease type %2",
     "DHCPSRV_PGSQL_COMMIT", "committing to PostgreSQL database",
-    "DHCPSRV_PGSQL_DB", "opening PostgreSQL lease database: %1",
     "DHCPSRV_PGSQL_DELETE_ADDR", "deleting lease for address %1",
     "DHCPSRV_PGSQL_DELETE_EXPIRED_RECLAIMED4", "deleting reclaimed IPv4 leases that expired more than %1 seconds ago",
     "DHCPSRV_PGSQL_DELETE_EXPIRED_RECLAIMED6", "deleting reclaimed IPv6 leases that expired more than %1 seconds ago",
@@ -502,7 +495,6 @@ const char* values[] = {
     "DHCPSRV_PGSQL_GET_SUBID_HWADDR", "obtaining IPv4 lease for subnet ID %1 and hardware address %2",
     "DHCPSRV_PGSQL_GET_SUBID_PAGE6", "obtaining at most %1 IPv6 leases starting from address %2 for subnet ID %3",
     "DHCPSRV_PGSQL_GET_VERSION", "obtaining schema version information",
-    "DHCPSRV_PGSQL_HOST_DB", "opening PostgreSQL hosts database: %1",
     "DHCPSRV_PGSQL_HOST_DB_GET_VERSION", "obtaining schema version information for the PostgreSQL hosts database",
     "DHCPSRV_PGSQL_HOST_DB_READONLY", "PostgreSQL host database opened for read access only",
     "DHCPSRV_PGSQL_HOST_DB_RECONNECT_ATTEMPT_FAILED", "database reconnect failed: %1",
index 59b8652a39cbab76290839815728f578515e92ca..9bedc3d6a099745734bc863aa266f17bafd36538 100644 (file)
@@ -144,7 +144,6 @@ extern const isc::log::MessageID DHCPSRV_MULTIPLE_RAW_SOCKETS_PER_IFACE;
 extern const isc::log::MessageID DHCPSRV_MYSQL_ADD_ADDR4;
 extern const isc::log::MessageID DHCPSRV_MYSQL_ADD_ADDR6;
 extern const isc::log::MessageID DHCPSRV_MYSQL_COMMIT;
-extern const isc::log::MessageID DHCPSRV_MYSQL_DB;
 extern const isc::log::MessageID DHCPSRV_MYSQL_DELETED_EXPIRED_RECLAIMED;
 extern const isc::log::MessageID DHCPSRV_MYSQL_DELETE_ADDR;
 extern const isc::log::MessageID DHCPSRV_MYSQL_DELETE_EXPIRED_RECLAIMED4;
@@ -174,7 +173,6 @@ extern const isc::log::MessageID DHCPSRV_MYSQL_GET_SUBID_CLIENTID;
 extern const isc::log::MessageID DHCPSRV_MYSQL_GET_SUBID_HWADDR;
 extern const isc::log::MessageID DHCPSRV_MYSQL_GET_SUBID_PAGE6;
 extern const isc::log::MessageID DHCPSRV_MYSQL_GET_VERSION;
-extern const isc::log::MessageID DHCPSRV_MYSQL_HOST_DB;
 extern const isc::log::MessageID DHCPSRV_MYSQL_HOST_DB_GET_VERSION;
 extern const isc::log::MessageID DHCPSRV_MYSQL_HOST_DB_READONLY;
 extern const isc::log::MessageID DHCPSRV_MYSQL_HOST_DB_RECONNECT_ATTEMPT_FAILED;
@@ -201,7 +199,6 @@ extern const isc::log::MessageID DHCPSRV_OPEN_SOCKET_FAIL;
 extern const isc::log::MessageID DHCPSRV_PGSQL_ADD_ADDR4;
 extern const isc::log::MessageID DHCPSRV_PGSQL_ADD_ADDR6;
 extern const isc::log::MessageID DHCPSRV_PGSQL_COMMIT;
-extern const isc::log::MessageID DHCPSRV_PGSQL_DB;
 extern const isc::log::MessageID DHCPSRV_PGSQL_DELETE_ADDR;
 extern const isc::log::MessageID DHCPSRV_PGSQL_DELETE_EXPIRED_RECLAIMED4;
 extern const isc::log::MessageID DHCPSRV_PGSQL_DELETE_EXPIRED_RECLAIMED6;
@@ -230,7 +227,6 @@ extern const isc::log::MessageID DHCPSRV_PGSQL_GET_SUBID_CLIENTID;
 extern const isc::log::MessageID DHCPSRV_PGSQL_GET_SUBID_HWADDR;
 extern const isc::log::MessageID DHCPSRV_PGSQL_GET_SUBID_PAGE6;
 extern const isc::log::MessageID DHCPSRV_PGSQL_GET_VERSION;
-extern const isc::log::MessageID DHCPSRV_PGSQL_HOST_DB;
 extern const isc::log::MessageID DHCPSRV_PGSQL_HOST_DB_GET_VERSION;
 extern const isc::log::MessageID DHCPSRV_PGSQL_HOST_DB_READONLY;
 extern const isc::log::MessageID DHCPSRV_PGSQL_HOST_DB_RECONNECT_ATTEMPT_FAILED;
index bbebc4ce7a9aadc775076fc0f40fa2ccb8aa1ebd..c3704f4b288b93ace315d9a4b0bdc028fc36dcd0 100644 (file)
@@ -807,12 +807,6 @@ The code has issued a commit call. All outstanding transactions will be
 committed to the database. Note that depending on the MySQL settings,
 the commit may not include a write to disk.
 
-% DHCPSRV_MYSQL_DB opening MySQL lease database: %1
-This informational message is logged when a DHCP server (either V4 or
-V6) is about to open a MySQL lease database. The parameters of the
-connection including database name and username needed to access it
-(but not the password if any) are logged.
-
 % DHCPSRV_MYSQL_DELETED_EXPIRED_RECLAIMED deleted %1 reclaimed leases from the database
 Logged at debug log level 50.
 A debug message issued when the server has removed a number of reclaimed
@@ -976,13 +970,6 @@ Logged at debug log level 50.
 A debug message issued when the server is about to obtain schema version
 information from the MySQL database.
 
-% DHCPSRV_MYSQL_HOST_DB opening MySQL hosts database: %1
-Logged at debug log level 50.
-This informational message is logged when a DHCP server (either V4 or
-V6) is about to open a MySQL hosts database. The parameters of the
-connection including database name and username needed to access it
-(but not the password if any) are logged.
-
 % DHCPSRV_MYSQL_HOST_DB_GET_VERSION obtaining schema version information for the MySQL hosts database
 Logged at debug log level 50.
 A debug message issued when the server is about to obtain schema version
@@ -1111,12 +1098,6 @@ The code has issued a commit call. All outstanding transactions will be
 committed to the database. Note that depending on the PostgreSQL settings,
 the commit may not include a write to disk.
 
-% DHCPSRV_PGSQL_DB opening PostgreSQL lease database: %1
-This informational message is logged when a DHCP server (either V4 or
-V6) is about to open a PostgreSQL lease database. The parameters of the
-connection including database name and username needed to access it
-(but not the password if any) are logged.
-
 % DHCPSRV_PGSQL_DELETE_ADDR deleting lease for address %1
 Logged at debug log level 50.
 A debug message issued when the server is attempting to delete a lease for
@@ -1274,13 +1255,6 @@ Logged at debug log level 50.
 A debug message issued when the server is about to obtain schema version
 information from the PostgreSQL database.
 
-% DHCPSRV_PGSQL_HOST_DB opening PostgreSQL hosts database: %1
-Logged at debug log level 50.
-This informational message is logged when a DHCP server (either V4 or
-V6) is about to open a PostgreSQL hosts database. The parameters of the
-connection including database name and username needed to access it
-(but not the password if any) are logged.
-
 % DHCPSRV_PGSQL_HOST_DB_GET_VERSION obtaining schema version information for the PostgreSQL hosts database
 Logged at debug log level 50.
 A debug message issued when the server is about to obtain schema version