diff options
Diffstat (limited to 'agent/mibgroup/disman/expression')
-rw-r--r-- | agent/mibgroup/disman/expression/expErrorTable.c | 144 | ||||
-rw-r--r-- | agent/mibgroup/disman/expression/expErrorTable.h | 49 | ||||
-rw-r--r-- | agent/mibgroup/disman/expression/expExpressionTable.c | 1177 | ||||
-rw-r--r-- | agent/mibgroup/disman/expression/expExpressionTable.h | 139 | ||||
-rw-r--r-- | agent/mibgroup/disman/expression/expObjectTable.c | 1465 | ||||
-rw-r--r-- | agent/mibgroup/disman/expression/expObjectTable.h | 92 | ||||
-rw-r--r-- | agent/mibgroup/disman/expression/expValueTable.c | 873 | ||||
-rw-r--r-- | agent/mibgroup/disman/expression/expValueTable.h | 63 |
8 files changed, 4002 insertions, 0 deletions
diff --git a/agent/mibgroup/disman/expression/expErrorTable.c b/agent/mibgroup/disman/expression/expErrorTable.c new file mode 100644 index 0000000..1feb3ee --- /dev/null +++ b/agent/mibgroup/disman/expression/expErrorTable.c @@ -0,0 +1,144 @@ +/* + *Copyright(c)2004,Cisco URP imburses and Network Information Center in Beijing University of Posts and Telecommunications researches. + * + *All right reserved + * + *File Name: expErrorTable.c + *File Description: expErrorTable MIB operation. + * + *Current Version:1.0 + *Author:JianShun Tong + *Date:2004.8.20 + */ + + +/* + * This file was generated by mib2c and is intended for use as + * a mib module for the ucd-snmp snmpd agent. + */ + + +/* + * This should always be included first before anything else + */ +#include <net-snmp/net-snmp-config.h> +#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 + + +/* + * minimal include directives + */ +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +#include "header_complex.h" +#include "expErrorTable.h" +#include "expExpressionTable.h" + + + +/* + * expErrorTable_variables_oid: + * this is the top level oid that we want to register under. This + * is essentially a prefix, with the suffix appearing in the + * variable below. + */ + +oid expErrorTable_variables_oid[] = + { 1, 3, 6, 1, 2, 1, 90, 1, 2, 2 }; + +/* + * variable2 expErrorTable_variables: + */ + +struct variable2 expErrorTable_variables[] = { + /* + * magic number , variable type , ro/rw , callback fn , L, oidsuffix + */ +#define EXPERRORTIME 1 + {EXPERRORTIME, ASN_UNSIGNED, NETSNMP_OLDAPI_RONLY, + var_expErrorTable, 2, {1, 1}}, +#define EXPERRORINDEX 2 + {EXPERRORINDEX, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_expErrorTable, 2, {1, 2}}, +#define EXPERRORCODE 3 + {EXPERRORCODE, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_expErrorTable, 2, {1, 3}}, +#define EXPERRORINSTANCE 4 + {EXPERRORINSTANCE, ASN_OBJECT_ID, NETSNMP_OLDAPI_RONLY, + var_expErrorTable, 2, {1, 4}} +}; + +extern struct header_complex_index *expExpressionTableStorage; + + +void +init_expErrorTable(void) +{ + DEBUGMSGTL(("expErrorTable", "initializing... ")); + + + + /* + * register ourselves with the agent to handle our mib tree + */ + REGISTER_MIB("expErrorTable", + expErrorTable_variables, variable2, + expErrorTable_variables_oid); + + DEBUGMSGTL(("expErrorTable", "done.\n")); +} + + + +unsigned char * +var_expErrorTable(struct variable *vp, + oid * name, + size_t *length, + int exact, size_t *var_len, WriteMethod ** write_method) +{ + struct expExpressionTable_data *StorageTmp = NULL; + + DEBUGMSGTL(("expErrorTable", "var_expErrorTable: Entering... \n")); + /* + * this assumes you have registered all your data properly + */ + if ((StorageTmp = + header_complex(expExpressionTableStorage, vp, name, length, exact, + var_len, write_method)) == NULL) + return NULL; + + /* + * this is where we do the value assignments for the mib results. + */ + switch (vp->magic) { + + case EXPERRORTIME: + *var_len = sizeof(StorageTmp->expErrorTime); + return (u_char *) & StorageTmp->expErrorTime; + + case EXPERRORINDEX: + *var_len = sizeof(StorageTmp->expErrorIndex); + return (u_char *) & StorageTmp->expErrorIndex; + + case EXPERRORCODE: + *var_len = sizeof(StorageTmp->expErrorCode); + return (u_char *) & StorageTmp->expErrorCode; + + case EXPERRORINSTANCE: + *var_len = StorageTmp->expErrorInstanceLen * sizeof(oid); + return (u_char *) StorageTmp->expErrorInstance; + } + + return NULL; +} diff --git a/agent/mibgroup/disman/expression/expErrorTable.h b/agent/mibgroup/disman/expression/expErrorTable.h new file mode 100644 index 0000000..5399159 --- /dev/null +++ b/agent/mibgroup/disman/expression/expErrorTable.h @@ -0,0 +1,49 @@ +/* + *Copyright(c)2004,Cisco URP imburses and Network Information Center in Beijing University of Posts and Telecommunications researches. + * + *All right reserved + * + *File Name:expErrorTable.h + *File Description: head file. + * + *Current Version:1.0 + *Author:JianShun Tong + *Date:2004.8.20 + */ + + +/* + * This file was generated by mib2c and is intended for use as a mib module + * for the ucd-snmp snmpd agent. + */ + + +#ifndef _MIBGROUP_EXPERRORTALBE_H +#define _MIBGROUP_EXPERRORTALBE_H + + + +/* + * we may use header_complex from the header_complex module + */ +config_require(header_complex) + + + struct expErrorTable_data { + + unsigned long expErrorTime; + long expErrorIndex; + long expErrorCode; + oid *expErrorInstance; + size_t expErrorInstanceLen; + }; + + /* + * function prototypes + */ + void init_expErrorTable(void); + FindVarMethod var_expErrorTable; + + + +#endif /* _MIBGROUP_EXPERRORTALBE_H */ diff --git a/agent/mibgroup/disman/expression/expExpressionTable.c b/agent/mibgroup/disman/expression/expExpressionTable.c new file mode 100644 index 0000000..ce3b0db --- /dev/null +++ b/agent/mibgroup/disman/expression/expExpressionTable.c @@ -0,0 +1,1177 @@ +/* + *Copyright(c)2004,Cisco URP imburses and Network Information Center in Beijing University of Posts and Telecommunications researches. + * + *All right reserved + * + *File Name: expExpressionTable.c + *File Description: expExpressionTable MIB operation. + * + *Current Version:1.0 + *Author:JianShun Tong + *Date:2004.8.20 + */ + +/* + * This file was generated by mib2c and is intended for use as + * a mib module for the ucd-snmp snmpd agent. + */ + + +/* + * This should always be included first before anything else + */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-features.h> +#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 + + +/* + * minimal include directives + */ +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> +#include "header_complex.h" +#include "expErrorTable.h" +#include "expExpressionTable.h" +#include "expObjectTable.h" +#include "expValueTable.h" + +netsnmp_feature_require(tdomain_support) +#ifndef NETSNMP_NO_WRITE_SUPPORT +netsnmp_feature_require(header_complex_find_entry) +#endif /* NETSNMP_NO_WRITE_SUPPORT */ + +/* + * expExpressionTable_variables_oid: + * this is the top level oid that we want to register under. This + * is essentially a prefix, with the suffix appearing in the + * variable below. + */ + +oid expExpressionTable_variables_oid[] = + { 1, 3, 6, 1, 2, 1, 90, 1, 2, 1 }; + +/* + * variable2 expExpressionTable_variables: + */ + +struct variable2 expExpressionTable_variables[] = { + /* + * magic number , variable type , ro/rw , callback fn , L, oidsuffix + */ +#define EXPEXPRESSION 3 + {EXPEXPRESSION, ASN_OCTET_STR, NETSNMP_OLDAPI_RWRITE, + var_expExpressionTable, 2, {1, 3}}, +#define EXPEXPRESSIONVALUETYPE 4 + {EXPEXPRESSIONVALUETYPE, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE, + var_expExpressionTable, 2, {1, 4}}, +#define EXPEXPRESSIONCOMMENT 5 + {EXPEXPRESSIONCOMMENT, ASN_OCTET_STR, NETSNMP_OLDAPI_RWRITE, + var_expExpressionTable, 2, {1, 5}}, +#define EXPEXPRESSIONDELTALNTERVAL 6 + {EXPEXPRESSIONDELTALNTERVAL, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE, + var_expExpressionTable, 2, {1, 6}}, +#define EXPEXPRESSIONPREFIX 7 + {EXPEXPRESSIONPREFIX, ASN_OBJECT_ID, NETSNMP_OLDAPI_RONLY, + var_expExpressionTable, 2, {1, 7}}, +#define EXPEXPRESSIONERRORS 8 + {EXPEXPRESSIONERRORS, ASN_UNSIGNED, NETSNMP_OLDAPI_RONLY, + var_expExpressionTable, 2, {1, 8}}, +#define EXPEXPRESSIONENTRYSTATUS 9 + {EXPEXPRESSIONENTRYSTATUS, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE, + var_expExpressionTable, 2, {1, 9}} +}; + +/* + * global storage of our data, saved in and configured by header_complex() + */ + +struct header_complex_index *expExpressionTableStorage = NULL; +extern struct header_complex_index *expObjectTableStorage; +extern struct header_complex_index *expValueTableStorage; + +oid mmTimeInstance[] = { 1, 3, 6, 1, 2, 1, 1, 3, 0 }; + +/* + * init_expExpressionTable(): + * Initialization routine. This is called when the agent starts up. + * At a minimum, registration of your variables should take place here. + */ +void +init_expExpressionTable(void) +{ + + + /* + * register ourselves with the agent to handle our mib tree + */ + REGISTER_MIB("expExpressionTable", expExpressionTable_variables, + variable2, expExpressionTable_variables_oid); + + /* + * register our config handler(s) to deal with registrations + */ + snmpd_register_config_handler("expExpressionTable", + parse_expExpressionTable, NULL, NULL); + + + snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA, + store_expExpressionTable, NULL); + + + DEBUGMSGTL(("expExpressionTable", "done.\n")); +} + +struct expExpressionTable_data * +create_expExpressionTable_data(void) +{ + struct expExpressionTable_data *StorageNew; + StorageNew = SNMP_MALLOC_STRUCT(expExpressionTable_data); + /* + * fill in default row values here into StorageNew + */ + /* + * fill in values for all tables (even if not + * appropriate), since its easier to do here than anywhere + * else + */ + + StorageNew->expExpression = strdup(""); + StorageNew->expExpressionValueType = EXPEXPRESSION_COUNTER32; + StorageNew->expExpressionComment = strdup(""); + StorageNew->expExpressionDeltaInterval = 0; + StorageNew->expExpressionPrefix = calloc(1, sizeof(oid) * 2); /* 0.0 */ + StorageNew->expExpressionPrefixLen = 2; + StorageNew->hc_ObjectTableStorage = NULL; + StorageNew->hc_ValueTableStorage = NULL; + StorageNew->storageType = ST_NONVOLATILE; + return StorageNew; +} + +int +expExpressionTable_add(struct expExpressionTable_data *thedata) +{ + netsnmp_variable_list *vars = NULL; + + + DEBUGMSGTL(("expExpressionTable", "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->expExpressionOwner, thedata->expExpressionOwnerLen); /* expExpressionOwner */ + snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->expExpressionName, thedata->expExpressionNameLen); /* expExpressionName */ + + header_complex_add_data(&expExpressionTableStorage, vars, thedata); + DEBUGMSGTL(("expExpressionTable", "registered an entry\n")); + + + DEBUGMSGTL(("expExpressionTable", "done.\n")); + return SNMPERR_SUCCESS; +} + + + +/* + * parse_mteTriggerTable(): + * parses .conf file entries needed to configure the mib. + */ +void +parse_expExpressionTable(const char *token, char *line) +{ + size_t tmpint; + oid *tmpoid = NULL; + struct expExpressionTable_data *StorageTmp = + SNMP_MALLOC_STRUCT(expExpressionTable_data); + + DEBUGMSGTL(("expExpressionTable", "parsing config... ")); + + if (StorageTmp == NULL) { + config_perror("malloc failure"); + return; + } + + line = + read_config_read_data(ASN_OCTET_STR, line, + &StorageTmp->expExpressionOwner, + &StorageTmp->expExpressionOwnerLen); + if (StorageTmp->expExpressionOwner == NULL) { + config_perror("invalid specification for expExpressionOwner"); + return; + } + + line = + read_config_read_data(ASN_OCTET_STR, line, + &StorageTmp->expExpressionName, + &StorageTmp->expExpressionNameLen); + if (StorageTmp->expExpressionName == NULL) { + config_perror("invalid specification for expExpressionName"); + return; + } + + line = + read_config_read_data(ASN_OCTET_STR, line, + &StorageTmp->expExpression, + &StorageTmp->expExpressionLen); + + line = + read_config_read_data(ASN_INTEGER, line, + &StorageTmp->expExpressionValueType, + &tmpint); + + line = + read_config_read_data(ASN_OCTET_STR, line, + &StorageTmp->expExpressionComment, + &StorageTmp->expExpressionCommentLen); + + line = + read_config_read_data(ASN_INTEGER, line, + &StorageTmp->expExpressionDeltaInterval, + &tmpint); + + line = + read_config_read_data(ASN_OBJECT_ID, line, + &StorageTmp->expExpressionPrefix, + &StorageTmp->expExpressionPrefixLen); + + line = + read_config_read_data(ASN_UNSIGNED, line, + &StorageTmp->expExpressionErrors, &tmpint); + + line = + read_config_read_data(ASN_INTEGER, line, + &StorageTmp->expExpressionEntryStatus, + &tmpint); + + line = + read_config_read_data(ASN_INTEGER, line, + &StorageTmp->have_copied_auth_info, &tmpint); + if (StorageTmp->have_copied_auth_info) { + line = + read_config_read_data(ASN_INTEGER, line, + &StorageTmp->pdu_version, &tmpint); + line = + read_config_read_data(ASN_INTEGER, line, + &StorageTmp->pdu_securityModel, &tmpint); + line = + read_config_read_data(ASN_INTEGER, line, + &StorageTmp->pdu_securityLevel, &tmpint); + line = + read_config_read_data(ASN_OBJECT_ID, line, &tmpoid, &tmpint); + if (!netsnmp_tdomain_support + (tmpoid, tmpint, &StorageTmp->pdu_tDomain, + &StorageTmp->pdu_tDomainLen)) { + config_perror + ("unsupported transport domain for mteTriggerEntry"); + return; + } + if (tmpoid != NULL) { + free(tmpoid); + } + + /* + * can be NULL? Yes. + */ + line = read_config_read_data(ASN_OCTET_STR, line, + &(StorageTmp->pdu_transport), + &StorageTmp->pdu_transportLen); + + line = + read_config_read_data(ASN_OCTET_STR, line, + &StorageTmp->pdu_community, + &StorageTmp->pdu_community_len); + if (StorageTmp->pdu_community == NULL) { + config_perror("invalid specification for pdu_community"); + return; + } + line = + read_config_read_data(ASN_OCTET_STR, line, + &StorageTmp->pdu_securityName, + &StorageTmp->pdu_securityNameLen); + if (StorageTmp->pdu_securityName == NULL) { + config_perror("invalid specification for pdu_securityName"); + return; + } + } + StorageTmp->storageType = ST_NONVOLATILE; + expExpressionTable_add(StorageTmp); + + + DEBUGMSGTL(("expExpressionTable", "done.\n")); +} + + +/* + * store_expExpressionTable(): + * stores .conf file entries needed to configure the mib. + */ +int +store_expExpressionTable(int majorID, int minorID, void *serverarg, + void *clientarg) +{ + char line[SNMP_MAXBUF]; + char *cptr; + size_t tmpint; + struct expExpressionTable_data *StorageTmp; + struct header_complex_index *hcindex; + + DEBUGMSGTL(("expExpressionTable", "storing data... ")); + + for (hcindex = expExpressionTableStorage; hcindex != NULL; + hcindex = hcindex->next) { + StorageTmp = (struct expExpressionTable_data *) hcindex->data; + + + if (StorageTmp->storageType == ST_NONVOLATILE) { + + memset(line, 0, sizeof(line)); + strcat(line, "expExpressionTable "); + cptr = line + strlen(line); + /* + * expExpressionTable + */ + + + cptr = + read_config_store_data(ASN_OCTET_STR, cptr, + &StorageTmp->expExpressionOwner, + &StorageTmp->expExpressionOwnerLen); + cptr = + read_config_store_data(ASN_OCTET_STR, cptr, + &StorageTmp->expExpressionName, + &StorageTmp->expExpressionNameLen); + cptr = + read_config_store_data(ASN_OCTET_STR, cptr, + &StorageTmp->expExpression, + &StorageTmp->expExpressionLen); + cptr = + read_config_store_data(ASN_INTEGER, cptr, + &StorageTmp->expExpressionValueType, + &tmpint); + cptr = + read_config_store_data(ASN_OCTET_STR, cptr, + &StorageTmp->expExpressionComment, + &StorageTmp-> + expExpressionCommentLen); + cptr = + read_config_store_data(ASN_INTEGER, cptr, + &StorageTmp-> + expExpressionDeltaInterval, + &tmpint); + cptr = + read_config_store_data(ASN_OBJECT_ID, cptr, + &StorageTmp->expExpressionPrefix, + &StorageTmp-> + expExpressionPrefixLen); + cptr = + read_config_store_data(ASN_UNSIGNED, cptr, + &StorageTmp->expExpressionErrors, + &tmpint); + cptr = + read_config_store_data(ASN_INTEGER, cptr, + &StorageTmp-> + expExpressionEntryStatus, &tmpint); + cptr = + read_config_store_data(ASN_INTEGER, cptr, + &StorageTmp->have_copied_auth_info, + &tmpint); + if (StorageTmp->have_copied_auth_info) { + cptr = + read_config_store_data(ASN_INTEGER, cptr, + &StorageTmp->pdu_version, + &tmpint); + cptr = + read_config_store_data(ASN_INTEGER, cptr, + &StorageTmp->pdu_securityModel, + &tmpint); + cptr = + read_config_store_data(ASN_INTEGER, cptr, + &StorageTmp->pdu_securityLevel, + &tmpint); + cptr = + read_config_store_data(ASN_OBJECT_ID, cptr, + (void *) (&StorageTmp-> + pdu_tDomain), + &StorageTmp->pdu_tDomainLen); + cptr = + read_config_store_data(ASN_OCTET_STR, cptr, + &StorageTmp->pdu_transport, + &StorageTmp->pdu_transportLen); + cptr = + read_config_store_data(ASN_OCTET_STR, cptr, + &StorageTmp->pdu_community, + &StorageTmp->pdu_community_len); + cptr = + read_config_store_data(ASN_OCTET_STR, cptr, + &StorageTmp->pdu_securityName, + &StorageTmp-> + pdu_securityNameLen); + } + + + snmpd_store_config(line); + } + } + DEBUGMSGTL(("expExpressionTable", "storage done.\n")); + return SNMPERR_SUCCESS; +} + + + + +/* + * var_expExpressionTable(): + * Handle this table separately from the scalar value case. + * The workings of this are basically the same as for var_expExpressionTable above. + */ +unsigned char * +var_expExpressionTable(struct variable *vp, + oid * name, + size_t *length, + int exact, + size_t *var_len, WriteMethod ** write_method) +{ + struct expExpressionTable_data *StorageTmp = NULL; + + DEBUGMSGTL(("expExpressionTable", + "var_expExpressionTable: Entering... \n")); + + /* + * this assumes you have registered all your data properly + */ + if ((StorageTmp = + header_complex(expExpressionTableStorage, vp, name, length, exact, + var_len, write_method)) == NULL) { + if (vp->magic == EXPEXPRESSIONENTRYSTATUS) + *write_method = write_expExpressionEntryStatus; + return NULL; + } + + + switch (vp->magic) { + + + case EXPEXPRESSION: + *write_method = write_expExpression; + *var_len = StorageTmp->expExpressionLen; + return (u_char *) StorageTmp->expExpression; + + case EXPEXPRESSIONVALUETYPE: + *write_method = write_expExpressionValueType; + *var_len = sizeof(StorageTmp->expExpressionValueType); + return (u_char *) & StorageTmp->expExpressionValueType; + + case EXPEXPRESSIONCOMMENT: + *write_method = write_expExpressionComment; + *var_len = StorageTmp->expExpressionCommentLen; + return (u_char *) StorageTmp->expExpressionComment; + + case EXPEXPRESSIONDELTALNTERVAL: + *write_method = write_expExpressionDeltaInterval; + *var_len = sizeof(StorageTmp->expExpressionDeltaInterval); + return (u_char *) & StorageTmp->expExpressionDeltaInterval; + + case EXPEXPRESSIONPREFIX: + *var_len = StorageTmp->expExpressionPrefixLen * sizeof(oid); + return (u_char *) StorageTmp->expExpressionPrefix; + + case EXPEXPRESSIONERRORS: + *var_len = sizeof(StorageTmp->expExpressionErrors); + return (u_char *) & StorageTmp->expExpressionErrors; + + case EXPEXPRESSIONENTRYSTATUS: + *write_method = write_expExpressionEntryStatus; + *var_len = sizeof(StorageTmp->expExpressionEntryStatus); + return (u_char *) & StorageTmp->expExpressionEntryStatus; + + default: + ERROR_MSG(""); + + } + return NULL; +} + + + +int +write_expExpression(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; + struct expExpressionTable_data *StorageTmp = NULL; + static size_t tmplen; + size_t newlen = + name_len - + (sizeof(expExpressionTable_variables_oid) / sizeof(oid) + 3 - 1); + + + DEBUGMSGTL(("expExpressionTable", + "write_expExpression entering action=%d... \n", action)); + if ((StorageTmp = + header_complex(expExpressionTableStorage, NULL, + &name[sizeof(expExpressionTable_variables_oid) / + sizeof(oid) + 3 - 1], &newlen, 1, NULL, + NULL)) == NULL) + return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */ + + + switch (action) { + case RESERVE1: + if (var_val_type != ASN_OCTET_STR) { + snmp_log(LOG_ERR, + "write to expExpression not ASN_OCTET_STR\n"); + return SNMP_ERR_WRONGTYPE; + } + if (StorageTmp->storageType != ST_NONVOLATILE) + return SNMP_ERR_NOTWRITABLE; + + 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 string 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->expExpression; + tmplen = StorageTmp->expExpressionLen; + memdup((u_char **) & StorageTmp->expExpression, var_val, + var_val_len); + StorageTmp->expExpressionLen = var_val_len; + break; + + + case UNDO: + /* + * Back out any changes made in the ACTION case + */ + SNMP_FREE(StorageTmp->expExpression); + StorageTmp->expExpression = tmpvar; + StorageTmp->expExpressionLen = 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); + snmp_store_needed(NULL); + break; + } + return SNMP_ERR_NOERROR; + +} + + + +int +write_expExpressionValueType(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 int tmpvar; + struct expExpressionTable_data *StorageTmp = NULL; + size_t newlen = + name_len - + (sizeof(expExpressionTable_variables_oid) / sizeof(oid) + 3 - 1); + + + DEBUGMSGTL(("expExpressionTable", + "write_expExpressionValueType entering action=%d... \n", + action)); + if ((StorageTmp = + header_complex(expExpressionTableStorage, NULL, + &name[sizeof(expExpressionTable_variables_oid) / + sizeof(oid) + 3 - 1], &newlen, 1, NULL, + NULL)) == NULL) + return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */ + + + switch (action) { + case RESERVE1: + if (var_val_type != ASN_INTEGER) { + snmp_log(LOG_ERR, + "write to expExpressionValueType not ASN_INTEGER\n"); + return SNMP_ERR_WRONGTYPE; + } + if (StorageTmp->storageType != ST_NONVOLATILE) + return SNMP_ERR_NOTWRITABLE; + + 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 string 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->expExpressionValueType; + StorageTmp->expExpressionValueType = *((long *) var_val); + break; + + + case UNDO: + /* + * Back out any changes made in the ACTION case + */ + StorageTmp->expExpressionValueType = 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! + */ + snmp_store_needed(NULL); + break; + } + return SNMP_ERR_NOERROR; + +} + + +int +write_expExpressionComment(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; + struct expExpressionTable_data *StorageTmp = NULL; + static size_t tmplen; + size_t newlen = + name_len - + (sizeof(expExpressionTable_variables_oid) / sizeof(oid) + 3 - 1); + + + DEBUGMSGTL(("expExpressionTable", + "write_expExpression entering action=%d... \n", action)); + if ((StorageTmp = + header_complex(expExpressionTableStorage, NULL, + &name[sizeof(expExpressionTable_variables_oid) / + sizeof(oid) + 3 - 1], &newlen, 1, NULL, + NULL)) == NULL) + return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */ + + + switch (action) { + case RESERVE1: + if (var_val_type != ASN_OCTET_STR) { + snmp_log(LOG_ERR, + "write to expExpressionComment not ASN_OCTET_STR\n"); + return SNMP_ERR_WRONGTYPE; + } + if (StorageTmp->storageType != ST_NONVOLATILE) + return SNMP_ERR_NOTWRITABLE; + + 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 string 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->expExpressionComment; + tmplen = StorageTmp->expExpressionCommentLen; + memdup((u_char **) & StorageTmp->expExpressionComment, var_val, + var_val_len); + StorageTmp->expExpressionCommentLen = var_val_len; + break; + + + case UNDO: + /* + * Back out any changes made in the ACTION case + */ + SNMP_FREE(StorageTmp->expExpressionComment); + StorageTmp->expExpressionComment = tmpvar; + StorageTmp->expExpressionCommentLen = 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); + snmp_store_needed(NULL); + break; + } + return SNMP_ERR_NOERROR; + +} + + +int +write_expExpressionDeltaInterval(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 int tmpvar; + struct expExpressionTable_data *StorageTmp = NULL; + size_t newlen = + name_len - + (sizeof(expExpressionTable_variables_oid) / sizeof(oid) + 3 - 1); + + + DEBUGMSGTL(("expExpressionTable", + "write_expExpressionValueType entering action=%d... \n", + action)); + if ((StorageTmp = + header_complex(expExpressionTableStorage, NULL, + &name[sizeof(expExpressionTable_variables_oid) / + sizeof(oid) + 3 - 1], &newlen, 1, NULL, + NULL)) == NULL) + return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */ + + + switch (action) { + case RESERVE1: + if (var_val_type != ASN_INTEGER) { + snmp_log(LOG_ERR, + "write to expExpressionDeltalnterval not ASN_INTEGER\n"); + return SNMP_ERR_WRONGTYPE; + } + if (StorageTmp->storageType != ST_NONVOLATILE) + return SNMP_ERR_NOTWRITABLE; + + 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 string 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->expExpressionDeltaInterval; + StorageTmp->expExpressionDeltaInterval = *((long *) var_val); + break; + + + case UNDO: + /* + * Back out any changes made in the ACTION case + */ + StorageTmp->expExpressionDeltaInterval = 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! + */ + snmp_store_needed(NULL); + break; + } + return SNMP_ERR_NOERROR; + +} + + +int +write_expExpressionEntryStatus(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) +{ + struct expExpressionTable_data *StorageTmp = NULL; + static struct expExpressionTable_data *StorageNew, *StorageDel; + size_t newlen = + name_len - + (sizeof(expExpressionTable_variables_oid) / sizeof(oid) + 3 - 1); + static int old_value; + int set_value; + static netsnmp_variable_list *vars, *vp; + struct header_complex_index *hciptr; + + StorageTmp = + header_complex(expExpressionTableStorage, NULL, + &name[sizeof(expExpressionTable_variables_oid) / + sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL); + + + + + if (var_val_type != ASN_INTEGER || var_val == NULL) { + snmp_log(LOG_ERR, + "write to expExpressionEntryStatus not ASN_INTEGER\n"); + return SNMP_ERR_WRONGTYPE; + } + set_value = *((long *) var_val); + + + /* + * check legal range, and notReady is reserved for us, not a user + */ + if (set_value < 1 || set_value > 6 || set_value == RS_NOTREADY) + return SNMP_ERR_INCONSISTENTVALUE; + + + switch (action) { + case RESERVE1: + /* + * stage one: test validity + */ + if (StorageTmp == NULL) { + /* + * create the row now? + */ + + + /* + * ditch illegal values now + */ + if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE) + return SNMP_ERR_INCONSISTENTVALUE; + + + /* + * destroying a non-existent row is actually legal + */ + if (set_value == RS_DESTROY) { + return SNMP_ERR_NOERROR; + } + + + /* + * illegal creation values + */ + if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE) { + return SNMP_ERR_INCONSISTENTVALUE; + } + } else { + /* + * row exists. Check for a valid state change + */ + if (set_value == RS_CREATEANDGO + || set_value == RS_CREATEANDWAIT) { + /* + * can't create a row that exists + */ + return SNMP_ERR_INCONSISTENTVALUE; + } + + if (StorageTmp->expExpressionEntryStatus == RS_ACTIVE && + set_value != RS_DESTROY) { + /* + * "Once made active an entry may not be modified except to + * delete it." XXX: doesn't this in fact apply to ALL + * columns of the table and not just this one? + */ + return SNMP_ERR_INCONSISTENTVALUE; + } + if (StorageTmp->storageType != ST_NONVOLATILE) + return SNMP_ERR_NOTWRITABLE; + } + break; + + + + + case RESERVE2: + /* + * memory reseveration, final preparation... + */ + if (StorageTmp == NULL) { + /* + * creation + */ + vars = NULL; + + + snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, NULL, 0); /* expExpressionOwner */ + snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, NULL, 0); /* expExpressionName */ + + + + if (header_complex_parse_oid + (& + (name + [sizeof(expExpressionTable_variables_oid) / sizeof(oid) + + 2]), newlen, vars) != SNMPERR_SUCCESS) { + /* + * XXX: free, zero vars + */ + return SNMP_ERR_INCONSISTENTNAME; + } + vp = vars; + + + StorageNew = create_expExpressionTable_data(); + + StorageNew->expExpressionOwner = malloc(vp->val_len + 1); + memcpy(StorageNew->expExpressionOwner, vp->val.string, + vp->val_len); + StorageNew->expExpressionOwner[vp->val_len] = '\0'; + StorageNew->expExpressionOwnerLen = vp->val_len; + + vp = vp->next_variable; + StorageNew->expExpressionName = malloc(vp->val_len + 1); + memcpy(StorageNew->expExpressionName, vp->val.string, + vp->val_len); + StorageNew->expExpressionName[vp->val_len] = '\0'; + StorageNew->expExpressionNameLen = vp->val_len; + + vp = vp->next_variable; + + StorageNew->expExpressionEntryStatus = set_value; + + } + + + break; + + + + + case FREE: + /* + * XXX: free, zero vars + */ + /* + * Release any resources that have been allocated + */ + break; + + + + + case ACTION: + /* + * The variable has been stored in set_value 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 + */ + + + if (StorageTmp == NULL) { + /* + * row creation, so add it + */ + if (StorageNew != NULL) + expExpressionTable_add(StorageNew); + /* + * XXX: ack, and if it is NULL? + */ + } else if (set_value != RS_DESTROY) { + /* + * set the flag? + */ + old_value = StorageTmp->expExpressionEntryStatus; + StorageTmp->expExpressionEntryStatus = *((long *) var_val); + } else { + /* + * destroy... extract it for now + */ + hciptr = + header_complex_find_entry(expExpressionTableStorage, + StorageTmp); + StorageDel = + header_complex_extract_entry(&expExpressionTableStorage, + hciptr); + } + break; + + + + + case UNDO: + /* + * Back out any changes made in the ACTION case + */ + if (StorageTmp == NULL) { + /* + * row creation, so remove it again + */ + hciptr = + header_complex_find_entry(expExpressionTableStorage, + StorageTmp); + StorageDel = + header_complex_extract_entry(&expExpressionTableStorage, + hciptr); + /* + * XXX: free it + */ + } else if (StorageDel != NULL) { + /* + * row deletion, so add it again + */ + expExpressionTable_add(StorageDel); + } else { + StorageTmp->expExpressionEntryStatus = old_value; + } + 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 (StorageDel != NULL) { + StorageDel = 0; + /* + * XXX: free it, its dead + */ + } else { + if (StorageTmp + && StorageTmp->expExpressionEntryStatus == + RS_CREATEANDGO) { + StorageTmp->expExpressionEntryStatus = RS_ACTIVE; + } else if (StorageTmp && + StorageTmp->expExpressionEntryStatus == + RS_CREATEANDWAIT) { + StorageTmp->expExpressionEntryStatus = RS_NOTINSERVICE; + } + } + if (StorageTmp && + StorageTmp->expExpressionEntryStatus == RS_ACTIVE && + !StorageTmp->have_copied_auth_info) { + + netsnmp_agent_session *asp = + netsnmp_get_current_agent_session(); + netsnmp_pdu *pdu = NULL; + + if (!asp) { + snmp_log(LOG_ERR, + "snmpTriggerTable: can't get master session for authentication params\n"); + } else { + pdu = asp->orig_pdu; + if (!pdu) { + snmp_log(LOG_ERR, + "snmpTriggerTable: can't get master pdu for authentication params\n"); + } + } + + if (pdu) { + DEBUGMSGTL(("expExpressionTest", + "copying PDU auth info\n")); + StorageTmp->pdu_version = pdu->version; + StorageTmp->pdu_securityModel = pdu->securityModel; + StorageTmp->pdu_securityLevel = pdu->securityLevel; + StorageTmp->pdu_tDomain = pdu->tDomain; + StorageTmp->pdu_tDomainLen = pdu->tDomainLen; + if (pdu->transport_data != NULL) { + StorageTmp->pdu_transport = + malloc(pdu->transport_data_length); + memcpy(StorageTmp->pdu_transport, pdu->transport_data, + pdu->transport_data_length); + } + StorageTmp->pdu_transportLen = pdu->transport_data_length; + if (pdu->community) { + StorageTmp->pdu_community = + calloc(1, pdu->community_len + 1); + memcpy(StorageTmp->pdu_community, pdu->community, + pdu->community_len); + StorageTmp->pdu_community_len = pdu->community_len; + } else { + StorageTmp->pdu_community = NULL; + StorageTmp->pdu_community_len = 0; + } + if (pdu->securityName) { + StorageTmp->pdu_securityName = + calloc(1, pdu->securityNameLen + 1); + memcpy(StorageTmp->pdu_securityName, pdu->securityName, + pdu->securityNameLen); + StorageTmp->pdu_securityNameLen = pdu->securityNameLen; + } else { + StorageTmp->pdu_securityName = NULL; + StorageTmp->pdu_securityNameLen = 0; + } + StorageTmp->have_copied_auth_info = 1; + } + } + snmp_store_needed(NULL); + break; + } + return SNMP_ERR_NOERROR; +} diff --git a/agent/mibgroup/disman/expression/expExpressionTable.h b/agent/mibgroup/disman/expression/expExpressionTable.h new file mode 100644 index 0000000..6c139f8 --- /dev/null +++ b/agent/mibgroup/disman/expression/expExpressionTable.h @@ -0,0 +1,139 @@ +/* + *Copyright(c)2004,Cisco URP imburses and Network Information Center in Beijing University of Posts and Telecommunications researches. + * + *All right reserved + * + *File Name: expExpressionTable.h + *File Description: head file. + * + *Current Version:1.0 + *Author:JianShun Tong + *Date:2004.8.20 + */ + +/* + * This file was generated by mib2c and is intended for use as a mib module + * for the ucd-snmp snmpd agent. + */ + + +#ifndef _MIBGROUP_EXPEXPRESSIONTABLE_H +#define _MIBGROUP_EXPEXPRESSIONTABLE_H + +/* + * we may use header_complex from the header_complex module + */ + + +config_require(header_complex) + + /* + * our storage structure(s) + */ + struct expExpressionTable_data { + + /* + * expExpressionTable + */ + char *expExpressionOwner; + size_t expExpressionOwnerLen; + char *expExpressionName; + size_t expExpressionNameLen; + char *expExpression; + size_t expExpressionLen; + long expExpressionValueType; + char *expExpressionComment; + size_t expExpressionCommentLen; + long expExpressionDeltaInterval; + oid *expExpressionPrefix; + size_t expExpressionPrefixLen; + unsigned long expExpressionErrors; + long expExpressionEntryStatus; + + /* + * expError Table + */ + unsigned long expErrorTime; + long expErrorIndex; + long expErrorCode; + oid *expErrorInstance; + size_t expErrorInstanceLen; + + /* + * internal variables + */ + int storageType; + + /* + * other tables storage + */ + struct header_complex_index *hc_ObjectTableStorage; + struct header_complex_index *hc_ValueTableStorage; + + + + /* + * pdu auth contents + */ + long have_copied_auth_info; + long pdu_version; + long pdu_securityModel; + long pdu_securityLevel; + void *pdu_transport; + size_t pdu_transportLen; + const oid *pdu_tDomain; + size_t pdu_tDomainLen; + u_char *pdu_community; + size_t pdu_community_len; + char *pdu_contextName; + size_t pdu_contextNameLen; + char *pdu_securityName; + size_t pdu_securityNameLen; + }; + + + +#define EXPEXPRESSION_COUNTER32 1 +#define EXPEXPRESSION_UNSIGNED32 2 +#define EXPEXPRESSION_TIMETICKS 3 +#define EXPEXPRESSION_INTEGER32 4 +#define EXPEXPRESSION_IPADDRESS 5 +#define EXPEXPRESSION_OCTETSTRING 6 +#define EXPEXPRESSION_OBJECTID 7 +#define EXPEXPRESSION_COUNTER64 8 + + +#define EXP_FAILURE_INVALIDSYNTAX 1 +#define EXP_FAILURE_UNDEFINEOBJECTINDEX 2 +#define EXP_FAILURE_UNRECOGNIZEOPERATOR 3 +#define EXP_FAILURE_UNRECOGNIZEDFUNCTION 4 +#define EXP_FAILURE_INVALIDOPERANDTYPE 5 +#define EXP_FAILURE_UNMATCHEDPARENTHESIS 6 +#define EXP_FAILURE_TOOMANYWILDCARDVALUES 7 +#define EXP_FAILURE_RECURSION 8 +#define EXP_FAILURE_DELTATOOSHORT 9 +#define EXP_FAILURE_RESOURCEUNAVAILABLE 10 +#define EXP_FAILURE_DIVIDEBYZERO 11 + + +/* + * function prototypes + */ + + + void init_expExpressionTable(void); + FindVarMethod var_expExpressionTable; + SNMPCallback store_expExpressionTable; + void parse_expExpressionTable(const char *, char *); + + WriteMethod write_expExpression; + WriteMethod write_expExpressionValueType; + WriteMethod write_expExpressionComment; + WriteMethod write_expExpressionDeltaInterval; + WriteMethod write_expExpressionEntryStatus; + + + + + +#endif /*_MIBGROUP_EXPEXPRESSIONTABLE_H */ diff --git a/agent/mibgroup/disman/expression/expObjectTable.c b/agent/mibgroup/disman/expression/expObjectTable.c new file mode 100644 index 0000000..e56f25a --- /dev/null +++ b/agent/mibgroup/disman/expression/expObjectTable.c @@ -0,0 +1,1465 @@ +/* + *Copyright(c)2004,Cisco URP imburses and Network Information Center in Beijing University of Posts and Telecommunications researches. + * + *All right reserved + * + *File Name: expObjectTable.c + *File Description: expObjectTable MIB operation. + * + *Current Version:1.0 + *Author:JianShun Tong + *Date:2004.8.20 + */ + + +/* + * This file was generated by mib2c and is intended for use as + * a mib module for the ucd-snmp snmpd agent. + */ + + +/* + * This should always be included first before anything else + */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-features.h> +#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 + +#ifndef NETSNMP_NO_WRITE_SUPPORT +netsnmp_feature_require(header_complex_find_entry) +#endif /* NETSNMP_NO_WRITE_SUPPORT */ + +/* + * minimal include directives + */ +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +#include "header_complex.h" +#include "expExpressionTable.h" +#include "expObjectTable.h" + + +/* + * expObjectTable_variables_oid: + * this is the top level oid that we want to register under. This + * is essentially a prefix, with the suffix appearing in the + * variable below. + */ +oid TimeInstance[] = { 1, 3, 6, 1, 2, 1, 1, 3, 0 }; + +oid expObjectTable_variables_oid[] = + { 1, 3, 6, 1, 2, 1, 90, 1, 2, 3 }; + +/* + * variable2 expObjectTable_variables: + */ + +struct variable2 expObjectTable_variables[] = { + /* + * magic number , variable type , ro/rw , callback fn , L, oidsuffix + */ +#define EXPOBJECTID 2 + {EXPOBJECTID, ASN_OBJECT_ID, NETSNMP_OLDAPI_RWRITE, + var_expObjectTable, 2, {1, 2}}, +#define EXPOBJECTIDWILDCARD 3 + {EXPOBJECTIDWILDCARD, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE, + var_expObjectTable, 2, {1, 3}}, +#define EXPOBJECTSAMPLETYPE 4 + {EXPOBJECTSAMPLETYPE, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE, + var_expObjectTable, 2, {1, 4}}, +#define EXPOBJECTDELTADISCONTINUITYID 5 + {EXPOBJECTDELTADISCONTINUITYID, ASN_OBJECT_ID, NETSNMP_OLDAPI_RWRITE, + var_expObjectTable, 2, {1, 5}}, +#define EXPOBJECTDISCONTINUITYIDWILDCARD 6 + {EXPOBJECTDISCONTINUITYIDWILDCARD, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE, + var_expObjectTable, 2, {1, 6}}, +#define EXPOBJECTDISCONTINUITYIDTYPE 7 + {EXPOBJECTDISCONTINUITYIDTYPE, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE, + var_expObjectTable, 2, {1, 7}}, +#define EXPOBJECTCONDITIONAL 8 + {EXPOBJECTCONDITIONAL, ASN_OBJECT_ID, NETSNMP_OLDAPI_RWRITE, + var_expObjectTable, 2, {1, 8}}, +#define EXPOBJECTCONDITIONALWILDCARD 9 + {EXPOBJECTCONDITIONALWILDCARD, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE, + var_expObjectTable, 2, {1, 9}}, +#define EXPOBJECTENTRYSTATUS 10 + {EXPOBJECTENTRYSTATUS, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE, + var_expObjectTable, 2, {1, 10}} +}; + + +/* + * global storage of our data, saved in and configured by header_complex() + */ +extern struct header_complex_index *expExpressionTableStorage; +extern struct header_complex_index *expValueTableStorage; + +struct header_complex_index *expObjectTableStorage = NULL; + +/* + * init_expObjectTable(): + * Initialization routine. This is called when the agent starts up. + * At a minimum, registration of your variables should take place here. + */ +void +init_expObjectTable(void) +{ + DEBUGMSGTL(("expObjectTable", "initializing... ")); + + + /* + * register ourselves with the agent to handle our mib tree + */ + REGISTER_MIB("expObjectTable", + expObjectTable_variables, variable2, + expObjectTable_variables_oid); + + /* + * register our config handler(s) to deal with registrations + */ + snmpd_register_config_handler("expObjectTable", parse_expObjectTable, + NULL, NULL); + + snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA, + store_expObjectTable, NULL); + + DEBUGMSGTL(("expObjectTable", "done.\n")); +} + + +struct expObjectTable_data * +create_expObjectTable_data(void) +{ + struct expObjectTable_data *StorageNew; + + StorageNew = SNMP_MALLOC_STRUCT(expObjectTable_data); + + /* + * fill in default row values here into StorageNew + */ + /* + * fill in values for all tables (even if not + * appropriate), since its easier to do here than anywhere + * else + */ + + StorageNew->expObjectIDWildcard = EXPOBJCETIDWILDCARD_FALSE; + StorageNew->expObjectSampleType = EXPOBJCETSAMPLETYPE_ABSOLUTEVALUE; + memdup((unsigned char **) + &(StorageNew->expObjectDeltaDiscontinuityID), + (unsigned char *) TimeInstance, sizeof(TimeInstance)); + StorageNew->expObjectDeltaDiscontinuityIDLen = + sizeof(TimeInstance) / sizeof(oid); + + + + + StorageNew->expObjectDiscontinuityIDWildcard = + EXPOBJCETDISCONTINUITYIDWILDCARD_FALSE; + StorageNew->expObjectDiscontinuityIDType = + EXPOBJECTDISCONTINUITYIDTYPE_TIMETICKS; + + StorageNew->expObjectConditional = calloc(1, sizeof(oid) * 2); /* 0.0 */ + StorageNew->expObjectConditionalLen = 2; + + StorageNew->expObjectID = calloc(1, sizeof(oid) * 2); /* 0.0 */ + StorageNew->expObjectIDLen = 2; + + StorageNew->expObjectConditionalWildcard = + EXPOBJECTCONDITIONALWILDCARD_FALSE; + StorageNew->storageType = ST_NONVOLATILE; + + return StorageNew; +} + +int +expObjectTable_add(struct expObjectTable_data *thedata) +{ + netsnmp_variable_list *vars = NULL; + + + DEBUGMSGTL(("expObjectTable", "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->expExpressionOwner, thedata->expExpressionOwnerLen); /* expExpressionOwner */ + snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->expExpressionName, thedata->expExpressionNameLen); /* expExpressionName */ + snmp_varlist_add_variable(&vars, NULL, 0, ASN_UNSIGNED, (char *) &thedata->expObjectIndex, sizeof(thedata->expObjectIndex)); /* expExpressionName */ + + + + + header_complex_add_data(&expObjectTableStorage, vars, thedata); + DEBUGMSGTL(("expObjectTable", "registered an entry\n")); + + + DEBUGMSGTL(("expObjectTable", "done.\n")); + return SNMPERR_SUCCESS; +} + + + +/* + * parse_mteTriggerTable(): + * parses .conf file entries needed to configure the mib. + */ +void +parse_expObjectTable(const char *token, char *line) +{ + size_t tmpint; + struct expObjectTable_data *StorageTmp = + SNMP_MALLOC_STRUCT(expObjectTable_data); + + DEBUGMSGTL(("expObjectTable", "parsing config... ")); + + if (StorageTmp == NULL) { + config_perror("malloc failure"); + return; + } + + line = + read_config_read_data(ASN_OCTET_STR, line, + &StorageTmp->expExpressionOwner, + &StorageTmp->expExpressionOwnerLen); + if (StorageTmp->expExpressionOwner == NULL) { + config_perror("invalid specification for expExpressionOwner"); + return; + } + + line = + read_config_read_data(ASN_OCTET_STR, line, + &StorageTmp->expExpressionName, + &StorageTmp->expExpressionNameLen); + if (StorageTmp->expExpressionName == NULL) { + config_perror("invalid specification for expExpressionName"); + return; + } + + line = + read_config_read_data(ASN_UNSIGNED, line, + &StorageTmp->expObjectIndex, &tmpint); + + line = + read_config_read_data(ASN_OBJECT_ID, line, + &StorageTmp->expObjectID, + &StorageTmp->expObjectIDLen); + if (StorageTmp->expObjectID == NULL) { + config_perror("invalid specification for expObjectID"); + return; + } + + line = + read_config_read_data(ASN_INTEGER, line, + &StorageTmp->expObjectIDWildcard, &tmpint); + + line = + read_config_read_data(ASN_INTEGER, line, + &StorageTmp->expObjectSampleType, &tmpint); + + line = + read_config_read_data(ASN_OBJECT_ID, line, + &StorageTmp->expObjectDeltaDiscontinuityID, + &StorageTmp-> + expObjectDeltaDiscontinuityIDLen); + if (StorageTmp->expObjectDeltaDiscontinuityID == NULL) { + config_perror + ("invalid specification for expObjectDeltaDiscontinuityID"); + return; + } + + line = + read_config_read_data(ASN_INTEGER, line, + &StorageTmp-> + expObjectDiscontinuityIDWildcard, &tmpint); + + line = + read_config_read_data(ASN_INTEGER, line, + &StorageTmp->expObjectDiscontinuityIDType, + &tmpint); + + line = + read_config_read_data(ASN_OBJECT_ID, line, + &StorageTmp->expObjectConditional, + &StorageTmp->expObjectConditionalLen); + if (StorageTmp->expObjectConditional == NULL) { + config_perror("invalid specification for expObjectConditional"); + return; + } + + line = + read_config_read_data(ASN_INTEGER, line, + &StorageTmp->expObjectConditionalWildcard, + &tmpint); + + line = + read_config_read_data(ASN_INTEGER, line, + &StorageTmp->expObjectEntryStatus, &tmpint); + + StorageTmp->storageType = ST_NONVOLATILE; + expObjectTable_add(StorageTmp); + + DEBUGMSGTL(("expObjectTable", "done.\n")); + +} + + + +/* + * store_expExpressionTable(): + * stores .conf file entries needed to configure the mib. + */ +int +store_expObjectTable(int majorID, int minorID, void *serverarg, + void *clientarg) +{ + char line[SNMP_MAXBUF]; + char *cptr; + size_t tmpint; + struct expObjectTable_data *StorageTmp; + struct header_complex_index *hcindex; + + DEBUGMSGTL(("expObjectTable", "storing data... ")); + + for (hcindex = expObjectTableStorage; hcindex != NULL; + hcindex = hcindex->next) { + StorageTmp = (struct expObjectTable_data *) hcindex->data; + + + + if (StorageTmp->storageType == ST_NONVOLATILE) { + + memset(line, 0, sizeof(line)); + strcat(line, "expObjectTable "); + cptr = line + strlen(line); + /* + * expObjectTable + */ + + cptr = + read_config_store_data(ASN_OCTET_STR, cptr, + &StorageTmp->expExpressionOwner, + &StorageTmp->expExpressionOwnerLen); + cptr = + read_config_store_data(ASN_OCTET_STR, cptr, + &StorageTmp->expExpressionName, + &StorageTmp->expExpressionNameLen); + cptr = + read_config_store_data(ASN_UNSIGNED, cptr, + &StorageTmp->expObjectIndex, + &tmpint); + cptr = + read_config_store_data(ASN_OBJECT_ID, cptr, + &StorageTmp->expObjectID, + &StorageTmp->expObjectIDLen); + cptr = + read_config_store_data(ASN_INTEGER, cptr, + &StorageTmp->expObjectIDWildcard, + &tmpint); + cptr = + read_config_store_data(ASN_INTEGER, cptr, + &StorageTmp->expObjectSampleType, + &tmpint); + cptr = + read_config_store_data(ASN_OBJECT_ID, cptr, + &StorageTmp-> + expObjectDeltaDiscontinuityID, + &StorageTmp-> + expObjectDeltaDiscontinuityIDLen); + cptr = + read_config_store_data(ASN_INTEGER, cptr, + &StorageTmp-> + expObjectDiscontinuityIDWildcard, + &tmpint); + cptr = + read_config_store_data(ASN_INTEGER, cptr, + &StorageTmp-> + expObjectDiscontinuityIDType, + &tmpint); + cptr = + read_config_store_data(ASN_OBJECT_ID, cptr, + &StorageTmp->expObjectConditional, + &StorageTmp-> + expObjectConditionalLen); + cptr = + read_config_store_data(ASN_INTEGER, cptr, + &StorageTmp-> + expObjectConditionalWildcard, + &tmpint); + cptr = + read_config_store_data(ASN_INTEGER, cptr, + &StorageTmp->expObjectEntryStatus, + &tmpint); + snmpd_store_config(line); + } + } + DEBUGMSGTL(("expObjectTable", "storage done\n")); + return 0; +} + + +/* + * var_expObjectTable(): + * Handle this table separately from the scalar value case. + * The workings of this are basically the same as for var_expObjectTable above. + */ +unsigned char * +var_expObjectTable(struct variable *vp, + oid * name, + size_t *length, + int exact, size_t *var_len, WriteMethod ** write_method) +{ + struct expObjectTable_data *StorageTmp = NULL; + + + DEBUGMSGTL(("expObjectTable", "var_expObjectTable: Entering... \n")); + /* + * this assumes you have registered all your data properly + */ + if ((StorageTmp = + header_complex(expObjectTableStorage, vp, name, length, exact, + var_len, write_method)) == NULL) { + if (vp->magic == EXPOBJECTENTRYSTATUS) + *write_method = write_expObjectEntryStatus; + return NULL; + } + /* + * this is where we do the value assignments for the mib results. + */ + switch (vp->magic) { + + case EXPOBJECTID: + *write_method = write_expObjectID; + *var_len = StorageTmp->expObjectIDLen * sizeof(oid); + return (u_char *) StorageTmp->expObjectID; + + case EXPOBJECTIDWILDCARD: + *write_method = write_expObjectIDWildcard; + *var_len = sizeof(StorageTmp->expObjectIDWildcard); + return (u_char *) & StorageTmp->expObjectIDWildcard; + + case EXPOBJECTSAMPLETYPE: + *write_method = write_expObjectSampleType; + *var_len = sizeof(StorageTmp->expObjectSampleType); + return (u_char *) & StorageTmp->expObjectSampleType; + + case EXPOBJECTDELTADISCONTINUITYID: + *write_method = write_expObjectDeltaDiscontinuityID; + *var_len = + StorageTmp->expObjectDeltaDiscontinuityIDLen * sizeof(oid); + return (u_char *) StorageTmp->expObjectDeltaDiscontinuityID; + + case EXPOBJECTDISCONTINUITYIDWILDCARD: + *write_method = write_expObjectDiscontinuityIDWildcard; + *var_len = sizeof(StorageTmp->expObjectDiscontinuityIDWildcard); + return (u_char *) & StorageTmp->expObjectDiscontinuityIDWildcard; + + case EXPOBJECTDISCONTINUITYIDTYPE: + *write_method = write_expObjectDiscontinuityIDWildcard; + *var_len = sizeof(StorageTmp->expObjectDiscontinuityIDType); + return (u_char *) & StorageTmp->expObjectDiscontinuityIDType; + + case EXPOBJECTCONDITIONAL: + *write_method = write_expObjectConditional; + *var_len = StorageTmp->expObjectConditionalLen * sizeof(oid); + return (u_char *) StorageTmp->expObjectConditional; + + case EXPOBJECTCONDITIONALWILDCARD: + *write_method = write_expObjectConditionalWildcard; + *var_len = sizeof(StorageTmp->expObjectConditionalWildcard); + return (u_char *) & StorageTmp->expObjectConditionalWildcard; + + case EXPOBJECTENTRYSTATUS: + *write_method = write_expObjectEntryStatus; + *var_len = sizeof(StorageTmp->expObjectEntryStatus); + return (u_char *) & StorageTmp->expObjectEntryStatus; + + + default: + ERROR_MSG(""); + } + return NULL; +} + +int +write_expObjectID(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 oid *tmpvar; + struct expObjectTable_data *StorageTmp = NULL; + static size_t tmplen; + size_t newlen = + name_len - (sizeof(expObjectTable_variables_oid) / sizeof(oid) + + 3 - 1); + + + DEBUGMSGTL(("expObjectTable", + "write_expObjectID entering action=%d... \n", action)); + if ((StorageTmp = + header_complex(expObjectTableStorage, NULL, + &name[sizeof(expObjectTable_variables_oid) / + sizeof(oid) + 3 - 1], &newlen, 1, NULL, + NULL)) == NULL) + return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */ + + + switch (action) { + case RESERVE1: + if (var_val_type != ASN_OBJECT_ID) { + snmp_log(LOG_ERR, "write to expObjectID not ASN_OBJECT_ID\n"); + return SNMP_ERR_WRONGTYPE; + } + if (StorageTmp->storageType != ST_NONVOLATILE) + return SNMP_ERR_NOTWRITABLE; + 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->expObjectID; + tmplen = StorageTmp->expObjectIDLen; + memdup((u_char **) & StorageTmp->expObjectID, var_val, + var_val_len); + StorageTmp->expObjectIDLen = var_val_len / sizeof(oid); + break; + + + case UNDO: + /* + * Back out any changes made in the ACTION case + */ + SNMP_FREE(StorageTmp->expObjectID); + StorageTmp->expObjectID = tmpvar; + StorageTmp->expObjectIDLen = 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! + */ + + /* + * XXX: if the valueID has actually changed, shouldn't we dump any + * previous values, as these are from a different object? + */ + SNMP_FREE(tmpvar); + snmp_store_needed(NULL); + break; + } + return SNMP_ERR_NOERROR; +} + +int +write_expObjectIDWildcard(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 int tmpvar; + struct expObjectTable_data *StorageTmp = NULL; + size_t newlen = + name_len - (sizeof(expObjectTable_variables_oid) / sizeof(oid) + + 3 - 1); + + + DEBUGMSGTL(("expObjectTable", + "write_expObjectIDWildcard entering action=%d... \n", + action)); + if ((StorageTmp = + header_complex(expObjectTableStorage, NULL, + &name[sizeof(expObjectTable_variables_oid) / + sizeof(oid) + 3 - 1], &newlen, 1, NULL, + NULL)) == NULL) + return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */ + + + switch (action) { + case RESERVE1: + if (var_val_type != ASN_INTEGER) { + snmp_log(LOG_ERR, + "write to expObjectIDWildcard not ASN_INTEGER\n"); + return SNMP_ERR_WRONGTYPE; + } + if (StorageTmp->storageType != ST_NONVOLATILE) + return SNMP_ERR_NOTWRITABLE; + 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->expObjectIDWildcard; + StorageTmp->expObjectIDWildcard = *((long *) var_val); + break; + + + case UNDO: + /* + * Back out any changes made in the ACTION case + */ + StorageTmp->expObjectIDWildcard = 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! + */ + snmp_store_needed(NULL); + break; + } + return SNMP_ERR_NOERROR; +} + + +int +write_expObjectSampleType(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 int tmpvar; + struct expObjectTable_data *StorageTmp = NULL; + size_t newlen = + name_len - (sizeof(expObjectTable_variables_oid) / sizeof(oid) + + 3 - 1); + + + DEBUGMSGTL(("expObjectTable", + "write_expObjectSampleType entering action=%d... \n", + action)); + if ((StorageTmp = + header_complex(expObjectTableStorage, NULL, + &name[sizeof(expObjectTable_variables_oid) / + sizeof(oid) + 3 - 1], &newlen, 1, NULL, + NULL)) == NULL) + return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */ + + + switch (action) { + case RESERVE1: + if (var_val_type != ASN_INTEGER) { + snmp_log(LOG_ERR, + "write to expObjectSampleTypenot ASN_INTEGER\n"); + return SNMP_ERR_WRONGTYPE; + } + if (StorageTmp->storageType != ST_NONVOLATILE) + return SNMP_ERR_NOTWRITABLE; + 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->expObjectSampleType; + StorageTmp->expObjectSampleType = *((long *) var_val); + break; + + + case UNDO: + /* + * Back out any changes made in the ACTION case + */ + StorageTmp->expObjectSampleType = 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! + */ + snmp_store_needed(NULL); + break; + } + return SNMP_ERR_NOERROR; +} + + + +int +write_expObjectDeltaDiscontinuityID(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 oid *tmpvar; + struct expObjectTable_data *StorageTmp = NULL; + static size_t tmplen; + size_t newlen = + name_len - (sizeof(expObjectTable_variables_oid) / sizeof(oid) + + 3 - 1); + + + DEBUGMSGTL(("expObjectTable", + "write_expObjectDeltaDiscontinuityID entering action=%d... \n", + action)); + if ((StorageTmp = + header_complex(expObjectTableStorage, NULL, + &name[sizeof(expObjectTable_variables_oid) / + sizeof(oid) + 3 - 1], &newlen, 1, NULL, + NULL)) == NULL) + return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */ + + + switch (action) { + case RESERVE1: + if (var_val_type != ASN_OBJECT_ID) { + snmp_log(LOG_ERR, + "write to expObjectDeltaDiscontinuityID not ASN_OBJECT_ID\n"); + return SNMP_ERR_WRONGTYPE; + } + if (StorageTmp->storageType != ST_NONVOLATILE) + return SNMP_ERR_NOTWRITABLE; + 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->expObjectDeltaDiscontinuityID; + tmplen = StorageTmp->expObjectDeltaDiscontinuityIDLen; + memdup((u_char **) & StorageTmp->expObjectDeltaDiscontinuityID, + var_val, var_val_len); + StorageTmp->expObjectDeltaDiscontinuityIDLen = + var_val_len / sizeof(oid); + break; + + + case UNDO: + /* + * Back out any changes made in the ACTION case + */ + SNMP_FREE(StorageTmp->expObjectDeltaDiscontinuityID); + StorageTmp->expObjectDeltaDiscontinuityID = tmpvar; + StorageTmp->expObjectDeltaDiscontinuityIDLen = 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! + */ + + /* + * XXX: if the valueID has actually changed, shouldn't we dump any + * previous values, as these are from a different object? + */ + SNMP_FREE(tmpvar); + snmp_store_needed(NULL); + break; + } + return SNMP_ERR_NOERROR; +} + + + +int +write_expObjectDiscontinuityIDWildcard(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 int tmpvar; + struct expObjectTable_data *StorageTmp = NULL; + size_t newlen = + name_len - (sizeof(expObjectTable_variables_oid) / sizeof(oid) + + 3 - 1); + + + DEBUGMSGTL(("expObjectTable", + "write_expObjectDiscontinuityIDWildcard entering action=%d... \n", + action)); + if ((StorageTmp = + header_complex(expObjectTableStorage, NULL, + &name[sizeof(expObjectTable_variables_oid) / + sizeof(oid) + 3 - 1], &newlen, 1, NULL, + NULL)) == NULL) + return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */ + + + switch (action) { + case RESERVE1: + if (var_val_type != ASN_INTEGER) { + snmp_log(LOG_ERR, + "write to expObjectDiscontinuityIDWildcard not ASN_INTEGER\n"); + return SNMP_ERR_WRONGTYPE; + } + if (StorageTmp->storageType != ST_NONVOLATILE) + return SNMP_ERR_NOTWRITABLE; + 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->expObjectDiscontinuityIDWildcard; + StorageTmp->expObjectDiscontinuityIDWildcard = *((long *) var_val); + break; + + + case UNDO: + /* + * Back out any changes made in the ACTION case + */ + StorageTmp->expObjectDiscontinuityIDWildcard = 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! + */ + snmp_store_needed(NULL); + break; + } + return SNMP_ERR_NOERROR; +} + + + +int +write_expObjectDiscontinuityIDType(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 int tmpvar; + struct expObjectTable_data *StorageTmp = NULL; + size_t newlen = + name_len - (sizeof(expObjectTable_variables_oid) / sizeof(oid) + + 3 - 1); + + + DEBUGMSGTL(("expObjectTable", + "write_expObjectDiscontinuityIDWildcard entering action=%d... \n", + action)); + if ((StorageTmp = + header_complex(expObjectTableStorage, NULL, + &name[sizeof(expObjectTable_variables_oid) / + sizeof(oid) + 3 - 1], &newlen, 1, NULL, + NULL)) == NULL) + return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */ + + + switch (action) { + case RESERVE1: + if (var_val_type != ASN_INTEGER) { + snmp_log(LOG_ERR, + "write to expObjectDiscontinuityIDType not ASN_INTEGER\n"); + return SNMP_ERR_WRONGTYPE; + } + if (StorageTmp->storageType != ST_NONVOLATILE) + return SNMP_ERR_NOTWRITABLE; + 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->expObjectDiscontinuityIDType; + StorageTmp->expObjectDiscontinuityIDType = *((long *) var_val); + break; + + + case UNDO: + /* + * Back out any changes made in the ACTION case + */ + StorageTmp->expObjectDiscontinuityIDType = 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! + */ + snmp_store_needed(NULL); + break; + } + return SNMP_ERR_NOERROR; +} + + + +int +write_expObjectConditional(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 oid *tmpvar; + struct expObjectTable_data *StorageTmp = NULL; + static size_t tmplen; + size_t newlen = + name_len - (sizeof(expObjectTable_variables_oid) / sizeof(oid) + + 3 - 1); + + + DEBUGMSGTL(("expObjectTable", + "write_expObjectConditional entering action=%d... \n", + action)); + if ((StorageTmp = + header_complex(expObjectTableStorage, NULL, + &name[sizeof(expObjectTable_variables_oid) / + sizeof(oid) + 3 - 1], &newlen, 1, NULL, + NULL)) == NULL) + return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */ + + + switch (action) { + case RESERVE1: + if (var_val_type != ASN_OBJECT_ID) { + snmp_log(LOG_ERR, + "write to expObjectConditional not ASN_OBJECT_ID\n"); + return SNMP_ERR_WRONGTYPE; + } + if (StorageTmp->storageType != ST_NONVOLATILE) + return SNMP_ERR_NOTWRITABLE; + 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->expObjectConditional; + tmplen = StorageTmp->expObjectConditionalLen; + memdup((u_char **) & StorageTmp->expObjectConditional, var_val, + var_val_len); + StorageTmp->expObjectConditionalLen = var_val_len / sizeof(oid); + break; + + + case UNDO: + /* + * Back out any changes made in the ACTION case + */ + SNMP_FREE(StorageTmp->expObjectConditional); + StorageTmp->expObjectConditional = tmpvar; + StorageTmp->expObjectConditionalLen = 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! + */ + + /* + * XXX: if the valueID has actually changed, shouldn't we dump any + * previous values, as these are from a different object? + */ + SNMP_FREE(tmpvar); + snmp_store_needed(NULL); + break; + } + return SNMP_ERR_NOERROR; +} + + + + +int +write_expObjectConditionalWildcard(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 int tmpvar; + struct expObjectTable_data *StorageTmp = NULL; + size_t newlen = + name_len - (sizeof(expObjectTable_variables_oid) / sizeof(oid) + + 3 - 1); + + + DEBUGMSGTL(("expObjectTable", + "write_expObjectConditionalWildcard entering action=%d... \n", + action)); + if ((StorageTmp = + header_complex(expObjectTableStorage, NULL, + &name[sizeof(expObjectTable_variables_oid) / + sizeof(oid) + 3 - 1], &newlen, 1, NULL, + NULL)) == NULL) + return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */ + + + switch (action) { + case RESERVE1: + if (var_val_type != ASN_INTEGER) { + snmp_log(LOG_ERR, + "write to expObjectConditionalWildcard not ASN_INTEGER\n"); + return SNMP_ERR_WRONGTYPE; + } + if (StorageTmp->storageType != ST_NONVOLATILE) + return SNMP_ERR_NOTWRITABLE; + 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->expObjectConditionalWildcard; + StorageTmp->expObjectConditionalWildcard = *((long *) var_val); + break; + + + case UNDO: + /* + * Back out any changes made in the ACTION case + */ + StorageTmp->expObjectConditionalWildcard = 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! + */ + snmp_store_needed(NULL); + break; + } + return SNMP_ERR_NOERROR; +} + + + + +int +write_expObjectEntryStatus(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) +{ + struct expObjectTable_data *StorageTmp = NULL; + static struct expObjectTable_data *StorageNew, *StorageDel; + size_t newlen = + name_len - (sizeof(expObjectTable_variables_oid) / sizeof(oid) + + 3 - 1); + static int old_value; + int set_value; + static netsnmp_variable_list *vars, *vp; + struct header_complex_index *hciptr; + + StorageTmp = + header_complex(expObjectTableStorage, NULL, + &name[sizeof(expObjectTable_variables_oid) / + sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL); + + + + + if (var_val_type != ASN_INTEGER || var_val == NULL) { + snmp_log(LOG_ERR, + "write to expObjectEntryStatus not ASN_INTEGER\n"); + return SNMP_ERR_WRONGTYPE; + } + set_value = *((long *) var_val); + + + /* + * check legal range, and notReady is reserved for us, not a user + */ + if (set_value < 1 || set_value > 6 || set_value == RS_NOTREADY) + return SNMP_ERR_INCONSISTENTVALUE; + + + switch (action) { + case RESERVE1: + /* + * stage one: test validity + */ + if (StorageTmp == NULL) { + /* + * create the row now? + */ + + + /* + * ditch illegal values now + */ + if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE) + return SNMP_ERR_INCONSISTENTVALUE; + + + /* + * destroying a non-existent row is actually legal + */ + if (set_value == RS_DESTROY) { + return SNMP_ERR_NOERROR; + } + + + /* + * illegal creation values + */ + if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE) { + return SNMP_ERR_INCONSISTENTVALUE; + } + } else { + /* + * row exists. Check for a valid state change + */ + if (set_value == RS_CREATEANDGO + || set_value == RS_CREATEANDWAIT) { + /* + * can't create a row that exists + */ + return SNMP_ERR_INCONSISTENTVALUE; + } + + if (StorageTmp->expObjectEntryStatus == RS_ACTIVE && + set_value != RS_DESTROY) { + /* + * "Once made active an entry may not be modified except to + * delete it." XXX: doesn't this in fact apply to ALL + * columns of the table and not just this one? + */ + return SNMP_ERR_INCONSISTENTVALUE; + } + if (StorageTmp->storageType != ST_NONVOLATILE) + return SNMP_ERR_NOTWRITABLE; + } + break; + + + + + case RESERVE2: + /* + * memory reseveration, final preparation... + */ + if (StorageTmp == NULL) { + /* + * creation + */ + vars = NULL; + + + snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, NULL, 0); /* expExpressionOwner */ + snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, NULL, 0); /* expExpressionName */ + snmp_varlist_add_variable(&vars, NULL, 0, ASN_UNSIGNED, NULL, 0); /* expObjectIndex */ + + + + if (header_complex_parse_oid + (& + (name + [sizeof(expObjectTable_variables_oid) / sizeof(oid) + + 2]), newlen, vars) != SNMPERR_SUCCESS) { + /* + * XXX: free, zero vars + */ + return SNMP_ERR_INCONSISTENTNAME; + } + vp = vars; + + + StorageNew = create_expObjectTable_data(); + + StorageNew->expExpressionOwner = malloc(vp->val_len + 1); + memcpy(StorageNew->expExpressionOwner, vp->val.string, + vp->val_len); + StorageNew->expExpressionOwner[vp->val_len] = '\0'; + StorageNew->expExpressionOwnerLen = vp->val_len; + + vp = vp->next_variable; + StorageNew->expExpressionName = malloc(vp->val_len + 1); + memcpy(StorageNew->expExpressionName, vp->val.string, + vp->val_len); + + StorageNew->expExpressionName[vp->val_len] = '\0'; + StorageNew->expExpressionNameLen = vp->val_len; + + vp = vp->next_variable; + StorageNew->expObjectIndex = *vp->val.integer; + + StorageNew->expObjectEntryStatus = set_value; + + } + + + break; + + + + + case FREE: + /* + * XXX: free, zero vars + */ + /* + * Release any resources that have been allocated + */ + break; + + + + + case ACTION: + /* + * The variable has been stored in set_value 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 + */ + + + if (StorageTmp == NULL) { + /* + * row creation, so add it + */ + if (StorageNew != NULL) + expObjectTable_add(StorageNew); + /* + * XXX: ack, and if it is NULL? + */ + } else if (set_value != RS_DESTROY) { + /* + * set the flag? + */ + old_value = StorageTmp->expObjectEntryStatus; + StorageTmp->expObjectEntryStatus = *((long *) var_val); + } else { + /* + * destroy... extract it for now + */ + hciptr = + header_complex_find_entry(expObjectTableStorage, + StorageTmp); + StorageDel = + header_complex_extract_entry(&expObjectTableStorage, + hciptr); + } + break; + + + + + case UNDO: + /* + * Back out any changes made in the ACTION case + */ + if (StorageTmp == NULL) { + /* + * row creation, so remove it again + */ + hciptr = + header_complex_find_entry(expObjectTableStorage, + StorageTmp); + StorageDel = + header_complex_extract_entry(&expObjectTableStorage, + hciptr); + /* + * XXX: free it + */ + } else if (StorageDel != NULL) { + /* + * row deletion, so add it again + */ + expObjectTable_add(StorageDel); + } else { + StorageTmp->expObjectEntryStatus = old_value; + } + 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 (StorageDel != NULL) { + StorageDel = 0; + /* + * XXX: free it, its dead + */ + } else { + if (StorageTmp + && StorageTmp->expObjectEntryStatus == RS_CREATEANDGO) { + StorageTmp->expObjectEntryStatus = RS_ACTIVE; + } else if (StorageTmp && + StorageTmp->expObjectEntryStatus == + RS_CREATEANDWAIT) { + StorageTmp->expObjectEntryStatus = RS_NOTINSERVICE; + } + } + snmp_store_needed(NULL); + break; + } + return SNMP_ERR_NOERROR; +} diff --git a/agent/mibgroup/disman/expression/expObjectTable.h b/agent/mibgroup/disman/expression/expObjectTable.h new file mode 100644 index 0000000..86fea31 --- /dev/null +++ b/agent/mibgroup/disman/expression/expObjectTable.h @@ -0,0 +1,92 @@ +/* + *Copyright(c)2004,Cisco URP imburses and Network Information Center in Beijing University of Posts and Telecommunications researches. + * + *All right reserved + * + *File Name: expObjectTable.h + *File Description: head file. + * + *Current Version:1.0 + *Author:JianShun Tong + *Date:2004.8.20 + */ + +/* + * This file was generated by mib2c and is intended for use as a mib module + * for the ucd-snmp snmpd agent. + */ + + +#ifndef _MIBGROUP_EXPOBJECTABLE_H +#define _MIBGROUP_EXPOBJECTABLE_H + + +/* + * we may use header_complex from the header_complex module + */ +config_require(header_complex) + + struct expObjectTable_data { + char *expExpressionOwner; + size_t expExpressionOwnerLen; + char *expExpressionName; + size_t expExpressionNameLen; + unsigned long expObjectIndex; + oid *expObjectID; + size_t expObjectIDLen; + long expObjectIDWildcard; + long expObjectSampleType; + oid *expObjectDeltaDiscontinuityID; + size_t expObjectDeltaDiscontinuityIDLen; + long expObjectDiscontinuityIDWildcard; + long expObjectDiscontinuityIDType; + oid *expObjectConditional; + size_t expObjectConditionalLen; + long expObjectConditionalWildcard; + long expObjectEntryStatus; + + + /* + * internal variables + */ + int storageType; + + + }; + /* + * enum definitions from the covered mib sections + */ +#define EXPOBJCETIDWILDCARD_TRUE 1 +#define EXPOBJCETIDWILDCARD_FALSE 2 +#define EXPOBJCETDISCONTINUITYIDWILDCARD_TRUE 1 +#define EXPOBJCETDISCONTINUITYIDWILDCARD_FALSE 2 +#define EXPOBJECTCONDITIONALWILDCARD_TRUE 1 +#define EXPOBJECTCONDITIONALWILDCARD_FALSE 2 +#define EXPOBJECTDISCONTINUITYIDTYPE_TIMETICKS 1 +#define EXPOBJECTDISCONTINUITYIDTYPE_TIMESTAMP 2 +#define EXPOBJECTDISCONTINUITYIDTYPE_DATEANDTIME 3 +#define EXPOBJCETSAMPLETYPE_ABSOLUTEVALUE 1 +#define EXPOBJCETSAMPLETYPE_DELTAVALUE 2 +#define EXPOBJCETSAMPLETYPE_CHANGEVALUE 3 + /* + * function prototypes + */ + void init_expObjectTable(void); + FindVarMethod var_expObjectTable; + SNMPCallback store_expObjectTable; + void parse_expObjectTable(const char *, char *); + + WriteMethod write_expObjectID; + WriteMethod write_expObjectIDWildcard; + WriteMethod write_expObjectSampleType; + WriteMethod write_expObjectDeltaDiscontinuityID; + WriteMethod write_expObjectDiscontinuityIDWildcard; + WriteMethod write_expObjectDiscontinuityIDType; + WriteMethod write_expObjectConditional; + WriteMethod write_expObjectConditionalWildcard; + WriteMethod write_expObjectEntryStatus; + + + + +#endif /* _MIBGROUP_EXPOBJECTABLE_H */ diff --git a/agent/mibgroup/disman/expression/expValueTable.c b/agent/mibgroup/disman/expression/expValueTable.c new file mode 100644 index 0000000..6b315c6 --- /dev/null +++ b/agent/mibgroup/disman/expression/expValueTable.c @@ -0,0 +1,873 @@ +/* + *Copyright(c)2004,Cisco URP imburses and Network Information Center in Beijing University of Posts and Telecommunications researches. + * + *All right reserved + * + *File Name: expValueTable.c + *File Description: expValueTable MIB operation. + * + *Current Version:1.0 + *Author:JianShun Tong + *Date:2004.8.20 + */ + + +/* + * This file was generated by mib2c and is intended for use as + * a mib module for the ucd-snmp snmpd agent. + */ + + +/* + * This should always be included first before anything else + */ +#include <net-snmp/net-snmp-config.h> +#if HAVE_STDLIB_H +#include <stdlib.h> +#endif + +#include <stdio.h> + +#if HAVE_STRING_H +#include <string.h> +#else +#include <strings.h> +#endif +#ifdef HAVE_LIMITS_H +#include <limits.h> +#endif + + +/* + * minimal include directives + */ +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> +#include "header_complex.h" +#include "expExpressionTable.h" +#include "expValueTable.h" +#include "expObjectTable.h" + + +/* + * expValueTable_variables_oid: + * this is the top level oid that we want to register under. This + * is essentially a prefix, with the suffix appearing in the + * variable below. + */ + +oid expValueTable_variables_oid[] = + { 1, 3, 6, 1, 2, 1, 90, 1, 3, 1 }; + +struct s_node { + unsigned data; + struct s_node *next; +}; +typedef struct s_node nodelink; +nodelink *operater = NULL; +nodelink *operand = NULL; + +/* + * variable2 expObjectTable_variables: + */ + +struct variable2 expValueTable_variables[] = { + /* + * magic number , variable type , ro/rw , callback fn , L, oidsuffix + */ +#define EXPVALUECOUNTER32VAL 2 + {EXPVALUECOUNTER32VAL, ASN_COUNTER, NETSNMP_OLDAPI_RONLY, + var_expValueTable, 2, {1, 2}}, +#define EXPVALUEUNSIGNED32VAL 3 + {EXPVALUEUNSIGNED32VAL, ASN_UNSIGNED, NETSNMP_OLDAPI_RONLY, + var_expValueTable, 2, {1, 3}}, +#define EXPVALUETIMETICKSVAL 4 + {EXPVALUETIMETICKSVAL, ASN_UNSIGNED, NETSNMP_OLDAPI_RONLY, + var_expValueTable, 2, {1, 4}}, +#define EXPVALUEINTEGER32VAL 5 + {EXPVALUEINTEGER32VAL, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_expValueTable, 2, {1, 5}}, +#define EXPVALUEIPADDRESSVAL 6 + {EXPVALUEIPADDRESSVAL, ASN_IPADDRESS, NETSNMP_OLDAPI_RONLY, + var_expValueTable, 2, {1, 6}}, +#define EXPVALUEOCTETSTRINGVAL 7 + {EXPVALUEOCTETSTRINGVAL, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, + var_expValueTable, 2, {1, 7}}, +#define EXPVALUEOIDVAL 8 + {EXPVALUEOIDVAL, ASN_OBJECT_ID, NETSNMP_OLDAPI_RONLY, + var_expValueTable, 2, {1, 8}}, +#define EXPVALUECOUNTER64VAL 9 + {EXPVALUECOUNTER64VAL, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, + var_expValueTable, 2, {1, 9}} +}; + + +/* + * global storage of our data, saved in and configured by header_complex() + */ +extern struct header_complex_index *expExpressionTableStorage; +extern struct header_complex_index *expObjectTableStorage; +struct header_complex_index *expValueTableStorage = NULL; +struct snmp_session session; + +/* + * init_expValueTable(): + * Initialization routine. This is called when the agent starts up. + * At a minimum, registration of your variables should take place here. + */ +void +init_expValueTable(void) +{ + DEBUGMSGTL(("expValueTable", "initializing... ")); + + + /* + * register ourselves with the agent to handle our mib tree + */ + REGISTER_MIB("expValueTable", + expValueTable_variables, variable2, + expValueTable_variables_oid); + init_snmp("snmpapp"); + + /* + * Initialize a "session" that defines who we're going to talk to + */ + snmp_sess_init(&session); /* set up defaults */ + session.peername = strdup("localhost"); + + DEBUGMSGTL(("expValueTable", "done.\n")); +} + +struct expValueTable_data * +create_expValueTable_data(void) +{ + struct expValueTable_data *StorageNew; + + StorageNew = SNMP_MALLOC_STRUCT(expValueTable_data); + + /* + * fill in default row values here into StorageNew + */ + /* + * fill in values for all tables (even if not + * appropriate), since its easier to do here than anywhere + * else + */ + StorageNew->expExpressionOwner = strdup(""); + StorageNew->expExpressionName = strdup(""); + StorageNew->expValueInstance = calloc(1, sizeof(oid) * sizeof(2)); /* 0.0.0 */ + StorageNew->expValueInstanceLen = 3; + return StorageNew; +} + +/* + * mteTriggerTable_add(): adds a structure node to our data set + */ +int +expValueTable_add(struct expExpressionTable_data *expression_data, + char *owner, size_t owner_len, char *name, + size_t name_len, oid * index, size_t index_len) +{ + netsnmp_variable_list *vars = NULL; + struct expValueTable_data *thedata, *StorageTmp; + struct header_complex_index *hcindex; + int founded = 0; + thedata = create_expValueTable_data(); + thedata->expValueCounter32Val = 0; + thedata->expExpressionOwner = owner; + thedata->expExpressionOwnerLen = owner_len; + thedata->expExpressionName = name; + thedata->expExpressionNameLen = name_len; + thedata->expValueInstance = index; + thedata->expValueInstanceLen = index_len; + thedata->expression_data = expression_data; + DEBUGMSGTL(("expValueTable", "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->expExpressionOwner, thedata->expExpressionOwnerLen); /* expExpressionOwner */ + snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->expExpressionName, thedata->expExpressionNameLen); /* expExpressionName */ + snmp_varlist_add_variable(&vars, NULL, 0, ASN_PRIV_IMPLIED_OBJECT_ID, + (u_char *) thedata->expValueInstance, + thedata->expValueInstanceLen * sizeof(oid)); + + for (hcindex = expValueTableStorage; hcindex != NULL; + hcindex = hcindex->next) { + StorageTmp = (struct expValueTable_data *) hcindex->data; + if (!strcmp + (StorageTmp->expExpressionOwner, thedata->expExpressionOwner) + && (StorageTmp->expExpressionOwnerLen == + thedata->expExpressionOwnerLen) + && !strcmp(StorageTmp->expExpressionName, + thedata->expExpressionName) + && (StorageTmp->expExpressionNameLen == + thedata->expExpressionNameLen) + && !snmp_oid_compare(StorageTmp->expValueInstance, + StorageTmp->expValueInstanceLen, + thedata->expValueInstance, + thedata->expValueInstanceLen)) { + founded = 1; + break; + } + + } + if (!founded) { + header_complex_add_data(&expValueTableStorage, vars, thedata); + DEBUGMSGTL(("expValueTable", "registered an entry\n")); + } else { + SNMP_FREE(thedata); + DEBUGMSGTL(("expValueTable", + "already have an entry, dont registe\n")); + } + + + DEBUGMSGTL(("expValueTable", "done.\n")); + return SNMPERR_SUCCESS; +} + + + + + +unsigned long +Evaluate_Expression(struct expValueTable_data *vtable_data) +{ + + struct header_complex_index *hcindex; + struct expObjectTable_data *objstorage, *objfound; + struct expValueTable_data *valstorage; + valstorage = vtable_data; + + char *expression; + char *result, *resultbak; + char *temp, *tempbak; + char intchar[10]; + int i = 0, j, k, l; + long value; + unsigned long result_u_long; + temp = malloc(100); + result = malloc(100); + tempbak = temp; + memset(result, 0, 100); + *result = '\0'; + resultbak = result; + + expression = vtable_data->expression_data->expExpression; + + while (*expression != '\0') { + if (*expression == '$') { + objfound = NULL; + i++; + for (j = 1; j < 100; j++) { + if ((*(expression + j) == '+') || + (*(expression + j) == '-') || + (*(expression + j) == '*') || + (*(expression + j) == '/') || + (*(expression + j) == '(') || + (*(expression + j) == ')') || + *(expression + j) == '\0') { + break; + } + } + sprintf(temp, "%.*s", j - 1, expression + 1); + l = atoi(temp); + expression = expression + j; + /* + * here use snmpget to get value + */ + for (hcindex = expObjectTableStorage; hcindex != NULL; + hcindex = hcindex->next) { + objstorage = (struct expObjectTable_data *) hcindex->data; + if (!strcmp + (objstorage->expExpressionOwner, + valstorage->expExpressionOwner) + && (objstorage->expExpressionOwnerLen == + valstorage->expExpressionOwnerLen) + && !strcmp(objstorage->expExpressionName, + valstorage->expExpressionName) + && (objstorage->expExpressionNameLen == + valstorage->expExpressionNameLen) + && (l == objstorage->expObjectIndex)) { + objfound = objstorage; + break; + } + } + + + if (!objfound) { + /* have err */ + return 0; + } + struct snmp_session *ss; + struct snmp_pdu *pdu; + struct snmp_pdu *response; + + oid anOID[MAX_OID_LEN]; + size_t anOID_len; + + memcpy(anOID, objfound->expObjectID, + objfound->expObjectIDLen * sizeof(oid)); + anOID_len = objfound->expObjectIDLen; + if (objfound->expObjectIDWildcard == EXPOBJCETIDWILDCARD_TRUE) { + anOID_len = + anOID_len + valstorage->expValueInstanceLen - 2; + memcpy(anOID + objfound->expObjectIDLen, + valstorage->expValueInstance + 2, + (valstorage->expValueInstanceLen - + 2) * sizeof(oid)); + } + struct variable_list *vars; + int status; + + /* + * Initialize the SNMP library + */ + + /* + * Initialize a "session" that defines who we're going to talk to + */ + session.version = vtable_data->expression_data->pdu_version; + + /* + * set the SNMPv1 community name used for authentication + */ + session.community = + vtable_data->expression_data->pdu_community; + session.community_len = + vtable_data->expression_data->pdu_community_len; + /* + * Open the session + */ + SOCK_STARTUP; + ss = snmp_open(&session); /* establish the session */ + + if (!ss) { + /* err */ + exit(2); + } + pdu = snmp_pdu_create(SNMP_MSG_GET); + snmp_add_null_var(pdu, anOID, anOID_len); + + /* + * Send the Request out. + */ + status = snmp_synch_response(ss, pdu, &response); + + /* + * Process the response. + */ + if (status == STAT_SUCCESS + && response->errstat == SNMP_ERR_NOERROR) { + /* + * SUCCESS: Print the result variables + */ + + vars = response->variables; + value = *(vars->val.integer); + sprintf(intchar, "%lu", value); + for (k = 1; k <= strlen(intchar); k++) { + *result = intchar[k - 1]; + result++; + } + + } else { + /* + * FAILURE: print what went wrong! + */ + + if (status == STAT_SUCCESS) + fprintf(stderr, "Error in packet\nReason: %s\n", + snmp_errstring(response->errstat)); + else + snmp_sess_perror("snmpget", ss); + + } + + /* + * Clean up: + * 1) free the response. + * 2) close the session. + */ + if (response) + snmp_free_pdu(response); + snmp_close(ss); + + SOCK_CLEANUP; + + } else { + *result = *expression; + result++; + expression++; + } + } + result_u_long = get_result(resultbak); + free(tempbak); + free(resultbak); + return result_u_long; +} + + + + + + + + +void +expValueTable_clean(void *data) +{ + struct expValueTable_data *cleanme = + (struct expValueTable_data *) data; + SNMP_FREE(cleanme->expValueInstance); + SNMP_FREE(cleanme->expValueIpAddressVal); + SNMP_FREE(cleanme->expValueOctetStringVal); + SNMP_FREE(cleanme->expValueOidVal); + SNMP_FREE(cleanme); +} + + + +void +build_valuetable(void) +{ + struct expExpressionTable_data *expstorage; + struct expObjectTable_data *objstorage, *objfound = NULL; + struct header_complex_index *hcindex, *object_hcindex; + char *expression; + oid *index; + int i = 0, j, l; + + DEBUGMSGTL(("expValueTable", "building valuetable... \n")); + + for (hcindex = expExpressionTableStorage; hcindex != NULL; + hcindex = hcindex->next) { + expstorage = (struct expExpressionTable_data *) hcindex->data; + if (expstorage->expExpressionEntryStatus == RS_ACTIVE) { + expression = expstorage->expExpression; + while (*expression != '\0') { + if (*expression == '$') { + i++; + for (j = 1; j < 100; j++) { + if ((*(expression + j) == '+') || + (*(expression + j) == '-') || + (*(expression + j) == '*') || + (*(expression + j) == '/') || + (*(expression + j) == '(') || + (*(expression + j) == ')') || + *(expression + j) == '\0') { + break; + } + } + { + char temp[100]; + + sprintf(temp, "%.*s", j - 1, expression + 1); + l = atoi(temp); + } + for (object_hcindex = expObjectTableStorage; + object_hcindex != NULL; + object_hcindex = object_hcindex->next) { + objstorage = + (struct expObjectTable_data *) object_hcindex-> + data; + if (!strcmp + (objstorage->expExpressionOwner, + expstorage->expExpressionOwner) + && (objstorage->expExpressionOwnerLen == + expstorage->expExpressionOwnerLen) + && !strcmp(objstorage->expExpressionName, + expstorage->expExpressionName) + && (objstorage->expExpressionNameLen == + expstorage->expExpressionNameLen) + && (l == objstorage->expObjectIndex)) { + if (objfound == NULL) { + objfound = objstorage; + } + if (objstorage->expObjectIDWildcard == + EXPOBJCETIDWILDCARD_TRUE) + objfound = objstorage; + } + } + expression = expression + j; + } else { + expression++; + } + }; + } + + if (!objfound) { + continue; + } + if (objfound->expObjectIDWildcard == EXPOBJCETIDWILDCARD_FALSE) { + index = calloc(1, MAX_OID_LEN); + *index = 0; + *(index + 1) = 0; + *(index + 2) = 0; + expValueTable_add(expstorage, objfound->expExpressionOwner, + objfound->expExpressionOwnerLen, + objfound->expExpressionName, + objfound->expExpressionNameLen, index, 3); + } else { + oid *targetOID; + size_t taggetOID_len; + targetOID = objfound->expObjectID; + struct snmp_pdu *pdu; + struct snmp_pdu *response; + oid *next_OID; + size_t next_OID_len; + taggetOID_len = objfound->expObjectIDLen; + int status; + struct snmp_session *ss; + /* + * Initialize the SNMP library + */ + + + /* + * set the SNMP version number + */ + session.version = expstorage->pdu_version; + + /* + * set the SNMPv1 community name used for authentication + */ + session.community = expstorage->pdu_community; + session.community_len = expstorage->pdu_community_len; + + /* + * Open the session + */ + SOCK_STARTUP; + ss = snmp_open(&session); /* establish the session */ + if (!ss) { + snmp_perror("ack"); + snmp_log(LOG_ERR, "something horrible happened!!!\n"); + exit(2); + } + + next_OID = targetOID; + next_OID_len = taggetOID_len; + do { + index = calloc(1, MAX_OID_LEN); + pdu = snmp_pdu_create(SNMP_MSG_GETNEXT); + + snmp_add_null_var(pdu, next_OID, next_OID_len); + + /* + * Send the Request out. + */ + status = snmp_synch_response(ss, pdu, &response); + + /* + * Process the response. + */ + if (status == STAT_SUCCESS + && response->errstat == SNMP_ERR_NOERROR) { + /* + * SUCCESS: Print the result variables + */ + + if (((response->variables->type >= SNMP_NOSUCHOBJECT && + response->variables->type <= SNMP_ENDOFMIBVIEW) + || snmp_oid_compare(targetOID, taggetOID_len, + response->variables->name, + taggetOID_len) != 0)) { + break; + } + /* add to expValueTable */ + + *index = 0; + *(index + 1) = 0; + memcpy(index + 2, + response->variables->name + taggetOID_len, + (response->variables->name_length - + taggetOID_len) * sizeof(oid)); + expValueTable_add(expstorage, + objfound->expExpressionOwner, + objfound->expExpressionOwnerLen, + objfound->expExpressionName, + objfound->expExpressionNameLen, + index, + response->variables->name_length - + taggetOID_len + 2); + + next_OID = response->variables->name; + + next_OID_len = response->variables->name_length; + + + + + } else { + /* + * FAILURE: print what went wrong! + */ + if (status == STAT_SUCCESS) + fprintf(stderr, "Error in packet\nReason: %s\n", + snmp_errstring(response->errstat)); + else + snmp_sess_perror("snmpget", ss); + } + } while (TRUE); + + } + + } + +} + + + +/* + * var_expValueTable(): + */ +unsigned char * +var_expValueTable(struct variable *vp, + oid * name, + size_t *length, + int exact, size_t *var_len, WriteMethod ** write_method) +{ + + struct expValueTable_data *StorageTmp = NULL; + + + + + DEBUGMSGTL(("expValueTable", "var_expValueTable: Entering... \n")); + + /* + * before we build valuetable we must free any other valutable if exist + */ + header_complex_free_all(expValueTableStorage, expValueTable_clean); + expValueTableStorage = NULL; + + + build_valuetable(); + + + /* + * this assumes you have registered all your data properly + */ + if ((StorageTmp = + header_complex(expValueTableStorage, vp, name, length, exact, + var_len, write_method)) == NULL) + return NULL; + + + /* + * this is where we do the value assignments for the mib results. + */ + switch (vp->magic) { + /* + * we only support counter32val + */ + + case EXPVALUECOUNTER32VAL: + StorageTmp->expValueCounter32Val = Evaluate_Expression(StorageTmp); + *var_len = sizeof(StorageTmp->expValueCounter32Val); + return (u_char *) & StorageTmp->expValueCounter32Val; + + case EXPVALUEUNSIGNED32VAL: + /* var_len = sizeof(StorageTmp->expValueUnsigned32Val); */ + /* return (u_char *) & StorageTmp->expValueUnsigned32Val; */ + return NULL; + + case EXPVALUETIMETICKSVAL: + /* var_len = sizeof(StorageTmp->expValueTimeTicksVal); */ + /* return (u_char *) & StorageTmp->expValueTimeTicksVal; */ + return NULL; + + case EXPVALUEINTEGER32VAL: + /* var_len = sizeof(StorageTmp->expValueInteger32Val); */ + /* return (u_char *) & StorageTmp->expValueInteger32Val; */ + return NULL; + + case EXPVALUEIPADDRESSVAL: + /* var_len = sizeof(StorageTmp->expValueIpAddressVal); */ + /* return (u_char *) & StorageTmp->expValueIpAddressVal; */ + return NULL; + + case EXPVALUEOCTETSTRINGVAL: + /* var_len = sizeof(StorageTmp->expValueOctetStringVal); */ + /* return (u_char *) & StorageTmp->expValueOctetStringVal; */ + return NULL; + + case EXPVALUEOIDVAL: + /* var_len = StorageTmp->expValueOidValLen; */ + /* return (u_char *) & StorageTmp->expValueOidVal; */ + return NULL; + + case EXPVALUECOUNTER64VAL: + /* var_len = sizeof(StorageTmp->expValueCounter64Val); */ + /* return (u_char *) & StorageTmp->expValueCounter64Val; */ + return NULL; + default: + ERROR_MSG(""); + return NULL; + } +} + + + + + +void +push(nodelink ** stack, unsigned long value) +{ + nodelink *newnode; + newnode = (nodelink *) malloc(sizeof(nodelink)); + if (!newnode) { + printf("\nMemory allocation failure!"); + return; + } + newnode->data = value; + newnode->next = *stack; + *stack = newnode; +} + +unsigned long +pop(nodelink ** stack) +{ + unsigned long value; + nodelink *top; + top = *stack; + *stack = (*stack)->next; + value = top->data; + free(top); + return value; +} + +int +priority(char operater) +{ + switch (operater) { + case '*': + case '/': + return 4; + case '+': + case '-': + return 3; + case ')': + return 2; + case '(': + return 1; + default: + return 0; + } +} + +unsigned long +calculate(int operater, unsigned long a, unsigned long b) +{ + switch (operater) { + case '+': + return (a + b); + case '-': + return (a - b); + case '*': + return (a * b); + case '/': + if (operater == '/' && b == 0) { + printf("\nDivision mustn\'t be 0!"); + exit(0); + } else + return (a / b); + } + return 0; +} + +unsigned long +get_operand(char *p, int *length) +{ + char c[13]; + int i = 0, k = 1; + unsigned long result = 0; + while (*p <= 57 && *p >= 48) + c[i++] = *(p++); + *length += --i; + for (; i >= 0; i--) { + result += (c[i] - 48) * k; + k *= 10; + } + return result; +} + +int +operator_class(char c) +{ + if (c <= 57 && c >= 48) + return 1; + if (c == 42 || c == 43 || c == 45 || c == 47) + return 2; + if (c == 41) + return 3; + if (c == 40) + return 4; + return 0; +} + +unsigned long +get_result(char *expr) +{ + int position = 0; + unsigned long op = 0, a = 0, b = 0, result = 0; + char *expression; + expression = expr; + while (*(expression + position) != '\0' + && *(expression + position) != '\n') { + switch (operator_class(*(expression + position))) { + case 1: + push(&operand, get_operand(expression + position, &position)); + break; + case 2: + if (operater != NULL) + while (operater != NULL + && priority(*(expression + position)) <= + priority(operater->data)) { + a = pop(&operand); + b = pop(&operand); + op = pop(&operater); + push(&operand, calculate(op, b, a)); + } + push(&operater, *(expression + position)); + break; + case 3: + while (operater != NULL && operater->data != '(') { + a = pop(&operand); + b = pop(&operand); + op = pop(&operater); + push(&operand, calculate(op, b, a)); + } + if (operater->data == '(') + pop(&operater); + break; + case 4: + push(&operater, '('); + break; + default: + printf("\nInvalid character in expression:"); + a = 0; + while (*(expression + (int) a) != '\n' + && *(expression + (int) a) != '\0') { + if (a != position) + printf("%c", *(expression + (int) a)); + else + printf("<%c>", *(expression + (int) a)); + a++; + } + exit(0); + } /* end switch */ + position++; + } + while (operater != NULL) { + op = pop(&operater); + a = pop(&operand); + b = pop(&operand); + push(&operand, calculate(op, b, a)); + } + result = pop(&operand); + return result; +} diff --git a/agent/mibgroup/disman/expression/expValueTable.h b/agent/mibgroup/disman/expression/expValueTable.h new file mode 100644 index 0000000..8569f9d --- /dev/null +++ b/agent/mibgroup/disman/expression/expValueTable.h @@ -0,0 +1,63 @@ +/* + *Copyright(c)2004,Cisco URP imburses and Network Information Center in Beijing University of Posts and Telecommunications researches. + * + *All right reserved + * + *File Name:expValueTable.h + *File Description: head file. + * + *Current Version:1.0 + *Author:JianShun Tong + *Date:2004.8.20 + */ + +/* + * This file was generated by mib2c and is intended for use as a mib module + * for the ucd-snmp snmpd agent. + */ + + +/* + * we may use header_complex from the header_complex module + */ +config_require(header_complex) + +#ifndef _MIBGROUP_EXPVALUETABLE_H +#define _MIBGROUP_EXPVALUETABLE_H + struct expValueTable_data { + char *expExpressionOwner; + size_t expExpressionOwnerLen; + char *expExpressionName; + size_t expExpressionNameLen; + oid *expValueInstance; + size_t expValueInstanceLen; + unsigned long expValueCounter32Val; + unsigned long expValueUnsigned32Val; + unsigned long expValueTimeTicksVal; + long expValueInteger32Val; + u_long *expValueIpAddressVal; + char *expValueOctetStringVal; + size_t expValueOctetStringValLen; + oid *expValueOidVal; + size_t expValueOidValLen; + long expValueCounter64Val; + + /* internal var */ + struct expExpressionTable_data *expression_data; + char *valuestr; + }; + + + /* + * function prototypes + */ + void init_expValueTable(void); + unsigned long get_result(char *expr); + FindVarMethod var_expValueTable; + int expValueTable_add(struct expExpressionTable_data + *expression_data, char *owner, + size_t owner_len, char *name, + size_t name_len, oid * index, + size_t index_len); + +#endif /* _MIBGROUP_EXPVALUETABLE_H */ |