From: Razvan Becheriu Date: Tue, 20 Jun 2023 16:35:14 +0000 (+0300) Subject: [#2725] add check for prefixlen for non pd type X-Git-Tag: Kea-2.4.0~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3810b6527d61072f2b2339fd077d3d4b0de63b97;p=thirdparty%2Fkea.git [#2725] add check for prefixlen for non pd type --- diff --git a/src/bin/admin/tests/data/lease6_dump_test.reference.csv b/src/bin/admin/tests/data/lease6_dump_test.reference.csv index 74fe733abf..36935378b4 100644 --- a/src/bin/admin/tests/data/lease6_dump_test.reference.csv +++ b/src/bin/admin/tests/data/lease6_dump_test.reference.csv @@ -1,4 +1,4 @@ address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source,pool_id -::10,32:30:33,30,1642000000,40,50,1,60,70,1,1,one.example.com,38:30,0,,90,16,0 -::11,32:31:33,30,1643210000,40,50,1,60,70,1,1,,38:30,1,{ },90,1,0 -::12,32:32:33,30,1643212345,40,50,1,60,70,1,1,threeˎxampleˌom,38:30,2,{ "a": 1, "b": "c" },90,4,0 +::10,32:30:33,30,1642000000,40,50,1,60,128,1,1,one.example.com,38:30,0,,90,16,0 +::11,32:31:33,30,1643210000,40,50,1,60,128,1,1,,38:30,1,{ },90,1,0 +::12,32:32:33,30,1643212345,40,50,1,60,128,1,1,threeˎxampleˌom,38:30,2,{ "a": 1, "b": "c" },90,4,0 diff --git a/src/bin/admin/tests/mysql_tests.sh.in b/src/bin/admin/tests/mysql_tests.sh.in index 55bbad3ad4..889ce522bb 100644 --- a/src/bin/admin/tests/mysql_tests.sh.in +++ b/src/bin/admin/tests/mysql_tests.sh.in @@ -1602,9 +1602,9 @@ mysql_lease6_dump_test() { # Insert the reference record insert_sql="\ -insert into lease6 values(inet6_aton('::10'),203,30,(SELECT FROM_UNIXTIME(1642000000)),40,50,1,60,70,1,1,'one.example.com',80,90,16,0,NULL,0);\ -insert into lease6 values(inet6_aton('::11'),213,30,(SELECT FROM_UNIXTIME(1643210000)),40,50,1,60,70,1,1,'',80,90,1,1,'{ }',0);\ -insert into lease6 values(inet6_aton('::12'),223,30,(SELECT FROM_UNIXTIME(1643212345)),40,50,1,60,70,1,1,'three,example,com',80,90,4,2,'{ \"a\": 1, \"b\": \"c\" }',0)" +insert into lease6 values(inet6_aton('::10'),203,30,(SELECT FROM_UNIXTIME(1642000000)),40,50,1,60,128,1,1,'one.example.com',80,90,16,0,NULL,0);\ +insert into lease6 values(inet6_aton('::11'),213,30,(SELECT FROM_UNIXTIME(1643210000)),40,50,1,60,128,1,1,'',80,90,1,1,'{ }',0);\ +insert into lease6 values(inet6_aton('::12'),223,30,(SELECT FROM_UNIXTIME(1643212345)),40,50,1,60,128,1,1,'three,example,com',80,90,4,2,'{ \"a\": 1, \"b\": \"c\" }',0)" run_command \ mysql_execute "$insert_sql" diff --git a/src/bin/admin/tests/pgsql_tests.sh.in b/src/bin/admin/tests/pgsql_tests.sh.in index 63b4e039f6..f9b839e20d 100644 --- a/src/bin/admin/tests/pgsql_tests.sh.in +++ b/src/bin/admin/tests/pgsql_tests.sh.in @@ -1062,9 +1062,9 @@ pgsql_lease6_dump_test() { # Because shell evaluates the double quoted string one more time, they need to be doubled. # Otherwise, the value is interpreted as ASCII instead of raw bytes. insert_sql="\ -insert into lease6 values(cast('::10' as inet),E'\\\\x323033',30,TO_TIMESTAMP(1642000000),40,50,1,60,70,'t','t','one.example.com',0,decode(encode('80','hex'),'hex'),90,16,'',0); \ -insert into lease6 values(cast('::11' as inet),E'\\\\x323133',30,TO_TIMESTAMP(1643210000),40,50,1,60,70,'t','t','',1,decode(encode('80','hex'),'hex'),90,1,'{ }',0); \ -insert into lease6 values(cast('::12' as inet),E'\\\\x323233',30,TO_TIMESTAMP(1643212345),40,50,1,60,70,'t','t','three,example,com',2,decode(encode('80','hex'),'hex'),90,4,'{ \"a\": 1, \"b\": \"c\" }',0)" +insert into lease6 values(cast('::10' as inet),E'\\\\x323033',30,TO_TIMESTAMP(1642000000),40,50,1,60,128,'t','t','one.example.com',0,decode(encode('80','hex'),'hex'),90,16,'',0); \ +insert into lease6 values(cast('::11' as inet),E'\\\\x323133',30,TO_TIMESTAMP(1643210000),40,50,1,60,128,'t','t','',1,decode(encode('80','hex'),'hex'),90,1,'{ }',0); \ +insert into lease6 values(cast('::12' as inet),E'\\\\x323233',30,TO_TIMESTAMP(1643212345),40,50,1,60,128,'t','t','three,example,com',2,decode(encode('80','hex'),'hex'),90,4,'{ \"a\": 1, \"b\": \"c\" }',0)" run_command \ pgsql_execute "$insert_sql" diff --git a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc index 2a282c2b49..40ee751cae 100644 --- a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc @@ -1822,7 +1822,7 @@ TEST_F(Dhcpv6SrvTest, RenewWrongIAID) { // leased by client B. The server should detect that the lease belong to // someone else and assign a different lease. This is the third out of three // scenarios tests by old RenewReject test. -TEST_F(Dhcpv6SrvTest, RenewSomeoneElesesLease) { +TEST_F(Dhcpv6SrvTest, RenewSomeoneElsesLease) { testRenewSomeoneElsesLease(Lease::TYPE_NA, IOAddress("2001:db8::1")); } diff --git a/src/bin/dhcp6/tests/dhcp6_test_utils.cc b/src/bin/dhcp6/tests/dhcp6_test_utils.cc index 9075e41670..212a4d769d 100644 --- a/src/bin/dhcp6/tests/dhcp6_test_utils.cc +++ b/src/bin/dhcp6/tests/dhcp6_test_utils.cc @@ -457,7 +457,7 @@ Dhcpv6SrvTest::testRenewWrongIAID(Lease::Type type, const IOAddress& addr) { const uint32_t valid_iaid = 234; const uint32_t bogus_iaid = 456; - uint8_t prefix_len = (type == Lease::TYPE_PD) ? 128 : pd_pool_->getLength(); + uint8_t prefix_len = (type != Lease::TYPE_PD) ? 128 : pd_pool_->getLength(); // Quick sanity check that the address we're about to use is ok ASSERT_TRUE(subnet_->inPool(type, addr)); @@ -514,7 +514,7 @@ Dhcpv6SrvTest::testRenewSomeoneElsesLease(Lease::Type type, const IOAddress& add const uint32_t valid_iaid = 234; const uint32_t transid = 1234; - uint8_t prefix_len = (type == Lease::TYPE_PD) ? 128 : pd_pool_->getLength(); + uint8_t prefix_len = (type != Lease::TYPE_PD) ? 128 : pd_pool_->getLength(); // GenerateClientId() also sets duid_ OptionPtr clientid = generateClientId(); diff --git a/src/bin/dhcp6/tests/fqdn_unittest.cc b/src/bin/dhcp6/tests/fqdn_unittest.cc index ecc7737051..2c0fc1ce64 100644 --- a/src/bin/dhcp6/tests/fqdn_unittest.cc +++ b/src/bin/dhcp6/tests/fqdn_unittest.cc @@ -80,8 +80,7 @@ public: // generateClientId assigns DUID to duid_. generateClientId(); lease_.reset(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"), - duid_, 1234, 501, 502, - 1, HWAddrPtr(), 0)); + duid_, 1234, 501, 502, 1, HWAddrPtr())); // Config DDNS to be enabled, all controls off enableD2(); } @@ -1823,7 +1822,7 @@ TEST_F(FqdnDhcpv6SrvTest, ddnsSharedNetworkTest) { // Make sure the lease hostname and fqdn flags are correct. Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, - IOAddress("2001:db8:1::1")); + IOAddress("2001:db8:1::1")); ASSERT_TRUE(lease); EXPECT_EQ("client1.one.example.com.", lease->hostname_); EXPECT_TRUE(lease->fqdn_fwd_); @@ -1980,7 +1979,7 @@ TEST_F(FqdnDhcpv6SrvTest, ddnsSharedNetworkTest2) { // Make sure the lease hostname and fdqn flags are correct. Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, - IOAddress("2001:db8:1::1")); + IOAddress("2001:db8:1::1")); ASSERT_TRUE(lease); EXPECT_EQ("client1.one.example.com.", lease->hostname_); EXPECT_TRUE(lease->fqdn_fwd_); @@ -2076,7 +2075,7 @@ TEST_F(FqdnDhcpv6SrvTest, processRequestRenew) { SCOPED_TRACE(scenario.description_); { // Make sure the lease does not exist. ASSERT_FALSE(LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, - IOAddress("2001:db8:1:1::dead:beef"))); + IOAddress("2001:db8:1:1::dead:beef"))); // Set and verify DDNS params flags subnet_->setDdnsSendUpdates(scenario.send_updates_); subnet_->setDdnsUpdateOnRenew(scenario.update_on_renew_); @@ -2089,7 +2088,7 @@ TEST_F(FqdnDhcpv6SrvTest, processRequestRenew) { // The lease should have been recorded in the database. Lease6Ptr old_lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, - IOAddress("2001:db8:1:1::dead:beef")); + IOAddress("2001:db8:1:1::dead:beef")); ASSERT_TRUE(old_lease); if (!scenario.send_updates_ || scenario.old_fqdn_.empty()) { @@ -2109,7 +2108,7 @@ TEST_F(FqdnDhcpv6SrvTest, processRequestRenew) { // The lease should have been recorded in the database. Lease6Ptr new_lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, - IOAddress("2001:db8:1:1::dead:beef")); + IOAddress("2001:db8:1:1::dead:beef")); ASSERT_TRUE(new_lease); // Verify queue count is correct. diff --git a/src/bin/dhcp6/tests/hooks_unittest.cc b/src/bin/dhcp6/tests/hooks_unittest.cc index 7f38299d1c..c34aa763c6 100644 --- a/src/bin/dhcp6/tests/hooks_unittest.cc +++ b/src/bin/dhcp6/tests/hooks_unittest.cc @@ -4022,14 +4022,12 @@ TEST_F(HooksDhcpv6SrvTest, lease6RenewSimple) { // Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid // value on purpose. They should be updated during RENEW. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = 1234; ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); // Check that the lease is really in the database - Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, - addr); + Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr); ASSERT_TRUE(l); // Check that preferred, valid and cltt really set and not using @@ -4126,14 +4124,12 @@ TEST_F(HooksDhcpv6SrvTest, lease6RenewLeaseUpdate) { // Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid // value on purpose. They should be updated during RENEW. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = 1234; ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); // Check that the lease is really in the database - Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, - addr); + Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr); ASSERT_TRUE(l); // Check that preferred, valid and cltt really set and not using @@ -4230,14 +4226,12 @@ TEST_F(HooksDhcpv6SrvTest, lease6RenewSkip) { // Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid // value on purpose. They should be updated during RENEW. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = 1234; ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); // Check that the lease is really in the database - Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, - addr); + Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr); ASSERT_TRUE(l); // Check that preferred, valid and cltt are really set and not using @@ -4301,14 +4295,12 @@ TEST_F(HooksDhcpv6SrvTest, lease6RebindSimple) { // Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid // value on purpose. They should be updated during REBIND. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = 1234; ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); // Check that the lease is really in the database - Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, - addr); + Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr); ASSERT_TRUE(l); // Check that preferred, valid and cltt really set and not using @@ -4400,14 +4392,12 @@ TEST_F(HooksDhcpv6SrvTest, lease6RebindLeaseUpdate) { // Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid // value on purpose. They should be updated during REBIND. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = 1234; ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); // Check that the lease is really in the database - Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, - addr); + Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr); ASSERT_TRUE(l); // Check that T1, T2, preferred, valid and cltt really set and not using @@ -4502,14 +4492,12 @@ TEST_F(HooksDhcpv6SrvTest, lease6RebindSkip) { // Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid // value on purpose. They should be updated during REBIND. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = 1234; ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); // Check that the lease is really in the database - Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, - addr); + Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr); ASSERT_TRUE(l); // Check that preferred, valid and cltt really set and not using @@ -4579,14 +4567,12 @@ TEST_F(HooksDhcpv6SrvTest, lease6ReleaseSimple) { // Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid // value on purpose. They should be updated during RENEW. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = 1234; ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); // Check that the lease is really in the database - Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, - addr); + Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr); ASSERT_TRUE(l); // Let's create a RELEASE @@ -4668,16 +4654,14 @@ TEST_F(HooksDhcpv6SrvTest, lease6ReleaseSimpleInfiniteLease) { // Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid // value on purpose. They should be updated during RENEW. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = 1234; lease->valid_lft_ = Lease::INFINITY_LFT; lease->current_valid_lft_ = Lease::INFINITY_LFT; ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); // Check that the lease is really in the database - Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, - addr); + Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr); ASSERT_TRUE(l); // Let's create a RELEASE @@ -4758,14 +4742,12 @@ TEST_F(HooksDhcpv6SrvTest, lease6ReleaseSimpleNoDelete) { // Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid // value on purpose. They should be updated during RENEW. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = 1234; ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); // Check that the lease is really in the database - Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, - addr); + Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr); ASSERT_TRUE(l); // Let's create a RELEASE @@ -4847,14 +4829,12 @@ TEST_F(HooksDhcpv6SrvTest, lease6ReleasePrefixSimple) { // Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid // value on purpose. They should be updated during RENEW. Lease6Ptr lease(new Lease6(Lease::TYPE_PD, prefix, duid_, iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 80)); + 501, 502, subnet_->getID(), HWAddrPtr(), 80)); lease->cltt_ = 1234; ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); // Check that the lease is really in the database - Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD, - prefix); + Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD, prefix); ASSERT_TRUE(l); // Let's create a RELEASE @@ -4930,16 +4910,14 @@ TEST_F(HooksDhcpv6SrvTest, lease6ReleasePrefixSimpleInfiniteLease) { // Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid // value on purpose. They should be updated during RENEW. Lease6Ptr lease(new Lease6(Lease::TYPE_PD, prefix, duid_, iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 80)); + 501, 502, subnet_->getID(), HWAddrPtr(), 80)); lease->cltt_ = 1234; lease->valid_lft_ = Lease::INFINITY_LFT; lease->current_valid_lft_ = Lease::INFINITY_LFT; ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); // Check that the lease is really in the database - Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD, - prefix); + Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD, prefix); ASSERT_TRUE(l); // Let's create a RELEASE @@ -5014,14 +4992,12 @@ TEST_F(HooksDhcpv6SrvTest, lease6ReleasePrefixSimpleNoDelete) { // Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid // value on purpose. They should be updated during RENEW. Lease6Ptr lease(new Lease6(Lease::TYPE_PD, prefix, duid_, iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 80)); + 501, 502, subnet_->getID(), HWAddrPtr(), 80)); lease->cltt_ = 1234; ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); // Check that the lease is really in the database - Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD, - prefix); + Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD, prefix); ASSERT_TRUE(l); // Let's create a RELEASE @@ -5102,14 +5078,12 @@ TEST_F(HooksDhcpv6SrvTest, lease6ReleaseSkip) { // Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid // value on purpose. They should be updated during RENEW. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = 1234; ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); // Check that the lease is really in the database - Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, - addr); + Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr); ASSERT_TRUE(l); // Let's create a RELEASE @@ -5135,8 +5109,7 @@ TEST_F(HooksDhcpv6SrvTest, lease6ReleaseSkip) { // Check that the lease is still there // get lease by address - l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, - addr); + l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr); ASSERT_TRUE(l); // Get lease by subnetid/duid/iaid combination @@ -5169,14 +5142,12 @@ TEST_F(HooksDhcpv6SrvTest, lease6ReleaseDrop) { // Note that preferred, valid, T1 and T2 timers and CLTT are set to invalid // value on purpose. They should be updated during RENEW. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = 1234; ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); // Check that the lease is really in the database - Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, - addr); + Lease6Ptr l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr); ASSERT_TRUE(l); // Let's create a RELEASE @@ -5202,8 +5173,7 @@ TEST_F(HooksDhcpv6SrvTest, lease6ReleaseDrop) { // Check that the lease is still there // get lease by address - l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, - addr); + l = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, addr); ASSERT_TRUE(l); // Get lease by subnetid/duid/iaid combination diff --git a/src/bin/lfc/tests/lfc_controller_unittests.cc b/src/bin/lfc/tests/lfc_controller_unittests.cc index 15472cbdda..026d3e9355 100644 --- a/src/bin/lfc/tests/lfc_controller_unittests.cc +++ b/src/bin/lfc/tests/lfc_controller_unittests.cc @@ -320,7 +320,6 @@ TEST_F(LFCControllerTest, fileRotate) { EXPECT_TRUE(noExistIOF()); removeTestFile(); - // Test 3: Create a file for previous and finish but not copy. writeFile(xstr_, "4"); writeFile(fstr_, "6"); @@ -332,7 +331,6 @@ TEST_F(LFCControllerTest, fileRotate) { EXPECT_TRUE(noExistIOF()); removeTestFile(); - // Test 4: Create a file for copy and finish but not previous. writeFile(istr_, "8"); writeFile(fstr_, "9"); @@ -344,7 +342,6 @@ TEST_F(LFCControllerTest, fileRotate) { EXPECT_TRUE(noExistIOF()); removeTestFile(); - // Test 5: rerun test 2 but using launch instead of cleanup // as we already have a finish file we shouldn't do any extra // processing @@ -442,7 +439,6 @@ TEST_F(LFCControllerTest, launch4) { EXPECT_TRUE(noExistIOFP()); removeTestFile(); - // Subtest 2: only previous available // Create the test previous file test_str = v4_hdr_ + a_1 + b_1 + c_1 + b_2 + a_2 + d_1; @@ -461,7 +457,6 @@ TEST_F(LFCControllerTest, launch4) { EXPECT_TRUE(noExistIOFP()); removeTestFile(); - // Subtest 3: only copy available // No previous file @@ -480,7 +475,6 @@ TEST_F(LFCControllerTest, launch4) { EXPECT_TRUE(noExistIOFP()); removeTestFile(); - // Subtest 4: neither available // No previous file @@ -496,7 +490,6 @@ TEST_F(LFCControllerTest, launch4) { EXPECT_TRUE(noExistIOFP()); removeTestFile(); - // Subtest 5: a file with a lot of errors // A previous file with a lot of errors astr = "1,\n2,\n3,\n4,\n5,\n6,\n7,\n7,\n8,\n9,\n10,\n"; @@ -579,7 +572,20 @@ TEST_F(LFCControllerTest, launch6) { string d_1 = "2001:db8:1::3,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f," "200,600,8,100,0,7,0,1,1,host.example.com,,1,,,,0\n"; - // Subtest 1: bot previous and copy available + // new files have 128 prefixlen for non PD type + string a_3_n = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f," + "200,400,8,100,0,7,128,1,1,host.example.com,,1,,,,0\n"; + + string b_2_n = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05," + "300,800,6,150,0,8,128,0,0,,,1,,,,0\n"; + + string b_3_n = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05," + "300,1000,6,150,0,8,128,0,0,,,1,,,,0\n"; + + string d_1_n = "2001:db8:1::3,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f," + "200,600,8,100,0,7,128,1,1,host.example.com,,1,,,,0\n"; + + // Subtest 1: both previous and copy available // Create the test previous file test_str = v6_hdr_ + a_1 + b_1 + a_2 + c_1 + a_3 + b_2; writeFile(xstr_, test_str); @@ -594,12 +600,11 @@ TEST_F(LFCControllerTest, launch6) { // Compare the results, we expect the last lease for each ip // except for A which has expired. // We also verify none of the temp or pid files remain. - test_str = v6_hdr_ + d_1 + b_3 + c_2; + test_str = v6_hdr_ + d_1_n + b_3_n + c_2; EXPECT_EQ(readFile(xstr_), test_str); EXPECT_TRUE(noExistIOFP()); removeTestFile(); - // Subtest 2: only previous available // Create the test previous file test_str = v6_hdr_ + a_1 + b_1 + a_2 + c_1 + a_3 + b_2; @@ -612,12 +617,11 @@ TEST_F(LFCControllerTest, launch6) { // Compare the results, we expect the last lease for each ip. // We also verify none of the temp or pid files remain. - test_str = v6_hdr_ + a_3 + b_2 + c_1; + test_str = v6_hdr_ + a_3_n + b_2_n + c_1; EXPECT_EQ(readFile(xstr_), test_str); EXPECT_TRUE(noExistIOFP()); removeTestFile(); - // Subtest 3: only copy available // No previous file @@ -630,12 +634,11 @@ TEST_F(LFCControllerTest, launch6) { // Compare the results, we expect the last lease for each ip. // We also verify none of the temp or pid files remain. - test_str = v6_hdr_ + d_1 + b_3 + c_2; + test_str = v6_hdr_ + d_1_n + b_3_n + c_2; EXPECT_EQ(readFile(xstr_), test_str); EXPECT_TRUE(noExistIOFP()); removeTestFile(); - // Subtest 4: neither available // No previous file @@ -651,7 +654,6 @@ TEST_F(LFCControllerTest, launch6) { EXPECT_TRUE(noExistIOFP()); removeTestFile(); - // Subtest 5: a file with a lot of errors // A previous file with a lot of errors. astr = "1,\n2,\n3,\n4,\n5,\n6,\n7,\n7,\n8,\n9,\n10,\n"; diff --git a/src/lib/dhcpsrv/csv_lease_file6.cc b/src/lib/dhcpsrv/csv_lease_file6.cc index 0098efc73b..22608cb7ef 100644 --- a/src/lib/dhcpsrv/csv_lease_file6.cc +++ b/src/lib/dhcpsrv/csv_lease_file6.cc @@ -101,12 +101,18 @@ CSVLeaseFile6::next(Lease6Ptr& lease) { return (true); } - lease.reset(new Lease6(readType(row), readAddress(row), readDUID(row), + Lease::Type type = readType(row); + uint8_t prefixlen = 128; + if (type == Lease::TYPE_PD) { + prefixlen = readPrefixLen(row); + } + + lease.reset(new Lease6(type, readAddress(row), readDUID(row), readIAID(row), readPreferred(row), readValid(row), readSubnetID(row), readHWAddr(row), - readPrefixLen(row))); + prefixlen)); lease->cltt_ = readCltt(row); lease->fqdn_fwd_ = readFqdnFwd(row); diff --git a/src/lib/dhcpsrv/lease.cc b/src/lib/dhcpsrv/lease.cc index b8bf3531d2..61c9cc8bd8 100644 --- a/src/lib/dhcpsrv/lease.cc +++ b/src/lib/dhcpsrv/lease.cc @@ -6,6 +6,8 @@ #include +#include +#include #include #include #include @@ -14,6 +16,7 @@ #include #include +using namespace isc::asiolink; using namespace isc::util; using namespace isc::data; using namespace std; @@ -452,7 +455,18 @@ Lease6::Lease6(Lease::Type type, const isc::asiolink::IOAddress& addr, preferred_lft_(preferred), reuseable_preferred_lft_(0), extended_info_action_(ExtendedInfoAction::ACTION_IGNORE) { if (!duid) { - isc_throw(InvalidOperation, "DUID is mandatory for an IPv6 lease"); + isc_throw(BadValue, "DUID is mandatory for an IPv6 lease"); + } + + if (type != Lease::TYPE_PD && prefixlen != 128) { + isc_throw(BadValue, "prefixlen must be 128 for non prefix type"); + } + + IOAddress first_address = firstAddrInPrefix(addr, prefixlen); + if (first_address != addr) { + isc_throw(BadValue, "Invalid Lease address boundaries: " << addr + << " is not the first address in prefix: " << first_address + << "/" << static_cast(prefixlen)); } cltt_ = time(NULL); @@ -471,7 +485,18 @@ Lease6::Lease6(Lease::Type type, const isc::asiolink::IOAddress& addr, extended_info_action_(ExtendedInfoAction::ACTION_IGNORE) { if (!duid) { - isc_throw(InvalidOperation, "DUID is mandatory for an IPv6 lease"); + isc_throw(BadValue, "DUID is mandatory for an IPv6 lease"); + } + + if (type != Lease::TYPE_PD && prefixlen != 128) { + isc_throw(BadValue, "prefixlen must be 128 for non prefix type"); + } + + IOAddress first_address = firstAddrInPrefix(addr, prefixlen); + if (first_address != addr) { + isc_throw(BadValue, "Invalid Lease address boundaries: " << addr + << " is not the first address in prefix: " << first_address + << "/" << static_cast(prefixlen)); } cltt_ = time(NULL); diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.cc b/src/lib/dhcpsrv/mysql_lease_mgr.cc index f1fb82d4b1..a9f0f15970 100644 --- a/src/lib/dhcpsrv/mysql_lease_mgr.cc +++ b/src/lib/dhcpsrv/mysql_lease_mgr.cc @@ -1669,6 +1669,10 @@ public: << "allowed."); } + if (type != Lease::TYPE_PD) { + prefix_len_ = 128; + } + // Set up DUID, DuidPtr duid_ptr(new DUID(duid_buffer_, duid_length_)); diff --git a/src/lib/dhcpsrv/pgsql_lease_mgr.cc b/src/lib/dhcpsrv/pgsql_lease_mgr.cc index 65e30b2edb..6ee99d6745 100644 --- a/src/lib/dhcpsrv/pgsql_lease_mgr.cc +++ b/src/lib/dhcpsrv/pgsql_lease_mgr.cc @@ -1173,6 +1173,10 @@ public: getColumnValue(r, row, POOL_ID_COL, pool_id_); + if (lease_type_ != Lease::TYPE_PD) { + prefix_len_ = 128; + } + Lease6Ptr result(boost::make_shared(lease_type_, addr, duid_ptr, iaid_u_.uval_, diff --git a/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc index 6b1789cf38..327a036861 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc @@ -928,8 +928,7 @@ class SharedNetworkAlloc4Test : public AllocEngine4Test { public: /// @brief Initializes configuration (2 subnets, 1 shared network) - SharedNetworkAlloc4Test() - :engine_(0) { + SharedNetworkAlloc4Test() : engine_(0) { // Create two subnets, each with a single address pool. The first subnet // has only one address in its address pool to make it easier to simulate // address exhaustion. diff --git a/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc index 23bd77d087..68a0fd4848 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc +++ b/src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc @@ -352,8 +352,7 @@ TEST_F(AllocEngine6Test, outOfAddresses6) { DuidPtr other_duid = DuidPtr(new DUID(vector(12, 0xff))); const uint32_t other_iaid = 3568; Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, other_duid, other_iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = time(NULL) - 10; // Allocated 10 seconds ago ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); @@ -409,8 +408,7 @@ TEST_F(AllocEngine6Test, solicitReuseExpiredLease6) { DuidPtr other_duid = DuidPtr(new DUID(vector(12, 0xff))); const uint32_t other_iaid = 3568; Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, other_duid, other_iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = time(NULL) - 500; // Allocated 500 seconds ago lease->valid_lft_ = 495; // Lease was valid for 495 seconds ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); @@ -473,8 +471,7 @@ TEST_F(AllocEngine6Test, defaultReuseExpiredLease6) { DuidPtr other_duid = DuidPtr(new DUID(vector(12, 0xff))); const uint32_t other_iaid = 3568; Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, other_duid, other_iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = time(NULL) - 500; // Allocated 500 seconds ago lease->valid_lft_ = 495; // Lease was valid for 495 seconds ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); @@ -519,8 +516,7 @@ TEST_F(AllocEngine6Test, hintReuseExpiredLease6) { DuidPtr other_duid = DuidPtr(new DUID(vector(12, 0xff))); const uint32_t other_iaid = 3568; Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, other_duid, other_iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = time(NULL) - 500; // Allocated 500 seconds ago lease->valid_lft_ = 495; // Lease was valid for 495 seconds ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); @@ -565,8 +561,7 @@ TEST_F(AllocEngine6Test, minReuseExpiredLease6) { DuidPtr other_duid = DuidPtr(new DUID(vector(12, 0xff))); const uint32_t other_iaid = 3568; Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, other_duid, other_iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = time(NULL) - 500; // Allocated 500 seconds ago lease->valid_lft_ = 495; // Lease was valid for 495 seconds ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); @@ -611,8 +606,7 @@ TEST_F(AllocEngine6Test, maxReuseExpiredLease6) { DuidPtr other_duid = DuidPtr(new DUID(vector(12, 0xff))); const uint32_t other_iaid = 3568; Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, other_duid, other_iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = time(NULL) - 500; // Allocated 500 seconds ago lease->valid_lft_ = 495; // Lease was valid for 495 seconds ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); @@ -666,8 +660,7 @@ TEST_F(AllocEngine6Test, classReuseExpiredLease6) { DuidPtr other_duid = DuidPtr(new DUID(vector(12, 0xff))); const uint32_t other_iaid = 3568; Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, other_duid, other_iaid, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = time(NULL) - 500; // Allocated 500 seconds ago lease->valid_lft_ = 495; // Lease was valid for 495 seconds ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); @@ -722,8 +715,7 @@ TEST_F(AllocEngine6Test, requestReuseExpiredLease6) { const SubnetID other_subnetid = 999; Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, other_duid, other_iaid, - 501, 502, other_subnetid, HWAddrPtr(), - 0)); + 501, 502, other_subnetid, HWAddrPtr())); int64_t other_cumulative = getStatistics("cumulative-assigned-nas", other_subnetid); @@ -790,7 +782,7 @@ TEST_F(AllocEngine6Test, requestExtendLeaseLifetime) { // Create a lease for the client. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::15"), duid_, iaid_, 300, 400, - subnet_->getID(), HWAddrPtr(), 128)); + subnet_->getID(), HWAddrPtr())); // Allocated 200 seconds ago - half of the lifetime. time_t lease_cltt = time(NULL) - 200; @@ -817,7 +809,7 @@ TEST_F(AllocEngine6Test, requestExtendLeaseLifetimeForReservation) { // Create a lease for the client. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1c"), duid_, iaid_, 300, 400, - subnet_->getID(), HWAddrPtr(), 128)); + subnet_->getID(), HWAddrPtr())); // Allocated 200 seconds ago - half of the lifetime. time_t lease_cltt = time(NULL) - 200; @@ -840,7 +832,7 @@ TEST_F(AllocEngine6Test, renewExtendLeaseLifetime) { // Create a lease for the client. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::15"), duid_, iaid_, 300, 400, - subnet_->getID(), HWAddrPtr(), 128)); + subnet_->getID(), HWAddrPtr())); // Allocated 200 seconds ago - half of the lifetime. time_t lease_cltt = time(NULL) - 200; @@ -868,7 +860,7 @@ TEST_F(AllocEngine6Test, defaultRenewLeaseLifetime) { // Create a lease for the client. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::15"), duid_, iaid_, 300, 400, - subnet_->getID(), HWAddrPtr(), 128)); + subnet_->getID(), HWAddrPtr())); // Allocated 200 seconds ago - half of the lifetime. time_t lease_cltt = time(NULL) - 200; @@ -903,7 +895,7 @@ TEST_F(AllocEngine6Test, hintRenewLeaseLifetime) { // Create a lease for the client. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::15"), duid_, iaid_, 300, 400, - subnet_->getID(), HWAddrPtr(), 128)); + subnet_->getID(), HWAddrPtr())); // Allocated 200 seconds ago - half of the lifetime. time_t lease_cltt = time(NULL) - 200; @@ -938,7 +930,7 @@ TEST_F(AllocEngine6Test, minRenewLeaseLifetime) { // Create a lease for the client. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::15"), duid_, iaid_, 300, 400, - subnet_->getID(), HWAddrPtr(), 128)); + subnet_->getID(), HWAddrPtr())); // Allocated 200 seconds ago - half of the lifetime. time_t lease_cltt = time(NULL) - 200; @@ -973,7 +965,7 @@ TEST_F(AllocEngine6Test, maxRenewLeaseLifetime) { // Create a lease for the client. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::15"), duid_, iaid_, 300, 400, - subnet_->getID(), HWAddrPtr(), 128)); + subnet_->getID(), HWAddrPtr())); // Allocated 200 seconds ago - half of the lifetime. time_t lease_cltt = time(NULL) - 200; @@ -1009,7 +1001,7 @@ TEST_F(AllocEngine6Test, renewClassLeaseLifetime) { // Create a lease for the client. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::15"), duid_, iaid_, 300, 400, - subnet_->getID(), HWAddrPtr(), 128)); + subnet_->getID(), HWAddrPtr())); // Allocated 200 seconds ago - half of the lifetime. time_t lease_cltt = time(NULL) - 200; lease->cltt_ = lease_cltt; @@ -1063,7 +1055,7 @@ TEST_F(AllocEngine6Test, renewExtendLeaseLifetimeForReservation) { // Create a lease for the client. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::15"), duid_, iaid_, 300, 400, - subnet_->getID(), HWAddrPtr(), 128)); + subnet_->getID(), HWAddrPtr())); // Allocated 200 seconds ago - half of the lifetime. time_t lease_cltt = time(NULL) - 200; @@ -2434,8 +2426,7 @@ TEST_F(AllocEngine6Test, largeAllocationAttemptsOverride) { // Allocate the lease. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress(address.str()), - duid, iaid, 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + duid, iaid, 501, 502, subnet_->getID(), HWAddrPtr())); ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); } @@ -2663,8 +2654,7 @@ TEST_F(AllocEngine6Test, reuseReclaimedExpiredViaRequest) { // Let's create an expired lease Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid_, iaid_, - 501, 502, subnet_->getID(), HWAddrPtr(), - 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = time(NULL) - 500; // Allocated 500 seconds ago lease->valid_lft_ = 495; // Lease was valid for 495 seconds lease->fqdn_fwd_ = true; @@ -2717,9 +2707,7 @@ TEST_F(AllocEngine6Test, reuseReclaimedExpiredViaRequest) { /// - 2001:db8:1::/56 subnet with pool with 64K addresses. class SharedNetworkAlloc6Test : public AllocEngine6Test { public: - SharedNetworkAlloc6Test() - :engine_(0) { - + SharedNetworkAlloc6Test() : engine_(0) { subnet1_ = Subnet6::create(IOAddress("2001:db8:1::"), 56, 1, 2, 3, 4, SubnetID(10)); subnet2_ = Subnet6::create(IOAddress("2001:db8:2::"), 56, 1, 2, 3, 4, SubnetID(20)); pool1_.reset(new Pool6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"), @@ -2739,8 +2727,7 @@ public: Lease6Ptr insertLease(std::string addr, SubnetID subnet_id) { Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress(addr), duid_, iaid_, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = time(NULL) - 10; // Allocated 10 seconds ago if (!LeaseMgrFactory::instance().addLease(lease)) { ADD_FAILURE() << "Failed to add a lease for address " << addr @@ -2812,8 +2799,7 @@ TEST_F(SharedNetworkAlloc6Test, solicitSharedNetworkOutOfAddresses) { const uint32_t other_iaid = 3568; Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1"), other_duid, other_iaid, 501, 502, - subnet1_->getID(), - HWAddrPtr(), 0)); + subnet1_->getID(), HWAddrPtr())); lease->cltt_ = time(NULL) - 10; // Allocated 10 seconds ago ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); @@ -3103,7 +3089,7 @@ TEST_F(SharedNetworkAlloc6Test, requestSharedNetworkExistingLeases) { // gets renewed. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, IOAddress("2001:db8:2::1"), duid_, iaid_, 501, 502, - subnet2_->getID(), HWAddrPtr(), 128)); + subnet2_->getID(), HWAddrPtr())); lease->state_ = Lease::STATE_EXPIRED_RECLAIMED; ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); @@ -4487,8 +4473,7 @@ TEST_F(AllocEngine6ExtendedInfoTest, reuseExpiredLease6) { // Create an expired lease for duid1_. Lease6Ptr lease(new Lease6(Lease::TYPE_NA, addr, duid1_, 1234, - 501, 502, subnet_->getID(), - HWAddrPtr(), 0)); + 501, 502, subnet_->getID(), HWAddrPtr())); lease->cltt_ = time(NULL) - 500; // Allocated 500 seconds ago lease->valid_lft_ = 495; // Lease was valid for 495 seconds ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); diff --git a/src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc b/src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc index c907c301ee..227f960c1b 100644 --- a/src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc +++ b/src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc @@ -154,7 +154,7 @@ TEST_F(CSVLeaseFile6Test, parse) { EXPECT_EQ(100, lease->preferred_lft_); EXPECT_EQ(Lease::TYPE_NA, lease->type_); EXPECT_EQ(7, lease->iaid_); - EXPECT_EQ(0, lease->prefixlen_); + EXPECT_EQ(128, lease->prefixlen_); EXPECT_TRUE(lease->fqdn_fwd_); EXPECT_TRUE(lease->fqdn_rev_); EXPECT_EQ("host.example.com", lease->hostname_); @@ -187,7 +187,7 @@ TEST_F(CSVLeaseFile6Test, parse) { EXPECT_EQ(150, lease->preferred_lft_); EXPECT_EQ(Lease::TYPE_NA, lease->type_); EXPECT_EQ(8, lease->iaid_); - EXPECT_EQ(0, lease->prefixlen_); + EXPECT_EQ(128, lease->prefixlen_); EXPECT_FALSE(lease->fqdn_fwd_); EXPECT_FALSE(lease->fqdn_rev_); EXPECT_TRUE(lease->hostname_.empty()); @@ -382,7 +382,7 @@ TEST_F(CSVLeaseFile6Test, mixedSchemaLoad) { EXPECT_EQ(100, lease->preferred_lft_); EXPECT_EQ(Lease::TYPE_NA, lease->type_); EXPECT_EQ(7, lease->iaid_); - EXPECT_EQ(0, lease->prefixlen_); + EXPECT_EQ(128, lease->prefixlen_); EXPECT_TRUE(lease->fqdn_fwd_); EXPECT_TRUE(lease->fqdn_rev_); EXPECT_EQ("one.example.com", lease->hostname_); @@ -408,7 +408,7 @@ TEST_F(CSVLeaseFile6Test, mixedSchemaLoad) { EXPECT_EQ(100, lease->preferred_lft_); EXPECT_EQ(Lease::TYPE_NA, lease->type_); EXPECT_EQ(7, lease->iaid_); - EXPECT_EQ(0, lease->prefixlen_); + EXPECT_EQ(128, lease->prefixlen_); EXPECT_TRUE(lease->fqdn_fwd_); EXPECT_TRUE(lease->fqdn_rev_); EXPECT_EQ("two.example.com", lease->hostname_); @@ -434,7 +434,7 @@ TEST_F(CSVLeaseFile6Test, mixedSchemaLoad) { EXPECT_EQ(100, lease->preferred_lft_); EXPECT_EQ(Lease::TYPE_NA, lease->type_); EXPECT_EQ(7, lease->iaid_); - EXPECT_EQ(0, lease->prefixlen_); + EXPECT_EQ(128, lease->prefixlen_); EXPECT_TRUE(lease->fqdn_fwd_); EXPECT_TRUE(lease->fqdn_rev_); EXPECT_EQ("three.example.com", lease->hostname_); @@ -459,7 +459,7 @@ TEST_F(CSVLeaseFile6Test, mixedSchemaLoad) { EXPECT_EQ(100, lease->preferred_lft_); EXPECT_EQ(Lease::TYPE_NA, lease->type_); EXPECT_EQ(7, lease->iaid_); - EXPECT_EQ(0, lease->prefixlen_); + EXPECT_EQ(128, lease->prefixlen_); EXPECT_TRUE(lease->fqdn_fwd_); EXPECT_TRUE(lease->fqdn_rev_); EXPECT_EQ("three.example.com", lease->hostname_); @@ -533,7 +533,7 @@ TEST_F(CSVLeaseFile6Test, downGrade) { EXPECT_EQ(100, lease->preferred_lft_); EXPECT_EQ(Lease::TYPE_NA, lease->type_); EXPECT_EQ(7, lease->iaid_); - EXPECT_EQ(0, lease->prefixlen_); + EXPECT_EQ(128, lease->prefixlen_); EXPECT_TRUE(lease->fqdn_fwd_); EXPECT_TRUE(lease->fqdn_rev_); EXPECT_EQ("three.example.com", lease->hostname_); diff --git a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc index c5d22c26f6..458fc95223 100644 --- a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc @@ -51,8 +51,8 @@ const char* ADDRESS4[] = { NULL }; const char* ADDRESS6[] = { - "2001:db8::0", "2001:db8::1", "2001:db8::2", "2001:db8::3", - "2001:db8::4", "2001:db8::5", "2001:db8::6", "2001:db8::7", + "2001:db8::", "2001:db8:1::", "2001:db8:2::", "2001:db8:3::", + "2001:db8:4::", "2001:db8:5::", "2001:db8:6::", "2001:db8:7::", NULL }; @@ -230,7 +230,7 @@ GenericLeaseMgrTest::initializeLease6(std::string address) { // Set other parameters. For historical reasons, address 0 is not used. if (address == straddress6_[0]) { lease->type_ = leasetype6_[0]; - lease->prefixlen_ = 4; + lease->prefixlen_ = 128; lease->iaid_ = 142; lease->duid_ = DuidPtr(new DUID(vector(8, 0x77))); lease->preferred_lft_ = 900; @@ -244,7 +244,7 @@ GenericLeaseMgrTest::initializeLease6(std::string address) { } else if (address == straddress6_[1]) { lease->type_ = leasetype6_[1]; - lease->prefixlen_ = 0; + lease->prefixlen_ = 128; lease->iaid_ = 42; lease->duid_ = DuidPtr(new DUID(vector(8, 0x42))); lease->preferred_lft_ = 3600; @@ -259,7 +259,7 @@ GenericLeaseMgrTest::initializeLease6(std::string address) { } else if (address == straddress6_[2]) { lease->type_ = leasetype6_[2]; - lease->prefixlen_ = 7; + lease->prefixlen_ = 48; lease->iaid_ = 89; lease->duid_ = DuidPtr(new DUID(vector(8, 0x3a))); lease->preferred_lft_ = 1800; @@ -273,7 +273,7 @@ GenericLeaseMgrTest::initializeLease6(std::string address) { } else if (address == straddress6_[3]) { lease->type_ = leasetype6_[3]; - lease->prefixlen_ = 28; + lease->prefixlen_ = 128; lease->iaid_ = 0xfffffffe; vector duid; for (uint8_t i = 31; i < 126; ++i) { @@ -297,7 +297,7 @@ GenericLeaseMgrTest::initializeLease6(std::string address) { } else if (address == straddress6_[4]) { // Same DUID and IAID as straddress6_1 lease->type_ = leasetype6_[4]; - lease->prefixlen_ = 15; + lease->prefixlen_ = 128; lease->iaid_ = 42; lease->duid_ = DuidPtr(new DUID(vector(8, 0x42))); lease->preferred_lft_ = 4800; @@ -312,7 +312,7 @@ GenericLeaseMgrTest::initializeLease6(std::string address) { } else if (address == straddress6_[5]) { // Same DUID and IAID as straddress6_1 lease->type_ = leasetype6_[5]; - lease->prefixlen_ = 24; + lease->prefixlen_ = 56; lease->iaid_ = 42; // Same as lease 4 lease->duid_ = DuidPtr(new DUID(vector(8, 0x42))); // Same as lease 4 @@ -329,7 +329,7 @@ GenericLeaseMgrTest::initializeLease6(std::string address) { } else if (address == straddress6_[6]) { // Same DUID as straddress6_1 lease->type_ = leasetype6_[6]; - lease->prefixlen_ = 24; + lease->prefixlen_ = 128; lease->iaid_ = 93; lease->duid_ = DuidPtr(new DUID(vector(8, 0x42))); // Same as lease 4 @@ -345,7 +345,7 @@ GenericLeaseMgrTest::initializeLease6(std::string address) { } else if (address == straddress6_[7]) { // Same IAID as straddress6_1 lease->type_ = leasetype6_[7]; - lease->prefixlen_ = 24; + lease->prefixlen_ = 128; lease->iaid_ = 42; lease->duid_ = DuidPtr(new DUID(vector(8, 0xe5))); lease->preferred_lft_ = 5600; @@ -1579,19 +1579,24 @@ GenericLeaseMgrTest::testLease6LeaseTypeCheck() { empty_lease->fqdn_fwd_ = true; empty_lease->fqdn_rev_ = true; empty_lease->hostname_ = "myhost.example.com."; - empty_lease->prefixlen_ = 4; + empty_lease->prefixlen_ = 128; - // Make Two leases per lease type, all with the same DUID, IAID but + // Make Two leases per lease type, all with the same DUID, IAID but // alternate the subnet_ids. vector leases; for (int i = 0; i < 6; ++i) { - Lease6Ptr lease(new Lease6(*empty_lease)); - lease->type_ = leasetype6_[i / 2]; - lease->addr_ = IOAddress(straddress6_[i]); - lease->subnet_id_ += (i % 2); - leases.push_back(lease); - EXPECT_TRUE(lmptr_->addLease(lease)); - } + if (i > 3) { + empty_lease->prefixlen_ = 48; + } else { + empty_lease->prefixlen_ = 128; + } + Lease6Ptr lease(new Lease6(*empty_lease)); + lease->type_ = leasetype6_[i / 2]; + lease->addr_ = IOAddress(straddress6_[(i / 2) + (i % 2) * 3]); + lease->subnet_id_ += (i % 2); + leases.push_back(lease); + EXPECT_TRUE(lmptr_->addLease(lease)); + } // Verify getting a single lease by type and address. for (int i = 0; i < 6; ++i) { @@ -1611,8 +1616,13 @@ GenericLeaseMgrTest::testLease6LeaseTypeCheck() { // Iterate over the lease types, asking for leases based on // lease type, DUID, and IAID. for (int i = 0; i < 3; ++i) { - Lease6Collection returned = lmptr_->getLeases6(leasetype6_[i], - *duid, 142); + Lease6Collection returned = lmptr_->getLeases6(leasetype6_[i], *duid, 142); + + auto compare = [](Lease6Ptr& left, Lease6Ptr& right) { + return (left->addr_ < right->addr_); + }; + std::sort(returned.begin(), returned.end(), compare); + // We should match two per lease type. ASSERT_EQ(2, returned.size()); @@ -1623,7 +1633,11 @@ GenericLeaseMgrTest::testLease6LeaseTypeCheck() { it != returned.end(); ++it) { addresses.push_back((*it)->addr_.toText()); } - sort(addresses.begin(), addresses.end()); + + auto compare_addr = [](const string& left, const string& right) { + return (IOAddress(left) < IOAddress(right)); + }; + sort(addresses.begin(), addresses.end(), compare_addr); // Now verify that the lease addresses match. EXPECT_EQ(addresses[0], leases[(i * 2)]->addr_.toText()); @@ -1634,8 +1648,7 @@ GenericLeaseMgrTest::testLease6LeaseTypeCheck() { // Iterate over the lease types, asking for leases based on // lease type, DUID, IAID, and subnet_id. for (int i = 0; i < 3; ++i) { - Lease6Collection returned = lmptr_->getLeases6(leasetype6_[i], - *duid, 142, 23); + Lease6Collection returned = lmptr_->getLeases6(leasetype6_[i], *duid, 142, 23); // We should match one per lease type. ASSERT_EQ(1, returned.size()); EXPECT_TRUE(*(returned[0]) == *leases[i * 2]); @@ -1643,8 +1656,7 @@ GenericLeaseMgrTest::testLease6LeaseTypeCheck() { // Verify getting a single lease by type, duid, iad, and subnet id. for (int i = 0; i < 6; ++i) { - Lease6Ptr returned = lmptr_->getLease6(leasetype6_[i / 2], - *duid, 142, (23 + (i % 2))); + Lease6Ptr returned = lmptr_->getLease6(leasetype6_[i / 2], *duid, 142, (23 + (i % 2))); // We should match one per lease type. ASSERT_TRUE(returned); EXPECT_TRUE(*returned == *leases[i]); @@ -1722,9 +1734,9 @@ GenericLeaseMgrTest::testGetLease6DuidIaidSubnetId() { void GenericLeaseMgrTest::testGetLeases6Duid() { //add leases - IOAddress addr1(std::string("2001:db8:1::111")); - IOAddress addr2(std::string("2001:db8:1::222")); - IOAddress addr3(std::string("2001:db8:1::333")); + IOAddress addr1(std::string("2001:db8:1::")); + IOAddress addr2(std::string("2001:db8:2::")); + IOAddress addr3(std::string("2001:db8:3::")); DuidPtr duid1(new DUID({0, 1, 1, 1, 1, 1, 1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf})); DuidPtr duid2(new DUID({0, 2, 2, 2, 2, 2, 2, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf})); @@ -1914,6 +1926,7 @@ GenericLeaseMgrTest::testUpdateLease6() { // Modify some fields in lease 1 (not the address) and update it. ++leases[1]->iaid_; leases[1]->type_ = Lease::TYPE_PD; + leases[1]->prefixlen_ = 93; leases[1]->valid_lft_ *= 2; leases[1]->hostname_ = "modified.hostname.v6."; leases[1]->fqdn_fwd_ = !leases[1]->fqdn_fwd_; @@ -1931,7 +1944,7 @@ GenericLeaseMgrTest::testUpdateLease6() { ++leases[1]->iaid_; leases[1]->type_ = Lease::TYPE_TA; leases[1]->cltt_ += 6; - leases[1]->prefixlen_ = 93; + leases[1]->prefixlen_ = 128; leases[1]->setContext(Element::fromJSON("{ \"foo\": \"bar\" }")); lmptr_->updateLease6(leases[1]); @@ -3189,20 +3202,20 @@ GenericLeaseMgrTest::testRecountLeaseStats6() { subnet_id = 1; // Insert three assigned NAs. - makeLease6(Lease::TYPE_NA, "3001:1::1", 0, subnet_id); - Lease6Ptr lease2 = makeLease6(Lease::TYPE_NA, "3001:1::2", 0, subnet_id); - makeLease6(Lease::TYPE_NA, "3001:1::3", 0, subnet_id); + makeLease6(Lease::TYPE_NA, "3001:1::1", 128, subnet_id); + Lease6Ptr lease2 = makeLease6(Lease::TYPE_NA, "3001:1::2", 128, subnet_id); + makeLease6(Lease::TYPE_NA, "3001:1::3", 128, subnet_id); expectedStats[subnet_id - 1]["assigned-nas"] = 5; // 3 + 2 declined // Insert two declined NAs. - makeLease6(Lease::TYPE_NA, "3001:1::4", 0, subnet_id, + makeLease6(Lease::TYPE_NA, "3001:1::4", 128, subnet_id, Lease::STATE_DECLINED); - makeLease6(Lease::TYPE_NA, "3001:1::5", 0, subnet_id, + makeLease6(Lease::TYPE_NA, "3001:1::5", 128, subnet_id, Lease::STATE_DECLINED); expectedStats[subnet_id - 1]["declined-addresses"] = 2; // Insert one expired NA. - makeLease6(Lease::TYPE_NA, "3001:1::6", 0, subnet_id, + makeLease6(Lease::TYPE_NA, "3001:1::6", 128, subnet_id, Lease::STATE_EXPIRED_RECLAIMED); // Insert two assigned PDs. @@ -3220,12 +3233,12 @@ GenericLeaseMgrTest::testRecountLeaseStats6() { subnet_id = 2; // Insert two assigned NAs. - makeLease6(Lease::TYPE_NA, "2001:db81::1", 0, subnet_id); - makeLease6(Lease::TYPE_NA, "2001:db81::2", 0, subnet_id); + makeLease6(Lease::TYPE_NA, "2001:db81::1", 128, subnet_id); + makeLease6(Lease::TYPE_NA, "2001:db81::2", 128, subnet_id); expectedStats[subnet_id - 1]["assigned-nas"] = 3; // 2 + 1 declined // Insert one declined NA. - Lease6Ptr lease3 = makeLease6(Lease::TYPE_NA, "2001:db81::3", 0, subnet_id, + Lease6Ptr lease3 = makeLease6(Lease::TYPE_NA, "2001:db81::3", 128, subnet_id, Lease::STATE_DECLINED); expectedStats[subnet_id - 1]["declined-addresses"] = 1; @@ -3819,14 +3832,14 @@ GenericLeaseMgrTest::testLeaseStatsQuery6() { // Two assigned PDs. // Two expired PDs. subnet_id = 1; - makeLease6(Lease::TYPE_NA, "3001:1::1", 0, subnet_id); - makeLease6(Lease::TYPE_NA, "3001:1::2", 0, subnet_id); - makeLease6(Lease::TYPE_NA, "3001:1::3", 0, subnet_id); - makeLease6(Lease::TYPE_NA, "3001:1::4", 0, subnet_id, + makeLease6(Lease::TYPE_NA, "3001:1::1", 128, subnet_id); + makeLease6(Lease::TYPE_NA, "3001:1::2", 128, subnet_id); + makeLease6(Lease::TYPE_NA, "3001:1::3", 128, subnet_id); + makeLease6(Lease::TYPE_NA, "3001:1::4", 128, subnet_id, Lease::STATE_DECLINED); - makeLease6(Lease::TYPE_NA, "3001:1::5", 0, subnet_id, + makeLease6(Lease::TYPE_NA, "3001:1::5", 128, subnet_id, Lease::STATE_DECLINED); - makeLease6(Lease::TYPE_NA, "3001:1::6", 0, subnet_id, + makeLease6(Lease::TYPE_NA, "3001:1::6", 128, subnet_id, Lease::STATE_EXPIRED_RECLAIMED); makeLease6(Lease::TYPE_PD, "3001:1:2:0100::", 112, subnet_id); makeLease6(Lease::TYPE_PD, "3001:1:2:0200::", 112, subnet_id); @@ -3839,18 +3852,18 @@ GenericLeaseMgrTest::testLeaseStatsQuery6() { // Two assigned NAs // One declined NAs subnet_id = 2; - makeLease6(Lease::TYPE_NA, "2001:db81::1", 0, subnet_id); - makeLease6(Lease::TYPE_NA, "2001:db81::2", 0, subnet_id); - makeLease6(Lease::TYPE_NA, "2001:db81::3", 0, subnet_id, + makeLease6(Lease::TYPE_NA, "2001:db81::1", 128, subnet_id); + makeLease6(Lease::TYPE_NA, "2001:db81::2", 128, subnet_id); + makeLease6(Lease::TYPE_NA, "2001:db81::3", 128, subnet_id, Lease::STATE_DECLINED); // Now let's add leases to subnet 3. // Two assigned NAs // One declined NAs subnet_id = 3; - makeLease6(Lease::TYPE_NA, "2002:db81::1", 0, subnet_id); - makeLease6(Lease::TYPE_NA, "2002:db81::2", 0, subnet_id); - makeLease6(Lease::TYPE_NA, "2002:db81::3", 0, subnet_id, + makeLease6(Lease::TYPE_NA, "2002:db81::1", 128, subnet_id); + makeLease6(Lease::TYPE_NA, "2002:db81::2", 128, subnet_id); + makeLease6(Lease::TYPE_NA, "2002:db81::3", 128, subnet_id, Lease::STATE_DECLINED); // Test single subnet for non-matching subnet @@ -3971,12 +3984,12 @@ GenericLeaseMgrTest::testLeaseStatsQueryAttribution6() { // Now let's insert two leases into subnet 1. subnet_id = 1; - makeLease6(Lease::TYPE_NA, "2001:db81::1", 0, subnet_id); - Lease6Ptr lease = makeLease6(Lease::TYPE_NA, "2001:db81::2", 0, subnet_id); + makeLease6(Lease::TYPE_NA, "2001:db81::1", 128, subnet_id); + Lease6Ptr lease = makeLease6(Lease::TYPE_NA, "2001:db81::2", 128, subnet_id); // And one lease into subnet 2. subnet_id = 2; - makeLease6(Lease::TYPE_NA, "2001:db81::3", 0, subnet_id); + makeLease6(Lease::TYPE_NA, "2001:db81::3", 128, subnet_id); // Move a lease to the second subnet. lease->subnet_id_ = subnet_id; @@ -4072,7 +4085,7 @@ GenericLeaseMgrTest::testLeaseLimits6() { EXPECT_EQ(text, ""); // -- A limit of 1 with 1 current lease should deny further leases. -- - makeLease6(Lease::TYPE_NA, "2001:db8::", 0, 1, Lease::STATE_DEFAULT, Element::fromJSON( + makeLease6(Lease::TYPE_NA, "2001:db8::", 128, 1, Lease::STATE_DEFAULT, Element::fromJSON( R"({ "ISC": { "client-classes": [ "foo" ] } })")); makeLease6(Lease::TYPE_PD, "2001:db8:1::", 64, 1, Lease::STATE_DEFAULT, Element::fromJSON( diff --git a/src/lib/dhcpsrv/tests/lease_file_loader_unittest.cc b/src/lib/dhcpsrv/tests/lease_file_loader_unittest.cc index c80364417f..5cb49a71a0 100644 --- a/src/lib/dhcpsrv/tests/lease_file_loader_unittest.cc +++ b/src/lib/dhcpsrv/tests/lease_file_loader_unittest.cc @@ -424,7 +424,6 @@ TEST_F(LeaseFileLoaderTest, loadWrite4LeaseRemove) { std::string b_2 = "192.0.3.15,dd:de:ba:0d:1b:2e:3e:4f,0a:00:01:04," "100,135,7,0,0,,1,,0\n"; - // Create lease file in which one of the entries for 192.0.2.1 // has a valid_lifetime of 0 and results in the deletion of the // lease. @@ -531,6 +530,7 @@ TEST_F(LeaseFileLoaderTest, loadWrite6) { std::string a_3 = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f," "200,400,8,100,0,7,0,1,1,host.example.com,,1," "{ \"foobar\": true },,,0\n"; + std::string b_1 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05," "300,300,6,150,0,8,0,0,0,,,1,,,,0\n"; std::string b_2 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05," @@ -539,6 +539,13 @@ TEST_F(LeaseFileLoaderTest, loadWrite6) { std::string c_1 = "3000:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f," "100,200,8,0,2,16,64,0,0,,,1,,,,0\n"; + // new files have 128 prefixlen for non PD type + std::string a_3_n = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f," + "200,400,8,100,0,7,128,1,1,host.example.com,,1," + "{ \"foobar\": true },,,0\n"; + + std::string b_2_n = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05," + "300,800,6,150,0,8,128,0,0,,,1,,,,0\n"; // Create a lease file with three valid leases: 2001:db8:1::1, // 3000:1:: and 2001:db8:2::10. @@ -585,7 +592,7 @@ TEST_F(LeaseFileLoaderTest, loadWrite6) { EXPECT_EQ(500, lease->cltt_); EXPECT_FALSE(lease->getContext()); - test_str = v6_hdr_ + a_3 + b_2 + c_1; + test_str = v6_hdr_ + a_3_n + b_2_n + c_1; writeLeases(*lf, storage, test_str); // We should have made 3 attempts to write, with 3 leases written and 0 errors @@ -610,9 +617,14 @@ TEST_F(LeaseFileLoaderTest, loadWrite6LeaseRemove) { std::string b_1 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05," "300,300,6,150,0,8,0,0,0,,,1,,,,0\n"; + std::string b_2 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05," "300,800,6,150,0,8,0,0,0,,,1,,,,0\n"; + // new files have 128 prefixlen for non PD type + std::string b_2_n = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05," + "300,800,6,150,0,8,128,0,0,,,1,,,,0\n"; + // Create lease file in which one of the entries for the 2001:db8:1::1 // has valid lifetime set to 0, in which case the lease should be // deleted. @@ -640,7 +652,7 @@ TEST_F(LeaseFileLoaderTest, loadWrite6LeaseRemove) { ASSERT_TRUE(lease); EXPECT_EQ(500, lease->cltt_); - test_str = v6_hdr_ + b_2; + test_str = v6_hdr_ + b_2_n; writeLeases(*lf, storage, test_str); // We should have made 1 attempts to write, with 1 leases written and 0 errors diff --git a/src/lib/dhcpsrv/tests/lease_unittest.cc b/src/lib/dhcpsrv/tests/lease_unittest.cc index 0ed815ade4..77c99c59ca 100644 --- a/src/lib/dhcpsrv/tests/lease_unittest.cc +++ b/src/lib/dhcpsrv/tests/lease_unittest.cc @@ -177,7 +177,6 @@ TEST_F(Lease4Test, leaseBelongsToClient) { EXPECT_FALSE(lease.belongsToClient(null_hw, diff_client_id)); EXPECT_FALSE(lease.belongsToClient(null_hw, null_client_id)); - // Verify cases for lease that has only HW address. lease.client_id_ = null_client_id; EXPECT_TRUE(lease.belongsToClient(matching_hw, matching_client_id)); @@ -649,7 +648,31 @@ TEST(Lease6Test, constructorDefault) { Lease6Ptr lease2; EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_NA, addr, DuidPtr(), iaid, 100, 200, - subnet_id)), InvalidOperation); + subnet_id)), BadValue); + + EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_NA, addr, + DuidPtr(), iaid, 100, 200, + subnet_id, true, true, "", HWAddrPtr())), BadValue); + + // Lease6 must have a valid prefix and prefix length. + addr = IOAddress(ADDRESS[5]); + EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_PD, addr, + duid, iaid, 100, 200, + subnet_id, HWAddrPtr(), 16)), BadValue); + + EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_PD, addr, + duid, iaid, 100, 200, + subnet_id, true, true, "", HWAddrPtr(), 16)), BadValue); + + // Lease6 must have a prefixlen set to 128 for non prefix type. + addr = IOAddress(ADDRESS[4]); + EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_NA, addr, + duid, iaid, 100, 200, + subnet_id, HWAddrPtr(), 96)), BadValue); + + EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_NA, addr, + duid, iaid, 100, 200, + subnet_id, true, true, "", HWAddrPtr(), 96)), BadValue); } // This test verifies that the Lease6 constructor which accepts FQDN data, @@ -693,7 +716,11 @@ TEST(Lease6Test, constructorWithFQDN) { Lease6Ptr lease2; EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_NA, addr, DuidPtr(), iaid, 100, 200, - subnet_id)), InvalidOperation); + subnet_id)), BadValue); + + EXPECT_THROW(lease2.reset(new Lease6(Lease::TYPE_NA, addr, + DuidPtr(), iaid, 100, 200, + subnet_id, true, true, "", HWAddrPtr())), BadValue); } /// @brief Lease6 Equality Test diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc index 53e8b22caf..cd6e9162e1 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc @@ -698,9 +698,9 @@ TEST_F(MemfileLeaseMgrTest, leaseFileCleanup6) { // entry each. std::string result_file_contents = new_file_contents + "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,800," - "8,100,0,7,0,1,1,,,1,{ \"foo\": true },,,0\n" + "8,100,0,7,128,1,1,,,1,{ \"foo\": true },,,0\n" "2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800," - "8,100,0,7,0,1,1,,,1,,,,0\n"; + "8,100,0,7,128,1,1,,,1,,,,0\n"; // The LFC should have created a file with the two leases and moved it // to leasefile6_0.csv.2 @@ -832,7 +832,7 @@ TEST_F(MemfileLeaseMgrTest, leaseFileCopy) { // the same. std::string input_file_contents = new_file_contents + "2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800," - "8,100,0,7,0,1,1,,,1,{ \"foo\": true },,,0\n"; + "8,100,0,7,128,1,1,,,1,{ \"foo\": true },,,0\n"; LeaseFileIO input_file(getLeaseFilePath("leasefile6_0.csv.1")); input_file.writeFile(input_file_contents); @@ -1999,9 +1999,9 @@ TEST_F(MemfileLeaseMgrTest, leaseUpgrade6) { // Verify cleaned, converted contents std::string result_file_contents = header_5_0 + "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,800," - "8,100,0,7,0,1,1,,,0,,,,0\n" + "8,100,0,7,128,1,1,,,0,,,,0\n" "2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800," - "8,100,0,7,0,1,1,,11:22:33:44:55,0,,1,0,0\n"; + "8,100,0,7,128,1,1,,11:22:33:44:55,0,,1,0,0\n"; EXPECT_EQ(result_file_contents, input_file.readFile()); } @@ -2508,7 +2508,7 @@ TEST_F(MemfileLeaseMgrTest, v6UserContext) { lease->toText(), "Type: IA_NA(0)\n" "Address: 2001:db8:1::1\n" - "Prefix length: 0\n" + "Prefix length: 128\n" "IAID: 7\n" "Pref life: 100\n" "Valid life: 400\n" @@ -2528,7 +2528,7 @@ TEST_F(MemfileLeaseMgrTest, v6UserContext) { lease->toText(), "Type: IA_NA(0)\n" "Address: 2001:db8:1::2\n" - "Prefix length: 0\n" + "Prefix length: 128\n" "IAID: 7\n" "Pref life: 100\n" "Valid life: 200\n" @@ -2548,7 +2548,7 @@ TEST_F(MemfileLeaseMgrTest, v6UserContext) { lease->toText(), "Type: IA_NA(0)\n" "Address: 2001:db8:1::4\n" - "Prefix length: 0\n" + "Prefix length: 128\n" "IAID: 7\n" "Pref life: 100\n" "Valid life: 200\n" @@ -2569,7 +2569,7 @@ TEST_F(MemfileLeaseMgrTest, v6UserContext) { lease->toText(), "Type: IA_NA(0)\n" "Address: 2001:db8:1::8\n" - "Prefix length: 0\n" + "Prefix length: 128\n" "IAID: 7\n" "Pref life: 100\n" "Valid life: 200\n" @@ -2819,9 +2819,9 @@ TEST_F(MemfileLeaseMgrTest, classLeaseRecount6) { // List of lease recipes. std::list recipes{ - { Lease::TYPE_NA, "3001::1", 0, Lease::STATE_DEFAULT, {"water", "slice"} }, - { Lease::TYPE_NA, "3001::2", 0, Lease::STATE_DEFAULT, {"melon"} }, - { Lease::TYPE_NA, "3001::3", 0, Lease::STATE_DEFAULT, {"melon", "slice"} }, + { Lease::TYPE_NA, "3001::1", 128, Lease::STATE_DEFAULT, {"water", "slice"} }, + { Lease::TYPE_NA, "3001::2", 128, Lease::STATE_DEFAULT, {"melon"} }, + { Lease::TYPE_NA, "3001::3", 128, Lease::STATE_DEFAULT, {"melon", "slice"} }, { Lease::TYPE_PD, "3001:1:2:0100::", 112, Lease::STATE_DEFAULT, {"grapes", "slice"} }, { Lease::TYPE_PD, "3001:1:2:0200::", 112, Lease::STATE_DEFAULT, {"wrath"} }, @@ -4159,10 +4159,10 @@ TEST_F(MemfileLeaseMgrTest, buildExtendedInfoTables6ExplicitSanitize) { // Check the lease file was updated. string new_content = "2001:db8:1::1,01:01:01:01:01:01:01:01:01:01:01:01:01," - "400,1000,8,100,0,7,0,1,1,,,1,,,,0\n" + "400,1000,8,100,0,7,128,1,1,,,1,,,,0\n" "2001:db8:1::2,02:02:02:02:02:02:02:02:02:02:02:02:02," - "200,200,8,100,0,7,0,1,1,,,1," + "200,200,8,100,0,7,128,1,1,,,1," "{ \"ISC\": { \"relay-info\": [ { \"hop\": 44," " \"link\": \"2001:db8::4\"," " \"options\": \"0x00250006010203040506003500086464646464646464\""