]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1518] reverted v4 changes which add persistent options if subnet is null
authorRazvan Becheriu <razvan@isc.org>
Fri, 20 Jan 2023 12:35:28 +0000 (14:35 +0200)
committerRazvan Becheriu <razvan@isc.org>
Fri, 20 Jan 2023 15:36:06 +0000 (17:36 +0200)
src/bin/dhcp4/dhcp4_srv.cc

index 09c6d443da2da6c0ba58731b57d7253f9b1a1c0f..0dac581215188584d4f8de887a9438f3f1ad021d 100644 (file)
@@ -1736,38 +1736,41 @@ Dhcpv4Srv::buildCfgOptionList(Dhcpv4Exchange& ex) {
 
     // Retrieve subnet.
     Subnet4Ptr subnet = ex.getContext()->subnet_;
+    if (!subnet) {
+        // All methods using the CfgOptionList object return soon when
+        // there is no subnet so do the same
+        return;
+    }
+
     // Firstly, host specific options.
     const ConstHostPtr& host = ex.getContext()->currentHost();
     if (host && !host->getCfgOption4()->empty()) {
         co_list.push_back(host->getCfgOption4());
     }
 
-    // Secondly, pool specific options. Pools are defined within a subnet, so
-    // if there is no subnet, there is nothing to do.
-    if (subnet) {
-        Pkt4Ptr resp = ex.getResponse();
-        IOAddress addr = IOAddress::IPV4_ZERO_ADDRESS();
-        if (resp) {
-            addr = resp->getYiaddr();
-        }
-        if (!addr.isV4Zero()) {
-            PoolPtr pool = subnet->getPool(Lease::TYPE_V4, addr, false);
-            if (pool && !pool->getCfgOption()->empty()) {
-                co_list.push_back(pool->getCfgOption());
-            }
+    // Secondly, pool specific options.
+    Pkt4Ptr resp = ex.getResponse();
+    IOAddress addr = IOAddress::IPV4_ZERO_ADDRESS();
+    if (resp) {
+        addr = resp->getYiaddr();
+    }
+    if (!addr.isV4Zero()) {
+        PoolPtr pool = subnet->getPool(Lease::TYPE_V4, addr, false);
+        if (pool && !pool->getCfgOption()->empty()) {
+            co_list.push_back(pool->getCfgOption());
         }
+    }
 
-        // Thirdly, subnet configured options.
-        if (!subnet->getCfgOption()->empty()) {
-            co_list.push_back(subnet->getCfgOption());
-        }
+    // Thirdly, subnet configured options.
+    if (!subnet->getCfgOption()->empty()) {
+        co_list.push_back(subnet->getCfgOption());
+    }
 
-        // Fourthly, shared network specific options.
-        SharedNetwork4Ptr network;
-        subnet->getSharedNetwork(network);
-        if (network && !network->getCfgOption()->empty()) {
-            co_list.push_back(network->getCfgOption());
-        }
+    // Fourthly, shared network specific options.
+    SharedNetwork4Ptr network;
+    subnet->getSharedNetwork(network);
+    if (network && !network->getCfgOption()->empty()) {
+        co_list.push_back(network->getCfgOption());
     }
 
     // Each class in the incoming packet
@@ -1804,6 +1807,17 @@ Dhcpv4Srv::buildCfgOptionList(Dhcpv4Exchange& ex) {
 
 void
 Dhcpv4Srv::appendRequestedOptions(Dhcpv4Exchange& ex) {
+    // Get the subnet relevant for the client. We will need it
+    // to get the options associated with it.
+    Subnet4Ptr subnet = ex.getContext()->subnet_;
+    // If we can't find the subnet for the client there is no way
+    // to get the options to be sent to a client. We don't log an
+    // error because it will be logged by the assignLease method
+    // anyway.
+    if (!subnet) {
+        return;
+    }
+
     // Unlikely short cut
     const CfgOptionList& co_list = ex.getCfgOptionList();
     if (co_list.empty()) {