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::Flag status
, int xerrno
);
77 void connectTimeout(int fd
);
78 time_t timeLeft() const; ///< the time left before the forwarding timeout expired
80 bool checkRetriable();
82 /// Pops a connection from connection pool if available. If not
83 /// checks the peer stand-by connection pool for available connection.
84 Comm::ConnectionPointer
pconnPop(const Comm::ConnectionPointer
&dest
, const char *domain
);
85 void pconnPush(Comm::ConnectionPointer
& conn
, const char *domain
);
87 bool dontRetry() { return flags
.dont_retry
; }
89 void dontRetry(bool val
) { flags
.dont_retry
= val
; }
91 /** return a ConnectionPointer to the current server connection (may or may not be open) */
92 Comm::ConnectionPointer
const & serverConnection() const { return serverConn
; };
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;
108 void connectedToPeer(Ssl::PeerConnectorAnswer
&answer
);
110 static void RegisterWithCacheManager(void);
112 /// stops monitoring server connection for closure and updates pconn stats
113 void closeServerConnection(const char *reason
);
117 HttpRequest
*request
;
118 AccessLogEntryPointer al
; ///< info for the future access.log entry
120 static void abort(void*);
125 Comm::ConnectionPointer clientConn
; ///< a possibly open connection to the client.
129 // AsyncCalls which we set and may need cancelling.
131 AsyncCall::Pointer connector
; ///< a call linking us to the ConnOpener producing serverConn.
135 bool connected_okay
; ///< TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc
137 bool forward_completed
;
140 /** connections to open, in order, until successful */
141 Comm::ConnectionList serverDestinations
;
143 Comm::ConnectionPointer serverConn
; ///< a successfully opened connection to a server.
145 /// possible pconn race states
146 typedef enum { raceImpossible
, racePossible
, raceHappened
} PconnRace
;
147 PconnRace pconnRace
; ///< current pconn race state
149 // NP: keep this last. It plays with private/public
150 CBDATA_CLASS2(FwdState
);
153 void getOutgoingAddress(HttpRequest
* request
, Comm::ConnectionPointer conn
);
155 #endif /* SQUID_FORWARD_H */