Commit ecaa3bfb authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[2414] CfgMgr now returns a subnet if a client is local.

parent bd3faa6a
......@@ -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]);
}
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment