From 0fb47d0a2d6d6ef2f76b4ce72bc4374c54a68045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Corbal=C3=A1n?= Date: Thu, 26 Nov 2015 00:07:58 +0000 Subject: [PATCH 1/3] Refresh nbr reachable state after received IPv6 unicast message --- core/net/ipv6/uip-ds6-nbr.c | 14 ++++++++++++++ core/net/ipv6/uip-ds6-nbr.h | 11 +++++++++++ core/net/ipv6/uip6.c | 9 +++++++++ 3 files changed, 34 insertions(+) diff --git a/core/net/ipv6/uip-ds6-nbr.c b/core/net/ipv6/uip-ds6-nbr.c index 3ccebddd1..36585d23c 100644 --- a/core/net/ipv6/uip-ds6-nbr.c +++ b/core/net/ipv6/uip-ds6-nbr.c @@ -322,6 +322,20 @@ uip_ds6_neighbor_periodic(void) } } /*---------------------------------------------------------------------------*/ +#if UIP_ND6_SEND_NA +void +uip_ds6_nbr_refresh_reachable_state(const uip_ipaddr_t *ipaddr) +{ + uip_ds6_nbr_t *nbr; + nbr = uip_ds6_nbr_lookup(ipaddr); + if(nbr != NULL) { + nbr->state = NBR_REACHABLE; + nbr->nscount = 0; + stimer_set(&nbr->reachable, UIP_ND6_REACHABLE_TIME / 1000); + } +} +#endif /* UIP_ND6_SEND_NA */ +/*---------------------------------------------------------------------------*/ uip_ds6_nbr_t * uip_ds6_get_least_lifetime_neighbor(void) { diff --git a/core/net/ipv6/uip-ds6-nbr.h b/core/net/ipv6/uip-ds6-nbr.h index 40a17d1e2..251e16c36 100644 --- a/core/net/ipv6/uip-ds6-nbr.h +++ b/core/net/ipv6/uip-ds6-nbr.h @@ -100,6 +100,17 @@ void uip_ds6_link_neighbor_callback(int status, int numtx); void uip_ds6_neighbor_periodic(void); int uip_ds6_nbr_num(void); +#if UIP_ND6_SEND_NA +/** + * \brief Refresh the reachable state of a neighbor. This function + * may be called when a node receives an IPv6 message that confirms the + * reachability of a neighbor. + * \param ipaddr pointer to the IPv6 address whose neighbor reachability state + * should be refreshed. + */ +void uip_ds6_nbr_refresh_reachable_state(const uip_ipaddr_t *ipaddr); +#endif /* UIP_ND6_SEND_NA */ + /** * \brief * This searches inside the neighbor table for the neighbor that is about to diff --git a/core/net/ipv6/uip6.c b/core/net/ipv6/uip6.c index a54754371..88df55340 100644 --- a/core/net/ipv6/uip6.c +++ b/core/net/ipv6/uip6.c @@ -84,6 +84,10 @@ #include "rpl/rpl-private.h" #endif +#if UIP_ND6_SEND_NA +#include "net/ipv6/uip-ds6-nbr.h" +#endif /* UIP_ND6_SEND_NA */ + #include /*---------------------------------------------------------------------------*/ @@ -1150,6 +1154,11 @@ uip_process(uint8_t flag) goto drop; } + /* Refresh neighbor state after receiving a unicast message */ +#if UIP_ND6_SEND_NA + uip_ds6_nbr_refresh_reachable_state(&UIP_IP_BUF->srcipaddr); +#endif /* UIP_ND6_SEND_NA */ + #if UIP_CONF_ROUTER /* * Next header field processing. In IPv6, we can have extension headers, From 373e5653e64ef1756a411bbeb4b7a58b4b5278db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Corbal=C3=A1n?= Date: Sun, 12 Jun 2016 16:09:45 +0100 Subject: [PATCH 2/3] uIPv6: Make sure dest address is not multicast before refreshing the state of a neighbor --- core/net/ipv6/uip6.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/net/ipv6/uip6.c b/core/net/ipv6/uip6.c index 88df55340..be43e1a20 100644 --- a/core/net/ipv6/uip6.c +++ b/core/net/ipv6/uip6.c @@ -1156,7 +1156,9 @@ uip_process(uint8_t flag) /* Refresh neighbor state after receiving a unicast message */ #if UIP_ND6_SEND_NA - uip_ds6_nbr_refresh_reachable_state(&UIP_IP_BUF->srcipaddr); + if(!uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) { + uip_ds6_nbr_refresh_reachable_state(&UIP_IP_BUF->srcipaddr); + } #endif /* UIP_ND6_SEND_NA */ #if UIP_CONF_ROUTER From 910f8289753a8abd690cfd2287c2516286b5c1d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Corbal=C3=A1n?= Date: Sun, 12 Jun 2016 16:55:48 +0100 Subject: [PATCH 3/3] Remove unneeded state refresh and set reachable timer upon adding a nbr --- core/net/ipv6/uip-ds6-nbr.c | 8 ++++++-- core/net/ipv6/uip-nd6.c | 22 +++++++++------------- core/net/rpl/rpl-icmp6.c | 8 -------- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/core/net/ipv6/uip-ds6-nbr.c b/core/net/ipv6/uip-ds6-nbr.c index 36585d23c..e51786372 100644 --- a/core/net/ipv6/uip-ds6-nbr.c +++ b/core/net/ipv6/uip-ds6-nbr.c @@ -96,8 +96,12 @@ uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr, uip_packetqueue_new(&nbr->packethandle); #endif /* UIP_CONF_IPV6_QUEUE_PKT */ #if UIP_ND6_SEND_NA - /* timers are set separately, for now we put them in expired state */ - stimer_set(&nbr->reachable, 0); + if(nbr->state == NBR_REACHABLE) { + stimer_set(&nbr->reachable, UIP_ND6_REACHABLE_TIME / 1000); + } else { + /* We set the timer in expired state */ + stimer_set(&nbr->reachable, 0); + } stimer_set(&nbr->sendns, 0); nbr->nscount = 0; #endif /* UIP_ND6_SEND_NA */ diff --git a/core/net/ipv6/uip-nd6.c b/core/net/ipv6/uip-nd6.c index 218507228..f8e804c45 100644 --- a/core/net/ipv6/uip-nd6.c +++ b/core/net/ipv6/uip-nd6.c @@ -522,14 +522,11 @@ na_input(void) goto discard; } - if(is_solicited) { - nbr->state = NBR_REACHABLE; - nbr->nscount = 0; - - /* reachable time is stored in ms */ - stimer_set(&(nbr->reachable), uip_ds6_if.reachable_time / 1000); - - } else { + /* Note: No need to refresh the state of the nbr here. + * It has already been refreshed upon receiving the unicast IPv6 ND packet. + * See: uip_ds6_nbr_refresh_reachable_state() + */ + if(!is_solicited) { nbr->state = NBR_STALE; } nbr->isrouter = is_router; @@ -552,11 +549,10 @@ na_input(void) goto discard; } } - if(is_solicited) { - nbr->state = NBR_REACHABLE; - /* reachable time is stored in ms */ - stimer_set(&(nbr->reachable), uip_ds6_if.reachable_time / 1000); - } + /* Note: No need to refresh the state of the nbr here. + * It has already been refreshed upon receiving the unicast IPv6 ND packet. + * See: uip_ds6_nbr_refresh_reachable_state() + */ } } if(nbr->isrouter && !is_router) { diff --git a/core/net/rpl/rpl-icmp6.c b/core/net/rpl/rpl-icmp6.c index 9ffc61dea..9b4566cc4 100644 --- a/core/net/rpl/rpl-icmp6.c +++ b/core/net/rpl/rpl-icmp6.c @@ -201,14 +201,6 @@ rpl_icmp6_update_nbr_table(uip_ipaddr_t *from, nbr_table_reason_t reason, void * } } - if(nbr != NULL) { -#if UIP_ND6_SEND_NA - /* set reachable timer if we added or found the nbr entry - and update - neighbor entry to reachable to avoid sending NS/NA, etc. */ - stimer_set(&nbr->reachable, UIP_ND6_REACHABLE_TIME / 1000); - nbr->state = NBR_REACHABLE; -#endif /* UIP_ND6_SEND_NA */ - } return nbr; } /*---------------------------------------------------------------------------*/