#include <ltrx_snmp.h>
Data Fields | |
| int(* | index )(int varix, int tabix) |
| void(* | init )(uint16_t type) |
| const MIBTAB * | mtp |
| const MIBVAR * | mvp |
| int(* | numtabs )(void) |
| int(* | numvars )(void) |
| int(* | set )(int varix, int tabix) |
This struct is used to define SNMP access to a particular MIB.
The get(), set(), init(), and check() callback functions can be defined as NULL. The index() function must be defined if the MIB contains a table. Additionally the get() and/or set() should be defined if a MIB variable is defined using MIBOPT_CAR and/or MIB_OPT_CAW.
When a MIB variable is defined with MIBOPT_CAR the get() function is called when an SNMP GET operation is performed on the variable.
void (*get)(int varix, int tabix, uint8_t ** vvptr);
| varix | (in) current 'MIBVAR' index |
| tabix | (in) current data storage table/struct index |
| vvptr | (out) store value here |
| void |
When a MIB variable is defined with MIBOPT_CAW the set() function is called when an SNMP Set operation is performed on the variable. The data value to be set is first written to the area specified by 'ptr' in the variable MIBVAR definition. The set() function is used to performed post processing on the data value (i.e. copy the data elsewhere and/or trigger some event). If your MIB Handler contains a table and you use the index() function then you should use set(). Likewise if you use the index2() function then you should use set2(). The table index/data passed to the set2() function is that returned by a previous call to your index2() function.
int (*set)(int varix, int tabix);
| varix | (in) current 'MIBVAR' index |
| tabix | (in) current data storage table/struct index |
| int | an SNMP_RV code |
int (*set2)(int varix, const uint8_t * pIndex, uint32_t indexLen, void * pData);
| varix | (in) current 'MIBVAR' index |
| pIndex | (in) encoded OID Table index |
| indexLen | (in) length of the encoded OID Table index |
| pData | (in) data being set (encoded) |
| int | an SNMP_RV code |
If the MIB contains a table then an index() function must be implemented.
The basic index() function is used by the agent to determine what table indexes (tabix) are valid. Using this routine is very inefficient. The agent will call your index() routine for every entry in your table until you return -1. After every call to your index() function, assuming the function returns 1, the agent will then call your get() routine to get the actual table index for that tabix. It will then do some lexicographic OID compares and keep track of the best match (for SNMP GetNext operations). If your table data is unorganized by SNMP standards then implementing this function makes things easy at a cost of bad performance.
int (*index)(int varix, int tabix);
| varix | (in) current 'MIBVAR' index |
| tabix | (in) current data storage table/struct index |
| -1 | end of table reached |
| 0 | skip entry |
| 1 | valid entry |
This index2() function is a more traditional MIB Handler index function in that the entire requested table index is passed to the function and there are variables used to return the resulting index/value for the SNMP operation back to the agent. Note that the passed in index is the exact data from the SNMP message. The index is BER encoded so you must handle any single index values that are potentially greater than
int (*index2)(int varix, SnmpOperationType oflag, const uint8_t * index, uint32_t indexLen, const uint8_t * resCharIndex, uint32_t * resIndexLen, void ** retValue);
| varix | (in) current 'MIBVAR' index |
| oflag | (in) type of SNMP operation |
| index | (in) encoded OID Table index |
| indexLen | (in) length of the encoded OID Table index |
| resIndex | (out) resulting encoded OID Table index |
| resIndexLen | (out) length of the resulting encoded OID Table index |
| retValue | (out) data for resulting OID Table index (get/set) |
| -1 | end of table reached or error (i.e. invalid index) |
| 0 | valid entry (results in resIndex, resIndexLen, retValue) |
An initialization function that is called when the MIB is registered with the SNMP Agent.
int (*init)(uint16_t type);
| type | (in) always 0 |
| void |
This routine is called to check the validity of a value before it is set via an SNMP SET operation. If your MIB Handler contains a table and you use the index() function then you should use check(). Likewise if you use the index2() function then you should use check2(). The table index passed to the check2() function is that returned by a previous call to your index2() function.
int (*check)(int varix, int tabix, const uint8_t * inp);
| varix | (in) current 'MIBVAR' index |
| tabix | (in) current data storage table/struct index |
| inp | (in) pointer to the BER encoded value to be set |
| int | an SNMP_RV code |
int (*check2)(int varix, const uint8_t * pIndex, uint32_t indexLen, const uint8_t * inp);
| varix | (in) current 'MIBVAR' index |
| index | (in) encoded OID Table index |
| indexLen | (in) length of the encoded OID Table index |
| inp | (in) pointer to the BER encoded value to be set |
| int | an SNMP_RV code |