Hi Yuriy,
Your mention of the lwip private mib generator makes me suspect that you are
using my MibParser python package.
If so, to illustrate how the table code works, in a very simplistic way, I have
attached a c source code file that fully implements the private mib example
that is included in the MibParser package.
For the exTable, take a look at:
- the test_table_struct at the top of the source code, also the declaration and
initialization of the test_table[] array
- at the bottom of the source code, in the lwip_privmib_init() function where
snmp_mib_node_insert is called twice
- the functions exEntry_get_value() and exEntry_set_value() where the
test_table
is accessed
I hope this helps,
James
----- Original Message ----
> From: Yuriy Kiselev <[email protected]>
> To: [email protected]
> Sent: Fri, April 13, 2012 5:56:15 AM
> Subject: [lwip-users] Add entry to snmp table
>
> Hello!
> I generated my own snmp tree with lwip private mib generator but I was
> not able to add entry in a table. I tried to use
> snmp_mib_node_insert() but it still empty: agent return noSuchName.
> Please can anyone show an example?
>
> MIB: http://pastebin.com/3bNaQynE
> private_mib.c: http://pastebin.com/ENi4pMED // adding node is in
> lwip_privmib_init();
>
> _______________________________________________
> lwip-users mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
#include "private_mib.h"
#include "lwip/snmp.h"
#include "lwip/snmp_msg.h"
#include "lwip/snmp_asn1.h"
#include "lwip/snmp_structs.h"
#include "syslog.h"
/**
* Initialises this private MIB before use.
*
*/
void ocstrncpy(u8_t *dst, u8_t *src, u8_t n);
void objectidncpy(s32_t *dst, s32_t *src, u8_t n);
void lwip_privmib_init(void);
#define SIZE_NAME_BUF 64
struct test_table_struct {
u32_t status;
char name[SIZE_NAME_BUF];
};
struct test_table_struct test_table[] = {{1, "One"}, {2, "Two"}};
static void exEntry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def
*od)
{
u8_t id;
//syslog_q(LOG_NOTICE, "exEntry_get_object_def");
/* return to object name, adding index depth (1) */
ident_len += 1;
ident -= 1;
if (ident_len == 2)
{
od->id_inst_len = ident_len;
od->id_inst_ptr = ident;
id = ident[0];
LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def private
exEntry.%"U16_F".0\n",(u16_t)id));
switch (id)
{
case 1: /* exIndex */
od->instance = MIB_OBJECT_TAB;
od->access = MIB_OBJECT_READ_ONLY;
od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
od->v_len = sizeof(u32_t);
break;
case 2: /* exStatus */
od->instance = MIB_OBJECT_TAB;
od->access = MIB_OBJECT_READ_WRITE;
od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
od->v_len = sizeof(u32_t);
break;
case 3: /* exName */
od->instance = MIB_OBJECT_TAB;
od->access = MIB_OBJECT_READ_ONLY;
od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
od->v_len = SIZE_NAME_BUF;
break;
default:
LWIP_DEBUGF(SNMP_MIB_DEBUG,("exEntry_get_object_def: no such
object\n"));
od->instance = MIB_OBJECT_NONE;
break;
};
}
else
{
LWIP_DEBUGF(SNMP_MIB_DEBUG,("private exEntry_get_object_def: no scalar\n"));
od->instance = MIB_OBJECT_NONE;
}
}
static void exEntry_get_value(struct obj_def *od, u16_t len, void *value)
{
u8_t id;
//syslog_q(LOG_NOTICE, "exEntry_get_value index: %d", od->id_inst_ptr[1]);
/* the index value can be found in: od->id_inst_ptr[1] */
id = od->id_inst_ptr[0];
switch (id)
{
case 1: /* exIndex */
{
s32_t *sint_ptr = value;
*sint_ptr = od->id_inst_ptr[1]; /* todo: set appropriate value */
}
break;
case 2: /* exStatus */
{
s32_t *sint_ptr = value;
*sint_ptr = test_table[od->id_inst_ptr[1]-1].status;
}
break;
case 3: /* exName */
ocstrncpy(value,(u8_t*)test_table[od->id_inst_ptr[1]-1].name,len);
break;
};
}
static u8_t exEntry_set_test(struct obj_def *od, u16_t len, void *value)
{
u8_t id, set_ok;
/* the index value can be found in: od->id_inst_ptr[1] */
set_ok = 0;
id = od->id_inst_ptr[0];
switch (id)
{
case 2:
set_ok = 1;
break;
};
return set_ok;
}
static void exEntry_set_value(struct obj_def *od, u16_t len, void *value)
{
u8_t id;
/* the index value can be found in: od->id_inst_ptr[1] */
id = od->id_inst_ptr[0];
switch (id)
{
case 2:
{
s32_t *sint_ptr = value;
test_table[od->id_inst_ptr[1]-1].status = *sint_ptr;
}
break;
};
}
struct mib_list_rootnode exEntry_root = {
&exEntry_get_object_def,
&exEntry_get_value,
&exEntry_set_test,
&exEntry_set_value,
MIB_NODE_LR,
0,
NULL,
NULL, 0,
};
/* exEntry .1.3.6.1.4.1.42421.1.1.3.1 */
const s32_t exEntry_ids[3] = { 1, 2, 3 };
struct mib_node* const exEntry_nodes[3] = {
(struct mib_node* const)&exEntry_root,
(struct mib_node* const)&exEntry_root,
(struct mib_node* const)&exEntry_root
};
const struct mib_array_node exEntry = {
&noleafs_get_object_def,
&noleafs_get_value,
&noleafs_set_test,
&noleafs_set_value,
MIB_NODE_AR,
3,
exEntry_ids,
exEntry_nodes
};
/* exTable .1.3.6.1.3.1.1.42421.1.4 */
s32_t exTable_ids[1] = { 1 };
struct mib_node* exTable_nodes[1] = {
(struct mib_node* const)&exEntry
};
struct mib_ram_array_node exTable = {
&noleafs_get_object_def,
&noleafs_get_value,
&noleafs_set_test,
&noleafs_set_value,
MIB_NODE_RA,
0,
exTable_ids,
exTable_nodes
};
static void mysystem_get_object_def(u8_t ident_len, s32_t *ident, struct
obj_def *od)
{
u8_t id;
/* return to object name, adding index depth (1) */
ident_len += 1;
ident -= 1;
if (ident_len == 2)
{
od->id_inst_len = ident_len;
od->id_inst_ptr = ident;
id = ident[0];
LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def private
mysystem.%"U16_F".0\n",(u16_t)id));
switch (id)
{
case 1: /* loglevel */
od->instance = MIB_OBJECT_SCALAR;
od->access = MIB_OBJECT_READ_WRITE;
od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
od->v_len = sizeof(u32_t);
break;
case 2: /* restart */
od->instance = MIB_OBJECT_SCALAR;
od->access = MIB_OBJECT_READ_WRITE;
od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
od->v_len = sizeof(u32_t);
break;
default:
LWIP_DEBUGF(SNMP_MIB_DEBUG,("mysystem_get_object_def: no such
object\n"));
od->instance = MIB_OBJECT_NONE;
break;
};
}
else
{
LWIP_DEBUGF(SNMP_MIB_DEBUG,("private mysystem_get_object_def: no
scalar\n"));
od->instance = MIB_OBJECT_NONE;
}
}
extern u32_t sysloglevel;
extern u32_t sysreset;
static void mysystem_get_value(struct obj_def *od, u16_t len, void *value)
{
u8_t id;
id = od->id_inst_ptr[0];
switch (id)
{
case 1: /* loglevel */
{
s32_t *sint_ptr = value;
*sint_ptr = sysloglevel;
}
break;
case 2: /* restart */
{
s32_t *sint_ptr = value;
*sint_ptr = sysreset;
}
break;
};
}
static u8_t mysystem_set_test(struct obj_def *od, u16_t len, void *value)
{
u8_t id, set_ok;
set_ok = 0;
id = od->id_inst_ptr[0];
switch (id)
{
case 1: /* loglevel */
/* validate the value argument and set ok */
set_ok = 1;
break;
case 2: /* restart */
/* validate the value argument and set ok */
set_ok = 1;
break;
};
return set_ok;
}
static void mysystem_set_value(struct obj_def *od, u16_t len, void *value)
{
u8_t id;
id = od->id_inst_ptr[0];
switch (id)
{
case 1: /* loglevel */
{
s32_t *sint_ptr = value;
sysloglevel = *sint_ptr; /* do something with the value */
}
break;
case 2: /* restart */
{
s32_t *sint_ptr = value;
sysreset = *sint_ptr; /* do something with the value */
}
break;
};
}
const mib_scalar_node mysystem_scalar = {
&mysystem_get_object_def,
&mysystem_get_value,
&mysystem_set_test,
&mysystem_set_value,
MIB_NODE_SC,
0
};
/* mysystem .1.3.6.1.4.1.42421.1.1 */
const s32_t mysystem_ids[3] = { 1, 2, 3 };
struct mib_node* const mysystem_nodes[3] = {
(struct mib_node* const)&mysystem_scalar,
(struct mib_node* const)&mysystem_scalar,
(struct mib_node* const)&exTable
};
const struct mib_array_node mysystem = {
&noleafs_get_object_def,
&noleafs_get_value,
&noleafs_set_test,
&noleafs_set_value,
MIB_NODE_AR,
3,
mysystem_ids,
mysystem_nodes
};
/* examples .1.3.6.1.1.42421.1.4 */
const s32_t examples_ids[1] = { 1 };
struct mib_node* const examples_nodes[1] = {
(struct mib_node* const)&mysystem
};
const struct mib_array_node examples = {
&noleafs_get_object_def,
&noleafs_get_value,
&noleafs_set_test,
&noleafs_set_value,
MIB_NODE_AR,
1,
examples_ids,
examples_nodes
};
/* xpr1769 .1.3.6.1.4.1.42421 */
const s32_t xpr1769_ids[1] = { 1 };
struct mib_node* const xpr1769_nodes[1] = {
(struct mib_node* const)&examples
};
const struct mib_array_node xpr1769 = {
&noleafs_get_object_def,
&noleafs_get_value,
&noleafs_set_test,
&noleafs_set_value,
MIB_NODE_AR,
1,
xpr1769_ids,
xpr1769_nodes
};
/* enterprises .1.3.6.1.1.4 */
const s32_t enterprises_ids[1] = { 42421 };
struct mib_node* const enterprises_nodes[1] = {
(struct mib_node* const)&xpr1769
};
const struct mib_array_node enterprises = {
&noleafs_get_object_def,
&noleafs_get_value,
&noleafs_set_test,
&noleafs_set_value,
MIB_NODE_AR,
1,
enterprises_ids,
enterprises_nodes
};
/* private .1.3.6.1.4 */
const s32_t private_ids[1] = { 1 };
struct mib_node* const private_nodes[1] = {
(struct mib_node* const)&enterprises
};
const struct mib_array_node private = {
&noleafs_get_object_def,
&noleafs_get_value,
&noleafs_set_test,
&noleafs_set_value,
MIB_NODE_AR,
1,
private_ids,
private_nodes
};
void
lwip_privmib_init(void)
{
struct mib_list_node *if_node = NULL;
snmp_mib_node_insert(&exEntry_root, exEntry_root.count + 1, &if_node);
snmp_mib_node_insert(&exEntry_root, exEntry_root.count + 1, &if_node);
/* enable getnext traversal on filled table */
exTable.maxlength = 1;
}
_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users