|
@@ -729,57 +729,31 @@ RelayInfoParser::RelayInfoParser(const Option::Universe& family)
|
|
|
: family_(family) {
|
|
|
};
|
|
|
|
|
|
+// Can't use a constructor as a function
|
|
|
+namespace {
|
|
|
+IOAddress buildIOAddress(const std::string& str) { return (IOAddress(str)); }
|
|
|
+};
|
|
|
+
|
|
|
+IOAddress
|
|
|
+RelayInfoParser::getIOAddress(ConstElementPtr scope,
|
|
|
+ const std::string& name) {
|
|
|
+ return (getAndConvert<IOAddress,
|
|
|
+ buildIOAddress>(scope, name, "address"));
|
|
|
+}
|
|
|
+
|
|
|
void
|
|
|
RelayInfoParser::parse(const isc::dhcp::Subnet::RelayInfoPtr& cfg,
|
|
|
ConstElementPtr relay_info) {
|
|
|
- // Let's start with some sanity checks.
|
|
|
- if (!relay_info || !cfg) {
|
|
|
- isc_throw(DhcpConfigError, "Logic error: RelayInfoParser::parse() called "
|
|
|
- "with at least one NULL parameter.");
|
|
|
- }
|
|
|
-
|
|
|
- if (relay_info->getType() != Element::map) {
|
|
|
- isc_throw(DhcpConfigError, "Configuration error: RelayInfoParser::parse() "
|
|
|
- "called with non-map parameter");
|
|
|
- }
|
|
|
-
|
|
|
- // Now create the default value.
|
|
|
- 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 (...) {
|
|
|
- isc_throw(DhcpConfigError, "Failed to parse ip-address "
|
|
|
- "value: " << param.second
|
|
|
- << " (" << param.second->getPosition() << ")");
|
|
|
- }
|
|
|
-
|
|
|
- // Check if the address family matches.
|
|
|
- if ( (ip.isV4() && family_ != Option::V4) ||
|
|
|
- (ip.isV6() && family_ != Option::V6) ) {
|
|
|
- isc_throw(DhcpConfigError, "ip-address field " << ip.toText()
|
|
|
- << " does not have IP address of expected family type: "
|
|
|
- << (family_ == Option::V4 ? "IPv4" : "IPv6")
|
|
|
- << " (" << param.second->getPosition() << ")");
|
|
|
- }
|
|
|
- } else {
|
|
|
- isc_throw(NotImplemented,
|
|
|
- "parser error: RelayInfoParser parameter not supported: "
|
|
|
- << param.second);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!ip_address_specified) {
|
|
|
- isc_throw(DhcpConfigError, "'relay' specified, but mandatory 'ip-address' "
|
|
|
- "paramter in it is missing");
|
|
|
+ // There is only one parameter which is mandatory
|
|
|
+ IOAddress ip = getIOAddress(relay_info, "ip-address");
|
|
|
+
|
|
|
+ // Check if the address family matches.
|
|
|
+ if ((ip.isV4() && family_ != Option::V4) ||
|
|
|
+ (ip.isV6() && family_ != Option::V6) ) {
|
|
|
+ isc_throw(DhcpConfigError, "ip-address field " << ip.toText()
|
|
|
+ << " does not have IP address of expected family type: "
|
|
|
+ << (family_ == Option::V4 ? "IPv4" : "IPv6")
|
|
|
+ << " (" << getPosition("ip-address", relay_info) << ")");
|
|
|
}
|
|
|
|
|
|
// Ok, we're done with parsing. Let's store the result in the structure
|
|
@@ -1065,11 +1039,6 @@ SubnetConfigParser::createSubnet(ConstElementPtr params) {
|
|
|
|
|
|
//**************************** D2ClientConfigParser **********************
|
|
|
|
|
|
-// Can't use a constructor as a function
|
|
|
-namespace {
|
|
|
-IOAddress buildIOAddress(const std::string& str) { return (IOAddress(str)); }
|
|
|
-};
|
|
|
-
|
|
|
IOAddress
|
|
|
D2ClientConfigParser::getIOAddress(ConstElementPtr scope,
|
|
|
const std::string& name) {
|