]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Tsantilas Christos <chtsanti@users.sourceforge.net>
authorHenrik Nordström <henrik@hlaptop.localdomain>
Thu, 3 Jun 2010 07:49:20 +0000 (09:49 +0200)
committerHenrik Nordström <henrik@hlaptop.localdomain>
Thu, 3 Jun 2010 07:49:20 +0000 (09:49 +0200)
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.

Regards,
    Christos

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

index 3fc6a8019d035a93167ffc05e77d0a7bd68b9936..814dd0e4a03ba0dcce22ae8256ebd7357bc3ebca 100644 (file)
@@ -64,6 +64,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
+    u_short peer_local_port; //< local port of the last server-side connection
 };
 
 extern void hierarchyNote(HierarchyLogEntry *, hier_code, const char *);
index a92f1d37f8ebc3eb053ed3cbc5bcf1dc6ffc555f..1e289011f880c9e9227ebd6880fc81f75d7e4e1a 100644 (file)
@@ -2611,6 +2611,7 @@ DOC_START
                <A      Server IP address or peer name
                la      Local IP address (http_port)
                lp      Local port number (http_port)
+               <lp     Local port number of the last server or peer connection
                sn      Unique sequence number per log line entry
                ts      Seconds since epoch
                tu      subsecond time (milliseconds)
index 8aff1aaa91594104cac2182e30097666866ba811..a954803d05bf26be40366d948e3cffb642187e51 100644 (file)
@@ -854,6 +854,9 @@ FwdState::connectStart()
 
         comm_add_close_handler(fd, fwdServerClosedWrapper, this);
 
+        // TODO: Avoid this if %<lp is not used? F->local_port is often cached.
+        request->hier.peer_local_port = comm_local_port(fd);
+
         dispatch();
 
         return;
@@ -895,6 +898,8 @@ FwdState::connectStart()
     if (!fs->_peer)
         origin_tries++;
 
+    request->hier.peer_local_port = comm_local_port(fd);
+
     /*
      * stats.conn_open is used to account for the number of
      * connections that we have open to the peer, so we can limit
index 436b57f73e8add6f54849711139db91df8a28d1b..b8a4b3e69117e45fec16a7c168337f2c1bd4d476 100644 (file)
@@ -344,6 +344,7 @@ typedef enum {
     LFT_LOCAL_IP,
     LFT_LOCAL_PORT,
     /*LFT_LOCAL_NAME, */
+    LFT_PEER_LOCAL_PORT,
 
     LFT_TIME_SECONDS_SINCE_EPOCH,
     LFT_TIME_SUBSECOND,
@@ -505,6 +506,7 @@ struct logformat_token_table_entry logformat_token_table[] = {
     {"la", LFT_LOCAL_IP},
     {"lp", LFT_LOCAL_PORT},
     /*{ "lA", LFT_LOCAL_NAME }, */
+    {"<lp", LFT_PEER_LOCAL_PORT},
 
     {"ts", LFT_TIME_SECONDS_SINCE_EPOCH},
     {"tu", LFT_TIME_SUBSECOND},
@@ -692,6 +694,14 @@ accessLogCustom(AccessLogEntry * al, customlog * log)
 
             break;
 
+        case LFT_PEER_LOCAL_PORT:
+            if (al->hier.peer_local_port) {
+                outint = al->hier.peer_local_port;
+                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);
@@ -2081,7 +2091,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_port(0)
 {
     memset(host, '\0', SQUIDHOSTNAMELEN);
     memset(cd_host, '\0', SQUIDHOSTNAMELEN);