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
;
31 * Returns the TOS value that we should be setting on the connection
32 * to the server, based on the ACL.
34 tos_t
GetTosToServer(HttpRequest
* request
);
37 * Returns the Netfilter mark value that we should be setting on the
38 * connection to the server, based on the ACL.
40 nfmark_t
GetNfmarkToServer(HttpRequest
* request
);
44 class FwdState
: public RefCountable
47 typedef RefCount
<FwdState
> Pointer
;
49 static void initModule();
51 /// Initiates request forwarding to a peer or origin server.
52 static void Start(const Comm::ConnectionPointer
&client
, StoreEntry
*, HttpRequest
*, const AccessLogEntryPointer
&alp
);
53 /// Same as Start() but no master xaction info (AccessLogEntry) available.
54 static void fwdStart(const Comm::ConnectionPointer
&client
, StoreEntry
*, HttpRequest
*);
56 /// This is the real beginning of server connection. Call it whenever
57 /// the forwarding server destination has changed and a new one needs to be opened.
58 /// Produces the cannot-forward error on fail if no better error exists.
59 void startConnectionOrFail();
61 void fail(ErrorState
*err
);
62 void unregister(Comm::ConnectionPointer
&conn
);
63 void unregister(int fd
);
65 void handleUnregisteredServerEnd();
67 bool reforwardableStatus(const Http::StatusCode s
) const;
68 void serverClosed(int fd
);
70 void connectDone(const Comm::ConnectionPointer
& conn
, comm_err_t status
, int xerrno
);
71 void connectTimeout(int fd
);
73 void negotiateSSL(int fd
);
75 bool checkRetriable();
77 void pconnPush(Comm::ConnectionPointer
& conn
, const char *domain
);
79 bool dontRetry() { return flags
.dont_retry
; }
81 void dontRetry(bool val
) { flags
.dont_retry
= val
; }
83 /** return a ConnectionPointer to the current server connection (may or may not be open) */
84 Comm::ConnectionPointer
const & serverConnection() const { return serverConn
; };
87 /// Callback function called when squid receive message from cert validator helper
88 static void sslCrtvdHandleReplyWrapper(void *data
, Ssl::CertValidationResponse
const &);
89 /// Process response from cert validator helper
90 void sslCrtvdHandleReply(Ssl::CertValidationResponse
const &);
91 /// Check SSL errors returned from cert validator against sslproxy_cert_error access list
92 Ssl::CertErrors
*sslCrtvdCheckForErrors(Ssl::CertValidationResponse
const &, Ssl::ErrorDetail
*&);
95 // hidden for safer management of self; use static fwdStart
96 FwdState(const Comm::ConnectionPointer
&client
, StoreEntry
*, HttpRequest
*, const AccessLogEntryPointer
&alp
);
97 void start(Pointer aSelf
);
99 #if STRICT_ORIGINAL_DST
100 void selectPeerForIntercepted();
102 static void logReplyStatus(int tries
, const Http::StatusCode status
);
103 void doneWithRetries();
106 ErrorState
*makeConnectingError(const err_type type
) const;
107 static void RegisterWithCacheManager(void);
111 HttpRequest
*request
;
112 AccessLogEntryPointer al
; ///< info for the future access.log entry
114 static void abort(void*);
119 Comm::ConnectionPointer clientConn
; ///< a possibly open connection to the client.
123 // AsyncCalls which we set and may need cancelling.
125 AsyncCall::Pointer connector
; ///< a call linking us to the ConnOpener producing serverConn.
129 bool connected_okay
; ///< TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc
131 bool forward_completed
;
134 /** connections to open, in order, until successful */
135 Comm::ConnectionList serverDestinations
;
137 Comm::ConnectionPointer serverConn
; ///< a successfully opened connection to a server.
139 /// possible pconn race states
140 typedef enum { raceImpossible
, racePossible
, raceHappened
} PconnRace
;
141 PconnRace pconnRace
; ///< current pconn race state
143 // NP: keep this last. It plays with private/public
144 CBDATA_CLASS2(FwdState
);
147 void getOutgoingAddress(HttpRequest
* request
, Comm::ConnectionPointer conn
);
149 #endif /* SQUID_FORWARD_H */