mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-08-09 17:13:49 +08:00
Changed index structs to mib_list_node structs to place the table index trees directly in the mib tree.
This commit is contained in:
@@ -48,7 +48,6 @@
|
||||
|
||||
struct netif *netif_list = NULL;
|
||||
struct netif *netif_default = NULL;
|
||||
u16_t netif_cnt = 0;
|
||||
|
||||
/**
|
||||
* Add a network interface to the list of lwIP netifs.
|
||||
@@ -92,7 +91,8 @@ netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
|
||||
/* add this netif to the list */
|
||||
netif->next = netif_list;
|
||||
netif_list = netif;
|
||||
netif_cnt++;
|
||||
snmp_inc_iflist();
|
||||
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("netif: added interface %c%c IP addr ",
|
||||
netif->name[0], netif->name[1]));
|
||||
ip_addr_debug_print(NETIF_DEBUG, ipaddr);
|
||||
@@ -117,10 +117,12 @@ void netif_remove(struct netif * netif)
|
||||
{
|
||||
if ( netif == NULL ) return;
|
||||
|
||||
snmp_delete_ipaddridx_tree(netif);
|
||||
|
||||
/* is it the first netif? */
|
||||
if (netif_list == netif) {
|
||||
netif_list = netif->next;
|
||||
netif_cnt--;
|
||||
snmp_dec_iflist();
|
||||
}
|
||||
else {
|
||||
/* look for netif further down the list */
|
||||
@@ -128,7 +130,7 @@ void netif_remove(struct netif * netif)
|
||||
for (tmpNetif = netif_list; tmpNetif != NULL; tmpNetif = tmpNetif->next) {
|
||||
if (tmpNetif->next == netif) {
|
||||
tmpNetif->next = netif->next;
|
||||
netif_cnt--;
|
||||
snmp_dec_iflist();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -203,7 +205,13 @@ netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
snmp_delete_ipaddridx_tree(netif);
|
||||
snmp_delete_iprteidx_tree(0,netif);
|
||||
/* set new IP address to netif */
|
||||
ip_addr_set(&(netif->ip_addr), ipaddr);
|
||||
snmp_insert_ipaddridx_tree(netif);
|
||||
snmp_insert_iprteidx_tree(0,netif);
|
||||
|
||||
#if 0 /* only allowed for Ethernet interfaces TODO: how can we check? */
|
||||
/** For Ethernet network interfaces, we would like to send a
|
||||
* "gratuitous ARP"; this is an ARP packet sent by a node in order
|
||||
@@ -235,7 +243,10 @@ netif_set_gw(struct netif *netif, struct ip_addr *gw)
|
||||
void
|
||||
netif_set_netmask(struct netif *netif, struct ip_addr *netmask)
|
||||
{
|
||||
snmp_delete_iprteidx_tree(0, netif);
|
||||
/* set new netmask to netif */
|
||||
ip_addr_set(&(netif->netmask), netmask);
|
||||
snmp_insert_iprteidx_tree(0, netif);
|
||||
LWIP_DEBUGF(NETIF_DEBUG | DBG_TRACE | DBG_STATE | 3, ("netif: netmask of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
|
||||
netif->name[0], netif->name[1],
|
||||
ip4_addr1(&netif->netmask),
|
||||
@@ -247,6 +258,16 @@ netif_set_netmask(struct netif *netif, struct ip_addr *netmask)
|
||||
void
|
||||
netif_set_default(struct netif *netif)
|
||||
{
|
||||
if (netif == NULL)
|
||||
{
|
||||
/* remove default route */
|
||||
snmp_delete_iprteidx_tree(1, netif);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* install default route */
|
||||
snmp_insert_iprteidx_tree(1, netif);
|
||||
}
|
||||
netif_default = netif;
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("netif: setting default interface %c%c\n",
|
||||
netif ? netif->name[0] : '\'', netif ? netif->name[1] : '\''));
|
||||
@@ -297,6 +318,5 @@ void
|
||||
netif_init(void)
|
||||
{
|
||||
netif_list = netif_default = NULL;
|
||||
netif_cnt = 0;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -158,47 +158,51 @@ snmp_iptooid(struct ip_addr *ip, s32_t *ident)
|
||||
ident[3] = trnc & 0xff;
|
||||
}
|
||||
|
||||
struct idx_node *
|
||||
snmp_idx_node_alloc(s32_t id)
|
||||
struct mib_list_node *
|
||||
snmp_mib_ln_alloc(s32_t id)
|
||||
{
|
||||
struct idx_node *in;
|
||||
struct mib_list_node *ln;
|
||||
|
||||
in = (struct idx_node*)mem_malloc(sizeof(struct idx_node));
|
||||
if (in != NULL)
|
||||
ln = (struct mib_list_node *)mem_malloc(sizeof(struct mib_list_node));
|
||||
if (ln != NULL)
|
||||
{
|
||||
in->next = NULL;
|
||||
in->prev = NULL;
|
||||
in->objid = id;
|
||||
in->nptr = NULL;
|
||||
ln->prev = NULL;
|
||||
ln->next = NULL;
|
||||
ln->objid = id;
|
||||
ln->nptr = NULL;
|
||||
}
|
||||
return in;
|
||||
return ln;
|
||||
}
|
||||
|
||||
void
|
||||
snmp_idx_node_free(struct idx_node *in)
|
||||
snmp_mib_ln_free(struct mib_list_node *ln)
|
||||
{
|
||||
mem_free(in);
|
||||
mem_free(ln);
|
||||
}
|
||||
|
||||
struct idx_root_node *
|
||||
snmp_idx_root_node_alloc(void)
|
||||
struct mib_list_rootnode *
|
||||
snmp_mib_lrn_alloc(void)
|
||||
{
|
||||
struct idx_root_node *irn;
|
||||
struct mib_list_rootnode *lrn;
|
||||
|
||||
irn = (struct idx_root_node*)mem_malloc(sizeof(struct idx_root_node));
|
||||
if (irn != NULL)
|
||||
lrn = (struct mib_list_rootnode*)mem_malloc(sizeof(struct mib_list_rootnode));
|
||||
if (lrn != NULL)
|
||||
{
|
||||
irn->head = NULL;
|
||||
irn->tail = NULL;
|
||||
irn->count = 0;
|
||||
lrn->get_object_def = noleafs_get_object_def;
|
||||
lrn->get_value = noleafs_get_value;
|
||||
lrn->node_type = MIB_NODE_LR;
|
||||
lrn->maxlength = 0;
|
||||
lrn->head = NULL;
|
||||
lrn->tail = NULL;
|
||||
lrn->count = 0;
|
||||
}
|
||||
return irn;
|
||||
return lrn;
|
||||
}
|
||||
|
||||
void
|
||||
snmp_idx_root_node_free(struct idx_root_node *irn)
|
||||
snmp_mib_lrn_free(struct mib_list_rootnode *lrn)
|
||||
{
|
||||
mem_free(irn);
|
||||
mem_free(lrn);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -213,9 +217,9 @@ snmp_idx_root_node_free(struct idx_root_node *irn)
|
||||
* @return -1 if failed, 1 if success.
|
||||
*/
|
||||
s8_t
|
||||
snmp_idx_node_insert(struct idx_root_node *rn, s32_t objid, struct idx_node **insn)
|
||||
snmp_mib_node_insert(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_node **insn)
|
||||
{
|
||||
struct idx_node *nn;
|
||||
struct mib_list_node *nn;
|
||||
s8_t insert;
|
||||
|
||||
LWIP_ASSERT("rn != NULL",rn != NULL);
|
||||
@@ -226,7 +230,7 @@ snmp_idx_node_insert(struct idx_root_node *rn, s32_t objid, struct idx_node **in
|
||||
{
|
||||
/* empty list, add first node */
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG,("alloc empty list objid==%"S32_F"\n",objid));
|
||||
nn = snmp_idx_node_alloc(objid);
|
||||
nn = snmp_mib_ln_alloc(objid);
|
||||
if (nn != NULL)
|
||||
{
|
||||
rn->head = nn;
|
||||
@@ -241,7 +245,7 @@ snmp_idx_node_insert(struct idx_root_node *rn, s32_t objid, struct idx_node **in
|
||||
}
|
||||
else
|
||||
{
|
||||
struct idx_node *n;
|
||||
struct mib_list_node *n;
|
||||
/* at least one node is present */
|
||||
n = rn->head;
|
||||
while ((n != NULL) && (insert == 0))
|
||||
@@ -259,7 +263,7 @@ snmp_idx_node_insert(struct idx_root_node *rn, s32_t objid, struct idx_node **in
|
||||
{
|
||||
/* alloc and insert at the tail */
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG,("alloc ins tail objid==%"S32_F"\n",objid));
|
||||
nn = snmp_idx_node_alloc(objid);
|
||||
nn = snmp_mib_ln_alloc(objid);
|
||||
if (nn != NULL)
|
||||
{
|
||||
nn->next = NULL;
|
||||
@@ -287,7 +291,7 @@ snmp_idx_node_insert(struct idx_root_node *rn, s32_t objid, struct idx_node **in
|
||||
/* n->objid > objid */
|
||||
/* alloc and insert between n->prev and n */
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG,("alloc ins n->prev, objid==%"S32_F", n\n",objid));
|
||||
nn = snmp_idx_node_alloc(objid);
|
||||
nn = snmp_mib_ln_alloc(objid);
|
||||
if (nn != NULL)
|
||||
{
|
||||
if (n->prev == NULL)
|
||||
@@ -332,13 +336,13 @@ snmp_idx_node_insert(struct idx_root_node *rn, s32_t objid, struct idx_node **in
|
||||
* @param objid is the object sub identifier
|
||||
* @param fn returns pointer to found node
|
||||
* @return 0 if not found, 1 if deletable,
|
||||
* 2 can't delete (2 or more children)
|
||||
* 2 can't delete (2 or more children), 3 not a list_node
|
||||
*/
|
||||
s8_t
|
||||
snmp_idx_node_find(struct idx_root_node *rn, s32_t objid, struct idx_node **fn)
|
||||
snmp_mib_node_find(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_node **fn)
|
||||
{
|
||||
s8_t fc;
|
||||
struct idx_node *n;
|
||||
struct mib_list_node *n;
|
||||
|
||||
LWIP_ASSERT("rn != NULL",rn != NULL);
|
||||
n = rn->head;
|
||||
@@ -355,15 +359,29 @@ snmp_idx_node_find(struct idx_root_node *rn, s32_t objid, struct idx_node **fn)
|
||||
/* leaf, can delete node */
|
||||
fc = 1;
|
||||
}
|
||||
else if (n->nptr->count > 1)
|
||||
{
|
||||
/* can't delete node */
|
||||
fc = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* count <= 1, can delete node */
|
||||
fc = 1;
|
||||
struct mib_list_rootnode *rn;
|
||||
|
||||
if (n->nptr->node_type == MIB_NODE_LR)
|
||||
{
|
||||
rn = (struct mib_list_rootnode *)n->nptr;
|
||||
if (rn->count > 1)
|
||||
{
|
||||
/* can't delete node */
|
||||
fc = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* count <= 1, can delete node */
|
||||
fc = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* other node type */
|
||||
fc = 3;
|
||||
}
|
||||
}
|
||||
*fn = n;
|
||||
return fc;
|
||||
@@ -377,16 +395,16 @@ snmp_idx_node_find(struct idx_root_node *rn, s32_t objid, struct idx_node **fn)
|
||||
* @param n points to the node to delete
|
||||
* @return the nptr to be freed by caller
|
||||
*/
|
||||
struct idx_root_node *
|
||||
snmp_idx_node_delete(struct idx_root_node *rn, struct idx_node *n)
|
||||
struct mib_list_rootnode *
|
||||
snmp_mib_node_delete(struct mib_list_rootnode *rn, struct mib_list_node *n)
|
||||
{
|
||||
struct idx_root_node *next;
|
||||
struct mib_list_rootnode *next;
|
||||
|
||||
LWIP_ASSERT("rn != NULL",rn != NULL);
|
||||
LWIP_ASSERT("n != NULL",n != NULL);
|
||||
|
||||
/* caller must remove this sub-tree */
|
||||
next = n->nptr;
|
||||
next = (struct mib_list_rootnode*)(n->nptr);
|
||||
rn->count -= 1;
|
||||
|
||||
if (n == rn->head)
|
||||
@@ -414,7 +432,7 @@ snmp_idx_node_delete(struct idx_root_node *rn, struct idx_node *n)
|
||||
n->next->prev = n->prev;
|
||||
}
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG,("free list objid==%"S32_F"\n",n->objid));
|
||||
snmp_idx_node_free(n);
|
||||
snmp_mib_ln_free(n);
|
||||
|
||||
return next;
|
||||
}
|
||||
@@ -754,6 +772,10 @@ snmp_expand_tree(struct mib_node *node, u8_t ident_len, s32_t *ident, struct snm
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(node_type == MIB_NODE_LR)
|
||||
{
|
||||
/** @todo need this for indexing tables */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* unknown/unhandled node_type */
|
||||
|
||||
@@ -489,6 +489,7 @@ udp_bind(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
|
||||
}
|
||||
}
|
||||
pcb->local_port = port;
|
||||
snmp_insert_udpidx_tree(pcb);
|
||||
/* pcb not active yet? */
|
||||
if (rebind == 0) {
|
||||
/* place the PCB on the active list if not already there */
|
||||
@@ -602,6 +603,8 @@ void
|
||||
udp_remove(struct udp_pcb *pcb)
|
||||
{
|
||||
struct udp_pcb *pcb2;
|
||||
|
||||
snmp_delete_udpidx_tree(pcb);
|
||||
/* pcb to be removed is first in list? */
|
||||
if (udp_pcbs == pcb) {
|
||||
/* make list start at 2nd pcb */
|
||||
|
||||
Reference in New Issue
Block a user