]> git.ipfire.org Git - thirdparty/squid.git/blob - src/FwdState.h
Connection stats, including %<lp, missing for persistent connections.
[thirdparty/squid.git] / src / FwdState.h
1 /*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_FORWARD_H
10 #define SQUID_FORWARD_H
11
12 #include "base/RefCount.h"
13 #include "comm.h"
14 #include "comm/Connection.h"
15 #include "err_type.h"
16 #include "fde.h"
17 #include "http/StatusCode.h"
18 #include "ip/Address.h"
19 #include "security/forward.h"
20 #if USE_OPENSSL
21 #include "ssl/support.h"
22 #endif
23
24 /* forward decls */
25
26 class AccessLogEntry;
27 typedef RefCount<AccessLogEntry> AccessLogEntryPointer;
28 class PconnPool;
29 typedef RefCount<PconnPool> PconnPoolPointer;
30 class ErrorState;
31 class HttpRequest;
32
33 #if USE_OPENSSL
34 namespace Ssl
35 {
36 class ErrorDetail;
37 class CertValidationResponse;
38 };
39 #endif
40
41 /**
42 * Returns the TOS value that we should be setting on the connection
43 * to the server, based on the ACL.
44 */
45 tos_t GetTosToServer(HttpRequest * request);
46
47 /**
48 * Returns the Netfilter mark value that we should be setting on the
49 * connection to the server, based on the ACL.
50 */
51 nfmark_t GetNfmarkToServer(HttpRequest * request);
52
53 /// Sets initial TOS value and Netfilter for the future outgoing connection.
54 void GetMarkingsToServer(HttpRequest * request, Comm::Connection &conn);
55
56 class HelperReply;
57
58 class FwdState : public RefCountable
59 {
60 CBDATA_CLASS(FwdState);
61
62 public:
63 typedef RefCount<FwdState> Pointer;
64 ~FwdState();
65 static void initModule();
66
67 /// Initiates request forwarding to a peer or origin server.
68 static void Start(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp);
69 /// Same as Start() but no master xaction info (AccessLogEntry) available.
70 static void fwdStart(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *);
71
72 /// This is the real beginning of server connection. Call it whenever
73 /// the forwarding server destination has changed and a new one needs to be opened.
74 /// Produces the cannot-forward error on fail if no better error exists.
75 void startConnectionOrFail();
76
77 void fail(ErrorState *err);
78 void unregister(Comm::ConnectionPointer &conn);
79 void unregister(int fd);
80 void complete();
81 void handleUnregisteredServerEnd();
82 int reforward();
83 bool reforwardableStatus(const Http::StatusCode s) const;
84 void serverClosed(int fd);
85 void connectStart();
86 void connectDone(const Comm::ConnectionPointer & conn, Comm::Flag status, int xerrno);
87 void connectTimeout(int fd);
88 time_t timeLeft() const; ///< the time left before the forwarding timeout expired
89 bool checkRetry();
90 bool checkRetriable();
91 void dispatch();
92 /// Pops a connection from connection pool if available. If not
93 /// checks the peer stand-by connection pool for available connection.
94 Comm::ConnectionPointer pconnPop(const Comm::ConnectionPointer &dest, const char *domain);
95 void pconnPush(Comm::ConnectionPointer & conn, const char *domain);
96
97 bool dontRetry() { return flags.dont_retry; }
98
99 void dontRetry(bool val) { flags.dont_retry = val; }
100
101 /** return a ConnectionPointer to the current server connection (may or may not be open) */
102 Comm::ConnectionPointer const & serverConnection() const { return serverConn; };
103
104 private:
105 // hidden for safer management of self; use static fwdStart
106 FwdState(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp);
107 void start(Pointer aSelf);
108
109 #if STRICT_ORIGINAL_DST
110 void selectPeerForIntercepted();
111 #endif
112 static void logReplyStatus(int tries, const Http::StatusCode status);
113 void doneWithRetries();
114 void completed();
115 void retryOrBail();
116 ErrorState *makeConnectingError(const err_type type) const;
117 void connectedToPeer(Security::EncryptorAnswer &answer);
118 static void RegisterWithCacheManager(void);
119
120 /// stops monitoring server connection for closure and updates pconn stats
121 void closeServerConnection(const char *reason);
122
123 void syncWithServerConn(const char *host);
124
125 public:
126 StoreEntry *entry;
127 HttpRequest *request;
128 AccessLogEntryPointer al; ///< info for the future access.log entry
129
130 static void abort(void*);
131
132 private:
133 Pointer self;
134 ErrorState *err;
135 Comm::ConnectionPointer clientConn; ///< a possibly open connection to the client.
136 time_t start_t;
137 int n_tries;
138
139 // AsyncCalls which we set and may need cancelling.
140 struct {
141 AsyncCall::Pointer connector; ///< a call linking us to the ConnOpener producing serverConn.
142 } calls;
143
144 struct {
145 bool connected_okay; ///< TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc
146 bool dont_retry;
147 bool forward_completed;
148 } flags;
149
150 /** connections to open, in order, until successful */
151 Comm::ConnectionList serverDestinations;
152
153 Comm::ConnectionPointer serverConn; ///< a successfully opened connection to a server.
154
155 /// possible pconn race states
156 typedef enum { raceImpossible, racePossible, raceHappened } PconnRace;
157 PconnRace pconnRace; ///< current pconn race state
158 };
159
160 void getOutgoingAddress(HttpRequest * request, Comm::ConnectionPointer conn);
161
162 #endif /* SQUID_FORWARD_H */
163