]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Use RegisteredRunners for WCCP (de)activation (#2104) auto master
authorAmos Jeffries <yadij@users.noreply.github.com>
Fri, 27 Jun 2025 16:36:23 +0000 (16:36 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Fri, 27 Jun 2025 21:31:06 +0000 (21:31 +0000)
src/Makefile.am
src/main.cc
src/tests/stub_wccp2.cc
src/wccp.cc
src/wccp.h [deleted file]
src/wccp2.cc
src/wccp2.h

index 5d061019454bcdb4a559d5b39f6998262de12943..1ef2860f5bc71572e1d399d53f22e60f57ff8186 100644 (file)
@@ -458,7 +458,6 @@ squid_SOURCES = \
        urn.cc \
        urn.h \
        wccp.cc \
-       wccp.h \
        wccp2.cc \
        wccp2.h \
        wordlist.cc \
index 492b443ada65f1b2146d5e4b47c8ae22aa598d04..9b4a46f816827eb1bbfda888109c4b4a6685c331 100644 (file)
@@ -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();
 
index afa2aba83edf5a0dbe7d9ad905b5a5c04af0f9c9..eb80f72a9de6c03997d9ae7eb3db31be053a1c3c 100644 (file)
@@ -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
index f257116c2b501f29579f22ef97d794dc5f3d9aae..44792d10f70fe54780065270911d8f6a073dfb46 100644 (file)
 #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 (file)
index 57c86d0..0000000
+++ /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 */
-
index 5c92c5498d8d421e598f224bff745a7dcf75de7c..38fc2d4ece3bdabca767fcce4fbc9a8c5ccb9c71 100644 (file)
@@ -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.
  */
index e1edc6cd4d06e7ddcc257f2aada2d7de14af1337..87cc2ba0967f918def024719fc20fb5e5a839c03 100644 (file)
@@ -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);