]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
snmp-agent: Move net-snmp headers out of our headers 14330/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 17 Jun 2024 08:33:39 +0000 (10:33 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 17 Jun 2024 08:33:39 +0000 (10:33 +0200)
The net-snmp headers are unfortunately defining things that we do not
want, like `INET6` and `HAVE_LIBSSL`, so it's better for us not to
include them from our headers.

pdns/dnsdistdist/dnsdist-snmp.cc
pdns/recursordist/rec-snmp.cc
pdns/snmp-agent.cc
pdns/snmp-agent.hh

index 34e9c7cdd3858adf8a35ad82cf2b430735239926..ab6a0f2a09021cadb559b5671aeafe895d8f0d77 100644 (file)
@@ -9,6 +9,14 @@ std::unique_ptr<DNSDistSNMPAgent> g_snmpAgent{nullptr};
 
 #ifdef HAVE_NET_SNMP
 
+#include <net-snmp/net-snmp-config.h>
+#include <net-snmp/definitions.h>
+#include <net-snmp/types.h>
+#include <net-snmp/utilities.h>
+#include <net-snmp/config_api.h>
+#include <net-snmp/agent/net-snmp-agent-includes.h>
+#undef INET6 /* SRSLY? */
+
 #define DNSDIST_OID 1, 3, 6, 1, 4, 1, 43315, 3
 #define DNSDIST_STATS_OID DNSDIST_OID, 1
 #define DNSDIST_STATS_TABLE_OID DNSDIST_OID, 2
@@ -387,12 +395,9 @@ bool DNSDistSNMPAgent::sendBackendStatusChangeTrap(const DownstreamState& dss)
   const string backendStatus = dss.getStatus();
   netsnmp_variable_list* varList = nullptr;
 
-  snmp_varlist_add_variable(&varList,
-                            snmpTrapOID.data(),
-                            snmpTrapOID.size(),
-                            ASN_OBJECT_ID,
-                            backendStatusChangeTrapOID.data(),
-                            backendStatusChangeTrapOID.size() * sizeof(oid));
+  addSNMPTrapOID(&varList,
+                 backendStatusChangeTrapOID.data(),
+                 backendStatusChangeTrapOID.size() * sizeof(oid));
 
   snmp_varlist_add_variable(&varList,
                             backendNameOID.data(),
@@ -426,12 +431,9 @@ bool DNSDistSNMPAgent::sendCustomTrap(const std::string& reason)
 #ifdef HAVE_NET_SNMP
   netsnmp_variable_list* varList = nullptr;
 
-  snmp_varlist_add_variable(&varList,
-                            snmpTrapOID.data(),
-                            snmpTrapOID.size(),
-                            ASN_OBJECT_ID,
-                            customTrapOID.data(),
-                            customTrapOID.size() * sizeof(oid));
+  addSNMPTrapOID(&varList,
+                 customTrapOID.data(),
+                 customTrapOID.size() * sizeof(oid));
 
   snmp_varlist_add_variable(&varList,
                             trapReasonOID.data(),
@@ -462,12 +464,9 @@ bool DNSDistSNMPAgent::sendDNSTrap(const DNSQuestion& dnsQuestion, const std::st
 
   netsnmp_variable_list* varList = nullptr;
 
-  snmp_varlist_add_variable(&varList,
-                            snmpTrapOID.data(),
-                            snmpTrapOID.size(),
-                            ASN_OBJECT_ID,
-                            actionTrapOID.data(),
-                            actionTrapOID.size() * sizeof(oid));
+  addSNMPTrapOID(&varList,
+                 actionTrapOID.data(),
+                 actionTrapOID.size() * sizeof(oid));
 
   snmp_varlist_add_variable(&varList,
                             socketFamilyOID.data(),
index 0684ed5a72c432eac7f99a8b6734cf451e8f067e..f433f38374249e893b1c5ddfd1aa780af39ee4d2 100644 (file)
 
 #ifdef HAVE_NET_SNMP
 
+#include <net-snmp/net-snmp-config.h>
+#include <net-snmp/definitions.h>
+#include <net-snmp/types.h>
+#include <net-snmp/utilities.h>
+#include <net-snmp/config_api.h>
+#include <net-snmp/agent/net-snmp-agent-includes.h>
+#undef INET6 /* SRSLY? */
+
 #define RECURSOR_OID 1, 3, 6, 1, 4, 1, 43315, 2
 #define RECURSOR_STATS_OID RECURSOR_OID, 1
 #define RECURSOR_TRAPS_OID RECURSOR_OID, 10, 0
@@ -277,12 +285,9 @@ bool RecursorSNMPAgent::sendCustomTrap([[maybe_unused]] const std::string& reaso
 #ifdef HAVE_NET_SNMP
   netsnmp_variable_list* varList = nullptr;
 
-  snmp_varlist_add_variable(&varList,
-                            snmpTrapOID.data(),
-                            snmpTrapOID.size(),
-                            ASN_OBJECT_ID,
-                            customTrapOID.data(),
-                            customTrapOID.size() * sizeof(oid));
+  addSNMPTrapOID(&varList,
+                 customTrapOID.data(),
+                 customTrapOID.size() * sizeof(oid));
 
   snmp_varlist_add_variable(&varList,
                             trapReasonOID.data(),
index a335f31d0c0d38bbff0e2f86faf256cb3b832853..0e7ca82d65e8c1ca6c9b7d4518423a4738e9d7a5 100644 (file)
@@ -9,6 +9,14 @@
 
 #ifdef HAVE_NET_SNMP
 
+#include <net-snmp/net-snmp-config.h>
+#include <net-snmp/definitions.h>
+#include <net-snmp/types.h>
+#include <net-snmp/utilities.h>
+#include <net-snmp/config_api.h>
+#include <net-snmp/agent/net-snmp-agent-includes.h>
+#undef INET6 /* SRSLY? */
+
 #ifndef HAVE_SNMP_SELECT_INFO2
 /* that's terrible, because it means we are going to have trouble with large
    FD numbers at some point.. */
@@ -25,7 +33,7 @@
 # include <net-snmp/library/large_fd_set.h>
 #endif
 
-const std::array<oid, 11> SNMPAgent::snmpTrapOID = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 };
+static const std::array<oid, 11> s_snmpTrapOID = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 };
 
 int SNMPAgent::setCounter64Value(netsnmp_request_info* request,
                                  uint64_t value)
@@ -40,6 +48,16 @@ int SNMPAgent::setCounter64Value(netsnmp_request_info* request,
   return SNMP_ERR_NOERROR;
 }
 
+void SNMPAgent::addSNMPTrapOID(netsnmp_variable_list** varList, const void* value, size_t len)
+{
+  snmp_varlist_add_variable(varList,
+                            s_snmpTrapOID.data(),
+                            s_snmpTrapOID.size(),
+                            ASN_OBJECT_ID,
+                            value,
+                            len);
+}
+
 bool SNMPAgent::sendTrap(pdns::channel::Sender<netsnmp_variable_list, void(*)(netsnmp_variable_list*)>& sender,
                          netsnmp_variable_list* varList)
 {
index c75db08616051209d1936c2ab73f893cf96a1c9d..06989afc21efb0de5fd0e3068799a3ef668bba21 100644 (file)
@@ -5,19 +5,12 @@
 #include <thread>
 #include <unistd.h>
 
-#ifdef HAVE_NET_SNMP
-#include <net-snmp/net-snmp-config.h>
-#include <net-snmp/definitions.h>
-#include <net-snmp/types.h>
-#include <net-snmp/utilities.h>
-#include <net-snmp/config_api.h>
-#include <net-snmp/agent/net-snmp-agent-includes.h>
-#undef INET6 /* SRSLY? */
-#endif /* HAVE_NET_SNMP */
-
 #include "mplexer.hh"
 #include "channel.hh"
 
+typedef struct netsnmp_request_info_s netsnmp_request_info;
+typedef struct variable_list netsnmp_variable_list;
+
 class SNMPAgent
 {
 public:
@@ -40,8 +33,7 @@ public:
 #endif /* HAVE_NET_SNMP */
 protected:
 #ifdef HAVE_NET_SNMP
-  /* OID for snmpTrapOID.0 */
-  static const std::array<oid, 11> snmpTrapOID;
+  static void addSNMPTrapOID(netsnmp_variable_list** varList, const void* value, size_t len);
 
   static bool sendTrap(pdns::channel::Sender<netsnmp_variable_list, void(*)(netsnmp_variable_list*)>& sender,
                        netsnmp_variable_list* varList);