]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 3236: Port of %oa, %<lp and %<la log format options
authorAmos Jeffries <squid3@treenet.co.nz>
Tue, 7 Jun 2011 02:13:37 +0000 (20:13 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Tue, 7 Jun 2011 02:13:37 +0000 (20:13 -0600)
Christos Tsantilas:
 Add logging of the local TCP port used by transactions with http servers

  The new log format code is "%<lp"

  In the case there are several server-side connections logs the port of
  the last connection.

  This is a Measurement Factory project.

Amos Jeffries:
 Port 2.7: logformat tag for logging the outgoing IP address (tcp_outgoing_address)

  This adds the log format to log the local IP address used on outgoing
  connections to peers and servers. Squid-2.7 called this %oa.

  However it is a perfectly matching part of the existing set of %la and
  %lp (local inbound) and %<lp (local outbound port).

  As such, the %oa is accepted as input for backward compatibility, but the
  Squid-3 version is: %<la

  This is based only very loosely on the Squid-2 %oa work by Andrew Atangulov

src/HierarchyLogEntry.h
src/access_log.cc
src/cf.data.pre
src/forward.cc
src/tunnel.cc

index 13ffd741104ecf3aa1b5e53237bbed0283e488ac..ebeba2b24b9637d3b65fdc8ddf6622b72dfa4b2e 100644 (file)
@@ -34,6 +34,7 @@
 #ifndef SQUID_HTTPHIERARCHYLOGENTRY_H
 #define SQUID_HTTPHIERARCHYLOGENTRY_H
 
+#include "ip/IpAddress.h"
 #include "rfc2181.h"
 #include "PingData.h"
 
@@ -62,6 +63,7 @@ public:
     int64_t peer_response_time; ///< last peer response delay
     timeval first_conn_start; ///< first connection use among all peers
     int64_t total_response_time; ///< cumulative for all peers
+    IpAddress peer_local_addr; ///< local IP:port of the last server-side connection
 };
 
 extern void hierarchyNote(HierarchyLogEntry *, hier_code, const char *);
index 34eb8c2dd2b5940ef6fef879ba8d1d230d79c088..6fbfdfb9f4860f552f3670e660ecde499cfa713f 100644 (file)
@@ -337,6 +337,9 @@ typedef enum {
     LFT_LOCAL_IP,
     LFT_LOCAL_PORT,
     /*LFT_LOCAL_NAME, */
+    LFT_PEER_LOCAL_IP,
+    LFT_PEER_LOCAL_IP_OLD_27,
+    LFT_PEER_LOCAL_PORT,
 
     LFT_TIME_SECONDS_SINCE_EPOCH,
     LFT_TIME_SUBSECOND,
@@ -493,7 +496,11 @@ struct logformat_token_table_entry logformat_token_table[] = {
 
     {"la", LFT_LOCAL_IP},
     {"lp", LFT_LOCAL_PORT},
-    /*{ "lA", LFT_LOCAL_NAME }, */
+    /*{ "lA", LFT_LOCAL_NAME }, */+
+    {"<la", LFT_PEER_LOCAL_IP},
+    {"oa", LFT_PEER_LOCAL_IP_OLD_27},
+    {"<lp", LFT_PEER_LOCAL_PORT},
+    /* {"ot", LFT_PEER_OUTGOING_TOS}, */
 
     {"ts", LFT_TIME_SECONDS_SINCE_EPOCH},
     {"tu", LFT_TIME_SUBSECOND},
@@ -668,6 +675,22 @@ accessLogCustom(AccessLogEntry * al, customlog * log)
 
             break;
 
+            // the fmt->type can not be LFT_PEER_LOCAL_IP_OLD_27
+            // but compiler complains if ommited
+        case LFT_PEER_LOCAL_IP_OLD_27:
+        case LFT_PEER_LOCAL_IP:
+            if (!al->hier.peer_local_addr.IsAnyAddr()) {
+                out = al->hier.peer_local_addr.NtoA(tmp,sizeof(tmp));
+            }
+            break;
+
+        case LFT_PEER_LOCAL_PORT:
+            if ((outint = al->hier.peer_local_addr.GetPort())) {
+                doint = 1;
+            }
+
+            break;
+
         case LFT_TIME_SECONDS_SINCE_EPOCH:
             // some platforms store time in 32-bit, some 64-bit...
             outoff = static_cast<int64_t>(current_time.tv_sec);
@@ -1498,6 +1521,12 @@ done:
         debugs(46, 0, "WARNING: the \"Hs\" formating code is deprecated use the \">Hs\" instead");
         lt->type = LFT_HTTP_SENT_STATUS_CODE;
         break;
+
+    case LFT_PEER_LOCAL_IP_OLD_27:
+        debugs(46, 0, "WARNING: The \"oa\" formatting code is deprecated. Use the \"<la\" instead.");
+        lt->type = LFT_PEER_LOCAL_IP;
+        break;
+
     default:
         break;
     }
@@ -2049,7 +2078,8 @@ HierarchyLogEntry::HierarchyLogEntry() :
         n_ichoices(0),
         peer_reply_status(HTTP_STATUS_NONE),
         peer_response_time(-1),
-        total_response_time(-1)
+        total_response_time(-1),
+        peer_local_addr()
 {
     memset(host, '\0', SQUIDHOSTNAMELEN);
     memset(cd_host, '\0', SQUIDHOSTNAMELEN);
index 23a7dd91e6e597df18e6b8b2296d6309c1d8ac04..6383ca86cabe958636f5a41e997f14811be17366 100644 (file)
@@ -2535,6 +2535,8 @@ DOC_START
                <A      Server IP address or peer name
                la      Local IP address (http_port)
                lp      Local port number (http_port)
+               <la     Local IP address of the last server or peer connection
+               <lp     Local port number of the last server or peer connection
                ts      Seconds since epoch
                tu      subsecond time (milliseconds)
                tl      Local time. Optional strftime format argument
index 4edb762b6f43b4dbd230d3591336562d27511fd1..45f623a72339495f2989d5e0c89aa386f054f132 100644 (file)
@@ -891,6 +891,9 @@ FwdState::connectStart()
 
         comm_add_close_handler(fd, fwdServerClosedWrapper, this);
 
+        if (comm_local_port(fd))
+            request->hier.peer_local_addr = fd_table[fd].local_addr;
+
         dispatch();
 
         return;
@@ -950,6 +953,9 @@ FwdState::connectStart()
     if (!fs->_peer)
         origin_tries++;
 
+    if (comm_local_port(fd))
+        request->hier.peer_local_addr = fd_table[fd].local_addr;
+
     /*
      * stats.conn_open is used to account for the number of
      * connections that we have open to the peer, so we can limit
index eb34ce568b5202ba04e6f18fe992792ccd266ef5..d1719ecc0869a2073c6b26a482c1a22c5478e33d 100644 (file)
@@ -676,6 +676,10 @@ tunnelStart(ClientHttpRequest * http, int64_t * size_ptr, int *status_ptr)
         return;
     }
 
+    // record local IP:port for %<la and %<lp logging
+    if (comm_local_port(sock))
+        request->hier.peer_local_addr = fd_table[sock].local_addr;
+
     tunnelState = new TunnelStateData;
 #if DELAY_POOLS