mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2025-08-03 21:14:40 +08:00
snmp: fixed ugly inheritance implementation by aggregating the "base class" (struct mib_node) in all derived node classes to get more type-safe code
This commit is contained in:
parent
59002d5081
commit
7962b21c00
File diff suppressed because it is too large
Load Diff
@ -183,12 +183,12 @@ snmp_mib_lrn_alloc(void)
|
|||||||
lrn = (struct mib_list_rootnode*)memp_malloc(MEMP_SNMP_ROOTNODE);
|
lrn = (struct mib_list_rootnode*)memp_malloc(MEMP_SNMP_ROOTNODE);
|
||||||
if (lrn != NULL)
|
if (lrn != NULL)
|
||||||
{
|
{
|
||||||
lrn->get_object_def = noleafs_get_object_def;
|
lrn->node.get_object_def = noleafs_get_object_def;
|
||||||
lrn->get_value = noleafs_get_value;
|
lrn->node.get_value = noleafs_get_value;
|
||||||
lrn->set_test = noleafs_set_test;
|
lrn->node.set_test = noleafs_set_test;
|
||||||
lrn->set_value = noleafs_set_value;
|
lrn->node.set_value = noleafs_set_value;
|
||||||
lrn->node_type = MIB_NODE_LR;
|
lrn->node.node_type = MIB_NODE_LR;
|
||||||
lrn->maxlength = 0;
|
lrn->node.maxlength = 0;
|
||||||
lrn->head = NULL;
|
lrn->head = NULL;
|
||||||
lrn->tail = NULL;
|
lrn->tail = NULL;
|
||||||
lrn->count = 0;
|
lrn->count = 0;
|
||||||
@ -469,11 +469,11 @@ snmp_search_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru
|
|||||||
/* array node (internal ROM or RAM, fixed length) */
|
/* array node (internal ROM or RAM, fixed length) */
|
||||||
an = (const struct mib_array_node *)node;
|
an = (const struct mib_array_node *)node;
|
||||||
i = 0;
|
i = 0;
|
||||||
while ((i < an->maxlength) && (an->objid[i] != *ident))
|
while ((i < an->node.maxlength) && (an->objid[i] != *ident))
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (i < an->maxlength)
|
if (i < an->node.maxlength)
|
||||||
{
|
{
|
||||||
/* found it, if available proceed to child, otherwise inspect leaf */
|
/* found it, if available proceed to child, otherwise inspect leaf */
|
||||||
LWIP_DEBUGF(SNMP_MIB_DEBUG,("an->objid[%"U16_F"]==%"S32_F" *ident==%"S32_F"\n",i,an->objid[i],*ident));
|
LWIP_DEBUGF(SNMP_MIB_DEBUG,("an->objid[%"U16_F"]==%"S32_F" *ident==%"S32_F"\n",i,an->objid[i],*ident));
|
||||||
@ -483,7 +483,7 @@ snmp_search_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru
|
|||||||
inspect remaining instance number / table index */
|
inspect remaining instance number / table index */
|
||||||
np->ident_len = ident_len;
|
np->ident_len = ident_len;
|
||||||
np->ident = ident;
|
np->ident = ident;
|
||||||
return (const struct mib_node*)an;
|
return &an->node;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -530,7 +530,7 @@ snmp_search_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru
|
|||||||
{
|
{
|
||||||
np->ident_len = ident_len;
|
np->ident_len = ident_len;
|
||||||
np->ident = ident;
|
np->ident = ident;
|
||||||
return (const struct mib_node*)lrn;
|
return &lrn->node;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -580,7 +580,7 @@ snmp_search_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru
|
|||||||
{
|
{
|
||||||
np->ident_len = ident_len;
|
np->ident_len = ident_len;
|
||||||
np->ident = ident;
|
np->ident = ident;
|
||||||
return (const struct mib_node*)en;
|
return &en->node;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -606,14 +606,12 @@ snmp_search_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru
|
|||||||
}
|
}
|
||||||
else if (node_type == MIB_NODE_SC)
|
else if (node_type == MIB_NODE_SC)
|
||||||
{
|
{
|
||||||
const mib_scalar_node *sn;
|
/* scalar node */
|
||||||
|
|
||||||
sn = (const mib_scalar_node *)node;
|
|
||||||
if ((ident_len == 1) && (*ident == 0))
|
if ((ident_len == 1) && (*ident == 0))
|
||||||
{
|
{
|
||||||
np->ident_len = ident_len;
|
np->ident_len = ident_len;
|
||||||
np->ident = ident;
|
np->ident = ident;
|
||||||
return (const struct mib_node*)sn;
|
return node;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -659,7 +657,7 @@ empty_table(const struct mib_node *node)
|
|||||||
{
|
{
|
||||||
const struct mib_array_node *an;
|
const struct mib_array_node *an;
|
||||||
an = (const struct mib_array_node *)node;
|
an = (const struct mib_array_node *)node;
|
||||||
if ((an->maxlength == 0) || (an->nptr == NULL))
|
if ((an->node.maxlength == 0) || (an->nptr == NULL))
|
||||||
{
|
{
|
||||||
empty = 1;
|
empty = 1;
|
||||||
}
|
}
|
||||||
@ -702,11 +700,11 @@ snmp_expand_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru
|
|||||||
if (ident_len > 0)
|
if (ident_len > 0)
|
||||||
{
|
{
|
||||||
i = 0;
|
i = 0;
|
||||||
while ((i < an->maxlength) && (an->objid[i] < *ident))
|
while ((i < an->node.maxlength) && (an->objid[i] < *ident))
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (i < an->maxlength)
|
if (i < an->node.maxlength)
|
||||||
{
|
{
|
||||||
LWIP_DEBUGF(SNMP_MIB_DEBUG,("an->objid[%"U16_F"]==%"S32_F" *ident==%"S32_F"\n",i,an->objid[i],*ident));
|
LWIP_DEBUGF(SNMP_MIB_DEBUG,("an->objid[%"U16_F"]==%"S32_F" *ident==%"S32_F"\n",i,an->objid[i],*ident));
|
||||||
/* add identifier to oidret */
|
/* add identifier to oidret */
|
||||||
@ -719,15 +717,15 @@ snmp_expand_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru
|
|||||||
/* leaf node (e.g. in a fixed size table) */
|
/* leaf node (e.g. in a fixed size table) */
|
||||||
if (an->objid[i] > *ident)
|
if (an->objid[i] > *ident)
|
||||||
{
|
{
|
||||||
return (const struct mib_node*)an;
|
return &an->node;
|
||||||
}
|
}
|
||||||
else if ((i + 1) < an->maxlength)
|
else if ((i + 1) < an->node.maxlength)
|
||||||
{
|
{
|
||||||
/* an->objid[i] == *ident */
|
/* an->objid[i] == *ident */
|
||||||
(oidret->len)--;
|
(oidret->len)--;
|
||||||
oidret->id[oidret->len] = an->objid[i + 1];
|
oidret->id[oidret->len] = an->objid[i + 1];
|
||||||
(oidret->len)++;
|
(oidret->len)++;
|
||||||
return (const struct mib_node*)an;
|
return &an->node;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -744,11 +742,11 @@ snmp_expand_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru
|
|||||||
/* non-leaf, store right child ptr and id */
|
/* non-leaf, store right child ptr and id */
|
||||||
LWIP_ASSERT("i < 0xff", i < 0xff);
|
LWIP_ASSERT("i < 0xff", i < 0xff);
|
||||||
j = i + 1;
|
j = i + 1;
|
||||||
while ((j < an->maxlength) && (empty_table(an->nptr[j])))
|
while ((j < an->node.maxlength) && (empty_table(an->nptr[j])))
|
||||||
{
|
{
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
if (j < an->maxlength)
|
if (j < an->node.maxlength)
|
||||||
{
|
{
|
||||||
struct nse cur_node;
|
struct nse cur_node;
|
||||||
cur_node.r_ptr = an->nptr[j];
|
cur_node.r_ptr = an->nptr[j];
|
||||||
@ -785,11 +783,11 @@ snmp_expand_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru
|
|||||||
u16_t j;
|
u16_t j;
|
||||||
/* ident_len == 0, complete with leftmost '.thing' */
|
/* ident_len == 0, complete with leftmost '.thing' */
|
||||||
j = 0;
|
j = 0;
|
||||||
while ((j < an->maxlength) && empty_table(an->nptr[j]))
|
while ((j < an->node.maxlength) && empty_table(an->nptr[j]))
|
||||||
{
|
{
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
if (j < an->maxlength)
|
if (j < an->node.maxlength)
|
||||||
{
|
{
|
||||||
LWIP_DEBUGF(SNMP_MIB_DEBUG,("left an->objid[j]==%"S32_F"\n",an->objid[j]));
|
LWIP_DEBUGF(SNMP_MIB_DEBUG,("left an->objid[j]==%"S32_F"\n",an->objid[j]));
|
||||||
oidret->id[oidret->len] = an->objid[j];
|
oidret->id[oidret->len] = an->objid[j];
|
||||||
@ -797,7 +795,7 @@ snmp_expand_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru
|
|||||||
if (an->nptr[j] == NULL)
|
if (an->nptr[j] == NULL)
|
||||||
{
|
{
|
||||||
/* leaf node */
|
/* leaf node */
|
||||||
return (const struct mib_node*)an;
|
return &an->node;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -837,7 +835,7 @@ snmp_expand_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru
|
|||||||
/* leaf node */
|
/* leaf node */
|
||||||
if (ln->objid > *ident)
|
if (ln->objid > *ident)
|
||||||
{
|
{
|
||||||
return (const struct mib_node*)lrn;
|
return &lrn->node;
|
||||||
}
|
}
|
||||||
else if (ln->next != NULL)
|
else if (ln->next != NULL)
|
||||||
{
|
{
|
||||||
@ -845,7 +843,7 @@ snmp_expand_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru
|
|||||||
(oidret->len)--;
|
(oidret->len)--;
|
||||||
oidret->id[oidret->len] = ln->next->objid;
|
oidret->id[oidret->len] = ln->next->objid;
|
||||||
(oidret->len)++;
|
(oidret->len)++;
|
||||||
return (const struct mib_node*)lrn;
|
return &lrn->node;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -915,7 +913,7 @@ snmp_expand_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru
|
|||||||
{
|
{
|
||||||
/* leaf node */
|
/* leaf node */
|
||||||
LWIP_DEBUGF(SNMP_MIB_DEBUG,("jn->nptr == NULL\n"));
|
LWIP_DEBUGF(SNMP_MIB_DEBUG,("jn->nptr == NULL\n"));
|
||||||
return (const struct mib_node*)lrn;
|
return &lrn->node;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -961,7 +959,7 @@ snmp_expand_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru
|
|||||||
/* leaf node */
|
/* leaf node */
|
||||||
if (ex_id > *ident)
|
if (ex_id > *ident)
|
||||||
{
|
{
|
||||||
return (const struct mib_node*)en;
|
return &en->node;
|
||||||
}
|
}
|
||||||
else if ((i + 1) < len)
|
else if ((i + 1) < len)
|
||||||
{
|
{
|
||||||
@ -970,7 +968,7 @@ snmp_expand_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru
|
|||||||
(oidret->len)--;
|
(oidret->len)--;
|
||||||
oidret->id[oidret->len] = ex_id;
|
oidret->id[oidret->len] = ex_id;
|
||||||
(oidret->len)++;
|
(oidret->len)++;
|
||||||
return (const struct mib_node*)en;
|
return &en->node;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1031,7 +1029,7 @@ snmp_expand_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru
|
|||||||
{
|
{
|
||||||
/* leaf node */
|
/* leaf node */
|
||||||
LWIP_DEBUGF(SNMP_MIB_DEBUG,("(ext_level + 1) == en->tree_levels\n"));
|
LWIP_DEBUGF(SNMP_MIB_DEBUG,("(ext_level + 1) == en->tree_levels\n"));
|
||||||
return (const struct mib_node*)en;
|
return &en->node;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1042,10 +1040,7 @@ snmp_expand_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru
|
|||||||
}
|
}
|
||||||
else if(node_type == MIB_NODE_SC)
|
else if(node_type == MIB_NODE_SC)
|
||||||
{
|
{
|
||||||
const mib_scalar_node *sn;
|
|
||||||
|
|
||||||
/* scalar node */
|
/* scalar node */
|
||||||
sn = (const mib_scalar_node *)node;
|
|
||||||
if (ident_len > 0)
|
if (ident_len > 0)
|
||||||
{
|
{
|
||||||
/* at .0 */
|
/* at .0 */
|
||||||
@ -1058,7 +1053,7 @@ snmp_expand_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru
|
|||||||
(oidret->len)++;
|
(oidret->len)++;
|
||||||
/* leaf node */
|
/* leaf node */
|
||||||
LWIP_DEBUGF(SNMP_MIB_DEBUG,("completed scalar leaf\n"));
|
LWIP_DEBUGF(SNMP_MIB_DEBUG,("completed scalar leaf\n"));
|
||||||
return (const struct mib_node*)sn;
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -128,13 +128,7 @@ typedef struct mib_node mib_scalar_node;
|
|||||||
struct mib_array_node
|
struct mib_array_node
|
||||||
{
|
{
|
||||||
/* inherited "base class" members */
|
/* inherited "base class" members */
|
||||||
void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
|
struct mib_node node;
|
||||||
void (*get_value)(struct obj_def *od, u16_t len, void *value);
|
|
||||||
u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
|
|
||||||
void (*set_value)(struct obj_def *od, u16_t len, void *value);
|
|
||||||
|
|
||||||
u8_t node_type;
|
|
||||||
u16_t maxlength;
|
|
||||||
|
|
||||||
/* additional struct members */
|
/* additional struct members */
|
||||||
const s32_t *objid;
|
const s32_t *objid;
|
||||||
@ -146,13 +140,7 @@ struct mib_array_node
|
|||||||
struct mib_ram_array_node
|
struct mib_ram_array_node
|
||||||
{
|
{
|
||||||
/* inherited "base class" members */
|
/* inherited "base class" members */
|
||||||
void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
|
struct mib_node node;
|
||||||
void (*get_value)(struct obj_def *od, u16_t len, void *value);
|
|
||||||
u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
|
|
||||||
void (*set_value)(struct obj_def *od, u16_t len, void *value);
|
|
||||||
|
|
||||||
u8_t node_type;
|
|
||||||
u16_t maxlength;
|
|
||||||
|
|
||||||
/* aditional struct members */
|
/* aditional struct members */
|
||||||
s32_t *objid;
|
s32_t *objid;
|
||||||
@ -172,13 +160,7 @@ struct mib_list_node
|
|||||||
struct mib_list_rootnode
|
struct mib_list_rootnode
|
||||||
{
|
{
|
||||||
/* inherited "base class" members */
|
/* inherited "base class" members */
|
||||||
void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
|
struct mib_node node;
|
||||||
void (*get_value)(struct obj_def *od, u16_t len, void *value);
|
|
||||||
u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
|
|
||||||
void (*set_value)(struct obj_def *od, u16_t len, void *value);
|
|
||||||
|
|
||||||
u8_t node_type;
|
|
||||||
u16_t maxlength;
|
|
||||||
|
|
||||||
/* additional struct members */
|
/* additional struct members */
|
||||||
struct mib_list_node *head;
|
struct mib_list_node *head;
|
||||||
@ -192,13 +174,7 @@ struct mib_list_rootnode
|
|||||||
struct mib_external_node
|
struct mib_external_node
|
||||||
{
|
{
|
||||||
/* inherited "base class" members */
|
/* inherited "base class" members */
|
||||||
void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
|
struct mib_node node;
|
||||||
void (*get_value)(struct obj_def *od, u16_t len, void *value);
|
|
||||||
u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
|
|
||||||
void (*set_value)(struct obj_def *od, u16_t len, void *value);
|
|
||||||
|
|
||||||
u8_t node_type;
|
|
||||||
u16_t maxlength;
|
|
||||||
|
|
||||||
/* additional struct members */
|
/* additional struct members */
|
||||||
/** points to an external (in memory) record of some sort of addressing
|
/** points to an external (in memory) record of some sort of addressing
|
||||||
|
Loading…
x
Reference in New Issue
Block a user