]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#620,!332] Network level relay address is taken into account for subnet selction.
authorMarcin Siodelski <marcin@isc.org>
Thu, 23 May 2019 12:41:28 +0000 (14:41 +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 a1561635779be3ddbcaf73a4ac62e08c932d6d94..aa86bbd8c3498d1f9ec88f575013a6528ef3de63 100644 (file)
@@ -249,15 +249,27 @@ CfgSubnets6::selectSubnet(const asiolink::IOAddress& address,
 
             // If the specified address matches a relay address, return this
             // subnet.
-            if (is_relay_address &&
-                ((*subnet)->hasRelayAddress(address)) &&
-                (*subnet)->clientSupported(client_classes)) {
-                LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
-                          DHCPSRV_CFGMGR_SUBNET6_RELAY)
-                    .arg((*subnet)->toText()).arg(address.toText());
-                return (*subnet);
+            if ((*subnet)->hasRelays()) {
+                if (!(*subnet)->hasRelayAddress(address) ||
+                    !(*subnet)->clientSupported(client_classes)) {
+                    continue;
+                }
+
+            } else {
+                SharedNetwork6Ptr network;
+                (*subnet)->getSharedNetwork(network);
+                if (!network || !network->hasRelayAddress(address) ||
+                    !network->clientSupported(client_classes)) {
+                    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);
         }
     }
 
index 2fd5119f314050c148fcdb9fd6963cdb45019862..33f4d9b24a4f54241743fa71b57ed86c0dd814f1 100644 (file)
@@ -250,6 +250,55 @@ TEST(CfgSubnets6Test, selectSubnetByRelayAddress) {
     EXPECT_EQ(subnet3, cfg.selectSubnet(selector));
 }
 
+// This test checks that subnet can be selected using a relay agent's
+// link address specified on the shared network level.
+TEST(CfgSubnets6Test, selectSubnetByNetworkRelayAddress) {
+    // Create 2 shared networks.
+    SharedNetwork6Ptr network1(new SharedNetwork6("net1"));
+    SharedNetwork6Ptr network2(new SharedNetwork6("net2"));
+    SharedNetwork6Ptr network3(new SharedNetwork6("net3"));
+
+    // Let's configure 3 subnets
+    Subnet6Ptr subnet1(new Subnet6(IOAddress("2001:db8:1::"), 48, 1, 2, 3, 4));
+    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));
+
+    // Associate subnets with shared networks.
+    network1->add(subnet1);
+    network2->add(subnet2);
+    network3->add(subnet3);
+
+    // Add subnets to the configuration.
+    CfgSubnets6 cfg;
+
+    cfg.add(subnet1);
+    cfg.add(subnet2);
+    cfg.add(subnet3);
+
+    // Make sure that none of the subnets is selected when there is no relay
+    // information configured for them.
+    SubnetSelector selector;
+    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_FALSE(cfg.selectSubnet(selector));
+
+    // Now specify relay information.
+    network1->addRelayAddress(IOAddress("2001:db8:ff::1"));
+    network2->addRelayAddress(IOAddress("2001:db8:ff::2"));
+    network3->addRelayAddress(IOAddress("2001:db8:ff::3"));
+
+    // And try again. This time relay-info is there and should match.
+    selector.first_relay_linkaddr_ = IOAddress("2001:db8:ff::1");
+    EXPECT_EQ(subnet1, cfg.selectSubnet(selector));
+    selector.first_relay_linkaddr_ = IOAddress("2001:db8:ff::2");
+    EXPECT_EQ(subnet2, 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
 // name associated with a asubnet.
 TEST(CfgSubnets6Test, selectSubnetByInterfaceName) {