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;
117 
118  bool transporting() const;
119 
121 
122 #if STRICT_ORIGINAL_DST
123  void selectPeerForIntercepted();
124 #endif
125  static void logReplyStatus(int tries, const Http::StatusCode status);
126  void doneWithRetries();
127  void completed();
128  void retryOrBail();
129 
130  void usePinned();
131 
134  bool pinnedCanRetry() const;
135 
136  template <typename StepStart>
137  void advanceDestination(const char *stepDescription, const Comm::ConnectionPointer &conn, const StepStart &startStep);
138 
141  static void RegisterWithCacheManager(void);
142 
148 
150  void closeServerConnection(const char *reason);
151 
152  void syncWithServerConn(const Comm::ConnectionPointer &server, const char *host, const bool reused);
153  void syncHierNote(const Comm::ConnectionPointer &server, const char *host);
154 
156  bool exhaustedTries() const;
157 
159  time_t connectingTimeout(const Comm::ConnectionPointer &conn) const;
160 
161  void cancelStep(const char *reason);
162 
163  void notifyConnOpener();
164  void reactToZeroSizeObject();
165 
167 
168 public:
172 
174  static void HandleStoreAbort(FwdState *);
175 
176 private:
177  Pointer self;
180  time_t start_t;
181  int n_tries;
182 
183  struct {
188  } flags;
189 
192 
195 
199 
202 
206 
208 
212 
215  const char *storedWholeReply_;
216 };
217 
218 class acl_tos;
220 
223 
225 extern PconnPool *fwdPconnPool;
226 
227 #endif /* SQUID_FORWARD_H */
228 
Ip::NfMarkConfig aclFindNfMarkConfig(acl_nfmark *, ACLChecklist *)
Checks for a netfilter mark value to apply depending on the ACL.
Definition: FwdState.cc:1510
void noteConnection(HappyConnOpenerAnswer &)
Definition: FwdState.cc:864
CBDATA_CHILD(FwdState)
Comm::ConnectionPointer serverConn
a successfully opened connection to a server.
Definition: FwdState.h:204
time_t start_t
Definition: FwdState.h:180
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:1609
void reactToZeroSizeObject()
ERR_ZERO_SIZE_OBJECT requires special adjustments.
Definition: FwdState.cc:508
JobWait< Http::Tunneler > peerWait
Definition: FwdState.h:198
bool destinationsFound
at least one candidate path found
Definition: FwdState.h:187
static void initModule()
Definition: FwdState.cc:1430
void syncWithServerConn(const Comm::ConnectionPointer &server, const char *host, const bool reused)
commits to using the given open to-peer connection
Definition: FwdState.cc:1095
void useDestinations()
Definition: FwdState.cc:469
void secureConnectionToPeerIfNeeded(const Comm::ConnectionPointer &)
handles an established TCP connection to peer (including origin servers)
Definition: FwdState.cc:994
AccessLogEntryPointer al
info for the future access.log entry
Definition: FwdState.h:171
@ raceHappened
Definition: FwdState.h:210
JobWait< HappyConnOpener > transportWait
waits for a transport connection to the peer to be established/opened
Definition: FwdState.h:191
time_t connectingTimeout(const Comm::ConnectionPointer &conn) const
Definition: FwdState.cc:1484
bool connected_okay
TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc.
Definition: FwdState.h:184
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:844
int type
Definition: errorpage.cc:153
void connectStart()
Definition: FwdState.cc:1129
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:1498
void usePinned()
send request on an existing connection dedicated to the requesting client
Definition: FwdState.cc:1166
void syncHierNote(const Comm::ConnectionPointer &server, const char *host)
Definition: FwdState.cc:1115
void tunnelEstablishmentDone(Http::TunnelerAnswer &answer)
resumes operations after the (possibly failed) HTTP CONNECT exchange
Definition: FwdState.cc:956
bool dont_retry
Definition: FwdState.h:185
void cancelStep(const char *reason)
Definition: FwdState.cc:222
StatusCode
Definition: StatusCode.h:20
err_type
Definition: forward.h:14
void unregister(Comm::ConnectionPointer &conn)
Definition: FwdState.cc:531
RefCount< FwdState > Pointer
Definition: FwdState.h:58
void fail(ErrorState *err)
Definition: FwdState.cc:490
static void Start(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp)
Initiates request forwarding to a peer or origin server.
Definition: FwdState.cc:362
static void RegisterWithCacheManager(void)
Definition: FwdState.cc:1436
static void HandleStoreAbort(FwdState *)
called by Store if the entry is no longer usable
Definition: FwdState.cc:107
@ racePossible
Definition: FwdState.h:210
virtual void noteDestination(Comm::ConnectionPointer conn) override
called when a new unique destination has been found
Definition: FwdState.cc:619
void stopAndDestroy(const char *reason)
ends forwarding; relies on refcounting so the effect may not be immediate
Definition: FwdState.cc:207
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:1456
bool forward_completed
Definition: FwdState.h:186
PconnRace
possible pconn race states
Definition: FwdState.h:210
bool dontRetry()
Definition: FwdState.h:98
void dispatch()
Definition: FwdState.cc:1202
bool pinnedCanRetry() const
Definition: FwdState.cc:1462
void updateAleWithFinalError()
updates ALE when we finalize the transaction error (if any)
Definition: FwdState.cc:262
void doneWithRetries()
Definition: FwdState.cc:820
virtual ~FwdState()
Definition: FwdState.cc:329
void getOutgoingAddress(HttpRequest *, const Comm::ConnectionPointer &)
Definition: FwdState.cc:1521
void successfullyConnectedToPeer(const Comm::ConnectionPointer &)
called when all negotiations with the peer have been completed
Definition: FwdState.cc:1079
void establishTunnelThruProxy(const Comm::ConnectionPointer &)
Definition: FwdState.cc:933
JobWait< Security::PeerConnector > encryptionWait
waits for the established transport connection to be secured/encrypted
Definition: FwdState.h:194
bool waitingForDispatched
whether we are waiting for the last dispatch()ed activity to end
Definition: FwdState.h:201
Comm::ConnectionPointer clientConn
a possibly open connection to the client.
Definition: FwdState.h:179
virtual void noteDestinationsEnd(ErrorState *selectionError) override
Definition: FwdState.cc:649
FwdState(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp)
Definition: FwdState.cc:144
AsyncCall::Pointer closeHandler
The serverConn close handler.
Definition: FwdState.h:207
int n_tries
the number of forwarding attempts so far
Definition: FwdState.h:181
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:463
static time_t ForwardTimeout(const time_t fwdStart)
time left to finish the whole forwarding process (which started at fwdStart)
Definition: FwdState.cc:455
void retryOrBail()
Definition: FwdState.cc:795
bool checkRetry()
Definition: FwdState.cc:713
ErrorState * err
Definition: FwdState.h:178
void completed()
Definition: FwdState.cc:278
ErrorState * makeConnectingError(const err_type type) const
static void logReplyStatus(int tries, const Http::StatusCode status)
Definition: FwdState.cc:1442
void GetMarkingsToServer(HttpRequest *request, Comm::Connection &conn)
Definition: FwdState.cc:1600
Final result (an open connection or an error) sent to the job initiator.
Flag
Definition: Flag.h:15
const char * storedWholeReply_
Definition: FwdState.h:215
a netfilter mark/mask pair
Definition: NfMarkConfig.h:21
void complete()
Definition: FwdState.cc:558
int reforward()
Definition: FwdState.cc:1330
@ raceImpossible
Definition: FwdState.h:210
static char server[MAXLINE]
void connectedToPeer(Security::EncryptorAnswer &answer)
called when all negotiations with the TLS-speaking peer have been completed
Definition: FwdState.cc:1043
RefCount< ResolvedPeers > ResolvedPeersPointer
Definition: FwdState.h:37
bool reforwardableStatus(const Http::StatusCode s) const
Definition: FwdState.cc:1404
PeerConnectionPointer destinationReceipt
peer selection result (or nil)
Definition: FwdState.h:205
StoreEntry * entry
Definition: FwdState.h:169
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:1023
static void fwdStart(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *)
Same as Start() but no master xaction info (AccessLogEntry) available.
Definition: FwdState.cc:439
PconnRace pconnRace
current pconn race state
Definition: FwdState.h:211
void connectDone(const Comm::ConnectionPointer &conn, Comm::Flag status, int xerrno)
void markStoredReplyAsWhole(const char *whyWeAreSure)
Definition: FwdState.cc:607
bool transporting() const
Definition: FwdState.cc:601
void start(Pointer aSelf)
Definition: FwdState.cc:168
static StatHist s
HttpRequest * request
Definition: FwdState.h:170
void serverClosed()
Definition: FwdState.cc:770
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:757
Comm::ConnectionPointer const & serverConnection() const
Definition: FwdState.h:106
void handleUnregisteredServerEnd()
Definition: FwdState.cc:828
ResolvedPeersPointer destinations
paths for forwarding the request
Definition: FwdState.h:203
void notifyConnOpener()
makes sure connection opener knows that the destinations have changed
Definition: FwdState.cc:683

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors