markabrahams / node-net-snmp

JavaScript implementation of the Simple Network Management Protocol (SNMP)
206 stars 97 forks source link

Rewrite getBulk's response handling #205

Closed mvduin closed 2 years ago

mvduin commented 2 years ago
  1. The ENonRepeaterCountMismatch error is eliminated since the conditions where it was generated correspond to perfectly valid responses that you're pretty much guaranteed to run into if you use multiple repeaters and a large enough maxRepetitions count.
  2. backwardsGetNexts now properly prevents EOutOfOrder errors for all of the varbinds (previously it failed to do so for non-repeaters).
  3. The OID ordering for repeaters is now checked properly if backwardsGetNexts is false.
  4. The OID for error responses is now checked if reportOidMismatchErrors is true.
mvduin commented 2 years ago

Just to add, RFC 3416 section 4.2.3 specifies three reasons why the number of varbinds in the response may be less than the total number of requested varbinds (N + M * R where N is the number of non-repeaters, R the number of repeaters, and M the max number of repetitions):

  1. If including all requested varbinds would cause the response to exceed a local constraint or the max message size specified in the request then some of the varbinds must be omitted from the end such that the message size does not exceed these constraints but is "approximately equal to" them, i.e. one should not omit more varbinds than needed to meet the constraints.
  2. If a complete set of responses from one repetition are all EndOfMibView the agent may end the response there.
  3. If "processing of a request with many repetitions requires a significantly greater amount of processing time than a normal request" the agent may choose to reduce the number of repetitions (but not to zero).

The second and third conditions will result in a response with varbinds for all non-repeaters and one or more complete sets of repeaters, but the first (and most common) condition imposes no such constraint. In fact, the RFC explicitly notes that "the number of variable bindings removed has no relationship to the values of N, M, or R.".

Even zero varbinds is acceptable, indicating that including even the first varbind would cause the response to exceed the message size constraints. GetBulkRequest should never get a tooBig error as response.

markabrahams commented 2 years ago

Thanks for this @mvduin ! I've merged into master now and published in version 3.7.2 of the npm.