Re: Help!I need 2 short snmp functions to go into modified discover

Juergen Schoenwaelder (schoenw@ibr.cs.tu-bs.de)
Thu, 24 Aug 1995 10:12:41 +0200

Hi!

jaques@lsil.com (Bob Jaques) said:

Bob> insted of testing via icmp I want to

Bob> test to see if snmp request on no of interfaces returns and is
Bob> greater than 1

Bob> test via snmp for interface 0 being local loop.

Bob> if interfaces > 1 and interface0 is not local loop this must
Bob> be a router or a least a multi-homed host.

Below is a simple minded implementation of two procs IsMultiHomed
and IsRouter. Note, you have to walk the ifTable as the loopback
can be anywhere in the table. Now the things that make a good
solution non trivial:

1) The procs expect a well configured SNMP session handle. Therefore
you have to know or to guess the parameters (e.g. community strings)
before you can use them.

2) You will have to rewrite these simple procs to make them
asynchronous so that you can query a few hundred hosts
simultaneously. Otherwise you will start waiting for those
bad guys that don't answer your SNMP requests.

3) IsRouter could actually rely on testing ipForwarding.0 but
there are agents out there that always claim to have forwarding
enabled. Therefore an additional check for IsMultiHomed makes
sense. There are more of these hurdles to take when writing
SNMP based applications...

4) To avoid the problem of retrieving SNMP values multiple times,
it would be a good idea to download all the interesting stuff
in one discover step and to analyze it in later steps.

Problem 1) has to be solved before you should think about the other
problems. Guessing SNMP session parameters and saving them for later
use is easy. The question is: how much guessing is allowed? Trying
public will probably be accepted by many people. But what about a
small dictionary of other frequently used SNMPv1 communities? When
does discovering turn into cracking into SNMP agents?

Juergen

proc IsMultiHomed {s} {
set ifNumber [lindex [lindex [$s get ifNumber.0] 0] 2]
if {$ifNumber == 1} {
return 0
}
set cnt 0
$s walk vbl ifType {
if {[lindex [lindex $vbl 0] 2] != "softwareLoopback"} {
incr cnt
}
}
return [expr $cnt > 1]
}

proc IsRouter {s} {
set ipForwarding [lindex [lindex [$s get ipForwarding.0] 0] 2]
if {$ipForwarding == "forwarding"} {
return [IsMultiHomed $s]
}
return 0
}

# a simple main to test the procs above

mib load rfc1213.mib
foreach host $argv {
set error [catch {
set s [snmp session -address $host]
set m [IsMultiHomed $s]
set r [IsRouter $s]
$s destroy
} msg]
if {$error} {
puts "$host:\t $msg"
} else {
puts "$host:\t IsMultiHomed = $m IsRouter = $r"
}
}
exit