From: Marcin Siodelski Date: Thu, 23 May 2019 16:15:01 +0000 (+0200) Subject: [#620,!332] Addressed review comments. X-Git-Tag: Kea-1.6.0-beta~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df1ace626ddc5d6635ea90507235366ff11ac6a0;p=thirdparty%2Fkea.git [#620,!332] Addressed review comments. --- 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