Discussion:
snmptranslate and read_objid()
Mihir Lala
2005-06-16 01:40:29 UTC
Permalink
If I run snmptranslate as follows:

snmptranslate -m MIBS/smi.my:MIBS/v2-smi.my:/MIBS/ENTERPRISE-1-STATS.my
.1.3.6.1.4.1.55555.2.4.2.0.1

...where 55555 is the enterprise Id and ENTERPRISE-1-STATS.my is a
proprietary MIB for this enterprise, then I get the output as:

ENTERPRISE-1-STATS-MIB:stat1

However if I run the same command with an enterprise ID such as 666666,
then the output is as:

SNMPv2-SMI::enterprise.66666.2.4.2.0.1

I see that snmptranslate.c uses read_objid() to lookup the name from
the tree that is loaded.

What I'd like to do is to get an "Unknown OID" in the second case;
basically having read_objid() return a failure.

Is this possible?

I am trying to write a trap receiver application, that can filter traps
(drop them) if they are coming from an enterprise (or MIB) that is not
loaded into this application.

thanks,
mrl






__________________________________
Discover Yahoo!
Get on-the-go sports scores, stock quotes, news and more. Check it out!
http://discover.yahoo.com/mobile.html
Robert Story
2005-06-21 16:37:12 UTC
Permalink
On Wed, 15 Jun 2005 20:38:48 -0700 (PDT) Mihir wrote:
ML> However if I run the same command with an enterprise ID such as 666666,
ML> then the output is as:
ML>
ML> SNMPv2-SMI::enterprise.66666.2.4.2.0.1
ML>
ML> I see that snmptranslate.c uses read_objid() to lookup the name from
ML> the tree that is loaded.
ML>
ML> What I'd like to do is to get an "Unknown OID" in the second case;
ML> basically having read_objid() return a failure.
ML>
ML> Is this possible?

No. The functionality of read_objid is well documented, and can't change.
However, you could write your own version to do what you want.
--
NOTE: messages sent directly to me, instead of the lists, will be deleted
unless they are requests for paid consulting services.

Robert Story; NET-SNMP Junkie
Support: <http://www.net-snmp.org/> <irc://irc.freenode.net/#net-snmp>
Archive: <http://sourceforge.net/mailarchive/forum.php?forum=net-snmp-users>

You are lost in a twisty maze of little standards, all different.
Mihir Lala
2005-06-21 20:13:24 UTC
Permalink
Hi,

I have snmptrapd running with a few MIBs known to it via the -m option.

I am generating a trap using the snmptrap application sending it the
notification objects as specified in the MIB. All works fine.

Now, when I generate a trap with an object that has a wrong 'type',
snmptrapd rightly complains with a message like:
"Wrong Type (should be INTEGER): STRING: "foo"

However when I generate a trap for an object defined to be of
SYNTAX INTEGER ( 0..100)

.. with a value of 102, snmptrapd does not complain.

Is there anyway I can make snmptrapd complain about this? Is this
information available in the tree that is populated when the MIB file
is parsed?

thanks,
mrl





__________________________________
Do you Yahoo!?
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250
Robert Story
2005-06-24 17:43:12 UTC
Permalink
On Tue, 21 Jun 2005 15:12:47 -0700 (PDT) Mihir wrote:
ML> Now, when I generate a trap with an object that has a wrong 'type',
ML> snmptrapd rightly complains with a message like:
ML> "Wrong Type (should be INTEGER): STRING: "foo"
ML>
ML> However when I generate a trap for an object defined to be of
ML> SYNTAX INTEGER ( 0..100)
ML>
ML> .. with a value of 102, snmptrapd does not complain.
ML>
ML> Is there anyway I can make snmptrapd complain about this? Is this
ML> information available in the tree that is populated when the MIB file
ML> is parsed?

The info should be in the tree, so you could add some code to snmptrapd to
check ranges. I think snmpset does this type of checking, so you could start
looking there... you might even make snmptrap check this and complain before
sending the trap...
--
NOTE: messages sent directly to me, instead of the lists, will be deleted
unless they are requests for paid consulting services.

Robert Story; NET-SNMP Junkie
Support: <http://www.net-snmp.org/> <irc://irc.freenode.net/#net-snmp>
Archive: <http://sourceforge.net/mailarchive/forum.php?forum=net-snmp-users>

You are lost in a twisty maze of little standards, all different.
Dave Shield
2005-06-22 06:20:20 UTC
Permalink
Post by Mihir Lala
I run the same command with an enterprise ID such as 666666,
SNMPv2-SMI::enterprise.66666.2.4.2.0.1
What I'd like to do is to get an "Unknown OID" in the second case;
basically having read_objid() return a failure.
How would you define a failure?
For example, consider:

$ snmptranslate .1.3.6.1.2.1.1
SNMPv2-MIB::system
$ snmptranslate .1.3.6.1.2.1.1.0
SNMPv2-MIB::system.0
$ snmptranslate .1.3.6.1.2.1.1.1
SNMPv2-MIB::system.1
$ snmptranslate .1.3.6.1.2.1.1.0.1.2.3
SNMPv2-MIB::system.0.1.2.3

