]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
corrected several snmp problems, including net_db support, spreading snmp code
authorkostas <>
Wed, 3 Dec 1997 00:59:32 +0000 (00:59 +0000)
committerkostas <>
Wed, 3 Dec 1997 00:59:32 +0000 (00:59 +0000)
to the appropriate files so that we don't make some structures global. minor
mib corrections.

include/snmp_impl.h
src/fqdncache.cc
src/ipcache.cc
src/mib.txt
src/net_db.cc
src/snmp_agent.cc
src/squid.h

index cd92bf03695c34c02b2a95a8c5a78a0b58a7edf1..62a26e976b9029c0ccc5d14e0f76c6a171946e91 100644 (file)
@@ -54,11 +54,11 @@ SOFTWARE.
 #define READ       1
 #define WRITE      0
 
-#define RESERVE1    0
-#define RESERVE2    1
-#define COMMIT      2
-#define ACTION      3
-#define FREE        4
+#define SNM_RESERVE1    0
+#define SNM_RESERVE2    1
+#define SNM_COMMIT      2
+#define SNM_ACTION      3
+#define SNM_FREE        4
 
 #define RONLY  0xAAAA          /* read access for everyone */
 #define RWRITE 0xAABA          /* add write access for community private */
index e19a8c20059bc46b7901f5e772339a722eb6deab..ec88a0387c418252856a81981169eebdae1c5314 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: fqdncache.cc,v 1.72 1997/12/02 03:19:28 wessels Exp $
+ * $Id: fqdncache.cc,v 1.73 1997/12/02 17:59:33 kostas Exp $
  *
  * DEBUG: section 35    FQDN Cache
  * AUTHOR: Harvest Derived
@@ -911,3 +911,78 @@ fqdncache_restart(void)
     fqdncache_low = (long) (((float) MAX_FQDN *
            (float) FQDN_LOW_WATER) / (float) 100);
 }
+
+#ifdef SQUID_SNMP
+u_char *
+var_fqdn_entry(struct variable * vp, oid * name, int *length, int exact, int
+    *var_len,
+    SNMPWM ** write_method)
+{
+    static int current = 0;
+    static long long_return;
+    static char *cp = NULL;
+    static fqdncache_entry *fq;
+    static struct in_addr fqaddr;
+    int i;
+    oid newname[MAX_NAME_LEN];
+    int result;
+    static char snbuf[256];
+
+    debug(49, 3) ("snmp: var_fqdn_entry called with magic=%d \n", vp->magic);
+    debug(49, 3) ("snmp: var_fqdn_entry with (%d,%d)\n", *length, *var_len);
+    sprint_objid(snbuf, name, *length);
+    debug(49, 3) ("snmp: var_fqdn_entry oid: %s\n", snbuf);
+
+    memcpy((char *) newname, (char *) vp->name, (int) vp->namelen * sizeof(oid));
+    newname[vp->namelen] = (oid) 1;
+
+    debug(49, 5) ("snmp var_fqdn_entry: hey, here we are.\n");
+
+    fq = NULL;
+    i = 0;
+    while (fq != NULL) {
+        newname[vp->namelen] = i + 1;
+        result = compare(name, *length, newname, (int) vp->namelen + 1);
+        if ((exact && (result == 0)) || (!exact && (result < 0))) {
+            debug(49, 5) ("snmp var_fqdn_entry: yup, a match.\n");
+            break;
+        }
+        i++;
+        fq = NULL;
+    }
+    if (fq == NULL)
+        return NULL;
+
+    debug(49, 5) ("hey, matched.\n");
+    memcpy((char *) name, (char *) newname, ((int) vp->namelen + 1) * sizeof(oid));    *length = vp->namelen + 1;
+    *write_method = 0;
+    *var_len = sizeof(long);    /* default length */
+    sprint_objid(snbuf, newname, *length);
+    debug(49, 5) ("snmp var_fqdn_entry  request for %s (%d)\n", snbuf, current);
+
+    switch (vp->magic) {
+    case NET_FQDN_ID:
+        long_return = (long) i;
+        return (u_char *) & long_return;
+    case NET_FQDN_NAME:
+        cp = fq->names[0];
+        *var_len = strlen(cp);
+        return (u_char *) cp;
+    case NET_FQDN_IP:
+        safe_inet_addr(fq->name, &fqaddr);
+        long_return = (long) fqaddr.s_addr;
+        return (u_char *) & long_return;
+    case NET_FQDN_LASTREF:
+        long_return = fq->lastref;
+        return (u_char *) & long_return;
+    case NET_FQDN_EXPIRES:
+        long_return = fq->expires;
+        return (u_char *) & long_return;
+    case NET_FQDN_STATE:
+        long_return = fq->status;
+        return (u_char *) & long_return;
+    default:
+        return NULL;
+    }
+}
+#endif
index 6171f3d34c680000fa01dc004a417f7f13478c28..9674c99c0459f0ed111c00168b4706c97913bb75 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ipcache.cc,v 1.149 1997/12/02 03:32:22 wessels Exp $
+ * $Id: ipcache.cc,v 1.150 1997/12/02 17:59:34 kostas Exp $
  *
  * DEBUG: section 14    IP Cache
  * AUTHOR: Harvest Derived
