]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/FwdState.h
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / FwdState.h
index 2baa0df9693df1bd11db69d8cffd7a47a4985a03..ae1434d08b8cd046eb28404fd77cbf1f293b480c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
@@ -9,9 +9,13 @@
 #ifndef SQUID_FORWARD_H
 #define SQUID_FORWARD_H
 
+#include "base/CbcPointer.h"
+#include "base/forward.h"
 #include "base/RefCount.h"
+#include "clients/forward.h"
 #include "comm.h"
 #include "comm/Connection.h"
+#include "comm/ConnOpener.h"
 #include "err_type.h"
 #include "fde.h"
 #include "http/StatusCode.h"
 
 class AccessLogEntry;
 typedef RefCount<AccessLogEntry> AccessLogEntryPointer;
-class PconnPool;
-typedef RefCount<PconnPool> PconnPoolPointer;
 class ErrorState;
 class HttpRequest;
+class PconnPool;
+class ResolvedPeers;
+typedef RefCount<ResolvedPeers> ResolvedPeersPointer;
+
+class HappyConnOpener;
+typedef CbcPointer<HappyConnOpener> HappyConnOpenerPointer;
+class HappyConnOpenerAnswer;
 
 #if USE_OPENSSL
 namespace Ssl
@@ -39,21 +48,14 @@ class CertValidationResponse;
 };
 #endif
 
-/**
- * Returns the TOS value that we should be setting on the connection
- * to the server, based on the ACL.
- */
-tos_t GetTosToServer(HttpRequest * request);
-
-/**
- * Returns the Netfilter mark value that we should be setting on the
- * connection to the server, based on the ACL.
- */
-nfmark_t GetNfmarkToServer(HttpRequest * request);
-
 /// Sets initial TOS value and Netfilter for the future outgoing connection.
+/// Updates the given Connection object, not the future transport connection.
 void GetMarkingsToServer(HttpRequest * request, Comm::Connection &conn);
 
+/// Recomputes and applies TOS value and Netfilter to the outgoing connection.
+/// Updates both the given Connection object and the transport connection.
+void ResetMarkingsToServer(HttpRequest *, Comm::Connection &);
+
 class HelperReply;
 
 class FwdState: public RefCountable, public PeerSelectionInitiator
@@ -78,7 +80,7 @@ public:
     /// This is the real beginning of server connection. Call it whenever
     /// the forwarding server destination has changed and a new one needs to be opened.
     /// Produces the cannot-forward error on fail if no better error exists.
-    void startConnectionOrFail();
+    void useDestinations();
 
     void fail(ErrorState *err);
     void unregister(Comm::ConnectionPointer &conn);
@@ -90,13 +92,10 @@ public:
     void serverClosed(int fd);
     void connectStart();
     void connectDone(const Comm::ConnectionPointer & conn, Comm::Flag status, int xerrno);
-    void connectTimeout(int fd);
     bool checkRetry();
     bool checkRetriable();
     void dispatch();
-    /// Pops a connection from connection pool if available. If not
-    /// checks the peer stand-by connection pool for available connection.
-    Comm::ConnectionPointer pconnPop(const Comm::ConnectionPointer &dest, const char *domain);
+
     void pconnPush(Comm::ConnectionPointer & conn, const char *domain);
 
     bool dontRetry() { return flags.dont_retry; }
@@ -116,6 +115,8 @@ private:
     virtual void noteDestination(Comm::ConnectionPointer conn) override;
     virtual void noteDestinationsEnd(ErrorState *selectionError) override;
 
+    void noteConnection(HappyConnOpenerAnswer &);
+
 #if STRICT_ORIGINAL_DST
     void selectPeerForIntercepted();
 #endif
@@ -123,16 +124,42 @@ private:
     void doneWithRetries();
     void completed();
     void retryOrBail();
+
+    void usePinned();
+
+    /// whether a pinned to-peer connection can be replaced with another one
+    /// (in order to retry or reforward a failed request)
+    bool pinnedCanRetry() const;
+
     ErrorState *makeConnectingError(const err_type type) const;
     void connectedToPeer(Security::EncryptorAnswer &answer);
     static void RegisterWithCacheManager(void);
 
+    void establishTunnelThruProxy();
+    void tunnelEstablishmentDone(Http::TunnelerAnswer &answer);
+    void secureConnectionToPeerIfNeeded();
+    void successfullyConnectedToPeer();
+
     /// stops monitoring server connection for closure and updates pconn stats
     void closeServerConnection(const char *reason);
 
-    void syncWithServerConn(const char *host);
+    void syncWithServerConn(const Comm::ConnectionPointer &server, const char *host, const bool reused);
     void syncHierNote(const Comm::ConnectionPointer &server, const char *host);
 
+    /// whether we have used up all permitted forwarding attempts
+    bool exhaustedTries() const;
+
+    /// \returns the time left for this connection to become connected or 1 second if it is less than one second left
+    time_t connectingTimeout(const Comm::ConnectionPointer &conn) const;
+
+    /// whether we are waiting for HappyConnOpener
+    /// same as calls.connector but may differ from connOpener.valid()
+    bool opening() const { return connOpener.set(); }
+
+    void cancelOpening(const char *reason);
+
+    void notifyConnOpener();
+
 public:
     StoreEntry *entry;
     HttpRequest *request;
@@ -145,7 +172,7 @@ private:
     ErrorState *err;
     Comm::ConnectionPointer clientConn;        ///< a possibly open connection to the client.
     time_t start_t;
-    int n_tries;
+    int n_tries; ///< the number of forwarding attempts so far
 
     // AsyncCalls which we set and may need cancelling.
     struct {
@@ -156,11 +183,11 @@ private:
         bool connected_okay; ///< TCP link ever opened properly. This affects retry of POST,PUT,CONNECT,etc
         bool dont_retry;
         bool forward_completed;
+        bool destinationsFound; ///< at least one candidate path found
     } flags;
 
-    /** connections to open, in order, until successful */
-    Comm::ConnectionList serverDestinations;
-
+    HappyConnOpenerPointer connOpener; ///< current connection opening job
+    ResolvedPeersPointer destinations; ///< paths for forwarding the request
     Comm::ConnectionPointer serverConn; ///< a successfully opened connection to a server.
 
     AsyncCall::Pointer closeHandler; ///< The serverConn close handler
@@ -172,5 +199,8 @@ private:
 
 void getOutgoingAddress(HttpRequest * request, Comm::ConnectionPointer conn);
 
+/// a collection of previously used persistent Squid-to-peer HTTP(S) connections
+extern PconnPool *fwdPconnPool;
+
 #endif /* SQUID_FORWARD_H */