FwdState.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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 ErrorState;
35class HttpRequest;
36class PconnPool;
37class ResolvedPeers;
39
40class HappyConnOpener;
42
46
50
51class HelperReply;
52
54{
56
57public:
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
108private:
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
160
161 void cancelStep(const char *reason);
162
163 void notifyConnOpener();
165
167
168public:
172
174 static void HandleStoreAbort(FwdState *);
175
176private:
180 time_t start_t;
182
183 struct {
189
192
195
199
202
206
208
212
215 const char *storedWholeReply_;
216};
217
218class acl_tos;
220
223
225extern PconnPool *fwdPconnPool;
226
227#endif /* SQUID_FORWARD_H */
228
PconnPool * fwdPconnPool
a collection of previously used persistent Squid-to-peer HTTP(S) connections
Definition: FwdState.cc:76
tos_t aclMapTOS(acl_tos *, ACLChecklist *)
Checks for a TOS value to apply depending on the ACL.
Definition: FwdState.cc:1496
void getOutgoingAddress(HttpRequest *, const Comm::ConnectionPointer &)
Definition: FwdState.cc:1519
RefCount< ResolvedPeers > ResolvedPeersPointer
Definition: FwdState.h:38
void GetMarkingsToServer(HttpRequest *request, Comm::Connection &conn)
Definition: FwdState.cc:1598
RefCount< AccessLogEntry > AccessLogEntryPointer
Definition: FwdState.h:33
void ResetMarkingsToServer(HttpRequest *, Comm::Connection &)
Definition: FwdState.cc:1607
Ip::NfMarkConfig aclFindNfMarkConfig(acl_nfmark *, ACLChecklist *)
Checks for a netfilter mark value to apply depending on the ACL.
Definition: FwdState.cc:1508
#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:186
void secureConnectionToPeerIfNeeded(const Comm::ConnectionPointer &)
handles an established TCP connection to peer (including origin servers)
Definition: FwdState.cc:996
Comm::ConnectionPointer clientConn
a possibly open connection to the client.
Definition: FwdState.h:179
bool checkRetry()
Definition: FwdState.cc:715
void reactToZeroSizeObject()
ERR_ZERO_SIZE_OBJECT requires special adjustments.
Definition: FwdState.cc:506
void handleUnregisteredServerEnd()
Definition: FwdState.cc:830
virtual void noteDestinationsEnd(ErrorState *selectionError) override
Definition: FwdState.cc:646
void connectedToPeer(Security::EncryptorAnswer &answer)
called when all negotiations with the TLS-speaking peer have been completed
Definition: FwdState.cc:1045
HttpRequest * request
Definition: FwdState.h:170
void serverClosed()
Definition: FwdState.cc:772
void successfullyConnectedToPeer(const Comm::ConnectionPointer &)
called when all negotiations with the peer have been completed
Definition: FwdState.cc:1081
PconnRace pconnRace
current pconn race state
Definition: FwdState.h:211
const char * storedWholeReply_
Definition: FwdState.h:215
struct FwdState::@73 flags
FwdState(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp)
Definition: FwdState.cc:142
JobWait< HappyConnOpener > transportWait
waits for a transport connection to the peer to be established/opened
Definition: FwdState.h:191
void doneWithRetries()
Definition: FwdState.cc:822
JobWait< Http::Tunneler > peerWait
Definition: FwdState.h:198
void completed()
Definition: FwdState.cc:276
void pconnPush(Comm::ConnectionPointer &conn, const char *domain)
bool transporting() const
Definition: FwdState.cc:599
PconnRace
possible pconn race states
Definition: FwdState.h:210
@ racePossible
Definition: FwdState.h:210
@ raceHappened
Definition: FwdState.h:210
@ raceImpossible
Definition: FwdState.h:210
bool destinationsFound
at least one candidate path found
Definition: FwdState.h:187
void complete()
Definition: FwdState.cc:556
static void Start(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp)
Initiates request forwarding to a peer or origin server.
Definition: FwdState.cc:360
virtual void noteDestination(Comm::ConnectionPointer conn) override
called when a new unique destination has been found
Definition: FwdState.cc:617
static void HandleStoreAbort(FwdState *)
called by Store if the entry is no longer usable
Definition: FwdState.cc:105
time_t connectingTimeout(const Comm::ConnectionPointer &conn) const
Definition: FwdState.cc:1482
bool connected_okay
TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc.
Definition: FwdState.h:184
static bool EnoughTimeToReForward(const time_t fwdStart)
Definition: FwdState.cc:461
void closePendingConnection(const Comm::ConnectionPointer &conn, const char *reason)
get rid of a to-server connection that failed to become serverConn
Definition: FwdState.cc:118
void unregister(Comm::ConnectionPointer &conn)
Definition: FwdState.cc:529
void connectDone(const Comm::ConnectionPointer &conn, Comm::Flag status, int xerrno)
void start(Pointer aSelf)
Definition: FwdState.cc:166
Comm::ConnectionPointer const & serverConnection() const
Definition: FwdState.h:106
bool dont_retry
Definition: FwdState.h:185
Comm::ConnectionPointer serverConn
a successfully opened connection to a server.
Definition: FwdState.h:204
void fail(ErrorState *err)
Definition: FwdState.cc:488
static time_t ForwardTimeout(const time_t fwdStart)
time left to finish the whole forwarding process (which started at fwdStart)
Definition: FwdState.cc:453
void closeServerConnection(const char *reason)
stops monitoring server connection for closure and updates pconn stats
Definition: FwdState.cc:130
bool dontRetry()
Definition: FwdState.h:98
CBDATA_CHILD(FwdState)
JobWait< Security::PeerConnector > encryptionWait
waits for the established transport connection to be secured/encrypted
Definition: FwdState.h:194
void dontRetry(bool val)
Definition: FwdState.h:100
void usePinned()
send request on an existing connection dedicated to the requesting client
Definition: FwdState.cc:1168
void tunnelEstablishmentDone(Http::TunnelerAnswer &answer)
resumes operations after the (possibly failed) HTTP CONNECT exchange
Definition: FwdState.cc:958
int n_tries
the number of forwarding attempts so far
Definition: FwdState.h:181
AsyncCall::Pointer closeHandler
The serverConn close handler.
Definition: FwdState.h:207
static void logReplyStatus(int tries, const Http::StatusCode status)
Definition: FwdState.cc:1440
static void RegisterWithCacheManager(void)
Definition: FwdState.cc:1434
void updateAleWithFinalError()
updates ALE when we finalize the transaction error (if any)
Definition: FwdState.cc:260
bool exhaustedTries() const
whether we have used up all permitted forwarding attempts
Definition: FwdState.cc:1454
RefCount< FwdState > Pointer
Definition: FwdState.h:58
void cancelStep(const char *reason)
Definition: FwdState.cc:220
void dispatch()
Definition: FwdState.cc:1204
StoreEntry * entry
Definition: FwdState.h:169
void establishTunnelThruProxy(const Comm::ConnectionPointer &)
Definition: FwdState.cc:935
void stopAndDestroy(const char *reason)
ends forwarding; relies on refcounting so the effect may not be immediate
Definition: FwdState.cc:205
static void initModule()
Definition: FwdState.cc:1428
time_t start_t
Definition: FwdState.h:180
bool checkRetriable()
Whether we may try sending this request again after a failure.
Definition: FwdState.cc:759
void syncWithServerConn(const Comm::ConnectionPointer &server, const char *host, const bool reused)
commits to using the given open to-peer connection
Definition: FwdState.cc:1097
bool waitingForDispatched
whether we are waiting for the last dispatch()ed activity to end
Definition: FwdState.h:201
void retryOrBail()
Definition: FwdState.cc:797
void noteConnection(HappyConnOpenerAnswer &)
Definition: FwdState.cc:866
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:685
void markStoredReplyAsWhole(const char *whyWeAreSure)
Definition: FwdState.cc:605
void connectStart()
Definition: FwdState.cc:1131
Pointer self
Definition: FwdState.h:177
PeerConnectionPointer destinationReceipt
peer selection result (or nil)
Definition: FwdState.h:205
void useDestinations()
Definition: FwdState.cc:467
void secureConnectionToPeer(const Comm::ConnectionPointer &)
encrypts an established TCP connection to peer (including origin servers)
Definition: FwdState.cc:1025
static void fwdStart(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *)
Same as Start() but no master xaction info (AccessLogEntry) available.
Definition: FwdState.cc:437
void syncHierNote(const Comm::ConnectionPointer &server, const char *host)
Definition: FwdState.cc:1117
int reforward()
Definition: FwdState.cc:1328
AccessLogEntryPointer al
info for the future access.log entry
Definition: FwdState.h:171
ErrorState * makeConnectingError(const err_type type) const
bool pinnedCanRetry() const
Definition: FwdState.cc:1460
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:846
ErrorState * err
Definition: FwdState.h:178
virtual ~FwdState()
Definition: FwdState.cc:327
bool reforwardableStatus(const Http::StatusCode s) const
Definition: FwdState.cc:1402
Final result (an open connection or an error) sent to the job initiator.
a netfilter mark/mask pair
Definition: NfMarkConfig.h:21
Interface for those who need a list of peers to forward a request to.
err_type
Definition: forward.h:14
int type
Definition: errorpage.cc:152
unsigned char tos_t
Definition: forward.h:27
Flag
Definition: Flag.h:15
StatusCode
Definition: StatusCode.h:20
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors