diff options
author | Marcin Siodelski <marcin@isc.org> | 2019-05-23 14:41:28 +0200 |
---|---|---|
committer | Marcin Siodelski <marcin@isc.org> | 2019-05-24 08:54:29 +0200 |
commit | 770b2f647dcaa45d9d0aef0d122b006f2c27e1b5 (patch) | |
tree | c531cae60bf5fa675a9db998ee43a768e229fefe | |
parent | [#624] ChangeLog updated. (diff) | |
download | kea-770b2f647dcaa45d9d0aef0d122b006f2c27e1b5.tar.xz kea-770b2f647dcaa45d9d0aef0d122b006f2c27e1b5.zip |
[#620,!332] Network level relay address is taken into account for subnet selction.
-rw-r--r-- | src/lib/dhcpsrv/cfg_subnets6.cc | 26 | ||||
-rw-r--r-- | src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc | 49 |
2 files changed, 68 insertions, 7 deletions
diff --git a/src/lib/dhcpsrv/cfg_subnets6.cc b/src/lib/dhcpsrv/cfg_subnets6.cc index a156163577..aa86bbd8c3 100644 --- a/src/lib/dhcpsrv/cfg_subnets6.cc +++ b/src/lib/dhcpsrv/cfg_subnets6.cc @@ -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); } } diff --git a/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc b/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc index 2fd5119f31..33f4d9b24a 100644 --- a/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc @@ -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) { |