From: Tomek Mrugalski Date: Mon, 27 Oct 2014 19:40:00 +0000 (+0100) Subject: [3555] Lease6::matches now checks hwaddr X-Git-Tag: trac3629a_base~5^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7da6edea5f2f767f12246e92ad061cd8f41e1822;p=thirdparty%2Fkea.git [3555] Lease6::matches now checks hwaddr --- diff --git a/src/lib/dhcpsrv/lease.cc b/src/lib/dhcpsrv/lease.cc index 4dc80b5abc..2d455f4f69 100644 --- a/src/lib/dhcpsrv/lease.cc +++ b/src/lib/dhcpsrv/lease.cc @@ -277,6 +277,18 @@ Lease4::operator==(const Lease4& other) const { bool Lease6::matches(const Lease6& other) const { + + // One lease has a hardware address, the other doesn't. + if ( (!hwaddr_ && other.hwaddr_) || + (hwaddr_ && !other.hwaddr_) ) { + return (false); + } + + // Both leases have hardware address, but they are not equal. + if (hwaddr_ && (*hwaddr_ != *other.hwaddr_)) { + return (false); + } + return (addr_ == other.addr_ && type_ == other.type_ && prefixlen_ == other.prefixlen_ && diff --git a/src/lib/dhcpsrv/tests/lease_unittest.cc b/src/lib/dhcpsrv/tests/lease_unittest.cc index e517caaa90..3a10c90a01 100644 --- a/src/lib/dhcpsrv/tests/lease_unittest.cc +++ b/src/lib/dhcpsrv/tests/lease_unittest.cc @@ -575,6 +575,34 @@ TEST(Lease6, matches) { lease1.duid_ = duid; EXPECT_FALSE(lease1.matches(lease2)); lease1.duid_ = lease2.duid_; + + // Hardware address checks + EXPECT_TRUE(lease1.matches(lease2)); // Neither lease have hardware address. + + // Let's add a hardware lease to the first one. + HWAddrPtr hwaddr(new HWAddr(HWADDR, sizeof(HWADDR), HTYPE_ETHER)); + lease1.hwaddr_ = hwaddr; + + // Only the first one has a hardware address, so not equal. + EXPECT_FALSE(lease1.matches(lease2)); + + // Only the second one has it, so still not equal. + lease1.hwaddr_.reset(); + lease2.hwaddr_ = hwaddr; + EXPECT_FALSE(lease1.matches(lease2)); + + // Ok, now both have it - they should be equal. + lease1.hwaddr_ = hwaddr; + EXPECT_TRUE(lease1.matches(lease2)); + + // Let's create a second instance that have the same values. + HWAddrPtr hwaddr2(new HWAddr(HWADDR, sizeof(HWADDR), HTYPE_ETHER)); + lease2.hwaddr_ = hwaddr2; + EXPECT_TRUE(lease1.matches(lease2)); + + // Let's modify the second address and check that they won't be equal anymore. + hwaddr2->hwaddr_[0]++; + EXPECT_FALSE(lease1.matches(lease2)); } /// @brief Lease6 Equality Test