You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bn...@apache.org on 2024/01/30 16:27:01 UTC

(trafficserver-libswoc) branch dev-1-0-10 created (now 9d62d22)

This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch dev-1-0-10
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


      at 9d62d22  Fix BWF conflict between unsigned and in_addr_t. Be thorough about IP4 address stored in host order.

This branch includes the following new commits:

     new 73955d8  Fix unit test problems.
     new bd4a054  Update to 1.0.10
     new 9d62d22  Fix BWF conflict between unsigned and in_addr_t. Be thorough about IP4 address stored in host order.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(trafficserver-libswoc) 03/03: Fix BWF conflict between unsigned and in_addr_t. Be thorough about IP4 address stored in host order.

Posted by bn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-10
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 9d62d2210a0919edfe7580d6439d470334dbe161
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Thu Jan 30 16:01:13 2020 -0600

    Fix BWF conflict between unsigned and in_addr_t.
    Be thorough about IP4 address stored in host order.
---
 swoc++/include/swoc/bwf_ip.h  |  6 +-----
 swoc++/include/swoc/swoc_ip.h | 15 ++++++++++++---
 swoc++/src/bw_ip_format.cc    |  6 +++---
 unit_tests/test_ip.cc         | 27 +++++++++++++++++++++++----
 4 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/swoc++/include/swoc/bwf_ip.h b/swoc++/include/swoc/bwf_ip.h
index be1fa46..2b19d7f 100644
--- a/swoc++/include/swoc/bwf_ip.h
+++ b/swoc++/include/swoc/bwf_ip.h
@@ -28,8 +28,8 @@ namespace swoc
 {
 // All of these expect the address to be in network order.
 BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, sockaddr const *addr);
-BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, in_addr_t addr);
 BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, in6_addr const &addr);
+BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, IP4Addr const &addr);
 BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, IPAddr const &addr);
 BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, sockaddr const *addr);
 
@@ -38,8 +38,4 @@ bwformat(BufferWriter &w, bwf::Spec const &spec, IPEndpoint const &addr) {
   return bwformat(w, spec, &addr.sa);
 }
 
-inline BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, IP4Addr const& addr) {
-  return bwformat(w, spec, addr.network_order());
-}
-
 } // namespace swoc
