Hi David,

I first sent this email to users list instead of coders where I'm
subscribed and the email bounced, apology if you get two copies of this
email
-------------------------------------------------------------------

my comments are embedded below.

On Thu, 2009-02-26 at 08:44 +0000, Dave Shield wrote:
> 2009/2/25 EYRE Bernadette <[email protected]>:
> > Thank you both Mike and Harish, every little help counts.
> > a little more help from others on other points
> > will be greatly appreciated


> 
> Mike has answered the issues regarding general SNMP processing.
> I've no idea what information Harish has suggested, since this doesn't
> seem to have been copied to the list.

Harish email is listed below:

Hi Berndette,  
Maybe you can get good sample programs for GETNEXT here
http://www.opensource.apple.com/darwinsource/10.4.4.ppc/net_snmp-18/net-snmp/apps/
  Hope this helps.
Thanks 
Harish

> 
> But it's impossible to advise you in more detail as to your precise
> code, because you've given no informaiton about what your code
> actually looks like.


My code registers organization root oid.

(I substituted y and x in the oid to conceal some proprietary stuff)

I don't register the individual tables and scalars. The master agent
knows of this root oid only. It knows to forward all the get/getnext
calls under this oid to my subagent.

the registration code is as follow:

static     netsnmp_handler_registration *regInfo = NULL;
static oid aSubagentMibRoot_oid[] = {1,3,6,1,4,1,y,x};
size_t aSubagentMibRoot_oid_len   = OID_LENGTH(aSubagentMibRoot_oid);


int
init_aSubagent(void)
{
   int retVal;
 
   /*
   ** a debugging statement.
   **/
   DEBUGMSGTL((AGENT,
           "Initializing the aSubagent module\n"));

   netsnmp_mib_handler* handler = netsnmp_create_handler(
           "aSubagent", &aSubagent_handler );

   if (!handler)
   {
       snmp_log(LOG_ERR, "agent create handler failed in
init_aSubagent()\n");
       return -1;
   }

   DEBUGMSGTL((AGENT,
           "Initalizing aSubagent MIB root oid.  \n"));

   regInfo = netsnmp_handler_registration_create( "aSubagent", handler,
              aSubagentMibRoot_oid, aSubagentMibRoot_oid_len,
              HANDLER_CAN_RWRITE
              );

   if (!regInfo)
   {
       snmp_log(LOG_ERR, "agent create handler failed in init_aSubagent
\n");
       return -1;
   }
 
   retVal = netsnmp_register_handler(regInfo);
   if ( retVal != MIB_REGISTERED_OK ) {
        snmp_log(LOG_ERR, " agent handler registration failed \n");
        return -1;
   }
   
    DEBUGMSGTL((AGENT,
        "Done initalizing aSubagentRegister module\n"));

 return 0;
}
>    There are several different table helpers, which work in very
> different ways.   I'm not prepared to try and guess which one
> you are actually using, which makes it impossible to answer a
> question such as
> 

I don't register tables or scalars because of two reasons:
(1) we have several tables and scalars, the code would be huge if I
register all the tables, 
and (2) my sub-agent is not the keeper of the tables and scalars.
It is because of this I opted to a more generic agent that handles all
tables and scalars

the sub-agent connects to the master and its handler is called as
expected no problem here.

the sub-agent uses propitiatory library to obtain the type and the value
of the objects based on the oid passed to me by the master agent
(net-snmp). 

my handler code is vaguely like this:

int aSubagent_OID_handler( netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info *reqinfo,
                          netsnmp_request_info *requests)
{

   int ret = SNMP_ERR_NOERROR;
   netsnmp_request_info *request;
   netsnmp_variable_list *var;

   DEBUGMSGTL((AGENT,
           "********************aSubagent OID Handler is called\n"));

   for (request = requests; request; request = request->next) {
       /* column and row index encoded portion */
       var = request->requestvb;
       

      /*if (request->processed != 0)
         continue; */

       switch(reqinfo->mode)
       {
       case MODE_GET:

           err = myget(var); 
           if (err )
           {
             
             netsnmp_set_request_error(reqinfo, request,
                                          SNMP_NOSUCHINSTANCE);
           }
           break;

       case MODE_GETNEXT:
           
           err = mygetNext(var);
           if (err )
           {
             
             netsnmp_set_request_error(reqinfo, request,
                                          SNMP_NOSUCHINSTANCE);
           }
           break;


> > 3 - if I'm expected to return only the index (modified oid?)
> > of the next valid instance, do I modify the
> >  name field of the netsnmp_variable_list struct?
> 
> 
The handler is called with just an oid, no index and no type are passed
to sub agent.

In mygetnext() function, and when I'm called with getnext operation for
an oid, say,
var->name = {1,3,6,1,4,1,y,x,2}, if this oid has many instances what am
I expected to return, the first object instance value using 
snmp_set_var_typed_value( var, snmpType,
                   (uchar *)bufp, buflen);
call?

If so, do I modify the var->name and var->name_length to be of the
actual instance, since the instance will have 1.3.6.1.4.1.y.x.2.1 oid,
or do I use another net-snmp api to add the new oid to the passed in var
list?

if the object has multiple instances how do I make the master agent call
me again for the next instance? what is it that the master agent needs
from the sub-agent to tell it to call the registered handler again for
the next instance? This is the missing piece of the puzzle for me.

the second part of the puzzle is the table handling:
since I don't register a table, and when a get or getnext is received,
my code is the responsible party to determine that the oid is that of
the a table, and my code is also responsible to determine table index
and table instances from the underlying library and subsystems. there is
no problem here.

My question regarding table handling is what net-snmp api's I have to
use to build a reply for a table get or getnext calls? Do I build a
table reply by using snmp_varlist_add_variable() api and build the reply
all in one get/getnext call?

> Similarly:
> 
> > 2 - if I'm expected to return a value as a reply to GETNEXT
> > call, why then my subagent is called again with GET mode?
> 
> I can't answer that without some indication of what query is
> being sent to the master agent.   Is this a single GETNEXT
> request, "snmpwalk" or what?  What OID(s) are being requested,
> and how do these relate to the OIDs of the subagent tables?
> Exactly what OIDs does the subagent register anyway?
> 
please see above comments.

> 
> It's *very* difficult to answer the question
>    "why doesn't my code work".
> We need solid information in order to have a chance of helping you.
> 
> Dave
thanks for any help you can provide,
Bernadette


------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to