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