diff --git a/CMakeLists.txt b/CMakeLists.txt index b26d0e209d9..ecdcd8d7999 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 9d2422ff77c..37b645bbeb7 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 9422f5d3f90..1858735d1f6 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 997e7fe2ce6..98001cb03de 100644 --- a/src/cripts/Connections.cc +++ b/src/cripts/Connections.cc @@ -19,6 +19,7 @@ #include "cripts/Lulu.hpp" #include "cripts/Preamble.hpp" #include +#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 }