RE: Table's String index does not work

"Naama Bar Menachem" <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
Hi

Running snmpd under debugger gave the following error message:
    *** glibc detected *** /usr/bin/snmpd: free(): invalid next size
(fast): 0x00000001201532a0 *** 
    Aborted

I have also noticed that the index of the next value that was brought
get's cut:
	./data/net/naamab/snmpgetnext -m ALL -M
/data/sw/snmp/snmp_mib_lnk/ -v 2c -c private 127.0.0.1
1.3.6.1.4.1.37576.4.1.4.1.1.3.\"committed-switch\"
	
NOVELSAT-DEMODULATOR-MIB::nsDemodConfigDiseqcNumDataBytes."non-committed
-sw" = Gauge32: 1
===> when the index value should actually be "non-committed-switch" (not
to be confused. I am doing getnext to "committed-switch" in order to get
"non-committed-switch")
Inner log prints show that at the end of get_next_entry function index
has un-cut value: idx->val.string=non-committed-switch

I attach both mib and c file. 
I don't understand which FREE can cause the crash...

Thank you,
Naama


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of
Dave Shield
Sent: Thursday, August 09, 2012 12:30 PM
To: Naama Bar Menachem
Cc: [email protected]
Subject: Re: Table's String index does not work

On 9 August 2012 10:17, Naama Bar Menachem
<[email protected]> wrote:
> GET-NEXT also works good but CRASHES at the end:

   That's an interesting description of "works" :-)

> ==> next call (any call) is exit with time out!

If the agent has crashed, then that is to be expected.

> However WALK fails due to TimeOut:

as is that.
  If the agent is no  longer running,  do you really expect it to
respond to subsequent requests?


