From: Amos Jeffries Date: Wed, 30 Mar 2011 04:29:35 +0000 (-0600) Subject: Port 2.7: logformat tag for logging the outgoing IP address (tcp_outgoing_address) X-Git-Tag: take06~27^2~55 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c3a082aee7707d65a90482f001077256043190d1;p=thirdparty%2Fsquid.git 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 %logformat

%>bs Number of HTTP-equivalent message body bytes received from the next hop.

icap::%>bs Number of message body bytes received from the ICAP server. -

%>lp Local TCP port used by transactions with http servers. +

%<la Local IP address of the last server or peer connection. Ported from 2.7 where it is called %oa. +

%<lp Local port number of the last server or peer connection.

%sn Unique sequence number per log line. Ported from 2.7

%>eui 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: location_rewrite_program

Not yet ported from 2.6 - logformat -

%oa tag not yet ported from 2.7 - refresh_pattern

stale-while-revalidate= not yet ported from 2.7

ignore-stale-while-revalidate= not yet ported from 2.7 diff --git a/src/HierarchyLogEntry.h b/src/HierarchyLogEntry.h index b5a04f2330..9038e5e6a2 100644 --- a/src/HierarchyLogEntry.h +++ b/src/HierarchyLogEntry.h @@ -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 }; diff --git a/src/cf.data.pre b/src/cf.data.pre index 7c6bce7db6..7e9fc23d0a 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -2873,6 +2873,7 @@ DOC_START 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 diff --git a/src/log/FormatSquidCustom.cc b/src/log/FormatSquidCustom.cc index 95430844bd..46102f7330 100644 --- a/src/log/FormatSquidCustom.cc +++ b/src/log/FormatSquidCustom.cc @@ -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; } diff --git a/src/log/Tokens.cc b/src/log/Tokens.cc index 0d5a179572..438e75b67b 100644 --- a/src/log/Tokens.cc +++ b/src/log/Tokens.cc @@ -85,13 +85,14 @@ struct logformat_token_table_entry logformat_token_table[] = { /*{ "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 \"type = LFT_PEER_LOCAL_IP; + break; + default: break; } diff --git a/src/log/Tokens.h b/src/log/Tokens.h index 54cffff0d0..7f3a0e7355 100644 --- a/src/log/Tokens.h +++ b/src/log/Tokens.h @@ -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, diff --git a/src/log/access_log.cc b/src/log/access_log.cc index c7eb2f2a89..9869232f83 100644 --- a/src/log/access_log.cc +++ b/src/log/access_log.cc @@ -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); diff --git a/src/tunnel.cc b/src/tunnel.cc index 6e1945de0c..8d409913a7 100644 --- a/src/tunnel.cc +++ b/src/tunnel.cc @@ -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 %hier.peer_local_addr = fd_table[sock].local_addr; tunnelState = new TunnelStateData; #if USE_DELAY_POOLS