From 68f59113d64775ad5e70871fbf46dd3b6d686ead Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 19 Dec 2012 22:22:14 +0000 Subject: [PATCH] Fix a route lifetime bug There is a bug in the current route purge routine which would result in a route's lifetime getting decremented more than once during the same pass. This commit fixes it The bug is documented here: http://thread.gmane.org/gmane.os.contiki.devel/16209 --- core/net/rpl/rpl.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/core/net/rpl/rpl.c b/core/net/rpl/rpl.c index f7936e553..7d76c3a27 100644 --- a/core/net/rpl/rpl.c +++ b/core/net/rpl/rpl.c @@ -62,14 +62,31 @@ rpl_purge_routes(void) { uip_ds6_route_t *r; + /* First pass, decrement lifetime */ r = uip_ds6_route_list_head(); while(r != NULL) { - if(r->state.lifetime <= 1) { + if(r->state.lifetime >= 1) { + /* + * If a route is at lifetime == 1, set it to 0, scheduling it for + * immediate removal below. This achieves the same as the original code, + * which would delete lifetime <= 1 + */ + r->state.lifetime--; + } + r = list_item_next(r); + } + + /* Second pass, remove dead routes */ + r = uip_ds6_route_list_head(); + + while(r != NULL) { + if(r->state.lifetime < 1) { + /* Routes with lifetime == 1 have only just been decremented from 2 to 1, + * thus we want to keep them. Hence < and not <= */ uip_ds6_route_rm(r); r = uip_ds6_route_list_head(); } else { - r->state.lifetime--; r = list_item_next(r); } }