mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 21:45:37 +00:00
[#488,!259] Parse siaddr, sname and boot-file-name in shared network parser.
This commit is contained in:
@@ -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()) {
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user