zwoop commented on a change in pull request #7516:
URL: https://github.com/apache/trafficserver/pull/7516#discussion_r575511198
##########
File path: 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<const Matchers<std::string> *>(_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;
Review comment:
why do you need these intermediary / temp variables? Just use
info.tcp_rtt instead, it's much clearer, and less waste.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]