I've been having some problems with mib2c generating the
right code in the old ucd-style.  I'm using NET-SNMP 5.2.1
on Linux.  It's pretty easy to tweak the resulting code to fix the
problems, but I thought I'm mention the problems in case I'm
doing something obviously wrong.

The two problems are:

1) Objects that are 'accessible-for-notify' are treated as if they
   are read-only scalars.  They should just be ignored.
2) The object OIDs are too short in the variables table.

I've attached a short MIB that demonstrates both of these
problems.  I ran mib2c like this:

mib2c DEMO-MIB::demoProject

and selected the ucd-snmp style.  Here's a snippet from the
output demoProject.c file:

oid             demoProject_variables_oid[] = { 1, 3, 6, 1, 4, 1, 99999 };

/*
* variable4 demoProject_variables:
*   this variable defines function callbacks and type return information
*   for the  mib section
*/

struct variable4 demoProject_variables[] = {
   /*
* magic number , variable type , ro/rw , callback fn , L, oidsuffix
    */
#define DEMOVERSION        1
   {DEMOVERSION, ASN_OCTET_STR, RONLY, var_demoProject, 1, {1}},
#define DEMOTRAPID        2
   {DEMOTRAPID, ASN_INTEGER, RONLY, var_demoProject, 1, {1}},
#define DEMOTRAPNAME        3
   {DEMOTRAPNAME, ASN_OCTET_STR, RONLY, var_demoProject, 1, {2}},
};

DEMOTRAPID and DEMOTRAPNAME shouldn't be there at all
and the DEMOVERSION object is generated as
  .1.3.6.1.4.1.99999.1
when it should be
  .1.3.6.1.4.1.99999.1.1.1

Here's the output of snmptranslate on this object:

snmptranslate -On DEMO-MIB::demoVersion
.1.3.6.1.4.1.99999.1.1.1


DEMO-MIB DEFINITIONS ::= BEGIN

IMPORTS
    NOTIFICATION-TYPE,
    MODULE-IDENTITY,
    OBJECT-TYPE,
    Integer32,
    enterprises
        FROM SNMPv2-SMI

    DisplayString 
        FROM SNMPv2-TC
;

demoProject MODULE-IDENTITY
    LAST-UPDATED  "200510170000Z"
    ORGANIZATION  "Demo"
    CONTACT-INFO 
        ""
    DESCRIPTION
        ""

    REVISION  "200510170000Z"
        DESCRIPTION
            " 1.0  - Initial Document."

     ::= { enterprises 99999 }


-- top level MIB headings of the DEMO MIB 

demoTraps     OBJECT IDENTIFIER  ::= { demoProject 0 }
demoSystem    OBJECT IDENTIFIER  ::= { demoProject 1 }
demoTrapInfo  OBJECT IDENTIFIER  ::= { demoProject 2 }

-- DEMO System Information

demoSystemScalars  OBJECT IDENTIFIER  ::= { demoSystem 1 }

-- -----------------------------------------
-- DEMO System Scalars
-- -----------------------------------------

demoVersion OBJECT-TYPE
    SYNTAX      DisplayString
    MAX-ACCESS  read-only
    STATUS      current
    DESCRIPTION
        "Version string."
    ::= { demoSystemScalars 1 }

-- -----------------------------------------
-- DEMO traps
-- -----------------------------------------

demoTest NOTIFICATION-TYPE
    OBJECTS    { demoTrapId, demoTrapName }
    STATUS    current
    DESCRIPTION
    " Test trap. "
    ::= { demoTraps 1 }

-- -----------------------------------------
-- DEMO Trap Info: stuff sent with traps
-- -----------------------------------------

demoTrapId OBJECT-TYPE
    SYNTAX      Integer32
    MAX-ACCESS  accessible-for-notify
    STATUS      current
    DESCRIPTION
        "Trap Id."
    ::= { demoTrapInfo 1 }

demoTrapName OBJECT-TYPE
    SYNTAX      DisplayString
    MAX-ACCESS  accessible-for-notify
    STATUS      current
    DESCRIPTION
        "Trap name."
    ::= { demoTrapInfo 2 }

END

Reply via email to