Re: Trap MIB strangeness

Juergen Schoenwaelder (schoenw@gaertner.de)
Wed, 28 May 1997 15:28:57 +0200

Keith Dart <kdart@cisco.com> said:

Keith> I was having some trouble including some mib files from Cisco
Keith> (*.my) into tkined. It can't parse the trap entries. I get
Keith> messages like this:

Keith> /usr/lib/tnm2.1.5/site/autoloadmibs/CISCO-FLASH-MIB-V1SMI.my: no parent
Keith> ciscoFlashMIBTrapPrefixTraps for node ciscoFlashCopyCompletionTrap

Keith> However, there is a "ciscoFlashMIBTrapPrefix" entry. After
Keith> investigating this, I found the culprit in the source file
Keith> "tnmMibParser.c":

Keith> case ENTERPRISE: {
Keith> if ((syntax = ReadKeyword(fp, keyword)) != LABEL) {
Keith> fprintf(stderr, "unable to parse ENTERPRISE %s\n", keyword);
Keith> return NULL;
Keith> }
Keith> enterprise = ckstrdup(keyword);
Keith> nodePtr->parentName = ckalloc(strlen(enterprise) + 8);
Keith> strcpy(nodePtr->parentName, enterprise);
Keith> ==> strcat(nodePtr->parentName, "Traps");
Keith> break;
Keith> }

Keith> This is appending the string "Traps" to the mib entry! Can
Keith> anyone explain why this is necessary?

This piece of code tries to convert a SNMPv1 trap definition into the
SNMPv2 definition. This usually means that a new MIB tree node needs
to be created which has a sub-identifier value of 0. The Cisco MIB you
are using has been converted from SNMPv2 format to SNMPv1 format using
SMICng. SMICng is clever and hence it creates a definition for the
missing MIB tree node. Scotty did not expect that this would happen
and hence we are in trouble.

The simplest workaround is to the original SNMPv2 CISOC MIBs instead
of the SNMPv1 MIBS generated by SMICng. Another approach is to make
the Tnm MIB parser code a bit more clever. Below is a patch (which is
taken from my current sources and which probably needs a helping hand
to fit into the 2.1.5 sources) which fixes this problem. To be honest,
the solution is not 100% correct, but I hope that it will work in >
90% of the cases. (To take care of the rest would mean to rewrite to
whole parser, which is not going to happen too soon.)

Juergen

--- /tmp/scotty-2.1.5/tnm/snmp/tnmMibParser.c Wed Oct 2 08:36:32 1996
+++ tnm/snmp/tnmMibParser.c Wed May 28 15:13:30 1997
@@ -1436,17 +1480,53 @@
return NULL;
}
break;
- case ENTERPRISE: {
- if ((syntax = ReadKeyword(fp, keyword)) != LABEL) {
+ case ENTERPRISE:
+ syntax = ReadKeyword(fp, keyword);
+ if (syntax == LEFTBRACKET) {
+ bracket = 1;
+ syntax = ReadKeyword(fp, keyword);
+ }
+ if (syntax != LABEL) {
fprintf(stderr, "unable to parse ENTERPRISE %s\n", keyword);
return NULL;
}
enterprise = ckstrdup(keyword);
- nodePtr->parentName = ckalloc(strlen(enterprise) + 8);
- strcpy(nodePtr->parentName, enterprise);
- strcat(nodePtr->parentName, "Traps");
+#if 1
+ /*
+ * This is a special hack. It is known to be buggy, but it
+ * works for most cases. (The rest will be done if people
+ * complain about it or when I have to rewrite this
+ * parser.) We check if we already have a node below the
+ * enterprise node which has the sub/identifier value 0.
+ * If not, we assume that we are converting a SNMPv1 MIB
+ * into a SNMPv2 MIB and that we have to create a new
+ * dummy MIB node for the subidentifier 0.
+ */
+
+ {
+ Tnm_MibNode *n;
+ for (n = *nodeList; n; n = n->nextPtr) {
+ if (n->subid == 0
+ && strcmp(n->parentName, keyword) == 0) break;
+ }
+ if (n) {
+ nodePtr->parentName = ckstrdup(n->label);
+ } else {
+ nodePtr->parentName = ckalloc(strlen(enterprise) + 8);
+ strcpy(nodePtr->parentName, enterprise);
+ strcat(nodePtr->parentName, "Traps");
+ }
+ }
+#endif
+ if (bracket) {
+ syntax = ReadKeyword(fp, keyword);
+ if (syntax != RIGHTBRACKET) {
+ fprintf(stderr, "expected closing bracket but got %s\n",
+ keyword);
+ return NULL;
+ }
+ }
break;
- }
case EOF:
return NULL;
default:

--
!! This message is brought to you via the `tkined & scotty' mailing list.
!! Please do not reply to this message to unsubscribe. To subscribe or
!! unsubscribe, send a mail message to <tkined-request@ibr.cs.tu-bs.de>.
!! See http://wwwsnmp.cs.utwente.nl/~schoenw/scotty/ for more information.