]> git.ipfire.org Git - thirdparty/squid.git/blame - src/AccessLogEntry.h
Log PROXY protocol v2 TLVs; fix PROXY protocol parsing bugs (#342)
[thirdparty/squid.git] / src / AccessLogEntry.h
CommitLineData
450e0c10 1/*
f6e9a3ee 2 * Copyright (C) 1996-2019 The Squid Software Foundation and contributors
450e0c10 3 *
bbc27441
AJ
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
450e0c10 7 */
bbc27441 8
450e0c10 9#ifndef SQUID_HTTPACCESSLOGENTRY_H
10#define SQUID_HTTPACCESSLOGENTRY_H
11
65d448bc 12#include "anyp/PortCfg.h"
8bf217bd 13#include "base/RefCount.h"
a14f38d0 14#include "comm/Connection.h"
602d9612 15#include "HierarchyLogEntry.h"
526ed14e 16#include "http/ProtocolVersion.h"
f35c0145 17#include "http/RequestMethod.h"
e74be5fd 18#include "HttpHeader.h"
c8f1812b 19#include "icp_opcode.h"
96d89ea0 20#include "ip/Address.h"
02c8dde5 21#include "LogTags.h"
cc0ca3b9 22#include "MessageSizes.h"
02c8dde5 23#include "Notes.h"
36c774f7 24#include "proxyp/forward.h"
f57ae909 25#include "sbuf/SBuf.h"
3ff65596
AR
26#if ICAP_CLIENT
27#include "adaptation/icap/Elements.h"
28#endif
cb4f4424 29#if USE_OPENSSL
f4698e0b 30#include "ssl/gadgets.h"
78a4bf03 31#include "ssl/support.h"
f4698e0b 32#endif
450e0c10 33
62ee09ca 34/* forward decls */
e1f7507e
AJ
35class HttpReply;
36class HttpRequest;
613924ee 37class CustomLog;
62ee09ca 38
41ebd397 39class AccessLogEntry: public RefCountable
450e0c10 40{
41
42public:
41ebd397
CT
43 typedef RefCount<AccessLogEntry> Pointer;
44
36c774f7 45 AccessLogEntry();
41ebd397 46 ~AccessLogEntry();
450e0c10 47
d4204018
AJ
48 /// Fetch the client IP log string into the given buffer.
49 /// Knows about several alternate locations of the IP
50 /// including indirect forwarded-for IP if configured to log that
51 void getLogClientIp(char *buf, size_t bufsz) const;
52
e3bf07f5
AJ
53 /// Fetch the client IDENT string, or nil if none is available.
54 const char *getClientIdent() const;
55
56 /// Fetch the external ACL provided 'user=' string, or nil if none is available.
57 const char *getExtUser() const;
58
58b148e1
AJ
59 /// Fetch the transaction method string (ICP opcode, HTCP opcode or HTTP method)
60 SBuf getLogMethod() const;
61
75d47340
CT
62 void syncNotes(HttpRequest *request);
63
f57ae909 64 SBuf url;
450e0c10 65
a14f38d0
AJ
66 /// TCP/IP level details about the client connection
67 Comm::ConnectionPointer tcpClient;
68 // TCP/IP level details about the server or peer connection
69 // are stored in hier.tcpServer
70
4e26d606
AJ
71 /** \brief This subclass holds log info for HTTP protocol
72 * \todo Inner class declarations should be moved outside
73 * \todo details of HTTP held in the parent class need moving into here.
74 */
450e0c10 75 class HttpDetails
76 {
77
78 public:
60745f24 79 HttpRequestMethod method;
78a4bf03
AJ
80 int code = 0;
81 const char *content_type = nullptr;
2592bc70 82 AnyP::ProtocolVersion version;
d6df21d2
AJ
83
84 /// counters for the original request received from client
85 // TODO calculate header and payload better (by parser)
86 // XXX payload encoding overheads not calculated at all yet.
cc0ca3b9 87 MessageSizes clientRequestSz;
d6df21d2
AJ
88
89 /// counters for the response sent to client
90 // TODO calculate header and payload better (by parser)
91 // XXX payload encoding overheads not calculated at all yet.
cc0ca3b9 92 MessageSizes clientReplySz;
d6df21d2 93
2fadd50d 94 } http;
450e0c10 95
4e26d606
AJ
96 /** \brief This subclass holds log info for ICP protocol
97 * \todo Inner class declarations should be moved outside
98 */
99 class IcpDetails
450e0c10 100 {
450e0c10 101 public:
78a4bf03 102 icp_opcode opcode = ICP_INVALID;
2fadd50d 103 } icp;
450e0c10 104
4e26d606
AJ
105 /** \brief This subclass holds log info for HTCP protocol
106 * \todo Inner class declarations should be moved outside
107 */
04f7fd38
AJ
108 class HtcpDetails
109 {
a8b1cdf6 110 public:
78a4bf03 111 const char *opcode = nullptr;
a8b1cdf6
AJ
112 } htcp;
113
cb4f4424 114#if USE_OPENSSL
08097970 115 /// logging information specific to the SSL protocol
87f237a9
A
116 class SslDetails
117 {
08097970 118 public:
78a4bf03
AJ
119 const char *user = nullptr; ///< emailAddress from the SSL client certificate
120 int bumpMode = ::Ssl::bumpEnd; ///< whether and how the request was SslBumped
08097970
AR
121 } ssl;
122#endif
123
4e26d606
AJ
124 /** \brief This subclass holds log info for Squid internal stats
125 * \todo Inner class declarations should be moved outside
126 * \todo some details relevant to particular protocols need shuffling to other sub-classes
127 * \todo this object field need renaming to 'squid' or something.
128 */
450e0c10 129 class CacheDetails
130 {
450e0c10 131 public:
78a4bf03 132 CacheDetails() {
d4806c91 133 caddr.setNoAddr();
4579a6d0 134 memset(&start_time, 0, sizeof(start_time));
01bd87d8 135 memset(&trTime, 0, sizeof(start_time));
450e0c10 136 }
137
b7ac5457 138 Ip::Address caddr;
78a4bf03
AJ
139 int64_t highOffset = 0;
140 int64_t objectSize = 0;
d2a6dcba 141 LogTags code;
af0ded40 142 struct timeval start_time; ///< The time the master transaction started
01bd87d8 143 struct timeval trTime; ///< The response time
78a4bf03
AJ
144 const char *rfc931 = nullptr;
145 const char *extuser = nullptr;
cb4f4424 146#if USE_OPENSSL
78a4bf03 147 const char *ssluser = nullptr;
f97700a0 148 Security::CertPointer sslClientCert; ///< cert received from the client
450e0c10 149#endif
fa720bfb 150 AnyP::PortCfgPointer port;
2fadd50d 151 } cache;
450e0c10 152
4e26d606
AJ
153 /** \brief This subclass holds log info for various headers in raw format
154 * \todo shuffle this to the relevant protocol section.
155 */
450e0c10 156 class Headers
157 {
450e0c10 158 public:
78a4bf03
AJ
159 char *request = nullptr; //< virgin HTTP request headers
160 char *adapted_request = nullptr; //< HTTP request headers after adaptation and redirection
161 char *reply = nullptr;
99690f32 162 } headers;
3ff65596 163
5038f9d8 164#if USE_ADAPTATION
99690f32
AR
165 /** \brief This subclass holds general adaptation log info.
166 * \todo Inner class declarations should be moved outside.
167 */
168 class AdaptationDetails
169 {
99690f32 170 public:
99690f32 171 /// image of the last ICAP response header or eCAP meta received
78a4bf03 172 char *last_meta = nullptr;
99690f32 173 } adapt;
3ff65596 174#endif
450e0c10 175
78a4bf03 176 const char *lastAclName = nullptr; ///< string for external_acl_type %ACL format code
b0e14ce2 177 SBuf lastAclData; ///< string for external_acl_type %DATA format code
4ff6370b 178
450e0c10 179 HierarchyLogEntry hier;
78a4bf03
AJ
180 HttpReply *reply = nullptr;
181 HttpRequest *request = nullptr; //< virgin HTTP request
182 HttpRequest *adapted_request = nullptr; //< HTTP request after adaptation and redirection
d06e17ea 183
f4f55a21 184 /// key:value pairs set by squid.conf note directive and
cf9f0261 185 /// key=value pairs returned from URL rewrite/redirect helper
f4f55a21 186 NotePairs::Pointer notes;
6fca33e0 187
36c774f7
EB
188 /// see ConnStateData::proxyProtocolHeader_
189 ProxyProtocol::HeaderPointer proxyProtocolHeader;
190
3ff65596
AR
191#if ICAP_CLIENT
192 /** \brief This subclass holds log info for ICAP part of request
193 * \todo Inner class declarations should be moved outside
194 */
e1381638
AJ
195 class IcapLogEntry
196 {
3ff65596 197 public:
78a4bf03 198 IcapLogEntry() {
01bd87d8
CT
199 memset(&trTime, 0, sizeof(trTime));
200 memset(&ioTime, 0, sizeof(ioTime));
201 memset(&processingTime, 0, sizeof(processingTime));
202 }
3ff65596 203
b7ac5457 204 Ip::Address hostAddr; ///< ICAP server IP address
3ff65596
AR
205 String serviceName; ///< ICAP service name
206 String reqUri; ///< ICAP Request-URI
78a4bf03
AJ
207 Adaptation::Icap::ICAP::Method reqMethod = Adaptation::methodNone; ///< ICAP request method
208 int64_t bytesSent = 0; ///< number of bytes sent to ICAP server so far
209 int64_t bytesRead = 0; ///< number of bytes read from ICAP server so far
bae917ac 210 /**
dcaab393 211 * number of ICAP body bytes read from ICAP server or -1 for no encapsulated
bae917ac
CT
212 * message data in ICAP reply (eg 204 responses)
213 */
78a4bf03
AJ
214 int64_t bodyBytesRead = -1;
215 HttpRequest* request = nullptr; ///< ICAP request
216 HttpReply* reply = nullptr; ///< ICAP reply
3ff65596 217
78a4bf03 218 Adaptation::Icap::XactOutcome outcome = Adaptation::Icap::xoUnknown; ///< final transaction status
3ff65596
AR
219 /** \brief Transaction response time.
220 * The timer starts when the ICAP transaction
221 * is created and stops when the result of the transaction is logged
222 */
01bd87d8 223 struct timeval trTime;
3ff65596
AR
224 /** \brief Transaction I/O time.
225 * The timer starts when the first ICAP request
e1381638 226 * byte is scheduled for sending and stops when the lastbyte of the
3ff65596
AR
227 * ICAP response is received.
228 */
01bd87d8 229 struct timeval ioTime;
78a4bf03 230 Http::StatusCode resStatus = Http::scNone; ///< ICAP response status code
01bd87d8 231 struct timeval processingTime; ///< total ICAP processing time
3ff65596
AR
232 }
233 icap;
234#endif
bec110e4
EB
235
236 /// Effective URI of the received client (or equivalent) HTTP request or,
237 /// in rare cases where that information was not collected, a nil pointer.
238 /// Receiving errors are represented by "error:..." URIs.
239 /// Adaptations and redirections do not affect this URI.
240 const SBuf *effectiveVirginUrl() const;
241
242 /// Remember Client URI (or equivalent) when there is no HttpRequest.
243 void setVirginUrlForMissingRequest(const SBuf &vu)
244 {
245 if (!request)
246 virginUrlForMissingRequest_ = vu;
247 }
248
249private:
250 /// Client URI (or equivalent) for effectiveVirginUrl() when HttpRequest is
251 /// missing. This member is ignored unless the request member is nil.
252 SBuf virginUrlForMissingRequest_;
450e0c10 253};
254
e1f7507e
AJ
255class ACLChecklist;
256class StoreEntry;
e1f7507e 257
450e0c10 258/* Should be in 'AccessLog.h' as the driver */
8a648e8d
FC
259void accessLogLogTo(CustomLog* log, AccessLogEntry::Pointer &al, ACLChecklist* checklist = NULL);
260void accessLogLog(AccessLogEntry::Pointer &, ACLChecklist * checklist);
261void accessLogRotate(void);
262void accessLogClose(void);
263void accessLogInit(void);
264const char *accessLogTime(time_t);
450e0c10 265
266#endif /* SQUID_HTTPACCESSLOGENTRY_H */
f53969cc 267