Hello
After further checking we found that when sending a getnext request with
index higher than the last entry in the table the handler is called
repeatedly, as shown bleow.
I suppose the I do not update correctly the information in the get_next
function when reaching the end of the table.
handler:calling: main handler bulk_to_next
handler:calling: calling handler bulk_to_next for mode GETNEXT
handler:returned: handler bulk_to_next returned 0
handler:calling: calling handler table for mode GETNEXT
handler:calling: calling handler nsDemodEventsTable for mode GETNEXT
handler:returned: handler nsDemodEventsTable returned 0
handler:returned: handler table returned 0
handler:calling: main handler bulk_to_next
handler:calling: calling handler bulk_to_next for mode GETNEXT
handler:returned: handler bulk_to_next returned 0
handler:calling: calling handler table for mode GETNEXT
handler:calling: calling handler nsDemodEventsTable for mode GETNEXT
handler:returned: handler nsDemodEventsTable returned 0
handler:returned: handler table returned 0
Can anyone suggest why this happen?
Or a way to debug it?
MOST IMPORTANT: Should get next function, when reaching the end of the
table, return the number of the next OID???
Thank you
OUR GETNEXT FUNCTION
------------------------
/** determine the appropriate row for an fuzzy request */
static struct nsDemodEventsTable_entry *
nsDemodEventsTable_get_next_entry(netsnmp_handler_registration *reginfo,
netsnmp_request_info *request,
int column,
netsnmp_variable_list * indexes)
{
struct nsDemodEventsTable_entry *row = NULL;
oid build_space[MAX_OID_LEN];
size_t build_space_len = 0;
size_t index_oid_len = 0;
netsnmp_variable_list *idx = indexes;
long tmp;
ns_event *event;
syslog(LOG_ALERT,"SCHMIL called nsDemodEventsTable_get_next_entry");
/*
* XXX - Use the 'indexes' parameter to identify the
* next row in the table....
*/
event = (ns_event *) ns_ipcc_mem_alloc(sizeof(ns_event));
if (!event){
return NULL;
}
tmp = *(idx->val.integer) << 32;
syslog(LOG_ALERT,"SCHMIL received index 1 %d", *(idx->val.integer));
idx = idx->next_variable;
syslog(LOG_ALERT,"SCHMIL received index 2 %d", *(idx->val.integer));
tmp |= *(idx->val.integer);
event->utc.tv_sec = tmp;
idx = idx->next_variable;
syslog(LOG_ALERT,"SCHMIL received index 3 %d", *(idx->val.integer));
tmp = *(idx->val.integer) << 32;
idx = idx->next_variable;
syslog(LOG_ALERT,"SCHMIL received index 4 %d", *(idx->val.integer));
tmp |= *(idx->val.integer);
event->utc.tv_nsec = tmp;
syslog(LOG_ALERT,"SCHMIL indexes %llu %llu",
event->utc.tv_sec,event->utc.tv_nsec);
if (ns_events_get_next_event(event)){
syslog(LOG_ALERT,"SCHMIL called found event with indexes %llu %llu",
event->utc.tv_sec,event->utc.tv_nsec);
EventsTable_entry.nsDemodEventsSeverity = event->severity;
strncpy(EventsTable_entry.nsDemodEventsSource,event->source,COLUMN_NSDEM
ODEVENTSSOURCE_MAX_LEN);
EventsTable_entry.nsDemodEventsSource_len =
strlen(EventsTable_entry.nsDemodEventsSource);
strncpy(EventsTable_entry.nsDemodEventsEvent,event->event,COLUMN_NSDEMOD
EVENTSEVENT_MAX_LEN);
EventsTable_entry.nsDemodEventsEvent_len =
strlen(EventsTable_entry.nsDemodEventsSource);
strncpy(EventsTable_entry.nsDemodEventsDescription,event->description,CO
LUMN_NSDEMODEVENTSDESCRIPTION_MAX_LEN);
EventsTable_entry.nsDemodEventsDescription_len =
strlen(EventsTable_entry.nsDemodEventsSource);
row = &EventsTable_entry;
/*
* XXX .... update the 'indexes' parameter with the
* appropriate index values ...
*/
idx = indexes;
*(idx->val.integer) = (event->utc.tv_sec) >> 32;
syslog(LOG_ALERT,"SCHMIL transmit index 1 %d", *(idx->val.integer));
idx = idx->next_variable;
*(idx->val.integer) = (event->utc.tv_sec) & 0xFFFFFFFF;
syslog(LOG_ALERT,"SCHMIL transmit index 2 %d", *(idx->val.integer));
idx = idx->next_variable;
*(idx->val.integer) = (event->utc.tv_nsec) >> 32;
syslog(LOG_ALERT,"SCHMIL transmit index 3 %d", *(idx->val.integer));
idx = idx->next_variable;
*(idx->val.integer) = (event->utc.tv_nsec) & 0xFFFFFFFF;
syslog(LOG_ALERT,"SCHMIL transmit index 4 %d", *(idx->val.integer));
}
ns_ipcc_mem_free();
/*
* ... and update the requested OID to match this instance
*/
memcpy(build_space, reginfo->rootoid, /* registered oid */
reginfo->rootoid_len * sizeof(oid));
build_space_len = reginfo->rootoid_len;
build_space[build_space_len++] = 1; /* entry */
build_space[build_space_len++] = column; /* column */
build_oid_noalloc(build_space + build_space_len,
MAX_OID_LEN - build_space_len, &index_oid_len,
NULL, 0, indexes);
snmp_set_var_objid(request->requestvb, build_space,
build_space_len + index_oid_len);
/*
* Finally, return the data structure for this row
*/
syslog(LOG_ALERT,"SCHMIL &EventsTable_entry = %x row = %x",
&EventsTable_entry,row);
return row;
}
-----Original Message-----
From: Naama Bar Menachem
Sent: Wednesday, March 23, 2011 4:40 PM
To: 'Dave Shield'
Cc: Net-SNMP users
Subject: RE: Raw-table doesn't work.
Hi,
I managed to have the get and getnext work and we are getting response.
But sending a getnext request with indexes equal or greater than the
indexes of the last row in the table the handler is called repeatedly in
an infinite loop
I suppose that my getnext function is not handling right the case when
we get to the end of the table.
What am I doing wrong?
/** determine the appropriate row for an fuzzy request */
static struct nsDemodEventsTable_entry *
nsDemodEventsTable_get_next_entry(netsnmp_handler_registration *reginfo,
netsnmp_request_info *request,
int column,
netsnmp_variable_list * indexes)
{
struct nsDemodEventsTable_entry *row = NULL;
oid build_space[MAX_OID_LEN];
size_t build_space_len = 0;
size_t index_oid_len = 0;
netsnmp_variable_list *idx = indexes;
long tmp;
ns_event *event;
syslog(LOG_ALERT,"SCHMIL called nsDemodEventsTable_get_next_entry");
/*
* XXX - Use the 'indexes' parameter to identify the
* next row in the table....
*/
event = (ns_event *) ns_ipcc_mem_alloc(sizeof(ns_event));
if (!event){
return NULL;
}
tmp = *(idx->val.integer) << 32;
syslog(LOG_ALERT,"SCHMIL received index 1 %d", *(idx->val.integer));
idx = idx->next_variable;
syslog(LOG_ALERT,"SCHMIL received index 2 %d", *(idx->val.integer));
tmp |= *(idx->val.integer);
event->utc.tv_sec = tmp;
idx = idx->next_variable;
syslog(LOG_ALERT,"SCHMIL received index 3 %d", *(idx->val.integer));
tmp = *(idx->val.integer) << 32;
idx = idx->next_variable;
syslog(LOG_ALERT,"SCHMIL received index 4 %d", *(idx->val.integer));
tmp |= *(idx->val.integer);
event->utc.tv_nsec = tmp;
syslog(LOG_ALERT,"SCHMIL indexes %llu %llu",
event->utc.tv_sec,event->utc.tv_nsec);
if (ns_events_get_next_event(event)){
syslog(LOG_ALERT,"SCHMIL called found event with indexes %llu %llu",
event->utc.tv_sec,event->utc.tv_nsec);
EventsTable_entry.nsDemodEventsSeverity = event->severity;
strncpy(EventsTable_entry.nsDemodEventsSource,event->source,COLUMN_NSDEM
ODEVENTSSOURCE_MAX_LEN);
EventsTable_entry.nsDemodEventsSource_len =
strlen(EventsTable_entry.nsDemodEventsSource);
strncpy(EventsTable_entry.nsDemodEventsEvent,event->event,COLUMN_NSDEMOD
EVENTSEVENT_MAX_LEN);
EventsTable_entry.nsDemodEventsEvent_len =
strlen(EventsTable_entry.nsDemodEventsSource);
strncpy(EventsTable_entry.nsDemodEventsDescription,event->description,CO
LUMN_NSDEMODEVENTSDESCRIPTION_MAX_LEN);
EventsTable_entry.nsDemodEventsDescription_len =
strlen(EventsTable_entry.nsDemodEventsSource);
row = &EventsTable_entry;
/*
* XXX .... update the 'indexes' parameter with the
* appropriate index values ...
*/
idx = indexes;
*(idx->val.integer) = (event->utc.tv_sec) >> 32;
syslog(LOG_ALERT,"SCHMIL transmit index 1 %d", *(idx->val.integer));
idx = idx->next_variable;
*(idx->val.integer) = (event->utc.tv_sec) & 0xFFFFFFFF;
syslog(LOG_ALERT,"SCHMIL transmit index 2 %d", *(idx->val.integer));
idx = idx->next_variable;
*(idx->val.integer) = (event->utc.tv_nsec) >> 32;
syslog(LOG_ALERT,"SCHMIL transmit index 3 %d", *(idx->val.integer));
idx = idx->next_variable;
*(idx->val.integer) = (event->utc.tv_nsec) & 0xFFFFFFFF;
syslog(LOG_ALERT,"SCHMIL transmit index 4 %d", *(idx->val.integer));
}
ns_ipcc_mem_free();
/*
* ... and update the requested OID to match this instance
*/
memcpy(build_space, reginfo->rootoid, /* registered oid */
reginfo->rootoid_len * sizeof(oid));
build_space_len = reginfo->rootoid_len;
build_space[build_space_len++] = 1; /* entry */
build_space[build_space_len++] = column; /* column */
build_oid_noalloc(build_space + build_space_len,
MAX_OID_LEN - build_space_len, &index_oid_len,
NULL, 0, indexes);
snmp_set_var_objid(request->requestvb, build_space,
build_space_len + index_oid_len);
/*
* Finally, return the data structure for this row
*/
syslog(LOG_ALERT,"SCHMIL &EventsTable_entry = %x row = %x",
&EventsTable_entry,row);
return row;
}
-----Original Message-----
From: [email protected] [mailto:[email protected]] On
Behalf Of Dave Shield
Sent: Wednesday, March 23, 2011 10:43 AM
To: Naama Bar Menachem
Cc: Net-SNMP users
Subject: Re: Raw-table doesn't work.
On 22 March 2011 19:32, Naama Bar Menachem
<[email protected]> wrote:
> The code below implements a simple rax-table.
>
> Although the initialize function succeeds the handler isn't called
when we
> send a get or getnext request
Are you sure that the handler isn't being called at all?
Or is it simply that the agent isn't returning the expected results?
I don't see any debug or trace statements in the handler,
so it's difficult to know exactly what testing you've done.
Following a quick look at the code, I have two main comments:
a) I'm not sure whether you actually need the
nsDemodEventsTable_entry structure. You could
probably use the ns_entry structure directly,
and avoid having to copy data between the two.
b) There seems to be some confusion between logical
and bitwise operations.
Statements such as
tmp = *(idx->val.integer) < 32;
are setting a boolean value (is the value less than
32)
rather than a left-shift (high-order 32 bits), which I suspect is
what's intended.
And similarly for
*(idx->val.integer) = (event->utc.tv_sec) && 0xFFFFFFFF;
which will set the index value to 1 regardless
(anything AND true is true).
This probably ought to be using a bit-wise OR ('&')
rather than logical OR ('&&')
Both of those would explain why the agent wasn't returning the
correct results, but not why the handler wasn't being called at all.
If that is actually what is happening, then I'm at a loss to explain
why.
Dave
PS: Please post your queries *once*
There's no point in sending the same request twice,
just to add a missing signature!
------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users