BIND 10 trac2320, updated. 1deefe2736bcc2b61e07f20ea732d178d84ab772 [2320] Small tweak inhwaddr.c implemented.
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Jan 2 16:51:44 UTC 2013
The branch, trac2320 has been updated
via 1deefe2736bcc2b61e07f20ea732d178d84ab772 (commit)
via 6c7d6aae42af702f8b846b3984c09854a5a58539 (commit)
via 09e8ac90d96a468beb509c4da6e9dd74975aa1ad (commit)
via 20419496af5c9374c7858251e1b857413d1f7d17 (commit)
from 6d3fb27de20503a07333bbc9e053451a80442a41 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 1deefe2736bcc2b61e07f20ea732d178d84ab772
Author: Tomek Mrugalski <tomasz at isc.org>
Date: Wed Jan 2 17:45:56 2013 +0100
[2320] Small tweak inhwaddr.c implemented.
commit 6c7d6aae42af702f8b846b3984c09854a5a58539
Author: Tomek Mrugalski <tomasz at isc.org>
Date: Wed Jan 2 17:45:42 2013 +0100
[2320] Tests for DHCPv4 RELEASE implemented
commit 09e8ac90d96a468beb509c4da6e9dd74975aa1ad
Author: Tomek Mrugalski <tomasz at isc.org>
Date: Wed Jan 2 17:43:53 2013 +0100
[2320] Pkt4::delOption() implemented.
commit 20419496af5c9374c7858251e1b857413d1f7d17
Author: Tomek Mrugalski <tomasz at isc.org>
Date: Wed Jan 2 17:43:27 2013 +0100
[2320] Additional tests implemented.
-----------------------------------------------------------------------
Summary of changes:
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc | 181 +++++++++++++++++++++-
src/lib/dhcp/hwaddr.cc | 2 +-
src/lib/dhcp/pkt4.cc | 10 ++
src/lib/dhcp/pkt4.h | 5 +
src/lib/dhcp/tests/hwaddr_unittest.cc | 10 ++
src/lib/dhcp/tests/pkt4_unittest.cc | 6 +
src/lib/dhcpsrv/tests/addr_utilities_unittest.cc | 47 ++++++
src/lib/dhcpsrv/tests/alloc_engine_unittest.cc | 40 +++++
8 files changed, 296 insertions(+), 5 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
index ba1ff3e..2a28309 100644
--- a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
+++ b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
@@ -709,10 +709,10 @@ TEST_F(Dhcpv4SrvTest, RenewBasic) {
ASSERT_NO_THROW( srv.reset(new NakedDhcpv4Srv(0)) );
const IOAddress addr("192.0.2.106");
- uint32_t temp_t1 = 50;
- uint32_t temp_t2 = 75;
- uint32_t temp_valid = 100;
- time_t temp_timestamp = time(NULL) - 10;
+ const uint32_t temp_t1 = 50;
+ const uint32_t temp_t2 = 75;
+ const uint32_t temp_valid = 100;
+ const time_t temp_timestamp = time(NULL) - 10;
// Generate client-id also duid_
OptionPtr clientid = generateClientId();
@@ -810,5 +810,178 @@ TEST_F(Dhcpv4SrvTest, sanityCheck) {
}
// @todo: write tests for RELEASE
+// This test verifies that incoming (positive) RELEASE can be handled properly,
+// that a REPLY is generated, that the response has status code and that the
+// lease is indeed removed from the database.
+//
+// expected:
+// - returned REPLY message has copy of client-id
+// - returned REPLY message has server-id
+// - returned REPLY message has IA that does not include an IAADDR
+// - lease is actually removed from LeaseMgr
+TEST_F(Dhcpv4SrvTest, ReleaseBasic) {
+ boost::scoped_ptr<NakedDhcpv4Srv> srv;
+ ASSERT_NO_THROW( srv.reset(new NakedDhcpv4Srv(0)) );
+
+ const IOAddress addr("192.0.2.106");
+ const uint32_t temp_t1 = 50;
+ const uint32_t temp_t2 = 75;
+ const uint32_t temp_valid = 100;
+ const time_t temp_timestamp = time(NULL) - 10;
+
+ // Generate client-id also duid_
+ OptionPtr clientid = generateClientId();
+
+ // Check that the address we are about to use is indeed in pool
+ ASSERT_TRUE(subnet_->inPool(addr));
+
+ // let's create a lease and put it in the LeaseMgr
+ uint8_t mac_addr[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
+ HWAddrPtr hw(new HWAddr(mac_addr, sizeof(mac_addr), HTYPE_ETHER));
+ Lease4Ptr used(new Lease4(addr, mac_addr, sizeof(mac_addr),
+ &client_id_->getDuid()[0], client_id_->getDuid().size(),
+ temp_valid, temp_t1, temp_t2, temp_timestamp,
+ subnet_->getID()));
+ ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used));
+
+ // Check that the lease is really in the database
+ Lease4Ptr l = LeaseMgrFactory::instance().getLease4(addr);
+ ASSERT_TRUE(l);
+
+ // Let's create a RELEASE
+ // Generate client-id also duid_
+ Pkt4Ptr rel = Pkt4Ptr(new Pkt4(DHCPRELEASE, 1234));
+ rel->setRemoteAddr(addr);
+ rel->setYiaddr(addr);
+ rel->addOption(clientid);
+ rel->addOption(srv->getServerID());
+ rel->setHWAddr(hw);
+
+ // Pass it to the server and hope for a REPLY
+ // Note: this is no response to RELEASE in DHCPv4
+ EXPECT_NO_THROW(srv->processRelease(rel));
+
+ // The lease should be gone from LeaseMgr
+ l = LeaseMgrFactory::instance().getLease4(addr);
+ EXPECT_FALSE(l);
+
+ // Try to get the lease by hardware address
+ // @todo: Uncomment this once trac2592 is implemented
+ // Lease4Collection leases = LeaseMgrFactory::instance().getLease4(hw->hwaddr_);
+ // EXPECT_EQ(leases.size(), 0);
+
+ // Try to get it by hw/subnet_id compination
+ l = LeaseMgrFactory::instance().getLease4(hw->hwaddr_, subnet_->getID());
+ EXPECT_FALSE(l);
+
+ // Try by client-id
+ // @todo: Uncomment this once trac2592 is implemented
+ //Lease4Collection leases = LeaseMgrFactory::instance().getLease4(*client_id_);
+ //EXPECT_EQ(leases.size(), 0);
+
+ // Try by client-id/subnet-id
+ l = LeaseMgrFactory::instance().getLease4(*client_id_, subnet_->getID());
+ EXPECT_FALSE(l);
+
+ // Ok, the lease is *really* not there.
+}
+
+// This test verifies that incoming (invalid) RELEASE can be handled properly.
+//
+// This test checks 3 scenarios:
+// 1. there is no such lease at all
+// 2. there is such a lease, but it is assigned to a different IAID
+// 3. there is such a lease, but it belongs to a different client
+//
+// expected:
+// - returned REPLY message has copy of client-id
+// - returned REPLY message has server-id
+// - returned REPLY message has IA that includes STATUS-CODE
+// - No lease in LeaseMgr
+TEST_F(Dhcpv4SrvTest, ReleaseReject) {
+ boost::scoped_ptr<NakedDhcpv4Srv> srv;
+ ASSERT_NO_THROW( srv.reset(new NakedDhcpv4Srv(0)) );
+
+ const IOAddress addr("192.0.2.106");
+ const uint32_t t1 = 50;
+ const uint32_t t2 = 75;
+ const uint32_t valid = 100;
+ const time_t timestamp = time(NULL) - 10;
+
+ // let's create a lease and put it in the LeaseMgr
+ uint8_t bogus_mac_addr[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
+ HWAddrPtr bogus_hw(new HWAddr(bogus_mac_addr, sizeof(bogus_mac_addr), HTYPE_ETHER));
+ OptionPtr bogus_clientid = generateClientId(7); // different length
+
+ // Generate client-id also duid_
+ OptionPtr clientid = generateClientId();
+
+ // Check that the address we are about to use is indeed in pool
+ ASSERT_TRUE(subnet_->inPool(addr));
+
+ // Let's create a RELEASE
+ // Generate client-id also duid_
+ Pkt4Ptr rel = Pkt4Ptr(new Pkt4(DHCPRELEASE, 1234));
+ rel->setRemoteAddr(addr);
+ rel->setYiaddr(addr);
+ rel->addOption(clientid);
+ rel->addOption(srv->getServerID());
+ rel->setHWAddr(bogus_hw);
+
+ // Case 1: No lease known to server
+ SCOPED_TRACE("CASE 1: Lease is not known to the server");
+
+ // There is nothing to check here. The lease is not there and server does
+ // not send anything back. This case is enumerated here just for keeping
+ // parity with similar test in DHCPv6.
+ EXPECT_NO_THROW(srv->processRelease(rel));
+
+ // CASE 2: Lease is known and belongs to this client, but to a different client-id
+ SCOPED_TRACE("CASE 2: Lease is known and belongs to this client, but uses different HW addr");
+
+ // Let's create a lease and put it in the LeaseMgr
+ uint8_t mac_addr[] = { 0, 0x1, 0x2, 0x3, 0x4, 0x5};
+ HWAddrPtr hw(new HWAddr(mac_addr, sizeof(mac_addr), HTYPE_ETHER));
+ Lease4Ptr used(new Lease4(addr, mac_addr, sizeof(mac_addr),
+ &client_id_->getDuid()[0], client_id_->getDuid().size(),
+ valid, t1, t2, timestamp, subnet_->getID()));
+ ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used));
+ // Check that the lease is really in the database
+ Lease4Ptr l = LeaseMgrFactory::instance().getLease4(addr);
+ ASSERT_TRUE(l);
+
+ rel->setHWAddr(bogus_hw);
+
+ EXPECT_NO_THROW(srv->processRelease(rel));
+
+ // Check that the lease was not removed (due to hardware address mis-match)
+ l = LeaseMgrFactory::instance().getLease4(addr);
+ ASSERT_TRUE(l);
+
+ // CASE 3: Lease belongs to a client with different client-id
+ SCOPED_TRACE("CASE 3: Lease belongs to a client with different client-id");
+
+ rel->setHWAddr(hw); // proper HW address this time
+ rel->delOption(DHO_DHCP_CLIENT_IDENTIFIER);
+ rel->addOption(bogus_clientid); // but invalid client-id
+
+ OptionPtr x = rel->getOption(DHO_DHCP_CLIENT_IDENTIFIER);
+
+ EXPECT_NO_THROW(srv->processRelease(rel));
+
+ // Check that the lease is still there
+ l = LeaseMgrFactory::instance().getLease4(addr);
+ ASSERT_TRUE(l);
+
+ // Final sanity check. Verify that with valid hw and client-id release is working
+ rel->delOption(DHO_DHCP_CLIENT_IDENTIFIER);
+ rel->addOption(clientid);
+
+ EXPECT_NO_THROW(srv->processRelease(rel));
+
+ l = LeaseMgrFactory::instance().getLease4(addr);
+ EXPECT_FALSE(l);
+
+}
} // end of anonymous namespace
diff --git a/src/lib/dhcp/hwaddr.cc b/src/lib/dhcp/hwaddr.cc
index 10f0ac3..d19f2ad 100644
--- a/src/lib/dhcp/hwaddr.cc
+++ b/src/lib/dhcp/hwaddr.cc
@@ -35,7 +35,7 @@ HWAddr::HWAddr(const std::vector<uint8_t>& hwaddr, uint8_t htype)
std::string HWAddr::toText() const {
std::stringstream tmp;
- tmp << "type=" << htype_ << " ";
+ tmp << "hwtype=" << static_cast<int>(htype_) << " ";
tmp << std::hex;
bool delim = false;
for (std::vector<uint8_t>::const_iterator it = hwaddr_.begin();
diff --git a/src/lib/dhcp/pkt4.cc b/src/lib/dhcp/pkt4.cc
index 9710fe5..411c346 100644
--- a/src/lib/dhcp/pkt4.cc
+++ b/src/lib/dhcp/pkt4.cc
@@ -369,6 +369,16 @@ Pkt4::getOption(uint8_t type) {
return boost::shared_ptr<isc::dhcp::Option>(); // NULL
}
+bool
+Pkt4::delOption(uint8_t type) {
+ isc::dhcp::Option::OptionCollection::iterator x = options_.find(type);
+ if (x!=options_.end()) {
+ options_.erase(x);
+ return (true); // delete successful
+ }
+ return (false); // can't find option to be deleted
+}
+
void
Pkt4::updateTimestamp() {
timestamp_ = boost::posix_time::microsec_clock::universal_time();
diff --git a/src/lib/dhcp/pkt4.h b/src/lib/dhcp/pkt4.h
index 4dc0744..6674bb1 100644
--- a/src/lib/dhcp/pkt4.h
+++ b/src/lib/dhcp/pkt4.h
@@ -325,6 +325,11 @@ public:
boost::shared_ptr<Option>
getOption(uint8_t opt_type);
+ /// @brief Deletes specified option
+ /// @param type option type to be deleted
+ /// @return true if anything was deleted, false otherwise
+ bool delOption(uint8_t type);
+
/// @brief Returns interface name.
///
/// Returns interface name over which packet was received or is
diff --git a/src/lib/dhcp/tests/hwaddr_unittest.cc b/src/lib/dhcp/tests/hwaddr_unittest.cc
index 8a97da1..1173b99 100644
--- a/src/lib/dhcp/tests/hwaddr_unittest.cc
+++ b/src/lib/dhcp/tests/hwaddr_unittest.cc
@@ -90,4 +90,14 @@ TEST(HWAddrTest, operators) {
EXPECT_TRUE(*hw4 != *hw5);
}
+TEST(HWAddrTest, toText) {
+ uint8_t data[] = {0, 1, 2, 3, 4, 5}; // last digit different
+ uint8_t htype = 15;
+
+ HWAddrPtr hw(new HWAddr(data, sizeof(data), htype));
+
+ EXPECT_EQ("hwtype=15 00:01:02:03:04:05", hw->toText());
+
+}
+
} // end of anonymous namespace
diff --git a/src/lib/dhcp/tests/pkt4_unittest.cc b/src/lib/dhcp/tests/pkt4_unittest.cc
index 3fb277c..6ca73b1 100644
--- a/src/lib/dhcp/tests/pkt4_unittest.cc
+++ b/src/lib/dhcp/tests/pkt4_unittest.cc
@@ -530,6 +530,12 @@ TEST(Pkt4Test, options) {
EXPECT_EQ(0, memcmp(ptr, v4Opts, sizeof(v4Opts)));
EXPECT_EQ(DHO_END, static_cast<uint8_t>(*(ptr + sizeof(v4Opts))));
+ // delOption() checks
+ EXPECT_TRUE(pkt->getOption(12)); // Sanity check: option 12 is still there
+ EXPECT_TRUE(pkt->delOption(12)); // We should be able to remove it
+ EXPECT_FALSE(pkt->getOption(12)); // It should not be there anymore
+ EXPECT_FALSE(pkt->delOption(12)); // And removal should fail
+
EXPECT_NO_THROW(
delete pkt;
);
diff --git a/src/lib/dhcpsrv/tests/addr_utilities_unittest.cc b/src/lib/dhcpsrv/tests/addr_utilities_unittest.cc
index 19f08a9..cdd59df 100644
--- a/src/lib/dhcpsrv/tests/addr_utilities_unittest.cc
+++ b/src/lib/dhcpsrv/tests/addr_utilities_unittest.cc
@@ -16,6 +16,7 @@
#include <config.h>
#include <dhcpsrv/addr_utilities.h>
+#include <exceptions/exceptions.h>
#include <gtest/gtest.h>
@@ -28,6 +29,8 @@ using namespace std;
using namespace isc::dhcp;
using namespace isc::asiolink;
+namespace {
+
// This test verifies that lastAddrInPrefix is able to handle IPv4 operations.
TEST(AddrUtilitiesTest, lastAddrInPrefix4) {
IOAddress addr1("192.0.2.1");
@@ -154,3 +157,47 @@ TEST(AddrUtilitiesTest, firstAddrInPrefix6) {
EXPECT_EQ("2001::ff80", firstAddrInPrefix(addr2, 121).toText());
EXPECT_EQ("2001::ff00", firstAddrInPrefix(addr2, 120).toText());
}
+
+// Checks if IPv4 netmask is generated properly
+TEST(AddrUtilitiesTest, getNetmask4) {
+ EXPECT_EQ("0.0.0.0", getNetmask4(0).toText());
+ EXPECT_EQ("128.0.0.0", getNetmask4(1).toText());
+ EXPECT_EQ("192.0.0.0", getNetmask4(2).toText());
+ EXPECT_EQ("224.0.0.0", getNetmask4(3).toText());
+ EXPECT_EQ("240.0.0.0", getNetmask4(4).toText());
+ EXPECT_EQ("248.0.0.0", getNetmask4(5).toText());
+ EXPECT_EQ("252.0.0.0", getNetmask4(6).toText());
+ EXPECT_EQ("254.0.0.0", getNetmask4(7).toText());
+ EXPECT_EQ("255.0.0.0", getNetmask4(8).toText());
+
+ EXPECT_EQ("255.128.0.0", getNetmask4(9).toText());
+ EXPECT_EQ("255.192.0.0", getNetmask4(10).toText());
+ EXPECT_EQ("255.224.0.0", getNetmask4(11).toText());
+ EXPECT_EQ("255.240.0.0", getNetmask4(12).toText());
+ EXPECT_EQ("255.248.0.0", getNetmask4(13).toText());
+ EXPECT_EQ("255.252.0.0", getNetmask4(14).toText());
+ EXPECT_EQ("255.254.0.0", getNetmask4(15).toText());
+ EXPECT_EQ("255.255.0.0", getNetmask4(16).toText());
+
+ EXPECT_EQ("255.255.128.0", getNetmask4(17).toText());
+ EXPECT_EQ("255.255.192.0", getNetmask4(18).toText());
+ EXPECT_EQ("255.255.224.0", getNetmask4(19).toText());
+ EXPECT_EQ("255.255.240.0", getNetmask4(20).toText());
+ EXPECT_EQ("255.255.248.0", getNetmask4(21).toText());
+ EXPECT_EQ("255.255.252.0", getNetmask4(22).toText());
+ EXPECT_EQ("255.255.254.0", getNetmask4(23).toText());
+ EXPECT_EQ("255.255.255.0", getNetmask4(24).toText());
+
+ EXPECT_EQ("255.255.255.128", getNetmask4(25).toText());
+ EXPECT_EQ("255.255.255.192", getNetmask4(26).toText());
+ EXPECT_EQ("255.255.255.224", getNetmask4(27).toText());
+ EXPECT_EQ("255.255.255.240", getNetmask4(28).toText());
+ EXPECT_EQ("255.255.255.248", getNetmask4(29).toText());
+ EXPECT_EQ("255.255.255.252", getNetmask4(30).toText());
+ EXPECT_EQ("255.255.255.254", getNetmask4(31).toText());
+ EXPECT_EQ("255.255.255.255", getNetmask4(32).toText());
+
+ EXPECT_THROW(getNetmask4(33), isc::BadValue);
+}
+
+}; // end of anonymous namespace
diff --git a/src/lib/dhcpsrv/tests/alloc_engine_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine_unittest.cc
index 7ce7d6e..8030abc 100644
--- a/src/lib/dhcpsrv/tests/alloc_engine_unittest.cc
+++ b/src/lib/dhcpsrv/tests/alloc_engine_unittest.cc
@@ -895,4 +895,44 @@ TEST_F(AllocEngine4Test, requestReuseExpiredLease4) {
detailCompareLease(lease, from_mgr);
}
+// This test checks if a lease is really renewed when renewLease4 method is
+// called
+TEST_F(AllocEngine4Test, renewLease4) {
+ boost::scoped_ptr<AllocEngine> engine;
+ ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 100)));
+ ASSERT_TRUE(engine);
+
+ IOAddress addr("192.0.2.102");
+ const uint32_t old_lifetime = 100;
+ const uint32_t old_t1 = 50;
+ const uint32_t old_t2 = 75;
+ const time_t old_timestamp = time(NULL) - 45; // Allocated 45 seconds ago
+
+ // Just a different hw/client-id for the second client
+ const uint8_t hwaddr2[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
+ const uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 };
+ Lease4Ptr lease(new Lease4(addr, clientid2, sizeof(clientid2), hwaddr2,
+ sizeof(hwaddr2), old_lifetime, old_t1, old_t2,
+ old_timestamp, subnet_->getID()));
+ ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease));
+
+ // lease was assigned 45 seconds ago and is valid for 100 seconds. Let's
+ // renew it.
+ ASSERT_FALSE(lease->expired());
+ lease = engine->renewLease4(subnet_, clientid_, hwaddr_, lease, false);
+ // Check that he got that single lease
+ ASSERT_TRUE(lease);
+ EXPECT_EQ(addr.toText(), lease->addr_.toText());
+
+ // Check that the lease matches subnet_, hwaddr_,clientid_ parameters
+ checkLease4(lease);
+
+ // Check that the lease is indeed updated in LeaseMgr
+ Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr);
+ ASSERT_TRUE(from_mgr);
+
+ // Now check that the lease in LeaseMgr has the same parameters
+ detailCompareLease(lease, from_mgr);
+}
+
}; // end of anonymous namespace
More information about the bind10-changes
mailing list