4.11   Request Processing

In the following discussions, the term VarBindList refers to a variable-binding list, a list of variable-binding pointer (vbp) instances.

4.11.1   GET PDU Processing

A VarBindList is allocated and initialized to hold the response information. Then the request VarBindList is processed in two passes.

In the first pass, each variable's leaf is located and checked for visibility in the current MIB view (see 4.9 View Tables).

In the second pass, the agent calls the getproc routines to perform instance-level testing and to find the values for the objects (for details, see the manual pages for snmpProcLib in F. SNMP Reference). Instead of returning the value, each getproc operation is responsible for installing it in the vbp by calling one of the getproc_got_*( ) functions. A getproc operation may also assume responsibility for other vbps in which case it should call one of the getproc_got_*( ) functions on their behalf.

An exception is generated (getproc_nosuchinst( )) if an object does not exist or if an instance does not exist. For other errors, the response VarBindList is discarded and the original list is converted into a response with an appropriate error code and encoded into a buffer.

(Note: the following only applies to asynchronous method routines; see 6.5 Asynchronous Method Routines.) snmpdContinue( ) is called when all the getproc( )operations have been started. It should be called when any tasks complete that were begun by a getproc operation but did not finish. snmpdContinue( ) examines the packet and, if all of the tasks have been completed, it causes the response to be encoded into a buffer for transmission by calling the completion routine.

4.11.2   GET NEXT and GET BULK PDU Processing

A VarBindList is allocated and initialized to hold the response information. Then the request VarBindList is processed in multiple passes. For each vbp, the first pass locates a leaf which has an object id which is the first successor to the object id of the vbp that is visible in the current MIB view.

In the next pass, the agent calls the nextproc routines to perform instance-level searching and to find the object-id and value for the vbp. Instead of returning the instance and value information, the nextproc should call one of the getproc_got_( ) routines to install the value, and nextproc_next_instance( ) to install the instance portion of the object-id. If no instance is found, the nextproc operation should call nextproc_no_next( ).

(Note: the following only applies to asynchronous method routines; see 6.5 Asynchronous Method Routines.) snmpdContinue( ) is called when all nextproc operations have been started. You should call it when any tasks complete that were begun by a nextproc operation but did not finish. When all of the tasks have completed, the SNMP agent steps through the response VarBindList and, for any vbp that was tagged with nextproc_no_next( ), step to the next object and start that object's nextproc operation.

When all of the vbps have been assigned valid objects or the exception VT_ENDOFMIB, the target agent proceeds to the next step. For GET NEXT PDUs this means generating the correct response packet, which may require translating an exception into an error. For GET BULK PDUs, the target agent may perform several iterations on the entire VarBindList. Each iteration performs the equivalent of a GET NEXT using the previous iterations's result as its starting point. The routine will stop when the packet is at the maximum size, the number of iterations is equal to the maximum requested in the packet or all requested variables are at the end of the MIB. When the last iteration is finished, or an error is encountered, the agent attempts to generate the response packet by calling the completion routine.

4.11.3   SET PDU Processing

The processing of SET request PDUs requires a number of passes through the VarBindList. There are several hooks available during processing, through which an agent designer can alter the way the SET is processed. The hooks that are provided must be defined at initialization during the invocation of snmpdInitFinish( ).


*   

NOTE: Hooks are called at various points during the processing of a SET request. For information on hooks, see 4.8 Hooks. Also see the manual page for the routine snmpdInitFinish( ) in F. SNMP Reference.

On the first pass, each variable's leaf is located, checked for visibility in the current MIB view, checked for writabilty, and type matched against the SET request.

At this point, a user-defined PDU-validation hook is called to let your code perform an overall PDU validation. This routine may return with:

-1
indicates the PDU is bad and should be rejected with a GEN_ERR error.

0
indicates that the PDU is good and that normal handling should proceed.

1
indicates the PDU is good and this routine has already performed all the set operations.

On the second pass through the VarBindList, a testproc operation may be started for each variable to check for accessibility and to test whether the proposed value is acceptable. The PDU-validation hook may tag particular VarBindList entries with a mark indicating that the associated testproc operation should be bypassed.

snmpdContinue( ) is called when all the testproc operations have been started. You should call it when any tasks complete that the testproc operation started but did not finish. If no errors occurred in the test phase, a pre-set-request hook (see 4.8 Hooks) may be called to perform activities prior to setting the requested variable. If an error occurred during the test phase, a set-failure hook is called to perform activities based on the failure of a SET operation.

After the pre-set-request hook returns, another pass is made over the VarBindList and a setproc operation may be started for each variable which has not otherwise been set.

(Note: the following only applies to asynchronous method routines; see 6.5 Asynchronous Method Routines.) snmpdContinue( ) is called again when all the setproc operations have been started. You should call it when any tasks complete that a setproc operation started but did not finish. When all of the tasks have completed, a post-set-request hook is called to give you the means to clear any caches or to actually trigger the accumulated sets, and to perform any activities required after setting the requested variable. At this time, the values can be saved to a file in case they need to be restored the next time the agent starts up.

If an error occurs during a setproc operation, the SNMP agent attempts to undo any sets that have already been performed. To do so, the agent examines the variable-binding pointers and runs any routines it finds in the undoproc field. This field should be set by the testproc or setproc( )operation responsible for the vbp. If you set this field during the testproc routine, you are allowing it to be called before the setproc operation finishes; if the setproc operation can not be interrupted (or you do not want to write the code to allow that) you should set the undoproc field at the end of the SET task.

(Note: the following only applies to asynchronous method routines.) Again, snmpdContinue( ) is called after the undoproc operations have been started and when any tasks complete that setproc or undoproc started but did not finish. The agent attempts to start any undoproc operations that have not already been started. After all the undoproc operations complete, a user-defined set-failure hook is called (see 4.8 Hooks).

When all of the tasks from the setproc operations and, in case of errors, the undoproc operations have completed, the internal packet structure for the original request packet is modified to become the response packet. The SNMP agent then attempts to generate the response packet by calling the completion routine.