]> git.ipfire.org Git - thirdparty/squid.git/blame - src/FwdState.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / FwdState.h
CommitLineData
bbc27441 1/*
4ac4a490 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
bbc27441
AJ
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
2087dca6 9#ifndef SQUID_FORWARD_H
10#define SQUID_FORWARD_H
3cd1350a 11
8bf217bd 12#include "base/RefCount.h"
582c2af2
FC
13#include "comm.h"
14#include "comm/Connection.h"
c8f1812b 15#include "err_type.h"
582c2af2 16#include "fde.h"
955394ce 17#include "http/StatusCode.h"
582c2af2 18#include "ip/Address.h"
fcfdf7f9 19#include "security/forward.h"
cb4f4424 20#if USE_OPENSSL
268a2e8f
CT
21#include "ssl/support.h"
22#endif
582c2af2 23
62ee09ca 24/* forward decls */
25
4bf68cfa
AR
26class AccessLogEntry;
27typedef RefCount<AccessLogEntry> AccessLogEntryPointer;
e8dca475
CT
28class PconnPool;
29typedef RefCount<PconnPool> PconnPoolPointer;
aa839030 30class ErrorState;
06093389 31class HttpRequest;
62ee09ca 32
cb4f4424 33#if USE_OPENSSL
268a2e8f
CT
34namespace Ssl
35{
22636a68
CT
36class ErrorDetail;
37class CertValidationResponse;
268a2e8f 38};
b56756cb 39#endif
268a2e8f 40
425de4c8
AJ
41/**
42 * Returns the TOS value that we should be setting on the connection
43 * to the server, based on the ACL.
44 */
45tos_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 */
51nfmark_t GetNfmarkToServer(HttpRequest * request);
52
6ee88490
CT
53/// Sets initial TOS value and Netfilter for the future outgoing connection.
54void GetMarkingsToServer(HttpRequest * request, Comm::Connection &conn);
55
4a77bb4e
CT
56class HelperReply;
57
3cd1350a 58class FwdState : public RefCountable
59{
5c2f68b7
AJ
60 CBDATA_CLASS(FwdState);
61
3cd1350a 62public:
63 typedef RefCount<FwdState> Pointer;
3cd1350a 64 ~FwdState();
65 static void initModule();
66
4bf68cfa
AR
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.
be364179 70 static void fwdStart(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *);
8652f8e7
AJ
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.
6b679a01 75 void startConnectionOrFail();
8652f8e7 76
3cd1350a 77 void fail(ErrorState *err);
00ae51e4 78 void unregister(Comm::ConnectionPointer &conn);
3cd1350a 79 void unregister(int fd);
80 void complete();
3e8c047e 81 void handleUnregisteredServerEnd();
3cd1350a 82 int reforward();
955394ce 83 bool reforwardableStatus(const Http::StatusCode s) const;
3cd1350a 84 void serverClosed(int fd);
85 void connectStart();
c8407295 86 void connectDone(const Comm::ConnectionPointer & conn, Comm::Flag status, int xerrno);
3cd1350a 87 void connectTimeout(int fd);
8aec3e1b 88 time_t timeLeft() const; ///< the time left before the forwarding timeout expired
3cd1350a 89 bool checkRetry();
90 bool checkRetriable();
91 void dispatch();
e8dca475
CT
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);
642a305c 95 void pconnPush(Comm::ConnectionPointer & conn, const char *domain);
3cd1350a 96
97 bool dontRetry() { return flags.dont_retry; }
98
99 void dontRetry(bool val) { flags.dont_retry = val; }
100
5229395c 101 /** return a ConnectionPointer to the current server connection (may or may not be open) */
00ae51e4 102 Comm::ConnectionPointer const & serverConnection() const { return serverConn; };
5229395c 103
3cd1350a 104private:
7a0fb323 105 // hidden for safer management of self; use static fwdStart
4bf68cfa 106 FwdState(const Comm::ConnectionPointer &client, StoreEntry *, HttpRequest *, const AccessLogEntryPointer &alp);
7a0fb323 107 void start(Pointer aSelf);
108
32c32865 109#if STRICT_ORIGINAL_DST
7c75511b 110 void selectPeerForIntercepted();
32c32865 111#endif
955394ce 112 static void logReplyStatus(int tries, const Http::StatusCode status);
9d2760b6 113 void doneWithRetries();
802a8c1d 114 void completed();
3e8c047e 115 void retryOrBail();
2ac4f6b5 116 ErrorState *makeConnectingError(const err_type type) const;
fcfdf7f9 117 void connectedToPeer(Security::EncryptorAnswer &answer);
6852be71 118 static void RegisterWithCacheManager(void);
3cd1350a 119
e8dca475
CT
120 /// stops monitoring server connection for closure and updates pconn stats
121 void closeServerConnection(const char *reason);
122
4b77ea6b 123 void syncWithServerConn(const char *host);
7d1dac79 124 void syncHierNote(const Comm::ConnectionPointer &server, const char *host);
4b77ea6b 125
3cd1350a 126public:
127 StoreEntry *entry;
128 HttpRequest *request;
4bf68cfa
AR
129 AccessLogEntryPointer al; ///< info for the future access.log entry
130
429871db 131 static void abort(void*);
3cd1350a 132
133private:
3cd1350a 134 Pointer self;
135 ErrorState *err;
5c336a3b 136 Comm::ConnectionPointer clientConn; ///< a possibly open connection to the client.
3cd1350a 137 time_t start_t;
138 int n_tries;
3cd1350a 139
e3a4aecc
AJ
140 // AsyncCalls which we set and may need cancelling.
141 struct {
142 AsyncCall::Pointer connector; ///< a call linking us to the ConnOpener producing serverConn.
143 } calls;
3cd1350a 144
26ac0430 145 struct {
e857372a
FC
146 bool connected_okay; ///< TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc
147 bool dont_retry;
148 bool forward_completed;
2fadd50d 149 } flags;
3cd1350a 150
5229395c 151 /** connections to open, in order, until successful */
00ae51e4
AJ
152 Comm::ConnectionList serverDestinations;
153
154 Comm::ConnectionPointer serverConn; ///< a successfully opened connection to a server.
d2bf2f90 155
398bc066
CT
156 AsyncCall::Pointer closeHandler; ///< The serverConn close handler
157
bc81ee68
AR
158 /// possible pconn race states
159 typedef enum { raceImpossible, racePossible, raceHappened } PconnRace;
160 PconnRace pconnRace; ///< current pconn race state
3cd1350a 161};
2087dca6 162
8a648e8d 163void getOutgoingAddress(HttpRequest * request, Comm::ConnectionPointer conn);
28618087 164
d85b8894 165#endif /* SQUID_FORWARD_H */
f53969cc 166