]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[710-cb_cmds-add-support-for-server-tags-in-global-options] Addressed some comments
authorFrancis Dupont <fdupont@isc.org>
Fri, 5 Jul 2019 11:09:51 +0000 (13:09 +0200)
committerFrancis Dupont <fdupont@isc.org>
Tue, 9 Jul 2019 07:30:45 +0000 (09:30 +0200)
src/lib/dhcpsrv/testutils/test_config_backend.h
src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.cc
src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.cc

index e29d2cce4ce51f6d9a4ec273c94761af5c980888..85bcbd9bf39cc535ba8ecb753e34fa296822de3b 100644 (file)
@@ -99,10 +99,9 @@ public:
         for (auto tag : tags) {
             // Until the stamped element tags are in a set (vs a vector)
             // we have to avoid duplicates.
-            if (dst->hasServerTag(tag)) {
-                continue;
+            if (!dst->hasServerTag(tag)) {
+                dst->setServerTag(tag.get());
             }
-            dst->setServerTag(tag.get());
         }
     }
 
@@ -116,10 +115,9 @@ public:
         for (auto tag : tags) {
             // Until the stamped element tags are in a set (vs a vector)
             // we have to avoid duplicates.
-            if (elem->hasServerTag(tag)) {
-                continue;
+            if (!elem->hasServerTag(tag)) {
+                elem->setServerTag(tag.get());
             }
-            elem->setServerTag(tag.get());
         }
     }
 
index 5c161fb3f6978d5f729a6646b145be591b644aaa..f91796ea86fc45cea5e0f669afe8a1a4e132f894 100644 (file)
@@ -562,29 +562,36 @@ TestConfigBackendDHCPv4::createUpdateOption4(const db::ServerSelector& server_se
     auto tags = server_selector.getTags();
     auto not_in_tags = false;
     for (auto subnet : subnets_) {
+       // Get the pool: if it is not here we can directly go to the next subnet.
         auto pool = subnet->getPool(Lease::TYPE_V4, pool_start_address);
         if (!pool) {
             continue;
         }
+
+       // Verify the subnet is in all or one of the given servers.
         if (!subnet->hasAllServerTag()) {
+           auto in_tags = false;
             for (auto tag : tags) {
                 if (subnet->hasServerTag(ServerTag(tag))) {
-                    not_in_tags = true;
+                   in_tags = true;
                     break;
                 }
             }
-            if (not_in_tags) {
+            if (!in_tags) {
+               // Records the fact a subnet was found but not in a server.
+               not_in_tags = true;
                 continue;
             }
         }
 
+       // Update the option.
         pool->getCfgOption()->del(option->space_name_, option->option_->getType());
         pool->getCfgOption()->add(*option, option->space_name_);
 
         return;
     }
 
-    if (!not_in_tags) {
+    if (not_in_tags) {
         isc_throw(BadValue, "attempted to create or update option in "
                   "a non existing pool " << pool_start_address
                   << " - " << pool_end_address);
index f4e5561587d434c14358a33de92339f862ff5154..e557f94b1c8cc74ad4e9012307108294432daccf 100644 (file)
@@ -561,29 +561,36 @@ TestConfigBackendDHCPv6::createUpdateOption6(const db::ServerSelector& server_se
     auto tags = server_selector.getTags();
     auto not_in_tags = false;
     for (auto subnet : subnets_) {
+       // Get the pool: if it is not here we can directly go to the next subnet.
         auto pool = subnet->getPool(Lease::TYPE_NA, pool_start_address);
         if (!pool) {
             continue;
         }
+
+       // Verify the subnet is in all or one of the given servers.
         if (!subnet->hasAllServerTag()) {
+           auto in_tags = false;
             for (auto tag : tags) {
                 if (subnet->hasServerTag(ServerTag(tag))) {
-                    not_in_tags = true;
+                   in_tags = true;
                     break;
                 }
             }
-            if (not_in_tags) {
+            if (!in_tags) {
+               // Records the fact a subnet was found but not in a server.
+               not_in_tags = true;
                 continue;
             }
         }
 
+       // Update the option.
         pool->getCfgOption()->del(option->space_name_, option->option_->getType());
         pool->getCfgOption()->add(*option, option->space_name_);
 
         return;
     }
 
-    if (!not_in_tags) {
+    if (not_in_tags) {
         isc_throw(BadValue, "attempted to create or update option in "
                   "a non existing pool " << pool_start_address
                   << " - " << pool_end_address);
@@ -603,29 +610,36 @@ TestConfigBackendDHCPv6::createUpdateOption6(const db::ServerSelector& server_se
     auto tags = server_selector.getTags();
     auto not_in_tags = false;
     for (auto subnet : subnets_) {
+       // Get the pd pool: if it is not here we can directly go to the next subnet.
         auto pdpool = subnet->getPool(Lease::TYPE_PD, pd_pool_prefix);
         if (!pdpool) {
             continue;
         }
+
+       // Verify the subnet is in all or one of the given servers.
         if (!subnet->hasAllServerTag()) {
+           auto in_tags = false;
             for (auto tag : tags) {
                 if (subnet->hasServerTag(ServerTag(tag))) {
-                    not_in_tags = true;
+                    in_tags = true;
                     break;
                 }
             }
-            if (not_in_tags) {
+            if (!in_tags) {
+               // Records the fact a subnet was found but not in a server.
+               not_in_tags = true;
                 continue;
             }
         }
 
+       // Update the option.
         pdpool->getCfgOption()->del(option->space_name_, option->option_->getType());
         pdpool->getCfgOption()->add(*option, option->space_name_);
 
         return;
     }
 
-    if (!not_in_tags) {
+    if (not_in_tags) {
         isc_throw(BadValue, "attempted to create or update option in "
                   "a non existing prefix pool " << pd_pool_prefix
                   << "/" << static_cast<unsigned>(pd_pool_prefix_length));