diff --git a/swoc++/include/swoc/swoc_ip.h b/swoc++/include/swoc/swoc_ip.h
index f440caa..66213cb 100644
--- a/swoc++/include/swoc/swoc_ip.h
+++ b/swoc++/include/swoc/swoc_ip.h
@@ -149,7 +149,7 @@ union IPEndpoint {
 };
 
 /** Storage for an IPv4 address.
-    Stored in network order.
+    Stored in host order.
  */
 class IP4Addr {
   using self_type = IP4Addr; ///< Self reference type.
@@ -185,6 +185,7 @@ public:
   sockaddr *fill(sockaddr_in *sa, in_port_t port = 0) const;
 
   in_addr_t network_order() const;
+  in_addr_t host_order() const;
 
   /** Parse @a text as IPv4 address.
       The address resulting from the parse is copied to this object if the conversion is successful,
@@ -210,13 +211,17 @@ public:
   /// Test for loopback
   bool is_loopback() const;
 
+  constexpr static in_addr_t reorder(in_addr_t src) {
+    return ((src & 0xFF) << 24) | (((src >> 8) & 0xFF) << 16) | (((src >> 16) & 0xFF) << 8) | ((src >> 24) & 0xFF);
+  }
+
 protected:
   friend bool operator==(self_type const &, self_type const &);
   friend bool operator!=(self_type const &, self_type const &);
   friend bool operator<(self_type const &, self_type const &);
   friend bool operator<=(self_type const &, self_type const &);
 
-  in_addr_t _addr = INADDR_ANY;
+  in_addr_t _addr = INADDR_ANY; ///< Address in host order.
 };
 
 /** Storage for an IPv6 address.
@@ -1002,7 +1007,7 @@ IPEndpoint::host_order_port(sockaddr const *addr) {
 
 // --- IPAddr variants ---
 
-inline constexpr IP4Addr::IP4Addr(in_addr_t addr) : _addr(addr) {}
+inline constexpr IP4Addr::IP4Addr(in_addr_t addr) : _addr(reorder(addr)) {}
 
 inline IP4Addr::IP4Addr(std::string_view const& text) {
   if (! this->load(text)) {
@@ -1026,6 +1031,10 @@ inline in_addr_t IP4Addr::network_order() const {
   return htonl(_addr);
 }
 
+inline in_addr_t IP4Addr::host_order() const {
+  return _addr;
+}
+
 inline IP4Addr::operator in_addr_t() const {
   return this->network_order();
 }
diff --git a/swoc++/src/bw_ip_format.cc b/swoc++/src/bw_ip_format.cc
index 0cf041e..14f5c27 100644
--- a/swoc++/src/bw_ip_format.cc
+++ b/swoc++/src/bw_ip_format.cc
@@ -49,9 +49,9 @@ namespace swoc
 using bwf::Spec;
 
 BufferWriter &
-bwformat(BufferWriter &w, Spec const &spec, in_addr_t addr)
+bwformat(BufferWriter &w, Spec const &spec, IP4Addr const& addr)
 {
-  in_addr_t host { ntohl(addr) };
+  in_addr_t host = addr.host_order();
   Spec local_spec{spec}; // Format for address elements.
   bool align_p = false;
 
@@ -253,7 +253,7 @@ bwformat(BufferWriter &w, Spec const &spec, sockaddr const *addr)
     bool bracket_p = false;
     switch (addr->sa_family) {
     case AF_INET:
-      bwformat(w, spec, reinterpret_cast<sockaddr_in const *>(addr)->sin_addr.s_addr);
+      bwformat(w, spec, IP4Addr{reinterpret_cast<sockaddr_in const *>(addr)->sin_addr.s_addr});
       break;
     case AF_INET6:
       if (port_p) {
diff --git a/unit_tests/test_ip.cc b/unit_tests/test_ip.cc
index 7ad662a..285e13f 100644
--- a/unit_tests/test_ip.cc
+++ b/unit_tests/test_ip.cc
@@ -62,7 +62,6 @@ TEST_CASE("ink_inet", "[libswoc][ip]") {
   IP6Addr a6_1{"fe80:88b5:4a:20c:29ff:feae:5587:1c33"};
   IP6Addr a6_2{"fe80:88b5:4a:20c:29ff:feae:5587:1c34"};
   IP6Addr a6_3{"de80:88b5:4a:20c:29ff:feae:5587:1c35"};
-  IP6Addr a6_4{"fe80:88b5:4a:20c:29ff:feae:5587:1c34"};
 
   REQUIRE(a6_1 != a6_null);
   REQUIRE(a6_1 != a6_2);
@@ -73,9 +72,29 @@ TEST_CASE("ink_inet", "[libswoc][ip]") {
   ++a6_1;
   REQUIRE(a6_1 != a6_2);
   REQUIRE(a6_1 > a6_2);
-  REQUIRE(a6_3 != a6_4);
-  REQUIRE(a6_3 < a6_4);
-  REQUIRE(a6_4 > a6_3);
+
+  REQUIRE(a6_3 != a6_2);
+  REQUIRE(a6_3 < a6_2);
+  REQUIRE(a6_2 > a6_3);
+
+  // Little bit of IP4 address arithmetic / comparison testing.
+  IP4Addr a4_null;
+  IP4Addr a4_1{"172.28.56.33"};
+  IP4Addr a4_2{"172.28.56.34"};
+  IP4Addr a4_3{"170.28.56.35"};
+
+  REQUIRE(a4_1 != a4_null);
+  REQUIRE(a4_1 != a4_2);
+  REQUIRE(a4_1 < a4_2);
+  REQUIRE(a4_2 > a4_1);
+  ++a4_1;
+  REQUIRE(a4_1 == a4_2);
+  ++a4_1;
+  REQUIRE(a4_1 != a4_2);
+  REQUIRE(a4_1 > a4_2);
+  REQUIRE(a4_3 != a4_2);
+  REQUIRE(a4_3 < a4_2);
+  REQUIRE(a4_2 > a4_3);
 
   // For this data, the bytes should be in IPv6 network order.
   static const std::tuple<TextView, bool, IP6Addr::raw_type> ipv6_ex[] = {


(trafficserver-libswoc) 01/03: Fix unit test problems.

Posted by bn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-10
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 73955d81f6d7a04a9cadda1958fb796254e0b4b0
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Thu Jan 30 12:45:03 2020 -0600

    Fix unit test problems.
---
 swoc++/include/swoc/DiscreteRange.h | 2 +-
 unit_tests/ex_TextView.cc           | 4 ++--
 unit_tests/test_swoc_file.cc        | 2 +-
 unit_tests/unit_tests.part          | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/swoc++/include/swoc/DiscreteRange.h b/swoc++/include/swoc/DiscreteRange.h
index 21d177e..6838b14 100644
--- a/swoc++/include/swoc/DiscreteRange.h
+++ b/swoc++/include/swoc/DiscreteRange.h
@@ -101,7 +101,7 @@ public:
   using metric_type = T;
   using Relation = DiscreteRangeRelation;
 
-  static constexpr self_type ALL{detail::minimum<metric_type>(), detail::maximum<metric_type>()};
+//  static constexpr self_type ALL{detail::minimum<metric_type>(), detail::maximum<metric_type>()};
 
   /** Default constructor.
       An empty range is constructed.
diff --git a/unit_tests/ex_TextView.cc b/unit_tests/ex_TextView.cc
index 0894a1e..b6b3b25 100644
--- a/unit_tests/ex_TextView.cc
+++ b/unit_tests/ex_TextView.cc
@@ -202,7 +202,7 @@ TEST_CASE("TextView Tokens", "[libswoc][example][textview][tokens]")
 
 TEST_CASE("TextView Lines", "[libswoc][example][textview][lines]")
 {
-  swoc::file::path path{"../doc/conf.py"};
+  swoc::file::path path{"doc/conf.py"};
   std::error_code ec;
 
   auto content   = swoc::file::load(path, ec);
@@ -240,7 +240,7 @@ TEST_CASE("TextView parsing", "[libswoc][example][text][parsing]") {
   swoc::IP4Addr addr;
 
   std::error_code ec;
-  auto data { swoc::file::load("../unit_tests/examples/resolver.txt"_tv, ec) };
+  auto data { swoc::file::load("unit_tests/examples/resolver.txt"_tv, ec) };
   REQUIRE(data.size() > 2); // if this fails, there's something wrong with the path or current directory.
 
   TextView content { data };
diff --git a/unit_tests/test_swoc_file.cc b/unit_tests/test_swoc_file.cc
index b60a616..a3f403c 100644
--- a/unit_tests/test_swoc_file.cc
+++ b/unit_tests/test_swoc_file.cc
@@ -47,7 +47,7 @@ TEST_CASE("swoc_file", "[libts][swoc_file]")
 
 TEST_CASE("swoc_file_io", "[libts][swoc_file_io]")
 {
-  path file("../unit_tests/test_swoc_file.cc");
+  path file("unit_tests/test_swoc_file.cc");
   std::error_code ec;
   std::string content = swoc::file::load(file, ec);
   REQUIRE(ec.value() == 0);
diff --git a/unit_tests/unit_tests.part b/unit_tests/unit_tests.part
index 8f9b304..fd2115e 100644
--- a/unit_tests/unit_tests.part
+++ b/unit_tests/unit_tests.part
@@ -7,7 +7,7 @@ DependsOn([
     ])
 
 env.AppendUnique(
-    CCFLAGS=['-std=c++17'],    
+    CCFLAGS=['-std=c++17'],
 )
 
 files = [
@@ -35,6 +35,6 @@ env.UnitTest(
     "tests",
     files,
     # data file we need for the test to pass
-    data_src=[Pattern(src_dir="#",includes=['doc/conf.py','unit_tests/test_swoc_file.cc'])]
+    data_src=[Pattern(src_dir="#",includes=['doc/conf.py','unit_tests/examples/resolver.txt', 'unit_tests/test_swoc_file.cc'])]
     )
 


(trafficserver-libswoc) 02/03: Update to 1.0.10

Posted by bn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-0-10
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit bd4a0543614fd5549ad6d1bfe17f4259a1234ef4
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Thu Jan 30 12:46:55 2020 -0600

    Update to 1.0.10
---
 doc/Doxyfile                       | 2 +-
 doc/conf.py                        | 2 +-
 swoc++/CMakeLists.txt              | 2 +-
 swoc++/include/swoc/swoc_version.h | 2 +-
 swoc++/swoc++.part                 | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/doc/Doxyfile b/doc/Doxyfile
index f0e766d..53db8ab 100644
--- a/doc/Doxyfile
+++ b/doc/Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NAME           = "LibSWOC++"
 # could be handy for archiving the generated documentation or if some version
 # control system is used.
 
-PROJECT_NUMBER         = "1.0.9"
+PROJECT_NUMBER         = "1.0.10"
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer a
diff --git a/doc/conf.py b/doc/conf.py
index 72bdcf6..f92efbe 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -80,7 +80,7 @@ project = u'Solid Wall Of C++'
 copyright = u'{}, amc@apache.org'.format(date.today().year)
 
 # The full version, including alpha/beta/rc tags.
-release = "1.0.9"
+release = "1.0.10"
 # The short X.Y version.
 version = '.'.join(release.split('.', 2)[:2])
 
diff --git a/swoc++/CMakeLists.txt b/swoc++/CMakeLists.txt
index 81a2c9f..f8a86b3 100644
--- a/swoc++/CMakeLists.txt
+++ b/swoc++/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.12)
 
 project(lib-swoc++ CXX)
-set(LIBSWOC_VERSION "1.0.9")
+set(LIBSWOC_VERSION "1.0.10")
 set(CMAKE_CXX_STANDARD 17)
 include(GNUInstallDirs)
 
diff --git a/swoc++/include/swoc/swoc_version.h b/swoc++/include/swoc/swoc_version.h
index b3f9963..62b5fef 100644
--- a/swoc++/include/swoc/swoc_version.h
+++ b/swoc++/include/swoc/swoc_version.h
@@ -39,5 +39,5 @@ namespace swoc
 {
 static constexpr unsigned MAJOR_VERSION = 1;
 static constexpr unsigned MINOR_VERSION = 0;
-static constexpr unsigned POINT_VERSION = 9;
+static constexpr unsigned POINT_VERSION = 10;
 } // namespace swoc
diff --git a/swoc++/swoc++.part b/swoc++/swoc++.part
index 8d34df8..14818d2 100644
--- a/swoc++/swoc++.part
+++ b/swoc++/swoc++.part
@@ -1,5 +1,5 @@
 Import("*")
-PartVersion("1.0.9")
+PartVersion("1.0.10")
 PartName("swoc++")
 
 files = [