1 #ifndef SQUID_FORWARD_H
2 #define SQUID_FORWARD_H
4 #include "base/RefCount.h"
6 #include "comm/Connection.h"
9 #include "http/StatusCode.h"
10 #include "ip/Address.h"
12 #include "ssl/support.h"
18 typedef RefCount
<AccessLogEntry
> AccessLogEntryPointer
;
20 typedef RefCount
<PconnPool
> PconnPoolPointer
;
28 class CertValidationResponse
;
29 class PeerConnectorAnswer
;
34 * Returns the TOS value that we should be setting on the connection
35 * to the server, based on the ACL.
37 tos_t
GetTosToServer(HttpRequest
* request
);
40 * Returns the Netfilter mark value that we should be setting on the
41 * connection to the server, based on the ACL.
43 nfmark_t
GetNfmarkToServer(HttpRequest
* request
);
45 /// Sets initial TOS value and Netfilter for the future outgoing connection.
46 void GetMarkingsToServer(HttpRequest
* request
, Comm::Connection
&conn
);
50 class FwdState
: public RefCountable
53 typedef RefCount
<FwdState
> Pointer
;
55 static void initModule();
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
*);
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();
67 void fail(ErrorState
*err
);
68 void unregister(Comm::ConnectionPointer
&conn
);
69 void unregister(int fd
);
71 void handleUnregisteredServerEnd();
73 bool reforwardableStatus(const Http::StatusCode s
) const;
74 void serverClosed(int fd
);
76 void connectDone(const Comm::ConnectionPointer
& conn
, comm_err_t status
, int xerrno
);
77 void connectTimeout(int fd
);
79 bool checkRetriable();
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
);
86 bool dontRetry() { return flags
.dont_retry
; }
88 void dontRetry(bool val
) { flags
.dont_retry
= val
; }
90 /** return a ConnectionPointer to the current server connection (may or may not be open) */
91 Comm::ConnectionPointer
const & serverConnection() const { return serverConn
; };
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
);
98 #if STRICT_ORIGINAL_DST
99 void selectPeerForIntercepted();
101 static void logReplyStatus(int tries
, const Http::StatusCode status
);
102 void doneWithRetries();
105 ErrorState
*makeConnectingError(const err_type type
) const;
107 void connectedToPeer(Ssl::PeerConnectorAnswer
&answer
);
109 static void RegisterWithCacheManager(void);
111 /// stops monitoring server connection for closure and updates pconn stats
112 void closeServerConnection(const char *reason
);
116 HttpRequest
*request
;
117 AccessLogEntryPointer al
; ///< info for the future access.log entry
119 static void abort(void*);
124 Comm::ConnectionPointer clientConn
; ///< a possibly open connection to the client.
128 // AsyncCalls which we set and may need cancelling.
130 AsyncCall::Pointer connector
; ///< a call linking us to the ConnOpener producing serverConn.
134 bool connected_okay
; ///< TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc
136 bool forward_completed
;
139 /** connections to open, in order, until successful */
140 Comm::ConnectionList serverDestinations
;
142 Comm::ConnectionPointer serverConn
; ///< a successfully opened connection to a server.
144 /// possible pconn race states
145 typedef enum { raceImpossible
, racePossible
, raceHappened
} PconnRace
;
146 PconnRace pconnRace
; ///< current pconn race state
148 // NP: keep this last. It plays with private/public
149 CBDATA_CLASS2(FwdState
);
152 void getOutgoingAddress(HttpRequest
* request
, Comm::ConnectionPointer conn
);
154 #endif /* SQUID_FORWARD_H */