Hello,
when polling some Cisco router I discovered that the perl snmp bulkwalk
function did not abort bulkwalking when some of the routers did not
increase their OIDs.
This patch adds an option 'NonIncreasing' to SNMP::Session->new. If
this option is set, an error is return instead of bulkwalking in an
never ending loop (making my life miserable :-)
Can somebody review and test this patch?
[This patch depends on the previous patch for the bus error]
Kind regards,
Ole Bjørn.
rocs3(obh) net-snmp 575$ cat patch.nonincreasing
diff -cr net-snmp-5.3.pre4-orig/include/net-snmp/library/snmp_api.h
net-snmp-5.3.pre4-obh/include/net-snmp/library/snmp_api.h
*** net-snmp-5.3.pre4-orig/include/net-snmp/library/snmp_api.h Tue Aug 30
02:24:45 2005
--- net-snmp-5.3.pre4-obh/include/net-snmp/library/snmp_api.h Tue Nov 22
15:57:21 2005
***************
*** 487,494 ****
#define SNMPERR_MALLOC (-62)
#define SNMPERR_KRB5 (-63)
#define SNMPERR_PROTOCOL (-64)
! #define SNMPERR_MAX (-64)
#define non_repeaters errstat
#define max_repetitions errindex
--- 493,501 ----
#define SNMPERR_MALLOC (-62)
#define SNMPERR_KRB5 (-63)
#define SNMPERR_PROTOCOL (-64)
+ #define SNMPERR_OID_NONINCREASING (-65)
! #define SNMPERR_MAX (-65)
#define non_repeaters errstat
#define max_repetitions errindex
diff -cr net-snmp-5.3.pre4-orig/perl/SNMP/SNMP.pm
net-snmp-5.3.pre4-obh/perl/SNMP/SNMP.pm
*** net-snmp-5.3.pre4-orig/perl/SNMP/SNMP.pm Sun Nov 20 22:16:23 2005
--- net-snmp-5.3.pre4-obh/perl/SNMP/SNMP.pm Tue Nov 22 15:16:30 2005
***************
*** 116,121 ****
--- 116,123 ----
$best_guess = 0; # determine whether or not to enable best-guess regular
# expression object name translation. 1 = Regex (-Ib),
# 2 = random (-IR)
+ $non_increasing = 0; # stop polling with an "OID not increasing"-error
+ # when an OID does not increases in bulkwalk.
$replace_newer = 0; # determine whether or not to tell the parser to replace
# older MIB modules with newer ones when loading MIBs.
# WARNING: This can cause an incorrect hierarchy.
***************
*** 542,547 ****
--- 544,550 ----
$this->{UseSprintValue} = $SNMP::use_sprint_value
unless exists $this->{UseSprintValue};
$this->{BestGuess} = $SNMP::best_guess unless exists $this->{BestGuess};
+ $this->{NonIncreasing} ||= $SNMP::non_increasing;
$this->{UseEnums} = $SNMP::use_enums unless exists $this->{UseEnums};
$this->{UseNumeric} = $SNMP::use_numeric unless exists $this->{UseNumeric};
***************
*** 570,575 ****
--- 573,579 ----
$this->{UseSprintValue} = $SNMP::use_sprint_value
unless exists $this->{UseSprintValue};
$this->{BestGuess} = $SNMP::best_guess unless exists $this->{BestGuess};
+ $this->{NonIncreasing} ||= $SNMP::non_increasing;
$this->{UseEnums} = $SNMP::use_enums unless exists $this->{UseEnums};
$this->{UseNumeric} = $SNMP::use_numeric unless exists $this->{UseNumeric};
***************
*** 1524,1529 ****
--- 1528,1541 ----
0 causes a regular lookup. setting to 1 causes a regular expression
match (defined as -Ib in snmpcmd) and setting to 2 causes a random
access lookup (defined as -IR in snmpcmd).
+
+ =item NonIncreasing
+
+ defaults to the value of SNMP::non_increasing at time of session
+ creation. this setting controls if a non-increasing OID during
+ bulkwalk will causes an error. setting to 0 causes the default
+ behaviour (which may, in very badly performing agents, result in a
never-ending loop).
+ setting to 1 causes an error (OID not increasing) when this error occur.
=item ErrorStr
diff -cr net-snmp-5.3.pre4-orig/perl/SNMP/SNMP.xs
net-snmp-5.3.pre4-obh/perl/SNMP/SNMP.xs
*** net-snmp-5.3.pre4-orig/perl/SNMP/SNMP.xs Wed Oct 5 14:26:46 2005
--- net-snmp-5.3.pre4-obh/perl/SNMP/SNMP.xs Tue Nov 22 15:11:45 2005
***************
*** 1957,1962 ****
--- 1957,1963 ----
SV **err_str_svp = hv_fetch((HV*)SvRV(context->sess_ref), "ErrorStr", 8,
1);
SV **err_num_svp = hv_fetch((HV*)SvRV(context->sess_ref), "ErrorNum", 8,
1);
SV **err_ind_svp = hv_fetch((HV*)SvRV(context->sess_ref), "ErrorInd", 8,
1);
+ int check = SvIV(*hv_fetch((HV*)SvRV(context->sess_ref),
"NonIncreasing",13,1));
DBPRT(3, (DBOUT "bulkwalk: sess_ref = 0x%p, sess_ptr_sv = 0x%p\n",
context->sess_ref, sess_ptr_sv));
***************
*** 2114,2119 ****
--- 2115,2130 ----
context->reqbase[pix].last_oid,
context->reqbase[pix].last_len) == 0)
{
+ if (check)
+ {
+ DBPRT(2, (DBOUT "Error: OID not increasing: %s\n",
+ snprint_objid(_debugx, sizeof(_debugx),
vars->name,vars->name_length)));
+ sv_setpv(*err_str_svp,
(char*)snmp_api_errstring(SNMPERR_OID_NONINCREASING));
+ sv_setiv(*err_num_svp, SNMPERR_OID_NONINCREASING);
+ sv_setiv(*err_ind_svp, pix);
+ goto err;
+ }
+
DBPRT(2, (DBOUT "Ignoring repeat oid: %s\n",
snprint_objid(_debugx, sizeof(_debugx),
vars->name,vars->name_length)));
diff -cr net-snmp-5.3.pre4-orig/snmplib/snmp_api.c
net-snmp-5.3.pre4-obh/snmplib/snmp_api.c
*** net-snmp-5.3.pre4-orig/snmplib/snmp_api.c Wed Nov 16 16:10:19 2005
--- net-snmp-5.3.pre4-obh/snmplib/snmp_api.c Tue Nov 22 14:25:19 2005
***************
*** 298,303 ****
--- 298,304 ----
"Out of memory (malloc failure)", /* SNMPERR_MALLOC */
"Kerberos related error", /* SNMPERR_KRB5 */
"Protocol error", /* SNMPERR_PROTOCOL */
+ "OID not increasing", /* SNMPERR_OID_NONINCREASING */
};
static const char *secLevelName[] = {
Ole Bjørn Hessen,
NMS-IP, PF-Nett, Telenor Networks
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc. Get Certified Today
Register for a JBoss Training Course. Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_idv28&alloc_id845&op=click
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders