summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/sphinx/arm/hooks.rst27
-rw-r--r--src/lib/dhcpsrv/tests/Makefile.am1
-rw-r--r--src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc43
-rw-r--r--src/lib/hooks/Makefile.am1
-rw-r--r--src/lib/hooks/hooks_parser.cc7
-rw-r--r--src/lib/hooks/hooks_parser.h4
6 files changed, 83 insertions, 0 deletions
diff --git a/doc/sphinx/arm/hooks.rst b/doc/sphinx/arm/hooks.rst
index b661bedfcf..1bd1bc4623 100644
--- a/doc/sphinx/arm/hooks.rst
+++ b/doc/sphinx/arm/hooks.rst
@@ -213,6 +213,33 @@ configuration would be:
because the parameters specified for the library (or the files those
parameters point to) may have changed.
+Since Kea-2.7.5, the server is able to load hooks specified only by name, if
+they reside in the default install location (the path is OS specific).
+
+::
+
+ "hooks-libraries": [
+ {
+ "library": "first_custom_hooks_example.so"
+ },
+ {
+ "library": "second_custom_hooks_example.so"
+ }
+ ]
+
+This snipper (on Ubuntu 24.04) is equivalent to:
+
+::
+
+ "hooks-libraries": [
+ {
+ "library": "/usr/lib/x86_64-linux-gnu/kea/hooks/first_custom_hooks_example.so"
+ },
+ {
+ "library": "/usr/lib/x86_64-linux-gnu/kea/hooks/second_custom_hooks_example.so"
+ }
+ ]
+
Libraries may have additional parameters that are not mandatory, in the
sense that there may be libraries that do not require them. However, for any
given library there is often a requirement to specify a certain
diff --git a/src/lib/dhcpsrv/tests/Makefile.am b/src/lib/dhcpsrv/tests/Makefile.am
index 289a8fdc9f..bc9b150ab0 100644
--- a/src/lib/dhcpsrv/tests/Makefile.am
+++ b/src/lib/dhcpsrv/tests/Makefile.am
@@ -6,6 +6,7 @@ AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/lib/dhcpsrv/tests\
AM_CPPFLAGS += -DDHCP_DATA_DIR=\"$(abs_top_builddir)/src/lib/dhcpsrv/tests\"
AM_CPPFLAGS += -DKEA_LFC_BUILD_DIR=\"$(abs_top_builddir)/src/bin/lfc\"
AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\"
+AM_CPPFLAGS += -DDEFAULT_HOOKS_PATH=\"$(libdir)/kea/hooks\"
AM_CXXFLAGS = $(KEA_CXXFLAGS)
diff --git a/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc b/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
index 9ea17057c3..af1ef3daca 100644
--- a/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
+++ b/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
@@ -34,6 +34,7 @@
#include <exceptions/exceptions.h>
#include <hooks/hooks_parser.h>
#include <hooks/hooks_manager.h>
+#include <util/filesystem.h>
#include <testutils/gtest_utils.h>
#include <testutils/test_to_element.h>
@@ -52,6 +53,7 @@ using namespace isc::dhcp;
using namespace isc::dhcp::test;
using namespace isc::hooks;
using namespace isc::test;
+using namespace isc::util::file;
namespace {
@@ -327,11 +329,13 @@ public:
ParseConfigTest()
:family_(AF_INET6) {
reset_context();
+ HooksLibrariesParser::default_hooks_path_ = string(DEFAULT_HOOKS_PATH);
}
~ParseConfigTest() {
reset_context();
CfgMgr::instance().clear();
+ HooksLibrariesParser::default_hooks_path_ = string(DEFAULT_HOOKS_PATH);
}
/// @brief Parses a configuration.
@@ -2277,6 +2281,45 @@ TEST_F(ParseConfigTest, oneHooksLibrary) {
EXPECT_EQ(CALLOUT_LIBRARY_1, hooks_libraries[0]);
}
+// hooks-libraries element that contains a single library with relative path.
+TEST_F(ParseConfigTest, oneHooksLibraryRelativePath) {
+ // Check that no libraries are currently loaded
+ vector<string> hooks_libraries = HooksManager::getLibraryNames();
+ EXPECT_TRUE(hooks_libraries.empty());
+
+ Path path(CALLOUT_LIBRARY_1);
+
+ HooksLibrariesParser::default_hooks_path_ = path.parentPath();
+
+ // Configuration with hooks-libraries set to a single library.
+ string config = setHooksLibrariesConfig(path.filename().c_str());
+
+ // Verify that the configuration string parses.
+ const int rcode = parseConfiguration(config);
+ ASSERT_TRUE(rcode == 0) << error_text_;
+
+ config = setHooksLibrariesConfig(CALLOUT_LIBRARY_1);
+
+ // Verify that the configuration object unparses.
+ ConstElementPtr expected;
+ ASSERT_NO_THROW(expected =
+ Element::fromJSON(config)->get("hooks-libraries"));
+ ASSERT_TRUE(expected);
+ const HooksConfig& cfg =
+ CfgMgr::instance().getStagingCfg()->getHooksConfig();
+ runToElementTest<HooksConfig>(expected, cfg);
+
+ // Check that the parser recorded a single library.
+ isc::hooks::HookLibsCollection libraries = getLibraries();
+ ASSERT_EQ(1, libraries.size());
+ EXPECT_EQ(CALLOUT_LIBRARY_1, libraries[0].first);
+
+ // Check that the change was propagated to the hooks manager.
+ hooks_libraries = HooksManager::getLibraryNames();
+ ASSERT_EQ(1, hooks_libraries.size());
+ EXPECT_EQ(CALLOUT_LIBRARY_1, hooks_libraries[0]);
+}
+
// hooks-libraries element that contains two libraries
TEST_F(ParseConfigTest, twoHooksLibraries) {
// Check that no libraries are currently loaded
diff --git a/src/lib/hooks/Makefile.am b/src/lib/hooks/Makefile.am
index 44a61fd3d1..94143c251b 100644
--- a/src/lib/hooks/Makefile.am
+++ b/src/lib/hooks/Makefile.am
@@ -1,6 +1,7 @@
SUBDIRS = . tests
AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+AM_CPPFLAGS += -DDEFAULT_HOOKS_PATH=\"$(libdir)/kea/hooks\"
AM_CPPFLAGS += $(BOOST_INCLUDES)
AM_CXXFLAGS = $(KEA_CXXFLAGS)
diff --git a/src/lib/hooks/hooks_parser.cc b/src/lib/hooks/hooks_parser.cc
index 56029896fe..62c47b13e8 100644
--- a/src/lib/hooks/hooks_parser.cc
+++ b/src/lib/hooks/hooks_parser.cc
@@ -23,6 +23,8 @@ namespace hooks {
// @todo use the flat style, split into list and item
+string HooksLibrariesParser::default_hooks_path_ = string(DEFAULT_HOOKS_PATH);
+
void
HooksLibrariesParser::parse(HooksConfig& libraries, ConstElementPtr value) {
// Initialize.
@@ -77,6 +79,11 @@ HooksLibrariesParser::parse(HooksConfig& libraries, ConstElementPtr value) {
entry_item.second->getPosition() << ")");
}
+ // If only the name of the library was provided, add the full path.
+ if (libname.find("/") == string::npos) {
+ libname = HooksLibrariesParser::default_hooks_path_ + "/" + libname;
+ }
+
// Note we have found the library name.
lib_found = true;
continue;
diff --git a/src/lib/hooks/hooks_parser.h b/src/lib/hooks/hooks_parser.h
index 441e56c1f1..0fea1fe26b 100644
--- a/src/lib/hooks/hooks_parser.h
+++ b/src/lib/hooks/hooks_parser.h
@@ -57,6 +57,10 @@ public:
/// @param libraries parsed libraries information will be stored here
/// @param value pointer to the content to be parsed
void parse(HooksConfig& libraries, isc::data::ConstElementPtr value);
+
+ /// @brief The default installation path for hooks, used to generate full
+ /// path if only the hook name is provided.
+ static std::string default_hooks_path_;
};
} // namespace isc::hooks