--0-774094194-1164654143=:47795
Content-Type: multipart/alternative; boundary="0-819376498-1164654143=:47795"

--0-819376498-1164654143=:47795
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit


Forgot to mention, for some snmpd gives the same value for both the var binds in case of integer variables. (setting two table vars in one PDU)

Thanks
Reddy

Note: forwarded message attached.
--0-819376498-1164654143=:47795
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit


Forgot to mention, for some snmpd gives the same value for both the var binds in case of integer variables. (setting two table vars in one PDU)

Thanks
Reddy

Note: forwarded message attached.
--0-819376498-1164654143=:47795--
--0-774094194-1164654143=:47795
Content-Type: message/rfc822
Content-Transfer-Encoding: 8bit

Received: from [139.85.50.248] by web58710.mail.re1.yahoo.com via HTTP;
Mon, 27 Nov 2006 10:54:23 PST
Date: Mon, 27 Nov 2006 10:54:22 -0800 (PST)
From: Venkata Guddeti
Subject: Re: Problem in setting values for two Table variables in one PDU
To: Dave Shield
Cc: net-snmp-coders@lists.sourceforge.net
In-Reply-To:
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="0-1482494378-1164653662=:88797"
Content-Transfer-Encoding: 8bit
Content-Length: 6447

--0-1482494378-1164653662=:88797
Content-Type: multipart/alternative; boundary="0-1997240224-1164653662=:88797"

--0-1997240224-1164653662=:88797
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Dear All
Yes, Even if I switch the order of variables, the problem is with the 2nd variable.
After more investigation in to this problem, I understood that set is not working if I try to set values for any two variables of a table in one PDU.

I am attaching the code here in a file tables_gbbfcommn.c: (Code is generated using iterate.conf option)

I have tried setting values for nsCacheTimeout.1.3.6.1.2.1.4.35 and nsCacheTimeout.1.3.6.1.2.1.4.34, as these are table params. Only thingis that these are implemented in snmpd itself. I am running my code as subagent.

Your help is greatly appreciated.
Thank you very much
Reddy


Dave Shield wrote: On 21/11/06, Venkata Guddeti wrote:
> When the snmpd receives one PDU with set for two variables in a table, my
> subagent does not get the values for both the variables properly.
> In the subagent, the value range
> check fails and returns wrong value error or wrong type error for the 2nd
> variable in the set. It is always the 2nd variable's value that is wrong.


So if you switch the order of the two varbinds, it's still the second
varbind that fails - correct?

What does the code that implements this table look like?

Dave


--0-1997240224-1164653662=:88797
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Dear All
Yes, Even if I switch the order of variables, the problem is with the 2nd variable.
After more investigation in to this problem, I understood that set is not working if I try to set values for any two variables of a table in one PDU.

I am attaching the code here in a file tables_gbbfcommn.c: (Code is generated using iterate.conf option)

I have tried setting values for nsCacheTimeout.1.3.6.1.2.1.4.35 and nsCacheTimeout.1.3.6.1.2.1.4.34, as these are table params. Only thingis that these are implemented in snmpd itself. I am running my code as subagent.

Your help is greatly appreciated.
Thank you very much
Reddy


Dave Shield <D.T.Shield@csc.liv.ac.uk> wrote:
On 21/11/06, Venkata Guddeti wrote:
> When the snmpd receives one PDU with set for two
variables in a table, my
> subagent does not get the values for both the variables properly.
> In the subagent, the value range
> check fails and returns wrong value error or wrong type error for the 2nd
> variable in the set. It is always the 2nd variable's value that is wrong.

So if you switch the order of the two varbinds, it's still the second
varbind that fails - correct?

What does the code that implements this table look like?

Dave


--0-1997240224-1164653662=:88797--
--0-1482494378-1164653662=:88797
Content-Type: text/x-csrc; name="tables_gbbfcommon.c"
Content-Description: 2180923674-tables_gbbfcommon.c
Content-Disposition: inline; filename="tables_gbbfcommon.c"

