FwdState.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 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 
32 class AccessLogEntry;
34 class ErrorState;
35 class HttpRequest;
36 class PconnPool;
37 class ResolvedPeers;
39 
40 class HappyConnOpener;
42 
46 
50 
51 class HelperReply;
52 
54 {
56 
57 public:
59  virtual ~FwdState();
60  static void initModule();
61 
63  static void Start(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp);
65  static void fwdStart(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *);
67  static time_t ForwardTimeout(const time_t fwdStart);
70  static bool EnoughTimeToReForward(const time_t fwdStart);
71 
75  void useDestinations();
76 
77  void fail(ErrorState *err);
79  void unregister(int fd);
80  void complete();
81 
84  void markStoredReplyAsWhole(const char *whyWeAreSure);
85 
87  int reforward();
88  bool reforwardableStatus(const Http::StatusCode s) const;
89  void serverClosed();
90  void connectStart();
91  void connectDone(const Comm::ConnectionPointer & conn, Comm::Flag status, int xerrno);
92  bool checkRetry();
93  bool checkRetriable();
94  void dispatch();
95 
96  void pconnPush(Comm::ConnectionPointer & conn, const char *domain);
97 
98  bool dontRetry() { return flags.dont_retry; }
99 
100  void dontRetry(bool val) { flags.dont_retry = val; }
101 
103  void closePendingConnection(const Comm::ConnectionPointer &conn, const char *reason);
104 
107 
108 private:
109  // hidden for safer management of self; use static fwdStart
111  void start(Pointer aSelf);
112  void stopAndDestroy(const char *reason);
113 
114  /* PeerSelectionInitiator API */
115  virtual void noteDestination(Comm::ConnectionPointer conn) override;
116  virtual void noteDestinationsEnd(ErrorState *selectionError) override;
119  bool usingDestination() const;
120 
122 
123 #if STRICT_ORIGINAL_DST
124  void selectPeerForIntercepted();
125 #endif
126  static void logReplyStatus(int tries, const Http::StatusCode status);
127  void doneWithRetries();
128  void completed();
129  void retryOrBail();
130 
131  void usePinned();
132 
135  bool pinnedCanRetry() const;
136 
137  template <typename StepStart>
138  void advanceDestination(const char *stepDescription, const Comm::ConnectionPointer &conn, const StepStart &startStep);
139 
142  static void RegisterWithCacheManager(void);
143 
149 
151  void closeServerConnection(const char *reason);
152 
153  void syncWithServerConn(const Comm::ConnectionPointer &server, const char *host, const bool reused);
154  void syncHierNote(const Comm::ConnectionPointer &server, const char *host);
155 
157  bool exhaustedTries() const;
158 
160  time_t connectingTimeout(const Comm::ConnectionPointer &conn) const;
161 
162  void cancelStep(const char *reason);
163 
164  void notifyConnOpener();
165  void reactToZeroSizeObject();
166 
168 
169 public:
173 
175  static void HandleStoreAbort(FwdState *);
176 
177 private:
178  Pointer self;
181  time_t start_t;
182  int n_tries;
183 
184  struct {
189  } flags;
190 
193 
196 
200 
204 
206 
210 
213  const char *storedWholeReply_;
214 };
215 
216 class acl_tos;
218 
221 
223 extern PconnPool *fwdPconnPool;
224 
225 #endif /* SQUID_FORWARD_H */
226 
Ip::NfMarkConfig aclFindNfMarkConfig(acl_nfmark *, ACLChecklist *)
Checks for a netfilter mark value to apply depending on the ACL.
Definition: FwdState.cc:1498
void noteConnection(HappyConnOpenerAnswer &)
Definition: FwdState.cc:855
CBDATA_CHILD(FwdState)
Comm::ConnectionPointer serverConn
a successfully opened connection to a server.
Definition: FwdState.h:202
time_t start_t
Definition: FwdState.h:181
void dontRetry(bool val)
Definition: FwdState.h:100
Interface for those who need a list of peers to forward a request to.
void ResetMarkingsToServer(HttpRequest *, Comm::Connection &)
Definition: FwdState.cc:1597
void reactToZeroSizeObject()
ERR_ZERO_SIZE_OBJECT requires special adjustments.
Definition: FwdState.cc:507
JobWait< Http::Tunneler > peerWait
Definition: FwdState.h:199
bool destinationsFound
at least one candidate path found
Definition: FwdState.h:188
static void initModule()
Definition: FwdState.cc:1418
void syncWithServerConn(const Comm::ConnectionPointer &server, const char *host, const bool reused)
commits to using the given open to-peer connection
Definition: FwdState.cc:1086
void useDestinations()
Definition: FwdState.cc:468
void secureConnectionToPeerIfNeeded(const Comm::ConnectionPointer &)
handles an established TCP connection to peer (including origin servers)
Definition: FwdState.cc:985
AccessLogEntryPointer al
info for the future access.log entry
Definition: FwdState.h:172
@ raceHappened
Definition: FwdState.h:208
JobWait< HappyConnOpener > transportWait
waits for a transport connection to the peer to be established/opened
Definition: FwdState.h:192
time_t connectingTimeout(const Comm::ConnectionPointer &conn) const
Definition: FwdState.cc:1472
bool connected_okay
TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc.
Definition: FwdState.h:185
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:835
int type
Definition: errorpage.cc:153
void connectStart()
Definition: FwdState.cc:1120
unsigned char tos_t
Definition: forward.h:27
tos_t aclMapTOS(acl_tos *, ACLChecklist *)
Checks for a TOS value to apply depending on the ACL.
Definition: FwdState.cc:1486
void usePinned()
send request on an existing connection dedicated to the requesting client
Definition: FwdState.cc:1157
void syncHierNote(const Comm::ConnectionPointer &server, const char *host)
Definition: FwdState.cc:1106
void tunnelEstablishmentDone(Http::TunnelerAnswer &answer)
resumes operations after the (possibly failed) HTTP CONNECT exchange
Definition: FwdState.cc:947
bool dont_retry
Definition: FwdState.h:186
void cancelStep(const char *reason)
Definition: FwdState.cc:221
StatusCode
Definition: StatusCode.h:20
err_type
Definition: forward.h:14
void unregister(Comm::ConnectionPointer &conn)
Definition: FwdState.cc:530
RefCount< FwdState > Pointer
Definition: FwdState.h:58
void fail(ErrorState *err)
Definition: FwdState.cc:489
static void Start(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp)
Initiates request forwarding to a peer or origin server.
Definition: FwdState.cc:361
static void RegisterWithCacheManager(void)
Definition: FwdState.cc:1424
static void HandleStoreAbort(FwdState *)
called by Store if the entry is no longer usable
Definition: FwdState.cc:107
@ racePossible
Definition: FwdState.h:208
virtual void noteDestination(Comm::ConnectionPointer conn) override
called when a new unique destination has been found
Definition: FwdState.cc:612
void stopAndDestroy(const char *reason)
ends forwarding; relies on refcounting so the effect may not be immediate
Definition: FwdState.cc:206
void closeServerConnection(const char *reason)
stops monitoring server connection for closure and updates pconn stats
Definition: FwdState.cc:132
bool exhaustedTries() const
whether we have used up all permitted forwarding attempts
Definition: FwdState.cc:1444
bool forward_completed
Definition: FwdState.h:187
PconnRace
possible pconn race states
Definition: FwdState.h:208
bool dontRetry()
Definition: FwdState.h:98
void dispatch()
Definition: FwdState.cc:1193
bool pinnedCanRetry() const
Definition: FwdState.cc:1450
void updateAleWithFinalError()
updates ALE when we finalize the transaction error (if any)
Definition: FwdState.cc:261
void doneWithRetries()
Definition: FwdState.cc:815
virtual ~FwdState()
Definition: FwdState.cc:328
void getOutgoingAddress(HttpRequest *, const Comm::ConnectionPointer &)
Definition: FwdState.cc:1509
void successfullyConnectedToPeer(const Comm::ConnectionPointer &)
called when all negotiations with the peer have been completed
Definition: FwdState.cc:1070
void establishTunnelThruProxy(const Comm::ConnectionPointer &)
Definition: FwdState.cc:924
JobWait< Security::PeerConnector > encryptionWait
waits for the established transport connection to be secured/encrypted
Definition: FwdState.h:195
Comm::ConnectionPointer clientConn
a possibly open connection to the client.
Definition: FwdState.h:180
virtual void noteDestinationsEnd(ErrorState *selectionError) override
Definition: FwdState.cc:645
FwdState(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp)
Definition: FwdState.cc:144
AsyncCall::Pointer closeHandler
The serverConn close handler.
Definition: FwdState.h:205
int n_tries
the number of forwarding attempts so far
Definition: FwdState.h:182
int conn
the current server connection FD
Definition: Transport.cc:26
RefCount< AccessLogEntry > AccessLogEntryPointer
Definition: FwdState.h:32
struct FwdState::@71 flags
static bool EnoughTimeToReForward(const time_t fwdStart)
Definition: FwdState.cc:462
static time_t ForwardTimeout(const time_t fwdStart)
time left to finish the whole forwarding process (which started at fwdStart)
Definition: FwdState.cc:454
void retryOrBail()
Definition: FwdState.cc:790
bool checkRetry()
Definition: FwdState.cc:712
ErrorState * err
Definition: FwdState.h:179
void completed()
Definition: FwdState.cc:277
ErrorState * makeConnectingError(const err_type type) const
static void logReplyStatus(int tries, const Http::StatusCode status)
Definition: FwdState.cc:1430
void GetMarkingsToServer(HttpRequest *request, Comm::Connection &conn)
Definition: FwdState.cc:1588
Final result (an open connection or an error) sent to the job initiator.
Flag
Definition: Flag.h:15
const char * storedWholeReply_
Definition: FwdState.h:213
a netfilter mark/mask pair
Definition: NfMarkConfig.h:21
void complete()
Definition: FwdState.cc:557
int reforward()
Definition: FwdState.cc:1318
@ raceImpossible
Definition: FwdState.h:208
static char server[MAXLINE]
void connectedToPeer(Security::EncryptorAnswer &answer)
called when all negotiations with the TLS-speaking peer have been completed
Definition: FwdState.cc:1034
RefCount< ResolvedPeers > ResolvedPeersPointer
Definition: FwdState.h:37
bool reforwardableStatus(const Http::StatusCode s) const
Definition: FwdState.cc:1392
PeerConnectionPointer destinationReceipt
peer selection result (or nil)
Definition: FwdState.h:203
StoreEntry * entry
Definition: FwdState.h:170
void pconnPush(Comm::ConnectionPointer &conn, const char *domain)
void secureConnectionToPeer(const Comm::ConnectionPointer &)
encrypts an established TCP connection to peer (including origin servers)
Definition: FwdState.cc:1014
bool usingDestination() const
Definition: FwdState.cc:594
static void fwdStart(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *)
Same as Start() but no master xaction info (AccessLogEntry) available.
Definition: FwdState.cc:438
PconnRace pconnRace
current pconn race state
Definition: FwdState.h:209
void connectDone(const Comm::ConnectionPointer &conn, Comm::Flag status, int xerrno)
void markStoredReplyAsWhole(const char *whyWeAreSure)
Definition: FwdState.cc:600
void start(Pointer aSelf)
Definition: FwdState.cc:167
static StatHist s
HttpRequest * request
Definition: FwdState.h:171
void serverClosed()
Definition: FwdState.cc:769
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
void closePendingConnection(const Comm::ConnectionPointer &conn, const char *reason)
get rid of a to-server connection that failed to become serverConn
Definition: FwdState.cc:120
PconnPool * fwdPconnPool
a collection of previously used persistent Squid-to-peer HTTP(S) connections
Definition: FwdState.cc:78
bool checkRetriable()
Whether we may try sending this request again after a failure.
Definition: FwdState.cc:756
Comm::ConnectionPointer const & serverConnection() const
Definition: FwdState.h:106
void handleUnregisteredServerEnd()
Definition: FwdState.cc:823
ResolvedPeersPointer destinations
paths for forwarding the request
Definition: FwdState.h:201
void notifyConnOpener()
makes sure connection opener knows that the destinations have changed
Definition: FwdState.cc:682

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors