pingCtlTable.c
上传用户:wxp200602
上传日期:2007-10-30
资源大小:4028k
文件大小:183k
- /*
- *Copyright(c)2004,Cisco URP imburses and Network Information Center in Beijing University of Posts and Telecommunications researches.
- *
- *All right reserved
- *
- *File Name:pingCtlTable.c
- *File Description:Rows of the pingCtlTable MIB add , delete and read.Rows of lookupResultsTable
- * MIB add and delete.Rows of pingProbeHistoryTable MIB add and delete.
- * The main function is also here.
- *
- *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 "pingCtlTable.h"
- #include "pingResultsTable.h"
- #include "pingProbeHistoryTable.h"
- #include "header_complex.h"
- /*
- *pingCtlTable_variables_oid:
- *
- */
- oid pingCtlTable_variables_oid[] =
- { 1, 3, 6, 1, 2, 1, 80, 1, 2 };
- /* trap */
- oid pingProbeFailed[] = { 1, 3, 6, 1, 2, 1, 80, 0, 1 };
- oid pingTestFailed[] = { 1, 3, 6, 1, 2, 1, 80, 0, 2 };
- oid pingTestCompleted[] = { 1, 3, 6, 1, 2, 1, 80, 0, 3 };
- struct variable2 pingCtlTable_variables[] = {
- /*
- * magic number , variable type , ro/rw , callback fn , L, oidsuffix
- */
- {COLUMN_PINGCTLTARGETADDRESSTYPE, ASN_INTEGER, RWRITE, var_pingCtlTable, 2, {1, 3}},
- {COLUMN_PINGCTLTARGETADDRESS, ASN_OCTET_STR, RWRITE, var_pingCtlTable, 2, {1, 4}},
- {COLUMN_PINGCTLDATASIZE, ASN_UNSIGNED, RONLY, var_pingCtlTable, 2, {1, 5}},
- {COLUMN_PINGCTLTIMEOUT, ASN_UNSIGNED, RONLY, var_pingCtlTable, 2, {1, 6}},
- {COLUMN_PINGCTLPROBECOUNT, ASN_UNSIGNED, RONLY, var_pingCtlTable, 2, {1, 7}},
- {COLUMN_PINGCTLADMINSTATUS, ASN_INTEGER, RWRITE, var_pingCtlTable, 2, {1, 8}},
- {COLUMN_PINGCTLDATAFILL, ASN_OCTET_STR, RWRITE, var_pingCtlTable, 2, {1, 9}},
- {COLUMN_PINGCTLFREQUENCY, ASN_UNSIGNED, RWRITE, var_pingCtlTable, 2, {1, 10}},
- {COLUMN_PINGCTLMAXROWS, ASN_UNSIGNED, RWRITE, var_pingCtlTable, 2, {1, 11}},
- {COLUMN_PINGCTLSTORAGETYPE, ASN_INTEGER, RWRITE, var_pingCtlTable, 2, {1, 12}},
- {COLUMN_PINGCTLTRAPGENERATION, ASN_OCTET_STR, RWRITE, var_pingCtlTable, 2, {1, 13}},
- {COLUMN_PINGCTLTRAPPROBEFAILUREFILTER, ASN_UNSIGNED, RWRITE, var_pingCtlTable, 2, {1, 14}},
- {COLUMN_PINGCTLTRAPTESTFAILUREFILTER, ASN_UNSIGNED, RWRITE, var_pingCtlTable, 2, {1, 15}},
- {COLUMN_PINGCTLTYPE, ASN_OBJECT_ID, RWRITE, var_pingCtlTable, 2, {1, 16}},
- {COLUMN_PINGCTLDESCR, ASN_OCTET_STR, RWRITE, var_pingCtlTable, 2, {1, 17}},
- {COLUMN_PINGCTLSOURCEADDRESSTYPE, ASN_INTEGER, RWRITE, var_pingCtlTable, 2, {1, 18}},
- {COLUMN_PINGCTLSOURCEADDRESS, ASN_OCTET_STR, RWRITE, var_pingCtlTable, 2, {1, 19}},
- {COLUMN_PINGCTLIFINDEX, ASN_INTEGER, RWRITE, var_pingCtlTable, 2, {1, 20}},
- {COLUMN_PINGCTLBYPASSROUTETABLE, ASN_INTEGER, RWRITE, var_pingCtlTable, 2, {1, 21}},
- {COLUMN_PINGCTLDSFIELD, ASN_UNSIGNED, RWRITE, var_pingCtlTable, 2, {1, 22}},
- {COLUMN_PINGCTLROWSTATUS, ASN_INTEGER, RWRITE, var_pingCtlTable, 2, {1, 23}}
- };
- /*
- * global storage of our data, saved in and configured by header_complex()
- */
- struct header_complex_index *pingCtlTableStorage = NULL;
- struct header_complex_index *pingResultsTableStorage = NULL;
- struct header_complex_index *pingProbeHistoryTableStorage = NULL;
- void
- init_pingCtlTable(void)
- {
- DEBUGMSGTL(("pingCtlTable", "initializing... "));
- /*
- * register ourselves with the agent to handle our mib tree
- */
- REGISTER_MIB("pingCtlTable", pingCtlTable_variables, variable2,
- pingCtlTable_variables_oid);
- /*
- * register our config handler(s) to deal with registrations
- */
- snmpd_register_config_handler("pingCtlTable", parse_pingCtlTable,
- NULL, NULL);
- /*
- * we need to be called back later to store our data
- */
- snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
- store_pingCtlTable, NULL);
- DEBUGMSGTL(("pingCtlTable", "done.n"));
- }
- struct pingCtlTable_data *
- create_pingCtlTable_data(void)
- {
- struct pingCtlTable_data *StorageNew = NULL;
- StorageNew = SNMP_MALLOC_STRUCT(pingCtlTable_data);
- if (StorageNew == NULL) {
- exit(1);
- }
- StorageNew->pingCtlTargetAddressType = 1;
- StorageNew->pingCtlTargetAddress = strdup("");
- StorageNew->pingCtlTargetAddressLen = 0;
- StorageNew->pingCtlDataSize = 0;
- StorageNew->pingCtlTimeOut = 3;
- StorageNew->pingCtlProbeCount = 1;
- StorageNew->pingCtlAdminStatus = 2;
- StorageNew->pingCtlDataFill = (char *) malloc(strlen("00") + 1);
- if (StorageNew->pingCtlDataFill == NULL) {
- exit(1);
- }
- memcpy(StorageNew->pingCtlDataFill, "00", strlen("00") + 1);
- StorageNew->pingCtlDataFill[strlen("00")] = ' ';
- StorageNew->pingCtlDataFillLen = strlen(StorageNew->pingCtlDataFill);
- StorageNew->pingCtlFrequency = 0;
- StorageNew->pingCtlMaxRows = 50;
- StorageNew->pingCtlStorageType = 1;
- StorageNew->pingCtlTrapGeneration = strdup("");
- StorageNew->pingCtlTrapGenerationLen = 0;
- StorageNew->pingCtlTrapGenerationLen = 0;
- StorageNew->pingCtlTrapProbeFailureFilter = 1;
- StorageNew->pingCtlTrapTestFailureFilter = 1;
- StorageNew->pingCtlType = calloc(1, sizeof(oid) * sizeof(2)); /* 0.0 */
- StorageNew->pingCtlTypeLen = 2;
- StorageNew->pingCtlDescr = strdup("");
- StorageNew->pingCtlDescrLen = 0;
- StorageNew->pingCtlSourceAddressType = 1;
- StorageNew->pingCtlSourceAddress = strdup("");
- StorageNew->pingCtlSourceAddressLen = 0;
- StorageNew->pingCtlIfIndex = 0;
- StorageNew->pingCtlByPassRouteTable = 2;
- StorageNew->pingCtlDSField = 0;
- StorageNew->pingResults = NULL;
- StorageNew->pingProbeHis = NULL;
- StorageNew->storageType = ST_NONVOLATILE;
- StorageNew->pingProbeHistoryMaxIndex = 0;
- return StorageNew;
- }
- /*
- * pingCtlTable_add(): adds a structure node to our data set
- */
- int
- pingCtlTable_add(struct pingCtlTable_data *thedata)
- {
- netsnmp_variable_list *vars = NULL;
- DEBUGMSGTL(("pingCtlTable", "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->pingCtlOwnerIndex, thedata->pingCtlOwnerIndexLen); /* pingCtlOwnerIndex */
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->pingCtlTestName, thedata->pingCtlTestNameLen); /* pingCtlOperationName */
- header_complex_add_data(&pingCtlTableStorage, vars, thedata);
- DEBUGMSGTL(("pingCtlTable", "registered an entryn"));
- vars = NULL;
- DEBUGMSGTL(("pingCtlTable", "done.n"));
- return SNMPERR_SUCCESS;
- }
- int
- pingResultsTable_add(struct pingCtlTable_data *thedata)
- {
- netsnmp_variable_list *vars_list = NULL;
- struct pingResultsTable_data *p = NULL;
- p = thedata->pingResults;
- if (thedata->pingResults != NULL) {
- snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_OCTET_STR, (char *) p->pingCtlOwnerIndex, p->pingCtlOwnerIndexLen); /* pingCtlOwnerIndex */
- snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_OCTET_STR, (char *) p->pingCtlTestName, p->pingCtlTestNameLen); /* pingCtlOperationName */
- /*
- * XXX: fill in default row values here into StorageNew
- *
- */
- DEBUGMSGTL(("pingResultsTable", "adding data... "));
- /*
- * add the index variables to the varbind list, which is
- * used by header_complex to index the data
- */
- header_complex_add_data(&pingResultsTableStorage, vars_list, p);
- DEBUGMSGTL(("pingResultsTable", "out finishedn"));
- }
- DEBUGMSGTL(("pingResultsTable", "done.n"));
- vars_list = NULL;
- return SNMPERR_SUCCESS;
- }
- int
- pingProbeHistoryTable_add(struct pingProbeHistoryTable_data *thedata)
- {
- netsnmp_variable_list *vars_list;
- vars_list = NULL;
- if (thedata != NULL) {
- snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_OCTET_STR, (char *) thedata->pingCtlOwnerIndex, thedata->pingCtlOwnerIndexLen); /* pingCtlOwnerIndex */
- snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_OCTET_STR, (char *) thedata->pingCtlTestName, thedata->pingCtlTestNameLen); /* pingCtlTestName */
- snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_UNSIGNED, (char *) &thedata->pingProbeHistoryIndex, sizeof(thedata->pingProbeHistoryIndex)); /* pingProbeHistoryIndex */
- /*
- * XXX: fill in default row values here into StorageNew
- *
- */
- DEBUGMSGTL(("pingProbeHistoryTable", "adding data... "));
- /*
- * add the index variables to the varbind list, which is
- * used by header_complex to index the data
- */
- header_complex_add_data(&pingProbeHistoryTableStorage, vars_list,
- thedata);
- DEBUGMSGTL(("pingProbeHistoryTable", "out finishedn"));
- }
-
- vars_list = NULL;
- DEBUGMSGTL(("pingProbeHistoryTable", "done.n"));
- return SNMPERR_SUCCESS;
- }
- int
- pingProbeHistoryTable_addall(struct pingCtlTable_data *thedata)
- {
- netsnmp_variable_list *vars_list = NULL;
- struct pingProbeHistoryTable_data *p = NULL;
- p = thedata->pingProbeHis;
- if (thedata->pingProbeHis != NULL)
- do {
- snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_OCTET_STR, (char *) p->pingCtlOwnerIndex, p->pingCtlOwnerIndexLen); /* pingCtlOwnerIndex */
- snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_OCTET_STR, (char *) p->pingCtlTestName, p->pingCtlTestNameLen); /* pingCtlTestName */
- snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_UNSIGNED, (char *) &p->pingProbeHistoryIndex, sizeof(p->pingProbeHistoryIndex)); /* pingProbeHistoryIndex */
- /*
- * XXX: fill in default row values here into StorageNew
- *
- */
- DEBUGMSGTL(("pingProbeHistoryTable", "adding data... "));
- /*
- * add the index variables to the varbind list, which is
- * used by header_complex to index the data
- */
- header_complex_add_data(&pingProbeHistoryTableStorage,
- vars_list, p);
- DEBUGMSGTL(("pingProbeHistoryTable", "out finishedn"));
- vars_list = NULL;
- p = p->next;
- } while (p != NULL);
- DEBUGMSGTL(("pingProbeHistoryTable", "done.n"));
- return SNMPERR_SUCCESS;
- }
- void
- pingCtlTable_cleaner(struct header_complex_index *thestuff)
- {
- struct header_complex_index *hciptr = NULL;
- struct pingCtlTable_data *StorageDel = NULL;
- DEBUGMSGTL(("pingProbeHistoryTable", "cleanerout "));
- for (hciptr = thestuff; hciptr != NULL; hciptr = hciptr->next) {
- StorageDel =
- header_complex_extract_entry(&pingCtlTableStorage, hciptr);
- DEBUGMSGTL(("pingProbeHistoryTable", "cleaner "));
- }
- }
- /*
- * parse_mteObjectsTable():
- * parses .conf file entries needed to configure the mib.
- */
- void
- parse_pingCtlTable(const char *token, char *line)
- {
- size_t tmpint;
- struct pingCtlTable_data *StorageTmp =
- SNMP_MALLOC_STRUCT(pingCtlTable_data);
- DEBUGMSGTL(("pingCtlTable", "parsing config... "));
- if (StorageTmp == NULL) {
- config_perror("malloc failure");
- return;
- }
- line =
- read_config_read_data(ASN_OCTET_STR, line,
- &StorageTmp->pingCtlOwnerIndex,
- &StorageTmp->pingCtlOwnerIndexLen);
- if (StorageTmp->pingCtlOwnerIndex == NULL) {
- config_perror("invalid specification for pingCtlOwnerIndex");
- return;
- }
- line =
- read_config_read_data(ASN_OCTET_STR, line,
- &StorageTmp->pingCtlTestName,
- &StorageTmp->pingCtlTestNameLen);
- if (StorageTmp->pingCtlTestName == NULL) {
- config_perror("invalid specification for pingCtlTestName");
- return;
- }
- line =
- read_config_read_data(ASN_INTEGER, line,
- &StorageTmp->pingCtlTargetAddressType,
- &tmpint);
- line =
- read_config_read_data(ASN_OCTET_STR, line,
- &StorageTmp->pingCtlTargetAddress,
- &StorageTmp->pingCtlTargetAddressLen);
- if (StorageTmp->pingCtlTargetAddress == NULL) {
- config_perror("invalid specification for pingCtlTargetAddress");
- return;
- }
- line =
- read_config_read_data(ASN_UNSIGNED, line,
- &StorageTmp->pingCtlDataSize, &tmpint);
- line =
- read_config_read_data(ASN_UNSIGNED, line,
- &StorageTmp->pingCtlTimeOut, &tmpint);
- line =
- read_config_read_data(ASN_UNSIGNED, line,
- &StorageTmp->pingCtlProbeCount, &tmpint);
- line =
- read_config_read_data(ASN_INTEGER, line,
- &StorageTmp->pingCtlAdminStatus, &tmpint);
- line =
- read_config_read_data(ASN_OCTET_STR, line,
- &StorageTmp->pingCtlDataFill,
- &StorageTmp->pingCtlDataFillLen);
- if (StorageTmp->pingCtlDataFill == NULL) {
- config_perror("invalid specification for pingCtlDataFill");
- return;
- }
- line =
- read_config_read_data(ASN_UNSIGNED, line,
- &StorageTmp->pingCtlFrequency, &tmpint);
- line =
- read_config_read_data(ASN_UNSIGNED, line,
- &StorageTmp->pingCtlMaxRows, &tmpint);
- line =
- read_config_read_data(ASN_INTEGER, line,
- &StorageTmp->pingCtlStorageType, &tmpint);
- line =
- read_config_read_data(ASN_OCTET_STR, line,
- &StorageTmp->pingCtlTrapGeneration,
- &StorageTmp->pingCtlTrapGenerationLen);
- if (StorageTmp->pingCtlTrapGeneration == NULL) {
- config_perror("invalid specification for pingCtlTrapGeneration");
- return;
- }
- line =
- read_config_read_data(ASN_UNSIGNED, line,
- &StorageTmp->pingCtlTrapProbeFailureFilter,
- &tmpint);
- line =
- read_config_read_data(ASN_UNSIGNED, line,
- &StorageTmp->pingCtlTrapTestFailureFilter,
- &tmpint);
- line =
- read_config_read_data(ASN_OBJECT_ID, line,
- &StorageTmp->pingCtlType,
- &StorageTmp->pingCtlTypeLen);
- if (StorageTmp->pingCtlType == NULL) {
- config_perror("invalid specification for pingCtlType");
- return;
- }
- line =
- read_config_read_data(ASN_OCTET_STR, line,
- &StorageTmp->pingCtlDescr,
- &StorageTmp->pingCtlDescrLen);
- if (StorageTmp->pingCtlDescr == NULL) {
- config_perror("invalid specification for pingCtlTrapDescr");
- return;
- }
- line =
- read_config_read_data(ASN_INTEGER, line,
- &StorageTmp->pingCtlSourceAddressType,
- &tmpint);
- line =
- read_config_read_data(ASN_OCTET_STR, line,
- &StorageTmp->pingCtlSourceAddress,
- &StorageTmp->pingCtlSourceAddressLen);
- if (StorageTmp->pingCtlSourceAddress == NULL) {
- config_perror("invalid specification for pingCtlSourceAddress");
- return;
- }
- line =
- read_config_read_data(ASN_INTEGER, line,
- &StorageTmp->pingCtlIfIndex, &tmpint);
- line =
- read_config_read_data(ASN_INTEGER, line,
- &StorageTmp->pingCtlByPassRouteTable,
- &tmpint);
- line =
- read_config_read_data(ASN_UNSIGNED, line,
- &StorageTmp->pingCtlDSField, &tmpint);
- line =
- read_config_read_data(ASN_INTEGER, line,
- &StorageTmp->pingCtlRowStatus, &tmpint);
- line =
- read_config_read_data(ASN_UNSIGNED, line,
- &StorageTmp->pingProbeHistoryMaxIndex,
- &tmpint);
- StorageTmp->storageType = ST_NONVOLATILE;
- pingCtlTable_add(StorageTmp);
- /* pingCtlTable_cleaner(pingCtlTableStorage); */
- DEBUGMSGTL(("pingCtlTable", "done.n"));
- }
- /*
- * store_pingCtlTable():
- * stores .conf file entries needed to configure the mib.
- */
- int
- store_pingCtlTable(int majorID, int minorID, void *serverarg,
- void *clientarg)
- {
- char line[SNMP_MAXBUF];
- char *cptr = NULL;
- size_t tmpint;
- struct pingCtlTable_data *StorageTmp = NULL;
- struct header_complex_index *hcindex = NULL;
- DEBUGMSGTL(("pingCtlTable", "storing data... "));
- for (hcindex = pingCtlTableStorage; hcindex != NULL;
- hcindex = hcindex->next) {
- StorageTmp = (struct pingCtlTable_data *) hcindex->data;
- if (StorageTmp->storageType != ST_READONLY) {
- memset(line, 0, sizeof(line));
- strcat(line, "pingCtlTable ");
- cptr = line + strlen(line);
- cptr =
- read_config_store_data(ASN_OCTET_STR, cptr,
- &StorageTmp->pingCtlOwnerIndex,
- &StorageTmp->pingCtlOwnerIndexLen);
- cptr =
- read_config_store_data(ASN_OCTET_STR, cptr,
- &StorageTmp->pingCtlTestName,
- &StorageTmp->pingCtlTestNameLen);
- cptr =
- read_config_store_data(ASN_INTEGER, cptr,
- &StorageTmp->
- pingCtlTargetAddressType, &tmpint);
- cptr =
- read_config_store_data(ASN_OCTET_STR, cptr,
- &StorageTmp->pingCtlTargetAddress,
- &StorageTmp->
- pingCtlTargetAddressLen);
- cptr =
- read_config_store_data(ASN_UNSIGNED, cptr,
- &StorageTmp->pingCtlDataSize,
- &tmpint);
- cptr =
- read_config_store_data(ASN_UNSIGNED, cptr,
- &StorageTmp->pingCtlTimeOut,
- &tmpint);
- cptr =
- read_config_store_data(ASN_UNSIGNED, cptr,
- &StorageTmp->pingCtlProbeCount,
- &tmpint);
- cptr =
- read_config_store_data(ASN_INTEGER, cptr,
- &StorageTmp->pingCtlAdminStatus,
- &tmpint);
- cptr =
- read_config_store_data(ASN_OCTET_STR, cptr,
- &StorageTmp->pingCtlDataFill,
- &StorageTmp->pingCtlDataFillLen);
- cptr =
- read_config_store_data(ASN_UNSIGNED, cptr,
- &StorageTmp->pingCtlFrequency,
- &tmpint);
- cptr =
- read_config_store_data(ASN_UNSIGNED, cptr,
- &StorageTmp->pingCtlMaxRows,
- &tmpint);
- cptr =
- read_config_store_data(ASN_INTEGER, cptr,
- &StorageTmp->pingCtlStorageType,
- &tmpint);
- cptr =
- read_config_store_data(ASN_OCTET_STR, cptr,
- &StorageTmp->pingCtlTrapGeneration,
- &StorageTmp->
- pingCtlTrapGenerationLen);
- cptr =
- read_config_store_data(ASN_UNSIGNED, cptr,
- &StorageTmp->
- pingCtlTrapProbeFailureFilter,
- &tmpint);
- cptr =
- read_config_store_data(ASN_UNSIGNED, cptr,
- &StorageTmp->
- pingCtlTrapTestFailureFilter,
- &tmpint);
- cptr =
- read_config_store_data(ASN_OBJECT_ID, cptr,
- &StorageTmp->pingCtlType,
- &StorageTmp->pingCtlTypeLen);
- cptr =
- read_config_store_data(ASN_OCTET_STR, cptr,
- &StorageTmp->pingCtlDescr,
- &StorageTmp->pingCtlDescrLen);
- cptr =
- read_config_store_data(ASN_INTEGER, cptr,
- &StorageTmp->
- pingCtlSourceAddressType, &tmpint);
- cptr =
- read_config_store_data(ASN_OCTET_STR, cptr,
- &StorageTmp->pingCtlSourceAddress,
- &StorageTmp->
- pingCtlSourceAddressLen);
- cptr =
- read_config_store_data(ASN_INTEGER, cptr,
- &StorageTmp->pingCtlIfIndex,
- &tmpint);
- cptr =
- read_config_store_data(ASN_INTEGER, cptr,
- &StorageTmp->
- pingCtlByPassRouteTable, &tmpint);
- cptr =
- read_config_store_data(ASN_UNSIGNED, cptr,
- &StorageTmp->pingCtlDSField,
- &tmpint);
- if (StorageTmp->pingCtlRowStatus == RS_ACTIVE)
- StorageTmp->pingCtlRowStatus = RS_NOTINSERVICE;
- cptr =
- read_config_store_data(ASN_INTEGER, cptr,
- &StorageTmp->pingCtlRowStatus,
- &tmpint);
- cptr =
- read_config_store_data(ASN_UNSIGNED, cptr,
- &StorageTmp->
- pingProbeHistoryMaxIndex, &tmpint);
- snmpd_store_config(line);
- }
- }
- DEBUGMSGTL(("pingCtlTable", "done.n"));
- return SNMPERR_SUCCESS;
- }
- /*
- * var_pingCtlTable():
- * 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_pingCtlTable(struct variable *vp,
- oid * name,
- size_t *length,
- int exact, size_t *var_len, WriteMethod ** write_method)
- {
- struct pingCtlTable_data *StorageTmp = NULL;
- /*
- * this assumes you have registered all your data properly
- */
- if ((StorageTmp =
- header_complex(pingCtlTableStorage, vp, name, length, exact,
- var_len, write_method)) == NULL) {
- if (vp->magic == COLUMN_PINGCTLROWSTATUS)
- *write_method = write_pingCtlRowStatus;
- return NULL;
- }
- /*
- * this is where we do the value assignments for the mib results.
- */
- switch (vp->magic) {
- case COLUMN_PINGCTLTARGETADDRESSTYPE:
- *write_method = write_pingCtlTargetAddressType;
- *var_len = sizeof(StorageTmp->pingCtlTargetAddressType);
- return (u_char *) & StorageTmp->pingCtlTargetAddressType;
- case COLUMN_PINGCTLTARGETADDRESS:
- *write_method = write_pingCtlTargetAddress;
- *var_len = (StorageTmp->pingCtlTargetAddressLen);
- return (u_char *) StorageTmp->pingCtlTargetAddress;
- case COLUMN_PINGCTLDATASIZE:
- *write_method = write_pingCtlDataSize;
- *var_len = sizeof(StorageTmp->pingCtlDataSize);
- return (u_char *) & StorageTmp->pingCtlDataSize;
- case COLUMN_PINGCTLTIMEOUT:
- *write_method = write_pingCtlTimeOut;
- *var_len = sizeof(StorageTmp->pingCtlTimeOut);
- return (u_char *) & StorageTmp->pingCtlTimeOut;
- case COLUMN_PINGCTLPROBECOUNT:
- *write_method = write_pingCtlProbeCount;
- *var_len = sizeof(StorageTmp->pingCtlProbeCount);
- return (u_char *) & StorageTmp->pingCtlProbeCount;
- case COLUMN_PINGCTLADMINSTATUS:
- *write_method = write_pingCtlAdminStatus;
- *var_len = sizeof(StorageTmp->pingCtlAdminStatus);
- return (u_char *) & StorageTmp->pingCtlAdminStatus;
- case COLUMN_PINGCTLDATAFILL:
- *write_method = write_pingCtlDataFill;
- *var_len = (StorageTmp->pingCtlDataFillLen);
- return (u_char *) StorageTmp->pingCtlDataFill;
- case COLUMN_PINGCTLFREQUENCY:
- *write_method = write_pingCtlFrequency;
- *var_len = sizeof(StorageTmp->pingCtlFrequency);
- return (u_char *) & StorageTmp->pingCtlFrequency;
- case COLUMN_PINGCTLMAXROWS:
- *write_method = write_pingCtlMaxRows;
- *var_len = sizeof(StorageTmp->pingCtlMaxRows);
- return (u_char *) & StorageTmp->pingCtlMaxRows;
- case COLUMN_PINGCTLSTORAGETYPE:
- *write_method = write_pingCtlStorageType;
- *var_len = sizeof(StorageTmp->pingCtlStorageType);
- return (u_char *) & StorageTmp->pingCtlStorageType;
- case COLUMN_PINGCTLTRAPGENERATION:
- *write_method = write_pingCtlTrapGeneration;
- *var_len = (StorageTmp->pingCtlTrapGenerationLen);
- return (u_char *) StorageTmp->pingCtlTrapGeneration;
- case COLUMN_PINGCTLTRAPPROBEFAILUREFILTER:
- *write_method = write_pingCtlTrapProbeFailureFilter;
- *var_len = sizeof(StorageTmp->pingCtlTrapProbeFailureFilter);
- return (u_char *) & StorageTmp->pingCtlTrapProbeFailureFilter;
- case COLUMN_PINGCTLTRAPTESTFAILUREFILTER:
- *write_method = write_pingCtlTrapTestFailureFilter;
- *var_len = sizeof(StorageTmp->pingCtlTrapTestFailureFilter);
- return (u_char *) & StorageTmp->pingCtlTrapTestFailureFilter;
- case COLUMN_PINGCTLTYPE:
- *write_method = write_pingCtlType;
- *var_len = (StorageTmp->pingCtlTypeLen) * sizeof(oid);
- return (u_char *) StorageTmp->pingCtlType;
- case COLUMN_PINGCTLDESCR:
- *write_method = write_pingCtlDescr;
- *var_len = (StorageTmp->pingCtlDescrLen);
- return (u_char *) StorageTmp->pingCtlDescr;
- case COLUMN_PINGCTLSOURCEADDRESSTYPE:
- *write_method = write_pingCtlSourceAddressType;
- *var_len = sizeof(StorageTmp->pingCtlSourceAddressType);
- return (u_char *) & StorageTmp->pingCtlSourceAddressType;
- case COLUMN_PINGCTLSOURCEADDRESS:
- *write_method = write_pingCtlSourceAddress;
- *var_len = (StorageTmp->pingCtlSourceAddressLen);
- return (u_char *) StorageTmp->pingCtlSourceAddress;
- case COLUMN_PINGCTLIFINDEX:
- *write_method = write_pingCtlIfIndex;
- *var_len = sizeof(StorageTmp->pingCtlIfIndex);
- return (u_char *) & StorageTmp->pingCtlIfIndex;
- case COLUMN_PINGCTLBYPASSROUTETABLE:
- *write_method = write_pingCtlByPassRouteTable;
- *var_len = sizeof(StorageTmp->pingCtlByPassRouteTable);
- return (u_char *) & StorageTmp->pingCtlByPassRouteTable;
- case COLUMN_PINGCTLDSFIELD:
- *write_method = write_pingCtlDSField;
- *var_len = sizeof(StorageTmp->pingCtlDSField);
- return (u_char *) & StorageTmp->pingCtlDSField;
- case COLUMN_PINGCTLROWSTATUS:
- *write_method = write_pingCtlRowStatus;
- *var_len = sizeof(StorageTmp->pingCtlRowStatus);
- return (u_char *) & StorageTmp->pingCtlRowStatus;
- default:
- ERROR_MSG("");
- }
- return NULL;
- }
- unsigned long
- pingProbeHistoryTable_count(struct pingCtlTable_data *thedata)
- {
- struct header_complex_index *hciptr2 = NULL;
- netsnmp_variable_list *vars = NULL;
- oid newoid[MAX_OID_LEN];
- size_t newoid_len;
- unsigned long count = 0;
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->pingCtlOwnerIndex, thedata->pingCtlOwnerIndexLen); /* pingCtlOwnerIndex */
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->pingCtlTestName, thedata->pingCtlTestNameLen); /* pingCtlOperationName */
- header_complex_generate_oid(newoid, &newoid_len, NULL, 0, vars);
- for (hciptr2 = pingProbeHistoryTableStorage; hciptr2 != NULL;
- hciptr2 = hciptr2->next) {
- if (snmp_oid_compare(newoid, newoid_len, hciptr2->name, newoid_len)
- == 0) {
- count = count + 1;
- }
- }
- return count;
- }
- int
- pingProbeHistoryTable_delLast(struct pingCtlTable_data *thedata)
- {
- struct header_complex_index *hciptr2 = NULL;
- struct header_complex_index *hcilast = NULL;
- struct pingProbeHistoryTable_data *StorageDel = NULL;
- struct pingProbeHistoryTable_data *StorageTmp = NULL;
- netsnmp_variable_list *vars = NULL;
- oid newoid[MAX_OID_LEN];
- size_t newoid_len;
- time_t last_time = 2147483647;
- struct tm *tp;
- tp = (struct tm *) malloc(sizeof(struct tm));
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->pingCtlOwnerIndex, thedata->pingCtlOwnerIndexLen); /* pingCtlOwnerIndex */
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->pingCtlTestName, thedata->pingCtlTestNameLen); /* pingCtlOperationName */
- header_complex_generate_oid(newoid, &newoid_len, NULL, 0, vars);
- for (hcilast = hciptr2 = pingProbeHistoryTableStorage; hciptr2 != NULL;
- hciptr2 = hciptr2->next) {
- if (snmp_oid_compare(newoid, newoid_len, hciptr2->name, newoid_len)
- == 0) {
- StorageTmp =
- header_complex_get_from_oid(pingProbeHistoryTableStorage,
- hciptr2->name,
- hciptr2->namelen);
- strptime(StorageTmp->pingProbeHistoryTime, "%c", tp);
- if (last_time > timegm(tp)) {
- last_time = timegm(tp);
- hcilast = hciptr2;
- }
- }
- }
- StorageDel =
- header_complex_extract_entry(&pingProbeHistoryTableStorage,
- hcilast);
- DEBUGMSGTL(("pingProbeHistoryTable",
- "delete the last one success!n"));
- SNMP_FREE(tp);
- }
- char *
- sock_ntop_host(const struct sockaddr *sa, socklen_t salen)
- {
- static char str[128]; /* Unix domain is largest */
- switch (sa->sa_family) {
- case AF_INET:{
- struct sockaddr_in *sin = (struct sockaddr_in *) sa;
- if (inet_ntop(AF_INET, &sin->sin_addr, str, sizeof(str)) ==
- NULL)
- return (NULL);
- return (str);
- }
- #ifdef IPV6
- case AF_INET6:{
- struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa;
- if (inet_ntop(AF_INET6, &sin6->sin6_addr, str, sizeof(str)) ==
- NULL)
- return (NULL);
- return (str);
- }
- #endif
- #ifdef AF_UNIX
- case AF_UNIX:{
- struct sockaddr_un *unp = (struct sockaddr_un *) sa;
- /*
- * OK to have no pathname bound to the socket: happens on
- * every connect() unless client calls bind() first.
- */
- if (unp->sun_path[0] == 0)
- strcpy(str, "(no pathname bound)");
- else
- snprintf(str, sizeof(str), "%s", unp->sun_path);
- return (str);
- }
- #endif
- #ifdef HAVE_SOCKADDR_DL_STRUCT
- case AF_LINK:{
- struct sockaddr_dl *sdl = (struct sockaddr_dl *) sa;
- if (sdl->sdl_nlen > 0)
- snprintf(str, sizeof(str), "%*s",
- sdl->sdl_nlen, &sdl->sdl_data[0]);
- else
- snprintf(str, sizeof(str), "AF_LINK, index=%d",
- sdl->sdl_index);
- return (str);
- }
- #endif
- default:
- snprintf(str, sizeof(str),
- "sock_ntop_host: unknown AF_xxx: %d, len %d",
- sa->sa_family, salen);
- return (str);
- }
- return (NULL);
- }
- char *
- Sock_ntop_host(const struct sockaddr *sa, socklen_t salen)
- {
- char *ptr;
- if ((ptr = sock_ntop_host(sa, salen)) == NULL)
- printf("sock_ntop_host error"); /* inet_ntop() sets errno */
- return (ptr);
- }
- unsigned short
- in_cksum(unsigned short *addr, int len)
- {
- int nleft = len;
- int sum = 0;
- unsigned short *w = addr;
- unsigned short answer = 0;
- /*
- * Our algorithm is simple, using a 32 bit accumulator (sum), we add
- * sequential 16 bit words to it, and at the end, fold back all the
- * carry bits from the top 16 bits into the lower 16 bits.
- */
- while (nleft > 1) {
- sum += *w++;
- nleft -= 2;
- }
- /*
- * 4mop up an odd byte, if necessary
- */
- if (nleft == 1) {
- *(unsigned char *) (&answer) = *(unsigned char *) w;
- sum += answer;
- }
- /*
- * 4add back carry outs from top 16 bits to low 16 bits
- */
- sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
- sum += (sum >> 16); /* add carry */
- answer = ~sum; /* truncate to 16 bits */
- return (answer);
- }
- struct addrinfo *
- host_serv(const char *host, const char *serv, int family, int socktype)
- {
- int n;
- struct addrinfo hints, *res;
- bzero(&hints, sizeof(struct addrinfo));
- hints.ai_flags = AI_CANONNAME; /* always return canonical name */
- hints.ai_family = family; /* AF_UNSPEC, AF_INET, AF_INET6, etc. */
- hints.ai_socktype = socktype; /* 0, SOCK_STREAM, SOCK_DGRAM, etc. */
- if ((n = getaddrinfo(host, serv, &hints, &res)) != 0)
- return (NULL);
- return (res); /* return pointer to first on linked list */
- }
- /*
- * end host_serv
- */
- /*
- * There is no easy way to pass back the integer return code from
- * getaddrinfo() in the function above, short of adding another argument
- * that is a pointer, so the easiest way to provide the wrapper function
- * is just to duplicate the simple function as we do here.
- */
- struct addrinfo *
- Host_serv(const char *host, const char *serv, int family, int socktype)
- {
- int n;
- struct addrinfo hints, *res;
- bzero(&hints, sizeof(struct addrinfo));
- hints.ai_flags = AI_CANONNAME; /* always return canonical name */
- hints.ai_family = family; /* 0, AF_INET, AF_INET6, etc. */
- hints.ai_socktype = socktype; /* 0, SOCK_STREAM, SOCK_DGRAM, etc. */
- if ((n = getaddrinfo(host, serv, &hints, &res)) != 0)
- printf("host_serv error for %s, %s: %s",
- (host == NULL) ? "(no hostname)" : host,
- (serv == NULL) ? "(no service name)" : serv,
- gai_strerror(n));
- return (res); /* return pointer to first on linked list */
- }
- int
- readable_timeo(int fd, int sec)
- {
- fd_set rset;
- struct timeval tv;
- FD_ZERO(&rset);
- FD_SET(fd, &rset);
- tv.tv_sec = sec;
- tv.tv_usec = 0;
- return (select(fd + 1, &rset, NULL, NULL, &tv));
- }
- /*
- * send trap
- */
- int
- send_ping_trap(struct pingCtlTable_data *item,
- oid * trap_oid, size_t trap_oid_len)
- {
- static oid objid_snmptrap[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 }; /* snmpTrapIOD.0 */
- struct pingResultsTable_data *StorageTmp = NULL;
- netsnmp_variable_list *var_list = NULL, *vars = NULL;
- oid newoid[MAX_OID_LEN];
- size_t newoid_len;
- oid pingCtlTargetAddress[] =
- { 1, 3, 6, 1, 2, 1, 80, 1, 2, 1, 4 };
- oid pingResultsMinRtt[] =
- { 1, 3, 6, 1, 2, 1, 80, 1, 3, 1, 4 };
- oid pingResultsMaxRtt[] =
- { 1, 3, 6, 1, 2, 1, 80, 1, 3, 1, 5 };
- oid pingResultsAverageRtt[] =
- { 1, 3, 6, 1, 2, 1, 80, 1, 3, 1, 6 };
- oid pingResultsProbeResponses[] =
- { 1, 3, 6, 1, 2, 1, 80, 1, 3, 1, 7 };
- oid pingResultsSendProbes[] =
- { 1, 3, 6, 1, 2, 1, 80, 1, 3, 1, 8 };
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) item->pingCtlOwnerIndex, item->pingCtlOwnerIndexLen); /* pingCtlOwnerIndex */
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) item->pingCtlTestName, item->pingCtlTestNameLen); /* pingCtlOperationName */
- StorageTmp = SNMP_MALLOC_STRUCT(pingResultsTable_data);
- if ((StorageTmp =
- (struct pingResultsTable_data *)
- header_complex_get(pingResultsTableStorage, vars)) == NULL)
- return SNMP_ERR_NOSUCHNAME;
- /*
- * snmpTrap oid
- */
- snmp_varlist_add_variable(&var_list, objid_snmptrap,
- sizeof(objid_snmptrap) / sizeof(oid),
- ASN_OBJECT_ID, (u_char *) trap_oid,
- trap_oid_len * sizeof(oid));
- /*
- * pingCtlTargetAddress
- */
- bzero(newoid, MAX_OID_LEN * sizeof(oid));
- header_complex_generate_oid(newoid, &newoid_len, pingCtlTargetAddress,
- sizeof(pingCtlTargetAddress) / sizeof(oid),
- vars);
- snmp_varlist_add_variable(&var_list, newoid,
- newoid_len,
- ASN_OCTET_STR,
- (u_char *) item->pingCtlTargetAddress,
- item->pingCtlTargetAddressLen);
- /*
- * pingResultsMinRtt
- */
- bzero(newoid, newoid_len);
- header_complex_generate_oid(newoid, &newoid_len, pingResultsMinRtt,
- sizeof(pingResultsMinRtt) / sizeof(oid),
- vars);
- snmp_varlist_add_variable(&var_list, newoid,
- newoid_len,
- ASN_UNSIGNED,
- (u_char *) & (StorageTmp->pingResultsMinRtt),
- sizeof(StorageTmp->pingResultsMinRtt));
- /*
- * pingResultsMaxRtt
- */
- bzero(newoid, newoid_len);
- header_complex_generate_oid(newoid, &newoid_len, pingResultsMaxRtt,
- sizeof(pingResultsMaxRtt) / sizeof(oid),
- vars);
- snmp_varlist_add_variable(&var_list, newoid,
- newoid_len,
- ASN_UNSIGNED,
- (u_char *) & (StorageTmp->pingResultsMaxRtt),
- sizeof(StorageTmp->pingResultsMaxRtt));
- /*
- * pingResultsAverageRtt
- */
- bzero(newoid, newoid_len);
- header_complex_generate_oid(newoid, &newoid_len, pingResultsAverageRtt,
- sizeof(pingResultsAverageRtt) /
- sizeof(oid), vars);
- snmp_varlist_add_variable(&var_list, newoid,
- newoid_len,
- ASN_UNSIGNED,
- (u_char *) & (StorageTmp->
- pingResultsAverageRtt),
- sizeof(StorageTmp->pingResultsAverageRtt));
- /*
- * pingResultsProbeResponses
- */
- bzero(newoid, newoid_len);
- header_complex_generate_oid(newoid, &newoid_len,
- pingResultsProbeResponses,
- sizeof(pingResultsProbeResponses) /
- sizeof(oid), vars);
- snmp_varlist_add_variable(&var_list, newoid,
- newoid_len,
- ASN_UNSIGNED,
- (u_char *) & (StorageTmp->
- pingResultsProbeResponses),
- sizeof(StorageTmp->
- pingResultsProbeResponses));
- /*
- * pingResultsSendProbes
- */
- bzero(newoid, newoid_len);
- header_complex_generate_oid(newoid, &newoid_len, pingResultsSendProbes,
- sizeof(pingResultsSendProbes) /
- sizeof(oid), vars);
- snmp_varlist_add_variable(&var_list, newoid,
- newoid_len,
- ASN_UNSIGNED,
- (u_char *) & (StorageTmp->
- pingResultsSendProbes),
- sizeof(StorageTmp->pingResultsSendProbes));
- /*
- * XXX: stuff based on event table
- */
- DEBUGMSG(("pingTest:send_ping_trap", "success!n"));
- send_v2trap(var_list);
- snmp_free_varbind(vars);
- vars = NULL;
- snmp_free_varbind(var_list);
- vars = NULL;
- }
- void
- readloop(struct pingCtlTable_data *item, struct addrinfo *ai, int datalen,
- unsigned long *minrtt, unsigned long *maxrtt,
- unsigned long *averagertt, pid_t pid)
- {
- int size;
- char recvbuf[BUFSIZE];
- char sendbuf[BUFSIZE];
- int nsent = 1;
- socklen_t len;
- ssize_t n;
- struct timeval tval;
- /* static int loop_num; */
- /* struct pingProbeHistoryTable_data * current=NULL; */
- struct pingProbeHistoryTable_data current_var;
- int sockfd;
- int current_probe_temp;
- int success_probe = 0;
- int fail_probe = 0;
- int flag;
- unsigned long *sumrtt;
- struct timeval tv;
- sumrtt = (unsigned long *) malloc(sizeof(unsigned long));
- sockfd = socket(pr->sasend->sa_family, SOCK_RAW, pr->icmpproto);
- setuid(getuid()); /* don't need special permissions any more */
- size = 60 * 1024; /* OK if setsockopt fails */
- tv.tv_sec = 5;
- tv.tv_usec = 0;
- setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
- for (current_probe_temp = 1;
- current_probe_temp <= item->pingCtlProbeCount;
- current_probe_temp++) {
- (*pr->fsend) (datalen, pid, nsent, sockfd, sendbuf);
- nsent++;
- len = pr->salen;
- if (readable_timeo(sockfd, item->pingCtlTimeOut) == 0) {
- /* printf("socket timeout!n"); */
- fail_probe = fail_probe + 1;
- flag = 1;
- } else {
- n = recvfrom(sockfd, recvbuf, sizeof(recvbuf), 0, pr->sarecv,
- &len);
- success_probe = success_probe + 1;
- flag = 0;
- }
- gettimeofday(&tval, NULL);
- time_t timep;
- time(&timep);
- (*pr->fproc) (recvbuf, n, &tval, timep, item, ai, datalen, minrtt,
- maxrtt, sumrtt, averagertt, current_probe_temp,
- success_probe, fail_probe, flag, ¤t_var, pid);
- printf("receiver success!n");
- if (current_probe_temp >= item->pingCtlProbeCount) {
- SNMP_FREE(sumrtt);
- sumrtt = NULL;
- return;
- }
- }
- }
- unsigned long
- round_double(double number)
- {
- unsigned long ret_num = 0;
- if (number - (unsigned long) number < 0.5)
- ret_num = (unsigned long) number;
- else
- ret_num = (unsigned long) number + 1;
- return ret_num;
- }
- int
- proc_v4(char *ptr, ssize_t len, struct timeval *tvrecv, time_t timep,
- struct pingCtlTable_data *item, struct addrinfo *ai, int datalen,
- unsigned long *minrtt, unsigned long *maxrtt,
- unsigned long *sumrtt, unsigned long *averagertt,
- unsigned long current_probe, int success_probe, int fail_probe,
- int flag, struct pingProbeHistoryTable_data *current_temp,
- pid_t pid)
- {
- int hlen1 = 0, icmplen = 0;
- unsigned long rtt = 0;
- struct ip *ip = NULL;
- struct icmp *icmp = NULL;
- struct timeval *tvsend = NULL;
- struct pingProbeHistoryTable_data *temp = NULL;
- static int probeFailed = 0;
- static int testFailed = 0;
- static int series = 0;
- netsnmp_variable_list *vars = NULL;
- struct pingResultsTable_data *StorageNew = NULL;
- if (flag == 0) {
- series = 0;
- ip = (struct ip *) ptr; /* start of IP header */
- hlen1 = ip->ip_hl << 2; /* length of IP header */
- icmp = (struct icmp *) (ptr + hlen1); /* start of ICMP header */
- if ((icmplen = len - hlen1) < 8)
- printf("icmplen (%d) < 8", icmplen);
- if (icmp->icmp_type == ICMP_ECHOREPLY) {
- if (icmp->icmp_id != pid)
- return; /* not a response to our ECHO_REQUEST */
- if (icmplen < 16)
- printf("icmplen (%d) < 16", icmplen);
- tvsend = (struct timeval *) icmp->icmp_data;
- rtt =
- round_double((1000000 * (tvrecv->tv_sec - tvsend->tv_sec) +
- tvrecv->tv_usec - tvsend->tv_usec) / 1000);
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) item->pingCtlOwnerIndex, item->pingCtlOwnerIndexLen); /* pingCtlOwnerIndex */
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) item->pingCtlTestName, item->pingCtlTestNameLen); /* pingCtlTestName */
- if ((StorageNew =
- header_complex_get(pingResultsTableStorage,
- vars)) == NULL)
- return SNMP_ERR_NOSUCHNAME;
- if (current_probe == 1) {
- *averagertt = rtt;
- *minrtt = rtt;
- *maxrtt = rtt;
- *sumrtt = rtt;
- } else {
- printf("elsen");
- if (rtt < *minrtt)
- *minrtt = rtt;
- if (rtt > *maxrtt)
- *maxrtt = rtt;
- *sumrtt = (*sumrtt) + rtt;
- *averagertt =
- round_double((*sumrtt) /
- (StorageNew->pingResultsProbeResponses +
- 1));
- }
- StorageNew->pingResultsMinRtt = *minrtt;
- StorageNew->pingResultsMaxRtt = *maxrtt;
- StorageNew->pingResultsAverageRtt = *averagertt;
- StorageNew->pingResultsProbeResponses =
- StorageNew->pingResultsProbeResponses + 1;
- StorageNew->pingResultsSendProbes =
- StorageNew->pingResultsSendProbes + 1;
- StorageNew->pingResultsRttSumOfSquares =
- StorageNew->pingResultsRttSumOfSquares + rtt * rtt;
- StorageNew->pingResultsLastGoodProbe =
- (char *) malloc(strlen(asctime(gmtime(&timep))));
- StorageNew->pingResultsLastGoodProbe =
- strdup(asctime(gmtime(&timep)));
- StorageNew->
- pingResultsLastGoodProbe[strlen(asctime(gmtime(&timep))) -
- 1] = ' ';
- StorageNew->pingResultsLastGoodProbeLen =
- strlen(asctime(gmtime(&timep))) - 1;
- temp = SNMP_MALLOC_STRUCT(pingProbeHistoryTable_data);
- temp->pingCtlOwnerIndex =
- (char *) malloc(item->pingCtlOwnerIndexLen + 1);
- memcpy(temp->pingCtlOwnerIndex, item->pingCtlOwnerIndex,
- item->pingCtlOwnerIndexLen + 1);
- temp->pingCtlOwnerIndex[item->pingCtlOwnerIndexLen] = ' ';
- temp->pingCtlOwnerIndexLen = item->pingCtlOwnerIndexLen;
- temp->pingCtlTestName =
- (char *) malloc(item->pingCtlTestNameLen + 1);
- memcpy(temp->pingCtlTestName, item->pingCtlTestName,
- item->pingCtlTestNameLen + 1);
- temp->pingCtlTestName[item->pingCtlTestNameLen] = ' ';
- temp->pingCtlTestNameLen = item->pingCtlTestNameLen;
- /* add lock to protect */
- pthread_mutex_t counter_mutex = PTHREAD_MUTEX_INITIALIZER;
- pthread_mutex_lock(&counter_mutex);
- if (item->pingProbeHistoryMaxIndex >=
- (unsigned long) (2147483647))
- item->pingProbeHistoryMaxIndex = 0;
- temp->pingProbeHistoryIndex =
- ++(item->pingProbeHistoryMaxIndex);
- pthread_mutex_unlock(&counter_mutex);
- temp->pingProbeHistoryResponse = rtt;
- temp->pingProbeHistoryStatus = 1;
- temp->pingProbeHistoryLastRC = 0;
- temp->pingProbeHistoryTime =
- (char *) malloc(strlen(asctime(gmtime(&timep))));
- temp->pingProbeHistoryTime = strdup(asctime(gmtime(&timep)));
- temp->pingProbeHistoryTime[strlen(asctime(gmtime(&timep))) -
- 1] = ' ';
- temp->pingProbeHistoryTimeLen =
- strlen(asctime(gmtime(&timep))) - 1;
- if (StorageNew->pingResultsSendProbes == 1)
- item->pingProbeHis = temp;
- else {
- (current_temp)->next = temp;
- }
- current_temp = temp;
- if (StorageNew->pingResultsSendProbes >=
- item->pingCtlProbeCount) {
- current_temp->next = NULL;
- }
- if (item->pingProbeHis != NULL)
- if (pingProbeHistoryTable_count(item) <
- item->pingCtlMaxRows) {
- if (pingProbeHistoryTable_add(current_temp) !=
- SNMPERR_SUCCESS)
- DEBUGMSGTL(("pingProbeHistoryTable",
- "registered an entry errorn"));
- } else {
- pingProbeHistoryTable_delLast(item);
- if (pingProbeHistoryTable_add(current_temp) !=
- SNMPERR_SUCCESS)
- DEBUGMSGTL(("pingProbeHistoryTable",
- "registered an entry errorn"));
- }
- }
- }
- else if (flag == 1)
- {
- if (series == 0)
- probeFailed = 1;
- else
- probeFailed = probeFailed + 1;
- series = 1;
- testFailed = testFailed + 1;
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) item->pingCtlOwnerIndex, item->pingCtlOwnerIndexLen); /* pingCtlOwnerIndex */
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) item->pingCtlTestName, item->pingCtlTestNameLen); /* pingCtlTestName */
- if ((StorageNew =
- header_complex_get(pingResultsTableStorage, vars)) == NULL)
- return SNMP_ERR_NOSUCHNAME;
- if (current_probe == 1) {
- *averagertt = rtt;
- *minrtt = rtt;
- *maxrtt = rtt;
- *sumrtt = rtt;
- }
- StorageNew->pingResultsSendProbes =
- StorageNew->pingResultsSendProbes + 1;
- temp = SNMP_MALLOC_STRUCT(pingProbeHistoryTable_data);
- temp->pingCtlOwnerIndex =
- (char *) malloc(item->pingCtlOwnerIndexLen + 1);
- memcpy(temp->pingCtlOwnerIndex, item->pingCtlOwnerIndex,
- item->pingCtlOwnerIndexLen + 1);
- temp->pingCtlOwnerIndex[item->pingCtlOwnerIndexLen] = ' ';
- temp->pingCtlOwnerIndexLen = item->pingCtlOwnerIndexLen;
- temp->pingCtlTestName =
- (char *) malloc(item->pingCtlTestNameLen + 1);
- memcpy(temp->pingCtlTestName, item->pingCtlTestName,
- item->pingCtlTestNameLen + 1);
- temp->pingCtlTestName[item->pingCtlTestNameLen] = ' ';
- temp->pingCtlTestNameLen = item->pingCtlTestNameLen;
- /* add lock to protect */
- pthread_mutex_t counter_mutex = PTHREAD_MUTEX_INITIALIZER;
- pthread_mutex_lock(&counter_mutex);
- temp->pingProbeHistoryIndex = ++(item->pingProbeHistoryMaxIndex);
- pthread_mutex_unlock(&counter_mutex);
- /* end */
- temp->pingProbeHistoryResponse = item->pingCtlTimeOut * 1000;
- temp->pingProbeHistoryStatus = 4;
- temp->pingProbeHistoryLastRC = 1;
- temp->pingProbeHistoryTime =
- (char *) malloc(strlen(asctime(gmtime(&timep))));
- temp->pingProbeHistoryTime = strdup(asctime(gmtime(&timep)));
- temp->pingProbeHistoryTime[strlen(asctime(gmtime(&timep))) - 1] =
- ' ';
- temp->pingProbeHistoryTimeLen =
- strlen(asctime(gmtime(&timep))) - 1;
- if (StorageNew->pingResultsSendProbes == 1)
- item->pingProbeHis = temp;
- else {
- (current_temp)->next = temp;
- }
- current_temp = temp;
- if (StorageNew->pingResultsSendProbes >= item->pingCtlProbeCount) {
- current_temp->next = NULL;
- }
- if (item->pingProbeHis != NULL)
- if (pingProbeHistoryTable_count(item) < item->pingCtlMaxRows) {
- if (pingProbeHistoryTable_add(current_temp) !=
- SNMPERR_SUCCESS)
- DEBUGMSGTL(("pingProbeHistoryTable",
- "registered an entry errorn"));
- } else {
- pingProbeHistoryTable_delLast(item);
- if (pingProbeHistoryTable_add(current_temp) !=
- SNMPERR_SUCCESS)
- DEBUGMSGTL(("pingProbeHistoryTable",
- "registered an entry errorn"));
- }
- if ((item->
- pingCtlTrapGeneration[0] & PINGTRAPGENERATION_PROBEFAILED) !=
- 0) {
- if (probeFailed >= item->pingCtlTrapProbeFailureFilter)
- send_ping_trap(item, pingProbeFailed,
- sizeof(pingProbeFailed) / sizeof(oid));
- }
- }
- if (current_probe == item->pingCtlProbeCount) {
- if ((item->
- pingCtlTrapGeneration[0] & PINGTRAPGENERATION_TESTCOMPLETED)
- != 0) {
- send_ping_trap(item, pingTestCompleted,
- sizeof(pingTestCompleted) / sizeof(oid));
- } else
- if ((item->
- pingCtlTrapGeneration[0] & PINGTRAPGENERATION_TESTFAILED)
- != 0) {
- if (testFailed >= item->pingCtlTrapTestFailureFilter)
- send_ping_trap(item, pingTestFailed,
- sizeof(pingTestFailed) / sizeof(oid));
- }
- else if ((item->
- pingCtlTrapGeneration[0] &
- PINGTRAPGENERATION_PROBEFAILED) != 0) {;
- } else {
- ;
- }
- series = 0;
- probeFailed = 0;
- testFailed = 0;
- }
- return;
- }
- void
- send_v4(int datalen, pid_t pid, int nsent, int sockfd, char *sendbuf)
- {
- int len;
- struct icmp *icmp = NULL;
- struct timeval *temp = NULL;
- icmp = (struct icmp *) sendbuf;
- icmp->icmp_type = ICMP_ECHO;
- icmp->icmp_code = 0;
- icmp->icmp_id = pid;
- icmp->icmp_seq = nsent;
- gettimeofday((struct timeval *) icmp->icmp_data, NULL);
- temp = (struct timeval *) icmp->icmp_data;
- len = 8 + datalen; /* checksum ICMP header and data */
- icmp->icmp_cksum = 0;
- icmp->icmp_cksum = in_cksum((u_short *) icmp, len);
- sendto(sockfd, sendbuf, len, 0, pr->sasend, pr->salen);
- }
- void
- run_ping(unsigned int clientreg, void *clientarg)
- /* run_ping(struct pingCtlTable_data *item) */
- {
- struct pingCtlTable_data *item = clientarg;
- netsnmp_variable_list *vars = NULL;
- struct pingResultsTable_data *StorageNew = NULL;
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) item->pingCtlOwnerIndex, item->pingCtlOwnerIndexLen); /* pingCtlOwnerIndex */
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) item->pingCtlTestName, item->pingCtlTestNameLen); /* pingCtlTestName */
- if ((StorageNew =
- header_complex_get(pingResultsTableStorage, vars)) == NULL)
- return;
- StorageNew->pingResultsSendProbes = 0;
- StorageNew->pingResultsProbeResponses = 0;
- if (item->pingCtlTargetAddressType == 1
- || item->pingCtlTargetAddressType == 16) {
- struct proto proto_v4 =
- { proc_v4, send_v4, NULL, NULL, 0, IPPROTO_ICMP };
- char *host = NULL;
- pid_t pid; /* our PID */
- int datalen;
- unsigned long *minrtt = NULL;
- unsigned long *maxrtt = NULL;
- unsigned long *averagertt = NULL;
- datalen = 56; /* data that goes with ICMP echo request */
- unsigned int n = 1;
- int c;
- struct addrinfo *ai = NULL;
- minrtt = malloc(sizeof(unsigned long));
- maxrtt = malloc(sizeof(unsigned long));
- averagertt = malloc(sizeof(unsigned long));
- host = item->pingCtlTargetAddress;
- pid = getpid();
- ai = host_serv(host, NULL, 0, 0);
- printf("PING %s (%s): %d data bytesn", ai->ai_canonname,
- sock_ntop_host(ai->ai_addr, ai->ai_addrlen), datalen);
- /*
- * 4initialize according to protocol
- */
- if (ai->ai_family == AF_INET) {
- pr = &proto_v4;
- #ifdef IPV6
- } else if (ai->ai_family == AF_INET6) {
- pr = &proto_v6;
- if (IN6_IS_ADDR_V4MAPPED(&(((struct sockaddr_in6 *)
- ai->ai_addr)->sin6_addr)))
- printf("cannot ping IPv4-mapped IPv6 address");
- #endif
- } else
- printf("unknown address family %d", ai->ai_family);
- pr->sasend = ai->ai_addr;
- pr->sarecv = calloc(1, ai->ai_addrlen);
- pr->salen = ai->ai_addrlen;
- readloop(item, ai, datalen, minrtt, maxrtt, averagertt, pid);
- SNMP_FREE(minrtt);
- minrtt = NULL;
- SNMP_FREE(maxrtt);
- maxrtt = NULL;
- SNMP_FREE(averagertt);
- averagertt = NULL;
- free(ai);
- ai = NULL;
- }
- else if (item->pingCtlTargetAddressType == 2) {
- int ch = 0, hold = 0, packlen = 0;
- u_char *packet = NULL;
- char *target = NULL;
- struct sockaddr_in6 firsthop;
- int socket_errno = 0;
- struct icmp6_filter filter;
- int err = 0, csum_offset = 0, sz_opt = 0;
- static int icmp_sock = 0;
- int uid = 0;
- struct sockaddr_in6 source;
- int preload = 0;
- struct cmsghdr *srcrt = NULL;
- static unsigned char cmsgbuf[4096];
- static int cmsglen = 0;
- struct sockaddr_in6 whereto; /* who to ping */
- int options = 0;
- char *hostname = NULL;
- char *device = NULL;
- int interval = 1000; /* interval between packets (msec) */
- int pmtudisc = -1;
- int datalen = DEFDATALEN;
- int timing = 0; /* flag to do timing */
- int working_recverr = 0;
- __u32 flowlabel = 0;
- __u32 tclass = 0;
- int ident = 0; /* process id to identify our packets */
- u_char outpack[MAX_PACKET];
- struct timeval start_time;
- static int screen_width = INT_MAX;
- int deadline = 0; /* time to die */
- int timeout = 0;
- timeout = item->pingCtlTimeOut;
- memset(&source, 0, sizeof(source));
- icmp_sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
- socket_errno = errno;
- uid = getuid();
- setuid(uid);
- source.sin6_family = AF_INET6;
- memset(&firsthop, 0, sizeof(firsthop));
- firsthop.sin6_family = AF_INET6;
- preload = 1;
- target = item->pingCtlTargetAddress;
- memset(&whereto, 0, sizeof(struct sockaddr_in6));
- whereto.sin6_family = AF_INET6;
- whereto.sin6_port = htons(IPPROTO_ICMPV6);
- if (inet_pton(AF_INET6, target, &whereto.sin6_addr) <= 0) {
- struct hostent *hp = NULL;
- hp = gethostbyname2(target, AF_INET6);
- if (hp == NULL) {
- fprintf(stderr, "unknown hostn");
- return;
- }
- memcpy(&whereto.sin6_addr, hp->h_addr_list[0], 16);
- } else {
- options |= F_NUMERIC;
- }
- if (ipv6_addr_any(&firsthop.sin6_addr))
- memcpy(&firsthop.sin6_addr, &whereto.sin6_addr, 16);
- hostname = target;
- if (ipv6_addr_any(&source.sin6_addr)) {
- int alen;
- int probe_fd = socket(AF_INET6, SOCK_DGRAM, 0);
- if (probe_fd < 0) {
- printf("error!n");
- perror("socket");
- return;
- }
- if (device) {
- struct ifreq ifr;
- memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, device, IFNAMSIZ - 1);
- if (setsockopt
- (probe_fd, SOL_SOCKET, SO_BINDTODEVICE, device,
- strlen(device) + 1) == -1) {
- #ifdef HAVE_SIN6_SCOPEID
- if ((firsthop.sin6_addr.
- s6_addr16[0] & htons(0xffc0)) == htons(0xfe80)
- || (firsthop.sin6_addr.
- s6_addr16[0] & htons(0xffff)) ==
- htons(0xff02)) {
- if (ioctl(probe_fd, SIOCGIFINDEX, &ifr) < 0) {
- fprintf(stderr, "ping: unknown iface %sn",
- device);
- return;
- }
- firsthop.sin6_scope_id = ifr.ifr_ifindex;
- }
- #endif
- }
- }
- firsthop.sin6_port = htons(1025);
- if (connect
- (probe_fd, (struct sockaddr *) &firsthop,
- sizeof(firsthop)) == -1) {
- perror("connect");
- return;
- }
- alen = sizeof(source);
- if (getsockname(probe_fd, (struct sockaddr *) &source, &alen)
- == -1) {
- perror("getsockname");
- return;
- }
- source.sin6_port = 0;
- close(probe_fd);
- }
- if (icmp_sock < 0) {
- errno = socket_errno;
- perror("ping: icmp open socket");
- return;
- }
- if ((whereto.sin6_addr.s6_addr16[0] & htons(0xff00)) ==
- htons(0xff00)) {
- if (uid) {
- if (interval < 1000) {
- fprintf(stderr,
- "ping: multicast ping with too short interval.n");
- return;
- }
- if (pmtudisc >= 0 && pmtudisc != IPV6_PMTUDISC_DO) {
- fprintf(stderr,
- "ping: multicast ping does not fragment.n");
- return;
- }
- }
- if (pmtudisc < 0)
- pmtudisc = IPV6_PMTUDISC_DO;
- }
- if (pmtudisc >= 0) {
- if (setsockopt
- (icmp_sock, SOL_IPV6, IPV6_MTU_DISCOVER, &pmtudisc,
- sizeof(pmtudisc)) == -1) {
- perror("ping: IPV6_MTU_DISCOVER");
- return;
- }
- }
- if (bind(icmp_sock, (struct sockaddr *) &source, sizeof(source)) ==
- -1) {
- perror("ping: bind icmp socket");
- return;
- }
- if (datalen >= sizeof(struct timeval)) /* can we time transfer */
- timing = 1;
- packlen = datalen + 8 + 4096 + 40 + 8; /* 4096 for rthdr */
- if (!(packet = (u_char *) malloc((u_int) packlen))) {
- fprintf(stderr, "ping: out of memory.n");
- return;
- }
- working_recverr = 1;
- hold = 1;
- if (setsockopt
- (icmp_sock, SOL_IPV6, IPV6_RECVERR, (char *) &hold,
- sizeof(hold))) {
- fprintf(stderr,
- "WARNING: your kernel is veeery old. No problems.n");
- working_recverr = 0;
- }
- /*
- * Estimate memory eaten by single packet. It is rough estimate.
- * * Actually, for small datalen's it depends on kernel side a lot.
- */
- hold = datalen + 8;
- hold += ((hold + 511) / 512) * (40 + 16 + 64 + 160);
- sock_setbufs(icmp_sock, hold, preload);
- csum_offset = 2;
- sz_opt = sizeof(int);
- err =
- setsockopt(icmp_sock, SOL_RAW, IPV6_CHECKSUM, &csum_offset,
- sz_opt);
- if (err < 0) {
- perror("setsockopt(RAW_CHECKSUM)");
- return;
- }
- /*
- * select icmp echo reply as icmp type to receive
- */
- ICMPV6_FILTER_SETBLOCKALL(&filter);
- if (!working_recverr) {
- ICMPV6_FILTER_SETPASS(ICMPV6_DEST_UNREACH, &filter);
- ICMPV6_FILTER_SETPASS(ICMPV6_PKT_TOOBIG, &filter);
- ICMPV6_FILTER_SETPASS(ICMPV6_TIME_EXCEED, &filter);
- ICMPV6_FILTER_SETPASS(ICMPV6_PARAMPROB, &filter);
- }
- ICMPV6_FILTER_SETPASS(ICMPV6_ECHO_REPLY, &filter);
- err = setsockopt(icmp_sock, SOL_ICMPV6, ICMPV6_FILTER, &filter,
- sizeof(struct icmp6_filter));
- if (err < 0) {
- perror("setsockopt(ICMPV6_FILTER)");
- return;
- }
- if (1) {
- int on = 1;
- if (setsockopt(icmp_sock, IPPROTO_IPV6, IPV6_HOPLIMIT,
- &on, sizeof(on)) == -1) {
- perror("can't receive hop limit");
- return;
- }
- }
- printf("PING %s(%s) ", hostname,
- pr_addr(&whereto.sin6_addr, options));
- if (flowlabel)
- printf(", flow 0x%05x, ", (unsigned) ntohl(flowlabel));
- if (device || (options & F_NUMERIC)) {
- printf("from %s %s: ",
- pr_addr_n(&source.sin6_addr), device ? : "");
- }
- printf("%d data bytesn", datalen);
- setup(icmp_sock, options, uid, timeout, preload, interval, datalen,
- (char *) outpack, &ident, &start_time, &screen_width,
- &deadline);
- main_loop(item, icmp_sock, preload, packet, packlen, cmsglen,
- (char *) cmsgbuf, &whereto, options, uid, hostname,
- interval, datalen, timing, working_recverr,
- (char *) outpack, &ident, &start_time, &screen_width,
- &deadline);
- }
- return;
- }
- void
- init_resultsTable(struct pingCtlTable_data *item)
- {
- struct pingResultsTable_data *StorageTmp = NULL;
- struct pingResultsTable_data *StorageNew = NULL;
- struct addrinfo *ai = NULL;
- char *host = NULL;
- netsnmp_variable_list *vars = NULL;
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) item->pingCtlOwnerIndex, item->pingCtlOwnerIndexLen); /* pingCtlOwnerIndex */
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) item->pingCtlTestName, item->pingCtlTestNameLen); /* pingCtlTestName */
- if ((StorageNew =
- header_complex_get(pingResultsTableStorage, vars)) != NULL) {
- StorageNew->pingResultsSendProbes = 0;
- StorageNew->pingResultsProbeResponses = 0;
- return;
- }
- ai = malloc(sizeof(struct addrinfo));
- host = item->pingCtlTargetAddress;
- ai = host_serv(host, NULL, 0, 0);
- StorageTmp = SNMP_MALLOC_STRUCT(pingResultsTable_data);
- StorageTmp->pingCtlOwnerIndex =
- (char *) malloc(item->pingCtlOwnerIndexLen + 1);
- memcpy(StorageTmp->pingCtlOwnerIndex, item->pingCtlOwnerIndex,
- item->pingCtlOwnerIndexLen + 1);
- StorageTmp->pingCtlOwnerIndex[item->pingCtlOwnerIndexLen] = ' ';
- StorageTmp->pingCtlOwnerIndexLen = item->pingCtlOwnerIndexLen;
- StorageTmp->pingCtlTestName =
- (char *) malloc(item->pingCtlTestNameLen + 1);
- memcpy(StorageTmp->pingCtlTestName, item->pingCtlTestName,
- item->pingCtlTestNameLen + 1);
- StorageTmp->pingCtlTestName[item->pingCtlTestNameLen] = ' ';
- StorageTmp->pingCtlTestNameLen = item->pingCtlTestNameLen;
- StorageTmp->pingResultsOperStatus = 1;
- if (item->pingCtlTargetAddressType == 1
- || item->pingCtlTargetAddressType == 16) {
- if (ai == NULL) {
- StorageTmp->pingResultsIpTargetAddressType = 0;
- StorageTmp->pingResultsIpTargetAddress = strdup("");
- StorageTmp->pingResultsIpTargetAddressLen = 0;
- } else {
- StorageTmp->pingResultsIpTargetAddressType = 1;
- StorageTmp->pingResultsIpTargetAddress =
- (char *)
- malloc(strlen(sock_ntop_host(ai->ai_addr, ai->ai_addrlen))
- + 1);
- StorageTmp->pingResultsIpTargetAddress =
- strdup(sock_ntop_host(ai->ai_addr, ai->ai_addrlen));
- StorageTmp->
- pingResultsIpTargetAddress[strlen
- (sock_ntop_host
- (ai->ai_addr,
- ai->ai_addrlen))] = ' ';
- StorageTmp->pingResultsIpTargetAddressLen =
- strlen(sock_ntop_host(ai->ai_addr, ai->ai_addrlen));
- }
- }
- if (item->pingCtlTargetAddressType == 2) {
- struct sockaddr_in6 whereto; /* Who to try to reach */
- register struct sockaddr_in6 *to =
- (struct sockaddr_in6 *) &whereto;
- struct hostent *hp = NULL;
- char pa[64];
- to->sin6_family = AF_INET6;
- to->sin6_port = htons(33434);
- if (inet_pton(AF_INET6, host, &to->sin6_addr) > 0) {
- StorageTmp->pingResultsIpTargetAddressType = 2;
- StorageTmp->pingResultsIpTargetAddress =
- (char *) malloc(strlen(host) + 1);
- StorageTmp->pingResultsIpTargetAddress = strdup(host);
- StorageTmp->pingResultsIpTargetAddress[strlen(host)] = ' ';
- StorageTmp->pingResultsIpTargetAddressLen = strlen(host);
- } else {
- hp = gethostbyname2(host, AF_INET6);
- if (hp != NULL) {
- const char *hostname = NULL;
- memmove((caddr_t) & to->sin6_addr, hp->h_addr, 16);
- hostname = inet_ntop(AF_INET6, &to->sin6_addr, pa, 64);
- StorageTmp->pingResultsIpTargetAddressType = 2;
- StorageTmp->pingResultsIpTargetAddress =
- (char *) malloc(strlen(hostname) + 1);
- StorageTmp->pingResultsIpTargetAddress = strdup(hostname);
- StorageTmp->pingResultsIpTargetAddress[strlen(hostname)] =
- ' ';
- StorageTmp->pingResultsIpTargetAddressLen =
- strlen(hostname);
- } else {
- (void) fprintf(stderr,
- "traceroute: unknown host %sn", host);
- StorageTmp->pingResultsIpTargetAddressType = 0;
- StorageTmp->pingResultsIpTargetAddress = strdup("");
- StorageTmp->pingResultsIpTargetAddressLen = 0;
- }
- }
- }
- StorageTmp->pingResultsMinRtt = 0;
- StorageTmp->pingResultsMaxRtt = 0;
- StorageTmp->pingResultsAverageRtt = 0;
- StorageTmp->pingResultsProbeResponses = 0;
- StorageTmp->pingResultsSendProbes = 0;
- StorageTmp->pingResultsRttSumOfSquares = 0;
- StorageTmp->pingResultsLastGoodProbe = strdup("");
- StorageTmp->pingResultsLastGoodProbeLen = 0;
- item->pingResults = StorageTmp;
- if (item->pingProbeHistoryMaxIndex == 0) {
- if (item->pingResults != NULL) {
- if (pingResultsTable_add(item) != SNMPERR_SUCCESS) {
- DEBUGMSGTL(("pingResultsTable", "init an entry errorn"));
- }
- }
- }
- SNMP_FREE(ai);
- ai = NULL;
- }
- int
- modify_ResultsOper(struct pingCtlTable_data *thedata, long val)
- {
- netsnmp_variable_list *vars = NULL;
- struct pingResultsTable_data *StorageTmp = NULL;
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->pingCtlOwnerIndex, thedata->pingCtlOwnerIndexLen); /* pingCtlOwnerIndex */
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->pingCtlTestName, thedata->pingCtlTestNameLen); /* pingCtlTestName */
- if ((StorageTmp =
- header_complex_get(pingResultsTableStorage, vars)) == NULL)
- return SNMP_ERR_NOSUCHNAME;
- StorageTmp->pingResultsOperStatus = val;
- DEBUGMSGTL(("pingResultsOperStatus", "done.n"));
- return SNMPERR_SUCCESS;
- }
- int
- pingResultsTable_del(struct pingCtlTable_data *thedata)
- {
- struct header_complex_index *hciptr2 = NULL;
- struct pingResultsTable_data *StorageDel = NULL;
- netsnmp_variable_list *vars = NULL;
- oid newoid[MAX_OID_LEN];
- size_t newoid_len;
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->pingCtlOwnerIndex, thedata->pingCtlOwnerIndexLen); /* pingCtlOwnerIndex */
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->pingCtlTestName, thedata->pingCtlTestNameLen); /* pingCtlOperationName */
- header_complex_generate_oid(newoid, &newoid_len, NULL, 0, vars);
- for (hciptr2 = pingResultsTableStorage; hciptr2 != NULL;
- hciptr2 = hciptr2->next) {
- if (snmp_oid_compare(newoid, newoid_len, hciptr2->name, newoid_len)
- == 0) {
- StorageDel =
- header_complex_extract_entry(&pingResultsTableStorage,
- hciptr2);
- if (StorageDel != NULL) {
- SNMP_FREE(StorageDel->pingCtlOwnerIndex);
- SNMP_FREE(StorageDel->pingCtlTestName);
- SNMP_FREE(StorageDel->pingResultsIpTargetAddress);
- SNMP_FREE(StorageDel->pingResultsLastGoodProbe);
- SNMP_FREE(StorageDel);
- }
- DEBUGMSGTL(("pingResultsTable", "delete success!n"));
- }
- }
- return SNMPERR_SUCCESS;
- }
- int
- pingProbeHistoryTable_del(struct pingCtlTable_data *thedata)
- {
- struct header_complex_index *hciptr2 = NULL;
- struct pingProbeHistoryTable_data *StorageDel = NULL;
- netsnmp_variable_list *vars = NULL;
- oid newoid[MAX_OID_LEN];
- size_t newoid_len;
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->pingCtlOwnerIndex, thedata->pingCtlOwnerIndexLen); /* pingCtlOwnerIndex */
- snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->pingCtlTestName, thedata->pingCtlTestNameLen); /* pingCtlOperationName */
- header_complex_generate_oid(newoid, &newoid_len, NULL, 0, vars);
- for (hciptr2 = pingProbeHistoryTableStorage; hciptr2 != NULL;
- hciptr2 = hciptr2->next) {
- if (snmp_oid_compare(newoid, newoid_len, hciptr2->name, newoid_len)
- == 0) {
- StorageDel =
- header_complex_extract_entry(&pingProbeHistoryTableStorage,
- hciptr2);
- if (StorageDel != NULL) {
- SNMP_FREE(StorageDel->pingCtlOwnerIndex);
- SNMP_FREE(StorageDel->pingCtlTestName);
- SNMP_FREE(StorageDel->pingProbeHistoryTime);
- SNMP_FREE(StorageDel);
- }
- DEBUGMSGTL(("pingProbeHistoryTable", "delete success!n"));
- }
- }
- return SNMPERR_SUCCESS;
- }
- int
- write_pingCtlTargetAddressType(int action,
- u_char * var_val,
- u_char var_val_type,
- size_t var_val_len,
- u_char * statP, oid * name, size_t name_len)
- {
- static size_t tmpvar;
- struct pingCtlTable_data *StorageTmp = NULL;
- static size_t tmplen;
- size_t newlen =
- name_len - (sizeof(pingCtlTable_variables_oid) / sizeof(oid) +
- 3 - 1);
- DEBUGMSGTL(("pingCtlTable",
- "write_pingCtlTargetAddressType entering action=%d... n",
- action));
- if ((StorageTmp =
- header_complex(pingCtlTableStorage, NULL,
- &name[sizeof(pingCtlTable_variables_oid) /
- sizeof(oid) + 3 - 1], &newlen, 1, NULL,
- NULL)) == NULL)
- return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */
- if (StorageTmp && StorageTmp->storageType == ST_READONLY) {
- return SNMP_ERR_NOTWRITABLE;
- }
- if (StorageTmp && StorageTmp->pingCtlRowStatus == RS_ACTIVE) {
- return SNMP_ERR_NOTWRITABLE;
- }
- switch (action) {
- case RESERVE1:
- if (var_val_type != ASN_INTEGER) {
- snmp_log(LOG_ERR,
- "write to pingCtlTargetAddressType not ASN_INTEGERn");
- return SNMP_ERR_WRONGTYPE;
- }
- break;
- case RESERVE2:
- /*
- * memory reseveration, final preparation...
- */
- break;
- case FREE:
- /*
- * Release any resources that have been allocated
- */
- break;
- case ACTION:
- /*
- * The variable has been stored in objid for
- * you to use, and you have just been asked to do something with
- * it. Note that anything done here must be reversable in the UNDO case
- */
- tmpvar = StorageTmp->pingCtlTargetAddressType;
- StorageTmp->pingCtlTargetAddressType = *((long *) var_val);
- break;
- case UNDO:
- /*
- * Back out any changes made in the ACTION case
- */
- StorageTmp->pingCtlTargetAddressType = tmpvar;
- break;
- case COMMIT:
- /*
- * Things are working well, so it's now safe to make the change
- * permanently. Make sure that anything done here can't fail!
- */
- break;
- }
- return SNMP_ERR_NOERROR;
- }
- int
- write_pingCtlTargetAddress(int action,
- u_char * var_val,
- u_char var_val_type,
- size_t var_val_len,
- u_char * statP, oid * name, size_t name_len)
- {
- static char *tmpvar;
- static size_t tmplen;
- struct pingCtlTable_data *StorageTmp = NULL;
- size_t newlen =
- name_len - (sizeof(pingCtlTable_variables_oid) / sizeof(oid) +
- 3 - 1);
- if ((StorageTmp =
- header_complex(pingCtlTableStorage, NULL,
- &name[sizeof(pingCtlTable_variables_oid) /
- sizeof(oid) + 3 - 1], &newlen, 1, NULL,
- NULL)) == NULL)
- return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */
- if (StorageTmp && StorageTmp->storageType == ST_READONLY) {
- return SNMP_ERR_NOTWRITABLE;
- }
- if (StorageTmp && StorageTmp->pingCtlRowStatus == RS_ACTIVE) {
- return SNMP_ERR_NOTWRITABLE;
- }
- switch (action) {
- case RESERVE1:
- if (var_val_type != ASN_OCTET_STR) {
- snmp_log(LOG_ERR,
- "write to pingCtlTargetAddress not ASN_OCTET_STRn");
- return SNMP_ERR_WRONGTYPE;
- }
- break;
- case RESERVE2:
- /*
- * memory reseveration, final preparation...
- */
- break;
- case FREE:
- /*
- * Release any resources that have been allocated
- */
- break;
- case ACTION:
- /*
- * The variable has been stored in long_ret for
- * you to use, and you have just been asked to do something with
- * it. Note that anything done here must be reversable in the UNDO case
- */
- tmpvar = StorageTmp->pingCtlTargetAddress;
- tmplen = StorageTmp->pingCtlTargetAddressLen;
- StorageTmp->pingCtlTargetAddress =
- (char *) malloc(var_val_len + 1);
- if (StorageTmp->pingCtlTargetAddress == NULL) {
- exit(1);
- }
- memcpy(StorageTmp->pingCtlTargetAddress, var_val, var_val_len);
- StorageTmp->pingCtlTargetAddress[var_val_len] = ' ';
- StorageTmp->pingCtlTargetAddressLen = var_val_len;
- break;
- case UNDO:
- /*
- * Back out any changes made in the ACTION case
- */
- SNMP_FREE(StorageTmp->pingCtlTargetAddress);
- StorageTmp->pingCtlTargetAddress = NULL;
- StorageTmp->pingCtlTargetAddress = tmpvar;
- StorageTmp->pingCtlTargetAddressLen = tmplen;
- break;
- case COMMIT:
- /*
- * Things are working well, so it's now safe to make the change
- * permanently. Make sure that anything done here can't fail!
- */
- SNMP_FREE(tmpvar);
- break;
- }
- return SNMP_ERR_NOERROR;
- }
- int
- write_pingCtlDataSize(int action,
- u_char * var_val,
- u_char var_val_type,
- size_t var_val_len,
- u_char * statP, oid * name, size_t name_len)
- {
- static size_t tmpvar;
- struct pingCtlTable_data *StorageTmp = NULL;
- static size_t tmplen;
- size_t newlen =
- name_len - (sizeof(pingCtlTable_variables_oid) / sizeof(oid) +
- 3 - 1);
- DEBUGMSGTL(("pingCtlTable",
- "pingCtlDataSize entering action=%d... n", action));
- if ((StorageTmp =
- header_complex(pingCtlTableStorage, NULL,
- &name[sizeof(pingCtlTable_variables_oid) /
- sizeof(oid) + 3 - 1], &newlen, 1, NULL,
- NULL)) == NULL)
- return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */
- if (StorageTmp && StorageTmp->storageType == ST_READONLY) {
- return SNMP_ERR_NOTWRITABLE;
- }
- if (StorageTmp && StorageTmp->pingCtlRowStatus == RS_ACTIVE) {
- return SNMP_ERR_NOTWRITABLE;
- }
- switch (action) {
- case RESERVE1:
- if (var_val_type != ASN_UNSIGNED) {
- snmp_log(LOG_ERR,
- "write to pingCtlDataSize not ASN_UNSIGNEDn");
- return SNMP_ERR_WRONGTYPE;
- }
- break;
- case RESERVE2:
- /*
- * memory reseveration, final preparation...
- */
- break;
- case FREE:
- /*
- * Release any resources that have been allocated
- */
- break;
- case ACTION:
- /*
- * The variable has been stored in objid for
- * you to use, and you have just been asked to do something with
- * it. Note that anything done here must be reversable in the UNDO case
- */
- tmpvar = StorageTmp->pingCtlDataSize;
- if ((*((long *) var_val)) >= 0 && (*((long *) var_val)) <= 65507)
- StorageTmp->pingCtlDataSize = *((long *) var_val);
- else
- StorageTmp->pingCtlDataSize = 56;
- break;
- case UNDO:
- /*
- * Back out any changes made in the ACTION case
- */
- StorageTmp->pingCtlDataSize = tmpvar;
- break;
- case COMMIT:
- /*
- * Things are working well, so it's now safe to make the change
- * permanently. Make sure that anything done here can't fail!
- */
- break;
- }
- return SNMP_ERR_NOERROR;
- }
- int
- write_pingCtlTimeOut(int action,
- u_char * var_val,
- u_char var_val_type,
- size_t var_val_len,
- u_char * statP, oid * name, size_t name_len)
- {
- static size_t tmpvar;
- struct pingCtlTable_data *StorageTmp = NULL;
- static size_t tmplen;
- size_t newlen =
- name_len - (sizeof(pingCtlTable_variables_oid) / sizeof(oid) +
- 3 - 1);
- DEBUGMSGTL(("pingCtlTable",
- "pingCtlTimeOut entering action=%d... n", action));
- if ((StorageTmp =
- header_complex(pingCtlTableStorage, NULL,
- &name[sizeof(pingCtlTable_variables_oid) /
- sizeof(oid) + 3 - 1], &newlen, 1, NULL,
- NULL)) == NULL)
- return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */
- if (StorageTmp && StorageTmp->storageType == ST_READONLY) {
- return SNMP_ERR_NOTWRITABLE;
- }
- if (StorageTmp && StorageTmp->pingCtlRowStatus == RS_ACTIVE) {
- return SNMP_ERR_NOTWRITABLE;
- }
- switch (action) {
- case RESERVE1:
- if (var_val_type != ASN_UNSIGNED) {
- snmp_log(LOG_ERR,
- "write to pingCtlDataSize not ASN_UNSIGNEDn");
- return SNMP_ERR_WRONGTYPE;
- }
- break;
- case RESERVE2:
- /*
- * memory reseveration, final preparation...
- */
- break;
- case FREE:
- /*
- * Release any resources that have been allocated
- */
- break;
- case ACTION:
- /*
- * The variable has been stored in objid for
- * you to use, and you have just been asked to do something with
- * it. Note that anything done here must be reversable in the UNDO case
- */
- tmpvar = StorageTmp->pingCtlTimeOut;
- if ((*((long *) var_val)) >= 1 && (*((long *) var_val)) <= 60)
- StorageTmp->pingCtlTimeOut = *((long *) var_val);
- else
- StorageTmp->pingCtlTimeOut = 3;
- break;
- case UNDO:
- /*
- * Back out any changes made in the ACTION case
- */
- StorageTmp->pingCtlTimeOut = tmpvar;
- break;
- case COMMIT:
- /*
- * Things are working well, so it's now safe to make the change
- * permanently. Make sure that anything done here can't fail!
- */
- break;
- }
- return SNMP_ERR_NOERROR;
- }
- int
- write_pingCtlProbeCount(int action,
- u_char * var_val,
- u_char var_val_type,
- size_t var_val_len,
- u_char * statP, oid * name, size_t name_len)
- {
- static size_t tmpvar;
- struct pingCtlTable_data *StorageTmp = NULL;
- static size_t tmplen;
- size_t newlen =
- name_len - (sizeof(pingCtlTable_variables_oid) / sizeof(oid) +
- 3 - 1);
- DEBUGMSGTL(("pingCtlTable",
- "pingCtlProbeCount entering action=%d... n", action));
- if ((StorageTmp =
- header_complex(pingCtlTableStorage, NULL,
- &name[sizeof(pingCtlTable_variables_oid) /
- sizeof(oid) + 3 - 1], &newlen, 1, NULL,
- NULL)) == NULL)
- return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */
- if (StorageTmp && StorageTmp->storageType == ST_READONLY) {
- return SNMP_ERR_NOTWRITABLE;
- }
- if (StorageTmp && StorageTmp->pingCtlRowStatus == RS_ACTIVE) {
- return SNMP_ERR_NOTWRITABLE;
- }
- switch (action) {
- case RESERVE1:
- if (var_val_type != ASN_UNSIGNED) {
- snmp_log(LOG_ERR,
- "write to pingCtlDataSize not ASN_UNSIGNEDn");
- return SNMP_ERR_WRONGTYPE;
- }
- break;
- case RESERVE2:
- /*
- * memory reseveration, final preparation...
- */
- break;
- case FREE:
- /*
- * Release any resources that have been allocated
- */
- break;
- case ACTION:
- /*
- * The variable has been stored in objid for
- * you to use, and you have just been asked to do something with
- * it. Note that anything done here must be reversable in the UNDO case
- */
- tmpvar = StorageTmp->pingCtlProbeCount;
- if ((*((long *) var_val)) >= 1 && (*((long *) var_val)) <= 15)
- StorageTmp->pingCtlProbeCount = *((long *) var_val);
- else
- StorageTmp->pingCtlProbeCount = 15;
- break;
- case UNDO:
- /*
- * Back out any changes made in the ACTION case
- */
- StorageTmp->pingCtlProbeCount = tmpvar;
- break;
- case COMMIT:
- /*
- * Things are working well, so it's now safe to make the change
- * permanently. Make sure that anything done here can't fail!
- */
- break;
- }
- return SNMP_ERR_NOERROR;
- }
- int
- write_pingCtlAdminStatus(int action,
- u_char * var_val,
- u_char var_val_type,
- size_t var_val_len,
- u_char * statP, oid * name, size_t name_len)
- {
- static size_t tmpvar;
- struct pingCtlTable_data *StorageTmp = NULL;
- static size_t tmplen;
- size_t newlen =
- name_len - (sizeof(pingCtlTable_variables_oid) / sizeof(oid) +
- 3 - 1);
- DEBUGMSGTL(("pingCtlTable",
- "pingCtlAdminStatus entering action=%d... n", action));
- if ((StorageTmp =
- header_complex(pingCtlTableStorage, NULL,
- &name[sizeof(pingCtlTable_variables_oid) /
- sizeof(oid) + 3 - 1], &newlen, 1, NULL,
- NULL)) == NULL)
- return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */
- if (StorageTmp && StorageTmp->storageType == ST_READONLY) {
- return SNMP_ERR_NOTWRITABLE;
- }
- switch (action) {
- case RESERVE1:
- if (var_val_type != ASN_INTEGER) {
- snmp_log(LOG_ERR,
- "write to pingCtlTargetAddressType not ASN_INTEGERn");
- return SNMP_ERR_WRONGTYPE;
- }
- break;
- case RESERVE2:
- /*
- * memory reseveration, final preparation...
- */
- break;
- case FREE:
- /*
- * Release any resources that have been allocated
- */
- break;
- case ACTION:
- /*
- * The variable has been stored in objid for
- * you to use, and you have just been asked to do something with
- * it. Note that anything done here must be reversable in the UNDO case
- */
- tmpvar = StorageTmp->pingCtlAdminStatus;
- StorageTmp->pingCtlAdminStatus = *((long *) var_val);
- break;
- case UNDO:
- /*
- * Back out any changes made in the ACTION case
- */
- StorageTmp->pingCtlAdminStatus = tmpvar;
- break;
- case COMMIT:
- /*
- * Things are working well, so it's now safe to make the change
- * permanently. Make sure that anything done here can't fail!
- */
- if (StorageTmp->pingCtlAdminStatus == 1
- && StorageTmp->pingCtlRowStatus == RS_ACTIVE) {
- StorageTmp->pingResults->pingResultsOperStatus = 1;
- modify_ResultsOper(StorageTmp, 1);
- if (StorageTmp->pingCtlFrequency != 0)
- StorageTmp->timer_id =
- snmp_alarm_register(StorageTmp->pingCtlFrequency,
- SA_REPEAT, run_ping, StorageTmp);
- else
- StorageTmp->timer_id = snmp_alarm_register(1, (int) NULL,
- run_ping,
- StorageTmp);
- } else if (StorageTmp->pingCtlAdminStatus == 2
- && StorageTmp->pingCtlRowStatus == RS_ACTIVE) {
- snmp_alarm_unregister(StorageTmp->timer_id);
- StorageTmp->pingResults->pingResultsOperStatus = 2;
- modify_ResultsOper(StorageTmp, 2);
- }
- break;
- }
- return SNMP_ERR_NOERROR;
- }
- int
- write_pingCtlDataFill(int action,
- u_char * var_val,
- u_char var_val_type,
- size_t var_val_len,
- u_char * statP, oid * name, size_t name_len)
- {
- static char *tmpvar;
- static size_t tmplen;
- struct pingCtlTable_data *StorageTmp = NULL;
- size_t newlen =
- name_len - (sizeof(pingCtlTable_variables_oid) / sizeof(oid) +
- 3 - 1);
- if ((StorageTmp =
- header_complex(pingCtlTableStorage, NULL,
- &name[sizeof(pingCtlTable_variables_oid) /
- sizeof(oid) + 3 - 1], &newlen, 1, NULL,
- NULL)) == NULL)
- return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */
- if (StorageTmp && StorageTmp->storageType == ST_READONLY) {
- return SNMP_ERR_NOTWRITABLE;
- }
- if (StorageTmp && StorageTmp->pingCtlRowStatus == RS_ACTIVE) {
- return SNMP_ERR_NOTWRITABLE;
- }
- switch (action) {
- case RESERVE1:
- if (var_val_type != ASN_OCTET_STR) {
- snmp_log(LOG_ERR,
- "write to pingCtlTargetAddress not ASN_OCTET_STRn");
- return SNMP_ERR_WRONGTYPE;
- }
- break;
- case RESERVE2:
- /*
- * memory reseveration, final preparation...
- */
- break;
- case FREE:
- /*
- * Release any resources that have been allocated
- */
- break;
- case ACTION:
- /*
- * The variable has been stored in long_ret for
- * you to use, and you have just been asked to do something with
- * it. Note that anything done here must be reversable in the UNDO case
- */
- tmpvar = StorageTmp->pingCtlDataFill;
- tmplen = StorageTmp->pingCtlDataFillLen;
- StorageTmp->pingCtlDataFill = (char *) malloc(var_val_len + 1);
- if (StorageTmp->pingCtlDataFill == NULL) {
- exit(1);
- }
- memcpy(StorageTmp->pingCtlDataFill, var_val, var_val_len);
- StorageTmp->pingCtlDataFill[var_val_len] = ' ';
- StorageTmp->pingCtlDataFillLen = var_val_len;
- break;
- case UNDO:
- /*
- * Back out any changes made in the ACTION case
- */
- SNMP_FREE(StorageTmp->pingCtlDataFill);
- StorageTmp->pingCtlDataFill = NULL;
- StorageTmp->pingCtlDataFill = tmpvar;
- StorageTmp->pingCtlDataFillLen = tmplen;
- break;
- case COMMIT:
- /*
- * Things are working well, so it's now safe to make the change
- * permanently. Make sure that anything done here can't fail!
- */
- SNMP_FREE(tmpvar);
- break;
- }
- return SNMP_ERR_NOERROR;
- }
- int
- write_pingCtlFrequency(int action,
- u_char * var_val,
- u_char var_val_type,
- size_t var_val_len,
- u_char * statP, oid * name, size_t name_len)
- {
- static size_t tmpvar;
- struct pingCtlTable_data *StorageTmp = NULL;
- static size_t tmplen;
- size_t newlen =
- name_len - (sizeof(pingCtlTable_variables_oid) / sizeof(oid) +
- 3 - 1);
- DEBUGMSGTL(("pingCtlTable",
- "pingCtlFrequency entering action=%d... n", action));
- if ((StorageTmp =
- header_complex(pingCtlTableStorage, NULL,
- &name[sizeof(pingCtlTable_variables_oid) /
- sizeof(oid) + 3 - 1], &newlen, 1, NULL,
- NULL)) == NULL)
- return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */
- if (StorageTmp && StorageTmp->storageType == ST_READONLY) {
- return SNMP_ERR_NOTWRITABLE;
- }
- if (StorageTmp && StorageTmp->pingCtlRowStatus == RS_ACTIVE) {
- return SNMP_ERR_NOTWRITABLE;
- }
- switch (action) {
- case RESERVE1:
- if (var_val_type != ASN_UNSIGNED) {
- snmp_log(LOG_ERR,
- "write to pingCtlDataSize not ASN_UNSIGNEDn");
- return SNMP_ERR_WRONGTYPE;
- }
- break;
- case RESERVE2:
- /*
- * memory reseveration, final preparation...
- */
- break;
- case FREE:
- /*
- * Release any resources that have been allocated
- */
- break;
- case ACTION:
- /*
- * The variable has been stored in objid for
- * you to use, and you have just been asked to do something with
- * it. Note that anything done here must be reversable in the UNDO case
- */
- tmpvar = StorageTmp->pingCtlFrequency;
- StorageTmp->pingCtlFrequency = *((long *) var_val);
- break;
- case UNDO:
- /*
- * Back out any changes made in the ACTION case
- */
- StorageTmp->pingCtlFrequency = tmpvar;
- break;
- case COMMIT:
- /*
- * Things are working well, so it's now safe to make the change
- * permanently. Make sure that anything done here can't fail!
- */
- break;
- }
- return SNMP_ERR_NOERROR;
- }