]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 2811: SNMP client table renumbering
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 14 Jan 2010 09:18:00 +0000 (22:18 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 14 Jan 2010 09:18:00 +0000 (22:18 +1300)
Bump the client table to version 2 for new IP address formatting.

* Also polishes the OID debug display a little bit.

src/client_db.cc
src/dns.cc
src/dns_internal.cc
src/fqdncache.cc
src/ipcache.cc
src/mib.txt
src/protos.h
src/snmp_agent.cc
src/snmp_core.cc

index ef08ee34a07846898d2c5d5800644845c0f45baa..93aa383457032f148742339cfe9979c3ad16c492 100644 (file)
@@ -36,6 +36,7 @@
 #include "event.h"
 #include "CacheManager.h"
 #include "ClientInfo.h"
+#include "ip/IpAddress.h"
 #include "SquidMath.h"
 #include "SquidTime.h"
 #include "Store.h"
@@ -412,27 +413,38 @@ client_entry(IpAddress *current)
 variable_list *
 snmp_meshCtblFn(variable_list * Var, snint * ErrP)
 {
-    variable_list *Answer = NULL;
-    static char key[16];
+    char key[MAX_IPSTRLEN];
     ClientInfo *c = NULL;
-    int aggr = 0;
+    IpAddress keyIp;
 
-    log_type l;
     *ErrP = SNMP_ERR_NOERROR;
-    debugs(49, 6, "snmp_meshCtblFn: Current : ");
-    snmpDebugOid(6, Var->name, Var->name_length);
-    /* FIXME INET6 : This must implement the key for IPv6 address */
-    snprintf(key, sizeof(key), "%d.%d.%d.%d", Var->name[LEN_SQ_NET + 3], Var->name[LEN_SQ_NET + 4],
-             Var->name[LEN_SQ_NET + 5], Var->name[LEN_SQ_NET + 6]);
-    debugs(49, 5, "snmp_meshCtblFn: [" << key << "] requested!");
+    MemBuf tmp;
+    debugs(49, 6, HERE << "Current : length=" << Var->name_length << ": " << snmpDebugOid(Var->name, Var->name_length, tmp));
+    if (Var->name_length == 16 ) {
+        oid2addr(&(Var->name[12]), keyIp, 4);
+#if USE_IPV6
+    } else if (Var->name_length == 28 ) {
+        oid2addr(&(Var->name[12]), keyIp, 16);
+#endif
+    } else {
+        *ErrP = SNMP_ERR_NOSUCHNAME;
+        return NULL;
+    }
+
+    keyIp.NtoA(key, sizeof(key));
+    debugs(49, 5, HERE << "[" << key << "] requested!");
     c = (ClientInfo *) hash_lookup(client_table, key);
 
     if (c == NULL) {
-        debugs(49, 5, "snmp_meshCtblFn: not found.");
+        debugs(49, 5, HERE << "not found.");
         *ErrP = SNMP_ERR_NOSUCHNAME;
         return NULL;
     }
 
+    variable_list *Answer = NULL;
+    int aggr = 0;
+    log_type l;
+
     switch (Var->name[LEN_SQ_NET + 2]) {
 
     case MESH_CTBL_ADDR_TYPE: {
index 29e4e991a0f83bce5f49b9688835d2ee8f9d53ce..f212b8e209791e77c1868b63dc9c0854e38c3a91 100644 (file)
@@ -148,8 +148,8 @@ variable_list *
 snmp_netDnsFn(variable_list * Var, snint * ErrP)
 {
     variable_list *Answer = NULL;
-    debugs(49, 5, "snmp_netDnsFn: Processing request: " << Var->name[LEN_SQ_NET + 1]);
-    snmpDebugOid(5, Var->name, Var->name_length);
+    MemBuf tmp;
+    debugs(49, 5, "snmp_netDnsFn: Processing request: " << Var->name[LEN_SQ_NET + 1] << " " << snmpDebugOid(Var->name, Var->name_length, tmp));
     *ErrP = SNMP_ERR_NOERROR;
 
     switch (Var->name[LEN_SQ_NET + 1]) {
index d4e9eb6a202d6c023b364b91761b3dd200b478db..b6c9f57a76dc04da00ace7756eea904b8599be2d 100644 (file)
@@ -1643,8 +1643,8 @@ snmp_netIdnsFn(variable_list * Var, snint * ErrP)
 {
     int i, n = 0;
     variable_list *Answer = NULL;
-    debugs(49, 5, "snmp_netDnsFn: Processing request: ");
-    snmpDebugOid(5, Var->name, Var->name_length);
+    MemBuf tmp;
+    debugs(49, 5, "snmp_netDnsFn: Processing request: " << snmpDebugOid(Var->name, Var->name_length, tmp));
     *ErrP = SNMP_ERR_NOERROR;
 
     switch (Var->name[LEN_SQ_NET + 1]) {
index 2bdf6e38d5b60c49fdb831509e7473dcccafbcf2..ab2699e2abca0f184a729b4f6ac9d3cd857d2067 100644 (file)
@@ -882,8 +882,8 @@ variable_list *
 snmp_netFqdnFn(variable_list * Var, snint * ErrP)
 {
     variable_list *Answer = NULL;
-    debugs(49, 5, "snmp_netFqdnFn: Processing request:");
-    snmpDebugOid(5, Var->name, Var->name_length);
+    MemBuf tmp;
+    debugs(49, 5, "snmp_netFqdnFn: Processing request:" << snmpDebugOid(Var->name, Var->name_length, tmp));
     *ErrP = SNMP_ERR_NOERROR;
 
     switch (Var->name[LEN_SQ_NET + 1]) {
index b0b8cc5f0ced9f31efaa49f2964394d5b96fe710..0276ac2beabeb90907042eafc79e4dd34dd5a379 100644 (file)
@@ -1489,8 +1489,8 @@ variable_list *
 snmp_netIpFn(variable_list * Var, snint * ErrP)
 {
     variable_list *Answer = NULL;
-    debugs(49, 5, "snmp_netIpFn: Processing request:");
-    snmpDebugOid(5, Var->name, Var->name_length);
+    MemBuf tmp;
+    debugs(49, 5, "snmp_netIpFn: Processing request:" << snmpDebugOid(Var->name, Var->name_length, tmp));
     *ErrP = SNMP_ERR_NOERROR;
 
     switch (Var->name[LEN_SQ_NET + 1]) {
index dba27db7c13db24f44d964c6f22ba0b6f62d596c..8a8137fff2e7a88801509309a22036d7c93de207 100644 (file)
@@ -929,15 +929,14 @@ squid MODULE-IDENTITY
                     "A list of cache client entries."
                ::= { cacheMesh 2 }
 
-
        cacheClientEntry OBJECT-TYPE
            SYNTAX CacheClientEntry
            MAX-ACCESS  not-accessible
            STATUS  current
            DESCRIPTION
-                    "An entry in cacheClientTable "
-          INDEX { cacheClientAddressType, cacheClientAddress }
-       ::= { cacheClientTable 1 }
+                    "An IP entry in cacheClientTable "
+          INDEX { cacheClientAddress }
+       ::= { cacheClientTable 2 }
 
        CacheClientEntry ::= SEQUENCE {
                cacheClientAddressType  InetAddressType,
index fdecc560898fcc159b033732caa19f1198c6b96e..4ff74b8fa7a1f45f10cc155717db9d82d3322d91 100644 (file)
@@ -282,13 +282,13 @@ SQUIDCEXTERN void httpHeaderStoreReport(StoreEntry * e);
 SQUIDCEXTERN void httpHdrMangleList(HttpHeader *, HttpRequest *, int req_or_rep);
 SQUIDCEXTERN int httpReqHdrManglersConfigured();
 
-#ifdef SQUID_SNMP
+#if SQUID_SNMP
 SQUIDCEXTERN PF snmpHandleUdp;
 SQUIDCEXTERN void snmpInit(void);
 SQUIDCEXTERN void snmpConnectionOpen(void);
 SQUIDCEXTERN void snmpConnectionShutdown(void);
 SQUIDCEXTERN void snmpConnectionClose(void);
-SQUIDCEXTERN void snmpDebugOid(int lvl, oid * Name, snint Len);
+SQUIDCEXTERN const char * snmpDebugOid(oid * Name, snint Len, MemBuf &outbuf);
 
 SQUIDCEXTERN void addr2oid(IpAddress &addr, oid *Dest);
 SQUIDCEXTERN void oid2addr(oid *Dest, IpAddress &addr, u_int code);
index 7b2162786d1904950d19d661946c9ac229250042..1c36bfb7256945bb3e7e4125e418779131008239 100644 (file)
@@ -53,8 +53,8 @@ variable_list *
 snmp_sysFn(variable_list * Var, snint * ErrP)
 {
     variable_list *Answer = NULL;
-    debugs(49, 5, "snmp_sysFn: Processing request:");
-    snmpDebugOid(5, Var->name, Var->name_length);
+    MemBuf tmp;
+    debugs(49, 5, "snmp_sysFn: Processing request:" << snmpDebugOid(Var->name, Var->name_length, tmp));
     *ErrP = SNMP_ERR_NOERROR;
 
     switch (Var->name[LEN_SQ_SYS]) {
index 13686ad24f12db653e2ef2193d7edf29fa903621..d27c7814424a17791f003216c80b3aa7bcd4f414 100644 (file)
@@ -251,27 +251,26 @@ snmpInit(void)
     snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.1.3", MESH_PTBL_RTT, snmp_meshPtblFn, peer_Inst);
     snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.1.3", MESH_PTBL_IGN, snmp_meshPtblFn, peer_Inst);
     snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.1.3", MESH_PTBL_KEEPAL_S, snmp_meshPtblFn, peer_Inst);
-    mib_tree_last = snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.1.3", MESH_PTBL_KEEPAL_R, snmp_meshPtblFn, peer_Inst);
+    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.1.3", MESH_PTBL_KEEPAL_R, snmp_meshPtblFn, peer_Inst);
 
-#if 0
     /* cacheClientTable - 1.3.6.1.4.1.3495.1.5.2 */
     snmpAddNodeStr("1.3.6.1.4.1.3495.1.5", MESH_CTBL, NULL, NULL);
 
-    /* BUG 2811: we NEED to create a reliable index for the clientDb and morph this to version 3 of the table. */
-
-    /* cacheClientEntry - 1.3.6.1.4.1.3495.1.5.2.1 */
-    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2", 1, NULL, NULL);
-    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.1", MESH_CTBL_ADDR_TYPE, snmp_meshCtblFn, client_Inst);
-    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.1", MESH_CTBL_ADDR, snmp_meshCtblFn, client_Inst);
-    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.1", MESH_CTBL_HTREQ, snmp_meshCtblFn, client_Inst);
-    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.1", MESH_CTBL_HTBYTES, snmp_meshCtblFn, client_Inst);
-    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.1", MESH_CTBL_HTHITS, snmp_meshCtblFn, client_Inst);
-    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.1", MESH_CTBL_HTHITBYTES, snmp_meshCtblFn, client_Inst);
-    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.1", MESH_CTBL_ICPREQ, snmp_meshCtblFn, client_Inst);
-    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.1", MESH_CTBL_ICPBYTES, snmp_meshCtblFn, client_Inst);
-    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.1", MESH_CTBL_ICPHITS, snmp_meshCtblFn, client_Inst);
-    mib_tree_last = snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.1", MESH_CTBL_ICPHITBYTES, snmp_meshCtblFn, client_Inst);
-#endif
+    /* BUG 2811: we NEED to create a reliable index for the client DB and make version 3 of the table. */
+    /* for now we have version 2 table with OID capable of mixed IPv4 / IPv6 clients and upgraded address text format. */
+
+    /* cacheClientEntry - 1.3.6.1.4.1.3495.1.5.2.2 */
+    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2", 2, NULL, NULL);
+    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.2", MESH_CTBL_ADDR_TYPE, snmp_meshCtblFn, client_Inst);
+    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.2", MESH_CTBL_ADDR, snmp_meshCtblFn, client_Inst);
+    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.2", MESH_CTBL_HTREQ, snmp_meshCtblFn, client_Inst);
+    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.2", MESH_CTBL_HTBYTES, snmp_meshCtblFn, client_Inst);
+    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.2", MESH_CTBL_HTHITS, snmp_meshCtblFn, client_Inst);
+    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.2", MESH_CTBL_HTHITBYTES, snmp_meshCtblFn, client_Inst);
+    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.2", MESH_CTBL_ICPREQ, snmp_meshCtblFn, client_Inst);
+    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.2", MESH_CTBL_ICPBYTES, snmp_meshCtblFn, client_Inst);
+    snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.2", MESH_CTBL_ICPHITS, snmp_meshCtblFn, client_Inst);
+    mib_tree_last = snmpAddNodeStr("1.3.6.1.4.1.3495.1.5.2.2", MESH_CTBL_ICPHITBYTES, snmp_meshCtblFn, client_Inst);
 
     debugs(49, 9, "snmpInit: Completed SNMP mib tree structure");
 }
@@ -588,8 +587,8 @@ snmpTreeGet(oid * Current, snint CurrentLen)
 
     debugs(49, 5, "snmpTreeGet: Called");
 
-    debugs(49, 6, "snmpTreeGet: Current : ");
-    snmpDebugOid(6, Current, CurrentLen);
+    MemBuf tmp;
+    debugs(49, 6, "snmpTreeGet: Current : " << snmpDebugOid(Current, CurrentLen, tmp) );
 
     mibTreeEntry = mib_tree_head;
 
@@ -619,8 +618,8 @@ snmpTreeNext(oid * Current, snint CurrentLen, oid ** Next, snint * NextLen)
 
     debugs(49, 5, "snmpTreeNext: Called");
 
-    debugs(49, 6, "snmpTreeNext: Current : ");
-    snmpDebugOid(6, Current, CurrentLen);
+    MemBuf tmp;
+    debugs(49, 6, "snmpTreeNext: Current : " << snmpDebugOid(Current, CurrentLen, tmp));
 
     mibTreeEntry = mib_tree_head;
 
@@ -650,8 +649,8 @@ snmpTreeNext(oid * Current, snint CurrentLen, oid ** Next, snint * NextLen)
         *NextLen = CurrentLen;
         *Next = (*mibTreeEntry->instancefunction) (Current, NextLen, mibTreeEntry, &Fn);
         if (*Next) {
-            debugs(49, 6, "snmpTreeNext: Next : ");
-            snmpDebugOid(6, *Next, *NextLen);
+            MemBuf tmp;
+            debugs(49, 6, "snmpTreeNext: Next : " << snmpDebugOid(*Next, *NextLen, tmp));
             return (Fn);
         }
     }
@@ -694,8 +693,8 @@ snmpTreeNext(oid * Current, snint CurrentLen, oid ** Next, snint * NextLen)
     }
 
     if (*Next) {
-        debugs(49, 6, "snmpTreeNext: Next : ");
-        snmpDebugOid(6, *Next, *NextLen);
+        MemBuf tmp;
+        debugs(49, 6, "snmpTreeNext: Next : " << snmpDebugOid(*Next, *NextLen, tmp));
         return (Fn);
     } else
         return NULL;
@@ -807,6 +806,8 @@ client_Inst(oid * name, snint * len, mib_tree_entry * current, oid_ParseFn ** Fn
             size = sizeof(in6_addr);
 #endif
 
+        debugs(49, 6, HERE << "len" << *len << ", current-len" << current->len << ", addr=" << laddr << ", size=" << size);
+
         instance = (oid *)xmalloc(sizeof(name) * (*len + size ));
         xmemcpy(instance, name, (sizeof(name) * (*len)));
 
@@ -830,6 +831,9 @@ client_Inst(oid * name, snint * len, mib_tree_entry * current, oid_ParseFn ** Fn
             else
                 newshift = sizeof(in6_addr);
 #endif
+
+            debugs(49, 6, HERE << "len" << *len << ", current-len" << current->len << ", addr=" << laddr << ", newshift=" << newshift);
+
             instance = (oid *)xmalloc(sizeof(name) * (current->len +  newshift));
             xmemcpy(instance, name, (sizeof(name) * (current->len)));
             addr2oid(laddr, &instance[current->len]);  // the addr.
@@ -841,7 +845,6 @@ client_Inst(oid * name, snint * len, mib_tree_entry * current, oid_ParseFn ** Fn
     return (instance);
 }
 
-
 /*
  * Utility functions
  */
@@ -1016,8 +1019,8 @@ snmpAddNode(oid * name, int len, oid_ParseFn * parsefunction, instance_Fn * inst
     mib_tree_entry *entry = NULL;
     va_start(args, children);
 
-    debugs(49, 6, "snmpAddNode: Children : " << children << ", Oid : ");
-    snmpDebugOid(6, name, len);
+    MemBuf tmp;
+    debugs(49, 6, "snmpAddNode: Children : " << children << ", Oid : " << snmpDebugOid(name, len, tmp));
 
     va_start(args, children);
     entry = (mib_tree_entry *)xmalloc(sizeof(mib_tree_entry));
@@ -1066,19 +1069,19 @@ snmpCreateOid(int length,...)
 /*
  * Debug calls, prints out the OID for debugging purposes.
  */
-void
-snmpDebugOid(int lvl, oid * Name, snint Len)
+const char *
+snmpDebugOid(oid * Name, snint Len, MemBuf &outbuf)
 {
-    char mbuf[16], objid[1024];
+    char mbuf[16];
     int x;
-    objid[0] = '\0';
+    if (outbuf.isNull())
+        outbuf.init(16, MAX_IPSTRLEN);
 
     for (x = 0; x < Len; x++) {
-        snprintf(mbuf, sizeof(mbuf), ".%u", (unsigned int) Name[x]);
-        strncat(objid, mbuf, sizeof(objid) - strlen(objid) - 1);
+        size_t bytes = snprintf(mbuf, sizeof(mbuf), ".%u", (unsigned int) Name[x]);
+        outbuf.append(mbuf, bytes);
     }
-
-    debugs(49, lvl, "   oid = " << objid);
+    return outbuf.content();
 }
 
 static void
@@ -1103,7 +1106,7 @@ addr2oid(IpAddress &addr, oid * Dest)
     struct in_addr iaddr;
 #if USE_IPV6
     struct in6_addr i6addr;
-    oid code = addr.IsIPv4()? INETADDRESSTYPE_IPV4  : INETADDRESSTYPE_IPV6 ;
+    oid code = addr.IsIPv6()? INETADDRESSTYPE_IPV6  : INETADDRESSTYPE_IPV4 ;
     u_int size = (code == INETADDRESSTYPE_IPV4) ? sizeof(struct in_addr):sizeof(struct in6_addr);
 #else
     oid code = INETADDRESSTYPE_IPV4 ;
@@ -1124,9 +1127,8 @@ addr2oid(IpAddress &addr, oid * Dest)
         // OID's are in network order
         Dest[i] = *cp++;
     }
-    debugs(49, 7, "addr2oid: Dest : ");
-    snmpDebugOid(7, Dest, size );
-
+    MemBuf tmp;
+    debugs(49, 7, "addr2oid: Dest : " << snmpDebugOid(Dest, size, tmp));
 }
 
 /*
@@ -1150,8 +1152,8 @@ oid2addr(oid * id, IpAddress &addr, u_int size)
     else
         cp = (u_char *) &(i6addr);
 #endif /* USE_IPV6 */
-    debugs(49, 7, "oid2addr: id : ");
-    snmpDebugOid(7, id, size  );
+    MemBuf tmp;
+    debugs(49, 7, "oid2addr: id : " << snmpDebugOid(id, size, tmp) );
     for (i=0 ; i<size; i++) {
         cp[i] = id[i];
     }