@@ -130,7 +130,7 @@ static struct {
     int release_locked;
 } IpcacheStats;
 
-dlink_list lru_list;
+static dlink_list lru_list;
 
 static int ipcache_testname(void);
 static PF ipcache_dnsHandleRead;
@@ -1067,3 +1067,64 @@ ipcache_restart(void)
     ipcache_low = (long) (((float) Config.ipcache.size *
            (float) Config.ipcache.low) / (float) 100);
 }
+
+#ifdef SQUID_SNMP
+
+u_char *
+var_ipcache_entry(struct variable * vp, oid * name, int *length, int exact, int *var_len,
+    SNMPWM ** write_method)
+{
+    static char snbuf[256], *cp;
+    static long long_return;
+    static int current = 0;
+    oid newname[MAX_NAME_LEN];
+    int result;
+    dlink_node *m = NULL;
+    ipcache_entry *IPc;
+       int cnt=1;
+
+    debug(49, 3) ("snmp: var_ipcache_entry called with magic=%d\n", vp->magic);
+    debug(49, 3) ("snmp: var_ipcache_entry with (%d,%d)\n", *length, *var_len);
+    sprint_objid(snbuf, name, *length);
+    debug(49, 3) ("snmp: var_ipcache_entry oid: %s\n", snbuf);
+
+    memcpy((char *) newname, (char *) vp->name, (int) vp->namelen * sizeof(oid));
+    newname[vp->namelen] = (oid) 1;
+
+    debug(49, 5) ("snmp var_ipcache_entry: hey, here we are.\n");
+
+
+        for (m = lru_list.head; m; m = m->next, cnt++) {
+        newname[vp->namelen] = cnt;
+        result = compare(name, *length, newname, (int) vp->namelen + 1);
+        if ((exact && (result == 0)) || (!exact && (result < 0))) {
+            debug(49, 5) ("snmp var_ipcache_entry: yup, a match.\n");
+            break;
+         }
+       }
+       
+    if (m == NULL)
+        return NULL;
+    if ((IPc = m->data) == NULL)
+        return NULL;
+
+    current++;
+    switch (vp->magic) {
+    case NET_IPC_ID:
+        long_return = (int) cnt;
+        return (u_char *) & long_return;
+    case NET_IPC_NAME:
+        cp = IPc->name;
+        *var_len = strlen(cp);
+        return (u_char *) cp;
+    case NET_IPC_IP:
+        long_return = IPc->addrs.in_addrs[0].s_addr;    /* first one only */
+        return (u_char *) & long_return;
+    case NET_IPC_STATE:
+        long_return = IPc->status;
+        return (u_char *) & long_return;
+    default:
+        return NULL;
+    }
+}
+#endif
index 6f5da2fa441bbafb1e7fbf2a5f0ea947fcd1e5f0..a81183fdcc2172962d503b2d18179d79ca2180a7 100644 (file)
@@ -295,10 +295,11 @@ squid             OBJECT IDENTIFIER ::= { nsfnet 17 }
                 STATUS current
                 DESCRIPTION
                         " An entry in the NetDb" 
-                INDEX   { netDbEntryNetwork }
+                INDEX   { netDbEntryId }
                 ::= { NetDbTable 1 } 
 
        NetDbEntry ::= SEQUENCE {
+               NetDbEntryId            Integer,
                NetDbEntryNetwork       IpAddress,
                NetDbEntryPingsSent     Counter32,
                NetDbEntryPingsRecv     Counter32, 
@@ -307,48 +308,54 @@ squid             OBJECT IDENTIFIER ::= { nsfnet 17 }
                NetDbEntryPingTime      TimeTicks,
                NetDbEntryLastUse       TimeTicks,
        }
+
+       NetDbEntryId OBJECT-TYPE
+                SYNTAX Integer
+                ACCESS read-only
+                STATUS current
+        ::= { netDbEntry 1 }
        
        NetDbEntryNetwork OBJECT-TYPE
                 SYNTAX IpAddress
                 ACCESS read-only
                 STATUS current
