Re: cache load never gets called
Kathy McLeod <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <OFFCC6A7C6.D532B1D7-ON86257704.0070C4D2-86257704.00722661@us.ibm.com> |
(See attached file: lldpPortConfigTable.cache.c)
Hi -
I had to make a couple of changes to the code generated by the mib2c when I
added the cache option (because the generated methods didn't exist (or at
least the compiler didn't find them and neither did I)). There didn't seem
to be a lot of choices as to what change to make, but just in case I
screwed something up, here are my changes. I included the file generated
by mib2c so you can see the code in context.
1) the mib2c generated
netsnmp_inject_handler_before(reg, netsnmp_cache_handler_GET(cache),
TABLE_DATA_NAME))
I changed it to
netsnmp_inject_handler_before(reg, netsnmp_cache_handler_get(cache), TABLE_
TDATA_NAME); (the TDATA change based on your note).
2) the mib2c generated
while ((thisRow = netsnmp_tdata_first_row(table))) {
I changed it to
while ((thisRow = netsnmp_tdata_row_first(table))) {
Hope this helps. Thanks.
Kathy McLeod
Dept S82 CCB - SNMP
IBM Rochester, MN
(507) 253-4803
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
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
lldpPortConfigTable.cache.c
(application/octet-stream, 14 KB)
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.table_data.conf 16004 2007-03-27 09:20:28Z 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 "lldpPortConfigTable.h"
/** Initializes the lldpPortConfigTable module */
void
init_lldpPortConfigTable(void)
{
/*
* here we initialize all the tables we're planning on supporting
*/
initialize_table_lldpPortConfigTable();
}
# Determine the first/last column names
/** Initialize the lldpPortConfigTable table by defining its contents and how it's structured */
void
initialize_table_lldpPortConfigTable(void)
{
static oid lldpPortConfigTable_oid[] =
{ 1, 0, 8802, 1, 1, 2, 1, 1, 6 };
size_t lldpPortConfigTable_oid_len =
OID_LENGTH(lldpPortConfigTable_oid);
netsnmp_handler_registration *reg;
netsnmp_tdata *table_data;
netsnmp_table_registration_info *table_info;
netsnmp_cache *cache;
reg =
netsnmp_create_handler_registration("lldpPortConfigTable",
lldpPortConfigTable_handler,
lldpPortConfigTable_oid,
lldpPortConfigTable_oid_len,
HANDLER_CAN_RWRITE);
table_data = netsnmp_tdata_create_table("lldpPortConfigTable", 0);
table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: lldpPortConfigPortNum */
0);
table_info->min_column = COLUMN_LLDPPORTCONFIGADMINSTATUS;
table_info->max_column = COLUMN_LLDPPORTCONFIGTLVSTXENABLE;
netsnmp_tdata_register(reg, table_data, table_info);
cache = netsnmp_cache_create(LLDPPORTCONFIGTABLE_TIMEOUT,
lldpPortConfigTable_load,
lldpPortConfigTable_free,
lldpPortConfigTable_oid,
lldpPortConfigTable_oid_len),
cache->magic = (void *) table_data;
netsnmp_inject_handler_before(reg, netsnmp_cache_handler_GET(cache),
TABLE_DATA_NAME))
/*
* Initialise the contents of the table here
*/
}
/*
* Typical data structure for a row entry
*/
struct lldpPortConfigTable_entry {
/*
* Index values
*/
long lldpPortConfigPortNum;
/*
* Column values
*/
long lldpPortConfigAdminStatus;
long old_lldpPortConfigAdminStatus;
long lldpPortConfigNotificationEnable;
long old_lldpPortConfigNotificationEnable;
char lldpPortConfigTLVsTxEnable[NNN];
size_t lldpPortConfigTLVsTxEnable_len;
char old_lldpPortConfigTLVsTxEnable[NNN];
size_t old_lldpPortConfigTLVsTxEnable_len;
int valid;
};
/*
* create a new row in the table
*/
netsnmp_tdata_row *lldpPortConfigTable_createEntry(netsnmp_tdata *
table_data,
long
lldpPortConfigPortNum) {
struct lldpPortConfigTable_entry *entry;
netsnmp_tdata_row *row;
entry = SNMP_MALLOC_TYPEDEF(struct lldpPortConfigTable_entry);
if (!entry)
return NULL;
row = netsnmp_tdata_create_row();
if (!row) {
SNMP_FREE(entry);
return NULL;
}
row-> data = entry;
entry->lldpPortConfigPortNum = lldpPortConfigPortNum;
netsnmp_tdata_row_add_index(row, ASN_INTEGER,
&(entry->lldpPortConfigPortNum),
sizeof(entry->lldpPortConfigPortNum));
netsnmp_tdata_add_row(table_data, row);
return row;
}
/*
* remove a row from the table
*/
void
lldpPortConfigTable_removeEntry(netsnmp_tdata * table_data,
netsnmp_tdata_row * row) {
struct lldpPortConfigTable_entry *entry;
if (!row)
return; /* Nothing to remove */
entry = (struct lldpPortConfigTable_entry *)
netsnmp_tdata_remove_and_delete_row(table_data, row);
if (entry)
SNMP_FREE(entry); /* XXX - release any other internal resources */
}
/*
* Example cache handling - set up table_data list from a suitable file
*/
int
lldpPortConfigTable_load(netsnmp_cache * cache, void *vmagic) {
netsnmp_tdata * table = (netsnmp_tdata *) vmagic;
netsnmp_tdata_row *row;
FILE * fp;
char buf[STRMAX];
;
fp = fopen("/data/for/lldpPortConfigTable", "r");
while (fgets(buf, STRMAX, fp)) {
/*
* Unpick 'buf' to extract the index values...
*/
this =
lldpPortConfigTable_createEntry(table, lldpPortConfigPortNum);
/*
* ... and then populate 'this' with the column values
*/
} fclose (fp);
}
int
lldpPortConfigTable_free(netsnmp_cache * cache, void *vmagic) {
netsnmp_tdata * table = (netsnmp_tdata *) vmagic;
netsnmp_tdata_row *this;
while ((this = netsnmp_tdata_get_first_row(table))) {
netsnmp_tdata_remove_and_delete_row(table, this);
}}
/** handles requests for the lldpPortConfigTable table */ int
lldpPortConfigTable_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_tdata * table_data;
netsnmp_tdata_row *table_row;
struct lldpPortConfigTable_entry *table_entry;
int ret;
switch (reqinfo->mode) {
/*
* Read-support (also covers GetNext requests)
*/
case MODE_GET:
for (request = requests; request; request = request->next) {
table_entry = (struct lldpPortConfigTable_entry *)
netsnmp_tdata_extract_entry(request);
table_info = netsnmp_extract_table_info(request);
switch (table_info->colnum) {
case COLUMN_LLDPPORTCONFIGADMINSTATUS:
if (!table_entry) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
table_entry->
lldpPortConfigAdminStatus);
break;
case COLUMN_LLDPPORTCONFIGNOTIFICATIONENABLE:
if (!table_entry) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
table_entry->
lldpPortConfigNotificationEnable);
break;
case COLUMN_LLDPPORTCONFIGTLVSTXENABLE:
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->
lldpPortConfigTLVsTxEnable,
table_entry->
lldpPortConfigTLVsTxEnable_len);
break;
default:
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHOBJECT);
break;
}
}
break;
/*
* Write-support
*/
case MODE_SET_RESERVE1:
for (request = requests; request; request = request->next) {
table_entry = (struct lldpPortConfigTable_entry *)
netsnmp_tdata_extract_entry(request);
table_info = netsnmp_extract_table_info(request);
switch (table_info->colnum) {
case COLUMN_LLDPPORTCONFIGADMINSTATUS:
/*
* 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);
return SNMP_ERR_NOERROR;
}
break;
case COLUMN_LLDPPORTCONFIGNOTIFICATIONENABLE:
/*
* 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);
return SNMP_ERR_NOERROR;
}
break;
case COLUMN_LLDPPORTCONFIGTLVSTXENABLE:
/*
* or possiblc 'netsnmp_check_vb_type_and_size'
*/
ret =
netsnmp_check_vb_type_and_max_size(request->requestvb,
ASN_OCTET_STR,
sizeof(table_entry->
lldpPortConfigTLVsTxEnable));
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:
break;
case MODE_SET_FREE:
break;
case MODE_SET_ACTION:
for (request = requests; request; request = request->next) {
table_entry = (struct lldpPortConfigTable_entry *)
netsnmp_tdata_extract_entry(request);
table_info = netsnmp_extract_table_info(request);
switch (table_info->colnum) {
case COLUMN_LLDPPORTCONFIGADMINSTATUS:
table_entry->old_lldpPortConfigAdminStatus =
table_entry->lldpPortConfigAdminStatus;
table_entry->lldpPortConfigAdminStatus =
*request->requestvb->val.integer;
break;
case COLUMN_LLDPPORTCONFIGNOTIFICATIONENABLE:
table_entry->old_lldpPortConfigNotificationEnable =
table_entry->lldpPortConfigNotificationEnable;
table_entry->lldpPortConfigNotificationEnable =
*request->requestvb->val.integer;
break;
case COLUMN_LLDPPORTCONFIGTLVSTXENABLE:
memcpy(table_entry->old_lldpPortConfigTLVsTxEnable,
table_entry->lldpPortConfigTLVsTxEnable,
sizeof(table_entry->lldpPortConfigTLVsTxEnable));
table_entry->old_lldpPortConfigTLVsTxEnable_len =
table_entry->lldpPortConfigTLVsTxEnable_len;
memset(table_entry->lldpPortConfigTLVsTxEnable, 0,
sizeof(table_entry->lldpPortConfigTLVsTxEnable));
memcpy(table_entry->lldpPortConfigTLVsTxEnable,
request->requestvb->val.string,
request->requestvb->val_len);
table_entry->lldpPortConfigTLVsTxEnable_len =
request->requestvb->val_len;
break;
}
}
break;
case MODE_SET_UNDO:
for (request = requests; request; request = request->next) {
table_entry = (struct lldpPortConfigTable_entry *)
netsnmp_tdata_extract_entry(request);
table_row = netsnmp_tdata_extract_row(request);
table_data = netsnmp_tdata_extract_table(request);
table_info = netsnmp_extract_table_info(request);
switch (table_info->colnum) {
case COLUMN_LLDPPORTCONFIGADMINSTATUS:
table_entry->lldpPortConfigAdminStatus =
table_entry->old_lldpPortConfigAdminStatus;
table_entry->old_lldpPortConfigAdminStatus = 0;
break;
case COLUMN_LLDPPORTCONFIGNOTIFICATIONENABLE:
table_entry->lldpPortConfigNotificationEnable =
table_entry->old_lldpPortConfigNotificationEnable;
table_entry->old_lldpPortConfigNotificationEnable = 0;
break;
case COLUMN_LLDPPORTCONFIGTLVSTXENABLE:
memcpy(table_entry->lldpPortConfigTLVsTxEnable,
table_entry->old_lldpPortConfigTLVsTxEnable,
sizeof(table_entry->lldpPortConfigTLVsTxEnable));
memset(table_entry->old_lldpPortConfigTLVsTxEnable, 0,
sizeof(table_entry->lldpPortConfigTLVsTxEnable));
table_entry->lldpPortConfigTLVsTxEnable_len =
table_entry->old_lldpPortConfigTLVsTxEnable_len;
break;
}
}
break;
case MODE_SET_COMMIT:
break;
}
return SNMP_ERR_NOERROR;
}