Search code examples
csnmpnet-snmpmib

How to list SMIv1 MIBS with net-snmp MIB API in C/C++?


I want to display a list of various MIBS with net-snmp and show other informations related to the SNMP tree structure.

Now it turns out that my customer's SMIv1 MIBS does not show up in the listing, but are correctly loaded by net-snmp.

Sample net-snmp code goes through the MIB structure in memory and assumes that we have the SMIv2 bijection between a MIB and a MODULE-IDENTITY note in the tree. So when we find a MODULE-IDENTITY node, we find a MIB.

Does anybody knows what is the correct method to list SMIv1 MIBS with net-snmp ? (or any workaround ?)

  // Read mibs and obtain memory structures
  struct tree * head = read_all_mibs();
  // Walk down the SNMP tree
  for ( struct tree * tp = head; tp; tp = tp->next_peer )
  {
     // Module-indentity
     if ( tp->type == TYPE_MODID )
     {
        // XXX We found a SMIv2 MIB, but SMIv1 MIBs have no MODULE-IDENTITY node
     }
  }

NB: I found a converter smidump (a command line tool, or as a web service at http://www.ibr.cs.tu-bs.de/projects/libsmi/tools/) but it does not adds a MODULE-IDENTITY node to the MIB.

Edit: Note that any tool that would convert an old SNMP MIB to a more recent one (SMIv2 style), could solve the problem. Any help in that particular direction ?

One suggestion could be, in the absence of MODULE-IDENTIFIER, to find the root OBJECT-IDENTIFIER of the MIB (sometimes the MIB will add node at many different and unrelated places so this would not work). With a root node I could show most of the tree related to that MIB.


Solution

  • The only solutions my colleague and I found to fix the problem, was to convert the "top-level" MIB(s) into a more SNMPv2-like structure. That is 1) import the type MODULE-IDENTITY, 2) replace the top-level node with a MODULE-IDENTITY declaration.

        ...
        IMPORTS
           MODULE-IDENTITY
           FROM
           SNMPv2-SMI
        ...
    
        -- Removed top-level node
        --    compaq              OBJECT IDENTIFIER ::= { enterprises 232 }
    
        -- Add a fake module-identity node
        compaq MODULE-IDENTITY
        LAST-UPDATED   "200111120000Z"
        ORGANIZATION   "COMPAQ"
        CONTACT-INFO
               "why.still.using.snmpv1@compaq.com"
        DESCRIPTION
               "why does compaq still provide these mibs in 2013?"
        REVISION       "9407210000Z"
        DESCRIPTION
               "Normal fixed MIB module."
        ::= { enterprises 232 }
    

    With this fix, the net-snmp library will show us a module-identity node for our MIB, just like with every other SNMPv2 mibs..