The last three are "partial" translations, in that they still
include trailing numeric subidentifiers. But they are also
"full" translations, because these trailing values are the
instance subidentifiers (though only one is actually valid)

Would you classify these are failures or not?
Post by Mihir Lala
I am trying to write a trap receiver application, that can filter traps
(drop them) if they are coming from an enterprise (or MIB) that is not
loaded into this application.
Surely the existing snmptrapd can do that - by supplying a suitable
default trap handler entry?

Dave
Vishwanath Kalbagilmath
2005-07-27 14:24:10 UTC
Permalink
Hi All,

What are the object types (ex: DisplayString) that are supported in SNMP
V1. Can anyone provide me sample v1 mib.

Thanks in adv.
Vishwanath
Post by Dave Shield
Post by Mihir Lala
I run the same command with an enterprise ID such as 666666,
SNMPv2-SMI::enterprise.66666.2.4.2.0.1
What I'd like to do is to get an "Unknown OID" in the second case;
basically having read_objid() return a failure.
How would you define a failure?
$ snmptranslate .1.3.6.1.2.1.1
SNMPv2-MIB::system
$ snmptranslate .1.3.6.1.2.1.1.0
SNMPv2-MIB::system.0
$ snmptranslate .1.3.6.1.2.1.1.1
SNMPv2-MIB::system.1
$ snmptranslate .1.3.6.1.2.1.1.0.1.2.3
SNMPv2-MIB::system.0.1.2.3
The last three are "partial" translations, in that they still
include trailing numeric subidentifiers. But they are also
"full" translations, because these trailing values are the
instance subidentifiers (though only one is actually valid)
Would you classify these are failures or not?
Post by Mihir Lala
I am trying to write a trap receiver application, that can filter traps
(drop them) if they are coming from an enterprise (or MIB) that is not
loaded into this application.
Surely the existing snmptrapd can do that - by supplying a suitable
default trap handler entry?
Dave
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Net-snmp-users mailing list
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
Mihir Lala
2005-06-22 13:32:08 UTC
Permalink
Post by Dave Shield
Post by Mihir Lala
I run the same command with an enterprise ID such as 666666,
SNMPv2-SMI::enterprise.66666.2.4.2.0.1
What I'd like to do is to get an "Unknown OID" in the second case;
basically having read_objid() return a failure.
How would you define a failure?
$ snmptranslate .1.3.6.1.2.1.1
SNMPv2-MIB::system
$ snmptranslate .1.3.6.1.2.1.1.0
SNMPv2-MIB::system.0
$ snmptranslate .1.3.6.1.2.1.1.1
SNMPv2-MIB::system.1
$ snmptranslate .1.3.6.1.2.1.1.0.1.2.3
SNMPv2-MIB::system.0.1.2.3
The last three are "partial" translations, in that they still
include trailing numeric subidentifiers. But they are also
"full" translations, because these trailing values are the
instance subidentifiers (though only one is actually valid)
Would you classify these are failures or not?
It would be more like a prefix (or subtree) match. If there is a "full"
translation to of an OID that s given then it's a success else a
failure.

In your example, a translate for .1.3.6.1.2.1.1 would return a success

but .1.3.6.1.2.1.1.0 or any of the others would be a failure.
Post by Dave Shield
Post by Mihir Lala
I am trying to write a trap receiver application, that can filter
traps
Post by Mihir Lala
(drop them) if they are coming from an enterprise (or MIB) that is
not
Post by Mihir Lala
loaded into this application.
Surely the existing snmptrapd can do that - by supplying a suitable
default trap handler entry?
Yes, I could have a handler, but the idea was to leverage the tree that
is already built using the MIB files and not having to configure OIDs.

On receiving a trap, the application would simply lookup the tree for
the "snmp_trap_oid" (second varbind in the v2c/v3 notifications) and
either process or drop the trap based on the the lookup return value.

In this way the only traps that get acknowledged are the ones whose MIB
files are loaded into the snmptrapd application.

thanks,
mrl



____________________________________________________
Yahoo! Sports
Rekindle the Rivalries. Sign up for Fantasy Football
http://football.fantasysports.yahoo.com
Dave Shield
2005-06-22 14:17:35 UTC
Permalink
Post by Mihir Lala
Post by Dave Shield
How would you define a failure?
$ snmptranslate .1.3.6.1.2.1.1
$ snmptranslate .1.3.6.1.2.1.1.0
$ snmptranslate .1.3.6.1.2.1.1.1
$ snmptranslate .1.3.6.1.2.1.1.0.1.2.3
It would be more like a prefix (or subtree) match. If there is a "full"
translation to of an OID that s given then it's a success else a
failure.
In your example, a translate for .1.3.6.1.2.1.1 would return a success
but .1.3.6.1.2.1.1.0 or any of the others would be a failure.
OK - so consider a slightly different set of examples:

