From 4ffab13eeb6ab72a21557797c0343df7961a80db Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Sun, 10 Dec 2017 06:55:28 -0800 Subject: [PATCH] Routing API: drop_route --- os/net/ipv6/tcpip.c | 25 +++++------------------- os/net/ipv6/uip-ds6-route.h | 1 - os/net/routing/nullrouting/nullrouting.c | 6 ++++++ os/net/routing/routing.h | 6 ++++++ os/net/routing/rpl-classic/rpl.c | 13 ++++++++++++ os/net/routing/rpl-lite/rpl.c | 7 +++++++ 6 files changed, 37 insertions(+), 21 deletions(-) diff --git a/os/net/ipv6/tcpip.c b/os/net/ipv6/tcpip.c index 903498532..eec3068ad 100644 --- a/os/net/ipv6/tcpip.c +++ b/os/net/ipv6/tcpip.c @@ -476,23 +476,6 @@ output_fallback(void) } /*---------------------------------------------------------------------------*/ static void -drop_route(uip_ds6_route_t *route) -{ -#if UIP_CONF_IPV6_RPL && (UIP_CONF_IPV6_RPL_LITE == 0) - - /* If we are running RPL, and if we are the root of the - network, we'll trigger a global repair before we remove - the route. */ - rpl_dag_t *dag; - dag = (rpl_dag_t *)route->state.dag; - if(dag != NULL && dag->instance != NULL) { - rpl_repair_root(dag->instance->instance_id); - } -#endif /* UIP_CONF_IPV6_RPL && (UIP_CONF_IPV6_RPL_LITE == 0) */ - uip_ds6_route_rm(route); -} -/*---------------------------------------------------------------------------*/ -static void annotate_transmission(uip_ipaddr_t *nexthop) { #if TCPIP_CONF_ANNOTATE_TRANSMISSIONS @@ -558,9 +541,11 @@ get_nexthop(uip_ipaddr_t *addr) never responded to link-layer acks, we drop its route. */ if(nexthop == NULL) { LOG_ERR("output: found dead route\n"); - drop_route(route); - /* We don't have a nexthop to send the packet to, so we drop - it. */ + /* Notifiy the routing protocol that we are about to remove the route */ + NETSTACK_ROUTING.drop_route(route); + /* Remove the route */ + uip_ds6_route_rm(route); + /* We don't have a nexthop to send the packet to, so we drop it. */ } else { LOG_INFO("output: found next hop from routing table: "); LOG_INFO_6ADDR(nexthop); diff --git a/os/net/ipv6/uip-ds6-route.h b/os/net/ipv6/uip-ds6-route.h index 8f2bc377d..663f0ad50 100644 --- a/os/net/ipv6/uip-ds6-route.h +++ b/os/net/ipv6/uip-ds6-route.h @@ -44,7 +44,6 @@ #include "net/nbr-table.h" #include "sys/stimer.h" #include "lib/list.h" -#include "net/routing/routing.h" #ifdef UIP_CONF_MAX_ROUTES #define UIP_MAX_ROUTES UIP_CONF_MAX_ROUTES diff --git a/os/net/routing/nullrouting/nullrouting.c b/os/net/routing/nullrouting/nullrouting.c index 5707143b1..e341225f9 100644 --- a/os/net/routing/nullrouting/nullrouting.c +++ b/os/net/routing/nullrouting/nullrouting.c @@ -103,6 +103,11 @@ link_callback(const linkaddr_t *addr, int status, int numtx) { } /*---------------------------------------------------------------------------*/ +static void +drop_route(uip_ds6_route_t *route) +{ +} +/*---------------------------------------------------------------------------*/ const struct routing_driver nullrouting_driver = { "Null Routing", init, @@ -116,6 +121,7 @@ const struct routing_driver nullrouting_driver = { ext_header_srh_update, ext_header_srh_get_next_hop, link_callback, + drop_route, }; /*---------------------------------------------------------------------------*/ diff --git a/os/net/routing/routing.h b/os/net/routing/routing.h index fa0e301af..330269826 100644 --- a/os/net/routing/routing.h +++ b/os/net/routing/routing.h @@ -118,6 +118,12 @@ 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 if it has decided to drop a route because + * + * \param route The route that will be dropped after this function returns + */ + void (* drop_route)(uip_ds6_route_t *route); }; #endif /* ROUTING_H_ */ diff --git a/os/net/routing/rpl-classic/rpl.c b/os/net/routing/rpl-classic/rpl.c index 6fa041eba..a649e247c 100644 --- a/os/net/routing/rpl-classic/rpl.c +++ b/os/net/routing/rpl-classic/rpl.c @@ -371,6 +371,18 @@ local_repair(const char *str) } } /*---------------------------------------------------------------------------*/ +static void +drop_route(uip_ds6_route_t *route) +{ + /* If we are the root of the network, trigger a global repair before + the route gets removed */ + rpl_dag_t *dag; + dag = (rpl_dag_t *)route->state.dag; + if(dag != NULL && dag->instance != NULL) { + rpl_repair_root(dag->instance->instance_id); + } +} +/*---------------------------------------------------------------------------*/ const struct routing_driver rpl_classic_driver = { "RPL Classic", init, @@ -384,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, + drop_route, }; /*---------------------------------------------------------------------------*/ diff --git a/os/net/routing/rpl-lite/rpl.c b/os/net/routing/rpl-lite/rpl.c index fe4f87684..dc1c123f2 100644 --- a/os/net/routing/rpl-lite/rpl.c +++ b/os/net/routing/rpl-lite/rpl.c @@ -193,6 +193,12 @@ init(void) rpl_ns_init(); } /*---------------------------------------------------------------------------*/ +static void +drop_route(uip_ds6_route_t *route) +{ + /* Do nothing. RPL-lite only supports non-storing mode, i.e. no routes */ +} +/*---------------------------------------------------------------------------*/ const struct routing_driver rpl_lite_driver = { "RPL Lite", init, @@ -206,6 +212,7 @@ const struct routing_driver rpl_lite_driver = { rpl_ext_header_srh_update, rpl_ext_header_srh_get_next_hop, rpl_link_callback, + drop_route, }; /*---------------------------------------------------------------------------*/