]>
Commit | Line | Data |
---|---|---|
bbc27441 AJ |
1 | /* |
2 | * Copyright (C) 1996-2014 The Squid Software Foundation and contributors | |
3 | * | |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
2087dca6 | 9 | #ifndef SQUID_FORWARD_H |
10 | #define SQUID_FORWARD_H | |
3cd1350a | 11 | |
8bf217bd | 12 | #include "base/RefCount.h" |
582c2af2 FC |
13 | #include "comm.h" |
14 | #include "comm/Connection.h" | |
c8f1812b | 15 | #include "err_type.h" |
582c2af2 | 16 | #include "fde.h" |
955394ce | 17 | #include "http/StatusCode.h" |
582c2af2 | 18 | #include "ip/Address.h" |
cb4f4424 | 19 | #if USE_OPENSSL |
268a2e8f CT |
20 | #include "ssl/support.h" |
21 | #endif | |
582c2af2 | 22 | |
62ee09ca | 23 | /* forward decls */ |
24 | ||
4bf68cfa AR |
25 | class AccessLogEntry; |
26 | typedef RefCount<AccessLogEntry> AccessLogEntryPointer; | |
e8dca475 CT |
27 | class PconnPool; |
28 | typedef RefCount<PconnPool> PconnPoolPointer; | |
aa839030 | 29 | class ErrorState; |
06093389 | 30 | class HttpRequest; |
62ee09ca | 31 | |
cb4f4424 | 32 | #if USE_OPENSSL |
268a2e8f CT |
33 | namespace Ssl |
34 | { | |
22636a68 CT |
35 | class ErrorDetail; |
36 | class CertValidationResponse; | |
a23223bf | 37 | class PeerConnectorAnswer; |
268a2e8f | 38 | }; |
b56756cb | 39 | #endif |
268a2e8f | 40 | |
425de4c8 AJ |
41 | /** |
42 | * Returns the TOS value that we should be setting on the connection | |
43 | * to the server, based on the ACL. | |
44 | */ | |
45 | tos_t GetTosToServer(HttpRequest * request); | |
46 | ||
47 | /** | |
48 | * Returns the Netfilter mark value that we should be setting on the | |
49 | * connection to the server, based on the ACL. | |
50 | */ | |
51 | nfmark_t GetNfmarkToServer(HttpRequest * request); | |
52 | ||
6ee88490 CT |
53 | /// Sets initial TOS value and Netfilter for the future outgoing connection. |
54 | void GetMarkingsToServer(HttpRequest * request, Comm::Connection &conn); | |
55 | ||
4a77bb4e CT |
56 | class HelperReply; |
57 | ||
3cd1350a | 58 | class FwdState : public RefCountable |
59 | { | |
3cd1350a | 60 | public: |
61 | typedef RefCount<FwdState> Pointer; | |
3cd1350a | 62 | ~FwdState(); |
63 | static void initModule(); | |
64 | ||
4bf68cfa AR |
65 | /// Initiates request forwarding to a peer or origin server. |
66 | static void Start(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp); | |
67 | /// Same as Start() but no master xaction info (AccessLogEntry) available. | |
be364179 | 68 | static void fwdStart(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *); |
8652f8e7 AJ |
69 | |
70 | /// This is the real beginning of server connection. Call it whenever | |
71 | /// the forwarding server destination has changed and a new one needs to be opened. | |
72 | /// Produces the cannot-forward error on fail if no better error exists. | |
6b679a01 | 73 | void startConnectionOrFail(); |
8652f8e7 | 74 | |
3cd1350a | 75 | void fail(ErrorState *err); |
00ae51e4 | 76 | void unregister(Comm::ConnectionPointer &conn); |
3cd1350a | 77 | void unregister(int fd); |
78 | void complete(); | |
3e8c047e | 79 | void handleUnregisteredServerEnd(); |
3cd1350a | 80 | int reforward(); |
955394ce | 81 | bool reforwardableStatus(const Http::StatusCode s) const; |
3cd1350a | 82 | void serverClosed(int fd); |
83 | void connectStart(); | |
c8407295 | 84 | void connectDone(const Comm::ConnectionPointer & conn, Comm::Flag status, int xerrno); |
3cd1350a | 85 | void connectTimeout(int fd); |
8aec3e1b | 86 | time_t timeLeft() const; ///< the time left before the forwarding timeout expired |
3cd1350a | 87 | bool checkRetry(); |
88 | bool checkRetriable(); | |
89 | void dispatch(); | |
e8dca475 CT |
90 | /// Pops a connection from connection pool if available. If not |
91 | /// checks the peer stand-by connection pool for available connection. | |
92 | Comm::ConnectionPointer pconnPop(const Comm::ConnectionPointer &dest, const char *domain); | |
642a305c | 93 | void pconnPush(Comm::ConnectionPointer & conn, const char *domain); |
3cd1350a | 94 | |
95 | bool dontRetry() { return flags.dont_retry; } | |
96 | ||
97 | void dontRetry(bool val) { flags.dont_retry = val; } | |
98 | ||
5229395c | 99 | /** return a ConnectionPointer to the current server connection (may or may not be open) */ |
00ae51e4 | 100 | Comm::ConnectionPointer const & serverConnection() const { return serverConn; }; |
5229395c | 101 | |
3cd1350a | 102 | private: |
7a0fb323 | 103 | // hidden for safer management of self; use static fwdStart |
4bf68cfa | 104 | FwdState(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp); |
7a0fb323 | 105 | void start(Pointer aSelf); |
106 | ||
32c32865 | 107 | #if STRICT_ORIGINAL_DST |
7c75511b | 108 | void selectPeerForIntercepted(); |
32c32865 | 109 | #endif |
955394ce | 110 | static void logReplyStatus(int tries, const Http::StatusCode status); |
9d2760b6 | 111 | void doneWithRetries(); |
802a8c1d | 112 | void completed(); |
3e8c047e | 113 | void retryOrBail(); |
2ac4f6b5 | 114 | ErrorState *makeConnectingError(const err_type type) const; |
a23223bf CT |
115 | #if USE_OPENSSL |
116 | void connectedToPeer(Ssl::PeerConnectorAnswer &answer); | |
117 | #endif | |
6852be71 | 118 | static void RegisterWithCacheManager(void); |
3cd1350a | 119 | |
e8dca475 CT |
120 | /// stops monitoring server connection for closure and updates pconn stats |
121 | void closeServerConnection(const char *reason); | |
122 | ||
3cd1350a | 123 | public: |
124 | StoreEntry *entry; | |
125 | HttpRequest *request; | |
4bf68cfa AR |
126 | AccessLogEntryPointer al; ///< info for the future access.log entry |
127 | ||
429871db | 128 | static void abort(void*); |
3cd1350a | 129 | |
130 | private: | |
3cd1350a | 131 | Pointer self; |
132 | ErrorState *err; | |
5c336a3b | 133 | Comm::ConnectionPointer clientConn; ///< a possibly open connection to the client. |
3cd1350a | 134 | time_t start_t; |
135 | int n_tries; | |
3cd1350a | 136 | |
e3a4aecc AJ |
137 | // AsyncCalls which we set and may need cancelling. |
138 | struct { | |
139 | AsyncCall::Pointer connector; ///< a call linking us to the ConnOpener producing serverConn. | |
140 | } calls; | |
3cd1350a | 141 | |
26ac0430 | 142 | struct { |
e857372a FC |
143 | bool connected_okay; ///< TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc |
144 | bool dont_retry; | |
145 | bool forward_completed; | |
2fadd50d | 146 | } flags; |
3cd1350a | 147 | |
5229395c | 148 | /** connections to open, in order, until successful */ |
00ae51e4 AJ |
149 | Comm::ConnectionList serverDestinations; |
150 | ||
151 | Comm::ConnectionPointer serverConn; ///< a successfully opened connection to a server. | |
d2bf2f90 | 152 | |
bc81ee68 AR |
153 | /// possible pconn race states |
154 | typedef enum { raceImpossible, racePossible, raceHappened } PconnRace; | |
155 | PconnRace pconnRace; ///< current pconn race state | |
156 | ||
d2bf2f90 AJ |
157 | // NP: keep this last. It plays with private/public |
158 | CBDATA_CLASS2(FwdState); | |
3cd1350a | 159 | }; |
2087dca6 | 160 | |
8a648e8d | 161 | void getOutgoingAddress(HttpRequest * request, Comm::ConnectionPointer conn); |
28618087 | 162 | |
d85b8894 | 163 | #endif /* SQUID_FORWARD_H */ |