From ac21a5f37076ea99422c959c63f62186c4a7d3cd Mon Sep 17 00:00:00 2001 From: Jan Breuer Date: Fri, 6 May 2016 16:15:20 +0200 Subject: [PATCH] nd6: add cleanup function --- src/core/ipv6/nd6.c | 25 +++++++++++++++++++++++++ src/core/netif.c | 8 ++++++++ src/include/lwip/nd6.h | 1 + 3 files changed, 34 insertions(+) diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index eb768847..77dab940 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -1843,4 +1843,29 @@ nd6_reachability_hint(const ip6_addr_t * ip6addr) } #endif /* LWIP_ND6_TCP_REACHABILITY_HINTS */ +void +nd6_cleanup_netif(struct netif * netif) +{ + u8_t i; + s8_t router_index; + for (i = 0; i < LWIP_ND6_NUM_PREFIXES; i++) { + if(prefix_list[i].netif == netif) { + prefix_list[i].netif = NULL; + prefix_list[i].flags = 0; + } + } + for (i = 0; i < LWIP_ND6_NUM_NEIGHBORS; i++) { + if(neighbor_cache[i].netif == netif) { + for (router_index = 0; router_index < LWIP_ND6_NUM_ROUTERS; router_index++) { + if (default_router_list[router_index].neighbor_entry == &neighbor_cache[i]) { + default_router_list[router_index].neighbor_entry = NULL; + default_router_list[router_index].flags = 0; + } + } + neighbor_cache[i].isrouter = 0; + nd6_free_neighbor_cache_entry(i); + } + } +} + #endif /* LWIP_IPV6 */ diff --git a/src/core/netif.c b/src/core/netif.c index ff6df4b2..49260432 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -68,6 +68,9 @@ #if LWIP_IPV6_MLD #include "lwip/mld6.h" #endif /* LWIP_IPV6_MLD */ +#if LWIP_IPV6 +#include "lwip/nd6.h" +#endif #if LWIP_NETIF_STATUS_CALLBACK #define NETIF_STATUS_CALLBACK(n) do{ if (n->status_callback) { (n->status_callback)(n); }}while(0) @@ -594,6 +597,11 @@ netif_set_down(struct netif *netif) etharp_cleanup_netif(netif); } #endif /* LWIP_IPV4 && LWIP_ARP */ + +#if LWIP_IPV6 + nd6_cleanup_netif(netif); +#endif /* LWIP_IPV6 */ + NETIF_STATUS_CALLBACK(netif); } } diff --git a/src/include/lwip/nd6.h b/src/include/lwip/nd6.h index d0646f1b..3f0ae298 100644 --- a/src/include/lwip/nd6.h +++ b/src/include/lwip/nd6.h @@ -351,6 +351,7 @@ err_t nd6_queue_packet(s8_t neighbor_index, struct pbuf * p); #if LWIP_ND6_TCP_REACHABILITY_HINTS void nd6_reachability_hint(const ip6_addr_t * ip6addr); #endif /* LWIP_ND6_TCP_REACHABILITY_HINTS */ +void nd6_cleanup_netif(struct netif * netif); #ifdef __cplusplus }