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.
diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c
index 0cb0318..2c2bd09 100644
--- a/src/core/ipv6/ip6.c
+++ b/src/core/ipv6/ip6.c
@@ -144,15 +144,9 @@
}
/* 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 37b91db..fb4e733 100644
--- a/src/core/ipv6/nd6.c
+++ b/src/core/ipv6/nd6.c
@@ -93,6 +93,7 @@
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);
@@ -1397,6 +1398,30 @@
}
/**
+ * 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.
*
* @param router_addr the IPv6 address of the router
diff --git a/src/include/lwip/nd6.h b/src/include/lwip/nd6.h
index e6e2d9c..1d4b2f2 100644
--- a/src/include/lwip/nd6.h
+++ b/src/include/lwip/nd6.h
@@ -143,7 +143,7 @@
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