]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Port 2.7: logformat tag for logging the outgoing IP address (tcp_outgoing_address)
authorAmos Jeffries <squid3@treenet.co.nz>
Wed, 30 Mar 2011 04:29:35 +0000 (22:29 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 30 Mar 2011 04:29:35 +0000 (22:29 -0600)
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

doc/release-notes/release-3.2.sgml
src/HierarchyLogEntry.h
src/cf.data.pre
src/forward.cc
src/log/FormatSquidCustom.cc
src/log/Tokens.cc
src/log/Tokens.h
src/log/access_log.cc
src/tunnel.cc

index c2e43849e3753f2423eef64b11b7f5fd3741c43e..f164ba385dc7d5f7e0232102dd7c05a929f09347 100644 (file)
@@ -519,7 +519,8 @@ This section gives a thorough account of those changes in three categories:
        <tag>logformat</tag>
         <p><em>%&gt;bs</em> Number of HTTP-equivalent message body bytes received from the next hop.
         <p><em>icap::%&gt;bs</em> Number of message body bytes received from the ICAP server.
-       <p><em>%&gt;lp</em> Local TCP port used by transactions with http servers.
+       <p><em>%&lt;la</em> Local IP address of the last server or peer connection. Ported from 2.7 where it is called <em>%oa</em>.
+       <p><em>%&lt;lp</em> Local port number of the last server or peer connection.
        <p><em>%sn</em> Unique sequence number per log line. Ported from 2.7
        <p><em>%&gt;eui</em> EUI logging (EUI-48 / MAC address for IPv4, EUI-64 for IPv6)
           Both EUI forms are logged in the same field. Type can be identified by length or byte delimiter.
@@ -897,9 +898,6 @@ This section gives an account of those changes in three categories:
        <tag>location_rewrite_program</tag>
        <p>Not yet ported from 2.6
 
-       <tag>logformat</tag>
-       <p><em>%oa</em> tag not yet ported from 2.7
-
        <tag>refresh_pattern</tag>
        <p><em>stale-while-revalidate=</em> not yet ported from 2.7
        <p><em>ignore-stale-while-revalidate=</em> not yet ported from 2.7
index b5a04f2330d8fe7110cfb24a312dbdf706a858f1..9038e5e6a2ebf9e9f39c46d56bbb8e02f1c33fc6 100644 (file)
@@ -35,6 +35,7 @@
 #define SQUID_HTTPHIERARCHYLOGENTRY_H
 
 #include "hier_code.h"
+#include "ip/Address.h"
 #include "lookup_t.h"
 #include "rfc2181.h"
 #include "PingData.h"
@@ -64,7 +65,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
+    Ip::Address peer_local_addr; ///< local IP:port of the last server-side connection
     int64_t bodyBytesRead;  ///< number of body bytes received from the next hop or -1
 };
 
index 7c6bce7db6eaf9cf3a11c496c9f7c6a7a7cdb867..7e9fc23d0aef027e6738a7f01f8920c10b7d7074 100644 (file)
@@ -2873,6 +2873,7 @@ 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
 
        Time related format codes:
index c5add74918914405d7b83c09d6404ebaa1b12797..0c1d27c1a290600026f28229097316b4f399ac2a 100644 (file)
@@ -880,8 +880,8 @@ 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);
+        if (comm_local_port(fd))
+            request->hier.peer_local_addr = fd_table[fd].local_addr;
 
         dispatch();
 
@@ -949,7 +949,8 @@ FwdState::connectStart()
     if (!fs->_peer)
         origin_tries++;
 
-    request->hier.peer_local_port = comm_local_port(fd);
+    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
index 95430844bd3fecfae5308b918538a201cc3d3650..46102f7330e8cc6a93841fae2a142508c1bc5482 100644 (file)
@@ -173,7 +173,7 @@ Log::Format::SquidCustom(AccessLogEntry * al, customlog * log)
 
         case LFT_LOCAL_IP:
             if (al->request) {
-                out = al->request->my_addr.NtoA(tmp,1024);
+                out = al->request->my_addr.NtoA(tmp,sizeof(tmp));
             }
 
             break;
@@ -186,9 +186,17 @@ Log::Format::SquidCustom(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 (al->hier.peer_local_port) {
-                outint = al->hier.peer_local_port;
+            if ((outint = al->hier.peer_local_addr.GetPort())) {
                 doint = 1;
             }
 
index 0d5a1795722c8957033154d0ebe1c5609dbe5577..438e75b67b6b90ed081a6fd1d8c39c5820e6543e 100644 (file)
@@ -85,13 +85,14 @@ struct logformat_token_table_entry logformat_token_table[] = {
     /*{ "<p", LFT_SERVER_PORT }, */
     {"<A", LFT_SERVER_IP_OR_PEER_NAME},
 
-    /* {"oa", LFT_OUTGOING_IP}, */
-    /* {"ot", LFT_OUTGOING_TOS}, */
-
     {"la", LFT_LOCAL_IP},
     {"lp", LFT_LOCAL_PORT},
     /*{ "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},
@@ -453,9 +454,15 @@ done:
         break;
 
     case LFT_HTTP_SENT_STATUS_CODE_OLD_30:
-        debugs(46, 0, "WARNING: the \"Hs\" formating code is deprecated use the \">Hs\" instead");
+        debugs(46, 0, "WARNING: The \"Hs\" formatting 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;
     }
index 54cffff0d0271f3fd40668bdd4cbdc7fc2793253..7f3a0e73552d8ffb1e29449b68d3a5a257119b6d 100644 (file)
@@ -59,6 +59,8 @@ 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,
index c7eb2f2a894709d0664c296d16517b26c8053e45..9869232f839d0e940aae3f165c26b7f5d326ca02 100644 (file)
@@ -252,7 +252,7 @@ HierarchyLogEntry::HierarchyLogEntry() :
         peer_reply_status(HTTP_STATUS_NONE),
         peer_response_time(-1),
         total_response_time(-1),
-        peer_local_port(0),
+        peer_local_addr(),
         bodyBytesRead(-1)
 {
     memset(host, '\0', SQUIDHOSTNAMELEN);
index 6e1945de0c30d92709b26b88b3fb37422633f11d..8d409913a756020154683cd24e035c0a40407958 100644 (file)
@@ -688,7 +688,9 @@ tunnelStart(ClientHttpRequest * http, int64_t * size_ptr, int *status_ptr)
         return;
     }
 
-    request->hier.peer_local_port = comm_local_port(sock); // for %<lp logging
+    // 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 USE_DELAY_POOLS