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
;
26 class CertValidationResponse
;
27 class PeerConnectorAnswer
;
32 * Returns the TOS value that we should be setting on the connection
33 * to the server, based on the ACL.
35 tos_t
GetTosToServer(HttpRequest
* request
);
38 * Returns the Netfilter mark value that we should be setting on the
39 * connection to the server, based on the ACL.
41 nfmark_t
GetNfmarkToServer(HttpRequest
* request
);
43 /// Sets initial TOS value and Netfilter for the future outgoing connection.
44 void GetMarkingsToServer(HttpRequest
* request
, Comm::Connection
&conn
);
48 class FwdState
: public RefCountable
51 typedef RefCount
<FwdState
> Pointer
;
53 static void initModule();
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
*);
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();
65 void fail(ErrorState
*err
);
66 void unregister(Comm::ConnectionPointer
&conn
);
67 void unregister(int fd
);
69 void handleUnregisteredServerEnd();
71 bool reforwardableStatus(const Http::StatusCode s
) const;
72 void serverClosed(int fd
);
74 void connectDone(const Comm::ConnectionPointer
& conn
, comm_err_t status
, int xerrno
);
75 void connectTimeout(int fd
);
77 bool checkRetriable();
79 void pconnPush(Comm::ConnectionPointer
& conn
, const char *domain
);
81 bool dontRetry() { return flags
.dont_retry
; }
83 void dontRetry(bool val
) { flags
.dont_retry
= val
; }
85 /** return a ConnectionPointer to the current server connection (may or may not be open) */
86 Comm::ConnectionPointer
const & serverConnection() const { return serverConn
; };
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
);
93 #if STRICT_ORIGINAL_DST
94 void selectPeerForIntercepted();
96 static void logReplyStatus(int tries
, const Http::StatusCode status
);
97 void doneWithRetries();
100 ErrorState
*makeConnectingError(const err_type type
) const;
102 void connectedToPeer(Ssl::PeerConnectorAnswer
&answer
);
104 static void RegisterWithCacheManager(void);
108 HttpRequest
*request
;
109 AccessLogEntryPointer al
; ///< info for the future access.log entry
111 static void abort(void*);
116 Comm::ConnectionPointer clientConn
; ///< a possibly open connection to the client.
120 // AsyncCalls which we set and may need cancelling.
122 AsyncCall::Pointer connector
; ///< a call linking us to the ConnOpener producing serverConn.
126 bool connected_okay
; ///< TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc
128 bool forward_completed
;
131 /** connections to open, in order, until successful */
132 Comm::ConnectionList serverDestinations
;
134 Comm::ConnectionPointer serverConn
; ///< a successfully opened connection to a server.
136 /// possible pconn race states
137 typedef enum { raceImpossible
, racePossible
, raceHappened
} PconnRace
;
138 PconnRace pconnRace
; ///< current pconn race state
140 // NP: keep this last. It plays with private/public
141 CBDATA_CLASS2(FwdState
);
144 void getOutgoingAddress(HttpRequest
* request
, Comm::ConnectionPointer conn
);
146 #endif /* SQUID_FORWARD_H */