mib2c
assumes that all tables are simple.
As with the scalar case, the variable routine needs to provide two basic functions - request validation and data retrieval.
header_simple_table
As with the scalar header routine, this takes the same parameters
as the main variable routine, with one addition - the maximum
valid index. Mib2c
generates a dummy token for this,
which must be replaced by the appropriate value.
checkmib
. However, the return
values of this were the reverse of those for generic_header
and header_simple_table
.
A version of checkmib
is still available for compatability
purposes, but you are encouraged to use header_simple_table
instead.
The basic code fragment
(see ucd-snmp/disk.c
)
is therefore of the form:
unsigned char * var_extensible_disk(vp, name, length, exact, var_len, write_method) { if (header_simple_table(vp,name,length,exact,var_len,write_method,numdisks) == MATCH_FAILED) return(NULL); [ etc, etc, etc ] }Note that the maximum index value parameter does not have to be a permanently fixed constant. It specifies the maximum valid index at the time the request is processed, and a subsequent request may have a different maximum.
mibII/sysORTable.c
where the table
is held purely internally to the agent code, including its size (and hence
the maximum valid index). This maximum could also be retrieved via a
system call, or via a kernel data variable.
header_simple_table
, so can be obtained as
name[*length-1]
.
ucd-snmp/disk.c
With some modules, this underlying table may be relatively large, or only accessible via a slow or cumbersome interface. The implementation described so far may prove unacceptably slow, particularly when walking a MIB tree requires the table to be loaded afresh for each variable requested.
In these circumstances,
a useful technique is to cache the table when it is first read in,
and use that cache for subsequent requests.
This can be done by having a separate routine to read in the table.
This uses two static variables, one a structure or array for the data
itself, and the other an additional timestamp to indicate when the table was last
loaded. When a call is made to this routine to "read" the table,
it can first check whether the cached table is "new enough".
If so, it can return immediately, and the system will use the cached data.
Only if the cached version is sufficiently old that it's probably out
of date, is it necessary to retrieve the current data, updating the
cached version and the timestamp value.
This is particularly useful if the data itself is relatively static,
such as a list of mounted filesystems.
There is an example of this technique in the Host Resources
implementation.
As with the scalar case, mib2c
simply provides placeholder
dummy return values. It's up to the programmer to fill in the details.
The next part concludes the examination of the detailed implementation by looking at more general tables.
Last modified: Wednesday, 01-Aug-2018 04:41:28 UTC
For questions regarding web content and site functionality, please write to the net-snmp-users mail list.