-       ::= { netDbEntry 1 }
+       ::= { netDbEntry 2 }
 
        NetDbEntryPingsSent OBJECT-TYPE
                 SYNTAX Counter32
                 ACCESS read-only
                 STATUS current
-        ::= { netDbEntry 2 }    
+        ::= { netDbEntry 3 }    
 
        NetDbEntryPingsRecv OBJECT-TYPE 
                 SYNTAX Counter32        
                 ACCESS read-only        
                 STATUS current  
-        ::= { netDbEntry 3 }            
+        ::= { netDbEntry 4 }            
 
        NetDbEntryHops OBJECT-TYPE
                 SYNTAX Integer                
                 ACCESS read-only                
                 STATUS current          
-        ::= { netDbEntry 4 }                    
+        ::= { netDbEntry 5 }                    
 
         NetDbEntryRtt OBJECT-TYPE      
                 SYNTAX TimeTicks
                 ACCESS read-only
                 STATUS current
-        ::= { netDbEntry 5 }
+        ::= { netDbEntry 6 }
 
        NetDbEntryPingTime OBJECT-TYPE
                 SYNTAX TimeTicks
                 ACCESS read-only
                 STATUS current
-        ::= { netDbEntry 6 }
+        ::= { netDbEntry 7 }
 
        NetDbEntryLastUse OBJECT-TYPE
                 SYNTAX TimeTicks
                 ACCESS read-only
                 STATUS current
-        ::= { netDbEntry 7 }
+        ::= { netDbEntry 8 }
 
        
        -- IP cache info
index b9247e57fae292b5bdb9e49e1f2145467ecbbab0..42a239ca79279e43779d205126799ffb85e810bb 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: net_db.cc,v 1.52 1997/12/01 22:45:53 wessels Exp $
+ * $Id: net_db.cc,v 1.53 1997/12/02 17:59:35 kostas Exp $
  *
  * DEBUG: section 37    Network Measurement Database
  * AUTHOR: Duane Wessels
@@ -33,7 +33,7 @@
 
 
 #if USE_ICMP
-hash_table *addr_table = NULL;
+static hash_table *addr_table = NULL;
 static hash_table *host_table = NULL;
 
 static struct in_addr networkFromInaddr(struct in_addr a);
@@ -113,13 +113,13 @@ netdbLookupHost(const char *key)
     return hptr ? (netdbEntry *) hptr->item : NULL;
 }
 
-netdbEntry *
+static netdbEntry *
 netdbGetFirst(hash_table * table)
 {
     return (netdbEntry *) hash_first(table);
 }
 
-netdbEntry *
+static netdbEntry *
 netdbGetNext(hash_table * table)
 {
     return (netdbEntry *) hash_next(table);
@@ -663,3 +663,77 @@ netdbUpdatePeer(request_t * r, peer * e, int irtt, int ihops)
        sortPeerByRtt);
 #endif
 }