> Debug prints show that the handle function 
> "nsDemodConfigDiseqcTable_handler" finishes successfully, no crash 
> while in it... (I see a print at the last row of the function, before
- 
> "return SNMP_ERR_NOERROR;"
>
> Where could be the problem??


We have no way of telling.
You will need to do some deeper digging to find out.

Have a look at the project wiki pages on debugging for some advice.

As a starting point, try running the agent under a debugger (using the
options '-f -Le'), and send the same GetNext query.
That should at least tell you where the problem is being triggered.

Dave

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

_______________________________________________
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
NOVELSAT-DEMODULATOR.mib (application/octet-stream, 45.1 KB) - not displayed
nsDemodConfigDiseqc.c (application/octet-stream, 28.7 KB)
/*
 * Note: this file originally auto-generated by mib2c using
 *  : mib2c.raw-table.conf 17436 2009-03-31 15:12:19Z 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 "nsDemodConfigDiseqc.h"
#include "ns_mibs.h"
#include "ns_logger.h"
#include "ns_db_tables.h"
#include "ns_db_utils.h"
#include "ns_ipc_client.h"
#include "ns_types.h"
#include "ns_errors_utils.h"
#include "ns_mibs_common_convert_db_mibs.h"


/*
 * column number definitions for table nsDemodConfigDiseqcTable 
 */
#define COLUMN_NSDEMODCONFIGDISEQCNAME				1
#define COLUMN_NSDEMODCONFIGDISEQCHEADERBYTES		2
#define COLUMN_NSDEMODCONFIGDISEQCNUMDATABYTES		3
#define COLUMN_NSDEMODCONFIGDISEQCTONEBURSTMODE		4
#define COLUMN_NSDEMODCONFIGDISEQCNOTIFYROWSTATUS	5

    /*
     * Typical data structure for a row entry 
     */
struct nsDemodConfigDiseqcTable_entry {
    /*
     * Index values 
     */
    char            nsDemodConfigDiseqcName[NS_TBL_FLD_MAX_LEN];
    size_t          nsDemodConfigDiseqcName_len;

    /*
     * Column values 
     */
    u_long          nsDemodConfigDiseqcHeaderBytes;
    u_long          old_nsDemodConfigDiseqcHeaderBytes;
    u_long          nsDemodConfigDiseqcNumDataBytes;
    u_long          old_nsDemodConfigDiseqcNumDataBytes;
    long            nsDemodConfigDiseqcToneBurstMode;
    long            old_nsDemodConfigDiseqcToneBurstMode;
    long            nsDemodConfigDiseqcNotifyRowStatus;

    int             valid;
};


struct nsDemodConfigDiseqcTable_entry DemodConfigDiseqc_entry;

/*
 * create a new row in the table 
 */
static struct nsDemodConfigDiseqcTable_entry *
nsDemodConfigDiseqcTable_createEntry(int dummy,
                                     char *nsDemodConfigDiseqcName,
                                     size_t nsDemodConfigDiseqcName_len)
{
	NS_SYSLOG_SNMP(LOG_ALERT, "~~~~~~~~~~~~~~~~~~~~~nbm: 1 createEntry");
	struct nsDemodConfigDiseqcTable_entry *entry;
	char	key_str[NS_TBL_FLD_MAX_LEN];
	char	*key_str_ptr = (char *)(&key_str);
	int		ret=0;
	ns_db_diseqc_core_tbl_record_t * dc_record;

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

    if (!(dc_record = ns_ipcc_mem_alloc(sizeof(ns_db_diseqc_core_tbl_record_t)))) {
    	NS_SYSLOG_SNMP(LOG_ALERT, " Failed to allocate shared memory\n");
    	return NULL;
    }

    //
    // should call ns-db-utils that call HALL function!!!
    // it should insert new command according to NAME (=key) only and set other parameters to default values
    //
    //strncpy(key_str, nsDemodConfigDiseqcName, nsDemodConfigDiseqcName_len);
    //ret = ns_db_util_add_table_row_with_user_index(NS_DB_TBL_ID_DISEQC_CORE, key_str_ptr);
    //
    //

    NS_SYSLOG_SNMP(LOG_ALERT, "~~~~~~~~~~~~~~~~~~~~~nbm: 2 nsDemodConfigDiseqcName=%s, nsDemodConfigDiseqcName_len=%d", nsDemodConfigDiseqcName, nsDemodConfigDiseqcName_len);
    strncpy(dc_record->name, nsDemodConfigDiseqcName, nsDemodConfigDiseqcName_len);
    NS_SYSLOG_SNMP(LOG_ALERT, "~~~~~~~~~~~~~~~~~~~~~nbm: 3 dc_record->name=%s", dc_record->name);
    dc_record->header = 0xe01022;
    dc_record->nr_data_bytes = 0;
    dc_record->tone_burst = 0;
    ret = ns_db_tbl_add_record(NS_DB_TBL_ID_DISEQC_CORE, dc_record);

    if (ret) {
    	NS_SYSLOG_SNMP(LOG_ALERT, "Failed to add new record. (%d)", ret);
    	return NULL;
    }

    return entry;
}

/*
 * remove a row from the table 
 */
static void
nsDemodConfigDiseqcTable_removeEntry(struct nsDemodConfigDiseqcTable_entry
                                     *entry)
{
	NS_SYSLOG_SNMP(LOG_ALERT, "~~~~~~~~~~~~~~~~~~~~~nbm: 1 removeEntry");
	char	key_str[NS_TBL_FLD_MAX_LEN];
	char	*key_str_ptr = (char *)(&key_str);
	int		ret=0;

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

    /*
     * XXX - remove entry from local data structure 
     */
    NS_SYSLOG_SNMP(LOG_ALERT, "~~~~~~~~~~~~~~~~~~~~~nbm: 2 entry->nsDemodConfigDiseqcName=%s, entry->nsDemodConfigDiseqcName_len=%d", entry->nsDemodConfigDiseqcName, entry->nsDemodConfigDiseqcName_len);
	strncpy(key_str, entry->nsDemodConfigDiseqcName, entry->nsDemodConfigDiseqcName_len);
    NS_SYSLOG_SNMP(LOG_ALERT, "~~~~~~~~~~~~~~~~~~~~~nbm: 3 key_str=%s", key_str);
    ret = ns_db_util_delete_table_row(NS_DB_TBL_ID_DISEQC_CORE, &key_str_ptr);

    if (ret) {
    	NS_SYSLOG_SNMP(LOG_ALERT, "Failed to delete record. (%d)", ret);
    } else {
    	if (entry) {
    		/* XXX - release any other internal resources */
    		//no need to free. we never allocate.
    	}
    }
}


/** determine the appropriate row for an exact request */
static struct nsDemodConfigDiseqcTable_entry *
nsDemodConfigDiseqcTable_get_entry(netsnmp_variable_list * indexes)
{
    NS_SYSLOG_SNMP(LOG_ALERT, "----------------------------------------nbm: get entry-1");
    struct nsDemodConfigDiseqcTable_entry *row = NULL;
    netsnmp_variable_list 								 *idx = indexes;
    ns_db_diseqc_core_tbl_record_t						 *tbl_record_pointer;
	char	*key_pointer;

	tbl_record_pointer = (ns_db_diseqc_core_tbl_record_t *) ns_ipcc_mem_alloc(sizeof(ns_db_diseqc_core_tbl_record_t));
	key_pointer = (uint8_t *) ns_ipcc_mem_alloc(sizeof(char)*NS_TBL_FLD_MAX_LEN);
    NS_SYSLOG_SNMP(LOG_ALERT, "----nbm: 2");

	if ((!key_pointer) || (!tbl_record_pointer)) {
		ns_ipcc_mem_free();
		return NULL;
	}
		NS_SYSLOG_SNMP(LOG_ALERT, "----nbm: 3, idx->val.string=%s, idx->val_len=%d", idx->val.string, idx->val_len);

	strncpy(key_pointer, idx->val.string, NS_TBL_FLD_MAX_LEN);
    NS_SYSLOG_SNMP(LOG_ALERT, "----nbm: 4, key_pointer=%s", key_pointer);

    /*
     * XXX - Use the 'indexes' parameter to retrieve the data
     * structure for the requested row, and return this.
     */
	if (!ns_db_tbl_get_record(NS_DB_TBL_ID_DISEQC_CORE, key_pointer, tbl_record_pointer)) {
	    NS_SYSLOG_SNMP(LOG_ALERT, "----nbm: 5");
	    NS_SYSLOG_SNMP(LOG_ALERT, "~~~~nbm: 5a tbl_record_pointer->name=%s, NS_TBL_FLD_MAX_LEN=%d", tbl_record_pointer->name, NS_TBL_FLD_MAX_LEN);
		strncpy(DemodConfigDiseqc_entry.nsDemodConfigDiseqcName, tbl_record_pointer->name, NS_TBL_FLD_MAX_LEN);
	    NS_SYSLOG_SNMP(LOG_ALERT, "~~~~nbm: 5b DemodConfigDiseqc_entry.nsDemodConfigDiseqcName=%s", DemodConfigDiseqc_entry.nsDemodConfigDiseqcName);
		DemodConfigDiseqc_entry.nsDemodConfigDiseqcName_len = strlen(tbl_record_pointer->name);
		DemodConfigDiseqc_entry.nsDemodConfigDiseqcHeaderBytes = tbl_record_pointer->header;
		DemodConfigDiseqc_entry.nsDemodConfigDiseqcNumDataBytes = tbl_record_pointer->nr_data_bytes;
		DemodConfigDiseqc_entry.nsDemodConfigDiseqcToneBurstMode = tbl_record_pointer->tone_burst;
	    NS_SYSLOG_SNMP(LOG_ALERT, "----nbm: 6, header=0x%lx, num=%d, tbm=%d", DemodConfigDiseqc_entry.nsDemodConfigDiseqcHeaderBytes, DemodConfigDiseqc_entry.nsDemodConfigDiseqcNumDataBytes, DemodConfigDiseqc_entry.nsDemodConfigDiseqcToneBurstMode);

		DemodConfigDiseqc_entry.nsDemodConfigDiseqcNotifyRowStatus = 1;

		/* get row */
		row = &DemodConfigDiseqc_entry;
	}

	ns_ipcc_mem_free();
    NS_SYSLOG_SNMP(LOG_ALERT, "----nbm: 7");

    /*
     * XXX - Use the 'indexes' parameter to retrieve the data
     * structure for the requested row, and return this. 
     */
    return row;
}

/** determine the appropriate row for an fuzzy request */
static struct nsDemodConfigDiseqcTable_entry *
nsDemodConfigDiseqcTable_get_next_entry(netsnmp_handler_registration
                                        *reginfo,
                                        netsnmp_request_info *request,
                                        int column,
                                        netsnmp_variable_list * indexes)
{
    struct nsDemodConfigDiseqcTable_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;
    ns_db_diseqc_core_tbl_record_t		*tbl_record_pointer;
	char								*key_pointer;
    int									ret=0;
    bool 								is_writable;
    bool 								is_visible;
    NS_SYSLOG_SNMP(LOG_ALERT, "=======================================nbm: get next entry-1");

	tbl_record_pointer = (ns_db_diseqc_core_tbl_record_t *) ns_ipcc_mem_alloc(sizeof(ns_db_diseqc_core_tbl_record_t));
	key_pointer = (uint8_t *) ns_ipcc_mem_alloc(sizeof(char)*NS_TBL_FLD_MAX_LEN);

	if ((!key_pointer) || (!tbl_record_pointer)) {
		ns_ipcc_mem_free();
		return NULL;
	}
    NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 2. index-type=%d, oct-str=%d, len=%d, str=%s, int=%d, c0=%c, c1=%c, c2=%c, c0=%d, c1=%d, c2=%d", idx->type, ASN_OCTET_STR, idx->val_len, idx->val.string, idx->val.integer, (idx->val.string)[0], (idx->val.string)[1], (idx->val.string)[2], (idx->val.string)[0], (idx->val.string)[1], (idx->val.string)[2]);

	strncpy(key_pointer, idx->val.string, NS_TBL_FLD_MAX_LEN);
    NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 3, key_pointer=%s", key_pointer);
    /*
     * XXX - Use the 'indexes' parameter to identify the
     * next row in the table.... 
     */
	if (!ns_db_tbl_get_next_record(NS_DB_TBL_ID_DISEQC_CORE, key_pointer, tbl_record_pointer)) {
		NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 4");
		NS_SYSLOG_SNMP(LOG_ALERT, "~~~~nbm: 4a tbl_record_pointer->name=%s, NS_TBL_FLD_MAX_LEN=%d", tbl_record_pointer->name, NS_TBL_FLD_MAX_LEN);
		strncpy(DemodConfigDiseqc_entry.nsDemodConfigDiseqcName, tbl_record_pointer->name, NS_TBL_FLD_MAX_LEN);
		NS_SYSLOG_SNMP(LOG_ALERT, "~~~~nbm: 4b DemodConfigDiseqc_entry.nsDemodConfigDiseqcName=%s", DemodConfigDiseqc_entry.nsDemodConfigDiseqcName);
		DemodConfigDiseqc_entry.nsDemodConfigDiseqcName_len = strlen(tbl_record_pointer->name);
		DemodConfigDiseqc_entry.nsDemodConfigDiseqcHeaderBytes = tbl_record_pointer->header;
		DemodConfigDiseqc_entry.nsDemodConfigDiseqcNumDataBytes = tbl_record_pointer->nr_data_bytes;
		DemodConfigDiseqc_entry.nsDemodConfigDiseqcToneBurstMode = tbl_record_pointer->tone_burst;

		DemodConfigDiseqc_entry.nsDemodConfigDiseqcNotifyRowStatus = 1;
		NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 5, header=0x%lx, num=%d, tbm=%d", DemodConfigDiseqc_entry.nsDemodConfigDiseqcHeaderBytes, DemodConfigDiseqc_entry.nsDemodConfigDiseqcNumDataBytes, DemodConfigDiseqc_entry.nsDemodConfigDiseqcToneBurstMode);

		/* get row */
		row = &DemodConfigDiseqc_entry;

		/*
		 * XXX   .... update the 'indexes' parameter with the
		 * appropriate index values ...
		 */
		NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 6, key_pointer=%s, NS_TBL_FLD_MAX_LEN=%d", key_pointer, NS_TBL_FLD_MAX_LEN);
		strncpy(idx->val.string, key_pointer, NS_TBL_FLD_MAX_LEN);
		idx->val_len = strlen(idx->val.string);
		NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 7, idx->val.string=%s, idx->val_len=%d", idx->val.string, idx->val_len);

		/*
		 * ... and update the requested OID to match this instance
		 */
		memcpy(build_space, reginfo->rootoid,       /* registered oid */
			   reginfo->rootoid_len * sizeof(oid));
		NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 8");
		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);
		NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 12");
		snmp_set_var_objid(request->requestvb, build_space,
						   build_space_len + index_oid_len);
		NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 13");
	}

    /*
     * Finally, return the data structure for this row 
     */
	NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 15");
	ns_ipcc_mem_free();
	NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 16");
    return row;
}

