FwdState.h
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#ifndef SQUID_FORWARD_H
10#define SQUID_FORWARD_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
53{
55
56public:
58 ~FwdState() override;
59 static void initModule();
60
62 static void Start(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp);
64 static void fwdStart(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *);
66 static time_t ForwardTimeout(const time_t fwdStart);
69 static bool EnoughTimeToReForward(const time_t fwdStart);
70
74 void useDestinations();
75
76 void fail(ErrorState *err);
78 void unregister(int fd);
79 void complete();
80
83 void markStoredReplyAsWhole(const char *whyWeAreSure);
84
86 int reforward();
87 void serverClosed();
88 void connectStart();
89 void connectDone(const Comm::ConnectionPointer & conn, Comm::Flag status, int xerrno);
90 bool checkRetry();
91 bool checkRetriable();
92 void dispatch();
93
94 void pconnPush(Comm::ConnectionPointer & conn, const char *domain);
95
96 bool dontRetry() { return flags.dont_retry; }
97
98 void dontRetry(bool val) { flags.dont_retry = val; }
99
101 void closePendingConnection(const Comm::ConnectionPointer &conn, const char *reason);
102
105
106private:
107 // hidden for safer management of self; use static fwdStart
109 void start(Pointer aSelf);
110 void stopAndDestroy(const char *reason);
111
112 /* PeerSelectionInitiator API */
114 void noteDestinationsEnd(ErrorState *selectionError) override;
115
116 bool transporting() const;
117
119
120#if STRICT_ORIGINAL_DST
121 void selectPeerForIntercepted();
122#endif
123 static void logReplyStatus(int tries, const Http::StatusCode status);
124 void doneWithRetries();
125 void completed();
126 void retryOrBail();
127
128 void usePinned();
129
132 bool pinnedCanRetry() const;
133
134 template <typename StepStart>
135 void advanceDestination(const char *stepDescription, const Comm::ConnectionPointer &conn, const StepStart &startStep);
136
139 static void RegisterWithCacheManager(void);
140
146
148 void closeServerConnection(const char *reason);
149
150 void syncWithServerConn(const Comm::ConnectionPointer &server, const char *host, const bool reused);
151 void syncHierNote(const Comm::ConnectionPointer &server, const char *host);
152
154 bool exhaustedTries() const;
155 void updateAttempts(int);
156
159
160 void cancelStep(const char *reason);
161
162 void notifyConnOpener();
164
166
167public:
171
173 static void HandleStoreAbort(FwdState *);
174
175private:
179 time_t start_t;
181
182 struct {
188
191
194
198
201
205
207
211
214 const char *storedWholeReply_;
215};
216
217class acl_tos;
219
222
224extern PconnPool *fwdPconnPool;
225
226#endif /* SQUID_FORWARD_H */
227
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:1453
void getOutgoingAddress(HttpRequest *, const Comm::ConnectionPointer &)
Definition: FwdState.cc:1476
RefCount< ResolvedPeers > ResolvedPeersPointer
Definition: FwdState.h:37
void GetMarkingsToServer(HttpRequest *request, Comm::Connection &conn)
Definition: FwdState.cc:1555
RefCount< AccessLogEntry > AccessLogEntryPointer
Definition: FwdState.h:33
void ResetMarkingsToServer(HttpRequest *, Comm::Connection &)
Definition: FwdState.cc:1564
Ip::NfMarkConfig aclFindNfMarkConfig(acl_nfmark *, ACLChecklist *)
Checks for a netfilter mark value to apply depending on the ACL.
Definition: FwdState.cc:1465
#define RefCountable
The locking interface for use on Reference-Counted classes.
Definition: Lock.h:66
int conn
the current server connection FD
Definition: Transport.cc:26
static char server[MAXLINE]
bool forward_completed
Definition: FwdState.h:185
void secureConnectionToPeerIfNeeded(const Comm::ConnectionPointer &)
handles an established TCP connection to peer (including origin servers)
Definition: FwdState.cc:968
Comm::ConnectionPointer clientConn
a possibly open connection to the client.
Definition: FwdState.h:178
bool checkRetry()
Definition: FwdState.cc:690
void reactToZeroSizeObject()
ERR_ZERO_SIZE_OBJECT requires special adjustments.
Definition: FwdState.cc:481
void handleUnregisteredServerEnd()
Definition: FwdState.cc:805
void noteDestinationsEnd(ErrorState *selectionError) override
Definition: FwdState.cc:621
void connectedToPeer(Security::EncryptorAnswer &answer)
called when all negotiations with the TLS-speaking peer have been completed
Definition: FwdState.cc:1015
HttpRequest * request
Definition: FwdState.h:169
void serverClosed()
Definition: FwdState.cc:747
void successfullyConnectedToPeer(const Comm::ConnectionPointer &)
called when all negotiations with the peer have been completed
Definition: FwdState.cc:1051
PconnRace pconnRace
current pconn race state
Definition: FwdState.h:210
const char * storedWholeReply_
Definition: FwdState.h:214
FwdState(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp)
Definition: FwdState.cc:120
JobWait< HappyConnOpener > transportWait
waits for a transport connection to the peer to be established/opened
Definition: FwdState.h:190
void doneWithRetries()
Definition: FwdState.cc:797
JobWait< Http::Tunneler > peerWait
Definition: FwdState.h:197
void completed()
Definition: FwdState.cc:257
void pconnPush(Comm::ConnectionPointer &conn, const char *domain)
bool transporting() const
Definition: FwdState.cc:574
PconnRace
possible pconn race states
Definition: FwdState.h:209
@ racePossible
Definition: FwdState.h:209
@ raceHappened
Definition: FwdState.h:209
@ raceImpossible
Definition: FwdState.h:209
bool destinationsFound
at least one candidate path found
Definition: FwdState.h:186
void complete()
Definition: FwdState.cc:531
static void Start(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp)
Initiates request forwarding to a peer or origin server.
Definition: FwdState.cc:341
void noteDestination(Comm::ConnectionPointer conn) override
called when a new unique destination has been found
Definition: FwdState.cc:592
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:1439
bool connected_okay
TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc.
Definition: FwdState.h:183
static bool EnoughTimeToReForward(const time_t fwdStart)
Definition: FwdState.cc:436
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
void unregister(Comm::ConnectionPointer &conn)
Definition: FwdState.cc:504
void connectDone(const Comm::ConnectionPointer &conn, Comm::Flag status, int xerrno)
void start(Pointer aSelf)
Definition: FwdState.cc:144
Comm::ConnectionPointer const & serverConnection() const
Definition: FwdState.h:104
bool dont_retry
Definition: FwdState.h:184
Comm::ConnectionPointer serverConn
a successfully opened connection to a server.
Definition: FwdState.h:203
void fail(ErrorState *err)
Definition: FwdState.cc:463
static time_t ForwardTimeout(const time_t fwdStart)
time left to finish the whole forwarding process (which started at fwdStart)
Definition: FwdState.cc:428
void closeServerConnection(const char *reason)
stops monitoring server connection for closure and updates pconn stats
Definition: FwdState.cc:108
bool dontRetry()
Definition: FwdState.h:96
CBDATA_CHILD(FwdState)
JobWait< Security::PeerConnector > encryptionWait
waits for the established transport connection to be secured/encrypted
Definition: FwdState.h:193
void dontRetry(bool val)
Definition: FwdState.h:98
void updateAttempts(int)
sets n_tries to the given value (while keeping ALE, if any, in sync)
Definition: FwdState.cc:1096
void usePinned()
send request on an existing connection dedicated to the requesting client
Definition: FwdState.cc:1152
void tunnelEstablishmentDone(Http::TunnelerAnswer &answer)
resumes operations after the (possibly failed) HTTP CONNECT exchange
Definition: FwdState.cc:930
int n_tries
the number of forwarding attempts so far
Definition: FwdState.h:180
AsyncCall::Pointer closeHandler
The serverConn close handler.
Definition: FwdState.h:206
static void logReplyStatus(int tries, const Http::StatusCode status)
Definition: FwdState.cc:1397
static void RegisterWithCacheManager(void)
Definition: FwdState.cc:1391
void updateAleWithFinalError()
updates ALE when we finalize the transaction error (if any)
Definition: FwdState.cc:238
bool exhaustedTries() const
whether we have used up all permitted forwarding attempts
Definition: FwdState.cc:1411
RefCount< FwdState > Pointer
Definition: FwdState.h:57
void cancelStep(const char *reason)
Definition: FwdState.cc:198
void dispatch()
Definition: FwdState.cc:1189
StoreEntry * entry
Definition: FwdState.h:168
~FwdState() override
Definition: FwdState.cc:308
void establishTunnelThruProxy(const Comm::ConnectionPointer &)
Definition: FwdState.cc:909
void stopAndDestroy(const char *reason)
ends forwarding; relies on refcounting so the effect may not be immediate
Definition: FwdState.cc:183
static void initModule()
Definition: FwdState.cc:1385
time_t start_t
Definition: FwdState.h:179
bool checkRetriable()
Whether we may try sending this request again after a failure.
Definition: FwdState.cc:734
void syncWithServerConn(const Comm::ConnectionPointer &server, const char *host, const bool reused)
commits to using the given open to-peer connection
Definition: FwdState.cc:1066
bool waitingForDispatched
whether we are waiting for the last dispatch()ed activity to end
Definition: FwdState.h:200
void retryOrBail()
Definition: FwdState.cc:772
void noteConnection(HappyConnOpenerAnswer &)
Definition: FwdState.cc:841
ResolvedPeersPointer destinations
paths for forwarding the request
Definition: FwdState.h:202
void notifyConnOpener()
makes sure connection opener knows that the destinations have changed
Definition: FwdState.cc:660
void markStoredReplyAsWhole(const char *whyWeAreSure)
Definition: FwdState.cc:580
void connectStart()
Definition: FwdState.cc:1116
Pointer self
Definition: FwdState.h:176
PeerConnectionPointer destinationReceipt
peer selection result (or nil)
Definition: FwdState.h:204
void useDestinations()
Definition: FwdState.cc:442
void secureConnectionToPeer(const Comm::ConnectionPointer &)
encrypts an established TCP connection to peer (including origin servers)
Definition: FwdState.cc:997
struct FwdState::@67 flags
static void fwdStart(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *)
Same as Start() but no master xaction info (AccessLogEntry) available.
Definition: FwdState.cc:412
void syncHierNote(const Comm::ConnectionPointer &server, const char *host)
Definition: FwdState.cc:1086
int reforward()
Definition: FwdState.cc:1311
AccessLogEntryPointer al
info for the future access.log entry
Definition: FwdState.h:170
ErrorState * makeConnectingError(const err_type type) const
bool pinnedCanRetry() const
Definition: FwdState.cc:1417
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:821
ErrorState * err
Definition: FwdState.h:177
Final result (an open connection or an error) sent to the job initiator.
a netfilter mark/mask pair
Definition: NfMarkConfig.h:23
Interface for those who need a list of peers to forward a request to.
err_type
Definition: forward.h:14
unsigned char tos_t
Definition: forward.h:27
Flag
Definition: Flag.h:15
StatusCode
Definition: StatusCode.h:20

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors