From a5039634d537ad2d6394c85a824797718ad634d2 Mon Sep 17 00:00:00 2001 From: Joakim Eriksson Date: Fri, 17 Nov 2017 16:36:17 +0100 Subject: [PATCH] fixed rpl-classic bug and moved the two lifetime loops into one --- os/net/rpl-classic/rpl-ns.c | 13 +++++-------- os/net/rpl-lite/rpl-ns.c | 8 +------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/os/net/rpl-classic/rpl-ns.c b/os/net/rpl-classic/rpl-ns.c index b3da4c8a5..dc2eb23e4 100644 --- a/os/net/rpl-classic/rpl-ns.c +++ b/os/net/rpl-classic/rpl-ns.c @@ -203,9 +203,11 @@ void rpl_ns_periodic(void) { rpl_ns_node_t *l; + rpl_ns_node_t *next; /* First pass, for all expired nodes, deallocate them iff no child points to them */ - for(l = list_head(nodelist); l != NULL; l = list_item_next(l)) { + for(l = list_head(nodelist); l != NULL; l = next) { + next = list_item_next(l); if(l->lifetime == 0) { rpl_ns_node_t *l2; for(l2 = list_head(nodelist); l2 != NULL; l2 = list_item_next(l2)) { @@ -217,13 +219,8 @@ rpl_ns_periodic(void) list_remove(nodelist, l); memb_free(&nodememb, l); num_nodes--; - } - } - - /* Second pass, decrement lifetime for all nodes with non-infinite lifetime */ - for(l = list_head(nodelist); l != NULL; l = list_item_next(l)) { - /* Don't touch infinite lifetime nodes */ - if(l->lifetime != 0xffffffff && l->lifetime > 0) { + } else if(l->lifetime != 0xffffffff) { + /* Decrement lifetime for all nodes with non-infinite lifetime */ l->lifetime--; } } diff --git a/os/net/rpl-lite/rpl-ns.c b/os/net/rpl-lite/rpl-ns.c index 04fea3a82..0b31484b8 100644 --- a/os/net/rpl-lite/rpl-ns.c +++ b/os/net/rpl-lite/rpl-ns.c @@ -229,13 +229,7 @@ rpl_ns_periodic(unsigned seconds) list_remove(nodelist, l); memb_free(&nodememb, l); num_nodes--; - } - } - - /* Second pass, decrement lifetime for all nodes with non-infinite lifetime */ - for(l = list_head(nodelist); l != NULL; l = list_item_next(l)) { - /* Don't touch infinite lifetime nodes */ - if(l->lifetime != RPL_ROUTE_INFINITE_LIFETIME) { + } else if(l->lifetime != RPL_ROUTE_INFINITE_LIFETIME) { l->lifetime = l->lifetime > seconds ? l->lifetime - seconds : 0; } }