/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.iterate.conf,v 5.9 2003/06/04 00:14:41 hardaker Exp $
*/

#include
#include
#include
#include "tables_gbbfcommon.h"

/** Initialize the fileTable table by defining its contents and how it's structured */
void
initialize_table_fileTable(void)
{
static oid fileTable_oid[] =
{ 1, 3, 6, 1, 4, 1, 303, 3, 3, 41, 28 };
netsnmp_table_registration_info *table_info;
netsnmp_handler_registration *my_handler;
netsnmp_iterator_info *iinfo;

/** create the table registration information structures */
table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_inf o);
iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);

/** if your table is read only, it's easiest to change the
HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY */
my_handler = netsnmp_create_handler_registration("fileTable",
fileTable_handler,
fileTable_oid,
OID_LENGTH
(fileTable_oid),
HANDLER_CAN_RWRITE);

if (!my_handler || !table_info || !iinfo) {
snmp_log(LOG_ERR, "malloc failed in initialize_table_fileTable");
return; /* Serious error. */
}

/************************************************** *
* Setting up the table's definition
*/
netsnmp_table_helper_add_indexes(table_info, ASN_OCTET_STR, /* index: fileTableIndex */
0);

/** Define the minimum and maximum accessible columns. This
optimizes retrival. */
table_info->min_column = 1;
table_info->max_column = 7;

/*
* iterator access routines
*/
iinfo->get_first_data_point = fileTable_get_first_data_point;
iinfo->get_next_data_point = fileTable_get_next_data_point;

/** you may wish to set these as well */
#ifdef MAYBE_USE_THESE
iinfo->make_data_context = fileTable_context_convert_function;
iinfo->free_data_context = fileTable_data_free;

/** pick *only* one of these if you use them */
iinfo->free_loop_context = fileTable_loop_free;
iinfo->free_loop_context_at_end = fileTable_loop_free;
#endif

/** tie the two structures together */
iinfo->table_reginfo = table_info;

/************************************************** *
* registering the table with the master agent
*/
DEBUGMSGTL(("initialize_table_fileTable",
"Registering table fileTable as a table iterator\n"));
netsnmp_register_table_iterator(my_handler, iinfo);
}

/** Initializes the tables_gbbfcommon module */
void
init_tables_gbbfcommon(void)
{

/** here we initialize all the tables we're planning on supporting */
initialize_table_fileTable();
}

/** returns the first data point within the fileTable table data.

Set the my_loop_context variable to the first data point structure
of your choice (from which you can find the next one). This could
be anything from the first node in a linked list, to an integer
pointer containing the beginning of an array variable.

Set the my_data_context variable to something to be returned to
you later (in your main fileTable_handler routine) that will provide
you with the data to return in a given row. This could be the
same pointer as what my_loop_context is set to, or something
different.

The put_index_data variable contains a list of snmp variable
bindings, one for each index in your table. Set the values of
each appropriately according to the data matching the first row
and return the put_index_data variable at the end of the function.
*/
netsnmp_variable_list *
fileTable_get_first_data_point(void **my_loop_context,
void **my_data_context,
netsnmp_variable_list * put_index_data,
netsnmp_iterator_info *mydata)
{

netsnmp_variable_list *vptr;

tUpdateConfigParamMsg *cfgMsg = g_ConfigurationAgent.GetAllTmpConfigurationParamet ers();

/* We use the positinonal count as our loop context */
int *position = (int*)malloc(sizeof(int));
*position = 0;

*my_loop_context = position /** XXX */ ;
*my_data_context = (void *)&cfgMsg->nmeCommonConfig.fileTable[*position] /** XXX */ ;

vptr = put_index_data;

snmp_set_var_value(vptr, (u_char *) cfgMsg->nmeCommonConfig.fileTable[*position].index,
strlen(cfgMsg->nmeCommonConfig.fileTable[*position].index));


vptr = vptr->next_variable;

return put_index_data;
}

