From: Amos Jeffries Date: Tue, 2 Sep 2025 05:46:16 +0000 (+0000) Subject: Add RegisteredRunner for HTCP (#2143) X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;ds=sidebyside;p=thirdparty%2Fsquid.git Add RegisteredRunner for HTCP (#2143) --- diff --git a/src/htcp.cc b/src/htcp.cc index cf6b3b6120..99b3c429db 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -13,6 +13,7 @@ #include "acl/Acl.h" #include "acl/FilledChecklist.h" #include "base/AsyncCallbacks.h" +#include "base/RunnersRegistry.h" #include "CachePeer.h" #include "CachePeers.h" #include "comm.h" @@ -1432,15 +1433,12 @@ htcpRecv(int fd, void *) Comm::SetSelect(fd, COMM_SELECT_READ, htcpRecv, nullptr, 0); } -/* - * ====================================================================== - * PUBLIC FUNCTIONS - * ====================================================================== - */ - -void -htcpOpenPorts(void) +static void +htcpOpenPorts() { + if (!IamWorkerProcess()) + return; + if (Config.Port.htcp <= 0) { debugs(31, Important(21), "HTCP Disabled."); return; @@ -1612,8 +1610,8 @@ htcpClear(StoreEntry * e, HttpRequest * req, const HttpRequestMethod &, CachePee * htcpSocketShutdown only closes the 'in' socket if it is * different than the 'out' socket. */ -void -htcpSocketShutdown(void) +static void +htcpSocketShutdown() { if (!Comm::IsConnOpen(htcpIncomingConn)) return; @@ -1641,9 +1639,12 @@ htcpSocketShutdown(void) Comm::SetSelect(htcpOutgoingConn->fd, COMM_SELECT_READ, nullptr, nullptr, 0); } -void -htcpClosePorts(void) +static void +htcpClosePorts() { + if (!IamWorkerProcess()) + return; + htcpSocketShutdown(); if (htcpOutgoingConn != nullptr) { @@ -1652,6 +1653,16 @@ htcpClosePorts(void) } } +class HtcpRr : public RegisteredRunner +{ +public: + void useConfig() override { htcpOpenPorts(); } + void startReconfigure() override { htcpClosePorts(); } + void syncConfig() override { htcpOpenPorts(); } + void startShutdown() override { htcpClosePorts(); } +}; +DefineRunnerRegistrator(HtcpRr); + static void htcpLogHtcp(Ip::Address &caddr, const int opcode, const LogTags_ot logcode, const char *url, AccessLogEntryPointer al) { diff --git a/src/htcp.h b/src/htcp.h index 4bf9aadc7f..b7422b2c56 100644 --- a/src/htcp.h +++ b/src/htcp.h @@ -43,9 +43,6 @@ public: /// \ingroup ServerProtocolHTCP void neighborsHtcpReply(const cache_key *, HtcpReplyData *, const Ip::Address &); -/// \ingroup ServerProtocolHTCP -void htcpOpenPorts(void); - class CachePeer; /** @@ -66,13 +63,6 @@ int htcpQuery(StoreEntry * e, HttpRequest * req, CachePeer * p); /// \ingroup ServerProtocolHTCP void htcpClear(StoreEntry * e, HttpRequest * req, const HttpRequestMethod &method, CachePeer * p, htcp_clr_reason reason); -/// \ingroup ServerProtocolHTCP -void htcpSocketShutdown(void); - -/// \ingroup ServerProtocolHTCP -void htcpClosePorts(void); - #endif /* USE_HTCP */ - #endif /* SQUID_SRC_HTCP_H */ diff --git a/src/main.cc b/src/main.cc index 790971ae43..c18dde60d7 100644 --- a/src/main.cc +++ b/src/main.cc @@ -42,7 +42,6 @@ #include "fs_io.h" #include "FwdState.h" #include "globals.h" -#include "htcp.h" #include "http/Stream.h" #include "HttpHeader.h" #include "HttpReply.h" @@ -778,9 +777,6 @@ serverConnectionsOpen(void) if (IamWorkerProcess()) { clientOpenListenSockets(); icpOpenPorts(); -#if USE_HTCP - htcpOpenPorts(); -#endif icmpEngine.Open(); netdbInit(); Acl::Node::Initialize(); @@ -796,10 +792,6 @@ serverConnectionsClose(void) if (IamWorkerProcess()) { clientConnectionsClose(); icpConnectionShutdown(); -#if USE_HTCP - htcpSocketShutdown(); -#endif - icmpEngine.Close(); } } @@ -818,9 +810,6 @@ mainReconfigureStart(void) // Initiate asynchronous closing sequence serverConnectionsClose(); icpClosePorts(); -#if USE_HTCP - htcpClosePorts(); -#endif #if USE_OPENSSL Ssl::TheGlobalContextStorage().reconfigureStart(); #endif @@ -1404,7 +1393,9 @@ RegisterModules() #if USE_AUTH CallRunnerRegistrator(PeerUserHashRr); #endif - +#if USE_HTCP + CallRunnerRegistrator(HtcpRr); +#endif #if USE_OPENSSL CallRunnerRegistrator(sslBumpCfgRr); #endif @@ -2025,9 +2016,6 @@ SquidShutdown() redirectShutdown(); externalAclShutdown(); icpClosePorts(); -#if USE_HTCP - htcpClosePorts(); -#endif releaseServerSockets(); commCloseAllSockets();