On Tue, Dec 4, 2012 at 11:08 AM, STOTTS Timothy <
timothy.sto...@transport.alstom.com> wrote:
> How can I do the following?
>
> 1. create a handler registration for the top OID of:
> const oid top_oid[] = { 1 };
> const size_t top_oid_len = OID_LENGTH(top_oid);
>
> 2. inject the handler such that any GET, SET, GETBULK (any USM
> authenticated access at all) of any node under the subtree of the top OID
> will call a function I specify
>
> 3. the handler function will have access to a value in memory that
> represents the IP address of the SNMP manager that is calling this SNMP
> agent as multiple managers/browsers will be accessing the device, and a
> decision must be made based on IP address
>
I seem to recall looking into getting the source IP address of the
originating manager
and concluding that the information is not currently available at this
level of messaging/API.
But,
... snip ...
I had to do this (sortof) in my (Perl based) SNMP network simulator.
NOTE, this is not an 'injector' as you are asking about,
but a complete replacement handler for any OIDs (which was what _I_ needed).
What I found was that I couldn't register the 'top OID' of '1'
but what I could do was register for each of the next levels down.
This isn't really a problem because your probably only interested in '1.3'.
My Perl snippet is below,
I hope it helps you, or gives you ideas.
Fulko
use NetSNMP::OID (':all');
use NetSNMP::agent (':all');
use NetSNMP::ASN (':all');
my $oidId = '1.0'; # start at the top
of the ISO tree...
while (1) {
$oid = getNextOidById($oidId) if (!defined($oid)); # look for the
'next known' OID/variable (it may be in another sub-tree)
last unless defined($oid); # we're done
searching if nothing was found
last unless (my ($suboid) = ($oid =~ /^1\.(\d*)/)); # also done if we
leave the '1.x' tree, else extract the 'x' part of the OID
$oidId = "1.$suboid"; # build a new base
OID based on the sub-tree ID we found something in
my $regoid = new NetSNMP::OID(".$oidId"); # note that we
have to prepend a leading dot onto the OID
$agent->register($0, $regoid, \&my_snmp_handler); # in order to
register to receive transactions for that sub-tree
print STDERR "Simulating OID sub-tree: $oidId\n";
$suboid++; # bump to the next
potential sub-tree after the one we found
$oidId = "1.$suboid"; # and make a new
top node
}
sub my_snmp_handler {
my ($handler, $registration_info, $request_info, $requests) = @_;
my $targetIp = inet_ntoa($request_info->getTargetIp());
for (my $request = $requests; $request; $request = $request->next()) {
# loop over each component of the request
simulate($targetIp, $request_info, $request);
# and pass it to the simulator
}
}
# the simulator is invoked with:
# the address of the simulated host,
# the SNMP operation (get, getnext, etc.)
# the request object
sub simulate {
my ($targetIp, $request_info, $request) = @_;
my $mode = $request_info->getMode();
my $oid = $request->getOID();
$oid =~ s/^ccitt\.//; # 'iso' comes in as 'ccitt.1', so
we need to strip off the front part and leave the '.1' behind
$oid =~ s/^iso/1/; # and then... replace the 'iso' at
the front of the OID with its numeric value
if ($mode != MODE_GET && $mode != MODE_GETNEXT ) {
print "Unsupported Operation - $mode\n";
$request->setError($request_info, SNMP_ERR_GENERR); # return the
'genErr' error
return;
}
...
$request->setValue($type, $value); # return the appropriate
value and type
...
if ($mode == MODE_GETNEXT) { # during getnext's only...
$request->setOID(find_next_oid...()); # replace the pre-filled-in
response OID with
} # whatever we determine the
'next' one should be
}
------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users