FilledChecklist.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
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.
7  */
8 
9 #include "squid.h"
10 #include "acl/FilledChecklist.h"
11 #include "client_side.h"
12 #include "comm/Connection.h"
13 #include "comm/forward.h"
14 #include "debug/Messages.h"
15 #include "ExternalACLEntry.h"
16 #include "http/Stream.h"
17 #include "HttpReply.h"
18 #include "HttpRequest.h"
19 #include "SquidConfig.h"
20 #if USE_AUTH
21 #include "auth/AclProxyAuth.h"
22 #include "auth/UserRequest.h"
23 #endif
24 
26 
28  dst_rdns(nullptr),
29 #if USE_AUTH
30  auth_user_request (nullptr),
31 #endif
32 #if SQUID_SNMP
33  snmp_community(nullptr),
34 #endif
35  requestErrorType(ERR_MAX),
36  conn_(nullptr),
37  fd_(-1),
38  destinationDomainChecked_(false),
39  sourceDomainChecked_(false)
40 {
41  my_addr.setEmpty();
44 }
45 
47 {
49 
50  safe_free(dst_rdns); // created by xstrdup().
51 
53 
54  debugs(28, 4, "ACLFilledChecklist destroyed " << this);
55 }
56 
57 static void
58 showDebugWarning(const char *msg)
59 {
60  static uint16_t count = 0;
61  if (count > 10)
62  return;
63 
64  ++count;
65  debugs(28, Important(58), "ERROR: ALE missing " << msg);
66 }
67 
68 void
70 {
71  // make sure the ALE fields used by Format::assemble to
72  // fill the old external_acl_type codes are set if any
73  // data on them exists in the Checklist
74 
75  if (!al->cache.port && conn()) {
76  showDebugWarning("listening port");
77  al->cache.port = conn()->port;
78  }
79 
80  if (request) {
81  if (!al->request) {
82  showDebugWarning("HttpRequest object");
83  // XXX: al->request should be original,
84  // but the request may be already adapted
85  al->request = request.getRaw();
87  }
88 
89  if (!al->adapted_request) {
90  showDebugWarning("adapted HttpRequest object");
93  }
94 
95  if (al->url.isEmpty()) {
96  showDebugWarning("URL");
97  // XXX: al->url should be the request URL from client,
98  // but request->url may be different (e.g.,redirected)
100  }
101  }
102 
103  if (hasReply() && !al->reply) {
104  showDebugWarning("HttpReply object");
105  al->reply = reply_;
106  }
107 }
108 
109 void
110 ACLFilledChecklist::syncAle(HttpRequest *adaptedRequest, const char *logUri) const
111 {
112  if (!al)
113  return;
114  if (adaptedRequest && !al->adapted_request) {
115  al->adapted_request = adaptedRequest;
117  }
118  if (logUri && al->url.isEmpty())
119  al->url = logUri;
120 }
121 
124 {
125  return cbdataReferenceValid(conn_) ? conn_ : nullptr;
126 }
127 
128 void
130 {
131  if (conn_ == aConn)
132  return; // no new information
133 
134  // no conn_ replacement/removal to reduce inconsistent fill concerns
135  assert(!conn_);
136  assert(aConn);
137 
138  // To reduce inconsistent fill concerns, we should be the only ones calling
139  // fillConnectionLevelDetails(). Set conn_ first so that the filling method
140  // can detect (some) direct calls from others.
141  conn_ = cbdataReference(aConn);
142  aConn->fillConnectionLevelDetails(*this);
143 }
144 
145 int
147 {
148  const auto c = conn();
149  return (c && c->clientConnection) ? c->clientConnection->fd : fd_;
150 }
151 
152 void
153 ACLFilledChecklist::fd(int aDescriptor)
154 {
155  const auto c = conn();
156  assert(!c || !c->clientConnection || c->clientConnection->fd == aDescriptor);
157  fd_ = aDescriptor;
158 }
159 
160 bool
162 {
164 }
165 
166 void
168 {
171 }
172 
173 bool
175 {
176  return sourceDomainChecked_;
177 }
178 
179 void
181 {
183  sourceDomainChecked_ = true;
184 }
185 
186 /*
187  * There are two common ACLFilledChecklist lifecycles paths:
188  *
189  * "Fast" (always synchronous or "blocking"): The user constructs an
190  * ACLFilledChecklist object on stack, configures it as needed, and calls one
191  * or both of its fastCheck() methods.
192  *
193  * "Slow" (usually asynchronous or "non-blocking"): The user allocates an
194  * ACLFilledChecklist object on heap (via Make()), configures it as needed,
195  * and passes it to NonBlockingCheck() while specifying the callback function
196  * to call with check results. NonBlockingCheck() calls the callback function
197  * (if the corresponding cbdata is still valid), either immediately/directly
198  * (XXX) or eventually/asynchronously. After this callback obligations are
199  * fulfilled, checkCallback() deletes the checklist object (i.e. "this").
200  */
202  dst_rdns(nullptr),
203 #if USE_AUTH
204  auth_user_request(nullptr),
205 #endif
206 #if SQUID_SNMP
207  snmp_community(nullptr),
208 #endif
209  requestErrorType(ERR_MAX),
210  conn_(nullptr),
211  fd_(-1),
212  destinationDomainChecked_(false),
213  sourceDomainChecked_(false)
214 {
215  my_addr.setEmpty();
216  src_addr.setEmpty();
217  dst_addr.setEmpty();
218 
219  changeAcl(A);
220  setRequest(http_request);
221 }
222 
224 {
225  assert(!request);
226  if (httpRequest) {
227  request = httpRequest;
228 #if FOLLOW_X_FORWARDED_FOR
231  else
232 #endif /* FOLLOW_X_FORWARDED_FOR */
235 
236  if (const auto cmgr = request->clientConnectionManager.get())
237  setConn(cmgr);
238  }
239 }
240 
241 void
243 {
244  if (!a)
245  return;
246 
247  al = a; // could have been set already (to a different value)
248  if (!request)
249  setRequest(a->request);
250  updateReply(a->reply);
251 }
252 
253 void
255 {
256  if (r)
257  reply_ = r; // may already be set, including to r
258 }
259 
Cbc * get() const
a temporary valid raw Cbc pointer or NULL
Definition: CbcPointer.h:159
void fillConnectionLevelDetails(ACLFilledChecklist &) const
CBDATA_CLASS_INIT(ACLFilledChecklist)
Ip::Address dst_addr
Ip::Address src_addr
bool isEmpty() const
Definition: SBuf.h:435
HttpReplyPointer reply
static void showDebugWarning(const char *msg)
struct SquidConfig::@97 onoff
C * getRaw() const
Definition: RefCount.h:89
int cbdataReferenceValid(const void *p)
Definition: cbdata.cc:270
AccessLogEntry::Pointer al
info for the future access.log, and external ACL
bool destinationDomainChecked() const
#define cbdataReference(var)
Definition: cbdata.h:348
bool asyncInProgress() const
async call has been started and has not finished (or failed) yet
Definition: Checklist.h:101
void syncAle(HttpRequest *adaptedRequest, const char *logUri) const override
assigns uninitialized adapted_request and url ALE components
void updateReply(const HttpReply::Pointer &)
int acl_uses_indirect_client
Definition: SquidConfig.h:326
HttpRequest * request
ConnStateData * conn() const
The client connection manager.
HttpReply::Pointer reply_
response added by updateReply() or nil
bool finished() const
whether markFinished() was called
Definition: Checklist.h:99
int fd() const
The client side fd. It uses conn() if available.
void verifyAle() const override
warns if there are uninitialized ALE components and fills them
static uint32 A
Definition: md4.c:43
Ip::Address indirect_client_addr
Definition: HttpRequest.h:152
HttpRequest::Pointer request
#define safe_free(x)
Definition: xalloc.h:73
#define assert(EX)
Definition: assert.h:17
class AccessLogEntry::CacheDetails cache
void changeAcl(const acl_access *)
change the current ACL list
Definition: Checklist.cc:187
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:161
#define cbdataReferenceDone(var)
Definition: cbdata.h:357
Ip::Address my_addr
Definition: HttpRequest.h:155
void setEmpty()
Fast reset of the stored content to what would be after default constructor.
Definition: Address.cc:204
@ ERR_MAX
Definition: forward.h:88
bool hasReply() const override
HttpRequest * adapted_request
ConnStateData * conn_
hack: client-to-Squid connection manager (if any)
void setConn(ConnStateData *)
set either conn
void setRequest(HttpRequest *)
configure client request-related fields for the first time
~ACLFilledChecklist() override
AnyP::PortCfgPointer port
#define Important(id)
Definition: Messages.h:93
AnyP::Port port
destination port of the request that caused serverConnection
Definition: client_side.h:145
void markDestinationDomainChecked()
const SBuf & effectiveRequestUri() const
RFC 7230 section 5.5 - Effective Request URI.
Definition: HttpRequest.cc:744
Ip::Address client_addr
Definition: HttpRequest.h:149
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
void updateAle(const AccessLogEntry::Pointer &)
bool sourceDomainChecked() const
CbcPointer< ConnStateData > clientConnectionManager
Definition: HttpRequest.h:232
class SquidConfig Config
Definition: SquidConfig.cc:12

 

Introduction

Documentation

Support

Miscellaneous