From d866e6bd34c6fd207b619134b69ceb835db6533c Mon Sep 17 00:00:00 2001 From: Laurent Deru Date: Thu, 7 Apr 2016 11:40:00 +0200 Subject: [PATCH] Make RPL route lifetime RFC compliant --- core/net/rpl/rpl-private.h | 8 +++++++- core/net/rpl/rpl-timers.c | 2 +- core/net/rpl/rpl.c | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/net/rpl/rpl-private.h b/core/net/rpl/rpl-private.h index bb7af2a04..393e49087 100644 --- a/core/net/rpl/rpl-private.h +++ b/core/net/rpl/rpl-private.h @@ -145,8 +145,14 @@ /* Special value indicating immediate removal. */ #define RPL_ZERO_LIFETIME 0 +/* Special value indicating infinite lifetime. */ +#define RPL_INFINITE_LIFETIME 0xFF + +#define RPL_ROUTE_INFINITE_LIFETIME 0xFFFFFFFF + #define RPL_LIFETIME(instance, lifetime) \ - ((unsigned long)(instance)->lifetime_unit * (lifetime)) + (((lifetime) == RPL_INFINITE_LIFETIME) ? RPL_ROUTE_INFINITE_LIFETIME : (unsigned long)(instance)->lifetime_unit * (lifetime)) + #ifndef RPL_CONF_MIN_HOPRANKINC /* RFC6550 defines the default MIN_HOPRANKINC as 256. diff --git a/core/net/rpl/rpl-timers.c b/core/net/rpl/rpl-timers.c index a9527f6e0..88c98353d 100644 --- a/core/net/rpl/rpl-timers.c +++ b/core/net/rpl/rpl-timers.c @@ -238,7 +238,7 @@ set_dao_lifetime_timer(rpl_instance_t *instance) /* Set up another DAO within half the expiration time, if such a time has been configured */ - if(instance->lifetime_unit != 0xffff && instance->default_lifetime != 0xff) { + if(instance->default_lifetime != RPL_INFINITE_LIFETIME) { clock_time_t expiration_time; expiration_time = (clock_time_t)instance->default_lifetime * (clock_time_t)instance->lifetime_unit * diff --git a/core/net/rpl/rpl.c b/core/net/rpl/rpl.c index 92ea2b309..fc49f0c4a 100644 --- a/core/net/rpl/rpl.c +++ b/core/net/rpl/rpl.c @@ -122,7 +122,7 @@ rpl_purge_routes(void) r = uip_ds6_route_head(); while(r != NULL) { - if(r->state.lifetime >= 1) { + if(r->state.lifetime >= 1 && r->state.lifetime != RPL_ROUTE_INFINITE_LIFETIME) { /* * 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,