]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 3288: regression in %<la and %<lp
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 20 Aug 2011 08:21:11 +0000 (20:21 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 20 Aug 2011 08:21:11 +0000 (20:21 +1200)
src/AccessLogEntry.h
src/HierarchyLogEntry.h
src/client_side_request.cc
src/format/Format.cc
src/forward.cc
src/log/access_log.cc
src/tunnel.cc

index d15604f2af36d4e77c28fb1c06db96478856db9a..e4c29fa0fd166d45399be51178965c5856acfb4b 100644 (file)
@@ -30,6 +30,7 @@
 #ifndef SQUID_HTTPACCESSLOGENTRY_H
 #define SQUID_HTTPACCESSLOGENTRY_H
 
+#include "comm/Connection.h"
 #include "HttpVersion.h"
 #include "HttpRequestMethod.h"
 #include "HierarchyLogEntry.h"
@@ -47,11 +48,16 @@ class AccessLogEntry
 {
 
 public:
-    AccessLogEntry() : url(NULL) , reply(NULL), request(NULL),
+    AccessLogEntry() : url(NULL), tcpClient(), reply(NULL), request(NULL),
             adapted_request(NULL) {}
 
     const char *url;
 
+    /// TCP/IP level details about the client connection
+    Comm::ConnectionPointer tcpClient;
+    // TCP/IP level details about the server or peer connection
+    // are stored in hier.tcpServer
+
     /** \brief This subclass holds log info for HTTP protocol
      * \todo Inner class declarations should be moved outside
      * \todo details of HTTP held in the parent class need moving into here.
index 9038e5e6a2ebf9e9f39c46d56bbb8e02f1c33fc6..f6bccbc68dc024ee7f7e723297b19d32d434d7d4 100644 (file)
@@ -34,8 +34,8 @@
 #ifndef SQUID_HTTPHIERARCHYLOGENTRY_H
 #define SQUID_HTTPHIERARCHYLOGENTRY_H
 
+#include "comm/Connection.h"
 #include "hier_code.h"
-#include "ip/Address.h"
 #include "lookup_t.h"
 #include "rfc2181.h"
 #include "PingData.h"
@@ -48,6 +48,13 @@ class HierarchyLogEntry
 
 public:
     HierarchyLogEntry();
+    ~HierarchyLogEntry() { tcpServer = NULL; };
+
+    /// Record details from a new server connection.
+    /// call this whenever the destination server changes.
+    void note(const Comm::ConnectionPointer &server, const char *requestedHost);
+
+public:
     hier_code code;
     char host[SQUIDHOSTNAMELEN];
     ping_data ping;
@@ -65,10 +72,8 @@ 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
-    Ip::Address peer_local_addr; ///< local IP:port of the last server-side connection
+    Comm::ConnectionPointer tcpServer; ///< TCP/IP level details of the last server-side connection
     int64_t bodyBytesRead;  ///< number of body bytes received from the next hop or -1
 };
 
-extern void hierarchyNote(HierarchyLogEntry *, hier_code, const char *);
-
 #endif /* SQUID_HTTPHIERARCHYLOGENTRY_H */
index 05d512c5c45651263b557b29470ce073b2856f7f..307dfebd363d4d67ba06044752520024d02c31b1 100644 (file)
@@ -175,7 +175,7 @@ ClientHttpRequest::ClientHttpRequest(ConnStateData * aConn) :
 {
     start_time = current_time;
     setConn(aConn);
-    clientConnection = aConn->clientConnection;
+    al.tcpClient = clientConnection = aConn->clientConnection;
     dlinkAdd(this, &active, &ClientActiveRequests);
 #if USE_ADAPTATION
     request_satisfaction_mode = false;
index 8e611520cbc04336815d00dcb2b12d3a52574c6b..7cb04620d58417f6388391ce00e35d776d2c929f 100644 (file)
@@ -361,31 +361,30 @@ Format::Format::assemble(MemBuf &mb, AccessLogEntry *al, int logSequenceNumber)
             /* case LFT_SERVER_PORT: */
 
         case LFT_LOCAL_IP:
-            if (al->request) {
-                out = al->request->my_addr.NtoA(tmp,sizeof(tmp));
+            if (al->tcpClient != NULL) {
+                out = al->tcpClient->local.NtoA(tmp,sizeof(tmp));
             }
-
             break;
 
         case LFT_LOCAL_PORT:
-            if (al->request) {
-                outint = al->request->my_addr.GetPort();
+            if (al->tcpClient != NULL) {
+                outint = al->tcpClient->local.GetPort();
                 doint = 1;
             }
-
             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));
+            if (al->hier.tcpServer != NULL) {
+                out = al->hier.tcpServer->local.NtoA(tmp,sizeof(tmp));
             }
             break;
 
         case LFT_PEER_LOCAL_PORT:
-            if ((outint = al->hier.peer_local_addr.GetPort())) {
+            if (al->hier.tcpServer != NULL) {
+                outint = al->hier.tcpServer->local.GetPort();
                 doint = 1;
             }
 
index 87bf1fd83427afe11117a18e18b03d84818a71f4..d258848878283582026cf3917f46da6bf43d7b56 100644 (file)
@@ -728,11 +728,6 @@ FwdState::connectDone(const Comm::ConnectionPointer &conn, comm_err_t status, in
 
     serverConn = conn;
 
-#if REDUNDANT_NOW
-    if (Config.onoff.log_ip_on_direct && serverConnection()->peerType == HIER_DIRECT)
-        updateHierarchyInfo();
-#endif
-
     debugs(17, 3, HERE << serverConnection() << ": '" << entry->url() << "'" );
 
     comm_add_close_handler(serverConnection()->fd, fwdServerClosedWrapper, this);
@@ -1195,24 +1190,9 @@ void
 FwdState::updateHierarchyInfo()
 {
     assert(request);
-
     assert(serverDestinations.size() > 0);
 
-    char nextHop[256];
-
-    if (serverConnection()->getPeer()) {
-        // went to peer, log peer host name
-        snprintf(nextHop,256,"%s", serverConnection()->getPeer()->name);
-    } else {
-        // went DIRECT, must honor log_ip_on_direct
-        if (!Config.onoff.log_ip_on_direct)
-            snprintf(nextHop,256,"%s",request->GetHost()); // domain name
-        else
-            serverConnection()->remote.NtoA(nextHop, 256);
-    }
-
-    assert(nextHop[0]);
-    hierarchyNote(&request->hier, serverConnection()->peerType, nextHop);
+    request->hier.note(serverConnection(), request->GetHost());
 }
 
 
index a1160e1fb5a6e563891914c71e4803de15ad92a7..35cfbe955c15cf1b87f8bbeb873e7f1e88ac05fb 100644 (file)
@@ -252,7 +252,7 @@ HierarchyLogEntry::HierarchyLogEntry() :
         peer_reply_status(HTTP_STATUS_NONE),
         peer_response_time(-1),
         total_response_time(-1),
-        peer_local_addr(),
+        tcpServer(NULL),
         bodyBytesRead(-1)
 {
     memset(host, '\0', SQUIDHOSTNAMELEN);
@@ -272,13 +272,26 @@ HierarchyLogEntry::HierarchyLogEntry() :
 }
 
 void
-hierarchyNote(HierarchyLogEntry * hl,
-              hier_code code,
-              const char *cache_peer)
+HierarchyLogEntry::note(const Comm::ConnectionPointer &server, const char *requestedHost)
 {
-    assert(hl != NULL);
-    hl->code = code;
-    xstrncpy(hl->host, cache_peer, SQUIDHOSTNAMELEN);
+    tcpServer = server;
+    if (tcpServer == NULL) {
+       code = HIER_NONE;
+       xstrncpy(host, requestedHost, sizeof(host));
+    } else {
+        code = tcpServer->peerType;
+
+        if (tcpServer->getPeer()) {
+            // went to peer, log peer host name
+            xstrncpy(host, tcpServer->getPeer()->name, sizeof(host));
+        } else {
+            // went DIRECT, must honor log_ip_on_direct
+            if (!Config.onoff.log_ip_on_direct)
+                xstrncpy(host, requestedHost, sizeof(host));
+            else
+                tcpServer->remote.NtoA(host, 256);
+        }
+    }
 }
 
 static void
index 6e9018a5a270b1334a81c4598f1c145807dfefe6..0114c7846659a91eac5b46d3499faf557b27090e 100644 (file)
@@ -571,14 +571,7 @@ tunnelConnectDone(const Comm::ConnectionPointer &conn, comm_err_t status, int xe
         tunnelState->server.setDelayId(DelayId());
 #endif
 
-    if (conn != NULL && conn->getPeer())
-        hierarchyNote(&tunnelState->request->hier, conn->peerType, conn->getPeer()->name);
-    else if (Config.onoff.log_ip_on_direct) {
-        conn->remote.NtoA(fd_table[conn->fd].ipaddr,sizeof(fd_table[conn->fd].ipaddr));
-        hierarchyNote(&tunnelState->request->hier, conn->peerType, fd_table[conn->fd].ipaddr);
-    } else
-        hierarchyNote(&tunnelState->request->hier, conn->peerType, tunnelState->getHost());
-
+    tunnelState->request->hier.note(conn, tunnelState->getHost());
 
     tunnelState->server.conn = conn;
     tunnelState->request->peer_host = conn->getPeer() ? conn->getPeer()->host : NULL;