]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2830] use uint128_t for random prefix allocation
authorRazvan Becheriu <razvan@isc.org>
Thu, 8 Jun 2023 13:33:19 +0000 (16:33 +0300)
committerRazvan Becheriu <razvan@isc.org>
Wed, 21 Jun 2023 12:06:06 +0000 (15:06 +0300)
13 files changed:
src/lib/asiolink/addr_utilities.cc
src/lib/asiolink/addr_utilities.h
src/lib/asiolink/tests/addr_utilities_unittest.cc
src/lib/dhcpsrv/ip_range_permutation.cc
src/lib/dhcpsrv/ip_range_permutation.h
src/lib/dhcpsrv/pool.cc
src/lib/dhcpsrv/pool.h
src/lib/dhcpsrv/tests/mysql_lease_extended_info_unittest.cc
src/lib/dhcpsrv/tests/pgsql_lease_extended_info_unittest.cc
src/lib/dns/tests/rdata_tsig_unittest.cc
src/lib/dns/tests/tsig_unittest.cc
src/lib/dns/tests/tsigrecord_unittest.cc
src/lib/util/tests/bigint_unittest.cc

index 78fd3bfa898df089e02e31ce902c5451276f0b99..438eacb5575a3557f8572149269881a54f8006fa 100644 (file)
@@ -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<uint8_t> offset_bytes(8);
+    std::vector<uint8_t> offset_bytes(16);
     for (int offset_idx = offset_bytes.size() - 1; offset_idx >= 0; --offset_idx) {
-        offset_bytes[offset_idx] = static_cast<uint8_t>(offset & 0x00000000000000ff);
+        offset_bytes[offset_idx] = static_cast<uint8_t>(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<uint16_t>(addr_bytes[i+8]) + carry;
+        uint16_t sum = static_cast<uint16_t>(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<uint16_t>(offset_bytes[i]);
-        }
+        sum += static_cast<uint16_t>(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]));
 }
 
-
-};
-};
+}
+}
index c305f75c594c475442776bfdc956ddcae1b479f2..87f356c7bb77de3360245883bd662988dd37643d 100644 (file)
@@ -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
index 2fa91d67c317e8b746bdf8f72dffd9eb8e6bcf9f..30a98170da0d2e46d013f6aabbbfc81dd44a6949 100644 (file)
@@ -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
index 183ce966839a88eb5eee4bff090523413735c609..78768f3226816e3a37e822a9fc5402b8993740e4 100644 (file)
@@ -23,7 +23,7 @@ IPRangePermutation::IPRangePermutation(const AddressRange& range)
 }
 
 IPRangePermutation::IPRangePermutation(const PrefixRange& range)
