diff --git a/src/lib/dhcpsrv/client_class_def.cc b/src/lib/dhcpsrv/client_class_def.cc index 456264c41b..018636483c 100644 --- a/src/lib/dhcpsrv/client_class_def.cc +++ b/src/lib/dhcpsrv/client_class_def.cc @@ -305,6 +305,11 @@ ClientClassDictionary::getClasses() const { return (list_); } +bool +ClientClassDictionary::empty() const { + return (list_->empty()); +} + bool ClientClassDictionary::dependOnClass(const std::string& name, std::string& dependent_class) const { diff --git a/src/lib/dhcpsrv/client_class_def.h b/src/lib/dhcpsrv/client_class_def.h index 4e9ee57d64..293e84ee8e 100644 --- a/src/lib/dhcpsrv/client_class_def.h +++ b/src/lib/dhcpsrv/client_class_def.h @@ -352,6 +352,11 @@ public: /// @return ClientClassDefListPtr to the list of classes const ClientClassDefListPtr& getClasses() const; + /// @brief Checks if the class dictionary is empty. + /// + /// @return true if there are no classes, false otherwise. + bool empty() const; + /// @brief Checks direct dependency. /// /// @param name The client class name. diff --git a/src/lib/dhcpsrv/config_backend_dhcp4.h b/src/lib/dhcpsrv/config_backend_dhcp4.h index 9b74e94cc5..c56976b621 100644 --- a/src/lib/dhcpsrv/config_backend_dhcp4.h +++ b/src/lib/dhcpsrv/config_backend_dhcp4.h @@ -667,7 +667,6 @@ public: virtual uint64_t deleteAllClientClasses4(const db::ServerSelector& server_selector) = 0; - /// @brief Deletes a server from the backend. /// /// @param server_tag Tag of the server to be deleted. diff --git a/src/lib/dhcpsrv/config_backend_pool_dhcp4.cc b/src/lib/dhcpsrv/config_backend_pool_dhcp4.cc index cc2fb2b315..1eaa2730ac 100644 --- a/src/lib/dhcpsrv/config_backend_pool_dhcp4.cc +++ b/src/lib/dhcpsrv/config_backend_pool_dhcp4.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2021 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 @@ -200,6 +200,39 @@ getModifiedGlobalParameters4(const db::BackendSelector& backend_selector, return (parameters); } +ClientClassDefPtr +ConfigBackendPoolDHCPv4::getClientClass4(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const std::string& name) const { + ClientClassDefPtr client_class; + getPropertyPtrConst + (&ConfigBackendDHCPv4::getClientClass4, backend_selector, server_selector, + client_class, name); + return (client_class); +} + +ClientClassDictionary +ConfigBackendPoolDHCPv4::getAllClientClasses4(const BackendSelector& backend_selector, + const ServerSelector& server_selector) const { + ClientClassDictionary client_classes; + getAllPropertiesConst + (&ConfigBackendDHCPv4::getAllClientClasses4, backend_selector, server_selector, + client_classes); + return (client_classes); + +} + +ClientClassDictionary +ConfigBackendPoolDHCPv4::getModifiedClientClasses4(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const { + ClientClassDictionary client_classes; + getMultiplePropertiesConst + (&ConfigBackendDHCPv4::getModifiedClientClasses4, backend_selector, server_selector, + client_classes, modification_time); + return (client_classes); +} + AuditEntryCollection ConfigBackendPoolDHCPv4:: getRecentAuditEntries(const db::BackendSelector& backend_selector, @@ -309,6 +342,16 @@ ConfigBackendPoolDHCPv4::createUpdateGlobalParameter4(const BackendSelector& bac server_selector, value); } +void +ConfigBackendPoolDHCPv4::createUpdateClientClass4(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const ClientClassDefPtr& client_class, + const std::string& follow_class_name) { + createUpdateDeleteProperty + (&ConfigBackendDHCPv4::createUpdateClientClass4, backend_selector, + server_selector, client_class, follow_class_name); +} + void ConfigBackendPoolDHCPv4::createUpdateServer4(const BackendSelector& backend_selector, const ServerPtr& server) { @@ -447,6 +490,22 @@ ConfigBackendPoolDHCPv4::deleteAllGlobalParameters4(const BackendSelector& backe server_selector)); } +uint64_t +ConfigBackendPoolDHCPv4::deleteClientClass4(const BackendSelector& backend_selector, + const ServerSelector& server_selector, + const std::string& name) { + return (createUpdateDeleteProperty + (&ConfigBackendDHCPv4::deleteClientClass4, backend_selector, + server_selector, name)); +} + +uint64_t +ConfigBackendPoolDHCPv4::deleteAllClientClasses4(const BackendSelector& backend_selector, + const ServerSelector& server_selector) { + return (createUpdateDeleteProperty + (&ConfigBackendDHCPv4::deleteAllClientClasses4, backend_selector, server_selector)); +} + uint64_t ConfigBackendPoolDHCPv4::deleteServer4(const BackendSelector& backend_selector, const ServerTag& server_tag) { diff --git a/src/lib/dhcpsrv/config_backend_pool_dhcp4.h b/src/lib/dhcpsrv/config_backend_pool_dhcp4.h index c86d740a34..b9132c6a2a 100644 --- a/src/lib/dhcpsrv/config_backend_pool_dhcp4.h +++ b/src/lib/dhcpsrv/config_backend_pool_dhcp4.h @@ -1,4 +1,4 @@ -// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2021 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 @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -221,6 +222,37 @@ public: const db::ServerSelector& server_selector, const boost::posix_time::ptime& modification_time) const; + /// @brief Retrieves a client class by name. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param name Client class name. + /// @return Pointer to the retrieved client class. + virtual ClientClassDefPtr + getClientClass4(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const std::string& name) const; + + /// @brief Retrieves all client classes. + /// + /// @param backend_selector Backend selector. + /// @param selector Server selector. + /// @return Collection of client classes. + virtual ClientClassDictionary + getAllClientClasses4(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector) const; + + /// @brief Retrieves client classes modified after specified time. + /// + /// @param backend_selector Backend selector. + /// @param selector Server selector. + /// @param modification_time Modification time. + /// @return Collection of client classes. + virtual ClientClassDictionary + getModifiedClientClasses4(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const boost::posix_time::ptime& modification_time) const; + /// @brief Retrieves the most recent audit entries. /// /// @param backend_selector Backend selector. @@ -348,6 +380,21 @@ public: const db::ServerSelector& server_selector, const data::StampedValuePtr& value); + /// @brief Creates or updates DHCPv4 client class. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param client_class Client class to be added or updated. + /// @param follow_client_class name of the class after which the + /// new or updated class should be positioned. An empty value + /// causes the class to be appended at the end of the class + /// hierarchy. + virtual void + createUpdateClientClass4(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const ClientClassDefPtr& client_class, + const std::string& follow_class_name); + /// @brief Creates or updates a server. /// /// @param backend_selector Backend selector. @@ -523,6 +570,26 @@ public: deleteAllGlobalParameters4(const db::BackendSelector& backend_selector, const db::ServerSelector& server_selector); + /// @brief Deletes DHCPv4 client class. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @param name Name of the class to be deleted. + /// @return Number of deleted client classes. + virtual uint64_t + deleteClientClass4(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector, + const std::string& name); + + /// @brief Deletes all client classes. + /// + /// @param backend_selector Backend selector. + /// @param server_selector Server selector. + /// @return Number of deleted client classes. + virtual uint64_t + deleteAllClientClasses4(const db::BackendSelector& backend_selector, + const db::ServerSelector& server_selector); + /// @brief Deletes a server from the backend. /// /// @param backend_selector Backend selector. diff --git a/src/lib/dhcpsrv/tests/client_class_def_unittest.cc b/src/lib/dhcpsrv/tests/client_class_def_unittest.cc index 443ce11d98..1eecae7950 100644 --- a/src/lib/dhcpsrv/tests/client_class_def_unittest.cc +++ b/src/lib/dhcpsrv/tests/client_class_def_unittest.cc @@ -260,6 +260,7 @@ TEST(ClientClassDictionary, basics) { const ClientClassDefListPtr classes = dictionary->getClasses(); ASSERT_TRUE(classes); EXPECT_EQ(0, classes->size()); + EXPECT_TRUE(classes->empty()); // Verify that we can add classes with both addClass variants // First addClass(name, expression, cfg_option) @@ -291,6 +292,7 @@ TEST(ClientClassDictionary, basics) { // Map should show 3 entries. EXPECT_EQ(3, classes->size()); + EXPECT_FALSE(classes->empty()); // Verify we can find them all. ASSERT_NO_THROW(cclass = dictionary->findClass("cc1")); @@ -312,6 +314,7 @@ TEST(ClientClassDictionary, basics) { // Verify that we can remove a class ASSERT_NO_THROW(dictionary->removeClass("cc3")); EXPECT_EQ(2, classes->size()); + EXPECT_FALSE(classes->empty()); // Shouldn't be able to find anymore ASSERT_NO_THROW(cclass = dictionary->findClass("cc3")); @@ -321,6 +324,7 @@ TEST(ClientClassDictionary, basics) { // without harm. ASSERT_NO_THROW(dictionary->removeClass("cc3")); EXPECT_EQ(2, classes->size()); + EXPECT_FALSE(classes->empty()); } // Verifies copy constructor and equality tools (methods/operators) diff --git a/src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.cc b/src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.cc index 343f37fd1f..8a726f1fa2 100644 --- a/src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.cc +++ b/src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.cc @@ -513,7 +513,7 @@ ClientClassDefPtr TestConfigBackendDHCPv4::getClientClass4(const db::ServerSelector& server_selector, const std::string& name) const { auto client_class = classes_.findClass(name); - if (!client_class) { + if (!client_class || server_selector.amAny()) { return (client_class); } if (server_selector.amUnassigned()) {