diff options
author | Marcin Siodelski <marcin@isc.org> | 2019-05-23 18:15:01 +0200 |
---|---|---|
committer | Marcin Siodelski <marcin@isc.org> | 2019-05-24 08:54:29 +0200 |
commit | df1ace626ddc5d6635ea90507235366ff11ac6a0 (patch) | |
tree | 4a35694dfa50e9f4cd0aa22758b6226d9f22bb34 | |
parent | [#620,!332] Network level relay address is taken into account for subnet selc... (diff) | |
download | kea-df1ace626ddc5d6635ea90507235366ff11ac6a0.tar.xz kea-df1ace626ddc5d6635ea90507235366ff11ac6a0.zip |
[#620,!332] Addressed review comments.
-rw-r--r-- | src/lib/dhcpsrv/cfg_subnets6.cc | 20 | ||||
-rw-r--r-- | src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc | 21 |
2 files changed, 31 insertions, 10 deletions
diff --git a/src/lib/dhcpsrv/cfg_subnets6.cc b/src/lib/dhcpsrv/cfg_subnets6.cc index aa86bbd8c3..d30b212fe5 100644 --- a/src/lib/dhcpsrv/cfg_subnets6.cc +++ b/src/lib/dhcpsrv/cfg_subnets6.cc @@ -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); + } } } diff --git a/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc b/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc index 33f4d9b24a..118b734f12 100644 --- a/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc @@ -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 |