From: Francis Dupont Date: Thu, 2 Jul 2020 14:40:48 +0000 (+0200) Subject: [#1254] Checkpoint: code done, tests and docs todo X-Git-Tag: Kea-1.8.0~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb44c58faa78db20755019d91ab2e29d18bd5233;p=thirdparty%2Fkea.git [#1254] Checkpoint: code done, tests and docs todo --- diff --git a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc index bae6d42309..83277c0c2a 100644 --- a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc +++ b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc @@ -722,6 +722,7 @@ Subnet4ConfigParser::parse(ConstElementPtr subnet) { HostReservationsListParser parser; parser.parse(subnet_->getID(), reservations, hosts); for (auto h = hosts.begin(); h != hosts.end(); ++h) { + validateResv(sn4ptr, *h); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(*h); } } @@ -930,6 +931,16 @@ Subnet4ConfigParser::initSubnet(data::ConstElementPtr params, parseDdnsParams(params, network); } +void +Subnet4ConfigParser::validateResv(const Subnet4Ptr& subnet, ConstHostPtr host) { + const IOAddress& address = host->getIPv4Reservation(); + if (!address.isV4Zero() && !subnet->inRange(address)) { + isc_throw(DhcpConfigError, "specified reservation '" << address + << "' is not matching the IPv4 subnet prefix '" + << subnet->toText() << "'"); + } +} + //**************************** Subnets4ListConfigParser ********************** Subnets4ListConfigParser::Subnets4ListConfigParser(bool check_iface) @@ -1166,6 +1177,7 @@ Subnet6ConfigParser::parse(ConstElementPtr subnet) { HostReservationsListParser parser; parser.parse(subnet_->getID(), reservations, hosts); for (auto h = hosts.begin(); h != hosts.end(); ++h) { + validateResvs(sn6ptr, *h); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(*h); } } @@ -1327,6 +1339,19 @@ Subnet6ConfigParser::initSubnet(data::ConstElementPtr params, parseDdnsParams(params, network); } +void +Subnet6ConfigParser::validateResvs(const Subnet6Ptr& subnet, ConstHostPtr host) { + IPv6ResrvRange range = host->getIPv6Reservations(IPv6Resrv::TYPE_NA); + for (auto it = range.first; it != range.second; ++it) { + const IOAddress& address = it->second.getPrefix(); + if (!subnet->inRange(address)) { + isc_throw(DhcpConfigError, "specified reservation '" << address + << "' is not matching the IPv6 subnet prefix '" + << subnet->toText() << "'"); + } + } +} + //**************************** Subnet6ListConfigParser ******************** Subnets6ListConfigParser::Subnets6ListConfigParser(bool check_iface) @@ -1525,5 +1550,5 @@ D2ClientConfigParser::setAllDefaults(isc::data::ConstElementPtr d2_config) { return (SimpleParser::setDefaults(mutable_d2, D2_CLIENT_CONFIG_DEFAULTS)); } -}; // namespace dhcp -}; // namespace isc +} // namespace dhcp +} // namespace isc diff --git a/src/lib/dhcpsrv/parsers/dhcp_parsers.h b/src/lib/dhcpsrv/parsers/dhcp_parsers.h index 3f004c1392..799ef7dc65 100644 --- a/src/lib/dhcpsrv/parsers/dhcp_parsers.h +++ b/src/lib/dhcpsrv/parsers/dhcp_parsers.h @@ -565,6 +565,13 @@ protected: /// @param len is the prefix length void initSubnet(data::ConstElementPtr params, asiolink::IOAddress addr, uint8_t len); + + /// @brief Verifies the host reservation address is in the subnet range + /// + /// @param subnet pointer to the subnet + /// @param host pointer to the host reservation + /// @throw DhcpConfigError when the address is not in the subnet range. + void validateResv(const Subnet4Ptr& subnet, ConstHostPtr host); }; /// @brief this class parses list of DHCP4 subnets @@ -771,6 +778,13 @@ protected: /// @param len is the prefix length void initSubnet(isc::data::ConstElementPtr params, isc::asiolink::IOAddress addr, uint8_t len); + + /// @brief Verifies host reservation addresses are in the subnet range + /// + /// @param subnet pointer to the subnet + /// @param host pointer to the host reservation + /// @throw DhcpConfigError when an address is not in the subnet range. + void validateResvs(const Subnet6Ptr& subnet, ConstHostPtr host); }; @@ -885,7 +899,7 @@ private: getMode(isc::data::ConstElementPtr scope, const std::string& name); }; -}; // end of isc::dhcp namespace -}; // end of isc namespace +} // end of isc::dhcp namespace +} // end of isc namespace #endif // DHCP_PARSERS_H