1 #ifndef SQUID_FORWARD_H
2 #define SQUID_FORWARD_H
4 #include "base/Vector.h"
5 #include "base/RefCount.h"
7 #include "comm/Connection.h"
10 #include "http/StatusCode.h"
11 #include "ip/Address.h"
13 #include "ssl/support.h"
19 typedef RefCount
<AccessLogEntry
> AccessLogEntryPointer
;
27 class CertValidationResponse
;
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
);
45 class FwdState
: public RefCountable
48 typedef RefCount
<FwdState
> Pointer
;
50 static void initModule();
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
*);
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();
62 void fail(ErrorState
*err
);
63 void unregister(Comm::ConnectionPointer
&conn
);
64 void unregister(int fd
);
66 void handleUnregisteredServerEnd();
68 bool reforwardableStatus(const Http::StatusCode s
) const;
69 void serverClosed(int fd
);
71 void connectDone(const Comm::ConnectionPointer
& conn
, comm_err_t status
, int xerrno
);
72 void connectTimeout(int fd
);
74 void negotiateSSL(int fd
);
76 bool checkRetriable();
78 void pconnPush(Comm::ConnectionPointer
& conn
, const char *domain
);
80 bool dontRetry() { return flags
.dont_retry
; }
82 void dontRetry(bool val
) { flags
.dont_retry
= val
; }
84 /** return a ConnectionPointer to the current server connection (may or may not be open) */
85 Comm::ConnectionPointer
const & serverConnection() const { return serverConn
; };
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
*&);
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
);
100 #if STRICT_ORIGINAL_DST
101 void selectPeerForIntercepted();
103 static void logReplyStatus(int tries
, const Http::StatusCode status
);
104 void doneWithRetries();
107 ErrorState
*makeConnectingError(const err_type type
) const;
108 static void RegisterWithCacheManager(void);
112 HttpRequest
*request
;
113 AccessLogEntryPointer al
; ///< info for the future access.log entry
115 static void abort(void*);
120 Comm::ConnectionPointer clientConn
; ///< a possibly open connection to the client.
124 // AsyncCalls which we set and may need cancelling.
126 AsyncCall::Pointer connector
; ///< a call linking us to the ConnOpener producing serverConn.
130 bool connected_okay
; ///< TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc
132 bool forward_completed
;
135 /** connections to open, in order, until successful */
136 Comm::ConnectionList serverDestinations
;
138 Comm::ConnectionPointer serverConn
; ///< a successfully opened connection to a server.
140 /// possible pconn race states
141 typedef enum { raceImpossible
, racePossible
, raceHappened
} PconnRace
;
142 PconnRace pconnRace
; ///< current pconn race state
144 // NP: keep this last. It plays with private/public
145 CBDATA_CLASS2(FwdState
);
148 void getOutgoingAddress(HttpRequest
* request
, Comm::ConnectionPointer conn
);
150 #endif /* SQUID_FORWARD_H */