From: Amos Jeffries Date: Fri, 27 Jun 2025 16:36:23 +0000 (+0000) Subject: Use RegisteredRunners for WCCP (de)activation (#2104) X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0b514968b6d7de6f4115fd56247ec714b9f70df8;p=thirdparty%2Fsquid.git Use RegisteredRunners for WCCP (de)activation (#2104) --- diff --git a/src/Makefile.am b/src/Makefile.am index 5d06101945..1ef2860f5b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -458,7 +458,6 @@ squid_SOURCES = \ urn.cc \ urn.h \ wccp.cc \ - wccp.h \ wccp2.cc \ wccp2.h \ wordlist.cc \ diff --git a/src/main.cc b/src/main.cc index 492b443ada..9b4a46f816 100644 --- a/src/main.cc +++ b/src/main.cc @@ -76,8 +76,6 @@ #include "time/Engine.h" #include "tools.h" #include "unlinkd.h" -#include "wccp.h" -#include "wccp2.h" #include "windows_service.h" #if USE_ADAPTATION @@ -779,16 +777,6 @@ sig_child(int sig) static void serverConnectionsOpen(void) { - if (IamPrimaryProcess()) { -#if USE_WCCP - wccpConnectionOpen(); -#endif - -#if USE_WCCPv2 - - wccp2ConnectionOpen(); -#endif - } // start various proxying services if we are responsible for them if (IamWorkerProcess()) { clientOpenListenSockets(); @@ -813,16 +801,6 @@ serverConnectionsClose(void) { assert(shutting_down || reconfiguring); - if (IamPrimaryProcess()) { -#if USE_WCCP - - wccpConnectionClose(); -#endif -#if USE_WCCPv2 - - wccp2ConnectionClose(); -#endif - } if (IamWorkerProcess()) { clientConnectionsClose(); icpConnectionShutdown(); @@ -966,17 +944,6 @@ mainReconfigureFinish(void *) #endif externalAclInit(); - if (IamPrimaryProcess()) { -#if USE_WCCP - - wccpInit(); -#endif -#if USE_WCCPv2 - - wccp2Init(); -#endif - } - serverConnectionsOpen(); neighbors_init(); @@ -1213,18 +1180,6 @@ mainInitialize(void) // PconnModule::GetInstance()->registerWithCacheManager(); // moved to PconnModule::PconnModule() - if (IamPrimaryProcess()) { -#if USE_WCCP - wccpInit(); - -#endif -#if USE_WCCPv2 - - wccp2Init(); - -#endif - } - serverConnectionsOpen(); neighbors_init(); @@ -1475,6 +1430,13 @@ RegisterModules() #if HAVE_FS_ROCK CallRunnerRegistratorIn(Rock, SwapDirRr); #endif + +#if USE_WCCP + CallRunnerRegistrator(WccpRr); +#endif +#if USE_WCCPv2 + CallRunnerRegistrator(Wccp2Rr); +#endif } int @@ -2086,15 +2048,6 @@ SquidShutdown() #if SQUID_SNMP snmpClosePorts(); #endif -#if USE_WCCP - - wccpConnectionClose(); -#endif -#if USE_WCCPv2 - - wccp2ConnectionClose(); -#endif - releaseServerSockets(); commCloseAllSockets(); diff --git a/src/tests/stub_wccp2.cc b/src/tests/stub_wccp2.cc index afa2aba83e..eb80f72a9d 100644 --- a/src/tests/stub_wccp2.cc +++ b/src/tests/stub_wccp2.cc @@ -7,18 +7,14 @@ */ #include "squid.h" -#include "wccp2.h" #if USE_WCCPv2 #define STUB_API "wccp2.cc" #include "tests/STUB.h" +#include "wccp2.h" class StoreEntry; - -void wccp2Init(void) STUB -void wccp2ConnectionOpen(void) STUB -void wccp2ConnectionClose(void) STUB void dump_wccp2_method(StoreEntry *, const char *, int) STUB void free_wccp2_method(int *) STUB void parse_wccp2_amethod(int *) STUB diff --git a/src/wccp.cc b/src/wccp.cc index f257116c2b..44792d10f7 100644 --- a/src/wccp.cc +++ b/src/wccp.cc @@ -11,13 +11,14 @@ #include "squid.h" #if USE_WCCP +#include "base/RunnersRegistry.h" #include "comm.h" #include "comm/Connection.h" #include "comm/Loops.h" #include "event.h" #include "fatal.h" #include "SquidConfig.h" -#include "wccp.h" +#include "tools.h" #define WCCP_PORT 2048 #define WCCP_REVISION 0 @@ -79,17 +80,12 @@ static int wccpLowestIP(void); static EVH wccpHereIam; static void wccpAssignBuckets(void); -/* - * The functions used during startup: - * wccpInit - * wccpConnectionOpen - * wccpConnectionShutdown - * wccpConnectionClose - */ - -void +static void wccpInit(void) { + if (!IamPrimaryProcess()) + return; + debugs(80, 5, "wccpInit: Called"); memset(&wccp_here_i_am, '\0', sizeof(wccp_here_i_am)); wccp_here_i_am.type = htonl(WCCP_HERE_I_AM); @@ -105,9 +101,12 @@ wccpInit(void) eventAdd("wccpHereIam", wccpHereIam, nullptr, 5.0, 1); } -void +static void wccpConnectionOpen(void) { + if (!IamPrimaryProcess()) + return; + debugs(80, 5, "wccpConnectionOpen: Called"); if (Config.Wccp.router.isAnyAddr()) { @@ -157,9 +156,12 @@ wccpConnectionOpen(void) local_ip = local; } -void +static void wccpConnectionClose(void) { + if (!IamPrimaryProcess()) + return; + if (theWccpConnection > -1) { debugs(80, DBG_IMPORTANT, "FD " << theWccpConnection << " Closing WCCPv1 socket"); comm_close(theWccpConnection); @@ -167,6 +169,16 @@ wccpConnectionClose(void) } } +class WccpRr : public RegisteredRunner +{ +public: + void useConfig() override { wccpInit(); wccpConnectionOpen(); } + void startReconfigure() override { wccpConnectionClose(); } + void syncConfig() override { wccpConnectionOpen(); } + void startShutdown() override { wccpConnectionClose(); } +}; +DefineRunnerRegistrator(WccpRr); + /* * Functions for handling the requests. */ diff --git a/src/wccp.h b/src/wccp.h deleted file mode 100644 index 57c86d0139..0000000000 --- a/src/wccp.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 1996-2025 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -/* DEBUG: section 80 WCCP Support */ - -#ifndef SQUID_SRC_WCCP_H -#define SQUID_SRC_WCCP_H - -#if USE_WCCP -void wccpInit(void); -void wccpConnectionOpen(void); -void wccpConnectionClose(void); -#endif /* USE_WCCP */ - -#endif /* SQUID_SRC_WCCP_H */ - diff --git a/src/wccp2.cc b/src/wccp2.cc index 5c92c5498d..38fc2d4ece 100644 --- a/src/wccp2.cc +++ b/src/wccp2.cc @@ -11,7 +11,7 @@ #include "squid.h" #if USE_WCCPv2 - +#include "base/RunnersRegistry.h" #include "cache_cf.h" #include "comm.h" #include "comm/Connection.h" @@ -23,6 +23,7 @@ #include "Parsing.h" #include "SquidConfig.h" #include "Store.h" +#include "tools.h" #include "wccp2.h" #if HAVE_NETDB_H @@ -652,9 +653,12 @@ wccp2_check_security(struct wccp2_service_list_t *srv, char *security, char *pac return (memcmp(md5Digest, md5_challenge, SQUID_MD5_DIGEST_LENGTH) == 0); } -void +static void wccp2Init(void) { + if (!IamPrimaryProcess()) + return; + Ip::Address_list *s; char *ptr; uint32_t service_flags; @@ -948,9 +952,12 @@ wccp2Init(void) } } -void +static void wccp2ConnectionOpen(void) { + if (!IamPrimaryProcess()) + return; + struct sockaddr_in router, local, null; socklen_t local_len, router_len; @@ -1036,9 +1043,11 @@ wccp2ConnectionOpen(void) wccp2_connected = 1; } -void +static void wccp2ConnectionClose(void) { + if (!IamPrimaryProcess()) + return; struct wccp2_service_list_t *service_list_ptr; @@ -1105,6 +1114,16 @@ wccp2ConnectionClose(void) wccp2_connected = 0; } +class Wccp2Rr : public RegisteredRunner +{ +public: + void useConfig() override { wccp2Init(); wccp2ConnectionOpen(); } + void startReconfigure() override { wccp2ConnectionClose(); } + void syncConfig() override { wccp2ConnectionOpen(); } + void startShutdown() override { wccp2ConnectionClose(); } +}; +DefineRunnerRegistrator(Wccp2Rr); + /* * Functions for handling the requests. */ diff --git a/src/wccp2.h b/src/wccp2.h index e1edc6cd4d..87cc2ba096 100644 --- a/src/wccp2.h +++ b/src/wccp2.h @@ -15,9 +15,6 @@ class StoreEntry; -void wccp2Init(void); -void wccp2ConnectionOpen(void); -void wccp2ConnectionClose(void); void parse_wccp2_method(int *v); void free_wccp2_method(int *v); void dump_wccp2_method(StoreEntry * e, const char *label, int v);