Squid Web Cache master
Loading...
Searching...
No Matches
FwdState.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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#ifndef SQUID_SRC_FWDSTATE_H
10#define SQUID_SRC_FWDSTATE_H
11
12#include "base/forward.h"
13#include "base/JobWait.h"
14#include "base/RefCount.h"
15#include "clients/forward.h"
16#include "comm.h"
17#include "comm/Connection.h"
18#include "error/forward.h"
19#include "fde.h"
20#include "http/StatusCode.h"
21#include "ip/Address.h"
22#include "ip/forward.h"
23#include "PeerSelectState.h"
24#include "ResolvedPeers.h"
25#include "security/forward.h"
26#if USE_OPENSSL
27#include "ssl/support.h"
28#endif
29
30/* forward decls */
31
32class AccessLogEntry;
34class HttpRequest;
35class PconnPool;
36class ResolvedPeers;
38
39class HappyConnOpener;
41
45
49
50class HelperReply;
51
58{
59public:
62
64 void stop()
65 {
66 if (!stopped) {
67 timer().pause();
68 stopped = true;
69 }
70 }
71
72private:
75
78
79 // We cannot rely on timer().ran(): This class eliminates excessive calls
80 // within a single task (e.g., an AsyncJob) while the timer (and its ran()
81 // state) may be shared/affected by multiple concurrent tasks.
83 bool stopped = false;
84};
85
87{
89
90public:
92 ~FwdState() override;
93 static void initModule();
94
96 static void Start(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp);
98 static void fwdStart(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *);
100 static time_t ForwardTimeout(const time_t fwdStart);
103 static bool EnoughTimeToReForward(const time_t fwdStart);
104
108 void useDestinations();
109
110 void fail(ErrorState *err);
112 void unregister(int fd);
113 void complete();
114
117 void markStoredReplyAsWhole(const char *whyWeAreSure);
118
120 int reforward();
121 void serverClosed();
122 void connectStart();
123 void connectDone(const Comm::ConnectionPointer & conn, Comm::Flag status, int xerrno);
124 bool checkRetry();
125 bool checkRetriable();
126 void dispatch();
127
128 void pconnPush(Comm::ConnectionPointer & conn, const char *domain);
129
130 bool dontRetry() { return flags.dont_retry; }
131
132 void dontRetry(bool val) { flags.dont_retry = val; }
133
135 void closePendingConnection(const Comm::ConnectionPointer &conn, const char *reason);
136
139
140private:
141 // hidden for safer management of self; use static fwdStart
143 void start(Pointer aSelf);
144 void stopAndDestroy(const char *reason);
145
146 /* PeerSelectionInitiator API */
147 void noteDestination(Comm::ConnectionPointer conn) override;
148 void noteDestinationsEnd(ErrorState *selectionError) override;
149
150 bool transporting() const;
151
153
154#if STRICT_ORIGINAL_DST
155 void selectPeerForIntercepted();
156#endif
157 static void logReplyStatus(int tries, const Http::StatusCode status);
158 void doneWithRetries();
159 void completed();
160 void retryOrBail();
161
162 void usePinned();
163
166 bool pinnedCanRetry() const;
167
168 template <typename StepStart>
169 void advanceDestination(const char *stepDescription, const Comm::ConnectionPointer &conn, const StepStart &startStep);
170
173 static void RegisterWithCacheManager(void);
174
180
182 void closeServerConnection(const char *reason);
183
184 void syncWithServerConn(const Comm::ConnectionPointer &server, const char *host, const bool reused);
185 void syncHierNote(const Comm::ConnectionPointer &server, const char *host);
186
188 bool exhaustedTries() const;
189 void updateAttempts(int);
190
192 time_t connectingTimeout(const Comm::ConnectionPointer &conn) const;
193
194 void cancelStep(const char *reason);
195
196 void notifyConnOpener();
198
200
201public:
205
207 static void HandleStoreAbort(FwdState *);
208
209private:
213 time_t start_t;
215
216 struct {
222
225
228
232
235
239
241
245
248 const char *storedWholeReply_;
249
252};
253
254class acl_tos;
256
259
261extern PconnPool *fwdPconnPool;
262
263#endif /* SQUID_SRC_FWDSTATE_H */
264
PconnPool * fwdPconnPool
a collection of previously used persistent Squid-to-peer HTTP(S) connections
Definition FwdState.cc:78
tos_t aclMapTOS(acl_tos *, ACLChecklist *)
Checks for a TOS value to apply depending on the ACL.
Definition FwdState.cc:1458
void getOutgoingAddress(HttpRequest *, const Comm::ConnectionPointer &)
Definition FwdState.cc:1481
RefCount< ResolvedPeers > ResolvedPeersPointer
Definition FwdState.h:37
void GetMarkingsToServer(HttpRequest *request, Comm::Connection &conn)
Definition FwdState.cc:1560
RefCount< AccessLogEntry > AccessLogEntryPointer
Definition FwdState.h:33
void ResetMarkingsToServer(HttpRequest *, Comm::Connection &)
Definition FwdState.cc:1569
Ip::NfMarkConfig aclFindNfMarkConfig(acl_nfmark *, ACLChecklist *)
Checks for a netfilter mark value to apply depending on the ACL.
Definition FwdState.cc:1470
#define RefCountable
The locking interface for use on Reference-Counted classes.
Definition Lock.h:66
static char server[MAXLINE]
bool forward_completed
Definition FwdState.h:219
void secureConnectionToPeerIfNeeded(const Comm::ConnectionPointer &)
handles an established TCP connection to peer (including origin servers)
Definition FwdState.cc:967
Comm::ConnectionPointer clientConn
a possibly open connection to the client.
Definition FwdState.h:212
bool checkRetry()
Definition FwdState.cc:691
void reactToZeroSizeObject()
ERR_ZERO_SIZE_OBJECT requires special adjustments.
Definition FwdState.cc:476
void handleUnregisteredServerEnd()
Definition FwdState.cc:804
void noteDestinationsEnd(ErrorState *selectionError) override
Definition FwdState.cc:616
void connectedToPeer(Security::EncryptorAnswer &answer)
called when all negotiations with the TLS-speaking peer have been completed
Definition FwdState.cc:1014
HttpRequest * request
Definition FwdState.h:203
void serverClosed()
Definition FwdState.cc:748
void successfullyConnectedToPeer(const Comm::ConnectionPointer &)
called when all negotiations with the peer have been completed
Definition FwdState.cc:1050
PconnRace pconnRace
current pconn race state
Definition FwdState.h:244
const char * storedWholeReply_
Definition FwdState.h:248
JobWait< HappyConnOpener > transportWait
waits for a transport connection to the peer to be established/opened
Definition FwdState.h:224
void doneWithRetries()
Definition FwdState.cc:796
JobWait< Http::Tunneler > peerWait
Definition FwdState.h:231
void completed()
Definition FwdState.cc:256
void pconnPush(Comm::ConnectionPointer &conn, const char *domain)
bool transporting() const
Definition FwdState.cc:569
PconnRace
possible pconn race states
Definition FwdState.h:243
@ racePossible
Definition FwdState.h:243
@ raceHappened
Definition FwdState.h:243
@ raceImpossible
Definition FwdState.h:243
bool destinationsFound
at least one candidate path found
Definition FwdState.h:220
void complete()
Definition FwdState.cc:526
static void Start(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp)
Initiates request forwarding to a peer or origin server.
Definition FwdState.cc:338
void noteDestination(Comm::ConnectionPointer conn) override
called when a new unique destination has been found
Definition FwdState.cc:587
static void HandleStoreAbort(FwdState *)
called by Store if the entry is no longer usable
Definition FwdState.cc:83
time_t connectingTimeout(const Comm::ConnectionPointer &conn) const
Definition FwdState.cc:1444
bool connected_okay
TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc.
Definition FwdState.h:217
static bool EnoughTimeToReForward(const time_t fwdStart)
Definition FwdState.cc:431
void closePendingConnection(const Comm::ConnectionPointer &conn, const char *reason)
get rid of a to-server connection that failed to become serverConn
Definition FwdState.cc:96
PeeringActivityTimer peeringTimer
Measures time spent on selecting and communicating with peers.
Definition FwdState.h:251
void unregister(Comm::ConnectionPointer &conn)
Definition FwdState.cc:499
void connectDone(const Comm::ConnectionPointer &conn, Comm::Flag status, int xerrno)
void start(Pointer aSelf)
Definition FwdState.cc:145
Comm::ConnectionPointer const & serverConnection() const
Definition FwdState.h:138
bool dont_retry
Definition FwdState.h:218
Comm::ConnectionPointer serverConn
a successfully opened connection to a server.
Definition FwdState.h:237
void fail(ErrorState *err)
Definition FwdState.cc:458
static time_t ForwardTimeout(const time_t fwdStart)
time left to finish the whole forwarding process (which started at fwdStart)
Definition FwdState.cc:423
void closeServerConnection(const char *reason)
stops monitoring server connection for closure and updates pconn stats
Definition FwdState.cc:108
bool dontRetry()
Definition FwdState.h:130
CBDATA_CHILD(FwdState)
JobWait< Security::PeerConnector > encryptionWait
waits for the established transport connection to be secured/encrypted
Definition FwdState.h:227
void dontRetry(bool val)
Definition FwdState.h:132
void updateAttempts(int)
sets n_tries to the given value (while keeping ALE, if any, in sync)
Definition FwdState.cc:1095
void usePinned()
send request on an existing connection dedicated to the requesting client
Definition FwdState.cc:1149
void tunnelEstablishmentDone(Http::TunnelerAnswer &answer)
resumes operations after the (possibly failed) HTTP CONNECT exchange
Definition FwdState.cc:929
int n_tries
the number of forwarding attempts so far
Definition FwdState.h:214
AsyncCall::Pointer closeHandler
The serverConn close handler.
Definition FwdState.h:240
static void logReplyStatus(int tries, const Http::StatusCode status)
Definition FwdState.cc:1402
static void RegisterWithCacheManager(void)
Definition FwdState.cc:1396
void updateAleWithFinalError()
updates ALE when we finalize the transaction error (if any)
Definition FwdState.cc:241
bool exhaustedTries() const
whether we have used up all permitted forwarding attempts
Definition FwdState.cc:1416
RefCount< FwdState > Pointer
Definition FwdState.h:91
void cancelStep(const char *reason)
Definition FwdState.cc:201
void dispatch()
Definition FwdState.cc:1186
StoreEntry * entry
Definition FwdState.h:202
~FwdState() override
Definition FwdState.cc:305
struct FwdState::@52 flags
void establishTunnelThruProxy(const Comm::ConnectionPointer &)
Definition FwdState.cc:908
void stopAndDestroy(const char *reason)
ends forwarding; relies on refcounting so the effect may not be immediate
Definition FwdState.cc:184
static void initModule()
Definition FwdState.cc:1390
time_t start_t
Definition FwdState.h:213
bool checkRetriable()
Whether we may try sending this request again after a failure.
Definition FwdState.cc:735
void syncWithServerConn(const Comm::ConnectionPointer &server, const char *host, const bool reused)
commits to using the given open to-peer connection
Definition FwdState.cc:1065
bool waitingForDispatched
whether we are waiting for the last dispatch()ed activity to end
Definition FwdState.h:234
void retryOrBail()
Definition FwdState.cc:773
void noteConnection(HappyConnOpenerAnswer &)
Definition FwdState.cc:840
ResolvedPeersPointer destinations
paths for forwarding the request
Definition FwdState.h:236
void notifyConnOpener()
makes sure connection opener knows that the destinations have changed
Definition FwdState.cc:661
void markStoredReplyAsWhole(const char *whyWeAreSure)
Definition FwdState.cc:575
void connectStart()
Definition FwdState.cc:1115
Pointer self
Definition FwdState.h:210
PeerConnectionPointer destinationReceipt
peer selection result (or nil)
Definition FwdState.h:238
void useDestinations()
Definition FwdState.cc:437
void secureConnectionToPeer(const Comm::ConnectionPointer &)
encrypts an established TCP connection to peer (including origin servers)
Definition FwdState.cc:996
static void fwdStart(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *)
Same as Start() but no master xaction info (AccessLogEntry) available.
Definition FwdState.cc:407
void syncHierNote(const Comm::ConnectionPointer &server, const char *host)
Definition FwdState.cc:1085
int reforward()
Definition FwdState.cc:1308
AccessLogEntryPointer al
info for the future access.log entry
Definition FwdState.h:204
ErrorState * makeConnectingError(const err_type type) const
bool pinnedCanRetry() const
Definition FwdState.cc:1422
void advanceDestination(const char *stepDescription, const Comm::ConnectionPointer &conn, const StepStart &startStep)
starts a preparation step for an established connection; retries on failures
Definition FwdState.cc:820
ErrorState * err
Definition FwdState.h:211
Final result (an open connection or an error) sent to the job initiator.
PeerConnectionPointer conn
a netfilter mark/mask pair
Interface for those who need a list of peers to forward a request to.
void stop()
pauses timer if stop() has not been called
Definition FwdState.h:64
Stopwatch & timer()
managed Stopwatch object within HierarchyLogEntry
Definition FwdState.cc:1597
HttpRequestPointer request
the owner of managed HierarchyLogEntry
Definition FwdState.h:77
~PeeringActivityTimer()
pauses timer if stop() has not been called
Definition FwdState.cc:1591
bool stopped
Whether the task is done participating in the managed activity.
Definition FwdState.h:83
void pause()
ends the current measurement period if needed; requires prior resume()
Definition Stopwatch.cc:41
err_type
Definition forward.h:14
unsigned char tos_t
Definition forward.h:27
Flag
Definition Flag.h:15
StatusCode
Definition StatusCode.h:20