/** functionally the same as fileTable_get_first_data_point, but
my_loop_context has already been set to a previous value and should
be updated to the next in the list. For example, if it was a
linked list, you might want to cast it to your local data type and
then return my_loop_context->next. The my_data_context pointer
should be set to something you need later (in your main
fileTable_handler routine) and the indexes in put_index_data updated
again. */
netsnmp_variable_list *
fileTable_get_next_data_point(void **my_loop_context,
void **my_data_context,
netsnmp_variable_list * put_index_data,
netsnmp_iterator_info *mydata)
{

tUpdateConfigParamMsg *cfgMsg = g_ConfigurationAgent.GetAllTmpConfigurationParamet ers();

netsnmp_variable_list *vptr;
int *position = (int *) *my_loop_context;

/* make sure we were called correctly */
if (!position)
return NULL;

/* go to the next route in the list */
(*position)++;

/* Are we beyond the end? */
if (*position >= FILE_TABLE_SIZE) {
/* End of routes. stop here by returning NULL */
SNMP_FREE(position);
*my_loop_context = NULL;
*my_data_context = NULL;
return NULL;
}

*my_loop_context = position /** XXX */ ;
*my_data_context = (void *)&cfgMsg->nmeCommonConfig.fileTable[*position] /** XXX */ ;

vptr = put_index_data;

snmp_set_var_value(vptr, (u_char *) cfgMsg->nmeCommonConfig.fileTable[*position].index,
strlen(cfgMsg->nmeCommonConfig.fileTable[*position].index) );
vptr = vptr->next_variable;

return put_index_data;
}

/** handles requests for the fileTable table, if anything else needs to be done */
int
fileTable_handler(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{

netsnmp_request_info *request;
netsnmp_table_request_info *table_info;
netsnmp_variable_list *var;
void *data_context;

for (request = requests; request; request = request->next) {
var = request->requestvb;
if (request->processed != 0)
continue;

/** perform anything here that you need to do before each
request is processed. */

/** the following extracts the my_data_context pointer set in
the loop functions above. You can then use the results to
help return data for the columns of the fileTable table in question */
data_context = netsnmp_extract_iterator_context(request);
if ( data_context == NULL) {
if (reqinfo->mode == MODE_GET) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
/** XXX: no row existed, if you support creation and this is a
set, start dealing with it here, else continue */
}

/** extracts the information about the table from the request */
table_info = netsnmp_extract_table_info(request);
/** table_info->colnum contains the column number requested */
/** table_info->indexes contains a linked list of snmp variable
bindings for the indexes of the table. Values in the list
have been set corresponding to the indexes of the
request */
if (table_info == NULL) {
continue;
}

/* declare variables that will be used down */
char *oldFileName = NULL;
tByte *oldIsFileActive = NULL;
tByte timeString[TIMESTAMP_LENGTH];
time_t timeInSec = 0;

switch (reqinfo->mode) {
/** the table_iterator helper should change all GETNEXTs
into GETs for you automatically, so you don't have to
worry about the GETNEXT case. Only GETs and SETs need
to be dealt with here */
case MODE_GET:
switch (table_info->colnum) {
case COLUMN_FILETABLEINDEX:
snmp_set_var_typed_value(var, ASN_OCTET_STR,
(u_char *) ((tNMEFileTable*) data_context)->index
, strlen(((tNMEFileTable*) data_context)->index)
);
printf("Index is %s\n", ((tNMEFileTable*) data_context)->index);
break;

case COLUMN_FILETABLEFILETYPE:
snmp_set_var_typed_value(var, ASN_OCTET_STR,
(u_char *) ((tNMEFileTable*) data_context)->fileType
, strlen(((tNMEFileTable*) data_context)->fileType)
);
break;

case COLUMN_FILETABLEFILENAME:
snmp_set_var_typed_value(var, ASN_OCTET_STR,
(u_char *) ((tNMEFileTable*) data_context)->fileName
, strlen(((tNMEFileTable*) data_context)->fileName)
);
printf("fileName is %s\n", ((tNMEFileTable*) data_context)->fileName);
break;

case COLUMN_FILETABLERESIDENTFILE:
snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *)&((tNMEFileTable*) data_context)->resFile
, sizeof(char)
);
break;

case COLUMN_FILETABLERESIDENTFILETIMESTAMP:
timeInSec = ((tNMEFileTable*)data_context)->resFileTimeStamp;
ConvertTimeFormatToChar(timeInSec, timeString);
snmp_set_var_typed_value(var, ASN_OCTET_STR,
(u_char *)timeString
, sizeof(timeString)
);
break;

case COLUMN_FILETABLEACTIVEFILE:
snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *)&((tNMEFileTable*) data_context)->activeFile
, sizeof(char)
);
break;

case COLUMN_FILETABLEACTIVEFILETIMESTAMP:
timeInSec = ((tNMEFileTable*) data_context)->actFileTimeStamp;
ConvertTimeFormatToChar(timeInSec, timeString);
snmp_set_var_typed_value(var, ASN_OCTET_STR,
(u_char *)timeString
, sizeof(timeString)
);
printf("actFileTimeStamp is %ld\n", ((tNMEFileTable*) data_context)->actFileTimeStamp);
break;

default:
/** We shouldn't get here */
snmp_log(LOG_ERR,
"problem encountered in fileTable_handler: unknown column\n");
}
break;

