]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#620,!332] Addressed review comments.
authorMarcin Siodelski <marcin@isc.org>
Thu, 23 May 2019 16:15:01 +0000 (18:15 +0200)
committerMarcin Siodelski <marcin@isc.org>
Fri, 24 May 2019 06:54:29 +0000 (02:54 -0400)
src/lib/dhcpsrv/cfg_subnets6.cc
src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc

index aa86bbd8c3498d1f9ec88f575013a6528ef3de63..d30b212fe5b8c31e678f81eb4a6a6b25d0b9f079 100644 (file)
@@ -250,26 +250,26 @@ CfgSubnets6::selectSubnet(const asiolink::IOAddress& address,
             // If the specified address matches a relay address, return this
             // subnet.
             if ((*subnet)->hasRelays()) {
-                if (!(*subnet)->hasRelayAddress(address) ||
-                    !(*subnet)->clientSupported(client_classes)) {
+                if (!(*subnet)->hasRelayAddress(address)) {
                     continue;
                 }
 
             } else {
                 SharedNetwork6Ptr network;
                 (*subnet)->getSharedNetwork(network);
-                if (!network || !network->hasRelayAddress(address) ||
-                    !network->clientSupported(client_classes)) {
+                if (!network || !network->hasRelayAddress(address)) {
                     continue;
                 }
             }
 
-            // The relay address is matching the one specified for a subnet
-            // or a shared network.
-            LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
-                      DHCPSRV_CFGMGR_SUBNET6_RELAY)
-                .arg((*subnet)->toText()).arg(address.toText());
-            return (*subnet);
+            if ((*subnet)->clientSupported(client_classes)) {
+                // The relay address is matching the one specified for a subnet
+                // or its shared network.
+                LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
+                          DHCPSRV_CFGMGR_SUBNET6_RELAY)
+                    .arg((*subnet)->toText()).arg(address.toText());
+                return (*subnet);
+            }
         }
     }
 
index 33f4d9b24a4f54241743fa71b57ed86c0dd814f1..118b734f12c4d90a8b289ab4fa99d7414abd90b9 100644 (file)
@@ -263,6 +263,11 @@ TEST(CfgSubnets6Test, selectSubnetByNetworkRelayAddress) {
     Subnet6Ptr subnet2(new Subnet6(IOAddress("2001:db8:2::"), 48, 1, 2, 3, 4));
     Subnet6Ptr subnet3(new Subnet6(IOAddress("2001:db8:3::"), 48, 1, 2, 3, 4));
 
+    // Allow subnet class of clients to use the subnets.
+    subnet1->allowClientClass("subnet");
+    subnet2->allowClientClass("subnet");
+    subnet3->allowClientClass("subnet");
+
     // Associate subnets with shared networks.
     network1->add(subnet1);
     network2->add(subnet2);
@@ -278,6 +283,10 @@ TEST(CfgSubnets6Test, selectSubnetByNetworkRelayAddress) {
     // Make sure that none of the subnets is selected when there is no relay
     // information configured for them.
     SubnetSelector selector;
+    selector.client_classes_.insert("subnet");
+
+    // The relays are not set for networks, so none of the subnets should
+    // be selected.
     selector.first_relay_linkaddr_ = IOAddress("2001:db8:ff::1");
     EXPECT_FALSE(cfg.selectSubnet(selector));
     selector.first_relay_linkaddr_ = IOAddress("2001:db8:ff::2");
@@ -297,6 +306,18 @@ TEST(CfgSubnets6Test, selectSubnetByNetworkRelayAddress) {
     EXPECT_EQ(subnet2, cfg.selectSubnet(selector));
     selector.first_relay_linkaddr_ = IOAddress("2001:db8:ff::3");
     EXPECT_EQ(subnet3, cfg.selectSubnet(selector));
+
+    // Modify the client classes associated with the first two subnets.
+    subnet1->allowClientClass("subnet1");
+    subnet2->allowClientClass("subnet2");
+
+    // This time the non-matching classes should prevent selection.
+    selector.first_relay_linkaddr_ = IOAddress("2001:db8:ff::1");
+    EXPECT_FALSE(cfg.selectSubnet(selector));
+    selector.first_relay_linkaddr_ = IOAddress("2001:db8:ff::2");
+    EXPECT_FALSE(cfg.selectSubnet(selector));
+    selector.first_relay_linkaddr_ = IOAddress("2001:db8:ff::3");
+    EXPECT_EQ(subnet3, cfg.selectSubnet(selector));
 }
 
 // This test checks that the subnet can be selected using an interface