From: Tomek Mrugalski Date: Tue, 30 Oct 2012 17:31:41 +0000 (+0100) Subject: [2414] CfgMgr now returns a subnet if a client is local. X-Git-Tag: trac2487_base~1^2~31^2~30 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ecaa3bfbcea80a640778d8f0629e7976d87bde92;p=thirdparty%2Fkea.git [2414] CfgMgr now returns a subnet if a client is local. --- diff --git a/src/lib/dhcp/cfgmgr.cc b/src/lib/dhcp/cfgmgr.cc index d06544c559..5b40a2d37e 100644 --- a/src/lib/dhcp/cfgmgr.cc +++ b/src/lib/dhcp/cfgmgr.cc @@ -41,7 +41,7 @@ CfgMgr::getSubnet6(const isc::asiolink::IOAddress& hint) { // configuration. Such requirement makes sense in IPv4, but not in IPv6. // The server does not need to have a global address (using just link-local // is ok for DHCPv6 server) from the pool it serves. - if (subnets6_.size() == 1) { + if ( (subnets6_.size() == 1) && hint.getAddress().to_v6().is_link_local()) { return (subnets6_[0]); } diff --git a/src/lib/dhcp/tests/cfgmgr_unittest.cc b/src/lib/dhcp/tests/cfgmgr_unittest.cc index 9c3e367462..fc330ea0a4 100644 --- a/src/lib/dhcp/tests/cfgmgr_unittest.cc +++ b/src/lib/dhcp/tests/cfgmgr_unittest.cc @@ -32,13 +32,22 @@ using boost::scoped_ptr; namespace { +class CfgMgrTest : public ::testing::Test { +public: + CfgMgrTest() { + } + + ~CfgMgrTest() { + CfgMgr::instance().deleteSubnets6(); + } +}; + + // This test verifies if the configuration manager is able to hold and return // valid leases -TEST(CfgMgrTest, subnet4) { +TEST_F(CfgMgrTest, subnet4) { CfgMgr& cfg_mgr = CfgMgr::instance(); - ASSERT_TRUE(&cfg_mgr != 0); - Subnet4Ptr subnet1(new Subnet4(IOAddress("192.0.2.0"), 26, 1, 2, 3)); Subnet4Ptr subnet2(new Subnet4(IOAddress("192.0.2.64"), 26, 1, 2, 3)); Subnet4Ptr subnet3(new Subnet4(IOAddress("192.0.2.128"), 26, 1, 2, 3)); @@ -66,11 +75,9 @@ TEST(CfgMgrTest, subnet4) { // This test verifies if the configuration manager is able to hold and return // valid leases -TEST(CfgMgrTest, subnet6) { +TEST_F(CfgMgrTest, subnet6) { CfgMgr& cfg_mgr = CfgMgr::instance(); - ASSERT_TRUE(&cfg_mgr != 0); - Subnet6Ptr subnet1(new Subnet6(IOAddress("2000::"), 48, 1, 2, 3, 4)); Subnet6Ptr subnet2(new Subnet6(IOAddress("3000::"), 48, 1, 2, 3, 4)); Subnet6Ptr subnet3(new Subnet6(IOAddress("4000::"), 48, 1, 2, 3, 4)); @@ -83,6 +90,10 @@ TEST(CfgMgrTest, subnet6) { // Now we have only one subnet, any request will be served from it EXPECT_EQ(subnet1, cfg_mgr.getSubnet6(IOAddress("2000::1"))); + // If we have only a single subnet and the request came from a local + // address, let's use that subnet + EXPECT_EQ(subnet1, cfg_mgr.getSubnet6(IOAddress("fe80::dead:beef"))); + cfg_mgr.addSubnet6(subnet2); cfg_mgr.addSubnet6(subnet3);