/** handles requests for the nsDemodConfigDiseqcTable table */
static int
nsDemodConfigDiseqcTable_handler(netsnmp_mib_handler *handler,
                                 netsnmp_handler_registration *reginfo,
                                 netsnmp_agent_request_info *reqinfo,
                                 netsnmp_request_info *requests)
{
	NS_SYSLOG_SNMP(LOG_ALERT, "~~~~~~~~~~~~~~~~~~~~~nbm: 1 handler");
    netsnmp_request_info *request;
    netsnmp_table_request_info *table_info;
    struct nsDemodConfigDiseqcTable_entry *table_entry;
    int             ret;
	char			key_str[NS_TBL_FLD_MAX_LEN];
	char			*key_str_ptr = (char *)(&key_str);
    uint8_t			val_uint8;
    uint32_t		val_uint32;
    uint64_t		val_uint64;

    ret = ns_utils_check_ipc_connection();
	if (ret==ns_err_get_err_num_by_id(NS_ERR_IPC_MSG_TIMEOUT)) {
		netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_GENERR);

	} else if (ret) {
		netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_GENERR);
		return SNMP_ERR_GENERR;

	} else {

		switch (reqinfo->mode) {
			/*
			 * Read-support
			 */
		case MODE_GET:
			NS_SYSLOG_SNMP(LOG_ALERT, "~~~~~~~~~~~~~~~~~~~~~nbm: 2 GET");
			ret = pthread_mutex_trylock(&snmp_active_thread_mutex);
			if (ret) {
				//mutex already locked, will not handle request
				DEBUGMSGTL(("nsDemodConfigLine", "Device is busy\n"));
				NS_SYSLOG_SNMP(LOG_ALERT, "SNMP Device is busy\n");
				netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_GENERR);
			} else {
				for (request = requests; request; request = request->next) {
					table_info = netsnmp_extract_table_info(request);
					table_entry =
						nsDemodConfigDiseqcTable_get_entry(table_info->indexes);

					switch (table_info->colnum) {
					case COLUMN_NSDEMODCONFIGDISEQCHEADERBYTES:
						if (!table_entry) {
							netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
							continue;
						}
						snmp_set_var_typed_integer(request->requestvb,
												   ASN_UNSIGNED,
												   table_entry->nsDemodConfigDiseqcHeaderBytes);
						break;
					case COLUMN_NSDEMODCONFIGDISEQCNUMDATABYTES:
						if (!table_entry) {
							netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
							continue;
						}
						snmp_set_var_typed_integer(request->requestvb,
												   ASN_UNSIGNED,
												   table_entry->nsDemodConfigDiseqcNumDataBytes);
						break;
					case COLUMN_NSDEMODCONFIGDISEQCTONEBURSTMODE:
						if (!table_entry) {
							netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
							continue;
						}
						snmp_set_var_typed_integer(request->requestvb,
												   ASN_INTEGER,
												   table_entry->nsDemodConfigDiseqcToneBurstMode);
						break;
					case COLUMN_NSDEMODCONFIGDISEQCNOTIFYROWSTATUS:
						if (!table_entry) {
							netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
							continue;
						}
						snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
												   table_entry->nsDemodConfigDiseqcNotifyRowStatus);
						break;
					default:
						netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
						break;
					}
				}
				//unlock is-busy mutex
				pthread_mutex_unlock(&snmp_active_thread_mutex);
			}
			break;

		case MODE_GETNEXT:
			NS_SYSLOG_SNMP(LOG_ALERT, "~~~~~~~~~~~~~~~~~~~~~nbm: 2 GETNEXT");
			ret = pthread_mutex_trylock(&snmp_active_thread_mutex);
			if (ret) {
				//mutex already locked, will not handle request
				DEBUGMSGTL(("nsDemodConfigLine", "Device is busy\n"));
				NS_SYSLOG_SNMP(LOG_ALERT, "SNMP Device is busy\n");
				netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_GENERR);
			} else {
				for (request = requests; request; request = request->next) {
					table_info = netsnmp_extract_table_info(request);
					table_entry = nsDemodConfigDiseqcTable_get_next_entry(reginfo, request,
																table_info->colnum,
																table_info->indexes);
					NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 20");

					switch (table_info->colnum) {
					case COLUMN_NSDEMODCONFIGDISEQCHEADERBYTES:
						NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 21 head");
						if (!table_entry) {
							netsnmp_set_request_error(reqinfo, request, SNMP_ENDOFMIBVIEW);
							continue;
						}
						snmp_set_var_typed_integer(request->requestvb,
												   ASN_UNSIGNED,
												   table_entry->
												   nsDemodConfigDiseqcHeaderBytes);
						break;
					case COLUMN_NSDEMODCONFIGDISEQCNUMDATABYTES:
						NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 22 num");
						if (!table_entry) {
							NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 23");
							netsnmp_set_request_error(reqinfo, request, SNMP_ENDOFMIBVIEW);
							continue;
						}
						NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 24");
						snmp_set_var_typed_integer(request->requestvb,
												   ASN_UNSIGNED,
												   table_entry->
												   nsDemodConfigDiseqcNumDataBytes);
						NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 25");
						break;
					case COLUMN_NSDEMODCONFIGDISEQCTONEBURSTMODE:
						NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 26 tbm");
						if (!table_entry) {
							netsnmp_set_request_error(reqinfo, request, SNMP_ENDOFMIBVIEW);
							continue;
						}
						snmp_set_var_typed_integer(request->requestvb,
												   ASN_INTEGER,
												   table_entry->
												   nsDemodConfigDiseqcToneBurstMode);
						break;
					case COLUMN_NSDEMODCONFIGDISEQCNOTIFYROWSTATUS:
						if (!table_entry) {
							netsnmp_set_request_error(reqinfo, request, SNMP_ENDOFMIBVIEW);
							continue;
						}
						snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
												   table_entry->
												   nsDemodConfigDiseqcNotifyRowStatus);
						break;
					default:
						netsnmp_set_request_error(reqinfo, request, SNMP_ENDOFMIBVIEW);
						break;
					}
					NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 30");
				}
				NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 31");
				//unlock is-busy mutex
				pthread_mutex_unlock(&snmp_active_thread_mutex);
				NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 32");
			}
			break;

			/*
			 * Write-support
			 */
		case MODE_SET_RESERVE1:
			NS_SYSLOG_SNMP(LOG_ALERT, "~~~~~~~~~~~~~~~~~~~~~nbm: 2 RESERVE1");
			ret = pthread_mutex_trylock(&snmp_active_thread_mutex);
			if (ret) {
				//mutex already locked, will not handle request
				DEBUGMSGTL(("nsDemodConfigLine", "Device is busy\n"));
				NS_SYSLOG_SNMP(LOG_ALERT, "SNMP Device is busy\n");
				netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_GENERR);
			} else {
				for (request = requests; request; request = request->next) {
					table_info = netsnmp_extract_table_info(request);
					table_entry = nsDemodConfigDiseqcTable_get_entry(table_info->indexes);
					if (!table_entry) {
						netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
						continue;
					}

					switch (table_info->colnum) {
					case COLUMN_NSDEMODCONFIGDISEQCHEADERBYTES:
						/*
						 * or possibly 'netsnmp_check_vb_int_range'
						 */
						ret = netsnmp_check_vb_uint(request->requestvb);
						if (ret != SNMP_ERR_NOERROR) {
							netsnmp_set_request_error(reqinfo, request, ret);
							pthread_mutex_unlock(&snmp_active_thread_mutex);
							return SNMP_ERR_NOERROR;
						}
						break;
					case COLUMN_NSDEMODCONFIGDISEQCNUMDATABYTES:
						/*
						 * or possibly 'netsnmp_check_vb_int_range'
						 */
						ret = netsnmp_check_vb_uint(request->requestvb);
						if (ret != SNMP_ERR_NOERROR) {
							netsnmp_set_request_error(reqinfo, request, ret);
							pthread_mutex_unlock(&snmp_active_thread_mutex);
							return SNMP_ERR_NOERROR;
						}
						break;
					case COLUMN_NSDEMODCONFIGDISEQCTONEBURSTMODE:
						/*
						 * or possibly 'netsnmp_check_vb_int_range'
						 */
						ret = netsnmp_check_vb_int(request->requestvb);
						if (ret != SNMP_ERR_NOERROR) {
							netsnmp_set_request_error(reqinfo, request, ret);
							pthread_mutex_unlock(&snmp_active_thread_mutex);
							return SNMP_ERR_NOERROR;
						}
						break;
					case COLUMN_NSDEMODCONFIGDISEQCNOTIFYROWSTATUS:
						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);
							pthread_mutex_unlock(&snmp_active_thread_mutex);
							return SNMP_ERR_NOERROR;
						}
						break;
					default:
						netsnmp_set_request_error(reqinfo, request,
												  SNMP_ERR_NOTWRITABLE);
						pthread_mutex_unlock(&snmp_active_thread_mutex);
						return SNMP_ERR_NOERROR;
					}
				}
				//unlock is-busy mutex
				pthread_mutex_unlock(&snmp_active_thread_mutex);
			}
			break;

		case MODE_SET_RESERVE2:
			NS_SYSLOG_SNMP(LOG_ALERT, "~~~~~~~~~~~~~~~~~~~~~nbm: 2 RESERVE2");
			ret = pthread_mutex_trylock(&snmp_active_thread_mutex);
			if (ret) {
				//mutex already locked, will not handle request
				DEBUGMSGTL(("nsDemodConfigLine", "Device is busy\n"));
				NS_SYSLOG_SNMP(LOG_ALERT, "SNMP Device is busy\n");
				netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_GENERR);
			} else {
				for (request = requests; request; request = request->next) {
					table_info = netsnmp_extract_table_info(request);
					//nbm: table_entry = nsDemodConfigDiseqcTable_get_entry(table_info->indexes);

					switch (table_info->colnum) {
					case COLUMN_NSDEMODCONFIGDISEQCNOTIFYROWSTATUS:
						switch (*request->requestvb->val.integer) {
						case RS_CREATEANDGO:
						case RS_CREATEANDWAIT:
							table_entry = nsDemodConfigDiseqcTable_createEntry(0,
																	 table_info->indexes->val.string,
																	 table_info->indexes->val_len);
							if (!table_entry) {
								netsnmp_set_request_error(reqinfo, request, SNMP_ERR_RESOURCEUNAVAILABLE);
								return SNMP_ERR_NOERROR;
							}
						}
					}
				}
				//unlock is-busy mutex
				pthread_mutex_unlock(&snmp_active_thread_mutex);
			}
			break;

		case MODE_SET_FREE:
			NS_SYSLOG_SNMP(LOG_ALERT, "~~~~~~~~~~~~~~~~~~~~~nbm: 2 FREE");
			ret = pthread_mutex_trylock(&snmp_active_thread_mutex);
			if (ret) {
				//mutex already locked, will not handle request
				DEBUGMSGTL(("nsDemodConfigLine", "Device is busy\n"));
				NS_SYSLOG_SNMP(LOG_ALERT, "SNMP Device is busy\n");
				netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_GENERR);
			} else {
				for (request = requests; request; request = request->next) {
					table_info = netsnmp_extract_table_info(request);
					table_entry =
						nsDemodConfigDiseqcTable_get_entry(table_info->indexes);

					switch (table_info->colnum) {
					case COLUMN_NSDEMODCONFIGDISEQCNOTIFYROWSTATUS:
						switch (*request->requestvb->val.integer) {
						case RS_CREATEANDGO:
						case RS_CREATEANDWAIT:
							if (table_entry && !table_entry->valid) {
								nsDemodConfigDiseqcTable_removeEntry(table_entry);
							}
						}
					}
				}
				//unlock is-busy mutex
				pthread_mutex_unlock(&snmp_active_thread_mutex);
			}
			break;

		case MODE_SET_ACTION:
			NS_SYSLOG_SNMP(LOG_ALERT, "~~~~~~~~~~~~~~~~~~~~~nbm: 2 ACTION");
			ret = pthread_mutex_trylock(&snmp_active_thread_mutex);
			if (ret) {
				//mutex already locked, will not handle request
				DEBUGMSGTL(("nsDemodConfigLine", "Device is busy\n"));
				NS_SYSLOG_SNMP(LOG_ALERT, "SNMP Device is busy\n");
				netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_GENERR);
			} else {
				for (request = requests; request; request = request->next) {
					table_info = netsnmp_extract_table_info(request);
					table_entry =
						nsDemodConfigDiseqcTable_get_entry(table_info->indexes);

					if (!table_entry) {
						netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
						continue;
					}

					switch (table_info->colnum) {
					case COLUMN_NSDEMODCONFIGDISEQCHEADERBYTES:
						table_entry->old_nsDemodConfigDiseqcHeaderBytes =
							table_entry->nsDemodConfigDiseqcHeaderBytes;
						table_entry->nsDemodConfigDiseqcHeaderBytes =
							*request->requestvb->val.integer;
						break;
					case COLUMN_NSDEMODCONFIGDISEQCNUMDATABYTES:
						table_entry->old_nsDemodConfigDiseqcNumDataBytes =
							table_entry->nsDemodConfigDiseqcNumDataBytes;
						table_entry->nsDemodConfigDiseqcNumDataBytes =
							*request->requestvb->val.integer;
						break;
					case COLUMN_NSDEMODCONFIGDISEQCTONEBURSTMODE:
						table_entry->old_nsDemodConfigDiseqcToneBurstMode =
							table_entry->nsDemodConfigDiseqcToneBurstMode;
						table_entry->nsDemodConfigDiseqcToneBurstMode =
							*request->requestvb->val.integer;
						break;
					case COLUMN_NSDEMODCONFIGDISEQCNOTIFYROWSTATUS:
						switch (*request->requestvb->val.integer) {
						case RS_ACTIVE:
						case RS_CREATEANDGO:
							break;
						}
						break;
					}
				}
				//unlock is-busy mutex
				pthread_mutex_unlock(&snmp_active_thread_mutex);
			}
			break;

		case MODE_SET_UNDO:
			NS_SYSLOG_SNMP(LOG_ALERT, "~~~~~~~~~~~~~~~~~~~~~nbm: 2 UNDO");
			ret = pthread_mutex_trylock(&snmp_active_thread_mutex);
			if (ret) {
				//mutex already locked, will not handle request
				DEBUGMSGTL(("nsDemodConfigLine", "Device is busy\n"));
				NS_SYSLOG_SNMP(LOG_ALERT, "SNMP Device is busy\n");
				netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_GENERR);
			} else {
				for (request = requests; request; request = request->next) {
					table_info = netsnmp_extract_table_info(request);
					table_entry =
						nsDemodConfigDiseqcTable_get_entry(table_info->indexes);

					if (!table_entry) {
						netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
						continue;
					}

					switch (table_info->colnum) {
					case COLUMN_NSDEMODCONFIGDISEQCHEADERBYTES:
						table_entry->nsDemodConfigDiseqcHeaderBytes =
							table_entry->old_nsDemodConfigDiseqcHeaderBytes;
						table_entry->old_nsDemodConfigDiseqcHeaderBytes = 0;
						break;
					case COLUMN_NSDEMODCONFIGDISEQCNUMDATABYTES:
						table_entry->nsDemodConfigDiseqcNumDataBytes =
							table_entry->old_nsDemodConfigDiseqcNumDataBytes;
						table_entry->old_nsDemodConfigDiseqcNumDataBytes = 0;
						break;
					case COLUMN_NSDEMODCONFIGDISEQCTONEBURSTMODE:
						table_entry->nsDemodConfigDiseqcToneBurstMode =
							table_entry->old_nsDemodConfigDiseqcToneBurstMode;
						table_entry->old_nsDemodConfigDiseqcToneBurstMode = 0;
						break;
					case COLUMN_NSDEMODCONFIGDISEQCNOTIFYROWSTATUS:
						switch (*request->requestvb->val.integer) {
						case RS_CREATEANDGO:
						case RS_CREATEANDWAIT:
							if (table_entry && !table_entry->valid) {
								nsDemodConfigDiseqcTable_removeEntry(table_entry);
							}
						}
						break;
					}
				}
				//unlock is-busy mutex
				pthread_mutex_unlock(&snmp_active_thread_mutex);
			}
			break;

		case MODE_SET_COMMIT:
			NS_SYSLOG_SNMP(LOG_ALERT, "~~~~~~~~~~~~~~~~~~~~~nbm: 2 COMMIT");
			ret = pthread_mutex_trylock(&snmp_active_thread_mutex);
			if (ret) {
				//mutex already locked, will not handle request
				DEBUGMSGTL(("nsDemodConfigLine", "Device is busy\n"));
				NS_SYSLOG_SNMP(LOG_ALERT, "SNMP Device is busy\n");
				netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_GENERR);
			} else {
				for (request = requests; request; request = request->next) {
					table_info = netsnmp_extract_table_info(request);
					table_entry = nsDemodConfigDiseqcTable_get_entry(table_info->indexes);

					if (!table_entry) {
						netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
						continue;
					}

					switch (table_info->colnum) {
					case COLUMN_NSDEMODCONFIGDISEQCNOTIFYROWSTATUS:
						switch (*request->requestvb->val.integer) {
						case RS_CREATEANDGO:
							table_entry->valid = 1;
							/*
							 * Fall-through
							 */
						case RS_ACTIVE:
							table_entry->nsDemodConfigDiseqcNotifyRowStatus = RS_ACTIVE;
							break;

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

						case RS_DESTROY:
							nsDemodConfigDiseqcTable_removeEntry(table_entry);
						}
					}
				}
				//unlock is-busy mutex
				pthread_mutex_unlock(&snmp_active_thread_mutex);
			}
			break;
		}
	}
	NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 40!!!");

	ns_ipcc_mem_free();
	NS_SYSLOG_SNMP(LOG_ALERT, "====nbm: 41!!!");
    return SNMP_ERR_NOERROR;
}

