Difference between revisions of "Template:FAQ:Coding 25"

From Net-SNMP Wiki
Jump to: navigation, search
 
m (5.4 release synchronisation)
Line 1: Line 1:
 +
<!-- NB:
 +
  There is a mismatch between the template numbering
 +
  for this entry, and the FAQ entries that refer to it.
 +
  This follows a review of the entries in the
 +
  Coding section.
 +
-->
 
Contexts are a mechanism within SNMPv3 (and AgentX) whereby
 
Contexts are a mechanism within SNMPv3 (and AgentX) whereby
 
an agent can support parallel versions of the same MIB objects,
 
an agent can support parallel versions of the same MIB objects,

Revision as of 14:29, 29 December 2006

Contexts are a mechanism within SNMPv3 (and AgentX) whereby an agent can support parallel versions of the same MIB objects, referring to different underlying data sets. By default, a MIB module registrations will use the default empty context of "". But it's also possible to explicitly register an individual MIB module using a different context.

With the v4 API, this uses the call 'register_mib_context()' rather than the REGISTER_MIB macro. This is significantly more detailed, but most of the additional parameters can take fixed values, if all that's needed is to change the registration context.

Instead of the macro call:

       REGISTER_MIB("my_token", my_variables, variable1, my_variables_oid);

use the function call:

       register_mib_context( "my_token",
                              my_variables, sizeof(variable1),
                              sizeof(my_variables)/sizeof(variable1),
                              my_variables_oid,
                              sizeof(my_variables_oid)/sizeof(oid),
                              DEFAULT_MIB_PRIORITY, 0, 0, NULL,
                              "my_context", -1, 0);

Things are much easier with the v5 helper-based API. Having created the registration structure, this just requires setting the 'contextName' field before actually registering the MIB module:

       netsnmp_handler_registration *reg;
       reg = netsnmp_create_handler_registration(.....);
       reg->contextName = strdup("my_context");
       netsnmp_register_handler(reg);


In either case, it will also be necessary to define suitable access control entries to cover requests using the new context. This can either list each context explicitly:

       access {group} "my_context" any noauth exact  ......

or use a single entry to cover all possible contexts:

       access {group} ""           any noauth prefix ......

But note that both steps are required. Changing the access control settings won't affect the default context used for MIB registrations, and registering a MIB in a non-default context won't automatically configure the necessary access control settings.