From c9861b0726a8687d554406c7f3f63df80400109c Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Sun, 10 Dec 2017 07:34:16 -0800 Subject: [PATCH] Routing API: added neighbor_state_changed --- os/net/ipv6/uip-ds6-nbr.c | 12 +++--------- os/net/ipv6/uip-ds6.h | 7 ------- os/net/routing/nullrouting/nullrouting.c | 6 ++++++ os/net/routing/routing.h | 9 +++++++++ os/net/routing/rpl-classic/rpl.c | 1 + os/net/routing/rpl-lite/rpl.c | 7 +++++++ 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/os/net/ipv6/uip-ds6-nbr.c b/os/net/ipv6/uip-ds6-nbr.c index 27678a2db..81c12bf96 100644 --- a/os/net/ipv6/uip-ds6-nbr.c +++ b/os/net/ipv6/uip-ds6-nbr.c @@ -53,19 +53,13 @@ #include "net/ipv6/uip-ds6.h" #include "net/ipv6/uip-ds6-nbr.h" #include "net/ipv6/uip-nd6.h" +#include "net/routing/routing.h" /* Log configuration */ #include "sys/log.h" #define LOG_MODULE "IPv6 Nbr" #define LOG_LEVEL LOG_LEVEL_IPV6 -#ifdef UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED -#define NEIGHBOR_STATE_CHANGED(n) UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED(n) -void NEIGHBOR_STATE_CHANGED(uip_ds6_nbr_t *n); -#else -#define NEIGHBOR_STATE_CHANGED(n) -#endif /* UIP_DS6_CONF_NEIGHBOR_STATE_CHANGED */ - NBR_TABLE_GLOBAL(uip_ds6_nbr_t, ds6_neighbors); /*---------------------------------------------------------------------------*/ @@ -107,7 +101,7 @@ uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr, LOG_INFO_(" link addr "); LOG_INFO_LLADDR((linkaddr_t*)lladdr); LOG_INFO_(" state %u\n", state); - NEIGHBOR_STATE_CHANGED(nbr); + NETSTACK_ROUTING.neighbor_state_changed(nbr); return nbr; } else { LOG_INFO("Add drop ip addr "); @@ -127,7 +121,7 @@ uip_ds6_nbr_rm(uip_ds6_nbr_t *nbr) #if UIP_CONF_IPV6_QUEUE_PKT uip_packetqueue_free(&nbr->packethandle); #endif /* UIP_CONF_IPV6_QUEUE_PKT */ - NEIGHBOR_STATE_CHANGED(nbr); + NETSTACK_ROUTING.neighbor_state_changed(nbr); return nbr_table_remove(ds6_neighbors, nbr); } return 0; diff --git a/os/net/ipv6/uip-ds6.h b/os/net/ipv6/uip-ds6.h index 29f9249c3..45394fec3 100644 --- a/os/net/ipv6/uip-ds6.h +++ b/os/net/ipv6/uip-ds6.h @@ -226,13 +226,6 @@ typedef struct uip_ds6_maddr { uip_ipaddr_t ipaddr; } uip_ds6_maddr_t; -/* only define the callback if RPL is active */ -#if UIP_CONF_IPV6_RPL && (UIP_CONF_IPV6_RPL_LITE == 0) -#ifndef UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED -#define UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED rpl_ipv6_neighbor_callback -#endif /* UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED */ -#endif /* UIP_CONF_IPV6_RPL */ - /** \brief Interface structure (contains all the interface variables) */ typedef struct uip_ds6_netif { uint32_t link_mtu; diff --git a/os/net/routing/nullrouting/nullrouting.c b/os/net/routing/nullrouting/nullrouting.c index e341225f9..2d48221e2 100644 --- a/os/net/routing/nullrouting/nullrouting.c +++ b/os/net/routing/nullrouting/nullrouting.c @@ -104,6 +104,11 @@ link_callback(const linkaddr_t *addr, int status, int numtx) } /*---------------------------------------------------------------------------*/ static void +neighbor_state_changed(uip_ds6_nbr_t *nbr) +{ +} +/*---------------------------------------------------------------------------*/ +static void drop_route(uip_ds6_route_t *route) { } @@ -121,6 +126,7 @@ const struct routing_driver nullrouting_driver = { ext_header_srh_update, ext_header_srh_get_next_hop, link_callback, + neighbor_state_changed, drop_route, }; /*---------------------------------------------------------------------------*/ diff --git a/os/net/routing/routing.h b/os/net/routing/routing.h index 330269826..dd10086a0 100644 --- a/os/net/routing/routing.h +++ b/os/net/routing/routing.h @@ -42,6 +42,7 @@ #include "contiki.h" #include "net/ipv6/uip.h" +#include "net/ipv6/uip-ds6-nbr.h" #include "net/ipv6/uip-ds6-route.h" #include "net/linkaddr.h" @@ -118,6 +119,14 @@ struct routing_driver { * \param numtx The total number of transmission attempts */ void (* link_callback)(const linkaddr_t *addr, int status, int numtx); + /** + * Called by uIP to notify addition/removal of IPv6 neighbor entries + * + * \param addr The link-layer addrress of the packet destination + * \param status The transmission status (see os/net/mac/mac.h) + * \param numtx The total number of transmission attempts + */ + void (* neighbor_state_changed)(uip_ds6_nbr_t *nbr); /** * Called by uIP if it has decided to drop a route because * diff --git a/os/net/routing/rpl-classic/rpl.c b/os/net/routing/rpl-classic/rpl.c index a649e247c..5f82cf182 100644 --- a/os/net/routing/rpl-classic/rpl.c +++ b/os/net/routing/rpl-classic/rpl.c @@ -396,6 +396,7 @@ const struct routing_driver rpl_classic_driver = { rpl_ext_header_srh_update, rpl_ext_header_srh_get_next_hop, rpl_link_callback, + rpl_ipv6_neighbor_callback, drop_route, }; /*---------------------------------------------------------------------------*/ diff --git a/os/net/routing/rpl-lite/rpl.c b/os/net/routing/rpl-lite/rpl.c index dc1c123f2..e45c6df42 100644 --- a/os/net/routing/rpl-lite/rpl.c +++ b/os/net/routing/rpl-lite/rpl.c @@ -194,6 +194,12 @@ init(void) } /*---------------------------------------------------------------------------*/ static void +neighbor_state_changed(uip_ds6_nbr_t *nbr) +{ + /* Nothing needs be done in non-storing mode */ +} +/*---------------------------------------------------------------------------*/ +static void drop_route(uip_ds6_route_t *route) { /* Do nothing. RPL-lite only supports non-storing mode, i.e. no routes */ @@ -212,6 +218,7 @@ const struct routing_driver rpl_lite_driver = { rpl_ext_header_srh_update, rpl_ext_header_srh_get_next_hop, rpl_link_callback, + neighbor_state_changed, drop_route, }; /*---------------------------------------------------------------------------*/