From 2571f336ef3f9c8d0a0c4d4c8bd4c2a2f1f2d117 Mon Sep 17 00:00:00 2001 From: Divya Bhat Date: Wed, 10 Feb 2021 21:21:01 +0000 Subject: [PATCH 01/11] Adding TCP Info header support to header rewrite Adding documentation for TCP Info support for header rewrite plugin --- doc/admin-guide/plugins/header_rewrite.en.rst | 18 +++++ plugins/header_rewrite/conditions.cc | 75 ++++++++++++++++++- plugins/header_rewrite/conditions.h | 22 +++++- plugins/header_rewrite/factory.cc | 2 + plugins/header_rewrite/header_rewrite.cc | 6 ++ plugins/header_rewrite/parser.cc | 8 ++ plugins/header_rewrite/resources.cc | 23 ++++++ plugins/header_rewrite/statement.cc | 2 + 8 files changed, 154 insertions(+), 2 deletions(-) diff --git a/doc/admin-guide/plugins/header_rewrite.en.rst b/doc/admin-guide/plugins/header_rewrite.en.rst index 9db100a735b..de5effec771 100644 --- a/doc/admin-guide/plugins/header_rewrite.en.rst +++ b/doc/admin-guide/plugins/header_rewrite.en.rst @@ -491,6 +491,14 @@ SSN-TXN-COUNT Returns the number of transactions between the Traffic Server proxy and the origin server from a single session. Any value greater than zero indicates connection reuse. +TCPINFO +~~~~~~~~ +:: + cond %{} + add-header @PropertyName ":{%{TCPINFO}}" + +This operation records TCP Info struct field values as an Internal remap as well as global header at the event hook specified by the condition. Supported hook conditions include TXN_START_HOOK, SEND_RESPONSE_HEADER_HOOK and TXN_CLOSE_HOOK in the Global plugin and REMAP_PSEUDO_HOOK, SEND_RESPONSE_HEADER_HOOK and TXN_CLOSE_HOOK in the Remap plugin. TCP Info fields currently recorded include rtt, rto, snd_cwnd and all_retrans. + Condition Operands ------------------ @@ -935,6 +943,16 @@ cache updates may have been performed. This hook context provides a means to modify aspects of the response sent to a client, while still caching the original versions of those attributes delivered by the origin server. +TXN_START_HOOK +~~~~~~~~~~~~~~ + +Rulesets are evaluated when |TS| receives a request and accepts it. This hook context indicates that a HTTP transaction is initiated. + +TXN_CLOSE_HOOK +~~~~~~~~~~~~~~ + +Rulesets are evaluated when |TS| completes a transaction, i.e., after a response has been sent to the client. Therefore, header modifications at this hook condition only makes sense for internal headers. + Affected Conditions ------------------- diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc index 84ce254cf37..4ee0dc62a4d 100644 --- a/plugins/header_rewrite/conditions.cc +++ b/plugins/header_rewrite/conditions.cc @@ -1333,4 +1333,77 @@ ConditionSessionTransactCount::append_value(std::string &s, Resources const &res TSDebug(PLUGIN_NAME, "Appending SSN-TXN-COUNT %s to evaluation value %.*s", _qualifier.c_str(), length, value); s.append(value, length); } -} \ No newline at end of file +} + +void +ConditionTcpInfo::initialize(Parser &p) +{ + Condition::initialize(p); + TSDebug(PLUGIN_NAME, "Initializing TCP Info"); + MatcherType *match = new MatcherType(_cond_op); + std::string const &arg = p.get_arg(); + + match->set(strtol(arg.c_str(), nullptr, 10)); + _matcher = match; +} + +void +ConditionTcpInfo::initialize_hooks() +{ + add_allowed_hook(TS_HTTP_TXN_START_HOOK); + add_allowed_hook(TS_HTTP_TXN_CLOSE_HOOK); + add_allowed_hook(TS_HTTP_SEND_RESPONSE_HDR_HOOK); +} + +bool +ConditionTcpInfo::eval(const Resources &res) +{ + std::string s; + + append_value(s, res); + bool rval = static_cast *>(_matcher)->test(s); + + TSDebug(PLUGIN_NAME, "Evaluating TCP-Info: %s - rval: %d", s.c_str(), rval); + + return rval; +} + +void +ConditionTcpInfo::append_value(std::string &s, Resources const &res) +{ +#if defined(TCP_INFO) && defined(HAVE_STRUCT_TCP_INFO) + TSReturnCode tsSsn; + int fd; + struct tcp_info info; + socklen_t tcp_info_len = sizeof(info); + tsSsn = TSHttpTxnClientFdGet(res.txnp, &fd); + if (tsSsn != TS_SUCCESS || fd <= 0) { + TSDebug(PLUGIN_NAME, "error getting the client socket fd from ssn"); + } + if (getsockopt(fd, IPPROTO_TCP, TCP_INFO, &info, &tcp_info_len) != 0) { + TSDebug(PLUGIN_NAME, "getsockopt(%d, TCP_INFO) failed: %s", fd, strerror(errno)); + } + + if (tsSsn == TS_SUCCESS) { + uint32_t rtt = info.tcpi_rtt; + uint32_t rto = info.tcpi_rto; + uint32_t snd_cwnd = info.tcpi_snd_cwnd; + uint32_t all_retx; +#if !defined(freebsd) || defined(__GLIBC__) + all_retx = info.tcpi_retrans; +#else + all_retx = info.__tcpi_retrans; +#endif + + if (tcp_info_len > 0) { + s += std::to_string(rtt); + s += "; "; + s += std::to_string(rto); + s += "; "; + s += std::to_string(snd_cwnd); + s += "; "; + s += std::to_string(all_retx); + } + } +#endif +} diff --git a/plugins/header_rewrite/conditions.h b/plugins/header_rewrite/conditions.h index 03f42d46437..ed6c61fc9c9 100644 --- a/plugins/header_rewrite/conditions.h +++ b/plugins/header_rewrite/conditions.h @@ -562,4 +562,24 @@ class ConditionSessionTransactCount : public Condition protected: bool eval(const Resources &res) override; -}; \ No newline at end of file +}; + +// Tcp Info +class ConditionTcpInfo : public Condition +{ + typedef Matchers MatcherType; + +public: + ConditionTcpInfo() { TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionTcpInfo"); } + + // noncopyable + ConditionTcpInfo(const ConditionTcpInfo &) = delete; + void operator=(const ConditionTcpInfo &) = delete; + + void initialize(Parser &p) override; + void append_value(std::string &s, const Resources &res) override; + +protected: + bool eval(const Resources &res) override; + void initialize_hooks() override; // Return status only valid in certain hooks +}; diff --git a/plugins/header_rewrite/factory.cc b/plugins/header_rewrite/factory.cc index a5decc71b73..dded4120d00 100644 --- a/plugins/header_rewrite/factory.cc +++ b/plugins/header_rewrite/factory.cc @@ -139,6 +139,8 @@ condition_factory(const std::string &cond) c = new ConditionInbound(); } else if (c_name == "SSN-TXN-COUNT") { c = new ConditionSessionTransactCount(); + } else if (c_name == "TCPINFO") { + c = new ConditionTcpInfo(); } else { TSError("[%s] Unknown condition %s", PLUGIN_NAME, c_name.c_str()); return nullptr; diff --git a/plugins/header_rewrite/header_rewrite.cc b/plugins/header_rewrite/header_rewrite.cc index a0e6707f2fe..85e0feebf72 100644 --- a/plugins/header_rewrite/header_rewrite.cc +++ b/plugins/header_rewrite/header_rewrite.cc @@ -279,6 +279,12 @@ cont_rewrite_headers(TSCont contp, TSEvent event, void *edata) case TS_EVENT_HTTP_SEND_RESPONSE_HDR: hook = TS_HTTP_SEND_RESPONSE_HDR_HOOK; break; + case TS_EVENT_HTTP_TXN_START: + hook = TS_HTTP_TXN_START_HOOK; + break; + case TS_EVENT_HTTP_TXN_CLOSE: + hook = TS_HTTP_TXN_CLOSE_HOOK; + break; default: TSError("[%s] unknown event for this plugin", PLUGIN_NAME); TSDebug(PLUGIN_NAME, "unknown event for this plugin"); diff --git a/plugins/header_rewrite/parser.cc b/plugins/header_rewrite/parser.cc index cb6e2c5cf3c..701227ed6e8 100644 --- a/plugins/header_rewrite/parser.cc +++ b/plugins/header_rewrite/parser.cc @@ -244,6 +244,14 @@ Parser::cond_is_hook(TSHttpHookID &hook) const hook = TS_REMAP_PSEUDO_HOOK; return true; } + if ("TXN_START_HOOK" == _op) { + hook = TS_HTTP_TXN_START_HOOK; + return true; + } + if ("TXN_CLOSE_HOOK" == _op) { + hook = TS_HTTP_TXN_CLOSE_HOOK; + return true; + } return false; } diff --git a/plugins/header_rewrite/resources.cc b/plugins/header_rewrite/resources.cc index bc861c6c2b7..e585512029c 100644 --- a/plugins/header_rewrite/resources.cc +++ b/plugins/header_rewrite/resources.cc @@ -87,6 +87,11 @@ Resources::gather(const ResourceIDs ids, TSHttpHookID hook) TSDebug(PLUGIN_NAME, "\tAdding TXN client response status resource"); resp_status = TSHttpHdrStatusGet(bufp, hdr_loc); } + if (client_bufp && client_hdr_loc) { + TSDebug(PLUGIN_NAME, "\tAdding TXN client response header buffers"); + bufp = client_bufp; + hdr_loc = client_hdr_loc; + } } break; @@ -99,6 +104,24 @@ Resources::gather(const ResourceIDs ids, TSHttpHookID hook) } break; + case TS_HTTP_TXN_START_HOOK: + // Get TCP Info at transaction start + if (client_bufp && client_hdr_loc) { + TSDebug(PLUGIN_NAME, "\tAdding TXN Start header buffers"); + bufp = client_bufp; + hdr_loc = client_hdr_loc; + } + break; + + case TS_HTTP_TXN_CLOSE_HOOK: + // Get TCP Info at transaction close + if (client_bufp && client_hdr_loc) { + TSDebug(PLUGIN_NAME, "\tAdding TXN Close header buffers"); + bufp = client_bufp; + hdr_loc = client_hdr_loc; + } + break; + default: break; } diff --git a/plugins/header_rewrite/statement.cc b/plugins/header_rewrite/statement.cc index ee342dc8adc..fd2c17f40a7 100644 --- a/plugins/header_rewrite/statement.cc +++ b/plugins/header_rewrite/statement.cc @@ -69,6 +69,8 @@ Statement::initialize_hooks() add_allowed_hook(TS_HTTP_SEND_REQUEST_HDR_HOOK); add_allowed_hook(TS_HTTP_SEND_RESPONSE_HDR_HOOK); add_allowed_hook(TS_REMAP_PSEUDO_HOOK); + add_allowed_hook(TS_HTTP_TXN_START_HOOK); + add_allowed_hook(TS_HTTP_TXN_CLOSE_HOOK); } // Parse URL qualifiers, this one is special since it's used in a few places. From c7a6d41f9e1914e19fc3565a291cca3329684667 Mon Sep 17 00:00:00 2001 From: Divya Bhat Date: Wed, 10 Feb 2021 21:21:01 +0000 Subject: [PATCH 02/11] Adding TCP Info header support to header rewrite Adding documentation for TCP Info support for header rewrite plugin --- doc/admin-guide/plugins/header_rewrite.en.rst | 18 +++++ plugins/header_rewrite/conditions.cc | 69 ++++++++++++++++++- plugins/header_rewrite/conditions.h | 22 +++++- plugins/header_rewrite/factory.cc | 2 + plugins/header_rewrite/header_rewrite.cc | 6 ++ plugins/header_rewrite/parser.cc | 8 +++ plugins/header_rewrite/resources.cc | 23 +++++++ plugins/header_rewrite/statement.cc | 2 + 8 files changed, 148 insertions(+), 2 deletions(-) diff --git a/doc/admin-guide/plugins/header_rewrite.en.rst b/doc/admin-guide/plugins/header_rewrite.en.rst index 9db100a735b..a6bc410cb1e 100644 --- a/doc/admin-guide/plugins/header_rewrite.en.rst +++ b/doc/admin-guide/plugins/header_rewrite.en.rst @@ -491,6 +491,14 @@ SSN-TXN-COUNT Returns the number of transactions between the Traffic Server proxy and the origin server from a single session. Any value greater than zero indicates connection reuse. +TCP-INFO +~~~~~~~~ +:: + cond %{} + add-header @PropertyName "%{TCP-INFO}" + +This operation records TCP Info struct field values as an Internal remap as well as global header at the event hook specified by the condition. Supported hook conditions include TXN_START_HOOK, SEND_RESPONSE_HEADER_HOOK and TXN_CLOSE_HOOK in the Global plugin and REMAP_PSEUDO_HOOK, SEND_RESPONSE_HEADER_HOOK and TXN_CLOSE_HOOK in the Remap plugin. TCP Info fields currently recorded include rtt, rto, snd_cwnd and all_retrans. + Condition Operands ------------------ @@ -935,6 +943,16 @@ cache updates may have been performed. This hook context provides a means to modify aspects of the response sent to a client, while still caching the original versions of those attributes delivered by the origin server. +TXN_START_HOOK +~~~~~~~~~~~~~~ + +Rulesets are evaluated when |TS| receives a request and accepts it. This hook context indicates that a HTTP transaction is initiated and therefore, can only be enabled as a global plugin. + +TXN_CLOSE_HOOK +~~~~~~~~~~~~~~ + +Rulesets are evaluated when |TS| completes a transaction, i.e., after a response has been sent to the client. Therefore, header modifications at this hook condition only makes sense for internal headers. + Affected Conditions ------------------- diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc index 84ce254cf37..f39e7f1606e 100644 --- a/plugins/header_rewrite/conditions.cc +++ b/plugins/header_rewrite/conditions.cc @@ -1333,4 +1333,71 @@ ConditionSessionTransactCount::append_value(std::string &s, Resources const &res TSDebug(PLUGIN_NAME, "Appending SSN-TXN-COUNT %s to evaluation value %.*s", _qualifier.c_str(), length, value); s.append(value, length); } -} \ No newline at end of file +} + +void +ConditionTcpInfo::initialize(Parser &p) +{ + Condition::initialize(p); + TSDebug(PLUGIN_NAME, "Initializing TCP Info"); + MatcherType *match = new MatcherType(_cond_op); + std::string const &arg = p.get_arg(); + + match->set(strtol(arg.c_str(), nullptr, 10)); + _matcher = match; +} + +void +ConditionTcpInfo::initialize_hooks() +{ + add_allowed_hook(TS_HTTP_TXN_START_HOOK); + add_allowed_hook(TS_HTTP_TXN_CLOSE_HOOK); + add_allowed_hook(TS_HTTP_SEND_RESPONSE_HDR_HOOK); +} + +bool +ConditionTcpInfo::eval(const Resources &res) +{ + std::string s; + + append_value(s, res); + bool rval = static_cast *>(_matcher)->test(s); + + TSDebug(PLUGIN_NAME, "Evaluating TCP-Info: %s - rval: %d", s.c_str(), rval); + + return rval; +} + +void +ConditionTcpInfo::append_value(std::string &s, Resources const &res) +{ +#if defined(TCP_INFO) && defined(HAVE_STRUCT_TCP_INFO) + TSReturnCode tsSsn; + int fd; + struct tcp_info info; + socklen_t tcp_info_len = sizeof(info); + tsSsn = TSHttpTxnClientFdGet(res.txnp, &fd); + if (tsSsn != TS_SUCCESS || fd <= 0) { + TSDebug(PLUGIN_NAME, "error getting the client socket fd from ssn"); + } + if (getsockopt(fd, IPPROTO_TCP, TCP_INFO, &info, &tcp_info_len) != 0) { + TSDebug(PLUGIN_NAME, "getsockopt(%d, TCP_INFO) failed: %s", fd, strerror(errno)); + } + + if (tsSsn == TS_SUCCESS) { + if (tcp_info_len > 0) { + char buf[12 * 4 + 9]; // 4x uint32's + 4x "; " + '\0' +#if !defined(freebsd) || defined(__GLIBC__) + snprintf(buf, sizeof(buf), "%" PRIu32 ";%" PRIu32 ";%" PRIu32 ";%" PRIu32 "", info.tcpi_rtt, info.tcpi_rto, + info.tcpi_snd_cwnd, info.tcpi_retrans); +#else + snprintf(buf, sizeof(buf), "%" PRIu32 ";%" PRIu32 ";%" PRIu32 ";%" PRIu32 "", info.tcpi_rtt, info.tcpi_rto, + info.tcpi_snd_cwnd, info.__tcpi_retrans); +#endif + s += buf; + } + } +#else + s += "-"; +#endif +} diff --git a/plugins/header_rewrite/conditions.h b/plugins/header_rewrite/conditions.h index 03f42d46437..ed6c61fc9c9 100644 --- a/plugins/header_rewrite/conditions.h +++ b/plugins/header_rewrite/conditions.h @@ -562,4 +562,24 @@ class ConditionSessionTransactCount : public Condition protected: bool eval(const Resources &res) override; -}; \ No newline at end of file +}; + +// Tcp Info +class ConditionTcpInfo : public Condition +{ + typedef Matchers MatcherType; + +public: + ConditionTcpInfo() { TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionTcpInfo"); } + + // noncopyable + ConditionTcpInfo(const ConditionTcpInfo &) = delete; + void operator=(const ConditionTcpInfo &) = delete; + + void initialize(Parser &p) override; + void append_value(std::string &s, const Resources &res) override; + +protected: + bool eval(const Resources &res) override; + void initialize_hooks() override; // Return status only valid in certain hooks +}; diff --git a/plugins/header_rewrite/factory.cc b/plugins/header_rewrite/factory.cc index a5decc71b73..26f9a4f7454 100644 --- a/plugins/header_rewrite/factory.cc +++ b/plugins/header_rewrite/factory.cc @@ -139,6 +139,8 @@ condition_factory(const std::string &cond) c = new ConditionInbound(); } else if (c_name == "SSN-TXN-COUNT") { c = new ConditionSessionTransactCount(); + } else if (c_name == "TCP-INFO") { + c = new ConditionTcpInfo(); } else { TSError("[%s] Unknown condition %s", PLUGIN_NAME, c_name.c_str()); return nullptr; diff --git a/plugins/header_rewrite/header_rewrite.cc b/plugins/header_rewrite/header_rewrite.cc index a0e6707f2fe..85e0feebf72 100644 --- a/plugins/header_rewrite/header_rewrite.cc +++ b/plugins/header_rewrite/header_rewrite.cc @@ -279,6 +279,12 @@ cont_rewrite_headers(TSCont contp, TSEvent event, void *edata) case TS_EVENT_HTTP_SEND_RESPONSE_HDR: hook = TS_HTTP_SEND_RESPONSE_HDR_HOOK; break; + case TS_EVENT_HTTP_TXN_START: + hook = TS_HTTP_TXN_START_HOOK; + break; + case TS_EVENT_HTTP_TXN_CLOSE: + hook = TS_HTTP_TXN_CLOSE_HOOK; + break; default: TSError("[%s] unknown event for this plugin", PLUGIN_NAME); TSDebug(PLUGIN_NAME, "unknown event for this plugin"); diff --git a/plugins/header_rewrite/parser.cc b/plugins/header_rewrite/parser.cc index cb6e2c5cf3c..701227ed6e8 100644 --- a/plugins/header_rewrite/parser.cc +++ b/plugins/header_rewrite/parser.cc @@ -244,6 +244,14 @@ Parser::cond_is_hook(TSHttpHookID &hook) const hook = TS_REMAP_PSEUDO_HOOK; return true; } + if ("TXN_START_HOOK" == _op) { + hook = TS_HTTP_TXN_START_HOOK; + return true; + } + if ("TXN_CLOSE_HOOK" == _op) { + hook = TS_HTTP_TXN_CLOSE_HOOK; + return true; + } return false; } diff --git a/plugins/header_rewrite/resources.cc b/plugins/header_rewrite/resources.cc index bc861c6c2b7..e585512029c 100644 --- a/plugins/header_rewrite/resources.cc +++ b/plugins/header_rewrite/resources.cc @@ -87,6 +87,11 @@ Resources::gather(const ResourceIDs ids, TSHttpHookID hook) TSDebug(PLUGIN_NAME, "\tAdding TXN client response status resource"); resp_status = TSHttpHdrStatusGet(bufp, hdr_loc); } + if (client_bufp && client_hdr_loc) { + TSDebug(PLUGIN_NAME, "\tAdding TXN client response header buffers"); + bufp = client_bufp; + hdr_loc = client_hdr_loc; + } } break; @@ -99,6 +104,24 @@ Resources::gather(const ResourceIDs ids, TSHttpHookID hook) } break; + case TS_HTTP_TXN_START_HOOK: + // Get TCP Info at transaction start + if (client_bufp && client_hdr_loc) { + TSDebug(PLUGIN_NAME, "\tAdding TXN Start header buffers"); + bufp = client_bufp; + hdr_loc = client_hdr_loc; + } + break; + + case TS_HTTP_TXN_CLOSE_HOOK: + // Get TCP Info at transaction close + if (client_bufp && client_hdr_loc) { + TSDebug(PLUGIN_NAME, "\tAdding TXN Close header buffers"); + bufp = client_bufp; + hdr_loc = client_hdr_loc; + } + break; + default: break; } diff --git a/plugins/header_rewrite/statement.cc b/plugins/header_rewrite/statement.cc index ee342dc8adc..fd2c17f40a7 100644 --- a/plugins/header_rewrite/statement.cc +++ b/plugins/header_rewrite/statement.cc @@ -69,6 +69,8 @@ Statement::initialize_hooks() add_allowed_hook(TS_HTTP_SEND_REQUEST_HDR_HOOK); add_allowed_hook(TS_HTTP_SEND_RESPONSE_HDR_HOOK); add_allowed_hook(TS_REMAP_PSEUDO_HOOK); + add_allowed_hook(TS_HTTP_TXN_START_HOOK); + add_allowed_hook(TS_HTTP_TXN_CLOSE_HOOK); } // Parse URL qualifiers, this one is special since it's used in a few places. From 5fafcbf1fe85e7e9ffd0b60f9ba6b502c957c2cf Mon Sep 17 00:00:00 2001 From: Divyashri Bhat Date: Tue, 9 Mar 2021 10:19:28 -0800 Subject: [PATCH 03/11] fixing indentation in doc --- doc/admin-guide/plugins/header_rewrite.en.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/admin-guide/plugins/header_rewrite.en.rst b/doc/admin-guide/plugins/header_rewrite.en.rst index ecd2a6ee92d..bc46a63dd05 100644 --- a/doc/admin-guide/plugins/header_rewrite.en.rst +++ b/doc/admin-guide/plugins/header_rewrite.en.rst @@ -494,6 +494,7 @@ Any value greater than zero indicates connection reuse. TCP-INFO ~~~~~~~~ :: + cond %{} add-header @PropertyName "%{TCP-INFO}" From 32c0cf46ba2cd758ac15692237f9073797d24c56 Mon Sep 17 00:00:00 2001 From: Divya Bhat Date: Tue, 9 Mar 2021 19:34:12 +0000 Subject: [PATCH 04/11] adding header file tcp info --- plugins/header_rewrite/conditions.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc index f39e7f1606e..17dbd355fc1 100644 --- a/plugins/header_rewrite/conditions.cc +++ b/plugins/header_rewrite/conditions.cc @@ -32,6 +32,17 @@ #include "conditions.h" #include "lulu.h" +// This is a bit of a hack, to get the more linux specific tcp_info struct ... +#if HAVE_STRUCT_LINUX_TCP_INFO +#ifndef _LINUX_TCP_H +#define _LINUX_TCP_H +#endif +#elif HAVE_NETINET_IN_H +#ifndef _NETINET_TCP_H +#define _NETINET_TCP_H +#endif +#endif + // ConditionStatus void ConditionStatus::initialize(Parser &p) From c60edc966005525ea1cf22544635c05b02564f78 Mon Sep 17 00:00:00 2001 From: Divya Bhat Date: Tue, 9 Mar 2021 19:34:12 +0000 Subject: [PATCH 05/11] adding header file tcp info fixing indentation in doc --- doc/admin-guide/plugins/header_rewrite.en.rst | 1 + plugins/header_rewrite/conditions.cc | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/doc/admin-guide/plugins/header_rewrite.en.rst b/doc/admin-guide/plugins/header_rewrite.en.rst index ecd2a6ee92d..bc46a63dd05 100644 --- a/doc/admin-guide/plugins/header_rewrite.en.rst +++ b/doc/admin-guide/plugins/header_rewrite.en.rst @@ -494,6 +494,7 @@ Any value greater than zero indicates connection reuse. TCP-INFO ~~~~~~~~ :: + cond %{} add-header @PropertyName "%{TCP-INFO}" diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc index f39e7f1606e..17dbd355fc1 100644 --- a/plugins/header_rewrite/conditions.cc +++ b/plugins/header_rewrite/conditions.cc @@ -32,6 +32,17 @@ #include "conditions.h" #include "lulu.h" +// This is a bit of a hack, to get the more linux specific tcp_info struct ... +#if HAVE_STRUCT_LINUX_TCP_INFO +#ifndef _LINUX_TCP_H +#define _LINUX_TCP_H +#endif +#elif HAVE_NETINET_IN_H +#ifndef _NETINET_TCP_H +#define _NETINET_TCP_H +#endif +#endif + // ConditionStatus void ConditionStatus::initialize(Parser &p) From dac3fadda0fd8c37df20f99afbd714a16de08ae9 Mon Sep 17 00:00:00 2001 From: Divya Bhat Date: Tue, 9 Mar 2021 19:34:12 +0000 Subject: [PATCH 06/11] adding header file tcp info fixing indentation in doc --- doc/admin-guide/plugins/header_rewrite.en.rst | 1 + plugins/header_rewrite/conditions.cc | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/doc/admin-guide/plugins/header_rewrite.en.rst b/doc/admin-guide/plugins/header_rewrite.en.rst index ecd2a6ee92d..bc46a63dd05 100644 --- a/doc/admin-guide/plugins/header_rewrite.en.rst +++ b/doc/admin-guide/plugins/header_rewrite.en.rst @@ -494,6 +494,7 @@ Any value greater than zero indicates connection reuse. TCP-INFO ~~~~~~~~ :: + cond %{} add-header @PropertyName "%{TCP-INFO}" diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc index f39e7f1606e..17dbd355fc1 100644 --- a/plugins/header_rewrite/conditions.cc +++ b/plugins/header_rewrite/conditions.cc @@ -32,6 +32,17 @@ #include "conditions.h" #include "lulu.h" +// This is a bit of a hack, to get the more linux specific tcp_info struct ... +#if HAVE_STRUCT_LINUX_TCP_INFO +#ifndef _LINUX_TCP_H +#define _LINUX_TCP_H +#endif +#elif HAVE_NETINET_IN_H +#ifndef _NETINET_TCP_H +#define _NETINET_TCP_H +#endif +#endif + // ConditionStatus void ConditionStatus::initialize(Parser &p) From 10354cc5e4ec8cbb9f9da23d6a16e0bb86da47f9 Mon Sep 17 00:00:00 2001 From: Divya Bhat Date: Fri, 19 Mar 2021 07:03:59 +0000 Subject: [PATCH 07/11] Fixing headers where TCP info is written --- plugins/header_rewrite/resources.cc | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/plugins/header_rewrite/resources.cc b/plugins/header_rewrite/resources.cc index e585512029c..0578d3b4a82 100644 --- a/plugins/header_rewrite/resources.cc +++ b/plugins/header_rewrite/resources.cc @@ -87,11 +87,6 @@ Resources::gather(const ResourceIDs ids, TSHttpHookID hook) TSDebug(PLUGIN_NAME, "\tAdding TXN client response status resource"); resp_status = TSHttpHdrStatusGet(bufp, hdr_loc); } - if (client_bufp && client_hdr_loc) { - TSDebug(PLUGIN_NAME, "\tAdding TXN client response header buffers"); - bufp = client_bufp; - hdr_loc = client_hdr_loc; - } } break; @@ -107,7 +102,7 @@ Resources::gather(const ResourceIDs ids, TSHttpHookID hook) case TS_HTTP_TXN_START_HOOK: // Get TCP Info at transaction start if (client_bufp && client_hdr_loc) { - TSDebug(PLUGIN_NAME, "\tAdding TXN Start header buffers"); + TSDebug(PLUGIN_NAME, "\tAdding TXN client request header buffers for TXN Start instance"); bufp = client_bufp; hdr_loc = client_hdr_loc; } @@ -115,10 +110,10 @@ Resources::gather(const ResourceIDs ids, TSHttpHookID hook) case TS_HTTP_TXN_CLOSE_HOOK: // Get TCP Info at transaction close - if (client_bufp && client_hdr_loc) { - TSDebug(PLUGIN_NAME, "\tAdding TXN Close header buffers"); - bufp = client_bufp; - hdr_loc = client_hdr_loc; + TSDebug(PLUGIN_NAME, "\tAdding TXN close buffers"); + if (TSHttpTxnClientRespGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) { + TSDebug(PLUGIN_NAME, "could not gather bufp/hdr_loc for request"); + return; } break; From e059dedac3ab53433acca05b677548bb27ab096c Mon Sep 17 00:00:00 2001 From: Divya Bhat Date: Wed, 31 Mar 2021 06:15:06 +0000 Subject: [PATCH 08/11] adding message for internal transaction --- plugins/header_rewrite/conditions.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc index 17dbd355fc1..273cfb07707 100644 --- a/plugins/header_rewrite/conditions.cc +++ b/plugins/header_rewrite/conditions.cc @@ -1388,6 +1388,10 @@ ConditionTcpInfo::append_value(std::string &s, Resources const &res) struct tcp_info info; socklen_t tcp_info_len = sizeof(info); tsSsn = TSHttpTxnClientFdGet(res.txnp, &fd); + if (TSHttpTxnIsInternal(res.txnp) == 1) { + TSDebug(PLUGIN_NAME, "No TCP-INFO available for internal transactions"); + return; + } if (tsSsn != TS_SUCCESS || fd <= 0) { TSDebug(PLUGIN_NAME, "error getting the client socket fd from ssn"); } From 8f2eb6f2671dd520231afb7301781d8eebb75361 Mon Sep 17 00:00:00 2001 From: Divya Bhat Date: Wed, 31 Mar 2021 06:27:25 +0000 Subject: [PATCH 09/11] Adding documenation for TCP-INFO in header rewrite --- doc/admin-guide/plugins/header_rewrite.en.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/admin-guide/plugins/header_rewrite.en.rst b/doc/admin-guide/plugins/header_rewrite.en.rst index bc46a63dd05..6dad9e1866f 100644 --- a/doc/admin-guide/plugins/header_rewrite.en.rst +++ b/doc/admin-guide/plugins/header_rewrite.en.rst @@ -498,7 +498,7 @@ TCP-INFO cond %{} add-header @PropertyName "%{TCP-INFO}" -This operation records TCP Info struct field values as an Internal remap as well as global header at the event hook specified by the condition. Supported hook conditions include TXN_START_HOOK, SEND_RESPONSE_HEADER_HOOK and TXN_CLOSE_HOOK in the Global plugin and REMAP_PSEUDO_HOOK, SEND_RESPONSE_HEADER_HOOK and TXN_CLOSE_HOOK in the Remap plugin. TCP Info fields currently recorded include rtt, rto, snd_cwnd and all_retrans. +This operation records TCP Info struct field values as an Internal remap as well as global header at the event hook specified by the condition. Supported hook conditions include TXN_START_HOOK, SEND_RESPONSE_HEADER_HOOK and TXN_CLOSE_HOOK in the Global plugin and REMAP_PSEUDO_HOOK, SEND_RESPONSE_HEADER_HOOK and TXN_CLOSE_HOOK in the Remap plugin. Conditions supported as request headers include TXN_START_HOOK and REMAP_PSEUDO_HOOK. The other conditions are supported as response headers. TCP Info fields currently recorded include rtt, rto, snd_cwnd and all_retrans. This operation is not supported on internal transactions. Condition Operands ------------------ From 8d0c560919774d16978991dc880592896c73d0c5 Mon Sep 17 00:00:00 2001 From: Divya Bhat Date: Wed, 31 Mar 2021 06:32:28 +0000 Subject: [PATCH 10/11] Fixing internal header debug message for TCP Info --- plugins/header_rewrite/conditions.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc index 273cfb07707..c31f5037b67 100644 --- a/plugins/header_rewrite/conditions.cc +++ b/plugins/header_rewrite/conditions.cc @@ -1383,15 +1383,15 @@ void ConditionTcpInfo::append_value(std::string &s, Resources const &res) { #if defined(TCP_INFO) && defined(HAVE_STRUCT_TCP_INFO) + if (TSHttpTxnIsInternal(res.txnp) == 1) { + TSDebug(PLUGIN_NAME, "No TCP-INFO available for internal transactions"); + return; + } TSReturnCode tsSsn; int fd; struct tcp_info info; socklen_t tcp_info_len = sizeof(info); tsSsn = TSHttpTxnClientFdGet(res.txnp, &fd); - if (TSHttpTxnIsInternal(res.txnp) == 1) { - TSDebug(PLUGIN_NAME, "No TCP-INFO available for internal transactions"); - return; - } if (tsSsn != TS_SUCCESS || fd <= 0) { TSDebug(PLUGIN_NAME, "error getting the client socket fd from ssn"); } From 17cd15bbb6fdbd8b6c6641c8340e4d4326f15f5d Mon Sep 17 00:00:00 2001 From: Divya Bhat Date: Wed, 31 Mar 2021 22:40:33 +0000 Subject: [PATCH 11/11] adding message for internal transaction --- doc/admin-guide/plugins/header_rewrite.en.rst | 2 +- plugins/header_rewrite/conditions.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/admin-guide/plugins/header_rewrite.en.rst b/doc/admin-guide/plugins/header_rewrite.en.rst index 6dad9e1866f..40f86a342bb 100644 --- a/doc/admin-guide/plugins/header_rewrite.en.rst +++ b/doc/admin-guide/plugins/header_rewrite.en.rst @@ -498,7 +498,7 @@ TCP-INFO cond %{} add-header @PropertyName "%{TCP-INFO}" -This operation records TCP Info struct field values as an Internal remap as well as global header at the event hook specified by the condition. Supported hook conditions include TXN_START_HOOK, SEND_RESPONSE_HEADER_HOOK and TXN_CLOSE_HOOK in the Global plugin and REMAP_PSEUDO_HOOK, SEND_RESPONSE_HEADER_HOOK and TXN_CLOSE_HOOK in the Remap plugin. Conditions supported as request headers include TXN_START_HOOK and REMAP_PSEUDO_HOOK. The other conditions are supported as response headers. TCP Info fields currently recorded include rtt, rto, snd_cwnd and all_retrans. This operation is not supported on internal transactions. +This operation records TCP Info struct field values as an Internal remap as well as global header at the event hook specified by the condition. Supported hook conditions include TXN_START_HOOK, SEND_RESPONSE_HEADER_HOOK and TXN_CLOSE_HOOK in the Global plugin and REMAP_PSEUDO_HOOK, SEND_RESPONSE_HEADER_HOOK and TXN_CLOSE_HOOK in the Remap plugin. Conditions supported as request headers include TXN_START_HOOK and REMAP_PSEUDO_HOOK. The other conditions are supported as response headers. TCP Info fields currently recorded include rtt, rto, snd_cwnd and all_retrans. This operation is not supported on transactions originated within Traffic Server (for e.g using the |TS| :c:func:`TSHttpTxnIsInternal`) Condition Operands ------------------ diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc index c31f5037b67..66c3e5d9173 100644 --- a/plugins/header_rewrite/conditions.cc +++ b/plugins/header_rewrite/conditions.cc @@ -1383,7 +1383,7 @@ void ConditionTcpInfo::append_value(std::string &s, Resources const &res) { #if defined(TCP_INFO) && defined(HAVE_STRUCT_TCP_INFO) - if (TSHttpTxnIsInternal(res.txnp) == 1) { + if (TSHttpTxnIsInternal(res.txnp)) { TSDebug(PLUGIN_NAME, "No TCP-INFO available for internal transactions"); return; }