]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1254] Checkpoint: code done, tests and docs todo
authorFrancis Dupont <fdupont@isc.org>
Thu, 2 Jul 2020 14:40:48 +0000 (16:40 +0200)
committerRazvan Becheriu <razvan@isc.org>
Fri, 14 Aug 2020 14:41:26 +0000 (17:41 +0300)
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
src/lib/dhcpsrv/parsers/dhcp_parsers.h

index bae6d42309416e2d57dcf9fce0b4808ccccb4c88..83277c0c2aa8456b9466cfa22c53ffdafc7e769b 100644 (file)
@@ -722,6 +722,7 @@ Subnet4ConfigParser::parse(ConstElementPtr subnet) {
         HostReservationsListParser<HostReservationParser4> 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<HostReservationParser6> 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
index 3f004c139267a5f6e7f23dc1825f58f24fd98353..799ef7dc6542124f5565990a856fdbec02914a04 100644 (file)
@@ -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