Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
LDIF 5.91 KB | None | 0 0
  1. diff --git a/doc/admin-guide/plugins/header_rewrite.en.rst b/doc/admin-guide/plugins/header_rewrite.en.rst
  2. index 7071fbe..419f05d 100644
  3. --- a/doc/admin-guide/plugins/header_rewrite.en.rst
  4. +++ b/doc/admin-guide/plugins/header_rewrite.en.rst
  5. @@ -179,6 +179,8 @@ CLIENT-IP
  6.  Remote IP address, as a string, of the client connection for the current
  7.  transaction.
  8.  
  9. +This condition is *deprecated* as of ATS v7.2.x, please use %{IP:CLIENT} instead.
  10. +
  11.  CLIENT-URL
  12.  ~~~~~~~~~~
  13.  ::
  14. @@ -291,6 +293,35 @@ INCOMING-PORT
  15.  TCP port, as a decimal integer, on which the incoming client connection was
  16.  made.
  17.  
  18. +IP
  19. +~~
  20. +::
  21. +
  22. +    cond %{IP:<part>} <operand>
  23. +
  24. +This is one of four possible IPs associated with the transaction, with the
  25. +possible parts being
  26. +::
  27. +
  28. +    %{IP:CLIENT}     Clients IP
  29. +    %{IP:INBOUND}    ATS's server IP the client connected to
  30. +    %{IP:SERVER}     Upstream (next-hop) server IP (typically origin, or parent)
  31. +    %{IP:OUTBOUND}   ATS's outbound IP, that was used to connect upstream (next-hop)
  32. +
  33. +Note that both %{IP:SERVER} and %{IP:OUTBOUND} can be unset, in which case the
  34. +string is instead set to "-". The common use for this condition is actually as
  35. +a value to an operator, e.g.
  36. +::
  37. +
  38. +   cond %{SEND_RESPONSE_HDR_HOOK}
  39. +     set-header X-Client-IP %{IP:CLIENT}
  40. +     set-header X-Inbound-IP %{IP:INBOUND}
  41. +     set-header X-Server-IP %{IP:SERVER}
  42. +     set-header X-Outbound-IP %{IP:OUTBOUND}
  43. +
  44. +Finally, this new condition replaces the old %{CLIENT-IP} condition, which is
  45. +now properly deprecated. It will be removed as of ATS v8.0.0.
  46. +
  47.  INTERNAL-TRANSACTION
  48.  ~~~~~~~~~~~~~~~~~~~~
  49.  ::
  50. diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc
  51. index d4425be..7fe4372 100644
  52. --- a/plugins/header_rewrite/conditions.cc
  53. +++ b/plugins/header_rewrite/conditions.cc
  54. @@ -582,6 +582,86 @@ ConditionClientIp::append_value(std::string &s, const Resources &res)
  55.  }
  56.  
  57.  void
  58. +ConditionIp::initialize(Parser &p)
  59. +{
  60. +  Condition::initialize(p);
  61. +
  62. +  MatcherType *match = new MatcherType(_cond_op);
  63. +
  64. +  match->set(p.get_arg());
  65. +  _matcher = match;
  66. +}
  67. +
  68. +void
  69. +ConditionIp::set_qualifier(const std::string &q)
  70. +{
  71. +  Condition::set_qualifier(q);
  72. +
  73. +  TSDebug(PLUGIN_NAME, "\tParsing %%{IP:%s} qualifier", q.c_str());
  74. +
  75. +  if (q == "CLIENT") {
  76. +    _ip_qual = IP_QUAL_CLIENT;
  77. +  } else if (q == "INBOUND") {
  78. +    _ip_qual = IP_QUAL_INBOUND;
  79. +  } else if (q == "SERVER") {
  80. +    _ip_qual = IP_QUAL_SERVER;
  81. +  } else if (q == "OUTBOUND") {
  82. +    _ip_qual = IP_QUAL_OUTBOUND;
  83. +  } else {
  84. +    TSError("[%s] Unknown IP() qualifier: %s", PLUGIN_NAME, q.c_str());
  85. +  }
  86. +}
  87. +
  88. +bool
  89. +ConditionIp::eval(const Resources &res)
  90. +{
  91. +  std::string s;
  92. +
  93. +  append_value(s, res);
  94. +  bool rval = static_cast<const Matchers<std::string> *>(_matcher)->test(s);
  95. +
  96. +  TSDebug(PLUGIN_NAME, "Evaluating IP(): %s - rval: %d", s.c_str(), rval);
  97. +
  98. +  return rval;
  99. +}
  100. +
  101. +void
  102. +ConditionIp::append_value(std::string &s, const Resources &res)
  103. +{
  104. +  bool ip_set = false;
  105. +  char ip[INET6_ADDRSTRLEN];
  106. +
  107. +  switch (_ip_qual) {
  108. +  case IP_QUAL_CLIENT:
  109. +    if (getIP(TSHttpTxnClientAddrGet(res.txnp), ip)) {
  110. +      ip_set = true;
  111. +    }
  112. +    break;
  113. +  case IP_QUAL_INBOUND:
  114. +    if (getIP(TSHttpTxnIncomingAddrGet(res.txnp), ip)) {
  115. +      ip_set = true;
  116. +    }
  117. +    break;
  118. +  case IP_QUAL_SERVER:
  119. +    if (getIP(TSHttpTxnServerAddrGet(res.txnp), ip)) {
  120. +      ip_set = true;
  121. +    }
  122. +    break;
  123. +  case IP_QUAL_OUTBOUND:
  124. +    if (getIP(TSHttpTxnOutgoingAddrGet(res.txnp), ip)) {
  125. +      ip_set = true;
  126. +    }
  127. +    break;
  128. +  }
  129. +
  130. +  if (ip_set) {
  131. +    s.append(ip);
  132. +  } else {
  133. +    s.append("-"); // ToDo: This is inline with logging, but can we do better?
  134. +  }
  135. +}
  136. +
  137. +void
  138.  ConditionIncomingPort::initialize(Parser &p)
  139.  {
  140.    Condition::initialize(p);
  141. diff --git a/plugins/header_rewrite/conditions.h b/plugins/header_rewrite/conditions.h
  142. index 3f31126..640f1a5 100644
  143. --- a/plugins/header_rewrite/conditions.h
  144. +++ b/plugins/header_rewrite/conditions.h
  145. @@ -359,6 +359,24 @@ protected:
  146.    bool eval(const Resources &res);
  147.  };
  148.  
  149. +class ConditionIp : public Condition
  150. +{
  151. +  typedef Matchers<std::string> MatcherType;
  152. +
  153. +public:
  154. +  explicit ConditionIp() : _ip_qual(IP_QUAL_CLIENT) { TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for ConditionIp"); };
  155. +  void initialize(Parser &p);
  156. +  void set_qualifier(const std::string &q);
  157. +  void append_value(std::string &s, const Resources &res);
  158. +
  159. +protected:
  160. +  bool eval(const Resources &res);
  161. +
  162. +private:
  163. +  DISALLOW_COPY_AND_ASSIGN(ConditionIp);
  164. +  IpQualifiers _ip_qual;
  165. +};
  166. +
  167.  class ConditionClientIp : public Condition
  168.  {
  169.    typedef Matchers<std::string> MatcherType;
  170. diff --git a/plugins/header_rewrite/factory.cc b/plugins/header_rewrite/factory.cc
  171. index 2acbdc8..3b70c7a 100644
  172. --- a/plugins/header_rewrite/factory.cc
  173. +++ b/plugins/header_rewrite/factory.cc
  174. @@ -123,7 +123,11 @@ condition_factory(const std::string &cond)
  175.      c = new ConditionInternalTxn();
  176.    } else if (c_name == "INTERNAL-TXN") {
  177.      c = new ConditionInternalTxn();
  178. +  } else if (c_name == "IP") {
  179. +    c = new ConditionIp();
  180.    } else if (c_name == "CLIENT-IP") {
  181. +    TSDebug(PLUGIN_NAME, "\tWARNING: configuration uses deprecated condition, CLIENT-IP()");
  182. +    TSError("warning: CLIENT-IP() is deprecated, use %%{IP:CLIENT} instead");
  183.      c = new ConditionClientIp();
  184.    } else if (c_name == "INCOMING-PORT") {
  185.      c = new ConditionIncomingPort();
  186. diff --git a/plugins/header_rewrite/statement.h b/plugins/header_rewrite/statement.h
  187. index 7aa627b..69e2df5 100644
  188. --- a/plugins/header_rewrite/statement.h
  189. +++ b/plugins/header_rewrite/statement.h
  190. @@ -72,6 +72,15 @@ enum IdQualifiers {
  191.    ID_QUAL_UNIQUE,
  192.  };
  193.  
  194. +// IP
  195. +enum IpQualifiers {
  196. +  IP_QUAL_CLIENT,
  197. +  IP_QUAL_INBOUND,
  198. +  // These two might not necessarily get populated, e.g. on a cache hit.
  199. +  IP_QUAL_SERVER,
  200. +  IP_QUAL_OUTBOUND,
  201. +};
  202. +
  203.  class Statement
  204.  {
  205.  public:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement