📄 lookupctltable.c
字号:
/* *Copyright(c)2004,Cisco URP imburses and Network Information Center in Beijing University of Posts and Telecommunications researches. * *All right reserved * *File Name:lookupCtlTable.c *File Description:Rows of the lookupCtlTable MIB add , delete and read.Rows of lookupResultsTable * MIB add and delete. * *Current Version:1.0 *Author:ChenJing *Date:2004.8.20 *//* * This should always be included first before anything else */#if HAVE_STDLIB_H#include <stdlib.h>#endif#if HAVE_STRING_H#include <string.h>#else#include <strings.h>#endif#ifdef HAVE_LIMITS_H#include <limits.h>#endif#include <netdb.h>#include <netinet/in.h>#include <sys/types.h>#include <sys/socket.h>#include <arpa/inet.h>#include <net-snmp/net-snmp-config.h>#include <net-snmp/net-snmp-includes.h>#include <net-snmp/agent/net-snmp-agent-includes.h>#include "lookupCtlTable.h"#include "lookupResultsTable.h"#include "header_complex.h"/* *For discontinuity checking. */oid lookupCtlTable_variables_oid[] = { 1, 3, 6, 1, 2, 1, 82, 1, 3 };struct variable2 lookupCtlTable_variables[] = { /* * magic number , variable type , ro/rw , callback fn , L, oidsuffix */ {COLUMN_LOOKUPCTLTARGETADDRESSTYPE, ASN_INTEGER, RWRITE, var_lookupCtlTable, 2, {1, 3}}, {COLUMN_LOOKUPCTLTARGETADDRESS, ASN_OCTET_STR, RWRITE, var_lookupCtlTable, 2, {1, 4}}, {COLUMN_LOOKUPCTLOPERSTATUS, ASN_INTEGER, RONLY, var_lookupCtlTable, 2, {1, 5}}, {COLUMN_LOOKUPCTLTIME, ASN_UNSIGNED, RONLY, var_lookupCtlTable, 2, {1, 6}}, {COLUMN_LOOKUPCTLRC, ASN_INTEGER, RONLY, var_lookupCtlTable, 2, {1, 7}}, {COLUMN_LOOKUPCTLROWSTATUS, ASN_INTEGER, RWRITE, var_lookupCtlTable, 2, {1, 8}}};/* * global storage of our data, saved in and configured by header_complex() */struct header_complex_index *lookupCtlTableStorage = NULL;struct header_complex_index *lookupResultsTableStorage = NULL;voidinit_lookupCtlTable(void){ DEBUGMSGTL(("lookupCtlTable", "initializing... ")); /* * register ourselves with the agent to handle our mib tree */ REGISTER_MIB("lookupCtlTable", lookupCtlTable_variables, variable2, lookupCtlTable_variables_oid); /* * register our config handler(s) to deal with registrations */ snmpd_register_config_handler("lookupCtlTable", parse_lookupCtlTable, NULL, NULL); /* * we need to be called back later to store our data */ snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA, store_lookupCtlTable, NULL); DEBUGMSGTL(("lookupCtlTable", "done.\n"));}struct lookupTable_data *create_lookupTable_data(void){ struct lookupTable_data *StorageNew = NULL; StorageNew = SNMP_MALLOC_STRUCT(lookupTable_data); if (StorageNew == NULL) { exit(1); } StorageNew->lookupCtlTargetAddress = strdup(""); StorageNew->lookupCtlTargetAddressLen = 0; StorageNew->lookupCtlOperStatus = 2l; StorageNew->lookupCtlTime = 0; StorageNew->storagetype = ST_NONVOLATILE; return StorageNew;}/* * lookupCtlTable_add(): adds a structure node to our data set */intlookupCtlTable_add(struct lookupTable_data *thedata){ netsnmp_variable_list *vars = NULL; DEBUGMSGTL(("lookupCtlTable", "adding data... ")); /* * add the index variables to the varbind list, which is * used by header_complex to index the data */ snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->lookupCtlOwnerIndex, thedata->lookupCtlOwnerIndexLen); /* lookupCtlOwnerIndex */ snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->lookupCtlOperationName, thedata->lookupCtlOperationNameLen); /* lookupCtlOperationName */ if (header_complex_add_data(&lookupCtlTableStorage, vars, thedata) == NULL) { return SNMPERR_GENERR; } DEBUGMSGTL(("lookupCtlTable", "registered an entry\n")); vars = NULL; DEBUGMSGTL(("lookupCtlTable", "done.\n")); return SNMPERR_SUCCESS;}intlookupResultsTable_add(struct lookupTable_data *thedata){ netsnmp_variable_list *vars_list = NULL; struct lookupResultsTable_data *p = NULL; p = thedata->ResultsTable; if (thedata->ResultsTable != NULL) do { snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_OCTET_STR, (char *) p->lookupCtlOwnerIndex, p->lookupCtlOwnerIndexLen); /* lookupCtlOwnerIndex */ snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_OCTET_STR, (char *) p->lookupCtlOperationName, p->lookupCtlOperationNameLen); /* lookupCtlOperationName */ snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_UNSIGNED, (char *) &p->lookupResultsIndex, sizeof(p->lookupResultsIndex)); /* lookupResultsIndex */ DEBUGMSGTL(("lookupResultsTable", "adding data... ")); /* * add the index variables to the varbind list, which is * used by header_complex to index the data */ if (header_complex_add_data (&lookupResultsTableStorage, vars_list, p) == NULL) { return SNMPERR_GENERR; } DEBUGMSGTL(("lookupResultsTable", "out finished\n")); vars_list = NULL; p = p->next; } while (p != NULL); DEBUGMSGTL(("lookupResultsTable", "done.\n"));}voidlookupCtlTable_cleaner(struct header_complex_index *thestuff){ struct header_complex_index *hciptr = NULL; struct lookupTable_data *StorageDel = NULL; DEBUGMSGTL(("lookupCtlTable", "cleanerout ")); for (hciptr = thestuff; hciptr != NULL; hciptr = hciptr->next) { StorageDel = header_complex_extract_entry(&lookupCtlTableStorage, hciptr); if (StorageDel != NULL) { free(StorageDel->lookupCtlOwnerIndex); StorageDel->lookupCtlOwnerIndex = NULL; free(StorageDel->lookupCtlOperationName); StorageDel->lookupCtlOperationName = NULL; free(StorageDel->lookupCtlTargetAddress); StorageDel->lookupCtlTargetAddress = NULL; free(StorageDel); StorageDel = NULL; } DEBUGMSGTL(("lookupCtlTable", "cleaner ")); }}/* * parse_lookupCtlTable(): * parses .conf file entries needed to configure the mib. */voidparse_lookupCtlTable(const char *token, char *line){ size_t tmpint; struct lookupTable_data *StorageTmp = SNMP_MALLOC_STRUCT(lookupTable_data); DEBUGMSGTL(("lookupCtlTable", "parsing config... ")); if (StorageTmp == NULL) { config_perror("malloc failure"); return; } line = read_config_read_data(ASN_OCTET_STR, line, &StorageTmp->lookupCtlOwnerIndex, &StorageTmp->lookupCtlOwnerIndexLen); if (StorageTmp->lookupCtlOwnerIndex == NULL) { config_perror("invalid specification for lookupCtlOwnerIndex"); return; } line = read_config_read_data(ASN_OCTET_STR, line, &StorageTmp->lookupCtlOperationName, &StorageTmp->lookupCtlOperationNameLen); if (StorageTmp->lookupCtlOperationName == NULL) { config_perror("invalid specification for lookupCtlOperationName"); return; } line = read_config_read_data(ASN_INTEGER, line, &StorageTmp->lookupCtlTargetAddressType, &tmpint); line = read_config_read_data(ASN_OCTET_STR, line, &StorageTmp->lookupCtlTargetAddress, &StorageTmp->lookupCtlTargetAddressLen); if (StorageTmp->lookupCtlTargetAddress == NULL) { config_perror("invalid specification for lookupCtlTargetAddress"); return; } line = read_config_read_data(ASN_INTEGER, line, &StorageTmp->lookupCtlOperStatus, &tmpint); line = read_config_read_data(ASN_UNSIGNED, line, &StorageTmp->lookupCtlTime, &tmpint); line = read_config_read_data(ASN_INTEGER, line, &StorageTmp->lookupCtlRc, &tmpint); line = read_config_read_data(ASN_INTEGER, line, &StorageTmp->lookupCtlRowStatus, &tmpint); StorageTmp->storagetype = ST_NONVOLATILE; lookupCtlTable_add(StorageTmp); /* lookupCtlTable_cleaner(lookupCtlTableStorage); */ DEBUGMSGTL(("lookupCtlTable", "done.\n"));}/* * store_lookupCtlTable(): * stores .conf file entries needed to configure the mib. */intstore_lookupCtlTable(int majorID, int minorID, void *serverarg, void *clientarg){ char line[SNMP_MAXBUF]; char *cptr; size_t tmpint; struct lookupTable_data *StorageTmp; struct header_complex_index *hcindex; DEBUGMSGTL(("lookupCtlTable", "storing data... ")); for (hcindex = lookupCtlTableStorage; hcindex != NULL; hcindex = hcindex->next) { StorageTmp = (struct lookupTable_data *) hcindex->data; if (StorageTmp->storagetype != ST_READONLY) { memset(line, 0, sizeof(line)); strcat(line, "lookupCtlTable "); cptr = line + strlen(line); cptr = read_config_store_data(ASN_OCTET_STR, cptr, &StorageTmp->lookupCtlOwnerIndex, &StorageTmp-> lookupCtlOwnerIndexLen); cptr = read_config_store_data(ASN_OCTET_STR, cptr, &StorageTmp->lookupCtlOperationName, &StorageTmp-> lookupCtlOperationNameLen); cptr = read_config_store_data(ASN_INTEGER, cptr, &StorageTmp-> lookupCtlTargetAddressType, &tmpint); cptr = read_config_store_data(ASN_OCTET_STR, cptr, &StorageTmp->lookupCtlTargetAddress, &StorageTmp-> lookupCtlTargetAddressLen); cptr = read_config_store_data(ASN_INTEGER, cptr, &StorageTmp->lookupCtlOperStatus, &tmpint); cptr = read_config_store_data(ASN_UNSIGNED, cptr, &StorageTmp->lookupCtlTime, &tmpint); cptr = read_config_store_data(ASN_INTEGER, cptr, &StorageTmp->lookupCtlRc, &tmpint); cptr = read_config_store_data(ASN_INTEGER, cptr, &StorageTmp->lookupCtlRowStatus, &tmpint); snmpd_store_config(line); } } DEBUGMSGTL(("lookupCtlTable", "done.\n")); return SNMPERR_SUCCESS;}/* * var_lookupCtlTable(): * Handle this table separately from the scalar value case. * The workings of this are basically the same as for var_mteObjectsTable above. */unsigned char *var_lookupCtlTable(struct variable *vp, oid * name, size_t *length, int exact, size_t *var_len, WriteMethod ** write_method){ struct lookupTable_data *StorageTmp = NULL; /* * this assumes you have registered all your data properly */ if ((StorageTmp = header_complex(lookupCtlTableStorage, vp, name, length, exact, var_len, write_method)) == NULL) { if (vp->magic == COLUMN_LOOKUPCTLROWSTATUS) *write_method = write_lookupCtlRowStatus; return NULL; } /* * this is where we do the value assignments for the mib results. */ switch (vp->magic) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -