diff options
Diffstat (limited to 'perl/SNMP')
38 files changed, 16025 insertions, 0 deletions
diff --git a/perl/SNMP/BUG b/perl/SNMP/BUG new file mode 100644 index 0000000..380e98b --- /dev/null +++ b/perl/SNMP/BUG @@ -0,0 +1,40 @@ + +1) Memory leak (have not seen this lately) + +The following snippet used to grow in memory (and may still) - please +notify me if anyone still observes this and even better has a fix. + +perl -le ' +use SNMP; +$obj = new SNMP::Session DestHost, "dubravka"; +while (){ +print $obj->get(["ifNumber",0]); +} +' + +***Note: need to verify this with the async API as well*** + +2) not sure if this is a bug but I can cause a crash with a 'goto +LABEL;' from within an async callback function. + +3) the following varbind format is not encoded correctly ... I have seen this crash the agent as well + +$sess->get(["sysDescr.0"]); + +use the following instead: + +$sess->get(["sysDescr",0]); +or +$sess->get("sysDescr.0"); + +4) this is not handled yet +$sess->get(['MODULE-NAME::mibName',0]); +but strangely +$sess->get(['MODULE-NAME::mibName.0']); +works + +5) if you are on a system that does not have vsnprintf in libc but you +do have BerkleyDB installed ucd configure will assume you will get it +from there - you will need to change hints/solaris.pl to + +$self->{LIBS} .= ' -lkstat -ldb'; diff --git a/perl/SNMP/MANIFEST b/perl/SNMP/MANIFEST new file mode 100644 index 0000000..cb32c37 --- /dev/null +++ b/perl/SNMP/MANIFEST @@ -0,0 +1,37 @@ +BUG +examples/async1.pl +examples/async2.pl +examples/bulkwalk.pl +examples/ipforward.pl +examples/mibtree.pl +examples/mibwalk.pl +examples/pingmib.pl +examples/tablewalk.pl +examples/testleak.pl +examples/trap-example.pl +hints/irix.pl +hints/solaris.pl +Makefile.PL +MANIFEST +MANIFEST.SKIP +perlsnmp.h +README +SNMP.pm +SNMP.xs +t/async.t +t/bulkwalk.t +t/conf.t +t/get.t +t/getnext.t +t/mib.t +t/mib.txt +t/mibload.t +t/notify.t +t/README +t/session.t +t/set.t +t/startagent.pl +t/conftest.conf +t/snmptest.conf +TODO +typemap diff --git a/perl/SNMP/MANIFEST.SKIP b/perl/SNMP/MANIFEST.SKIP new file mode 100644 index 0000000..d3183e1 --- /dev/null +++ b/perl/SNMP/MANIFEST.SKIP @@ -0,0 +1,11 @@ +\.bak$ +\.o$ +~$ +^Makefile$ +^Makefile.old$ +\.bs$ +\.bso$ +\.c +\.em +^include +^host$ diff --git a/perl/SNMP/Makefile.PL b/perl/SNMP/Makefile.PL new file mode 100644 index 0000000..e617cb7 --- /dev/null +++ b/perl/SNMP/Makefile.PL @@ -0,0 +1,363 @@ +use ExtUtils::MakeMaker; +require 5; +use Config; +use Getopt::Long; +my $lib_version; +my %MakeParams = (); +my $opts; + +# See lib/ExtUtils/MakeMaker.pm for details of how to influence +# the contents of the Makefile that is written. + +%MakeParams = InitMakeParams(); + +WriteMakefile(%MakeParams); + +Check_Version(); + +GetTestInfo(); + +sub InitMakeParams { + my %Params = ( + NAME => 'SNMP', + dist => { SUFFIX => "gz", COMPRESS => "gzip -9f"}, + MAN3PODS => { 'SNMP.pm' => '$(INST_MAN3DIR)/SNMP.3' }, + XSPROTOARG => '-noprototypes', # XXX remove later? + VERSION_FROM => 'SNMP.pm', + realclean => { FILES => 'host' }, + ); + + if ($ENV{'OSTYPE'} eq 'msys') { + $Params{'DEFINE'} = "-DMINGW_PERL"; + } + + my ($snmp_lib, $snmp_llib, $sep); + if (($Config{'osname'} eq 'MSWin32' && $ENV{'OSTYPE'} eq '')) { + $opts = NetSNMPGetOpts(); + $Params{'DEFINE'} = "-DMSVC_PERL -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS"; + $sep = '\\'; + $snmp_lib_file = 'netsnmp.lib'; + $snmp_link_lib = 'netsnmp'; + + if (lc($opts->{'debug'}) eq "true") { + $lib_dir = 'lib\\debug'; + } + else { + $lib_dir = 'lib\\release'; + } + + if (lc($opts->{'insource'}) eq "true") { + $Params{'LIBS'} = "-L$basedir\\win32\\$lib_dir\\ -l$snmp_link_lib"; + } + else { + my @LibDirs = split (';',$ENV{LIB}); + my $LibDir; + if ($opts->{'prefix'}) { + push (@LibDirs,"$ENV{'NET-SNMP-PATH'}${sep}lib"); + } + $noLibDir = 1; + while ($noLibDir) { + $LibDir = find_files(["$snmp_lib_file"],\@LibDirs); + if ($LibDir ne '') { + $noLibDir = 0; + # Put quotes around LibDir to allow spaces in paths + $LibDir = '"' . $LibDir . '"'; + } + else + { + @LibDirs = (); + $LibDirs[0] = prompt("The Net-SNMP library ($snmp_lib_file) could not be found.\nPlease enter the directory where it is located:"); + $LibDirs[0] =~ s/\\$//; + } + } + $Params{LIBS} = "-L$LibDir -l$snmp_link_lib"; + } + + $Params{'INC'} = "-I$basedir\\include\\ -I$basedir\\include\\net-snmp\\ -I$basedir\\win32\\ "; + } + else { + $opts = NetSNMPGetOpts(); + $Params{'LDDLFLAGS'} = "$Config{lddlflags} " . `$opts->{'nsconfig'} --ldflags`; + if (!$ENV{'NETSNMP_LIBS'}) { + $Params{'LIBS'} = `$opts->{'nsconfig'} --libs`; + chomp($Params{'LIBS'}); + } else { + $Params{'LIBS'} = $ENV{'NETSNMP_LIBS'}; + } + if (!$ENV{'NETSNMP_CCFLAGS'}) { + $Params{'CCFLAGS'} = `$opts->{'nsconfig'} --cflags`; + chomp($Params{'CCFLAGS'}); + $Params{'CCFLAGS'} .= " " . $Config{'ccflags'}; + } else { + $Params{'CCFLAGS'} = $ENV{'NETSNMP_CCFLAGS'}; + } + $lib_version = `$opts->{'nsconfig'} --version`; + if (lc($opts->{'insource'}) eq "true") { + $Params{'LIBS'} = "-L../../snmplib/.libs -L../../snmplib/ " . $Params{'LIBS'}; + $Params{'CCFLAGS'} = "-I../../include " . $Params{'CCFLAGS'}; +# } else { +# $Params{'PREREQ_PM'} = { 'NetSNMP::default_store' => 0.01 }; + } + $Params{'CCFLAGS'} =~ s/ -W(all|inline|strict-prototypes|write-strings|cast-qual|no-char-subscripts)//g; # ignore developer warnings + if (!$ENV{'NETSNMP_PREFIX'}) { + $prefix = `$opts->{'nsconfig'} --prefix`; + chomp($prefix); + $sep = '/'; + } else { + $prefix = $ENV{'NETSNMP_PREFIX'}; + } + if ($Params{'LIBS'} eq "" || $Params{'CCFLAGS'} eq "") { + die "You need to install net-snmp first (I can't find net-snmp-config)"; + } + } + + return(%Params); + +} + +sub GetTestInfo { + my $sep = ($^O =~ /win32/i ? '\\' : '/'); + my $info_file = "t${sep}snmptest.cmd"; + my $snmpd_path1 = "${prefix}${sep}sbin"; + my $snmpd_path2 = "${sep}usr${sep}sbin"; + my $snmpd_path3 = "${sep}usr${sep}bin"; + my $win32_snmpd_path = $ENV{'NET-SNMP-PATH'} . $sep . "bin"; + + open(H, ">$info_file") || die "Error: could not open file '$info_file'($!)"; + + my ($mibdir, $snmpd, $snmptrapd); + + # Windows + if ($Config{'osname'} eq 'MSWin32' && $ENV{'OSTYPE'} eq '') { + if (lc ($opts->{'insource'}) eq "true") { + $mibdir = "../../mibs"; + if (lc($opts->{'debug'}) eq "true") { + $snmpd = "../../win32/bin/debug"; + $snmptrapd = "../../win32/bin/debug"; + } + else { + $snmpd = "../../win32/bin/release"; + $snmptrapd = "../../win32/bin/release"; + } + } else { + $mibdir = $ENV{'NET-SNMP-PATH'} . "${sep}share${sep}snmp${sep}mibs"; + $snmpd = find_files(["snmpd.exe"], [$win32_snmpd_path]); + $snmptrapd = find_files(["snmptrapd.exe"], [$win32_snmpd_path]); + } + } + + # Unix + else { + if (lc($opts->{'insource'}) eq "true") { + $mibdir = "../../mibs"; + $snmpd = "../../agent/snmpd"; + $snmptrapd = "../../apps/snmptrapd"; + } else { + $mibdir = "${prefix}${sep}share${sep}snmp${sep}mibs"; + $snmpd = find_files(["snmpd"], [$snmpd_path1, $snmpd_path2]); + $snmptrapd = find_files(["snmptrapd"], [$snmpd_path1, $snmpd_path2]); + } + } + + $mibdir = find_files(["NET-SNMP-MIB.txt"],[$mibdir]); + + $mibdir ||= prompt("Unable to locate the MIBs, Please enter the path: ", + $mibdir); + $snmpd ||= prompt("Unable to locate \"snmpd\". Please enter the path: ", + $snmpd_path1); + $snmptrapd ||= + prompt("Unable to locate \"snmptrapd\". Please enter the path: ", + $snmpd_path1); + + if ($Config{'osname'} eq 'MSWin32' && $ENV{'OSTYPE'} eq '') { + $snmpd = $snmpd . $sep . "snmpd.exe"; + $snmptrapd = $snmptrapd . $sep . "snmptrapd.exe"; + } + else { + if ($ENV{'OSTYPE'} eq 'msys') { + $snmpd =~ s/snmpd$/snmpd.exe/; + $snmptrapd =~ s/snmptrapd$/snmptrapd.exe/; + } + else + { + $snmpd =~ s/($sep)?(snmpd)?$/${sep}snmpd/; + $snmptrapd =~ s/($sep)?(snmptrapd)?$/${sep}snmptrapd/; + } + } + + print H "SNMPD => $snmpd\n"; + print H "SNMPTRAPD => $snmptrapd\n"; + print H "MIBDIR => $mibdir\n"; + + if (!(lc($opts->{'insource'}) eq "true")) { + if (-e $snmpd and -r $snmpd) { + if (not -x $snmpd) { + warn("Error: $snmpd not executable. 'make test' will not work.\n"); + } + } else { + warn("Error: $snmpd does not exist or is unreadable. 'make test' will not work.\n"); + } + + if (-e $snmptrapd and -r $snmptrapd) { + if (not -x $snmptrapd) { + warn("Error: $snmptrapd not executable. 'make test' will not work.\n"); + } + } else { + warn("Error: $snmptrapd does not exist or is unreadable. 'make test' will not work.\n"); + } + } +# end of else + close H; +} + +sub HasSSL { + my $config_header = shift; + my $has_ssl; + unless (open(C,"<$config_header")) { + warn("Unable to open $config_header, assuming no SSL\n"); + return undef; + } + while (<C>) { + $has_ssl++, last if /^\s*#define\s+NETSNMP_USE_OPENSSL/; + } + close C; + return $has_ssl; +} +# common subroutines -- DO NOT EDIT. +# They are imported from the Makefile.subs.pl file +sub NetSNMPGetOpts { + my %ret; + my $rootpath = shift; + $rootpath = "../" if (!$rootpath); + $rootpath .= '/' if ($rootpath !~ /\/$/); + + if (($Config{'osname'} eq 'MSWin32' && $ENV{'OSTYPE'} eq '')) { + + # Grab command line options first. Only used if environment variables are not set + GetOptions("NET-SNMP-IN-SOURCE=s" => \$ret{'insource'}, + "NET-SNMP-PATH=s" => \$ret{'prefix'}, + "NET-SNMP-DEBUG=s" => \$ret{'debug'}); + + if ($ENV{'NET-SNMP-IN-SOURCE'}) + { + $ret{'insource'} = $ENV{'NET-SNMP-IN-SOURCE'}; + undef ($ret{'prefix'}); + } + elsif ($ENV{'NET-SNMP-PATH'}) + { + $ret{'prefix'} = $ENV{'NET-SNMP-PATH'}; + } + + if ($ENV{'NET-SNMP-DEBUG'}) + { + $ret{'debug'} = $ENV{'NET-SNMP-DEBUG'}; + } + + # Update environment variables in case they are needed + $ENV{'NET-SNMP-IN-SOURCE'} = $ret{'insource'}; + $ENV{'NET-SNMP-PATH'} = $ret{'prefix'}; + $ENV{'NET-SNMP-DEBUG'} = $ret{'debug'}; + + $basedir = `%COMSPEC% /c cd`; + chomp $basedir; + $basedir =~ /(.*?)\\perl.*/; + $basedir = $1; + print "Net-SNMP base directory: $basedir\n"; + if ($basedir =~ / /) { + die "\nA space has been detected in the base directory. This is not " . + "supported\nPlease rename the folder and try again.\n\n"; + } + } + else + { + if ($ENV{'NET-SNMP-CONFIG'} && + $ENV{'NET-SNMP-IN-SOURCE'}) { + # have env vars, pull from there + $ret{'nsconfig'} = $ENV{'NET-SNMP-CONFIG'}; + $ret{'insource'} = $ENV{'NET-SNMP-IN-SOURCE'}; + } else { + # don't have env vars, pull from command line and put there + GetOptions("NET-SNMP-CONFIG=s" => \$ret{'nsconfig'}, + "NET-SNMP-IN-SOURCE=s" => \$ret{'insource'}); + + if (lc($ret{'insource'}) eq "true" && $ret{'nsconfig'} eq "") { + $ret{'nsconfig'}="sh ROOTPATH../net-snmp-config"; + } elsif ($ret{'nsconfig'} eq "") { + $ret{'nsconfig'}="net-snmp-config"; + } + + $ENV{'NET-SNMP-CONFIG'} = $ret{'nsconfig'}; + $ENV{'NET-SNMP-IN-SOURCE'} = $ret{'insource'}; + } + } + + $ret{'nsconfig'} =~ s/ROOTPATH/$rootpath/; + + $ret{'rootpath'} = $rootpath; + + \%ret; +} + +sub find_files { + my($f,$d) = @_; + my ($dir,$found,$file); + for $dir (@$d){ + $found = 0; + for $file (@$f) { + $found++ if -f "$dir/$file"; + } + if ($found == @$f) { + return $dir; + } + } +} + + +sub Check_Version { + if (($Config{'osname'} ne 'MSWin32' || $ENV{'OSTYPE'} ne '')) { + my $foundversion = 0; + return if ($ENV{'NETSNMP_DONT_CHECK_VERSION'}); + open(I,"<Makefile"); + while (<I>) { + if (/^VERSION = (.*)/) { + my $perlver = $1; + my $srcver = $lib_version; + chomp($srcver); + my $srcfloat = floatize_version($srcver); + $perlver =~ s/pre/0./; + # we allow for perl/CPAN-only revisions beyond the default + # version formatting of net-snmp itself. + $perlver =~ s/(\.\d{5}).*/\1/; + $perlver =~ s/0*$//; + if ($srcfloat ne $perlver) { + if (!$foundversion) { + print STDERR "ERROR: +Net-SNMP installed version: $srcver => $srcfloat +Perl Module Version: $perlver + +These versions must match for perfect support of the module. It is possible +that different versions may work together, but it is strongly recommended +that you make these two versions identical. You can get the Net-SNMP +source code and the associated perl modules directly from + + http://www.net-snmp.org/ + +If you want to continue anyway please set the NETSNMP_DONT_CHECK_VERSION +environmental variable to 1 and re-run the Makefile.PL script.\n"; + exit(1); + } + } + $foundversion = 1; + last; + } + } + close(I); + die "ERROR: Couldn't find version number of this module\n" + if (!$foundversion); + } +} + +sub floatize_version { + my ($major, $minor, $patch, $opps) = ($_[0] =~ /^(\d+)\.(\d+)\.?(\d*)\.?(\d*)/); + return $major + $minor/100 + $patch/10000 + $opps/100000; +} diff --git a/perl/SNMP/README b/perl/SNMP/README new file mode 100644 index 0000000..5d85aca --- /dev/null +++ b/perl/SNMP/README @@ -0,0 +1,896 @@ + The Perl5 'SNMP' Extension Module + for the Net-SNMP Library + +Contents: + Introduction: + Availability: + Contact: + Supported Platforms: + Release Notes: + Installation: + Operational Description: + Trouble Shooting: + Acknowledgments: + History: + Copyright: + +Introduction: + + ******************************NOTE NOTE NOTE************************** + This module now relies on many other modules. Ideally, do not try + to build it independently, as it won't work as well. Instead of + running "perl Makefile.PL" in this directory, run it in the + net-snmp/perl directory instead which has a global makefile used to + build all the sub-modules in their proper order. + ******************************NOTE NOTE NOTE************************** + + Note: The perl SNMP 5.x module which comes with net-snmp 5.0 and + higher is different than previous versions in a number of ways. Most + importantly, it behaves like a proper net-snmp application and calls + init_snmp properly, which means it will read configuration files and + use those defaults where appropriate automatically parse MIB files, + etc. This will likely affect your perl applications if you have, for + instance, default values set up in your snmp.conf file (as the perl + module will now make use of those defaults). The docmuentation, + however, has sadly not been updated yet (aside from this note). + + This is the Perl5 'SNMP' extension module. The SNMP module provides a + full featured, tri-lingual SNMP (SNMPv3, SNMPv2c, SNMPv1) API. The + SNMP module also provides an interface to the SMI MIB parse-tree for + run-time access to parsed MIB data. The SNMP module internals rely on + the Net-SNMP toolkit library (previously known as ucd-snmp). For + information on the Net-SNMP library see the documentation provided + with the Net-SNMP distribution or the project web page available on + 'Source Forge': + + http://www.net-snmp.org/ + +Availability: + + The most recent release of the Perl5 SNMP module can be found bundled + with the latest Net-SNMP distibution available from: + + http://www.net-snmp.org/download.html + + (Note: The perl SNMP distribution obtained this way has the highest + chance of being up to date and compatible with the Net-SNMP version + with which it is bundled.) + + A seperately bundled package of the SNMP module can be obtained from CPAN. + + (Note: In previous releases this module was compatible with the CMU + SNMP library. Starting with Perl5/SNMP-1.7 this module will *only* + work with the Net-SNMP (aka ucd-snmp) library due to dependence on new + features) + +Contact: + + The following mailing list should be consider the primary support + mechanism for this module: + + net-snmp-users ATATAT lists.sourceforge.net mail list + + (see http://www.net-snmp.org/lists/users/ to subscribe) + +Supported Platforms: + + Linux 1.2.x, 2.x + Solaris 2.x (see the net-snmp README.solaris file!) + MS Windows + Many other UNIX variants + Let us know what it *doesn't* work on, as it should on most systems + +Release Notes: + + SNMP module version 5.x is being developed against NET-SNMP-5.0 + see http://www.net-snmp.org/ for details. + + Compatibility with earlier or later versions of Net-SNMP or + UCD-SNMP is not guaranteed due to the dynamic nature of open + software development :). The perl module will check the version of + net-snmp you have installed for a match and warn you if they don't + match exactly. + +KNOWN BUGS: + + The make test suite likely won't work perfectly. It relies on + running an existing Net-SNMP SNMP agent and various configuration + which makes it very hard to ensure exact compatibility. If "make + test" fails on you we suggest you install the module anyway. + + (none?) (HA!) + +********************************************************************** +* the rest of this file is likely out of date ************************ +* the rest of this file is likely out of date ************************ +* the rest of this file is likely out of date ************************ +********************************************************************** + +Installation: + + Build and install the Net-SNMP package - see Net-SNMP README and + INSTALL docs. + + (Note: To ensure that any previous Net-SNMP, ucd-snmp or cmu snmp + installation's library or headers are not used by mistake, use the + -NET-SNMP-CONFIG directive to explicitly set the path to the + net-snmp-config command that knows about the net-snmp installation you + want to use.) + + NOTE: build all the perl modules at once using the Makefile.PL in the + net-snmp/perl directory rather than the one in this directory. + + Unix: + + cd net-snmp/perl + perl Makefile.PL [-NET-SNMP-CONFIG="sh ../../net-snmp-config"] [-NET-SNMP-IN-SOURCE=true] + make + make test + make install + + FreeBSD: + + cd net-snmp/perl + perl Makefile.PL -NET-SNMP-CONFIG="sh ../../net-snmp-config" -NET-SNMP-IN-SOURCE=true + make + make test + make install + + Win32 (MSVC++) + + This section covers installation of the Perl modules for Microsoft Visual + C++ 6.0 and Microsoft Microsoft Development Environment 2003/2003 + (MSVC 7.0/7.1). See the following sections for Cygwin and MinGW. + + ActiveState Perl is required. + + Note: With ActiveState Perl (currently at 5.8.2 build 808) and possibly other + versions of Perl on Windows, if a Perl script modifies a + system environment variable and then calls a C function, the + C function will not see the new environment variable. This + problem can be seen with the failure of test #3 in the SNMP + conf test (perl/SNMP/t/conf.t). The change to the + SNMPCONFPATH env variable is not seen by the calls to the C + SNMP module. + + Note: The source code should *not* be in a folder that contains a space. For + example, compiling in your 'My Documents' or your Desktop (usually + c:\Documents and Settings\xxxx\Desktop) is not supported. + + Automatic building / testing with nmakeperl.bat: + + 1. Ensure a static version of Net-SNMP has been compiled and + installed. Also ensure the DLL version of snmplib has been + compiled and installed. The Perl modules will not function + correctly without a shared snmplib library or DLL. + + 2. Install the regex win32 package (gnu_regex.exe). It is available from + + http://people.delphiforums.com/gjc/gnu_regex.html + + a. Copy regex.h to the include folder of MSVC++ + + Example: "C:\Program Files\Microsoft Visual Studio .NET 2003\ + Vc7\include\regex.h" + + b. Copy gnu_regex.lib to the lib folder of MSVC++ + + Example: "C:\Program Files\Microsoft Visual Studio .NET 2003\ + Vc7\lib\gnu_regex.lib" + + c. Copy gnu_regex.dll to your %windir%\system32 folder + + Example: "C:\winnt\system32\gnu_regex.dll" + + 3. Set the environment PATH to locate "nmake", "cl", and "link". + Visual Studio installs a VCVARS32.BAT batch file for this purpose. + + 4. Using a command prompt window, cd to the source base directory. + + 5. Invoke win32\nmakeperl.bat to build the Perl SNMP modules. If you see + errors, review the "nmake.out" file first. If no errors there, + then the modules built correctly, but the tests did not rigourously + prove the mettle of the modules. Review "nmaketest.out". If the + first three sections mostly pass, the modules are well formed. + + NOTE: If the tests fail, there may be a perl application left hanging. + Use the Task Manager to remove any stale perl or snmp*.exe process. + + 6. The final step is to invoke "nmake install". If no errors occurred, + then the SNMP modules are available for use by your Perl programs. + + + Manual building / testing: + + 1. Ensure a static version of Net-SNMP has been compiled and + installed. Also ensure the DLL version of snmplib has been + compiled and installed. The Perl modules will not function + correctly without a shared snmplib library or DLL. + + 2. Install the regex win32 package (gnu_regex.exe). It is available from + + http://people.delphiforums.com/gjc/gnu_regex.html + + a. Copy regex.h to the include folder of MSVC++ + + Example: "C:\Program Files\Microsoft Visual Studio .NET 2003\ + Vc7\include\regex.h" + + b. Copy gnu_regex.lib to the lib folder of MSVC++ + + Example: "C:\Program Files\Microsoft Visual Studio .NET 2003\ + Vc7\lib\gnu_regex.lib" + + c. Copy gnu_regex.dll to your %windir%\system32 folder + + Example: "C:\winnt\system32\gnu_regex.dll" + + 3. Set the environment PATH to locate "nmake", "cl", and "link". + Visual Studio installs a VCVARS32.BAT for this purpose. + + 4. Using a command prompt window, cd to the perl directory. + + 5. Type: + + perl Makefile.PL CAPI=TRUE -NET-SNMP-IN-SOURCE=TRUE + + to compile against the RELEASE version of Net-SNMP, or: + + perl Makefile.PL CAPI=TRUE -NET-SNMP-IN-SOURCE=TRUE -NET-SNMP-DEBUG=TRUE + + to compile against the DEBUG version of Net-SNMP. + + nmake + nmake test + nmake install + + Note: The --NET-SNMP-IN-SOURCE=TRUE causes the Makefile to use the + library files from the installed Net-SNMP directory. + To specify the installed Net-SNMP directory, use: + + perl Makefile.PL CAPI=TRUE -NET-SNMP-PATH="c:\usr" + + Note: -NET-SNMP-DEBUG has no effect while compiling against an + installed copy of Net-SNMP. + + Note: To include OpenSSL, see the net-snmp/README.win32 to compile + libsnmp with libeay32 and see that libeay.lib is in the + lib folder, or in the lib folder of the installed + Net-SNMP if using -NET-SNMP-PATH. For example, + c:\usr\lib + + Note: 'nmake test' will automatically start and stop the + agent(snmpd) and trap receiver (snmptrapd) while testing the + SNMP module. + + + Win32 (Cygwin): + + cd net-snmp\perl + perl Makefile.PL -NET-SNMP-IN-SOURCE=true + make + make test + make install + + If you get an error saying your system can't compile, you are + probably missing the regex library. Install regex from + http://mirrors.sunsite.dk/cygwin/release/regex/regex-4.4-2-src.tar.bz2 + + Note: The source code should *not* be in a folder that contains a space. For + example, compiling in your 'My Documents' or your Desktop (usually + c:\Documents and Settings\xxxx\Desktop) is not supported. + + + Win32 (MinGW): + + Note: As of February 25th, 2004, the MinGW build of Net-SNMP does not + compile the DLL version of libsnmp. Some modules will not function + correctly without a shared library / DLL. The OID module does not + appear to work at all without the DLL, and some parts of other + modules may not work. For example, sharing configurations between + modules which is why the SNMP conf test fails. + + Note: The source code should *not* be in a folder that contains a space. For + example, compiling in your 'My Documents' or your Desktop (usually + c:\Documents and Settings\xxxx\Desktop) is not supported. + + These directions are for MinGW 3.1.0 with MSYS 1.0.9 and ActiveState Perl. + Compiling the Perl modules using a MinGW built Perl environment has not + been tested. + + Note: With ActiveState Perl (currently at 5.8.2 build 808) and + possibly other versions of Perl on Windows, if a Perl script + modifies a system environment variable and then calls a C + function, the C function will not see the new environment + variable. This problem can be seen with the failure of test + #3 in the SNMP conf test (perl/SNMP/t/conf.t). The change to + the SNMPCONFPATH env variable is not seen by the calls to the + C SNMP module. + + The main Net-SNMP package must be compiled with the regex library. + See Net-SNMP README.win32 for compiling with MinGW. + + The following additional software is required: + + dmake: + http://www.cpan.org/authors/id/GSAR/dmake-4.1pl1-win32.zip + + ExtUtils-FakeConfig: + http://search.cpan.org/~mbarbon/ExtUtils-FakeConfig-0.05/ + + Note: A PPM package is available from ActiveState for + ExtUtils-FakeConfig, but it does not include the + make_implib.pl script. Downloading from CPAN is + recommended. + + Installing DMAKE and ExtUtils-FakeConfig: + ----------------------------------------- + + 1. Install DMAKE as described in the README.NOW contained in the DMAKE .ZIP + file ensuring the DMAKE program can be found in the system path. + + 2. Extract ExtUtils-FakeConfig-0.05.zip to a temporary folder. + + 3. Add the MinGW bin folder to your system path. + + 4. Open a Windows command prompt (cmd) and cd into + ExtUtils-FakeConfig-0.05 and typet he following to build and + install the ExtUtils-FakeConfig module: + + perl Makefile.PL + dmake + dmake install + + 5. A Perl import library needs to be created using the ExtUtils-FakeConfig + make_implib.pl script. + + For ActiveState Perl 5.6.x installed to c:\Perl, type the + following on one line: + + perl script/make_implib.pl --output-dir=C:/Perl/lib/CORE + --output-lib=libperl56.a --target=mingw c:/Perl/bin/Perl56.dll + + For ActiveState Perl 5.8.x installed to c:\Perl, type the + following on one line: + + perl script/make_implib.pl --output-dir=C:/Perl/lib/CORE + --output-lib=libperl58.a --target=mingw c:/Perl/bin/Perl58.dll + + +Building the Perl module: +------------------------- + + 1. Complete the section titled 'Installing DMAKE and ExtUtils-FakeConfig' + + 2. Open an MSYS shell and cd into the net-snmp/Perl folder and type the + following on one line: + + perl -MConfig_m Makefile.PL -NET-SNMP-IN-SOURCE=true DEFINE=-DMINGW_PERL + + 3. Open a Windows command prompt (cmd) and cd into the net-snmp/perl folder + and type: + + dmake + dmake test + dmake install + + Note: 'dmake test' will automatically start and stop the agent(snmpd) and + trap receiver (snmptrapd) while testing the SNMP module. + + 4. Remove the MinGW bin folder to your system path if it was not already in + your path for step 3 of 'Installing DMAKE and ExtUtils-FakeConfig'. + + + Operational Description: + + The basic operations of the SNMP protocol are provided by this module + through an object oriented interface for modularity and ease of use. + The primary class is SNMP::Session which encapsulates the persistent + aspects of a connection between the management application and the + managed agent. Internally the class is implemented as a blessed hash + reference. This class supplies 'get', 'getnext', 'set', 'fget', and + 'fgetnext' and other method calls. The methods take a variety of input + argument formats and support both synchronous and asynchronous + operation through a polymorphic API (i.e., method behaviour varies + dependent on args passed - see below). + + A description of the fields which can be specified when an + SNMP::Session object is created follows: + + SNMP::Session + public: + DestHost - default 'localhost', hostname or ip addr of SNMP agent + Community - default 'public', SNMP community string (used for both R/W) + Version - default '1', [2 (same as 2c), 2c, 3] + RemotePort - default '161', allow remote UDP port to be overridden + Timeout - default '1000000', micro-seconds before retry + Retries - default '5', retries before failure + RetryNoSuch - default '0', if enabled NOSUCH errors in 'get' pdus will + be repaired, removing the varbind in error, and resent - + undef will be returned for all NOSUCH varbinds, when set + to '0' this feature is disabled and the entire get request + will fail on any NOSUCH error (applies to v1 only) + SecName - default 'initial', security name (v3) + SecLevel - default 'noAuthNoPriv', security level [noAuthNoPriv, + authNoPriv, authPriv] (v3) + SecEngineId - default <none>, security engineID, will be probed if not + supplied (v3) + ContextEngineId - default <SecEngineId>, context engineID, will be + probed if not supplied (v3) + Context - default '', context name (v3) + AuthProto - default 'MD5', authentication protocol [MD5, SHA] (v3) + AuthPass - default <none>, authentication passphrase + PrivProto - default 'DES', privacy protocol [DES] (v3) + PrivPass - default <none>, privacy passphrase (v3) + VarFormats - default 'undef', used by 'fget[next]', holds an hash + reference of output value formatters, (e.g., {<obj> => + <sub-ref>, ... }, <obj> must match the <obj> and format + used in the get operation. A special <obj>, '*', may be + used to apply all <obj>s, the supplied sub is called to + translate the value to a new format. The sub is called + passing the Varbind as the arg + TypeFormats - default 'undef', used by 'fget[next]', holds an hash + reference of output value formatters, (e.g., {<type> => + <sub-ref>, ... }, the supplied sub is called to translate + the value to a new format, unless a VarFormat mathces first + (e.g., $session->{TypeFormats}{INTEGER} = \&mapEnum(); + although this can be done more efficiently by enabling + $SNMP::use_enums or session creation param 'UseEnums') + UseLongNames - defaults to the value of SNMP::use_long_names at time + of session creation. set to non-zero to have <tags> + for 'getnext' methods generated preferring longer Mib name + convention (e.g., system.sysDescr vs just sysDescr) + UseSprintValue - defaults to the value of SNMP::use_sprint_value at time + of session creation. set to non-zero to have return values + for 'get' and 'getnext' methods formatted with the libraries + sprint_value function. This will result in certain data types + being returned in non-canonical format Note: values returned + with this option set may not be appropriate for 'set' operations + (see discussion of value formats in <vars> description section) + UseEnums - defaults to the value of SNMP::use_enums at time of session + creation. set to non-zero to have integer return values + converted to enumeration identifiers if possible, these values + will also be acceptable when supplied to 'set' operations + UseNumeric - defaults to the value of SNMP::use_numeric at time of session + creation. set to non-zero to have <tags> returned by the 'get' + methods untranslated (i.e. dotted-decimal). Setting the + UseLongNames value for the session is highly recommended. + BestGuess - defaults to the value of SNMP::best_guess at time of session + creation. this setting controls how <tags> are parsed. setting + to 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). + ErrorStr - read-only, holds the error message assoc. w/ last request + ErrorNum - read-only, holds the snmp_err or status of last request + ErrorInd - read-only, holds the snmp_err_index when appropriate + + private: + DestAddr - internal field used to hold the translated DestHost field + SessPtr - internal field used to cache a created session structure + + methods: + new(<fields>) - Constructs a new SNMP::Session object. The fields are + passed to the constructor as a hash list + (e.g., $session = new SNMP::Session(DestHost => 'foo', + Community => 'private');), returns an object reference + or undef in case of error. + update(<fields>)- Updates the SNMP::Session object with the values fields + passed in as a hash list (similar to new(<fields>)) + (WARNING! not fully implemented) + get(<vars>[,<callback>]) + - do SNMP GET, multiple <vars> formats accepted. + for synchronous operation <vars> will be updated + with value(s) and type(s) and will also return + retrieved value(s). If <callback> supplied method + will operate asynchronously + fget(<vars>[,<callback>]) + - do SNMP GET like 'get' and format the values according + the handlers specified in $sess->{VarFormats} and + $sess->{TypeFormats}. Async *not supported* + getnext(<vars>[,<callback>]) + - do SNMP GETNEXT, multiple <vars> formats accepted, + returns retrieved value(s), <vars> passed as arguments are + updated to indicate next lexicographical <obj>,<iid>,<val>, + and <type> Note: simple string <vars>,(e.g., 'sysDescr.0') + form is not updated. If <callback> supplied method + will operate asynchronously + fgetnext(<vars>[,<callback>]) + - do SNMP GETNEXT like getnext and format the values according + the handlers specified in $sess->{VarFormats} and + $sess->{TypeFormats}. Async *not supported* + set(<vars>[,<callback>]) + - do SNMP SET, multiple <vars> formats accepted. + the value field in all <vars> formats must be in a canonical + format (i.e., well known format) to ensure unambiguous + translation to SNMP MIB data value (see discussion of + canonical value format <vars> description section), + returns true on success or undef on error. If <callback> + supplied method will operate asynchronously + getbulk(<non-repeaters>, <max-repeaters>, <vars> [, <callback>]) + - do an SNMP GETBULK, from the list of Varbinds, the single + next lexico instance is fetched for the first n Varbinds + as defined by <non-repeaters>. For remaining Varbinds, + the m lexico instances are retrieved each of the remaining + Varbinds, where m is <max-repeaters>. + bulkwalk(<non-repeaters>, <max-repeaters>, <vars> [, <callback>]) + - do an "SNMP bulkwalk" on the given variables. Bulkwalk is + implemented by sending an SNMP GETBULK request to fetch the + variables. Objects are copied to the return list until the + sub-tree is exited. If the request is not completed at the + end of a packet, a new request is created, starting where + the previous packet left off. This implementation is able + to handle multiple repeated vars, as well as non-repeaters. + Returns a list (or, in scalar context, a reference to a + list) of arrays of VarBinds. The VarBinds consist of the + responses for each requested variable. bulkwalk() leaves + the original Varbinds list intact to facilitate querying + of multiple devices. + + SNMP::TrapSession - supports all applicable fields from SNMP::Session + (see above) + methods: + new(<fields>) - Constructs a new SNMP::TrapSession object. The fields are + passed to the constructor as a hash list + (e.g., $trapsess = new SNMP::Session(DestHost => 'foo', + Community => 'private');), returns an object reference + or undef in case of error. + trap(enterprise, agent, generic, specific, uptime, <vars>) + $sess->trap(enterprise=>'.1.3.6.1.4.1.2021', # or 'ucdavis' [default] + agent => '127.0.0.1', # or 'localhost',[dflt 1st intf on host] + generic => specific, # can be omitted if 'specific' supplied + specific => 5, # can be omitted if 'generic' supplied + uptime => 1234, # dflt to localhost uptime (0 on win32) + [[ifIndex, 1, 1],[sysLocation, 0, "here"]]); # optional vars + # always last + or v2 format + trap(oid, uptime, <vars>) + $sess->trap(oid => 'snmpRisingAlarm', + uptime => 1234, + [[ifIndex, 1, 1],[sysLocation, 0, "here"]]); # optional vars + # always last + + + Acceptable variable formats: + <vars> may be one of the following forms: + + SNMP::VarList: - represents an array of MIB objects to get or set, + implemented as a blessed reference to an array of + SNMP::Varbinds, (e.g., [<varbind1>, <varbind2>, ...]) + + SNMP::Varbind: - represents a single MIB object to get or set, implemented as + a blessed reference to a 4 element array; + [<obj>, <iid>, <val>, <type>]. + <obj> - one of the following forms: + 1) leaf identifier (e.g., 'sysDescr') assumed to be + unique for practical purposes + 2) fully qualified identifier (e.g., + '.iso.org.dod.internet.mgmt.mib-2.system.sysDescr') + 3) fully qualified, dotted-decimal, numeric OID (e.g., + '.1.3.6.1.2.1.1.1') + <iid> - the dotted-decimal, instance identifier. for + scalar MIB objects use '0' + <val> - the SNMP data value retrieved from or being set + to the agents MIB. for (f)get(next) operations + <val> may have a variety of formats as determined by + session and package settings. However for set + operations the <val> format must be canonical to + ensure unambiguous translation. The canonical forms + are as follows: + OBJECTID => dotted-decimal (e.g., .1.3.6.1.2.1.1.1) + OCTETSTR => perl scalar containing octets, + INTEGER => decimal signed integer (or enum), + NETADDR => dotted-decimal, + IPADDR => dotted-decimal, + COUNTER => decimal unsigned integer, + COUNTER64 => decimal unsigned integer, + GAUGE, => decimal unsigned integer, + UINTEGER, => decimal unsigned integer, + TICKS, => decimal unsigned integer, + OPAQUE => perl scalar containing octets, + NULL, => perl scalar containing nothing, + + + <type> - SNMP data type (see list above), this field is + populated by 'get' and 'getnext' operations. In + some cases the programmer needs to populate this + field when passing to a 'set' operation. this + field need not be supplied when the attribute + indicated by <tag> is already described by loaded + Mib modules. for 'set's, if a numeric OID is used + and the object is not currently in the loaded Mib, + the <type> field must be supplied + + simple string - light weight form of <var> used to 'set' or 'get' a + single attribute without constructing an SNMP::Varbind. + stored in a perl scalar, has the form '<tag>.<iid>', + (e.g., 'sysDescr.0'). for 'set' operations the value + is passed as a second arg. Note: This argument form is + not updated in get[next] operations as are the other forms. + + Acceptable callback formats: + <callback> may be one of the following forms: + + without arguments: + \&subname + sub { ... } + or with arguments: + [ \&subname, $arg1, ... ] + [ sub { ... }, $arg1, ... ] + [ "method", $obj, $arg1, ... ] + + callback will be called when response is received or timeout + occurs. the last argument passed to callback will be a + SNMP::VarList reference. In case of timeout the last argument + will be undef. + + SNMP package variables and functions: + + $SNMP::VERSION - the current version specifier (e.g., 3.1.0) + + $SNMP::auto_init_mib - default '1', set to 0 to disable automatic reading + of the MIB upon session creation. set to non-zero + to call initMib at session creation which will result + in MIB loading according to Net-SNMP env. variables + (see man mib_api) + + $SNMP::verbose - default '0', controls warning/info output of + SNMP module, 0 => no output, 1 => enables warning/info + output from SNMP module itself (is also controlled + by SNMP::debugging - see below) + + $SNMP::use_long_names - default '0', set to non-zero to enable the use of + longer Mib identifiers. see translateObj. will also + influence the formatting of <tag> in varbinds returned + from 'getnext' operations. Can be set on a per session + basis (UseLongNames) + + $SNMP::use_sprint_value - default '0', set to non-zero to enable formatting of + response values using the snmp libraries sprint_value + function. can also be set on a per session basis (see + UseSprintValue) Note: returned values may not be + suitable for 'set' operations + + $SNMP::use_enums - default '0',set non-zero to return values as enums and + allow sets using enums where appropriate. integer data + will still be accepted for set operations. can also be + set on a per session basis (see UseEnums) + + $SNMP::use_numeric - default '0', set to non-zero to return tags as numeric + OID's, instead of translating them. Also setting + $SNMP::use_long_names to non-zero is highly recommended. + + $SNMP::best_guess - default '0'. this setting controls how <tags> are + parsed. setting to 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). can also be set + on a per session basis (see BestGuess) + + $SNMP::save_descriptions - default '0',set non-zero to have mib parser save + attribute descriptions. must be set prior to mib + initialization + + $SNMP::debugging - default '0', controls debugging output level + within SNMP module and libsnmp + 1 => enables 'SNMP::verbose' (see above) + 2 => level 1 plus snmp_set_do_debugging(1), + 3 => level 2 plus snmp_set_dump_packet(1) + + $SNMP::dump_packet - default '0', set [non-]zero to independently set + snmp_set_dump_packet() + + %SNMP::MIB - a tied hash to access parsed MIB information. After + the MIB has been loaded this hash allows access to + to the parsed in MIB meta-data(the structure of the + MIB (i.e., schema)). The hash returns blessed + references to SNMP::MIB::NODE objects which represent + a single MIB attribute. The nodes can be fetched with + multiple 'key' formats - the leaf name (e.g.,sysDescr) + or fully/partially qualified name (e.g., + system.sysDescr) or fully qualified numeric OID. The + returned node object supports the following fields: + + objectID - dotted decimal fully qualified OID + label - leaf textual identifier (e.g., 'sysDescr') + subID - leaf numeric OID component of objectID (e.g., '1') + moduleID - textual identifier for module (e.g., 'RFC1213-MIB') + parent - parent node + children - array reference of children nodes + nextNode - next lexico node (BUG!does not return in lexico order) + type - returns application type (see getType for values) + access - returns ACCESS (ReadOnly, ReadWrite, WriteOnly, + NoAccess, Notify, Create) + status - returns STATUS (Mandatory, Optional, Obsolete, + Deprecated, Current) + syntax - returns 'textualConvention' if defined else 'type' + textualConvention - returns TEXTUAL-CONVENTION + units - returns UNITS + hint - returns HINT + enums - returns hash ref {tag => num, ...} + ranges - returns array ref of hash ref [{low=>num, high=>num}] + defaultValue - returns default value + description - returns DESCRIPTION ($SNMP::save_descriptions must + be set prior to MIB initialization/parsing) + + + &SNMP::setMib(<file>) - allows dynamic parsing of the mib and explicit + specification of mib file independent of environment + variables. called with no args acts like initMib, + loading MIBs indicated by environment variables (see + Net-SNMP mib_api docs). passing non-zero second arg + forces previous mib to be freed and replaced + (Note: second arg not working since freeing previous + Mib is more involved than before). + + &SNMP::initMib() - calls library netsnmp_init_mib function if MIB not + already loaded - does nothing if MIB already loaded. + Will parse directories and load modules according to + environment variables described in Net-SNMP + documentations. + (see man mib_api, MIBDIRS, MIBS, MIBFILE(S), etc.) + + &SNMP::addMibDirs(<dir>,...) - calls library add_mibdir for each directory + supplied. will cause directory(s) to be added to + internal list and made available for searching in + subsequent loadModules calls + + &SNMP::addMibFiles(<file>,...) - calls library read_mib function. The file(s) + supplied will be read and all Mib module definitions + contained therein will be added to internal mib tree + structure + + &SNMP::loadModules(<mod>,...) - calls library read_module function. The + module(s) supplied will be searched for in the + current mibdirs and and added to internal mib tree + structure. Passing special <mod>, 'ALL', will cause + all known modules to be loaded. + + &SNMP::unloadModules(<mod>,...) - *Not Implemented* + + &SNMP::translateObj(<var>[,arg,[arg]]) - will convert a text obj tag to an + OID and vice-versa. Any iid suffix is retained + numerically. Default behaviour when converting a + numeric OID to text form is to return leaf identifier + only (e.g.,'sysDescr') but when $SNMP::use_long_names + is non-zero or a non-zero second arg is supplied it + will return a longer textual identifier. An optional + third argument of non-zero will cause the module name + to be prepended to the text name (e.g. + 'SNMPv2-MIB::sysDescr'). When converting a text obj, + the $SNMP::best_guess option is used. If no Mib is + loaded when called and $SNMP::auto_init_mib is enabled + then the Mib will be loaded. Will return 'undef' upon + failure. + + &SNMP::getType(<var>) - return SNMP data type for given textual identifier + OBJECTID, OCTETSTR, INTEGER, NETADDR, IPADDR, COUNTER + GAUGE, TIMETICKS, OPAQUE, or undef + + &SNMP::mapEnum(<var>) - converts integer value to enumeration tag defined + in Mib or converts tag to integer depending on + input. the function will return the corresponding + integer value *or* tag for a given MIB attribute + and value. The function will sense which direction + to perform the conversion. Various arg formats are + supported + $val = SNMP::mapEnum($varbind); + # where $varbind is SNMP::Varbind or equiv + # note: $varbind will be updated + $val = SNMP::mapEnum('ipForwarding', 'forwarding'); + $val = SNMP::mapEnum('ipForwarding', 1); + + &SNMP::MainLoop([<timeout>, [<callback>]]) + - to be used with async SNMP::Session + calls. MainLoop must be called after initial async calls + so return packets from the agent will not be processed. + If no args supplied this function enters an infinite loop + so program must be exited in a callback or externally + interrupted. If <timeout + + &SNMP::finish() + - This function, when called from an SNMP::MainLoop() + callback function, will cause the current SNMP::MainLoop + to return after the callback is completed. finish() can + be used to terminate an otherwise-infinite MainLoop. A + new MainLoop() instance can then be started to handle + further requests. + + Exported SNMP utility functions + &snmp_get() - takes args of SNMP::Session::new followed by those of + SNMP::Session::get + + &snmp_getnext() - takes args of SNMP::Session::new followed by those of + SNMP::Session::getnext + + &snmp_set() - takes args of SNMP::Session::new followed by those of + SNMP::Session::set + + &snmp_trap() - takes args of SNMP::TrapSession::new followed by those of + SNMP::TrapSession::trap + + Note: utility functions do not support async operation yet. + +Trouble Shooting: + + If problems occur there are number areas to look at to narrow down the + possibilities. + + The first step should be to test the Net-SNMP installation + independently from the Perl5 SNMP interface. + + Try running the apps from the Net-SNMP distribution. + + Make sure your agent (snmpd) is running and properly configured with + read-write access for the community you are using. + + Ensure that your MIBs are installed and environment variables are set + appropriately (see man mib_api) + + Be sure to ensure headers and libraries from old CMU installations are + not being used by mistake (see -NET-SNMP-PATH). + + If the problem occurs during compilation/linking check that the snmp + library being linked is actually the Net-SNMP library (there have been + name conflicts with existing snmp libs). + + Also check that the header files are correct and up to date. + + Sometimes compiling the Net-SNMP library with + 'position-independent-code' enabled is required (HPUX specifically). + + If you cannot resolve the problem you can post to + comp.lang.perl.modules or email net-snmp-users@lists.sourceforge.net. + + please give sufficient information to analyze the problem (OS type, + versions for OS/Perl/net-SNMP/compiler, complete error output, etc.) + +Acknowledgments: + + Many thanks to all those who supplied patches, suggestions and + feedback. + + Joe Marzot (the original author) + Wes Hardaker and the net-snmp-coders + Dave Perkins + Marcel Wiget + David Blackburn + John Stofell + Gary Hayward + Claire Harrison + Achim Bohnet + Doug Kingston + Jacques Vidrine + Carl Jacobsen + Wayne Marquette + Scott Schumate + Michael Slifcak + Srivathsan Srinivasagopalan + Bill Fenner + Jef Peeraer + Daniel Hagerty + Karl "Rat" Schilke and Electric Lightwave, Inc. + Perl5 Porters + Alex Burger + + Apologies to any/all who's patch/feature/request was not mentioned or + included - most likely it was lost when paying work intruded on my + fun. Please try again if you do not see a desired feature. This may + actually turn out to be a decent package with such excellent help and + the fact that I have more time to work on it than in the past. + +Copyright: + + [See the COPYING file for the copyright license of Net-SNMP] + + Copyright (c) 1995-2000 G. S. Marzot. All rights reserved. + This program is free software; you can redistribute it and/or + modify it under the same terms as Perl itself. + + Copyright (c) 2001-2002 Networks Associates Technology, Inc. All + Rights Reserved. This program is free software; you can + redistribute it and/or modify it under the same terms as Perl + itself. + + Copyright (c) 2003-2006 SPARTA, Inc. All Rights Reserved. This + program is free software; you can redistribute it and/or modify + it under the same terms as Perl itself. diff --git a/perl/SNMP/SNMP.pm b/perl/SNMP/SNMP.pm new file mode 100644 index 0000000..ffc5a2f --- /dev/null +++ b/perl/SNMP/SNMP.pm @@ -0,0 +1,2680 @@ +# SNMP.pm -- Perl 5 interface to the Net-SNMP toolkit +# +# written by G. S. Marzot (marz@users.sourceforge.net) +# +# Copyright (c) 1995-2006 G. S. Marzot. All rights reserved. +# This program is free software; you can redistribute it and/or +# modify it under the same terms as Perl itself. + +package SNMP; +$VERSION = '5.0702'; # current release version number + +use strict; +use warnings; + +require Exporter; +require DynaLoader; +require AutoLoader; + +use NetSNMP::default_store (':all'); + +@SNMP::ISA = qw(Exporter AutoLoader DynaLoader); +# Items to export into callers namespace by default. Note: do not export +# names by default without a very good reason. Use EXPORT_OK instead. +# Do not simply export all your public functions/methods/constants. +@SNMP::EXPORT = qw( + RECEIVED_MESSAGE + SNMPERR_BAD_ADDRESS + SNMPERR_BAD_LOCPORT + SNMPERR_BAD_SESSION + SNMPERR_GENERR + SNMPERR_TOO_LONG + SNMP_DEFAULT_ADDRESS + SNMP_DEFAULT_COMMUNITY_LEN + SNMP_DEFAULT_ENTERPRISE_LENGTH + SNMP_DEFAULT_ERRINDEX + SNMP_DEFAULT_ERRSTAT + SNMP_DEFAULT_PEERNAME + SNMP_DEFAULT_REMPORT + SNMP_DEFAULT_REQID + SNMP_DEFAULT_RETRIES + SNMP_DEFAULT_TIME + SNMP_DEFAULT_TIMEOUT + SNMP_DEFAULT_VERSION + TIMED_OUT + snmp_get + snmp_getnext + snmp_set + snmp_trap + SNMP_API_TRADITIONAL + SNMP_API_SINGLE +); + +sub AUTOLOAD { + no strict; + # This AUTOLOAD is used to 'autoload' constants from the constant() + # XS function. If a constant is not found then control is passed + # to the AUTOLOAD in AutoLoader. + my($val,$pack,$file,$line); + my $constname; + ($constname = $AUTOLOAD) =~ s/.*:://; + # croak "&$module::constant not defined" if $constname eq 'constant'; + ($!, $val) = constant($constname, @_ ? $_[0] : 0); + if ($! != 0) { + if ($! =~ /Invalid/) { + $AutoLoader::AUTOLOAD = $AUTOLOAD; + goto &AutoLoader::AUTOLOAD; + } + else { + ($pack,$file,$line) = caller; + die "Your vendor has not defined SNMP macro $constname, used at $file line $line. +"; + } + } + eval "sub $AUTOLOAD { $val }"; + goto &$AUTOLOAD; +} + +bootstrap SNMP; + +# Preloaded methods go here. + +# Package variables +tie $SNMP::debugging, 'SNMP::DEBUGGING'; +tie $SNMP::debug_internals, 'SNMP::DEBUG_INTERNALS'; +tie $SNMP::dump_packet, 'SNMP::DUMP_PACKET'; +tie %SNMP::MIB, 'SNMP::MIB'; +tie $SNMP::save_descriptions, 'SNMP::MIB::SAVE_DESCR'; +tie $SNMP::replace_newer, 'SNMP::MIB::REPLACE_NEWER'; +tie $SNMP::mib_options, 'SNMP::MIB::MIB_OPTIONS'; + +%SNMP::V3_SEC_LEVEL_MAP = (noAuthNoPriv => 1, authNoPriv => 2, authPriv =>3); + +use vars qw( + $auto_init_mib $use_long_names $use_sprint_value $use_enums + $use_numeric %MIB $verbose $debugging $dump_packet $save_descriptions + $best_guess $non_increasing $replace_newer %session_params + $debug_internals $mib_options +); + +$auto_init_mib = 1; # enable automatic MIB loading at session creation time +$use_long_names = 0; # non-zero to prefer longer mib textual identifiers rather + # than just leaf indentifiers (see translateObj) + # may also be set on a per session basis(see UseLongNames) +$use_sprint_value = 0; # non-zero to enable formatting of response values + # using the snmp libraries "snprint_value" + # may also be set on a per session basis(see UseSprintValue) + # note: returned values not suitable for 'set' operations +$use_enums = 0; # non-zero to return integers as enums and allow sets + # using enums where appropriate - integer data will + # still be accepted for set operations + # may also be set on a per session basis (see UseEnums) +$use_numeric = 0; # non-zero to return object tags as numeric OID's instead + # of converting to textual representations. use_long_names, + # if non-zero, returns the entire OID, otherwise, return just + # the label portion. use_long_names is also set if the + # use_numeric variable is set. +%MIB = (); # tied hash to access libraries internal mib tree structure + # parsed in from mib files +$verbose = 0; # controls warning/info output of SNMP module, + # 0 => no output, 1 => enables warning and info + # output from SNMP module itself (is also controlled + # by SNMP::debugging) +$debugging = 0; # non-zero to globally enable libsnmp do_debugging output + # set to >= 2 to enabling packet dumping (see below) +$dump_packet = 0; # non-zero to globally enable libsnmp dump_packet output. + # is also enabled when $debugging >= 2 +$save_descriptions = 0; #tied scalar to control saving descriptions during + # mib parsing - must be set prior to mib loading +$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. + +sub register_debug_tokens { + my $tokens = shift; + + SNMP::_register_debug_tokens($tokens); +} + +sub getenv { + my $name = shift; + + return SNMP::_getenv($name); +} + +sub setenv { + my $envname = shift; + my $envval = shift; + my $overwrite = shift; + + return SNMP::_setenv($envname, $envval, $overwrite); +} + +sub setMib { +# loads mib from file name provided +# setting second arg to true causes currently loaded mib to be replaced +# otherwise mib file will be added to existing loaded mib database +# NOTE: now deprecated in favor of addMibFiles and new module based funcs + my $file = shift; + my $force = shift || '0'; + return 0 if $file and not (-r $file); + SNMP::_read_mib($file,$force); +} + +sub initMib { +# equivalent to calling the snmp library init_mib if Mib is NULL +# if Mib is already loaded this function does nothing +# Pass a zero valued argument to get minimal mib tree initialization +# If non zero argument or no argument then full mib initialization + + SNMP::init_snmp("perl"); + return; + + + if (defined $_[0] and $_[0] == 0) { + SNMP::_init_mib_internals(); + } else { + SNMP::_read_mib(""); + } +} + +sub addMibDirs { +# adds directories to search path when a module is requested to be loaded + SNMP::init_snmp("perl"); + foreach (@_) { + SNMP::_add_mib_dir($_) or return undef; + } + return 1; +} + +sub addMibFiles { +# adds mib definitions to currently loaded mib database from +# file(s) supplied + SNMP::init_snmp("perl"); + foreach (@_) { + SNMP::_read_mib($_) or return undef; + } + return 1; +} + +sub loadModules { +# adds mib module definitions to currently loaded mib database. +# Modules will be searched from previously defined mib search dirs +# Passing and arg of 'ALL' will cause all known modules to be loaded + SNMP::init_snmp("perl"); + foreach (@_) { + SNMP::_read_module($_) or return undef; + } + return 1; +} + +sub unloadModules { +# causes modules to be unloaded from mib database +# Passing and arg of 'ALL' will cause all known modules to be unloaded + warn("SNMP::unloadModules not implemented! (yet)"); +} + +sub translateObj { +# Translate object identifier(tag or numeric) into alternate representation +# (i.e., sysDescr => '.1.3.6.1.2.1.1.1' and '.1.3.6.1.2.1.1.1' => sysDescr) +# when $SNMP::use_long_names or second arg is non-zero the translation will +# return longer textual identifiers (e.g., system.sysDescr). An optional +# third argument of non-zero will cause the module name to be prepended +# to the text name (e.g. 'SNMPv2-MIB::sysDescr'). If no Mib is loaded +# when called and $SNMP::auto_init_mib is enabled then the Mib will be +# loaded. Will return 'undef' upon failure. + SNMP::init_snmp("perl"); + my $obj = shift; + my $temp = shift; + my $include_module_name = shift || "0"; + my $long_names = $temp || $SNMP::use_long_names; + + return undef if not defined $obj; + my $res; + if ($obj =~ /^\.?(\d+\.)*\d+$/) { + $res = SNMP::_translate_obj($obj,1,$long_names,$SNMP::auto_init_mib,0,$include_module_name); + } elsif ($obj =~ /(\.\d+)*$/ && $SNMP::best_guess == 0) { + $res = SNMP::_translate_obj($`,0,$long_names,$SNMP::auto_init_mib,0,$include_module_name); + $res .= $& if defined $res and defined $&; + } elsif ($SNMP::best_guess) { + $res = SNMP::_translate_obj($obj,0,$long_names,$SNMP::auto_init_mib,$SNMP::best_guess,$include_module_name); + } + + return($res); +} + +sub getType { +# return SNMP data type for given textual identifier +# OBJECTID, OCTETSTR, INTEGER, NETADDR, IPADDR, COUNTER +# GAUGE, TIMETICKS, OPAQUE, or undef + my $tag = shift; + SNMP::_get_type($tag, $SNMP::best_guess); +} + +sub mapEnum { +# return the corresponding integer value *or* tag for a given MIB attribute +# and value. The function will sense which direction to perform the conversion +# various arg formats are supported +# $val = SNMP::mapEnum($varbind); # note: will update $varbind +# $val = SNMP::mapEnum('ipForwarding', 'forwarding'); +# $val = SNMP::mapEnum('ipForwarding', 1); +# + my $var = shift; + my ($tag, $val, $update); + if (ref($var) =~ /ARRAY/ or ref($var) =~ /Varbind/) { + $tag = SNMP::Varbind::tag($var); + $val = SNMP::Varbind::val($var); + $update = 1; + } else { + $tag = $var; + $val = shift; + } + my $iflag = $val =~ /^\d+$/; + my $res = SNMP::_map_enum($tag, $val, $iflag, $SNMP::best_guess); + if ($update and defined $res) { SNMP::Varbind::val($var) = $res; } + return($res); +} + +%session_params = (DestHost => 1, + Community => 1, + Version => 1, + Timeout => 1, + Retries => 1, + RemotePort => 1, + LocalPort => 1); + +sub strip_session_params { + my @params; + my @args; + my $param; + while ($param = shift) { + push(@params,$param, shift), next + if $session_params{$param}; + push(@args,$param); + } + @_ = @args; + @params; +} + + +sub snmp_get { +# procedural form of 'get' method. sometimes quicker to code +# but is less efficient since the Session is created and destroyed +# with each call. Takes all the parameters of both SNMP::Session::new and +# SNMP::Session::get (*NOTE*: this api does not support async callbacks) + + my @sess_params = &strip_session_params; + my $sess = new SNMP::Session(@sess_params); + + $sess->get(@_); +} + +sub snmp_getnext { +# procedural form of 'getnext' method. sometimes quicker to code +# but is less efficient since the Session is created and destroyed +# with each call. Takes all the parameters of both SNMP::Session::new and +# SNMP::Session::getnext (*NOTE*: this api does not support async callbacks) + + my @sess_params = &strip_session_params; + my $sess = new SNMP::Session(@sess_params); + + $sess->getnext(@_); +} + +sub snmp_set { +# procedural form of 'set' method. sometimes quicker to code +# but is less efficient since the Session is created and destroyed +# with each call. Takes all the parameters of both SNMP::Session::new and +# SNMP::Session::set (*NOTE*: this api does not support async callbacks) + + my @sess_params = &strip_session_params; + my $sess = new SNMP::Session(@sess_params); + + $sess->set(@_); +} + +sub snmp_trap { +# procedural form of 'trap' method. sometimes quicker to code +# but is less efficient since the Session is created and destroyed +# with each call. Takes all the parameters of both SNMP::TrapSession::new and +# SNMP::TrapSession::trap + + my @sess_params = &strip_session_params; + my $sess = new SNMP::TrapSession(@sess_params); + + $sess->trap(@_); +} + +#--------------------------------------------------------------------- +# Preserves the ability to call MainLoop() with no args so we don't +# break old code +# +# Alternately, MainLoop() could be called as an object method, +# ( $sess->MainLoop() ) , so that $self winds up in @_. Then it would +# be more like : +# my $self = shift; +# .... +# SNMP::_main_loop(......, $self->{SessPtr}); +#--------------------------------------------------------------------- +sub MainLoop { + my $ss = shift if(&SNMP::_api_mode() == SNMP::SNMP_API_SINGLE()); + my $time = shift; + my $callback = shift; + my $time_sec = ($time ? int $time : 0); + my $time_usec = ($time ? int(($time-$time_sec)*1000000) : 0); + SNMP::_main_loop($time_sec,$time_usec,$callback,(defined($ss) ? $ss->{SessPtr} : ())); +} + +sub finish { + SNMP::_mainloop_finish(); +} + +sub reply_cb { + # callback function for async snmp calls + # when triggered, will do a SNMP read on the + # given fd + my $fd = shift; + SNMP::_read_on_fd($fd); +} + +sub select_info { + # retrieves SNMP used fd's and timeout info + # calculates timeout in fractional seconds + # ( easy to use with select statement ) + my($block, $to_sec, $to_usec, @fd_set)=SNMP::_get_select_info(); + my $time_sec_dec = ($block? 0 : $to_sec + $to_usec * 1e-6); + #print "fd's for snmp -> ", @fd_set, "\n"; + #print "block -> ", $block, "\n"; + #print "timeout_sec -> ", $to_sec, "\n"; + #print "timeout_usec -> ", $to_usec, "\n"; + #print "timeout dec -> ", $time_sec_dec, "\n"; + return ($time_sec_dec,@fd_set); +} + +sub check_timeout { + # check to see if a snmp session + # timed out, and if so triggers + # the callback function + SNMP::_check_timeout(); + # check to see when have to check again + my($block, $to_sec, $to_usec, @fd_set)=SNMP::_get_select_info(); + my $time_sec_dec = ($block? 0 : $to_sec + $to_usec * 1e-6); + #print "fd's for snmp -> ", @fd_set, "\n"; + #print "block -> ", $block, "\n"; + #print "timeout_sec -> ", $to_sec, "\n"; + #print "timeout_usec -> ", $to_usec, "\n"; + #print "timeout dec -> ", $time_sec_dec, "\n"; + return ($time_sec_dec); +} + +sub _tie { +# this is a little implementation hack so ActiveState can access pp_tie +# thru perl code. All other environments allow the calling of pp_tie from +# XS code but AS was not exporting it when PERL_OBJECT was used. +# +# short term solution was call this perl func which calls 'tie' +# +# longterm fix is to supply a patch which allows AS to export pp_tie in +# such a way that it can be called from XS code. gsarathy says: +# a patch to util.c is needed to provide access to PL_paddr +# so it is possible to call PL_paddr[OP_TIE] as the compiler does + tie($_[0],$_[1],$_[2],$_[3]); +} + +sub split_vars { + # This sub holds the regex that is used throughout this module + # to parse the base part of an OID from the IID. + # eg: portName.9.30 -> ['portName','9.30'] + my $vars = shift; + + # The regex was changed to this simple form by patch 722075 for some reason. + # Testing shows now (2/05) that it is not needed, and that the long expression + # works fine. AB + # my ($tag, $iid) = ($vars =~ /^(.*?)\.?(\d+)+$/); + + # These following two are the same. Broken down for easier maintenance + # my ($tag, $iid) = ($vars =~ /^((?:\.\d+)+|(?:\w+(?:\-*\w+)+))\.?(.*)$/); + my ($tag, $iid) = + ($vars =~ /^( # Capture $1 + # 1. either this 5.5.5.5 + (?:\.\d+)+ # for grouping, won't increment $1 + | + # 2. or asdf-asdf-asdf-asdf + (?: # grouping again + \w+ # needs some letters followed by + (?:\-*\w+)+ # zero or more dashes, one or more letters + ) + ) + \.? # optionally match a dot + (.*) # whatever is left in the string is our iid ($2) + $/x + ); + return [$tag,$iid]; +} + +package SNMP::Session; + +sub new { + my $type = shift; + my $this = {}; + my ($name, $aliases, $host_type, $len, $thisaddr); + + SNMP::init_snmp("perl"); + + %$this = @_; + + $this->{ErrorStr} = ''; # if methods return undef check for expln. + $this->{ErrorNum} = 0; # contains SNMP error return + + $this->{Version} ||= + NetSNMP::default_store::netsnmp_ds_get_int(NetSNMP::default_store::NETSNMP_DS_LIBRARY_ID, + NetSNMP::default_store::NETSNMP_DS_LIB_SNMPVERSION) || + SNMP::SNMP_DEFAULT_VERSION(); + + if ($this->{Version} eq 128) { + # special handling of the bogus v1 definition. + $this->{Version} = 1; + } + + # allow override of local SNMP port + $this->{LocalPort} ||= 0; + + # destination host defaults to localhost + $this->{DestHost} ||= 'localhost'; + + # community defaults to public + $this->{Community} ||= NetSNMP::default_store::netsnmp_ds_get_string(NetSNMP::default_store::NETSNMP_DS_LIBRARY_ID(), + NetSNMP::default_store::NETSNMP_DS_LIB_COMMUNITY()) || 'public'; + + # number of retries before giving up, defaults to SNMP_DEFAULT_RETRIES + $this->{Retries} = SNMP::SNMP_DEFAULT_RETRIES() unless defined($this->{Retries}); + + # timeout before retry, defaults to SNMP_DEFAULT_TIMEOUT + $this->{Timeout} = SNMP::SNMP_DEFAULT_TIMEOUT() unless defined($this->{Timeout}); + # flag to enable fixing pdu and retrying with a NoSuch error + $this->{RetryNoSuch} ||= 0; + + # backwards compatibility. Make host = host:port + if ($this->{RemotePort} && $this->{DestHost} !~ /:/) { + $this->{DestHost} = $this->{DestHost} . ":" . $this->{RemotePort}; + } + + if ($this->{DestHost} =~ /^(dtls|tls|ssh)/) { + # only works with version 3 + $this->{Version} = 3; + } + + if ($this->{Version} eq '1' or $this->{Version} eq '2' + or $this->{Version} eq '2c') { + $this->{SessPtr} = SNMP::_new_session($this->{Version}, + $this->{Community}, + $this->{DestHost}, + $this->{LocalPort}, + $this->{Retries}, + $this->{Timeout}, + ); + } elsif ($this->{Version} eq '3' ) { + $this->{SecName} ||= + NetSNMP::default_store::netsnmp_ds_get_string(NetSNMP::default_store::NETSNMP_DS_LIBRARY_ID(), + NetSNMP::default_store::NETSNMP_DS_LIB_SECNAME()) || + 'initial'; + if (!$this->{SecLevel}) { + $this->{SecLevel} = + NetSNMP::default_store::netsnmp_ds_get_int(NetSNMP::default_store::NETSNMP_DS_LIBRARY_ID(), + NetSNMP::default_store::NETSNMP_DS_LIB_SECLEVEL()) || + $SNMP::V3_SEC_LEVEL_MAP{'noAuthNoPriv'}; + } elsif ($this->{SecLevel} !~ /^\d+$/) { + $this->{SecLevel} = $SNMP::V3_SEC_LEVEL_MAP{$this->{SecLevel}}; + } + $this->{SecEngineId} ||= ''; + $this->{ContextEngineId} ||= $this->{SecEngineId}; + $this->{Context} ||= + NetSNMP::default_store::netsnmp_ds_get_string(NetSNMP::default_store::NETSNMP_DS_LIBRARY_ID(), + NetSNMP::default_store::NETSNMP_DS_LIB_CONTEXT()) || ''; + + if ($this->{DestHost} =~ /^(dtls|tls|ssh)/) { + # this is a tunneled protocol + + $this->{'OurIdentity'} ||= ''; + $this->{'TheirIdentity'} ||= ''; + $this->{'TheirHostname'} ||= ''; + $this->{'TrustCert'} ||= ''; + + $this->{'SecLevel'} = $SNMP::V3_SEC_LEVEL_MAP{'authPriv'}; + + $this->{SessPtr} = + SNMP::_new_tunneled_session($this->{Version}, + $this->{DestHost}, + $this->{Retries}, + $this->{Timeout}, + $this->{SecName}, + $this->{SecLevel}, + $this->{ContextEngineId}, + $this->{Context}, + $this->{'OurIdentity'}, + $this->{'TheirIdentity'}, + $this->{'TheirHostname'}, + $this->{'TrustCert'}, + ); + + + } else { + # USM or some other internal security protocol + + # USM specific parameters: + $this->{AuthProto} ||= 'DEFAULT'; # use the library's default + $this->{AuthPass} ||= + NetSNMP::default_store::netsnmp_ds_get_string(NetSNMP::default_store::NETSNMP_DS_LIBRARY_ID(), + NetSNMP::default_store::NETSNMP_DS_LIB_AUTHPASSPHRASE()) || + NetSNMP::default_store::netsnmp_ds_get_string(NetSNMP::default_store::NETSNMP_DS_LIBRARY_ID(), + NetSNMP::default_store::NETSNMP_DS_LIB_PASSPHRASE()) || ''; + + $this->{AuthMasterKey} ||= ''; + $this->{PrivMasterKey} ||= ''; + $this->{AuthLocalizedKey} ||= ''; + $this->{PrivLocalizedKey} ||= ''; + + $this->{PrivProto} ||= 'DEFAULT'; # use the library's default + $this->{PrivPass} ||= + NetSNMP::default_store::netsnmp_ds_get_string(NetSNMP::default_store::NETSNMP_DS_LIBRARY_ID(), + NetSNMP::default_store::NETSNMP_DS_LIB_PRIVPASSPHRASE()) || + NetSNMP::default_store::netsnmp_ds_get_string(NetSNMP::default_store::NETSNMP_DS_LIBRARY_ID(), + NetSNMP::default_store::NETSNMP_DS_LIB_PASSPHRASE()) || ''; + $this->{EngineBoots} = 0 if not defined $this->{EngineBoots}; + $this->{EngineTime} = 0 if not defined $this->{EngineTime}; + + $this->{SessPtr} = + SNMP::_new_v3_session($this->{Version}, + $this->{DestHost}, + $this->{Retries}, + $this->{Timeout}, + $this->{SecName}, + $this->{SecLevel}, + $this->{SecEngineId}, + $this->{ContextEngineId}, + $this->{Context}, + $this->{AuthProto}, + $this->{AuthPass}, + $this->{PrivProto}, + $this->{PrivPass}, + $this->{EngineBoots}, + $this->{EngineTime}, + $this->{AuthMasterKey}, + length($this->{AuthMasterKey}), + $this->{PrivMasterKey}, + length($this->{PrivMasterKey}), + $this->{AuthLocalizedKey}, + length($this->{AuthLocalizedKey}), + $this->{PrivLocalizedKey}, + length($this->{PrivLocalizedKey}), + ); + } + } + unless ($this->{SessPtr}) { + warn("unable to create session") if $SNMP::verbose; + return undef; + } + + SNMP::initMib($SNMP::auto_init_mib); # ensures that *some* mib is loaded + + $this->{UseLongNames} = $SNMP::use_long_names + unless exists $this->{UseLongNames}; + $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}; + + # Force UseLongNames if UseNumeric is in use. + $this->{UseLongNames}++ if $this->{UseNumeric}; + + bless $this, $type; +} + +sub update { +# *Not Implemented* +# designed to update the fields of session to allow retargetting to different +# host, community name change, timeout, retry changes etc. Unfortunately not +# working yet because some updates (the address in particular) need to be +# done on the internal session pointer which cannot be fetched w/o touching +# globals at this point which breaks win32. A patch to the net-snmp toolkit +# is needed + my $this = shift; + my ($name, $aliases, $host_type, $len, $thisaddr); + my %new_fields = @_; + + @$this{keys %new_fields} = values %new_fields; + + $this->{UseLongNames} = $SNMP::use_long_names + unless exists $this->{UseLongNames}; + $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}; + + # Force UseLongNames if UseNumeric is in use. + $this->{UseLongNames}++ if $this->{UseNumeric}; + + SNMP::_update_session($this->{Version}, + $this->{Community}, + $this->{DestHost}, + $this->{RemotePort}, + $this->{LocalPort}, + $this->{Retries}, + $this->{Timeout}, + ); + + +} + +sub set { + my $this = shift; + my $vars = shift; + my $varbind_list_ref; + my $res = 0; + + if (ref($vars) =~ /SNMP::VarList/) { + $varbind_list_ref = $vars; + } elsif (ref($vars) =~ /SNMP::Varbind/) { + $varbind_list_ref = [$vars]; + } elsif (ref($vars) =~ /ARRAY/) { + $varbind_list_ref = [$vars]; + $varbind_list_ref = $vars if ref($$vars[0]) =~ /ARRAY/; + } else { + #$varbind_list_ref = [[$tag, $iid, $val]]; + my $split_vars = SNMP::split_vars($vars); + my $val = shift; + push @$split_vars,$val; + $varbind_list_ref = [$split_vars]; + } + my $cb = shift; + + $res = SNMP::_set($this, $varbind_list_ref, $cb); +} + +sub get { + my $this = shift; + my $vars = shift; + my ($varbind_list_ref, @res); + + if (ref($vars) =~ /SNMP::VarList/) { + $varbind_list_ref = $vars; + } elsif (ref($vars) =~ /SNMP::Varbind/) { + $varbind_list_ref = [$vars]; + } elsif (ref($vars) =~ /ARRAY/) { + $varbind_list_ref = [$vars]; + $varbind_list_ref = $vars if ref($$vars[0]) =~ /ARRAY/; + } else { + $varbind_list_ref = [SNMP::split_vars($vars)]; + } + + my $cb = shift; + + @res = SNMP::_get($this, $this->{RetryNoSuch}, $varbind_list_ref, $cb); + + return(wantarray() ? @res : $res[0]); +} + + +my $have_netsnmp_oid = eval { require NetSNMP::OID; }; +sub gettable { + + # + # getTable + # -------- + # + # Get OIDs starting at $table_oid, and continue down the tree + # until we get to an OID which does not start with $table_oid, + # i.e. we have reached the end of this table. + # + + my $state; + + my ($this, $root_oid, @options) = @_; + $state->{'options'} = {@options}; + my ($textnode, $varbinds, $vbl, $res, $repeat); + + # translate the OID into numeric form if its not + if ($root_oid !~ /^[\.0-9]+$/) { + $textnode = $root_oid; + $root_oid = SNMP::translateObj($root_oid); + } else { + $textnode = SNMP::translateObj($root_oid); + } + + # bail if we don't have a valid oid. + return if (!$root_oid); + + # deficed if we're going to parse indexes + my $parse_indexes = (defined($state->{'options'}{'noindexes'})) ? + 0 : $have_netsnmp_oid; + + # get the list of columns we should look at. + my @columns; + if (!$state->{'options'}{'columns'}) { + if ($textnode) { + my %indexes; + + if ($parse_indexes) { + # get indexes + my @indexes = + @{$SNMP::MIB{$textnode}{'children'}[0]{'indexes'} || []}; + # quick translate into a hash + map { $indexes{$_} = 1; } @indexes; + } + + # calculate the list of accessible columns that aren't indexes + my $children = $SNMP::MIB{$textnode}{'children'}[0]{'children'}; + foreach my $c (@$children) { + push @{$state->{'columns'}}, + $root_oid . ".1." . $c->{'subID'} + if (!$indexes{$c->{'label'}}); + } + if ($#{$state->{'columns'}} == -1) { + # some tables are only indexes, and we need to walk at + # least one column. We pick the last. + push @{$state->{'columns'}}, $root_oid . ".1." . + $children->[$#$children]{'subID'} + if ref($state) eq 'HASH' and ref($children) eq 'ARRAY'; + } + } + } else { + # XXX: requires specification in numeric OID... ack.! + @{$state->{'columns'}} = @{$state->{'options'}{'columns'}}; + + # if the columns aren't numeric, we need to turn them into + # numeric columns... + map { + if ($_ !~ /\.1\.3/) { + $_ = $SNMP::MIB{$_}{'objectID'}; + } + } @{$state->{'columns'}}; + } + + # create the initial walking info. + foreach my $c (@{$state->{'columns'}}) { + push @{$state->{'varbinds'}}, [$c]; + push @{$state->{'stopconds'}}, $c; + } + + if ($#{$state->{'varbinds'}} == -1) { + print STDERR "ack: gettable failed to find any columns to look for.\n"; + return; + } + + $vbl = $state->{'varbinds'}; + + my $repeatcount; + if ($this->{Version} eq '1' || $state->{'options'}{nogetbulk}) { + $state->{'repeatcount'} = 1; + } elsif ($state->{'options'}{'repeat'}) { + $state->{'repeatcount'} = $state->{'options'}{'repeat'}; + } elsif ($#{$state->{'varbinds'}} == -1) { + $state->{'repeatcount'} = 1; + } else { + # experimentally determined maybe guess at a best repeat value + # 1000 bytes max (safe), 30 bytes average for encoding of the + # varbind (experimentally determined to be closer to + # 26. Again, being safe. Then devide by the number of + # varbinds. + $state->{'repeatcount'} = int(1000 / 36 / ($#{$state->{'varbinds'}} + 1)); + } + # Make sure we run at least once + if ($state->{'repeatcount'} < 1) { + $state->{'repeatcount'} = 1; + } + + # + # if we've been configured with a callback, then call the + # sub-functions with a callback to our own "next" processing + # function (_gettable_do_it). or else call the blocking method and + # call the next processing function ourself. + # + if ($state->{'options'}{'callback'}) { + if ($this->{Version} ne '1' && !$state->{'options'}{'nogetbulk'}) { + $res = $this->getbulk(0, $state->{'repeatcount'}, $vbl, + [\&_gettable_do_it, $this, $vbl, + $parse_indexes, $textnode, $state]); + } else { + $res = $this->getnext($vbl, + [\&_gettable_do_it, $this, $vbl, + $parse_indexes, $textnode, $state]); + } + } else { + if ($this->{Version} ne '1' && !$state->{'options'}{'nogetbulk'}) { + $res = $this->getbulk(0, $state->{'repeatcount'}, $vbl); + } else { + $res = $this->getnext($vbl); + } + return $this->_gettable_do_it($vbl, $parse_indexes, $textnode, $state); + } + return 0; +} + +sub _gettable_do_it() { + my ($this, $vbl, $parse_indexes, $textnode, $state) = @_; + + my ($res); + + $vbl = $_[$#_] if ($state->{'options'}{'callback'}); + + while ($#$vbl > -1 && !$this->{ErrorNum}) { + if (($#$vbl + 1) % ($#{$state->{'stopconds'}} + 1) != 0) { + if ($vbl->[$#$vbl][2] ne 'ENDOFMIBVIEW') { + # unless it's an end of mib view we didn't get the + # proper number of results back. + print STDERR "ack: gettable results not appropriate\n"; + } + my @k = keys(%{$state->{'result_hash'}}); + last if ($#k > -1); # bail with what we have + return; + } + + $state->{'varbinds'} = []; + my $newstopconds; + + my $lastsetstart = ($state->{'repeatcount'}-1) * ($#{$state->{'stopconds'}}+1); + + for (my $i = 0; $i <= $#$vbl; $i++) { + my $row_oid = SNMP::translateObj($vbl->[$i][0]); + my $row_text = $vbl->[$i][0]; + my $row_index = $vbl->[$i][1]; + my $row_value = $vbl->[$i][2]; + my $row_type = $vbl->[$i][3]; + + if ($row_oid =~ + /^$state->{'stopconds'}[$i % ($#{$state->{'stopconds'}}+1)]/ && + $row_value ne 'ENDOFMIBVIEW' ){ + + if ($row_type eq "OBJECTID") { + + # If the value returned is an OID, translate this + # back in to a textual OID + + $row_value = SNMP::translateObj($row_value); + + } + + # Place the results in a hash + + $state->{'result_hash'}{$row_index}{$row_text} = $row_value; + + # continue past this next time + if ($i >= $lastsetstart) { + push @$newstopconds, + $state->{'stopconds'}->[$i%($#{$state->{'stopconds'}}+1)]; + push @{$state->{'varbinds'}},[$vbl->[$i][0],$vbl->[$i][1]]; + } + } + } + if ($#$newstopconds == -1) { + last; + } + if ($#{$state->{'varbinds'}} == -1) { + print "gettable ack. shouldn't get here\n"; + } + $vbl = $state->{'varbinds'}; + $state->{'stopconds'} = $newstopconds; + + # + # if we've been configured with a callback, then call the + # sub-functions with a callback to our own "next" processing + # function (_gettable_do_it). or else call the blocking method and + # call the next processing function ourself. + # + if ($state->{'options'}{'callback'}) { + if ($this->{Version} ne '1' && !$state->{'options'}{'nogetbulk'}) { + $res = $this->getbulk(0, $state->{'repeatcount'}, $vbl, + [\&_gettable_do_it, $this, $vbl, + $parse_indexes, $textnode, $state]); + } else { + $res = $this->getnext($vbl, + [\&_gettable_do_it, $this, $vbl, + $parse_indexes, $textnode, $state]); + } + return; + } else { + if ($this->{Version} ne '1' && !$state->{'options'}{'nogetbulk'}) { + $res = $this->getbulk(0, $state->{'repeatcount'}, $vbl); + } else { + $res = $this->getnext($vbl); + } + } + } + + # finish up + _gettable_end_routine($state, $parse_indexes, $textnode); + + # return the hash if no callback was specified + if (!$state->{'options'}{'callback'}) { + return($state->{'result_hash'}); + } + + # + # if they provided a callback, call it + # (if an array pass the args as well) + # + if (ref($state->{'options'}{'callback'}) eq 'ARRAY') { + my $code = shift @{$state->{'options'}{'callback'}}; + $code->(@{$state->{'options'}{'callback'}}, $state->{'result_hash'}); + } else { + $state->{'options'}{'callback'}->($state->{'result_hash'}); + } +} + +sub _gettable_end_routine { + my ($state, $parse_indexes, $textnode) = @_; + if ($parse_indexes) { + my @indexes = @{$SNMP::MIB{$textnode}{'children'}[0]{'indexes'}}; + my $i; + foreach my $trow (keys(%{$state->{'result_hash'}})) { + my $noid = new NetSNMP::OID($state->{'columns'}[0] . "." . $trow); + if (!$noid) { + print STDERR "***** ERROR parsing $state->{'columns'}[0].$trow MIB OID\n"; + next; + } + my $nindexes = $noid->get_indexes(); + if (!$nindexes || ref($nindexes) ne 'ARRAY' || + $#indexes != $#$nindexes) { + print STDERR "***** ERROR parsing $state->{'columns'}[0].$trow MIB indexes:\n $noid => " . ref($nindexes) . "\n [should be an ARRAY]\n expended # indexes = $#indexes\n"; + if (ref($nindexes) eq 'ARRAY') { + print STDERR "***** ERROR parsing $state->{'columns'}[0].$trow MIB indexes: " . ref($nindexes) . " $#indexes $#$nindexes\n"; + } + next; + } + + for ($i = 0; $i <= $#indexes; $i++) { + $state->{'result_hash'}{$trow}{$indexes[$i]} = $nindexes->[$i]; + } + } + } +} + + +sub fget { + my $this = shift; + my $vars = shift; + my ($varbind_list_ref, @res); + + if (ref($vars) =~ /SNMP::VarList/) { + $varbind_list_ref = $vars; + } elsif (ref($vars) =~ /SNMP::Varbind/) { + $varbind_list_ref = [$vars]; + } elsif (ref($vars) =~ /ARRAY/) { + $varbind_list_ref = [$vars]; + $varbind_list_ref = $vars if ref($$vars[0]) =~ /ARRAY/; + } else { + $varbind_list_ref = [SNMP::split_vars($vars)]; + } + + my $cb = shift; + + SNMP::_get($this, $this->{RetryNoSuch}, $varbind_list_ref, $cb); + + foreach my $varbind (@$varbind_list_ref) { + my $sub = $this->{VarFormats}{SNMP::Varbind::tag($varbind)} || + $this->{TypeFormats}{SNMP::Varbind::type($varbind)}; + &$sub($varbind) if defined $sub; + push(@res, SNMP::Varbind::val($varbind)); + } + + return(wantarray() ? @res : $res[0]); +} + +sub getnext { + my $this = shift; + my $vars = shift; + my ($varbind_list_ref, @res); + + if (ref($vars) =~ /SNMP::VarList/) { + $varbind_list_ref = $vars; + } elsif (ref($vars) =~ /SNMP::Varbind/) { + $varbind_list_ref = [$vars]; + } elsif (ref($vars) =~ /ARRAY/) { + $varbind_list_ref = [$vars]; + $varbind_list_ref = $vars if ref($$vars[0]) =~ /ARRAY/; + } else { + $varbind_list_ref = [SNMP::split_vars($vars)]; + } + + my $cb = shift; + + @res = SNMP::_getnext($this, $varbind_list_ref, $cb); + + return(wantarray() ? @res : $res[0]); +} + +sub fgetnext { + my $this = shift; + my $vars = shift; + my ($varbind_list_ref, @res); + + if (ref($vars) =~ /SNMP::VarList/) { + $varbind_list_ref = $vars; + } elsif (ref($vars) =~ /SNMP::Varbind/) { + $varbind_list_ref = [$vars]; + } elsif (ref($vars) =~ /ARRAY/) { + $varbind_list_ref = [$vars]; + $varbind_list_ref = $vars if ref($$vars[0]) =~ /ARRAY/; + } else { + $varbind_list_ref = [SNMP::split_vars($vars)]; + } + + my $cb = shift; + + SNMP::_getnext($this, $varbind_list_ref, $cb); + + foreach my $varbind (@$varbind_list_ref) { + my $sub = $this->{VarFormats}{SNMP::Varbind::tag($varbind)} || + $this->{TypeFormats}{SNMP::Varbind::type($varbind)}; + &$sub($varbind) if defined $sub; + push(@res, SNMP::Varbind::val($varbind)); + } + + return(wantarray() ? @res : $res[0]); +} + +sub getbulk { + my $this = shift; + my $nonrepeaters = shift; + my $maxrepetitions = shift; + my $vars = shift; + my ($varbind_list_ref, @res); + + if (ref($vars) =~ /SNMP::VarList/) { + $varbind_list_ref = $vars; + } elsif (ref($vars) =~ /SNMP::Varbind/) { + $varbind_list_ref = [$vars]; + } elsif (ref($vars) =~ /ARRAY/) { + $varbind_list_ref = [$vars]; + $varbind_list_ref = $vars if ref($$vars[0]) =~ /ARRAY/; + } else { + $varbind_list_ref = [SNMP::split_vars($vars)]; + } + + my $cb = shift; + + @res = SNMP::_getbulk($this, $nonrepeaters, $maxrepetitions, $varbind_list_ref, $cb); + + return(wantarray() ? @res : $res[0]); +} + +sub bulkwalk { + my $this = shift; + my $nonrepeaters = shift; + my $maxrepetitions = shift; + my $vars = shift; + my ($varbind_list_ref, @res); + + if (ref($vars) =~ /SNMP::VarList/) { + $varbind_list_ref = $vars; + } elsif (ref($vars) =~ /SNMP::Varbind/) { + $varbind_list_ref = [$vars]; + } elsif (ref($vars) =~ /ARRAY/) { + $varbind_list_ref = [$vars]; + $varbind_list_ref = $vars if ref($$vars[0]) =~ /ARRAY/; + } else { + # my ($tag, $iid) = ($vars =~ /^((?:\.\d+)+|\w+)\.?(.*)$/); + my ($tag, $iid) = ($vars =~ /^(.*?)\.?(\d+)+$/); + $varbind_list_ref = [[$tag, $iid]]; + } + + if (scalar @$varbind_list_ref == 0) { + $this->{ErrorNum} = SNMP::constant("SNMPERR_GENERR", 0); + $this->{ErrorStr} = "cannot bulkwalk() empty variable list"; + return undef; + } + if (scalar @$varbind_list_ref < $nonrepeaters) { + $this->{ErrorNum} = SNMP::constant("SNMPERR_GENERR", 0); + $this->{ErrorStr} = "bulkwalk() needs at least $nonrepeaters varbinds"; + return undef; + } + + my $cb = shift; + @res = SNMP::_bulkwalk($this, $nonrepeaters, $maxrepetitions, + $varbind_list_ref, $cb); + + # Return, in list context, a copy of the array of arrays of Varbind refs. + # In scalar context, return either a reference to the array of arrays of + # Varbind refs, or the request ID for an asynchronous bulkwalk. This is + # a compromise between the getbulk()-ish return, and the more useful array + # of arrays of Varbinds return from the synchronous bulkwalk(). + # + return @res if (wantarray()); + return defined($cb) ? $res[0] : \@res; +} + +my %trap_type = (coldStart => 0, warmStart => 1, linkDown => 2, linkUp => 3, + authFailure => 4, egpNeighborLoss => 5, specific => 6 ); +sub trap { +# (v1) enterprise, agent, generic, specific, uptime, <vars> +# $sess->trap(enterprise=>'.1.3.6.1.4.1.2021', # or 'ucdavis' [default] +# agent => '127.0.0.1', # or 'localhost',[default 1st intf on host] +# generic => specific, # can be omitted if 'specific' supplied +# specific => 5, # can be omitted if 'generic' supplied +# uptime => 1234, # default to localhost uptime (0 on win32) +# [[ifIndex, 1, 1],[sysLocation, 0, "here"]]); # optional vars +# # always last +# (v2) oid, uptime, <vars> +# $sess->trap(uptime => 1234, +# oid => 'snmpRisingAlarm', +# [[ifIndex, 1, 1],[sysLocation, 0, "here"]]); # optional vars +# # always last +# # always last + + + my $this = shift; + my $vars = pop if ref($_[$#_]); # last arg may be varbind or varlist + my %param = @_; + my ($varbind_list_ref, @res); + + if (ref($vars) =~ /SNMP::VarList/) { + $varbind_list_ref = $vars; + } elsif (ref($vars) =~ /SNMP::Varbind/) { + $varbind_list_ref = [$vars]; + } elsif (ref($vars) =~ /ARRAY/) { + $varbind_list_ref = [$vars]; + $varbind_list_ref = $vars if ref($$vars[0]) =~ /ARRAY/; + } + + if ($this->{Version} eq '1') { + my $enterprise = $param{enterprise} || 'ucdavis'; + $enterprise = SNMP::translateObj($enterprise) + unless $enterprise =~ /^[\.\d]+$/; + my $agent = $param{agent} || ''; + my $generic = $param{generic} || 'specific'; + $generic = $trap_type{$generic} || $generic; + my $uptime = $param{uptime} || SNMP::_sys_uptime(); + my $specific = $param{specific} || 0; + @res = SNMP::_trapV1($this, $enterprise, $agent, $generic, $specific, + $uptime, $varbind_list_ref); + } elsif (($this->{Version} eq '2')|| ($this->{Version} eq '2c')) { + my $trap_oid = $param{oid} || $param{trapoid} || '.0.0'; + my $uptime = $param{uptime} || SNMP::_sys_uptime(); + @res = SNMP::_trapV2($this, $uptime, $trap_oid, $varbind_list_ref); + } + + return(wantarray() ? @res : $res[0]); +} + +sub inform { +# (v3) oid, uptime, <vars> +# $sess->inform(uptime => 1234, +# oid => 'coldStart', +# [[ifIndex, 1, 1],[sysLocation, 0, "here"]]); # optional vars +# # then callback + # always last + + + my $this = shift; + my $vars; + my $cb; + $cb = pop if ref($_[$#_]) eq 'CODE'; # last arg may be code + $vars = pop if ref($_[$#_]); # varbind or varlist + my %param = @_; + my ($varbind_list_ref, @res); + + if (ref($vars) =~ /SNMP::VarList/) { + $varbind_list_ref = $vars; + } elsif (ref($vars) =~ /SNMP::Varbind/) { + $varbind_list_ref = [$vars]; + } elsif (ref($vars) =~ /ARRAY/) { + $varbind_list_ref = [$vars]; + $varbind_list_ref = $vars if ref($$vars[0]) =~ /ARRAY/; + } + + my $trap_oid = $param{oid} || $param{trapoid}; + my $uptime = $param{uptime} || SNMP::_sys_uptime(); + + if($this->{Version} eq '3') { + @res = SNMP::_inform($this, $uptime, $trap_oid, $varbind_list_ref, $cb); + } else { + warn("error:inform: This version doesn't support the command\n"); + } + + return(wantarray() ? @res : $res[0]); +} + +package SNMP::TrapSession; +@SNMP::TrapSession::ISA = ('SNMP::Session'); + +sub new { + my $type = shift; + + # allow override of remote SNMP trap port + unless (grep(/RemotePort/, @_)) { + push(@_, 'RemotePort', 162); # push on new default for trap session + } + + SNMP::Session::new($type, @_); +} + +package SNMP::Varbind; + +$SNMP::Varbind::tag_f = 0; +$SNMP::Varbind::iid_f = 1; +$SNMP::Varbind::val_f = 2; +$SNMP::Varbind::type_f = 3; +$SNMP::Varbind::time_f = 4; + +sub new { + my $type = shift; + my $this = shift; + $this ||= []; + bless $this; +} + +sub tag { + $_[0]->[$SNMP::Varbind::tag_f]; +} + +sub iid { + $_[0]->[$SNMP::Varbind::iid_f]; +} + +sub val { + $_[0]->[$SNMP::Varbind::val_f]; +} + +sub type { + $_[0]->[$SNMP::Varbind::type_f]; +} + +sub name { + if (defined($_[0]->[$SNMP::Varbind::iid_f]) && ($_[0]->[$SNMP::Varbind::iid_f] =~ m/^[0-9]+$/)) { + return $_[0]->[$SNMP::Varbind::tag_f] . "." . $_[0]->[$SNMP::Varbind::iid_f]; + } + + return $_[0]->[$SNMP::Varbind::tag_f]; +} + +sub fmt { + my $self = shift; + return $self->name . " = \"" . $self->val . "\" (" . $self->type . ")"; +} + + +#sub DESTROY { +# print "SNMP::Varbind::DESTROY($_[0])\n"; +#} + +package SNMP::VarList; + +sub new { + my $type = shift; + my $this = []; + my $varb; + foreach $varb (@_) { + $varb = new SNMP::Varbind($varb) unless ref($varb) =~ /SNMP::Varbind/; + push(@{$this}, $varb); + } + + bless $this; +} + +#sub DESTROY { +# print "SNMP::VarList::DESTROY($_[0])\n"; +#} + +package SNMP::DEBUGGING; +# controls info/debugging output from SNMP module and libsnmp +# $SNMP::debugging == 1 => enables general info and warning output +# (eqiv. to setting $SNMP::verbose) +# $SNMP::debugging == 2 => enables do_debugging from libsnmp as well +# $SNMP::debugging == 3 => enables packet_dump from libsnmp as well +sub TIESCALAR { my $class = shift; my $val; bless \$val, $class; } + +sub FETCH { ${$_[0]}; } + +sub STORE { + $SNMP::verbose = $_[1]; + SNMP::_set_debugging($_[1]>1); + $SNMP::dump_packet = ($_[1]>2); + ${$_[0]} = $_[1]; +} + +sub DELETE { + $SNMP::verbose = 0; + SNMP::_set_debugging(0); + $SNMP::dump_packet = 0; + ${$_[0]} = undef; +} + +package SNMP::DEBUG_INTERNALS; # Controls SNMP.xs debugging. +sub TIESCALAR { my $class = shift; my $val; bless \$val, $class; } + +sub FETCH { ${$_[0]}; } + +sub STORE { + SNMP::_debug_internals($_[1]); + ${$_[0]} = $_[1]; +} + +sub DELETE { + SNMP::_debug_internals(0); + ${$_[0]} = undef; +} + +package SNMP::DUMP_PACKET; +# controls packet dump output from libsnmp + +sub TIESCALAR { my $class = shift; my $val; bless \$val, $class; } + +sub FETCH { ${$_[0]}; } + +sub STORE { SNMP::_dump_packet($_[1]); ${$_[0]} = $_[1]; } + +sub DELETE { SNMP::_dump_packet(0); ${$_[0]} = 0; } + +package SNMP::MIB; + +sub TIEHASH { + bless {}; +} + +sub FETCH { + my $this = shift; + my $key = shift; + + if (!defined $this->{$key}) { + tie(%{$this->{$key}}, 'SNMP::MIB::NODE', $key) or return undef; + } + $this->{$key}; +} + +sub STORE { + warn "STORE(@_) : write access to the MIB not implemented\n"; +} + +sub DELETE { + delete $_[0]->{$_[1]}; # just delete cache entry +} + +sub FIRSTKEY { return '.1'; } # this should actually start at .0 but + # because nodes are not stored in lexico + # order in ucd-snmp node tree walk will + # miss most of the tree +sub NEXTKEY { # this could be sped up by using an XS __get_next_oid maybe + my $node = $_[0]->FETCH($_[1])->{nextNode}; + $node->{objectID}; +} +sub EXISTS { exists $_[0]->{$_[1]} || $_[0]->FETCH($_[1]); } +sub CLEAR { undef %{$_[0]}; } # clear the cache + +package SNMP::MIB::NODE; +my %node_elements = + ( + objectID => 0, # dotted decimal fully qualified OID + label => 0, # leaf textual identifier (e.g., 'sysDescr') + subID => 0, # leaf numeric OID component of objectID (e.g., '1') + moduleID => 0, # textual identifier for module (e.g., 'RFC1213-MIB') + parent => 0, # parent node + children => 0, # array reference of children nodes + indexes => 0, # returns array of column labels + implied => 0, # boolean: is the last index IMPLIED + varbinds => 0, # returns array of trap/notification varbinds + nextNode => 0, # next lexico node (BUG! does not return in lexico order) + type => 0, # returns simple type (see getType for values) + access => 0, # returns ACCESS (ReadOnly, ReadWrite, WriteOnly, + # NoAccess, Notify, Create) + status => 0, # returns STATUS (Mandatory, Optional, Obsolete, + # Deprecated) + syntax => 0, # returns 'textualConvention' if defined else 'type' + textualConvention => 0, # returns TEXTUAL-CONVENTION + units => 0, # returns UNITS + hint => 0, # returns HINT + enums => 0, # returns hash ref {tag => num, ...} + ranges => 0, # returns array ref of hash ref [{low => num, high => num}] + defaultValue => 0, # returns default value + description => 0, # returns DESCRIPTION ($SNMP::save_descriptions must + # be set prior to MIB initialization/parsing + augments => 0, # textual identifier of augmented object + ); + +# sub TIEHASH - implemented in SNMP.xs + +# sub FETCH - implemented in SNMP.xs + +sub STORE { + warn "STORE(@_): write access to MIB node not implemented\n"; +} + +sub DELETE { + warn "DELETE(@_): write access to MIB node not implemented\n"; +} + +sub FIRSTKEY { my $k = keys %node_elements; (each(%node_elements))[0]; } +sub NEXTKEY { (each(%node_elements))[0]; } +sub EXISTS { exists($node_elements{$_[1]}); } +sub CLEAR { + warn "CLEAR(@_): write access to MIB node not implemented\n"; +} + +#sub DESTROY { +# warn "DESTROY(@_): write access to MIB node not implemented\n"; +# # print "SNMP::MIB::NODE::DESTROY : $_[0]->{label} ($_[0])\n"; +#} +package SNMP::MIB::SAVE_DESCR; + +sub TIESCALAR { my $class = shift; my $val; bless \$val, $class; } + +sub FETCH { ${$_[0]}; } + +sub STORE { SNMP::_set_save_descriptions($_[1]); ${$_[0]} = $_[1]; } + +sub DELETE { SNMP::_set_save_descriptions(0); ${$_[0]} = 0; } + +package SNMP::MIB::REPLACE_NEWER; # Controls MIB parsing + +sub TIESCALAR { my $class = shift; my $val; bless \$val, $class; } + +sub FETCH { ${$_[0]}; } + +sub STORE { + SNMP::_set_replace_newer($_[1]); + ${$_[0]} = $_[1]; +} + +sub DELETE { + SNMP::_set_replace_newer(0); + ${$_[0]} = 0; +} + +package SNMP::MIB::MIB_OPTIONS; + +sub TIESCALAR { my $class = shift; my $val; bless \$val, $class; } + +sub FETCH { ${$_[0]}; } + +sub STORE { SNMP::_mib_toggle_options($_[1]); ${$_[0]} = $_[1]; } + +sub DELETE { SNMP::_mib_toggle_options(0); ${$_[0]} = ''; } + +package SNMP; +END{SNMP::_sock_cleanup() if defined &SNMP::_sock_cleanup;} +# Autoload methods go after __END__, and are processed by the autosplit prog. + +1; +__END__ + +=head1 NAME + +SNMP - The Perl5 'SNMP' Extension Module for the Net-SNMP SNMP package. + +=head1 SYNOPSIS + + use SNMP; + ... + $sess = new SNMP::Session(DestHost => localhost, Community => public); + $val = $sess->get('sysDescr.0'); + ... + $vars = new SNMP::VarList([sysDescr,0], [sysContact,0], [sysLocation,0]); + @vals = $sess->get($vars); + ... + $vb = new SNMP::Varbind(); + do { + $val = $sess->getnext($vb); + print "@{$vb}\n"; + } until ($sess->{ErrorNum}); + ... + $SNMP::save_descriptions = 1; + SNMP::initMib(); # assuming mib is not already loaded + print "$SNMP::MIB{sysDescr}{description}\n"; + +=head1 DESCRIPTION + + +Note: The perl SNMP 5.0 module which comes with net-snmp 5.0 and +higher is different than previous versions in a number of ways. Most +importantly, it behaves like a proper net-snmp application and calls +init_snmp properly, which means it will read configuration files and +use those defaults where appropriate automatically parse MIB files, +etc. This will likely affect your perl applications if you have, for +instance, default values set up in your snmp.conf file (as the perl +module will now make use of those defaults). The documentation, +however, has sadly not been updated yet (aside from this note), nor is +the read_config default usage implementation fully complete. + +The basic operations of the SNMP protocol are provided by this module +through an object oriented interface for modularity and ease of use. +The primary class is SNMP::Session which encapsulates the persistent +aspects of a connection between the management application and the +managed agent. Internally the class is implemented as a blessed hash +reference. This class supplies 'get', 'getnext', 'set', 'fget', and +'fgetnext' method calls. The methods take a variety of input argument +formats and support both synchronous and asynchronous operation through +a polymorphic API (i.e., method behaviour varies dependent on args +passed - see below). + +=head1 SNMP::Session + +$sess = new SNMP::Session(DestHost => 'host', ...) + +The following arguments may be passed to new as a hash. + +=head2 Basic Options + +=over 4 + +=item DestHost + +Hostname or IP address of the SNMP agent you want to talk to. +Specified in Net-SNMP formatted agent addresses. These addresses +typically look like one of the following: + + localhost + tcp:localhost + tls:localhost + tls:localhost:9876 + udp6:[::1]:9876 + unix:/some/path/to/file/socket + +Defaults to 'localhost'. + +=item Version + +SNMP version to use. + +The default is taken from library configuration - probably 3 [1, 2 +(same as 2c), 2c, 3]. + +=item Timeout + +The number of micro-seconds to wait before resending a request. + +The default is '1000000' + +=item Retries + +The number of times to retry a request. + +The default is '5' + +=item RetryNoSuch + +If enabled NOSUCH errors in 'get' pdus will +be repaired, removing the varbind in error, and resent - +undef will be returned for all NOSUCH varbinds, when set +to '0' this feature is disabled and the entire get request +will fail on any NOSUCH error (applies to v1 only) + +The default is '0'. + +=back + +=head2 SNMPv3/TLS Options + +=over + +=item OurIdentity + +Our X.509 identity to use, which should either be a fingerprint or the +filename that holds the certificate. + +=item TheirIdentity + +The remote server's identity to connect to, specified as eihter a +fingerprint or a file name. Either this must be specified, or the +hostname below along with a trust anchor. + +=item TheirHostname + +The remote server's hostname that is expected. If their certificate +was signed by a CA then their hostname presented in the certificate +must match this value or the connection fails to be established (to +avoid man-in-the-middle attacks). + +=item TrustCert + +A trusted certificate to use a trust anchor (like a CA certificate) +for verifying a remote server's certificate. If a CA certificate is +used to validate a certificate then the TheirHostname parameter must +also be specified to ensure their presente hostname in the certificate +matches. + +=back + +=head2 SNMPv3/USM Options + +=over + +=item SecName + +The SNMPv3 security name to use (most for SNMPv3 with USM). + +The default is 'initial'. + +=item SecLevel + +The SNMPv3 security level to use [noAuthNoPriv, authNoPriv, authPriv] (v3) + +The default is 'noAuthNoPriv'. + +=item SecEngineId + +The SNMPv3 security engineID to use (if the snmpv3 security model +needs it; for example USM). + +The default is <none>, security engineID and it will be probed if not +supplied (v3) + +=item ContextEngineId + +The SNMPv3 context engineID to use. + +The default is the <none> and will be set either to the SecEngineId +value if set or discovered or will be discovered in other ways if +using TLS (RFC5343 based discovery). + +=item Context + +The SNMPv3 context name to use. + +The default is '' (an empty string) + +=item AuthProto + +The SNMPv3/USM authentication protocol to use [MD5, SHA]. + +The default is 'MD5'. + +=item AuthPass + +The SNMPv3/USM authentication passphrase to use. + +default <none>, authentication passphrase + +=item PrivProto + +The SNMPv3/USM privacy protocol to use [DES, AES]. + +The default is 'DES'. + +=item PrivPass + +The SNMPv3/USM privacy passphrase to use. + +default <none>, privacy passphrase (v3) + +=item AuthMasterKey + +=item PrivMasterKey + +=item AuthLocalizedKey + +=item PrivLocalizedKey + +Directly specified SNMPv3 USM user keys (used if you want to specify +the keys instead of deriving them from a password as above). + +=back + +=head2 SNMPv1 and SNMPv2c Options + +=item Community + +For SNMPv1 and SNMPv2c, the clear-text community name to use. + +The default is 'public'. + +=head2 Other Configuration Options + +=over + +=item VarFormats + +default 'undef', used by 'fget[next]', holds an hash +reference of output value formatters, (e.g., {<obj> => +<sub-ref>, ... }, <obj> must match the <obj> and format +used in the get operation. A special <obj>, '*', may be +used to apply all <obj>s, the supplied sub is called to +translate the value to a new format. The sub is called +passing the Varbind as the arg + +=item TypeFormats + +default 'undef', used by 'fget[next]', holds an hash +reference of output value formatters, (e.g., {<type> => +<sub-ref>, ... }, the supplied sub is called to translate +the value to a new format, unless a VarFormat mathces first +(e.g., $sess->{TypeFormats}{INTEGER} = \&mapEnum(); +although this can be done more efficiently by enabling +$SNMP::use_enums or session creation param 'UseEnums') + +=item UseLongNames + +defaults to the value of SNMP::use_long_names at time +of session creation. set to non-zero to have <tags> +for 'getnext' methods generated preferring longer Mib name +convention (e.g., system.sysDescr vs just sysDescr) + +=item UseSprintValue + +defaults to the value of SNMP::use_sprint_value at time +of session creation. set to non-zero to have return values +for 'get' and 'getnext' methods formatted with the libraries +snprint_value function. This will result in certain data types +being returned in non-canonical format Note: values returned +with this option set may not be appropriate for 'set' operations +(see discussion of value formats in <vars> description section) + +=item UseEnums + +defaults to the value of SNMP::use_enums at time of session +creation. set to non-zero to have integer return values +converted to enumeration identifiers if possible, these values +will also be acceptable when supplied to 'set' operations + +=item UseNumeric + +defaults to the value of SNMP::use_numeric at time of session +creation. set to non-zero to have <tags> for get methods returned +as numeric OID's rather than descriptions. UseLongNames will be +set so that the full OID is returned to the caller. + +=item BestGuess + +defaults to the value of SNMP::best_guess at time of session +creation. this setting controls how <tags> are parsed. setting to +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 + +read-only, holds the error message assoc. w/ last request + +=item ErrorNum + +read-only, holds the snmp_err or staus of last request + +=item ErrorInd + +read-only, holds the snmp_err_index when appropriate + +=back + +Private variables: + +=over + +=item DestAddr + +internal field used to hold the translated DestHost field + +=item SessPtr + +internal field used to cache a created session structure + +=item RemotePort + +Obsolete. Please use the DestHost specifier to indicate the hostname +and port combination instead of this paramet. + +=back + +=head2 SNMP::Session methods + +=over + +=item $sess->update(E<lt>fieldsE<gt>) + +Updates the SNMP::Session object with the values fields +passed in as a hash list (similar to new(E<lt>fieldsE<gt>)) +B<(WARNING! not fully implemented)> + +=item $sess->get(E<lt>varsE<gt> [,E<lt>callbackE<gt>]) + +do SNMP GET, multiple <vars> formats accepted. +for syncronous operation <vars> will be updated +with value(s) and type(s) and will also return +retrieved value(s). If <callback> supplied method +will operate asynchronously + +=item $sess->fget(E<lt>varsE<gt> [,E<lt>callbackE<gt>]) + +do SNMP GET like 'get' and format the values according +the handlers specified in $sess->{VarFormats} and +$sess->{TypeFormats} + +=item $sess->getnext(E<lt>varsE<gt> [,E<lt>callbackE<gt>]) + +do SNMP GETNEXT, multiple <vars> formats accepted, +returns retrieved value(s), <vars> passed as arguments are +updated to indicate next lexicographical <obj>,<iid>,<val>, +and <type> + +Note: simple string <vars>,(e.g., 'sysDescr.0') +form is not updated. If <callback> supplied method +will operate asynchronously + +=item $sess->fgetnext(E<lt>varsE<gt> [,E<lt>callbackE<gt>]) + +do SNMP GETNEXT like getnext and format the values according +the handlers specified in $sess->{VarFormats} and +$sess->{TypeFormats} + +=item $sess->set(E<lt>varsE<gt> [,E<lt>callbackE<gt>]) + +do SNMP SET, multiple <vars> formats accepted. +the value field in all <vars> formats must be in a canonical +format (i.e., well known format) to ensure unambiguous +translation to SNMP MIB data value (see discussion of +canonical value format <vars> description section), +returns snmp_errno. If <callback> supplied method +will operate asynchronously + +=item $sess->getbulk(E<lt>non-repeatersE<gt>, E<lt>max-repeatersE<gt>, E<lt>varsE<gt>) + +do an SNMP GETBULK, from the list of Varbinds, the single +next lexico instance is fetched for the first n Varbinds +as defined by <non-repeaters>. For remaining Varbinds, +the m lexico instances are retrieved each of the remaining +Varbinds, where m is <max-repeaters>. + +=item $sess->bulkwalk(E<lt>non-repeatersE<gt>, E<lt>max-repeatersE<gt>, E<lt>varsE<gt> [,E<lt>callbackE<gt>]) + +Do a "bulkwalk" of the list of Varbinds. This is done by +sending a GETBULK request (see getbulk() above) for the +Varbinds. For each requested variable, the response is +examined to see if the next lexico instance has left the +requested sub-tree. Any further instances returned for +this variable are ignored, and the walk for that sub-tree +is considered complete. + +If any sub-trees were not completed when the end of the +responses is reached, another request is composed, consisting +of the remaining variables. This process is repeated until +all sub-trees have been completed, or too many packets have +been exchanged (to avoid loops). + +The bulkwalk() method returns an array containing an array of +Varbinds, one for each requested variable, in the order of the +variable requests. Upon error, bulkwalk() returns undef and +sets $sess->ErrorStr and $sess->ErrorNum. If a callback is +supplied, bulkwalk() returns the SNMP request id, and returns +immediately. The callback will be called with the supplied +argument list and the returned variables list. + +Note: Because the client must "discover" that the tree is +complete by comparing the returned variables with those that +were requested, there is a potential "gotcha" when using the +max-repeaters value. Consider the following code to print a +list of interfaces and byte counts: + + $numInts = $sess->get('ifNumber.0'); + ($desc, $in, $out) = $sess->bulkwalk(0, $numInts, + [['ifDescr'], ['ifInOctets'], ['ifOutOctets']]); + + for $i (0..($numInts - 1)) { + printf "Interface %4s: %s inOctets, %s outOctets\n", + $$desc[$i]->val, $$in[$i]->val, $$out[$i]->val; + } + +This code will produce *two* requests to the agent -- the first +to get the interface values, and the second to discover that all +the information was in the first packet. To get around this, +use '$numInts + 1' for the max_repeaters value. This asks the +agent to include one additional (unrelated) variable that signals +the end of the sub-tree, allowing bulkwalk() to determine that +the request is complete. + +=item $results = $sess->gettable(E<lt>TABLE OIDE<gt>, E<lt>OPTIONS<gt>) + +This will retrieve an entire table of data and return a hash reference +to that data. The returned hash reference will have indexes of the +OID suffixes for the index data as the key. The value for each entry +will be another hash containing the data for a given row. The keys to +that hash will be the column names, and the values will be the data. + +Example: + + #!/usr/bin/perl + + use SNMP; + use Data::Dumper; + + my $s = new SNMP::Session(DestHost => 'localhost'); + + print Dumper($s->gettable('ifTable')); + +On my machine produces: + + $VAR1 = { + '6' => { + 'ifMtu' => '1500', + 'ifPhysAddress' => 'PV', + # ... + 'ifInUnknownProtos' => '0' + }, + '4' => { + 'ifMtu' => '1480', + 'ifPhysAddress' => '', + # ... + 'ifInUnknownProtos' => '0' + }, + # ... + }; + +By default, it will try to do as optimized retrieval as possible. +It'll request multiple columns at once, and use GETBULK if possible. +A few options may be specified by passing in an I<OPTIONS> hash +containing various parameters: + +=over + +=item noindexes => 1 + +Instructs the code not to parse the indexes and place the results in +the second hash. If you don't need the index data, this will be +faster. + +=item columns => [ colname1, ... ] + +This specifies which columns to collect. By default, it will try to +collect all the columns defined in the MIB table. + +=item repeat => I<COUNT> + +Specifies a GETBULK repeat I<COUNT>. IE, it will request this many +varbinds back per column when using the GETBULK operation. Shortening +this will mean smaller packets which may help going through some +systems. By default, this value is calculated and attempts to guess +at what will fit all the results into 1000 bytes. This calculation is +fairly safe, hopefully, but you can either raise or lower the number +using this option if desired. In lossy networks, you want to make +sure that the packets don't get fragmented and lowering this value is +one way to help that. + +=item nogetbulk => 1 + +Force the use of GETNEXT rather than GETBULK. (always true for +SNMPv1, as it doesn't have GETBULK anyway). Some agents are great +implementers of GETBULK and this allows you to force the use of +GETNEXT operations instead. + +=item callback => \&subroutine + +=item callback => [\&subroutine, optarg1, optarg2, ...] + +If a callback is specified, gettable will return quickly without +returning results. When the results are finally retrieved the +callback subroutine will be called (see the other sections defining +callback behaviour and how to make use of SNMP::MainLoop which is +required fro this to work). An additional argument of the normal hash +result will be added to the callback subroutine arguments. + +Note 1: internally, the gettable function uses it's own callbacks +which are passed to getnext/getbulk as appropriate. + +Note 2: callback support is only available in the SNMP module version +5.04 and above. To test for this in code intending to support both +versions prior to 5.04 and 5.04 and up, the following should work: + + if ($response = $sess->gettable('ifTable', callback => \&my_sub)) { + # got a response, gettable doesn't support callback + my_sub($response); + $no_mainloop = 1; + } + +Deciding on whether to use SNMP::MainLoop is left as an exercise to +the reader since it depends on whether your code uses other callbacks +as well. + +=back + +=back + +=head1 SNMP::TrapSession + +$sess = new SNMP::Session(DestHost => 'host', ...) + +supports all applicable fields from SNMP::Session +(see above) + +=head2 SNMP::TrapSession methods + +=over + +=item $sess->trap(enterprise, agent, generic, specific, uptime, <vars>) + + $sess->trap(enterprise=>'.1.3.6.1.4.1.2021', # or 'ucdavis' [default] + agent => '127.0.0.1', # or 'localhost',[dflt 1st intf on host] + generic => specific, # can be omitted if 'specific' supplied + specific => 5, # can be omitted if 'generic' supplied + uptime => 1234, # dflt to localhost uptime (0 on win32) + [[ifIndex, 1, 1],[sysLocation, 0, "here"]]); # optional vars + # always last + +=item trap(oid, uptime, <vars>) - v2 format + + $sess->trap(oid => 'snmpRisingAlarm', + uptime => 1234, + [[ifIndex, 1, 1],[sysLocation, 0, "here"]]); # optional vars + # always last + +=back + +=head1 Acceptable variable formats: + +<vars> may be one of the following forms: + +=over + +=item SNMP::VarList + +represents an array of MIB objects to get or set, +implemented as a blessed reference to an array of +SNMP::Varbinds, (e.g., [<varbind1>, <varbind2>, ...]) + +=item SNMP::Varbind + +represents a single MIB object to get or set, implemented as +a blessed reference to a 4 element array; +[<obj>, <iid>, <val>, <type>]. + +=over + +=item <obj> + +one of the following forms: + +=over + +=item 1) + +leaf identifier (e.g., 'sysDescr') assumed to be +unique for practical purposes + +=item 2) + +fully qualified identifier (e.g., +'.iso.org.dod.internet.mgmt.mib-2.system.sysDescr') + +=item 3) + +fully qualified, dotted-decimal, numeric OID (e.g., +'.1.3.6.1.2.1.1.1') + +=back + +=item <iid> + +the dotted-decimal, instance identifier. for +scalar MIB objects use '0' + +=item <val> + +the SNMP data value retrieved from or being set +to the agents MIB. for (f)get(next) operations +<val> may have a variety of formats as determined by +session and package settings. However for set +operations the <val> format must be canonical to +ensure unambiguous translation. The canonical forms +are as follows: + +=over + +=item OBJECTID + +dotted-decimal (e.g., .1.3.6.1.2.1.1.1) + +=item OCTETSTR + +perl scalar containing octets + +=item INTEGER + +decimal signed integer (or enum) + +=item NETADDR + +dotted-decimal + +=item IPADDR + +dotted-decimal + +=item COUNTER + +decimal unsigned integer + +=item COUNTER64 + +decimal unsigned integer + +=item GAUGE + +decimal unsigned integer + +=item UINTEGER + +decimal unsigned integer + +=item TICKS + +decimal unsigned integer + +=item OPAQUE + +perl scalar containing octets + +=item NULL + +perl scalar containing nothing + +=back + +=item <type> + +SNMP data type (see list above), this field is +populated by 'get' and 'getnext' operations. In +some cases the programmer needs to populate this +field when passing to a 'set' operation. this +field need not be supplied when the attribute +indicated by <tag> is already described by loaded +Mib modules. for 'set's, if a numeric OID is used +and the object is not currently in the loaded Mib, +the <type> field must be supplied + +=back + +=item simple string + +light weight form of <var> used to 'set' or 'get' a +single attribute without constructing an SNMP::Varbind. +stored in a perl scalar, has the form '<tag>.<iid>', +(e.g., 'sysDescr.0'). for 'set' operations the value +is passed as a second arg. Note: This argument form is +not updated in get[next] operations as are the other forms. + +=back + +=head1 Acceptable callback formats + +<callback> may be one of the following forms: + +=over + +=item without arguments + +=over + +=item \&subname + +=item sub { ... } + +=back + +=item or with arguments + +=over + +=item [ \&subname, $arg1, ... ] + +=item [ sub { ... }, $arg1, ... ] + +=item [ "method", $obj, $arg1, ... ] + +=back + +=back + +callback will be called when response is received or timeout +occurs. the last argument passed to callback will be a +SNMP::VarList reference. In case of timeout the last argument +will be undef. + +=over + +=item &SNMP::MainLoop([<timeout>, [<callback>]]) + +to be used with async SNMP::Session +calls. MainLoop must be called after initial async calls +so return packets from the agent will not be processed. +If no args supplied this function enters an infinite loop +so program must be exited in a callback or externally +interrupted. If <timeout(sic) + +=item &SNMP::finish() + +This function, when called from an SNMP::MainLoop() callback +function, will cause the current SNMP::MainLoop() to return +after the callback is completed. finish() can be used to +terminate an otherwise-infinite MainLoop. A new MainLoop() +instance can then be started to handle further requests. + +=back + +=head1 SNMP package variables and functions + +=over + +=item $SNMP::VERSION + +the current version specifier (e.g., 3.1.0) + +=item $SNMP::auto_init_mib + +default '1', set to 0 to disable automatic reading +of the MIB upon session creation. set to non-zero +to call initMib at session creation which will result +in MIB loading according to Net-SNMP env. variables (see +man mib_api) + +=item $SNMP::verbose + +default '0', controls warning/info output of +SNMP module, 0 => no output, 1 => enables warning/info +output from SNMP module itself (is also controlled +by SNMP::debugging - see below) + +=item $SNMP::use_long_names + +default '0', set to non-zero to enable the use of +longer Mib identifiers. see translateObj. will also +influence the formatting of <tag> in varbinds returned +from 'getnext' operations. Can be set on a per session +basis (UseLongNames) + +=item $SNMP::use_sprint_value + +default '0', set to non-zero to enable formatting of +response values using the snmp libraries snprint_value +function. can also be set on a per session basis (see +UseSprintValue) Note: returned values may not be +suitable for 'set' operations + +=item $SNMP::use_enums + +default '0',set non-zero to return values as enums and +allow sets using enums where appropriate. integer data +will still be accepted for set operations. can also be +set on a per session basis (see UseEnums) + +=item $SNMP::use_numeric + +default to '0',set to non-zero to have <tags> for 'get' +methods returned as numeric OID's rather than descriptions. +UseLongNames will be set so that the entire OID will be +returned. Set on a per-session basis (see UseNumeric). + +=item $SNMP::best_guess + +default '0'. This setting controls how <tags> are +parsed. Setting to 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). Can also be set +on a per session basis (see BestGuess) + +=item $SNMP::save_descriptions + +default '0',set non-zero to have mib parser save +attribute descriptions. must be set prior to mib +initialization + +=item $SNMP::debugging + +default '0', controls debugging output level +within SNMP module and libsnmp + +=over + +=item 1 + +enables 'SNMP::verbose' (see above) + +=item 2 + +level 1 plus snmp_set_do_debugging(1) + +=item 3 + +level 2 plus snmp_set_dump_packet(1) + +=back + +=item $SNMP::dump_packet + +default '0', set [non-]zero to independently set +snmp_set_dump_packet() + +=item SNMP::register_debug_tokens() + +Allows to register one or more debug tokens, just like the -D option of snmpd. +Each debug token enables a group of debug statements. An example: +SNMP::register_debug_tokens("tdomain,netsnmp_unix"); + +=back + +=head1 %SNMP::MIB + +a tied hash to access parsed MIB information. After +the MIB has been loaded this hash allows access to +to the parsed in MIB meta-data(the structure of the +MIB (i.e., schema)). The hash returns blessed +references to SNMP::MIB::NODE objects which represent +a single MIB attribute. The nodes can be fetched with +multiple 'key' formats - the leaf name (e.g.,sysDescr) +or fully/partially qualified name (e.g., +system.sysDescr) or fully qualified numeric OID. The +returned node object supports the following fields: + +=over + +=item objectID + +dotted decimal fully qualified OID + +=item label + +leaf textual identifier (e.g., 'sysDescr') + +=item subID + +leaf numeric OID component of objectID (e.g., '1') + +=item moduleID + +textual identifier for module (e.g., 'RFC1213-MIB') + +=item parent + +parent node + +=item children + +array reference of children nodes + +=item nextNode + +next lexico node B<(BUG!does not return in lexico order)> + +=item type + +returns application type (see getType for values) + +=item access + +returns ACCESS (ReadOnly, ReadWrite, WriteOnly, +NoAccess, Notify, Create) + +=item status + +returns STATUS (Mandatory, Optional, Obsolete, +Deprecated) + +=item syntax + +returns 'textualConvention' if defined else 'type' + +=item textualConvention + +returns TEXTUAL-CONVENTION + +=item TCDescription + +returns the TEXTUAL-CONVENTION's DESCRIPTION field. + +=item units + +returns UNITS + +=item hint + +returns HINT + +=item enums + +returns hash ref {tag => num, ...} + +=item ranges + +returns array ref of hash ref [{low => num, high => num}, ...] + +=item description + +returns DESCRIPTION ($SNMP::save_descriptions must +be set prior to MIB initialization/parsing) + +=item reference + +returns the REFERENCE clause + +=item indexes + +returns the objects in the INDEX clause + +=item implied + +returns true if the last object in the INDEX is IMPLIED + +=back + +=head1 MIB Functions + +=over + +=item &SNMP::setMib(<file>) + +allows dynamic parsing of the mib and explicit +specification of mib file independent of environment +variables. called with no args acts like initMib, +loading MIBs indicated by environment variables (see +Net-SNMP mib_api docs). passing non-zero second arg +forces previous mib to be freed and replaced +B<(Note: second arg not working since freeing previous +Mib is more involved than before)>. + +=item &SNMP::initMib() + +calls library init_mib function if Mib not already +loaded - does nothing if Mib already loaded. will +parse directories and load modules according to +environment variables described in Net-SNMP documentations. +(see man mib_api, MIBDIRS, MIBS, MIBFILE(S), etc.) + +=item &SNMP::addMibDirs(<dir>,...) + +calls library add_mibdir for each directory +supplied. will cause directory(s) to be added to +internal list and made available for searching in +subsequent loadModules calls + +=item &SNMP::addMibFiles(<file>,...) + +calls library read_mib function. The file(s) +supplied will be read and all Mib module definitions +contained therein will be added to internal mib tree +structure + +=item &SNMP::loadModules(<mod>,...) + +calls library read_module function. The +module(s) supplied will be searched for in the +current mibdirs and and added to internal mib tree +structure. Passing special <mod>, 'ALL', will cause +all known modules to be loaded. + +=item &SNMP::unloadModules(<mod>,...) + +B<*Not Implemented*> + +=item &SNMP::translateObj(<var>[,arg,[arg]]) + +will convert a text obj tag to an OID and vice-versa. +Any iid suffix is retained numerically. Default +behaviour when converting a numeric OID to text +form is to return leaf identifier only +(e.g.,'sysDescr') but when $SNMP::use_long_names +is non-zero or a non-zero second arg is supplied it +will return a longer textual identifier. An optional +third argument of non-zero will cause the module name +to be prepended to the text name (e.g. +'SNMPv2-MIB::sysDescr'). When converting a text obj, +the $SNMP::best_guess option is used. If no Mib is +loaded when called and $SNMP::auto_init_mib is enabled +then the Mib will be loaded. Will return 'undef' upon +failure. + +=item &SNMP::getType(<var>) + +return SNMP data type for given textual identifier +OBJECTID, OCTETSTR, INTEGER, NETADDR, IPADDR, COUNTER +GAUGE, TIMETICKS, OPAQUE, or undef + +=item &SNMP::mapEnum(<var>) + +converts integer value to enumertion tag defined +in Mib or converts tag to integer depending on +input. the function will return the corresponding +integer value *or* tag for a given MIB attribute +and value. The function will sense which direction +to perform the conversion. Various arg formats are +supported + +=over + +=item $val = SNMP::mapEnum($varbind); + +where $varbind is SNMP::Varbind or equiv. +note: $varbind will be updated + +=item $val = SNMP::mapEnum('ipForwarding', 'forwarding'); + +=item $val = SNMP::mapEnum('ipForwarding', 1); + +=back + +=back + +=head1 Exported SNMP utility functions + +Note: utility functions do not support async operation yet. + +=over + +=item &snmp_get() + +takes args of SNMP::Session::new followed by those of +SNMP::Session::get + +=item &snmp_getnext() + +takes args of SNMP::Session::new followed by those of +SNMP::Session::getnext + +=item &snmp_set() + +takes args of SNMP::Session::new followed by those of +SNMP::Session::set + +=item &snmp_trap() + +takes args of SNMP::TrapSession::new followed by those of +SNMP::TrapSession::trap + +=back + +=head1 Trouble Shooting + +If problems occur there are number areas to look at to narrow down the +possibilities. + +The first step should be to test the Net-SNMP installation +independently from the Perl5 SNMP interface. + +Try running the apps from the Net-SNMP distribution. + +Make sure your agent (snmpd) is running and properly configured with +read-write access for the community you are using. + +Ensure that your MIBs are installed and enviroment variables are set +appropriately (see man mib_api) + +Be sure to remove old net-snmp installations and ensure headers and +libraries from old CMU installations are not being used by mistake. + +If the problem occurs during compilation/linking check that the snmp +library being linked is actually the Net-SNMP library (there have been +name conflicts with existing snmp libs). + +Also check that the header files are correct and up to date. + +Sometimes compiling the Net-SNMP library with +'position-independent-code' enabled is required (HPUX specifically). + +If you cannot resolve the problem you can post to +comp.lang.perl.modules or +net-snmp-users@net-snmp-users@lists.sourceforge.net + +please give sufficient information to analyze the problem (OS type, +versions for OS/Perl/Net-SNMP/compiler, complete error output, etc.) + +=head1 Acknowledgements + +Many thanks to all those who supplied patches, suggestions and +feedback. + + Joe Marzot (the original author) + Wes Hardaker and the net-snmp-coders + Dave Perkins + Marcel Wiget + David Blackburn + John Stofell + Gary Hayward + Claire Harrison + Achim Bohnet + Doug Kingston + Jacques Vidrine + Carl Jacobsen + Wayne Marquette + Scott Schumate + Michael Slifcak + Srivathsan Srinivasagopalan + Bill Fenner + Jef Peeraer + Daniel Hagerty + Karl "Rat" Schilke and Electric Lightwave, Inc. + Perl5 Porters + Alex Burger + +Apologies to any/all who's patch/feature/request was not mentioned or +included - most likely it was lost when paying work intruded on my +fun. Please try again if you do not see a desired feature. This may +actually turn out to be a decent package with such excellent help and +the fact that I have more time to work on it than in the past. + +=head1 AUTHOR + +bugs, comments, questions to net-snmp-users@lists.sourceforge.net + +=head1 Copyright + + Copyright (c) 1995-2000 G. S. Marzot. All rights reserved. + This program is free software; you can redistribute it and/or + modify it under the same terms as Perl itself. + + Copyright (c) 2001-2002 Networks Associates Technology, Inc. All + Rights Reserved. This program is free software; you can + redistribute it and/or modify it under the same terms as Perl + itself. + +=cut diff --git a/perl/SNMP/SNMP.xs b/perl/SNMP/SNMP.xs new file mode 100644 index 0000000..b4f35c8 --- /dev/null +++ b/perl/SNMP/SNMP.xs @@ -0,0 +1,5473 @@ +/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- + SNMP.xs -- Perl 5 interface to the Net-SNMP toolkit + + written by G. S. Marzot (marz@users.sourceforge.net) + + Copyright (c) 1995-2006 G. S. Marzot. All rights reserved. + This program is free software; you can redistribute it and/or + modify it under the same terms as Perl itself. +*/ +#define WIN32SCK_IS_STDSCK +#if defined(_WIN32) && !defined(_WIN32_WINNT) +#define _WIN32_WINNT 0x501 +#endif + +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <sys/types.h> +#include <arpa/inet.h> +#include <errno.h> +#ifndef MSVC_PERL + #include <signal.h> +#endif +#include <stdio.h> +#include <ctype.h> +#ifdef I_SYS_TIME +#include <sys/time.h> +#endif +#include <netdb.h> +#include <stdlib.h> +#ifndef MSVC_PERL + #include <unistd.h> +#endif + +#ifdef HAVE_REGEX_H +#include <regex.h> +#endif + +#ifndef __P +#define __P(x) x +#endif + +#ifndef na +#define na PL_na +#endif + +#ifndef sv_undef +#define sv_undef PL_sv_undef +#endif + +#ifndef stack_base +#define stack_base PL_stack_base +#endif + +#ifndef G_VOID +#define G_VOID G_DISCARD +#endif + +#include "perlsnmp.h" + +#define SUCCESS 1 +#define FAILURE 0 + +#define ZERO_BUT_TRUE "0 but true" + +#define SNMP_API_TRADITIONAL 0 +#define SNMP_API_SINGLE 1 + +#define VARBIND_TAG_F 0 +#define VARBIND_IID_F 1 +#define VARBIND_VAL_F 2 +#define VARBIND_TYPE_F 3 + +#define TYPE_UNKNOWN 0 +#define MAX_TYPE_NAME_LEN 32 +#define STR_BUF_SIZE (MAX_TYPE_NAME_LEN * MAX_OID_LEN) +#define ENG_ID_BUF_SIZE 32 + +#define SYS_UPTIME_OID_LEN 9 +#define SNMP_TRAP_OID_LEN 11 +#define NO_RETRY_NOSUCH 0 +static oid sysUpTime[SYS_UPTIME_OID_LEN] = {1, 3, 6, 1, 2, 1, 1, 3, 0}; +static oid snmpTrapOID[SNMP_TRAP_OID_LEN] = {1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0}; + +/* Internal flag to determine snmp_main_loop() should return after callback */ +static int mainloop_finish = 0; + +/* Internal flag to determine which API we're using */ +static int api_mode = SNMP_API_TRADITIONAL; + +/* these should be part of transform_oids.h ? */ +#define USM_AUTH_PROTO_MD5_LEN 10 +#define USM_AUTH_PROTO_SHA_LEN 10 +#define USM_PRIV_PROTO_DES_LEN 10 + +/* why does ucd-snmp redefine sockaddr_in ??? */ +#define SIN_ADDR(snmp_addr) (((struct sockaddr_in *) &(snmp_addr))->sin_addr) + +typedef netsnmp_session SnmpSession; +typedef struct tree SnmpMibNode; +typedef struct snmp_xs_cb_data { + SV* perl_cb; + SV* sess_ref; +} snmp_xs_cb_data; + +static void __recalc_timeout _((struct timeval*,struct timeval*, + struct timeval*,struct timeval*, int* )); +static int __is_numeric_oid _((char*)); +static int __is_leaf _((struct tree*)); +static int __translate_appl_type _((char*)); +static int __translate_asn_type _((int)); +static int __snprint_value _((char *, size_t, + netsnmp_variable_list*, struct tree *, + int, int)); +static int __sprint_num_objid _((char *, oid *, int)); +static int __scan_num_objid _((char *, oid *, size_t *)); +static int __get_type_str _((int, char *)); +static int __get_label_iid _((char *, char **, char **, int)); +static int __oid_cmp _((oid *, size_t, oid *, size_t)); +static int __tp_sprint_num_objid _((char*,SnmpMibNode *)); +static SnmpMibNode * __get_next_mib_node _((SnmpMibNode *)); +static struct tree * __tag2oid _((char *, char *, oid *, size_t *, int *, int)); +static int __concat_oid_str _((oid *, size_t *, char *)); +static int __add_var_val_str _((netsnmp_pdu *, oid *, size_t, char *, + int, int)); +static int __send_sync_pdu _((netsnmp_session *, netsnmp_pdu *, + netsnmp_pdu **, int , SV *, SV *, SV *)); +static int __snmp_xs_cb __P((int, netsnmp_session *, int, + netsnmp_pdu *, void *)); +static SV* __push_cb_args2 _((SV * sv, SV * esv, SV * tsv)); +#define __push_cb_args(a,b) __push_cb_args2(a,b,NULL) +static int __call_callback _((SV * sv, int flags)); +static char* __av_elem_pv _((AV * av, I32 key, char *dflt)); + +#define USE_NUMERIC_OIDS 0x08 +#define NON_LEAF_NAME 0x04 +#define USE_LONG_NAMES 0x02 +#define FAIL_ON_NULL_IID 0x01 +#define NO_FLAGS 0x00 + +/* Structures used by snmp_bulkwalk method to track requested OID's/subtrees. */ +typedef struct bulktbl { + oid req_oid[MAX_OID_LEN]; /* The OID originally requested. */ + oid last_oid[MAX_OID_LEN]; /* Last-seen OID under this branch. */ + AV *vars; /* Array of Varbinds for this OID. */ + size_t req_len; /* Length of requested OID. */ + size_t last_len; /* Length of last-seen OID. */ + char norepeat; /* Is this a non-repeater OID? */ + char complete; /* Non-zero if this tree complete. */ + char ignore; /* Ignore this OID, not requested. */ +} bulktbl; + +/* Context for bulkwalk() sessions. Used to store state across callbacks. */ +typedef struct walk_context { + SV *sess_ref; /* Reference to Perl SNMP session object. */ + SV *perl_cb; /* Pointer to Perl callback func or array. */ + bulktbl *req_oids; /* Pointer to bulktbl[] for requested OIDs. */ + bulktbl *repbase; /* Pointer to first repeater in req_oids[]. */ + bulktbl *reqbase; /* Pointer to start of requests req_oids[]. */ + int nreq_oids; /* Number of valid bulktbls in req_oids[]. */ + int req_remain; /* Number of outstanding requests remaining */ + int non_reps; /* Number of nonrepeater vars in req_oids[] */ + int repeaters; /* Number of repeater vars in req_oids[]. */ + int max_reps; /* Maximum repetitions of variable per PDU. */ + int exp_reqid; /* Expect a response to this request only. */ + int getlabel_f; /* Flag long/numeric names for get_label(). */ + int sprintval_f; /* Flag enum/sprint values for sprintval(). */ + int pkts_exch; /* Number of packet exchanges with agent. */ + int oid_total; /* Total number of OIDs received this walk. */ + int oid_saved; /* Total number of OIDs saved as results. */ +} walk_context; + +/* Prototypes for bulkwalk support functions. */ +static netsnmp_pdu *_bulkwalk_send_pdu _((walk_context *context)); +static int _bulkwalk_done _((walk_context *context)); +static int _bulkwalk_recv_pdu _((walk_context *context, netsnmp_pdu *pdu)); +static int _bulkwalk_finish _((walk_context *context, int okay)); +static int _bulkwalk_async_cb _((int op, SnmpSession *ss, int reqid, + netsnmp_pdu *pdu, void *context_ptr)); + +/* Prototype for error handler */ +void snmp_return_err( struct snmp_session *ss, SV *err_str, SV *err_num, SV *err_ind ); + +/* Structure to hold valid context sessions. */ +struct valid_contexts { + walk_context **valid; /* Array of valid walk_context pointers. */ + int sz_valid; /* Maximum size of valid contexts array. */ + int num_valid; /* Count of valid contexts in the array. */ +}; +static struct valid_contexts *_valid_contexts = NULL; +static int _context_add _((walk_context *context)); +static int _context_del _((walk_context *context)); +static int _context_okay _((walk_context *context)); + +/* Wrapper around fprintf(stderr, ...) for clean and easy debug output. */ +#ifdef DEBUGGING +static int _debug_level = 0; +#define DBOUT PerlIO_stderr(), +#define DBPRT(severity, otherargs) \ + do { \ + if (_debug_level && severity <= _debug_level) { \ + (void)PerlIO_printf otherargs; \ + } \ + } while (/*CONSTCOND*/0) + +char _debugx[1024]; /* Space to sprintf() into - used by sprint_objid(). */ + +/* wrapper around snprint_objid to snprint_objid to return the pointer + instead of length */ + +static char * +__snprint_oid(const oid *objid, size_t objidlen) { + snprint_objid(_debugx, sizeof(_debugx), objid, objidlen); + return _debugx; +} + +#define DBDCL(x) x +#else /* DEBUGGING */ +#define DBDCL(x) +#define DBOUT +/* Do nothing but in such a way that the compiler sees "otherargs". */ +#define DBPRT(severity, otherargs) \ + do { if (0) printf otherargs; } while(0) + +static char * +__snprint_oid(const oid *objid, size_t objidlen) +{ + return "(debugging is disabled)"; +} + +#endif /* DEBUGGING */ + +void +__libraries_init(char *appname) + { + static int have_inited = 0; + + if (have_inited) + return; + have_inited = 1; + + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, + NETSNMP_DS_LIB_QUICK_PRINT, 1); + init_snmp(appname); + + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS, 1); + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_SUFFIX_ONLY, 1); + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, + NETSNMP_OID_OUTPUT_SUFFIX); + SOCK_STARTUP; + + } + +static void +__recalc_timeout (tvp, ctvp, ltvp, itvp, block) +struct timeval* tvp; +struct timeval* ctvp; +struct timeval* ltvp; +struct timeval* itvp; +int *block; +{ + struct timeval now; + + if (!timerisset(itvp)) return; /* interval zero means loop forever */ + *block = 0; + gettimeofday(&now,(struct timezone *)0); + + if (ctvp->tv_sec < 0) { /* first time or callback just fired */ + timersub(&now,ltvp,ctvp); + timersub(ctvp,itvp,ctvp); + timersub(itvp,ctvp,ctvp); + timeradd(ltvp,itvp,ltvp); + } else { + timersub(&now,ltvp,ctvp); + timersub(itvp,ctvp,ctvp); + } + + /* flag is set for callback but still hasnt fired so set to something + * small and we will service packets first if there are any ready + * (also guard against negative timeout - should never happen?) + */ + if (!timerisset(ctvp) || ctvp->tv_sec < 0 || ctvp->tv_usec < 0) { + ctvp->tv_sec = 0; + ctvp->tv_usec = 10; + } + + /* if snmp timeout > callback timeout or no more requests to process */ + if (timercmp(tvp, ctvp, >) || !timerisset(tvp)) { + *tvp = *ctvp; /* use the smaller non-zero timeout */ + timerclear(ctvp); /* used as a flag to let callback fire on timeout */ + } +} + +static int +__is_numeric_oid (oidstr) +char* oidstr; +{ + if (!oidstr) return 0; + for (; *oidstr; oidstr++) { + if (isalpha((int)*oidstr)) return 0; + } + return(1); +} + +static int +__is_leaf (tp) +struct tree* tp; +{ + char buf[MAX_TYPE_NAME_LEN]; + return (tp && __get_type_str(tp->type,buf)); +} + +static SnmpMibNode* +__get_next_mib_node (tp) +SnmpMibNode* tp; +{ + /* printf("tp = %lX, parent = %lX, peer = %lX, child = %lX\n", + tp, tp->parent, tp->next_peer, tp->child_list); */ + if (tp->child_list) return(tp->child_list); + if (tp->next_peer) return(tp->next_peer); + if (!tp->parent) return(NULL); + for (tp = tp->parent; !tp->next_peer; tp = tp->parent) { + if (!tp->parent) return(NULL); + } + return(tp->next_peer); +} + +static int +__translate_appl_type(typestr) +char* typestr; +{ + if (typestr == NULL || *typestr == '\0') return TYPE_UNKNOWN; + + if (!strncasecmp(typestr,"INTEGER32",8)) + return(TYPE_INTEGER32); + if (!strncasecmp(typestr,"INTEGER",3)) + return(TYPE_INTEGER); + if (!strncasecmp(typestr,"UNSIGNED32",3)) + return(TYPE_UNSIGNED32); + if (!strcasecmp(typestr,"COUNTER")) /* check all in case counter64 */ + return(TYPE_COUNTER); + if (!strncasecmp(typestr,"GAUGE",3)) + return(TYPE_GAUGE); + if (!strncasecmp(typestr,"IPADDR",3)) + return(TYPE_IPADDR); + if (!strncasecmp(typestr,"OCTETSTR",3)) + return(TYPE_OCTETSTR); + if (!strncasecmp(typestr,"TICKS",3)) + return(TYPE_TIMETICKS); + if (!strncasecmp(typestr,"OPAQUE",3)) + return(TYPE_OPAQUE); + if (!strncasecmp(typestr,"OBJECTID",3)) + return(TYPE_OBJID); + if (!strncasecmp(typestr,"NETADDR",3)) + return(TYPE_NETADDR); + if (!strncasecmp(typestr,"COUNTER64",3)) + return(TYPE_COUNTER64); + if (!strncasecmp(typestr,"NULL",3)) + return(TYPE_NULL); + if (!strncasecmp(typestr,"BITS",3)) + return(TYPE_BITSTRING); + if (!strncasecmp(typestr,"ENDOFMIBVIEW",3)) + return(SNMP_ENDOFMIBVIEW); + if (!strncasecmp(typestr,"NOSUCHOBJECT",7)) + return(SNMP_NOSUCHOBJECT); + if (!strncasecmp(typestr,"NOSUCHINSTANCE",7)) + return(SNMP_NOSUCHINSTANCE); + if (!strncasecmp(typestr,"UINTEGER",3)) + return(TYPE_UINTEGER); /* historic - should not show up */ + /* but it does? */ + if (!strncasecmp(typestr, "NOTIF", 3)) + return(TYPE_NOTIFTYPE); + if (!strncasecmp(typestr, "TRAP", 4)) + return(TYPE_TRAPTYPE); + return(TYPE_UNKNOWN); +} + +static int +__translate_asn_type(type) +int type; +{ + switch (type) { + case ASN_INTEGER: + return(TYPE_INTEGER); + break; + case ASN_OCTET_STR: + return(TYPE_OCTETSTR); + break; + case ASN_OPAQUE: + return(TYPE_OPAQUE); + break; + case ASN_OBJECT_ID: + return(TYPE_OBJID); + break; + case ASN_TIMETICKS: + return(TYPE_TIMETICKS); + break; + case ASN_GAUGE: + return(TYPE_GAUGE); + break; + case ASN_COUNTER: + return(TYPE_COUNTER); + break; + case ASN_IPADDRESS: + return(TYPE_IPADDR); + break; + case ASN_BIT_STR: + return(TYPE_BITSTRING); + break; + case ASN_NULL: + return(TYPE_NULL); + break; + /* no translation for these exception type values */ + case SNMP_ENDOFMIBVIEW: + case SNMP_NOSUCHOBJECT: + case SNMP_NOSUCHINSTANCE: + return(type); + break; + case ASN_UINTEGER: + return(TYPE_UINTEGER); + break; + case ASN_COUNTER64: + return(TYPE_COUNTER64); + break; + default: + warn("translate_asn_type: unhandled asn type (%d)\n",type); + return(TYPE_OTHER); + break; + } +} + +#define USE_BASIC 0 +#define USE_ENUMS 1 +#define USE_SPRINT_VALUE 2 +static int +__snprint_value (buf, buf_len, var, tp, type, flag) +char * buf; +size_t buf_len; +netsnmp_variable_list * var; +struct tree * tp; +int type; +int flag; +{ + int len = 0; + u_char* ip; + struct enum_list *ep; + + + buf[0] = '\0'; + if (flag == USE_SPRINT_VALUE) { + snprint_value(buf, buf_len, var->name, var->name_length, var); + len = strlen(buf); + } else { + switch (var->type) { + case ASN_INTEGER: + if (flag == USE_ENUMS) { + for(ep = tp->enums; ep; ep = ep->next) { + if (ep->value == *var->val.integer) { + strlcpy(buf, ep->label, buf_len); + len = strlen(buf); + break; + } + } + } + if (!len) { + snprintf(buf, buf_len, "%ld", *var->val.integer); + buf[buf_len-1] = '\0'; + len = strlen(buf); + } + break; + + case ASN_GAUGE: + case ASN_COUNTER: + case ASN_TIMETICKS: + case ASN_UINTEGER: + snprintf(buf, buf_len, "%lu", (unsigned long) *var->val.integer); + buf[buf_len-1] = '\0'; + len = strlen(buf); + break; + + case ASN_OCTET_STR: + case ASN_OPAQUE: + len = var->val_len; + if ( len > buf_len ) + len = buf_len; + memcpy(buf, (char*)var->val.string, len); + break; + + case ASN_IPADDRESS: + ip = (u_char*)var->val.string; + snprintf(buf, buf_len, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); + buf[buf_len-1] = '\0'; + len = strlen(buf); + break; + + case ASN_NULL: + break; + + case ASN_OBJECT_ID: + __sprint_num_objid(buf, (oid *)(var->val.objid), + var->val_len/sizeof(oid)); + len = strlen(buf); + break; + + case SNMP_ENDOFMIBVIEW: + snprintf(buf, buf_len, "%s", "ENDOFMIBVIEW"); + break; + case SNMP_NOSUCHOBJECT: + snprintf(buf, buf_len, "%s", "NOSUCHOBJECT"); + break; + case SNMP_NOSUCHINSTANCE: + snprintf(buf, buf_len, "%s", "NOSUCHINSTANCE"); + break; + + case ASN_COUNTER64: +#ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES + case ASN_OPAQUE_COUNTER64: + case ASN_OPAQUE_U64: +#endif + printU64(buf,(struct counter64 *)var->val.counter64); + len = strlen(buf); + break; + +#ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES + case ASN_OPAQUE_I64: + printI64(buf,(struct counter64 *)var->val.counter64); + len = strlen(buf); + break; +#endif + + case ASN_BIT_STR: + snprint_bitstring(buf, buf_len, var, NULL, NULL, NULL); + len = strlen(buf); + break; +#ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES + case ASN_OPAQUE_FLOAT: + if (var->val.floatVal) + snprintf(buf, buf_len, "%f", *var->val.floatVal); + break; + + case ASN_OPAQUE_DOUBLE: + if (var->val.doubleVal) + snprintf(buf, buf_len, "%f", *var->val.doubleVal); + break; +#endif + + case ASN_NSAP: + default: + warn("snprint_value: asn type not handled %d\n",var->type); + } + } + return(len); +} + +static int +__sprint_num_objid (buf, objid, len) +char *buf; +oid *objid; +int len; +{ + int i; + buf[0] = '\0'; + for (i=0; i < len; i++) { + sprintf(buf,".%" NETSNMP_PRIo "u",*objid++); + buf += strlen(buf); + } + return SUCCESS; +} + +static int +__tp_sprint_num_objid (buf, tp) +char *buf; +SnmpMibNode *tp; +{ + oid newname[MAX_OID_LEN], *op; + /* code taken from get_node in snmp_client.c */ + for (op = newname + MAX_OID_LEN - 1; op >= newname; op--) { + *op = tp->subid; + tp = tp->parent; + if (tp == NULL) break; + } + return __sprint_num_objid(buf, op, newname + MAX_OID_LEN - op); +} + +static int +__scan_num_objid (buf, objid, len) +char *buf; +oid *objid; +size_t *len; +{ + char *cp; + *len = 0; + if (*buf == '.') buf++; + cp = buf; + while (*buf) { + if (*buf++ == '.') { + sscanf(cp, "%" NETSNMP_PRIo "u", objid++); + /* *objid++ = atoi(cp); */ + (*len)++; + cp = buf; + } else { + if (isalpha((int)*buf)) { + return FAILURE; + } + } + } + sscanf(cp, "%" NETSNMP_PRIo "u", objid++); + /* *objid++ = atoi(cp); */ + (*len)++; + return SUCCESS; +} + +static int +__get_type_str (type, str) +int type; +char * str; +{ + switch (type) { + case TYPE_OBJID: + strcpy(str, "OBJECTID"); + break; + case TYPE_OCTETSTR: + strcpy(str, "OCTETSTR"); + break; + case TYPE_INTEGER: + strcpy(str, "INTEGER"); + break; + case TYPE_INTEGER32: + strcpy(str, "INTEGER32"); + break; + case TYPE_UNSIGNED32: + strcpy(str, "UNSIGNED32"); + break; + case TYPE_NETADDR: + strcpy(str, "NETADDR"); + break; + case TYPE_IPADDR: + strcpy(str, "IPADDR"); + break; + case TYPE_COUNTER: + strcpy(str, "COUNTER"); + break; + case TYPE_GAUGE: + strcpy(str, "GAUGE"); + break; + case TYPE_TIMETICKS: + strcpy(str, "TICKS"); + break; + case TYPE_OPAQUE: + strcpy(str, "OPAQUE"); + break; + case TYPE_COUNTER64: + strcpy(str, "COUNTER64"); + break; + case TYPE_NULL: + strcpy(str, "NULL"); + break; + case SNMP_ENDOFMIBVIEW: + strcpy(str, "ENDOFMIBVIEW"); + break; + case SNMP_NOSUCHOBJECT: + strcpy(str, "NOSUCHOBJECT"); + break; + case SNMP_NOSUCHINSTANCE: + strcpy(str, "NOSUCHINSTANCE"); + break; + case TYPE_UINTEGER: + strcpy(str, "UINTEGER"); /* historic - should not show up */ + /* but it does? */ + break; + case TYPE_NOTIFTYPE: + strcpy(str, "NOTIF"); + break; + case TYPE_BITSTRING: + strcpy(str, "BITS"); + break; + case TYPE_TRAPTYPE: + strcpy(str, "TRAP"); + break; + case TYPE_OTHER: /* not sure if this is a valid leaf type?? */ + case TYPE_NSAPADDRESS: + default: /* unsupported types for now */ + strcpy(str, ""); + return(FAILURE); + } + return SUCCESS; +} + +/* does a destructive disection of <label1>...<labeln>.<iid> returning + <labeln> and <iid> in seperate strings (note: will destructively + alter input string, 'name') */ +static int +__get_label_iid (name, last_label, iid, flag) +char * name; +char ** last_label; +char ** iid; +int flag; +{ + char *lcp; + char *icp; + int len = strlen(name); + int found_label = 0; + + *last_label = *iid = NULL; + + if (len == 0) return(FAILURE); + + /* Handle case where numeric oid's have been requested. The input 'name' + ** in this case should be a numeric OID -- return failure if not. + */ + if ((flag & USE_NUMERIC_OIDS)) { + if (!__is_numeric_oid(name)) + return(FAILURE); + + /* Walk backward through the string, looking for first two '.' chars */ + lcp = &(name[len]); + icp = NULL; + while (lcp > name) { + if (*lcp == '.') { + + /* If this is the first occurence of '.', note it in icp. + ** Otherwise, this must be the second occurrence, so break + ** out of the loop. + */ + if (icp == NULL) + icp = lcp; + else + break; + } + lcp --; + } + + /* Make sure we found at least a label and index. */ + if (!icp) + return(FAILURE); + + /* Push forward past leading '.' chars and separate the strings. */ + lcp ++; + *icp ++ = '\0'; + + *last_label = (flag & USE_LONG_NAMES) ? name : lcp; + *iid = icp; + + return(SUCCESS); + } + + lcp = icp = &(name[len]); + + while (lcp > name) { + if (*lcp == '.') { + if (found_label) { + lcp++; + break; + } else { + icp = lcp; + } + } + if (!found_label && isalpha((unsigned char)*lcp)) found_label = 1; + lcp--; + } + + if (!found_label + || ((icp + 1 >= name + len || !isdigit((unsigned char)*(icp+1))) + && (flag & FAIL_ON_NULL_IID))) + return(FAILURE); + + if (flag & NON_LEAF_NAME) { /* dont know where to start instance id */ + /* put the whole thing in label */ + icp = &(name[len]); + flag |= USE_LONG_NAMES; + /* special hack in case no mib loaded - object identifiers will + * start with .iso.<num>.<num>...., in which case it is preferable + * to make the label entirely numeric (i.e., convert "iso" => "1") + */ + if (*lcp == '.' && lcp == name) { + if (!strncmp(".ccitt.",lcp,7)) { + name += 2; + *name = '.'; + *(name+1) = '0'; + } else if (!strncmp(".iso.",lcp,5)) { + name += 2; + *name = '.'; + *(name+1) = '1'; + } else if (!strncmp(".joint-iso-ccitt.",lcp,17)) { + name += 2; + *name = '.'; + *(name+1) = '2'; + } + } + } else if (*icp) { + *(icp++) = '\0'; + } + *last_label = (flag & USE_LONG_NAMES ? name : lcp); + + *iid = icp; + + return(SUCCESS); +} + + +static int +__oid_cmp(oida_arr, oida_arr_len, oidb_arr, oidb_arr_len) +oid *oida_arr; +size_t oida_arr_len; +oid *oidb_arr; +size_t oidb_arr_len; +{ + for (;oida_arr_len && oidb_arr_len; + oida_arr++, oida_arr_len--, oidb_arr++, oidb_arr_len--) { + if (*oida_arr == *oidb_arr) continue; + return(*oida_arr > *oidb_arr ? 1 : -1); + } + if (oida_arr_len == oidb_arr_len) return(0); + return(oida_arr_len > oidb_arr_len ? 1 : -1); +} + +/* Convert a tag (string) to an OID array */ +/* Tag can be either a symbolic name, or an OID string */ +static struct tree * +__tag2oid(tag, iid, oid_arr, oid_arr_len, type, best_guess) +char * tag; +char * iid; +oid * oid_arr; +size_t * oid_arr_len; +int * type; +int best_guess; +{ + struct tree *tp = NULL; + struct tree *rtp = NULL; + oid newname[MAX_OID_LEN], *op; + size_t newname_len = 0; + + if (type) *type = TYPE_UNKNOWN; + if (oid_arr_len) *oid_arr_len = 0; + if (!tag) goto done; + + /*********************************************************/ + /* best_guess = 0 - same as no switches (read_objid) */ + /* if multiple parts, or uses find_node */ + /* if a single leaf */ + /* best_guess = 1 - same as -Ib (get_wild_node) */ + /* best_guess = 2 - same as -IR (get_node) */ + /*********************************************************/ + + /* numeric scalar (1,2) */ + /* single symbolic (1,2) */ + /* single regex (1) */ + /* partial full symbolic (2) */ + /* full symbolic (2) */ + /* module::single symbolic (2) */ + /* module::partial full symbolic (2) */ + if (best_guess == 1 || best_guess == 2) { + if (!__scan_num_objid(tag, newname, &newname_len)) { /* make sure it's not a numeric tag */ + newname_len = MAX_OID_LEN; + if (best_guess == 2) { /* Random search -IR */ + if (get_node(tag, newname, &newname_len)) { + rtp = tp = get_tree(newname, newname_len, get_tree_head()); + } + } + else if (best_guess == 1) { /* Regex search -Ib */ + clear_tree_flags(get_tree_head()); + if (get_wild_node(tag, newname, &newname_len)) { + rtp = tp = get_tree(newname, newname_len, get_tree_head()); + } + } + } + else { + rtp = tp = get_tree(newname, newname_len, get_tree_head()); + } + if (type) *type = (tp ? tp->type : TYPE_UNKNOWN); + if ((oid_arr == NULL) || (oid_arr_len == NULL)) return rtp; + memcpy(oid_arr,(char*)newname,newname_len*sizeof(oid)); + *oid_arr_len = newname_len; + } + + /* if best_guess is off and multi part tag or module::tag */ + /* numeric scalar */ + /* module::single symbolic */ + /* module::partial full symbolic */ + /* FULL symbolic OID */ + else if (strchr(tag,'.') || strchr(tag,':')) { + if (!__scan_num_objid(tag, newname, &newname_len)) { /* make sure it's not a numeric tag */ + newname_len = MAX_OID_LEN; + if (read_objid(tag, newname, &newname_len)) { /* long name */ + rtp = tp = get_tree(newname, newname_len, get_tree_head()); + } + } + else { + rtp = tp = get_tree(newname, newname_len, get_tree_head()); + } + if (type) *type = (tp ? tp->type : TYPE_UNKNOWN); + if ((oid_arr == NULL) || (oid_arr_len == NULL)) return rtp; + memcpy(oid_arr,(char*)newname,newname_len*sizeof(oid)); + *oid_arr_len = newname_len; + } + + /* else best_guess is off and it is a single leaf */ + /* single symbolic */ + else { + rtp = tp = find_node(tag, get_tree_head()); + if (tp) { + if (type) *type = tp->type; + if ((oid_arr == NULL) || (oid_arr_len == NULL)) return rtp; + /* code taken from get_node in snmp_client.c */ + for(op = newname + MAX_OID_LEN - 1; op >= newname; op--){ + *op = tp->subid; + tp = tp->parent; + if (tp == NULL) + break; + } + *oid_arr_len = newname + MAX_OID_LEN - op; + memcpy(oid_arr, op, *oid_arr_len * sizeof(oid)); + } else { + return(rtp); /* HACK: otherwise, concat_oid_str confuses things */ + } + } + done: + if (iid && *iid && oid_arr_len) __concat_oid_str(oid_arr, oid_arr_len, iid); + return(rtp); +} + +/* function: __concat_oid_str + * + * This function converts a dotted-decimal string, soid_str, to an array + * of oid types and concatenates them on doid_arr begining at the index + * specified by doid_arr_len. + * + * returns : SUCCESS, FAILURE + */ +static int +__concat_oid_str(doid_arr, doid_arr_len, soid_str) +oid *doid_arr; +size_t *doid_arr_len; +char * soid_str; +{ + char *soid_buf; + char *cp; + char *st; + + if (!soid_str || !*soid_str) return SUCCESS;/* successfully added nothing */ + if (*soid_str == '.') soid_str++; + soid_buf = strdup(soid_str); + if (!soid_buf) + return FAILURE; + cp = strtok_r(soid_buf,".",&st); + while (cp) { + sscanf(cp, "%" NETSNMP_PRIo "u", &(doid_arr[(*doid_arr_len)++])); + /* doid_arr[(*doid_arr_len)++] = atoi(cp); */ + cp = strtok_r(NULL,".",&st); + } + free(soid_buf); + return(SUCCESS); +} + +/* + * add a varbind to PDU + */ +static int +__add_var_val_str(pdu, name, name_length, val, len, type) + netsnmp_pdu *pdu; + oid *name; + size_t name_length; + char * val; + int len; + int type; +{ + netsnmp_variable_list *vars; + oid oidbuf[MAX_OID_LEN]; + int ret = SUCCESS; + + if (pdu->variables == NULL){ + pdu->variables = vars + = netsnmp_calloc(1, sizeof(netsnmp_variable_list)); + } else { + for(vars = pdu->variables; + vars->next_variable; + vars = vars->next_variable) + /*EXIT*/; + vars->next_variable = netsnmp_calloc(1, sizeof(netsnmp_variable_list)); + vars = vars->next_variable; + } + + vars->next_variable = NULL; + vars->name = netsnmp_malloc(name_length * sizeof(oid)); + memcpy((char *)vars->name, (char *)name, name_length * sizeof(oid)); + vars->name_length = name_length; + switch (type) { + case TYPE_INTEGER: + case TYPE_INTEGER32: + vars->type = ASN_INTEGER; + vars->val.integer = netsnmp_malloc(sizeof(long)); + if (val) + *(vars->val.integer) = strtol(val,NULL,0); + else { + ret = FAILURE; + *(vars->val.integer) = 0; + } + vars->val_len = sizeof(long); + break; + + case TYPE_GAUGE: + case TYPE_UNSIGNED32: + vars->type = ASN_GAUGE; + goto UINT; + case TYPE_COUNTER: + vars->type = ASN_COUNTER; + goto UINT; + case TYPE_TIMETICKS: + vars->type = ASN_TIMETICKS; + goto UINT; + case TYPE_UINTEGER: + vars->type = ASN_UINTEGER; +UINT: + vars->val.integer = netsnmp_malloc(sizeof(long)); + if (val) + sscanf(val,"%lu",vars->val.integer); + else { + ret = FAILURE; + *(vars->val.integer) = 0; + } + vars->val_len = sizeof(long); + break; + + case TYPE_OCTETSTR: + vars->type = ASN_OCTET_STR; + goto OCT; + + case TYPE_BITSTRING: + vars->type = ASN_OCTET_STR; + goto OCT; + + case TYPE_OPAQUE: + vars->type = ASN_OCTET_STR; +OCT: + vars->val.string = netsnmp_malloc(len); + vars->val_len = len; + if (val && len) + memcpy((char *)vars->val.string, val, len); + else { + ret = FAILURE; + vars->val.string = (u_char *) netsnmp_strdup(""); + vars->val_len = 0; + } + break; + + case TYPE_IPADDR: + vars->type = ASN_IPADDRESS; + vars->val.integer = netsnmp_malloc(sizeof(in_addr_t)); + if (val) + *((in_addr_t *)vars->val.integer) = inet_addr(val); + else { + ret = FAILURE; + *(vars->val.integer) = 0; + } + vars->val_len = sizeof(in_addr_t); + break; + + case TYPE_OBJID: + vars->type = ASN_OBJECT_ID; + vars->val_len = MAX_OID_LEN; + /* if (read_objid(val, oidbuf, &(vars->val_len))) { */ + /* tp = __tag2oid(val,NULL,oidbuf,&(vars->val_len),NULL,0); */ + if (!val || !snmp_parse_oid(val, oidbuf, &vars->val_len)) { + vars->val.objid = NULL; + ret = FAILURE; + } else { + vars->val_len *= sizeof(oid); + vars->val.objid = netsnmp_malloc(vars->val_len); + memcpy((char *)vars->val.objid, (char *)oidbuf, vars->val_len); + } + break; + + default: + vars->type = ASN_NULL; + vars->val_len = 0; + vars->val.string = NULL; + ret = FAILURE; + } + + return ret; +} + +/* takes ss and pdu as input and updates the 'response' argument */ +/* the input 'pdu' argument will be freed */ +static int +__send_sync_pdu(ss, pdu, response, retry_nosuch, + err_str_sv, err_num_sv, err_ind_sv) +netsnmp_session *ss; +netsnmp_pdu *pdu; +netsnmp_pdu **response; +int retry_nosuch; +SV * err_str_sv; +SV * err_num_sv; +SV * err_ind_sv; +{ + int status; + long command = pdu->command; + *response = NULL; +retry: + if(api_mode == SNMP_API_SINGLE) + { + status = snmp_sess_synch_response(ss, pdu, response); + } else { + status = snmp_synch_response(ss, pdu, response); + }; + + if ((*response == NULL) && (status == STAT_SUCCESS)) status = STAT_ERROR; + + switch (status) { + case STAT_SUCCESS: + switch ((*response)->errstat) { + case SNMP_ERR_NOERROR: + break; + + case SNMP_ERR_NOSUCHNAME: + if (retry_nosuch && (pdu = snmp_fix_pdu(*response, command))) { + if (*response) snmp_free_pdu(*response); + goto retry; + } + + /* Pv1, SNMPsec, Pv2p, v2c, v2u, v2*, and SNMPv3 PDUs */ + case SNMP_ERR_TOOBIG: + case SNMP_ERR_BADVALUE: + case SNMP_ERR_READONLY: + case SNMP_ERR_GENERR: + /* in SNMPv2p, SNMPv2c, SNMPv2u, SNMPv2*, and SNMPv3 PDUs */ + case SNMP_ERR_NOACCESS: + case SNMP_ERR_WRONGTYPE: + case SNMP_ERR_WRONGLENGTH: + case SNMP_ERR_WRONGENCODING: + case SNMP_ERR_WRONGVALUE: + case SNMP_ERR_NOCREATION: + case SNMP_ERR_INCONSISTENTVALUE: + case SNMP_ERR_RESOURCEUNAVAILABLE: + case SNMP_ERR_COMMITFAILED: + case SNMP_ERR_UNDOFAILED: + case SNMP_ERR_AUTHORIZATIONERROR: + case SNMP_ERR_NOTWRITABLE: + /* in SNMPv2c, SNMPv2u, SNMPv2*, and SNMPv3 PDUs */ + case SNMP_ERR_INCONSISTENTNAME: + default: + sv_catpv(err_str_sv, + (char*)snmp_errstring((*response)->errstat)); + sv_setiv(err_num_sv, (*response)->errstat); + sv_setiv(err_ind_sv, (*response)->errindex); + status = (*response)->errstat; + break; + } + break; + + case STAT_TIMEOUT: + case STAT_ERROR: + snmp_return_err(ss, err_str_sv, err_num_sv, err_ind_sv); + break; + + default: + snmp_return_err(ss, err_str_sv, err_num_sv, err_ind_sv); + sv_catpv(err_str_sv, "send_sync_pdu: unknown status"); + break; + } + + return(status); +} + +static int +__snmp_xs_cb (op, ss, reqid, pdu, cb_data) +int op; +netsnmp_session *ss; +int reqid; +netsnmp_pdu *pdu; +void *cb_data; +{ + SV *varlist_ref; + AV *varlist; + SV *varbind_ref; + AV *varbind; + SV *traplist_ref = NULL; + AV *traplist = NULL; + netsnmp_variable_list *vars; + struct tree *tp; + int len; + SV *tmp_sv; + int type; + char tmp_type_str[MAX_TYPE_NAME_LEN]; + char str_buf[STR_BUF_SIZE], *str_bufp = str_buf; + size_t str_buf_len = sizeof(str_buf); + size_t out_len = 0; + int buf_over = 0; + char *label; + char *iid; + char *cp; + int getlabel_flag = NO_FLAGS; + int sprintval_flag = USE_BASIC; + netsnmp_pdu *reply_pdu; + int old_numeric, old_printfull, old_format; + netsnmp_transport *transport = NULL; + + SV* cb = ((struct snmp_xs_cb_data*)cb_data)->perl_cb; + SV* sess_ref = ((struct snmp_xs_cb_data*)cb_data)->sess_ref; + SV **err_str_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorStr", 8, 1); + SV **err_num_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorNum", 8, 1); + SV **err_ind_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorInd", 8, 1); + + ENTER; + SAVETMPS; + + if (cb_data != ss->callback_magic) + free(cb_data); + + sv_setpv(*err_str_svp, (char*)snmp_errstring(pdu->errstat)); + sv_setiv(*err_num_svp, pdu->errstat); + sv_setiv(*err_ind_svp, pdu->errindex); + + varlist_ref = &sv_undef; /* Prevent unintialized use below. */ + + switch (op) { + case NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE: + traplist_ref = NULL; + switch (pdu->command) { + case SNMP_MSG_INFORM: + /* + * Ideally, we would use the return value from the callback to + * decide what response, if any, we send, and what the error status + * and error index should be. + */ + reply_pdu = snmp_clone_pdu(pdu); + if (reply_pdu) { + reply_pdu->command = SNMP_MSG_RESPONSE; + reply_pdu->reqid = pdu->reqid; + reply_pdu->errstat = reply_pdu->errindex = 0; + if(api_mode == SNMP_API_SINGLE) + { + snmp_sess_send(ss, reply_pdu); + } else { + snmp_send(ss, reply_pdu); + } + } else { + warn("Couldn't clone PDU for inform response"); + } + /* FALLTHRU */ + case SNMP_MSG_TRAP: + case SNMP_MSG_TRAP2: + traplist = newAV(); + traplist_ref = newRV_noinc((SV*)traplist); +#if 0 + /* of dubious utility... */ + av_push(traplist, newSViv(pdu->command)); +#endif + av_push(traplist, newSViv(pdu->reqid)); + if ((transport = snmp_sess_transport(snmp_sess_pointer(ss))) != NULL) { + cp = transport->f_fmtaddr(transport, pdu->transport_data, + pdu->transport_data_length); + av_push(traplist, newSVpv(cp, strlen(cp))); + netsnmp_free(cp); + } else { + /* This shouldn't ever happen; every session has a transport. */ + av_push(traplist, newSVpv("", 0)); + } + av_push(traplist, newSVpv((char*) pdu->community, pdu->community_len)); + if (pdu->command == SNMP_MSG_TRAP) { + /* SNMP v1 only trap fields */ + snprint_objid(str_buf, sizeof(str_buf), pdu->enterprise, pdu->enterprise_length); + av_push(traplist, newSVpv(str_buf,strlen(str_buf))); + cp = inet_ntoa(*((struct in_addr *) pdu->agent_addr)); + av_push(traplist, newSVpv(cp,strlen(cp))); + av_push(traplist, newSViv(pdu->trap_type)); + av_push(traplist, newSViv(pdu->specific_type)); + /* perl didn't have perlSVuv until 5.6.0 */ + tmp_sv=newSViv(0); + sv_setuv(tmp_sv, pdu->time); + av_push(traplist, tmp_sv); + } + /* FALLTHRU */ + case SNMP_MSG_RESPONSE: + { + varlist = newAV(); + varlist_ref = newRV_noinc((SV*)varlist); + + /* + ** Set up for numeric OID's, if necessary. Save the old values + ** so that they can be restored when we finish -- these are + ** library-wide globals, and have to be set/restored for each + ** session. + */ + old_numeric = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_OIDS); + old_printfull = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_FULL_OID); + old_format = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT); + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseLongNames", 12, 1))) { + getlabel_flag |= USE_LONG_NAMES; + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_FULL_OID, 1); + } + /* Setting UseNumeric forces UseLongNames on so check for UseNumeric + after UseLongNames (above) to make sure the final outcome of + NETSNMP_DS_LIB_OID_OUTPUT_FORMAT is NETSNMP_OID_OUTPUT_NUMERIC */ + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseNumeric", 10, 1))) { + getlabel_flag |= USE_NUMERIC_OIDS; + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_OIDS, 1); + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, NETSNMP_OID_OUTPUT_NUMERIC); + } + + sv_bless(varlist_ref, gv_stashpv("SNMP::VarList",0)); + for(vars = (pdu?pdu->variables:NULL); vars; vars = vars->next_variable) { + int local_getlabel_flag = getlabel_flag; + varbind = newAV(); + varbind_ref = newRV_noinc((SV*)varbind); + sv_bless(varbind_ref, gv_stashpv("SNMP::Varbind",0)); + av_push(varlist, varbind_ref); + *str_buf = '.'; + *(str_buf+1) = '\0'; + out_len = 0; + tp = netsnmp_sprint_realloc_objid_tree((u_char**)&str_bufp, + &str_buf_len, + &out_len, 0, &buf_over, + vars->name,vars->name_length); + str_buf[sizeof(str_buf)-1] = '\0'; + if (__is_leaf(tp)) { + type = tp->type; + } else { + local_getlabel_flag |= NON_LEAF_NAME; + type = __translate_asn_type(vars->type); + } + __get_label_iid(str_buf,&label,&iid,local_getlabel_flag); + if (label) { + av_store(varbind, VARBIND_TAG_F, + newSVpv(label, strlen(label))); + } else { + av_store(varbind, VARBIND_TAG_F, + newSVpv("", 0)); + } + if (iid) { + av_store(varbind, VARBIND_IID_F, + newSVpv(iid, strlen(iid))); + } else { + av_store(varbind, VARBIND_IID_F, + newSVpv("", 0)); + } + __get_type_str(type, tmp_type_str); + tmp_sv = newSVpv(tmp_type_str, strlen(tmp_type_str)); + av_store(varbind, VARBIND_TYPE_F, tmp_sv); + len = __snprint_value(str_buf, sizeof(str_buf), + vars, tp, type, sprintval_flag); + tmp_sv = newSVpv((char*)str_buf, len); + av_store(varbind, VARBIND_VAL_F, tmp_sv); + } /* for */ + + /* Reset the library's behavior for numeric/symbolic OID's. */ + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_OIDS, old_numeric ); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_FULL_OID, old_printfull); + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, old_format); + + } /* case SNMP_MSG_RESPONSE */ + break; + default:; + } /* switch pdu->command */ + break; + + case NETSNMP_CALLBACK_OP_TIMED_OUT: + varlist_ref = &sv_undef; + sv_setpv(*err_str_svp, (char*)snmp_api_errstring(SNMPERR_TIMEOUT)); + sv_setiv(*err_num_svp, SNMPERR_TIMEOUT); + break; + default:; + } /* switch op */ + if (cb_data != ss->callback_magic) + sv_2mortal(cb); + cb = __push_cb_args2(cb, + (SvTRUE(varlist_ref) ? sv_2mortal(varlist_ref):varlist_ref), + (SvTRUE(traplist_ref) ? sv_2mortal(traplist_ref):traplist_ref)); + __call_callback(cb, G_DISCARD); + + FREETMPS; + LEAVE; + if (cb_data != ss->callback_magic) + sv_2mortal(sess_ref); + return 1; +} + +static SV * +__push_cb_args2(sv,esv,tsv) +SV *sv; +SV *esv; +SV *tsv; +{ + dSP; + if (SvTYPE(SvRV(sv)) != SVt_PVCV) sv = SvRV(sv); + + PUSHMARK(sp); + if (SvTYPE(sv) == SVt_PVAV) { + AV *av = (AV *) sv; + int n = av_len(av) + 1; + SV **x = av_fetch(av, 0, 0); + if (x) { + int i = 1; + sv = *x; + + for (i = 1; i < n; i++) { + x = av_fetch(av, i, 0); + if (x) { + SV *arg = *x; + XPUSHs(sv_mortalcopy(arg)); + } else { + XPUSHs(&sv_undef); + } + } + } else { + sv = &sv_undef; + } + } + if (esv) XPUSHs(sv_mortalcopy(esv)); + if (tsv) XPUSHs(sv_mortalcopy(tsv)); + PUTBACK; + return sv; +} + +static int +__call_callback(sv, flags) +SV *sv; +int flags; +{ + I32 myframe = TOPMARK; + I32 count; + ENTER; + if (SvTYPE(sv) == SVt_PVCV) + { + count = perl_call_sv(sv, flags); + } + else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) + { + count = perl_call_sv(SvRV(sv), flags); + } + else + { + + SV **top = stack_base + myframe + 1; + SV *obj = *top; + if (SvPOK(sv) && SvROK(obj) && SvOBJECT(SvRV(obj))) + { + count = perl_call_method(SvPV(sv, na), flags); + } + else if (SvPOK(obj) && SvROK(sv) && SvOBJECT(SvRV(sv))) + { + /* We have obj method ... + Used to be used instead of LangMethodCall() + */ + *top = sv; + count = perl_call_method(SvPV(obj, na), flags); + } + else + { + count = perl_call_sv(sv, flags); + } + } + LEAVE; + return count; +} + +/* Bulkwalk support routines */ + +/* Add a context pointer to the list of valid pointers. Place it in the first +** NULL slot in the array. +*/ +static int +_context_add(walk_context *context) +{ + int i, j, new_sz; + + if ((i = _context_okay(context)) != 0) /* Already exists? Okay. */ + return i; + + /* Initialize the array if necessary. */ + if (_valid_contexts == NULL) { + + /* Create the _valid_contexts structure. */ + Newz(0, _valid_contexts, 1, struct valid_contexts); + assert(_valid_contexts != NULL); + + /* Populate the original valid contexts array. */ + Newz(0, _valid_contexts->valid, 4, walk_context *); + assert(_valid_contexts->valid != NULL); + + /* Computer number of slots in the array. */ + _valid_contexts->sz_valid = sizeof(*_valid_contexts->valid) / + sizeof(walk_context *); + + for (i = 0; i < _valid_contexts->sz_valid; i++) + _valid_contexts->valid[i] = NULL; + + DBPRT(3, (DBOUT "Created valid_context array 0x%p (%d slots)\n", + _valid_contexts->valid, _valid_contexts->sz_valid)); + } + + /* Search through the list, looking for NULL's -- unused slots. */ + for (i = 0; i < _valid_contexts->sz_valid; i++) + if (_valid_contexts->valid[i] == NULL) + break; + + /* Did we walk off the end of the list? Need to grow the list. Double + ** it for now. + */ + if (i == _valid_contexts->sz_valid) { + new_sz = _valid_contexts->sz_valid * 2; + + Renew(_valid_contexts->valid, new_sz, walk_context *); + assert(_valid_contexts->valid != NULL); + + DBPRT(3, (DBOUT "Resized valid_context array 0x%p from %d to %d slots\n", + _valid_contexts->valid, _valid_contexts->sz_valid, new_sz)); + + _valid_contexts->sz_valid = new_sz; + + /* Initialize the new half of the resized array. */ + for (j = i; j < new_sz; j++) + _valid_contexts->valid[j] = NULL; + } + + /* Store the context pointer in the array and return 0 (success). */ + _valid_contexts->valid[i] = context; + DBPRT(3,(DBOUT "Add context 0x%p to valid context list\n", context)); + return 0; +} + +/* Remove a context pointer from the valid list. Replace the pointer with +** NULL in the valid pointer list. +*/ +static int +_context_del(walk_context *context) +{ + int i; + + if (_valid_contexts == NULL) /* Make sure it was initialized. */ + return 1; + + for (i = 0; i < _valid_contexts->sz_valid; i++) { + if (_valid_contexts->valid[i] == context) { + DBPRT(3,(DBOUT "Remove context 0x%p from valid context list\n", context)); + _valid_contexts->valid[i] = NULL; /* Remove it from the list. */ + return 0; /* Return successful status. */ + } + } + return 1; +} + +/* Check if a specific context pointer is in the valid list. Return true (1) +** if the context is still in the valid list, or 0 if not (or context is NULL). +*/ +static int +_context_okay(walk_context *context) +{ + int i; + + if (_valid_contexts == NULL) /* Make sure it was initialized. */ + return 0; + + if (context == NULL) /* Asked about a NULL context? Fail. */ + return 0; + + for (i = 0; i < _valid_contexts->sz_valid; i++) + if (_valid_contexts->valid[i] == context) + return 1; /* Found it! */ + + return 0; /* No match -- return failure. */ +} + +/* Check if the walk is completed, based upon the context. Also set the +** ignore flag on any completed variables -- this prevents them from being +** being sent in later packets. +*/ +static int +_bulkwalk_done(walk_context *context) +{ + int is_done = 1; + int i; + bulktbl *bt_entry; /* bulktbl requested OID entry */ + + /* Don't consider walk done until at least one packet has been exchanged. */ + if (context->pkts_exch == 0) + return 0; + + /* Fix up any requests that have completed. If the complete flag is set, + ** or it is a non-repeater OID, set the ignore flag so that it will not + ** be considered further. Assume we are done with the walk, and note + ** otherwise if we aren't. Return 1 if all requests are complete, or 0 + ** if there's more to do. + */ + for (i = 0; i < context->nreq_oids; i ++) { + bt_entry = &context->req_oids[i]; + + if (bt_entry->complete || bt_entry->norepeat) { + + /* This request is complete. Remove it from list of + ** walks still in progress. + */ + DBPRT(1, (DBOUT "Ignoring %s request oid %s\n", + bt_entry->norepeat ? "nonrepeater" : "completed", + __snprint_oid(bt_entry->req_oid, bt_entry->req_len))); + + /* Ignore this OID in any further packets. */ + bt_entry->ignore = 1; + } + + /* If any OID is not being ignored, the walk is not done. Must loop + ** through all requests to do the fixup -- no early return possible. + */ + if (!bt_entry->ignore) + is_done = 0; + } + + return is_done; /* Did the walk complete? */ +} + +/* Callback registered with SNMP. Return 1 from this callback to cause the +** current request to be deleted from the retransmit queue. +*/ +static int +_bulkwalk_async_cb(int op, + SnmpSession *ss, + int reqid, + netsnmp_pdu *pdu, + void *context_ptr) +{ + walk_context *context; + int done = 0; + SV **err_str_svp; + SV **err_num_svp; + + /* Handle callback request for asynchronous bulkwalk. If the bulkwalk has + ** not completed, and has not timed out, send the next request packet in + ** the walk. + ** + ** Return 0 to indicate success (caller ignores return value). + */ + + DBPRT(2, (DBOUT "bulkwalk_async_cb(op %d, reqid 0x%08X, context 0x%p)\n", + op, reqid, context_ptr)); + + context = (walk_context *)context_ptr; + + /* Make certain this is a valid context pointer. This pdu may + ** have been retransmitted after the bulkwalk was completed + ** (and the context was destroyed). If so, just return. + */ + if (!_context_okay(context)) { + DBPRT(2,(DBOUT "Ignoring PDU for dead context 0x%p...\n", context)); + return 1; + } + + /* Is this a retransmission of a request we've already seen or some + ** unexpected request id? If so, just ignore it. + */ + if (reqid != context->exp_reqid) { + DBPRT(2, + (DBOUT "Got reqid 0x%08X, expected reqid 0x%08X. Ignoring...\n", reqid, + context->exp_reqid)); + return 1; + } + /* Ignore any future packets for this reqid. */ + context->exp_reqid = -1; + + err_str_svp = hv_fetch((HV*)SvRV(context->sess_ref), "ErrorStr", 8, 1); + err_num_svp = hv_fetch((HV*)SvRV(context->sess_ref), "ErrorNum", 8, 1); + + switch (op) { + case NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE: + { + DBPRT(1,(DBOUT "Received message for reqid 0x%08X ...\n", reqid)); + + switch (pdu->command) + { + case SNMP_MSG_RESPONSE: + { + DBPRT(2, (DBOUT "Calling bulkwalk_recv_pdu(context 0x%p, pdu 0x%p)\n", + context_ptr, pdu)); + + /* Handle the response PDU. If an error occurs or there were + ** no variables in the response, consider the walk done. If + ** the response was okay, check if we have any more to do after + ** this response. + */ + if (_bulkwalk_recv_pdu(context, pdu) <= 0) + done = 1; + else + done = _bulkwalk_done(context); /* Also set req ignore flags */ + break; + } + default: + { + DBPRT(1,(DBOUT "unexpected pdu->command %d\n", pdu->command)); + done = 1; /* "This can't happen!", so bail out when it does. */ + break; + } + } + + break; + } + + case NETSNMP_CALLBACK_OP_TIMED_OUT: + { + DBPRT(1,(DBOUT "\n*** Timeout for reqid 0x%08X\n\n", reqid)); + + sv_setpv(*err_str_svp, (char*)snmp_api_errstring(SNMPERR_TIMEOUT)); + sv_setiv(*err_num_svp, SNMPERR_TIMEOUT); + + /* Timeout means something bad has happened. Return a not-okay + ** result to the async callback. + */ + _bulkwalk_finish(context, 0 /* NOT OKAY */); + return 1; + } + + default: + { + DBPRT(1,(DBOUT "unexpected callback op %d\n", op)); + sv_setpv(*err_str_svp, (char*)snmp_api_errstring(SNMPERR_GENERR)); + sv_setiv(*err_num_svp, SNMPERR_GENERR); + _bulkwalk_finish(context, 0 /* NOT OKAY */); + return 1; + } + } + + /* We have either timed out, or received and parsed in a response. Now, + ** if we have more variables to test, call bulkwalk_send_pdu() to enqueue + ** another async packet, and return. + ** + ** If, however, the bulkwalk has completed (or an error has occurred that + ** cuts the walk short), call bulkwalk_finish() to push the results onto + ** the Perl call stack. Then explicitly call the Perl callback that was + ** passed in by the user oh-so-long-ago. + */ + if (!done) { + DBPRT(1,(DBOUT "bulkwalk not complete -- send next pdu from callback\n")); + + if (_bulkwalk_send_pdu(context) != NULL) + return 1; + + DBPRT(1,(DBOUT "send_pdu() failed!\n")); + /* Fall through and return what we have so far. */ + } + + /* Call the perl callback with the return values and we're done. */ + _bulkwalk_finish(context, 1 /* OKAY */); + + return 1; +} + +static netsnmp_pdu * +_bulkwalk_send_pdu(walk_context *context) +{ + netsnmp_pdu *pdu = NULL; + netsnmp_pdu *response = NULL; + struct bulktbl *bt_entry; + int nvars = 0; + int reqid; + int status; + int i; + + /* Send a pdu requesting any remaining variables in the context. + ** + ** In synchronous mode, returns a pointer to the response packet. + ** + ** In asynchronous mode, it returns the request ID, cast to a struct snmp *, + ** not a valid SNMP response packet. The async code should not be trying + ** to get variables out of this "response". + ** + ** In either case, return a NULL pointer on error or failure. + */ + + SV **sess_ptr_sv = hv_fetch((HV*)SvRV(context->sess_ref), "SessPtr", 7, 1); + netsnmp_session *ss = (SnmpSession *)SvIV((SV*)SvRV(*sess_ptr_sv)); + 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); + + /* Create a new PDU and send the remaining set of requests to the agent. */ + pdu = snmp_pdu_create(SNMP_MSG_GETBULK); + if (pdu == NULL) { + sv_setpv(*err_str_svp, "snmp_pdu_create(GETBULK) failed: "); + sv_catpv(*err_str_svp, strerror(errno)); + sv_setiv(*err_num_svp, SNMPERR_MALLOC); + goto err; + } + + /* Request non-repeater variables only in the first packet exchange. */ + pdu->errstat = (context->pkts_exch == 0) ? context->non_reps : 0; + pdu->errindex = context->max_reps; + + for (i = 0; i < context->nreq_oids; i++) { + bt_entry = &context->req_oids[i]; + if (bt_entry->ignore) + continue; + + assert(bt_entry->complete == 0); + + if (!snmp_add_null_var(pdu, bt_entry->last_oid, bt_entry->last_len)) { + sv_setpv(*err_str_svp, "snmp_add_null_var() failed"); + sv_setiv(*err_num_svp, SNMPERR_GENERR); + sv_setiv(*err_ind_svp, i); + goto err; + } + + nvars ++; + + DBPRT(1, (DBOUT " Add %srepeater %s\n", bt_entry->norepeat ? "non" : "", + __snprint_oid(bt_entry->last_oid, bt_entry->last_len))); + } + + /* Make sure variables are actually being requested in the packet. */ + assert (nvars != 0); + + context->pkts_exch ++; + + DBPRT(1, (DBOUT "Sending %ssynchronous request %d...\n", + SvTRUE(context->perl_cb) ? "a" : "", context->pkts_exch)); + + /* We handle the asynchronous and synchronous requests differently here. + ** For async, we simply enqueue the packet with a callback to handle the + ** returned response, then return. Note that this we call the bulkwalk + ** callback, and hand it the walk_context, not the Perl callback. The + ** snmp_async_send() function returns the reqid on success, 0 on failure. + */ + if (SvTRUE(context->perl_cb)) { + if(api_mode == SNMP_API_SINGLE) + { + reqid = snmp_sess_async_send(ss, pdu, _bulkwalk_async_cb, (void *)context); + } else { + reqid = snmp_async_send(ss, pdu, _bulkwalk_async_cb, (void *)context); + } + + DBPRT(2,(DBOUT "bulkwalk_send_pdu(): snmp_async_send => 0x%08X\n", reqid)); + + if (reqid == 0) { + snmp_return_err(ss, *err_num_svp, *err_ind_svp, *err_str_svp); + goto err; + } + + /* Make a note of the request we expect to be answered. */ + context->exp_reqid = reqid; + + /* Callbacks take care of the rest. Let the caller know how many vars + ** we sent in this request. Note that this is not a valid SNMP PDU, + ** but that's because a response has not yet been received. + */ + return (netsnmp_pdu *)(intptr_t)reqid; + } + + /* This code is for synchronous mode support. + ** + ** Send the PDU and block awaiting the response. Return the response + ** packet back to the caller. Note that snmp_sess_read() frees the pdu. + */ + status = __send_sync_pdu(ss, pdu, &response, NO_RETRY_NOSUCH, + *err_str_svp, *err_num_svp, *err_ind_svp); + + pdu = NULL; + + /* Check for a failed request. __send_sync_pdu() will set the appropriate + ** values in the error string and number SV's. + */ + if (status != STAT_SUCCESS) { + DBPRT(1,(DBOUT "__send_sync_pdu() -> %d\n",(int)status)); + goto err; + } + + DBPRT(1, (DBOUT "%d packets exchanged, response 0x%p\n", context->pkts_exch, + response)); + return response; + + + err: + if (pdu) + snmp_free_pdu(pdu); + return NULL; +} + +/* Handle an incoming GETBULK response PDU. This function just pulls the +** variables off of the PDU and builds up the arrays of returned values +** that are stored in the context. +** +** Returns the number of variables found in this packet, or -1 on error. +** Note that the caller is expected to free the pdu. +*/ +static int +_bulkwalk_recv_pdu(walk_context *context, netsnmp_pdu *pdu) +{ + netsnmp_variable_list *vars; + struct tree *tp; + char type_str[MAX_TYPE_NAME_LEN]; + char str_buf[STR_BUF_SIZE], *str_bufp = str_buf; + size_t str_buf_len = sizeof(str_buf); + size_t out_len = 0; + int buf_over = 0; + char *label; + char *iid; + bulktbl *expect = NULL; + int old_numeric; + int old_printfull; + int old_format; + int getlabel_flag; + int type; + int pix; + int len; + int i; + AV *varbind; + SV *rv; + SV **sess_ptr_sv = hv_fetch((HV*)SvRV(context->sess_ref), "SessPtr", 7, 1); + 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)); + + /* Set up for numeric OID's, if necessary. Save the old values + ** so that they can be restored when we finish -- these are + ** library-wide globals, and have to be set/restored for each + ** session. + */ + old_numeric = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_OIDS); + old_printfull = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_FULL_OID); + old_format = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT); + if (context->getlabel_f & USE_NUMERIC_OIDS) { + DBPRT(2,(DBOUT "Using numeric oid's\n")); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_OIDS, 1); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_FULL_OID, 1); + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, NETSNMP_OID_OUTPUT_NUMERIC); + } + + /* Parse through the list of variables returned, adding each return to + ** the appropriate array (as a VarBind). Also keep track of which + ** repeated OID we're expecting to see, and check if that tree walk has + ** been completed (i.e. we've walked past the root of our request). If + ** so, mark the request complete so that we don't send it again in any + ** subsequent request packets. + */ + if (context->pkts_exch == 1) + context->reqbase = context->req_oids; /* Request with non-repeaters */ + else + context->reqbase = context->repbase; /* Request only repeater vars */ + + /* Note the first variable we expect to see. Should be reqbase. */ + expect = context->reqbase; + + for (vars = pdu->variables, pix = 0; + vars != NULL; + vars = vars->next_variable, pix ++) + { + + /* If no outstanding requests remain, we're done. This works, but it + ** causes the reported total variable count to be wrong (since the + ** remaining vars on the last packet are not counted). In practice + ** this is probably worth the win, but for debugging it's not. + */ + if (context->req_remain == 0) { + DBPRT(2,(DBOUT "No outstanding requests remain. Terminating processing.\n")); + while (vars) { + pix ++; + vars = vars->next_variable; + } + break; + } + + /* Determine which OID we expect to see next. We assert that the OID's + ** must be returned in the expected order. The first nreq_oids returns + ** should match the req_oids array, after that, we must cycle through + ** the repeaters in order. Non-repeaters are not included in later + ** packets, so cannot have the "ignore" flag set. + */ + + if (context->oid_saved < context->non_reps) { + assert(context->pkts_exch == 1); + + expect = context->reqbase ++; + assert(expect->norepeat); + + } else { + /* Must be a repeater. Look for the first one that is not being + ** ignored. Make sure we don't loop around to where we started. + ** If we get here but everything is being ignored, there's a problem. + ** + ** Note that we *do* accept completed but not ignored OID's -- these + ** are OID's for trees that have been completed sometime in this + ** response, but must be looked at to maintain ordering. + */ + /* In previous version we started from 1st repeater any time when + ** pix == 0. But if 1st repeater is ignored we can get wrong results, + ** because it was not included in 2nd and later request. So we set + ** expect to repbase-1 and then search for 1st non-ignored repeater. + ** repbase-1 is nessessary because we're starting search in loop below + ** from ++expect and it will be exactly repbase on 1st search pass. + */ + if (pix == 0) + expect = context->repbase - 1; + + /* Find the repeater OID we expect to see. Ignore any + ** OID's marked 'ignore' -- these have been completed + ** and were not requested in this iteration. + */ + for (i = 0; i < context->repeaters; i++) { + + /* Loop around to first repeater if we hit the end. */ + if (++ expect == &context->req_oids[context->nreq_oids]) + expect = context->reqbase = context->repbase; + + /* Stop if this OID is not being ignored. */ + if (!expect->ignore) + break; + } + } + + DBPRT(2, (DBOUT "Var %03d request %s\n", pix, + __snprint_oid(expect->req_oid, expect->req_len))); + + /* Did we receive an error condition for this variable? + ** If it's a repeated variable, mark it as complete and + ** fall through to the block below. + */ + if ((vars->type == SNMP_ENDOFMIBVIEW) || + (vars->type == SNMP_NOSUCHOBJECT) || + (vars->type == SNMP_NOSUCHINSTANCE)) + { + DBPRT(2,(DBOUT "error type %d\n", (int)vars->type)); + + /* ENDOFMIBVIEW should be okay for a repeater - just walked off the + ** end of the tree. Mark the request as complete, and go on to the + ** next one. + */ + if ((context->oid_saved >= context->non_reps) && + (vars->type == SNMP_ENDOFMIBVIEW)) + { + expect->complete = 1; + DBPRT(2, (DBOUT "Ran out of tree for oid %s\n", + __snprint_oid(vars->name,vars->name_length))); + + context->req_remain --; + + /* Go on to the next variable. */ + continue; + + } + sv_setpv(*err_str_svp, + (char*)snmp_api_errstring(SNMPERR_UNKNOWN_OBJID)); + sv_setiv(*err_num_svp, SNMPERR_UNKNOWN_OBJID); + sv_setiv(*err_ind_svp, pix); + goto err; + } + + /* If this is not the first packet, skip any duplicated OID values, if + ** present. These should be the seed values copied from the last OID's + ** of the previous packet. In practice we don't see this, but it is + ** easy enough to do, and will avoid confusion for the caller from mis- + ** behaving agents (badly misbehaving... ;^). + */ + if (context->pkts_exch > 1) { + if (__oid_cmp(vars->name, vars->name_length, + expect->last_oid, expect->last_len) <= 0) + { + if (check) + { + DBPRT(2, (DBOUT "Error: OID not increasing: %s\n", + __snprint_oid(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_oid(vars->name,vars->name_length))); + + continue; + } + } + + context->oid_total ++; /* Count each variable received. */ + + /* If this is a non-repeater, handle it. Otherwise, if it is a + ** repeater, has the walk wandered off of the requested tree? If so, + ** this request is complete, so mark it as such. Ignore any other + ** variables in a completed request. In order to maintain the correct + ** ordering of which variables we expect to see in this packet, we must + ** not set the ignore flags immediately. It is done in bulkwalk_done(). + */ + if (context->oid_saved < context->non_reps) { + DBPRT(2, (DBOUT " expected var %s (nonrepeater %d/%d)\n", + __snprint_oid(expect->req_oid, expect->req_len), + pix, context->non_reps)); + DBPRT(2, (DBOUT " received var %s\n", + __snprint_oid(vars->name, vars->name_length))); + + /* This non-repeater has now been seen, so mark the sub-tree as + ** completed. Note that this may not be the same oid as requested, + ** since non-repeaters act like GETNEXT requests, not GET's. <sigh> + */ + context->req_oids[pix].complete = 1; + context->req_remain --; + + } else { /* Must be a repeater variable. */ + + DBPRT(2, (DBOUT " received oid %s\n", + __snprint_oid(vars->name, vars->name_length))); + + /* Are we already done with this tree? If so, just ignore this + ** variable and move on to the next expected variable. + */ + if (expect->complete) { + DBPRT(2,(DBOUT " this branch is complete - ignoring.\n")); + continue; + } + + /* If the base oid of this variable doesn't match the expected oid, + ** assume that we've walked past the end of the subtree. Set this + ** subtree to be completed, and go on to the next variable. + */ + if ((vars->name_length < expect->req_len) || + (memcmp(vars->name, expect->req_oid, expect->req_len*sizeof(oid)))) + { + DBPRT(2,(DBOUT " walked off branch - marking subtree as complete.\n")); + expect->complete = 1; + context->req_remain --; + continue; + } + + /* Still interested in the tree -- we need to keep track of the + ** last-seen value in case we need to send an additional request + ** packet. + */ + (void)memcpy(expect->last_oid, vars->name, + vars->name_length * sizeof(oid)); + expect->last_len = vars->name_length; + + } + + /* Create a new Varbind and populate it with the parsed information + ** returned by the agent. This Varbind is then pushed onto the arrays + ** maintained for each request OID in the context. These varbinds are + ** collected into a return array by bulkwalk_finish(). + */ + varbind = (AV*) newAV(); + if (varbind == NULL) { + sv_setpv(*err_str_svp, "newAV() failed: "); + sv_catpv(*err_str_svp, (char*)strerror(errno)); + sv_setiv(*err_num_svp, SNMPERR_MALLOC); + goto err; + } + + *str_buf = '.'; + *(str_buf+1) = '\0'; + out_len = 0; + tp = netsnmp_sprint_realloc_objid_tree((u_char**)&str_bufp, &str_buf_len, + &out_len, 0, &buf_over, + vars->name,vars->name_length); + str_buf[sizeof(str_buf)-1] = '\0'; + + getlabel_flag = context->getlabel_f; + + if (__is_leaf(tp)) { + type = tp->type; + } else { + getlabel_flag |= NON_LEAF_NAME; + type = __translate_asn_type(vars->type); + } + if (__get_label_iid(str_buf, &label, &iid, getlabel_flag) == FAILURE) { + label = str_buf; + iid = label + strlen(label); + } + + DBPRT(2,(DBOUT " save var %s.%s = ", label, iid)); + + av_store(varbind, VARBIND_TAG_F, newSVpv(label, strlen(label))); + av_store(varbind, VARBIND_IID_F, newSVpv(iid, strlen(iid))); + + __get_type_str(type, type_str); + av_store(varbind, VARBIND_TYPE_F, newSVpv(type_str, strlen(type_str))); + + len=__snprint_value(str_buf, sizeof(str_buf), + vars, tp, type, context->sprintval_f); + av_store(varbind, VARBIND_VAL_F, newSVpv(str_buf, len)); + + str_buf[len] = '\0'; + DBPRT(3,(DBOUT "'%s' (%s)\n", str_buf, type_str)); + +#if 0 + /* huh? */ + /* If necessary, store a timestamp as the semi-documented 5th element. */ + if (sv_timestamp) + av_store(varbind, VARBIND_TIME_F, SvREFCNT_inc(sv_timestamp)); +#endif + + /* Push ref to the varbind onto the list of vars for OID. */ + rv = newRV_noinc((SV *)varbind); + sv_bless(rv, gv_stashpv("SNMP::Varbind", 0)); + av_push(expect->vars, rv); + + context->oid_saved ++; /* Count this as a saved variable. */ + + } /* next variable in response packet */ + + DBPRT(1, (DBOUT "-- pkt %d saw %d vars, total %d (%d saved)\n", context->pkts_exch, + pix, context->oid_total, context->oid_saved)); + + /* We assert that all non-repeaters must be returned in + ** the initial response (they are not repeated in additional + ** packets, so would be dropped). If nonrepeaters still + ** exist, consider it a fatal error. + */ + if ((context->pkts_exch == 1) && (context->oid_saved < context->non_reps)) { + /* Re-use space from the value string for error message. */ + sprintf(str_buf, "%d non-repeaters went unanswered", context->non_reps); + sv_setpv(*err_str_svp, str_buf); + sv_setiv(*err_num_svp, SNMPERR_GENERR); + sv_setiv(*err_num_svp, context->oid_saved); + goto err; + } + + /* Reset the library's behavior for numeric/symbolic OID's. */ + if (context->getlabel_f & USE_NUMERIC_OIDS) { + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_OIDS, old_numeric); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_FULL_OID, old_printfull); + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, old_format); + } + + return pix; + + err: + return -1; + +} + +/* Once the bulkwalk has completed, extend the stack and push references to +** each of the arrays of SNMP::Varbind's onto the stack. Return the number +** of arrays pushed on the stack. The caller should return to Perl, or call +** the Perl callback function. +** +** Note that this function free()'s the walk_context and request bulktbl's. +*/ +static int +_bulkwalk_finish(walk_context *context, int okay) +{ + dSP; + int npushed = 0; + int i; + int async = 0; + bulktbl *bt_entry; + AV *ary = NULL; + SV *rv; + SV *perl_cb; + + 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); + + async = SvTRUE(context->perl_cb); + + /* XXX + _bulkwalk_finish() was originally intended to be called from XS code, and + would extend the caller's stack with result. Later it was changed into + an asynchronous version that calls perl code instead. These two branches + differ significantly in how they treat perl stack. Due to these differences, + often implicit (f.ex. dMARK calls POPMARK ), it would be a good idea + to write two different procedures, _bulkwalk_finish_sync and _bulkwalk_finish_async + for cleaner separation. */ + + if (async) PUSHMARK(sp); + + { + +#ifdef dITEMS + dMARK; + dITEMS; +#else + /* unfortunately this may pop a mark, which is not what we want */ + /* older perl versions don't declare dITEMS though and the + following declars it but also uses dAXMARK instead of dMARK + which is the bad popping version */ + dMARK; + + /* err... This is essentially what the newer dITEMS does */ + I32 items = sp - mark; +#endif + + + /* Successfully completed the bulkwalk. For synchronous calls, push each + ** of the request value arrays onto the stack, and return the number of + ** items pushed onto the stack. For async, create a new array and push + ** the references onto it. The array is then passed to the Perl callback. + */ + if(!async) + SP -= items; + + DBPRT(1, (DBOUT "Bulwalk %s (saved %d/%d), ", okay ? "completed" : "had error", + context->oid_saved, context->oid_total)); + + if (okay) { + DBPRT(1, (DBOUT "%s %d varbind refs %s\n", + async ? "pass ref to array of" : "return", + context->nreq_oids, + async ? "to callback" : "on stack to caller")); + + /* Create the array to hold the responses for the asynchronous callback, + ** or pre-extend the stack enough to hold responses for synch return. + */ + if (async) { + ary = (AV *)newAV(); + if (ary == NULL) { + sv_setpv(*err_str_svp, "newAV(): "); + sv_catpv(*err_str_svp, (char *)strerror(errno)); + sv_setiv(*err_num_svp, errno); + } + + /* NULL ary pointer is okay -- we'll handle it below... */ + + } else { + EXTEND(sp, context->nreq_oids); + + } + + /* Push a reference to each array of varbinds onto the stack, in + ** the order requested. Note that these arrays may be empty. + */ + for (i = 0; i < context->nreq_oids; i++) { + bt_entry = &context->req_oids[i]; + + DBPRT(2, (DBOUT " %sreq #%d (%s) => %d var%s\n", + bt_entry->complete ? "" : "incomplete ", i, + __snprint_oid(bt_entry->req_oid, bt_entry->req_len), + (int)av_len(bt_entry->vars) + 1, + (int)av_len(bt_entry->vars) > 0 ? "s" : "")); + + if (async && ary == NULL) { + DBPRT(2,(DBOUT " [dropped due to newAV() failure]\n")); + continue; + } + + /* Get a reference to the varlist, and push it onto array or stack */ + rv = newRV_noinc((SV *)bt_entry->vars); + sv_bless(rv, gv_stashpv("SNMP::VarList",0)); + + if (async) + av_push(ary, rv); + else + PUSHs(sv_2mortal((SV *)rv)); + + npushed ++; + } + + } else { /* Not okay -- push a single undef on the stack if not async */ + + if (!async) { + XPUSHs(&sv_undef); + npushed = 1; + } else { + for (i = 0; i < context->nreq_oids; i++) { + sv_2mortal((SV *) (context->req_oids[i].vars)); + } + } + } + + /* XXX Future enhancement -- make statistics (pkts exchanged, vars + ** saved vs. received, total time, etc) available to caller so they + ** can adjust their request parameters and/or re-order requests. + */ + if(!async) + SP -= items; + + PUTBACK; + + if (async) { + /* Asynchronous callback. Push the caller's arglist onto the stack, + ** and follow it with the contents of the array (or undef if newAV() + ** failed or the session had an error). Then mortalize the Perl + ** callback pointer, and call the callback. + */ + if (!okay || ary == NULL) + rv = &sv_undef; + else + rv = newRV_noinc((SV *)ary); + + sv_2mortal(perl_cb = context->perl_cb); + perl_cb = __push_cb_args(perl_cb, (SvTRUE(rv) ? sv_2mortal(rv) : rv)); + + __call_callback(perl_cb, G_DISCARD); + } + sv_2mortal(context->sess_ref); + + /* Free the allocated space for the request states and return number of + ** variables found. Remove the context from the valid context list. + */ + _context_del(context); + DBPRT(2,(DBOUT "Free() context->req_oids\n")); + Safefree(context->req_oids); + DBPRT(2,(DBOUT "Free() context 0x%p\n", context)); + Safefree(context); + return npushed; +}} + +/* End of bulkwalk support routines */ + +static char * +__av_elem_pv(AV *av, I32 key, char *dflt) +{ + SV **elem = av_fetch(av, key, 0); + + return (elem && SvOK(*elem)) ? SvPV(*elem, na) : dflt; +} + +static int +not_here(const char *s) +{ + warn("%s not implemented on this architecture", s); + return -1; +} + +#define TEST_CONSTANT(value, name, C) \ + if (strEQ(name, #C)) { \ + *value = C; \ + return 0; \ + } +#define TEST_CONSTANT2(value, name, C, V) \ + if (strEQ(name, #C)) { \ + *value = V; \ + return 0; \ + } + +static int constant(double *value, const char * const name, const int arg) +{ + switch (*name) { + case 'N': + TEST_CONSTANT(value, name, NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE); + TEST_CONSTANT(value, name, NETSNMP_CALLBACK_OP_TIMED_OUT); + break; + case 'S': + TEST_CONSTANT(value, name, SNMPERR_BAD_ADDRESS); + TEST_CONSTANT(value, name, SNMPERR_BAD_LOCPORT); + TEST_CONSTANT(value, name, SNMPERR_BAD_SESSION); + TEST_CONSTANT(value, name, SNMPERR_GENERR); + TEST_CONSTANT(value, name, SNMPERR_TOO_LONG); + TEST_CONSTANT(value, name, SNMP_DEFAULT_ADDRESS); + TEST_CONSTANT(value, name, SNMP_DEFAULT_COMMUNITY_LEN); + TEST_CONSTANT(value, name, SNMP_DEFAULT_ENTERPRISE_LENGTH); + TEST_CONSTANT(value, name, SNMP_DEFAULT_ERRINDEX); + TEST_CONSTANT(value, name, SNMP_DEFAULT_ERRSTAT); + TEST_CONSTANT2(value, name, SNMP_DEFAULT_PEERNAME, 0); + TEST_CONSTANT(value, name, SNMP_DEFAULT_REMPORT); + TEST_CONSTANT(value, name, SNMP_DEFAULT_REQID); + TEST_CONSTANT(value, name, SNMP_DEFAULT_RETRIES); + TEST_CONSTANT(value, name, SNMP_DEFAULT_TIME); + TEST_CONSTANT(value, name, SNMP_DEFAULT_TIMEOUT); + TEST_CONSTANT2(value, name, SNMP_DEFAULT_VERSION, + NETSNMP_DEFAULT_SNMP_VERSION); + TEST_CONSTANT(value, name, SNMP_API_SINGLE); + TEST_CONSTANT(value, name, SNMP_API_TRADITIONAL); + break; + case 'X': + goto not_there; + break; + default: + break; + } + return EINVAL; + +not_there: + not_here(name); + return ENOENT; +} + +/* + Since s_snmp_errno can't be trusted with Single Session, this calls either + snmp_error or snmp_sess_error to populate ErrorStr,ErrorNum, and ErrorInd + in SNMP::Session objects +*/ +void snmp_return_err( struct snmp_session *ss, SV *err_str, SV *err_num, SV *err_ind ) +{ + int err; + int liberr; + char *errstr; + if(ss == NULL) + return; + if(api_mode == SNMP_API_SINGLE) + { + snmp_sess_error(ss, &err, &liberr, &errstr); + } else { + snmp_error(ss, &err, &liberr, &errstr); + } + sv_catpv(err_str, errstr); + sv_setiv(err_num, liberr); + sv_setiv(err_ind, err); + netsnmp_free(errstr); +} + + +/* + int snmp_api_mode( int mode ) + Returns or sets static int api_mode for reference by functions to determine + whether to use Traditional (non-threadsafe) or Single-Session (threadsafe) + SNMP API calls. + + Call with (int)NULL to return the current mode, or with SNMP_API_TRADITIONAL + or SNMP_API_SINGLE to set the current mode. (defined above) + + pm side call defaults to (int)NULL +*/ +int snmp_api_mode( int mode ) +{ + if (mode == 0) + return api_mode; + api_mode = mode; + return api_mode; +} + +MODULE = SNMP PACKAGE = SNMP PREFIX = snmp + +void +constant(name,arg) + char * name + int arg + INIT: + int status; + double value; + PPCODE: + value = 0; + status = constant(&value, name, arg); + XPUSHs(sv_2mortal(newSVuv(status))); + XPUSHs(sv_2mortal(newSVnv(value))); + +long +snmp_sys_uptime() + CODE: + RETVAL = get_uptime(); + OUTPUT: + RETVAL + +void +init_snmp(appname) + char *appname + CODE: + __libraries_init(appname); + +#---------------------------------------------------------------------- +# Perl call defaults to (int)NULL when given no args, so it will return +# the current api_mode values +#---------------------------------------------------------------------- +int +snmp_api_mode(mode=0) + int mode + +SnmpSession * +snmp_new_session(version, community, peer, lport, retries, timeout) + char * version + char * community + char * peer + int lport + int retries + int timeout + CODE: + { + SnmpSession session = {0}; + SnmpSession *ss = NULL; + int verbose = SvIV(perl_get_sv("SNMP::verbose", 0x01 | 0x04)); + + __libraries_init("perl"); + + session.version = -1; +#ifndef NETSNMP_DISABLE_SNMPV1 + if (!strcmp(version, "1")) { + session.version = SNMP_VERSION_1; + } +#endif +#ifndef NETSNMP_DISABLE_SNMPV2C + if ((!strcmp(version, "2")) || (!strcmp(version, "2c"))) { + session.version = SNMP_VERSION_2c; + } +#endif + if (!strcmp(version, "3")) { + session.version = SNMP_VERSION_3; + } + if (session.version == -1) { + if (verbose) + warn("error:snmp_new_session:Unsupported SNMP version (%s)\n", version); + goto end; + } + + session.community_len = strlen((char *)community); + session.community = (u_char *)community; + session.peername = peer; + session.local_port = lport; + session.retries = retries; /* 5 */ + session.timeout = timeout; /* 1000000L */ + session.authenticator = NULL; + + if(api_mode == SNMP_API_SINGLE) + { + ss = snmp_sess_open(&session); + } else { + ss = snmp_open(&session); + } + + if (ss == NULL) { + if (verbose) warn("error:snmp_new_session: Couldn't open SNMP session"); + } + end: + RETVAL = ss; + } + OUTPUT: + RETVAL + +SnmpSession * +snmp_new_v3_session(version, peer, retries, timeout, sec_name, sec_level, sec_eng_id, context_eng_id, context, auth_proto, auth_pass, priv_proto, priv_pass, eng_boots, eng_time, auth_master_key, auth_master_key_len, priv_master_key, priv_master_key_len, auth_localized_key, auth_localized_key_len, priv_localized_key, priv_localized_key_len) + int version + char * peer + int retries + int timeout + char * sec_name + int sec_level + char * sec_eng_id + char * context_eng_id + char * context + char * auth_proto + char * auth_pass + char * priv_proto + char * priv_pass + int eng_boots + int eng_time + char * auth_master_key + size_t auth_master_key_len + char * priv_master_key + size_t priv_master_key_len + char * auth_localized_key + size_t auth_localized_key_len + char * priv_localized_key + size_t priv_localized_key_len + CODE: + { + SnmpSession session = {0}; + SnmpSession *ss = NULL; + int verbose = SvIV(perl_get_sv("SNMP::verbose", 0x01 | 0x04)); + + __libraries_init("perl"); + + if (version == 3) { + session.version = SNMP_VERSION_3; + } else { + if (verbose) + warn("error:snmp_new_v3_session:Unsupported SNMP version (%d)\n", version); + goto end; + } + + session.peername = peer; + session.retries = retries; /* 5 */ + session.timeout = timeout; /* 1000000L */ + session.authenticator = NULL; + session.contextNameLen = strlen(context); + session.contextName = context; + session.securityNameLen = strlen(sec_name); + session.securityName = sec_name; + session.securityLevel = sec_level; + session.securityModel = USM_SEC_MODEL_NUMBER; + session.securityEngineIDLen = + hex_to_binary2((u_char*)sec_eng_id, strlen(sec_eng_id), + (char **) &session.securityEngineID); + session.contextEngineIDLen = + hex_to_binary2((u_char*)context_eng_id, strlen(context_eng_id), + (char **) &session.contextEngineID); + session.engineBoots = eng_boots; + session.engineTime = eng_time; +#ifndef NETSNMP_DISABLE_MD5 + if (!strcmp(auth_proto, "MD5")) { + session.securityAuthProto = + snmp_duplicate_objid(usmHMACMD5AuthProtocol, + USM_AUTH_PROTO_MD5_LEN); + session.securityAuthProtoLen = USM_AUTH_PROTO_MD5_LEN; + } else +#endif + if (!strcmp(auth_proto, "SHA")) { + session.securityAuthProto = + snmp_duplicate_objid(usmHMACSHA1AuthProtocol, + USM_AUTH_PROTO_SHA_LEN); + session.securityAuthProtoLen = USM_AUTH_PROTO_SHA_LEN; + } else if (!strcmp(auth_proto, "DEFAULT")) { + const oid *theoid = + get_default_authtype(&session.securityAuthProtoLen); + session.securityAuthProto = + snmp_duplicate_objid(theoid, session.securityAuthProtoLen); + } else { + if (verbose) + warn("error:snmp_new_v3_session:Unsupported authentication protocol(%s)\n", auth_proto); + goto end; + } + if (session.securityLevel >= SNMP_SEC_LEVEL_AUTHNOPRIV) { + if (auth_localized_key_len) { + memdup(&session.securityAuthLocalKey, + (u_char*)auth_localized_key, + auth_localized_key_len); + session.securityAuthLocalKeyLen = auth_localized_key_len; + } else if (auth_master_key_len) { + session.securityAuthKeyLen = + SNMP_MIN(auth_master_key_len, + sizeof(session.securityAuthKey)); + memcpy(session.securityAuthKey, auth_master_key, + session.securityAuthKeyLen); + } else { + if (strlen(auth_pass) > 0) { + session.securityAuthKeyLen = USM_AUTH_KU_LEN; + if (generate_Ku(session.securityAuthProto, + session.securityAuthProtoLen, + (u_char *)auth_pass, strlen(auth_pass), + session.securityAuthKey, + &session.securityAuthKeyLen) != SNMPERR_SUCCESS) { + if (verbose) + warn("error:snmp_new_v3_session:Error generating Ku from authentication password.\n"); + goto end; + } + } + } + } +#ifndef NETSNMP_DISABLE_DES + if (!strcmp(priv_proto, "DES")) { + session.securityPrivProto = + snmp_duplicate_objid(usmDESPrivProtocol, + USM_PRIV_PROTO_DES_LEN); + session.securityPrivProtoLen = USM_PRIV_PROTO_DES_LEN; + } else +#endif + if (!strncmp(priv_proto, "AES", 3)) { + session.securityPrivProto = + snmp_duplicate_objid(usmAESPrivProtocol, + USM_PRIV_PROTO_AES_LEN); + session.securityPrivProtoLen = USM_PRIV_PROTO_AES_LEN; + } else if (!strcmp(priv_proto, "DEFAULT")) { + const oid *theoid = + get_default_privtype(&session.securityPrivProtoLen); + session.securityPrivProto = + snmp_duplicate_objid(theoid, session.securityPrivProtoLen); + } else { + if (verbose) + warn("error:snmp_new_v3_session:Unsupported privacy protocol(%s)\n", priv_proto); + goto end; + } + if (session.securityLevel >= SNMP_SEC_LEVEL_AUTHPRIV) { + if (priv_localized_key_len) { + memdup(&session.securityPrivLocalKey, + (u_char*)priv_localized_key, + priv_localized_key_len); + session.securityPrivLocalKeyLen = priv_localized_key_len; + } else if (priv_master_key_len) { + session.securityPrivKeyLen = + SNMP_MIN(auth_master_key_len, + sizeof(session.securityPrivKey)); + memcpy(session.securityPrivKey, priv_master_key, + session.securityPrivKeyLen); + } else { + session.securityPrivKeyLen = USM_PRIV_KU_LEN; + if (generate_Ku(session.securityAuthProto, + session.securityAuthProtoLen, + (u_char *)priv_pass, strlen(priv_pass), + session.securityPrivKey, + &session.securityPrivKeyLen) != SNMPERR_SUCCESS) { + if (verbose) + warn("error:snmp_new_v3_session:Error generating Ku from privacy pass phrase.\n"); + goto end; + } + } + } + + if(api_mode == SNMP_API_SINGLE) + { + ss = snmp_sess_open(&session); + } else { + ss = snmp_open(&session); + } + + if (ss == NULL) { + if (verbose) warn("error:snmp_new_v3_session:Couldn't open SNMP session"); + } + end: + RETVAL = ss; + netsnmp_free(session.securityPrivLocalKey); + netsnmp_free(session.securityPrivProto); + netsnmp_free(session.securityAuthLocalKey); + netsnmp_free(session.securityAuthProto); + netsnmp_free(session.contextEngineID); + netsnmp_free(session.securityEngineID); + } + OUTPUT: + RETVAL + +SnmpSession * +snmp_new_tunneled_session(version, peer, retries, timeout, sec_name, sec_level, context_eng_id, context, our_identity, their_identity, their_hostname, trust_cert) + int version + char * peer + int retries + int timeout + char * sec_name + int sec_level + char * context_eng_id + char * context + char * our_identity + char * their_identity + char * their_hostname + char * trust_cert + CODE: + { + SnmpSession session = {0}; + SnmpSession *ss = NULL; + int verbose = SvIV(perl_get_sv("SNMP::verbose", 0x01 | 0x04)); + + __libraries_init("perl"); + + session.version = version; + + session.peername = peer; + session.retries = retries; /* 5 */ + session.timeout = timeout; /* 1000000L */ + session.contextNameLen = strlen(context); + session.contextName = context; + session.securityNameLen = strlen(sec_name); + session.securityName = sec_name; + session.securityLevel = sec_level; + session.securityModel = NETSNMP_TSM_SECURITY_MODEL; + session.contextEngineIDLen = + hex_to_binary2((u_char*)context_eng_id, strlen(context_eng_id), + (char **) &session.contextEngineID); + + /* create the transport configuration store */ + if (!session.transport_configuration) { + netsnmp_container_init_list(); + session.transport_configuration = + netsnmp_container_find("transport_configuration:fifo"); + if (!session.transport_configuration) { + fprintf(stderr, "failed to initialize the transport configuration container\n"); + RETVAL = NULL; + return; + } + + session.transport_configuration->compare = + (netsnmp_container_compare*) + netsnmp_transport_config_compare; + } + + if (our_identity && our_identity[0] != '\0') + CONTAINER_INSERT(session.transport_configuration, + netsnmp_transport_create_config("our_identity", + our_identity)); + + if (their_identity && their_identity[0] != '\0') + CONTAINER_INSERT(session.transport_configuration, + netsnmp_transport_create_config("their_identity", + their_identity)); + + if (their_hostname && their_hostname[0] != '\0') + CONTAINER_INSERT(session.transport_configuration, + netsnmp_transport_create_config("their_hostname", + their_hostname)); + + if (trust_cert && trust_cert[0] != '\0') + CONTAINER_INSERT(session.transport_configuration, + netsnmp_transport_create_config("trust_cert", + trust_cert)); + + + ss = snmp_open(&session); + + if (ss == NULL) { + if (verbose) warn("error:snmp_new_v3_session:Couldn't open SNMP session"); + } + + RETVAL = ss; + netsnmp_free(session.securityPrivLocalKey); + netsnmp_free(session.securityPrivProto); + netsnmp_free(session.securityAuthLocalKey); + netsnmp_free(session.securityAuthProto); + netsnmp_free(session.contextEngineID); + netsnmp_free(session.securityEngineID); + } + OUTPUT: + RETVAL + +SnmpSession * +snmp_update_session(sess_ref, version, community, peer, lport, retries, timeout) + SV * sess_ref + char * version + char * community + char * peer + int lport + int retries + int timeout + CODE: + { + SV **sess_ptr_sv; + SnmpSession *ss; + int verbose = SvIV(perl_get_sv("SNMP::verbose", 0x01 | 0x04)); + + sess_ptr_sv = hv_fetch((HV*)SvRV(sess_ref), "SessPtr", 7, 1); + ss = (SnmpSession *)SvIV((SV*)SvRV(*sess_ptr_sv)); + + if (!ss) goto update_end; + + ss->version = -1; +#ifndef NETSNMP_DISABLE_SNMPV1 + if (!strcmp(version, "1")) { + ss->version = SNMP_VERSION_1; + } +#endif +#ifndef NETSNMP_DISABLE_SNMPV2C + if (!strcmp(version, "2") || !strcmp(version, "2c")) { + ss->version = SNMP_VERSION_2c; + } +#endif + if (!strcmp(version, "3")) { + ss->version = SNMP_VERSION_3; + } + if (ss->version == -1) { + if (verbose) + warn("snmp_update_session: Unsupported SNMP version (%s)\n", version); + goto update_end; + } + /* WARNING LEAKAGE but I cant free lib memory under win32 */ + ss->community_len = strlen((char *)community); + ss->community = (u_char *)netsnmp_strdup(community); + ss->peername = netsnmp_strdup(peer); + ss->local_port = lport; + ss->retries = retries; /* 5 */ + ss->timeout = timeout; /* 1000000L */ + ss->authenticator = NULL; + + update_end: + RETVAL = ss; + } + OUTPUT: + RETVAL + +int +snmp_add_mib_dir(mib_dir,force=0) + char * mib_dir + int force + CODE: + { + int result = 0; /* Avoid use of uninitialized variable below. */ + int verbose = SvIV(perl_get_sv("SNMP::verbose", 0x01 | 0x04)); + + DBPRT(999, (DBOUT "force=%d\n", force)); + + if (mib_dir && *mib_dir) { + result = add_mibdir(mib_dir); + } + if (result) { + if (verbose) warn("snmp_add_mib_dir: Added mib dir %s\n", mib_dir); + } else { + if (verbose) warn("snmp_add_mib_dir: Failed to add %s\n", mib_dir); + } + RETVAL = (I32)result; + } + OUTPUT: + RETVAL + +void +snmp_init_mib_internals() + CODE: + { + int notused = 1; notused++; + /* this function does nothing */ + /* it is kept only for backwards compatibility */ + } + + +char * +snmp_getenv(name) + char *name; +CODE: + RETVAL = netsnmp_getenv(name); +OUTPUT: + RETVAL + +int +snmp_setenv(envname, envval, overwrite) + char *envname; + char *envval; + int overwrite; +CODE: + RETVAL = netsnmp_setenv(envname, envval, overwrite); +OUTPUT: + RETVAL + +int +snmp_read_mib(mib_file, force=0) + char * mib_file + int force + CODE: + { + int verbose = SvIV(perl_get_sv("SNMP::verbose", 0x01 | 0x04)); + + DBPRT(999, (DBOUT "force=%d\n", force)); + + if ((mib_file == NULL) || (*mib_file == '\0')) { + if (get_tree_head() == NULL) { + if (verbose) warn("snmp_read_mib: initializing MIB\n"); + netsnmp_init_mib(); + if (get_tree_head()) { + if (verbose) warn("done\n"); + } else { + if (verbose) warn("failed\n"); + } + } + } else { + if (verbose) warn("snmp_read_mib: reading MIB: %s\n", mib_file); + if (strcmp("ALL",mib_file)) + read_mib(mib_file); + else + read_all_mibs(); + if (get_tree_head()) { + if (verbose) warn("done\n"); + } else { + if (verbose) warn("failed\n"); + } + } + RETVAL = (IV)get_tree_head(); + } + OUTPUT: + RETVAL + + +int +snmp_read_module(module) + char * module + CODE: + { + int verbose = SvIV(perl_get_sv("SNMP::verbose", 0x01 | 0x04)); + + if (!strcmp(module,"ALL")) { + read_all_mibs(); + } else { + netsnmp_read_module(module); + } + if (get_tree_head()) { + if (verbose) warn("Read %s\n", module); + } else { + if (verbose) warn("Failed reading %s\n", module); + } + RETVAL = (IV)get_tree_head(); + } + OUTPUT: + RETVAL + + +void +snmp_set(sess_ref, varlist_ref, perl_callback) + SV * sess_ref + SV * varlist_ref + SV * perl_callback + PPCODE: + { + AV *varlist; + SV **varbind_ref; + SV **varbind_val_f; + AV *varbind; + I32 varlist_len; + I32 varlist_ind; + SnmpSession *ss; + netsnmp_pdu *pdu, *response; + struct tree *tp; + oid *oid_arr; + size_t oid_arr_len = MAX_OID_LEN; + char *tag_pv; + snmp_xs_cb_data *xs_cb_data; + SV **sess_ptr_sv; + SV **err_str_svp; + SV **err_num_svp; + SV **err_ind_svp; + int status = 0; + int type; + int res; + int verbose = SvIV(perl_get_sv("SNMP::verbose", 0x01 | 0x04)); + int use_enums; + struct enum_list *ep; + int best_guess; +#ifndef NETSNMP_NO_WRITE_SUPPORT + + New (0, oid_arr, MAX_OID_LEN, oid); + + if (oid_arr && SvROK(sess_ref) && SvROK(varlist_ref)) { + + use_enums = SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseEnums",8,1)); + sess_ptr_sv = hv_fetch((HV*)SvRV(sess_ref), "SessPtr", 7, 1); + ss = (SnmpSession *)SvIV((SV*)SvRV(*sess_ptr_sv)); + err_str_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorStr", 8, 1); + err_num_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorNum", 8, 1); + err_ind_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorInd", 8, 1); + sv_setpv(*err_str_svp, ""); + sv_setiv(*err_num_svp, 0); + sv_setiv(*err_ind_svp, 0); + best_guess = SvIV(*hv_fetch((HV*)SvRV(sess_ref),"BestGuess",9,1)); + + pdu = snmp_pdu_create(SNMP_MSG_SET); + + varlist = (AV*) SvRV(varlist_ref); + varlist_len = av_len(varlist); + for(varlist_ind = 0; varlist_ind <= varlist_len; varlist_ind++) { + varbind_ref = av_fetch(varlist, varlist_ind, 0); + if (SvROK(*varbind_ref)) { + varbind = (AV*) SvRV(*varbind_ref); + tag_pv = __av_elem_pv(varbind, VARBIND_TAG_F,NULL); + tp=__tag2oid(tag_pv, + __av_elem_pv(varbind, VARBIND_IID_F,NULL), + oid_arr, &oid_arr_len, &type, best_guess); + + if (oid_arr_len==0) { + if (verbose) + warn("error: set: unknown object ID (%s)", + (tag_pv?tag_pv:"<null>")); + sv_catpv(*err_str_svp, + (char*)snmp_api_errstring(SNMPERR_UNKNOWN_OBJID)); + sv_setiv(*err_num_svp, SNMPERR_UNKNOWN_OBJID); + XPUSHs(&sv_undef); /* unknown OID */ + snmp_free_pdu(pdu); + goto done; + } + + + if (type == TYPE_UNKNOWN) { + type = __translate_appl_type( + __av_elem_pv(varbind, VARBIND_TYPE_F, NULL)); + if (type == TYPE_UNKNOWN) { + if (verbose) + warn("error: set: no type found for object"); + sv_catpv(*err_str_svp, + (char*)snmp_api_errstring(SNMPERR_VAR_TYPE)); + sv_setiv(*err_num_svp, SNMPERR_VAR_TYPE); + XPUSHs(&sv_undef); /* unknown OID */ + snmp_free_pdu(pdu); + goto done; + } + } + + varbind_val_f = av_fetch(varbind, VARBIND_VAL_F, 0); + + if (type==TYPE_INTEGER && use_enums && tp && tp->enums) { + for(ep = tp->enums; ep; ep = ep->next) { + if (varbind_val_f && SvOK(*varbind_val_f) && + !strcmp(ep->label, SvPV(*varbind_val_f,na))) { + sv_setiv(*varbind_val_f, ep->value); + break; + } + } + } + + res = __add_var_val_str(pdu, oid_arr, oid_arr_len, + (varbind_val_f && SvOK(*varbind_val_f) ? + SvPV(*varbind_val_f,na):NULL), + (varbind_val_f && SvPOK(*varbind_val_f) ? + SvCUR(*varbind_val_f):0), type); + + if (verbose && res == FAILURE) + warn("error: set: adding variable/value to PDU"); + } /* if var_ref is ok */ + } /* for all the vars */ + + if (SvTRUE(perl_callback)) { + xs_cb_data = + (snmp_xs_cb_data*)malloc(sizeof(snmp_xs_cb_data)); + xs_cb_data->perl_cb = newSVsv(perl_callback); + xs_cb_data->sess_ref = newRV_inc(SvRV(sess_ref)); + + if(api_mode == SNMP_API_SINGLE) + { + status = snmp_sess_async_send(ss, pdu, __snmp_xs_cb, + (void*)xs_cb_data); + } else { + status = snmp_async_send(ss, pdu, __snmp_xs_cb, + (void*)xs_cb_data); + } + if (status != 0) { + XPUSHs(sv_2mortal(newSViv(status))); /* push the reqid?? */ + } else { + snmp_free_pdu(pdu); + snmp_return_err(ss, *err_str_svp, *err_num_svp, *err_ind_svp); + XPUSHs(&sv_undef); + } + goto done; + } + + status = __send_sync_pdu(ss, pdu, &response, + NO_RETRY_NOSUCH, + *err_str_svp, *err_num_svp, + *err_ind_svp); + + if (response) snmp_free_pdu(response); + + if (status) { + XPUSHs(&sv_undef); + } else { + XPUSHs(sv_2mortal(newSVpv(ZERO_BUT_TRUE,0))); + } + } else { + + /* BUG!!! need to return an error value */ + XPUSHs(&sv_undef); /* no mem or bad args */ + } +#else /* NETSNMP_NO_WRITE_SUPPORT */ + warn("error: Net-SNMP was compiled using --enable-read-only, set() can not be used."); +#endif /* NETSNMP_NO_WRITE_SUPPORT */ +done: + Safefree(oid_arr); + } + +void +snmp_catch(sess_ref, perl_callback) + SV * sess_ref + SV * perl_callback + PPCODE: + { + netsnmp_session *ss; + SV **sess_ptr_sv; + SV **err_str_svp; + SV **err_num_svp; + SV **err_ind_svp; + + if (SvROK(sess_ref)) { + sess_ptr_sv = hv_fetch((HV*)SvRV(sess_ref), "SessPtr", 7, 1); + ss = (SnmpSession *)SvIV((SV*)SvRV(*sess_ptr_sv)); + err_str_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorStr", 8, 1); + err_num_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorNum", 8, 1); + err_ind_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorInd", 8, 1); + sv_setpv(*err_str_svp, ""); + sv_setiv(*err_num_svp, 0); + sv_setiv(*err_ind_svp, 0); + + ss->callback = NULL; + ss->callback_magic = NULL; + + if (SvTRUE(perl_callback)) { + snmp_xs_cb_data *xs_cb_data; + xs_cb_data = + (snmp_xs_cb_data*)malloc(sizeof(snmp_xs_cb_data)); + xs_cb_data->perl_cb = newSVsv(perl_callback); + xs_cb_data->sess_ref = newRV_inc(SvRV(sess_ref)); + + # it might be more efficient to pass the varbind_ref to + # __snmp_xs_cb as part of perl_callback so it is not freed + # and reconstructed for each call + ss->callback = __snmp_xs_cb; + ss->callback_magic = xs_cb_data; + sv_2mortal(newSViv(1)); + goto done; + } + } + sv_2mortal(newSViv(0)); + done: + ; + } + +void +snmp_get(sess_ref, retry_nosuch, varlist_ref, perl_callback) + SV * sess_ref + int retry_nosuch + SV * varlist_ref + SV * perl_callback + PPCODE: + { + AV *varlist; + SV **varbind_ref; + AV *varbind; + I32 varlist_len; + I32 varlist_ind; + netsnmp_session *ss; + netsnmp_pdu *pdu, *response; + netsnmp_variable_list *vars; + struct tree *tp; + int len; + oid *oid_arr; + size_t oid_arr_len = MAX_OID_LEN; + SV *tmp_sv; + int type; + char tmp_type_str[MAX_TYPE_NAME_LEN]; + snmp_xs_cb_data *xs_cb_data; + SV **sess_ptr_sv; + SV **err_str_svp; + SV **err_num_svp; + SV **err_ind_svp; + int status; + char str_buf[STR_BUF_SIZE], *str_bufp = str_buf; + size_t str_buf_len = sizeof(str_buf); + size_t out_len = 0; + int buf_over = 0; + char *label; + char *iid; + int getlabel_flag = NO_FLAGS; + int sprintval_flag = USE_BASIC; + int verbose = SvIV(perl_get_sv("SNMP::verbose", 0x01 | 0x04)); + int old_format; + SV *sv_timestamp = NULL; + int best_guess; + + New (0, oid_arr, MAX_OID_LEN, oid); + + if (oid_arr && SvROK(sess_ref) && SvROK(varlist_ref)) { + + sess_ptr_sv = hv_fetch((HV*)SvRV(sess_ref), "SessPtr", 7, 1); + ss = (SnmpSession *)SvIV((SV*)SvRV(*sess_ptr_sv)); + err_str_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorStr", 8, 1); + err_num_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorNum", 8, 1); + err_ind_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorInd", 8, 1); + sv_setpv(*err_str_svp, ""); + sv_setiv(*err_num_svp, 0); + sv_setiv(*err_ind_svp, 0); + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseLongNames", 12, 1))) + getlabel_flag |= USE_LONG_NAMES; + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseNumeric", 10, 1))) + getlabel_flag |= USE_NUMERIC_OIDS; + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseEnums", 8, 1))) + sprintval_flag = USE_ENUMS; + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseSprintValue", 14, 1))) + sprintval_flag = USE_SPRINT_VALUE; + best_guess = SvIV(*hv_fetch((HV*)SvRV(sess_ref),"BestGuess",9,1)); + + pdu = snmp_pdu_create(SNMP_MSG_GET); + + varlist = (AV*) SvRV(varlist_ref); + varlist_len = av_len(varlist); + for(varlist_ind = 0; varlist_ind <= varlist_len; varlist_ind++) { + varbind_ref = av_fetch(varlist, varlist_ind, 0); + if (SvROK(*varbind_ref)) { + char *tag_pv; + varbind = (AV*) SvRV(*varbind_ref); + + tag_pv = __av_elem_pv(varbind, VARBIND_TAG_F, ".0"); + tp = __tag2oid(tag_pv, + __av_elem_pv(varbind, VARBIND_IID_F, NULL), + oid_arr, &oid_arr_len, NULL, best_guess); + + if (oid_arr_len) { + snmp_add_null_var(pdu, oid_arr, oid_arr_len); + } else { + if (verbose) + warn("error: get: unknown object ID (%s)", + (tag_pv?tag_pv:"<null>")); + sv_catpv(*err_str_svp, + (char*)snmp_api_errstring(SNMPERR_UNKNOWN_OBJID)); + sv_setiv(*err_num_svp, SNMPERR_UNKNOWN_OBJID); + XPUSHs(&sv_undef); /* unknown OID */ + snmp_free_pdu(pdu); + goto done; + } + + } /* if var_ref is ok */ + } /* for all the vars */ + + if (perl_callback && SvTRUE(perl_callback)) { + xs_cb_data = + (snmp_xs_cb_data*)malloc(sizeof(snmp_xs_cb_data)); + xs_cb_data->perl_cb = newSVsv(perl_callback); + xs_cb_data->sess_ref = newSVsv(sess_ref); + + if(api_mode == SNMP_API_SINGLE) + { + status = snmp_sess_async_send(ss, pdu, __snmp_xs_cb, + (void*)xs_cb_data); + } else { + status = snmp_async_send(ss, pdu, __snmp_xs_cb, + (void*)xs_cb_data); + } + if (status != 0) { + XPUSHs(sv_2mortal(newSViv(status))); /* push the reqid?? */ + } else { + snmp_free_pdu(pdu); + snmp_return_err(ss, *err_num_svp, *err_ind_svp, *err_str_svp); + XPUSHs(&sv_undef); + } + goto done; + } + + status = __send_sync_pdu(ss, pdu, &response, + retry_nosuch, + *err_str_svp, *err_num_svp, + *err_ind_svp); + + /* + ** Set up for numeric or full OID's, if necessary. Save the old + ** output format so that it can be restored when we finish -- this + ** is a library-wide global, and has to be set/restored for each + ** session. + */ + old_format = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, + NETSNMP_DS_LIB_OID_OUTPUT_FORMAT); + + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseLongNames", 12, 1))) { + getlabel_flag |= USE_LONG_NAMES; + + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, + NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, + NETSNMP_OID_OUTPUT_FULL); + } + /* Setting UseNumeric forces UseLongNames on so check for UseNumeric + after UseLongNames (above) to make sure the final outcome of + NETSNMP_DS_LIB_OID_OUTPUT_FORMAT is NETSNMP_OID_OUTPUT_NUMERIC */ + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseNumeric", 10, 1))) { + getlabel_flag |= USE_LONG_NAMES; + getlabel_flag |= USE_NUMERIC_OIDS; + + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, + NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, + NETSNMP_OID_OUTPUT_NUMERIC); + } + + if (SvIOK(*hv_fetch((HV*)SvRV(sess_ref),"TimeStamp", 9, 1)) && + SvIV(*hv_fetch((HV*)SvRV(sess_ref),"TimeStamp", 9, 1))) + sv_timestamp = newSViv((IV)time(NULL)); + + for(vars = (response?response->variables:NULL), varlist_ind = 0; + vars && (varlist_ind <= varlist_len); + vars = vars->next_variable, varlist_ind++) { + int local_getlabel_flag = getlabel_flag; + varbind_ref = av_fetch(varlist, varlist_ind, 0); + if (SvROK(*varbind_ref)) { + varbind = (AV*) SvRV(*varbind_ref); + + *str_buf = '.'; + *(str_buf+1) = '\0'; + out_len = 0; + tp = netsnmp_sprint_realloc_objid_tree((u_char**)&str_bufp, + &str_buf_len, + &out_len, 0, + &buf_over, + vars->name, + vars->name_length); + str_buf[sizeof(str_buf)-1] = '\0'; + + if (__is_leaf(tp)) { + type = tp->type; + } else { + local_getlabel_flag |= NON_LEAF_NAME; + type = __translate_asn_type(vars->type); + } + __get_label_iid(str_buf,&label,&iid,local_getlabel_flag); + if (label) { + av_store(varbind, VARBIND_TAG_F, + newSVpv(label, strlen(label))); + } else { + av_store(varbind, VARBIND_TAG_F, + newSVpv("", 0)); + } + if (iid) { + av_store(varbind, VARBIND_IID_F, + newSVpv(iid, strlen(iid))); + } else { + av_store(varbind, VARBIND_IID_F, + newSVpv("", 0)); + } + __get_type_str(type, tmp_type_str); + tmp_sv = newSVpv(tmp_type_str, strlen(tmp_type_str)); + av_store(varbind, VARBIND_TYPE_F, tmp_sv); + len=__snprint_value(str_buf,sizeof(str_buf), + vars,tp,type,sprintval_flag); + tmp_sv = newSVpv(str_buf, len); + av_store(varbind, VARBIND_VAL_F, tmp_sv); + if (sv_timestamp) + av_store(varbind, VARBIND_TYPE_F, sv_timestamp); + XPUSHs(sv_mortalcopy(tmp_sv)); + } else { + /* Return undef for this variable. */ + XPUSHs(&sv_undef); + } + } + + /* Reset the library's behavior for numeric/symbolic OID's. */ + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, + NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, + old_format); + + if (response) snmp_free_pdu(response); + + } else { + XPUSHs(&sv_undef); /* no mem or bad args */ + } +done: + Safefree(oid_arr); + } + +void +snmp_getnext(sess_ref, varlist_ref, perl_callback) + SV * sess_ref + SV * varlist_ref + SV * perl_callback + PPCODE: + { + AV *varlist; + SV **varbind_ref; + AV *varbind; + I32 varlist_len; + I32 varlist_ind; + netsnmp_session *ss; + netsnmp_pdu *pdu, *response; + netsnmp_variable_list *vars; + struct tree *tp; + int len; + oid *oid_arr; + size_t oid_arr_len = MAX_OID_LEN; + SV *tmp_sv; + int type; + char tmp_type_str[MAX_TYPE_NAME_LEN]; + snmp_xs_cb_data *xs_cb_data; + SV **sess_ptr_sv; + SV **err_str_svp; + SV **err_num_svp; + SV **err_ind_svp; + int status; + char str_buf[STR_BUF_SIZE], *str_bufp = str_buf; + size_t str_buf_len = sizeof(str_buf); + char tmp_buf_prefix[STR_BUF_SIZE]; + char str_buf_prefix[STR_BUF_SIZE]; + size_t out_len = 0; + int buf_over = 0; + char *label; + char *iid; + int getlabel_flag = NO_FLAGS; + int sprintval_flag = USE_BASIC; + int verbose = SvIV(perl_get_sv("SNMP::verbose", 0x01 | 0x04)); + int old_format; + SV *sv_timestamp = NULL; + int best_guess; + char *tmp_prefix_ptr; + char *st; + + New (0, oid_arr, MAX_OID_LEN, oid); + + if (oid_arr && SvROK(sess_ref) && SvROK(varlist_ref)) { + + sess_ptr_sv = hv_fetch((HV*)SvRV(sess_ref), "SessPtr", 7, 1); + ss = (SnmpSession *)SvIV((SV*)SvRV(*sess_ptr_sv)); + err_str_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorStr", 8, 1); + err_num_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorNum", 8, 1); + err_ind_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorInd", 8, 1); + sv_setpv(*err_str_svp, ""); + sv_setiv(*err_num_svp, 0); + sv_setiv(*err_ind_svp, 0); + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseLongNames", 12, 1))) + getlabel_flag |= USE_LONG_NAMES; + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseNumeric", 10, 1))) + getlabel_flag |= USE_NUMERIC_OIDS; + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseEnums", 8, 1))) + sprintval_flag = USE_ENUMS; + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseSprintValue", 14, 1))) + sprintval_flag = USE_SPRINT_VALUE; + best_guess = SvIV(*hv_fetch((HV*)SvRV(sess_ref),"BestGuess",9,1)); + + pdu = snmp_pdu_create(SNMP_MSG_GETNEXT); + + varlist = (AV*) SvRV(varlist_ref); + varlist_len = av_len(varlist); + for(varlist_ind = 0; varlist_ind <= varlist_len; varlist_ind++) { + varbind_ref = av_fetch(varlist, varlist_ind, 0); + if (SvROK(*varbind_ref)) { + char *tag_pv; + varbind = (AV*) SvRV(*varbind_ref); + + /* If the varbind includes the module prefix, capture it for use later */ + strlcpy(tmp_buf_prefix, __av_elem_pv(varbind, VARBIND_TAG_F, ".0"), STR_BUF_SIZE); + tmp_prefix_ptr = strstr(tmp_buf_prefix,"::"); + if (tmp_prefix_ptr) { + tmp_prefix_ptr = strtok_r(tmp_buf_prefix, "::", &st); + strlcpy(str_buf_prefix, tmp_prefix_ptr, STR_BUF_SIZE); + } + else { + *str_buf_prefix = '\0'; + } + + tag_pv = __av_elem_pv(varbind, VARBIND_TAG_F, ".0"); + tp = __tag2oid(tag_pv, + __av_elem_pv(varbind, VARBIND_IID_F, NULL), + oid_arr, &oid_arr_len, NULL, best_guess); + + if (oid_arr_len) { + snmp_add_null_var(pdu, oid_arr, oid_arr_len); + } else { + if (verbose) + warn("error: getnext: unknown object ID (%s)", + (tag_pv?tag_pv:"<null>")); + sv_catpv(*err_str_svp, + (char*)snmp_api_errstring(SNMPERR_UNKNOWN_OBJID)); + sv_setiv(*err_num_svp, SNMPERR_UNKNOWN_OBJID); + XPUSHs(&sv_undef); /* unknown OID */ + snmp_free_pdu(pdu); + goto done; + } + + } /* if var_ref is ok */ + } /* for all the vars */ + + if (SvTRUE(perl_callback)) { + xs_cb_data = + (snmp_xs_cb_data*)malloc(sizeof(snmp_xs_cb_data)); + xs_cb_data->perl_cb = newSVsv(perl_callback); + xs_cb_data->sess_ref = newSVsv(sess_ref); + + if(api_mode == SNMP_API_SINGLE) + { + status = snmp_sess_async_send(ss, pdu, __snmp_xs_cb, + (void*)xs_cb_data); + } else { + status = snmp_async_send(ss, pdu, __snmp_xs_cb, + (void*)xs_cb_data); + } + if (status != 0) { + XPUSHs(sv_2mortal(newSViv(status))); /* push the reqid?? */ + } else { + snmp_free_pdu(pdu); + snmp_return_err(ss, *err_num_svp, *err_ind_svp, *err_str_svp); + XPUSHs(&sv_undef); + } + goto done; + } + + status = __send_sync_pdu(ss, pdu, &response, + NO_RETRY_NOSUCH, + *err_str_svp, *err_num_svp, + *err_ind_svp); + + /* + ** Set up for numeric or full OID's, if necessary. Save the old + ** output format so that it can be restored when we finish -- this + ** is a library-wide global, and has to be set/restored for each + ** session. + */ + old_format = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, + NETSNMP_DS_LIB_OID_OUTPUT_FORMAT); + + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseLongNames", 12, 1))) { + getlabel_flag |= USE_LONG_NAMES; + + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, + NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, + NETSNMP_OID_OUTPUT_FULL); + } + /* Setting UseNumeric forces UseLongNames on so check + for UseNumeric after UseLongNames (above) to make + sure the final outcome of + NETSNMP_DS_LIB_OID_OUTPUT_FORMAT is + NETSNMP_OID_OUTPUT_NUMERIC */ + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseNumeric", 10, 1))) { + getlabel_flag |= USE_LONG_NAMES; + getlabel_flag |= USE_NUMERIC_OIDS; + + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, + NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, + NETSNMP_OID_OUTPUT_NUMERIC); + } + + if (SvIOK(*hv_fetch((HV*)SvRV(sess_ref),"TimeStamp", 9, 1)) && + SvIV(*hv_fetch((HV*)SvRV(sess_ref),"TimeStamp", 9, 1))) + sv_timestamp = newSViv((IV)time(NULL)); + + for(vars = (response?response->variables:NULL), varlist_ind = 0; + vars && (varlist_ind <= varlist_len); + vars = vars->next_variable, varlist_ind++) { + int local_getlabel_flag = getlabel_flag; + varbind_ref = av_fetch(varlist, varlist_ind, 0); + if (SvROK(*varbind_ref)) { + varbind = (AV*) SvRV(*varbind_ref); + + *str_buf = '.'; + *(str_buf+1) = '\0'; + out_len = 0; + tp = netsnmp_sprint_realloc_objid_tree((u_char**)&str_bufp, + &str_buf_len, + &out_len, 0, + &buf_over, + vars->name, + vars->name_length); + str_buf[sizeof(str_buf)-1] = '\0'; + + /* Prepend the module prefix to the next OID if needed */ + if (*str_buf_prefix) { + strlcat(str_buf_prefix, "::", STR_BUF_SIZE); + strlcat(str_buf_prefix, str_buf, STR_BUF_SIZE); + strlcpy(str_buf, str_buf_prefix, STR_BUF_SIZE); + } + + if (__is_leaf(tp)) { + type = tp->type; + } else { + local_getlabel_flag |= NON_LEAF_NAME; + type = __translate_asn_type(vars->type); + } + __get_label_iid(str_buf,&label,&iid,local_getlabel_flag); + if (label) { + av_store(varbind, VARBIND_TAG_F, + newSVpv(label, strlen(label))); + } else { + av_store(varbind, VARBIND_TAG_F, + newSVpv("", 0)); + } + if (iid) { + av_store(varbind, VARBIND_IID_F, + newSVpv(iid, strlen(iid))); + } else { + av_store(varbind, VARBIND_IID_F, + newSVpv("", 0)); + } + __get_type_str(type, tmp_type_str); + tmp_sv = newSVpv(tmp_type_str, strlen(tmp_type_str)); + av_store(varbind, VARBIND_TYPE_F, tmp_sv); + len=__snprint_value(str_buf,sizeof(str_buf), + vars,tp,type,sprintval_flag); + tmp_sv = newSVpv(str_buf, len); + av_store(varbind, VARBIND_VAL_F, tmp_sv); + if (sv_timestamp) + av_store(varbind, VARBIND_TYPE_F, sv_timestamp); + XPUSHs(sv_mortalcopy(tmp_sv)); + } else { + /* Return undef for this variable. */ + XPUSHs(&sv_undef); + } + } + + /* Reset the library's behavior for numeric/symbolic OID's. */ + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, + NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, + old_format); + + if (response) snmp_free_pdu(response); + + } else { + XPUSHs(&sv_undef); /* no mem or bad args */ + } +done: + Safefree(oid_arr); + } + +void +snmp_getbulk(sess_ref, nonrepeaters, maxrepetitions, varlist_ref, perl_callback) + SV * sess_ref + int nonrepeaters + int maxrepetitions + SV * varlist_ref + SV * perl_callback + PPCODE: + { + AV *varlist; + SV **varbind_ref; + AV *varbind; + I32 varlist_len; + I32 varlist_ind; + netsnmp_session *ss; + netsnmp_pdu *pdu, *response; + netsnmp_variable_list *vars; + struct tree *tp; + int len; + oid *oid_arr; + size_t oid_arr_len = MAX_OID_LEN; + SV *tmp_sv; + int type; + char tmp_type_str[MAX_TYPE_NAME_LEN]; + snmp_xs_cb_data *xs_cb_data; + SV **sess_ptr_sv; + SV **err_str_svp; + SV **err_num_svp; + SV **err_ind_svp; + int status; + char str_buf[STR_BUF_SIZE], *str_bufp = str_buf; + size_t str_buf_len = sizeof(str_buf); + size_t out_len = 0; + int buf_over = 0; + char *label; + char *iid; + int getlabel_flag = NO_FLAGS; + int sprintval_flag = USE_BASIC; + int verbose = SvIV(perl_get_sv("SNMP::verbose", 0x01 | 0x04)); + int old_format; + SV *rv; + SV *sv_timestamp = NULL; + int best_guess; + + New (0, oid_arr, MAX_OID_LEN, oid); + + if (oid_arr && SvROK(sess_ref) && SvROK(varlist_ref)) { + + sess_ptr_sv = hv_fetch((HV*)SvRV(sess_ref), "SessPtr", 7, 1); + ss = (SnmpSession *)SvIV((SV*)SvRV(*sess_ptr_sv)); + err_str_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorStr", 8, 1); + err_num_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorNum", 8, 1); + err_ind_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorInd", 8, 1); + sv_setpv(*err_str_svp, ""); + sv_setiv(*err_num_svp, 0); + sv_setiv(*err_ind_svp, 0); + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseLongNames", 12, 1))) + getlabel_flag |= USE_LONG_NAMES; + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseNumeric", 10, 1))) + getlabel_flag |= USE_NUMERIC_OIDS; + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseEnums", 8, 1))) + sprintval_flag = USE_ENUMS; + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseSprintValue", 14, 1))) + sprintval_flag = USE_SPRINT_VALUE; + best_guess = SvIV(*hv_fetch((HV*)SvRV(sess_ref),"BestGuess",9,1)); + + pdu = snmp_pdu_create(SNMP_MSG_GETBULK); + + pdu->errstat = nonrepeaters; + pdu->errindex = maxrepetitions; + + varlist = (AV*) SvRV(varlist_ref); + varlist_len = av_len(varlist); + for(varlist_ind = 0; varlist_ind <= varlist_len; varlist_ind++) { + varbind_ref = av_fetch(varlist, varlist_ind, 0); + if (SvROK(*varbind_ref)) { + char *tag_pv; + varbind = (AV*) SvRV(*varbind_ref); + tag_pv = __av_elem_pv(varbind, VARBIND_TAG_F, "0"); + __tag2oid(tag_pv, + __av_elem_pv(varbind, VARBIND_IID_F, NULL), + oid_arr, &oid_arr_len, NULL, best_guess); + + + if (oid_arr_len) { + snmp_add_null_var(pdu, oid_arr, oid_arr_len); + } else { + if (verbose) + warn("error: getbulk: unknown object ID (%s)", + (tag_pv?tag_pv:"<null>")); + sv_catpv(*err_str_svp, + (char*)snmp_api_errstring(SNMPERR_UNKNOWN_OBJID)); + sv_setiv(*err_num_svp, SNMPERR_UNKNOWN_OBJID); + XPUSHs(&sv_undef); /* unknown OID */ + snmp_free_pdu(pdu); + goto done; + } + + + } /* if var_ref is ok */ + } /* for all the vars */ + + if (SvTRUE(perl_callback)) { + xs_cb_data = + (snmp_xs_cb_data*)malloc(sizeof(snmp_xs_cb_data)); + xs_cb_data->perl_cb = newSVsv(perl_callback); + xs_cb_data->sess_ref = newSVsv(sess_ref); + + if(api_mode == SNMP_API_SINGLE) + { + status = snmp_sess_async_send(ss, pdu, __snmp_xs_cb, + (void*)xs_cb_data); + } else { + status = snmp_async_send(ss, pdu, __snmp_xs_cb, + (void*)xs_cb_data); + } + if (status != 0) { + XPUSHs(sv_2mortal(newSViv(status))); /* push the reqid?? */ + } else { + snmp_free_pdu(pdu); + snmp_return_err(ss, *err_num_svp, *err_ind_svp, *err_str_svp); + XPUSHs(&sv_undef); + } + goto done; + } + + status = __send_sync_pdu(ss, pdu, &response, + NO_RETRY_NOSUCH, + *err_str_svp, *err_num_svp, + *err_ind_svp); + + if (SvIOK(*hv_fetch((HV*)SvRV(sess_ref),"TimeStamp", 9, 1)) && + SvIV(*hv_fetch((HV*)SvRV(sess_ref),"TimeStamp", 9, 1))) + sv_timestamp = newSViv((IV)time(NULL)); + + av_clear(varlist); + + /* + ** Set up for numeric or full OID's, if necessary. Save the old + ** output format so that it can be restored when we finish -- this + ** is a library-wide global, and has to be set/restored for each + ** session. + */ + old_format = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, + NETSNMP_DS_LIB_OID_OUTPUT_FORMAT); + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseLongNames", 12, 1))) { + getlabel_flag |= USE_LONG_NAMES; + + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, + NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, + NETSNMP_OID_OUTPUT_FULL); + } + /* Setting UseNumeric forces UseLongNames on so check for UseNumeric + after UseLongNames (above) to make sure the final outcome of + NETSNMP_DS_LIB_OID_OUTPUT_FORMAT is NETSNMP_OID_OUTPUT_NUMERIC */ + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseNumeric", 10, 1))) { + getlabel_flag |= USE_LONG_NAMES; + getlabel_flag |= USE_NUMERIC_OIDS; + + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, + NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, + NETSNMP_OID_OUTPUT_NUMERIC); + } + + if(response && response->variables) { + for(vars = response->variables; + vars; + vars = vars->next_variable) { + + int local_getlabel_flag = getlabel_flag; + varbind = (AV*) newAV(); + *str_buf = '.'; + *(str_buf+1) = '\0'; + out_len = 0; + buf_over = 0; + str_bufp = str_buf; + tp = netsnmp_sprint_realloc_objid_tree((u_char**)&str_bufp, + &str_buf_len, + &out_len, 0, + &buf_over, + vars->name, + vars->name_length); + str_buf[sizeof(str_buf)-1] = '\0'; + if (__is_leaf(tp)) { + type = tp->type; + } else { + local_getlabel_flag |= NON_LEAF_NAME; + type = __translate_asn_type(vars->type); + } + __get_label_iid(str_buf,&label,&iid,local_getlabel_flag); + if (label) { + av_store(varbind, VARBIND_TAG_F, + newSVpv(label, strlen(label))); + } else { + av_store(varbind, VARBIND_TAG_F, + newSVpv("", 0)); + } + if (iid) { + av_store(varbind, VARBIND_IID_F, + newSVpv(iid, strlen(iid))); + } else { + av_store(varbind, VARBIND_IID_F, + newSVpv("", 0)); + } + __get_type_str(type, tmp_type_str); + av_store(varbind, VARBIND_TYPE_F, newSVpv(tmp_type_str, + strlen(tmp_type_str))); + + len=__snprint_value(str_buf,sizeof(str_buf), + vars,tp,type,sprintval_flag); + tmp_sv = newSVpv(str_buf, len); + av_store(varbind, VARBIND_VAL_F, tmp_sv); + if (sv_timestamp) + av_store(varbind, VARBIND_TYPE_F, SvREFCNT_inc(sv_timestamp)); + + rv = newRV_noinc((SV *)varbind); + sv_bless(rv, gv_stashpv("SNMP::Varbind",0)); + av_push(varlist, rv); + + XPUSHs(sv_mortalcopy(tmp_sv)); + } + } else { + XPUSHs(&sv_undef); + } + + /* Reset the library's behavior for numeric/symbolic OID's. */ + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, + NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, + old_format); + + if (response) snmp_free_pdu(response); + + } else { + XPUSHs(&sv_undef); /* no mem or bad args */ + } +done: + Safefree(oid_arr); + } + +void +snmp_bulkwalk(sess_ref, nonrepeaters, maxrepetitions, varlist_ref,perl_callback) + SV * sess_ref + int nonrepeaters + int maxrepetitions + SV * varlist_ref + SV * perl_callback + PPCODE: + { + AV *varlist; + SV **varbind_ref; + AV *varbind; + I32 varlist_len; + I32 varlist_ind; + netsnmp_session *ss; + netsnmp_pdu *pdu = NULL; + oid oid_arr[MAX_OID_LEN]; + size_t oid_arr_len; + SV **sess_ptr_sv; + SV **err_str_svp; + SV **err_num_svp; + SV **err_ind_svp; + char str_buf[STR_BUF_SIZE]; + int verbose = SvIV(perl_get_sv("SNMP::verbose", 0x01 | 0x04)); + walk_context *context = NULL; /* Context for this bulkwalk */ + bulktbl *bt_entry; /* Current bulktbl/OID entry */ + int i; /* General purpose iterator */ + int npushed; /* Number of return arrays */ + int okay; /* Did bulkwalk complete okay */ + int best_guess; + + if (!SvROK(sess_ref) || !SvROK(varlist_ref)) { + if (verbose) + warn("bulkwalk: Bad session or varlist reference!\n"); + + XSRETURN_UNDEF; + } + + sess_ptr_sv = hv_fetch((HV*)SvRV(sess_ref), "SessPtr", 7, 1); + ss = (SnmpSession *)SvIV((SV*)SvRV(*sess_ptr_sv)); + err_str_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorStr", 8, 1); + err_num_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorNum", 8, 1); + err_ind_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorInd", 8, 1); + sv_setpv(*err_str_svp, ""); + sv_setiv(*err_num_svp, 0); + sv_setiv(*err_ind_svp, 0); + best_guess = SvIV(*hv_fetch((HV*)SvRV(sess_ref),"BestGuess",9,1)); + + /* Create and initialize a new session context for this bulkwalk. + ** This will be used to carry state between callbacks. + */ + Newz(0x57616b6c /* "Walk" */, context, 1, walk_context); + if (context == NULL) { + sprintf(str_buf, "malloc(context) failed (%s)", strerror(errno)); + sv_setpv(*err_str_svp, str_buf); + sv_setiv(*err_num_svp, SNMPERR_MALLOC); + goto err; + } + + /* Store the Perl callback and session reference in the context. */ + context->perl_cb = newSVsv(perl_callback); + context->sess_ref = newSVsv(sess_ref); + + DBPRT(3,(DBOUT "bulkwalk: sess_ref = 0x%p, sess_ptr_sv = 0x%p, ss = 0x%p\n", + sess_ref, sess_ptr_sv, ss)); + + context->getlabel_f = NO_FLAGS; /* long/numeric name flags */ + context->sprintval_f = USE_BASIC; /* Don't do fancy printing */ + context->req_oids = NULL; /* List of oid's requested */ + context->repbase = NULL; /* Repeaters in req_oids[] */ + context->reqbase = NULL; /* Ptr to start of requests */ + context->nreq_oids = 0; /* Number of oid's in list */ + context->repeaters = 0; /* Repeater count (see below) */ + context->non_reps = nonrepeaters; /* Non-repeater var count */ + context->max_reps = maxrepetitions; /* Max repetition/var count */ + context->pkts_exch = 0; /* Packets exchanged in walk */ + context->oid_total = 0; /* OID's received during walk */ + context->oid_saved = 0; /* OID's saved as results */ + + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseLongNames", 12, 1))) + context->getlabel_f |= USE_LONG_NAMES; + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseNumeric", 10, 1))) + context->getlabel_f |= USE_NUMERIC_OIDS; + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseEnums", 8, 1))) + context->sprintval_f = USE_ENUMS; + if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseSprintValue", 14, 1))) + context->sprintval_f = USE_SPRINT_VALUE; + + /* Set up an array of bulktbl's to hold the original list of + ** requested OID's. This is used to populate the PDU's with + ** oid values, to contain/sort the return values, and (through + ** last_oid/last_len) to determine when the bulkwalk for each + ** variable has completed. + */ + varlist = (AV*) SvRV(varlist_ref); + varlist_len = av_len(varlist) + 1; /* XXX av_len returns index of + ** last element not #elements */ + + Newz(0, context->req_oids, varlist_len, bulktbl); + + if (context->req_oids == NULL) { + sprintf(str_buf, "Newz(req_oids) failed (%s)", strerror(errno)); + if (verbose) + warn("%s", str_buf); + sv_setpv(*err_str_svp, str_buf); + sv_setiv(*err_num_svp, SNMPERR_MALLOC); + goto err; + } + + /* Walk through the varbind_list, parsing and copying each OID + ** into a bulktbl slot in the req_oids array. Bail if there's + ** some error. Create the initial packet to send out, which + ** includes the non-repeaters. + */ + DBPRT(1,(DBOUT "Building request table:\n")); + for (varlist_ind = 0; varlist_ind < varlist_len; varlist_ind++) { + /* Get a handle on this entry in the request table. */ + bt_entry = &context->req_oids[context->nreq_oids]; + + DBPRT(1,(DBOUT " request %d: ", (int) varlist_ind)); + + /* Get the request varbind from the varlist, parse it out to + ** tag and index, and copy it to the req_oid[] array slots. + */ + varbind_ref = av_fetch(varlist, varlist_ind, 0); + if (!SvROK(*varbind_ref)) { + sv_setpv(*err_str_svp, \ + (char*)snmp_api_errstring(SNMPERR_BAD_NAME)); + sv_setiv(*err_num_svp, SNMPERR_BAD_NAME); + goto err; + } + + varbind = (AV*) SvRV(*varbind_ref); + __tag2oid(__av_elem_pv(varbind, VARBIND_TAG_F, "0"), + __av_elem_pv(varbind, VARBIND_IID_F, NULL), + oid_arr, &oid_arr_len, NULL, best_guess); + + if ((oid_arr_len == 0) || (oid_arr_len > MAX_OID_LEN)) { + if (verbose) + warn("error: bulkwalk(): unknown object ID"); + sv_setpv(*err_str_svp, \ + (char*)snmp_api_errstring(SNMPERR_UNKNOWN_OBJID)); + sv_setiv(*err_num_svp, SNMPERR_UNKNOWN_OBJID); + goto err; + } + + /* Copy the now-parsed OID into the first available slot + ** in the req_oids[] array. Set both the req_oid (original + ** request) and the last_oid (last requested/seen oid) to + ** the initial value. We build packets using last_oid (see + ** below), so initialize last_oid to the initial request. + */ + Copy((void *)oid_arr, (void *)bt_entry->req_oid, + oid_arr_len, oid); + Copy((void *)oid_arr, (void *)bt_entry->last_oid, + oid_arr_len, oid); + + bt_entry->req_len = oid_arr_len; + bt_entry->last_len = oid_arr_len; + + /* Adjust offset to and count of repeaters. Note non-repeater + ** OID's in the list, if appropriate. + */ + if (varlist_ind >= context->non_reps) { + + /* Store a pointer to the first repeater value. */ + if (context->repbase == NULL) + context->repbase = bt_entry; + + context->repeaters ++; + + } else { + bt_entry->norepeat = 1; + DBPRT(1,(DBOUT "HERE 1\n")); + DBPRT(1,(DBOUT "(nonrepeater) ")); + } + + /* Initialize the array in which to hold the Varbinds to be + ** returned for the OID or subtree. + */ + if ((bt_entry->vars = (AV*) newAV()) == NULL) { + sv_setpv(*err_str_svp, "newAV() failed: "); + sv_catpv(*err_str_svp, strerror(errno)); + sv_setiv(*err_num_svp, SNMPERR_MALLOC); + goto err; + } + DBPRT(1,(DBOUT "%s\n", __snprint_oid(oid_arr, oid_arr_len))); + context->nreq_oids ++; + } + + /* Keep track of the number of outstanding requests. This lets us + ** finish processing early if we're done with all requests. + */ + context->req_remain = context->nreq_oids; + DBPRT(1,(DBOUT "Total %d variable requests added\n", context->nreq_oids)); + + /* If no good variable requests were found, return an error. */ + if (context->nreq_oids == 0) { + sv_setpv(*err_str_svp, "No variables found in varlist"); + sv_setiv(*err_num_svp, SNMPERR_NO_VARS); + goto err; + } + + /* Note that this is a good context. This allows later callbacks + ** to ignore re-sent PDU's that correspond to completed (and hence + ** destroyed) bulkwalk contexts. + */ + _context_add(context); + + /* For asynchronous bulkwalk requests, all we have to do at this + ** point is enqueue the asynchronous GETBULK request with our + ** bulkwalk-specific callback and return. Remember that the + ** bulkwalk_send_pdu() function returns the reqid cast to an + ** snmp_pdu pointer, or NULL on failure. Return undef if the + ** initial send fails; bulkwalk_send_pdu() takes care of setting + ** the various error values. + ** + ** From here, the callbacks do all the work, including sending + ** requests for variables and handling responses. The caller's + ** callback will be invoked as soon as the walk completes. + */ + if (SvTRUE(perl_callback)) { + DBPRT(1,(DBOUT "Starting asynchronous bulkwalk...\n")); + + pdu = _bulkwalk_send_pdu(context); + + if (pdu == NULL) { + DBPRT(1,(DBOUT "Initial asynchronous send failed...\n")); + XSRETURN_UNDEF; + } + + /* Sent okay... Return the request ID in 'pdu' as an SvIV. */ + DBPRT(1,(DBOUT "Okay, request id is %ld\n", (long)(intptr_t)pdu)); +/* XSRETURN_IV((intptr_t)pdu); */ + XPUSHs(sv_2mortal(newSViv((IV)pdu))); + XSRETURN(1); + } + + /* For synchronous bulkwalk, we perform the basic send/receive + ** iteration right here. Once the walk has been completed, the + ** bulkwalk_finish() function will push the return values onto + ** the Perl call stack, and we return. + */ + DBPRT(1,(DBOUT "Starting synchronous bulkwalk...\n")); + + while (!(okay = _bulkwalk_done(context))) { + + /* Send a request for the next batch of variables. */ + DBPRT(1, (DBOUT "Building %s GETBULK bulkwalk PDU (%d)...\n", + context->pkts_exch ? "next" : "first", + context->pkts_exch)); + pdu = _bulkwalk_send_pdu(context); + + /* If the request failed, consider the walk done. */ + if (pdu == NULL) { + DBPRT(1,(DBOUT "bulkwalk_send_pdu() failed!\n")); + break; + } + + /* Handle the variables in this response packet. Break out + ** of the loop if an error occurs or no variables are found + ** in the response. + */ + if ((i = _bulkwalk_recv_pdu(context, pdu)) <= 0) { + DBPRT(2,(DBOUT "bulkwalk_recv_pdu() returned %d (error/empty)\n", i)); + goto err; + } + + /* Free the returned pdu. Don't bother to do this for the async + ** case, since the SNMP callback mechanism itself does the free + ** for us. + */ + snmp_free_pdu(pdu); + + /* And loop. The call to bulkwalk_done() sets the ignore flags + ** for any completed request subtrees. Next time around, they + ** won't be added to the request sent to the agent. + */ + continue; + } + + DBPRT(1, (DBOUT "Bulkwalk done... calling bulkwalk_finish(%s)...\n", + okay ? "okay" : "error")); + npushed = _bulkwalk_finish(context, okay); + + DBPRT(2,(DBOUT "Returning %d values on the stack.\n", npushed)); + XSRETURN(npushed); + + /* Handle error cases and clean up after ourselves. */ + err: + if (context) { + if (context->req_oids && context->nreq_oids) { + bt_entry = context->req_oids; + for (i = 0; i < context->nreq_oids; i++, bt_entry++) + av_clear(bt_entry->vars); + } + if (context->req_oids) + Safefree(context->req_oids); + Safefree(context); + } + if (pdu) + snmp_free_pdu(pdu); + + XSRETURN_UNDEF; + } + + +void +snmp_trapV1(sess_ref,enterprise,agent,generic,specific,uptime,varlist_ref) + SV * sess_ref + char * enterprise + char * agent + int generic + int specific + long uptime + SV * varlist_ref + PPCODE: + { + AV *varlist; + SV **varbind_ref; + SV **varbind_val_f; + AV *varbind; + I32 varlist_len; + I32 varlist_ind; + SnmpSession *ss; + netsnmp_pdu *pdu = NULL; + struct tree *tp; + oid *oid_arr; + size_t oid_arr_len = MAX_OID_LEN; + SV **sess_ptr_sv; + SV **err_str_svp; + SV **err_num_svp; + SV **err_ind_svp; + int type; + int res; + int verbose = SvIV(perl_get_sv("SNMP::verbose", 0x01 | 0x04)); + int use_enums = SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseEnums",8,1)); + struct enum_list *ep; + int best_guess; + + New (0, oid_arr, MAX_OID_LEN, oid); + + if (oid_arr && SvROK(sess_ref)) { + + sess_ptr_sv = hv_fetch((HV*)SvRV(sess_ref), "SessPtr", 7, 1); + ss = (SnmpSession *)SvIV((SV*)SvRV(*sess_ptr_sv)); + err_str_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorStr", 8, 1); + err_num_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorNum", 8, 1); + err_ind_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorInd", 8, 1); + sv_setpv(*err_str_svp, ""); + sv_setiv(*err_num_svp, 0); + sv_setiv(*err_ind_svp, 0); + best_guess = SvIV(*hv_fetch((HV*)SvRV(sess_ref),"BestGuess",9,1)); + + pdu = snmp_pdu_create(SNMP_MSG_TRAP); + + if (SvROK(varlist_ref)) { + varlist = (AV*) SvRV(varlist_ref); + varlist_len = av_len(varlist); + for(varlist_ind = 0; varlist_ind <= varlist_len; varlist_ind++) { + varbind_ref = av_fetch(varlist, varlist_ind, 0); + if (SvROK(*varbind_ref)) { + varbind = (AV*) SvRV(*varbind_ref); + + tp=__tag2oid(__av_elem_pv(varbind, VARBIND_TAG_F, NULL), + __av_elem_pv(varbind, VARBIND_IID_F, NULL), + oid_arr, &oid_arr_len, &type, best_guess); + + if (oid_arr_len == 0) { + if (verbose) + warn("error:trap: unable to determine oid for object"); + goto err; + } + + if (type == TYPE_UNKNOWN) { + type = __translate_appl_type( + __av_elem_pv(varbind, VARBIND_TYPE_F, NULL)); + if (type == TYPE_UNKNOWN) { + if (verbose) + warn("error:trap: no type found for object"); + goto err; + } + } + + varbind_val_f = av_fetch(varbind, VARBIND_VAL_F, 0); + + if (type==TYPE_INTEGER && use_enums && tp && tp->enums) { + for(ep = tp->enums; ep; ep = ep->next) { + if (varbind_val_f && SvOK(*varbind_val_f) && + !strcmp(ep->label, SvPV(*varbind_val_f,na))) { + sv_setiv(*varbind_val_f, ep->value); + break; + } + } + } + + res = __add_var_val_str(pdu, oid_arr, oid_arr_len, + (varbind_val_f && SvOK(*varbind_val_f) ? + SvPV(*varbind_val_f,na):NULL), + (varbind_val_f && SvPOK(*varbind_val_f) ? + SvCUR(*varbind_val_f):0), + type); + + if(res == FAILURE) { + if(verbose) warn("error:trap: adding varbind"); + goto err; + } + + } /* if var_ref is ok */ + } /* for all the vars */ + } + + pdu->enterprise = (oid *)netsnmp_malloc(MAX_OID_LEN * sizeof(oid)); + tp = __tag2oid(enterprise,NULL, pdu->enterprise, + &pdu->enterprise_length, NULL, best_guess); + if (pdu->enterprise_length == 0) { + if (verbose) warn("error:trap:invalid enterprise id: %s", enterprise); + goto err; + } + /* If agent is given then set the v1-TRAP specific + agent-address field to that. Otherwise set it to + our address. */ + if (agent && strlen(agent)) { + if (0 > netsnmp_gethostbyname_v4(agent, + (in_addr_t *)pdu->agent_addr)){ + if (verbose) + warn("error:trap:invalid agent address: %s", agent); + goto err; + } + } else { + *((in_addr_t *)pdu->agent_addr) = get_myaddr(); + } + pdu->trap_type = generic; + pdu->specific_type = specific; + pdu->time = uptime; + + if(api_mode == SNMP_API_SINGLE) + { + if(snmp_sess_send(ss,pdu) == 0) + snmp_free_pdu(pdu); + } else { + if (snmp_send(ss, pdu) == 0) + snmp_free_pdu(pdu); + } + XPUSHs(sv_2mortal(newSVpv(ZERO_BUT_TRUE,0))); + } else { +err: + XPUSHs(&sv_undef); /* no mem or bad args */ + if (pdu) snmp_free_pdu(pdu); + } + Safefree(oid_arr); + } + + +void +snmp_trapV2(sess_ref,uptime,trap_oid,varlist_ref) + SV * sess_ref + char * uptime + char * trap_oid + SV * varlist_ref + PPCODE: + { + AV *varlist; + SV **varbind_ref; + SV **varbind_val_f; + AV *varbind; + I32 varlist_len; + I32 varlist_ind; + SnmpSession *ss; + netsnmp_pdu *pdu = NULL; + struct tree *tp; + oid *oid_arr; + size_t oid_arr_len = MAX_OID_LEN; + SV **sess_ptr_sv; + SV **err_str_svp; + SV **err_num_svp; + SV **err_ind_svp; + int type; + int res; + int verbose = SvIV(perl_get_sv("SNMP::verbose", 0x01 | 0x04)); + int use_enums = SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseEnums",8,1)); + struct enum_list *ep; + int best_guess; + + New (0, oid_arr, MAX_OID_LEN, oid); + + if (oid_arr && SvROK(sess_ref)) { + + sess_ptr_sv = hv_fetch((HV*)SvRV(sess_ref), "SessPtr", 7, 1); + ss = (SnmpSession *)SvIV((SV*)SvRV(*sess_ptr_sv)); + err_str_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorStr", 8, 1); + err_num_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorNum", 8, 1); + err_ind_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorInd", 8, 1); + sv_setpv(*err_str_svp, ""); + sv_setiv(*err_num_svp, 0); + sv_setiv(*err_ind_svp, 0); + best_guess = SvIV(*hv_fetch((HV*)SvRV(sess_ref),"BestGuess",9,1)); + + pdu = snmp_pdu_create(SNMP_MSG_TRAP2); + + if (SvROK(varlist_ref)) { + varlist = (AV*) SvRV(varlist_ref); + varlist_len = av_len(varlist); + } else { + varlist = NULL; + varlist_len = -1; + } + /************************************************/ + res = __add_var_val_str(pdu, sysUpTime, SYS_UPTIME_OID_LEN, + uptime, strlen(uptime), TYPE_TIMETICKS); + + if(res == FAILURE) { + if(verbose) warn("error:trap v2: adding sysUpTime varbind"); + goto err; + } + + res = __add_var_val_str(pdu, snmpTrapOID, SNMP_TRAP_OID_LEN, + trap_oid ,strlen(trap_oid) ,TYPE_OBJID); + + if(res == FAILURE) { + if(verbose) warn("error:trap v2: adding snmpTrapOID varbind"); + goto err; + } + + + /******************************************************/ + + for(varlist_ind = 0; varlist_ind <= varlist_len; varlist_ind++) { + varbind_ref = av_fetch(varlist, varlist_ind, 0); + if (SvROK(*varbind_ref)) { + varbind = (AV*) SvRV(*varbind_ref); + + tp=__tag2oid(__av_elem_pv(varbind, VARBIND_TAG_F,NULL), + __av_elem_pv(varbind, VARBIND_IID_F,NULL), + oid_arr, &oid_arr_len, &type, best_guess); + + if (oid_arr_len == 0) { + if (verbose) + warn("error:trap v2: unable to determine oid for object"); + goto err; + } + + if (type == TYPE_UNKNOWN) { + type = __translate_appl_type( + __av_elem_pv(varbind, VARBIND_TYPE_F, NULL)); + if (type == TYPE_UNKNOWN) { + if (verbose) + warn("error:trap v2: no type found for object"); + goto err; + } + } + + varbind_val_f = av_fetch(varbind, VARBIND_VAL_F, 0); + + if (type==TYPE_INTEGER && use_enums && tp && tp->enums) { + for(ep = tp->enums; ep; ep = ep->next) { + if (varbind_val_f && SvOK(*varbind_val_f) && + !strcmp(ep->label, SvPV(*varbind_val_f,na))) { + sv_setiv(*varbind_val_f, ep->value); + break; + } + } + } + + res = __add_var_val_str(pdu, oid_arr, oid_arr_len, + (varbind_val_f && SvOK(*varbind_val_f) ? + SvPV(*varbind_val_f,na):NULL), + (varbind_val_f && SvPOK(*varbind_val_f) ? + SvCUR(*varbind_val_f):0), + type); + + if(res == FAILURE) { + if(verbose) warn("error:trap v2: adding varbind"); + goto err; + } + + } /* if var_ref is ok */ + } /* for all the vars */ + + if(api_mode == SNMP_API_SINGLE) + { + if (snmp_sess_send(ss, pdu) == 0) + snmp_free_pdu(pdu); + } else { + if (snmp_send(ss, pdu) == 0) + snmp_free_pdu(pdu); + } + + XPUSHs(sv_2mortal(newSVpv(ZERO_BUT_TRUE,0))); + } else { +err: + XPUSHs(&sv_undef); /* no mem or bad args */ + if (pdu) snmp_free_pdu(pdu); + } + Safefree(oid_arr); + } + + + +void +snmp_inform(sess_ref,uptime,trap_oid,varlist_ref,perl_callback) + SV * sess_ref + char * uptime + char * trap_oid + SV * varlist_ref + SV * perl_callback + PPCODE: + { + AV *varlist; + SV **varbind_ref; + SV **varbind_val_f; + AV *varbind; + I32 varlist_len; + I32 varlist_ind; + SnmpSession *ss; + netsnmp_pdu *pdu = NULL; + netsnmp_pdu *response; + struct tree *tp; + oid *oid_arr; + size_t oid_arr_len = MAX_OID_LEN; + snmp_xs_cb_data *xs_cb_data; + SV **sess_ptr_sv; + SV **err_str_svp; + SV **err_num_svp; + SV **err_ind_svp; + int status = 0; + int type; + int res; + int verbose = SvIV(perl_get_sv("SNMP::verbose", 0x01 | 0x04)); + int use_enums = SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseEnums",8,1)); + struct enum_list *ep; + int best_guess; + + New (0, oid_arr, MAX_OID_LEN, oid); + + if (oid_arr && SvROK(sess_ref) && SvROK(varlist_ref)) { + + sess_ptr_sv = hv_fetch((HV*)SvRV(sess_ref), "SessPtr", 7, 1); + ss = (SnmpSession *)SvIV((SV*)SvRV(*sess_ptr_sv)); + err_str_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorStr", 8, 1); + err_num_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorNum", 8, 1); + err_ind_svp = hv_fetch((HV*)SvRV(sess_ref), "ErrorInd", 8, 1); + sv_setpv(*err_str_svp, ""); + sv_setiv(*err_num_svp, 0); + sv_setiv(*err_ind_svp, 0); + best_guess = SvIV(*hv_fetch((HV*)SvRV(sess_ref),"BestGuess",9,1)); + + pdu = snmp_pdu_create(SNMP_MSG_INFORM); + + varlist = (AV*) SvRV(varlist_ref); + varlist_len = av_len(varlist); + /************************************************/ + res = __add_var_val_str(pdu, sysUpTime, SYS_UPTIME_OID_LEN, + uptime, strlen(uptime), TYPE_TIMETICKS); + + if(res == FAILURE) { + if(verbose) warn("error:inform: adding sysUpTime varbind"); + goto err; + } + + res = __add_var_val_str(pdu, snmpTrapOID, SNMP_TRAP_OID_LEN, + trap_oid ,strlen(trap_oid) ,TYPE_OBJID); + + if(res == FAILURE) { + if(verbose) warn("error:inform: adding snmpTrapOID varbind"); + goto err; + } + + + /******************************************************/ + + for(varlist_ind = 0; varlist_ind <= varlist_len; varlist_ind++) { + varbind_ref = av_fetch(varlist, varlist_ind, 0); + if (SvROK(*varbind_ref)) { + varbind = (AV*) SvRV(*varbind_ref); + + tp=__tag2oid(__av_elem_pv(varbind, VARBIND_TAG_F,NULL), + __av_elem_pv(varbind, VARBIND_IID_F,NULL), + oid_arr, &oid_arr_len, &type, best_guess); + + if (oid_arr_len == 0) { + if (verbose) + warn("error:inform: unable to determine oid for object"); + goto err; + } + + if (type == TYPE_UNKNOWN) { + type = __translate_appl_type( + __av_elem_pv(varbind, VARBIND_TYPE_F, NULL)); + if (type == TYPE_UNKNOWN) { + if (verbose) + warn("error:inform: no type found for object"); + goto err; + } + } + + varbind_val_f = av_fetch(varbind, VARBIND_VAL_F, 0); + + if (type==TYPE_INTEGER && use_enums && tp && tp->enums) { + for(ep = tp->enums; ep; ep = ep->next) { + if (varbind_val_f && SvOK(*varbind_val_f) && + !strcmp(ep->label, SvPV(*varbind_val_f,na))) { + sv_setiv(*varbind_val_f, ep->value); + break; + } + } + } + + res = __add_var_val_str(pdu, oid_arr, oid_arr_len, + (varbind_val_f && SvOK(*varbind_val_f) ? + SvPV(*varbind_val_f,na):NULL), + (varbind_val_f && SvPOK(*varbind_val_f) ? + SvCUR(*varbind_val_f):0), + type); + + if(res == FAILURE) { + if(verbose) warn("error:inform: adding varbind"); + goto err; + } + + } /* if var_ref is ok */ + } /* for all the vars */ + + + if (SvTRUE(perl_callback)) { + xs_cb_data = + (snmp_xs_cb_data*)malloc(sizeof(snmp_xs_cb_data)); + xs_cb_data->perl_cb = newSVsv(perl_callback); + xs_cb_data->sess_ref = newRV_inc(SvRV(sess_ref)); + + if(api_mode == SNMP_API_SINGLE) + { + status = snmp_sess_async_send(ss, pdu, __snmp_xs_cb, + (void*)xs_cb_data); + } else { + status = snmp_async_send(ss, pdu, __snmp_xs_cb, + (void*)xs_cb_data); + } + if (status != 0) { + XPUSHs(sv_2mortal(newSViv(status))); /* push the reqid?? */ + } else { + snmp_free_pdu(pdu); + snmp_return_err(ss, *err_num_svp, *err_ind_svp, *err_str_svp); + XPUSHs(&sv_undef); + } + goto done; + } + + status = __send_sync_pdu(ss, pdu, &response, + NO_RETRY_NOSUCH, + *err_str_svp, *err_num_svp, + *err_ind_svp); + + if (response) snmp_free_pdu(response); + + if (status) { + XPUSHs(&sv_undef); + } else { + XPUSHs(sv_2mortal(newSVpv(ZERO_BUT_TRUE,0))); + } + } else { +err: + XPUSHs(&sv_undef); /* no mem or bad args */ + if (pdu) snmp_free_pdu(pdu); + } +done: + Safefree(oid_arr); + } + + + +char * +snmp_get_type(tag, best_guess) + char * tag + int best_guess + CODE: + { + struct tree *tp = NULL; + static char type_str[MAX_TYPE_NAME_LEN]; + char *ret = NULL; + + if (tag && *tag) tp = __tag2oid(tag, NULL, NULL, NULL, NULL, best_guess); + if (tp) __get_type_str(tp->type, ret = type_str); + RETVAL = ret; + } + OUTPUT: + RETVAL + + +void +snmp_dump_packet(flag) + int flag + CODE: + { + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, + NETSNMP_DS_LIB_DUMP_PACKET, flag); + } + + +char * +snmp_map_enum(tag, val, iflag, best_guess) + char * tag + char * val + int iflag + int best_guess + CODE: + { + struct tree *tp = NULL; + struct enum_list *ep; + char str_buf[STR_BUF_SIZE]; + int ival; + + RETVAL = NULL; + + if (tag && *tag) tp = __tag2oid(tag, NULL, NULL, NULL, NULL, best_guess); + + if (tp) { + if (iflag) { + ival = atoi(val); + for(ep = tp->enums; ep; ep = ep->next) { + if (ep->value == ival) { + RETVAL = ep->label; + break; + } + } + } else { + for(ep = tp->enums; ep; ep = ep->next) { + if (strEQ(ep->label, val)) { + sprintf(str_buf,"%d", ep->value); + RETVAL = str_buf; + break; + } + } + } + } + } + OUTPUT: + RETVAL + +#define SNMP_XLATE_MODE_OID2TAG 1 +#define SNMP_XLATE_MODE_TAG2OID 0 + +char * +snmp_translate_obj(var,mode,use_long,auto_init,best_guess,include_module_name) + char * var + int mode + int use_long + int auto_init + int best_guess + int include_module_name + CODE: + { + char str_buf[STR_BUF_SIZE]; + char str_buf_temp[STR_BUF_SIZE]; + oid oid_arr[MAX_OID_LEN]; + size_t oid_arr_len = MAX_OID_LEN; + char * label; + char * iid; + int status = FAILURE; + int verbose = SvIV(perl_get_sv("SNMP::verbose", 0x01 | 0x04)); + struct tree *module_tree = NULL; + char modbuf[256]; + int old_format; /* Current NETSNMP_DS_LIB_OID_OUTPUT_FORMAT */ + + str_buf[0] = '\0'; + str_buf_temp[0] = '\0'; + + if (auto_init) + netsnmp_init_mib(); /* vestigial */ + + /* Save old output format and set to FULL so long_names works */ + old_format = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT); + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, NETSNMP_OID_OUTPUT_FULL); + + switch (mode) { + case SNMP_XLATE_MODE_TAG2OID: + if (!__tag2oid(var, NULL, oid_arr, &oid_arr_len, NULL, best_guess)) { + if (verbose) warn("error:snmp_translate_obj:Unknown OID %s\n",var); + } else { + status = __sprint_num_objid(str_buf, oid_arr, oid_arr_len); + } + break; + case SNMP_XLATE_MODE_OID2TAG: + oid_arr_len = 0; + __concat_oid_str(oid_arr, &oid_arr_len, var); + snprint_objid(str_buf_temp, sizeof(str_buf_temp), oid_arr, oid_arr_len); + + if (!use_long) { + label = NULL; iid = NULL; + if (((status=__get_label_iid(str_buf_temp, + &label, &iid, NO_FLAGS)) == SUCCESS) + && label) { + strlcpy(str_buf_temp, label, sizeof(str_buf_temp)); + if (iid && *iid) { + strlcat(str_buf_temp, ".", sizeof(str_buf_temp)); + strlcat(str_buf_temp, iid, sizeof(str_buf_temp)); + } + } + } + + /* Prepend modulename:: if enabled */ + if (include_module_name) { + module_tree = get_tree (oid_arr, oid_arr_len, get_tree_head()); + if (module_tree) { + if (strcmp(module_name(module_tree->modid, modbuf), "#-1") ) { + strcat(str_buf, modbuf); + strcat(str_buf, "::"); + } + else { + strcat(str_buf, "UNKNOWN::"); + } + } + } + strcat(str_buf, str_buf_temp); + + break; + default: + if (verbose) warn("snmp_translate_obj:unknown translation mode: %d\n", mode); + } + if (*str_buf) { + RETVAL = (char*)str_buf; + } else { + RETVAL = (char*)NULL; + } + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, old_format); + } + OUTPUT: + RETVAL + +void +snmp_set_replace_newer(val) + int val + CODE: + { + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, + NETSNMP_DS_LIB_MIB_REPLACE, val); + } + +void +snmp_set_save_descriptions(val) + int val + CODE: + { + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, + NETSNMP_DS_LIB_SAVE_MIB_DESCRS, val); + } + +void +snmp_set_debugging(val) + int val + CODE: + { + snmp_set_do_debugging(val); + } + +void +snmp_register_debug_tokens(tokens) + char *tokens + CODE: + { + debug_register_tokens(tokens); + snmp_set_do_debugging(1); + } + +void +snmp_debug_internals(val) + int val + CODE: + { +#ifdef DEBUGGING + _debug_level = val; +#else + val++; +#endif /* DEBUGGING */ + } + + +void +snmp_mib_toggle_options(options) + char *options + CODE: + { + snmp_mib_toggle_options(options); + } + +void +snmp_sock_cleanup() + CODE: + { + SOCK_CLEANUP; + } + +void +snmp_mainloop_finish() + CODE: + { + mainloop_finish = 1; + } + + +#----------------------------------------------------------------------------- +# Note: ss=(SnmpSession*)NULL is so &SNMP::MainLoop() can still be called +# without a sess handler argument, this way I'm not breaking anyone's old code +# +# see MainLoop() in SNMP.pm for more details +#----------------------------------------------------------------------------- +void +snmp_main_loop(timeout_sec,timeout_usec,perl_callback,ss=(SnmpSession*)NULL) + int timeout_sec + int timeout_usec + SV * perl_callback + SnmpSession *ss + CODE: + { + int numfds, fd_count; + fd_set fdset; + struct timeval time_val, *tvp; + struct timeval last_time, *ltvp; + struct timeval ctimeout, *ctvp; + struct timeval interval, *itvp; + int block; + SV *cb; + + mainloop_finish = 0; + + itvp = &interval; + itvp->tv_sec = timeout_sec; + itvp->tv_usec = timeout_usec; + ctvp = &ctimeout; + ctvp->tv_sec = -1; + ctvp->tv_usec = 0; + ltvp = &last_time; + gettimeofday(ltvp,(struct timezone*)0); + timersub(ltvp,itvp,ltvp); + while (1) { + numfds = 0; + FD_ZERO(&fdset); + block = 1; + tvp = &time_val; + timerclear(tvp); + if(api_mode == SNMP_API_SINGLE) + { + snmp_sess_select_info(ss,&numfds, &fdset, tvp, &block); + } else { + snmp_select_info(&numfds, &fdset, tvp, &block); + } + __recalc_timeout(tvp,ctvp,ltvp,itvp,&block); + # printf("pre-select: numfds = %ld, block = %ld\n", numfds, block); + if (block == 1) tvp = NULL; /* block without timeout */ + fd_count = select(numfds, &fdset, 0, 0, tvp); + #printf("post-select: fd_count = %ld,block = %ld\n",fd_count,block); + if (fd_count > 0) { + ENTER; + SAVETMPS; + if(api_mode == SNMP_API_SINGLE) + { + snmp_sess_read(ss, &fdset); + } else { + snmp_read(&fdset); + } + FREETMPS; + LEAVE; + + } else switch(fd_count) { + case 0: + SPAGAIN; + ENTER; + SAVETMPS; + if(api_mode == SNMP_API_SINGLE) + { + snmp_sess_timeout( ss ); + } else { + snmp_timeout(); + } + if (!timerisset(ctvp)) { + if (SvTRUE(perl_callback)) { + /* sv_2mortal(perl_callback); */ + cb = __push_cb_args(perl_callback, NULL); + __call_callback(cb, G_DISCARD); + ctvp->tv_sec = -1; + + } else { + FREETMPS; + LEAVE; + goto done; + } + } + FREETMPS; + LEAVE; + break; + case -1: + if (errno == EINTR) { + continue; + } else { + /* snmp_set_detail(strerror(errno)); */ + /* snmp_errno = SNMPERR_GENERR; */ + } + default:; + } + + /* A call to snmp_mainloop_finish() in the callback sets the + ** mainloop_finish flag. Exit the loop after the callback returns. + */ + if (mainloop_finish) + goto done; + + } + done: + return; + } + + +void +snmp_get_select_info() + PPCODE: + { + int numfds; + fd_set fdset; + struct timeval time_val, *tvp; + int block; + int i; + + numfds = 0; + block = 1; + tvp = &time_val; + FD_ZERO(&fdset); + snmp_select_info(&numfds, &fdset, tvp, &block); + XPUSHs(sv_2mortal(newSViv(block))); + if(block){ + XPUSHs(sv_2mortal(newSViv(0))); + XPUSHs(sv_2mortal(newSViv(0))); + } else { + XPUSHs(sv_2mortal(newSViv(tvp->tv_sec))); + XPUSHs(sv_2mortal(newSViv(tvp->tv_usec))); + } + if ( numfds ) { + for(i=0; i<numfds ; i++) { + if(FD_ISSET(i, &fdset)){ + XPUSHs(sv_2mortal(newSViv(i))); + } + } + } else { + XPUSHs(&sv_undef); /* no mem or bad args */ + } + } + +void +snmp_read_on_fd(fd) + int fd + CODE: + { + fd_set fdset; + + FD_ZERO(&fdset); + FD_SET(fd, &fdset); + + snmp_read(&fdset); + } + +void +snmp_check_timeout() + CODE: + { + snmp_timeout(); + } + +MODULE = SNMP PACKAGE = SNMP::MIB::NODE PREFIX = snmp_mib_node_ + +SV * +snmp_mib_node_TIEHASH(cl,key,tp=0) + char * cl + char * key + IV tp + CODE: + { + __libraries_init("perl"); + if (!tp) tp = (IV)__tag2oid(key, NULL, NULL, NULL, NULL,0); + if (tp) { + RETVAL = sv_setref_iv(newSV(0), cl, tp); + } else { + RETVAL = &sv_undef; + } + } + OUTPUT: + RETVAL + + +SV * +snmp_mib_node_FETCH(tp_ref, key) + SV * tp_ref + char * key + CODE: + { + char c = *key; + char str_buf[STR_BUF_SIZE]; + SnmpMibNode *tp = NULL, *tptmp = NULL; + struct index_list *ip; + struct enum_list *ep; + struct range_list *rp; + struct varbind_list *vp; + struct module *mp; + SV *child_list_aref, *next_node_href, *mib_tied_href = NULL; + SV **nn_hrefp; + HV *mib_hv, *enum_hv, *range_hv; + AV *index_av, *varbind_av, *ranges_av; + MAGIC *mg = NULL; + SV *ret = NULL; + + if (SvROK(tp_ref)) tp = (SnmpMibNode*)SvIV((SV*)SvRV(tp_ref)); + + ret = newSV(0); + if (tp) + switch (c) { + case 'a': /* access */ + if (strncmp("access", key, strlen(key)) == 0) { + switch (tp->access) { + case MIB_ACCESS_READONLY: + sv_setpv(ret,"ReadOnly"); + break; + case MIB_ACCESS_READWRITE: + sv_setpv(ret,"ReadWrite"); + break; + case MIB_ACCESS_WRITEONLY: + sv_setpv(ret,"WriteOnly"); + break; + case MIB_ACCESS_NOACCESS: + sv_setpv(ret,"NoAccess"); + break; + case MIB_ACCESS_NOTIFY: + sv_setpv(ret,"Notify"); + break; + case MIB_ACCESS_CREATE: + sv_setpv(ret,"Create"); + break; + default: + break; + } + } else if (strncmp("augments", key, strlen(key)) == 0) { + sv_setpv(ret,tp->augments); + } + break; + case 'c': /* children */ + if (strncmp("children", key, strlen(key))) break; + child_list_aref = newRV((SV*)newAV()); + for (tp = tp->child_list; tp; tp = tp->next_peer) { + mib_hv = perl_get_hv("SNMP::MIB", FALSE); + if (SvMAGICAL(mib_hv)) mg = mg_find((SV*)mib_hv, 'P'); + if (mg) mib_tied_href = (SV*)mg->mg_obj; + next_node_href = newRV((SV*)newHV()); + __tp_sprint_num_objid(str_buf, tp); + nn_hrefp = hv_fetch((HV*)SvRV(mib_tied_href), + str_buf, strlen(str_buf), 1); + if (!SvROK(*nn_hrefp)) { + sv_setsv(*nn_hrefp, next_node_href); + ENTER ; + SAVETMPS ; + PUSHMARK(sp) ; + XPUSHs(SvRV(*nn_hrefp)); + XPUSHs(sv_2mortal(newSVpv("SNMP::MIB::NODE",0))); + XPUSHs(sv_2mortal(newSVpv(str_buf,0))); + XPUSHs(sv_2mortal(newSViv((IV)tp))); + PUTBACK ; + perl_call_pv("SNMP::_tie",G_VOID); + /* pp_tie(ARGS); */ + SPAGAIN ; + FREETMPS ; + LEAVE ; + } /* if SvROK */ + av_push((AV*)SvRV(child_list_aref), *nn_hrefp); + } /* for child_list */ + sv_setsv(ret, child_list_aref); + break; + case 'v': + if (strncmp("varbinds", key, strlen(key))) break; + varbind_av = newAV(); + for (vp = tp->varbinds; vp; vp = vp->next) { + av_push(varbind_av, newSVpv((vp->vblabel),strlen(vp->vblabel))); + } + sv_setsv(ret, newRV((SV*)varbind_av)); + break; + case 'd': /* description */ + if (strncmp("description", key, strlen(key))) { + if(!(strncmp("defaultValue",key,strlen(key)))) { + /* We're looking at defaultValue */ + sv_setpv(ret, tp->defaultValue); + break; + } /* end if */ + } /* end if */ + /* we must be looking at description */ + sv_setpv(ret,tp->description); + break; + case 'i': /* indexes, implied */ + if (tp->augments) { + clear_tree_flags(get_tree_head()); + tptmp = find_best_tree_node(tp->augments, get_tree_head(), NULL); + if (tptmp == NULL) { + tptmp = tp; + } + } else { + tptmp = tp; + } + if (strcmp("implied", key) == 0) { + /* only the last index can be implied */ + int isimplied = 0; + if (tptmp && tptmp->indexes) { + for(ip=tptmp->indexes; ip->next; ip = ip->next) { + } + isimplied = ip->isimplied; + } + sv_setiv(ret, isimplied); + break; + } + if (strncmp("indexes", key, strlen(key))) break; + index_av = newAV(); + if (tptmp) + for(ip=tptmp->indexes; ip != NULL; ip = ip->next) { + av_push(index_av,newSVpv((ip->ilabel),strlen(ip->ilabel))); + } + sv_setsv(ret, newRV((SV*)index_av)); + break; + case 'l': /* label */ + if (strncmp("label", key, strlen(key))) break; + sv_setpv(ret,tp->label); + break; + case 'm': /* moduleID */ + if (strncmp("moduleID", key, strlen(key))) break; + mp = find_module(tp->modid); + if (mp) sv_setpv(ret, mp->name); + break; + case 'n': /* nextNode */ + if (strncmp("nextNode", key, strlen(key))) break; + tp = __get_next_mib_node(tp); + if (tp == NULL) { + sv_setsv(ret, &sv_undef); + break; + } + mib_hv = perl_get_hv("SNMP::MIB", FALSE); + if (SvMAGICAL(mib_hv)) mg = mg_find((SV*)mib_hv, 'P'); + if (mg) mib_tied_href = (SV*)mg->mg_obj; + __tp_sprint_num_objid(str_buf, tp); + + nn_hrefp = hv_fetch((HV*)SvRV(mib_tied_href), + str_buf, strlen(str_buf), 1); + /* if (!SvROK(*nn_hrefp)) { */ /* bug in ucd - 2 .0.0 nodes */ + next_node_href = newRV((SV*)newHV()); + sv_setsv(*nn_hrefp, next_node_href); + ENTER ; + SAVETMPS ; + PUSHMARK(sp) ; + XPUSHs(SvRV(*nn_hrefp)); + XPUSHs(sv_2mortal(newSVpv("SNMP::MIB::NODE",0))); + XPUSHs(sv_2mortal(newSVpv(str_buf,0))); + XPUSHs(sv_2mortal(newSViv((IV)tp))); + PUTBACK ; + perl_call_pv("SNMP::_tie",G_VOID); + /* pp_tie(ARGS); */ + SPAGAIN ; + FREETMPS ; + LEAVE ; + /* } */ + sv_setsv(ret, *nn_hrefp); + break; + case 'o': /* objectID */ + if (strncmp("objectID", key, strlen(key))) break; + __tp_sprint_num_objid(str_buf, tp); + sv_setpv(ret,str_buf); + break; + case 'p': /* parent */ + if (strncmp("parent", key, strlen(key))) break; + tp = tp->parent; + if (tp == NULL) { + sv_setsv(ret, &sv_undef); + break; + } + mib_hv = perl_get_hv("SNMP::MIB", FALSE); + if (SvMAGICAL(mib_hv)) mg = mg_find((SV*)mib_hv, 'P'); + if (mg) mib_tied_href = (SV*)mg->mg_obj; + next_node_href = newRV((SV*)newHV()); + __tp_sprint_num_objid(str_buf, tp); + nn_hrefp = hv_fetch((HV*)SvRV(mib_tied_href), + str_buf, strlen(str_buf), 1); + if (!SvROK(*nn_hrefp)) { + sv_setsv(*nn_hrefp, next_node_href); + ENTER ; + SAVETMPS ; + PUSHMARK(sp) ; + XPUSHs(SvRV(*nn_hrefp)); + XPUSHs(sv_2mortal(newSVpv("SNMP::MIB::NODE",0))); + XPUSHs(sv_2mortal(newSVpv(str_buf,0))); + XPUSHs(sv_2mortal(newSViv((IV)tp))); + PUTBACK ; + perl_call_pv("SNMP::_tie",G_VOID); + /* pp_tie(ARGS); */ + SPAGAIN ; + FREETMPS ; + LEAVE ; + } + sv_setsv(ret, *nn_hrefp); + break; + case 'r': /* ranges */ + if (strncmp("reference", key, strlen(key)) == 0) { + sv_setpv(ret,tp->reference); + break; + } + if (strncmp("ranges", key, strlen(key))) break; + ranges_av = newAV(); + for(rp=tp->ranges; rp ; rp = rp->next) { + range_hv = newHV(); + (void)hv_store(range_hv, "low", strlen("low"), newSViv(rp->low), 0); + (void)hv_store(range_hv, "high", strlen("high"), newSViv(rp->high), 0); + av_push(ranges_av, newRV((SV*)range_hv)); + } + sv_setsv(ret, newRV((SV*)ranges_av)); + break; + case 's': /* subID */ + if (strncmp("subID", key, strlen(key))) { + if (strncmp("status", key, strlen(key))) { + if (strncmp("syntax", key, strlen(key))) break; + if (tp->tc_index >= 0) { + sv_setpv(ret, get_tc_descriptor(tp->tc_index)); + } else { + __get_type_str(tp->type, str_buf); + sv_setpv(ret, str_buf); + } + break; + } + + switch(tp->status) { + case MIB_STATUS_MANDATORY: + sv_setpv(ret,"Mandatory"); + break; + case MIB_STATUS_OPTIONAL: + sv_setpv(ret,"Optional"); + break; + case MIB_STATUS_OBSOLETE: + sv_setpv(ret,"Obsolete"); + break; + case MIB_STATUS_DEPRECATED: + sv_setpv(ret,"Deprecated"); + break; + case MIB_STATUS_CURRENT: + sv_setpv(ret,"Current"); + break; + default: + break; + } + } else { + sv_setiv(ret,(I32)tp->subid); + } + break; + case 't': /* type */ + if (strncmp("type", key, strlen(key))) { + if (strncmp("textualConvention", key, strlen(key))) break; + sv_setpv(ret, get_tc_descriptor(tp->tc_index)); + break; + } + __get_type_str(tp->type, str_buf); + sv_setpv(ret, str_buf); + break; + case 'T': /* textual convention description */ + if (strncmp("TCDescription", key, strlen(key))) break; + sv_setpv(ret, get_tc_description(tp->tc_index)); + break; + case 'u': /* units */ + if (strncmp("units", key, strlen(key))) break; + sv_setpv(ret,tp->units); + break; + case 'h': /* hint */ + if (strncmp("hint", key, strlen(key))) break; + sv_setpv(ret,tp->hint); + break; + case 'e': /* enums */ + if (strncmp("enums", key, strlen(key))) break; + enum_hv = newHV(); + for(ep=tp->enums; ep != NULL; ep = ep->next) { + (void)hv_store(enum_hv, ep->label, strlen(ep->label), + newSViv(ep->value), 0); + } + sv_setsv(ret, newRV((SV*)enum_hv)); + break; + default: + break; + } + RETVAL = ret; + } + OUTPUT: + RETVAL + +MODULE = SNMP PACKAGE = SnmpSessionPtr PREFIX = snmp_session_ + +void +snmp_session_DESTROY(sess_ptr) + SnmpSession *sess_ptr + CODE: + { + if(sess_ptr != NULL) + { + if(api_mode == SNMP_API_SINGLE) + { + snmp_sess_close( sess_ptr ); + } else { + snmp_close( sess_ptr ); + } + } + } + diff --git a/perl/SNMP/TODO b/perl/SNMP/TODO new file mode 100644 index 0000000..edd7c7c --- /dev/null +++ b/perl/SNMP/TODO @@ -0,0 +1,40 @@ +enhance make test + +implement v2 traps and v3 inform requests. + +solidify/enhance the V3 api + +handle TCP sessions + +See that informative strings are returned and the the error number is +useful in all cases. (need to set $! for errors where a session is not +returned (failed engineId discovery, memory alloc error, failed key +computation?)) + +PC and other unix builds - any platform issues + +building with shared libs + +ensure module does not complain with -w. + +enhance async api so that a boolean false return from a callback exits +the MainLoop + +enhance async api to store a reference to the perl SNMP::Sesion object +for 2 reasons: 1) if the initial calling session goes out of scope we +won't destroy the C-struct session until the callback is called. 2) it +allows us to set error codes in the perl SNMP::Session object + +see if new async hooks play with Event.pm + +handle dynamic changes to Session parameters, perhaps tie Error* to +snmp_session struct rather than current duplicate representation. + +make the parsed mib interface $SNMP::MIB writable + +allow unloading and reinitialization of parsed MIB + +attach to libucdagent - provide agent functionality + +look for *Not Implemeted* and implement :) + diff --git a/perl/SNMP/examples/async1.pl b/perl/SNMP/examples/async1.pl new file mode 100644 index 0000000..ffd6065 --- /dev/null +++ b/perl/SNMP/examples/async1.pl @@ -0,0 +1,17 @@ +use SNMP; + +$SNMP::auto_init_mib = 0; + +$sess = new SNMP::Session(); + +sub poller { + # VarList is undefined if TIMEOUT occured + if (!defined($_[1])) { die "request timed out[$_[0]->{ErrorStr}]\n"; } + if ($i++>100000) { die "completed 500 polls\n"; } + #print $_[1][0]->tag, " = ", $_[1][0]->val, "\n"; + $_[0]->get($_[1], [\&poller, $_[0]]); +} + +$sess->get([[".1.3.6.1.2.1.1.3.0"]], [\&poller, $sess]); + +SNMP::MainLoop(); diff --git a/perl/SNMP/examples/async2.pl b/perl/SNMP/examples/async2.pl new file mode 100644 index 0000000..f0e41b3 --- /dev/null +++ b/perl/SNMP/examples/async2.pl @@ -0,0 +1,19 @@ +use SNMP; + +$SNMP::auto_init_mib = 0; + +$sess = new SNMP::Session(); + +sub poller_handler { + if (++$i>500) { die "completed 500 polls\n"; }; + # VarList is undefined if TIMEOUT occured + if (!defined($_[1])) { + warn "request timed out[$_[0]->{ErrorStr}]\n"; + return; + } +# print "$i) ",$_[1][0]->tag, " = ", $_[1][0]->val, "\n"; +} + +# $sess->get([[".1.3.6.1.2.1.1.3.0"]], [\&poller_handler, $sess]); + +SNMP::MainLoop(.1,sub {for (1..50) {$sess->get([['.1.3.6.1.2.1.1.3.0']], [\&poller_handler, $sess]);} }); diff --git a/perl/SNMP/examples/bulkwalk.pl b/perl/SNMP/examples/bulkwalk.pl new file mode 100644 index 0000000..3ee2412 --- /dev/null +++ b/perl/SNMP/examples/bulkwalk.pl @@ -0,0 +1,121 @@ +use SNMP; + +# Hard-coded hostname and community. This is icky, but I didn't want to +# muddle the example with parsing command line arguments. Deal with it. -r +# +my $hostname='localhost'; +my $port='161'; +my $community='public'; + +$SNMP::debugging = 0; +$SNMP::dump_packet = 0; + +$sess = new SNMP::Session( 'DestHost' => $hostname, + 'Community' => $community, + 'RemotePort' => $port, + 'Timeout' => 300000, + 'Retries' => 3, + 'Version' => '2c', + 'UseLongNames' => 1, # Return full OID tags + 'UseNumeric' => 1, # Return dotted decimal OID + 'UseEnums' => 0, # Don't use enumerated vals + 'UseSprintValue' => 0); # Don't pretty-print values + +die "Cannot create session: ${SNMP::ErrorStr}\n" unless defined $sess; + +# Set up a list of two non-repeaters and some repeated variables. +# +# IMPORTANT NOTE: +# +# The 'get' performed for non-repeaters is a "GETNEXT" (the non-repeater +# requests are not fulfilled with SNMP GET's). This means that you must +# ask for the lexicographically preceeding variable for non-repeaters. +# +# For most branches (i.e. 'sysUpTime'), this "just works" -- be sure you +# don't ask for an instance, and the response will be as expected. However, +# if you want a specific variable instance (i.e. 'ifSpeed.5'), you must +# ask for the _preceeding_ variable ('ifSpeed.4' in this example). +# +# See section 4.2.3 of RFC 1905 for more details on GETBULK PDU handling. +# + +my $vars = new SNMP::VarList( ['sysUpTime'], # Nonrepeater variable + ['ifNumber'], # Nonrepeater variable + ['ifSpeed'], # Repeated variable + ['ifDescr'] ); # Repeated variable. + +# Do the bulkwalk of the two non-repeaters, and the repeaters. Ask for no +# more than 8 values per response packet. If the caller already knows how +# many instances will be returned for the repeaters, it can ask only for +# that many repeaters. +# +@resp = $sess->bulkwalk(2, 8, $vars); +die "Cannot do bulkwalk: $sess->{ErrorStr} ($sess->{ErrorNum})\n" + if $sess->{ErrorNum}; + +# Print out the returned response for each variable. +for $vbarr ( @resp ) { + # Determine which OID this request queried. This is kept in the VarList + # reference passed to bulkwalk(). + $oid = $$vars[$i++]->tag(); + + # Count the number of responses to this query. The count will be 1 for + # non-repeaters, 1 or more for repeaters. + $num = scalar @$vbarr; + print "$num responses for oid $oid: \n"; + + # Display the returned list of varbinds using the SNMP::Varbind methods. + for $v (@$vbarr) { + printf("\t%s = %s (%s)\n", $v->name, $v->val, $v->type); + } + print "\n"; +} + +# +# Now do the same bulkwalk again, but in asynchronous mode. Set up a Perl +# callback to receive the reference to the array of arrays of Varbind's for +# the return value, and pass along the $vars VarList to it. This allows us +# to print the oid tags (the callback code is almost the same as above). +# +# First, define the Perl callback to be called when the bulkwalk completes. +# The call to SNMP::finish() will cause the SNMP::MainLoop() to return once +# the callback has completed, so that processing can continue. +# +sub callback { + my ($vars, $values) = @_; + + for $vbarr ( @$values ) { + # Determine which OID this request queried. This is kept in the + # '$vars' VarList reference passed to the Perl callback by the + # asynchronous callback. + $oid = (shift @$vars)->tag(); + + # Count the number of responses to this query. The count will be 1 for + # non-repeaters, 1 or more for repeaters. + $num = scalar @$vbarr; + print "$num responses for oid $oid: \n"; + + # Display the returned list of varbinds using the SNMP::Varbind methods. + for $v (@$vbarr) { + printf("\t%s = %s (%s)\n", $v->name, $v->val, $v->type); + } + print "\n"; + } + + SNMP::finish(); +} + +# The actual bulkwalk request is done here. Note that the $vars VarList +# reference will be passed to the Perl callback when the bulkwalk completes. +# +my $reqid = $sess->bulkwalk(2, 8, $vars, [ \&callback, $vars ]); +die "Cannot do async bulkwalk: $sess->{ErrorStr} ($sess->{ErrorNum})\n" + if $sess->{ErrorNum}; + +# Now drop into the SNMP event loop and await completion of the bulkwalk. +# The call to SNMP::finish() in &callback will make the SNMP::MainLoop() +# return to the caller. +# +SNMP::MainLoop(); + +exit 0; diff --git a/perl/SNMP/examples/ipforward.pl b/perl/SNMP/examples/ipforward.pl new file mode 100644 index 0000000..de61e40 --- /dev/null +++ b/perl/SNMP/examples/ipforward.pl @@ -0,0 +1,30 @@ +use SNMP; +$SNMP::use_enums = 1; + +my $host = shift; +my $comm = shift; +$sess = new SNMP::Session(DestHost => $host, Community => $comm); + +$vars = new SNMP::VarList( ['ipRouteIfIndex'], ['ipRouteType'], + ['ipRouteProto'], ['ipRouteMask'], + ['ipRouteNextHop'], ['ipRouteAge'], + ['ipRouteMetric1']); + +format STDOUT_TOP = + Destination Next Hop Mask Proto Age Metric +--------------- --------------- -------------- ------- -------- ------ +. + +format STDOUT = +@<<<<<<<<<<<<<< @<<<<<<<<<<<<<< @<<<<<<<<<<<<< @|||||| @||||||| @||||| +$dest, $nhop, $mask, $proto, $age, $metric +. + +for (($index,$type,$proto,$mask,$nhop,$age,$metric) = $sess->getnext($vars); + $$vars[0]->tag eq 'ipRouteIfIndex' and not $sess->{ErrorStr}; + ($index,$type,$proto,$mask,$nhop,$age,$metric) = $sess->getnext($vars)) { + $dest = $$vars[0]->iid; + write; +} + +print "$sess->{ErrorStr}\n"; diff --git a/perl/SNMP/examples/mibtree.pl b/perl/SNMP/examples/mibtree.pl new file mode 100644 index 0000000..0616126 --- /dev/null +++ b/perl/SNMP/examples/mibtree.pl @@ -0,0 +1,20 @@ +use SNMP; +$SNMP::save_descriptions = 1; # must be set prior to mib initialization +SNMP::initMib(); # parses default list of Mib modules from default dirs + +# read dotted decimal oid or symbolic name to look up +# partial name will be searched and all matches returned +$val = shift || die "supply partial or complete object name or identifier\n"; + +if ($node = $SNMP::MIB{$val}) { + print "$node:$node->{label} [$node->{objectID}]\n"; + while (($k,$v) = each %$node) { + print "\t$k => $v\n"; + } +} else { + while (($k,$v) = each %SNMP::MIB) { + print "$v->{label} [$v->{obj}]\n" #accepts unique partial key(objectID) + if $k =~ /$val/ or $v->{label} =~ /$val/; + } +} + diff --git a/perl/SNMP/examples/mibwalk.pl b/perl/SNMP/examples/mibwalk.pl new file mode 100644 index 0000000..d62dc68 --- /dev/null +++ b/perl/SNMP/examples/mibwalk.pl @@ -0,0 +1,17 @@ +# snmpwalk of entire MIB +# stop on error at end of MIB + +use SNMP 1.8; +$SNMP::use_sprint_value = 1; +my $host = shift || localhost; +my $comm = shift || public; + +$sess = new SNMP::Session(DestHost => $host, Community => $comm); + +$var = new SNMP::Varbind([]); + +do { + $val = $sess->getnext($var); + print SNMP::Varbind::tag($var).".".SNMP::Varbind::iid($var)." = ". + SNMP::Varbind::val($var)."\n"; +} until ($sess->{ErrorStr}); diff --git a/perl/SNMP/examples/pingmib.pl b/perl/SNMP/examples/pingmib.pl new file mode 100755 index 0000000..e6aa792 --- /dev/null +++ b/perl/SNMP/examples/pingmib.pl @@ -0,0 +1,46 @@ +#!/usr/bin/env perl + +# Ping a host via the CISCO-PING-MIB. For more information about the +# CISCO-PING-MIB, see also +# http://tools.cisco.com/Support/SNMP/do/BrowseMIB.do?local=en&mibName=CISCO-PING-MIB. + +use strict; +use SNMP; + +my $target = shift || die "no ping target supplied\n"; # numeric ip address +my $host = shift || 'localhost'; +my $community = shift || 'private'; + +{ + my $sess = new SNMP::Session (DestHost => $host, + Community => $community, + Retries => 1); + + my $dec = pack("C*",split /\./, $target); + my $oid = ".1.3.6.1.4.1.9.9.16.1.1.1"; + my $row = "300"; + my $res; + + $res = $sess->set([ + ["$oid.16", $row, 6, "INTEGER"], + ["$oid.16", $row, 5, "INTEGER"], + ["$oid.15", $row, "MoNDS", "OCTETSTR"], + ["$oid.2", $row, 1, "INTEGER"], + ["$oid.4", $row, 20, "INTEGER"], + ["$oid.5", $row, 150, "INTEGER"], + ["$oid.3", $row, $dec, "OCTETSTR"]]); + defined($res) || die "row creation failed"; + + $res = $sess->set([["$oid.16", $row, 1, "INTEGER"]]); + defined($res) || die "row activation failed"; + + sleep 30; + my ($sent, $received, $low, $avg, $high, $completed) = $sess->get([ + ["$oid.9", $row], ["$oid.10", $row], ["$oid.11", $row], + ["$oid.12", $row], ["$oid.13", $row], ["$oid.14", $row]]); + + printf "Packet loss: %d% (%d/%d)\n", (100 * ($sent-$received)) / $sent, + $received, $sent; + print "Average delay $avg (low: $low high: $high)\n"; + $sess->set(["$oid.16", $row, 6, "INTEGER"]); +} diff --git a/perl/SNMP/examples/tablewalk.pl b/perl/SNMP/examples/tablewalk.pl new file mode 100644 index 0000000..6fe344c --- /dev/null +++ b/perl/SNMP/examples/tablewalk.pl @@ -0,0 +1,19 @@ +# snmpwalk of a single table +# getnext of 3 columns from ipAddrEntry table +# stop after last row in table + +use SNMP 1.8; + +my $host = shift || localhost; +my $comm = shift || public; + +my $sess = new SNMP::Session ( DestHost => $host, Community => $comm ); + +my $vars = new SNMP::VarList([ipAdEntAddr],[ipAdEntIfIndex],[ipAdEntNetMask]); + +for (@vals = $sess->getnext($vars); + $vars->[0]->tag =~ /ipAdEntAddr/ # still in table + and not $sess->{ErrorStr}; # and not end of mib or other error + @vals = $sess->getnext($vars)) { + print " ($vals[1]) $vals[0]/$vals[2]\n"; +} diff --git a/perl/SNMP/examples/testleak.pl b/perl/SNMP/examples/testleak.pl new file mode 100644 index 0000000..495f33b --- /dev/null +++ b/perl/SNMP/examples/testleak.pl @@ -0,0 +1,19 @@ +use SNMP 1.6; + +$host = shift; +unless ($host) { + $| = 1; print "enter SNMP host address: "; $| = 0; + chomp($host = <STDIN>); +} + +$obj = new SNMP::Session DestHost, $host; + +while (){ +print $obj->get(["ifNumber",0]); + open(COM,"ps -u$$|") || die; + @bar = <COM>; + $siz = (split(' ',$bar[1]))[4]; + $rss = (split(' ',$bar[1]))[5]; + close(COM); + print "siz = $siz, rss = $rss\n"; +} diff --git a/perl/SNMP/examples/trap-example.pl b/perl/SNMP/examples/trap-example.pl new file mode 100644 index 0000000..8b8913f --- /dev/null +++ b/perl/SNMP/examples/trap-example.pl @@ -0,0 +1,94 @@ +use strict; +use vars qw(); +use SNMP qw(); + +&SNMP::initMib(); + +&SNMP::loadModules( + 'RFC2127-MIB', + ); + +sub trap_call_setup; +sub trap_dummy; + +# +# should eventually get these out of the MIB... +# +my %dispatch_table = ( + 'isdnMibCallInformation', \&trap_call_setup, + '.', \&trap_dummy, +); + +sub trap_dispatcher +{ + my $session = shift; + my $ref = shift; + my $trapType; + my ($reqid, $addr, $community); + + # if this is a timeout, then there will be no args... + if (defined($ref)) { + $ref->[1]->[2] = SNMP::translateObj($ref->[1]->val); + $trapType = $ref->[1]->val; + my $args = shift; + ($reqid, $addr, $community) = @{$args}; + } else { + $trapType = 'timeout'; + } + + if (defined($dispatch_table{$trapType})) { + &{$dispatch_table{$trapType}}($session, $ref); + } elsif (defined($dispatch_table{'.'})) { + &{$dispatch_table{'.'}}($session, $ref); + } else { + # don't do anything... silently discard. + } +} + +sub trap_dummy +{ + my $session = shift; + my $ref = shift; + + my $trapType = $ref->[1]->val; + + warn "unexpected trap " . $trapType; +} + + +sub trap_call_setup +{ + my $session = shift; + my $varlist = shift; + my $args = shift; + + my $ifIndex = $varlist->[2]->val; + my $isdnBearerOperStatus = $varlist->[3]->val; + my $isdnBearerPeerAddress = $varlist->[4]->val; + my $isdnBearerPeerSubAddress = $varlist->[5]->val; + my $isdnBearerInfoType = $varlist->[6]->val; + my $isdnBearerCallOrigin = $varlist->[5]->val; + + my ($reqid, $ipaddr, $community) = @{$args}; + + printf "Call from %s", $isdnBearerPeerAddress; + printf "*%s", $isdnBearerPeerSubAddress if ($isdnBearerPeerSubAddress ne ''); + printf "\n"; +} + +my $session = new SNMP::Session( + DestHost => 'udp:162', + LocalPort => 1, + Version => '2c', + UseEnums => 0, + ); + +if (!defined($session)) { + die "can't create listener session"; +} + +# otherwise assume that ErrorNum is zero... + +$session->SNMP::_catch([\&trap_dispatcher, $session]); + +&SNMP::MainLoop(); diff --git a/perl/SNMP/hints/irix.pl b/perl/SNMP/hints/irix.pl new file mode 100644 index 0000000..3e38826 --- /dev/null +++ b/perl/SNMP/hints/irix.pl @@ -0,0 +1,2 @@ +# uses libelf for nlist on irix (>= 5.3?) +$self->{LIBS} .= ' -lelf'; diff --git a/perl/SNMP/hints/solaris.pl b/perl/SNMP/hints/solaris.pl new file mode 100644 index 0000000..87dccd1 --- /dev/null +++ b/perl/SNMP/hints/solaris.pl @@ -0,0 +1,4 @@ +# uses kstat on solaris for get_uptime +$self->{LIBS} .= ' -lkstat'; +# add -ldb if you are getting the vsnprintf not found error +# $self->{LIBS} .= ' -lkstat -ldb'; diff --git a/perl/SNMP/netsnmp-feature-definitions.h b/perl/SNMP/netsnmp-feature-definitions.h new file mode 100644 index 0000000..adc642c --- /dev/null +++ b/perl/SNMP/netsnmp-feature-definitions.h @@ -0,0 +1,8 @@ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-features.h> + +netsnmp_feature_require(snprint_objid) +netsnmp_feature_require(snprint_value) +netsnmp_feature_require(find_module) +netsnmp_feature_require(get_tc_description) + diff --git a/perl/SNMP/perlsnmp.h b/perl/SNMP/perlsnmp.h new file mode 100644 index 0000000..57bb064 --- /dev/null +++ b/perl/SNMP/perlsnmp.h @@ -0,0 +1,24 @@ +#ifndef timeradd +#define timeradd(a, b, result) \ + do { \ + (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ + (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ + if ((result)->tv_usec >= 1000000) \ + { \ + ++(result)->tv_sec; \ + (result)->tv_usec -= 1000000; \ + } \ + } while (0) +#endif + +#ifndef timersub +#define timersub(a, b, result) \ + do { \ + (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ + (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ + if ((result)->tv_usec < 0) { \ + --(result)->tv_sec; \ + (result)->tv_usec += 1000000; \ + } \ + } while (0) +#endif diff --git a/perl/SNMP/t/README b/perl/SNMP/t/README new file mode 100644 index 0000000..7921732 --- /dev/null +++ b/perl/SNMP/t/README @@ -0,0 +1,81 @@ + +mibload +(save_descriptions, use_long_names) + setmib + initMib + addMibDirs + addMibFiles + loadModules + unloadModules (todo) + +mib + translateObj + getType + mapEnum + SNMP::MIB::NODE + +session + connectivity + error handling + mib loading + parameters + +get +(use_enums, sprint_val, long_names) + var formats + fget + multi varbinds + error reporting + +getnext + +set + +trap?? + +async + +snmpv3 + + +This is the first stab at setting up comprehensive tests for +SNMP-1.7 which look and act like regular perl5 test results. + +Use teststub.t attached below as a template for creating additional +test modules. + +Add more tests and feed them back into the distribution! The more the +better! + +Written by John Stoffel (jfs@fluent.com =or= john@nesc.org) 10/14/1997 + +------------<teststub.t>-------------------------------- +#!./perl + +BEGIN { + unless(grep /blib/, @INC) { + chdir 't' if -d 't'; + @INC = '../lib' if -d '../lib'; + } +} +use Test; +use SNMP 3.0; + +$SNMP::verbose = 0; +$num = 0; # Number of tests to run + +print "1..$num\n"; +$n = 1; + +my $junk_oid = ".1.3.6.1.2.1.1.1.1.1.1"; +my $oid = '.1.3.6.1.2.1.1.1'; +my $name = 'sysDescr'; +my $junk_name = 'fooDescr'; + +###################################################################### +# Garbage names return Undef. +# test 1 +$type = SNMP::getType($junk_name); +printf "%s %d\n", (!defined($type)) ? "ok" :"not ok", $n++; + + diff --git a/perl/SNMP/t/async.t b/perl/SNMP/t/async.t new file mode 100644 index 0000000..f3fb38d --- /dev/null +++ b/perl/SNMP/t/async.t @@ -0,0 +1,169 @@ +#!./perl +BEGIN { + unless(grep /blib/, @INC) { + chdir 't' if -d 't'; + @INC = '../lib' if -d '../lib'; + } + eval "use Cwd qw(abs_path)"; + $ENV{'SNMPCONFPATH'} = 'nopath'; + $ENV{'MIBDIRS'} = '+' . abs_path("../../mibs"); + + $skipped_tests = ($^O =~ /win32/i) ? 20 : 0; +} + +use Test; +BEGIN {plan tests => 20 - $skipped_tests} +use SNMP; +use vars qw($agent_port $comm $agent_host); + +if ($^O =~ /win32/i) { + warn "Win32/Win64 detected - skipping async calls\n"; + exit; +} + +require "t/startagent.pl"; + + +sub cb1; # forward reference +sub cb2; +sub cb3; +sub cb4; +sub cb5; +sub cb6; +sub cb7; +sub cbDummy; + +$SNMP::verbose = 0; +$SNMP::dump_packet = 0; + +my $sess = new SNMP::Session(DestHost => $agent_host, + Version => 1, + Community => $comm, + RemotePort => $agent_port); + +# try getting unregistered OID. +my $result = $sess->get([["HooHaaHooHaa","0"]], [\&cbDummy, $sess]); +ok(!defined($result)); + +# this get should work +$result = $sess->get([["sysDescr","0"]], [\&cb1, $sess]); +ok($result); + +SNMP::MainLoop(); + +snmptest_cleanup(); + +exit 0; + +sub cb1{ + my $sess = shift; + my $vlist = shift; + + ok(defined($vlist)); + my $tag = $vlist->[0]->tag; + ok($tag eq 'sysDescr'); + my $val = $vlist->[0]->val; + ok(defined $val); + my $iid = $vlist->[0]->iid; + my $type = $vlist->[0]->type; + ok($type eq 'OCTETSTR'); + my $res = $sess->getnext([["sysDescr",0]], [\&cb2, $sess]); + ok ($res); +} # end of cb1 + +sub cb2{ + my $sess = shift; + my $vlist = shift; + + ok(defined($vlist)); + ok(ref($vlist->[0]) =~ /Varbind/); + ok($vlist->[0][0] eq 'sysObjectID'); + my $res = $sess->get([[".1.3.6.1.2.1.1.1.0"]], [\&cb3, $sess]); + ok($res); +} # end of cb2 + +sub cb3{ + my $sess = shift; + my $vlist = shift; + + ok(defined($vlist)); + + ok($vlist->[0][0] eq 'sysDescr'); + + my $res = $sess->getnext([["sysDescr",0]], [\&cb4, $sess]); + ok($res); +} # end of cb3 + +sub cb4{ + my $sess = shift; + my $vlist = shift; + + ok(defined $vlist); + my $res = $sess->set("sysDescr.0", "hahaha", [\&cb5, $sess]); +} # end of cb4 + +sub cb5{ + my $sess = shift; + my $vlist = shift; + + ok(defined($vlist)); + + my $res = $sess->set("sysORID.1", ".1.3.6.1.2.1.1.1", [\&cb6, $sess]); + ok(defined $res); +} # end of cb5 + +sub cb6{ + my $sess = shift; + my $vlist = shift; + my $tag = $vlist->[0]->tag; + my $val = $vlist->[0]->val; + + ok($tag =~ /^sysORID/); +# create list of varbinds for GETS, val field can be null or omitted + my $vars = + new SNMP::VarList ( + ['sysDescr', '0', ''], + ['sysObjectID', '0'], + ['sysUpTime', '0'], + ['sysContact', '0'], + ['sysName', '0'], + ['sysLocation', '0'], + ['sysServices', '0'], + ['ifNumber', '0'], + ['ifDescr', '1'], + ['ifSpeed', '1'], + ['snmpInPkts', '0'], + ['snmpInBadVersions', '0'], + ['snmpInBadCommunityNames', '0'], + ['snmpInBadCommunityUses', '0'], + ['snmpInASNParseErrs', '0'], + ['snmpEnableAuthenTraps', '0'], + ['sysORID', '1'], + ['sysORDescr', '1'], + ['sysORUpTime', '1'], + ['sysORLastChange', '0'], + ['ipInHdrErrors', '0'], + ['ipDefaultTTL', '0'], + ['ipInHdrErrors', '0'], + ); + my $res = $sess->get($vars, [\&cb7, $sess]); + ok(defined $res); +} # end of cb6 + +sub cb7{ + my $sess = shift; + my $vlist = shift; + + + my $tag = $vlist->[0]->tag; + my $val = $vlist->[0]->val; + + ok(@{$vlist} == 23); + + SNMP::finish(); +} # end of cb7 + +sub cbDummy { + warn("error: this should not get called"); +} + diff --git a/perl/SNMP/t/bulkwalk.t b/perl/SNMP/t/bulkwalk.t new file mode 100644 index 0000000..2d13e7b --- /dev/null +++ b/perl/SNMP/t/bulkwalk.t @@ -0,0 +1,339 @@ +#!./perl +# +# $Id$ +# +# Test bulkwalk functionality. + +BEGIN { + unless(grep /blib/, @INC) { + chdir 't' if -d 't'; + @INC = '../lib' if -d '../lib'; + } + eval "use Cwd qw(abs_path)"; + $ENV{'SNMPCONFPATH'} = 'nopath'; + $ENV{'MIBDIRS'} = '+' . abs_path("../../mibs"); + $skipped_tests = ($^O =~ /win32/i) ? 21 : 0; +} +use Test; +BEGIN { $num = 62 - $skipped_tests; plan test => $num; } + +use SNMP; + +require "t/startagent.pl"; + +use vars qw($agent_port $comm2 $agent_host); + +$SNMP::debugging = 0; +$SNMP::verbose = 0; + +#print "1..$num\n"; + +###################################################################### +# Fire up a session. +$s1 = new SNMP::Session( + 'DestHost' => $agent_host, + 'Community' => $comm2, + 'RemotePort' => $agent_port, + 'Version' => '2c', + 'UseNumeric' => 1, + 'UseEnum' => 0, + 'UseLongNames' => 1 +); +ok(defined($s1)); + +###################################################################### +# +# Attempt to use the bulkwalk method to get a few variables from the +# SNMP agent. +# test 1 +$vars = new SNMP::VarList ( ['sysUpTime'], ['ifNumber'], # NON-repeaters + ['ifSpeed'], ['ifDescr']); # Repeated variables. + +$expect = scalar @$vars; +@list = $s1->bulkwalk(2, 16, $vars); + +ok($s1->{ErrorNum} == 0); + +# Did we get back the list of references to returned values? +# +ok(scalar @list == $expect); +if (defined($list[0][0])) { + # Sanity check the returned values. list[0] is sysUptime nonrepeater. + ok($list[0][0]->tag eq ".1.3.6.1.2.1.1.3"); # check system.sysUptime OID + ok($list[0][0]->iid eq "0"); # check system.sysUptime.0 IID + ok($list[0][0]->val =~ m/^\d+$/); # Uptime is numeric + ok($list[0][0]->type eq "TICKS"); # Uptime should be in ticks. +} +else { + ok(0); + ok(0); + ok(0); + ok(0); +} +if (defined($list[1][0])) { + # Find out how many interfaces to expect. list[1] is ifNumber nonrepeater. + ok($list[1][0]->tag eq ".1.3.6.1.2.1.2.1"); # Should be system.ifNumber OID. + ok($list[1][0]->iid eq "0"); # system.ifNumber.0 IID. + ok($list[1][0]->val =~ m/^\d+$/); # Number is all numeric + #XXX: test fails due SMIv1 codes being returned intstead of SMIv2... + #ok($list[1][0]->type eq "INTEGER32"); # Number should be integer. + + $ifaces = $list[1][0]->val; +} +else { + ok(0); + ok(0); + ok(0); +} + +# Make sure we got an ifSpeed for each interface. list[2] is ifSpeed repeater. +ok(scalar @{$list[2]} == $ifaces); +# Make sure we got an ifDescr for each interface. list[3] is ifDescr repeater. +ok(scalar @{$list[3]} == $ifaces); + +if (defined($list[2][0])) { + # Test for reasonable values from the agent. + ok($list[2][0]->tag eq ".1.3.6.1.2.1.2.2.1.5"); # Should be system.ifSpeed OID. + ok($list[2][0]->iid eq "1"); # Instance should be 1. + ok($list[2][0]->val =~ m/^\d+$/); # Number is all numeric + ok($list[2][0]->type eq "GAUGE"); # Number should be a gauge. +} +else { + ok(0); + ok(0); + ok(0); + ok(0); +} + +if (defined($list[3][0])) { + ok($list[3][0]->tag eq ".1.3.6.1.2.1.2.2.1.2"); # Should be system.ifDescr OID. + ok($list[3][0]->iid eq "1"); # Instance should be 1. + + # The first interface is probably loopback. Check this. + ok($list[3][0]->type eq "OCTETSTR"); # Description is a string. + + # This might fail on systems that don't have lo0/loopback as their first + # interface. Please adjust accordingly. + $loopback = $list[3][0]->val; + if ($^O =~ /win32/i) { + ok(($loopback =~ /loopback/i)); + } elsif ($^O =~ /(irix|hpux)/i) { + # IRIX/HP-UX may have lo0 at the *end* of the interface list, + # so just check for a non-empty string + ok(($loopback ne '')); + } elsif ($^O eq 'freebsd') { + $loopback = $list[3][-1]->val; + ok(($loopback =~ /^lo/)); + } else { + ok(($loopback =~ /^lo/)); + } +} +else { + ok(0); + ok(0); + ok(0); + ok(0); +} + +############################################################################### +# Attempt to use the bulkwalk method to get only non-repeaters +# test 2 +$vars = new SNMP::VarList ( ['sysUpTime'], ['ifNumber'] ); # NON-repeaters + +$expect = scalar @$vars; +@list = $s1->bulkwalk(2, 0, $vars); +#@list = $s1->bulkwalk(2, 16, $vars); +ok($s1->{ErrorNum} == 0); + +# Did we get back the list of references to returned values? +# +ok(scalar @list == $expect); + +if (defined($list[0][0])) { + # Sanity check the returned values. list[0] is sysUptime nonrepeater. + ok($list[0][0]->tag eq ".1.3.6.1.2.1.1.3"); # check system.sysUptime OID + ok($list[0][0]->iid eq "0"); # check system.sysUptime.0 IID + ok($list[0][0]->val =~ m/^\d+$/); # Uptime is numeric + ok($list[0][0]->type eq "TICKS"); # Uptime should be in ticks. +} +else { + ok(0); + ok(0); + ok(0); + ok(0); +} + +if (defined($list[1][0])) { + # Find out how many interfaces to expect. list[1] is ifNumber nonrepeater. + ok($list[1][0]->tag eq ".1.3.6.1.2.1.2.1"); # Should be system.ifNumber OID. + ok($list[1][0]->iid eq "0"); # system.ifNumber.0 IID. + ok($list[1][0]->val =~ m/^\d+$/); # Number is all numeric + #XXX: test fails due SMIv1 codes being returned intstead of SMIv2... + #ok($list[1][0]->type eq "INTEGER32"); # Number should be integer. + $ifaces = $list[1][0]->val; +} +else { + ok(0); + ok(0); + ok(0); +} + +############################################################################### +# Attempt to use the bulkwalk method to get only repeated variables +# test 3 +$vars = new SNMP::VarList ( ['ifIndex'], ['ifSpeed'] ); # repeaters + +$expect = scalar @$vars; +@list = $s1->bulkwalk(0, 16, $vars); +ok($s1->{ErrorNum} == 0); + +# Did we get back the list of references to returned values? +# +ok(scalar @list == $expect); + +# Make sure we got an ifIndex for each interface. list[0] is ifIndex repeater. +ok(scalar @{$list[0]} == $ifaces); + +# Make sure we got an ifSpeed for each interface. list[0] is ifSpeed repeater. +ok(scalar @{$list[1]} == $ifaces); + +if (defined($list[0][0])) { + # Test for reasonable values from the agent. + ok($list[0][0]->tag eq ".1.3.6.1.2.1.2.2.1.1"); # Should be system.ifIndex OID. + ok($list[0][0]->iid eq "1"); # Instance should be 1. + ok($list[0][0]->val =~ m/^\d+$/); # Number is all numeric + #XXX: test fails due SMIv1 codes being returned intstead of SMIv2... + #ok($list[0][0]->type eq "INTEGER32"); # Number should be an integer. +} +else { + ok(0); + ok(0); + ok(0); +} + +if (defined($list[1][0])) { + ok($list[1][0]->tag eq ".1.3.6.1.2.1.2.2.1.5"); # Should be system.ifSpeed OID. + ok($list[1][0]->iid eq "1"); # Instance should be 1. + ok($list[1][0]->val =~ m/^\d+$/); # Number is all numeric + ok($list[1][0]->type eq "GAUGE"); # Number should be a gauge. +} +else { + ok(0); + ok(0); + ok(0); + ok(0); +} + +###################################################################### +# Asynchronous Bulkwalk Methods +###################################################################### +# +# Attempt to use the bulkwalk method to get a few variables from the +# SNMP agent. +# test 4 +sub async_cb1 { + my ($vars, $list) = @_; + ok(defined $list && ref($list) =~ m/ARRAY/); + ok(defined $vars && ref($vars) =~ m/SNMP::VarList/); + + ok(scalar @$list == scalar @$vars); + + my $vbr; + + if (defined($list->[0][0])) { + # Sanity check the returned values. First is sysUptime nonrepeater. + $vbr = $list->[0][0]; + ok($vbr->tag eq ".1.3.6.1.2.1.1.3"); # check system.sysUptime OID + ok($vbr->iid eq "0"); # check system.sysUptime.0 IID + ok($vbr->val =~ m/^\d+$/); # Uptime is numeric + ok($vbr->type eq "TICKS"); # Uptime should be in ticks. + } + else { + ok(0); + ok(0); + ok(0); + ok(0); + } + + if (defined($list->[1][0])) { + # Find out how many interfaces to expect. Next is ifNumber nonrepeater. + $vbr = $list->[1][0]; + ok($vbr->tag eq ".1.3.6.1.2.1.2.1"); # Should be system.ifNumber OID. + ok($vbr->iid eq "0"); # system.ifNumber.0 IID. + ok($vbr->val =~ m/^\d+$/); # Number is all numeric + #XXX: test fails due SMIv1 codes being returned intstead of SMIv2... + # ok($vbr->type eq "INTEGER32"); # Number should be integer. + $ifaces = $vbr->[2]; + } + else { + ok(0); + ok(0); + ok(0); + } + + # Test for reasonable values from the agent. + ok(scalar @{$list->[2]} == $ifaces); + + if (defined($list->[2][0])) { + $vbr = $list->[2][0]; + ok($vbr->tag eq ".1.3.6.1.2.1.2.2.1.5"); # Should be ifSpeed OID + ok($vbr->iid eq "1"); # Instance should be 1. + ok($vbr->val =~ m/^\d+$/); # Number is all numeric + ok($vbr->type eq "GAUGE"); # Should be a gauge. + + ok(scalar @{$list->[3]} == $ifaces); + } + else { + ok(0); + ok(0); + ok(0); + ok(0); + ok(0); + } + + if (defined($list->[3][0])) { + $vbr = $list->[3][0]; + ok($vbr->tag eq ".1.3.6.1.2.1.2.2.1.2"); # Should be ifDescr OID + ok($vbr->iid eq "1"); # Instance should be 1. + + # The first interface is probably loopback. Check this. + ok($vbr->type eq "OCTETSTR"); + + # This might fail on systems that don't have lo0/loopback as their first + # interface. Please adjust accordingly. + if ($^O =~ /(irix|hpux)/i) { + # IRIX/HP-UX may have lo0 at the *end* of the interface list, + # so just check for a non-empty string + ok(($vbr->val ne '')); + } elsif ($^O eq 'freebsd') { + $vbr = $list->[3][-1]; + ok(($vbr->val =~ /^lo/)); + } else { + ok(($vbr->val =~ /^lo/)); + } + } + else { + ok(0); + ok(0); + ok(0); + ok(0); + } + + SNMP::finish(); +} + +$vars = new SNMP::VarList ( ['sysUpTime'], ['ifNumber'], # NON-repeaters + ['ifSpeed'], ['ifDescr']); # Repeated variables. + +if ($^O =~ /win32/i) { + warn "Win32/Win64 detected - skipping async calls\n"; +} +else { + @list = $s1->bulkwalk(2, 16, $vars, [ \&async_cb1, $vars ] ); + ok($s1->{ErrorNum} == 0); + SNMP::MainLoop(); +} +ok(1); + +snmptest_cleanup(); + diff --git a/perl/SNMP/t/conf.t b/perl/SNMP/t/conf.t new file mode 100644 index 0000000..9a37048 --- /dev/null +++ b/perl/SNMP/t/conf.t @@ -0,0 +1,53 @@ +#!./perl + +BEGIN { + unless(grep /blib/, @INC) { + chdir 't' if -d 't'; + @INC = '../lib' if -d '../lib'; + } + $ENV{'MIBS'} = ''; +} + +# This merely checks to see if the default_store routines work from +# read configuration files. Functionally, if this fails then it's a +# serious problem because they linked with static libraries instead of +# shared ones as the memory space is different. + +use Test; +BEGIN {plan tests => 3} + +my $envsep = ($^O =~ /win32/i) ? ';' : ':'; + +SNMP::setenv('SNMPCONFPATH', '.' . $envsep . 't', 1); + +ok(1); # just start up + +use SNMP; +use NetSNMP::default_store(':all'); + +# should be 0, as it's un-initialized +$myint = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, + NETSNMP_DS_LIB_NUMERIC_TIMETICKS); + +ok($myint == 0); + +SNMP::init_snmp("conftest"); + +$myint = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, + NETSNMP_DS_LIB_NUMERIC_TIMETICKS); + +# ok, should be 1 as it's initalized by the snmp.conf config file. +ok($myint == 1); + +# this is a pretty major error, so if it's not true we really really +# print a big big warning. Technically, I suspect this is a bad thing +# to do in perl tests but... +if ($myint != 1) { + die "\n\n\n" . "*" x 75 . "\nBIG PROBLEM($myint): I wasn't able to read + data from a configuration file. This likely means that you've + compiled the net-snmp package with static libraries, which can + cause real problems with the perl module. Please reconfigure your + net-snmp package for use with shared libraries (run configure with + --enable-shared)\n" . "*" x 75 . "\n\n\n\n"; +} + diff --git a/perl/SNMP/t/conftest.conf b/perl/SNMP/t/conftest.conf new file mode 100644 index 0000000..9cf5219 --- /dev/null +++ b/perl/SNMP/t/conftest.conf @@ -0,0 +1,2 @@ +[snmp] +numericTimeticks 1 diff --git a/perl/SNMP/t/get.t b/perl/SNMP/t/get.t new file mode 100644 index 0000000..f88de65 --- /dev/null +++ b/perl/SNMP/t/get.t @@ -0,0 +1,216 @@ +#!./perl + +BEGIN { + unless(grep /blib/, @INC) { + chdir 't' if -d 't'; + @INC = '../lib' if -d '../lib'; + } + eval "use Cwd qw(abs_path)"; + $ENV{'SNMPCONFPATH'} = 'nopath'; + $ENV{'MIBDIRS'} = '+' . abs_path("../../mibs"); +} +use Test; +BEGIN { $n = 17; plan tests => $n } +use SNMP; +use vars qw($agent_port $comm $agent_host); +require "t/startagent.pl"; +$SNMP::debugging = 0; +$SNMP::verbose = 0; +$SNMP::dump_packet = 0; + +my $junk_oid = ".1.3.6.1.2.1.1.1.1.1.1"; +my $oid = '.1.3.6.1.2.1.1.1'; +my $junk_name = 'fooDescr'; +my $junk_host = 'no.host.here'; +my $name = "gmarzot\@nortelnetworks.com"; +my $s1; + +# create list of varbinds for GETS, val field can be null or omitted +$vars = new SNMP::VarList ( + ['sysDescr', '0', ''], + ['sysObjectID', '0'], + ['sysUpTime', '0'], + ['sysContact', '0'], + ['sysName', '0'], + ['sysLocation', '0'], + ['sysServices', '0'], + + ['snmpInPkts', '0'], + ['snmpInBadVersions', '0'], + ['snmpInBadCommunityNames', '0'], + ['snmpInBadCommunityUses', '0'], + ['snmpInASNParseErrs', '0'], + ['snmpEnableAuthenTraps', '0'], + + ['sysORID', '1'], + ['sysORDescr', '1'], + ['sysORUpTime', '1'], + ['sysORLastChange', '0'], + ['snmpSilentDrops', '0'], + ['snmpProxyDrops', '0'], + +## not all agents we know will support these objects +# ['hrStorageType', '2'], +# ['hrSystemDate', '0'], +# ['sysORIndex', '1'], +# ['ifName', '1'], +# ['ifNumber', '0'], +# ['ifDescr', '1'], +# ['ifSpeed', '1'], +# ['snmpTrapEnterprise', '2'], +# ['ipInHdrErrors', '0'], +# ['ipDefaultTTL', '0'], +# ['ipInHdrErrors', '0'], + + ); +################################################################ +# Yet to do: +# test for the max limit the 'get' can provide. +# Figure out why the IP and Physical address are not getting printed. +# why ifname is not getting printed? +################################################################ +# ['ipNetToMediaPhysAddress', '0'], +# ['ipAdEntAddr', '0'], +# ['snmpTrapOID', '0'], +# ['hrSystemNumUsers', '0'], +# ['hrFSLastFullBackupDate', '0'], +# ['ifPromiscuousMode', '0'], + + + +###################################################################### +# Fire up a session. + $s1 = + new SNMP::Session (DestHost=>$agent_host,Version=>1,Community=>$comm,RemotePort=>$agent_port); + ok(defined($s1)); + +###################################################################### +# Get the standard Vars and check that we got some defined vars back +@ret = $s1->get($vars); +ok(!$s1->{ErrorStr} and defined($ret[0])); +#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; +###################################################################### +# Check that we got back the number we asked for. +ok($#ret == $#{$vars}); +#print("dude : $#ret\n"); +################################################ + +# Test for a string +$contact = $s1->get('sysContact.0'); +#print("contact is : $contact\n"); +ok( defined($contact)); + + +$name = $s1->get('sysName.0'); +#print("Name is : $name\n"); +ok( defined($name)); + + +$location = $s1->get('sysLocation.0'); +#print("Location is : $location\n"); +ok( defined($location)); +######################################### + + +# Test for an integer +$ttl = $s1->get('ipDefaultTTL.0'); +#print("TTL is : $ttl\n"); +ok( defined($ttl)); +######################################## + + +# Test for a TimeTicks +$time = $s1->get('sysUpTime.0'); +#print("up time is : $time hundredths of a second\n"); +ok( defined($time)); +######################################### + + +#Test for a Counter32 type. +$totalDatagramsReceived = $s1->get('ipInHdrErrors.0'); +#print("totalDatagramsReceived is : $totalDatagramsReceived\n"); +ok( defined($totalDatagramsReceived)); +################################################ + + +#Test for a PhysicalAddr type +$physaddr = $s1->get('ipNetToMediaPhysAddress.0'); +#print("physical addr is : $physaddr \n"); +ok( defined($physaddr)); +############################################## + + +#Test for a IpAddr type +$ipaddr = $s1->get('ipAdEntAddr.0'); +#print("Ip address is : $ipaddr \n"); +ok( defined($ipaddr)); +############################################## + + +#Test for a OID type +$trapOID = $s1->get('snmpTrapOID.0'); +#print("trap OID is : $trapOID $s1->{ErrorStr}\n"); +ok( defined($trapOID)); +############################################## + + +#Test for a Gauge type +#$numusers = $s1->get('hrSystemNumUsers.0'); +#print("Number of users is : $numusers \n"); +#ok( defined($numusers)); +############################################## + +#nosuchname +#Test for a date & time type +#$datetime = $s1->get('hrFSLastFullBackupDate.0'); +#print("Number of users is : $datetime \n"); +#ok( defined($datetime)); +############################################## + +#nosuchname +#Test for a Truth value type +#$mode = $s1->get('ifPromiscuousMode.16'); +#print("Truth value(1 true, 2 false) is : $mode \n"); +#ok( defined($mode)); +############################################## + +# Time stamp test +$time = $s1->get('sysORLastChange.0'); +#print("time stamp is : $time \n"); +ok(defined($time)); +############################################# + +# Integer test +#$index = $s1->get('sysORIndex.0'); +#print("index is : $index\n"); +#ok(defined($index)); +############################################# + +# OID test +$oid = $s1->get('sysORID.1'); +#print("index is : $oid\n"); +ok(defined($oid)); +############################################# + +# String test +$descr = $s1->get('sysORDescr.1'); +#print("Sys Descr is : $descr\n"); +ok(defined($descr)); +############################################# + +# string String test +$ifname = $s1->get('ifDescr.1'); +#print("ifname is : $ifname $s1->{ErrorStr}\n"); +ok(defined($ifname)); +############################################# + + +# Try getting some unknown(wrong ?) data +$unknown = $s1->get('ifmyData.0'); +ok(!defined($unknown)); +############################################## + + +snmptest_cleanup(); + + diff --git a/perl/SNMP/t/getnext.t b/perl/SNMP/t/getnext.t new file mode 100644 index 0000000..417ae91 --- /dev/null +++ b/perl/SNMP/t/getnext.t @@ -0,0 +1,102 @@ +#!./perl + +BEGIN { + unless(grep /blib/, @INC) { + chdir 't' if -d 't'; + @INC = '../lib' if -d '../lib'; + } + eval "use Cwd qw(abs_path)"; + $ENV{'SNMPCONFPATH'} = 'nopath'; + $ENV{'MIBDIRS'} = '+' . abs_path("../../mibs"); +} + +use Test; +BEGIN { plan tests => 9 } +use SNMP; +use vars qw($agent_port $comm $agent_host); +require "t/startagent.pl"; + + +my $junk_oid = ".1.3.6.1.2.1.1.1.1.1.1"; +my $oid = '.1.3.6.1.2.1.1.1'; +my $junk_name = 'fooDescr'; +my $junk_host = 'no.host.here'; +my $name = "gmarzot\@nortelnetworks.com"; + +$SNMP::debugging = 0; +my $n = 9; # Number of tests to run + +#print "1..$n\n"; +#if ($n == 0) { exit 0; } + +# create list of varbinds for GETS, val field can be null or omitted +my $vars = new SNMP::VarList ( + ['sysDescr', '0', ''], + ['sysContact', '0'], + ['sysName', '0'], + ['sysLocation', '0'], + ['sysServices', '0'], + ['ifNumber', '0'], + ['ifDescr', '1'], + ['ifSpeed', '1'], + ); + + +############################## 1 ##################################### +# Fire up a session. + my $s1 = + new SNMP::Session (DestHost=>$agent_host,Version=>1,Community=>$comm,RemotePort=>$agent_port); + ok(defined($s1)); + +############################# 2 ####################################### +# Try getnext on sysDescr.0 + +my $next = $s1->getnext('sysDescr.0'); +#print ("The next OID is : $next\n"); +ok($s1->{ErrorStr} eq ''); +#print STDERR "Error string1 = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; +#print("\n"); + +########################### 3 ######################################## +#$v1 = $s1->getnext('sysLocation.0'); +#print ("The next OID is : $v1\n"); +my $v2 = $s1->getnext('sysServices.0'); +#print ("The next OID is : $v2\n"); +ok($s1->{ErrorStr} eq ''); +#print STDERR "Error string2 = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; +#print("\n"); + + +############################ 4 ####################################### +# try it on an unknown OID +my $v3 = $s1->getnext('Srivathsan.0'); +#print ("The unknown OID is : $v3\n"); +ok($s1->{ErrorStr} =~ /^Unknown/); +#print STDERR "Error string5 = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; +#print("\n"); +############################# 5 ####################################### +# On a non-accessible value +#my $kkk = $s1->getnext('vacmSecurityName.1'); +#print("kkk is $kkk\n"); +#ok($s1->{ErrorInd} != 0); +#print STDERR "Error string5 = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; +#print("\n"); + +############################# 6 #################################### +# We should get back sysDescr.0 here. +my $var = new SNMP::Varbind(['sysDescr']); +my $res2 = $s1->getnext($var); +#print("res2 is : $res2\n"); +ok((not $s1->{ErrorStr} and not $s1->{ErrorInd})); +ok((defined $var->iid and $var->iid eq 0)); +ok((defined $var->val and $var->val eq $res2)); + +############################# 7 ###################################### +# get the next one after that as well for a second check +my $res3 = $s1->getnext($var); +#print("res3 is : $res3\n"); +ok((defined $var->tag and $var->tag eq 'sysObjectID')); +ok((defined $var->val and $var->val eq $res3)); + + + snmptest_cleanup(); diff --git a/perl/SNMP/t/mib.t b/perl/SNMP/t/mib.t new file mode 100644 index 0000000..f4ba91a --- /dev/null +++ b/perl/SNMP/t/mib.t @@ -0,0 +1,226 @@ +#!./perl + +# Written by John Stoffel (jfs@fluent.com) - 10/13/1997 + +BEGIN { + unless(grep /blib/, @INC) { + chdir 't' if -d 't'; + @INC = '../lib' if -d '../lib'; + } + eval "use Cwd qw(abs_path)"; + $ENV{'SNMPCONFPATH'} = 'nopath'; + $ENV{'MIBDIRS'} = '+' . abs_path("../../mibs"); + $ENV{'MIBS'} = 'ALL'; +} + +# to print the description... +$SNMP::save_descriptions = 1; + +use Test; +BEGIN {plan tests => 35} +use SNMP; + +$SNMP::verbose = 0; +$SNMP::best_guess = 2; + +use vars qw($bad_oid); +require "t/startagent.pl"; + +############################# 1 ###################################### +#check if +my $res = $SNMP::MIB{sysDescr}{label}; +#print("Label is:$res\n"); +ok("sysDescr" eq $res); +#print("\n"); +############################# 2 ###################################### +$res = $SNMP::MIB{sysDescr}{objectID}; +#print("OID is: $res\n"); +ok(defined($res)); +#print("\n"); +############################# 3 ###################################### +$res = $SNMP::MIB{sysDescr}{access}; +#print("access is: $res\n"); +ok($res eq 'ReadOnly'); +#print("\n"); +############################## 4 ################################### +$res = $SNMP::MIB{sysLocation}{access}; +#$res = $SNMP::MIB{sysORIndex}{access}; +ok($res eq 'ReadWrite'); +############################## 5 ################################### +$res = $SNMP::MIB{sysLocation}{type}; +ok($res eq 'OCTETSTR'); +############################# 6 #################################### +$res = $SNMP::MIB{sysLocation}{status}; +#print STDERR ("status is: $res\n"); +ok($res eq 'Current'); +#print STDERR ("\n"); +############################# 7 ################################# +$res = $SNMP::MIB{sysORTable}{access}; +#print("access is: $res\n"); +ok($res eq 'NoAccess'); +#print("\n"); +############################# 8 ############################### +$res = $SNMP::MIB{sysLocation}{subID}; +#print("subID is: $res\n"); +ok(defined($res)); +#print("\n"); +############################ 9 ############################## +$res = $SNMP::MIB{sysLocation}{syntax}; +#print("syntax is: $res\n"); +ok($res eq 'DisplayString'); +#print("\n"); +############################ 10 ########################### +$res = $SNMP::MIB{ipAdEntAddr}{syntax}; +ok($res eq 'IPADDR'); +#print("\n"); +########################## 11 ########################## +$res = $SNMP::MIB{atNetAddress}{syntax}; +#print ("syntax is: $res\n"); +ok($res eq 'NETADDR'); +#print("\n"); +######################## 12 ############################### +$res = $SNMP::MIB{ipReasmOKs}{syntax}; +#print("syntax is: $res\n"); +ok($res eq 'COUNTER'); +#print("\n"); +###################### 13 ############################## +$res = $SNMP::MIB{sysDescr}{moduleID}; +#print("Module ID is: $res\n"); +ok(defined($res)); +#print("\n"); +###################### 14 ######################### +$des = $SNMP::MIB{atNetAddress}{description}; +#print("des is --> $des\n"); +ok(defined($des)); +#print("\n"); + +###################### 15 ######################### +$res = $SNMP::MIB{atNetAddress}{nextNode}; +#print("res is --> $res\n"); +ok(ref($res) eq "HASH"); +#print("\n"); + +######################## 16 ######################### +$res = $SNMP::MIB{sysDescr}{children}; +#print("res is --> $res\n"); +ok(ref($res) eq "ARRAY"); +#print("\n"); +#################### 17 ######################### + +$res = $SNMP::MIB{sysDescr}{badField}; +ok(!defined($res)); + + +###################### 18 ######################### +$res = $SNMP::MIB{sysDescr}{hint}; +#print("res is --> $res\n"); +#XXX: test fails due SMIv1 codes being returned intstead of SMIv2... +#ok(defined($res) && $res =~ /^255a/); +#print("\n"); +###################### 19 ######################### + +$res = $SNMP::MIB{ifPhysAddress}{hint}; +#print("res is --> $res\n"); +#XXX: test fails due SMIv1 codes being returned intstead of SMIv2... +#ok(defined($res) && $res =~ /^1x:/); +#print("\n"); + + +###################### some translate tests ####### + +##################### 20 ######################### +# Garbage names return Undef. + +my $type1 = SNMP::getType($bad_name); +ok(!defined($type1)); +#printf "%s %d\n", (!defined($type1)) ? "ok" :"not ok", $n++; + +###################################################################### +# getType() supports numeric OIDs now + +my $type2 = SNMP::getType($oid); +#XXX: test fails due SMIv1 codes being returned intstead of SMIv2... +#ok(defined($type2) && $type2 =~ /OCTETSTR/); + +###################################################################### +# This tests that sysDescr returns a valid type. + +my $type3 = SNMP::getType($name); +ok(defined($type3)); + +###################################################################### +# Translation tests from Name -> OID +# sysDescr to .1.3.6.1.2.1.1.1 +$oid_tag = SNMP::translateObj($name); +ok($oid eq $oid_tag); + +###################################################################### +# Translation tests from Name -> OID +# RFC1213-MIB::sysDescr to .1.3.6.1.2.1.1.1 +$oid_tag = SNMP::translateObj($name_module); +ok($oid eq $oid_tag); + +###################################################################### +# Translation tests from Name -> OID +# .iso.org.dod.internet.mgmt.mib-2.system.sysDescr to .1.3.6.1.2.1.1.1 +$oid_tag = SNMP::translateObj($name_long); +ok($oid eq $oid_tag); + +###################################################################### +# bad name returns 'undef' +$oid_tag = ''; +$oid_tag = SNMP::translateObj($bad_name); +ok(!defined($oid_tag)); + + +###################################################################### +# OID -> name +# .1.3.6.1.2.1.1.1 to sysDescr +$name_tag = SNMP::translateObj($oid); +ok($name eq $name_tag); + +###################################################################### +# OID -> name +# .1.3.6.1.2.1.1.1 to RFC1213-MIB::sysDescr or +# .1.3.6.1.2.1.1.1 to SNMPv2-MIB::sysDescr +$name_tag = SNMP::translateObj($oid,0,1); +$name_module2 = $name_module2; # To eliminate 'only use once' variable warning +ok(($name_module eq $name_tag) || ($name_module2 eq $name_tag)); + +###################################################################### +# OID -> name +# .1.3.6.1.2.1.1.1 to .iso.org.dod.internet.mgmt.mib-2.system.sysDescr +$name_tag = SNMP::translateObj($oid,1); +ok($name_long eq $name_tag); + +###################################################################### +# OID -> name +# .1.3.6.1.2.1.1.1 to RFC1213-MIB::.iso.org.dod.internet.mgmt.mib-2.system.sysDescr or +# .1.3.6.1.2.1.1.1 to SNMPv2-MIB::.iso.org.dod.internet.mgmt.mib-2.system.sysDescr +$name_module_long = $name_module_long; # To eliminate 'only use once' variable warning +$name_module_long2 = $name_module_long2; # To eliminate 'only use once' variable warning +$name_tag = SNMP::translateObj($oid,1,1); +ok(($name_module_long eq $name_tag) || ($name_module_long2 eq $name_tag)); + +###################################################################### +# bad OID -> Name + +$name_tag = SNMP::translateObj($bad_oid); +ok($name ne $name_tag); +#printf "%s %d\n", ($name ne $name_tag) ? "ok" :"not ok", $n++; + + +###################################################################### +# ranges + +$node = $SNMP::MIB{snmpTargetAddrMMS}; +ok($node); +$ranges = $node->{ranges}; +ok($ranges and ref $ranges eq 'ARRAY'); +ok(@$ranges == 2); +ok($$ranges[0]{low} == 0); +ok($$ranges[0]{high} == 0); +ok($$ranges[1]{low} == 484); +ok($$ranges[1]{high} == 2147483647); + +snmptest_cleanup(); diff --git a/perl/SNMP/t/mib.txt b/perl/SNMP/t/mib.txt new file mode 100644 index 0000000..347a2af --- /dev/null +++ b/perl/SNMP/t/mib.txt @@ -0,0 +1,4208 @@ +RFC1155-SMI DEFINITIONS ::= BEGIN + nullOID OBJECT IDENTIFIER ::= { ccitt 0 } + internet OBJECT IDENTIFIER ::= { iso org(3) dod(6) 1 } + directory OBJECT IDENTIFIER ::= { internet 1 } + mgmt OBJECT IDENTIFIER ::= { internet 2 } + experimental OBJECT IDENTIFIER ::= { internet 3 } + private OBJECT IDENTIFIER ::= { internet 4 } + enterprises OBJECT IDENTIFIER ::= { private 1 } +END + +-- @(#)WSCCS o/mibs-rfc1213.mib 1.1 8/30/95 +-- Changes to rfc1213 (MIB-II): +-- No changes needed. + + + RFC1213-MIB DEFINITIONS ::= BEGIN + + IMPORTS + mgmt, NetworkAddress, IpAddress, Counter, Gauge, + TimeTicks + FROM RFC1155-SMI + OBJECT-TYPE + FROM RFC-1212; + + -- This MIB module uses the extended OBJECT-TYPE macro as + -- defined in [14]; + + + -- MIB-II (same prefix as MIB-I) + + mib-2 OBJECT IDENTIFIER ::= { mgmt 1 } + + -- textual conventions + + DisplayString ::= + OCTET STRING + -- This data type is used to model textual information taken + -- from the NVT ASCII character set. By convention, objects + -- with this syntax are declared as having + -- + -- SIZE (0..255) + + PhysAddress ::= + OCTET STRING + -- This data type is used to model media addresses. For many + -- types of media, this will be in a binary representation. + -- For example, an ethernet address would be represented as + -- a string of 6 octets. + + + -- groups in MIB-II + + system OBJECT IDENTIFIER ::= { mib-2 1 } + + interfaces OBJECT IDENTIFIER ::= { mib-2 2 } + + at OBJECT IDENTIFIER ::= { mib-2 3 } + + ip OBJECT IDENTIFIER ::= { mib-2 4 } + + icmp OBJECT IDENTIFIER ::= { mib-2 5 } + + tcp OBJECT IDENTIFIER ::= { mib-2 6 } + + udp OBJECT IDENTIFIER ::= { mib-2 7 } + + egp OBJECT IDENTIFIER ::= { mib-2 8 } + + -- historical (some say hysterical) + -- cmot OBJECT IDENTIFIER ::= { mib-2 9 } + + transmission OBJECT IDENTIFIER ::= { mib-2 10 } + + snmp OBJECT IDENTIFIER ::= { mib-2 11 } + + + -- the System group + + -- Implementation of the System group is mandatory for all + -- systems. If an agent is not configured to have a value + -- for any of these variables, a string of length 0 is + -- returned. + + sysDescr OBJECT-TYPE + SYNTAX DisplayString (SIZE (0..255)) + ACCESS read-only + STATUS mandatory + DESCRIPTION + "A textual description of the entity. This value + should include the full name and version + identification of the system's hardware type, + software operating-system, and networking + software. It is mandatory that this only contain + printable ASCII characters." + ::= { system 1 } + + sysObjectID OBJECT-TYPE + SYNTAX OBJECT IDENTIFIER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The vendor's authoritative identification of the + network management subsystem contained in the + entity. This value is allocated within the SMI + enterprises subtree (1.3.6.1.4.1) and provides an + easy and unambiguous means for determining `what + kind of box' is being managed. For example, if + vendor `Flintstones, Inc.' was assigned the + subtree 1.3.6.1.4.1.4242, it could assign the + identifier 1.3.6.1.4.1.4242.1.1 to its `Fred + Router'." + ::= { system 2 } + + sysUpTime OBJECT-TYPE + SYNTAX TimeTicks + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The time (in hundredths of a second) since the + network management portion of the system was last + re-initialized." + ::= { system 3 } + + sysContact OBJECT-TYPE + SYNTAX DisplayString (SIZE (0..255)) + ACCESS read-write + STATUS mandatory + DESCRIPTION + "The textual identification of the contact person + for this managed node, together with information + on how to contact this person." + ::= { system 4 } + + sysName OBJECT-TYPE + SYNTAX DisplayString (SIZE (0..255)) + ACCESS read-write + STATUS mandatory + DESCRIPTION + "An administratively-assigned name for this + managed node. By convention, this is the node's + fully-qualified domain name." + ::= { system 5 } + + sysLocation OBJECT-TYPE + SYNTAX DisplayString (SIZE (0..255)) + ACCESS read-write + STATUS mandatory + DESCRIPTION + "The physical location of this node (e.g., + `telephone closet, 3rd floor')." + ::= { system 6 } + + sysServices OBJECT-TYPE + SYNTAX INTEGER (0..127) + ACCESS read-only + STATUS mandatory + DESCRIPTION + "A value which indicates the set of services that + this entity primarily offers. + + The value is a sum. This sum initially takes the + value zero, Then, for each layer, L, in the range + 1 through 7, that this node performs transactions + for, 2 raised to (L - 1) is added to the sum. For + example, a node which performs primarily routing + functions would have a value of 4 (2^(3-1)). In + contrast, a node which is a host offering + application services would have a value of 72 + (2^(4-1) + 2^(7-1)). Note that in the context of + the Internet suite of protocols, values should be + calculated accordingly: + + layer functionality + 1 physical (e.g., repeaters) + 2 datalink/subnetwork (e.g., bridges) + 3 internet (e.g., IP gateways) + 4 end-to-end (e.g., IP hosts) + 7 applications (e.g., mail relays) + + For systems including OSI protocols, layers 5 and + 6 may also be counted." + ::= { system 7 } + + + -- the Interfaces group + + -- Implementation of the Interfaces group is mandatory for + -- all systems. + + ifNumber OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of network interfaces (regardless of + their current state) present on this system." + ::= { interfaces 1 } + + + -- the Interfaces table + + -- The Interfaces table contains information on the entity's + -- interfaces. Each interface is thought of as being + -- attached to a `subnetwork'. Note that this term should + -- not be confused with `subnet' which refers to an + -- addressing partitioning scheme used in the Internet suite + -- of protocols. + + ifTable OBJECT-TYPE + SYNTAX SEQUENCE OF IfEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "A list of interface entries. The number of + entries is given by the value of ifNumber." + ::= { interfaces 2 } + + ifEntry OBJECT-TYPE + SYNTAX IfEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "An interface entry containing objects at the + subnetwork layer and below for a particular + interface." + INDEX { ifIndex } + ::= { ifTable 1 } + + IfEntry ::= + SEQUENCE { + ifIndex + INTEGER, + ifDescr + DisplayString, + ifType + INTEGER, + ifMtu + INTEGER, + ifSpeed + Gauge, + ifPhysAddress + PhysAddress, + ifAdminStatus + INTEGER, + ifOperStatus + INTEGER, + ifLastChange + TimeTicks, + ifInOctets + Counter, + ifInUcastPkts + Counter, + ifInNUcastPkts + Counter, + ifInDiscards + Counter, + ifInErrors + Counter, + ifInUnknownProtos + Counter, + ifOutOctets + Counter, + ifOutUcastPkts + Counter, + ifOutNUcastPkts + Counter, + ifOutDiscards + Counter, + ifOutErrors + Counter, + ifOutQLen + Gauge, + ifSpecific + OBJECT IDENTIFIER + } + + ifIndex OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "A unique value for each interface. Its value + ranges between 1 and the value of ifNumber. The + value for each interface must remain constant at + least from one re-initialization of the entity's + network management system to the next re- + initialization." + ::= { ifEntry 1 } + + ifDescr OBJECT-TYPE + SYNTAX DisplayString (SIZE (0..255)) + ACCESS read-only + STATUS mandatory + DESCRIPTION + "A textual string containing information about the + interface. This string should include the name of + the manufacturer, the product name and the version + of the hardware interface." + ::= { ifEntry 2 } + + ifType OBJECT-TYPE + SYNTAX INTEGER { + other(1), -- none of the following + regular1822(2), + hdh1822(3), + ddn-x25(4), + rfc877-x25(5), + ethernet-csmacd(6), + iso88023-csmacd(7), + iso88024-tokenBus(8), + iso88025-tokenRing(9), + iso88026-man(10), + starLan(11), + proteon-10Mbit(12), + proteon-80Mbit(13), + hyperchannel(14), + fddi(15), + lapb(16), + sdlc(17), + ds1(18), -- T-1 + e1(19), -- european equiv. of T-1 + basicISDN(20), + primaryISDN(21), -- proprietary serial + propPointToPointSerial(22), + ppp(23), + softwareLoopback(24), + eon(25), -- CLNP over IP [11] + ethernet-3Mbit(26), + nsip(27), -- XNS over IP + slip(28), -- generic SLIP + ultra(29), -- ULTRA technologies + ds3(30), -- T-3 + sip(31), -- SMDS + frame-relay(32) + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The type of interface, distinguished according to + the physical/link protocol(s) immediately `below' + the network layer in the protocol stack." + ::= { ifEntry 3 } + + ifMtu OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The size of the largest datagram which can be + sent/received on the interface, specified in + octets. For interfaces that are used for + transmitting network datagrams, this is the size + of the largest network datagram that can be sent + on the interface." + ::= { ifEntry 4 } + + ifSpeed OBJECT-TYPE + SYNTAX Gauge + ACCESS read-only + STATUS mandatory + DESCRIPTION + "An estimate of the interface's current bandwidth + in bits per second. For interfaces which do not + vary in bandwidth or for those where no accurate + estimation can be made, this object should contain + the nominal bandwidth." + ::= { ifEntry 5 } + + ifPhysAddress OBJECT-TYPE + SYNTAX PhysAddress + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The interface's address at the protocol layer + immediately `below' the network layer in the + protocol stack. For interfaces which do not have + such an address (e.g., a serial line), this object + should contain an octet string of zero length." + ::= { ifEntry 6 } + + ifAdminStatus OBJECT-TYPE + SYNTAX INTEGER { + up(1), -- ready to pass packets + down(2), + testing(3) -- in some test mode + } + ACCESS read-write + STATUS mandatory + DESCRIPTION + "The desired state of the interface. The + testing(3) state indicates that no operational + packets can be passed." + ::= { ifEntry 7 } + + ifOperStatus OBJECT-TYPE + SYNTAX INTEGER { + up(1), -- ready to pass packets + down(2), + testing(3) -- in some test mode + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The current operational state of the interface. + The testing(3) state indicates that no operational + packets can be passed." + ::= { ifEntry 8 } + + ifLastChange OBJECT-TYPE + SYNTAX TimeTicks + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The value of sysUpTime at the time the interface + entered its current operational state. If the + current state was entered prior to the last re- + initialization of the local network management + subsystem, then this object contains a zero + value." + ::= { ifEntry 9 } + + ifInOctets OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of octets received on the + interface, including framing characters." + ::= { ifEntry 10 } + + ifInUcastPkts OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of subnetwork-unicast packets + delivered to a higher-layer protocol." + ::= { ifEntry 11 } + + ifInNUcastPkts OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of non-unicast (i.e., subnetwork- + broadcast or subnetwork-multicast) packets + delivered to a higher-layer protocol." + ::= { ifEntry 12 } + + ifInDiscards OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of inbound packets which were chosen + to be discarded even though no errors had been + detected to prevent their being deliverable to a + higher-layer protocol. One possible reason for + discarding such a packet could be to free up + buffer space." + ::= { ifEntry 13 } + + ifInErrors OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of inbound packets that contained + errors preventing them from being deliverable to a + higher-layer protocol." + ::= { ifEntry 14 } + ifInUnknownProtos OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of packets received via the interface + which were discarded because of an unknown or + unsupported protocol." + ::= { ifEntry 15 } + + ifOutOctets OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of octets transmitted out of the + interface, including framing characters." + ::= { ifEntry 16 } + + ifOutUcastPkts OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of packets that higher-level + protocols requested be transmitted to a + subnetwork-unicast address, including those that + were discarded or not sent." + ::= { ifEntry 17 } + + ifOutNUcastPkts OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of packets that higher-level + protocols requested be transmitted to a non- + unicast (i.e., a subnetwork-broadcast or + subnetwork-multicast) address, including those + that were discarded or not sent." + ::= { ifEntry 18 } + + ifOutDiscards OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of outbound packets which were chosen + to be discarded even though no errors had been + detected to prevent their being transmitted. One + possible reason for discarding such a packet could + be to free up buffer space." + ::= { ifEntry 19 } + + ifOutErrors OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of outbound packets that could not be + transmitted because of errors." + ::= { ifEntry 20 } + + ifOutQLen OBJECT-TYPE + SYNTAX Gauge + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The length of the output packet queue (in + packets)." + ::= { ifEntry 21 } + + ifSpecific OBJECT-TYPE + SYNTAX OBJECT IDENTIFIER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "A reference to MIB definitions specific to the + particular media being used to realize the + interface. For example, if the interface is + realized by an ethernet, then the value of this + object refers to a document defining objects + specific to ethernet. If this information is not + present, its value should be set to the OBJECT + IDENTIFIER { 0 0 }, which is a syntatically valid + object identifier, and any conformant + implementation of ASN.1 and BER must be able to + generate and recognize this value." + ::= { ifEntry 22 } + + + -- the Address Translation group + + -- Implementation of the Address Translation group is + -- mandatory for all systems. Note however that this group + -- is deprecated by MIB-II. That is, it is being included + -- solely for compatibility with MIB-I nodes, and will most + -- likely be excluded from MIB-III nodes. From MIB-II and + -- onwards, each network protocol group contains its own + -- address translation tables. + + -- The Address Translation group contains one table which is + -- the union across all interfaces of the translation tables + -- for converting a NetworkAddress (e.g., an IP address) into + -- a subnetwork-specific address. For lack of a better term, + -- this document refers to such a subnetwork-specific address + -- as a `physical' address. + + -- Examples of such translation tables are: for broadcast + -- media where ARP is in use, the translation table is + -- equivalent to the ARP cache; or, on an X.25 network where + -- non-algorithmic translation to X.121 addresses is + -- required, the translation table contains the + -- NetworkAddress to X.121 address equivalences. + + atTable OBJECT-TYPE + SYNTAX SEQUENCE OF AtEntry + ACCESS not-accessible + STATUS deprecated + DESCRIPTION + "The Address Translation tables contain the + NetworkAddress to `physical' address equivalences. + Some interfaces do not use translation tables for + determining address equivalences (e.g., DDN-X.25 + has an algorithmic method); if all interfaces are + of this type, then the Address Translation table + is empty, i.e., has zero entries." + ::= { at 1 } + + atEntry OBJECT-TYPE + SYNTAX AtEntry + ACCESS not-accessible + STATUS deprecated + DESCRIPTION + "Each entry contains one NetworkAddress to + `physical' address equivalence." + INDEX { atIfIndex, + atNetAddress } + ::= { atTable 1 } + + AtEntry ::= + SEQUENCE { + atIfIndex + INTEGER, + atPhysAddress + PhysAddress, + atNetAddress + NetworkAddress + } + + atIfIndex OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-write + STATUS deprecated + DESCRIPTION + "The interface on which this entry's equivalence + is effective. The interface identified by a + particular value of this index is the same + interface as identified by the same value of + ifIndex." + ::= { atEntry 1 } + + atPhysAddress OBJECT-TYPE + SYNTAX PhysAddress + ACCESS read-write + STATUS deprecated + DESCRIPTION + "The media-dependent `physical' address. + + Setting this object to a null string (one of zero + length) has the effect of invaliding the + corresponding entry in the atTable object. That + is, it effectively dissasociates the interface + identified with said entry from the mapping + identified with said entry. It is an + implementation-specific matter as to whether the + agent removes an invalidated entry from the table. + Accordingly, management stations must be prepared + to receive tabular information from agents that + corresponds to entries not currently in use. + Proper interpretation of such entries requires + examination of the relevant atPhysAddress object." + ::= { atEntry 2 } + + atNetAddress OBJECT-TYPE + SYNTAX NetworkAddress + ACCESS read-write + STATUS deprecated + DESCRIPTION + "The NetworkAddress (e.g., the IP address) + corresponding to the media-dependent `physical' + address." + ::= { atEntry 3 } + + + -- the IP group + + -- Implementation of the IP group is mandatory for all + -- systems. + + ipForwarding OBJECT-TYPE + SYNTAX INTEGER { + forwarding(1), -- acting as a gateway + not-forwarding(2) -- NOT acting as a gateway + } + ACCESS read-write + STATUS mandatory + DESCRIPTION + "The indication of whether this entity is acting + as an IP gateway in respect to the forwarding of + datagrams received by, but not addressed to, this + entity. IP gateways forward datagrams. IP hosts + do not (except those source-routed via the host). + + Note that for some managed nodes, this object may + take on only a subset of the values possible. + Accordingly, it is appropriate for an agent to + return a `badValue' response if a management + station attempts to change this object to an + inappropriate value." + ::= { ip 1 } + + ipDefaultTTL OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-write + STATUS mandatory + DESCRIPTION + "The default value inserted into the Time-To-Live + field of the IP header of datagrams originated at + this entity, whenever a TTL value is not supplied + by the transport layer protocol." + ::= { ip 2 } + + ipInReceives OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of input datagrams received from + interfaces, including those received in error." + ::= { ip 3 } + + ipInHdrErrors OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of input datagrams discarded due to + errors in their IP headers, including bad + checksums, version number mismatch, other format + errors, time-to-live exceeded, errors discovered + in processing their IP options, etc." + ::= { ip 4 } + + ipInAddrErrors OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of input datagrams discarded because + the IP address in their IP header's destination + field was not a valid address to be received at + this entity. This count includes invalid + addresses (e.g., 0.0.0.0) and addresses of + unsupported Classes (e.g., Class E). For entities + which are not IP Gateways and therefore do not + forward datagrams, this counter includes datagrams + discarded because the destination address was not + a local address." + ::= { ip 5 } + + ipForwDatagrams OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of input datagrams for which this + entity was not their final IP destination, as a + result of which an attempt was made to find a + route to forward them to that final destination. + In entities which do not act as IP Gateways, this + counter will include only those packets which were + Source-Routed via this entity, and the Source- + Route option processing was successful." + ::= { ip 6 } + + ipInUnknownProtos OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of locally-addressed datagrams + received successfully but discarded because of an + unknown or unsupported protocol." + ::= { ip 7 } + + ipInDiscards OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of input IP datagrams for which no + problems were encountered to prevent their + continued processing, but which were discarded + (e.g., for lack of buffer space). Note that this + counter does not include any datagrams discarded + while awaiting re-assembly." + ::= { ip 8 } + + ipInDelivers OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of input datagrams successfully + delivered to IP user-protocols (including ICMP)." + ::= { ip 9 } + + ipOutRequests OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of IP datagrams which local IP + user-protocols (including ICMP) supplied to IP in + requests for transmission. Note that this counter + does not include any datagrams counted in + ipForwDatagrams." + ::= { ip 10 } + + ipOutDiscards OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of output IP datagrams for which no + problem was encountered to prevent their + transmission to their destination, but which were + discarded (e.g., for lack of buffer space). Note + that this counter would include datagrams counted + in ipForwDatagrams if any such packets met this + (discretionary) discard criterion." + ::= { ip 11 } + + ipOutNoRoutes OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of IP datagrams discarded because no + route could be found to transmit them to their + destination. Note that this counter includes any + packets counted in ipForwDatagrams which meet this + `no-route' criterion. Note that this includes any + datagarms which a host cannot route because all of + its default gateways are down." + ::= { ip 12 } + + ipReasmTimeout OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The maximum number of seconds which received + fragments are held while they are awaiting + reassembly at this entity." + ::= { ip 13 } + + ipReasmReqds OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of IP fragments received which needed + to be reassembled at this entity." + ::= { ip 14 } + + ipReasmOKs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of IP datagrams successfully re- + assembled." + ::= { ip 15 } + + ipReasmFails OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of failures detected by the IP re- + assembly algorithm (for whatever reason: timed + out, errors, etc). Note that this is not + necessarily a count of discarded IP fragments + since some algorithms (notably the algorithm in + RFC 815) can lose track of the number of fragments + by combining them as they are received." + ::= { ip 16 } + + ipFragOKs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of IP datagrams that have been + successfully fragmented at this entity." + ::= { ip 17 } + + ipFragFails OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of IP datagrams that have been + discarded because they needed to be fragmented at + this entity but could not be, e.g., because their + Don't Fragment flag was set." + ::= { ip 18 } + + ipFragCreates OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of IP datagram fragments that have + been generated as a result of fragmentation at + this entity." + ::= { ip 19 } + + -- the IP address table + + -- The IP address table contains this entity's IP addressing + -- information. + + ipAddrTable OBJECT-TYPE + SYNTAX SEQUENCE OF IpAddrEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "The table of addressing information relevant to + this entity's IP addresses." + ::= { ip 20 } + + ipAddrEntry OBJECT-TYPE + SYNTAX IpAddrEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "The addressing information for one of this + entity's IP addresses." + INDEX { ipAdEntAddr } + ::= { ipAddrTable 1 } + + IpAddrEntry ::= + SEQUENCE { + ipAdEntAddr + IpAddress, + ipAdEntIfIndex + INTEGER, + ipAdEntNetMask + IpAddress, + ipAdEntBcastAddr + INTEGER, + ipAdEntReasmMaxSize + INTEGER (0..65535) + } + + ipAdEntAddr OBJECT-TYPE + SYNTAX IpAddress + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The IP address to which this entry's addressing + information pertains." + ::= { ipAddrEntry 1 } + + ipAdEntIfIndex OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The index value which uniquely identifies the + interface to which this entry is applicable. The + interface identified by a particular value of this + index is the same interface as identified by the + same value of ifIndex." + ::= { ipAddrEntry 2 } + + ipAdEntNetMask OBJECT-TYPE + SYNTAX IpAddress + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The subnet mask associated with the IP address of + this entry. The value of the mask is an IP + address with all the network bits set to 1 and all + the hosts bits set to 0." + ::= { ipAddrEntry 3 } + + ipAdEntBcastAddr OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The value of the least-significant bit in the IP + broadcast address used for sending datagrams on + the (logical) interface associated with the IP + address of this entry. For example, when the + Internet standard all-ones broadcast address is + used, the value will be 1. This value applies to + both the subnet and network broadcasts addresses + used by the entity on this (logical) interface." + ::= { ipAddrEntry 4 } + + ipAdEntReasmMaxSize OBJECT-TYPE + SYNTAX INTEGER (0..65535) + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The size of the largest IP datagram which this + entity can re-assemble from incoming IP fragmented + datagrams received on this interface." + ::= { ipAddrEntry 5 } + + -- the IP routing table + + -- The IP routing table contains an entry for each route + -- presently known to this entity. + + ipRouteTable OBJECT-TYPE + SYNTAX SEQUENCE OF IpRouteEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "This entity's IP Routing table." + ::= { ip 21 } + + ipRouteEntry OBJECT-TYPE + SYNTAX IpRouteEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "A route to a particular destination." + INDEX { ipRouteDest } + ::= { ipRouteTable 1 } + + IpRouteEntry ::= + SEQUENCE { + ipRouteDest + IpAddress, + ipRouteIfIndex + INTEGER, + ipRouteMetric1 + INTEGER, + ipRouteMetric2 + INTEGER, + ipRouteMetric3 + INTEGER, + ipRouteMetric4 + INTEGER, + ipRouteNextHop + IpAddress, + ipRouteType + INTEGER, + ipRouteProto + INTEGER, + ipRouteAge + INTEGER, + ipRouteMask + IpAddress, + ipRouteMetric5 + INTEGER, + ipRouteInfo + OBJECT IDENTIFIER + } + + ipRouteDest OBJECT-TYPE + SYNTAX IpAddress + ACCESS read-write + STATUS mandatory + DESCRIPTION + "The destination IP address of this route. An + entry with a value of 0.0.0.0 is considered a + default route. Multiple routes to a single + destination can appear in the table, but access to + such multiple entries is dependent on the table- + access mechanisms defined by the network + management protocol in use." + ::= { ipRouteEntry 1 } + + ipRouteIfIndex OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-write + STATUS mandatory + DESCRIPTION + "The index value which uniquely identifies the + local interface through which the next hop of this + route should be reached. The interface identified + by a particular value of this index is the same + interface as identified by the same value of + ifIndex." + ::= { ipRouteEntry 2 } + + ipRouteMetric1 OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-write + STATUS mandatory + DESCRIPTION + "The primary routing metric for this route. The + semantics of this metric are determined by the + routing-protocol specified in the route's + ipRouteProto value. If this metric is not used, + its value should be set to -1." + ::= { ipRouteEntry 3 } + + ipRouteMetric2 OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-write + STATUS mandatory + DESCRIPTION + "An alternate routing metric for this route. The + semantics of this metric are determined by the + routing-protocol specified in the route's + ipRouteProto value. If this metric is not used, + its value should be set to -1." + ::= { ipRouteEntry 4 } + + ipRouteMetric3 OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-write + STATUS mandatory + DESCRIPTION + "An alternate routing metric for this route. The + semantics of this metric are determined by the + routing-protocol specified in the route's + ipRouteProto value. If this metric is not used, + its value should be set to -1." + ::= { ipRouteEntry 5 } + + ipRouteMetric4 OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-write + STATUS mandatory + DESCRIPTION + "An alternate routing metric for this route. The + semantics of this metric are determined by the + routing-protocol specified in the route's + ipRouteProto value. If this metric is not used, + its value should be set to -1." + ::= { ipRouteEntry 6 } + + ipRouteNextHop OBJECT-TYPE + SYNTAX IpAddress + ACCESS read-write + STATUS mandatory + DESCRIPTION + "The IP address of the next hop of this route. + (In the case of a route bound to an interface + which is realized via a broadcast media, the value + of this field is the agent's IP address on that + interface.)" + ::= { ipRouteEntry 7 } + + ipRouteType OBJECT-TYPE + SYNTAX INTEGER { + other(1), -- none of the following + + invalid(2), -- an invalidated route + -- route to directly + + direct(3), -- connected (sub-)network + + -- route to a non-local + indirect(4) -- host/network/sub-network + } + ACCESS read-write + STATUS mandatory + DESCRIPTION + "The type of route. Note that the values + direct(3) and indirect(4) refer to the notion of + direct and indirect routing in the IP + architecture. + + Setting this object to the value invalid(2) has + the effect of invalidating the corresponding entry + in the ipRouteTable object. That is, it + effectively dissasociates the destination + identified with said entry from the route + identified with said entry. It is an + implementation-specific matter as to whether the + agent removes an invalidated entry from the table. + Accordingly, management stations must be prepared + to receive tabular information from agents that + corresponds to entries not currently in use. + Proper interpretation of such entries requires + examination of the relevant ipRouteType object." + ::= { ipRouteEntry 8 } + + ipRouteProto OBJECT-TYPE + SYNTAX INTEGER { + other(1), -- none of the following + + -- non-protocol information, + -- e.g., manually configured + local(2), -- entries + + -- set via a network + netmgmt(3), -- management protocol + + -- obtained via ICMP, + icmp(4), -- e.g., Redirect + + -- the remaining values are + -- all gateway routing + -- protocols + egp(5), + ggp(6), + hello(7), + rip(8), + is-is(9), + es-is(10), + ciscoIgrp(11), + bbnSpfIgp(12), + ospf(13), + bgp(14) + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The routing mechanism via which this route was + learned. Inclusion of values for gateway routing + protocols is not intended to imply that hosts + should support those protocols." + ::= { ipRouteEntry 9 } + + ipRouteAge OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-write + STATUS mandatory + DESCRIPTION + "The number of seconds since this route was last + updated or otherwise determined to be correct. + Note that no semantics of `too old' can be implied + except through knowledge of the routing protocol + by which the route was learned." + ::= { ipRouteEntry 10 } + + ipRouteMask OBJECT-TYPE + SYNTAX IpAddress + ACCESS read-write + STATUS mandatory + DESCRIPTION + "Indicate the mask to be logical-ANDed with the + destination address before being compared to the + value in the ipRouteDest field. For those systems + that do not support arbitrary subnet masks, an + agent constructs the value of the ipRouteMask by + determining whether the value of the correspondent + ipRouteDest field belong to a class-A, B, or C + network, and then using one of: + + mask network + 255.0.0.0 class-A + 255.255.0.0 class-B + 255.255.255.0 class-C + + If the value of the ipRouteDest is 0.0.0.0 (a + default route), then the mask value is also + 0.0.0.0. It should be noted that all IP routing + subsystems implicitly use this mechanism." + ::= { ipRouteEntry 11 } + + ipRouteMetric5 OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-write + STATUS mandatory + DESCRIPTION + "An alternate routing metric for this route. The + semantics of this metric are determined by the + routing-protocol specified in the route's + ipRouteProto value. If this metric is not used, + its value should be set to -1." + ::= { ipRouteEntry 12 } + + ipRouteInfo OBJECT-TYPE + SYNTAX OBJECT IDENTIFIER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "A reference to MIB definitions specific to the + particular routing protocol which is responsible + for this route, as determined by the value + specified in the route's ipRouteProto value. If + this information is not present, its value should + be set to the OBJECT IDENTIFIER { 0 0 }, which is + a syntatically valid object identifier, and any + conformant implementation of ASN.1 and BER must be + able to generate and recognize this value." + ::= { ipRouteEntry 13 } + + + -- the IP Address Translation table + + -- The IP address translation table contain the IpAddress to + -- `physical' address equivalences. Some interfaces do not + -- use translation tables for determining address + -- equivalences (e.g., DDN-X.25 has an algorithmic method); + -- if all interfaces are of this type, then the Address + -- Translation table is empty, i.e., has zero entries. + + ipNetToMediaTable OBJECT-TYPE + SYNTAX SEQUENCE OF IpNetToMediaEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "The IP Address Translation table used for mapping + from IP addresses to physical addresses." + ::= { ip 22 } + + ipNetToMediaEntry OBJECT-TYPE + SYNTAX IpNetToMediaEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "Each entry contains one IpAddress to `physical' + address equivalence." + INDEX { ipNetToMediaIfIndex, + ipNetToMediaNetAddress } + ::= { ipNetToMediaTable 1 } + + IpNetToMediaEntry ::= + SEQUENCE { + ipNetToMediaIfIndex + INTEGER, + ipNetToMediaPhysAddress + PhysAddress, + ipNetToMediaNetAddress + IpAddress, + ipNetToMediaType + INTEGER + } + + ipNetToMediaIfIndex OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-write + STATUS mandatory + DESCRIPTION + "The interface on which this entry's equivalence + is effective. The interface identified by a + particular value of this index is the same + interface as identified by the same value of + ifIndex." + ::= { ipNetToMediaEntry 1 } + + ipNetToMediaPhysAddress OBJECT-TYPE + SYNTAX PhysAddress + ACCESS read-write + STATUS mandatory + DESCRIPTION + "The media-dependent `physical' address." + ::= { ipNetToMediaEntry 2 } + + ipNetToMediaNetAddress OBJECT-TYPE + SYNTAX IpAddress + ACCESS read-write + STATUS mandatory + DESCRIPTION + "The IpAddress corresponding to the media- + dependent `physical' address." + ::= { ipNetToMediaEntry 3 } + + ipNetToMediaType OBJECT-TYPE + SYNTAX INTEGER { + other(1), -- none of the following + invalid(2), -- an invalidated mapping + dynamic(3), + static(4) + } + ACCESS read-write + STATUS mandatory + DESCRIPTION + "The type of mapping. + + Setting this object to the value invalid(2) has + the effect of invalidating the corresponding entry + in the ipNetToMediaTable. That is, it effectively + dissasociates the interface identified with said + entry from the mapping identified with said entry. + It is an implementation-specific matter as to + whether the agent removes an invalidated entry + from the table. Accordingly, management stations + must be prepared to receive tabular information + from agents that corresponds to entries not + currently in use. Proper interpretation of such + entries requires examination of the relevant + ipNetToMediaType object." + ::= { ipNetToMediaEntry 4 } + + + -- additional IP objects + + ipRoutingDiscards OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of routing entries which were chosen + to be discarded even though they are valid. One + possible reason for discarding such an entry could + be to free-up buffer space for other routing + entries." + ::= { ip 23 } + + + -- the ICMP group + + -- Implementation of the ICMP group is mandatory for all + -- systems. + + icmpInMsgs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of ICMP messages which the + entity received. Note that this counter includes + all those counted by icmpInErrors." + ::= { icmp 1 } + + icmpInErrors OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP messages which the entity + received but determined as having ICMP-specific + errors (bad ICMP checksums, bad length, etc.)." + ::= { icmp 2 } + + icmpInDestUnreachs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Destination Unreachable + messages received." + ::= { icmp 3 } + + icmpInTimeExcds OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Time Exceeded messages + received." + ::= { icmp 4 } + + icmpInParmProbs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Parameter Problem messages + received." + ::= { icmp 5 } + + icmpInSrcQuenchs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Source Quench messages + received." + ::= { icmp 6 } + + icmpInRedirects OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Redirect messages received." + ::= { icmp 7 } + + icmpInEchos OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Echo (request) messages + received." + ::= { icmp 8 } + + icmpInEchoReps OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Echo Reply messages received." + ::= { icmp 9 } + + icmpInTimestamps OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Timestamp (request) messages + received." + ::= { icmp 10 } + + icmpInTimestampReps OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Timestamp Reply messages + received." + ::= { icmp 11 } + + icmpInAddrMasks OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Address Mask Request messages + received." + ::= { icmp 12 } + + icmpInAddrMaskReps OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Address Mask Reply messages + received." + ::= { icmp 13 } + + icmpOutMsgs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of ICMP messages which this + entity attempted to send. Note that this counter + includes all those counted by icmpOutErrors." + ::= { icmp 14 } + + icmpOutErrors OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP messages which this entity did + not send due to problems discovered within ICMP + such as a lack of buffers. This value should not + include errors discovered outside the ICMP layer + such as the inability of IP to route the resultant + datagram. In some implementations there may be no + types of error which contribute to this counter's + value." + ::= { icmp 15 } + + icmpOutDestUnreachs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Destination Unreachable + messages sent." + ::= { icmp 16 } + + icmpOutTimeExcds OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Time Exceeded messages sent." + ::= { icmp 17 } + + icmpOutParmProbs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Parameter Problem messages + sent." + ::= { icmp 18 } + + icmpOutSrcQuenchs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Source Quench messages sent." + ::= { icmp 19 } + + icmpOutRedirects OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Redirect messages sent. For a + host, this object will always be zero, since hosts + do not send redirects." + ::= { icmp 20 } + + icmpOutEchos OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Echo (request) messages sent." + ::= { icmp 21 } + + icmpOutEchoReps OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Echo Reply messages sent." + ::= { icmp 22 } + + icmpOutTimestamps OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Timestamp (request) messages + sent." + ::= { icmp 23 } + + icmpOutTimestampReps OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Timestamp Reply messages + sent." + ::= { icmp 24 } + + icmpOutAddrMasks OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Address Mask Request messages + sent." + ::= { icmp 25 } + + icmpOutAddrMaskReps OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of ICMP Address Mask Reply messages + sent." + ::= { icmp 26 } + + + -- the TCP group + + -- Implementation of the TCP group is mandatory for all + -- systems that implement the TCP. + + -- Note that instances of object types that represent + -- information about a particular TCP connection are + -- transient; they persist only as long as the connection + -- in question. + + tcpRtoAlgorithm OBJECT-TYPE + SYNTAX INTEGER { + other(1), -- none of the following + + constant(2), -- a constant rto + rsre(3), -- MIL-STD-1778, Appendix B + vanj(4) -- Van Jacobson's algorithm [10] + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The algorithm used to determine the timeout value + used for retransmitting unacknowledged octets." + ::= { tcp 1 } + + tcpRtoMin OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The minimum value permitted by a TCP + implementation for the retransmission timeout, + measured in milliseconds. More refined semantics + for objects of this type depend upon the algorithm + used to determine the retransmission timeout. In + particular, when the timeout algorithm is rsre(3), + an object of this type has the semantics of the + LBOUND quantity described in RFC 793." + ::= { tcp 2 } + + + tcpRtoMax OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The maximum value permitted by a TCP + implementation for the retransmission timeout, + measured in milliseconds. More refined semantics + for objects of this type depend upon the algorithm + used to determine the retransmission timeout. In + particular, when the timeout algorithm is rsre(3), + an object of this type has the semantics of the + UBOUND quantity described in RFC 793." + ::= { tcp 3 } + + tcpMaxConn OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The limit on the total number of TCP connections + the entity can support. In entities where the + maximum number of connections is dynamic, this + object should contain the value -1." + ::= { tcp 4 } + + tcpActiveOpens OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of times TCP connections have made a + direct transition to the SYN-SENT state from the + CLOSED state." + ::= { tcp 5 } + + tcpPassiveOpens OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of times TCP connections have made a + direct transition to the SYN-RCVD state from the + LISTEN state." + ::= { tcp 6 } + + tcpAttemptFails OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of times TCP connections have made a + direct transition to the CLOSED state from either + the SYN-SENT state or the SYN-RCVD state, plus the + number of times TCP connections have made a direct + transition to the LISTEN state from the SYN-RCVD + state." + ::= { tcp 7 } + + tcpEstabResets OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of times TCP connections have made a + direct transition to the CLOSED state from either + the ESTABLISHED state or the CLOSE-WAIT state." + ::= { tcp 8 } + + tcpCurrEstab OBJECT-TYPE + SYNTAX Gauge + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of TCP connections for which the + current state is either ESTABLISHED or CLOSE- + WAIT." + ::= { tcp 9 } + + tcpInSegs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of segments received, including + those received in error. This count includes + segments received on currently established + connections." + ::= { tcp 10 } + + tcpOutSegs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of segments sent, including + those on current connections but excluding those + containing only retransmitted octets." + ::= { tcp 11 } + + tcpRetransSegs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of segments retransmitted - that + is, the number of TCP segments transmitted + containing one or more previously transmitted + octets." + ::= { tcp 12 } + + + -- the TCP Connection table + + -- The TCP connection table contains information about this + -- entity's existing TCP connections. + + tcpConnTable OBJECT-TYPE + SYNTAX SEQUENCE OF TcpConnEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "A table containing TCP connection-specific + information." + ::= { tcp 13 } + + tcpConnEntry OBJECT-TYPE + SYNTAX TcpConnEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "Information about a particular current TCP + connection. An object of this type is transient, + in that it ceases to exist when (or soon after) + the connection makes the transition to the CLOSED + state." + INDEX { tcpConnLocalAddress, + tcpConnLocalPort, + tcpConnRemAddress, + tcpConnRemPort } + ::= { tcpConnTable 1 } + + TcpConnEntry ::= + SEQUENCE { + tcpConnState + INTEGER, + tcpConnLocalAddress + IpAddress, + tcpConnLocalPort + INTEGER (0..65535), + tcpConnRemAddress + IpAddress, + tcpConnRemPort + INTEGER (0..65535) + } + + tcpConnState OBJECT-TYPE + SYNTAX INTEGER { + closed(1), + listen(2), + synSent(3), + synReceived(4), + established(5), + finWait1(6), + finWait2(7), + closeWait(8), + lastAck(9), + closing(10), + timeWait(11), + deleteTCB(12) + } + ACCESS read-write + STATUS mandatory + DESCRIPTION + "The state of this TCP connection. + + The only value which may be set by a management + station is deleteTCB(12). Accordingly, it is + appropriate for an agent to return a `badValue' + response if a management station attempts to set + this object to any other value. + + If a management station sets this object to the + value deleteTCB(12), then this has the effect of + deleting the TCB (as defined in RFC 793) of the + corresponding connection on the managed node, + resulting in immediate termination of the + connection. + + As an implementation-specific option, a RST + segment may be sent from the managed node to the + other TCP endpoint (note however that RST segments + are not sent reliably)." + ::= { tcpConnEntry 1 } + + tcpConnLocalAddress OBJECT-TYPE + SYNTAX IpAddress + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The local IP address for this TCP connection. In + the case of a connection in the listen state which + is willing to accept connections for any IP + interface associated with the node, the value + 0.0.0.0 is used." + ::= { tcpConnEntry 2 } + + tcpConnLocalPort OBJECT-TYPE + SYNTAX INTEGER (0..65535) + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The local port number for this TCP connection." + ::= { tcpConnEntry 3 } + + tcpConnRemAddress OBJECT-TYPE + SYNTAX IpAddress + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The remote IP address for this TCP connection." + ::= { tcpConnEntry 4 } + + tcpConnRemPort OBJECT-TYPE + SYNTAX INTEGER (0..65535) + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The remote port number for this TCP connection." + ::= { tcpConnEntry 5 } + + + -- additional TCP objects + + tcpInErrs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of segments received in error + (e.g., bad TCP checksums)." + ::= { tcp 14 } + + tcpOutRsts OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of TCP segments sent containing the + RST flag." + ::= { tcp 15 } + + + -- the UDP group + + -- Implementation of the UDP group is mandatory for all + -- systems which implement the UDP. + + udpInDatagrams OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of UDP datagrams delivered to + UDP users." + ::= { udp 1 } + + udpNoPorts OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of received UDP datagrams for + which there was no application at the destination + port." + ::= { udp 2 } + + udpInErrors OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of received UDP datagrams that could + not be delivered for reasons other than the lack + of an application at the destination port." + ::= { udp 3 } + + udpOutDatagrams OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of UDP datagrams sent from this + entity." + ::= { udp 4 } + + + -- the UDP Listener table + + -- The UDP listener table contains information about this + -- entity's UDP end-points on which a local application is + -- currently accepting datagrams. + + udpTable OBJECT-TYPE + SYNTAX SEQUENCE OF UdpEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "A table containing UDP listener information." + ::= { udp 5 } + + udpEntry OBJECT-TYPE + SYNTAX UdpEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "Information about a particular current UDP + listener." + INDEX { udpLocalAddress, udpLocalPort } + ::= { udpTable 1 } + + UdpEntry ::= + SEQUENCE { + udpLocalAddress + IpAddress, + udpLocalPort + INTEGER (0..65535) + } + + udpLocalAddress OBJECT-TYPE + SYNTAX IpAddress + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The local IP address for this UDP listener. In + the case of a UDP listener which is willing to + accept datagrams for any IP interface associated + with the node, the value 0.0.0.0 is used." + ::= { udpEntry 1 } + + udpLocalPort OBJECT-TYPE + SYNTAX INTEGER (0..65535) + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The local port number for this UDP listener." + ::= { udpEntry 2 } + + + -- the EGP group + + -- Implementation of the EGP group is mandatory for all + -- systems which implement the EGP. + + egpInMsgs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of EGP messages received without + error." + ::= { egp 1 } + + egpInErrors OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of EGP messages received that proved + to be in error." + ::= { egp 2 } + + egpOutMsgs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of locally generated EGP + messages." + ::= { egp 3 } + + egpOutErrors OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of locally generated EGP messages not + sent due to resource limitations within an EGP + entity." + ::= { egp 4 } + + + -- the EGP Neighbor table + + -- The EGP neighbor table contains information about this + -- entity's EGP neighbors. + + egpNeighTable OBJECT-TYPE + SYNTAX SEQUENCE OF EgpNeighEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "The EGP neighbor table." + ::= { egp 5 } + + egpNeighEntry OBJECT-TYPE + SYNTAX EgpNeighEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "Information about this entity's relationship with + a particular EGP neighbor." + INDEX { egpNeighAddr } + ::= { egpNeighTable 1 } + + EgpNeighEntry ::= + SEQUENCE { + egpNeighState + INTEGER, + egpNeighAddr + IpAddress, + egpNeighAs + INTEGER, + egpNeighInMsgs + Counter, + egpNeighInErrs + Counter, + egpNeighOutMsgs + Counter, + egpNeighOutErrs + Counter, + egpNeighInErrMsgs + Counter, + egpNeighOutErrMsgs + Counter, + egpNeighStateUps + Counter, + egpNeighStateDowns + Counter, + egpNeighIntervalHello + INTEGER, + egpNeighIntervalPoll + INTEGER, + egpNeighMode + INTEGER, + egpNeighEventTrigger + INTEGER + } + + egpNeighState OBJECT-TYPE + SYNTAX INTEGER { + idle(1), + acquisition(2), + down(3), + up(4), + cease(5) + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The EGP state of the local system with respect to + this entry's EGP neighbor. Each EGP state is + represented by a value that is one greater than + the numerical value associated with said state in + RFC 904." + ::= { egpNeighEntry 1 } + + egpNeighAddr OBJECT-TYPE + SYNTAX IpAddress + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The IP address of this entry's EGP neighbor." + ::= { egpNeighEntry 2 } + + egpNeighAs OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The autonomous system of this EGP peer. Zero + should be specified if the autonomous system + number of the neighbor is not yet known." + ::= { egpNeighEntry 3 } + + egpNeighInMsgs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of EGP messages received without error + from this EGP peer." + ::= { egpNeighEntry 4 } + + egpNeighInErrs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of EGP messages received from this EGP + peer that proved to be in error (e.g., bad EGP + checksum)." + ::= { egpNeighEntry 5 } + + egpNeighOutMsgs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of locally generated EGP messages to + this EGP peer." + ::= { egpNeighEntry 6 } + + egpNeighOutErrs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of locally generated EGP messages not + sent to this EGP peer due to resource limitations + within an EGP entity." + ::= { egpNeighEntry 7 } + + egpNeighInErrMsgs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of EGP-defined error messages received + from this EGP peer." + ::= { egpNeighEntry 8 } + + egpNeighOutErrMsgs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of EGP-defined error messages sent to + this EGP peer." + ::= { egpNeighEntry 9 } + + egpNeighStateUps OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of EGP state transitions to the UP + state with this EGP peer." + ::= { egpNeighEntry 10 } + + egpNeighStateDowns OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The number of EGP state transitions from the UP + state to any other state with this EGP peer." + ::= { egpNeighEntry 11 } + + egpNeighIntervalHello OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The interval between EGP Hello command + retransmissions (in hundredths of a second). This + represents the t1 timer as defined in RFC 904." + ::= { egpNeighEntry 12 } + + egpNeighIntervalPoll OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The interval between EGP poll command + retransmissions (in hundredths of a second). This + represents the t3 timer as defined in RFC 904." + ::= { egpNeighEntry 13 } + + egpNeighMode OBJECT-TYPE + SYNTAX INTEGER { active(1), passive(2) } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The polling mode of this EGP entity, either + passive or active." + ::= { egpNeighEntry 14 } + + egpNeighEventTrigger OBJECT-TYPE + SYNTAX INTEGER { start(1), stop(2) } + ACCESS read-write + STATUS mandatory + DESCRIPTION + "A control variable used to trigger operator- + initiated Start and Stop events. When read, this + variable always returns the most recent value that + egpNeighEventTrigger was set to. If it has not + been set since the last initialization of the + network management subsystem on the node, it + returns a value of `stop'. + + When set, this variable causes a Start or Stop + event on the specified neighbor, as specified on + pages 8-10 of RFC 904. Briefly, a Start event + causes an Idle peer to begin neighbor acquisition + and a non-Idle peer to reinitiate neighbor + acquisition. A stop event causes a non-Idle peer + to return to the Idle state until a Start event + occurs, either via egpNeighEventTrigger or + otherwise." + ::= { egpNeighEntry 15 } + + + -- additional EGP objects + + egpAs OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The autonomous system number of this EGP entity." + ::= { egp 6 } + + + -- the Transmission group + + -- Based on the transmission media underlying each interface + -- on a system, the corresponding portion of the Transmission + -- group is mandatory for that system. + + -- When Internet-standard definitions for managing + -- transmission media are defined, the transmission group is + -- used to provide a prefix for the names of those objects. + + -- Typically, such definitions reside in the experimental + -- portion of the MIB until they are "proven", then as a + -- part of the Internet standardization process, the + -- definitions are accordingly elevated and a new object + -- identifier, under the transmission group is defined. By + -- convention, the name assigned is: + -- + -- type OBJECT IDENTIFIER ::= { transmission number } + -- + -- where "type" is the symbolic value used for the media in + -- the ifType column of the ifTable object, and "number" is + -- the actual integer value corresponding to the symbol. + + + -- the SNMP group + + -- Implementation of the SNMP group is mandatory for all + -- systems which support an SNMP protocol entity. Some of + -- the objects defined below will be zero-valued in those + -- SNMP implementations that are optimized to support only + -- those functions specific to either a management agent or + -- a management station. In particular, it should be + -- observed that the objects below refer to an SNMP entity, + -- and there may be several SNMP entities residing on a + -- managed node (e.g., if the node is hosting acting as + -- a management station). + + snmpInPkts OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of Messages delivered to the + SNMP entity from the transport service." + ::= { snmp 1 } + + snmpOutPkts OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP Messages which were + passed from the SNMP protocol entity to the + transport service." + ::= { snmp 2 } + + snmpInBadVersions OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP Messages which were + delivered to the SNMP protocol entity and were for + an unsupported SNMP version." + ::= { snmp 3 } + + snmpInBadCommunityNames OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP Messages delivered to + the SNMP protocol entity which used a SNMP + community name not known to said entity." + ::= { snmp 4 } + + snmpInBadCommunityUses OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP Messages delivered to + the SNMP protocol entity which represented an SNMP + operation which was not allowed by the SNMP + community named in the Message." + ::= { snmp 5 } + + snmpInASNParseErrs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of ASN.1 or BER errors + encountered by the SNMP protocol entity when + decoding received SNMP Messages." + ::= { snmp 6 } + + -- { snmp 7 } is not used in rfc1213, but MIBII.mdl had one :( + snmpInBadTypes OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Total number of PDUs having an unknown PDU type" + ::= { snmp 7 } + + snmpInTooBigs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP PDUs which were + delivered to the SNMP protocol entity and for + which the value of the error-status field is + `tooBig'." + ::= { snmp 8 } + + snmpInNoSuchNames OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP PDUs which were + delivered to the SNMP protocol entity and for + which the value of the error-status field is + `noSuchName'." + ::= { snmp 9 } + + snmpInBadValues OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP PDUs which were + delivered to the SNMP protocol entity and for + which the value of the error-status field is + `badValue'." + ::= { snmp 10 } + + snmpInReadOnlys OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number valid SNMP PDUs which were + delivered to the SNMP protocol entity and for + which the value of the error-status field is + `readOnly'. It should be noted that it is a + protocol error to generate an SNMP PDU which + contains the value `readOnly' in the error-status + field, as such this object is provided as a means + of detecting incorrect implementations of the + SNMP." + ::= { snmp 11 } + + snmpInGenErrs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP PDUs which were + delivered to the SNMP protocol entity and for + which the value of the error-status field is + `genErr'." + ::= { snmp 12 } + + snmpInTotalReqVars OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of MIB objects which have been + retrieved successfully by the SNMP protocol entity + as the result of receiving valid SNMP Get-Request + and Get-Next PDUs." + ::= { snmp 13 } + + snmpInTotalSetVars OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of MIB objects which have been + altered successfully by the SNMP protocol entity + as the result of receiving valid SNMP Set-Request + PDUs." + ::= { snmp 14 } + + snmpInGetRequests OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP Get-Request PDUs which + have been accepted and processed by the SNMP + protocol entity." + ::= { snmp 15 } + + snmpInGetNexts OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP Get-Next PDUs which have + been accepted and processed by the SNMP protocol + entity." + ::= { snmp 16 } + + snmpInSetRequests OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP Set-Request PDUs which + have been accepted and processed by the SNMP + protocol entity." + ::= { snmp 17 } + + snmpInGetResponses OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP Get-Response PDUs which + have been accepted and processed by the SNMP + protocol entity." + ::= { snmp 18 } + + snmpInTraps OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP Trap PDUs which have + been accepted and processed by the SNMP protocol + entity." + ::= { snmp 19 } + + snmpOutTooBigs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP PDUs which were + generated by the SNMP protocol entity and for + which the value of the error-status field is + `tooBig.'" + ::= { snmp 20 } + + snmpOutNoSuchNames OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP PDUs which were + generated by the SNMP protocol entity and for + which the value of the error-status is + `noSuchName'." + ::= { snmp 21 } + + snmpOutBadValues OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP PDUs which were + generated by the SNMP protocol entity and for + which the value of the error-status field is + `badValue'." + ::= { snmp 22 } + + -- { snmp 23 } is not used in rfc1213, but MIBII.mdl had one :( + snmpOutReadOnlys OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP PDUs which were + generated by the SNMP protocol entity and for + which the value of the error-status field is + `readOnly'." + ::= { snmp 23 } + + snmpOutGenErrs OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP PDUs which were + generated by the SNMP protocol entity and for + which the value of the error-status field is + `genErr'." + ::= { snmp 24 } + + snmpOutGetRequests OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP Get-Request PDUs which + have been generated by the SNMP protocol entity." + ::= { snmp 25 } + + snmpOutGetNexts OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP Get-Next PDUs which have + been generated by the SNMP protocol entity." + ::= { snmp 26 } + + snmpOutSetRequests OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP Set-Request PDUs which + have been generated by the SNMP protocol entity." + ::= { snmp 27 } + + snmpOutGetResponses OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP Get-Response PDUs which + have been generated by the SNMP protocol entity." + ::= { snmp 28 } + + snmpOutTraps OBJECT-TYPE + SYNTAX Counter + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total number of SNMP Trap PDUs which have + been generated by the SNMP protocol entity." + ::= { snmp 29 } + + snmpEnableAuthenTraps OBJECT-TYPE + SYNTAX INTEGER { enabled(1), disabled(2) } + ACCESS read-write + STATUS mandatory + DESCRIPTION + "Indicates whether the SNMP agent process is + permitted to generate authentication-failure + traps. The value of this object overrides any + configuration information; as such, it provides a + means whereby all authentication-failure traps may + be disabled. + + Note that it is strongly recommended that this + object be stored in non-volatile memory so that it + remains constant between re-initializations of the + network management system." + ::= { snmp 30 } + + END +-- @(#)WSCCS g/mibs-wfcommon.mib 1.4 10/26/95 +Wellfleet-COMMON-MIB + +DEFINITIONS ::= BEGIN + +IMPORTS + + enterprises + FROM RFC1155-SMI; + +wellfleet OBJECT IDENTIFIER ::= { enterprises 18 } + +wfSwSeries7 OBJECT IDENTIFIER ::= { wellfleet 3 } + +wfHardwareConfig OBJECT IDENTIFIER ::= { wfSwSeries7 1 } + +wfHwModuleGroup OBJECT IDENTIFIER ::= { wfHardwareConfig 4 } + +wfSystem OBJECT IDENTIFIER ::= { wfSwSeries7 3 } + +END -- Wellfleet-COMMON-MIB +-- @(#)WSCCS i/mibs-hardware.mib 1.2 10/9/95 +Wellfleet-HARDWARE-MIB DEFINITIONS ::= BEGIN + +-- Created by mdl2asn version 3.1 +-- Creation date: Wed Aug 30 16:42:01 EDT 1995 + + + IMPORTS + + IpAddress, Counter, Gauge, TimeTicks, Opaque, enterprises, mgmt + FROM RFC1155-SMI + OBJECT-TYPE + FROM RFC-1212 + TRAP-TYPE + FROM RFC-1215 + DisplayString, mib-2 + FROM RFC1213-MIB + wfHardwareConfig + FROM Wellfleet-COMMON-MIB; + + + wfHwBase OBJECT IDENTIFIER ::= { wfHardwareConfig 1 } + + wfHwBpIdOpt OBJECT-TYPE + SYNTAX INTEGER { + acefn(1), + aceln(2), + acecn(3), + afn(4), + in(5), + an(16), + sys5000(5000), + freln(16640), + frecn(16896), + frerbln(17152), + asn(20480), + asnzcable(20736), + asnbcable(20992) + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The BackPlane identification number." + ::= { wfHwBase 1 } + + wfHwBpRev OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The revision level of the BackPlane. High byte is in upper 2 bytes." + ::= { wfHwBase 2 } + + wfHwBpSerialNumber OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The serial number of the BackPlane." + ::= { wfHwBase 3 } + + wfBCNPwrSupply1 OBJECT-TYPE + SYNTAX INTEGER { + ok(1), + fail(2), + notpresent(3) + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Status of BCN Hot-Swappable Power Supply 1" + DEFVAL { notpresent } + ::= { wfHwBase 4 } + + wfBCNPwrSupply2 OBJECT-TYPE + SYNTAX INTEGER { + ok(1), + fail(2), + notpresent(3) + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Status of BCN Hot-Swappable Power Supply 2" + DEFVAL { notpresent } + ::= { wfHwBase 5 } + + wfBCNPwrSupply3 OBJECT-TYPE + SYNTAX INTEGER { + ok(1), + fail(2), + notpresent(3) + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Status of BCN Hot-Swappable Power Supply 3" + DEFVAL { notpresent } + ::= { wfHwBase 6 } + + wfBCNPwrSupply4 OBJECT-TYPE + SYNTAX INTEGER { + ok(1), + fail(2), + notpresent(3) + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Status of BCN Hot-Swappable Power Supply 4" + DEFVAL { notpresent } + ::= { wfHwBase 7 } + + wfBCNFanStatus OBJECT-TYPE + SYNTAX INTEGER { + ok(1), + fail(2), + notpresent(3) + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Status of BCN Fan Tray" + DEFVAL { notpresent } + ::= { wfHwBase 8 } + + wfBCNTemperature OBJECT-TYPE + SYNTAX INTEGER { + ok(1), + caution(2), + notpresent(3) + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Status of BCN Temperature sensor" + DEFVAL { notpresent } + ::= { wfHwBase 9 } + + wfHwTable OBJECT-TYPE + SYNTAX SEQUENCE OF WfHwEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "Hardware Table - indexed by slot number" + ::= { wfHardwareConfig 2 } + + wfHwEntry OBJECT-TYPE + SYNTAX WfHwEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "Hardware specific information about a slot." + INDEX { wfHwSlot } + ::= { wfHwTable 1 } + + WfHwEntry ::= SEQUENCE { + wfHwSlot + INTEGER, + wfHwModIdOpt + INTEGER, + wfHwModRev + OCTET STRING, + wfHwModSerialNumber + OCTET STRING, + wfHwMotherBdIdOpt + INTEGER, + wfHwMotherBdRev + OCTET STRING, + wfHwMotherBdSerialNumber + OCTET STRING, + wfHwDaughterBdIdOpt + INTEGER, + wfHwDaughterBdRev + OCTET STRING, + wfHwDaughterBdSerialNumber + OCTET STRING, + wfHwBabyBdIdOpt + INTEGER, + wfHwBabyBdRev + OCTET STRING, + wfHwBabyBdSerialNumber + OCTET STRING, + wfHwDiagPromRev + OCTET STRING, + wfHwDiagPromDate + DisplayString, + wfHwDiagPromSource + DisplayString, + wfHwBootPromRev + OCTET STRING, + wfHwBootPromDate + DisplayString, + wfHwBootPromSource + DisplayString, + wfHwSparePromRev + OCTET STRING, + wfHwSparePromDate + DisplayString, + wfHwSparePromSource + DisplayString, + wfHwFileSysPresent + INTEGER, + wfHwFileSysPresent2 + INTEGER, + wfHwConfigServer + INTEGER, + wfHwConfigFile + DisplayString, + wfHwConfigDateAndTime + OCTET STRING, + wfHwActiveImageName + DisplayString, + wfHwActiveImageSource + DisplayString, + wfHwActiveImageDate + DisplayString, + wfHwMotherBdMemorySize + INTEGER, + wfHwFastPacketCacheSize + INTEGER, + wfHwModDaughterBd1IdOpt + INTEGER, + wfHwModDaughterBd1AwRev + OCTET STRING, + wfHwModDaughterBd1Rev + OCTET STRING, + wfHwModDaughterBd1SerialNumber + OCTET STRING, + wfHwModDaughterBd2IdOpt + INTEGER, + wfHwModDaughterBd2AwRev + OCTET STRING, + wfHwModDaughterBd2Rev + OCTET STRING, + wfHwModDaughterBd2SerialNumber + OCTET STRING + } + + wfHwSlot OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "A unique value for each slot. + Its value ranges between 1 and 14. + There are products in this family that contain 1, 5, and 14 slots." + ::= { wfHwEntry 1 } + + wfHwModIdOpt OBJECT-TYPE + SYNTAX INTEGER { + enet1(1), + enet2(8), + sync1(16), + sync1a(17), + t11(24), + dse1(32), + dse1a(33), + dst416(40), + sst416a(41), + dst4(42), + sst4a(43), + sst416(44), + stok416(45), + sst4(46), + stok4(47), + floppy(48), + necfloppy(49), + t12(56), + t12a(57), + st1(58), + t156k(60), + e1(61), + st156k(62), + se1(63), + t12n(64), + st1n(65), + t156kn(66), + st156kn(67), + e1n(68), + se1n(69), + sync(80), + sync2a(81), + cmcfddi(88), + iphfddi(89), + dt(104), + dsde1(112), + dsde1a(113), + enet(114), + dse2(116), + dse2a(117), + sse(118), + ssea(119), + dsde10bt(120), + enet3(132), + dsde2(156), + oldqenf(160), + denf(161), + qenf(162), + qef(164), + def(165), + mct1(168), + smct1(169), + dtok(176), + mce1(184), + smce1(185), + mce1ii75(188), + smce1ii75(189), + mce1ii120(190), + smce1ii120(191), + wffddi2m(192), + wffddi1m(193), + wffddi2s(194), + wffddi1s(195), + wffddi2mf(196), + wffddi1mf(197), + wffddi2sf(198), + wffddi1sf(199), + fmdset(200), + fmdst(201), + fmdse(202), + fmsst(203), + fmsse(204), + fnsdse(208), + fnsdsdt(216), + fnsdst(217), + dhssi(224), + shssi(225), + esafnf(232), + esafdsenf(233), + esafssenf(234), + esafdenf(235), + esaf(236), + esafdse(237), + esafsse(238), + esafde(239), + qtok(256), + asn(511), + anseds(1024), + ansedst(1025), + ansedsh(1026), + ansedsi(1027), + ansedsti(1028), + ansedshi(1029), + ansets(1030), + ansetst(1031), + ansetsh(1032), + andeds(1033), + andedst(1034), + andedsh(1035), + andstx(1036), + andst(1037), + andsti(1038), + antst(1039), + antstx(1040), + ansdsedst(1041), + ansdsedstx(1042), + ansedsi2(1043), + ansedsti2(1044), + ansedshi2(1045), + andsti2(1046), + ansedsg(1047), + ansedsgx(1048), + ansetsg(1049), + andedsg(1050), + ansedsgi(1051), + ansetsgx(1052), + andedsgx(1053), + ansedsgix(1054), + ansedsx(1055), + ansetsx(1056), + andedsx(1057), + ansedstx(1058), + ansetstx(1059), + andedstx(1060), + andsti2x(1061), + ansedsi2x(1062), + ansedsti2x(1063), + atmalc(4096), + atmalctaxi100(4097), + atmalcsonetmm(4098), + atmalcsonetsm(4099), + osync(4352), + comp(4353), + comp128(4354), + atmcoc3mm(4608), + atmcoc3sm(4609), + atmcoc3utp5(4610), + de100(4864), + atmcds3(5120), + atmce3(5121), + qmct1rj45(5376), + qmct1db15(5377), + srml(8448), + atm5000ah(524288), + qe(1048799), + qehwf(1048798), + qefddi2m(1048831), + qefddi2mhwf(1048830), + qefddi2s(1048823), + qefddi2shwf(1048822), + qefddi1m(1048815), + qefddi1mhwf(1048814), + qefddi1s(1048807), + qefddi1shwf(1048806), + qecddi2stp(1048827), + qecddi2stphwf(1048826), + qecddi1stp(1048811), + qecddi1stphwf(1048810), + qecddi2utp(1048763), + qecddi2utphwf(1048762), + qecddi1utp(1048747), + qecddi1utphwf(1048746), + enet3atm(1048832), + enet3enet(1048833), + enet3fddi(1048834), + enet3tok(1048835), + enet3tokf(1048836), + enet3sync(1048837), + enet3only(1048863), + fddiatm(1048864), + fddienet(1048865), + fddifddi(1048866), + fdditok(1048867), + fdditokf(1048868), + fddisync(1048869), + fddionly(1048895), + tok3atm(1048896), + tok3enet(1048897), + tok3fddi(1048898), + tok3tok(1048899), + tok3tokf(1048900), + tok3sync(1048901), + tok3only(1048927), + tokf3atm(1048928), + tokf3enet(1048929), + tokf3fddi(1048930), + tokf3tok(1048931), + tokf3tokf(1048932), + tokf3sync(1048933), + tokf3only(1048959), + enet3datm(1048960), + enet3denet(1048961), + enet3dfddi(1048962), + enet3dtok(1048963), + enet3dtokf(1048964), + enet3dsync(1048965), + enet3donly(1048991), + chipcomfenet(1049089), + chipcomffddi(1049090), + chipcomftok(1049091), + chipcomftokf(1049092), + chipcomfdsync(1049093), + chipcomfisdn(1049094), + chipcomffddis(1049095), + chipcomfonly(1049119), + chipcomenet(1049217), + chipcomfddi(1049218), + chipcomtok(1049219), + chipcomtokf(1049220), + chipcomdsync(1049221), + chipcomisdn(1049222), + chipcomfddis(1049223), + chipcomonly(1049247) + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The module identification number. + + Port Configurations + HWStat Name Enet Sync Async Token Framer Fiber + ------ ------------ ------ ---- ----- ----- ------ ----- + 1 ENET-1 2 0 0 0 0 0 + 8 ENET-2 2 0 0 0 0 0 + + 16 SYNC-1 0 4 1 0 0 0 + 17 SYNC-1 [1] 0 4 1 0 0 0 + + 24 T1-1 0 2 1 0 2 0 + + 32 DSE-1 1 2 1 0 0 0 + 33 DSE-1 [1] 1 2 1 0 0 0 + + 40 DST-4/16 0 2 1 1 0 0 + 41 SST-4/16 [1] 0 1 1 1 0 0 + 42 DST-4 0 2 1 1 0 0 + 43 SST-4 [1] 0 1 1 1 0 0 + 44 SST-4/16 0 1 1 1 0 0 + 45 STOK-4/16 [3] 0 0 0 1 0 0 + 46 SST-4 0 1 1 1 0 0 + 47 STOK-4 [3] 0 0 0 1 0 0 + + 48 FLOPPY 0 0 0 0 0 0 + + 56 T1-2 0 2 1 0 2 0 + 57 T1-2 0 2 1 0 2 0 + 58 ST1 0 1 1 0 1 0 + 60 T1-56K 0 1 1 0 1 0 + 61 E1 [3] 0 2 0 0 2 0 + 62 ST1-56K 0 1 1 0 1 0 + 63 SE1 [3] 0 1 0 0 1 0 + + 64 T1-2n 0 2 1 0 2 0 + 65 ST1n 0 1 1 0 1 0 + 66 T1-56Kn 0 1 1 0 1 0 + 67 ST1-56Kn 0 1 1 0 1 0 + 68 E1n [3] 0 2 0 0 2 0 + 69 SE1n [3] 0 1 0 0 1 0 + + 80 SYNC-2 0 4 1 0 0 0 + 81 SYNC-2 [1] 0 4 1 0 0 0 + + 88 CMC-FDDI [6] 0 0 0 0 0 1 + 89 IPHASE-FDDI [6] 0 0 0 0 0 1 + + 112 DSDE-1 2 2 1 0 0 0 + 113 DSDE-1 [1] 2 2 1 0 0 0 + 114 ENET 2 0 0 0 0 0 + 116 DSE-2 1 2 1 0 0 0 + 117 DSE-2 [1] 1 2 1 0 0 0 + 118 SSE 1 1 1 0 0 0 + 119 SSE [1] 1 1 1 0 0 0 + + 132 ENET-3 [2] 2 0 0 0 0 0 + + 156 DSDE-2 [2] 2 2 1 0 0 0 + + 160 QE/NF 4 0 0 0 0 0 + 161 DE/NF [5] 2 0 0 0 0 0 + 162 QE/NF 4 0 0 0 0 0 + 164 QE/F [4] 4 0 0 0 0 0 + 165 DE/F [4,5] 2 0 0 0 0 0 + + 168 MCT1 0 2 Munich 0 0 2 0 + 169 SMCT1 0 1 Munich 0 0 1 0 + + 176 DTOK 0 0 0 2 0 0 + + 184 MCE1 0 2 Munich 0 0 2 0 + 185 SMCE1 0 1 Munich 0 0 1 0 + 188 MCE1II75 0 2 Munich 0 0 2 0 + 189 SMCE1II75 0 1 Munich 0 0 1 0 + 190 MCE1II120 0 2 Munich 0 0 2 0 + 191 SMCE1II120 0 1 Munich 0 0 1 0 + + 192 WF_FDDI_2M 0 0 0 0 0 1 + 193 WF_FDDI_1M 0 0 0 0 0 1 + 194 WF_FDDI_2S 0 0 0 0 0 1 + 195 WF_FDDI_1S 0 0 0 0 0 1 + 196 WF_FDDI_2MF 0 0 0 0 0 1 + 197 WF_FDDI_1MF 0 0 0 0 0 1 + 198 WF_FDDI_2SF 0 0 0 0 0 1 + 199 WF_FDDI_1SF 0 0 0 0 0 1 + + 200 HW_MODULE_FMDSET [7] 1 2 0 1 0 0 + 201 HW_MODULE_FMDST [7] 0 2 0 1 0 0 + 202 HW_MODULE_FMDSE [7] 1 2 0 0 0 0 + 203 HW_MODULE_FMSST [7] 0 1 0 1 0 0 + 204 HW_MODULE_FMSSE [7] 1 1 0 0 0 0 + + 208 FNSDSE [7] 1 2 0 0 0 0 + 216 FNSDSDT [7] 0 2 0 2 0 0 + 217 FNSDST [7] 0 2 0 1 0 0 + + 224 DHSSI 0 2 hssi 0 0 0 0 + 225 SHSSI 0 1 hssi 0 0 0 0 + + 232 ESAF_NF 2 2 0 0 0 0 + 233 ESAF_DSE_NF 1 2 0 0 0 0 + 234 ESAF_SSE_NF 1 1 0 0 0 0 + 235 ESAF_DE_NF 2 0 0 0 0 0 + 236 ESAF [2] 2 2 0 0 0 0 + 237 ESAF_DSE [2] 1 2 0 0 0 0 + 238 ESAF_SSE [2] 1 1 0 0 0 0 + 239 ESAF_DE [2] 2 0 0 0 0 0 + + 256 QTOK 0 0 0 4 0 0 + + ASN (Barracuda) + + 511 ASN[8] + + + AN Module IDs (Piranha, Guppy...) + + ID Mnemonic ENET SYNC ISDN TR HUB DCM + -- -------- ---- ---- ---- -- --- --- + 1024 ANSEDS 1 2 0 0 0 N + + 1025 ANSEDST 1 2 0 1 0 N + + 1026 ANSEDSH 1 2 0 0 12 N + + 1027 ANSEDSI 1 2 1 0 0 N + + 1028 ANSEDSTI 1 2 1 1 0 N + + 1029 ANSEDSHI 1 2 1 0 12 N + + 1030 ANSETS 1 3 0 0 0 N + + 1031 ANSETST 1 3 0 1 0 N + + 1032 ANSETSH 1 3 0 0 12 N + + 1033 ANDEDS 2 2 0 0 0 N + + 1034 ANDEDST 2 2 0 1 0 N + + 1035 ANDEDSH 2 2 0 0 12 N + + 1036 ANDSTX 0 2 0 1 0 Y + (formerly ANDS) + + 1037 ANDST 0 2 0 1 0 N + + 1038 ANDSTI 0 2 1 1 0 N + + 1039 ANTST 0 3 0 1 0 N + + 1040 ANTSTX 0 3 0 1 0 Y + (formerly ANSDSEDS) + + 1041 ANSDSEDST 1 2 0 1 0 N + + 1042 ANSDSEDSTX 1 2 0 1 0 Y + (formerly ANSDSEDSH) + + 1043 ANSEDSI2 1 2 1 0 0 N + + 1044 ANSEDSTI2 1 2 1 1 0 N + + 1045 ANSEDSHI2 1 2 1 0 12 N + + 1046 ANDSTI2 0 2 1 1 0 N + + 1047 ANSEDSG 1 2 0 0 8 N + + 1048 ANSEDSGX 1 2 0 0 8 Y + + 1049 ANSETSG 1 3 0 0 8 N + + 1050 ANDEDSG 2 2 0 0 8 N + + 1051 ANSEDSGI 1 2 1 0 8 N + + 1052 ANSETSGX 1 3 0 0 8 Y + + 1053 ANDEDSGX 2 2 0 0 8 Y + + 1054 ANSEDSGIX 1 2 1 0 8 Y + + 1055 ANSEDSX 1 2 0 0 0 Y + + 1056 ANSETSX 1 3 0 0 0 Y + + 1057 ANDEDSX 2 2 0 0 0 Y + + 1058 ANSEDSTX 1 2 0 1 0 Y + + 1059 ANSETSTX 1 3 0 1 0 Y + + 1060 ANDEDSTX 2 2 0 1 0 Y + + 1061 ANDSTI2X 0 2 1 0 0 Y + + 1062 ANSEDSI2X 1 2 1 0 0 Y + + 1063 ANSEDSTI2X 1 2 1 1 0 Y + + + 4096 ATMALC 0 0 0 0 0 0 + 4097 ATMALCTAXI100 0 0 0 0 0 1 + 4098 ATMALCSONETMM 0 0 0 0 1 1 [9] + 4099 ATMALCSONETSM 0 0 0 0 1 1 [9] + 4352 OSYNC 0 8 0 0 0 0 + 4353 OSYNC_COMP (32) 0 8 0 0 0 0 + 4354 OSYNC_COMP128 0 8 0 0 0 0 + + 4608 ATMCOC3MM 0 0 0 0 1 1 [10] + 4609 ATMCOC3SM 0 0 0 0 1 1 [10] + 4610 ATMCOC3UTP5 0 0 0 0 1 0 [10] + + 4864 DE100 2 0 0 0 0 0 + + 5120 ATMCDS3 0 0 0 0 1 0 [10] + 5121 ATMCE3 0 0 0 0 1 0 [10] + + 8448 SRML 0 0 0 0 0 0 + + + NOTES: + [1] Indicates Module has COM Port 1 configured for ASYNC. + The AM8530's port B is configured for COM1. + + [2] This Module contains the DEFA - Hardware Filtering. CAMS + must be programmed (can contain 2 - 6 CAMS onboard). + + [3] The AM8530 has been removed (depopulated) from this module. + Programming this device should not be performed. + + [4] Contains Dual Defa hardware. (Can be depopulated) + + [5] Depop'd two ports of hardware to make Dual Ethernet module. + + [6] These are FDDI modules. The ID cannot be read from the Link + module I/O space. + + [7] These are AFN Platform Integrated 'Modules' - Cannot be detached + or be used by any other platform. + + [8] Module IDs from 1280(0x500) to 2559(0x9ff) are used + for the ASN Net Modules. Module ID 512(0x200) is + used for the ASN SPEX. These IDs are documented in + MODULE.mdl. A module ID of 511(0x1ff) in + 'wfHwEntry.wfHwModIdOpt' indicates that it is an + ASN platform and the user should refer to + 'wfHwModuleEntry.wfHwModuleModIdOpt' for Module ID details + + [9] ATMALC link modules. The physical option for SONET includes a + framer and the medium is fiber optics. Only one port per physical + daughtercard per link module. + + [10] ARE UTOPIA link modules. " + ::= { wfHwEntry 2 } + + wfHwModRev OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The revision level of the module. High byte is in upper 2 bytes." + ::= { wfHwEntry 3 } + + wfHwModSerialNumber OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The serial number of the module." + ::= { wfHwEntry 4 } + + wfHwMotherBdIdOpt OBJECT-TYPE + SYNTAX INTEGER { + sysctrl(1), + ace12(2), + ace25(3), + ace32(4), + afn(5), + in(6), + sysctrl2(7), + an(16), + fre(256), + fre2(768), + o60(769), + asn(1024), + are(1280), + srmf(8704) + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The mother board identification number." + ::= { wfHwEntry 5 } + + wfHwMotherBdRev OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The revision level of the mother board. High byte is in upper 2 bytes." + ::= { wfHwEntry 6 } + + wfHwMotherBdSerialNumber OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The serial number of the mother board." + ::= { wfHwEntry 7 } + + wfHwDaughterBdIdOpt OBJECT-TYPE + SYNTAX INTEGER { + sysctrl(1), + ace68020mhz12(2), + ace68020mhz25(3), + ace68030mhz32(4), + fre68040mhz25(4352), + fre68040mhz33(4608) + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The daughter board identification number." + ::= { wfHwEntry 8 } + + wfHwDaughterBdRev OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The revision level of the daughter board. High byte is in upper 2 bytes." + ::= { wfHwEntry 9 } + + wfHwDaughterBdSerialNumber OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The serial number of the daughter board." + ::= { wfHwEntry 10 } + + wfHwBabyBdIdOpt OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The baby board identification number." + ::= { wfHwEntry 11 } + + wfHwBabyBdRev OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The revision level of the baby board. High byte is in upper 2 bytes." + ::= { wfHwEntry 12 } + + wfHwBabyBdSerialNumber OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The serial number of the baby board." + ::= { wfHwEntry 13 } + + wfHwDiagPromRev OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The revision level of the Diagnostic PROM. Major revision level + is in the upper 2 bytes, minor revision level in the lower 2 bytes." + ::= { wfHwEntry 14 } + + wfHwDiagPromDate OBJECT-TYPE + SYNTAX DisplayString + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The creation date of the Diagnostic PROM" + ::= { wfHwEntry 15 } + + wfHwDiagPromSource OBJECT-TYPE + SYNTAX DisplayString + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The origin of the Diagnostic PROM contents" + ::= { wfHwEntry 16 } + + wfHwBootPromRev OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The revision level of the BOOT PROM. Major revision level + is in the upper 2 bytes, minor revision level in the lower 2 bytes." + ::= { wfHwEntry 17 } + + wfHwBootPromDate OBJECT-TYPE + SYNTAX DisplayString + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The creation date of the Boot PROM" + ::= { wfHwEntry 18 } + + wfHwBootPromSource OBJECT-TYPE + SYNTAX DisplayString + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The origin of the Boot PROM contents" + ::= { wfHwEntry 19 } + + wfHwSparePromRev OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The revision level of the BOOT PROM. Major revision level + is in the upper 2 bytes, minor revision level in the lower 2 bytes." + ::= { wfHwEntry 20 } + + wfHwSparePromDate OBJECT-TYPE + SYNTAX DisplayString + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The creation date of the Spare PROM" + ::= { wfHwEntry 21 } + + wfHwSparePromSource OBJECT-TYPE + SYNTAX DisplayString + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The origin of the Spare PROM contents" + ::= { wfHwEntry 22 } + + wfHwFileSysPresent OBJECT-TYPE + SYNTAX INTEGER { + filesys(1), + nofilesys(2) + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Flag indicating presence of File System on this slot." + DEFVAL { nofilesys } + ::= { wfHwEntry 23 } + + wfHwFileSysPresent2 OBJECT-TYPE + SYNTAX INTEGER { + filesys(1), + nofilesys(2) + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Flag indicating presence of File System (Syscon2 volume#2) on this slot." + DEFVAL { nofilesys } + ::= { wfHwEntry 24 } + + wfHwConfigServer OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The slot number from which this slot was served its + configuration. If the value for this attribute is 0, this + slot obtained its configuration from a file system resource + (not necessarily local); If the value for this attribute is + -1, this slot does not participate in the boot process (e.g. + SRM). A positive value indicates that the configuration was + obtained from memory from the slot indicated by the value of + this attribute." + ::= { wfHwEntry 25 } + + wfHwConfigFile OBJECT-TYPE + SYNTAX DisplayString + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The name of the config file the active configuration was + derived from. This does NOT necessarily reflect the + current configuration!" + ::= { wfHwEntry 26 } + + wfHwConfigDateAndTime OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The 11 octet date and time that a configuration was + loaded on/served to this slot. Octet map: 1-2 Year, + 3 Month, 4 Day, 5 Hour, 6 Minutes, 7 Seconds, + 8 Deci-seconds, 9 Direction from GMT ('+'|`-'), 10 GMT Hour + Offset, 11 GMT Minute Offset." + ::= { wfHwEntry 27 } + + wfHwActiveImageName OBJECT-TYPE + SYNTAX DisplayString + ACCESS read-only + STATUS mandatory + DESCRIPTION + "If slot was booted from a local source: this is the name of the active + image, which is in the form of <volume>:<image name>. + If slot was booted from a network source: this is the full pathname + where the active image was found on the remote server." + ::= { wfHwEntry 28 } + + wfHwActiveImageSource OBJECT-TYPE + SYNTAX DisplayString + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The origin of the active image" + ::= { wfHwEntry 29 } + + wfHwActiveImageDate OBJECT-TYPE + SYNTAX DisplayString + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The date which the active image was created" + ::= { wfHwEntry 30 } + + wfHwMotherBdMemorySize OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The total installed dram size in kilobytes." + ::= { wfHwEntry 31 } + + wfHwFastPacketCacheSize OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The size of the installed fast packet cache in kilobytes." + ::= { wfHwEntry 32 } + + wfHwModDaughterBd1IdOpt OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Link module daughter board #1 identification number" + ::= { wfHwEntry 33 } + + wfHwModDaughterBd1AwRev OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Link module daughter board #1 artwork revision level" + ::= { wfHwEntry 34 } + + wfHwModDaughterBd1Rev OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Link module daughter board #1 board revision level" + ::= { wfHwEntry 35 } + + wfHwModDaughterBd1SerialNumber OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Link module daughter board #1 serial number" + ::= { wfHwEntry 36 } + + wfHwModDaughterBd2IdOpt OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Link module daughter board #2 identification number" + ::= { wfHwEntry 37 } + + wfHwModDaughterBd2AwRev OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Link module daughter board #2 artwork revision level" + ::= { wfHwEntry 38 } + + wfHwModDaughterBd2Rev OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Link module daughter board #2 board revision level" + ::= { wfHwEntry 39 } + + wfHwModDaughterBd2SerialNumber OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Link module daughter board #2 serial number" + ::= { wfHwEntry 40 } + + END -- Wellfleet-HARDWARE-MIB +-- @(#)WSCCS q/mibs-module.mib 1.1 8/30/95 +Wellfleet-MODULE-MIB DEFINITIONS ::= BEGIN + +-- Created by mdl2asn version 3.1 +-- Creation date: Wed Aug 30 16:45:27 EDT 1995 + + + IMPORTS + + IpAddress, Counter, Gauge, TimeTicks, Opaque, enterprises, mgmt + FROM RFC1155-SMI + OBJECT-TYPE + FROM RFC-1212 + TRAP-TYPE + FROM RFC-1215 + DisplayString, mib-2 + FROM RFC1213-MIB + wfHwModuleGroup + FROM Wellfleet-COMMON-MIB; + + + wfHwModuleTable OBJECT-TYPE + SYNTAX SEQUENCE OF WfHwModuleEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "Hardware Module Table + Filled in by the Module Driver. Read by SNMP to + build the driver load records " + ::= { wfHwModuleGroup 1 } + + wfHwModuleEntry OBJECT-TYPE + SYNTAX WfHwModuleEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "Hardware specific information about a slot." + INDEX { wfHwModuleSlot, + wfHwModuleModule } + ::= { wfHwModuleTable 1 } + + WfHwModuleEntry ::= SEQUENCE { + wfHwModuleSlot + INTEGER, + wfHwModuleModule + INTEGER, + wfHwModuleModIdOpt + INTEGER, + wfHwModuleModRev + OCTET STRING, + wfHwModuleModSerialNumber + OCTET STRING, + wfHwModuleArtworkRev + DisplayString + } + + wfHwModuleSlot OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "A unique value for each slot. + Its value ranges between 1 and 4." + ::= { wfHwModuleEntry 1 } + + wfHwModuleModule OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "This value ranges between 1 and 4" + ::= { wfHwModuleEntry 2 } + + wfHwModuleModIdOpt OBJECT-TYPE + SYNTAX INTEGER { + spex(512), + hss(768), + hsd(769), + denm(1280), + denmhwf(1281), + dsnmnn(1536), + dsnmn1(1537), + dsnmn2(1538), + dsnm1n(1540), + dsnm11(1541), + dsnm12(1542), + dsnm2n(1544), + dsnm21(1545), + dsnm22(1546), + dsnmnnisdn(1584), + dsnmn1isdn(1585), + dsnmn2isdn(1586), + dsnm1nisdn(1588), + dsnm11isdn(1589), + dsnm12isdn(1590), + dsnm2nisdn(1592), + dsnm21isdn(1593), + dsnm22isdn(1594), + mmfsdsas(1792), + mmfsddas(1793), + smfsdsas(1800), + smfsddas(1801), + mmscsas(1808), + mmscdas(1809), + smammbdas(1825), + mmasmbdas(1833), + mmfsdsashwf(1856), + mmfsddashwf(1857), + smfsdsashwf(1864), + smfsddashwf(1865), + mmscsashwf(1872), + mmscdashwf(1873), + smammbdashwf(1889), + mmasmbdashwf(1897), + dtnm(2048), + cam(2049), + se100nm(2304), + asnqbri(2560) + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Module IDs for the net modules modules" + ::= { wfHwModuleEntry 3 } + + wfHwModuleModRev OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The revision level of the module. High byte is in upper 2 bytes." + ::= { wfHwModuleEntry 4 } + + wfHwModuleModSerialNumber OBJECT-TYPE + SYNTAX OCTET STRING + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The serial number of the module." + ::= { wfHwModuleEntry 5 } + + wfHwModuleArtworkRev OBJECT-TYPE + SYNTAX DisplayString + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The Artwork Revision number of the module" + ::= { wfHwModuleEntry 6 } + + wfModuleTable OBJECT-TYPE + SYNTAX SEQUENCE OF WfModuleEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "This table is used by the module driver for Barracuda" + ::= { wfHwModuleGroup 2 } + + wfModuleEntry OBJECT-TYPE + SYNTAX WfModuleEntry + ACCESS not-accessible + STATUS mandatory + DESCRIPTION + "Hardware specific information about a slot." + INDEX { wfModuleSlot } + ::= { wfModuleTable 1 } + + WfModuleEntry ::= SEQUENCE { + wfModuleDelete + INTEGER, + wfModuleSlot + INTEGER, + wfModuleTimerFrequency + INTEGER, + wfModuleBufferBalance + INTEGER, + wfModuleFddiWeight + INTEGER, + wfModuleTokenRingWeight + INTEGER, + wfModuleCsmacdWeight + INTEGER, + wfModuleSyncWeight + INTEGER, + wfModuleFreeBufferCredits + INTEGER, + wfModuleTotalBufferCredits + INTEGER, + wfModuleRestart + INTEGER, + wfModuleCsmacd100Weight + INTEGER + } + + wfModuleDelete OBJECT-TYPE + SYNTAX INTEGER { + created(1), + deleted(2) + } + ACCESS read-write + STATUS mandatory + DESCRIPTION + "create/delete parameter" + DEFVAL { created } + ::= { wfModuleEntry 1 } + + wfModuleSlot OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "A unique value for each slot. + Its value ranges between 1 and 14. + There are products in this family that contain 1, 5, and 14 slots." + ::= { wfModuleEntry 2 } + + wfModuleTimerFrequency OBJECT-TYPE + SYNTAX INTEGER { + timerdefault(1) + } + ACCESS read-write + STATUS mandatory + DESCRIPTION + "This value determines the frequency for the buffer balance + algorithm to run" + DEFVAL { timerdefault } + ::= { wfModuleEntry 3 } + + wfModuleBufferBalance OBJECT-TYPE + SYNTAX INTEGER { + txrx(1), + none(2), + rx(3), + tx(4) + } + ACCESS read-write + STATUS mandatory + DESCRIPTION + "Enable/Disable buffer balancing algorithm selectively" + DEFVAL { txrx } + ::= { wfModuleEntry 4 } + + wfModuleFddiWeight OBJECT-TYPE + SYNTAX INTEGER(1..10) + ACCESS read-write + STATUS mandatory + DESCRIPTION + "This value determines the weight of the fddi line + for the buffer balancing algorithm" + DEFVAL { 6 } + ::= { wfModuleEntry 5 } + + wfModuleTokenRingWeight OBJECT-TYPE + SYNTAX INTEGER(1..10) + ACCESS read-write + STATUS mandatory + DESCRIPTION + "This value determines the weight of the token-ring + for the buffer balancing algorithm" + DEFVAL { 4 } + ::= { wfModuleEntry 6 } + + wfModuleCsmacdWeight OBJECT-TYPE + SYNTAX INTEGER(1..10) + ACCESS read-write + STATUS mandatory + DESCRIPTION + "This value determines the weight of the csmacd line + for the buffer balancing algorithm" + DEFVAL { 3 } + ::= { wfModuleEntry 7 } + + wfModuleSyncWeight OBJECT-TYPE + SYNTAX INTEGER(1..10) + ACCESS read-write + STATUS mandatory + DESCRIPTION + "This value determines the weight of the sync line + for the buffer balancing algorithm" + DEFVAL { 2 } + ::= { wfModuleEntry 8 } + + wfModuleFreeBufferCredits OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "This attribute indicates the number of buffers + available to line drivers but not used by them" + ::= { wfModuleEntry 9 } + + wfModuleTotalBufferCredits OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "This attribute indicates the total number of buffers + available to line drivers" + ::= { wfModuleEntry 10 } + + wfModuleRestart OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-write + STATUS mandatory + DESCRIPTION + "This attribute should be touched after the queue + lengths are configured in the line-records" + ::= { wfModuleEntry 11 } + + wfModuleCsmacd100Weight OBJECT-TYPE + SYNTAX INTEGER(1..10) + ACCESS read-write + STATUS mandatory + DESCRIPTION + "This value determines the weight of the csmacd 100MB line + for the buffer balancing algorithm" + DEFVAL { 6 } + ::= { wfModuleEntry 12 } + + END -- Wellfleet-MODULE-MIB +-- @(#)WSCCS h/mibs-sys.mib 1.1 8/30/95 +Wellfleet-SYS-MIB DEFINITIONS ::= BEGIN + +-- Created by mdl2asn version 3.1 +-- Creation date: Wed Aug 30 16:48:50 EDT 1995 + + + IMPORTS + + IpAddress, Counter, Gauge, TimeTicks, Opaque, enterprises, mgmt + FROM RFC1155-SMI + OBJECT-TYPE + FROM RFC-1212 + TRAP-TYPE + FROM RFC-1215 + DisplayString, mib-2 + FROM RFC1213-MIB + wfSystem + FROM Wellfleet-COMMON-MIB; + + + wfSys OBJECT IDENTIFIER ::= { wfSystem 1 } + + wfSysDescr OBJECT-TYPE + SYNTAX DisplayString + ACCESS read-only + STATUS mandatory + DESCRIPTION + "A textual description of the entity including full name and version of + the system's hardware type, OS, and networking SW " + ::= { wfSys 1 } + + wfSysObjectID OBJECT-TYPE + SYNTAX OBJECT IDENTIFIER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Provides an unambiguous means for determining the MIB type (old product vs. + harpoon MIB)." + ::= { wfSys 2 } + + wfSysUpTime OBJECT-TYPE + SYNTAX TimeTicks + ACCESS read-only + STATUS mandatory + DESCRIPTION + "Time in seconds/100 since the last cold start" + ::= { wfSys 3 } + + wfSysContact OBJECT-TYPE + SYNTAX DisplayString + ACCESS read-write + STATUS mandatory + DESCRIPTION + "Contact person for this node and where/how to contact them" + ::= { wfSys 4 } + + wfSysName OBJECT-TYPE + SYNTAX DisplayString + ACCESS read-write + STATUS mandatory + DESCRIPTION + "Node's fully qualified domain name or administratively assigned name" + ::= { wfSys 5 } + + wfSysLocation OBJECT-TYPE + SYNTAX DisplayString + ACCESS read-write + STATUS mandatory + DESCRIPTION + "Physical Location of this Node" + ::= { wfSys 6 } + + wfSysServices OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "A sum of numbers indicating the set of services the entity offers. For each + layer L, add 2**(L - 1). Example: 78 = Layers 2,3,4, and 7." + DEFVAL { 78 } + ::= { wfSys 7 } + + wfSysGmtOffset OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The positive or negative offset from Greenwich Mean Time (GMT). This + effectively describes the time zone." + ::= { wfSys 8 } + + wfSysMibVersion OBJECT-TYPE + SYNTAX DisplayString + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The version of the private management information base currently being + used by the system software. Format is: xV.RR" + ::= { wfSys 9 } + + wfSysMibRevision OBJECT-TYPE + SYNTAX INTEGER + ACCESS read-write + STATUS mandatory + DESCRIPTION + "The revision level of the private management information base currently + being used by the system software." + ::= { wfSys 10 } + + wfSysAgentType OBJECT-TYPE + SYNTAX INTEGER { + anrptragenttype(29), + anhubagenttype(30) + } + ACCESS read-only + STATUS mandatory + DESCRIPTION + "The network management agent's module type" + ::= { wfSys 11 } + + wfSysMibCounterEnable OBJECT-TYPE + SYNTAX INTEGER { + enabled(1), + disabled(2) + } + ACCESS read-write + STATUS mandatory + DESCRIPTION + "Mib II counter Switch" + DEFVAL { enabled } + ::= { wfSys 12 } + + END -- Wellfleet-SYS-MIB diff --git a/perl/SNMP/t/mibload.t b/perl/SNMP/t/mibload.t new file mode 100644 index 0000000..e44748a --- /dev/null +++ b/perl/SNMP/t/mibload.t @@ -0,0 +1,95 @@ +#!./perl + +BEGIN { + unless(grep /blib/, @INC) { + chdir 't' if -d 't'; + @INC = '../lib' if -d '../lib'; + } + eval "use Cwd qw(abs_path)"; + $ENV{'SNMPCONFPATH'} = 'nopath'; + $ENV{'MIBDIRS'} = '+' . abs_path("../../mibs"); +} + +use Test; +BEGIN {plan tests => 7} +use SNMP; + +require "t/startagent.pl"; + +use vars qw($mibdir); + +$SNMP::verbose = 0; + +my $mib_file = 't/mib.txt'; +my $junk_mib_file = 'mib.txt'; + +my $mibfile1; +my @mibdir; +my $mibfile2; + +if ($^O =~ /win32/i) { + $mibdir =~ s"/"\\"g; + $mibfile1 = "$mibdir\\TCP-MIB.txt"; + @mibdir = ("$mibdir"); + $mibfile2 = "$mibdir\\IPV6-TCP-MIB.txt"; +} +else { + $mibfile1 = "$mibdir/TCP-MIB.txt"; + @mibdir = ("$mibdir"); + $mibfile2 = "$mibdir/IPV6-TCP-MIB.txt"; +} + +if ($^O =~ /win32/i) { + $mibdir =~ s"/"\\"g; +} + + +###################################################################### +# See if we can find a mib to use, return of 0 means the file wasn't +# found or isn't readable. + +$res = SNMP::setMib($junk_mib_file,1); +ok(defined(!$res)); +###################################################################### +# Now we give the right name + +$res = SNMP::setMib($mib_file,1); +ok(defined($res)); +###################################################################### +# See if we can find a mib to use + +$res = SNMP::setMib($mib_file,0); +ok(defined($res)); +######################## 4 ################################ +# add a mib dir + +$res = SNMP::addMibDirs($mibdir[0]); + +SNMP::loadModules("IP-MIB", "IF-MIB", "IANAifType-MIB", "RFC1213-MIB"); +#SNMP::unloadModules(RMON-MIB); +#etherStatsDataSource shouldn't be found. +#present only in 1271 & RMON-MIB. +# +# XXX: because we can't count on user .conf files, we should turn off +# support for them (maybe set SNMPCONFPATH at the top of this +# script?). But for the mean time just search for a bogus node that +# will never exist. +$res = $SNMP::MIB{bogusetherStatsDataSource}; + +ok(!defined($res)); + +######################## 5 ############################ +# add mib file + +$res1 = SNMP::addMibFiles($mibfile1); +ok(defined($res1)); +$res2 = SNMP::addMibFiles($mibfile2); +ok(defined($res2)); + +$res = $SNMP::MIB{ipv6TcpConnState}{moduleID}; + +ok($res =~ /^IPV6-TCP-MIB/); +################################################# + +snmptest_cleanup(); + diff --git a/perl/SNMP/t/notify.t b/perl/SNMP/t/notify.t new file mode 100644 index 0000000..72600fa --- /dev/null +++ b/perl/SNMP/t/notify.t @@ -0,0 +1,106 @@ +#!./perl + +BEGIN { + unless(grep /blib/, @INC) { + chdir 't' if -d 't'; + @INC = '../lib' if -d '../lib'; + } + eval "use Cwd qw(abs_path)"; + $ENV{'SNMPCONFPATH'} = 'nopath'; + $ENV{'MIBDIRS'} = '+' . abs_path("../../mibs"); +} +use Test; +BEGIN { $n = 11; plan tests => $n } +use SNMP; +use vars qw($agent_port $comm $comm2 $trap_port $agent_host $sec_name $priv_pass $auth_pass $bad_name); +require 't/startagent.pl'; +$SNMP::debugging = 0; + +my $res; +my $enterprise = '.1.3.6.1.2.1.1.1.0'; +my $generic = 'specific'; + +# V1 trap testing +######################## 1 ############################ +# Fire up a trap session. +my $s1 = + new SNMP::Session (DestHost=>$agent_host,Version=>1,Community=>$comm,RemotePort=>$trap_port); +ok(defined($s1)); + +######################## 2 ############################ +# test v1 trap +if (defined($s1)) { + $res = $s1->trap(enterprise => $enterprise, agent=>$agent_host, generic=>$generic,[[sysContact, 0, 'root@localhost'], [sysLocation, 0, 'here']] ); +} +ok($res =~ /^0 but true/); + +######################## 3 ############################ +# test with wrong varbind +undef $res; +if (defined($s1)) { + $res = $s1->trap([[$bad_name, 0, 'root@localhost'], [sysLocation, 0, 'here']] ); + #print("res is $res\n"); +} +ok(!defined($res)); +######################################################### + +# V2 testing +######################## 4 ############################ +# Fire up a v2 trap session. +my $s2 = + new SNMP::Session (Version=>2, DestHost=>$agent_host,Community=>$comm2,RemotePort=>$trap_port); +ok(defined($s2)); +######################## 5 ############################ +# test v2 trap +undef $res; +if (defined($s2)) { + $res = $s2->trap(uptime=>200, trapoid=>'coldStart',[[sysContact, 0, 'root@localhost'], [sysLocation, 0, 'here']] ); + #print("res is $res\n"); +} +ok($res =~ /^0 but true/); +######################## 6 ############################ +# no trapoid and uptime given. Should take defaults... +my $ret; +if (defined($s2)) { + $ret = $s2->trap([[sysContact, 0, 'root@localhost'], [sysLocation, 0, 'here']] ); + #print("res is $ret\n"); +} +ok(defined($ret)); +######################## 7 ############################ +# no varbind list given. +undef $res; +if (defined($s2)) { + $res = $s2->trap(trapoid=>'coldStart'); + #print("res is $res\n"); +} +ok(defined($res) && $res =~ /^0 but true/); + +######################################################### + +# v3 testing +######################## 8 ############################ +# Fire up a v3 trap session. +my $s3 = new SNMP::Session(Version=>3, DestHost=> $agent_host, RemotePort=>$trap_port, SecName => $sec_name); +ok(defined($s3)); + +######################## 9 ############################ +if (defined($s3)) { + $res = $s3->inform(uptime=>111, trapoid=>'coldStart', [[sysContact, 0, 'root@localhost'], [sysLocation, 0, 'here']] ); +} +ok($res =~ /^0 but true/); + +######################## 10 ############################ +# Fire up a v3 trap session. +$s3 = new SNMP::Session(Version=>3, DestHost=> $agent_host, RemotePort=>$trap_port, SecName => $sec_name, SecLevel => authPriv, AuthPass => $auth_pass, PrivPass => $priv_pass); +ok(defined($s3)); + +######################## 11 ############################ +undef $res; +if (defined($s3)) { + $res = $s3->inform(uptime=>111, trapoid=>'coldStart', [[sysContact, 0, 'root@localhost'], [sysLocation, 0, 'here']] ); + print "res = $res\n"; +} + +ok(defined($res) && ($res =~ /^0 but true/)); + +snmptest_cleanup(); diff --git a/perl/SNMP/t/session.t b/perl/SNMP/t/session.t new file mode 100644 index 0000000..3f51386 --- /dev/null +++ b/perl/SNMP/t/session.t @@ -0,0 +1,76 @@ +#!./perl + +BEGIN { + unless(grep /blib/, @INC) { + chdir 't' if -d 't'; + @INC = '../lib' if -d '../lib'; + } + eval "use Cwd qw(abs_path)"; + $ENV{'SNMPCONFPATH'} = 'nopath'; + $ENV{'MIBDIRS'} = '+' . abs_path("../../mibs"); +} +use Test; +BEGIN { plan tests => 5} +use SNMP; +use vars qw($agent_port $comm $agent_host $bad_auth_pass $auth_pass $sec_name $bad_sec_name $bad_version $bad_priv_pass $priv_pass); +require "t/startagent.pl"; + +$SNMP::debugging = 0; + +# create list of varbinds for GETS, val field can be null or omitted +my $vars = new SNMP::VarList ( + ['sysDescr', '0', ''], + ['sysContact', '0'], + ['sysName', '0'], + ['sysLocation', '0'], + ['sysServices', '0'], + ['ifNumber', '0'], + ['ifDescr', '1'], + ['ifSpeed', '1'], + ); + +#########################== 1 ===######################################### +# Create a bogus session, undef means the host can't be found. +# removed! this test can hang for a long time if DNS is not functioning +# my $s1 = new SNMP::Session (DestHost => $bad_host ); +# ok(!defined($s1)); +#print("\n"); +#####################== 2 ====############################################ +# Fire up a session. + my $s2 = + new SNMP::Session (DestHost=>$agent_host, Community=>$comm, + RemotePort=>$agent_port); + ok(defined($s2)); +######################== 3 ==== ########################################## + +# Fire up a V3 session +my $s3 = new SNMP::Session (Version => 3 , RemotePort => $agent_port, + SecName => $sec_name ); +ok(defined($s3)); +#print STDERR "Error string1 = $s3->{ErrorStr}:$s3->{ErrorInd}\n"; +#print("\n"); +#####################=== 4 ====########################################### +#create a V3 session by setting an IP address/port not running an agent +my $s4 = new SNMP::Session (Version => 3, RemotePort => 1002, Retries => 0); +# engineId discovery should fail resulting in session creation failure (undef) +ok(!defined($s4)); +#print STDERR "Error string1 = $s4->{ErrorStr}:$s4->{ErrorInd}\n"; +#print("\n"); +###################### 5 ########################################### +#create a session with bad version +my $s5 = new SNMP::Session (Version=>$bad_version); +ok(!defined($s5)); +#print("\n"); +######################## 6 ######################################## +#Test for v3 session creation success +my $s6 = new SNMP::Session (Version => 3, RemotePort => $agent_port, + SecLevel => 'authPriv', + SecName => $sec_name, + PrivPass => $priv_pass, + AuthPass => $auth_pass); +ok(defined($s6)); +#print STDERR "Error string2 = $s6->{ErrorStr}:$s6->{ErrorInd}\n"; +#print("\n"); +##################### 7 ############################################ + +snmptest_cleanup(); diff --git a/perl/SNMP/t/set.t b/perl/SNMP/t/set.t new file mode 100644 index 0000000..9925654 --- /dev/null +++ b/perl/SNMP/t/set.t @@ -0,0 +1,224 @@ +#!./perl + +BEGIN { + unless(grep /blib/, @INC) { + chdir 't' if -d 't'; + @INC = '../lib' if -d '../lib'; + } + eval "use Cwd qw(abs_path)"; + $ENV{'SNMPCONFPATH'} = 'nopath'; + $ENV{'MIBDIRS'} = '+' . abs_path("../../mibs"); +} +use Test; +BEGIN { plan tests => 7 } +use SNMP; +use vars qw($agent_port $comm $agent_host); +require "t/startagent.pl"; + + +my $junk_oid = ".1.3.6.1.2.1.1.1.1.1.1"; +my $oid = ".1.3.6.1.2.1.1.1"; +my $junk_name = 'fooDescr'; +my $junk_host = 'no.host.here'; +my $name = "gmarzot\@nortelnetworks.com"; + +$SNMP::debugging = 0; +$n = 15; # Number of tests to run + +#print "1..$n\n"; +if ($n == 0) { exit 0; } + +# create list of varbinds for GETS, val field can be null or omitted +my $vars = new SNMP::VarList ( + ['sysDescr', '0', ''], + ['sysObjectID', '0'], + ['sysUpTime', '0'], + ['sysContact', '0'], + ['sysName', '0'], + ['sysLocation', '0'], + ['sysServices', '0'], + ['ifNumber', '0'], + ['ifDescr', '1'], + ['ifSpeed', '1'], + + ['snmpInPkts', '0'], + ['snmpInBadVersions', '0'], + ['snmpInBadCommunityNames', '0'], + ['snmpInBadCommunityUses', '0'], + ['snmpInASNParseErrs', '0'], + ['snmpEnableAuthenTraps', '0'], +# ['snmpSilentDrops', '0'], +# ['snmpProxyDrops', '0'], +# ['snmpTrapEnterprise', '2'], + +# ['hrStorageType', '2'], +# ['hrSystemDate', '0'], + ['sysORIndex', '1'], + ['sysORID', '2'], + ['sysORDescr', '3'], + ['sysORUpTime', '4'], +# ['ifName', '1'], + ['sysORLastChange', '0'], + ['ipInHdrErrors', '0'], + ['ipDefaultTTL', '0'], + ['ipInHdrErrors', '0'], + ); +################################################################ +# ['ipNetToMediaPhysAddress', '0'], +# ['ipAdEntAddr', '0'], +# ['snmpTrapOID', '0'], +# ['hrSystemNumUsers', '0'], +# ['hrFSLastFullBackupDate', '0'], +# ['ifPromiscuousMode', '0'], + + + +######################### 1 ####################################### +# Fire up a session. + my $s1 = + new SNMP::Session (DestHost=>$agent_host,Version=>1,Community=>$comm,RemotePort=>$agent_port); + ok(defined($s1)); + +####################### 2 ########################################## +# Set some value and see if the value is set properly. + +$originalLocation = $s1->get('sysLocation.0'); +$value = 'Router Management Labs'; +$s1->set('sysLocation.0', $value); +$finalvalue = $s1->get('sysLocation.0'); +ok($originalLocation ne $finalvalue); +#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; +#print("set value is: $finalvalue\n\n"); +$s1->set('sysLocation.0', $originalLocation); + +######################## 3 ####################################### + +# Now, reset that string with a non-string value. +# This will FAIL. :) + +#$nonstrvalue = '.9.23.56.7'; +#$s1->set('sysLocation.0', $nonstrvalue); +#$finalvalue = $s1->get('sysLocation.0'); +#ok(!defined($finalvalue)); + +#if (($initialvalue cmp $finalvalue) != 0 ) { +# ok(1); +#} +#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; +#print("set value is: $finalvalue\n\n"); +#$s1->set('sysLocation.0', $originalLocation); + +####################### 4 ##################################### + +# Test for an integer (READ-ONLY) +$originalservice = $s1->get('sysServices.0'); +#print("services is: $originalservice\n"); +$junk_service = "Nortel Networks"; +$s1->set('sysServices.0', $junk_service); + +$finalvalue = $s1->get('sysServices.0'); +#print("services is: $finalvalue\n"); +#print("Services is: $originalservice\n"); +ok($originalservice eq $finalvalue); +#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; +$s1->set('sysServices.0',$originalservice); +#print("\n"); + +################## 5 ###################### +# Test for an integer (READ-WRITE) +# The snmpEnableAuthenTraps takes only two values - 1 and 2. +# If any other value is tried to be set, it doesn't set and +# retains the old value. + +$originalTrap = $s1->get('snmpEnableAuthenTraps.0'); +#print("trap is -- $originalTrap\n"); +$junk_trap = "Nortel Networks"; +$s1->set('snmpEnableAuthenTraps.0', $junk_trap); +$finalvalue = $s1->get('snmpEnableAuthenTraps.0'); +#print("final trap is: $finalvalue\n"); +ok($finalvalue ne $junk_trap); +# Should the error be 'Value out of range: SNMPERR_RANGE ? +#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; +$s1->set('snmpEnableAuthenTraps.0',$originalTrap); +#print("\n"); +################### 6 ####################### +# Test for a TimeTicks (is this advisable? ) +# Trying to set uptime which cannot be done (READ-ONLY). +#$time = $s1->get('sysUpTime.0'); +#print("up time is : $time hundredths of a second\n"); +#$junk_time = 12345; +#$s1->set('sysUpTime.0', $junk_time); +#$finalvalue = $s1->get('sysUpTime.0'); +#print("final time is: $finalvalue hundredths of a second \n"); +# Will the final value always be equal to the initial value? +# depends on how fast this piece of code executes? +#ok($finalvalue == $time); +#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; +#print("\n"); + +################### 7 ###################### + + +#Test for a Counter32 type. +# READ-ONLY. + +#$Pkts = $s1->get('snmpInPkts.0'); +#print(" pkts is : $Pkts\n"); +#$junk_pkts = -1234; +#$s1->set('snmpInPkts.0', $junk_pkts); +#$finalPkts = $s1->get('snmpInPkts.0'); +#print("now pkts is : $finalPkts\n"); +#ok($finalPkts > $Pkts); +# Expecting genErr +#ok($s1->{ErrorStr} =~ /^\(gen/); +#print STDERR "pkts is = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; +#print("\n"); +################## 8 ############################## + +# Set a non-accessible attribute +$s1->set('ipAddrEntry.1', 'MyEID'); +# What should I expect - genErr or Bad variable type ? +# What gets checked first - type or accessibility? +# if type, then this is right..else, genErr is expected. +ok($s1->{ErrorStr} =~ /^Bad/ ); +#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; +#print("\n"); + +################# 12 ########################## +# Time stamp test - READ-ONLY +#$origtime = $s1->get('sysORLastChange.0'); +#print("Time is: $origtime\n"); +#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; +#$time = $s1->set('sysORLastChange.0', 12345); +#print("time stamp is : $time \n"); +# Should get genErr. +#ok($time =~ /^genErr/); +#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; +#print("\n"); + +############## 13 ############################ + +# OID test +my $oldoid = $s1->get("sysORID.1"); +#print("OID is : $oldoid\n"); +$junk_OID = ".6.6.6.6.6.6"; +$s1->set('sysORID.1', $junk_OID); +$newOID = $s1->get("sysORID.1"); +#print("new oid is $newOID\n"); +ok($oldoid eq $newOID); +#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; +#print("\n"); +################ 14 ########################## + +# Try setting an unregistered OID. +$junk_data = 'hehehe'; +$s1->set('ifmyData.0', $junk_data); + +#print STDERR "Error string = $s1->{ErrorStr}:$s1->{ErrorInd}\n"; +ok( $s1->{ErrorStr} =~ /^Unknown/ ); + +############################################## + +snmptest_cleanup(); + + diff --git a/perl/SNMP/t/snmptest.conf b/perl/SNMP/t/snmptest.conf new file mode 100644 index 0000000..355e310 --- /dev/null +++ b/perl/SNMP/t/snmptest.conf @@ -0,0 +1,21 @@ +sysservices 72 + +createUser v3_user MD5 test_pass_auth DES test_pass_priv + +# sec.name source community +com2sec v2c_user default v2c_private +com2sec v1_user default v1_private +com2sec v3_user default v3_private + +# sec.model sec.name +group v2c_group v2c v2c_user +group v1_group v1 v1_user +group v3_group usm v3_user + +# incl/excl subtree mask +view all included .1 80 + +# context sec.model sec.level match read write notif +access v2c_group "" any noauth exact all all all +access v1_group "" any noauth exact all all all +access v3_group "" any noauth exact all all all diff --git a/perl/SNMP/t/startagent.pl b/perl/SNMP/t/startagent.pl new file mode 100644 index 0000000..3e92c12 --- /dev/null +++ b/perl/SNMP/t/startagent.pl @@ -0,0 +1,125 @@ +# common parameters used in SNMP::Session creation and tests +$agent_host = 'localhost'; +$agent_port = 8765; +$trap_port = 8764; +$mibdir = '/usr/local/share/snmp/mibs'; +$comm = 'v1_private'; +$comm2 = 'v2c_private'; +$comm3 = 'v3_private'; +$sec_name = 'v3_user'; +$oid = '.1.3.6.1.2.1.1.1'; +$name = 'sysDescr'; +$name_module = 'RFC1213-MIB::sysDescr'; +$name_module2 = 'SNMPv2-MIB::sysDescr'; +$name_long = '.iso.org.dod.internet.mgmt.mib-2.system.sysDescr'; +$name_module_long = 'RFC1213-MIB::.iso.org.dod.internet.mgmt.mib-2.system.sysDescr'; +$name_module_long2 = 'SNMPv2-MIB::.iso.org.dod.internet.mgmt.mib-2.system.sysDescr'; +$auth_pass = 'test_pass_auth'; +$priv_pass = 'test_pass_priv'; + +# don't use any .conf files other than those specified. +$ENV{'SNMPCONFPATH'} |= "bogus"; + +# erroneous input to test failure cases +$bad_comm = 'BAD_COMMUNITY'; +$bad_name = "badName"; +$bad_oid = ".1.3.6.1.2.1.1.1.1.1.1"; +$bad_host = 'bad.host.here'; +$bad_port = '9999999'; +$bad_auth_pass = 'bad_auth_pass'; +$bad_priv_pass = 'bad_priv_pass'; +$bad_sec_name = 'bad_sec_name'; +$bad_version = 7; + +local $snmpd_cmd; +local $snmptrapd_cmd; +my $line; + +if ($^O =~ /win32/i) { + require Win32::Process; +} + +sub run_async { + my ($pidfile, $cmd, @args) = @_; + if (-r "$cmd" and -x "$cmd") { + if ($^O =~ /win32/i) { + $cmd =~ s/\//\\/g; + system "start \"$cmd\" /min cmd /c \"$cmd @args 2>&1\""; + } else { + system "$cmd @args 2>&1"; + } + # Wait at most three seconds for the pid file to appear. + for ($i = 0; ($i < 3) && ! (-r "$pidfile"); ++$i) { + sleep 1; + } + } else { + warn "Couldn't run $cmd\n"; + } +} + +sub snmptest_cleanup { + kill_by_pid_file("t/snmpd.pid"); + unlink("t/snmpd.pid"); + kill_by_pid_file("t/snmptrapd.pid"); + unlink("t/snmptrapd.pid"); +} + +sub kill_by_pid_file { + if ((-e "$_[0]") && (-r "$_[0]")) { + if ($^O !~ /win32/i) { + # Unix or Windows + Cygwin. + system "kill `cat $_[0]` > /dev/null 2>&1"; + } else { + # Windows + MSVC or Windows + MinGW. + open(H, "<$_[0]"); + my $pid = (<H>); + close (H); + if ($pid > 0) { + Win32::Process::KillProcess($pid, 0) + } + } + } +} + + +# Stop any processes started during a previous test. +snmptest_cleanup(); + +#Open the snmptest.cmd file and get the info +if (open(CMD, "<t/snmptest.cmd")) { + while ($line = <CMD>) { + if ($line =~ /HOST\s*=>\s*(.*?)\s+$/) { + $agent_host = $1; + } elsif ($line =~ /MIBDIR\s*=>\s*(.*?)\s+$/) { + $mibdir = $1; + } elsif ($line =~ /AGENT_PORT\s*=>\s*(.*?)\s+$/) { + $agent_port = $1; + } elsif ($line =~ /SNMPD\s*=>\s*(.*?)\s+$/) { + $snmpd_cmd = $1; + } elsif ($line =~ /SNMPTRAPD\s*=>\s*(.*?)\s+$/) { + $snmptrapd_cmd = $1; + } + } # end of while + close CMD; +} else { + die ("Could not start agent. Couldn't find snmptest.cmd file\n"); +} + +# Start snmpd and snmptrapd. + +#warn "\nStarting agents for test script $0\n"; + +my $scriptname = "snmptest"; +if ($0 =~ /^t[\/\\](.*)\.t$/) { + $scriptname = $1; +} + +if ($snmpd_cmd) { + run_async("t/snmpd.pid", "$snmpd_cmd", "-r -d -Lf t/snmpd-$scriptname.log -M+$mibdir -C -c t/snmptest.conf -p t/snmpd.pid ${agent_host}:${agent_port} >t/snmpd-$scriptname.stderr"); +} +if ($snmptrapd_cmd) { + run_async("t/snmptrapd.pid", "$snmptrapd_cmd", "-d -Lf t/snmptrapd-$scriptname.log -p t/snmptrapd.pid -M+$mibdir -C -c t/snmptest.conf -C ${agent_host}:${trap_port} >t/snmptrapd-$scriptname.stderr"); +} + +1; + diff --git a/perl/SNMP/typemap b/perl/SNMP/typemap new file mode 100644 index 0000000..f5e9826 --- /dev/null +++ b/perl/SNMP/typemap @@ -0,0 +1,2 @@ +SnmpSession * T_PTROBJ +SnmpMibNode * T_PTROBJ |