From: Christos Tsantilas Date: Sun, 26 Jan 2020 20:13:55 +0000 (+0000) Subject: Add %transport::>connection_id logformat code (#546) X-Git-Tag: 4.15-20210522-snapshot~169 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a120b7a8793b8b1fadd97063dd5c20485a3ab1f1;p=thirdparty%2Fsquid.git Add %transport::>connection_id logformat code (#546) Knowing client transport connection ID can be very helpful in triage, especially when dealing with multiple requests associated with a problematic connection (e.g., two access log records associated with a single TLS connection bumping failure). The "transport" namespace was added in hope to reduce confusion when/if other connection_id %codes are added. The shorter and more familiar "tcp::" namespace was rejected because we want configurations using the new %code to continue to work well after Squid gains HTTP/3 support, and HTTP/3 uses UDP for transport connections. Other UDP-based protocols may have similar "connection" concepts. This is a Measurement Factory project. --- diff --git a/src/cf.data.pre b/src/cf.data.pre index 615895e243..ab485d6040 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -4563,6 +4563,19 @@ DOC_START >qos Client connection TOS/DSCP value set by Squid >nfmark Client connection netfilter packet MARK set by Squid + transport::>connection_id Identifies a transport connection + accepted by Squid (e.g., a connection carrying the + logged HTTP request). Currently, Squid only supports + TCP transport connections. + + The logged identifier is an unsigned integer. These + IDs are guaranteed to monotonically increase within a + single worker process lifetime, with higher values + corresponding to connections that were accepted later. + Many IDs are skipped (i.e. never logged). Concurrent + workers and restarted workers use similar, partially + overlapping sequences of IDs. + la Local listening IP address the client connection was connected to. lp Local listening port number the client connection was connected to. diff --git a/src/comm/Connection.cc b/src/comm/Connection.cc index 3e36be06e3..1fb1351328 100644 --- a/src/comm/Connection.cc +++ b/src/comm/Connection.cc @@ -19,7 +19,7 @@ #include "SquidTime.h" #include -InstanceIdDefinitions(Comm::Connection, "conn"); +InstanceIdDefinitions(Comm::Connection, "conn", uint64_t); class CachePeer; bool diff --git a/src/comm/Connection.h b/src/comm/Connection.h index d5d8c55a9b..b02f23ef10 100644 --- a/src/comm/Connection.h +++ b/src/comm/Connection.h @@ -175,7 +175,7 @@ public: Eui::Eui64 remoteEui64; #endif - InstanceId id; + InstanceId id; private: /** cache_peer data object (if any) */ diff --git a/src/format/ByteCode.h b/src/format/ByteCode.h index 088ac0db3e..a519867e04 100644 --- a/src/format/ByteCode.h +++ b/src/format/ByteCode.h @@ -46,6 +46,8 @@ typedef enum { LFT_CLIENT_LOCAL_TOS, LFT_CLIENT_LOCAL_NFMARK, + LFT_TRANSPORT_CLIENT_CONNECTION_ID, + LFT_CLIENT_HANDSHAKE, /* client connection local squid.conf details */ diff --git a/src/format/Format.cc b/src/format/Format.cc index 2152f6f36c..76f6011f01 100644 --- a/src/format/Format.cc +++ b/src/format/Format.cc @@ -508,6 +508,13 @@ Format::Format::assemble(MemBuf &mb, const AccessLogEntry::Pointer &al, int logS } break; + case LFT_TRANSPORT_CLIENT_CONNECTION_ID: + if (al->tcpClient) { + outUint64 = al->tcpClient->id.value; + doUint64 = true; + } + break; + case LFT_CLIENT_LOCAL_NFMARK: if (al->tcpClient) { sb.appendf("0x%x", al->tcpClient->nfmark); diff --git a/src/format/Token.cc b/src/format/Token.cc index 2be31d51e8..9175bf776a 100644 --- a/src/format/Token.cc +++ b/src/format/Token.cc @@ -183,6 +183,10 @@ static TokenTableEntry TokenTableProxyProtocol[] = { TokenTableEntry(">h", LFT_PROXY_PROTOCOL_RECEIVED_HEADER), }; +static TokenTableEntry TokenTableTransport[] = { + TokenTableEntry(">connection_id", LFT_TRANSPORT_CLIENT_CONNECTION_ID), +}; + #if USE_ADAPTATION static TokenTableEntry TokenTableAdapt[] = { TokenTableEntry("all_trs", LFT_ADAPTATION_ALL_XACT_TIMES), @@ -259,6 +263,7 @@ Format::Token::Init() TheConfig.registerTokens(SBuf("ssl"),::Format::TokenTableSsl); #endif TheConfig.registerTokens(SBuf("proxy_protocol"), ::Format::TokenTableProxyProtocol); + TheConfig.registerTokens(SBuf("transport"), ::Format::TokenTableTransport); } /// Scans a token table to see if the next token exists there diff --git a/src/tests/stub_libcomm.cc b/src/tests/stub_libcomm.cc index 4e3edbc092..6c921b3727 100644 --- a/src/tests/stub_libcomm.cc +++ b/src/tests/stub_libcomm.cc @@ -28,7 +28,7 @@ CachePeer * Comm::Connection::getPeer() const STUB_RETVAL(NULL) void Comm::Connection::setPeer(CachePeer * p) STUB ScopedId Comm::Connection::codeContextGist() const STUB_RETVAL(id.detach()) std::ostream &Comm::Connection::detailCodeContext(std::ostream &os) const STUB_RETVAL(os) -InstanceIdDefinitions(Comm::Connection, "conn"); +InstanceIdDefinitions(Comm::Connection, "conn", uint64_t); #include "comm/ConnOpener.h" CBDATA_NAMESPACED_CLASS_INIT(Comm, ConnOpener);