]> git.ipfire.org Git - thirdparty/squid.git/blob - src/FwdState.h
Merged from trunk (r13515).
[thirdparty/squid.git] / src / FwdState.h
1 #ifndef SQUID_FORWARD_H
2 #define SQUID_FORWARD_H
3
4 #include "base/RefCount.h"
5 #include "comm.h"
6 #include "comm/Connection.h"
7 #include "err_type.h"
8 #include "fde.h"
9 #include "http/StatusCode.h"
10 #include "ip/Address.h"
11 #if USE_OPENSSL
12 #include "ssl/support.h"
13 #endif
14
15 /* forward decls */
16
17 class AccessLogEntry;
18 typedef RefCount<AccessLogEntry> AccessLogEntryPointer;
19 class PconnPool;
20 typedef RefCount<PconnPool> PconnPoolPointer;
21 class ErrorState;
22 class HttpRequest;
23
24 #if USE_OPENSSL
25 namespace Ssl
26 {
27 class ErrorDetail;
28 class CertValidationResponse;
29 class PeerConnectorAnswer;
30 };
31 #endif
32
33 /**
34 * Returns the TOS value that we should be setting on the connection
35 * to the server, based on the ACL.
36 */
37 tos_t GetTosToServer(HttpRequest * request);
38
39 /**
40 * Returns the Netfilter mark value that we should be setting on the
41 * connection to the server, based on the ACL.
42 */
43 nfmark_t GetNfmarkToServer(HttpRequest * request);
44
45 /// Sets initial TOS value and Netfilter for the future outgoing connection.
46 void GetMarkingsToServer(HttpRequest * request, Comm::Connection &conn);
47
48 class HelperReply;
49
50 class FwdState : public RefCountable
51 {
52 public:
53 typedef RefCount<FwdState> Pointer;
54 ~FwdState();
55 static void initModule();
56
57 /// Initiates request forwarding to a peer or origin server.
58 static void Start(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp);
59 /// Same as Start() but no master xaction info (AccessLogEntry) available.
60 static void fwdStart(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *);
61
62 /// This is the real beginning of server connection. Call it whenever
63 /// the forwarding server destination has changed and a new one needs to be opened.
64 /// Produces the cannot-forward error on fail if no better error exists.
65 void startConnectionOrFail();
66
67 void fail(ErrorState *err);
68 void unregister(Comm::ConnectionPointer &conn);
69 void unregister(int fd);
70 void complete();
71 void handleUnregisteredServerEnd();
72 int reforward();
73 bool reforwardableStatus(const Http::StatusCode s) const;
74 void serverClosed(int fd);
75 void connectStart();
76 void connectDone(const Comm::ConnectionPointer & conn, Comm::Flag status, int xerrno);
77 void connectTimeout(int fd);
78 time_t timeLeft() const; ///< the time left before the forwarding timeout expired
79 bool checkRetry();
80 bool checkRetriable();
81 void dispatch();
82 /// Pops a connection from connection pool if available. If not
83 /// checks the peer stand-by connection pool for available connection.
84 Comm::ConnectionPointer pconnPop(const Comm::ConnectionPointer &dest, const char *domain);
85 void pconnPush(Comm::ConnectionPointer & conn, const char *domain);
86
87 bool dontRetry() { return flags.dont_retry; }
88
89 void dontRetry(bool val) { flags.dont_retry = val; }
90
91 /** return a ConnectionPointer to the current server connection (may or may not be open) */
92 Comm::ConnectionPointer const & serverConnection() const { return serverConn; };
93
94 private:
95 // hidden for safer management of self; use static fwdStart
96 FwdState(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp);
97 void start(Pointer aSelf);
98
99 #if STRICT_ORIGINAL_DST
100 void selectPeerForIntercepted();
101 #endif
102 static void logReplyStatus(int tries, const Http::StatusCode status);
103 void doneWithRetries();
104 void completed();
105 void retryOrBail();
106 ErrorState *makeConnectingError(const err_type type) const;
107 #if USE_OPENSSL
108 void connectedToPeer(Ssl::PeerConnectorAnswer &answer);
109 #endif
110 static void RegisterWithCacheManager(void);
111
112 /// stops monitoring server connection for closure and updates pconn stats
113 void closeServerConnection(const char *reason);
114
115 public:
116 StoreEntry *entry;
117 HttpRequest *request;
118 AccessLogEntryPointer al; ///< info for the future access.log entry
119
120 static void abort(void*);
121
122 private:
123 Pointer self;
124 ErrorState *err;
125 Comm::ConnectionPointer clientConn; ///< a possibly open connection to the client.
126 time_t start_t;
127 int n_tries;
128
129 // AsyncCalls which we set and may need cancelling.
130 struct {
131 AsyncCall::Pointer connector; ///< a call linking us to the ConnOpener producing serverConn.
132 } calls;
133
134 struct {
135 bool connected_okay; ///< TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc
136 bool dont_retry;
137 bool forward_completed;
138 } flags;
139
140 /** connections to open, in order, until successful */
141 Comm::ConnectionList serverDestinations;
142
143 Comm::ConnectionPointer serverConn; ///< a successfully opened connection to a server.
144
145 /// possible pconn race states
146 typedef enum { raceImpossible, racePossible, raceHappened } PconnRace;
147 PconnRace pconnRace; ///< current pconn race state
148
149 // NP: keep this last. It plays with private/public
150 CBDATA_CLASS2(FwdState);
151 };
152
153 void getOutgoingAddress(HttpRequest * request, Comm::ConnectionPointer conn);
154
155 #endif /* SQUID_FORWARD_H */