fix several bugs in the source routing table
@@ -115,9 +115,11 @@ uip_sr_expire_parent(void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t
uip_sr_node_t *l = uip_sr_get_node(graph, child);
/* Check if parent matches */
if(l != NULL && node_matches_address(graph, l->parent, parent)) {
+ if(l->lifetime > UIP_SR_REMOVAL_DELAY) {
l->lifetime = UIP_SR_REMOVAL_DELAY;
}
}
+}
/*---------------------------------------------------------------------------*/
uip_sr_node_t *
uip_sr_update_node(void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32_t lifetime)
@@ -213,11 +215,15 @@ uip_sr_periodic(unsigned seconds)
next = list_item_next(l);
if(l->lifetime == 0) {
uip_sr_node_t *l2;
+ int can_be_removed = 1;
for(l2 = list_head(nodelist); l2 != NULL; l2 = list_item_next(l2)) {
if(l2->parent == l) {
+ can_be_removed = 0;
break;
}
}
+ if(can_be_removed) {
+ /* No child found, deallocate node */
if(LOG_INFO_ENABLED) {
uip_ipaddr_t node_addr;
NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, l);
@@ -225,10 +231,10 @@ uip_sr_periodic(unsigned seconds)
LOG_INFO_6ADDR(&node_addr);
LOG_INFO_("\n");
}
- /* No child found, deallocate node */
list_remove(nodelist, l);
memb_free(&nodememb, l);
num_nodes--;
+ }
} else if(l->lifetime != UIP_SR_INFINITE_LIFETIME) {
l->lifetime = l->lifetime > seconds ? l->lifetime - seconds : 0;
}
