From: Razvan Becheriu Date: Thu, 8 Jun 2023 13:33:19 +0000 (+0300) Subject: [#2830] use uint128_t for random prefix allocation X-Git-Tag: Kea-2.4.0~161 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f6b8592edb16eb755c6c0f172224ecad836b577;p=thirdparty%2Fkea.git [#2830] use uint128_t for random prefix allocation --- diff --git a/src/lib/asiolink/addr_utilities.cc b/src/lib/asiolink/addr_utilities.cc index 78fd3bfa89..438eacb557 100644 --- a/src/lib/asiolink/addr_utilities.cc +++ b/src/lib/asiolink/addr_utilities.cc @@ -365,7 +365,7 @@ uint128_t prefixesInRange(const uint8_t pool_len, const uint8_t delegated_len) { return (uint128_t(1) << count); } -IOAddress offsetAddress(const IOAddress& addr, uint64_t offset) { +IOAddress offsetAddress(const IOAddress& addr, isc::util::uint128_t offset) { // There is nothing to do if the offset is 0. if (offset == 0) { return (addr); @@ -384,9 +384,9 @@ IOAddress offsetAddress(const IOAddress& addr, uint64_t offset) { // This is IPv6 address. Let's first convert the offset value to network // byte order and store within the vector. - std::vector offset_bytes(8); + std::vector offset_bytes(16); for (int offset_idx = offset_bytes.size() - 1; offset_idx >= 0; --offset_idx) { - offset_bytes[offset_idx] = static_cast(offset & 0x00000000000000ff); + offset_bytes[offset_idx] = static_cast(offset & 0xff); offset = offset >> 8; } @@ -394,20 +394,17 @@ IOAddress offsetAddress(const IOAddress& addr, uint64_t offset) { auto addr_bytes = addr.toBytes(); // Sum up the bytes. - uint16_t carry = 0; - for (int i = offset_bytes.size() - 1; (i >= 0) || (carry > 0); --i) { + for (int i = offset_bytes.size() - 1; (i >= 0); --i) { // Sum the bytes of the address, offset and the carry. - uint16_t sum = static_cast(addr_bytes[i+8]) + carry; + uint16_t sum = static_cast(addr_bytes[i]) + carry; // Protect against the case when we went beyond the offset vector and // we have only carry to add. - if (i >= 0 ) { - sum += static_cast(offset_bytes[i]); - } + sum += static_cast(offset_bytes[i]); // Update the address byte. - addr_bytes[i+8] = sum % 256; + addr_bytes[i] = sum % 256; // Calculate the carry value. carry = sum / 256; @@ -417,6 +414,5 @@ IOAddress offsetAddress(const IOAddress& addr, uint64_t offset) { return (IOAddress::fromBytes(AF_INET6, &addr_bytes[0])); } - -}; -}; +} +} diff --git a/src/lib/asiolink/addr_utilities.h b/src/lib/asiolink/addr_utilities.h index c305f75c59..87f356c7bb 100644 --- a/src/lib/asiolink/addr_utilities.h +++ b/src/lib/asiolink/addr_utilities.h @@ -91,7 +91,7 @@ isc::util::uint128_t prefixesInRange(const uint8_t pool_len, const uint8_t deleg /// @param addr input address /// @param offset distance of the returned address from the input address. /// @return address being offset greater than the input address -IOAddress offsetAddress(const IOAddress& addr, uint64_t offset); +IOAddress offsetAddress(const IOAddress& addr, isc::util::uint128_t offset); } // namespace asiolink } // namespace isc diff --git a/src/lib/asiolink/tests/addr_utilities_unittest.cc b/src/lib/asiolink/tests/addr_utilities_unittest.cc index 2fa91d67c3..30a98170da 100644 --- a/src/lib/asiolink/tests/addr_utilities_unittest.cc +++ b/src/lib/asiolink/tests/addr_utilities_unittest.cc @@ -385,4 +385,4 @@ TEST(AddrUtilitiesTest, offsetIPv6Address) { EXPECT_EQ("3000::1c", offsetAddress(IOAddress("3000::15"), 7).toText()); } -}; // end of anonymous namespace +} // end of anonymous namespace diff --git a/src/lib/dhcpsrv/ip_range_permutation.cc b/src/lib/dhcpsrv/ip_range_permutation.cc index 183ce96683..78768f3226 100644 --- a/src/lib/dhcpsrv/ip_range_permutation.cc +++ b/src/lib/dhcpsrv/ip_range_permutation.cc @@ -23,7 +23,7 @@ IPRangePermutation::IPRangePermutation(const AddressRange& range) } IPRangePermutation::IPRangePermutation(const PrefixRange& range) - : range_start_(range.start_), step_(static_cast(1) << (128 - range.delegated_length_)), + : range_start_(range.start_), step_(isc::util::uint128_t(1) << (128 - range.delegated_length_)), cursor_(prefixesInRange(range.prefix_length_, range.delegated_length_) - 1), initial_cursor_(cursor_), state_(), done_(false), generator_() { std::random_device rd; @@ -52,7 +52,7 @@ IPRangePermutation::next(bool& done) { // addresses between the cursor and the end of the range have been already // returned by this function. Therefore we focus on the remaining cursor-1 // addresses. Let's get random address from this sub-range. - std::uniform_int_distribution dist(0, cursor_ - 1); + std::uniform_int_distribution dist(0, static_cast(cursor_ - 1)); auto next_loc = dist(generator_); IOAddress next_loc_address = IOAddress::IPV4_ZERO_ADDRESS(); diff --git a/src/lib/dhcpsrv/ip_range_permutation.h b/src/lib/dhcpsrv/ip_range_permutation.h index 93cbb096f2..cb4c0bdc72 100644 --- a/src/lib/dhcpsrv/ip_range_permutation.h +++ b/src/lib/dhcpsrv/ip_range_permutation.h @@ -9,6 +9,7 @@ #include #include +#include #include @@ -114,27 +115,27 @@ private: /// Distance between two neighboring addresses or delegated prefixes, /// i.e. 1 for address range and delegated prefix size for delegated /// prefixes. - uint64_t step_; + isc::util::uint128_t step_; /// Keeps the position of the next address or prefix to be swapped with /// a randomly picked address or prefix from the range of 0..cursor-1. The /// cursor value is decreased every time a new IP address or prefix /// is returned. - uint64_t cursor_; + isc::util::uint128_t cursor_; /// Keeps the initial cursor position for @c reset function. - uint64_t initial_cursor_; + isc::util::uint128_t initial_cursor_; /// Keeps the current permutation state. The state associates the /// swapped IP addresses or delegated prefixes with their positions in /// the permutation. - std::unordered_map state_; + std::unordered_map state_; /// Indicates if the addresses or delegated prefixes are exhausted. bool done_; /// Random generator. - std::mt19937 generator_; + std::mt19937_64 generator_; }; /// @brief Pointer to the @c IPRangePermutation. diff --git a/src/lib/dhcpsrv/pool.cc b/src/lib/dhcpsrv/pool.cc index 177513e7e3..4d9f381249 100644 --- a/src/lib/dhcpsrv/pool.cc +++ b/src/lib/dhcpsrv/pool.cc @@ -21,7 +21,7 @@ namespace dhcp { Pool::Pool(Lease::Type type, const isc::asiolink::IOAddress& first, const isc::asiolink::IOAddress& last) : id_(0), first_(first), last_(last), type_(type), capacity_(0), - cfg_option_(new CfgOption()), client_class_(""), permutation_() { + cfg_option_(new CfgOption()), client_class_("") { } bool Pool::inRange(const isc::asiolink::IOAddress& addr) const { diff --git a/src/lib/dhcpsrv/pool.h b/src/lib/dhcpsrv/pool.h index f004dc5524..0015bb1e82 100644 --- a/src/lib/dhcpsrv/pool.h +++ b/src/lib/dhcpsrv/pool.h @@ -170,13 +170,6 @@ public: /// @return A pointer to unparsed pool configuration. virtual data::ElementPtr toElement() const; - /// @brief Returns pointer to the permutation associated with the pool. - /// - /// @return Pointer to the address range permutation. - IPRangePermutationPtr getPermutation() const { - return (permutation_); - } - protected: /// @brief protected constructor @@ -233,12 +226,6 @@ protected: /// @brief Holds pool-specific allocation state. AllocationStatePtr allocation_state_; - - /// @brief Pointer to the permutation object. - /// - /// It may be initialized for some pools to provide address - /// or delegated prefix randomization capabilities. - IPRangePermutationPtr permutation_; }; class Pool4; diff --git a/src/lib/dhcpsrv/tests/mysql_lease_extended_info_unittest.cc b/src/lib/dhcpsrv/tests/mysql_lease_extended_info_unittest.cc index fc077f5f6f..6ada1aaeb2 100644 --- a/src/lib/dhcpsrv/tests/mysql_lease_extended_info_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_lease_extended_info_unittest.cc @@ -182,6 +182,10 @@ MySqlExtendedInfoTest::testInitLease4() { // Use the page version as it returns leases in order. EXPECT_NO_THROW(got = lease_mgr_->getLeases4(zero, LeasePageSize(100))); ASSERT_EQ(leases4.size(), got.size()); + auto compare = [](Lease4Ptr& left, Lease4Ptr& right) { + return (left->addr_ < right->addr_); + }; + std::sort(got.begin(), got.end(), compare); for (size_t i = 0; i < leases4.size(); ++i) { ConstElementPtr expected = leases4[i]->toElement(); LeasePtr lease = got[i]; @@ -1007,6 +1011,10 @@ MySqlExtendedInfoTest::testInitLease6() { Lease6Collection got; EXPECT_NO_THROW(got = lease_mgr_->getLeases6()); ASSERT_EQ(leases6.size(), got.size()); + auto compare = [](Lease6Ptr& left, Lease6Ptr& right) { + return (left->addr_ < right->addr_); + }; + std::sort(got.begin(), got.end(), compare); for (size_t i = 0; i < leases6.size(); ++i) { ConstElementPtr expected = leases6[i]->toElement(); LeasePtr lease = got[i]; diff --git a/src/lib/dhcpsrv/tests/pgsql_lease_extended_info_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_lease_extended_info_unittest.cc index 1bd8291428..9c4f36484c 100644 --- a/src/lib/dhcpsrv/tests/pgsql_lease_extended_info_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_lease_extended_info_unittest.cc @@ -182,6 +182,10 @@ PgSqlExtendedInfoTest::testInitLease4() { // Use the page version as it returns leases in order. EXPECT_NO_THROW(got = lease_mgr_->getLeases4(zero, LeasePageSize(100))); ASSERT_EQ(leases4.size(), got.size()); + auto compare = [](Lease4Ptr& left, Lease4Ptr& right) { + return (left->addr_ < right->addr_); + }; + std::sort(got.begin(), got.end(), compare); for (size_t i = 0; i < leases4.size(); ++i) { ConstElementPtr expected = leases4[i]->toElement(); LeasePtr lease = got[i]; @@ -1007,6 +1011,10 @@ PgSqlExtendedInfoTest::testInitLease6() { Lease6Collection got; EXPECT_NO_THROW(got = lease_mgr_->getLeases6()); ASSERT_EQ(leases6.size(), got.size()); + auto compare = [](Lease6Ptr& left, Lease6Ptr& right) { + return (left->addr_ < right->addr_); + }; + std::sort(got.begin(), got.end(), compare); for (size_t i = 0; i < leases6.size(); ++i) { ConstElementPtr expected = leases6[i]->toElement(); LeasePtr lease = got[i]; diff --git a/src/lib/dns/tests/rdata_tsig_unittest.cc b/src/lib/dns/tests/rdata_tsig_unittest.cc index 7b45b3b836..e98b11b00d 100644 --- a/src/lib/dns/tests/rdata_tsig_unittest.cc +++ b/src/lib/dns/tests/rdata_tsig_unittest.cc @@ -30,6 +30,7 @@ using namespace isc; using namespace isc::dns; using namespace isc::util; using namespace isc::dns::rdata; +using namespace isc::dns::rdata::any; using isc::UnitTestUtil; using isc::util::unittests::matchWireData; @@ -57,39 +58,39 @@ protected: {} void checkFromText_None(const string& rdata_str) { - checkFromText( + checkFromText( rdata_str, rdata_tsig, false, false); } void checkFromText_InvalidText(const string& rdata_str) { - checkFromText( + checkFromText( rdata_str, rdata_tsig, true, true); } void checkFromText_BadValue(const string& rdata_str) { - checkFromText( + checkFromText( rdata_str, rdata_tsig, true, true); } void checkFromText_LexerError(const string& rdata_str) { checkFromText - ( + ( rdata_str, rdata_tsig, true, true); } void checkFromText_TooLongLabel(const string& rdata_str) { - checkFromText( + checkFromText( rdata_str, rdata_tsig, true, true); } void checkFromText_EmptyLabel(const string& rdata_str) { - checkFromText( + checkFromText( rdata_str, rdata_tsig, true, true); } void checkFromText_BadString(const string& rdata_str) { checkFromText - ( + ( rdata_str, rdata_tsig, true, false); } @@ -102,7 +103,7 @@ protected: const string valid_text4; const string valid_text5; vector expect_data; - const any::TSIG rdata_tsig; // commonly used test RDATA + const TSIG rdata_tsig; // commonly used test RDATA }; TEST_F(Rdata_TSIG_Test, fromText) { @@ -117,23 +118,22 @@ TEST_F(Rdata_TSIG_Test, fromText) { EXPECT_EQ(0, rdata_tsig.getOtherLen()); EXPECT_EQ(static_cast(NULL), rdata_tsig.getOtherData()); - any::TSIG tsig2(valid_text2); + TSIG tsig2(valid_text2); EXPECT_EQ(12, tsig2.getMACSize()); EXPECT_EQ(TSIGError::BAD_SIG_CODE, tsig2.getError()); - any::TSIG tsig3(valid_text3); + TSIG tsig3(valid_text3); EXPECT_EQ(6, tsig3.getOtherLen()); // The other data is unusual, but we don't reject it. - EXPECT_NO_THROW(any::TSIG tsig4(valid_text4)); + EXPECT_NO_THROW(TSIG tsig4(valid_text4)); // numeric representation of TSIG error - any::TSIG tsig5(valid_text5); + TSIG tsig5(valid_text5); EXPECT_EQ(2845, tsig5.getError()); // not fully qualified algorithm name - any::TSIG tsig1("hmac-md5.sig-alg.reg.int 1286779327 300 " - "0 16020 BADKEY 0"); + TSIG tsig1("hmac-md5.sig-alg.reg.int 1286779327 300 0 16020 BADKEY 0"); EXPECT_EQ(0, tsig1.compare(rdata_tsig)); // multi-line rdata @@ -141,7 +141,7 @@ TEST_F(Rdata_TSIG_Test, fromText) { "0 16020 BADKEY 0 )"); // short-form HMAC-MD5 name - const any::TSIG tsig6("hmac-md5. 1286779327 300 0 16020 BADKEY 0"); + const TSIG tsig6("hmac-md5. 1286779327 300 0 16020 BADKEY 0"); EXPECT_EQ(0, tsig6.compare(rdata_tsig)); }; @@ -194,7 +194,7 @@ TEST_F(Rdata_TSIG_Test, badText) { } void -fromWireCommonChecks(const any::TSIG& tsig) { +fromWireCommonChecks(const TSIG& tsig) { EXPECT_EQ(Name("hmac-sha256"), tsig.getAlgorithm()); EXPECT_EQ(1286978795, tsig.getTimeSigned()); EXPECT_EQ(300, tsig.getFudge()); @@ -212,13 +212,13 @@ fromWireCommonChecks(const any::TSIG& tsig) { TEST_F(Rdata_TSIG_Test, createFromWire) { RdataPtr rdata(rdataFactoryFromFile(RRType::TSIG(), RRClass::ANY(), "rdata_tsig_fromWire1.wire")); - fromWireCommonChecks(dynamic_cast(*rdata)); + fromWireCommonChecks(dynamic_cast(*rdata)); } TEST_F(Rdata_TSIG_Test, createFromWireWithOtherData) { RdataPtr rdata(rdataFactoryFromFile(RRType::TSIG(), RRClass::ANY(), "rdata_tsig_fromWire2.wire")); - const any::TSIG& tsig(dynamic_cast(*rdata)); + const TSIG& tsig(dynamic_cast(*rdata)); EXPECT_EQ(18, tsig.getError()); const uint64_t otherdata = 1286978795 + 300 + 1; // time-signed + fudge + 1 @@ -236,7 +236,7 @@ TEST_F(Rdata_TSIG_Test, createFromWireWithOtherData) { TEST_F(Rdata_TSIG_Test, createFromWireWithoutMAC) { RdataPtr rdata(rdataFactoryFromFile(RRType::TSIG(), RRClass::ANY(), "rdata_tsig_fromWire3.wire")); - const any::TSIG& tsig(dynamic_cast(*rdata)); + const TSIG& tsig(dynamic_cast(*rdata)); EXPECT_EQ(16, tsig.getError()); EXPECT_EQ(0, tsig.getMACSize()); EXPECT_EQ(static_cast(NULL), tsig.getMAC()); @@ -247,7 +247,7 @@ TEST_F(Rdata_TSIG_Test, createFromWireWithCompression) { "rdata_tsig_fromWire4.wire", // we need to skip the dummy name: Name("hmac-sha256").getLength())); - fromWireCommonChecks(dynamic_cast(*rdata)); + fromWireCommonChecks(dynamic_cast(*rdata)); } TEST_F(Rdata_TSIG_Test, badFromWire) { @@ -274,57 +274,49 @@ TEST_F(Rdata_TSIG_Test, badFromWire) { } TEST_F(Rdata_TSIG_Test, copyConstruct) { - const any::TSIG copy(rdata_tsig); + const TSIG copy(rdata_tsig); EXPECT_EQ(0, copy.compare(rdata_tsig)); // Check the copied data is valid even after the original is deleted - any::TSIG* copy2 = new any::TSIG(rdata_tsig); - any::TSIG copy3(*copy2); + TSIG* copy2 = new TSIG(rdata_tsig); + TSIG copy3(*copy2); delete copy2; EXPECT_EQ(0, copy3.compare(rdata_tsig)); } TEST_F(Rdata_TSIG_Test, createFromParams) { - EXPECT_EQ(0, rdata_tsig.compare(any::TSIG(Name("hmac-md5.sig-alg.reg.int"), - 1286779327, 300, 0, NULL, 16020, - 17, 0, NULL))); + EXPECT_EQ(0, rdata_tsig.compare(TSIG(Name("hmac-md5.sig-alg.reg.int"), + 1286779327, 300, 0, NULL, 16020, 17, 0, NULL))); const uint8_t fake_data[] = { 0x14, 0x02, 0x84, 0x14, 0x02, 0x84, 0x14, 0x02, 0x84, 0x14, 0x02, 0x84 }; - EXPECT_EQ(0, any::TSIG(valid_text2).compare( - any::TSIG(Name("hmac-sha256"), 1286779327, 300, 12, - fake_data, 16020, 16, 0, NULL))); + EXPECT_EQ(0, TSIG(valid_text2).compare(TSIG(Name("hmac-sha256"), 1286779327, 300, 12, + fake_data, 16020, 16, 0, NULL))); const uint8_t fake_data2[] = { 0x14, 0x02, 0x84, 0x14, 0x02, 0x84 }; - EXPECT_EQ(0, any::TSIG(valid_text3).compare( - any::TSIG(Name("hmac-sha1"), 1286779327, 300, 12, - fake_data, 16020, 18, 6, fake_data2))); + EXPECT_EQ(0, TSIG(valid_text3).compare(TSIG(Name("hmac-sha1"), 1286779327, 300, 12, + fake_data, 16020, 18, 6, fake_data2))); - EXPECT_THROW(any::TSIG(Name("hmac-sha256"), 1ULL << 48, 300, 12, - fake_data, 16020, 18, 6, fake_data2), + EXPECT_THROW(TSIG(Name("hmac-sha256"), 1ULL << 48, 300, 12, fake_data, 16020, 18, 6, fake_data2), isc::OutOfRange); - EXPECT_THROW(any::TSIG(Name("hmac-sha256"), 0, 300, 0, fake_data, 16020, - 18, 0, NULL), + EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 0, fake_data, 16020, 18, 0, NULL), isc::InvalidParameter); - EXPECT_THROW(any::TSIG(Name("hmac-sha256"), 0, 300, 12, NULL, 16020, - 18, 0, NULL), + EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 12, NULL, 16020, 18, 0, NULL), isc::InvalidParameter); - EXPECT_THROW(any::TSIG(Name("hmac-sha256"), 0, 300, 0, NULL, 16020, - 18, 0, fake_data), + EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 0, NULL, 16020, 18, 0, fake_data), isc::InvalidParameter); - EXPECT_THROW(any::TSIG(Name("hmac-sha256"), 0, 300, 0, NULL, 16020, - 18, 6, NULL), + EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 0, NULL, 16020, 18, 6, NULL), isc::InvalidParameter); } TEST_F(Rdata_TSIG_Test, assignment) { - any::TSIG copy(valid_text2); + TSIG copy(valid_text2); copy = rdata_tsig; EXPECT_EQ(0, copy.compare(rdata_tsig)); // Check if the copied data is valid even after the original is deleted - any::TSIG* copy2 = new any::TSIG(rdata_tsig); - any::TSIG copy3(valid_text2); + TSIG* copy2 = new TSIG(rdata_tsig); + TSIG copy3(valid_text2); copy3 = *copy2; delete copy2; EXPECT_EQ(0, copy3.compare(rdata_tsig)); @@ -350,7 +342,7 @@ Rdata_TSIG_Test::toWireCommonChecks(Output& output) const { expect_data.clear(); output.clear(); - any::TSIG(valid_text2).toWire(output); + TSIG(valid_text2).toWire(output); UnitTestUtil::readWireData("rdata_tsig_toWire2.wire", expect_data); expect_data.erase(expect_data.begin(), expect_data.begin() + 2); matchWireData(&expect_data[0], expect_data.size(), @@ -358,7 +350,7 @@ Rdata_TSIG_Test::toWireCommonChecks(Output& output) const { expect_data.clear(); output.clear(); - any::TSIG(valid_text3).toWire(output); + TSIG(valid_text3).toWire(output); UnitTestUtil::readWireData("rdata_tsig_toWire3.wire", expect_data); expect_data.erase(expect_data.begin(), expect_data.begin() + 2); matchWireData(&expect_data[0], expect_data.size(), @@ -395,32 +387,31 @@ TEST_F(Rdata_TSIG_Test, toWireRenderer) { TEST_F(Rdata_TSIG_Test, toText) { EXPECT_EQ(valid_text1, rdata_tsig.toText()); - EXPECT_EQ(valid_text2, any::TSIG(valid_text2).toText()); - EXPECT_EQ(valid_text3, any::TSIG(valid_text3).toText()); - EXPECT_EQ(valid_text5, any::TSIG(valid_text5).toText()); + EXPECT_EQ(valid_text2, TSIG(valid_text2).toText()); + EXPECT_EQ(valid_text3, TSIG(valid_text3).toText()); + EXPECT_EQ(valid_text5, TSIG(valid_text5).toText()); } TEST_F(Rdata_TSIG_Test, compare) { // test RDATAs, sorted in the ascending order. // "AAAA" encoded in BASE64 corresponds to 0x000000, so it should be the // smallest data of the same length. - vector compare_set; - compare_set.push_back(any::TSIG("a.example 0 300 0 16020 0 0")); - compare_set.push_back(any::TSIG("example 0 300 0 16020 0 0")); - compare_set.push_back(any::TSIG("example 1 300 0 16020 0 0")); - compare_set.push_back(any::TSIG("example 1 600 0 16020 0 0")); - compare_set.push_back(any::TSIG("example 1 600 3 AAAA 16020 0 0")); - compare_set.push_back(any::TSIG("example 1 600 3 FAKE 16020 0 0")); - compare_set.push_back(any::TSIG("example 1 600 3 FAKE 16021 0 0")); - compare_set.push_back(any::TSIG("example 1 600 3 FAKE 16021 1 0")); - compare_set.push_back(any::TSIG("example 1 600 3 FAKE 16021 1 3 AAAA")); - compare_set.push_back(any::TSIG("example 1 600 3 FAKE 16021 1 3 FAKE")); - - EXPECT_EQ(0, compare_set[0].compare( - any::TSIG("A.EXAMPLE 0 300 0 16020 0 0"))); - - vector::const_iterator it; - vector::const_iterator it_end = compare_set.end(); + vector compare_set; + compare_set.push_back(TSIG("a.example 0 300 0 16020 0 0")); + compare_set.push_back(TSIG("example 0 300 0 16020 0 0")); + compare_set.push_back(TSIG("example 1 300 0 16020 0 0")); + compare_set.push_back(TSIG("example 1 600 0 16020 0 0")); + compare_set.push_back(TSIG("example 1 600 3 AAAA 16020 0 0")); + compare_set.push_back(TSIG("example 1 600 3 FAKE 16020 0 0")); + compare_set.push_back(TSIG("example 1 600 3 FAKE 16021 0 0")); + compare_set.push_back(TSIG("example 1 600 3 FAKE 16021 1 0")); + compare_set.push_back(TSIG("example 1 600 3 FAKE 16021 1 3 AAAA")); + compare_set.push_back(TSIG("example 1 600 3 FAKE 16021 1 3 FAKE")); + + EXPECT_EQ(0, compare_set[0].compare(TSIG("A.EXAMPLE 0 300 0 16020 0 0"))); + + vector::const_iterator it; + vector::const_iterator it_end = compare_set.end(); for (it = compare_set.begin(); it != it_end - 1; ++it) { EXPECT_GT(0, (*it).compare(*(it + 1))); EXPECT_LT(0, (*(it + 1)).compare(*it)); diff --git a/src/lib/dns/tests/tsig_unittest.cc b/src/lib/dns/tests/tsig_unittest.cc index 85b75532c9..e1a537c328 100644 --- a/src/lib/dns/tests/tsig_unittest.cc +++ b/src/lib/dns/tests/tsig_unittest.cc @@ -42,6 +42,7 @@ using namespace isc::dns; using namespace isc::util; using namespace isc::util::encode; using namespace isc::dns::rdata; +using namespace isc::dns::rdata::any; using isc::UnitTestUtil; using isc::util::unittests::matchWireData; @@ -88,10 +89,8 @@ protected: badkey_name("badkey.example.com"), test_class(RRClass::IN()), test_ttl(86400), message(Message::RENDER), dummy_data(1024, 0xdd), // should be sufficiently large for all tests - dummy_record(badkey_name, any::TSIG(TSIGKey::HMACMD5_NAME(), - 0x4da8877a, - TSIGContext::DEFAULT_FUDGE, - 0, NULL, qid, 0, 0, NULL)) + dummy_record(badkey_name, TSIG(TSIGKey::HMACMD5_NAME(), 0x4da8877a, + TSIGContext::DEFAULT_FUDGE, 0, NULL, qid, 0, 0, NULL)) { // Make sure we use the system time by default so that we won't be // confused due to other tests that tweak the time. @@ -217,7 +216,7 @@ commonSignChecks(ConstTSIGRecordPtr tsig, uint16_t expected_qid, const Name& expected_algorithm = TSIGKey::HMACMD5_NAME()) { ASSERT_TRUE(tsig != NULL); - const any::TSIG& tsig_rdata = tsig->getRdata(); + const TSIG& tsig_rdata = tsig->getRdata(); EXPECT_EQ(expected_algorithm, tsig_rdata.getAlgorithm()); EXPECT_EQ(expected_timesigned, tsig_rdata.getTimeSigned()); @@ -357,7 +356,7 @@ TEST_F(TSIGTest, signAtActualTime) { SCOPED_TRACE("Sign test for query at actual time"); ConstTSIGRecordPtr tsig = createMessageAndSign(qid, test_name, tsig_ctx.get()); - const any::TSIG& tsig_rdata = tsig->getRdata(); + const TSIG& tsig_rdata = tsig->getRdata(); // Check the resulted time signed is in the range of [now, now + 5] // (5 is an arbitrary choice). Note that due to the order of the call @@ -790,11 +789,10 @@ TEST_F(TSIGTest, badkeyForResponse) { } // A similar case with a different algorithm - const TSIGRecord dummy_record2(test_name, - any::TSIG(TSIGKey::HMACSHA1_NAME(), - 0x4da8877a, - TSIGContext::DEFAULT_FUDGE, - 0, NULL, qid, 0, 0, NULL)); + const TSIGRecord dummy_record2(test_name, TSIG(TSIGKey::HMACSHA1_NAME(), + 0x4da8877a, + TSIGContext::DEFAULT_FUDGE, + 0, NULL, qid, 0, 0, NULL)); { SCOPED_TRACE("Verify a response resulting in BADKEY due to bad alg"); commonVerifyChecks(*tsig_ctx, &dummy_record2, &dummy_data[0], diff --git a/src/lib/dns/tests/tsigrecord_unittest.cc b/src/lib/dns/tests/tsigrecord_unittest.cc index d2686feb7c..69b330b349 100644 --- a/src/lib/dns/tests/tsigrecord_unittest.cc +++ b/src/lib/dns/tests/tsigrecord_unittest.cc @@ -29,6 +29,7 @@ using namespace std; using namespace isc::util; using namespace isc::dns; using namespace isc::dns::rdata; +using namespace isc::dns::rdata::any; using isc::UnitTestUtil; using isc::util::unittests::matchWireData; @@ -37,19 +38,24 @@ class TSIGRecordTest : public ::testing::Test { protected: TSIGRecordTest() : test_name("www.example.com"), test_mac(16, 0xda), - test_rdata(any::TSIG(TSIGKey::HMACMD5_NAME(), 0x4da8877a, - TSIGContext::DEFAULT_FUDGE, - test_mac.size(), &test_mac[0], - 0x2d65, 0, 0, NULL)), + test_rdata(TSIG(TSIGKey::HMACMD5_NAME(), 0x4da8877a, TSIGContext::DEFAULT_FUDGE, + test_mac.size(), &test_mac[0], 0x2d65, 0, 0, NULL)), test_record(test_name, test_rdata), - buffer(0) - {} + buffer(0) { + } + const Name test_name; + vector test_mac; - const any::TSIG test_rdata; + + const TSIG test_rdata; + const TSIGRecord test_record; + OutputBuffer buffer; + MessageRenderer renderer; + vector data; }; diff --git a/src/lib/util/tests/bigint_unittest.cc b/src/lib/util/tests/bigint_unittest.cc index 01d3463f1b..fef8cba035 100644 --- a/src/lib/util/tests/bigint_unittest.cc +++ b/src/lib/util/tests/bigint_unittest.cc @@ -37,7 +37,7 @@ TEST(BigintTest, int128) { EXPECT_EQ(16, int128_t(65) / int128_t(4)); // Check that dividing by zero throws. - EXPECT_THROW_MSG(int128_t(1) / 0, std::overflow_error, "Division by zero."); + EXPECT_THROW_MSG(int128_t(1) / 0, std::overflow_error, "Integer Division by zero."); // Check that underflowing results in a negative number for int128_t. EXPECT_EQ(-1, int128_t(0) - 1); @@ -73,7 +73,7 @@ TEST(BigintTest, uint128) { EXPECT_EQ(16, uint128_t(65) / uint128_t(4)); // Check that dividing by zero throws. - EXPECT_THROW_MSG(uint128_t(1) / 0, std::overflow_error, "Division by zero."); + EXPECT_THROW_MSG(uint128_t(1) / 0, std::overflow_error, "Integer Division by zero."); // Check that underflowing results in a positive number for uint128_t. EXPECT_LT(0, uint128_t(0) - 1);