]> git.ipfire.org Git - thirdparty/squid.git/blob - src/FwdState.h
Merged from trunk rev.13445
[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 bool checkRetry();
79 bool checkRetriable();
80 void dispatch();
81 /// Pops a connection from connection pool if available. If not
82 /// checks the peer stand-by connection pool for available connection.
83 Comm::ConnectionPointer pconnPop(const Comm::ConnectionPointer &dest, const char *domain);
84 void pconnPush(Comm::ConnectionPointer & conn, const char *domain);
85
86 bool dontRetry() { return flags.dont_retry; }
87
88 void dontRetry(bool val) { flags.dont_retry = val; }
89
90 /** return a ConnectionPointer to the current server connection (may or may not be open) */
91 Comm::ConnectionPointer const & serverConnection() const { return serverConn; };
92
93 private:
94 // hidden for safer management of self; use static fwdStart
95 FwdState(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp);
96 void start(Pointer aSelf);
97
98 #if STRICT_ORIGINAL_DST
99 void selectPeerForIntercepted();
100 #endif
101 static void logReplyStatus(int tries, const Http::StatusCode status);
102 void doneWithRetries();
103 void completed();
104 void retryOrBail();
105 ErrorState *makeConnectingError(const err_type type) const;
106 #if USE_OPENSSL
107 void connectedToPeer(Ssl::PeerConnectorAnswer &answer);
108 #endif
109 static void RegisterWithCacheManager(void);
110
111 /// stops monitoring server connection for closure and updates pconn stats
112 void closeServerConnection(const char *reason);
113
114 public:
115 StoreEntry *entry;
116 HttpRequest *request;
117 AccessLogEntryPointer al; ///< info for the future access.log entry
118
119 static void abort(void*);
120
121 private:
122 Pointer self;
123 ErrorState *err;
124 Comm::ConnectionPointer clientConn; ///< a possibly open connection to the client.
125 time_t start_t;
126 int n_tries;
127
128 // AsyncCalls which we set and may need cancelling.
129 struct {
130 AsyncCall::Pointer connector; ///< a call linking us to the ConnOpener producing serverConn.
131 } calls;
132
133 struct {
134 bool connected_okay; ///< TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc
135 bool dont_retry;
136 bool forward_completed;
137 } flags;
138
139 /** connections to open, in order, until successful */
140 Comm::ConnectionList serverDestinations;
141
142 Comm::ConnectionPointer serverConn; ///< a successfully opened connection to a server.
143
144 /// possible pconn race states
145 typedef enum { raceImpossible, racePossible, raceHappened } PconnRace;
146 PconnRace pconnRace; ///< current pconn race state
147
148 // NP: keep this last. It plays with private/public
149 CBDATA_CLASS2(FwdState);
150 };
151
152 void getOutgoingAddress(HttpRequest * request, Comm::ConnectionPointer conn);
153
154 #endif /* SQUID_FORWARD_H */