You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@trafficserver.apache.org by Wolfgang Walter <tr...@stwm.de> on 2014/04/09 22:27:21 UTC

[PATCH 3/6] Logging: add % %

>From 7f3324b42f8cbe5049fdf8c7bc5bf0c60f9195e7 Mon Sep 17 00:00:00 2001
From: Wolfgang Walter <ti...@stusta.de>
Date: Sun, 6 Apr 2014 13:20:06 +0200
Subject: [PATCH 3/6] Logging: add %<pqli> %<pqlp>

pqli logs the source ip address of the server request.

pqlp logs the source port of the server request.
---
 proxy/http/HttpSM.cc           |  7 +++++++
 proxy/http/HttpTransact.h      |  3 +++
 proxy/logging/Log.cc           | 14 ++++++++++++++
 proxy/logging/LogAccess.cc     | 18 ++++++++++++++++++
 proxy/logging/LogAccess.h      |  2 ++
 proxy/logging/LogAccessHttp.cc | 16 ++++++++++++++++
 proxy/logging/LogAccessHttp.h  |  2 ++
 7 files changed, 62 insertions(+)

diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc
index e60f5a4..2a65209 100644
--- a/proxy/http/HttpSM.cc
+++ b/proxy/http/HttpSM.cc
@@ -2877,6 +2877,8 @@ HttpSM::tunnel_handler_server(int event, HttpTunnelProducer * p)
   ink_assert(p->vc_type == HT_HTTP_SERVER);
   ink_assert(p->vc == server_session);
 
