]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Add RegisteredRunner for SNMP (#2142)
authorAmos Jeffries <yadij@users.noreply.github.com>
Sat, 30 Aug 2025 10:17:49 +0000 (10:17 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Sat, 30 Aug 2025 20:45:16 +0000 (20:45 +0000)
src/main.cc
src/snmp_core.cc
src/snmp_core.h

index e5d9a98ec976a112ebb0929bb03a574ae896e533..790971ae437d5e321b41f2ac0ee67a1a7b2f225b 100644 (file)
 #if USE_ADAPTATION
 #include "adaptation/Config.h"
 #endif
-#if SQUID_SNMP
-#include "snmp_core.h"
-#endif
 
 #include <cerrno>
 #if HAVE_GETOPT_H
@@ -784,10 +781,6 @@ serverConnectionsOpen(void)
 #if USE_HTCP
         htcpOpenPorts();
 #endif
-#if SQUID_SNMP
-        snmpOpenPorts();
-#endif
-
         icmpEngine.Open();
         netdbInit();
         Acl::Node::Initialize();
@@ -808,9 +801,6 @@ serverConnectionsClose(void)
 #endif
 
         icmpEngine.Close();
-#if SQUID_SNMP
-        snmpClosePorts();
-#endif
     }
 }
 
@@ -1138,11 +1128,6 @@ mainInitialize(void)
     icapLogOpen();
 #endif
 
-#if SQUID_SNMP
-
-    snmpInit();
-
-#endif
 #if MALLOC_DBG
 
     malloc_debug(0, malloc_debug_level);
@@ -1428,6 +1413,10 @@ RegisterModules()
     CallRunnerRegistratorIn(Rock, SwapDirRr);
 #endif
 
+#if SQUID_SNMP
+    CallRunnerRegistrator(SnmpRr);
+#endif
+
 #if USE_WCCP
     CallRunnerRegistrator(WccpRr);
 #endif
@@ -2038,9 +2027,6 @@ SquidShutdown()
     icpClosePorts();
 #if USE_HTCP
     htcpClosePorts();
-#endif
-#if SQUID_SNMP
-    snmpClosePorts();
 #endif
     releaseServerSockets();
     commCloseAllSockets();
index cc41fc727df6fd1dc5d6837ef2578bca4f0179b7..a031b8bf6c9dcc3f0b4b62c2c9848f21ed672cc8 100644 (file)
@@ -12,6 +12,7 @@
 #include "acl/FilledChecklist.h"
 #include "base/AsyncCallbacks.h"
 #include "base/CbcPointer.h"
+#include "base/RunnersRegistry.h"
 #include "CachePeer.h"
 #include "CachePeers.h"
 #include "client_db.h"
@@ -57,19 +58,15 @@ static mib_tree_entry *snmpTreeEntry(oid entry, snint len, mib_tree_entry * curr
 static mib_tree_entry *snmpTreeSiblingEntry(oid entry, snint len, mib_tree_entry * current);
 extern "C" void snmpSnmplibDebug(int lvl, char *buf);
 
-/*
- * The functions used during startup:
- * snmpInit
- * snmpConnectionOpen
- * snmpConnectionClose
- */
-
 /*
  * Turns the MIB into a Tree structure. Called during the startup process.
  */
-void
-snmpInit(void)
+static void
+snmpInit()
 {
+    if (!IamWorkerProcess())
+        return;
+
     debugs(49, 5, "snmpInit: Building SNMP mib tree structure");
 
     snmplib_debug_hook = snmpSnmplibDebug;
@@ -255,10 +252,11 @@ snmpInit(void)
     debugs(49, 9, "snmpInit: Completed SNMP mib tree structure");
 }
 
-void
-snmpOpenPorts(void)
+static void
+snmpOpenPorts()
 {
-    debugs(49, 5, "snmpConnectionOpen: Called");
+    if (!IamWorkerProcess())
+        return;
 
     if (Config.Port.snmp <= 0)
         return;
@@ -319,9 +317,12 @@ snmpPortOpened(Ipc::StartListeningAnswer &answer)
         fatalf("Lost SNMP port (%d) on FD %d", (int)conn->local.port(), conn->fd);
 }
 
-void
-snmpClosePorts(void)
+static void
+snmpClosePorts()
 {
+    if (!IamWorkerProcess())
+        return;
+
     if (Comm::IsConnOpen(snmpIncomingConn)) {
         debugs(49, DBG_IMPORTANT, "Closing SNMP receiving port " << snmpIncomingConn->local);
         snmpIncomingConn->close();
@@ -336,9 +337,16 @@ snmpClosePorts(void)
     snmpOutgoingConn = nullptr;
 }
 
-/*
- * Functions for handling the requests.
- */
+class SnmpRr : public RegisteredRunner
+{
+public:
+    void finalizeConfig() override { snmpInit(); }
+    void useConfig() override { snmpOpenPorts(); }
+    void startReconfigure() override { snmpClosePorts(); }
+    void syncConfig() override { snmpOpenPorts(); }
+    void startShutdown() override { snmpClosePorts(); }
+};
+DefineRunnerRegistrator(SnmpRr);
 
 /*
  * Accept the UDP packet
index 9e6430af9597db425d024f42de9c80c0bfd81723..2d650bf1a54b5ce6d614313658295e7b038b4c55 100644 (file)
@@ -47,9 +47,6 @@ AggrType snmpAggrType(oid* Current, snint CurrentLen);
 extern Comm::ConnectionPointer snmpOutgoingConn;
 
 extern PF snmpHandleUdp;
-void snmpInit(void);
-void snmpOpenPorts(void);
-void snmpClosePorts(void);
 const char * snmpDebugOid(oid * Name, snint Len, MemBuf &outbuf);
 void addr2oid(Ip::Address &addr, oid *Dest);
 void oid2addr(oid *Dest, Ip::Address &addr, u_int code);