]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#488,!259] Parse siaddr, sname and boot-file-name in shared network parser.
authorMarcin Siodelski <marcin@isc.org>
Wed, 6 Mar 2019 15:47:00 +0000 (16:47 +0100)
committerMarcin Siodelski <marcin@isc.org>
Thu, 7 Mar 2019 13:00:36 +0000 (08:00 -0500)
src/lib/dhcpsrv/parsers/shared_network_parser.cc
src/lib/dhcpsrv/tests/shared_network_parser_unittest.cc

index 283ad68ecf41671a7bb35976b55a583035063828..712c2f570d91d2db9bd979c629664118f23e056a 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <config.h>
 
+#include <asiolink/io_address.h>
 #include <cc/data.h>
 #include <dhcpsrv/cfg_option.h>
 #include <dhcpsrv/parsers/dhcp_parsers.h>
@@ -15,6 +16,7 @@
 #include <boost/pointer_cast.hpp>
 #include <string>
 
+using namespace isc::asiolink;
 using namespace isc::data;
 
 namespace isc {
@@ -72,6 +74,57 @@ SharedNetwork4Parser::parse(const data::ConstElementPtr& shared_network_data) {
                                                         "authoritative"));
         }
 
+        // Set next-server
+        if (shared_network_data->contains("next-server")) {
+            std::string next_server;
+            try {
+                next_server = getString(shared_network_data, "next-server");
+                if (!next_server.empty()) {
+                    shared_network->setSiaddr(IOAddress(next_server));
+                }
+            } catch (...) {
+                ConstElementPtr next = shared_network_data->get("next-server");
+                std::string pos;
+                if (next) {
+                    pos = next->getPosition().str();
+                } else {
+                    pos = shared_network_data->getPosition().str();
+                }
+                isc_throw(DhcpConfigError, "invalid parameter next-server : "
+                          << next_server << "(" << pos << ")");
+            }
+        }
+
+        // Set server-hostname.
+        if (shared_network_data->contains("server-hostname")) {
+            std::string sname = getString(shared_network_data, "server-hostname");
+            if (!sname.empty()) {
+                if (sname.length() >= Pkt4::MAX_SNAME_LEN) {
+                    ConstElementPtr error = shared_network_data->get("server-hostname");
+                    isc_throw(DhcpConfigError, "server-hostname must be at most "
+                              << Pkt4::MAX_SNAME_LEN - 1 << " bytes long, it is "
+                              << sname.length() << " ("
+                              << error->getPosition() << ")");
+                }
+                shared_network->setSname(sname);
+            }
+        }
+
+        // Set boot-file-name.
+        if (shared_network_data->contains("boot-file-name")) {
+            std::string filename = getString(shared_network_data, "boot-file-name");
+            if (!filename.empty()) {
+                if (filename.length() > Pkt4::MAX_FILE_LEN) {
+                    ConstElementPtr error = shared_network_data->get("boot-file-name");
+                    isc_throw(DhcpConfigError, "boot-file-name must be at most "
+                              << Pkt4::MAX_FILE_LEN - 1 << " bytes long, it is "
+                              << filename.length() << " ("
+                              << error->getPosition() << ")");
+                }
+                shared_network->setFilename(filename);
+            }
+        }
+
         if (shared_network_data->contains("client-class")) {
             std::string client_class = getString(shared_network_data, "client-class");
             if (!client_class.empty()) {
index 2a7e0dbddd444dc78ac0041a6bb78b4adf37c3e0..d52c3d88967857dcf49b6b039ce4765b58a65f87 100644 (file)
@@ -229,9 +229,6 @@ TEST_F(SharedNetwork4ParserTest, parse) {
     ASSERT_NO_THROW(network = parser.parse(config_element));
     ASSERT_TRUE(network);
 
-    /// @todo Validate next-server, server-hostname, boot-file-name once
-    /// they become a part of the shared network.
-
     // Check basic parameters.
     EXPECT_TRUE(network->getAuthoritative());
     EXPECT_EQ("srv1", network->getClientClass().get());
@@ -243,6 +240,9 @@ TEST_F(SharedNetwork4ParserTest, parse) {
     EXPECT_TRUE(network->getCalculateTeeTimes());
     EXPECT_EQ(0.345, network->getT1Percent());
     EXPECT_EQ(0.721, network->getT2Percent());
+    EXPECT_EQ("/dev/null", network->getFilename().get());
+    EXPECT_EQ("10.0.0.1", network->getSiaddr().get().toText());
+    EXPECT_EQ("example.org", network->getSname().get());
 
     // Relay information.
     auto relay_info = network->getRelayInfo();