From: kostas <> Date: Wed, 3 Dec 1997 00:59:32 +0000 (+0000) Subject: corrected several snmp problems, including net_db support, spreading snmp code X-Git-Tag: SQUID_3_0_PRE1~4422 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ce75f381f3b4850f7eac14d897abcfe4bc731b14;p=thirdparty%2Fsquid.git corrected several snmp problems, including net_db support, spreading snmp code to the appropriate files so that we don't make some structures global. minor mib corrections. --- diff --git a/include/snmp_impl.h b/include/snmp_impl.h index cd92bf0369..62a26e976b 100644 --- a/include/snmp_impl.h +++ b/include/snmp_impl.h @@ -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 */ diff --git a/src/fqdncache.cc b/src/fqdncache.cc index e19a8c2005..ec88a0387c 100644 --- a/src/fqdncache.cc +++ b/src/fqdncache.cc @@ -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 diff --git a/src/ipcache.cc b/src/ipcache.cc index 6171f3d34c..9674c99c04 100644 --- a/src/ipcache.cc +++ b/src/ipcache.cc @@ -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 diff --git a/src/mib.txt b/src/mib.txt index 6f5da2fa44..a81183fdcc 100644 --- a/src/mib.txt +++ b/src/mib.txt @@ -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 diff --git a/src/net_db.cc b/src/net_db.cc index b9247e57fa..42a239ca79 100644 --- a/src/net_db.cc +++ b/src/net_db.cc @@ -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 diff --git a/src/snmp_agent.cc b/src/snmp_agent.cc index 6c4f5d79a1..d867e3cba3 100644 --- a/src/snmp_agent.cc +++ b/src/snmp_agent.cc @@ -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 { diff --git a/src/squid.h b/src/squid.h index e51fee2727..4c7fda71c2 100644 --- a/src/squid.h +++ b/src/squid.h @@ -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 * @@ -273,7 +273,10 @@ #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 */