+
+#ifdef SQUID_SNMP
+u_char *
+var_netdb_entry(struct variable * vp, oid * name, int *length, int exact, int *var_len, SNMPWM ** write_method)
+{
+    oid newname[MAX_NAME_LEN];
+    static char snbuf[256];
+    static netdbEntry *n = NULL;
+    static long long_return;
+       int cnt=1;
+
+    debug(49, 3) ("snmp: var_netdb_entry called with magic=%d\n", vp->magic);
+    debug(49, 3) ("snmp: var_netdb_entry with (%d,%d)\n", *length, *var_len);
+    sprint_objid(snbuf, name, *length);
+    debug(49, 3) ("snmp: var_netdb_entry oid: %s\n", snbuf);
+
+    memcpy((char *) newname, (char *) vp->name, (int) vp->namelen * sizeof(oid));
+    newname[vp->namelen] = (oid) 1;
+
+    debug(49, 5) ("snmp var_netdb_entry: hey, here we are.\n");
+#ifdef USE_ICMP
+    n=netdbGetFirst(addr_table);
+
+    while (n != NULL) {
+        newname[vp->namelen] = cnt++;
+        result = compare(name, *length, newname, (int) vp->namelen + 1);
+        if ((exact && (result == 0)) || (!exact && (result < 0))) {
+            debug(49, 5) ("snmp var_netdb_entry: yup, a match.\n");
+            break;
+        }
+        n=netdbGetNext(addr_table);
+    }
+#endif
+    if (n == NULL)
+        return NULL;
+
+    debug(49, 5) ("hey, matched.\n");
+    memcpy((char *) name, (char *) newname, ((int) vp->namelen + 1) * sizeof(oid));
+    *length = vp->namelen + 1;
+    *write_method = 0;
+    *var_len = sizeof(long);    /* default length */
+    sprint_objid(snbuf, newname, *length);
+    debug(49, 5) ("snmp var_netdb_entry with peertable request for %s (%d)\n", snbuf, newname[10]);
+
+    switch (vp->magic) {
+    case NETDB_ID:
+       long_return= (long) cnt-1;
+       return (u_char *) & long_return;
+    case NETDB_NET:
+        long_return = (long) n->network;
+        return (u_char *) & long_return;
+    case NETDB_PING_S:
+        long_return = (long) n->pings_sent;
+        return (u_char *) & long_return;
+    case NETDB_PING_R:
+        long_return = (long) n->pings_recv;
+        return (u_char *) & long_return;
+    case NETDB_HOPS:
+        long_return = (long) n->hops;
+        return (u_char *) & long_return;
+    case NETDB_RTT:
+        long_return = (long) n->rtt;
+        return (u_char *) & long_return;
+    case NETDB_PINGTIME:
+        long_return = (long) n->next_ping_time;
+        return (u_char *) & long_return;
+    case NETDB_LASTUSE:
+        long_return = (long) n->last_use_time;
+        return (u_char *) & long_return;
+    default:
+        return NULL;
+    }
+}
+#endif
index 6c4f5d79a1a07073706b6341e396da42d6f9622e..d867e3cba384812d9c664471b39c7526adaad8df 100644 (file)
@@ -307,7 +307,7 @@ snmp_agent_parse(sn_data, length, out_sn_data, out_length, sourceip, ireqid)
            errstat, errindex, &errindex);
     else
        errstat = parse_var_op_list(sn_data, length, out_sn_data, *out_length,
-           &errindex, msgtype, RESERVE1);
+           &errindex, msgtype, SNM_RESERVE1);
 
     if (errstat == SNMP_ERR_NOSUCHNAME) {
        /* see if we have forwarding turned on */
@@ -319,7 +319,7 @@ snmp_agent_parse(sn_data, length, out_sn_data, out_length, sourceip, ireqid)
     if (msgtype == SET_REQ_MSG) {
        if (errstat == SNMP_ERR_NOERROR)
            errstat = parse_var_op_list(sn_data, length, out_sn_data, *out_length,
-               &errindex, msgtype, RESERVE2);
+               &errindex, msgtype, SNM_RESERVE2);
        if (errstat == SNMP_ERR_NOERROR) {
            /*
             * SETS require 3-4 passes through the var_op_list.  The first two
@@ -331,9 +331,9 @@ snmp_agent_parse(sn_data, length, out_sn_data, out_length, sourceip, ireqid)
             * pass is made so that any reserved resources can be freed.
             */
            parse_var_op_list(sn_data, length, out_sn_data, *out_length,
-               &dummyindex, msgtype, COMMIT);
+               &dummyindex, msgtype, SNM_COMMIT);
            parse_var_op_list(sn_data, length, out_sn_data, *out_length,
-               &dummyindex, msgtype, ACTION);
+               &dummyindex, msgtype, SNM_ACTION);
            if (create_identical(startData, out_auth, startLength, 0L, 0L)) {
                *out_length = packet_end - out_auth;
                return 1;
@@ -342,7 +342,7 @@ snmp_agent_parse(sn_data, length, out_sn_data, out_length, sourceip, ireqid)
            return 0;
        } else {
            parse_var_op_list(sn_data, length, out_sn_data, *out_length,
-               &dummyindex, msgtype, FREE);
+               &dummyindex, msgtype, SNM_FREE);
        }
     }
     switch ((short) errstat) {
@@ -514,7 +514,7 @@ parse_var_op_list(sn_data, length, out_sn_data, out_length, index, msgtype, acti
                        }
                    }
                    /* actually do the set if necessary */
-                   if (action == COMMIT)
+                   if (action == SNM_COMMIT)
                        setVariable(var_val, var_val_type, var_val_len,
                            statP, statLen);
                } else {
index e51fee272753c1b3057e5a53eac3cc74ac1249ed..4c7fda71c265e61005bf27e5803d209b3479842b 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: squid.h,v 1.140 1997/12/02 05:06:43 wessels Exp $
+ * $Id: squid.h,v 1.141 1997/12/02 17:59:37 kostas Exp $
  *
  * AUTHOR: Duane Wessels
  *
 
 #ifdef SQUID_SNMP
 #include "snmp.h"
+#include "snmp_impl.h"
+#include "snmp_vars.h"
 #include "snmp_config.h"
+#include "cache_snmp.h"
 #endif
 
 /* Needed for poll() on Linux at least */