[net-snmp] - table callback function - SNMP

This is a discussion on [net-snmp] - table callback function - SNMP ; HI, I have a problem: I'm implementing a (sub)agent using net-snmp framework. I register a table with the following code: /* create the table structure itself */ myIfTable_set = netsnmp_create_table_data_set("myIfTable"); /* comment this out or delete if you don't support ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: [net-snmp] - table callback function

  1. [net-snmp] - table callback function

    HI,
    I have a problem: I'm implementing a (sub)agent using net-snmp framework.
    I register a table with the following code:

    /* create the table structure itself */
    myIfTable_set = netsnmp_create_table_data_set("myIfTable");

    /* comment this out or delete if you don't support creation of new rows
    */
    myIfTable_set->allow_creation = 1;

    /* Adding indexes */
    netsnmp_table_dataset_add_index(myIfTable_set, ASN_INTEGER);

    #define COLUMN_IFTABLE_INDEX_S 1
    #define COLUMN_IFTABLE_PHISADDR 2

    /* Add row : qui definisco le colonne */
    netsnmp_table_set_multi_add_default_row(myIfTable_ set,
    COLUMN_IFTABLE_INDEX_S,
    ASN_INTEGER, 0, NULL, 0,
    COLUMN_IFTABLE_PHISADDR,
    ASN_OCTET_STR,1 , NULL, 0 ,
    0);


    /* Register the table */

    netsnmp_register_table_data_set(netsnmp_create_han dler_registration("myIfTab
    le",

    do_myIfTable, // <------------------- Callback func.

    myIfTable_oid,

    myIfTable_oid_len,

    HANDLER_CAN_RWRITE),

    myIfTable_set, NULL);



    In this way, I define a callback function (do_myIfTable), but it works ONLY
    if I add one or more rows: if the table is empty, the callback function
    don't works. Why? How can I handle the get/set requests in another way?

    Thanks very much
    Roberto



  2. Re: [net-snmp] - table callback function

    Roberto wrote:
    > I have a problem: I'm implementing a (sub)agent using net-snmp framework.
    > I register a table with the following code:
    >
    > /* create the table structure itself */
    > myIfTable_set = netsnmp_create_table_data_set("myIfTable");


    [snip]


    > In this way, I define a callback function (do_myIfTable), but it works
    > ONLY if I add one or more rows: if the table is empty, the callback
    > function don't works.


    Yes.
    The 'table_dataset' helper is built around the idea that the contents
    of the table are stored internally to the agent, and the helper handler
    takes care of deciding which instances to return.
    Your handler is only called to allow you to tweak these internal
    values (e.g. to adjust a particular column value, or to punch holes in
    the table).

    > How can I handle the get/set requests in another way?


    If you want to have control yourself over what rows a particular
    table contains, then I suggest you use one of the other table helpers.
    Either table_iterator or table_array.

    Dave

  3. Re: [net-snmp] - table callback function

    Thanks Dave.

    I found that it's possible to manage empty tables also using the macro
    REGISTER_MIB:


    // Define the variable ------------------------
    struct variable4 my_variables[] = {
    /* magic number , variable type , ro/rw , callback fn , L,
    oidsuffix */
    /* (L = length of the oidsuffix) */

    #define MYINDEX 1
    { MYINDEX , ASN_INTEGER , RONLY , var_callbackFunction, 3,
    { 2,1,1 } },
    };


    // Register the variable ------------------------
    REGISTER_MIB("provina", lvs_variables, variable4, myIfTable_oid);


    // The callback function is so defined: --------
    unsigned char *
    var_lvsServiceTable(struct variable *vp,
    oid *name,
    size_t *length,
    int exact,
    size_t *var_len,
    WriteMethod **write_method)
    {

    printf ("Inside the callback Function!\n");

    int aNumber = 3;
    switch(vp->magic) {


    case MYINDEX:
    printf ("Inside MYINDEX\n");

    *var_len = sizeof(aNumber );
    return (unsigned char *)&aNumber ;
    default:
    ERROR_MSG("");
    }

    return NULL;
    }

    ################################################## ###########

    It works but when I get a walk routine, it never stop!
    I think your solution is better...

    Roberto



+ Reply to Thread