case MODE_SET_RESERVE1:
/** mib2cXXX: clear out old undo info if we have any. Remove if
table_iterator becomes un-serialized */

switch (table_info->colnum)
{
case COLUMN_FILETABLEFILENAME:
printf("Recieved a file name as \"%s\"\n", (const char*)(requests->requestvb->val.string));
if (requests->requestvb->type != ASN_OCTET_STR) {
printf("Recieved a wrong file type\n");
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGTYPE);
}
break;

case COLUMN_FILETABLEACTIVEFILE:
int val = *(requests->requestvb->val.integer);
printf("Recieved active file flag %d for index %s \n", val, ((tNMEFileTable*) data_context)->index);

if (*(requests->requestvb->val.integer) < NETMAN_NO ||
(*(requests->requestvb->val.integer) > NETMAN_YES)) {
printf("Recieved a wrong active file flag %d\n", val);
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGVALUE);
}

break;
}
break;

case MODE_SET_RESERVE2:
switch (table_info->colnum)
{
case COLUMN_FILETABLEFILENAME:
oldFileName = (char*)malloc(NETMAN_FILE_PATH_SIZE*sizeof(char));
if (oldFileName == NULL ) {
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
}

break;

case COLUMN_FILETABLEACTIVEFILE:
oldIsFileActive = (tByte*)malloc(sizeof(tByte));
if (oldIsFileActive == NULL ) {
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
}
break;
}
break;

case MODE_SET_FREE:
switch (table_info->colnum)
{
case COLUMN_FILETABLEFILENAME:
if (oldFileName != NULL ) {
free(oldFileName);
oldFileName = NULL;
}
break;

case COLUMN_FILETABLEACTIVEFILE:
if (oldIsFileActive != NULL ) {
free(oldIsFileActive);
oldIsFileActive = NULL;
}
break;
}
break;

case MODE_SET_ACTION:
switch (table_info->colnum)
{
case COLUMN_FILETABLEFILENAME:
//strcpy(oldFileName, ((tNMEFileTable*) data_context)->fileName);
strcpy(((tNMEFileTable*) data_context)->fileName, (const char*)requests->requestvb->val.string);
printf("Got the file name as %s\n", requests->requestvb->val.string);
break;

case COLUMN_FILETABLEACTIVEFILE:
//(*oldIsFileActive) = ((tNMEFileTable*) data_context)->activeFile;
((tNMEFileTable*) data_context)->activeFile = *(requests->requestvb->val.integer);
int val = ((tNMEFileTable*) data_context)->activeFile;
printf("Got the file active flag as %d\n",val );
break;
}
break;