/** Initialize the nsDemodConfigDiseqcTable table by defining its contents and how it's structured */
static void
initialize_table_nsDemodConfigDiseqcTable(void)
{
    const oid       nsDemodConfigDiseqcTable_oid[] =
        { 1, 3, 6, 1, 4, 1, 37576, 4, 1, 4, 1 };
    netsnmp_handler_registration *reg;
    netsnmp_table_registration_info *table_info;

    reg =
        netsnmp_create_handler_registration("nsDemodConfigDiseqcTable",
                                            nsDemodConfigDiseqcTable_handler,
                                            nsDemodConfigDiseqcTable_oid,
                                            OID_LENGTH
                                            (nsDemodConfigDiseqcTable_oid),
                                            HANDLER_CAN_RWRITE);

    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
    netsnmp_table_helper_add_indexes(table_info, ASN_OCTET_STR, /* index: nsDemodConfigDiseqcName */
                                     0);

    table_info->min_column = COLUMN_NSDEMODCONFIGDISEQCHEADERBYTES;
    table_info->max_column = COLUMN_NSDEMODCONFIGDISEQCNOTIFYROWSTATUS;

    netsnmp_register_table(reg, table_info);

    /*
     * Initialise the contents of the table here 
     */
}

/** Initializes the nsDemodConfigDiseqc module */
void
init_nsDemodConfigDiseqc(void)
{
    /*
     * here we initialize all the tables we're planning on supporting 
     */
    initialize_table_nsDemodConfigDiseqcTable();
}
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.