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

sudheerv 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 583e5ed  Add Access log fields for ProxyProtocol Context
583e5ed is described below

commit 583e5ed5f3db1e33075b8e5b880d6f6bf1e730f3
Author: Sudheer Vinukonda <[email protected]>
AuthorDate: Tue Apr 28 08:56:20 2020 -0700

    Add Access log fields for ProxyProtocol Context
---
 doc/admin-guide/logging/formatting.en.rst |  7 ++++
 proxy/logging/Log.cc                      | 15 +++++++++
 proxy/logging/LogAccess.cc                | 55 +++++++++++++++++++++++++++++++
 proxy/logging/LogAccess.h                 |  3 ++
 4 files changed, 80 insertions(+)

diff --git a/doc/admin-guide/logging/formatting.en.rst 
b/doc/admin-guide/logging/formatting.en.rst
index c81f435..242afe2 100644
--- a/doc/admin-guide/logging/formatting.en.rst
+++ b/doc/admin-guide/logging/formatting.en.rst
@@ -505,6 +505,13 @@ shi   Origin Server  IP address resolved via DNS by |TS| 
for the origin server.
 shn   Origin Server  Host name of the origin server.
 nhi   Origin Server  Destination IP address of next hop
 nhp   Origin Server  Destination port of next hop
+ppv   Proxy Protocol Proxy Protocol Version used (if any) between the 
Loadbalancer
+      Version        and |TS|
+pps   Proxy Protocol Source IP received via Proxy Protocol context from the LB 
to
+      Source IP      the |TS|
+ppd   Proxy Protocol Destination IP received via Proxy Protocol context from 
the LB
+      Dest IP        to the |TS|
+
 ===== ============== ==========================================================
 
 .. note::
diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc
index 8be6bd7..4d46f6d 100644
--- a/proxy/logging/Log.cc
+++ b/proxy/logging/Log.cc
@@ -917,6 +917,21 @@ Log::init_fields()
   global_field_list.add(field, false);
   field_symbol_hash.emplace("ctpd", field);
 
+  field = new LogField("proxy_protocol_version", "ppv", LogField::dINT, 
&LogAccess::marshal_proxy_protocol_version,
+                       
reinterpret_cast<LogField::UnmarshalFunc>(&LogAccess::unmarshal_str));
+  global_field_list.add(field, false);
+  field_symbol_hash.emplace("ppv", field);
+
+  field = new LogField("proxy_protocol_src_ip", "pps", LogField::IP, 
&LogAccess::marshal_proxy_protocol_src_ip,
+                       &LogAccess::unmarshal_ip_to_str);
+  global_field_list.add(field, false);
+  field_symbol_hash.emplace("ppsip", field);
+
+  field = new LogField("proxy_protocol_dst_ip", "ppd", LogField::IP, 
&LogAccess::marshal_proxy_protocol_dst_ip,
+                       &LogAccess::unmarshal_ip_to_str);
+  global_field_list.add(field, false);
+  field_symbol_hash.emplace("ppdip", field);
+
   field = new LogField("version_build_number", "vbn", LogField::STRING, 
&LogAccess::marshal_version_build_number,
                        (LogField::UnmarshalFunc)&LogAccess::unmarshal_str);
   global_field_list.add(field, false);
diff --git a/proxy/logging/LogAccess.cc b/proxy/logging/LogAccess.cc
index 08f5b0a..6d8d9e1 100644
--- a/proxy/logging/LogAccess.cc
+++ b/proxy/logging/LogAccess.cc
@@ -1315,6 +1315,61 @@ LogAccess::marshal_version_build_number(char *buf)
   -------------------------------------------------------------------------*/
 
 int
+LogAccess::marshal_proxy_protocol_version(char *buf)
+{
+  const char *version_str = nullptr;
+  int len                 = INK_MIN_ALIGN;
+
+  if (m_http_sm) {
+    NetVConnection::ProxyProtocolVersion ver = 
m_http_sm->t_state.pp_info.proxy_protocol_version;
+    switch (ver) {
+    case NetVConnection::ProxyProtocolVersion::V1:
+      version_str = "V1";
+      break;
+    case NetVConnection::ProxyProtocolVersion::V2:
+      version_str = "V2";
+      break;
+    case NetVConnection::ProxyProtocolVersion::UNDEFINED:
+    default:
+      version_str = "-";
+      break;
+    }
+    len = LogAccess::strlen(version_str);
+  }
+
+  if (buf) {
+    marshal_str(buf, version_str, len);
+  }
+  return len;
+}
+
+/*-------------------------------------------------------------------------
+  -------------------------------------------------------------------------*/
+int
+LogAccess::marshal_proxy_protocol_src_ip(char *buf)
+{
+  sockaddr const *ip = nullptr;
+  if (m_http_sm && m_http_sm->t_state.pp_info.proxy_protocol_version != 
NetVConnection::ProxyProtocolVersion::UNDEFINED) {
+    ip = &m_http_sm->t_state.pp_info.src_addr.sa;
+  }
+  return marshal_ip(buf, ip);
+}
+
+/*-------------------------------------------------------------------------
+  -------------------------------------------------------------------------*/
+int
+LogAccess::marshal_proxy_protocol_dst_ip(char *buf)
+{
+  sockaddr const *ip = nullptr;
+  if (m_http_sm && m_http_sm->t_state.pp_info.proxy_protocol_version != 
NetVConnection::ProxyProtocolVersion::UNDEFINED) {
+    ip = &m_http_sm->t_state.pp_info.dst_addr.sa;
+  }
+  return marshal_ip(buf, ip);
+}
+
+/*-------------------------------------------------------------------------
+  -------------------------------------------------------------------------*/
+int
 LogAccess::marshal_client_host_port(char *buf)
 {
   if (buf) {
diff --git a/proxy/logging/LogAccess.h b/proxy/logging/LogAccess.h
index b29e6f4..e5c14cb 100644
--- a/proxy/logging/LogAccess.h
+++ b/proxy/logging/LogAccess.h
@@ -255,6 +255,9 @@ public:
   inkcoreapi int marshal_cache_read_retries(char *);                          
// INT
   inkcoreapi int marshal_cache_write_retries(char *);                         
// INT
   inkcoreapi int marshal_cache_collapsed_connection_success(char *);          
// INT
+  inkcoreapi int marshal_proxy_protocol_version(char *);                      
// STR
+  inkcoreapi int marshal_proxy_protocol_src_ip(char *);                       
// STR
+  inkcoreapi int marshal_proxy_protocol_dst_ip(char *);                       
// STR
 
   // named fields from within a http header
   //

Reply via email to