case MODE_SET_COMMIT:
switch (table_info->colnum)
{
case COLUMN_FILETABLEFILENAME:
if (oldFileName != NULL ) {
free(oldFileName);
oldFileName = NULL;
}
break;

case COLUMN_FILETABLEACTIVEFILE:
if (oldIsFileActive != NULL ) {
free(oldIsFileActive);
oldIsFileActive = NULL;
}
break;
}
break;

case MODE_SET_UNDO:
switch (table_info->colnum)
{
case COLUMN_FILETABLEFILENAME:
//strcpy(((tNMEFileTable*) data_context)->fileName,oldFileName);
if (oldFileName != NULL ) {
free(oldFileName);
oldFileName = NULL;
}
break;

case COLUMN_FILETABLEACTIVEFILE:
//((tNMEFileTable*) data_context)->activeFile = (*oldIsFileActive);
if (oldIsFileActive != NULL ) {
free(oldIsFileActive);
oldIsFileActive = NULL;
}
break;
}
break;


default:
snmp_log(LOG_ERR,
"problem encountered in fileTable_handler: unsupported mode\n");
}
}
return SNMP_ERR_NOERROR;
}

/************************************************** ********************/
/* HNS Defined functions starts here*/
/* Function Name: checkFileIndexAndType
* @param - newFileIndex is string containing ABSxx, EPHxx etc.
* returns - true if the string is expected, otherwise false */
/************************************************** ********************/
bool checkFileIndexAndType(char *newFileIndex)
{
char *aFileTypes[] = {"ABS", "EPH", "NBC", "SW" };
int numcharsToCompare = 2; /* comparing two chars would be enough */
int num_file_types = 4; /* as listed above */

for (int i=0; i if (strncmp(aFileTypes[i], newFileIndex, numcharsToCompare) == 0)
return (true);
}
return (false);
}
///
///************************************************** ************************//
///
/// NAME: ConvertTimeFormatToChar
///
/// DESCRIPTION: - This function converts the time given in seconds to the
/// format NME needs.
/// @param timeInSec - time in seconds
/// @param timeString - strores the formatted time in an array of size 8
///************************************************** ************************//
///
bool ConvertTimeFormatToChar(time_t timeInSec, tByte *timeString)
{
struct tm *brokenDownTime = localtime(&timeInSec);
char time_string[40];
strftime(time_string, sizeof (time_string), "%Y %m %d %H %M %S", brokenDownTime);
int year, mon, day, hr, min, sec;
sscanf(time_string,"%d %u %u %u %u %u", &year, &mon, &day, &hr, &min, &sec);
timeString[2] = mon;
timeString[3] = day;
timeString[4] = hr;
timeString[5] = min;
timeString[6] = sec;

timeString[1] = (unsigned char)(year & 0xff);
timeString[0] = (unsigned char)(year >> 8);
timeString[7] = (unsigned char)(0); // deci seconds are set to 0
return true;
}
///
///************************************************** ************************//
///
/// NAME: ConvertTimeFromCharToSec
///
/// DESCRIPTION: - This function converts the time given in an array to the
/// seconds format
/// @param dateTime - strores the formatted time in an array of size 8
/// @param timeInSec - time in seconds
///************************************************** ************************//
///
bool convertTimeToSecFromChar(tByte *dateTime, time_t *timeInSec)
{
char time_string[40];
unsigned short year = 0;
struct tm brokenDownTime;
unsigned char yearArray[2];

yearArray[0] = dateTime[0] ;
yearArray[1] = dateTime[1] ;
year = *((unsigned short *)yearArray);

sprintf(time_string,"%u %u %u %u %u %u", year, dateTime[2], dateTime[3],
dateTime[4], dateTime[5], dateTime[6]);
strptime(time_string, "%Y %m %d %H %M %S", &brokenDownTime);
(*timeInSec) = mktime(&brokenDownTime);
return true;
}


--0-1482494378-1164653662=:88797--

--0-774094194-1164654143=:47795
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?p...rge&CID=DEVDEV
--0-774094194-1164654143=:47795
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/...et-snmp-coders

--0-774094194-1164654143=:47795--