]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#39,!108] Options order changed:
authorTomek Mrugalski <tomasz@isc.org>
Wed, 31 Oct 2018 13:24:05 +0000 (14:24 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Wed, 31 Oct 2018 13:24:05 +0000 (14:24 +0100)
 - it is now: host, class, pool, subnet, network, global

src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp6/dhcp6_srv.cc

index f8fca028f899f0a31a740f2e5131c666f9090b4e..e0c286b8263285cdbdbbc7bd4a259fe1ad4870c4 100644 (file)
@@ -1316,38 +1316,13 @@ Dhcpv4Srv::buildCfgOptionList(Dhcpv4Exchange& ex) {
         return;
     }
 
-    // Firstly, host specific options.
+    // First: host specific options.
     const ConstHostPtr& host = ex.getContext()->currentHost();
     if (host && !host->getCfgOption4()->empty()) {
         co_list.push_back(host->getCfgOption4());
     }
 
-    // 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());
-    }
-
-    // Forthly, 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
+    // Second: each class the incoming packet belongs to.
     const ClientClasses& classes = ex.getQuery()->getClasses();
     for (ClientClasses::const_iterator cclass = classes.cbegin();
          cclass != classes.cend(); ++cclass) {
@@ -1371,7 +1346,32 @@ Dhcpv4Srv::buildCfgOptionList(Dhcpv4Exchange& ex) {
         co_list.push_back(ccdef->getCfgOption());
     }
 
-    // Last global options
+    // Third: 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());
+        }
+    }
+
+    // Fourth: subnet configured options.
+    if (!subnet->getCfgOption()->empty()) {
+        co_list.push_back(subnet->getCfgOption());
+    }
+
+    // Fifth: shared network specific options.
+    SharedNetwork4Ptr network;
+    subnet->getSharedNetwork(network);
+    if (network && !network->getCfgOption()->empty()) {
+        co_list.push_back(network->getCfgOption());
+    }
+
+    // Sixth: global options come last.
     if (!CfgMgr::instance().getCurrentCfg()->getCfgOption()->empty()) {
         co_list.push_back(CfgMgr::instance().getCurrentCfg()->getCfgOption());
     }
index c0adebbba3b033039d9cb75b4eb3cacf6b2c79f3..cbefd2e8858078350808dda3acb0af9772cf5897 100644 (file)
@@ -1051,40 +1051,12 @@ void
 Dhcpv6Srv::buildCfgOptionList(const Pkt6Ptr& question,
                               AllocEngine::ClientContext6& ctx,
                               CfgOptionList& co_list) {
-    // Firstly, host specific options.
+    // First: host specific options.
     if (ctx.currentHost() && !ctx.currentHost()->getCfgOption6()->empty()) {
         co_list.push_back(ctx.currentHost()->getCfgOption6());
     }
 
-    // Secondly, pool specific options. Pools are defined within a subnet, so
-    // if there is no subnet, there is nothing to do.
-    if (ctx.subnet_) {
-        BOOST_FOREACH(const AllocEngine::ResourceType& resource,
-                      ctx.allocated_resources_) {
-            PoolPtr pool = ctx.subnet_->getPool(resource.second == 128 ?
-                                                Lease::TYPE_NA : Lease::TYPE_PD,
-                                                resource.first, false);
-            if (pool && !pool->getCfgOption()->empty()) {
-                co_list.push_back(pool->getCfgOption());
-            }
-        }
-    };
-
-    if (ctx.subnet_) {
-        // Next, subnet configured options.
-        if (!ctx.subnet_->getCfgOption()->empty()) {
-            co_list.push_back(ctx.subnet_->getCfgOption());
-        }
-
-        // Then, shared network specific options.
-        SharedNetwork6Ptr network;
-        ctx.subnet_->getSharedNetwork(network);
-        if (network && !network->getCfgOption()->empty()) {
-            co_list.push_back(network->getCfgOption());
-        }
-    }
-
-    // Each class in the incoming packet
+    // Second: each class the incoming packet belongs to.
     const ClientClasses& classes = question->getClasses();
     for (ClientClasses::const_iterator cclass = classes.cbegin();
          cclass != classes.cend(); ++cclass) {
@@ -1110,7 +1082,35 @@ Dhcpv6Srv::buildCfgOptionList(const Pkt6Ptr& question,
         co_list.push_back(ccdef->getCfgOption());
     }
 
-    // Last global options
+    // Third: pool specific options. Pools are defined within a subnet, so
+    // if there is no subnet, there is nothing to do.
+    if (ctx.subnet_) {
+        BOOST_FOREACH(const AllocEngine::ResourceType& resource,
+                      ctx.allocated_resources_) {
+            PoolPtr pool = ctx.subnet_->getPool(resource.second == 128 ?
+                                                Lease::TYPE_NA : Lease::TYPE_PD,
+                                                resource.first, false);
+            if (pool && !pool->getCfgOption()->empty()) {
+                co_list.push_back(pool->getCfgOption());
+            }
+        }
+    };
+
+    if (ctx.subnet_) {
+        // Fourth: subnet configured options.
+        if (!ctx.subnet_->getCfgOption()->empty()) {
+            co_list.push_back(ctx.subnet_->getCfgOption());
+        }
+
+        // Fifth: shared network specific options.
+        SharedNetwork6Ptr network;
+        ctx.subnet_->getSharedNetwork(network);
+        if (network && !network->getCfgOption()->empty()) {
+            co_list.push_back(network->getCfgOption());
+        }
+    }
+
+    // Sixth: global options
     if (!CfgMgr::instance().getCurrentCfg()->getCfgOption()->empty()) {
         co_list.push_back(CfgMgr::instance().getCurrentCfg()->getCfgOption());
     }