From 06ff89cbe49a57781ac3fdc98a4990ebfff18f8c Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Wed, 14 Dec 2016 13:59:08 +0000 Subject: [PATCH] nd6: use default_router_list internally only This patch rearranges the code division between nd6.c and ip6.c such that the latter does not need to access ND6-internal data structures (specifically, "default_router_list") directly anymore. --- src/core/ipv6/ip6.c | 12 +++--------- src/core/ipv6/nd6.c | 25 +++++++++++++++++++++++++ src/include/lwip/nd6.h | 2 +- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c index 0cb03182..2c2bd099 100644 --- a/src/core/ipv6/ip6.c +++ b/src/core/ipv6/ip6.c @@ -144,15 +144,9 @@ ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest) } /* Get the netif for a suitable router. */ - i = nd6_select_router(dest, NULL); - if (i >= 0) { - if (default_router_list[i].neighbor_entry != NULL) { - if (default_router_list[i].neighbor_entry->netif != NULL) { - if (netif_is_up(default_router_list[i].neighbor_entry->netif) && netif_is_link_up(default_router_list[i].neighbor_entry->netif)) { - return default_router_list[i].neighbor_entry->netif; - } - } - } + netif = nd6_find_route(dest); + if (netif != NULL && netif_is_up(netif) && netif_is_link_up(netif)) { + return netif; } /* try with the netif that matches the source address. */ diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index 37b91dbb..fb4e7339 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -93,6 +93,7 @@ static void nd6_free_neighbor_cache_entry(s8_t i); static s8_t nd6_find_destination_cache_entry(const ip6_addr_t *ip6addr); static s8_t nd6_new_destination_cache_entry(void); static s8_t nd6_is_prefix_in_netif(const ip6_addr_t *ip6addr, struct netif *netif); +static s8_t nd6_select_router(const ip6_addr_t *ip6addr, struct netif *netif); static s8_t nd6_get_router(const ip6_addr_t *router_addr, struct netif *netif); static s8_t nd6_new_router(const ip6_addr_t *router_addr, struct netif *netif); static s8_t nd6_get_onlink_prefix(ip6_addr_t *prefix, struct netif *netif); @@ -1396,6 +1397,30 @@ nd6_select_router(const ip6_addr_t *ip6addr, struct netif *netif) return -1; } +/** + * Find a router-announced route to the given destination. + * + * The caller is responsible for checking whether the returned netif, if any, + * is in a suitable state (up, link up) to be used for packet transmission. + * + * @param ip6addr the destination IPv6 address + * @return the netif to use for the destination, or NULL if none found + */ +struct netif * +nd6_find_route(const ip6_addr_t *ip6addr) +{ + s8_t i; + + i = nd6_select_router(ip6addr, NULL); + if (i >= 0) { + if (default_router_list[i].neighbor_entry != NULL) { + return default_router_list[i].neighbor_entry->netif; /* may be NULL */ + } + } + + return NULL; +} + /** * Find an entry for a default router. * diff --git a/src/include/lwip/nd6.h b/src/include/lwip/nd6.h index e6e2d9c1..1d4b2f26 100644 --- a/src/include/lwip/nd6.h +++ b/src/include/lwip/nd6.h @@ -143,7 +143,7 @@ void nd6_tmr(void); void nd6_input(struct pbuf *p, struct netif *inp); void nd6_clear_destination_cache(void); s8_t nd6_get_next_hop_entry(const ip6_addr_t *ip6addr, struct netif *netif); -s8_t nd6_select_router(const ip6_addr_t *ip6addr, struct netif *netif); +struct netif *nd6_find_route(const ip6_addr_t *ip6addr); u16_t nd6_get_destination_mtu(const ip6_addr_t *ip6addr, struct netif *netif); err_t nd6_queue_packet(s8_t neighbor_index, struct pbuf *p); #if LWIP_ND6_TCP_REACHABILITY_HINTS