📄 hist_m.c
字号:
/* Beholder RMON ethernet network monitor,Copyright (C) 1993 DNPAP group *//* See file COPYING 'GNU General Public Licence' for copyright details */#include <stdio.h>#include <string.h>#include <memory.h>#include <dnpap.h>#include <config.h>#include <maxmem.h>#include <message.h>#include <mac.h>#include <snmp.h>#include <mibrqs.h>#include <mibsup.h>#include <dmath.h>#include "hist_e.h"#include "hist_c.h"#include "hist.h"IMPORT BOOLEAN BeholderStrictRMON;#define CONTROLINDEXSIZE 1#define HISTORYINDEXSIZE 2extern LONG HistoryMaxNrBuckets;static MIB_LOCAL *HistoryControlInstance = NULL; static BOOLEAN RmonNext(SNMP_OBJECT *obj, MIB_LOCAL **local, WORD idlen, WORD indexsize, ETHER_HISTORY **elem);BOOLEAN HistoryMInit(VOID){LONG i, nriface, j, nrcoll, n;CHAR s[81];BOOLEAN v;LONG buckets, interval;MAC_IFACE *iface;LONG histsource[] = {1,3,6,1,2,1,2,2,1,1,1};CHAR histowner[] = "monitorHistory";#define STATUSINDEX 11SNMP_OBJECT histobj[] = { { SNMP_PDU_SET, {1,3,6,1,2,1,16,2,1,1,7,1}, 12, SNMP_INTEGER }, { SNMP_PDU_SET, {1,3,6,1,2,1,16,2,1,1,6,1}, 12, SNMP_DISPLAYSTR }, { SNMP_PDU_SET, {1,3,6,1,2,1,16,2,1,1,2,1}, 12, SNMP_OBJECTID }, { SNMP_PDU_SET, {1,3,6,1,2,1,16,2,1,1,3,1}, 12, SNMP_INTEGER }, { SNMP_PDU_SET, {1,3,6,1,2,1,16,2,1,1,5,1}, 12, SNMP_INTEGER }}; MessageConfig(HISTORY_ERROR, "History"); if (HistoryConfigInit() == FALSE) return FALSE; n = 1; nriface = (LONG)MacIfaceCount(); for (i = 1; i <= nriface; i++) { sprintf(s, "beholder.history.iface.%ld", i); if (ConfigGetBoolean(s, &v) == TRUE) { iface = MacIfaceGet((WORD)i); if (iface != NULL && v == TRUE && (iface->type == MAC_TYPE_ETHERNET_CSMACD || iface->type == MAC_TYPE_88023_CSMACD)) { nrcoll = 2; sprintf(s, "beholder.history.collectors.%ld", i); ConfigGetLong(s, &nrcoll); for (j = 1; j <= nrcoll; j++) { buckets = 50; if (j % 2 == 1) interval = 30; else interval = 1800; sprintf(s, "beholder.history.buckets.%ld.%ld", i, j); ConfigGetLong(s, &buckets); sprintf(s, "beholder.history.interval.%ld.%ld", i, j); ConfigGetLong(s, &interval); histobj[0].Id[STATUSINDEX] = n; histobj[1].Id[STATUSINDEX] = n; histobj[2].Id[STATUSINDEX] = n; histobj[3].Id[STATUSINDEX] = n; histobj[4].Id[STATUSINDEX] = n; histobj[0].Syntax.LngInt = SNMP_INVALID; MibRequest(&histobj[0]); histobj[0].Syntax.LngInt = SNMP_CREATEREQUEST; if (MibRequest(&histobj[0]) != SNMP_NOERROR) { DnpapMessage(DMC_WARNING, HISTORY_HISTINIT, "history: couldn't create history collector %ld (%ld,%ld)", n, i, j); continue; } strncpy(histobj[1].Syntax.BufChr, histowner, histobj[1].SyntaxLen = strlen(histowner)); if (MibRequest(&histobj[1]) != SNMP_NOERROR) { DnpapMessage(DMC_WARNING, HISTORY_HISTINIT, "history: couldn't set owner of history collector %ld (%ld,%ld)", n, i, j); histobj[0].Syntax.LngInt = SNMP_INVALID; MibRequest(&histobj[0]); continue; } memcpy(histobj[2].Syntax.BufInt, histsource, sizeof(histsource)); histobj[2].Syntax.BufInt[sizeof(histsource)/sizeof(histsource[0])-1] = i; histobj[2].SyntaxLen = sizeof(histsource)/sizeof(histsource[0]); if (MibRequest(&histobj[2]) != SNMP_NOERROR) { DnpapMessage(DMC_WARNING, HISTORY_HISTINIT, "history: couldn't set datasource of history collector %ld (%ld,%ld)", n, i, j); histobj[0].Syntax.LngInt = SNMP_INVALID; MibRequest(&histobj[0]); continue; } histobj[3].Syntax.LngInt = buckets; if (MibRequest(&histobj[3]) != SNMP_NOERROR) { DnpapMessage(DMC_WARNING, HISTORY_HISTINIT, "history: couldn't set number of buckets of history collector %ld (%ld,%ld)", n, i, j); histobj[0].Syntax.LngInt = SNMP_INVALID; MibRequest(&histobj[0]); continue; } histobj[4].Syntax.LngInt = interval; if (MibRequest(&histobj[4]) != SNMP_NOERROR) { DnpapMessage(DMC_WARNING, HISTORY_HISTINIT, "history: couldn't set interval of history collector %ld (%ld,%ld)", i, j); histobj[0].Syntax.LngInt = SNMP_INVALID; MibRequest(&histobj[0]); continue; } histobj[0].Syntax.LngInt = SNMP_VALID; if (MibRequest(&histobj[0]) != SNMP_NOERROR) { DnpapMessage(DMC_WARNING, HISTORY_HISTINIT, "history: couldn't set history collector %ld (%ld,%ld) to valid", n, i, j); histobj[0].Syntax.LngInt = SNMP_INVALID; MibRequest(&histobj[0]); continue; } n++; } } } } return TRUE;}BOOLEAN RmonNext(SNMP_OBJECT *obj, MIB_LOCAL **local, WORD idlen, WORD indexsize, ETHER_HISTORY **elem){HISTORY_CONTROL *data;LONG index; if (*local == NULL || indexsize < 1) return FALSE; if (obj->IdLen < idlen + indexsize) { switch (indexsize) { case HISTORYINDEXSIZE: while (*local != NULL && (((HISTORY_CONTROL*)(*local)->Data)->BucketsGranted == 0 || (((HISTORY_CONTROL*)(*local)->Data)->BucketsWrapped == FALSE && ((HISTORY_CONTROL*)(*local)->Data)->BucketsPos == 0))) *local = (*local)->Next; if (*local == NULL) return FALSE; obj->Id[idlen] = (*local)->Index; obj->Id[idlen+1] = ((HISTORY_CONTROL*)(*local)->Data)->BucketsDeleted + 1; obj->IdLen = idlen + HISTORYINDEXSIZE; *elem = EtherHistorySearch((HISTORY_CONTROL*)(*local)->Data, obj, idlen); break; case CONTROLINDEXSIZE: obj->Id[idlen] = (*local)->Index; obj->IdLen = idlen + CONTROLINDEXSIZE; break; } return TRUE; } else { switch (indexsize) { case HISTORYINDEXSIZE: data = (HISTORY_CONTROL*)(*local)->Data; if ((index = obj->Id[idlen+1] - ((HISTORY_CONTROL*)(*local)->Data)->BucketsDeleted) < 1) { while (*local != NULL && (((HISTORY_CONTROL*)(*local)->Data)->BucketsGranted == 0 || (((HISTORY_CONTROL*)(*local)->Data)->BucketsWrapped == FALSE && ((HISTORY_CONTROL*)(*local)->Data)->BucketsPos == 0))) *local = (*local)->Next; if (*local == NULL) return FALSE; obj->Id[idlen] = (*local)->Index; obj->Id[idlen+1] = ((HISTORY_CONTROL*)(*local)->Data)->BucketsDeleted + 1; obj->IdLen = idlen + HISTORYINDEXSIZE; *elem = EtherHistorySearch((HISTORY_CONTROL*)(*local)->Data, obj, idlen); break; } else if ((data->BucketsWrapped == TRUE && index < data->BucketsGranted) || (data->BucketsWrapped == FALSE && index < data->BucketsPos)) { /* BucketsWrapped == FALSE and BucketsPos == 0 if Status != VALID */ obj->Id[idlen] = (*local)->Index; obj->Id[idlen+1]++; obj->IdLen = idlen + HISTORYINDEXSIZE; *elem = EtherHistorySearch((HISTORY_CONTROL*)(*local)->Data, obj, idlen); break; } *local = (*local)->Next; while (*local != NULL && (((HISTORY_CONTROL*)(*local)->Data)->BucketsGranted == 0 || (((HISTORY_CONTROL*)(*local)->Data)->BucketsWrapped == FALSE && ((HISTORY_CONTROL*)(*local)->Data)->BucketsPos == 0))) *local = (*local)->Next; if (*local == NULL) return FALSE; obj->Id[idlen] = (*local)->Index; obj->Id[idlen+1] = ((HISTORY_CONTROL*)(*local)->Data)->BucketsDeleted + 1; obj->IdLen = idlen + HISTORYINDEXSIZE; *elem = EtherHistorySearch((HISTORY_CONTROL*)(*local)->Data, obj, idlen); break; case CONTROLINDEXSIZE: /* only go to next collector if requested index was higher or equal */ if (obj->Id[idlen] >= (*local)->Index) *local = (*local)->Next; if (*local == NULL) return FALSE; obj->Id[idlen] = (*local)->Index; obj->IdLen = idlen + CONTROLINDEXSIZE; break; } return TRUE; } return FALSE;}WORD HistoryControlIndex(SNMP_OBJECT *obj, WORD idlen){MIB_LOCAL *local = NULL; if ((local = MibRmon(obj, HistoryControlInstance, idlen, CONTROLINDEXSIZE)) == NULL) return SNMP_NOSUCHNAME; switch (obj->Request) { case SNMP_PDU_NEXT: if (RmonNext (obj, &local, idlen, CONTROLINDEXSIZE, NULL) == FALSE) return SNMP_NOSUCHNAME; case SNMP_PDU_GET: obj->Syntax.LngInt = local->Index; return SNMP_NOERROR; case SNMP_PDU_SET: return SNMP_READONLY; } return SNMP_GENERROR;}WORD HistoryControlDataSource(SNMP_OBJECT *obj, WORD idlen){MIB_LOCAL *local = NULL;HISTORY_CONTROL *data;MAC_IFACE *iface; if ((local = MibRmon(obj, HistoryControlInstance, idlen, CONTROLINDEXSIZE)) == NULL) return SNMP_NOSUCHNAME; switch (obj->Request) { case SNMP_PDU_NEXT: if (RmonNext(obj, &local, idlen, CONTROLINDEXSIZE, NULL) == FALSE) return SNMP_NOSUCHNAME; case SNMP_PDU_GET: data = (HISTORY_CONTROL*) local->Data; if (BeholderStrictRMON && !BooleanCheck(data->ObjectSet, HISTORY_BOOLEAN_DATASOURCE)) return SNMP_NOSUCHNAME; memcpy(obj->Syntax.BufInt, data->Source, data->SourceLen*sizeof(data->Source[0])); obj->SyntaxLen = data->SourceLen; return SNMP_NOERROR; case SNMP_PDU_SET: data = (HISTORY_CONTROL*) local->Data; if (data->Status != SNMP_UNDERCREATION) return SNMP_READONLY; if (data->SourceLen != obj->SyntaxLen || memcmp(data->Source, obj->Syntax.BufInt, (data->SourceLen-1)*sizeof(data->Source[0])) != 0) return SNMP_BADVALUE; if ((iface = MacIfaceGet((WORD) obj->Syntax.BufInt[obj->SyntaxLen-1])) == NULL) return SNMP_BADVALUE; if (iface->type != MAC_TYPE_ETHERNET_CSMACD && iface->type != MAC_TYPE_88023_CSMACD) return SNMP_BADVALUE; memcpy(data->Source, obj->Syntax.BufInt, obj->SyntaxLen*sizeof(data->Source[0])); data->SourceLen = obj->SyntaxLen; data->Iface = iface; BooleanSetTrue(data->ObjectSet, HISTORY_BOOLEAN_DATASOURCE); return SNMP_NOERROR; } return SNMP_GENERROR;}WORD HistoryControlBucketsRequested(SNMP_OBJECT *obj, WORD idlen)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -