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

cmcfarlen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 97c5a8108b Fix check for tcp_info struct (#12128)
97c5a8108b is described below

commit 97c5a8108bb495fa943fc8550fb6121c8f8a4179
Author: Chris McFarlen <[email protected]>
AuthorDate: Fri Mar 28 18:14:23 2025 -0500

    Fix check for tcp_info struct (#12128)
---
 CMakeLists.txt                       |  4 ++--
 include/cripts/Connections.hpp       | 14 +++++++++++++-
 plugins/header_rewrite/conditions.cc |  2 +-
 src/cripts/Connections.cc            |  5 +++--
 4 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b26d0e209d..ecdcd8d799 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -532,9 +532,9 @@ check_cxx_source_compiles(
   HAVE_CRYPTO_EX_DUP_TYPE1
 )
 
-set(CMAKE_REQUIRED_INCLUDES netinet/in.h netinet/tcp.h)
+set(CMAKE_EXTRA_INCLUDE_FILES netinet/in.h netinet/tcp.h)
 check_type_size("struct tcp_info" STRUCT_TCP_INFO)
-unset(CMAKE_REQUIRED_INCLUDES)
+unset(CMAKE_EXTRA_INCLUDE_FILES)
 
 # Since Linux 2.6.12
 check_struct_has_member("struct tcp_info" tcpi_total_retrans "linux/tcp.h" 
HAVE_STRUCT_TCP_INFO_TCPI_TOTAL_RETRANS)
diff --git a/include/cripts/Connections.hpp b/include/cripts/Connections.hpp
index 9d2422ff77..37b645bbeb 100644
--- a/include/cripts/Connections.hpp
+++ b/include/cripts/Connections.hpp
@@ -28,6 +28,18 @@ class Context;
 #include "cripts/Lulu.hpp"
 #include "cripts/Matcher.hpp"
 
+// This is figured out in this way because
+// this header has to be available to include
+// from cripts scripts that won't have access
+// to ink_platform.h.
+#if __has_include("linux/tcp.h")
+#include "linux/tcp.h"
+#define HAS_TCP_INFO 1
+#elif __has_include("netinet/tcp.h") && !defined(__APPLE__)
+#include "netinet/tcp.h"
+#define HAS_TCP_INFO 1
+#endif
+
 namespace cripts
 {
 namespace Net
@@ -220,7 +232,7 @@ class ConnBase
     }
 
 // ToDo: Add more member accesses? Tthe underlying info makes it hard to make 
it cross platform
-#if defined(TCP_INFO) && defined(HAVE_STRUCT_TCP_INFO)
+#if HAS_TCP_INFO
     integer
     rtt()
     {
diff --git a/plugins/header_rewrite/conditions.cc 
b/plugins/header_rewrite/conditions.cc
index 9422f5d3f9..1858735d1f 100644
--- a/plugins/header_rewrite/conditions.cc
+++ b/plugins/header_rewrite/conditions.cc
@@ -1275,7 +1275,7 @@ ConditionTcpInfo::eval(const Resources &res)
 }
 
 void
-ConditionTcpInfo::append_value(std::string &s, Resources const & /* res 
ATS_UNUSED */)
+ConditionTcpInfo::append_value(std::string &s, [[maybe_unused]] Resources 
const &res)
 {
 #if defined(TCP_INFO) && defined(HAVE_STRUCT_TCP_INFO)
   if (TSHttpTxnIsInternal(res.txnp)) {
diff --git a/src/cripts/Connections.cc b/src/cripts/Connections.cc
index 997e7fe2ce..98001cb03d 100644
--- a/src/cripts/Connections.cc
+++ b/src/cripts/Connections.cc
@@ -19,6 +19,7 @@
 #include "cripts/Lulu.hpp"
 #include "cripts/Preamble.hpp"
 #include <arpa/inet.h>
+#include "tscore/ink_platform.h"
 
 constexpr unsigned NORMALIZED_TIME_QUANTUM = 3600; // 1 hour
 
@@ -77,9 +78,9 @@ detail::ConnBase::TcpInfo::Log()
   if (_ready) {
     // A lot of this is taken verbatim from header_rewrite, may want to 
rewrite this with sstreams
 #if HAVE_STRUCT_TCP_INFO_TCPI_TOTAL_RETRANS
-    _logging = fmt::format("{};{};{};{}", info.tcpi_rtt, info.tcpi_rto, 
info.tcpi_snd_cwnd, info.tcpi_retrans);
+    _logging = cripts::string(format("{};{};{};{}", info.tcpi_rtt, 
info.tcpi_rto, info.tcpi_snd_cwnd, info.tcpi_retrans));
 #elif HAVE_STRUCT_TCP_INFO___TCPI_RETRANS
-    _logging = fmt::format("{};{};{};{}", info.tcpi_rtt, info.tcpi_rto, 
info.tcpi_snd_cwnd, info.__tcpi_retrans);
+    _logging = cripts::string(fmt::format("{};{};{};{}", info.tcpi_rtt, 
info.tcpi_rto, info.tcpi_snd_cwnd, info.__tcpi_retrans));
 #endif
   }
 

Reply via email to