# # Define types of data by mib type, and translate into needed C code. # ############################################################################ # source variable typing information: include: mib2c.vartypes.conf # Begin code template section ############################################################################ # variable statemnts used in a couple of places below ############################################################################ type: code-varInits code: /* variables we may use later */ code: static long long_ret; code: static u_long ulong_ret; code: static unsigned char string[SPRINT_MAX_LEN]; code: static oid objid[MAX_OID_LEN]; code: static struct counter64 c64; ############################################################################ # The .h file ############################################################################ type: code-dot-h code: /* This file was generated by mib2c and is intended for use as a mib module code: for the ucd-snmp snmpd agent. */ code: code: #ifndef _MIBGROUP_${OUTPUTNAME}_H code: #define _MIBGROUP_${OUTPUTNAME}_H code: code: /* we may use header_generic and header_simple_table from the util_funcs module */ code: code: config_require(util_funcs) code: code: /* function prototypes */ code: code: void init_$outputName(void); code: FindVarMethod var_$outputName; code: $variables{'code-var_table-decl'}{'processed'} code: $variables{'code-write-func-decl'}{'processed'} code: code: #endif /* _MIBGROUP_${OUTPUTNAME}_H */ ############################################################################ # The .c file, top ############################################################################ type: code-main-part code: /* This file was generated by mib2c and is intended for use as a mib module code: for the ucd-snmp snmpd agent. */ code: code: #ifdef IN_UCD_SNMP_SOURCE code: /* If we're compiling this file inside the ucd-snmp source tree */ code: code: /* This should always be included first before anything else */ code: #include <config.h> code: code: /* minimal include directives */ code: #include \"mibincl.h\" code: #include \"util_funcs.h\" code: code: #else /* !IN_UCD_SNMP_SOURCE */ code: code: #include <ucd-snmp/ucd-snmp-config.h> code: #include <ucd-snmp/ucd-snmp-includes.h> code: #include <ucd-snmp/ucd-snmp-agent-includes.h> code: code: #endif /* !IN_UCD_SNMP_SOURCE */ code: code: #include \"$outputName.h\" code: code: /* code: * ${outputName}_variables_oid: code: * this is the top level oid that we want to register under. This code: * is essentially a prefix, with the suffix appearing in the code: * variable below. code: */ code: code: oid ${outputName}_variables_oid[] = { $commaoid }; code: code: /* code: * variable$varlen ${outputName}_variables: code: * this variable defines function callbacks and type return information code: * for the $outputName mib section code: */ code: code: struct variable$varlen ${outputName}_variables[] = { code: /* magic number , variable type , ro/rw , callback fn , L, oidsuffix */ code: $variables{'variable-structure-info'}{'processed'} code: }; code: /* (L = length of the oidsuffix) */ code: code: /* code: * init_$outputName(): code: * Initialization routine. This is called when the agent starts up. code: * At a minimum, registration of your variables should take place here. code: */ code: void init_$outputName(void) { code: code: /* register ourselves with the agent to handle our mib tree */ code: REGISTER_MIB(\"$outputName\", ${outputName}_variables, variable$varlen,\ code: ${outputName}_variables_oid); code: code: /* place any other initialization junk you need here */ code: } code: code: /* code: * var_$outputName(): code: * This function is called every time the agent gets a request for code: * a scalar variable that might be found within your mib section code: * registered above. It is up to you to do the right thing and code: * return the correct value. code: * You should also correct the value of \"var_len\" if necessary. code: * code: * Please see the documentation for more information about writing code: * module extensions, and check out the examples in the examples code: * and mibII directories. code: */ code: unsigned char * code: var_$outputName(struct variable *vp, code: oid *name, code: size_t *length, code: int exact, code: size_t *var_len, code: WriteMethod **write_method) code: { code: code: $variables{'code-varInits'}{'code'} code: code: if (header_generic(vp,name,length,exact,var_len,write_method) code: == MATCH_FAILED ) code: return NULL; code: code: /* code: * this is where we do the value assignments for the mib results. code: */ code: switch(vp->magic) {\n\n code: $variables{$outputName}{'code-case-statements'}{'processed'} code: default: code: ERROR_MSG(\"\"); code: } code: return NULL; code: } code: code: $variables{'code-var_table'}{'processed'} code: code: $variables{'code-write-func'}{'processed'} ############################################################################ # var_ function for tables, which is handled specially and used above # # Note: $vtable is set to the table name in the processtable loop. ############################################################################ # # header file defs first # type: code-var_table-decl processtable: code-var_table-decl code: FindVarMethod var_$vtable; # # Code code per table # type: code-var_table processtable: code-var_table code: /* code: * var_$vtable(): code: * Handle this table separately from the scalar value case. code: * The workings of this are basically the same as for var_$outputName above. code: */ code: unsigned char * code: var_$vtable(struct variable *vp, code: oid *name, code: size_t *length, code: int exact, code: size_t *var_len, code: WriteMethod **write_method) code: { code: code: $variables{'code-varInits'}{'code'} code: code: /* code: * This assumes that the table is a \'simple\' table. code: * See the implementation documentation for the meaning of this. code: * You will need to provide the correct value for the TABLE_SIZE parameter code: * code: * If this table does not meet the requirements for a simple table, code: * you will need to provide the replacement code yourself. code: * Mib2c is not smart enough to write this for you. code: * Again, see the implementation documentation for what is required. code: */ code: if (header_simple_table(vp,name,length,exact,var_len,write_method, TABLE_SIZE) code: == MATCH_FAILED ) code: return NULL; code: code: /* code: * this is where we do the value assignments for the mib results. code: */ code: switch(vp->magic) {\n\n code: $variables{$vtable}{'code-case-statements'}{'processed'} code: default: code: ERROR_MSG(\"\"); code: } code: return NULL; code: } ############################################################################ # case statement sections ############################################################################ type: code-case-statements process: code-case-statements skipif: $mib->{'access'} =~ /NoAccess/ code: case $NAME: code: " . (($mib->{'access'} =~ /ReadWrite|WriteOnly|Create/) ? "*write_method = write_$mib->{label};" : "") . " code: $variables{$mib->{'type'}}{'case'} code: ############################################################################ # storage structure information ############################################################################ type: variable-structure-info process: variable-structure-info skipif: $mib->{'access'} =~ /NoAccess/ code: " . sprintf("#define %-20s $count", $NAME) . " code: " . sprintf(" { %-20s, %-14s, %-6.6s, %s, %d, { %s } },", $NAME, $variables{$mib->{'type'}}{'asnType'}, $accessToUCD{$mib->{'access'}}, "var_$vroutine", $depth-1, $subid) . " ############################################################################ # write function defitition, also appended to the end of the .c file. ############################################################################ # # Header info: declair write functions for set processing # process: code-write-func-decl type: code-write-func-decl skipif: $mib->{'access'} !~ /Write|Create/ code: WriteMethod write_$name; # # C code # type: code-write-func process: code-write-func skipif: $mib->{'access'} !~ /Write|Create/ code: int code: write_$name(int action, code: u_char *var_val, code: u_char var_val_type, code: size_t var_val_len, code: u_char *statP, code: oid *name, code: size_t name_len) code: { code: $variables{$mib->{'type'}}{writeInit} code: int size; code: code: switch ( action ) { code: case RESERVE1: code: if (var_val_type != $variables{$mib->{'type'}}{asnType}){ code: fprintf(stderr, \"write to $name not $variables{$mib->{'type'}}{asnType}\\n\"); code: return SNMP_ERR_WRONGTYPE; code: } code: if (var_val_len > sizeof($variables{$mib->{'type'}}{variable})){ code: fprintf(stderr,\"write to $name: bad length\\n\"); code: return SNMP_ERR_WRONGLENGTH; code: } code: break; code: code: case RESERVE2: code: size = var_val_len; code: $variables{$mib->{'type'}}{variable} = ($variables{$mib->{'type'}}{cast}) var_val; code: code: break; code: code: case FREE: code: /* Release any resources that have been allocated */ code: break; code: code: case ACTION: code: /* The variable has been stored in $variables{$mib->{'type'}}{variable} for code: you to use, and you have just been asked to do something with code: it. Note that anything done here must be reversable in the UNDO case */ code: break; code: code: case UNDO: code: /* Back out any changes made in the ACTION case */ code: break; code: code: case COMMIT: code: /* Things are working well, so it's now safe to make the change code: permanently. Make sure that anything done here can't fail! */ code: break; code: } code: return SNMP_ERR_NOERROR; code: } code: code: