SNMP Set is getting Failed

"Kumar Sanjay-XJD784" <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
 
Hi All, 
	I try to give the snmp set does Hit the  "case
MODE_SET_RESERVE1:" but it HIt to  "case MODE_SET_FREE:"

Can anyone help me out what could be the possible reason.

I am able to do the snmp get.

Find the file herein attachment for the reference.

Thanks,
Sanjay

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl

_______________________________________________
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
ccAuditLoggingCfgTable.h (application/octet-stream, 759 B)
/*
 * Note: this file originally auto-generated by mib2c using
 *  : mib2c.iterate.conf 17695 2009-07-21 12:22:18Z dts12 $
 */
#ifndef CCAUDITLOGGINGCFGTABLE_H
#define CCAUDITLOGGINGCFGTABLE_H

/* function declarations */
void init_ccAuditLoggingCfgTable(void);
void initialize_table_ccAuditLoggingCfgTable(void);
Netsnmp_Node_Handler ccAuditLoggingCfgTable_handler;
Netsnmp_First_Data_Point  ccAuditLoggingCfgTable_get_first_data_point;
Netsnmp_Next_Data_Point   ccAuditLoggingCfgTable_get_next_data_point;

/* column number definitions for table ccAuditLoggingCfgTable */
       #define COLUMN_CCAUDITLOGSNMPV3USERNAME		1
       #define COLUMN_CCAUDITLOGSNMPCLIENTIPADDR		2
       #define COLUMN_CCAUDITLOGROWSTATUS		3
#endif /* CCAUDITLOGGINGCFGTABLE_H */
ccAuditLoggingCfgTable.c (application/octet-stream, 19.2 KB)
/*
 * Note: this file originally auto-generated by mib2c using
 *  : mib2c.iterate.conf 17695 2009-07-21 12:22: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 "ccAuditLoggingCfgTable.h"

/* Typical data structure for a row entry */
struct ccAuditLoggingCfgTable_entry {
    /* Index values */
    char ccAuditLogsnmpv3UserName[255];
    size_t ccAuditLogsnmpv3UserName_len;
    in_addr_t ccAuditLogsnmpClientIpAddr;

    /* Column values */
    //char ccAuditLogsnmpv3UserName[255];
    //size_t ccAuditLogsnmpv3UserName_len;
    char old_ccAuditLogsnmpv3UserName[255];
    size_t old_ccAuditLogsnmpv3UserName_len;
    //in_addr_t ccAuditLogsnmpClientIpAddr;
    in_addr_t old_ccAuditLogsnmpClientIpAddr;
    long ccAuditLogRowStatus;

    /* Illustrate using a simple linked list */
    int   valid;
    struct ccAuditLoggingCfgTable_entry *next;
};

struct ccAuditLoggingCfgTable_entry  *ccAuditLoggingCfgTable_head;
struct ccAuditLoggingCfgTable_entry *
ccAuditLoggingCfgTable_createEntry(
                 char* ccAuditLogsnmpv3UserName,
                 size_t ccAuditLogsnmpv3UserName_len,
                 in_addr_t  ccAuditLogsnmpClientIpAddr);

/*
 * Function used from latest net-snmp version 
 */
	int
snmp_set_var_typed_integer(netsnmp_variable_list * newvar,
		u_char type, long val)
{
	newvar->type = type;
	return snmp_set_var_value(newvar, &val, sizeof(long));
}



/** Initializes the ccAuditLoggingCfgTable module */
void
init_ccAuditLoggingCfgTable(void)
{
  /* here we initialize all the tables we're planning on supporting */
     snmp_log( LOG_ERR,"Entering-> Fun:%s Line:%d \n", __func__, __LINE__);
    initialize_table_ccAuditLoggingCfgTable();
     snmp_log( LOG_ERR,"Exiting-> Fun:%s Line:%d \n", __func__, __LINE__);
}


//  # Determine the first/last column names

/** Initialize the ccAuditLoggingCfgTable table by defining its contents and how it's structured */
void
initialize_table_ccAuditLoggingCfgTable(void)
{
    const oid ccAuditLoggingCfgTable_oid[] = {1,3,6,1,4,1,388,11,2,2,11,10};
    const size_t ccAuditLoggingCfgTable_oid_len   = OID_LENGTH(ccAuditLoggingCfgTable_oid);
    netsnmp_handler_registration    *reg;
    netsnmp_iterator_info           *iinfo;
    netsnmp_table_registration_info *table_info;

    struct ccAuditLoggingCfgTable_entry *entry = NULL;

     snmp_log( LOG_ERR,"Entering-> Fun:%s Line:%d \n", __func__, __LINE__);

    DEBUGMSGTL(("ccAuditLoggingCfgTable:init", "initializing table ccAuditLoggingCfgTable\n"));

    reg = netsnmp_create_handler_registration("ccAuditLoggingCfgTable",     
		    			      ccAuditLoggingCfgTable_handler,  
				  	      ccAuditLoggingCfgTable_oid, 
					      ccAuditLoggingCfgTable_oid_len,
				              HANDLER_CAN_RWRITE);

    table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
    netsnmp_table_helper_add_indexes(table_info,
                           ASN_OCTET_STR,  /* index: ccAuditLogsnmpv3UserName */
                           ASN_IPADDRESS,  /* index: ccAuditLogsnmpClientIpAddr */
                           0);
    table_info->min_column = COLUMN_CCAUDITLOGSNMPV3USERNAME;
    table_info->max_column = COLUMN_CCAUDITLOGROWSTATUS;
    
    iinfo = SNMP_MALLOC_TYPEDEF( netsnmp_iterator_info );
    iinfo->get_first_data_point = ccAuditLoggingCfgTable_get_first_data_point;
    iinfo->get_next_data_point  = ccAuditLoggingCfgTable_get_next_data_point;
    iinfo->table_reginfo        = table_info;
    
    netsnmp_register_table_iterator( reg, iinfo );

    snmp_log( LOG_ERR,"Before Initialisation-> Fun:%s Line:%d \n", __func__, __LINE__);
    /* Initialise the contents of the table here */
    entry = ccAuditLoggingCfgTable_createEntry("sanjay", 7, 1111); 
    entry->ccAuditLogRowStatus = RS_CREATEANDGO;
    snmp_log( LOG_ERR,"After Init and Exiting-> Fun:%s Line:%d \n", __func__, __LINE__);
}

/* create a new row in the (unsorted) table */
struct ccAuditLoggingCfgTable_entry *
ccAuditLoggingCfgTable_createEntry(
                 char* ccAuditLogsnmpv3UserName,
                 size_t ccAuditLogsnmpv3UserName_len,
                 in_addr_t  ccAuditLogsnmpClientIpAddr
                ) {
    struct ccAuditLoggingCfgTable_entry *entry;

    entry = SNMP_MALLOC_TYPEDEF(struct ccAuditLoggingCfgTable_entry);
    if (!entry)
        return NULL;

    memcpy(entry->ccAuditLogsnmpv3UserName, ccAuditLogsnmpv3UserName, ccAuditLogsnmpv3UserName_len);
    entry->ccAuditLogsnmpv3UserName_len = ccAuditLogsnmpv3UserName_len;
    entry->ccAuditLogsnmpClientIpAddr = ccAuditLogsnmpClientIpAddr;
    entry->next = ccAuditLoggingCfgTable_head;
    ccAuditLoggingCfgTable_head = entry;
    return entry;
}

/* remove a row from the table */
void
ccAuditLoggingCfgTable_removeEntry( struct ccAuditLoggingCfgTable_entry *entry ) {
    struct ccAuditLoggingCfgTable_entry *ptr, *prev;

    if (!entry)
        return;    /* Nothing to remove */

    for ( ptr  = ccAuditLoggingCfgTable_head, prev = NULL;
          ptr != NULL;
          prev = ptr, ptr = ptr->next ) {
        if ( ptr == entry )
            break;
    }
    if ( !ptr )
        return;    /* Can't find it */

    if ( prev == NULL )
        ccAuditLoggingCfgTable_head = ptr->next;
    else
        prev->next = ptr->next;

    SNMP_FREE( entry );   /* XXX - release any other internal resources */
}


/* Example iterator hook routines - using 'get_next' to do most of the work */
netsnmp_variable_list *
ccAuditLoggingCfgTable_get_first_data_point(void **my_loop_context,
                          void **my_data_context,
                          netsnmp_variable_list *put_index_data,
                          netsnmp_iterator_info *mydata)
{
    *my_loop_context = ccAuditLoggingCfgTable_head;
    return ccAuditLoggingCfgTable_get_next_data_point(my_loop_context, my_data_context,
                                    put_index_data,  mydata );
}

netsnmp_variable_list *
ccAuditLoggingCfgTable_get_next_data_point(void **my_loop_context,
                          void **my_data_context,
                          netsnmp_variable_list *put_index_data,
                          netsnmp_iterator_info *mydata)
{
    struct ccAuditLoggingCfgTable_entry *entry = (struct ccAuditLoggingCfgTable_entry *)*my_loop_context;
    netsnmp_variable_list *idx = put_index_data;

    if ( entry ) {
        snmp_set_var_value( idx, entry->ccAuditLogsnmpv3UserName, sizeof(entry->ccAuditLogsnmpv3UserName) );
        idx = idx->next_variable;
        snmp_set_var_typed_integer( idx, ASN_IPADDRESS, entry->ccAuditLogsnmpClientIpAddr );
        idx = idx->next_variable;
        *my_data_context = (void *)entry;
        *my_loop_context = (void *)entry->next;
        return put_index_data;
    } else {
        return NULL;
    }
}


/** handles requests for the ccAuditLoggingCfgTable table */
int
ccAuditLoggingCfgTable_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;
    struct ccAuditLoggingCfgTable_entry          *table_entry;
    struct ccAuditLoggingCfgTable_entry          *table_row = NULL;
    int ret = SNMPERR_SUCCESS;

    DEBUGMSGTL(("ccAuditLoggingCfgTable:handler", "Processing request (%d)\n", reqinfo->mode));

    switch (reqinfo->mode) {
        /*
         * Read-support (also covers GetNext requests)
         */
    case MODE_GET:
        for (request=requests; request; request=request->next) {
            table_entry = (struct ccAuditLoggingCfgTable_entry *)
                              netsnmp_extract_iterator_context(request);
            table_info  =     netsnmp_extract_table_info(      request);
    	
	    snmp_log( LOG_ERR,"GET -> Fun:%s Line:%d \n", __func__, __LINE__);
    
            switch (table_info->colnum) {
            case COLUMN_CCAUDITLOGSNMPV3USERNAME:
                if ( !table_entry ) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
                                 (u_char*)table_entry->ccAuditLogsnmpv3UserName,
                                          table_entry->ccAuditLogsnmpv3UserName_len);
                break;
            case COLUMN_CCAUDITLOGSNMPCLIENTIPADDR:
                if ( !table_entry ) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer( request->requestvb, ASN_IPADDRESS,
                                            table_entry->ccAuditLogsnmpClientIpAddr);
                break;
            case COLUMN_CCAUDITLOGROWSTATUS:
                if ( !table_entry ) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
               snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
                                            table_entry->ccAuditLogRowStatus);
                break;
            default:
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_NOSUCHOBJECT);
                break;
            }
        }
        break;

        /*
         * Write-support
         */
    case MODE_SET_RESERVE1:
	    snmp_log( LOG_ERR,"RESERVE1 1 -> Fun:%s Line:%d \n", __func__, __LINE__);
        for (request=requests; request; request=request->next) {
            table_entry = (struct ccAuditLoggingCfgTable_entry *)
                              netsnmp_extract_iterator_context(request);
	    if(NULL == table_entry){
		    snmp_log( LOG_ERR,"RESERVE1 1 return -> Fun:%s Line:%d \n", __func__, __LINE__);
		    return 1;
	    }
	    table_info  =     netsnmp_extract_table_info(      request);
	    if(NULL == table_info){
		    snmp_log( LOG_ERR,"RESERVE1 2-> Fun:%s Line:%d \n", __func__, __LINE__);
		    return 1;
	    }
	    snmp_log( LOG_ERR,"RESERVE1 2 return -> Fun:%s Line:%d \n", __func__, __LINE__);

            switch (table_info->colnum) {
            case COLUMN_CCAUDITLOGSNMPV3USERNAME:
	        /* or possibly 'netsnmp_check_vb_type_and_size' */
                ret = netsnmp_check_vb_type_and_size(
                          request->requestvb, ASN_OCTET_STR, sizeof(table_entry->ccAuditLogsnmpv3UserName));
                if ( ret != SNMP_ERR_NOERROR ) {
                    netsnmp_set_request_error( reqinfo, request, ret );
                    return SNMP_ERR_NOERROR;
                }
                break;
	    case COLUMN_CCAUDITLOGSNMPCLIENTIPADDR:
		/* or possibly 'netsnmp_check_vb_int_range' */
		ret = netsnmp_check_vb_type_and_size(
				request->requestvb, ASN_INTEGER, sizeof(table_entry->ccAuditLogsnmpClientIpAddr));
		/* ret = netsnmp_check_vb_int( request->requestvb ); */
		if ( ret != SNMP_ERR_NOERROR ) {
			netsnmp_set_request_error( reqinfo, request, ret );
			return SNMP_ERR_NOERROR;
		}
		break;
            case COLUMN_CCAUDITLOGROWSTATUS:
                ret = netsnmp_check_vb_rowstatus(request->requestvb,
                         (table_entry ? RS_ACTIVE : RS_NONEXISTENT ));
                if ( ret != SNMP_ERR_NOERROR ) {
                    netsnmp_set_request_error( reqinfo, request, ret );
                    return SNMP_ERR_NOERROR;
                }
                break;
            default:
                netsnmp_set_request_error( reqinfo, request,
                                           SNMP_ERR_NOTWRITABLE );
                return SNMP_ERR_NOERROR;
            }
        }
        break;

    case MODE_SET_RESERVE2:
	    snmp_log( LOG_ERR,"RESERVE2 1 -> Fun:%s Line:%d \n", __func__, __LINE__);
        for (request=requests; request; request=request->next) {
            table_entry = (struct ccAuditLoggingCfgTable_entry *)
                              netsnmp_extract_iterator_context(request);
            table_info  =     netsnmp_extract_table_info(      request);
	    snmp_log( LOG_ERR,"RESERVE2 2 -> Fun:%s Line:%d \n", __func__, __LINE__);
    
            switch (table_info->colnum) {
            case COLUMN_CCAUDITLOGROWSTATUS:
                switch (*request->requestvb->val.integer) {
                case RS_CREATEANDGO:
                case RS_CREATEANDWAIT:
                    table_row = ccAuditLoggingCfgTable_createEntry(
                        table_info->indexes->val.string,
                        table_info->indexes->val_len,
                        *table_info->indexes->val.integer
                        );
                    if (table_row) {
                        //netsnmp_insert_iterator_context(table_row );
                    } else {
                        netsnmp_set_request_error( reqinfo, request,
                                                   SNMP_ERR_RESOURCEUNAVAILABLE );
                        return SNMP_ERR_NOERROR;
                    }
                }
            }
        }
        break;

    case MODE_SET_FREE:
        for (request=requests; request; request=request->next) {
            table_entry = (struct ccAuditLoggingCfgTable_entry *)
                              netsnmp_extract_iterator_context(request);
            table_info  =     netsnmp_extract_table_info(      request);
	    
	    snmp_log( LOG_ERR,"SET_FREE -> Fun:%s Line:%d \n", __func__, __LINE__);
    
            switch (table_info->colnum) {
            case COLUMN_CCAUDITLOGROWSTATUS:
                switch (*request->requestvb->val.integer) {
                case RS_CREATEANDGO:
                case RS_CREATEANDWAIT:
			if (table_entry && !table_entry->valid) {
				if(NULL != table_row){
	    				snmp_log( LOG_ERR,"SET_FREE -> table_row in not NULL \n");
					ccAuditLoggingCfgTable_removeEntry(table_row );
				}
			}
                }
            }
        }
        break;

    case MODE_SET_ACTION:
	    snmp_log( LOG_ERR,"ACTION 1 -> Fun:%s Line:%d \n", __func__, __LINE__);
        for (request=requests; request; request=request->next) {
            table_entry = (struct ccAuditLoggingCfgTable_entry *)
                              netsnmp_extract_iterator_context(request);
            table_info  =     netsnmp_extract_table_info(      request);
	    
	    snmp_log( LOG_ERR,"ACTION 2-> Fun:%s Line:%d \n", __func__, __LINE__);
    
            switch (table_info->colnum) {
            case COLUMN_CCAUDITLOGSNMPV3USERNAME:
                memcpy( table_entry->old_ccAuditLogsnmpv3UserName,
                        table_entry->ccAuditLogsnmpv3UserName,
                        sizeof(table_entry->ccAuditLogsnmpv3UserName));
                table_entry->old_ccAuditLogsnmpv3UserName_len =
                        table_entry->ccAuditLogsnmpv3UserName_len;
                memset( table_entry->ccAuditLogsnmpv3UserName, 0,
                        sizeof(table_entry->ccAuditLogsnmpv3UserName));
                memcpy( table_entry->ccAuditLogsnmpv3UserName,
                        request->requestvb->val.string,
                        request->requestvb->val_len);
                table_entry->ccAuditLogsnmpv3UserName_len =
                        request->requestvb->val_len;
                break;
            case COLUMN_CCAUDITLOGSNMPCLIENTIPADDR:
                table_entry->old_ccAuditLogsnmpClientIpAddr = table_entry->ccAuditLogsnmpClientIpAddr;
                table_entry->ccAuditLogsnmpClientIpAddr     = *request->requestvb->val.integer;
                break;
            }
        }
        /* Check the internal consistency of an active row */
#if 0
        for (request=requests; request; request=request->next) {
            table_entry = (struct ccAuditLoggingCfgTable_entry *)
                              netsnmp_extract_iterator_context(request);
            table_info  =     netsnmp_extract_table_info(      request);
    
            switch (table_info->colnum) {
            case COLUMN_CCAUDITLOGROWSTATUS:
                switch (*request->requestvb->val.integer) {
                case RS_ACTIVE:
                case RS_CREATEANDGO:
                /*   if (??) {
                        netsnmp_set_request_error( reqinfo, request,
                                                   SNMP_ERR_INCONSISTENTVALUE );
                        return SNMP_ERR_NOERROR;
                    }*/
                }
            }
        }
#endif
        break;

    case MODE_SET_UNDO:
        for (request=requests; request; request=request->next) {
            table_entry = (struct ccAuditLoggingCfgTable_entry *)
                              netsnmp_extract_iterator_context(request);
            table_info  =     netsnmp_extract_table_info(      request);
    
	    snmp_log( LOG_ERR,"SET_UNDO -> Fun:%s Line:%d \n", __func__, __LINE__);

            switch (table_info->colnum) {
            case COLUMN_CCAUDITLOGSNMPV3USERNAME:
                memcpy( table_entry->ccAuditLogsnmpv3UserName,
                        table_entry->old_ccAuditLogsnmpv3UserName,
                        sizeof(table_entry->ccAuditLogsnmpv3UserName));
                memset( table_entry->old_ccAuditLogsnmpv3UserName, 0,
                        sizeof(table_entry->ccAuditLogsnmpv3UserName));
                table_entry->ccAuditLogsnmpv3UserName_len =
                        table_entry->old_ccAuditLogsnmpv3UserName_len;
                break;
            case COLUMN_CCAUDITLOGSNMPCLIENTIPADDR:
                table_entry->ccAuditLogsnmpClientIpAddr     = table_entry->old_ccAuditLogsnmpClientIpAddr;
                table_entry->old_ccAuditLogsnmpClientIpAddr = 0;
                break;
            case COLUMN_CCAUDITLOGROWSTATUS:
                switch (*request->requestvb->val.integer) {
                case RS_CREATEANDGO:
                case RS_CREATEANDWAIT:
                    if (table_entry && !table_entry->valid) {
                        ccAuditLoggingCfgTable_removeEntry(table_row );
                    }
                }
                break;
            }
        }
        break;

    case MODE_SET_COMMIT:
        for (request=requests; request; request=request->next) {
            table_entry = (struct ccAuditLoggingCfgTable_entry *)
                              netsnmp_extract_iterator_context(request);
            table_info  =     netsnmp_extract_table_info(      request);
	    
	    snmp_log( LOG_ERR,"COMMIT -> Fun:%s Line:%d \n", __func__, __LINE__);
    
            switch (table_info->colnum) {
            case COLUMN_CCAUDITLOGROWSTATUS:
                switch (*request->requestvb->val.integer) {
                case RS_CREATEANDGO:
                    table_entry->valid = 1;
                    /* Fall-through */
                case RS_ACTIVE:
                    table_entry->ccAuditLogRowStatus = RS_ACTIVE;
                    break;

                case RS_CREATEANDWAIT:
                    table_entry->valid = 1;
                    /* Fall-through */
                case RS_NOTINSERVICE:
                    table_entry->ccAuditLogRowStatus = RS_NOTINSERVICE;
                    break;

                case RS_DESTROY:
                    ccAuditLoggingCfgTable_removeEntry(table_row );
                }
            }
        }
        break;
    }
    return SNMP_ERR_NOERROR;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.