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