}
// Now create the default value.
- isc::asiolink::IOAddress ip(family_ == Option::V4 ? "0.0.0.0" : "::");
+ isc::asiolink::IOAddress ip(family_ == Option::V4 ? IOAddress::IPV4_ZERO_ADDRESS()
+ : IOAddress::IPV6_ZERO_ADDRESS());
// Now iterate over all parameters. Currently there's only one supported
// parameter, so it should be an easy thing to check.
+ bool ip_address_specified = false;
BOOST_FOREACH(ConfigPair param, relay_info->mapValue()) {
if (param.first == "ip-address") {
+ ip_address_specified = true;
+
try {
ip = asiolink::IOAddress(param.second->stringValue());
} catch (...) {
}
}
+ if (!ip_address_specified) {
+ isc_throw(DhcpConfigError, "'relay' specified, but mandatory 'ip-address' "
+ "paramter in it is missing");
+ }
+
// Ok, we're done with parsing. Let's store the result in the structure
// we were given as configuration storage.
*cfg = isc::dhcp::Subnet::RelayInfo(ip);
" }";
ElementPtr json = Element::fromJSON(config_str);
+ // We need to set the default ip-address to something.
+ Subnet::RelayInfoPtr result(new Subnet::RelayInfo(asiolink::IOAddress("0.0.0.0")));
+
+ RelayInfoParser parser(Option::V4);
+
+ // Subnet4 parser will pass 0.0.0.0 to the RelayInfoParser
+ EXPECT_NO_THROW(parser.parse(result, json));
+ EXPECT_EQ("192.0.2.1", result->addr_.toText());
+}
+
+/// @brief Checks that a bogus relay info structure for IPv4 is rejected.
+TEST_F(ParseConfigTest, bogusRelayInfo4) {
+
// Invalid config (wrong family type of the ip-address field)
std::string config_str_bogus1 =
" {"
" }";
ElementPtr json_bogus2 = Element::fromJSON(config_str_bogus2);
+ // Invalid config (ip-address is mandatory)
+ std::string config_str_bogus3 =
+ " {"
+ " }";
+ ElementPtr json_bogus3 = Element::fromJSON(config_str_bogus3);
+
// We need to set the default ip-address to something.
- Subnet::RelayInfoPtr result(new Subnet::RelayInfo(asiolink::IOAddress("0.0.0.0")));
+ Subnet::RelayInfoPtr result(new Subnet::RelayInfo(IOAddress::IPV4_ZERO_ADDRESS()));
RelayInfoParser parser(Option::V4);
- // Subnet4 parser will pass 0.0.0.0 to the RelayInfoParser
- EXPECT_NO_THROW(parser.parse(result, json));
- EXPECT_EQ("192.0.2.1", result->addr_.toText());
-
- // Let's check negative scenario (wrong family type)
+ // wrong family type
EXPECT_THROW(parser.parse(result, json_bogus1), DhcpConfigError);
- // Let's check negative scenario (too large byte values in pseudo-IPv4 addr)
+ // Too large byte values in pseudo-IPv4 addr
+ EXPECT_THROW(parser.parse(result, json_bogus2), DhcpConfigError);
+
+ // Mandatory ip-address is missing. What a pity.
EXPECT_THROW(parser.parse(result, json_bogus2), DhcpConfigError);
}
" }";
ElementPtr json = Element::fromJSON(config_str);
+ // We need to set the default ip-address to something.
+ Subnet::RelayInfoPtr result(new Subnet::RelayInfo(asiolink::IOAddress("::")));
+
+ RelayInfoParser parser(Option::V6);
+ // Subnet4 parser will pass :: to the RelayInfoParser
+ EXPECT_NO_THROW(parser.parse(result, json));
+ EXPECT_EQ("2001:db8::1", result->addr_.toText());
+}
+
+/// @brief Checks that a valid relay info structure for IPv6 can be handled
+TEST_F(ParseConfigTest, bogusRelayInfo6) {
+
// Invalid config (wrong family type of the ip-address field
std::string config_str_bogus1 =
" {"
" }";
ElementPtr json_bogus2 = Element::fromJSON(config_str_bogus2);
+ // Missing mandatory ip-address field.
+ std::string config_str_bogus3 =
+ " {"
+ " }";
+ ElementPtr json_bogus3 = Element::fromJSON(config_str_bogus3);
+
// We need to set the default ip-address to something.
Subnet::RelayInfoPtr result(new Subnet::RelayInfo(asiolink::IOAddress("::")));
RelayInfoParser parser(Option::V6);
- // Subnet4 parser will pass :: to the RelayInfoParser
- EXPECT_NO_THROW(parser.parse(result, json));
- EXPECT_EQ("2001:db8::1", result->addr_.toText());
- // Let's check negative scenario (wrong family type)
+ // Negative scenario (wrong family type)
EXPECT_THROW(parser.parse(result, json_bogus1), DhcpConfigError);
- // Unparseable text that looks like IPv6 address, but has too many colons
+ // Looks like IPv6 address, but has too many colons
EXPECT_THROW(parser.parse(result, json_bogus2), DhcpConfigError);
+
+ // Mandatory ip-address is missing. What a pity.
+ EXPECT_THROW(parser.parse(result, json_bogus3), DhcpConfigError);
}
// There's no test for ControlSocketParser, as it is tested in the DHCPv4 code