getting error "pdu failed to be created" on snmp_synch_response(ss, pdu, &response)
Vivek Singh Bhadauria <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <[email protected]> |
HI, I am running snmpd and snmpagent(using Net-SNMP api). snmpagent send the pdu and process the response. I am getting "pdu failed to be created" error on calling snmp_synch_response(ss, pdu, &response). And because of this error, snmpd stops responding but still shows running. I am attaching c file for reference where main code starts from line number 134. At this a new thread is created each time when we set the scalar object() and then alarmMIBThread() method is being called for creating/sending the pdu. Note: this error comes when I run it number of times by calling a new thread. What could be the reason for this error? Below is the log for the above case. ======================================================================= sess_process_packet: session 0x8e51098 fd 7 pkt 0x8e54fd8 length 60 sess_process_packet: session 0x8dc85d8 fd 3 pkt 0x8e54fd8 length 1 sess_process_packet: session 0x8dc9028 fd 5 pkt 0x8e54fd8 length 1 sess_process_packet: session 0x8dc85d8 fd 3 pkt 0x8e54fd8 length 1 sess_process_packet: session 0x8dc9028 fd 5 pkt 0x8e54fd8 length 1 sess_process_packet: session 0x8e51098 fd 7 pkt 0x8e54fd8 length 20 sess_process_packet: session 0x8dc85d8 fd 3 pkt 0x8e54fd8 length 1 sess_process_packet: session 0x8dc9028 fd 5 pkt 0x8e54fd8 length 1 sess_process_packet: session 0x8e51098 fd 7 pkt 0x8e54fd8 length 20 sess_process_packet: session 0x8dc85d8 fd 3 pkt 0x8e54fd8 length 1 Enter alarmMIBThread ----------------------------------------------------------------------- one97AlarmResyncEnable = 1 one97AlarmResyncStartTime = 0 one97AlarmResyncEndTime = 1345555569 Enter Resync snmp_synch_response sess_process_packet: session 0x8dc9028 fd 5 pkt 0x8e67650 length 1 pdu failed to be created sess_process_packet: session 0x8e65c38 fd 8 pkt 0x8e54fd8 length 65 Exit Resync snmp_synch_response SNMPv2-SMI::mib-2.118.1.2.2.1.8.4.108.105.110.101.11.48.49.50.55.49.57.57.56.51.57.48.1 = Gauge32: 10 ======================================================================= ------------------------------------------------------------------------------ _______________________________________________ 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
test.c
(text/x-csrc, 11.4 KB)
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.scalar.conf 11805 2005-01-07 09:37:18Z dts12 $
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "one97Configuration.h"
#include "scalarConfFileio.h"
#include <pthread.h>
#include<string.h>
//#include <stdlib.h>
u_long one97ThresholdConfigMaxEntries = 20; // Default value
u_long one97DestinationPortMaxEntries = 20;
u_long one97DestinationURLMaxEntries = 20;
u_long one97RunningSwConfigMaxEntries = 100;
u_long one97FilterdLogConfigMaxEntries = 100;
int one97AlarmResyncEnable = 1; // 1 True, 2 false
u_long one97AlarmResyncStartTime = 0;
u_long one97AlarmResyncEndTime = 0;
void alarmMIBThread(void * ptr);
int command = SNMP_MSG_GET;
int input_variable(netsnmp_variable_list *);
u_long temp;
/** Initializes the one97Configuration module */
void
init_one97Configuration(void)
{
static oid one97AlarmResyncEndTime_oid[] = { 1,3,6,1,4,1,33830,1,1,5,3 };
DEBUGMSGTL(("\nverbose:one97Configuration", "Initializing\n"));
netsnmp_register_scalar(
netsnmp_create_handler_registration("one97AlarmResyncEndTime", handle_one97AlarmResyncEndTime,
one97AlarmResyncEndTime_oid, OID_LENGTH(one97AlarmResyncEndTime_oid),
HANDLER_CAN_RWRITE
));
DEBUGMSGTL(("\nverbose:one97Configuration", "Initialized\n"));
}
int
handle_one97AlarmResyncEndTime(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
int ret;
/* We are never called for a GETNEXT if it's registered as a
"instance", as it's "magically" handled for us. */
/* a instance handler also only hands us one request at a time, so
we don't need to loop over a list of requests; we'll only get one. */
switch(reqinfo->mode) {
case MODE_GET:
snmp_set_var_typed_value(requests->requestvb, ASN_TIMETICKS,
(u_char *) &one97AlarmResyncEndTime/* XXX: a pointer to the scalar's data */,
sizeof(u_long)/* XXX: the length of the data in bytes */);
break;
/*
* SET REQUEST
*
* multiple states in the transaction. See:
* http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
*/
case MODE_SET_RESERVE1:
#if 1 /* or you could use netsnmp_check_vb_type_and_size instead */
ret = netsnmp_check_vb_type(requests->requestvb, ASN_TIMETICKS);
if(*(requests->requestvb->val.integer) < 0)
{
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGVALUE);
}
if ( ret != SNMP_ERR_NOERROR ) {
netsnmp_set_request_error(reqinfo, requests, ret );
}
#endif
break;
case MODE_SET_RESERVE2:
#if 0 /* XXX malloc "undo" storage buffer */
if (/* XXX if malloc, or whatever, failed: */) {
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
}
#endif
break;
case MODE_SET_FREE:
/* XXX: free resources allocated in RESERVE1 and/or
RESERVE2. Something failed somewhere, and the states
below won't be called. */
break;
case MODE_SET_ACTION:
#if 0 /* XXX: perform the value change here */
if (/* XXX: error? */) {
netsnmp_set_request_error(reqinfo, requests, /* some error */);
}
#endif
break;
case MODE_SET_COMMIT:
#if 0 /* XXX: delete temporary storage */
if (/* XXX: error? */) {
/* try _really_really_ hard to never get to this point */
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
}
#endif
one97AlarmResyncEndTime = *(requests->requestvb->val.integer);
//Start a thread that will send traps using alarmActiveTable info.
if((one97AlarmResyncEnable == 1) && (one97AlarmResyncStartTime <= one97AlarmResyncEndTime))
{
// 2 args one97AlarmResyncStartTime one97AlarmResyncEndTime
pthread_t thread; /* thread variable */
pthread_create (&thread, NULL, (void *) &alarmMIBThread, (void *) NULL );
}
break;
case MODE_SET_UNDO:
#if 0 /* XXX: UNDO and return to previous value for the object */
if (/* XXX: error? */) {
/* try _really_really_ hard to never get to this point */
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED);
}
#endif
break;
default:
/* we should never get here, so this is a really bad error */
snmp_log(LOG_ERR, "unknown mode (%d) in handle_one97AlarmResyncEndTime\n", reqinfo->mode );
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
void alarmMIBThread( void * ptr)
{
printf("Enter alarmMIBThread \n");
/**
* Step 1 : Get alarmActiveTable row
* Step 2 : Validate the row with input time range
* Step 3 : get alarmActiveVariable rows
* Step 4 : prepare varbinds for trap
* Step 5 : send snmpv2 trap
**/
printf("\n-----------------------------------------------------------------------\n");
ReSyncAlarm();
printf("Exit alarmMIBThread \n");
printf("\n=======================================================================\n");
}
int ReSyncAlarm()
{
netsnmp_session session, *ss;
netsnmp_pdu *pdu, *response;
netsnmp_variable_list *vars;
oid name[MAX_OID_LEN];
size_t name_length;
oid root[MAX_OID_LEN] = { 1,3,6,1,2,1,118,1,2,2,1,8 };
size_t rootlen=12;
int count;
int running;
int status;
int exitval = 0;
u_long startTime = one97AlarmResyncStartTime;
u_long endTime = one97AlarmResyncEndTime;
printf("one97AlarmResyncEnable = %d\t", one97AlarmResyncEnable);
printf("one97AlarmResyncStartTime = %lu\t", startTime);
printf("one97AlarmResyncEndTime = %lu\n", endTime);
snmp_sess_init(&session);
session.version = SNMP_VERSION_2c;
session.timeout = (long)(10 * 1000000L);
session.retries = 2;
session.community = (unsigned char *) "public";
session.community_len = 6;
//printf("\n Enter Resync\n");
SOCK_STARTUP;
/*
* open an SNMP session
*/
ss = snmp_open(&session);
if (ss == NULL) {
/*
* diagnose snmp_open errors with the input netsnmp_session pointer
*/
snmp_sess_perror("reSync snmpwalk", &session);
SOCK_CLEANUP;
return exitval;
//exit(1);
}
/*
* get first object to start walk
*/
memmove(name, root, rootlen * sizeof(oid));
name_length = rootlen;
running = 1;
while (running) {
/*
* create PDU for GETNEXT request and add object name to request
*/
pdu = snmp_pdu_create(SNMP_MSG_GETNEXT);
if ( !pdu ) {
fprintf(stderr, "Failed to create ReSync PDU\n");
printf("ReSync Failed to create PDU\n");
//SOCK_CLEANUP;
break;
//return exitval;
//exit(1);
}
snmp_add_null_var(pdu, name, name_length);
printf(" Enter Resync snmp_synch_response\n");
/*
* do the request
*/
status = snmp_synch_response(ss, pdu, &response);
printf(" Exit Resync snmp_synch_response status = %d\n", status);
if (status == STAT_SUCCESS) {
if (response->errstat == SNMP_ERR_NOERROR) {
/*
* check resulting variables
*/
for (vars = response->variables; vars;
vars = vars->next_variable) {
if ((vars->name_length < rootlen)
|| (memcmp(root, vars->name, rootlen * sizeof(oid))
!= 0)) {
/*
* not part of this subtree
*/
running = 0;
break;
//continue;
}
print_variable(vars->name, vars->name_length, vars);
if ((vars->type != SNMP_ENDOFMIBVIEW) &&
(vars->type != SNMP_NOSUCHOBJECT) &&
(vars->type != SNMP_NOSUCHINSTANCE)) {
/*
* not an exception value
*/
if (snmp_oid_compare(name, name_length,
vars->name,
vars->name_length) >= 0) {
fprintf(stderr, "Error: OID not increasing: ");
fprint_objid(stderr, name, name_length);
fprintf(stderr, " >= ");
fprint_objid(stderr, vars->name,
vars->name_length);
fprintf(stderr, "\n");
running = 0;
exitval = 1;
}
// End Validate alarmActiveEntry before fetching next pdu
memmove((char *) name, (char *) vars->name,
vars->name_length * sizeof(oid));
name_length = vars->name_length;
} else
/*
* an exception value, so stop
*/
running = 0;
}
} else {
printf("\n status != STAT_SUCCESS");
/*
* error in response, print it
*/
running = 0;
if (response->errstat == SNMP_ERR_NOSUCHNAME) {
printf("End of MIB\n");
} else {
fprintf(stderr, "Error in packet.\nReason: %s\n",
snmp_errstring(response->errstat));
if (response->errindex != 0) {
fprintf(stderr, "Failed object: ");
for (count = 1, vars = response->variables;
vars && count != response->errindex;
vars = vars->next_variable, count++)
/*EMPTY*/;
if (vars)
fprint_objid(stderr, vars->name,
vars->name_length);
fprintf(stderr, "\n");
}
exitval = 2;
}
}
} else if (status == STAT_TIMEOUT) {
fprintf(stderr, "reSyncAlarm Timeout: No Response from %s\n",
session.peername);
running = 0;
exitval = 1;
} else { /* status == STAT_ERROR */
snmp_sess_perror("reSync snmpwalk", ss);
running = 0;
exitval = 1;
}
if (response)
{
printf("snmp_free_pdu\n");
snmp_free_pdu(response);
}
}
snmp_close(ss);
printf("exit ReSyncAlarm\n");
SOCK_CLEANUP;
return exitval;
}