44 const s32_t prefix[4] = {1, 3, 6, 1};
46 #define NODE_STACK_SIZE (LWIP_SNMP_OBJ_ID_LEN)
51 struct mib_node* r_ptr;
57 static u8_t node_stack_cnt;
58 static struct nse node_stack[NODE_STACK_SIZE];
64 push_node(
struct nse* node)
66 LWIP_ASSERT(
"node_stack_cnt < NODE_STACK_SIZE",node_stack_cnt < NODE_STACK_SIZE);
68 if (node_stack_cnt < NODE_STACK_SIZE)
70 node_stack[node_stack_cnt] = *node;
79 pop_node(
struct nse* node)
81 if (node_stack_cnt > 0)
84 *node = node_stack[node_stack_cnt];
102 while ((nif !=
NULL) && (i < ifidx))
116 snmp_netiftoifindex(
struct netif *netif,
s32_t *ifidx)
122 while ((nif !=
NULL) && (nif != netif))
138 IP4_ADDR(ip, ident[0], ident[1], ident[2], ident[3]);
155 struct mib_list_node *
156 snmp_mib_ln_alloc(
s32_t id)
158 struct mib_list_node *ln;
160 ln = (
struct mib_list_node *)
memp_malloc(MEMP_SNMP_NODE);
172 snmp_mib_ln_free(
struct mib_list_node *ln)
177 struct mib_list_rootnode *
178 snmp_mib_lrn_alloc(
void)
180 struct mib_list_rootnode *lrn;
182 lrn = (
struct mib_list_rootnode*)
memp_malloc(MEMP_SNMP_ROOTNODE);
185 lrn->get_object_def = noleafs_get_object_def;
186 lrn->get_value = noleafs_get_value;
187 lrn->set_test = noleafs_set_test;
188 lrn->set_value = noleafs_set_value;
189 lrn->node_type = MIB_NODE_LR;
199 snmp_mib_lrn_free(
struct mib_list_rootnode *lrn)
216 snmp_mib_node_insert(
struct mib_list_rootnode *rn,
s32_t objid,
struct mib_list_node **insn)
218 struct mib_list_node *nn;
225 if (rn->head ==
NULL)
229 nn = snmp_mib_ln_alloc(objid);
244 struct mib_list_node *n;
247 while ((n !=
NULL) && (insert == 0))
249 if (n->objid == objid)
256 else if (n->objid < objid)
262 nn = snmp_mib_ln_alloc(objid);
290 nn = snmp_mib_ln_alloc(objid);
338 snmp_mib_node_find(
struct mib_list_rootnode *rn,
s32_t objid,
struct mib_list_node **fn)
341 struct mib_list_node *n;
345 while ((n !=
NULL) && (n->objid != objid))
353 else if (n->nptr ==
NULL)
360 struct mib_list_rootnode *r;
362 if (n->nptr->node_type == MIB_NODE_LR)
364 r = (
struct mib_list_rootnode *)n->nptr;
394 struct mib_list_rootnode *
395 snmp_mib_node_delete(
struct mib_list_rootnode *rn,
struct mib_list_node *n)
397 struct mib_list_rootnode *next;
403 next = (
struct mib_list_rootnode*)(n->nptr);
412 n->next->prev =
NULL;
415 else if (n == rn->tail)
421 n->prev->next =
NULL;
427 n->prev->next = n->next;
428 n->next->prev = n->prev;
452 snmp_search_tree(
struct mib_node *node,
u8_t ident_len,
s32_t *ident,
struct snmp_name_ptr *np)
454 u8_t node_type, ext_level;
460 node_type = node->node_type;
461 if ((node_type == MIB_NODE_AR) || (node_type == MIB_NODE_RA))
463 struct mib_array_node *an;
469 an = (
struct mib_array_node *)node;
471 while ((i < an->maxlength) && (an->objid[i] != *ident))
475 if (i < an->maxlength)
479 if (an->nptr[i] ==
NULL)
483 np->ident_len = ident_len;
485 return (
struct mib_node*)an;
509 else if(node_type == MIB_NODE_LR)
511 struct mib_list_rootnode *lrn;
512 struct mib_list_node *ln;
517 lrn = (
struct mib_list_rootnode *)node;
520 while ((ln !=
NULL) && (ln->objid != *ident))
528 if (ln->nptr ==
NULL)
530 np->ident_len = ident_len;
532 return (
struct mib_node*)lrn;
556 else if(node_type == MIB_NODE_EX)
558 struct mib_external_node *en;
564 en = (
struct mib_external_node *)node;
567 len = en->level_length(en->addr_inf,ext_level);
568 while ((i < len) && (en->ident_cmp(en->addr_inf,ext_level,i,*ident) != 0))
576 en->get_objid(en->addr_inf,ext_level,i,&debug_id);
578 if ((ext_level + 1) == en->tree_levels)
580 np->ident_len = ident_len;
582 return (
struct mib_node*)en;
606 else if (node_type == MIB_NODE_SC)
610 sn = (mib_scalar_node *)node;
611 if ((ident_len == 1) && (*ident == 0))
613 np->ident_len = ident_len;
615 return (
struct mib_node*)sn;
640 empty_table(
struct mib_node *node)
647 node_type = node->node_type;
648 if (node_type == MIB_NODE_LR)
650 struct mib_list_rootnode *lrn;
651 lrn = (
struct mib_list_rootnode *)node;
652 if ((lrn->count == 0) || (lrn->head ==
NULL))
657 else if ((node_type == MIB_NODE_AR) || (node_type == MIB_NODE_RA))
659 struct mib_array_node *an;
660 an = (
struct mib_array_node *)node;
661 if ((an->maxlength == 0) || (an->nptr ==
NULL))
666 else if (node_type == MIB_NODE_EX)
668 struct mib_external_node *en;
669 en = (
struct mib_external_node *)node;
670 if (en->tree_levels == 0)
683 snmp_expand_tree(
struct mib_node *node,
u8_t ident_len,
s32_t *ident,
struct snmp_obj_id *oidret)
685 u8_t node_type, ext_level, climb_tree;
693 node_type = node->node_type;
694 if ((node_type == MIB_NODE_AR) || (node_type == MIB_NODE_RA))
696 struct mib_array_node *an;
700 an = (
struct mib_array_node *)node;
704 while ((i < an->maxlength) && (an->objid[i] < *ident))
708 if (i < an->maxlength)
712 oidret->id[oidret->len] = an->objid[i];
715 if (an->nptr[i] ==
NULL)
719 if (an->objid[i] > *ident)
721 return (
struct mib_node*)an;
723 else if ((i + 1) < an->maxlength)
727 oidret->id[oidret->len] = an->objid[i + 1];
729 return (
struct mib_node*)an;
747 while ((j < an->maxlength) && (empty_table(an->nptr[j])))
751 if (j < an->maxlength)
753 cur_node.r_ptr = an->nptr[j];
754 cur_node.r_id = an->objid[j];
759 cur_node.r_ptr =
NULL;
761 push_node(&cur_node);
762 if (an->objid[i] == *ident)
787 while ((j < an->maxlength) && empty_table(an->nptr[j]))
791 if (j < an->maxlength)
794 oidret->id[oidret->len] = an->objid[j];
796 if (an->nptr[j] ==
NULL)
799 return (
struct mib_node*)an;
814 else if(node_type == MIB_NODE_LR)
816 struct mib_list_rootnode *lrn;
817 struct mib_list_node *ln;
820 lrn = (
struct mib_list_rootnode *)node;
825 while ((ln !=
NULL) && (ln->objid < *ident))
832 oidret->id[oidret->len] = ln->objid;
834 if (ln->nptr ==
NULL)
837 if (ln->objid > *ident)
839 return (
struct mib_node*)lrn;
841 else if (ln->next !=
NULL)
845 oidret->id[oidret->len] = ln->next->objid;
847 return (
struct mib_node*)lrn;
858 struct mib_list_node *
jn;
863 while ((jn !=
NULL) && empty_table(jn->nptr))
869 cur_node.r_ptr = jn->nptr;
870 cur_node.r_id = jn->objid;
875 cur_node.r_ptr =
NULL;
877 push_node(&cur_node);
878 if (ln->objid == *ident)
901 struct mib_list_node *
jn;
904 while ((jn !=
NULL) && empty_table(jn->nptr))
911 oidret->id[oidret->len] = jn->objid;
913 if (jn->nptr ==
NULL)
917 return (
struct mib_node*)lrn;
932 else if(node_type == MIB_NODE_EX)
934 struct mib_external_node *en;
938 en = (
struct mib_external_node *)node;
944 len = en->level_length(en->addr_inf,ext_level);
945 while ((i < len) && (en->ident_cmp(en->addr_inf,ext_level,i,*ident) < 0))
952 en->get_objid(en->addr_inf,ext_level,i,&ex_id);
954 oidret->id[oidret->len] = ex_id;
957 if ((ext_level + 1) == en->tree_levels)
963 return (
struct mib_node*)en;
965 else if ((i + 1) < len)
968 en->get_objid(en->addr_inf,ext_level,i + 1,&ex_id);
970 oidret->id[oidret->len] = ex_id;
972 return (
struct mib_node*)en;
993 cur_node.r_ptr = node;
994 en->get_objid(en->addr_inf,ext_level,j,&cur_node.r_id);
995 cur_node.r_nl = ext_level + 1;
999 cur_node.r_ptr =
NULL;
1001 push_node(&cur_node);
1002 if (en->ident_cmp(en->addr_inf,ext_level,i,*ident) == 0)
1025 en->get_objid(en->addr_inf,ext_level,0,&ex_id);
1027 oidret->id[oidret->len] = ex_id;
1029 if ((ext_level + 1) == en->tree_levels)
1033 return (
struct mib_node*)en;
1042 else if(node_type == MIB_NODE_SC)
1044 mib_scalar_node *sn;
1047 sn = (mib_scalar_node *)node;
1056 oidret->id[oidret->len] = 0;
1060 return (
struct mib_node*)sn;
1078 while ((node_stack_cnt > 0) && (child.r_ptr ==
NULL))
1084 if (child.r_ptr !=
NULL)
1088 oidret->id[oidret->len] = child.r_id;
1091 ext_level = child.r_nl;
1114 snmp_iso_prefix_tst(
u8_t ident_len,
s32_t *ident)
1116 if ((ident_len > 3) &&
1117 (ident[0] == 1) && (ident[1] == 3) &&
1118 (ident[2] == 6) && (ident[3] == 1))
1140 snmp_iso_prefix_expand(
u8_t ident_len,
s32_t *ident,
struct snmp_obj_id *oidret)
1142 const s32_t *prefix_ptr;
1147 prefix_ptr = &prefix[0];
1148 ret_ptr = &oidret->id[0];
1149 ident_len = ((ident_len < 4)?ident_len:4);
1150 while ((i < ident_len) && ((*ident) <= (*prefix_ptr)))
1152 *ret_ptr++ = *prefix_ptr++;
1161 *ret_ptr++ = *prefix_ptr++;