$ snmptranslate .1.3.6.1.2.1.1.2
$ snmptranslate .1.3.6.1.2.1.1.2.0
$ snmptranslate .1.3.6.1.2.1.1.2.1
$ snmptranslate .1.3.6.1.2.1.1.2.0.1.2.3

That's the same structure, but working with 'SNMPv2-MIB::sysObjectID'.
According to your definition, all but the first one would count as
failures (since there'd be numeric subidentifiers left over).

But the second OID listed is the one that's actually used in practice
(being the OID of the sysObjectID scalar instance), so it seems a
bit perverse to call that a "failure".
It certainly wouldn't be appropriate as part of the main SNMP library.
Post by Mihir Lala
Yes, I could have a handler, but the idea was to leverage the tree that
is already built using the MIB files and not having to configure OIDs.
On receiving a trap, the application would simply lookup the tree for
the "snmp_trap_oid" (second varbind in the v2c/v3 notifications) and
either process or drop the trap based on the the lookup return value.
In this way the only traps that get acknowledged are the ones whose MIB
files are loaded into the snmptrapd application.
Yup - you could implement that using the existing snmptrapd framework.
Define a default trap handler, called for *all* incoming traps.
That handler should take the trap OID (which is one of the input
parameters), do a read_objid() lookup, and check whether the result
had a trailing numeric subidentifier.
If it does, then return without doing any more processing.
Otherwise, it would continue with whatever acknowledgements, etc
you needed to do.

That's perfectly possible with the current Net-SNMP toolkit. I don't
think you need to add any new APIs.


Dave
Mihir Lala
2005-06-22 16:25:13 UTC
Permalink
Post by Mihir Lala
Post by Mihir Lala
Yes, I could have a handler, but the idea was to leverage the tree
that
Post by Mihir Lala
is already built using the MIB files and not having to configure
OIDs.
Post by Mihir Lala
On receiving a trap, the application would simply lookup the tree
for
Post by Mihir Lala
the "snmp_trap_oid" (second varbind in the v2c/v3 notifications)
and
Post by Mihir Lala
either process or drop the trap based on the the lookup return
value.
Post by Mihir Lala
In this way the only traps that get acknowledged are the ones whose
MIB
Post by Mihir Lala
files are loaded into the snmptrapd application.
Yup - you could implement that using the existing snmptrapd
framework.
Define a default trap handler, called for *all* incoming traps.
ok, so far so good.
Post by Mihir Lala
That handler should take the trap OID (which is one of the input
parameters), do a read_objid() lookup, and check whether the result
had a trailing numeric subidentifier.
After a few experiments and if I understand you correctly, would this
work as:

void
default_handler(const oid *objid_rcvd_in_trap, size_t len)
{
char oid_buf[256];
oid oid_out[MAX_OID_LEN];
size_t oid_out_len;

snprint_objid(oid_buf, sizeof(oid_buf), objid_rcvd_in_trap, len);

read_objid(oid_buf, oid_out, &oid_out_len);

if(oid_out_len < len) {
/* failure, discard */
} else {
/* success, move on */
}
}
Post by Mihir Lala
If it does, then return without doing any more processing.
Otherwise, it would continue with whatever acknowledgements, etc
you needed to do.
That's perfectly possible with the current Net-SNMP toolkit. I
don't
think you need to add any new APIs.
thanks,
mrl

P.S: I dropped he first part of the email since it seems it isn't
relevant to what I wan't to achieve.

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Mihir Lala
2005-06-27 13:24:20 UTC
Permalink
Post by Robert Story
ML> Now, when I generate a trap with an object that has a wrong
'type',
ML> "Wrong Type (should be INTEGER): STRING: "foo"
ML>
ML> However when I generate a trap for an object defined to be of
ML> SYNTAX INTEGER ( 0..100)
ML>
ML> .. with a value of 102, snmptrapd does not complain.
ML>
ML> Is there anyway I can make snmptrapd complain about this? Is this
ML> information available in the tree that is populated when the MIB
file
ML> is parsed?
The info should be in the tree, so you could add some code to
snmptrapd to
check ranges. I think snmpset does this type of checking, so you
could start
looking there... you might even make snmptrap check this and complain
before
sending the trap...
Just an FYI, snmpset doesn't seem to be doing range checking. It relies
on the agent to return a "wrong value" error code.

The information is there in the tree though so I can get to it.

thanks,
mihir

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Wes Hardaker
2005-06-27 17:42:11 UTC
Permalink
Mihir> What I'd like to do is to get an "Unknown OID" in the second case;
Mihir> basically having read_objid() return a failure.

Mihir> Is this possible?

Mihir> I am trying to write a trap receiver application, that can filter traps
Mihir> (drop them) if they are coming from an enterprise (or MIB) that is not
Mihir> loaded into this application.

No... It's not. All OIDs are completely legal, even if you can't
translate them into a name. It'd be better to look for
enterprises.NUMBER in a regular expression or something and drop
anything did wasn't a number.
--
Wes Hardaker
Sparta, Inc.
Loading...