]> git.ipfire.org Git - thirdparty/squid.git/blob - src/FwdState.h
Broken: define and use stub_libauth.cc
[thirdparty/squid.git] / src / FwdState.h
1 #ifndef SQUID_FORWARD_H
2 #define SQUID_FORWARD_H
3
4 #include "base/RefCount.h"
5 #include "base/Vector.h"
6 #include "comm.h"
7 #include "comm/Connection.h"
8 #include "err_type.h"
9 #include "fde.h"
10 #include "http/StatusCode.h"
11 #include "ip/Address.h"
12 #if USE_SSL
13 #include "ssl/support.h"
14 #endif
15
16 /* forward decls */
17
18 class AccessLogEntry;
19 typedef RefCount<AccessLogEntry> AccessLogEntryPointer;
20 class ErrorState;
21 class HttpRequest;
22
23 #if USE_SSL
24 namespace Ssl
25 {
26 class ErrorDetail;
27 class CertValidationResponse;
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 class HelperReply;
44
45 class FwdState : public RefCountable
46 {
47 public:
48 typedef RefCount<FwdState> Pointer;
49 ~FwdState();
50 static void initModule();
51
52 /// Initiates request forwarding to a peer or origin server.
53 static void Start(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp);
54 /// Same as Start() but no master xaction info (AccessLogEntry) available.
55 static void fwdStart(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *);
56
57 /// This is the real beginning of server connection. Call it whenever
58 /// the forwarding server destination has changed and a new one needs to be opened.
59 /// Produces the cannot-forward error on fail if no better error exists.
60 void startConnectionOrFail();
61
62 void fail(ErrorState *err);
63 void unregister(Comm::ConnectionPointer &conn);
64 void unregister(int fd);
65 void complete();
66 void handleUnregisteredServerEnd();
67 int reforward();
68 bool reforwardableStatus(const Http::StatusCode s) const;
69 void serverClosed(int fd);
70 void connectStart();
71 void connectDone(const Comm::ConnectionPointer & conn, comm_err_t status, int xerrno);
72 void connectTimeout(int fd);
73 void initiateSSL();
74 void negotiateSSL(int fd);
75 bool checkRetry();
76 bool checkRetriable();
77 void dispatch();
78 void pconnPush(Comm::ConnectionPointer & conn, const char *domain);
79
80 bool dontRetry() { return flags.dont_retry; }
81
82 void dontRetry(bool val) { flags.dont_retry = val; }
83
84 /** return a ConnectionPointer to the current server connection (may or may not be open) */
85 Comm::ConnectionPointer const & serverConnection() const { return serverConn; };
86
87 #if USE_SSL
88 /// Callback function called when squid receive message from cert validator helper
89 static void sslCrtvdHandleReplyWrapper(void *data, Ssl::CertValidationResponse const &);
90 /// Process response from cert validator helper
91 void sslCrtvdHandleReply(Ssl::CertValidationResponse const &);
92 /// Check SSL errors returned from cert validator against sslproxy_cert_error access list
93 Ssl::CertErrors *sslCrtvdCheckForErrors(Ssl::CertValidationResponse const &, Ssl::ErrorDetail *&);
94 #endif
95 private:
96 // hidden for safer management of self; use static fwdStart
97 FwdState(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp);
98 void start(Pointer aSelf);
99
100 #if STRICT_ORIGINAL_DST
101 void selectPeerForIntercepted();
102 #endif
103 static void logReplyStatus(int tries, const Http::StatusCode status);
104 void doneWithRetries();
105 void completed();
106 void retryOrBail();
107 ErrorState *makeConnectingError(const err_type type) const;
108 static void RegisterWithCacheManager(void);
109
110 public:
111 StoreEntry *entry;
112 HttpRequest *request;
113 AccessLogEntryPointer al; ///< info for the future access.log entry
114
115 static void abort(void*);
116
117 private:
118 Pointer self;
119 ErrorState *err;
120 Comm::ConnectionPointer clientConn; ///< a possibly open connection to the client.
121 time_t start_t;
122 int n_tries;
123
124 // AsyncCalls which we set and may need cancelling.
125 struct {
126 AsyncCall::Pointer connector; ///< a call linking us to the ConnOpener producing serverConn.
127 } calls;
128
129 struct {
130 bool connected_okay; ///< TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc
131 bool dont_retry;
132 bool forward_completed;
133 } flags;
134
135 /** connections to open, in order, until successful */
136 Comm::ConnectionList serverDestinations;
137
138 Comm::ConnectionPointer serverConn; ///< a successfully opened connection to a server.
139
140 /// possible pconn race states
141 typedef enum { raceImpossible, racePossible, raceHappened } PconnRace;
142 PconnRace pconnRace; ///< current pconn race state
143
144 // NP: keep this last. It plays with private/public
145 CBDATA_CLASS2(FwdState);
146 };
147
148 void getOutgoingAddress(HttpRequest * request, Comm::ConnectionPointer conn);
149
150 #endif /* SQUID_FORWARD_H */