-    : range_start_(range.start_), step_(static_cast<uint64_t>(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<uint64_t> dist(0, cursor_ - 1);
+    std::uniform_int_distribution<uint64_t> dist(0, static_cast<uint64_t>(cursor_ - 1));
     auto next_loc = dist(generator_);
 
     IOAddress next_loc_address = IOAddress::IPV4_ZERO_ADDRESS();
index 93cbb096f228f0bac9be65c668ef665a524f2568..cb4c0bdc72911a5961575f468bc1c009e96e8943 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <asiolink/io_address.h>
 #include <dhcpsrv/ip_range.h>
+#include <util/bigints.h>
 
 #include <boost/shared_ptr.hpp>
 
@@ -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<uint64_t, asiolink::IOAddress> state_;
+    std::unordered_map<isc::util::uint128_t, asiolink::IOAddress> 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.
index 177513e7e3c08215a80cee8983e94071ee086de4..4d9f38124967ce0de8565eb8963952eff4a31889 100644 (file)
@@ -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 {
index f004dc5524fdd5153586875cacc488e3264acc60..0015bb1e8294a64299666e39cfed91564e6d300a 100644 (file)
@@ -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;
index fc077f5f6fadf34c17d9abfbe7952779668b5a92..6ada1aaeb20b859ba9fee7ddb94b635a9a0bca9a 100644 (file)
@@ -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];
index 1bd829142811fcf0f28f06ecd7cf779bb755e4c3..9c4f36484ca3e91b4cebe01a5ff11fb495f36050 100644 (file)
@@ -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];
index 7b45b3b836ae1a625c8348fcc3906f22df0ac7cc..e98b11b00d818eb67a4af27c1585e2cd5ae6234a 100644 (file)
@@ -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<any::TSIG, isc::Exception, isc::Exception>(
+        checkFromText<TSIG, isc::Exception, isc::Exception>(
             rdata_str, rdata_tsig, false, false);
     }
 
     void checkFromText_InvalidText(const string& rdata_str) {
-        checkFromText<any::TSIG, InvalidRdataText, InvalidRdataText>(
+        checkFromText<TSIG, InvalidRdataText, InvalidRdataText>(
             rdata_str, rdata_tsig, true, true);
     }
 
     void checkFromText_BadValue(const string& rdata_str) {
-        checkFromText<any::TSIG, BadValue, BadValue>(
+        checkFromText<TSIG, BadValue, BadValue>(
             rdata_str, rdata_tsig, true, true);
     }
 
     void checkFromText_LexerError(const string& rdata_str) {
         checkFromText
-            <any::TSIG, InvalidRdataText, MasterLexer::LexerError>(
+            <TSIG, InvalidRdataText, MasterLexer::LexerError>(
                 rdata_str, rdata_tsig, true, true);
     }
 
     void checkFromText_TooLongLabel(const string& rdata_str) {
-        checkFromText<any::TSIG, TooLongLabel, TooLongLabel>(
+        checkFromText<TSIG, TooLongLabel, TooLongLabel>(
             rdata_str, rdata_tsig, true, true);
     }
 
     void checkFromText_EmptyLabel(const string& rdata_str) {
-        checkFromText<any::TSIG, EmptyLabel, EmptyLabel>(
+        checkFromText<TSIG, EmptyLabel, EmptyLabel>(
             rdata_str, rdata_tsig, true, true);
     }
 
     void checkFromText_BadString(const string& rdata_str) {
         checkFromText
-            <any::TSIG, InvalidRdataText, isc::Exception>(
+            <TSIG, InvalidRdataText, isc::Exception>(
                 rdata_str, rdata_tsig, true, false);
     }
 
@@ -102,7 +103,7 @@ protected:
     const string valid_text4;
     const string valid_text5;
     vector<uint8_t> 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<void*>(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<any::TSIG&>(*rdata));
+    fromWireCommonChecks(dynamic_cast<TSIG&>(*rdata));
 }
 
 TEST_F(Rdata_TSIG_Test, createFromWireWithOtherData) {
     RdataPtr rdata(rdataFactoryFromFile(RRType::TSIG(), RRClass::ANY(),
                                         "rdata_tsig_fromWire2.wire"));
-    const any::TSIG& tsig(dynamic_cast<any::TSIG&>(*rdata));
+    const TSIG& tsig(dynamic_cast<TSIG&>(*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<any::TSIG&>(*rdata));
+    const TSIG& tsig(dynamic_cast<TSIG&>(*rdata));
     EXPECT_EQ(16, tsig.getError());
     EXPECT_EQ(0, tsig.getMACSize());
     EXPECT_EQ(static_cast<const void*>(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<any::TSIG&>(*rdata));
+    fromWireCommonChecks(dynamic_cast<TSIG&>(*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<any::TSIG> 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<any::TSIG>::const_iterator it;
-    vector<any::TSIG>::const_iterator it_end = compare_set.end();
+    vector<TSIG> 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<TSIG>::const_iterator it;
+    vector<TSIG>::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));
index 85b75532c9b7bd40af3da33922ab504fed8c0689..e1a537c32829c8f1502b3e2019fe17dffce2da7e 100644 (file)
@@ -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],
index d2686feb7c8ecb727223f508d6e80e1c9b539cd9..69b330b34902ee23506288775093b1139db48858 100644 (file)
@@ -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<unsigned char> test_mac;
-    const any::TSIG test_rdata;
+
+    const TSIG test_rdata;
+
     const TSIGRecord test_record;
+
     OutputBuffer buffer;
+
     MessageRenderer renderer;
+
     vector<unsigned char> data;
 };
 
index 01d3463f1b34f24983a99c14372cba8458d50109..fef8cba035242a9b40f6120237879abdefc3d538 100644 (file)
@@ -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);