+  ats_ip_copy(&t_state.current.server->local_addr, server_session->get_netvc()->get_local_addr());
+
   if (close_connection) {
     p->vc->do_io_close();
     p->read_vio = NULL;
@@ -3425,6 +3427,11 @@ HttpSM::tunnel_handler_ssl_producer(int event, HttpTunnelProducer * p)
 
   STATE_ENTER(&HttpSM::tunnel_handler_ssl_producer, event);
 
+  if (p->vc_type == HT_HTTP_SERVER && server_entry->vc == p->vc) {
+      NetVConnection* netvc = (NetVConnection *) p->vc;
+      ats_ip_copy(&t_state.current.server->local_addr, netvc->get_local_addr());
+  }
+
   switch (event) {
   case VC_EVENT_EOS:
     // The write side of this connection is still alive
diff --git a/proxy/http/HttpTransact.h b/proxy/http/HttpTransact.h
index 652c5ac..9255fdb 100644
--- a/proxy/http/HttpTransact.h
+++ b/proxy/http/HttpTransact.h
@@ -715,6 +715,8 @@ public:
     /// @c true if the connection is transparent.
     bool is_transparent;
 
+    IpEndpoint local_addr;
+
     bool had_connect_fail() const { return 0 != connect_result; }
     void clear_connect_fail() { connect_result = 0; }
     void set_connect_fail(int e) { connect_result = e; }
@@ -736,6 +738,7 @@ public:
         is_transparent(false)
     {
       memset(&addr, 0, sizeof(addr));
+      memset(&local_addr, 0, sizeof(addr));
     }
 
   };
diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc
index 560085c..fe671d0 100644
--- a/proxy/logging/Log.cc
+++ b/proxy/logging/Log.cc
@@ -672,6 +672,20 @@ Log::init_fields()
   global_field_list.add(field, false);
   ink_hash_table_insert(field_symbol_hash, "pqsp", field);
 
+  field = NEW(new LogField("proxy_req_local_ip", "pqli",
+                           LogField::IP,
+                           &LogAccess::marshal_proxy_req_local_ip,
+                           &LogAccess::unmarshal_ip_to_str));
+  global_field_list.add(field, false);
+  ink_hash_table_insert(field_symbol_hash, "pqli", field);
+
+  field = NEW(new LogField("proxy_req_server_port", "pqlp",
+                           LogField::sINT,
+                           &LogAccess::marshal_proxy_req_local_port,
+                           &LogAccess::unmarshal_int_to_str));
+  global_field_list.add(field, false);
+  ink_hash_table_insert(field_symbol_hash, "pqlp", field);
+
   Ptr<LogFieldAliasTable> hierarchy_map = make_ptr(NEW(new LogFieldAliasTable));
   hierarchy_map->init(36,
                       SQUID_HIER_EMPTY, "EMPTY",
diff --git a/proxy/logging/LogAccess.cc b/proxy/logging/LogAccess.cc
index 5db1740..9a14391 100644
--- a/proxy/logging/LogAccess.cc
+++ b/proxy/logging/LogAccess.cc
@@ -340,6 +340,24 @@ LogAccess::marshal_proxy_req_server_port(char *buf)
   -------------------------------------------------------------------------*/
 
 int
+LogAccess::marshal_proxy_req_local_ip(char *buf)
+{
+  DEFAULT_IP_FIELD;
+}
+
+/*-------------------------------------------------------------------------
+  -------------------------------------------------------------------------*/
+
+int
+LogAccess::marshal_proxy_req_local_port(char *buf)
+{
+  DEFAULT_INT_FIELD;
+}
+
+/*-------------------------------------------------------------------------
+  -------------------------------------------------------------------------*/
+
+int
 LogAccess::marshal_proxy_hierarchy_route(char *buf)
 {
   DEFAULT_INT_FIELD;
diff --git a/proxy/logging/LogAccess.h b/proxy/logging/LogAccess.h
index 909efb7..2ef5ca5 100644
--- a/proxy/logging/LogAccess.h
+++ b/proxy/logging/LogAccess.h
@@ -206,6 +206,8 @@ public:
   inkcoreapi virtual int marshal_proxy_req_server_name(char *); // STR
   inkcoreapi virtual int marshal_proxy_req_server_ip(char *);   // INT
   inkcoreapi virtual int marshal_proxy_req_server_port(char *);   // INT
+  inkcoreapi virtual int marshal_proxy_req_local_ip(char *);   // INT
+  inkcoreapi virtual int marshal_proxy_req_local_port(char *);   // INT
   inkcoreapi virtual int marshal_proxy_hierarchy_route(char *); // INT
   inkcoreapi virtual int marshal_proxy_host_name(char *);       // STR
   inkcoreapi virtual int marshal_proxy_host_ip(char *); // STR
diff --git a/proxy/logging/LogAccessHttp.cc b/proxy/logging/LogAccessHttp.cc
index 626e672..8d82aab 100644
--- a/proxy/logging/LogAccessHttp.cc
+++ b/proxy/logging/LogAccessHttp.cc
@@ -697,6 +697,22 @@ LogAccessHttp::marshal_proxy_req_server_port(char *buf)
   return INK_MIN_ALIGN;
 }
 
+int
+LogAccessHttp::marshal_proxy_req_local_ip(char *buf)
+{
+  return marshal_ip(buf, m_http_sm->t_state.current.server != NULL ? &m_http_sm->t_state.current.server->local_addr.sa : 0);
+}
+
+int
+LogAccessHttp::marshal_proxy_req_local_port(char *buf)
+{
+  if (buf) {
+    in_port_t port = m_http_sm->t_state.current.server != NULL ? ats_ip_port_host_order(&m_http_sm->t_state.current.server->local_addr.sa) : 0;
+    marshal_int(buf, port);
+  }
+  return INK_MIN_ALIGN;
+}
+
 /*-------------------------------------------------------------------------
   -------------------------------------------------------------------------*/
 
diff --git a/proxy/logging/LogAccessHttp.h b/proxy/logging/LogAccessHttp.h
index cfd9f0a..133cd94 100644
--- a/proxy/logging/LogAccessHttp.h
+++ b/proxy/logging/LogAccessHttp.h
@@ -92,6 +92,8 @@ public:
   virtual int marshal_proxy_req_server_name(char *);    // STR
   virtual int marshal_proxy_req_server_ip(char *);      // INT
   virtual int marshal_proxy_req_server_port(char *);    // INT
+  virtual int marshal_proxy_req_local_ip(char *);       // STR
+  virtual int marshal_proxy_req_local_port(char *);     // INT
   virtual int marshal_proxy_hierarchy_route(char *);    // INT
 
   //
-- 
1.9.1