From a8ce7a78b5b294e6bce02de887552a1e4593db4e Mon Sep 17 00:00:00 2001 From: Tomek Mrugalski Date: Tue, 31 Jul 2018 18:58:13 +0200 Subject: [PATCH] [5683] if clause moved in Lease parsers --- src/hooks/dhcp/lease_cmds/lease_parser.cc | 24 ++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/hooks/dhcp/lease_cmds/lease_parser.cc b/src/hooks/dhcp/lease_cmds/lease_parser.cc index 27c2b2b128..db4143d589 100644 --- a/src/hooks/dhcp/lease_cmds/lease_parser.cc +++ b/src/hooks/dhcp/lease_cmds/lease_parser.cc @@ -55,6 +55,12 @@ Lease4Parser::parse(ConstSrvConfigPtr& cfg, isc_throw(BadValue, "Invalid subnet-id: No IPv4 subnet with subnet-id=" << subnet_id << " currently configured."); } + + if (!subnet->inRange(addr)) { + isc_throw(BadValue, "The address " << addr.toText() << " does not belong " + "to subnet " << subnet->toText() << ", subnet-id=" << subnet_id); + } + } else { // Subnet-id was not specified. Let's try to figure it out on our own. subnet = cfg->getCfgSubnets4()->selectSubnet(addr); @@ -65,11 +71,6 @@ Lease4Parser::parse(ConstSrvConfigPtr& cfg, subnet_id = subnet->getID(); } - if (!subnet->inRange(addr)) { - isc_throw(BadValue, "The address " << addr.toText() << " does not belong " - "to subnet " << subnet->toText() << ", subnet-id=" << subnet_id); - } - // Client-id is optional. ClientIdPtr client_id; if (lease_info->contains("client-id")) { @@ -225,6 +226,13 @@ Lease6Parser::parse(ConstSrvConfigPtr& cfg, isc_throw(BadValue, "Invalid subnet-id: No IPv6 subnet with subnet-id=" << subnet_id << " currently configured."); } + + // Check if the address specified really belongs to the subnet. + if ((type == Lease::TYPE_NA) && !subnet->inRange(addr)) { + isc_throw(BadValue, "The address " << addr.toText() << " does not belong " + "to subnet " << subnet->toText() << ", subnet-id=" << subnet_id); + } + } else { if (type != Lease::TYPE_NA) { isc_throw(BadValue, "Subnet-id is 0 or not specified. This is allowed for" @@ -238,12 +246,6 @@ Lease6Parser::parse(ConstSrvConfigPtr& cfg, subnet_id = subnet->getID(); } - // Check if the address specified really belongs to the subnet. - if ((type == Lease::TYPE_NA) && !subnet->inRange(addr)) { - isc_throw(BadValue, "The address " << addr.toText() << " does not belong " - "to subnet " << subnet->toText() << ", subnet-id=" << subnet_id); - } - uint32_t iaid = getUint32(lease_info, "iaid"); // Hw-address is optional in v6 leases. -- 2.47.2